24 #include <tqwhatsthis.h>
25 #include <tqgroupbox.h>
26 #include <tqcheckbox.h>
28 #include <kfinddialog.h>
30 #include <kseparator.h>
32 #include <tdelocale.h>
33 #include <tdemessagebox.h>
36 #include "alarmlistview.h"
37 #include "preferences.h"
42 FIND_LIVE = KFindDialog::MinimumUserOption,
43 FIND_EXPIRED = KFindDialog::MinimumUserOption << 1,
44 FIND_MESSAGE = KFindDialog::MinimumUserOption << 2,
45 FIND_FILE = KFindDialog::MinimumUserOption << 3,
46 FIND_COMMAND = KFindDialog::MinimumUserOption << 4,
47 FIND_EMAIL = KFindDialog::MinimumUserOption << 5
49 static long FIND_KALARM_OPTIONS = FIND_LIVE | FIND_EXPIRED | FIND_MESSAGE | FIND_FILE | FIND_COMMAND | FIND_EMAIL;
52 Find::Find(EventListViewBase* parent)
75 mOptions = FIND_LIVE | FIND_EXPIRED | FIND_MESSAGE | FIND_FILE | FIND_COMMAND | FIND_EMAIL;
76 bool noExpired = !Preferences::expiredKeepDays();
77 bool showExpired = mListView->isA(
"AlarmListView") && ((AlarmListView*)mListView)->showingExpired();
78 if (noExpired || !showExpired)
79 mOptions &= ~FIND_EXPIRED;
83 KWin::activateWindow(mDialog->winId());
88 mDialog =
new KFindDialog(mListView,
"FindDlg", mOptions, mHistory, (mListView->selectedCount() > 1));
90 mDialog =
new KFindDialog(
false, mListView,
"FindDlg", mOptions, mHistory, (mListView->selectedCount() > 1));
92 mDialog->setHasSelection(
false);
93 TQWidget* kalarmWidgets = mDialog->findExtension();
96 TQBoxLayout* layout =
new TQVBoxLayout(kalarmWidgets, 0, KDialog::spacingHint());
97 TQGroupBox* group =
new TQGroupBox(i18n(
"Alarm Type"), kalarmWidgets);
98 layout->addWidget(group);
99 TQGridLayout* grid =
new TQGridLayout(group, 2, 2, KDialog::marginHint(), KDialog::spacingHint());
100 grid->addRowSpacing(0, mDialog->fontMetrics().lineSpacing()/2);
101 grid->setColStretch(1, 1);
104 mLive =
new TQCheckBox(i18n(
"Acti&ve"), group);
105 mLive->setFixedSize(mLive->sizeHint());
106 TQWhatsThis::add(mLive, i18n(
"Check to include active alarms in the search."));
107 grid->addWidget(mLive, 1, 0, TQt::AlignAuto);
109 mExpired =
new TQCheckBox(i18n(
"Ex&pired"), group);
110 mExpired->setFixedSize(mExpired->sizeHint());
111 TQWhatsThis::add(mExpired,
112 i18n(
"Check to include expired alarms in the search. "
113 "This option is only available if expired alarms are currently being displayed."));
114 grid->addWidget(mExpired, 1, 2, TQt::AlignAuto);
116 mActiveExpiredSep =
new KSeparator(TQt::Horizontal, kalarmWidgets);
117 grid->addMultiCellWidget(mActiveExpiredSep, 2, 2, 0, 2);
120 mMessageType =
new TQCheckBox(i18n(
"Text"), group,
"message");
121 mMessageType->setFixedSize(mMessageType->sizeHint());
122 TQWhatsThis::add(mMessageType, i18n(
"Check to include text message alarms in the search."));
123 grid->addWidget(mMessageType, 3, 0);
125 mFileType =
new TQCheckBox(i18n(
"Fi&le"), group,
"file");
126 mFileType->setFixedSize(mFileType->sizeHint());
127 TQWhatsThis::add(mFileType, i18n(
"Check to include file alarms in the search."));
128 grid->addWidget(mFileType, 3, 2);
130 mCommandType =
new TQCheckBox(i18n(
"Co&mmand"), group,
"command");
131 mCommandType->setFixedSize(mCommandType->sizeHint());
132 TQWhatsThis::add(mCommandType, i18n(
"Check to include command alarms in the search."));
133 grid->addWidget(mCommandType, 4, 0);
135 mEmailType =
new TQCheckBox(i18n(
"&Email"), group,
"email");
136 mEmailType->setFixedSize(mEmailType->sizeHint());
137 TQWhatsThis::add(mEmailType, i18n(
"Check to include email alarms in the search."));
138 grid->addWidget(mEmailType, 4, 2);
141 mLive->setChecked(mOptions & FIND_LIVE);
142 mExpired->setChecked(mOptions & FIND_EXPIRED);
143 mMessageType->setChecked(mOptions & FIND_MESSAGE);
144 mFileType->setChecked(mOptions & FIND_FILE);
145 mCommandType->setChecked(mOptions & FIND_COMMAND);
146 mEmailType->setChecked(mOptions & FIND_EMAIL);
149 connect(mDialog, TQ_SIGNAL(okClicked()),
this, TQ_SLOT(slotFind()));
158 mActiveExpiredSep->hide();
164 mActiveExpiredSep->show();
169 bool expired =
false;
172 bool command =
false;
174 for (EventListViewItemBase* item = mListView->firstChild(); item; item = item->nextSibling())
176 const KAEvent&
event = item->event();
181 switch (event.action())
183 case KAEvent::MESSAGE: text =
true;
break;
184 case KAEvent::FILE: file =
true;
break;
185 case KAEvent::COMMAND: command =
true;
break;
186 case KAEvent::EMAIL: email =
true;
break;
189 mLive->setEnabled(live);
190 mExpired->setEnabled(expired);
191 mMessageType->setEnabled(text);
192 mFileType->setEnabled(file);
193 mCommandType->setEnabled(command);
194 mEmailType->setEnabled(email);
196 mDialog->setHasCursor(mListView->currentItem());
198 if (mDialog->exec() == TQDialog::Accepted)
210 void Find::slotFind()
214 mHistory = mDialog->findHistory();
215 mOptions = mDialog->options() & ~FIND_KALARM_OPTIONS;
216 mOptions |= (mLive->isEnabled() && mLive->isChecked() ? FIND_LIVE : 0)
217 | (mExpired->isEnabled() && mExpired->isChecked() ? FIND_EXPIRED : 0)
218 | (mMessageType->isEnabled() && mMessageType->isChecked() ? FIND_MESSAGE : 0)
219 | (mFileType->isEnabled() && mFileType->isChecked() ? FIND_FILE : 0)
220 | (mCommandType->isEnabled() && mCommandType->isChecked() ? FIND_COMMAND : 0)
221 | (mEmailType->isEnabled() && mEmailType->isChecked() ? FIND_EMAIL : 0);
222 if (!(mOptions & (FIND_LIVE | FIND_EXPIRED))
223 || !(mOptions & (FIND_MESSAGE | FIND_FILE | FIND_COMMAND | FIND_EMAIL)))
225 KMessageBox::sorry(mDialog, i18n(
"No alarm types are selected to search"));
230 long options = mOptions & (KFindDialog::WholeWordsOnly | KFindDialog::CaseSensitive | KFindDialog::RegularExpression);
231 bool newFind = !mFind;
232 bool newPattern = (mDialog->pattern() != mLastPattern);
233 mLastPattern = mDialog->pattern();
236 mFind->resetCounts();
237 mFind->setPattern(mLastPattern);
238 mFind->setOptions(options);
243 mFind =
new KFind(mLastPattern, options, mListView);
244 mDialog->deleteLater();
246 mFind =
new KFind(mLastPattern, options, mListView, mDialog);
248 connect(mFind, TQ_SIGNAL(destroyed()), TQ_SLOT(slotKFindDestroyed()));
249 mFind->closeFindNextDialog();
253 mStartID = TQString();
254 mNoCurrentItem = newPattern;
255 bool checkEnd =
false;
259 if (mOptions & KFindDialog::FromCursor)
261 EventListViewItemBase* item = mListView->currentItem();
264 mStartID = item->event().id();
265 mNoCurrentItem =
false;
272 findNext(
true,
true, checkEnd,
false);
273 if (mFind && newFind)
282 void Find::findNext(
bool forward,
bool sort,
bool checkEnd,
bool fromCurrent)
287 EventListViewItemBase* item = mNoCurrentItem ? 0 : mListView->currentItem();
289 item = nextItem(item, forward);
294 for ( ; item && !last; item = nextItem(item, forward))
296 const KAEvent&
event = item->event();
297 if (!fromCurrent && !mStartID.isNull() && mStartID ==
event.id())
300 bool live = !
event.expired();
301 if ((live && !(mOptions & FIND_LIVE))
302 || (!live && !(mOptions & FIND_EXPIRED)))
304 switch (event.action())
306 case KAEvent::MESSAGE:
307 if (!(mOptions & FIND_MESSAGE))
309 mFind->setData(event.cleanText());
310 found = (mFind->find() == KFind::Match);
314 if (!(mOptions & FIND_FILE))
316 mFind->setData(event.cleanText());
317 found = (mFind->find() == KFind::Match);
320 case KAEvent::COMMAND:
321 if (!(mOptions & FIND_COMMAND))
323 mFind->setData(event.cleanText());
324 found = (mFind->find() == KFind::Match);
328 if (!(mOptions & FIND_EMAIL))
330 mFind->setData(event.emailAddresses(
", "));
331 found = (mFind->find() == KFind::Match);
334 mFind->setData(event.emailSubject());
335 found = (mFind->find() == KFind::Match);
338 mFind->setData(event.emailAttachments().join(
", "));
339 found = (mFind->find() == KFind::Match);
342 mFind->setData(event.cleanText());
343 found = (mFind->find() == KFind::Match);
351 mNoCurrentItem = !item;
356 mListView->clearSelection();
357 mListView->setSelected(item,
true);
358 mListView->setCurrentItem(item);
359 mListView->ensureItemVisible(item);
364 if (mFound || checkEnd)
366 TQString msg = forward ? i18n(
"End of alarm list reached.\nContinue from the beginning?")
367 : i18n(
"Beginning of alarm list reached.\nContinue from the end?");
368 if (KMessageBox::questionYesNo(mListView, msg, TQString(), KStdGuiItem::cont(), KStdGuiItem::cancel()) == KMessageBox::Yes)
370 mNoCurrentItem =
true;
371 findNext(forward,
false);
376 mFind->displayFinalDialog();
377 mNoCurrentItem =
false;
384 EventListViewItemBase* Find::nextItem(EventListViewItemBase* item,
bool forward)
const
387 if (mOptions & KFindDialog::FindBackwards)
390 it = item ? item->itemBelow() : mListView->firstChild();
392 it = item ? item->itemAbove() : mListView->lastItem();
393 return (EventListViewItemBase*)it;
KAEvent corresponds to a KCal::Event instance.