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>
90 #include <QDragEnterEvent>
92 #include <QResizeEvent>
93 #include <QCloseEvent>
94 #include <QDesktopWidget>
96 using namespace KAlarmCal;
141 MainWindow::MainWindow(
bool restored)
144 mHiddenTrayParent(false),
149 setAttribute(Qt::WA_DeleteOnClose);
150 setWindowModality(Qt::WindowModal);
152 setPlainCaption(KGlobal::mainComponent().aboutData()->programName());
153 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
160 KConfigGroup wconfig(KGlobal::config(),
WINDOW_NAME);
161 mResourcesWidth = wconfig.readEntry(
QString::fromLatin1(
"Splitter %1").arg(KApplication::desktop()->width()), (
int)0);
164 setAcceptDrops(
true);
168 mSplitter =
new QSplitter(Qt::Horizontal,
this);
171 setCentralWidget(mSplitter);
175 Akonadi::Control::widgetNeedsAkonadi(
this);
178 AlarmResources* resources = AlarmResources::instance();
184 connect(resources, SIGNAL(signalErrorMessage(
QString)), SLOT(showErrorMessage(
QString)));
190 mListFilterModel->setEventTypeFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
193 mListFilterModel->
setStatusFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
196 mListView->
setModel(mListFilterModel);
205 connect(mListView, SIGNAL(contextMenuRequested(
QPoint)), SLOT(slotContextMenuRequested(
QPoint)));
208 SLOT(slotCalendarStatusChanged()));
210 connect(resources, SIGNAL(resourceStatusChanged(AlarmResource*,AlarmResources::Change)),
211 SLOT(slotCalendarStatusChanged()));
213 connect(mResourceSelector, SIGNAL(resized(
QSize,
QSize)), SLOT(resourcesResized()));
219 if (mWindowList.
count() == 1)
224 else if (
theApp()->trayWindow())
227 slotCalendarStatusChanged();
237 delete mResourceSelector;
238 mResourceSelector = 0;
249 KGlobal::config()->sync();
259 config.writeEntry(
"HiddenTrayParent",
isTrayParent() && isHidden());
260 config.writeEntry(
"ShowArchived", mShowArchived);
261 config.writeEntry(
"ShowTime", mShowTime);
262 config.writeEntry(
"ShowTimeTo", mShowTimeTo);
263 config.writeEntry(
"ResourcesWidth", mResourceSelector->
isHidden() ? 0 : mResourceSelector->
width());
273 mHiddenTrayParent = config.readEntry(
"HiddenTrayParent",
true);
274 mShowArchived = config.readEntry(
"ShowArchived",
false);
275 mShowTime = config.readEntry(
"ShowTime",
true);
276 mShowTimeTo = config.readEntry(
"ShowTimeTo",
false);
277 mResourcesWidth = config.readEntry(
"ResourcesWidth", (
int)0);
278 mShowResources = (mResourcesWidth > 0);
289 if (tray && tray->isVisible())
291 for (
int i = 0, end = mWindowList.
count(); i < end; ++i)
292 if (mWindowList[i]->isVisible())
293 return mWindowList[i];
298 return mWindowList[0];
307 if (!tray || !KSystemTrayIcon::isSystemTrayAvailable())
311 return mWindowList.
count() == 1;
320 delete mWindowList[0];
328 if (obj == mSplitter)
345 else if (obj == mListView)
349 case QEvent::KeyPress:
352 if (ke->
key() == Qt::Key_Delete && ke->
modifiers() == Qt::ShiftModifier)
355 mActionDeleteForce->trigger();
376 MainWindowBase::resizeEvent(re);
377 if (mResourcesWidth > 0)
380 widths.
append(mResourcesWidth);
386 void MainWindow::resourcesResized()
388 if (!mShown || mResizing)
391 if (widths.
count() > 1)
393 mResourcesWidth = widths[0];
396 if (mResourcesWidth <= 5)
400 KConfigGroup config(KGlobal::config(),
WINDOW_NAME);
401 config.writeEntry(
QString::fromLatin1(
"Splitter %1").arg(KApplication::desktop()->width()), mResourcesWidth);
413 if (mResourcesWidth > 0)
416 widths.
append(mResourcesWidth);
420 MainWindowBase::showEvent(se);
429 MainWindowBase::show();
435 KAMessageBox::error(
this, i18nc(
"@info",
"Failure to create menus (perhaps <filename>%1</filename> missing or corrupted)",
UI_FILE));
445 MainWindowBase::hideEvent(he);
451 void MainWindow::initActions()
454 KActionCollection* actions = actionCollection();
456 mActionTemplates =
new KAction(i18nc(
"@action",
"&Templates..."),
this);
457 actions->addAction(
QLatin1String(
"templates"), mActionTemplates);
458 connect(mActionTemplates, SIGNAL(triggered(
bool)), SLOT(slotTemplates()));
460 mActionNew =
new NewAlarmAction(
false, i18nc(
"@action",
"&New"),
this);
465 action->setGlobalShortcut(dummy);
466 connect(action, SIGNAL(triggered(
bool)), SLOT(slotNewDisplay()));
470 action->setGlobalShortcut(dummy);
471 connect(action, SIGNAL(triggered(
bool)), SLOT(slotNewCommand()));
475 action->setGlobalShortcut(dummy);
476 connect(action, SIGNAL(triggered(
bool)), SLOT(slotNewEmail()));
480 action->setGlobalShortcut(dummy);
481 connect(action, SIGNAL(triggered(
bool)), SLOT(slotNewAudio()));
484 actions->addAction(
QLatin1String(
"newFromTemplate"), action);
485 connect(action, SIGNAL(selected(
const KAEvent*)), SLOT(slotNewFromTemplate(
const KAEvent*)));
487 mActionCreateTemplate =
new KAction(i18nc(
"@action",
"Create Tem&plate..."),
this);
488 actions->addAction(
QLatin1String(
"createTemplate"), mActionCreateTemplate);
489 connect(mActionCreateTemplate, SIGNAL(triggered(
bool)), SLOT(slotNewTemplate()));
491 mActionCopy =
new KAction(KIcon(
QLatin1String(
"edit-copy")), i18nc(
"@action",
"&Copy..."),
this);
493 mActionCopy->setShortcut(
QKeySequence(Qt::SHIFT + Qt::Key_Insert));
494 connect(mActionCopy, SIGNAL(triggered(
bool)), SLOT(slotCopy()));
496 mActionModify =
new KAction(KIcon(
QLatin1String(
"document-properties")), i18nc(
"@action",
"&Edit..."),
this);
498 mActionModify->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_E));
499 connect(mActionModify, SIGNAL(triggered(
bool)), SLOT(slotModify()));
501 mActionDelete =
new KAction(KIcon(
QLatin1String(
"edit-delete")), i18nc(
"@action",
"&Delete"),
this);
503 mActionDelete->setShortcut(QKeySequence::Delete);
504 connect(mActionDelete, SIGNAL(triggered(
bool)), SLOT(slotDeleteIf()));
507 mActionDeleteForce =
new KAction(i18nc(
"@action",
"Delete Without Confirmation"),
this);
508 actions->addAction(
QLatin1String(
"delete-force"), mActionDeleteForce);
509 mActionDeleteForce->setShortcut(QKeySequence::Delete + Qt::SHIFT);
510 connect(mActionDeleteForce, SIGNAL(triggered(
bool)), SLOT(slotDeleteForce()));
512 mActionReactivate =
new KAction(i18nc(
"@action",
"Reac&tivate"),
this);
513 actions->addAction(
QLatin1String(
"undelete"), mActionReactivate);
514 mActionReactivate->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_R));
515 connect(mActionReactivate, SIGNAL(triggered(
bool)), SLOT(slotReactivate()));
517 mActionEnable =
new KAction(
this);
519 mActionEnable->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_B));
520 connect(mActionEnable, SIGNAL(triggered(
bool)), SLOT(slotEnable()));
522 action =
new KAction(i18nc(
"@action",
"Wake From Suspend..."),
this);
524 connect(action, SIGNAL(triggered(
bool)), SLOT(slotWakeFromSuspend()));
526 action = KAlarm::createStopPlayAction(
this);
528 action->setGlobalShortcut(dummy);
531 actions->addAction(
QLatin1String(
"showAlarmTimes"), mActionShowTime);
532 connect(mActionShowTime, SIGNAL(triggered(
bool)), SLOT(slotShowTime()));
535 actions->addAction(
QLatin1String(
"showTimeToAlarms"), mActionShowTimeTo);
536 mActionShowTimeTo->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_I));
537 connect(mActionShowTimeTo, SIGNAL(triggered(
bool)), SLOT(slotShowTimeTo()));
539 mActionShowArchived =
new KToggleAction(i18nc(
"@action",
"Show Archi&ved Alarms"),
this);
540 actions->addAction(
QLatin1String(
"showArchivedAlarms"), mActionShowArchived);
541 mActionShowArchived->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_P));
542 connect(mActionShowArchived, SIGNAL(triggered(
bool)), SLOT(slotShowArchived()));
544 mActionToggleTrayIcon =
new KToggleAction(i18nc(
"@action",
"Show in System &Tray"),
this);
545 actions->addAction(
QLatin1String(
"showInSystemTray"), mActionToggleTrayIcon);
546 connect(mActionToggleTrayIcon, SIGNAL(triggered(
bool)), SLOT(slotToggleTrayIcon()));
548 mActionToggleResourceSel =
new KToggleAction(KIcon(
QLatin1String(
"view-choose")), i18nc(
"@action",
"Show &Calendars"),
this);
549 actions->addAction(
QLatin1String(
"showResources"), mActionToggleResourceSel);
550 connect(mActionToggleResourceSel, SIGNAL(triggered(
bool)), SLOT(slotToggleResourceSelector()));
552 mActionSpreadWindows = KAlarm::createSpreadWindowsAction(
this);
553 actions->addAction(
QLatin1String(
"spread"), mActionSpreadWindows);
554 mActionSpreadWindows->setGlobalShortcut(dummy);
556 mActionImportAlarms =
new KAction(i18nc(
"@action",
"Import &Alarms..."),
this);
557 actions->addAction(
QLatin1String(
"importAlarms"), mActionImportAlarms);
558 connect(mActionImportAlarms, SIGNAL(triggered(
bool)), SLOT(slotImportAlarms()));
560 mActionImportBirthdays =
new KAction(i18nc(
"@action",
"Import &Birthdays..."),
this);
561 actions->addAction(
QLatin1String(
"importBirthdays"), mActionImportBirthdays);
562 connect(mActionImportBirthdays, SIGNAL(triggered(
bool)), SLOT(slotBirthdays()));
564 mActionExportAlarms =
new KAction(i18nc(
"@action",
"E&xport Selected Alarms..."),
this);
565 actions->addAction(
QLatin1String(
"exportAlarms"), mActionExportAlarms);
566 connect(mActionExportAlarms, SIGNAL(triggered(
bool)), SLOT(slotExportAlarms()));
568 mActionExport =
new KAction(i18nc(
"@action",
"E&xport..."),
this);
570 connect(mActionExport, SIGNAL(triggered(
bool)), SLOT(slotExportAlarms()));
572 action =
new KAction(KIcon(
QLatin1String(
"view-refresh")), i18nc(
"@action",
"&Refresh Alarms"),
this);
574 connect(action, SIGNAL(triggered(
bool)), SLOT(slotRefreshAlarms()));
576 action = KAlarm::createAlarmEnableAction(
this);
581 QAction * act = KStandardAction::undo(
this, 0, actions);
586 act = KStandardAction::redo(
this, 0, actions);
592 mActionUndo =
new KToolBarPopupAction(KIcon(
QLatin1String(
"edit-undo")), undoText,
this);
595 connect(mActionUndo, SIGNAL(triggered(
bool)), SLOT(slotUndo()));
597 mActionRedo =
new KToolBarPopupAction(KIcon(
QLatin1String(
"edit-redo")), redoText,
this);
600 connect(mActionRedo, SIGNAL(triggered(
bool)), SLOT(slotRedo()));
602 KStandardAction::find(mListView, SLOT(slotFind()), actions);
603 mActionFindNext = KStandardAction::findNext(mListView, SLOT(slotFindNext()), actions);
604 mActionFindPrev = KStandardAction::findPrev(mListView, SLOT(slotFindPrev()), actions);
605 KStandardAction::selectAll(mListView, SLOT(selectAll()), actions);
606 KStandardAction::deselect(mListView, SLOT(
clearSelection()), actions);
609 KAction* act = KStandardAction::quit(0, 0, actions);
610 connect(act, SIGNAL(triggered(
bool)), SLOT(slotQuit()), Qt::QueuedConnection);
611 KStandardAction::keyBindings(
this, SLOT(slotConfigureKeys()), actions);
612 KStandardAction::configureToolbars(
this, SLOT(slotConfigureToolbar()), actions);
613 KStandardAction::preferences(
this, SLOT(slotPreferences()), actions);
615 setStandardToolBarMenuEnabled(
true);
618 applyMainWindowSettings(KGlobal::config()->group(
WINDOW_NAME));
620 mContextMenu =
static_cast<KMenu*
>(factory()->container(
QLatin1String(
"listContext"),
this));
621 mActionsMenu =
static_cast<KMenu*
>(factory()->container(
QLatin1String(
"actions"),
this));
622 KMenu* resourceMenu =
static_cast<KMenu*
>(factory()->container(
QLatin1String(
"resourceContext"),
this));
624 mMenuError = (!mContextMenu || !mActionsMenu || !resourceMenu);
625 connect(mActionUndo->menu(), SIGNAL(aboutToShow()), SLOT(slotInitUndoMenu()));
626 connect(mActionUndo->menu(), SIGNAL(triggered(
QAction*)), SLOT(slotUndoItem(
QAction*)));
627 connect(mActionRedo->menu(), SIGNAL(aboutToShow()), SLOT(slotInitRedoMenu()));
628 connect(mActionRedo->menu(), SIGNAL(triggered(
QAction*)), SLOT(slotRedoItem(
QAction*)));
630 connect(mListView, SIGNAL(findActive(
bool)), SLOT(slotFindActive(
bool)));
631 Preferences::connect(SIGNAL(archivedKeepDaysChanged(
int)),
this, SLOT(updateKeepArchived(
int)));
632 Preferences::connect(SIGNAL(showInSystemTrayChanged(
bool)),
this, SLOT(updateTrayIconAction()));
633 connect(
theApp(), SIGNAL(trayIconToggled()), SLOT(updateTrayIconAction()));
637 mActionShowTime->setChecked(mShowTime);
638 mActionShowTimeTo->setChecked(mShowTimeTo);
639 mActionShowArchived->setChecked(mShowArchived);
640 if (!Preferences::archivedKeepDays())
641 mActionShowArchived->setEnabled(
false);
642 mActionToggleResourceSel->setChecked(mShowResources);
643 slotToggleResourceSelector();
644 updateTrayIconAction();
647 mActionFindNext->setEnabled(
false);
648 mActionFindPrev->setEnabled(
false);
650 mActionCopy->setEnabled(
false);
651 mActionModify->setEnabled(
false);
652 mActionDelete->setEnabled(
false);
653 mActionReactivate->setEnabled(
false);
654 mActionEnable->setEnabled(
false);
655 mActionCreateTemplate->setEnabled(
false);
656 mActionExport->setEnabled(
false);
665 void MainWindow::enableTemplateMenuItem(
bool enable)
667 for (
int i = 0, end = mWindowList.
count(); i < end; ++i)
668 mWindowList[i]->mActionTemplates->setEnabled(enable);
688 void MainWindow::updateKeepArchived(
int days)
690 kDebug() << (bool)days;
691 if (mShowArchived && !days)
693 mActionShowArchived->setEnabled(days);
705 mListView->clearSelection();
707 QModelIndex index = mListFilterModel->eventIndex(eventId);
710 mListView->select(index);
711 mListView->scrollTo(index);
714 mListView->select(eventId,
true);
727 return mListView->selectedEvent();
743 KAlarm::editNewAlarm(type, mListView);
750 void MainWindow::slotNewFromTemplate(
const KAEvent* tmplate)
752 KAlarm::editNewAlarm(tmplate, mListView);
759 void MainWindow::slotNewTemplate()
764 KAlarm::editNewTemplate(&event,
this);
768 KAlarm::editNewTemplate(event,
this);
776 void MainWindow::slotCopy()
781 KAlarm::editNewAlarm(&event,
this);
785 KAlarm::editNewAlarm(event,
this);
793 void MainWindow::slotModify()
798 KAlarm::editAlarm(&event,
this);
802 KAlarm::editAlarm(event,
this);
810 void MainWindow::slotDelete(
bool force)
820 for (
int i = 0, end = events.count(); i < end; ++i)
821 ids.
append(events[i]->id());
826 int n = events.count();
828 "Do you really want to delete the %1 selected alarms?", n),
829 i18ncp(
"@title:window",
"Delete Alarm",
"Delete Alarms", n),
830 KGuiItem(i18nc(
"@action:button",
"&Delete"),
QLatin1String(
"edit-delete")),
831 KStandardGuiItem::cancel(),
833 != KMessageBox::Continue)
841 for (
int i = 0; i < events.count(); )
843 Akonadi::Collection c = resources->collectionForEvent(events[i].itemId());
847 undos.
append(events[i++], c);
850 for (
int i = 0, e = 0, end = ids.
count(); i < end; ++i)
856 undos.
append(*events[e++], r);
860 if (events.isEmpty())
861 kDebug() <<
"No alarms left to delete";
865 KAlarm::deleteEvents(events,
true,
this);
874 void MainWindow::slotReactivate()
887 KAlarm::reactivateEvents(events, ineligibleIDs, 0,
this);
890 KAlarm::reactivateEvents(events, ineligibleIDs, 0,
this);
895 for (
int i = 0, end = events.count(); i < end; ++i)
900 undos.
append(events[i], resources->collectionForEvent(events[i].itemId()));
915 void MainWindow::slotEnable()
917 bool enable = mActionEnableEnable;
923 KAEvent::List eventCopies;
925 for (
int i = 0, end = events.count(); i < end; ++i)
926 eventCopies += events[i];
927 KAlarm::enableEvents(eventCopies, enable,
this);
934 void MainWindow::slotShowTime()
936 mShowTime = !mShowTime;
937 mActionShowTime->setChecked(mShowTime);
938 if (!mShowTime && !mShowTimeTo)
943 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
952 void MainWindow::slotShowTimeTo()
954 mShowTimeTo = !mShowTimeTo;
955 mActionShowTimeTo->setChecked(mShowTimeTo);
956 if (!mShowTimeTo && !mShowTime)
961 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
970 void MainWindow::slotShowArchived()
972 mShowArchived = !mShowArchived;
973 mActionShowArchived->setChecked(mShowArchived);
974 mActionShowArchived->setToolTip(mShowArchived ? i18nc(
"@info:tooltip",
"Hide Archived Alarms")
975 : i18nc(
"@info:tooltip",
"Show Archived Alarms"));
977 mListFilterModel->setEventTypeFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
979 mListFilterModel->
setStatusFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
982 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
990 void MainWindow::slotSpreadWindowsShortcut()
992 mActionSpreadWindows->trigger();
998 void MainWindow::slotWakeFromSuspend()
1007 void MainWindow::slotImportAlarms()
1016 void MainWindow::slotExportAlarms()
1022 KAEvent::List evts = KAEvent::ptrList(events);
1027 if (!events.isEmpty())
1036 void MainWindow::slotBirthdays()
1042 if (dlg->exec() == QDialog::Accepted)
1053 for (
int i = 0, end = events.
count(); i < end; ++i)
1056 Akonadi::Collection c = resources->collectionForEvent(events[i].itemId());
1057 undos.
append(events[i], c);
1064 if (status != KAlarm::UPDATE_FAILED)
1065 KAlarm::outputAlarmWarnings(dlg);
1074 void MainWindow::slotTemplates()
1079 enableTemplateMenuItem(
false);
1080 connect(mTemplateDlg, SIGNAL(finished()), SLOT(slotTemplatesEnd()));
1081 mTemplateDlg->show();
1088 void MainWindow::slotTemplatesEnd()
1092 mTemplateDlg->delayedDestruct();
1094 enableTemplateMenuItem(
true);
1101 void MainWindow::slotToggleTrayIcon()
1109 void MainWindow::slotToggleResourceSelector()
1111 mShowResources = mActionToggleResourceSel->isChecked();
1114 if (mResourcesWidth <= 0)
1117 mResourceSelector->
resize(mResourcesWidth, mResourceSelector->
height());
1119 if (widths.
count() == 1)
1121 int listwidth = widths[0] - mSplitter->
handleWidth() - mResourcesWidth;
1123 widths.
append(listwidth);
1124 widths[0] = mResourcesWidth;
1128 mResourceSelector->
show();
1131 mResourceSelector->
hide();
1133 KConfigGroup config(KGlobal::config(),
VIEW_GROUP);
1140 void MainWindow::showErrorMessage(
const QString& msg)
1150 void MainWindow::updateTrayIconAction()
1152 mActionToggleTrayIcon->setEnabled(KSystemTrayIcon::isSystemTrayAvailable());
1153 mActionToggleTrayIcon->setChecked(
theApp()->trayIconDisplayed());
1159 void MainWindow::slotFindActive(
bool active)
1161 mActionFindNext->setEnabled(active);
1162 mActionFindPrev->setEnabled(active);
1168 void MainWindow::slotUndo()
1170 Undo::undo(
this, KGlobal::locale()->removeAcceleratorMarker(mActionUndo->text()));
1176 void MainWindow::slotRedo()
1178 Undo::redo(
this, KGlobal::locale()->removeAcceleratorMarker(mActionRedo->text()));
1184 void MainWindow::slotUndoItem(
QAction* action)
1186 int id = mUndoMenuIds[action];
1193 void MainWindow::slotRedoItem(
QAction* action)
1195 int id = mUndoMenuIds[action];
1203 void MainWindow::slotInitUndoMenu()
1205 initUndoMenu(mActionUndo->menu(),
Undo::UNDO);
1212 void MainWindow::slotInitRedoMenu()
1214 initUndoMenu(mActionRedo->menu(),
Undo::REDO);
1223 mUndoMenuIds.
clear();
1226 for (
int i = 0, end = ids.
count(); i < end; ++i)
1232 ? i18nc(
"@action Undo/Redo [action]",
"%1 %2", action, actText)
1233 : i18nc(
"@action Undo [action]: message",
"%1 %2: %3", action, actText, descrip);
1235 mUndoMenuIds[act] = id;
1243 void MainWindow::slotUndoStatus(
const QString& undo,
const QString& redo)
1247 mActionUndo->setEnabled(
false);
1248 mActionUndo->setText(undoText);
1252 mActionUndo->setEnabled(
true);
1257 mActionRedo->setEnabled(
false);
1258 mActionRedo->setText(redoText);
1262 mActionRedo->setEnabled(
true);
1270 void MainWindow::slotRefreshAlarms()
1272 KAlarm::refreshAlarms();
1278 void MainWindow::slotPreferences()
1286 void MainWindow::slotConfigureKeys()
1288 KShortcutsDialog::configure(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed,
this);
1294 void MainWindow::slotConfigureToolbar()
1296 saveMainWindowSettings(KGlobal::config()->group(
WINDOW_NAME));
1297 KEditToolBar dlg(factory());
1298 connect(&dlg, SIGNAL(newToolBarConfig()),
this, SLOT(slotNewToolbarConfig()));
1306 void MainWindow::slotNewToolbarConfig()
1309 applyMainWindowSettings(KGlobal::config()->group(
WINDOW_NAME));
1318 void MainWindow::slotQuit()
1328 if (!
theApp()->sessionClosingDown())
1370 KMime::Headers::Base* hd = content.headerByType(header);
1371 return hd ? hd->asUnicodeString() :
QString();
1382 KAEvent::SubAction action = KAEvent::MESSAGE;
1384 AlarmText alarmText;
1404 kDebug() <<
"email";
1405 KMime::Content content;
1406 content.setContent(bytes);
1409 if (content.textContent())
1410 body = content.textContent()->decodedText(
true,
true);
1411 unsigned long sernum = 0;
1427 #ifdef KMAIL_SUPPORTED
1432 kDebug() <<
"KMail_list";
1440 KGlobal::locale()->formatDateTime(dt), summary.
subject(),
1451 kDebug() <<
"iCalendar";
1453 Event::List events = calendar->rawEvents();
1455 Event::List events = calendar.rawEvents();
1457 if (!events.isEmpty())
1459 KAEvent ev(events[0]);
1460 KAlarm::editNewAlarm(&ev, win);
1465 Todo::List todos = calendar->rawTodos();
1467 Todo::List todos = calendar.rawTodos();
1469 if (todos.isEmpty())
1472 Todo::Ptr todo = todos[0];
1474 Todo* todo = todos[0];
1476 alarmText.setTodo(todo);
1477 KDateTime start = todo->dtStart(
true);
1478 if (!start.isValid() && todo->hasDueDate())
1479 start = todo->dtDue(
true);
1480 KAEvent::Flags flags = KAEvent::DEFAULT_FONT;
1481 if (start.isDateOnly())
1482 flags |= KAEvent::ANY_TIME;
1483 KAEvent ev(start, alarmText.displayText(), Preferences::defaultBgColour(), Preferences::defaultFgColour(),
1484 QFont(), KAEvent::MESSAGE, 0, flags,
true);
1487 ev.setRecurrence(*todo->recurrence());
1488 ev.setNextOccurrence(KDateTime::currentUtcDateTime());
1491 KAlarm::editNewAlarm(&ev, win);
1498 KMimeType::Ptr mimeType = KMimeType::findByUrl(files[0]);
1499 action = mimeType->name().startsWith(
QLatin1String(
"audio/")) ? KAEvent::AUDIO : KAEvent::FILE;
1500 alarmText.setText(files[0].prettyUrl());
1506 alarmText.setText(text);
1511 if (!alarmText.isEmpty())
1513 if (action == KAEvent::MESSAGE
1514 && (alarmText.isEmail() || alarmText.isScript()))
1519 types += i18nc(
"@item:inlistbox",
"Display Alarm");
1520 if (alarmText.isEmail())
1521 types += i18nc(
"@item:inlistbox",
"Email Alarm");
1522 else if (alarmText.isScript())
1523 types += i18nc(
"@item:inlistbox",
"Command Alarm");
1525 QString type = KInputDialog::getItem(i18nc(
"@title:window",
"Alarm Type"),
1526 i18nc(
"@info",
"Choose alarm type to create:"), types, 0,
false, &ok,
mainMainWindow());
1531 action = alarmText.isEmail() ? KAEvent::EMAIL : KAEvent::COMMAND;
1533 KAlarm::editNewAlarm(action, win, &alarmText);
1541 void MainWindow::slotCalendarStatusChanged()
1548 AlarmResources* resources = AlarmResources::instance();
1549 bool active = resources->activeCount(CalEvent::ACTIVE,
true);
1550 bool templat = resources->activeCount(CalEvent::TEMPLATE,
true);
1552 for (
int i = 0, end = mWindowList.
count(); i < end; ++i)
1555 w->mActionImportAlarms->setEnabled(active || templat);
1556 w->mActionImportBirthdays->setEnabled(active);
1557 w->mActionCreateTemplate->setEnabled(templat);
1567 void MainWindow::slotSelection()
1575 int count = events.count();
1584 bool active = mActionNew->isEnabled();
1586 bool readOnly =
false;
1587 bool allArchived =
true;
1588 bool enableReactivate =
true;
1589 bool enableEnableDisable =
true;
1590 bool enableEnable =
false;
1591 bool enableDisable =
false;
1593 KDateTime now = KDateTime::currentUtcDateTime();
1594 for (
int i = 0; i <
count; ++i)
1598 KAEvent*
event = ev ? ev : &events[i];
1600 KAEvent*
event = events[i];
1602 bool expired =
event->expired();
1604 allArchived =
false;
1611 if (enableReactivate
1612 && (!expired || !event->occursAfter(now,
true)))
1613 enableReactivate =
false;
1614 if (enableEnableDisable)
1617 enableEnableDisable = enableEnable = enableDisable =
false;
1620 if (!enableEnable && !event->enabled())
1621 enableEnable =
true;
1622 if (!enableDisable && event->enabled())
1623 enableDisable =
true;
1632 mActionCreateTemplate->setEnabled((count == 1) && (AlarmResources::instance()->activeCount(CalEvent::TEMPLATE,
true) > 0));
1634 mActionExportAlarms->setEnabled(
true);
1635 mActionExport->setEnabled(
true);
1636 mActionCopy->setEnabled(active && count == 1);
1637 mActionModify->setEnabled(count == 1);
1638 mActionDelete->setEnabled(!readOnly && (active || allArchived));
1639 mActionReactivate->setEnabled(active && enableReactivate);
1640 mActionEnable->setEnabled(active && !readOnly && (enableEnable || enableDisable));
1641 if (enableEnable || enableDisable)
1642 setEnableText(enableEnable);
1651 void MainWindow::slotContextMenuRequested(
const QPoint& globalPos)
1655 mContextMenu->popup(globalPos);
1661 void MainWindow::selectionCleared()
1663 mActionCreateTemplate->setEnabled(
false);
1664 mActionExportAlarms->setEnabled(
false);
1665 mActionExport->setEnabled(
false);
1666 mActionCopy->setEnabled(
false);
1667 mActionModify->setEnabled(
false);
1668 mActionDelete->setEnabled(
false);
1669 mActionReactivate->setEnabled(
false);
1670 mActionEnable->setEnabled(
false);
1676 void MainWindow::setEnableText(
bool enable)
1678 mActionEnableEnable = enable;
1679 mActionEnable->setText(enable ? i18nc(
"@action",
"Ena&ble") : i18nc(
"@action",
"Disa&ble"));
1688 if (win && mWindowList.
indexOf(win) != -1)
1691 if (win->isVisible())
1701 win->setWindowState(win->windowState() & ~Qt::WindowMinimized);
1703 win->activateWindow();
1727 mEditAlarmMap[dlg] = event;
1730 ev.setResource(resource);
1731 mEditAlarmMap[dlg] = ev;
1733 connect(dlg, SIGNAL(accepted()), SLOT(editAlarmOk()));
1734 connect(dlg, SIGNAL(destroyed(
QObject*)), SLOT(editAlarmDeleted(
QObject*)));
1735 dlg->setAttribute(Qt::WA_DeleteOnClose,
true);
1743 void MainWindow::editAlarmOk()
1749 if (it == mEditAlarmMap.
end())
1751 KAEvent
event = it.
value();
1752 mEditAlarmMap.
erase(it);
1753 if (!event.isValid())
1755 if (dlg->result() != QDialog::Accepted)
1759 KAlarm::updateEditedAlarm(dlg, event, c);
1761 KAlarm::updateEditedAlarm(dlg, event, event.resource());
1769 void MainWindow::editAlarmDeleted(
QObject* obj)
1771 mEditAlarmMap.
remove(static_cast<EditAlarmDlg*>(obj));
static void emitChanged()
Qt::KeyboardModifiers modifiers() const
virtual void dropEvent(QDropEvent *)
static const char * SHOW_TIME_TO_KEY
QByteArray data(const QString &mimeType) const
KAEvent * selectedEvent() const
virtual void hideEvent(QHideEvent *)
iterator erase(iterator pos)
static bool redo(QWidget *parent, const QString &action)
void setSizes(const QList< int > &list)
static EventListModel * alarms()
void selectTimeColumns(bool time, bool timeTo)
const QMimeData * mimeData() const
static bool importAlarms(QWidget *, AlarmResource *=0)
QItemSelectionModel * selectionModel() const
void setStretchFactor(int index, int stretch)
bool eventReadOnly(const QString &uniqueID) const
virtual QByteArray text(quint32 serialNumber) const =0
static void executeDragEnterEvent(QDragEnterEvent *)
Result of calendar update.
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))
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QList< QKeySequence > shortcuts() const
static KShortcut redoShortcut
static QString redoTextStripped
static QString description(Type, int id)
MainWindow * assocMainWindow() const
TemplateMenuAction * fromTemplateAlarmAction() const
QString join(const QString &separator) const
void sortByColumn(int column, Qt::SortOrder order)
AlarmResource * resourceForEvent(const QString &eventID) const
void acceptProposedAction()
virtual QSize sizeHint() 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 QString i18n_a_ShowAlarmTimes()
int indexOf(const T &value, int from) const
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 *)
int count(const T &value) const
static MailList fromMimeData(const QMimeData *md)
void append(const T &value)
QList< int > sizes() const
static QList< int > ids(Type)
void installEventFilter(QObject *filterObj)
void setChildrenCollapsible(bool)
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)
void setItemDelegate(QAbstractItemDelegate *delegate)
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
QVector< KAEvent > events() const
static const char * SHOW_TIME_KEY
Unique event identifier for Akonadi.
static void saveReactivates(const EventList &, const QString &name=QString())
virtual bool eventFilter(QObject *, QEvent *)
static const char * VIEW_GROUP
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 *)
int count(const T &value) const
bool displayTrayIcon(bool show, MainWindow *=0)
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Options(Notify|WindowModal))
QString fromLatin1(const char *str, int size)
static QString actionText(Type)
Provides read and write access to calendar files and resources.
int indexOf(const QRegExp &rx, int from) const
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 &)
iterator find(const Key &key)
static const char * SHOW_RESOURCES_KEY
void doQuit(QWidget *parent)
static QString i18n_chk_ShowTimeToAlarm()
KAction * displayAlarmAction() const
void setTime_t(uint seconds)
KAEvent * selectedEvent() const
const T value(const Key &key) const
int remove(const Key &key)
virtual void showEvent(QShowEvent *)