summaryrefslogtreecommitdiffabout
path: root/korganizer/searchdialog.cpp
Unidiff
Diffstat (limited to 'korganizer/searchdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/searchdialog.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/korganizer/searchdialog.cpp b/korganizer/searchdialog.cpp
index aa1b244..cef59a2 100644
--- a/korganizer/searchdialog.cpp
+++ b/korganizer/searchdialog.cpp
@@ -1,279 +1,279 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 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 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 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 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 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. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qlayout.h> 25#include <qlayout.h>
26#include <qcheckbox.h> 26#include <qcheckbox.h>
27#include <qgroupbox.h> 27#include <qgroupbox.h>
28#include <qlabel.h> 28#include <qlabel.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30#include <qlineedit.h> 30#include <qlineedit.h>
31#include <qpushbutton.h> 31#include <qpushbutton.h>
32 32
33#include <klocale.h> 33#include <klocale.h>
34#include <kmessagebox.h> 34#include <kmessagebox.h>
35 35
36#include <libkdepim/kdateedit.h> 36#include <libkdepim/kdateedit.h>
37 37
38#include "koglobals.h" 38#include "koglobals.h"
39#include "koprefs.h" 39#include "koprefs.h"
40 40
41#include "calendarview.h" 41#include "calendarview.h"
42#include "koviewmanager.h" 42#include "koviewmanager.h"
43#include "searchdialog.h" 43#include "searchdialog.h"
44 44
45SearchDialog::SearchDialog(Calendar *calendar,CalendarView *parent) 45SearchDialog::SearchDialog(Calendar *calendar,CalendarView *parent)
46 : QVBox( 0 ) 46 : QVBox( 0 )
47 47
48{ 48{
49 mCalendar = calendar; 49 mCalendar = calendar;
50 QFrame *topFrame = new QFrame( this ) ;//plainPage(); 50 QFrame *topFrame = new QFrame( this ) ;//plainPage();
51 QVBoxLayout *layout = new QVBoxLayout(topFrame,KDialog::marginHint(),KDialog::spacingHint()); 51 QVBoxLayout *layout = new QVBoxLayout(topFrame,KDialog::marginHint(),KDialog::spacingHint());
52 52
53 // Search expression 53 // Search expression
54 QHBoxLayout *subLayout = new QHBoxLayout(); 54 QHBoxLayout *subLayout = new QHBoxLayout();
55 layout->addLayout(subLayout); 55 layout->addLayout(subLayout);
56 searchLabel = new QLabel(topFrame); 56 searchLabel = new QLabel(topFrame);
57 searchLabel->setText(i18n("Search for:")); 57 searchLabel->setText(i18n("Search for:"));
58 subLayout->addWidget(searchLabel); 58 subLayout->addWidget(searchLabel);
59 59
60 searchEdit = new QLineEdit(topFrame); 60 searchEdit = new QLineEdit(topFrame);
61 subLayout->addWidget(searchEdit); 61 subLayout->addWidget(searchEdit);
62 QPushButton *OkButton = new QPushButton( i18n("&Find"), topFrame ); 62 QPushButton *OkButton = new QPushButton( i18n("&Find"), topFrame );
63 //OkButton->setDefault( true ); 63 //OkButton->setDefault( true );
64 connect(OkButton,SIGNAL(clicked()),SLOT(doSearch())); 64 connect(OkButton,SIGNAL(clicked()),SLOT(doSearch()));
65 subLayout->addWidget(OkButton); 65 subLayout->addWidget(OkButton);
66 searchEdit->setText("*"); // Find all events by default 66 searchEdit->setText("*"); // Find all events by default
67 searchEdit->setFocus(); 67 searchEdit->setFocus();
68 connect(searchEdit, SIGNAL(textChanged ( const QString & )),this,SLOT(searchTextChanged( const QString & ))); 68 connect(searchEdit, SIGNAL(textChanged ( const QString & )),this,SLOT(searchTextChanged( const QString & )));
69 connect(searchEdit, SIGNAL( returnPressed () ),this,SLOT(doSearch())); 69 connect(searchEdit, SIGNAL( returnPressed () ),this,SLOT(doSearch()));
70 // Subjects to search 70 // Subjects to search
71 // QGroupBox *subjectGroup = new QGroupBox(1,Vertical,i18n("Search In"), 71 // QGroupBox *subjectGroup = new QGroupBox(1,Vertical,i18n("Search In"),
72 // topFrame); 72 // topFrame);
73 73
74 QHBox *incidenceGroup = new QHBox( topFrame ); 74 QHBox *incidenceGroup = new QHBox( topFrame );
75 layout->addWidget(incidenceGroup); 75 layout->addWidget(incidenceGroup);
76 76
77 mSearchEvent = new QCheckBox(i18n("Events"),incidenceGroup); 77 mSearchEvent = new QCheckBox(i18n("Events"),incidenceGroup);
78 mSearchEvent->setChecked(true); 78 mSearchEvent->setChecked(true);
79 mSearchTodo = new QCheckBox(i18n("Todos"),incidenceGroup); 79 mSearchTodo = new QCheckBox(i18n("Todos"),incidenceGroup);
80 mSearchJournal = new QCheckBox(i18n("Journals"),incidenceGroup); 80 mSearchJournal = new QCheckBox(i18n("Journals"),incidenceGroup);
81 81
82 QHBox *subjectGroup = new QHBox( topFrame ); 82 QHBox *subjectGroup = new QHBox( topFrame );
83 layout->addWidget(subjectGroup); 83 layout->addWidget(subjectGroup);
84 84
85 mSummaryCheck = new QCheckBox(i18n("Summary/Loc."),subjectGroup); 85 mSummaryCheck = new QCheckBox(i18n("Summary/Loc."),subjectGroup);
86 mSummaryCheck->setChecked(true); 86 mSummaryCheck->setChecked(true);
87 mDescriptionCheck = new QCheckBox(i18n("Descriptions"),subjectGroup); 87 mDescriptionCheck = new QCheckBox(i18n("Details"),subjectGroup);
88 mCategoryCheck = new QCheckBox(i18n("Categories"),subjectGroup); 88 mCategoryCheck = new QCheckBox(i18n("Categories"),subjectGroup);
89 89
90 QHBox *attendeeGroup = new QHBox( topFrame ); 90 QHBox *attendeeGroup = new QHBox( topFrame );
91 layout->addWidget(attendeeGroup ); 91 layout->addWidget(attendeeGroup );
92 new QLabel( i18n("Attendee:"),attendeeGroup ); 92 new QLabel( i18n("Attendee:"),attendeeGroup );
93 mSearchAName = new QCheckBox(i18n("Name"),attendeeGroup ); 93 mSearchAName = new QCheckBox(i18n("Name"),attendeeGroup );
94 mSearchAEmail = new QCheckBox(i18n("Email"), attendeeGroup ); 94 mSearchAEmail = new QCheckBox(i18n("Email"), attendeeGroup );
95 // Date range 95 // Date range
96 // QGroupBox *rangeGroup = new QGroupBox(1,Horizontal,i18n("Date Range"), 96 // QGroupBox *rangeGroup = new QGroupBox(1,Horizontal,i18n("Date Range"),
97 // topFrame); 97 // topFrame);
98 // layout->addWidget(rangeGroup); 98 // layout->addWidget(rangeGroup);
99 99
100 QWidget *rangeWidget = new QWidget(topFrame); 100 QWidget *rangeWidget = new QWidget(topFrame);
101 QHBoxLayout *rangeLayout = new QHBoxLayout(rangeWidget,0,KDialog::spacingHint()); 101 QHBoxLayout *rangeLayout = new QHBoxLayout(rangeWidget,0,KDialog::spacingHint());
102 rangeLayout->addWidget(new QLabel(i18n("From:"),rangeWidget)); 102 rangeLayout->addWidget(new QLabel(i18n("From:"),rangeWidget));
103 mStartDate = new KDateEdit(rangeWidget); 103 mStartDate = new KDateEdit(rangeWidget);
104 rangeLayout->addWidget(mStartDate); 104 rangeLayout->addWidget(mStartDate);
105 rangeLayout->addWidget(new QLabel(i18n("To:"),rangeWidget)); 105 rangeLayout->addWidget(new QLabel(i18n("To:"),rangeWidget));
106 mEndDate = new KDateEdit(rangeWidget); 106 mEndDate = new KDateEdit(rangeWidget);
107 mEndDate->setDate(QDate::currentDate().addDays(365)); 107 mEndDate->setDate(QDate::currentDate().addDays(365));
108 rangeLayout->addWidget(mEndDate); 108 rangeLayout->addWidget(mEndDate);
109 QToolButton *wt = QWhatsThis::whatsThisButton ( rangeWidget ); 109 QToolButton *wt = QWhatsThis::whatsThisButton ( rangeWidget );
110 rangeLayout->addWidget( (QWidget*)wt ); 110 rangeLayout->addWidget( (QWidget*)wt );
111 layout->addWidget(rangeWidget); 111 layout->addWidget(rangeWidget);
112 // Results list view 112 // Results list view
113 listView = new KOListView(mCalendar,topFrame); 113 listView = new KOListView(mCalendar,topFrame);
114 layout->addWidget(listView); 114 layout->addWidget(listView);
115 115
116 listView->readSettings(KOGlobals::config(),"SearchListView Layout"); 116 listView->readSettings(KOGlobals::config(),"SearchListView Layout");
117 117
118 setCaption( i18n("KO/Pi Find: ")); 118 setCaption( i18n("KO/Pi Find: "));
119#ifdef DESKTOP_VERSION 119#ifdef DESKTOP_VERSION
120 OkButton = new QPushButton( i18n("Close"), this ); 120 OkButton = new QPushButton( i18n("Close"), this );
121 connect(OkButton,SIGNAL(clicked()),SLOT(hide())); 121 connect(OkButton,SIGNAL(clicked()),SLOT(hide()));
122#endif 122#endif
123} 123}
124 124
125SearchDialog::~SearchDialog() 125SearchDialog::~SearchDialog()
126{ 126{
127 127
128} 128}
129void SearchDialog::accept() 129void SearchDialog::accept()
130{ 130{
131 doSearch(); 131 doSearch();
132} 132}
133void SearchDialog::updateList() 133void SearchDialog::updateList()
134{ 134{
135 //listView->updateList(); 135 //listView->updateList();
136 if ( isVisible() ) { 136 if ( isVisible() ) {
137 updateView(); 137 updateView();
138 //qDebug("SearchDialog::updated "); 138 //qDebug("SearchDialog::updated ");
139 } 139 }
140 else { 140 else {
141 listView->clear(); 141 listView->clear();
142 //qDebug("SearchDialog::cleared "); 142 //qDebug("SearchDialog::cleared ");
143 143
144 } 144 }
145} 145}
146void SearchDialog::searchTextChanged( const QString &_text ) 146void SearchDialog::searchTextChanged( const QString &_text )
147{ 147{
148#if 0 148#if 0
149 enableButton( KDialogBase::User1, !_text.isEmpty() ); 149 enableButton( KDialogBase::User1, !_text.isEmpty() );
150#endif 150#endif
151} 151}
152 152
153void SearchDialog::doSearch() 153void SearchDialog::doSearch()
154{ 154{
155 QRegExp re; 155 QRegExp re;
156 156
157 re.setWildcard(true); // most people understand these better. 157 re.setWildcard(true); // most people understand these better.
158 re.setCaseSensitive(false); 158 re.setCaseSensitive(false);
159 re.setPattern(searchEdit->text()); 159 re.setPattern(searchEdit->text());
160 if (!re.isValid() ) { 160 if (!re.isValid() ) {
161 KMessageBox::sorry(this, 161 KMessageBox::sorry(this,
162 i18n("Invalid search expression,\ncannot perform " 162 i18n("Invalid search expression,\ncannot perform "
163 "the search.\nPlease enter a search expression\n" 163 "the search.\nPlease enter a search expression\n"
164 "using the wildcard characters\n '*' and '?'" 164 "using the wildcard characters\n '*' and '?'"
165 "where needed.")); 165 "where needed."));
166 return; 166 return;
167 } 167 }
168 168
169 search(re); 169 search(re);
170 170
171 listView->setStartDate( mStartDate->date() ); 171 listView->setStartDate( mStartDate->date() );
172 listView->showEvents(mMatchedEvents); 172 listView->showEvents(mMatchedEvents);
173 listView->addTodos(mMatchedTodos); 173 listView->addTodos(mMatchedTodos);
174 listView->addJournals(mMatchedJournals); 174 listView->addJournals(mMatchedJournals);
175 175
176 if (mMatchedEvents.count() + mMatchedJournals.count() + mMatchedTodos.count() == 0) { 176 if (mMatchedEvents.count() + mMatchedJournals.count() + mMatchedTodos.count() == 0) {
177 setCaption(i18n("No items found. Use '*' and '?' where needed.")); 177 setCaption(i18n("No items found. Use '*' and '?' where needed."));
178 } else { 178 } else {
179 QString mess; 179 QString mess;
180 mess = mess.sprintf( i18n("%d item(s) found."), mMatchedEvents.count()+ mMatchedJournals.count() + mMatchedTodos.count() ); 180 mess = mess.sprintf( i18n("%d item(s) found."), mMatchedEvents.count()+ mMatchedJournals.count() + mMatchedTodos.count() );
181 setCaption( i18n("KO/Pi Find: ") + mess); 181 setCaption( i18n("KO/Pi Find: ") + mess);
182 182
183 } 183 }
184 searchEdit->setFocus(); 184 searchEdit->setFocus();
185} 185}
186void SearchDialog::updateConfig() 186void SearchDialog::updateConfig()
187{ 187{
188 listView->updateConfig(); 188 listView->updateConfig();
189} 189}
190void SearchDialog::updateView() 190void SearchDialog::updateView()
191{ 191{
192 192
193 QRegExp re; 193 QRegExp re;
194 re.setWildcard(true); // most people understand these better. 194 re.setWildcard(true); // most people understand these better.
195 re.setCaseSensitive(false); 195 re.setCaseSensitive(false);
196 re.setPattern(searchEdit->text()); 196 re.setPattern(searchEdit->text());
197 if (re.isValid()) { 197 if (re.isValid()) {
198 search(re); 198 search(re);
199 } else { 199 } else {
200 mMatchedEvents.clear(); 200 mMatchedEvents.clear();
201 mMatchedTodos.clear(); 201 mMatchedTodos.clear();
202 mMatchedJournals.clear(); 202 mMatchedJournals.clear();
203 } 203 }
204 listView->setStartDate( mStartDate->date() ); 204 listView->setStartDate( mStartDate->date() );
205 listView->showEvents(mMatchedEvents); 205 listView->showEvents(mMatchedEvents);
206 listView->addTodos(mMatchedTodos); 206 listView->addTodos(mMatchedTodos);
207 listView->addJournals(mMatchedJournals); 207 listView->addJournals(mMatchedJournals);
208} 208}
209 209
210void SearchDialog::search(const QRegExp &re) 210void SearchDialog::search(const QRegExp &re)
211{ 211{
212 QPtrList<Event> events = mCalendar->events( mStartDate->date(), 212 QPtrList<Event> events = mCalendar->events( mStartDate->date(),
213 mEndDate->date(), 213 mEndDate->date(),
214 false /*mInclusiveCheck->isChecked()*/ ); 214 false /*mInclusiveCheck->isChecked()*/ );
215 215
216 mMatchedEvents.clear(); 216 mMatchedEvents.clear();
217 if ( mSearchEvent->isChecked() ) { 217 if ( mSearchEvent->isChecked() ) {
218 Event *ev; 218 Event *ev;
219 for(ev=events.first();ev;ev=events.next()) { 219 for(ev=events.first();ev;ev=events.next()) {
220 if (mSummaryCheck->isChecked()) { 220 if (mSummaryCheck->isChecked()) {
221#if QT_VERSION >= 0x030000 221#if QT_VERSION >= 0x030000
222 if (re.search(ev->summary()) != -1) 222 if (re.search(ev->summary()) != -1)
223#else 223#else
224 if (re.match(ev->summary()) != -1) 224 if (re.match(ev->summary()) != -1)
225#endif 225#endif
226 { 226 {
227 mMatchedEvents.append(ev); 227 mMatchedEvents.append(ev);
228 continue; 228 continue;
229 } 229 }
230#if QT_VERSION >= 0x030000 230#if QT_VERSION >= 0x030000
231 if (re.search(ev->location()) != -1) 231 if (re.search(ev->location()) != -1)
232#else 232#else
233 if (re.match(ev->location()) != -1) 233 if (re.match(ev->location()) != -1)
234#endif 234#endif
235 { 235 {
236 mMatchedEvents.append(ev); 236 mMatchedEvents.append(ev);
237 continue; 237 continue;
238 } 238 }
239 } 239 }
240 if (mDescriptionCheck->isChecked()) { 240 if (mDescriptionCheck->isChecked()) {
241#if QT_VERSION >= 0x030000 241#if QT_VERSION >= 0x030000
242 if (re.search(ev->description()) != -1) 242 if (re.search(ev->description()) != -1)
243#else 243#else
244 if (re.match(ev->description()) != -1) 244 if (re.match(ev->description()) != -1)
245#endif 245#endif
246 { 246 {
247 mMatchedEvents.append(ev); 247 mMatchedEvents.append(ev);
248 continue; 248 continue;
249 } 249 }
250 } 250 }
251 if (mCategoryCheck->isChecked()) { 251 if (mCategoryCheck->isChecked()) {
252#if QT_VERSION >= 0x030000 252#if QT_VERSION >= 0x030000
253 if (re.search(ev->categoriesStr()) != -1) 253 if (re.search(ev->categoriesStr()) != -1)
254#else 254#else
255 if (re.match(ev->categoriesStr()) != -1) 255 if (re.match(ev->categoriesStr()) != -1)
256#endif 256#endif
257 { 257 {
258 mMatchedEvents.append(ev); 258 mMatchedEvents.append(ev);
259 continue; 259 continue;
260 } 260 }
261 } 261 }
262 if ( mSearchAName->isChecked() || mSearchAEmail->isChecked() ) { 262 if ( mSearchAName->isChecked() || mSearchAEmail->isChecked() ) {
263 QPtrList<Attendee> tmpAList = ev->attendees(); 263 QPtrList<Attendee> tmpAList = ev->attendees();
264 Attendee *a; 264 Attendee *a;
265 for (a = tmpAList.first(); a; a = tmpAList.next()) { 265 for (a = tmpAList.first(); a; a = tmpAList.next()) {
266 if (mSearchAName->isChecked()) { 266 if (mSearchAName->isChecked()) {
267#if QT_VERSION >= 0x030000 267#if QT_VERSION >= 0x030000
268 if (re.search(a->name()) != -1) 268 if (re.search(a->name()) != -1)
269#else 269#else
270 if (re.match(a->name()) != -1) 270 if (re.match(a->name()) != -1)
271#endif 271#endif
272 { 272 {
273 mMatchedEvents.append(ev); 273 mMatchedEvents.append(ev);
274 break; 274 break;
275 } 275 }
276 } 276 }
277 if (mSearchAEmail->isChecked()) { 277 if (mSearchAEmail->isChecked()) {
278#if QT_VERSION >= 0x030000 278#if QT_VERSION >= 0x030000
279 if (re.search(a->email()) != -1) 279 if (re.search(a->email()) != -1)