• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

akregator

  • sources
  • kde-4.14
  • kdepim
  • akregator
  • src
searchbar.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2005 Frank Osterfeld <osterfeld@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "searchbar.h"
26 #include "akregatorconfig.h"
27 #include "articlematcher.h"
28 #include "article.h"
29 
30 #include <kcombobox.h>
31 #include <kiconloader.h>
32 #include <klineedit.h>
33 #include <klocale.h>
34 #include <kstandarddirs.h>
35 
36 #include <khbox.h>
37 #include <KIcon>
38 
39 #include <QLabel>
40 #include <QList>
41 #include <QString>
42 #include <QTimer>
43 
44 
45 using namespace boost;
46 using namespace Akregator;
47 using namespace Akregator::Filters;
48 
49 namespace Akregator
50 {
51 
52 class SearchBar::SearchBarPrivate
53 {
54 public:
55  QString searchText;
56  QTimer timer;
57  KLineEdit* searchLine;
58  KComboBox* searchCombo;
59  int delay;
60  std::vector<shared_ptr<const AbstractMatcher> > matchers;
61  void triggerTimer() {
62  if (timer.isActive())
63  timer.stop();
64 
65  timer.start(200);
66  }
67 };
68 
69 SearchBar::SearchBar(QWidget* parent) : KHBox(parent), d(new SearchBar::SearchBarPrivate)
70 {
71  d->delay = 400;
72  setMargin(2);
73  setSpacing(5);
74  setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
75 
76  QLabel* searchLabel = new QLabel(this);
77  searchLabel->setText( i18nc("Title of article searchbar", "S&earch:") );
78 
79  d->searchLine = new KLineEdit(this);
80  d->searchLine->setClearButtonShown(true);
81 
82  connect(d->searchLine, SIGNAL(textChanged(QString)),
83  this, SLOT(slotSearchStringChanged(QString)));
84 
85  searchLabel->setBuddy(d->searchLine);
86 
87  QLabel* statusLabel = new QLabel(this);
88  statusLabel->setText( i18n("Status:") );
89 
90  d->searchCombo = new KComboBox(this);
91 
92  QIcon iconAll = KIconLoader::global()->loadIcon("system-run", KIconLoader::Small);
93  QIcon iconNew(KStandardDirs::locate("data", "akregator/pics/kmmsgnew.png"));
94  QIcon iconUnread(KStandardDirs::locate("data", "akregator/pics/kmmsgunseen.png"));
95  const KIcon iconKeep( "mail-mark-important" );
96 
97  d->searchCombo->addItem(iconAll, i18n("All Articles"));
98  d->searchCombo->addItem(iconUnread, i18nc("Unread articles filter", "Unread"));
99  d->searchCombo->addItem(iconNew, i18nc("New articles filter", "New"));
100  d->searchCombo->addItem(iconKeep, i18nc("Important articles filter", "Important"));
101 
102  d->searchLine->setToolTip( i18n( "Enter space-separated terms to filter article list" ) );
103  d->searchCombo->setToolTip( i18n( "Choose what kind of articles to show in article list" ) );
104 
105  connect(d->searchCombo, SIGNAL(activated(int)),
106  this, SLOT(slotSearchComboChanged(int)));
107 
108  connect(&(d->timer), SIGNAL(timeout()), this, SLOT(slotActivateSearch()));
109  d->timer.setSingleShot(true);
110 }
111 
112 SearchBar::~SearchBar()
113 {
114  delete d;
115  d = 0;
116 }
117 
118 QString SearchBar::text() const
119 {
120  return d->searchText;
121 }
122 
123 int SearchBar::status() const
124 {
125  return d->searchCombo->currentIndex();
126 }
127 
128 void SearchBar::setDelay(int ms)
129 {
130  d->delay = ms;
131 }
132 
133 int SearchBar::delay() const
134 {
135  return d->delay;
136 }
137 
138 void SearchBar::slotClearSearch()
139 {
140  if (status() != 0 || !d->searchLine->text().isEmpty())
141  {
142  d->searchLine->clear();
143  d->searchCombo->setCurrentIndex(0);
144  d->timer.stop();
145  slotActivateSearch();
146  }
147 }
148 
149 void SearchBar::slotSetStatus(int status)
150 {
151  d->searchCombo->setCurrentIndex(status);
152  d->triggerTimer();
153 }
154 
155 void SearchBar::slotSetText(const QString& text)
156 {
157  d->searchLine->setText(text);
158  d->triggerTimer();
159 }
160 
161 void SearchBar::slotSearchComboChanged(int /*index*/)
162 {
163  d->triggerTimer();
164 }
165 
166 std::vector<shared_ptr<const AbstractMatcher> > SearchBar::matchers() const {
167  return d->matchers;
168 }
169 
170 
171 void SearchBar::slotSearchStringChanged(const QString& search)
172 {
173  d->searchText = search;
174  d->triggerTimer();
175 }
176 
177 void SearchBar::slotActivateSearch()
178 {
179  QList<Criterion> textCriteria;
180  QList<Criterion> statusCriteria;
181 
182  if (!d->searchText.isEmpty())
183  {
184  Criterion subjCrit( Criterion::Title, Criterion::Contains, d->searchText);
185  textCriteria << subjCrit;
186  Criterion crit1( Criterion::Description, Criterion::Contains, d->searchText);
187  textCriteria << crit1;
188  Criterion authCrit( Criterion::Author, Criterion::Contains, d->searchText);
189  textCriteria << authCrit;
190  }
191 
192  if (d->searchCombo->currentIndex())
193  {
194  switch (d->searchCombo->currentIndex())
195  {
196  case 1: // Unread
197  {
198  Criterion crit1( Criterion::Status, Criterion::Equals, New);
199  Criterion crit2( Criterion::Status, Criterion::Equals, Unread);
200  statusCriteria << crit1;
201  statusCriteria << crit2;
202  break;
203  }
204  case 2: // New
205  {
206  Criterion crit( Criterion::Status, Criterion::Equals, New);
207  statusCriteria << crit;
208  break;
209  }
210  case 3: // Keep flag set
211  {
212  Criterion crit( Criterion::KeepFlag, Criterion::Equals, true);
213  statusCriteria << crit;
214  break;
215  }
216  default:
217  break;
218  }
219  }
220 
221  std::vector<boost::shared_ptr<const AbstractMatcher> > matchers;
222 
223  matchers.push_back( boost::shared_ptr<const AbstractMatcher>( new ArticleMatcher( textCriteria, ArticleMatcher::LogicalOr ) ) );
224  matchers.push_back( boost::shared_ptr<const AbstractMatcher>( new ArticleMatcher( statusCriteria, ArticleMatcher::LogicalOr ) ) );
225  Settings::setStatusFilter( d->searchCombo->currentIndex() );
226  Settings::setTextFilter( d->searchText );
227  d->matchers = matchers;
228  emit signalSearch( matchers );
229 }
230 
231 }
232 
articlematcher.h
QWidget
Akregator::SearchBar::slotSetStatus
void slotSetStatus(int status)
Definition: searchbar.cpp:149
Akregator::SearchBar::~SearchBar
~SearchBar()
Definition: searchbar.cpp:112
Akregator::SearchBar::matchers
std::vector< boost::shared_ptr< const Filters::AbstractMatcher > > matchers() const
Definition: searchbar.cpp:166
QSizePolicy
Status
Status
Definition: akregatorstorageexporter.cpp:63
Akregator::SearchBar::delay
int delay() const
Definition: searchbar.cpp:133
Akregator::SearchBar::setDelay
void setDelay(int ms)
Definition: searchbar.cpp:128
Akregator::New
article was fetched in the last fetch of it's feed and not read yet.
Definition: types.h:33
Akregator::SearchBar::status
int status() const
Definition: searchbar.cpp:123
QLabel::setBuddy
void setBuddy(QWidget *buddy)
QTimer
QLabel::setText
void setText(const QString &)
QString
QList
Definition: article.h:41
article.h
Akregator::SearchBar::slotSetText
void slotSetText(const QString &text)
Definition: searchbar.cpp:155
Akregator::Filters::Criterion
Criterion for ArticleMatcher.
Definition: articlematcher.h:110
Akregator::Filters::ArticleMatcher
a powerful matcher supporting multiple criterions, which can be combined via logical OR or AND ...
Definition: articlematcher.h:75
QTimer::stop
void stop()
Akregator::SearchBar::text
QString text() const
Definition: searchbar.cpp:118
Akregator::SearchBar::slotClearSearch
void slotClearSearch()
Definition: searchbar.cpp:138
Akregator::Unread
article wasn't read yet by the user
Definition: types.h:31
searchbar.h
KHBox
QLabel
Akregator::SearchBar
Definition: searchbar.h:45
Akregator::SearchBar::signalSearch
void signalSearch(const std::vector< boost::shared_ptr< const Akregator::Filters::AbstractMatcher > > &)
emitted when the text and status filters were updated.
QIcon
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akregator

Skip menu "akregator"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal