summaryrefslogtreecommitdiffabout
path: root/korganizer/searchdialog.cpp
Unidiff
Diffstat (limited to 'korganizer/searchdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/searchdialog.cpp396
1 files changed, 396 insertions, 0 deletions
diff --git a/korganizer/searchdialog.cpp b/korganizer/searchdialog.cpp
new file mode 100644
index 0000000..74d48b9
--- a/dev/null
+++ b/korganizer/searchdialog.cpp
@@ -0,0 +1,396 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <qlayout.h>
26#include <qcheckbox.h>
27#include <qgroupbox.h>
28#include <qlabel.h>
29#include <qlineedit.h>
30#include <qpushbutton.h>
31
32#include <klocale.h>
33#include <kmessagebox.h>
34
35#include <libkdepim/kdateedit.h>
36
37#include "koglobals.h"
38#include "koprefs.h"
39
40#include "calendarview.h"
41#include "koviewmanager.h"
42#include "searchdialog.h"
43#include "searchdialog.moc"
44
45SearchDialog::SearchDialog(Calendar *calendar,CalendarView *parent)
46 : KDialogBase(Plain,i18n("KO/Pi Find "),User1|Close,User1,parent,0,false,false,
47 i18n("&Find"))
48{
49 mCalendar = calendar;
50 QFrame *topFrame = plainPage();
51 QVBoxLayout *layout = new QVBoxLayout(topFrame,0,spacingHint());
52
53 // Search expression
54 QHBoxLayout *subLayout = new QHBoxLayout();
55 layout->addLayout(subLayout);
56
57 searchLabel = new QLabel(topFrame);
58 searchLabel->setText(i18n("Search for:"));
59 subLayout->addWidget(searchLabel);
60
61 searchEdit = new QLineEdit(topFrame);
62 subLayout->addWidget(searchEdit);
63 searchEdit->setText("*"); // Find all events by default
64 searchEdit->setFocus();
65 connect(searchEdit, SIGNAL(textChanged ( const QString & )),this,SLOT(searchTextChanged( const QString & )));
66 connect(searchEdit, SIGNAL( returnPressed () ),this,SLOT(doSearch()));
67 // Subjects to search
68 // QGroupBox *subjectGroup = new QGroupBox(1,Vertical,i18n("Search In"),
69 // topFrame);
70
71
72
73 QHBox *incidenceGroup = new QHBox( topFrame );
74 layout->addWidget(incidenceGroup);
75
76 mSearchEvent = new QCheckBox(i18n("Events"),incidenceGroup);
77 mSearchEvent->setChecked(true);
78 mSearchTodo = new QCheckBox(i18n("Todos"),incidenceGroup);
79 mSearchJournal = new QCheckBox(i18n("Journals"),incidenceGroup);
80
81 QHBox *subjectGroup = new QHBox( topFrame );
82 layout->addWidget(subjectGroup);
83
84 mSummaryCheck = new QCheckBox(i18n("Summaries"),subjectGroup);
85 mSummaryCheck->setChecked(true);
86 mDescriptionCheck = new QCheckBox(i18n("Descriptions"),subjectGroup);
87 mCategoryCheck = new QCheckBox(i18n("Categories"),subjectGroup);
88
89 QHBox *attendeeGroup = new QHBox( topFrame );
90 layout->addWidget(attendeeGroup );
91 new QLabel( i18n("Attendee:"),attendeeGroup );
92 mSearchAName = new QCheckBox(i18n("Name"),attendeeGroup );
93 mSearchAEmail = new QCheckBox(i18n("Email"), attendeeGroup );
94 // Date range
95 // QGroupBox *rangeGroup = new QGroupBox(1,Horizontal,i18n("Date Range"),
96 // topFrame);
97 // layout->addWidget(rangeGroup);
98
99 QWidget *rangeWidget = new QWidget(topFrame);
100 QHBoxLayout *rangeLayout = new QHBoxLayout(rangeWidget,0,spacingHint());
101
102 rangeLayout->addWidget(new QLabel(i18n("From:"),rangeWidget));
103 mStartDate = new KDateEdit(rangeWidget);
104 rangeLayout->addWidget(mStartDate);
105 rangeLayout->addWidget(new QLabel(i18n("To:"),rangeWidget));
106 mEndDate = new KDateEdit(rangeWidget);
107 mEndDate->setDate(QDate::currentDate().addDays(365));
108 rangeLayout->addWidget(mEndDate);
109
110 // mInclusiveCheck = new QCheckBox(i18n("Events have to be completely included"), topFrame);
111 //mInclusiveCheck->setChecked(false);
112 layout->addWidget(rangeWidget);
113 //layout->addWidget(mInclusiveCheck);
114 // Subjects to search
115
116
117 // Results list view
118 listView = new KOListView(mCalendar,topFrame);
119 //listView->showDates();
120
121
122 layout->addWidget(listView);
123
124 // if ( KOPrefs::instance()->mCompactDialogs ) {
125 // KOGlobals::fitDialogToScreen( this, true );
126 // }
127
128 listView->readSettings(KOGlobals::config(),"SearchListView Layout");
129 connect(this,SIGNAL(user1Clicked()),SLOT(doSearch()));
130 QPushButton *CloseButton = findButton( Close );
131 //connect(CloseButton,SIGNAL(clicked()),listView, SLOT(clear()));
132
133#ifndef DESKTOP_VERSION
134 setCaption(i18n("Click OK to search ->"));
135 hideButtons();
136#endif
137}
138
139SearchDialog::~SearchDialog()
140{
141
142}
143void SearchDialog::accept()
144{
145 doSearch();
146}
147void SearchDialog::updateList()
148{
149 //listView->updateList();
150 if ( isVisible() ) {
151 updateView();
152 //qDebug("SearchDialog::updated ");
153 }
154 else {
155 listView->clear();
156 //qDebug("SearchDialog::cleared ");
157
158 }
159}
160void SearchDialog::searchTextChanged( const QString &_text )
161{
162 enableButton( KDialogBase::User1, !_text.isEmpty() );
163}
164
165void SearchDialog::doSearch()
166{
167 QRegExp re;
168
169 re.setWildcard(true); // most people understand these better.
170 re.setCaseSensitive(false);
171 re.setPattern(searchEdit->text());
172 if (!re.isValid() ) {
173 KMessageBox::sorry(this,
174 i18n("Invalid search expression,\ncannot perform "
175 "the search.\nPlease enter a search expression\n"
176 "using the wildcard characters\n '*' and '?'"
177 "where needed."));
178 return;
179 }
180
181 search(re);
182
183 listView->setStartDate( mStartDate->date() );
184 listView->showEvents(mMatchedEvents);
185 listView->addTodos(mMatchedTodos);
186 listView->addJournals(mMatchedJournals);
187
188 if (mMatchedEvents.count() + mMatchedJournals.count() + mMatchedTodos.count() == 0) {
189 KMessageBox::information(this,
190 i18n("No event/todo were found matching\nyour search expression.\nUse the wildcard characters\n ' * ' and ' ? ' where needed."));
191#ifndef DESKTOP_VERSION
192 setCaption(i18n("Click OK to search ->"));
193#else
194 setCaption(i18n("KO/Pi Find "));
195#endif
196 } else {
197 QString mess;
198 mess = mess.sprintf( i18n("%d item(s) found."), mMatchedEvents.count()+ mMatchedJournals.count() + mMatchedTodos.count() );
199 setCaption( i18n("KO/Pi Find: ") + mess);
200
201 }
202}
203void SearchDialog::updateConfig()
204{
205 listView->updateConfig();
206}
207void SearchDialog::updateView()
208{
209
210 QRegExp re;
211 re.setWildcard(true); // most people understand these better.
212 re.setCaseSensitive(false);
213 re.setPattern(searchEdit->text());
214 if (re.isValid()) {
215 search(re);
216 } else {
217 mMatchedEvents.clear();
218 mMatchedTodos.clear();
219 mMatchedJournals.clear();
220 }
221 listView->setStartDate( mStartDate->date() );
222 listView->showEvents(mMatchedEvents);
223 listView->addTodos(mMatchedTodos);
224 listView->addJournals(mMatchedJournals);
225}
226
227void SearchDialog::search(const QRegExp &re)
228{
229 QPtrList<Event> events = mCalendar->events( mStartDate->date(),
230 mEndDate->date(),
231 false /*mInclusiveCheck->isChecked()*/ );
232
233 mMatchedEvents.clear();
234 if ( mSearchEvent->isChecked() ) {
235 Event *ev;
236 for(ev=events.first();ev;ev=events.next()) {
237 if (mSummaryCheck->isChecked()) {
238#if QT_VERSION >= 300
239 if (re.search(ev->summary()) != -1)
240#else
241 if (re.match(ev->summary()) != -1)
242#endif
243 {
244 mMatchedEvents.append(ev);
245 continue;
246 }
247 }
248 if (mDescriptionCheck->isChecked()) {
249#if QT_VERSION >= 300
250 if (re.search(ev->description()) != -1)
251#else
252 if (re.match(ev->description()) != -1)
253#endif
254 {
255 mMatchedEvents.append(ev);
256 continue;
257 }
258 }
259 if (mCategoryCheck->isChecked()) {
260#if QT_VERSION >= 300
261 if (re.search(ev->categoriesStr()) != -1)
262#else
263 if (re.match(ev->categoriesStr()) != -1)
264#endif
265 {
266 mMatchedEvents.append(ev);
267 continue;
268 }
269 }
270 if ( mSearchAName->isChecked() || mSearchAEmail->isChecked() ) {
271 QPtrList<Attendee> tmpAList = ev->attendees();
272 Attendee *a;
273 for (a = tmpAList.first(); a; a = tmpAList.next()) {
274 if (mSearchAName->isChecked()) {
275#if QT_VERSION >= 300
276 if (re.search(a->name()) != -1)
277#else
278 if (re.match(a->name()) != -1)
279#endif
280 {
281 mMatchedEvents.append(ev);
282 break;
283 }
284 }
285 if (mSearchAEmail->isChecked()) {
286#if QT_VERSION >= 300
287 if (re.search(a->email()) != -1)
288#else
289 if (re.match(a->email()) != -1)
290#endif
291 {
292 mMatchedEvents.append(ev);
293 break;
294 }
295 }
296 }
297 }
298 }
299 }
300 QPtrList<Todo> todos = mCalendar->todos( );
301 mMatchedTodos.clear();
302 if ( mSearchTodo->isChecked() ) {
303 Todo *tod;
304 for(tod=todos.first();tod;tod=todos.next()) {
305 if (mSummaryCheck->isChecked()) {
306#if QT_VERSION >= 300
307 if (re.search(tod->summary()) != -1)
308#else
309 if (re.match(tod->summary()) != -1)
310#endif
311 {
312 mMatchedTodos.append(tod);
313 continue;
314 }
315 }
316 if (mDescriptionCheck->isChecked()) {
317#if QT_VERSION >= 300
318 if (re.search(tod->description()) != -1)
319#else
320 if (re.match(tod->description()) != -1)
321#endif
322 {
323 mMatchedTodos.append(tod);
324 continue;
325 }
326 }
327 if (mCategoryCheck->isChecked()) {
328#if QT_VERSION >= 300
329 if (re.search(tod->categoriesStr()) != -1)
330#else
331 if (re.match(tod->categoriesStr()) != -1)
332#endif
333 {
334 mMatchedTodos.append(tod);
335 continue;
336 }
337 }
338 if ( mSearchAName->isChecked() || mSearchAEmail->isChecked() ) {
339 QPtrList<Attendee> tmpAList = tod->attendees();
340 Attendee *a;
341 for (a = tmpAList.first(); a; a = tmpAList.next()) {
342 if (mSearchAName->isChecked()) {
343#if QT_VERSION >= 300
344 if (re.search(a->name()) != -1)
345#else
346 if (re.match(a->name()) != -1)
347#endif
348 {
349 mMatchedTodos.append(tod);
350 break;
351 }
352 }
353 if (mSearchAEmail->isChecked()) {
354#if QT_VERSION >= 300
355 if (re.search(a->email()) != -1)
356#else
357 if (re.match(a->email()) != -1)
358#endif
359 {
360 mMatchedTodos.append(tod);
361 break;
362 }
363 }
364 }
365 }
366 }
367 }
368 mMatchedJournals.clear();
369 if (mSearchJournal->isChecked() ) {
370 QPtrList<Journal> journals = mCalendar->journals( );
371 Journal* journ;
372
373 for(journ=journals.first();journ;journ=journals.next()) {
374 if ( journ->dtStart().date() <= mEndDate->date()
375 &&journ->dtStart().date() >= mStartDate->date()) {
376#if QT_VERSION >= 300
377 if (re.search(journ->description()) != -1)
378#else
379 if (re.match(journ->description()) != -1)
380#endif
381 {
382 mMatchedJournals.append(journ);
383 continue;
384 }
385 }
386 }
387 }
388
389}
390void SearchDialog::keyPressEvent ( QKeyEvent *e)
391{
392
393 e->ignore();
394
395}
396//mMatchedJournals;