32 #include <kalarmcal/kaevent.h>
34 #include <kfinddialog.h>
36 #include <kseparator.h>
37 #include <kwindowsystem.h>
43 #include <QVBoxLayout>
44 #include <QGridLayout>
47 using namespace KAlarmCal;
62 class FindDlg :
public KFindDialog
65 FindDlg(
QWidget* parent,
long options = 0,
const QStringList& findStrings = QStringList(),
bool hasSelection =
false)
66 : KFindDialog(parent, options, findStrings, hasSelection) {}
68 void slotButtonClicked(
int button)
73 KFindDialog::slotButtonClicked(button);
86 connect(mListView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(slotSelectionChanged()));
96 void Find::slotSelectionChanged()
99 mDialog->setHasCursor(mListView->selectionModel()->currentIndex().isValid());
113 && (static_cast<AlarmListModel*>(mListView->model())->eventTypeFilter() & CalEvent::ARCHIVED);
115 && (
static_cast<AlarmListFilterModel*
>(mListView->model())->statusFilter() & CalEvent::ARCHIVED);
117 if (noArchived || !showArchived)
123 KWindowSystem::activateWindow(mDialog->winId());
128 mDialog =
new FindDlg(mListView, mOptions, mHistory, (mListView->selectionModel()->selectedRows().count() > 1));
129 mDialog->setModal(
false);
130 mDialog->setObjectName(QLatin1String(
"FindDlg"));
131 mDialog->setHasSelection(
false);
132 QWidget* kalarmWidgets = mDialog->findExtension();
135 QVBoxLayout* layout =
new QVBoxLayout(kalarmWidgets);
136 layout->setMargin(0);
137 layout->setSpacing(KDialog::spacingHint());
139 layout->addWidget(group);
140 QGridLayout* grid =
new QGridLayout(group);
141 grid->setMargin(KDialog::marginHint());
142 grid->setSpacing(KDialog::spacingHint());
143 grid->setColumnStretch(1, 1);
146 mLive =
new QCheckBox(i18nc(
"@option:check Alarm type",
"Active"), group);
147 mLive->setFixedSize(mLive->sizeHint());
148 mLive->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to include active alarms in the search."));
149 grid->addWidget(mLive, 1, 0, Qt::AlignLeft);
151 mArchived =
new QCheckBox(i18nc(
"@option:check Alarm type",
"Archived"), group);
152 mArchived->setFixedSize(mArchived->sizeHint());
153 mArchived->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to include archived alarms in the search. "
154 "This option is only available if archived alarms are currently being displayed."));
155 grid->addWidget(mArchived, 1, 2, Qt::AlignLeft);
157 mActiveArchivedSep =
new KSeparator(Qt::Horizontal, kalarmWidgets);
158 grid->addWidget(mActiveArchivedSep, 2, 0, 1, 3);
161 mMessageType =
new QCheckBox(i18nc(
"@option:check Alarm action = text display",
"Text"), group);
162 mMessageType->setFixedSize(mMessageType->sizeHint());
163 mMessageType->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to include text message alarms in the search."));
164 grid->addWidget(mMessageType, 3, 0);
166 mFileType =
new QCheckBox(i18nc(
"@option:check Alarm action = file display",
"File"), group);
167 mFileType->setFixedSize(mFileType->sizeHint());
168 mFileType->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to include file alarms in the search."));
169 grid->addWidget(mFileType, 3, 2);
171 mCommandType =
new QCheckBox(i18nc(
"@option:check Alarm action",
"Command"), group);
172 mCommandType->setFixedSize(mCommandType->sizeHint());
173 mCommandType->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to include command alarms in the search."));
174 grid->addWidget(mCommandType, 4, 0);
176 mEmailType =
new QCheckBox(i18nc(
"@option:check Alarm action",
"Email"), group);
177 mEmailType->setFixedSize(mEmailType->sizeHint());
178 mEmailType->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to include email alarms in the search."));
179 grid->addWidget(mEmailType, 4, 2);
181 mAudioType =
new QCheckBox(i18nc(
"@option:check Alarm action",
"Audio"), group);
182 mAudioType->setFixedSize(mAudioType->sizeHint());
183 mAudioType->setWhatsThis(i18nc(
"@info:whatsthis",
"Check to include audio alarms in the search."));
184 grid->addWidget(mAudioType, 5, 0);
190 mFileType->setChecked(mOptions &
FIND_FILE);
192 mEmailType->setChecked(mOptions &
FIND_EMAIL);
193 mAudioType->setChecked(mOptions &
FIND_AUDIO);
195 connect(mDialog, SIGNAL(okClicked()),
this, SLOT(slotFind()));
203 mActiveArchivedSep->hide();
209 mActiveArchivedSep->show();
214 bool archived =
false;
217 bool command =
false;
220 int rowCount = mListView->model()->rowCount();
221 for (
int row = 0; row < rowCount; ++row)
224 KAEvent viewEvent = mListView->
event(row);
225 const KAEvent*
event = &viewEvent;
227 const KAEvent*
event = mListView->
event(row);
229 if (event->expired())
233 switch (event->actionTypes())
235 case KAEvent::ACT_EMAIL: email =
true;
break;
236 case KAEvent::ACT_AUDIO: audio =
true;
break;
237 case KAEvent::ACT_COMMAND: command =
true;
break;
238 case KAEvent::ACT_DISPLAY:
239 if (event->actionSubType() == KAEvent::FILE)
245 case KAEvent::ACT_DISPLAY_COMMAND:
251 mLive->setEnabled(live);
252 mArchived->setEnabled(archived);
253 mMessageType->setEnabled(text);
254 mFileType->setEnabled(file);
255 mCommandType->setEnabled(command);
256 mEmailType->setEnabled(email);
257 mAudioType->setEnabled(audio);
259 mDialog->setHasCursor(mListView->selectionModel()->currentIndex().isValid());
266 void Find::slotFind()
270 mHistory = mDialog->findHistory();
272 if ((mOptions & KFind::RegularExpression) && !QRegExp(mDialog->pattern()).isValid())
274 mOptions |= (mLive->isEnabled() && mLive->isChecked() ?
FIND_LIVE : 0)
275 | (mArchived->isEnabled() && mArchived->isChecked() ?
FIND_ARCHIVED : 0)
276 | (mMessageType->isEnabled() && mMessageType->isChecked() ?
FIND_MESSAGE : 0)
277 | (mFileType->isEnabled() && mFileType->isChecked() ?
FIND_FILE : 0)
278 | (mCommandType->isEnabled() && mCommandType->isChecked() ?
FIND_COMMAND : 0)
279 | (mEmailType->isEnabled() && mEmailType->isChecked() ?
FIND_EMAIL : 0)
280 | (mAudioType->isEnabled() && mAudioType->isChecked() ?
FIND_AUDIO : 0);
289 long options = mOptions & (KFind::WholeWordsOnly | KFind::CaseSensitive | KFind::RegularExpression);
290 bool newFind = !mFind;
291 bool newPattern = (mDialog->pattern() != mLastPattern);
292 mLastPattern = mDialog->pattern();
295 mFind->resetCounts();
296 mFind->setPattern(mLastPattern);
297 mFind->setOptions(options);
301 mFind =
new KFind(mLastPattern, options, mListView, mDialog);
302 connect(mFind, SIGNAL(destroyed()), SLOT(slotKFindDestroyed()));
303 mFind->closeFindNextDialog();
308 mNoCurrentItem = newPattern;
309 bool checkEnd =
false;
313 if (mOptions & KFind::FromCursor)
315 QModelIndex index = mListView->selectionModel()->currentIndex();
319 mStartID = mListView->
event(index).id();
321 mStartID = mListView->
event(index)->id();
323 mNoCurrentItem =
false;
331 if (mFind && newFind)
340 void Find::findNext(
bool forward,
bool checkEnd,
bool fromCurrent)
344 index = mListView->selectionModel()->currentIndex();
346 index = nextItem(index, forward);
351 for ( ; index.isValid() && !last; index = nextItem(index, forward))
354 KAEvent viewEvent = mListView->
event(index);
355 const KAEvent*
event = &viewEvent;
357 const KAEvent*
event = mListView->
event(index);
359 if (!fromCurrent && !mStartID.isNull() && mStartID ==
event->id())
362 bool live = !
event->expired();
366 switch (event->actionTypes())
368 case KAEvent::ACT_EMAIL:
371 mFind->setData(event->emailAddresses(QLatin1String(
", ")));
372 found = (mFind->find() == KFind::Match);
375 mFind->setData(event->emailSubject());
376 found = (mFind->find() == KFind::Match);
379 mFind->setData(event->emailAttachments().join(QLatin1String(
", ")));
380 found = (mFind->find() == KFind::Match);
383 mFind->setData(event->cleanText());
384 found = (mFind->find() == KFind::Match);
387 case KAEvent::ACT_AUDIO:
390 mFind->setData(event->audioFile());
391 found = (mFind->find() == KFind::Match);
394 case KAEvent::ACT_COMMAND:
397 mFind->setData(event->cleanText());
398 found = (mFind->find() == KFind::Match);
401 case KAEvent::ACT_DISPLAY:
402 if (event->actionSubType() == KAEvent::FILE)
406 mFind->setData(event->cleanText());
407 found = (mFind->find() == KFind::Match);
411 case KAEvent::ACT_DISPLAY_COMMAND:
414 mFind->setData(event->cleanText());
415 found = (mFind->find() == KFind::Match);
425 mNoCurrentItem = !index.isValid();
430 QItemSelectionModel* sel = mListView->selectionModel();
431 sel->
select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
432 sel->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
433 mListView->scrollTo(index);
438 if (mFound || checkEnd)
440 QString msg = forward ? i18nc(
"@info",
"<para>End of alarm list reached.</para><para>Continue from the beginning?</para>")
441 : i18nc(
"@info",
"<para>Beginning of alarm list reached.</para><para>Continue from the end?</para>");
442 if (
KAMessageBox::questionYesNo(mListView, msg, QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::Yes)
444 mNoCurrentItem =
true;
450 mFind->displayFinalDialog();
451 mNoCurrentItem =
false;
458 QModelIndex Find::nextItem(
const QModelIndex& index,
bool forward)
const
460 if (mOptions & KFind::FindBackwards)
462 if (!index.isValid())
464 QAbstractItemModel* model = mListView->model();
466 return model->index(0, 0);
468 return model->index(model->rowCount() - 1, 0);
471 return mListView->indexBelow(index);
473 return mListView->indexAbove(index);
virtual QByteArray text(quint32 serialNumber) const =0
static long FIND_KALARM_OPTIONS
static int archivedKeepDays()
Get Days to keep expired alarms.
KAEvent * event(int row) const
void select(const QString &eventId, bool scrollToEvent=false)
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
Find(EventListView *parent)
void findNext(bool forward)
static int questionYesNo(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Options(Notify|WindowModal))