22 #include "mainwindow.moc"
30 #include "alarmresources.h"
49 #include <kalarmcal/alarmtext.h>
50 #include <kalarmcal/kaevent.h>
53 #include <kmime/kmime_content.h>
55 #include <kcalcore/memorycalendar.h>
56 #include <kcalutils/icaldrag.h>
57 #include <akonadi/control.h>
58 using namespace KCalCore;
59 using namespace KCalUtils;
61 #include <kcal/calendarlocal.h>
62 #include <kcal/icaldrag.h>
70 #include <kactioncollection.h>
71 #include <kinputdialog.h>
72 #include <ksystemtrayicon.h>
73 #include <kstandardaction.h>
74 #include <kiconloader.h>
77 #include <kglobalsettings.h>
78 #include <kconfiggroup.h>
79 #include <kshortcutsdialog.h>
80 #include <kedittoolbar.h>
81 #include <kxmlguifactory.h>
82 #include <kaboutdata.h>
84 #include <ktoggleaction.h>
85 #include <ktoolbarpopupaction.h>
88 #include <QHeaderView>
91 #include <QDesktopWidget>
92 #include <QDragEnterEvent>
94 #include <QResizeEvent>
95 #include <QCloseEvent>
98 using namespace KAlarmCal;
100 static const QString
UI_FILE = QLatin1String(
"kalarmui.rc");
143 MainWindow::MainWindow(
bool restored)
146 mHiddenTrayParent(false),
151 setAttribute(Qt::WA_DeleteOnClose);
152 setWindowModality(Qt::WindowModal);
153 setObjectName(QLatin1String(
"MainWin"));
154 setPlainCaption(KGlobal::mainComponent().aboutData()->programName());
155 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
162 KConfigGroup wconfig(KGlobal::config(),
WINDOW_NAME);
163 mResourcesWidth = wconfig.readEntry(QString::fromLatin1(
"Splitter %1").arg(KApplication::desktop()->width()), (
int)0);
166 setAcceptDrops(
true);
170 mSplitter =
new QSplitter(Qt::Horizontal,
this);
171 mSplitter->setChildrenCollapsible(
false);
172 mSplitter->installEventFilter(
this);
173 setCentralWidget(mSplitter);
177 Akonadi::Control::widgetNeedsAkonadi(
this);
180 AlarmResources* resources = AlarmResources::instance();
183 mSplitter->setStretchFactor(0, 0);
184 mSplitter->setStretchFactor(1, 1);
186 connect(resources, SIGNAL(signalErrorMessage(QString)), SLOT(showErrorMessage(QString)));
192 mListFilterModel->setEventTypeFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
195 mListFilterModel->
setStatusFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
198 mListView->
setModel(mListFilterModel);
206 connect(mListView->selectionModel(), SIGNAL(
selectionChanged(QItemSelection,QItemSelection)), SLOT(slotSelection()));
207 connect(mListView, SIGNAL(contextMenuRequested(QPoint)), SLOT(slotContextMenuRequested(QPoint)));
210 SLOT(slotCalendarStatusChanged()));
212 connect(resources, SIGNAL(resourceStatusChanged(AlarmResource*,AlarmResources::Change)),
213 SLOT(slotCalendarStatusChanged()));
215 connect(mResourceSelector, SIGNAL(resized(QSize,QSize)), SLOT(resourcesResized()));
216 mListView->installEventFilter(
this);
219 setAutoSaveSettings(QLatin1String(
WINDOW_NAME),
true);
220 mWindowList.append(
this);
221 if (mWindowList.count() == 1)
226 else if (
theApp()->trayWindow())
229 slotCalendarStatusChanged();
236 mWindowList.removeAt(mWindowList.indexOf(
this));
239 delete mResourceSelector;
240 mResourceSelector = 0;
251 KGlobal::config()->sync();
261 config.writeEntry(
"HiddenTrayParent",
isTrayParent() && isHidden());
262 config.writeEntry(
"ShowArchived", mShowArchived);
263 config.writeEntry(
"ShowTime", mShowTime);
264 config.writeEntry(
"ShowTimeTo", mShowTimeTo);
265 config.writeEntry(
"ResourcesWidth", mResourceSelector->isHidden() ? 0 : mResourceSelector->width());
275 mHiddenTrayParent = config.readEntry(
"HiddenTrayParent",
true);
276 mShowArchived = config.readEntry(
"ShowArchived",
false);
277 mShowTime = config.readEntry(
"ShowTime",
true);
278 mShowTimeTo = config.readEntry(
"ShowTimeTo",
false);
279 mResourcesWidth = config.readEntry(
"ResourcesWidth", (
int)0);
280 mShowResources = (mResourcesWidth > 0);
291 if (tray && tray->isVisible())
293 for (
int i = 0, end = mWindowList.count(); i < end; ++i)
294 if (mWindowList[i]->isVisible())
295 return mWindowList[i];
298 if (mWindowList.isEmpty())
300 return mWindowList[0];
309 if (!tray || !KSystemTrayIcon::isSystemTrayAvailable())
313 return mWindowList.count() == 1;
321 while (!mWindowList.isEmpty())
322 delete mWindowList[0];
330 if (obj == mSplitter)
347 else if (obj == mListView)
351 case QEvent::KeyPress:
353 QKeyEvent* ke =
static_cast<QKeyEvent*
>(e);
354 if (ke->key() == Qt::Key_Delete && ke->modifiers() == Qt::ShiftModifier)
357 mActionDeleteForce->trigger();
378 MainWindowBase::resizeEvent(re);
379 if (mResourcesWidth > 0)
382 widths.append(mResourcesWidth);
383 widths.append(width() - mResourcesWidth - mSplitter->handleWidth());
384 mSplitter->setSizes(widths);
388 void MainWindow::resourcesResized()
390 if (!mShown || mResizing)
393 if (widths.count() > 1)
395 mResourcesWidth = widths[0];
398 if (mResourcesWidth <= 5)
402 KConfigGroup config(KGlobal::config(),
WINDOW_NAME);
403 config.writeEntry(QString::fromLatin1(
"Splitter %1").arg(KApplication::desktop()->width()), mResourcesWidth);
415 if (mResourcesWidth > 0)
418 widths.append(mResourcesWidth);
419 widths.append(width() - mResourcesWidth - mSplitter->handleWidth());
420 mSplitter->setSizes(widths);
422 MainWindowBase::showEvent(se);
431 MainWindowBase::show();
437 KAMessageBox::error(
this, i18nc(
"@info",
"Failure to create menus (perhaps <filename>%1</filename> missing or corrupted)",
UI_FILE));
447 MainWindowBase::hideEvent(he);
453 void MainWindow::initActions()
456 KActionCollection* actions = actionCollection();
458 mActionTemplates =
new KAction(i18nc(
"@action",
"&Templates..."),
this);
459 actions->addAction(QLatin1String(
"templates"), mActionTemplates);
460 connect(mActionTemplates, SIGNAL(triggered(
bool)), SLOT(slotTemplates()));
462 mActionNew =
new NewAlarmAction(
false, i18nc(
"@action",
"&New"),
this);
463 actions->addAction(QLatin1String(
"new"), mActionNew);
466 actions->addAction(QLatin1String(
"newDisplay"), action);
467 action->setGlobalShortcut(dummy);
468 connect(action, SIGNAL(triggered(
bool)), SLOT(slotNewDisplay()));
471 actions->addAction(QLatin1String(
"newCommand"), action);
472 action->setGlobalShortcut(dummy);
473 connect(action, SIGNAL(triggered(
bool)), SLOT(slotNewCommand()));
476 actions->addAction(QLatin1String(
"newEmail"), action);
477 action->setGlobalShortcut(dummy);
478 connect(action, SIGNAL(triggered(
bool)), SLOT(slotNewEmail()));
481 actions->addAction(QLatin1String(
"newAudio"), action);
482 action->setGlobalShortcut(dummy);
483 connect(action, SIGNAL(triggered(
bool)), SLOT(slotNewAudio()));
486 actions->addAction(QLatin1String(
"newFromTemplate"), action);
487 connect(action, SIGNAL(selected(
const KAEvent*)), SLOT(slotNewFromTemplate(
const KAEvent*)));
489 mActionCreateTemplate =
new KAction(i18nc(
"@action",
"Create Tem&plate..."),
this);
490 actions->addAction(QLatin1String(
"createTemplate"), mActionCreateTemplate);
491 connect(mActionCreateTemplate, SIGNAL(triggered(
bool)), SLOT(slotNewTemplate()));
493 mActionCopy =
new KAction(KIcon(QLatin1String(
"edit-copy")), i18nc(
"@action",
"&Copy..."),
this);
494 actions->addAction(QLatin1String(
"copy"), mActionCopy);
495 mActionCopy->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Insert));
496 connect(mActionCopy, SIGNAL(triggered(
bool)), SLOT(slotCopy()));
498 mActionModify =
new KAction(KIcon(QLatin1String(
"document-properties")), i18nc(
"@action",
"&Edit..."),
this);
499 actions->addAction(QLatin1String(
"modify"), mActionModify);
500 mActionModify->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E));
501 connect(mActionModify, SIGNAL(triggered(
bool)), SLOT(slotModify()));
503 mActionDelete =
new KAction(KIcon(QLatin1String(
"edit-delete")), i18nc(
"@action",
"&Delete"),
this);
504 actions->addAction(QLatin1String(
"delete"), mActionDelete);
505 mActionDelete->setShortcut(QKeySequence::Delete);
506 connect(mActionDelete, SIGNAL(triggered(
bool)), SLOT(slotDeleteIf()));
509 mActionDeleteForce =
new KAction(i18nc(
"@action",
"Delete Without Confirmation"),
this);
510 actions->addAction(QLatin1String(
"delete-force"), mActionDeleteForce);
511 mActionDeleteForce->setShortcut(QKeySequence::Delete + Qt::SHIFT);
512 connect(mActionDeleteForce, SIGNAL(triggered(
bool)), SLOT(slotDeleteForce()));
514 mActionReactivate =
new KAction(i18nc(
"@action",
"Reac&tivate"),
this);
515 actions->addAction(QLatin1String(
"undelete"), mActionReactivate);
516 mActionReactivate->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
517 connect(mActionReactivate, SIGNAL(triggered(
bool)), SLOT(slotReactivate()));
519 mActionEnable =
new KAction(
this);
520 actions->addAction(QLatin1String(
"disable"), mActionEnable);
521 mActionEnable->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B));
522 connect(mActionEnable, SIGNAL(triggered(
bool)), SLOT(slotEnable()));
524 action =
new KAction(i18nc(
"@action",
"Wake From Suspend..."),
this);
525 actions->addAction(QLatin1String(
"wakeSuspend"), action);
526 connect(action, SIGNAL(triggered(
bool)), SLOT(slotWakeFromSuspend()));
528 action = KAlarm::createStopPlayAction(
this);
529 actions->addAction(QLatin1String(
"stopAudio"), action);
530 action->setGlobalShortcut(dummy);
533 actions->addAction(QLatin1String(
"showAlarmTimes"), mActionShowTime);
534 connect(mActionShowTime, SIGNAL(triggered(
bool)), SLOT(slotShowTime()));
537 actions->addAction(QLatin1String(
"showTimeToAlarms"), mActionShowTimeTo);
538 mActionShowTimeTo->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_I));
539 connect(mActionShowTimeTo, SIGNAL(triggered(
bool)), SLOT(slotShowTimeTo()));
541 mActionShowArchived =
new KToggleAction(i18nc(
"@action",
"Show Archi&ved Alarms"),
this);
542 actions->addAction(QLatin1String(
"showArchivedAlarms"), mActionShowArchived);
543 mActionShowArchived->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
544 connect(mActionShowArchived, SIGNAL(triggered(
bool)), SLOT(slotShowArchived()));
546 mActionToggleTrayIcon =
new KToggleAction(i18nc(
"@action",
"Show in System &Tray"),
this);
547 actions->addAction(QLatin1String(
"showInSystemTray"), mActionToggleTrayIcon);
548 connect(mActionToggleTrayIcon, SIGNAL(triggered(
bool)), SLOT(slotToggleTrayIcon()));
550 mActionToggleResourceSel =
new KToggleAction(KIcon(QLatin1String(
"view-choose")), i18nc(
"@action",
"Show &Calendars"),
this);
551 actions->addAction(QLatin1String(
"showResources"), mActionToggleResourceSel);
552 connect(mActionToggleResourceSel, SIGNAL(triggered(
bool)), SLOT(slotToggleResourceSelector()));
554 mActionSpreadWindows = KAlarm::createSpreadWindowsAction(
this);
555 actions->addAction(QLatin1String(
"spread"), mActionSpreadWindows);
556 mActionSpreadWindows->setGlobalShortcut(dummy);
558 mActionImportAlarms =
new KAction(i18nc(
"@action",
"Import &Alarms..."),
this);
559 actions->addAction(QLatin1String(
"importAlarms"), mActionImportAlarms);
560 connect(mActionImportAlarms, SIGNAL(triggered(
bool)), SLOT(slotImportAlarms()));
562 mActionImportBirthdays =
new KAction(i18nc(
"@action",
"Import &Birthdays..."),
this);
563 actions->addAction(QLatin1String(
"importBirthdays"), mActionImportBirthdays);
564 connect(mActionImportBirthdays, SIGNAL(triggered(
bool)), SLOT(slotBirthdays()));
566 mActionExportAlarms =
new KAction(i18nc(
"@action",
"E&xport Selected Alarms..."),
this);
567 actions->addAction(QLatin1String(
"exportAlarms"), mActionExportAlarms);
568 connect(mActionExportAlarms, SIGNAL(triggered(
bool)), SLOT(slotExportAlarms()));
570 mActionExport =
new KAction(i18nc(
"@action",
"E&xport..."),
this);
571 actions->addAction(QLatin1String(
"export"), mActionExport);
572 connect(mActionExport, SIGNAL(triggered(
bool)), SLOT(slotExportAlarms()));
574 action =
new KAction(KIcon(QLatin1String(
"view-refresh")), i18nc(
"@action",
"&Refresh Alarms"),
this);
575 actions->addAction(QLatin1String(
"refreshAlarms"), action);
576 connect(action, SIGNAL(triggered(
bool)), SLOT(slotRefreshAlarms()));
578 action = KAlarm::createAlarmEnableAction(
this);
579 actions->addAction(QLatin1String(
"alarmsEnable"), action);
583 QAction * act = KStandardAction::undo(
this, 0, actions);
588 act = KStandardAction::redo(
this, 0, actions);
594 mActionUndo =
new KToolBarPopupAction(KIcon(QLatin1String(
"edit-undo")), undoText,
this);
595 actions->addAction(QLatin1String(
"edit_undo"), mActionUndo);
597 connect(mActionUndo, SIGNAL(triggered(
bool)), SLOT(slotUndo()));
599 mActionRedo =
new KToolBarPopupAction(KIcon(QLatin1String(
"edit-redo")), redoText,
this);
600 actions->addAction(QLatin1String(
"edit_redo"), mActionRedo);
602 connect(mActionRedo, SIGNAL(triggered(
bool)), SLOT(slotRedo()));
604 KStandardAction::find(mListView, SLOT(slotFind()), actions);
605 mActionFindNext = KStandardAction::findNext(mListView, SLOT(slotFindNext()), actions);
606 mActionFindPrev = KStandardAction::findPrev(mListView, SLOT(slotFindPrev()), actions);
607 KStandardAction::selectAll(mListView, SLOT(selectAll()), actions);
608 KStandardAction::deselect(mListView, SLOT(
clearSelection()), actions);
611 KAction* act = KStandardAction::quit(0, 0, actions);
612 connect(act, SIGNAL(triggered(
bool)), SLOT(slotQuit()), Qt::QueuedConnection);
613 KStandardAction::keyBindings(
this, SLOT(slotConfigureKeys()), actions);
614 KStandardAction::configureToolbars(
this, SLOT(slotConfigureToolbar()), actions);
615 KStandardAction::preferences(
this, SLOT(slotPreferences()), actions);
617 setStandardToolBarMenuEnabled(
true);
620 applyMainWindowSettings(KGlobal::config()->group(
WINDOW_NAME));
622 mContextMenu =
static_cast<KMenu*
>(factory()->container(QLatin1String(
"listContext"),
this));
623 mActionsMenu =
static_cast<KMenu*
>(factory()->container(QLatin1String(
"actions"),
this));
624 KMenu* resourceMenu =
static_cast<KMenu*
>(factory()->container(QLatin1String(
"resourceContext"),
this));
626 mMenuError = (!mContextMenu || !mActionsMenu || !resourceMenu);
627 connect(mActionUndo->menu(), SIGNAL(aboutToShow()), SLOT(slotInitUndoMenu()));
628 connect(mActionUndo->menu(), SIGNAL(triggered(QAction*)), SLOT(slotUndoItem(QAction*)));
629 connect(mActionRedo->menu(), SIGNAL(aboutToShow()), SLOT(slotInitRedoMenu()));
630 connect(mActionRedo->menu(), SIGNAL(triggered(QAction*)), SLOT(slotRedoItem(QAction*)));
631 connect(
Undo::instance(), SIGNAL(changed(QString,QString)), SLOT(slotUndoStatus(QString,QString)));
632 connect(mListView, SIGNAL(findActive(
bool)), SLOT(slotFindActive(
bool)));
633 Preferences::connect(SIGNAL(archivedKeepDaysChanged(
int)),
this, SLOT(updateKeepArchived(
int)));
634 Preferences::connect(SIGNAL(showInSystemTrayChanged(
bool)),
this, SLOT(updateTrayIconAction()));
635 connect(
theApp(), SIGNAL(trayIconToggled()), SLOT(updateTrayIconAction()));
639 mActionShowTime->setChecked(mShowTime);
640 mActionShowTimeTo->setChecked(mShowTimeTo);
641 mActionShowArchived->setChecked(mShowArchived);
643 mActionShowArchived->setEnabled(
false);
644 mActionToggleResourceSel->setChecked(mShowResources);
645 slotToggleResourceSelector();
646 updateTrayIconAction();
649 mActionFindNext->setEnabled(
false);
650 mActionFindPrev->setEnabled(
false);
652 mActionCopy->setEnabled(
false);
653 mActionModify->setEnabled(
false);
654 mActionDelete->setEnabled(
false);
655 mActionReactivate->setEnabled(
false);
656 mActionEnable->setEnabled(
false);
657 mActionCreateTemplate->setEnabled(
false);
658 mActionExport->setEnabled(
false);
667 void MainWindow::enableTemplateMenuItem(
bool enable)
669 for (
int i = 0, end = mWindowList.count(); i < end; ++i)
670 mWindowList[i]->mActionTemplates->setEnabled(enable);
690 void MainWindow::updateKeepArchived(
int days)
692 kDebug() << (bool)days;
693 if (mShowArchived && !days)
695 mActionShowArchived->setEnabled(days);
707 mListView->clearSelection();
709 QModelIndex index = mListFilterModel->eventIndex(eventId);
712 mListView->select(index);
713 mListView->scrollTo(index);
716 mListView->select(eventId,
true);
729 return mListView->selectedEvent();
745 KAlarm::editNewAlarm(type, mListView);
752 void MainWindow::slotNewFromTemplate(
const KAEvent* tmplate)
754 KAlarm::editNewAlarm(tmplate, mListView);
761 void MainWindow::slotNewTemplate()
766 KAlarm::editNewTemplate(&event,
this);
770 KAlarm::editNewTemplate(event,
this);
778 void MainWindow::slotCopy()
783 KAlarm::editNewAlarm(&event,
this);
787 KAlarm::editNewAlarm(event,
this);
795 void MainWindow::slotModify()
800 KAlarm::editAlarm(&event,
this);
804 KAlarm::editAlarm(event,
this);
812 void MainWindow::slotDelete(
bool force)
822 for (
int i = 0, end = events.count(); i < end; ++i)
823 ids.append(events[i]->id());
828 int n = events.count();
830 "Do you really want to delete the %1 selected alarms?", n),
831 i18ncp(
"@title:window",
"Delete Alarm",
"Delete Alarms", n),
832 KGuiItem(i18nc(
"@action:button",
"&Delete"), QLatin1String(
"edit-delete")),
833 KStandardGuiItem::cancel(),
835 != KMessageBox::Continue)
843 for (
int i = 0; i < events.count(); )
845 Akonadi::Collection c = resources->collectionForEvent(events[i].itemId());
849 undos.
append(events[i++], c);
852 for (
int i = 0, e = 0, end = ids.count(); i < end; ++i)
858 undos.
append(*events[e++], r);
862 if (events.isEmpty())
863 kDebug() <<
"No alarms left to delete";
867 KAlarm::deleteEvents(events,
true,
this);
876 void MainWindow::slotReactivate()
888 QVector<EventId> ineligibleIDs;
889 KAlarm::reactivateEvents(events, ineligibleIDs, 0,
this);
891 QStringList ineligibleIDs;
892 KAlarm::reactivateEvents(events, ineligibleIDs, 0,
this);
897 for (
int i = 0, end = events.count(); i < end; ++i)
900 if (!ineligibleIDs.contains(
EventId(events[i])))
902 undos.
append(events[i], resources->collectionForEvent(events[i].itemId()));
905 QString
id = events[i]->id();
906 if (!ineligibleIDs.contains(
id))
917 void MainWindow::slotEnable()
919 bool enable = mActionEnableEnable;
922 QVector<KAEvent> eventCopies;
925 KAEvent::List eventCopies;
927 for (
int i = 0, end = events.count(); i < end; ++i)
928 eventCopies += events[i];
929 KAlarm::enableEvents(eventCopies, enable,
this);
936 void MainWindow::slotShowTime()
938 mShowTime = !mShowTime;
939 mActionShowTime->setChecked(mShowTime);
940 if (!mShowTime && !mShowTimeTo)
945 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
954 void MainWindow::slotShowTimeTo()
956 mShowTimeTo = !mShowTimeTo;
957 mActionShowTimeTo->setChecked(mShowTimeTo);
958 if (!mShowTimeTo && !mShowTime)
963 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
972 void MainWindow::slotShowArchived()
974 mShowArchived = !mShowArchived;
975 mActionShowArchived->setChecked(mShowArchived);
976 mActionShowArchived->setToolTip(mShowArchived ? i18nc(
"@info:tooltip",
"Hide Archived Alarms")
977 : i18nc(
"@info:tooltip",
"Show Archived Alarms"));
979 mListFilterModel->setEventTypeFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
981 mListFilterModel->
setStatusFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
984 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
992 void MainWindow::slotSpreadWindowsShortcut()
994 mActionSpreadWindows->trigger();
1000 void MainWindow::slotWakeFromSuspend()
1009 void MainWindow::slotImportAlarms()
1018 void MainWindow::slotExportAlarms()
1022 if (!events.isEmpty())
1024 KAEvent::List evts = KAEvent::ptrList(events);
1029 if (!events.isEmpty())
1038 void MainWindow::slotBirthdays()
1044 if (dlg->exec() == QDialog::Accepted)
1046 QVector<KAEvent> events = dlg->events();
1047 if (!events.isEmpty())
1051 KAlarm::UpdateStatus status = KAlarm::addEvents(events, dlg,
true,
true);
1055 for (
int i = 0, end = events.count(); i < end; ++i)
1058 Akonadi::Collection c = resources->collectionForEvent(events[i].itemId());
1059 undos.
append(events[i], c);
1066 if (status != KAlarm::UPDATE_FAILED)
1067 KAlarm::outputAlarmWarnings(dlg);
1076 void MainWindow::slotTemplates()
1081 enableTemplateMenuItem(
false);
1082 connect(mTemplateDlg, SIGNAL(finished()), SLOT(slotTemplatesEnd()));
1083 mTemplateDlg->show();
1090 void MainWindow::slotTemplatesEnd()
1094 mTemplateDlg->delayedDestruct();
1096 enableTemplateMenuItem(
true);
1103 void MainWindow::slotToggleTrayIcon()
1111 void MainWindow::slotToggleResourceSelector()
1113 mShowResources = mActionToggleResourceSel->isChecked();
1116 if (mResourcesWidth <= 0)
1118 mResourcesWidth = mResourceSelector->sizeHint().width();
1119 mResourceSelector->resize(mResourcesWidth, mResourceSelector->height());
1121 if (widths.count() == 1)
1123 int listwidth = widths[0] - mSplitter->handleWidth() - mResourcesWidth;
1124 mListView->resize(listwidth, mListView->height());
1125 widths.append(listwidth);
1126 widths[0] = mResourcesWidth;
1128 mSplitter->setSizes(widths);
1130 mResourceSelector->show();
1133 mResourceSelector->hide();
1135 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
1142 void MainWindow::showErrorMessage(
const QString& msg)
1152 void MainWindow::updateTrayIconAction()
1154 mActionToggleTrayIcon->setEnabled(KSystemTrayIcon::isSystemTrayAvailable());
1155 mActionToggleTrayIcon->setChecked(
theApp()->trayIconDisplayed());
1161 void MainWindow::slotFindActive(
bool active)
1163 mActionFindNext->setEnabled(active);
1164 mActionFindPrev->setEnabled(active);
1170 void MainWindow::slotUndo()
1172 Undo::undo(
this, KGlobal::locale()->removeAcceleratorMarker(mActionUndo->text()));
1178 void MainWindow::slotRedo()
1180 Undo::redo(
this, KGlobal::locale()->removeAcceleratorMarker(mActionRedo->text()));
1186 void MainWindow::slotUndoItem(QAction* action)
1188 int id = mUndoMenuIds[action];
1195 void MainWindow::slotRedoItem(QAction* action)
1197 int id = mUndoMenuIds[action];
1205 void MainWindow::slotInitUndoMenu()
1207 initUndoMenu(mActionUndo->menu(),
Undo::UNDO);
1214 void MainWindow::slotInitRedoMenu()
1216 initUndoMenu(mActionRedo->menu(),
Undo::REDO);
1225 mUndoMenuIds.clear();
1228 for (
int i = 0, end = ids.count(); i < end; ++i)
1233 QString
text = descrip.isEmpty()
1234 ? i18nc(
"@action Undo/Redo [action]",
"%1 %2", action, actText)
1235 : i18nc(
"@action Undo [action]: message",
"%1 %2: %3", action, actText, descrip);
1236 QAction* act = menu->addAction(text);
1237 mUndoMenuIds[act] = id;
1245 void MainWindow::slotUndoStatus(
const QString& undo,
const QString& redo)
1249 mActionUndo->setEnabled(
false);
1250 mActionUndo->setText(undoText);
1254 mActionUndo->setEnabled(
true);
1255 mActionUndo->setText(QString::fromLatin1(
"%1 %2").arg(undoText).arg(undo));
1259 mActionRedo->setEnabled(
false);
1260 mActionRedo->setText(redoText);
1264 mActionRedo->setEnabled(
true);
1265 mActionRedo->setText(QString::fromLatin1(
"%1 %2").arg(redoText).arg(redo));
1272 void MainWindow::slotRefreshAlarms()
1274 KAlarm::refreshAlarms();
1280 void MainWindow::slotPreferences()
1288 void MainWindow::slotConfigureKeys()
1290 KShortcutsDialog::configure(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed,
this);
1296 void MainWindow::slotConfigureToolbar()
1298 saveMainWindowSettings(KGlobal::config()->group(
WINDOW_NAME));
1299 KEditToolBar dlg(factory());
1300 connect(&dlg, SIGNAL(newToolBarConfig()),
this, SLOT(slotNewToolbarConfig()));
1308 void MainWindow::slotNewToolbarConfig()
1311 applyMainWindowSettings(KGlobal::config()->group(
WINDOW_NAME));
1320 void MainWindow::slotQuit()
1330 if (!
theApp()->sessionClosingDown())
1358 e->acceptProposedAction();
1372 KMime::Headers::Base* hd = content.headerByType(header);
1373 return hd ? hd->asUnicodeString() : QString();
1382 kDebug() <<
"Formats:" << e->mimeData()->formats();
1384 KAEvent::SubAction action = KAEvent::MESSAGE;
1386 AlarmText alarmText;
1395 QString fmts = data->formats().join(QLatin1String(
", "));
1403 if (!(bytes = data->data(QLatin1String(
"message/rfc822"))).isEmpty())
1406 kDebug() <<
"email";
1407 KMime::Content content;
1408 content.setContent(bytes);
1411 if (content.textContent())
1412 body = content.textContent()->decodedText(
true,
true);
1413 unsigned long sernum = 0;
1419 if (!mailList.isEmpty())
1429 #ifdef KMAIL_SUPPORTED
1434 kDebug() <<
"KMail_list";
1435 if (mailList.isEmpty())
1439 dt.setTime_t(summary.
date());
1440 QString body = KAMail::getMailBody(summary.
serialNumber());
1441 alarmText.setEmail(summary.
to(), summary.
from(), QString(),
1442 KGlobal::locale()->formatDateTime(dt), summary.
subject(),
1453 kDebug() <<
"iCalendar";
1455 Event::List events = calendar->rawEvents();
1457 Event::List events = calendar.rawEvents();
1459 if (!events.isEmpty())
1461 KAEvent ev(events[0]);
1462 KAlarm::editNewAlarm(&ev, win);
1467 Todo::List todos = calendar->rawTodos();
1469 Todo::List todos = calendar.rawTodos();
1471 if (todos.isEmpty())
1474 Todo::Ptr todo = todos[0];
1476 Todo* todo = todos[0];
1478 alarmText.setTodo(todo);
1479 KDateTime start = todo->dtStart(
true);
1480 if (!start.isValid() && todo->hasDueDate())
1481 start = todo->dtDue(
true);
1482 KAEvent::Flags flags = KAEvent::DEFAULT_FONT;
1483 if (start.isDateOnly())
1484 flags |= KAEvent::ANY_TIME;
1486 QFont(), KAEvent::MESSAGE, 0, flags,
true);
1489 ev.setRecurrence(*todo->recurrence());
1490 ev.setNextOccurrence(KDateTime::currentUtcDateTime());
1493 KAlarm::editNewAlarm(&ev, win);
1500 KMimeType::Ptr mimeType = KMimeType::findByUrl(files[0]);
1501 action = mimeType->name().startsWith(QLatin1String(
"audio/")) ? KAEvent::AUDIO : KAEvent::FILE;
1502 alarmText.setText(files[0].prettyUrl());
1504 else if (data->hasText())
1506 QString text = data->text();
1508 alarmText.setText(text);
1513 if (!alarmText.isEmpty())
1515 if (action == KAEvent::MESSAGE
1516 && (alarmText.isEmail() || alarmText.isScript()))
1521 types += i18nc(
"@item:inlistbox",
"Display Alarm");
1522 if (alarmText.isEmail())
1523 types += i18nc(
"@item:inlistbox",
"Email Alarm");
1524 else if (alarmText.isScript())
1525 types += i18nc(
"@item:inlistbox",
"Command Alarm");
1527 QString type = KInputDialog::getItem(i18nc(
"@title:window",
"Alarm Type"),
1528 i18nc(
"@info",
"Choose alarm type to create:"), types, 0,
false, &ok,
mainMainWindow());
1531 int i = types.indexOf(type);
1533 action = alarmText.isEmail() ? KAEvent::EMAIL : KAEvent::COMMAND;
1535 KAlarm::editNewAlarm(action, win, &alarmText);
1543 void MainWindow::slotCalendarStatusChanged()
1550 AlarmResources* resources = AlarmResources::instance();
1551 bool active = resources->activeCount(CalEvent::ACTIVE,
true);
1552 bool templat = resources->activeCount(CalEvent::TEMPLATE,
true);
1554 for (
int i = 0, end = mWindowList.count(); i < end; ++i)
1557 w->mActionImportAlarms->setEnabled(active || templat);
1558 w->mActionImportBirthdays->setEnabled(active);
1559 w->mActionCreateTemplate->setEnabled(templat);
1569 void MainWindow::slotSelection()
1577 int count = events.count();
1586 bool active = mActionNew->isEnabled();
1588 bool readOnly =
false;
1589 bool allArchived =
true;
1590 bool enableReactivate =
true;
1591 bool enableEnableDisable =
true;
1592 bool enableEnable =
false;
1593 bool enableDisable =
false;
1595 KDateTime now = KDateTime::currentUtcDateTime();
1596 for (
int i = 0; i <
count; ++i)
1600 KAEvent*
event = ev ? ev : &events[i];
1602 KAEvent*
event = events[i];
1604 bool expired =
event->expired();
1606 allArchived =
false;
1613 if (enableReactivate
1614 && (!expired || !event->occursAfter(now,
true)))
1615 enableReactivate =
false;
1616 if (enableEnableDisable)
1619 enableEnableDisable = enableEnable = enableDisable =
false;
1622 if (!enableEnable && !event->enabled())
1623 enableEnable =
true;
1624 if (!enableDisable && event->enabled())
1625 enableDisable =
true;
1634 mActionCreateTemplate->setEnabled((count == 1) && (AlarmResources::instance()->activeCount(CalEvent::TEMPLATE,
true) > 0));
1636 mActionExportAlarms->setEnabled(
true);
1637 mActionExport->setEnabled(
true);
1638 mActionCopy->setEnabled(active && count == 1);
1639 mActionModify->setEnabled(count == 1);
1640 mActionDelete->setEnabled(!readOnly && (active || allArchived));
1641 mActionReactivate->setEnabled(active && enableReactivate);
1642 mActionEnable->setEnabled(active && !readOnly && (enableEnable || enableDisable));
1643 if (enableEnable || enableDisable)
1644 setEnableText(enableEnable);
1653 void MainWindow::slotContextMenuRequested(
const QPoint& globalPos)
1657 mContextMenu->popup(globalPos);
1663 void MainWindow::selectionCleared()
1665 mActionCreateTemplate->setEnabled(
false);
1666 mActionExportAlarms->setEnabled(
false);
1667 mActionExport->setEnabled(
false);
1668 mActionCopy->setEnabled(
false);
1669 mActionModify->setEnabled(
false);
1670 mActionDelete->setEnabled(
false);
1671 mActionReactivate->setEnabled(
false);
1672 mActionEnable->setEnabled(
false);
1678 void MainWindow::setEnableText(
bool enable)
1680 mActionEnableEnable = enable;
1681 mActionEnable->setText(enable ? i18nc(
"@action",
"Ena&ble") : i18nc(
"@action",
"Disa&ble"));
1690 if (win && mWindowList.indexOf(win) != -1)
1693 if (win->isVisible())
1703 win->setWindowState(win->windowState() & ~Qt::WindowMinimized);
1705 win->activateWindow();
1729 mEditAlarmMap[dlg] = event;
1732 ev.setResource(resource);
1733 mEditAlarmMap[dlg] = ev;
1735 connect(dlg, SIGNAL(accepted()), SLOT(editAlarmOk()));
1736 connect(dlg, SIGNAL(destroyed(
QObject*)), SLOT(editAlarmDeleted(
QObject*)));
1737 dlg->setAttribute(Qt::WA_DeleteOnClose,
true);
1745 void MainWindow::editAlarmOk()
1750 QMap<EditAlarmDlg*, KAEvent>::Iterator it = mEditAlarmMap.find(dlg);
1751 if (it == mEditAlarmMap.end())
1753 KAEvent
event = it.value();
1754 mEditAlarmMap.erase(it);
1755 if (!event.isValid())
1757 if (dlg->result() != QDialog::Accepted)
1761 KAlarm::updateEditedAlarm(dlg, event, c);
1763 KAlarm::updateEditedAlarm(dlg, event, event.resource());
1771 void MainWindow::editAlarmDeleted(
QObject* obj)
1773 mEditAlarmMap.remove(static_cast<EditAlarmDlg*>(obj));
static void emitChanged()
virtual void dropEvent(QDropEvent *)
static const char * SHOW_TIME_TO_KEY
KAEvent * selectedEvent() const
virtual void hideEvent(QHideEvent *)
static bool redo(QWidget *parent, const QString &action)
static EventListModel * alarms()
void selectTimeColumns(bool time, bool timeTo)
static bool importAlarms(QWidget *, AlarmResource *=0)
static QColor defaultBgColour()
Get Background color.
bool eventReadOnly(const QString &uniqueID) const
virtual QByteArray text(quint32 serialNumber) const =0
static void executeDragEnterEvent(QDragEnterEvent *)
The MainWindowBase class is a base class for KAlarm's main window and message window.
bool wantShowInSystemTray() const
static WakeFromSuspendDlg * create(QWidget *parent)
virtual void resizeEvent(QResizeEvent *)
static AlarmCalendar * resources()
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
static KShortcut redoShortcut
static QString redoTextStripped
static QString description(Type, int id)
MainWindow * assocMainWindow() const
TemplateMenuAction * fromTemplateAlarmAction() const
AlarmResource * resourceForEvent(const QString &eventID) const
static TemplateDlg * create(QWidget *parent=0)
static QString undoTextStripped
static void saveDeletes(const EventList &, const QString &name=QString())
virtual void closeEvent(QCloseEvent *)
KAEvent::List selectedEvents() const
static int archivedKeepDays()
Get Days to keep expired alarms.
static QString i18n_a_ShowAlarmTimes()
bool isTrayParent() const
the KAlarm application object
static void saveAdds(const EventList &, const QString &name=QString())
void removeWindow(MainWindow *)
void editAlarm(EditAlarmDlg *, const KAEvent &, AlarmResource *)
static MailList fromMimeData(const QMimeData *md)
static QList< int > ids(Type)
void setAssocMainWindow(MainWindow *win)
static KTimeZone timeZone(bool reload=false)
virtual void setModel(QAbstractItemModel *)
KAction * emailAlarmAction() const
static AkonadiModel * instance()
void selectEvent(const QString &eventID)
static const QString UI_FILE
static const char * WINDOW_NAME
static MainWindow * create(bool restored=false)
KAction * audioAlarmAction() const
static bool canDecode(const QMimeData *md)
static const char * SHOW_ARCHIVED_KEY
virtual void readProperties(const KConfigGroup &)
static bool undo(QWidget *parent, const QString &action)
This class provides a view of alarm calendar resources.
static MainWindow * toggleWindow(MainWindow *)
static void connect(const char *signal, const QObject *receiver, const char *member)
static Akonadi::Collection::List enabledCollections(CalEvent::Type, bool writable)
Return the enabled collections which contain a specified mime type.
KAction * commandAlarmAction() const
static QString i18n_o_ShowTimeToAlarms()
static const QLatin1String CONFIRM_ALARM_DELETION
static const char * SHOW_TIME_KEY
Unique event identifier for Akonadi.
static int warningContinueCancel(QWidget *parent, ButtonCode defaultButton, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const QString &dontAskAgainName=QString())
static void saveReactivates(const EventList &, const QString &name=QString())
virtual bool eventFilter(QObject *, QEvent *)
static const char * VIEW_GROUP
static QColor defaultFgColour()
Get Foreground color.
void reload()
Reload all collections' data from Akonadi storage (not from the backend).
Akonadi::Collection collection(const KAEvent &e) const
static QString i18n_chk_ShowAlarmTime()
void initActions(KActionCollection *)
TrayWindow * trayWindow() const
static QString getMailHeader(const char *header, KMime::Content &content)
static void executeDropEvent(MainWindow *, QDropEvent *)
bool displayTrayIcon(bool show, MainWindow *=0)
static QString actionText(Type)
Provides read and write access to calendar files and resources.
void setStatusFilter(CalEvent::Types)
static bool exportAlarms(const KAEvent::List &, QWidget *parent)
quint32 serialNumber() const
KAEvent * event(const QString &uniqueId)
static bool confirmAlarmDeletion()
static KShortcut undoShortcut
static MainWindow * mainMainWindow()
void append(const KAEvent &e, AlarmResource *r)
void setContextMenu(KMenu *)
virtual void saveProperties(KConfigGroup &)
static const char * SHOW_RESOURCES_KEY
void doQuit(QWidget *parent)
static QString i18n_chk_ShowTimeToAlarm()
KAction * displayAlarmAction() const
KAEvent * selectedEvent() const
virtual void showEvent(QShowEvent *)