summaryrefslogtreecommitdiffstats
path: root/adept/libadept/quickfilter.cpp
blob: 73007270bcfb4db253351b0a685846552e062f01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <apt-front/predicate/combinators.h>
#include <apt-front/predicate/factory.h>
#include <tqobjectlist.h>
#include <klocale.h>
#include <kdebug.h>
#include <klineedit.h>
#include <tqcheckbox.h>

#include "quickfilter.h"

using namespace aptFront;
using namespace adept;

QuickFilterWidget::QuickFilterWidget( TQWidget *parent, const char *name )
    : QuickFilterUi( parent, name )
{
    setFocusProxy( m_match );
    connect( m_match, TQT_SIGNAL( textChanged( const TQString & ) ),
             this, TQT_SLOT( textChanged( const TQString & ) ) );
    /* connect( m_reset, TQT_SIGNAL( clicked() ),
       this, TQT_SLOT( reset() ) ); */
    connect( m_match, TQT_SIGNAL( returnPressed() ),
             this, TQT_SLOT( widgetsChanged() ) );
    connect( &timer, TQT_SIGNAL( timeout() ),
             this, TQT_SLOT( widgetsChanged() ) );

    TQObjectList *chld = queryList( TQCHECKBOX_OBJECT_NAME_STRING );
    TQObjectListIt it( *chld );
    while( it.current() != 0 ) {
        connect( it.current(), TQT_SIGNAL( toggled( bool )  ),
                 this, TQT_SLOT( widgetsChanged() ) );
        ++it;
    }
}

void QuickFilterWidget::mouseReleaseEvent( TQMouseEvent *e ) {
    m_match->setFocus();
    QuickFilterUi::mouseReleaseEvent( e );
}

void QuickFilterWidget::textChanged( const TQString & )
{
    kdDebug() << "QuickFilterWidget::textChanged" << endl;
    timer.start( 1000, true );
}

QuickFilterWidget::Predicate QuickFilterWidget::predicate()
{
    typedef QuickFilter< entity::Package > F;
    F f; int w = 0;
    if ( m_name->isChecked() ) w |= F::Name;
    if ( m_description->isChecked() ) w |= F::Description;
    if ( m_maintainer->isChecked() ) w |= F::Maintainer;

    f.setMatch( u8( m_match->text() ) );
    f.setWhat( w );

    return predicate::adapt< entity::Entity >( f );
}

static void blockedSet( TQCheckBox *b, bool v ) {
    b->blockSignals( true );
    b->setChecked( v );
    b->blockSignals( false );
}

void QuickFilterWidget::predicateChanged() {
    typedef QuickFilter< entity::Package > F;
    F f = downcast< F >( m_pred );
    m_match->blockSignals( true );
    m_match->setText( f.match() );
    m_match->blockSignals( false );
    int w = f.what();

    blockedSet( m_name, w & F::Name );
    blockedSet( m_description, w & F::Description );
    blockedSet( m_maintainer, w & F::Maintainer );
}