25 #include "akregatorconfig.h"
26 #include "articlefilter.h"
28 #include "searchbar.h"
30 #include <kcombobox.h>
31 #include <kiconloader.h>
32 #include <klineedit.h>
33 #include <tdelocale.h>
34 #include <kstandarddirs.h>
36 #include <tqapplication.h>
42 #include <tqtoolbutton.h>
43 #include <tqtooltip.h>
51 class SearchBar::SearchBarPrivate
58 KLineEdit* searchLine;
59 KComboBox* searchCombo;
63 SearchBar::SearchBar(TQWidget* parent,
const char* name) : TQHBox(parent, name), d(new SearchBar::SearchBarPrivate)
68 setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) );
69 TQToolButton *clearButton =
new TQToolButton(
this);
70 clearButton->setIconSet( SmallIconSet( TQApplication::reverseLayout() ?
"clear_left" :
"locationbar_erase" ) );
72 clearButton->setAutoRaise(
true);
74 TQLabel* searchLabel =
new TQLabel(
this);
75 searchLabel->setText( i18n(
"S&earch:") );
77 d->searchLine =
new KLineEdit(
this,
"searchline");
78 connect(d->searchLine, TQ_SIGNAL(textChanged(
const TQString &)),
79 this, TQ_SLOT(slotSearchStringChanged(
const TQString &)));
81 searchLabel->setBuddy(d->searchLine);
83 TQLabel* statusLabel =
new TQLabel(
this);
84 statusLabel->setText( i18n(
"Status:") );
86 d->searchCombo =
new KComboBox(
this,
"searchcombo");
87 TQPixmap iconAll = TDEGlobal::iconLoader()->loadIcon(
"application-x-executable", TDEIcon::Small);
88 TQPixmap iconNew(locate(
"data",
"akregator/pics/kmmsgnew.png"));
89 TQPixmap iconUnread(locate(
"data",
"akregator/pics/kmmsgunseen.png"));
90 TQPixmap iconKeep(locate(
"data",
"akregator/pics/kmmsgflag.png"));
92 d->searchCombo->insertItem(iconAll, i18n(
"All Articles"));
93 d->searchCombo->insertItem(iconUnread, i18n(
"Unread"));
94 d->searchCombo->insertItem(iconNew, i18n(
"New"));
95 d->searchCombo->insertItem(iconKeep, i18n(
"Important"));
97 TQToolTip::add( clearButton, i18n(
"Clear filter" ) );
98 TQToolTip::add( d->searchLine, i18n(
"Enter space-separated terms to filter article list" ) );
99 TQToolTip::add( d->searchCombo, i18n(
"Choose what kind of articles to show in article list" ) );
101 connect(clearButton, TQ_SIGNAL( clicked() ),
102 this, TQ_SLOT(slotClearSearch()) );
104 connect(d->searchCombo, TQ_SIGNAL(activated(
int)),
105 this, TQ_SLOT(slotSearchComboChanged(
int)));
107 connect(&(d->timer), TQ_SIGNAL(timeout()),
this, TQ_SLOT(slotActivateSearch()));
110 SearchBar::~SearchBar()
116 TQString SearchBar::text()
const
118 return d->searchText;
121 int SearchBar::status()
const
123 return d->searchCombo->currentItem();
126 void SearchBar::setDelay(
int ms)
131 int SearchBar::delay()
const
136 void SearchBar::slotClearSearch()
138 if (status() != 0 || !d->searchLine->text().isEmpty())
140 d->searchLine->clear();
141 d->searchCombo->setCurrentItem(0);
143 slotActivateSearch();
147 void SearchBar::slotSetStatus(
int status)
149 d->searchCombo->setCurrentItem(status);
150 slotSearchComboChanged(status);
153 void SearchBar::slotSetText(
const TQString& text)
155 d->searchLine->setText(text);
156 slotSearchStringChanged(text);
159 void SearchBar::slotSearchComboChanged(
int )
161 if (d->timer.isActive())
164 d->timer.start(200,
true);
167 void SearchBar::slotSearchStringChanged(
const TQString& search)
169 d->searchText = search;
170 if (d->timer.isActive())
173 d->timer.start(200,
true);
176 void SearchBar::slotActivateSearch()
178 TQValueList<Criterion> textCriteria;
179 TQValueList<Criterion> statusCriteria;
181 if (!d->searchText.isEmpty())
183 Criterion subjCrit( Criterion::Title, Criterion::Contains, d->searchText);
184 textCriteria << subjCrit;
185 Criterion crit1( Criterion::Description, Criterion::Contains, d->searchText);
186 textCriteria << crit1;
187 Criterion crit2( Criterion::Author, Criterion::Contains, d->searchText);
188 textCriteria << crit2;
191 if (d->searchCombo->currentItem())
193 switch (d->searchCombo->currentItem())
197 Criterion crit1( Criterion::Status, Criterion::Equals, Article::New);
198 Criterion crit2( Criterion::Status, Criterion::Equals, Article::Unread);
199 statusCriteria << crit1;
200 statusCriteria << crit2;
205 Criterion crit( Criterion::Status, Criterion::Equals, Article::New);
206 statusCriteria << crit;
211 Criterion crit( Criterion::KeepFlag, Criterion::Equals,
true);
212 statusCriteria << crit;
220 d->textFilter =
ArticleMatcher(textCriteria, ArticleMatcher::LogicalOr);
221 d->statusFilter =
ArticleMatcher(statusCriteria, ArticleMatcher::LogicalOr);
222 Settings::setStatusFilter(d->searchCombo->currentItem());
223 Settings::setTextFilter(d->searchText);
224 emit signalSearch(d->textFilter, d->statusFilter);
229 #include "searchbar.moc"
a powerful matcher supporting multiple criterions, which can be combined via logical OR or AND
Criterion for ArticleMatcher.