• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.12
  • kdepim
  • kalarm
mainwindow.cpp
Go to the documentation of this file.
1 /*
2  * mainwindow.cpp - main application window
3  * Program: kalarm
4  * Copyright © 2001-2012 by David Jarvie <djarvie@kde.org>
5  *
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
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 #include "mainwindow.moc"
23 
24 #include "alarmcalendar.h"
25 #include "alarmlistdelegate.h"
26 #include "autoqpointer.h"
27 #include "alarmlistview.h"
28 #ifndef USE_AKONADI
29 #include "alarmlistfiltermodel.h"
30 #include "alarmresources.h"
31 #include "eventlistmodel.h"
32 #endif
33 #include "birthdaydlg.h"
34 #include "functions.h"
35 #include "kalarmapp.h"
36 #include "kamail.h"
37 #include "messagebox.h"
38 #include "newalarmaction.h"
39 #include "prefdlg.h"
40 #include "preferences.h"
41 #include "resourceselector.h"
42 #include "synchtimer.h"
43 #include "templatedlg.h"
44 #include "templatemenuaction.h"
45 #include "templatepickdlg.h"
46 #include "traywindow.h"
47 #include "wakedlg.h"
48 
49 #include <kalarmcal/alarmtext.h>
50 #include <kalarmcal/kaevent.h>
51 
52 #include <libkdepim/misc/maillistdrag.h>
53 #include <kmime/kmime_content.h>
54 #ifdef USE_AKONADI
55 #include <kcalcore/memorycalendar.h>
56 #include <kcalutils/icaldrag.h>
57 #include <akonadi/control.h>
58 using namespace KCalCore;
59 using namespace KCalUtils;
60 #else
61 #include <kcal/calendarlocal.h>
62 #include <kcal/icaldrag.h>
63 using namespace KCal;
64 #endif
65 
66 #include <kmenubar.h>
67 #include <ktoolbar.h>
68 #include <kmenu.h>
69 #include <kaction.h>
70 #include <kactioncollection.h>
71 #include <kinputdialog.h>
72 #include <ksystemtrayicon.h>
73 #include <kstandardaction.h>
74 #include <kiconloader.h>
75 #include <kurl.h>
76 #include <klocale.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>
83 #include <kdebug.h>
84 #include <ktoggleaction.h>
85 #include <ktoolbarpopupaction.h>
86 #include <kicon.h>
87 
88 #include <QHeaderView>
89 #include <QSplitter>
90 #include <QByteArray>
91 #include <QDesktopWidget>
92 #include <QDragEnterEvent>
93 #include <QDropEvent>
94 #include <QResizeEvent>
95 #include <QCloseEvent>
96 #include <QTimer>
97 
98 using namespace KAlarmCal;
99 
100 static const QString UI_FILE = QLatin1String("kalarmui.rc");
101 static const char* WINDOW_NAME = "MainWindow";
102 
103 static const char* VIEW_GROUP = "View";
104 static const char* SHOW_TIME_KEY = "ShowAlarmTime";
105 static const char* SHOW_TIME_TO_KEY = "ShowTimeToAlarm";
106 static const char* SHOW_ARCHIVED_KEY = "ShowArchivedAlarms";
107 static const char* SHOW_RESOURCES_KEY = "ShowResources";
108 
109 static QString undoText;
110 static QString undoTextStripped;
111 static KShortcut undoShortcut;
112 static QString redoText;
113 static QString redoTextStripped;
114 static KShortcut redoShortcut;
115 
116 
117 /*=============================================================================
118 = Class: MainWindow
119 =============================================================================*/
120 
121 MainWindow::WindowList MainWindow::mWindowList;
122 TemplateDlg* MainWindow::mTemplateDlg = 0;
123 
124 // Collect these widget labels together to ensure consistent wording and
125 // translations across different modules.
126 QString MainWindow::i18n_a_ShowAlarmTimes() { return i18nc("@action", "Show &Alarm Times"); }
127 QString MainWindow::i18n_chk_ShowAlarmTime() { return i18nc("@option:check", "Show alarm time"); }
128 QString MainWindow::i18n_o_ShowTimeToAlarms() { return i18nc("@action", "Show Time t&o Alarms"); }
129 QString MainWindow::i18n_chk_ShowTimeToAlarm() { return i18nc("@option:check", "Show time until alarm"); }
130 
131 
132 /******************************************************************************
133 * Construct an instance.
134 * To avoid resize() events occurring while still opening the calendar (and
135 * resultant crashes), the calendar is opened before constructing the instance.
136 */
137 MainWindow* MainWindow::create(bool restored)
138 {
139  theApp()->checkCalendar(); // ensure calendar is open
140  return new MainWindow(restored);
141 }
142 
143 MainWindow::MainWindow(bool restored)
144  : MainWindowBase(0, Qt::WindowContextHelpButtonHint),
145  mResourcesWidth(-1),
146  mHiddenTrayParent(false),
147  mShown(false),
148  mResizing(false)
149 {
150  kDebug();
151  setAttribute(Qt::WA_DeleteOnClose);
152  setWindowModality(Qt::WindowModal);
153  setObjectName(QLatin1String("MainWin")); // used by LikeBack
154  setPlainCaption(KGlobal::mainComponent().aboutData()->programName());
155  KConfigGroup config(KGlobal::config(), VIEW_GROUP);
156  mShowResources = config.readEntry(SHOW_RESOURCES_KEY, false);
157  mShowArchived = config.readEntry(SHOW_ARCHIVED_KEY, false);
158  mShowTime = config.readEntry(SHOW_TIME_KEY, true);
159  mShowTimeTo = config.readEntry(SHOW_TIME_TO_KEY, false);
160  if (!restored)
161  {
162  KConfigGroup wconfig(KGlobal::config(), WINDOW_NAME);
163  mResourcesWidth = wconfig.readEntry(QString::fromLatin1("Splitter %1").arg(KApplication::desktop()->width()), (int)0);
164  }
165 
166  setAcceptDrops(true); // allow drag-and-drop onto this window
167  if (!mShowTimeTo)
168  mShowTime = true; // ensure at least one time column is visible
169 
170  mSplitter = new QSplitter(Qt::Horizontal, this);
171  mSplitter->setChildrenCollapsible(false);
172  mSplitter->installEventFilter(this);
173  setCentralWidget(mSplitter);
174 
175  // Create the calendar resource selector widget
176 #ifdef USE_AKONADI
177  Akonadi::Control::widgetNeedsAkonadi(this);
178  mResourceSelector = new ResourceSelector(mSplitter);
179 #else
180  AlarmResources* resources = AlarmResources::instance();
181  mResourceSelector = new ResourceSelector(resources, mSplitter);
182 #endif
183  mSplitter->setStretchFactor(0, 0); // don't resize resource selector when window is resized
184  mSplitter->setStretchFactor(1, 1);
185 #ifndef USE_AKONADI
186  connect(resources, SIGNAL(signalErrorMessage(QString)), SLOT(showErrorMessage(QString)));
187 #endif
188 
189  // Create the alarm list widget
190 #ifdef USE_AKONADI
191  mListFilterModel = new AlarmListModel(this);
192  mListFilterModel->setEventTypeFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
193 #else
194  mListFilterModel = new AlarmListFilterModel(EventListModel::alarms(), this);
195  mListFilterModel->setStatusFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
196 #endif
197  mListView = new AlarmListView(WINDOW_NAME, mSplitter);
198  mListView->setModel(mListFilterModel);
199  mListView->selectTimeColumns(mShowTime, mShowTimeTo);
200 #ifdef USE_AKONADI
201  mListView->sortByColumn(mShowTime ? AlarmListModel::TimeColumn : AlarmListModel::TimeToColumn, Qt::AscendingOrder);
202 #else
203  mListView->sortByColumn(mShowTime ? EventListModel::TimeColumn : EventListModel::TimeToColumn, Qt::AscendingOrder);
204 #endif
205  mListView->setItemDelegate(new AlarmListDelegate(mListView));
206  connect(mListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(slotSelection()));
207  connect(mListView, SIGNAL(contextMenuRequested(QPoint)), SLOT(slotContextMenuRequested(QPoint)));
208 #ifdef USE_AKONADI
209  connect(AkonadiModel::instance(), SIGNAL(collectionStatusChanged(Akonadi::Collection,AkonadiModel::Change,QVariant,bool)),
210  SLOT(slotCalendarStatusChanged()));
211 #else
212  connect(resources, SIGNAL(resourceStatusChanged(AlarmResource*,AlarmResources::Change)),
213  SLOT(slotCalendarStatusChanged()));
214 #endif
215  connect(mResourceSelector, SIGNAL(resized(QSize,QSize)), SLOT(resourcesResized()));
216  mListView->installEventFilter(this);
217  initActions();
218 
219  setAutoSaveSettings(QLatin1String(WINDOW_NAME), true); // save toolbars, window sizes etc.
220  mWindowList.append(this);
221  if (mWindowList.count() == 1)
222  {
223  // It's the first main window
224  if (theApp()->wantShowInSystemTray())
225  theApp()->displayTrayIcon(true, this); // create system tray icon for run-in-system-tray mode
226  else if (theApp()->trayWindow())
227  theApp()->trayWindow()->setAssocMainWindow(this); // associate this window with the system tray icon
228  }
229  slotCalendarStatusChanged(); // initialise action states now that window is registered
230 }
231 
232 MainWindow::~MainWindow()
233 {
234  kDebug();
235  bool trayParent = isTrayParent(); // must call before removing from window list
236  mWindowList.removeAt(mWindowList.indexOf(this));
237 
238  // Prevent view updates during window destruction
239  delete mResourceSelector;
240  mResourceSelector = 0;
241  delete mListView;
242  mListView = 0;
243 
244  if (theApp()->trayWindow())
245  {
246  if (trayParent)
247  delete theApp()->trayWindow();
248  else
249  theApp()->trayWindow()->removeWindow(this);
250  }
251  KGlobal::config()->sync(); // save any new window size to disc
252  theApp()->quitIf();
253 }
254 
255 /******************************************************************************
256 * Save settings to the session managed config file, for restoration
257 * when the program is restored.
258 */
259 void MainWindow::saveProperties(KConfigGroup& config)
260 {
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());
266 }
267 
268 /******************************************************************************
269 * Read settings from the session managed config file.
270 * This function is automatically called whenever the app is being
271 * restored. Read in whatever was saved in saveProperties().
272 */
273 void MainWindow::readProperties(const KConfigGroup& config)
274 {
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);
281 }
282 
283 /******************************************************************************
284 * Get the main main window, i.e. the parent of the system tray icon, or if
285 * none, the first main window to be created. Visible windows take precedence
286 * over hidden ones.
287 */
288 MainWindow* MainWindow::mainMainWindow()
289 {
290  MainWindow* tray = theApp()->trayWindow() ? theApp()->trayWindow()->assocMainWindow() : 0;
291  if (tray && tray->isVisible())
292  return tray;
293  for (int i = 0, end = mWindowList.count(); i < end; ++i)
294  if (mWindowList[i]->isVisible())
295  return mWindowList[i];
296  if (tray)
297  return tray;
298  if (mWindowList.isEmpty())
299  return 0;
300  return mWindowList[0];
301 }
302 
303 /******************************************************************************
304 * Check whether this main window is effectively the parent of the system tray icon.
305 */
306 bool MainWindow::isTrayParent() const
307 {
308  TrayWindow* tray = theApp()->trayWindow();
309  if (!tray || !KSystemTrayIcon::isSystemTrayAvailable())
310  return false;
311  if (tray->assocMainWindow() == this)
312  return true;
313  return mWindowList.count() == 1;
314 }
315 
316 /******************************************************************************
317 * Close all main windows.
318 */
319 void MainWindow::closeAll()
320 {
321  while (!mWindowList.isEmpty())
322  delete mWindowList[0]; // N.B. the destructor removes the window from the list
323 }
324 
325 /******************************************************************************
326 * Intercept events for the splitter widget.
327 */
328 bool MainWindow::eventFilter(QObject* obj, QEvent* e)
329 {
330  if (obj == mSplitter)
331  {
332  switch (e->type())
333  {
334  case QEvent::Resize:
335  // Don't change resources size while WINDOW is being resized.
336  // Resize event always occurs before Paint.
337  mResizing = true;
338  break;
339  case QEvent::Paint:
340  // Allow resources to be resized again
341  mResizing = false;
342  break;
343  default:
344  break;
345  }
346  }
347  else if (obj == mListView)
348  {
349  switch (e->type())
350  {
351  case QEvent::KeyPress:
352  {
353  QKeyEvent* ke = static_cast<QKeyEvent*>(e);
354  if (ke->key() == Qt::Key_Delete && ke->modifiers() == Qt::ShiftModifier)
355  {
356  // Prevent Shift-Delete being processed by EventListDelegate
357  mActionDeleteForce->trigger();
358  return true;
359  }
360  break;
361  }
362  default:
363  break;
364  }
365  }
366  return false;
367 }
368 
369 /******************************************************************************
370 * Called when the window's size has changed (before it is painted).
371 * Sets the last column in the list view to extend at least to the right hand
372 * edge of the list view.
373 * Records the new size in the config file.
374 */
375 void MainWindow::resizeEvent(QResizeEvent* re)
376 {
377  // Save the window's new size only if it's the first main window
378  MainWindowBase::resizeEvent(re);
379  if (mResourcesWidth > 0)
380  {
381  QList<int> widths;
382  widths.append(mResourcesWidth);
383  widths.append(width() - mResourcesWidth - mSplitter->handleWidth());
384  mSplitter->setSizes(widths);
385  }
386 }
387 
388 void MainWindow::resourcesResized()
389 {
390  if (!mShown || mResizing)
391  return;
392  QList<int> widths = mSplitter->sizes();
393  if (widths.count() > 1)
394  {
395  mResourcesWidth = widths[0];
396  // Width is reported as non-zero when resource selector is
397  // actually invisible, so note a zero width in these circumstances.
398  if (mResourcesWidth <= 5)
399  mResourcesWidth = 0;
400  else if (mainMainWindow() == this)
401  {
402  KConfigGroup config(KGlobal::config(), WINDOW_NAME);
403  config.writeEntry(QString::fromLatin1("Splitter %1").arg(KApplication::desktop()->width()), mResourcesWidth);
404  }
405  }
406 }
407 
408 /******************************************************************************
409 * Called when the window is first displayed.
410 * Sets the last column in the list view to extend at least to the right hand
411 * edge of the list view.
412 */
413 void MainWindow::showEvent(QShowEvent* se)
414 {
415  if (mResourcesWidth > 0)
416  {
417  QList<int> widths;
418  widths.append(mResourcesWidth);
419  widths.append(width() - mResourcesWidth - mSplitter->handleWidth());
420  mSplitter->setSizes(widths);
421  }
422  MainWindowBase::showEvent(se);
423  mShown = true;
424 }
425 
426 /******************************************************************************
427 * Display the window.
428 */
429 void MainWindow::show()
430 {
431  MainWindowBase::show();
432  if (mMenuError)
433  {
434  // Show error message now that the main window has been displayed.
435  // Waiting until now lets the user easily associate the message with
436  // the main window which is faulty.
437  KAMessageBox::error(this, i18nc("@info", "Failure to create menus (perhaps <filename>%1</filename> missing or corrupted)", UI_FILE));
438  mMenuError = false;
439  }
440 }
441 
442 /******************************************************************************
443 * Called after the window is hidden.
444 */
445 void MainWindow::hideEvent(QHideEvent* he)
446 {
447  MainWindowBase::hideEvent(he);
448 }
449 
450 /******************************************************************************
451 * Initialise the menu, toolbar and main window actions.
452 */
453 void MainWindow::initActions()
454 {
455  KShortcut dummy;
456  KActionCollection* actions = actionCollection();
457 
458  mActionTemplates = new KAction(i18nc("@action", "&Templates..."), this);
459  actions->addAction(QLatin1String("templates"), mActionTemplates);
460  connect(mActionTemplates, SIGNAL(triggered(bool)), SLOT(slotTemplates()));
461 
462  mActionNew = new NewAlarmAction(false, i18nc("@action", "&New"), this);
463  actions->addAction(QLatin1String("new"), mActionNew);
464 
465  KAction* action = mActionNew->displayAlarmAction();
466  actions->addAction(QLatin1String("newDisplay"), action);
467  action->setGlobalShortcut(dummy); // actions->addAction() must be called first!
468  connect(action, SIGNAL(triggered(bool)), SLOT(slotNewDisplay()));
469 
470  action = mActionNew->commandAlarmAction();
471  actions->addAction(QLatin1String("newCommand"), action);
472  action->setGlobalShortcut(dummy); // actions->addAction() must be called first!
473  connect(action, SIGNAL(triggered(bool)), SLOT(slotNewCommand()));
474 
475  action = mActionNew->emailAlarmAction();
476  actions->addAction(QLatin1String("newEmail"), action);
477  action->setGlobalShortcut(dummy); // actions->addAction() must be called first!
478  connect(action, SIGNAL(triggered(bool)), SLOT(slotNewEmail()));
479 
480  action = mActionNew->audioAlarmAction();
481  actions->addAction(QLatin1String("newAudio"), action);
482  action->setGlobalShortcut(dummy); // actions->addAction() must be called first!
483  connect(action, SIGNAL(triggered(bool)), SLOT(slotNewAudio()));
484 
485  action = mActionNew->fromTemplateAlarmAction();
486  actions->addAction(QLatin1String("newFromTemplate"), action);
487  connect(action, SIGNAL(selected(const KAEvent*)), SLOT(slotNewFromTemplate(const KAEvent*)));
488 
489  mActionCreateTemplate = new KAction(i18nc("@action", "Create Tem&plate..."), this);
490  actions->addAction(QLatin1String("createTemplate"), mActionCreateTemplate);
491  connect(mActionCreateTemplate, SIGNAL(triggered(bool)), SLOT(slotNewTemplate()));
492 
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()));
497 
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()));
502 
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()));
507 
508  // Set up Shift-Delete as a shortcut to delete without confirmation
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()));
513 
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()));
518 
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()));
523 
524  action = new KAction(i18nc("@action", "Wake From Suspend..."), this);
525  actions->addAction(QLatin1String("wakeSuspend"), action);
526  connect(action, SIGNAL(triggered(bool)), SLOT(slotWakeFromSuspend()));
527 
528  action = KAlarm::createStopPlayAction(this);
529  actions->addAction(QLatin1String("stopAudio"), action);
530  action->setGlobalShortcut(dummy); // actions->addAction() must be called first!
531 
532  mActionShowTime = new KToggleAction(i18n_a_ShowAlarmTimes(), this);
533  actions->addAction(QLatin1String("showAlarmTimes"), mActionShowTime);
534  connect(mActionShowTime, SIGNAL(triggered(bool)), SLOT(slotShowTime()));
535 
536  mActionShowTimeTo = new KToggleAction(i18n_o_ShowTimeToAlarms(), this);
537  actions->addAction(QLatin1String("showTimeToAlarms"), mActionShowTimeTo);
538  mActionShowTimeTo->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_I));
539  connect(mActionShowTimeTo, SIGNAL(triggered(bool)), SLOT(slotShowTimeTo()));
540 
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()));
545 
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()));
549 
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()));
553 
554  mActionSpreadWindows = KAlarm::createSpreadWindowsAction(this);
555  actions->addAction(QLatin1String("spread"), mActionSpreadWindows);
556  mActionSpreadWindows->setGlobalShortcut(dummy); // actions->addAction() must be called first!
557 
558  mActionImportAlarms = new KAction(i18nc("@action", "Import &Alarms..."), this);
559  actions->addAction(QLatin1String("importAlarms"), mActionImportAlarms);
560  connect(mActionImportAlarms, SIGNAL(triggered(bool)), SLOT(slotImportAlarms()));
561 
562  mActionImportBirthdays = new KAction(i18nc("@action", "Import &Birthdays..."), this);
563  actions->addAction(QLatin1String("importBirthdays"), mActionImportBirthdays);
564  connect(mActionImportBirthdays, SIGNAL(triggered(bool)), SLOT(slotBirthdays()));
565 
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()));
569 
570  mActionExport = new KAction(i18nc("@action", "E&xport..."), this);
571  actions->addAction(QLatin1String("export"), mActionExport);
572  connect(mActionExport, SIGNAL(triggered(bool)), SLOT(slotExportAlarms()));
573 
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()));
577 
578  action = KAlarm::createAlarmEnableAction(this);
579  actions->addAction(QLatin1String("alarmsEnable"), action);
580  if (undoText.isNull())
581  {
582  // Get standard texts, etc., for Undo and Redo actions
583  QAction * act = KStandardAction::undo(this, 0, actions);
584  undoShortcut = KShortcut(act->shortcuts());
585  undoText = act->text();
586  undoTextStripped = KGlobal::locale()->removeAcceleratorMarker(undoText);
587  delete act;
588  act = KStandardAction::redo(this, 0, actions);
589  redoShortcut = KShortcut(act->shortcuts());
590  redoText = act->text();
591  redoTextStripped = KGlobal::locale()->removeAcceleratorMarker(redoText);
592  delete act;
593  }
594  mActionUndo = new KToolBarPopupAction(KIcon(QLatin1String("edit-undo")), undoText, this);
595  actions->addAction(QLatin1String("edit_undo"), mActionUndo);
596  mActionUndo->setShortcut(undoShortcut);
597  connect(mActionUndo, SIGNAL(triggered(bool)), SLOT(slotUndo()));
598 
599  mActionRedo = new KToolBarPopupAction(KIcon(QLatin1String("edit-redo")), redoText, this);
600  actions->addAction(QLatin1String("edit_redo"), mActionRedo);
601  mActionRedo->setShortcut(redoShortcut);
602  connect(mActionRedo, SIGNAL(triggered(bool)), SLOT(slotRedo()));
603 
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);
609  // Quit only once the event loop is called; otherwise, the parent window will
610  // be deleted while still processing the action, resulting in a crash.
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);
616  mResourceSelector->initActions(actions);
617  setStandardToolBarMenuEnabled(true);
618  createGUI(UI_FILE);
619  // Load menu and toolbar settings
620  applyMainWindowSettings(KGlobal::config()->group(WINDOW_NAME));
621 
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));
625  mResourceSelector->setContextMenu(resourceMenu);
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()));
636 
637  // Set menu item states
638  setEnableText(true);
639  mActionShowTime->setChecked(mShowTime);
640  mActionShowTimeTo->setChecked(mShowTimeTo);
641  mActionShowArchived->setChecked(mShowArchived);
642  if (!Preferences::archivedKeepDays())
643  mActionShowArchived->setEnabled(false);
644  mActionToggleResourceSel->setChecked(mShowResources);
645  slotToggleResourceSelector();
646  updateTrayIconAction(); // set the correct text for this action
647  mActionUndo->setEnabled(Undo::haveUndo());
648  mActionRedo->setEnabled(Undo::haveRedo());
649  mActionFindNext->setEnabled(false);
650  mActionFindPrev->setEnabled(false);
651 
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);
659 
660  Undo::emitChanged(); // set the Undo/Redo menu texts
661 // Daemon::monitoringAlarms();
662 }
663 
664 /******************************************************************************
665 * Enable or disable the Templates menu item in every main window instance.
666 */
667 void MainWindow::enableTemplateMenuItem(bool enable)
668 {
669  for (int i = 0, end = mWindowList.count(); i < end; ++i)
670  mWindowList[i]->mActionTemplates->setEnabled(enable);
671 }
672 
673 /******************************************************************************
674 * Refresh the alarm list in every main window instance.
675 */
676 void MainWindow::refresh()
677 {
678  kDebug();
679 #ifdef USE_AKONADI
680  AkonadiModel::instance()->reload();
681 #else
682  EventListModel::alarms()->reload();
683 #endif
684 }
685 
686 /******************************************************************************
687 * Called when the keep archived alarm setting changes in the user preferences.
688 * Enable/disable Show archived alarms option.
689 */
690 void MainWindow::updateKeepArchived(int days)
691 {
692  kDebug() << (bool)days;
693  if (mShowArchived && !days)
694  slotShowArchived(); // toggle Show Archived option setting
695  mActionShowArchived->setEnabled(days);
696 }
697 
698 /******************************************************************************
699 * Select an alarm in the displayed list.
700 */
701 #ifdef USE_AKONADI
702 void MainWindow::selectEvent(Akonadi::Item::Id eventId)
703 #else
704 void MainWindow::selectEvent(const QString& eventId)
705 #endif
706 {
707  mListView->clearSelection();
708 #ifdef USE_AKONADI
709  QModelIndex index = mListFilterModel->eventIndex(eventId);
710  if (index.isValid())
711  {
712  mListView->select(index);
713  mListView->scrollTo(index);
714  }
715 #else
716  mListView->select(eventId, true);
717 #endif
718 }
719 
720 /******************************************************************************
721 * Return the single selected alarm in the displayed list.
722 */
723 #ifdef USE_AKONADI
724 KAEvent MainWindow::selectedEvent() const
725 #else
726 KAEvent* MainWindow::selectedEvent() const
727 #endif
728 {
729  return mListView->selectedEvent();
730 }
731 
732 /******************************************************************************
733 * Deselect all alarms in the displayed list.
734 */
735 void MainWindow::clearSelection()
736 {
737  mListView->clearSelection();
738 }
739 
740 /******************************************************************************
741 * Called when the New button is clicked to edit a new alarm to add to the list.
742 */
743 void MainWindow::slotNew(EditAlarmDlg::Type type)
744 {
745  KAlarm::editNewAlarm(type, mListView);
746 }
747 
748 /******************************************************************************
749 * Called when a template is selected from the New From Template popup menu.
750 * Executes a New Alarm dialog, preset from the selected template.
751 */
752 void MainWindow::slotNewFromTemplate(const KAEvent* tmplate)
753 {
754  KAlarm::editNewAlarm(tmplate, mListView);
755 }
756 
757 /******************************************************************************
758 * Called when the New Template button is clicked to create a new template
759 * based on the currently selected alarm.
760 */
761 void MainWindow::slotNewTemplate()
762 {
763 #ifdef USE_AKONADI
764  KAEvent event = mListView->selectedEvent();
765  if (event.isValid())
766  KAlarm::editNewTemplate(&event, this);
767 #else
768  KAEvent* event = mListView->selectedEvent();
769  if (event)
770  KAlarm::editNewTemplate(event, this);
771 #endif
772 }
773 
774 /******************************************************************************
775 * Called when the Copy button is clicked to edit a copy of an existing alarm,
776 * to add to the list.
777 */
778 void MainWindow::slotCopy()
779 {
780 #ifdef USE_AKONADI
781  KAEvent event = mListView->selectedEvent();
782  if (event.isValid())
783  KAlarm::editNewAlarm(&event, this);
784 #else
785  KAEvent* event = mListView->selectedEvent();
786  if (event)
787  KAlarm::editNewAlarm(event, this);
788 #endif
789 }
790 
791 /******************************************************************************
792 * Called when the Modify button is clicked to edit the currently highlighted
793 * alarm in the list.
794 */
795 void MainWindow::slotModify()
796 {
797 #ifdef USE_AKONADI
798  KAEvent event = mListView->selectedEvent();
799  if (event.isValid())
800  KAlarm::editAlarm(&event, this); // edit alarm (view-only mode if archived or read-only)
801 #else
802  KAEvent* event = mListView->selectedEvent();
803  if (event)
804  KAlarm::editAlarm(event, this); // edit alarm (view-only mode if archived or read-only)
805 #endif
806 }
807 
808 /******************************************************************************
809 * Called when the Delete button is clicked to delete the currently highlighted
810 * alarms in the list.
811 */
812 void MainWindow::slotDelete(bool force)
813 {
814 #ifdef USE_AKONADI
815  QVector<KAEvent> events = mListView->selectedEvents();
816 #else
817  KAEvent::List events = mListView->selectedEvents();
818  // Save the IDs of the events to be deleted, in case any events are
819  // deleted by being triggered while the confirmation prompt is displayed
820  // (in which case their pointers will become invalid).
821  QStringList ids;
822  for (int i = 0, end = events.count(); i < end; ++i)
823  ids.append(events[i]->id());
824 #endif
825 
826  if (!force && Preferences::confirmAlarmDeletion())
827  {
828  int n = events.count();
829  if (KAMessageBox::warningContinueCancel(this, i18ncp("@info", "Do you really want to delete the selected alarm?",
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(),
834  Preferences::CONFIRM_ALARM_DELETION)
835  != KMessageBox::Continue)
836  return;
837  }
838 
839  // Remove any events which have just triggered, from the list to delete.
840  Undo::EventList undos;
841  AlarmCalendar* resources = AlarmCalendar::resources();
842 #ifdef USE_AKONADI
843  for (int i = 0; i < events.count(); )
844  {
845  Akonadi::Collection c = resources->collectionForEvent(events[i].itemId());
846  if (!c.isValid())
847  events.remove(i);
848  else
849  undos.append(events[i++], c);
850  }
851 #else
852  for (int i = 0, e = 0, end = ids.count(); i < end; ++i)
853  {
854  AlarmResource* r = resources->resourceForEvent(ids[i]);
855  if (!r)
856  events.remove(e);
857  else
858  undos.append(*events[e++], r);
859  }
860 #endif
861 
862  if (events.isEmpty())
863  kDebug() << "No alarms left to delete";
864  else
865  {
866  // Delete the events from the calendar and displays
867  KAlarm::deleteEvents(events, true, this);
868  Undo::saveDeletes(undos);
869  }
870 }
871 
872 /******************************************************************************
873 * Called when the Reactivate button is clicked to reinstate the currently
874 * highlighted archived alarms in the list.
875 */
876 void MainWindow::slotReactivate()
877 {
878 #ifdef USE_AKONADI
879  QVector<KAEvent> events = mListView->selectedEvents();
880 #else
881  KAEvent::List events = mListView->selectedEvents();
882 #endif
883  mListView->clearSelection();
884 
885  // Add the alarms to the displayed lists and to the calendar file
886  Undo::EventList undos;
887 #ifdef USE_AKONADI
888  QVector<EventId> ineligibleIDs;
889  KAlarm::reactivateEvents(events, ineligibleIDs, 0, this);
890 #else
891  QStringList ineligibleIDs;
892  KAlarm::reactivateEvents(events, ineligibleIDs, 0, this);
893 #endif
894 
895  // Create the undo list, excluding ineligible events
896  AlarmCalendar* resources = AlarmCalendar::resources();
897  for (int i = 0, end = events.count(); i < end; ++i)
898  {
899 #ifdef USE_AKONADI
900  if (!ineligibleIDs.contains(EventId(events[i])))
901  {
902  undos.append(events[i], resources->collectionForEvent(events[i].itemId()));
903  }
904 #else
905  QString id = events[i]->id();
906  if (!ineligibleIDs.contains(id))
907  undos.append(*events[i], resources->resourceForEvent(id));
908 #endif
909  }
910  Undo::saveReactivates(undos);
911 }
912 
913 /******************************************************************************
914 * Called when the Enable/Disable button is clicked to enable or disable the
915 * currently highlighted alarms in the list.
916 */
917 void MainWindow::slotEnable()
918 {
919  bool enable = mActionEnableEnable; // save since changed in response to KAlarm::enableEvent()
920 #ifdef USE_AKONADI
921  QVector<KAEvent> events = mListView->selectedEvents();
922  QVector<KAEvent> eventCopies;
923 #else
924  KAEvent::List events = mListView->selectedEvents();
925  KAEvent::List eventCopies;
926 #endif
927  for (int i = 0, end = events.count(); i < end; ++i)
928  eventCopies += events[i];
929  KAlarm::enableEvents(eventCopies, enable, this);
930  slotSelection(); // update Enable/Disable action text
931 }
932 
933 /******************************************************************************
934 * Called when the Show Alarm Times menu item is selected or deselected.
935 */
936 void MainWindow::slotShowTime()
937 {
938  mShowTime = !mShowTime;
939  mActionShowTime->setChecked(mShowTime);
940  if (!mShowTime && !mShowTimeTo)
941  slotShowTimeTo(); // at least one time column must be displayed
942  else
943  {
944  mListView->selectTimeColumns(mShowTime, mShowTimeTo);
945  KConfigGroup config(KGlobal::config(), VIEW_GROUP);
946  config.writeEntry(SHOW_TIME_KEY, mShowTime);
947  config.writeEntry(SHOW_TIME_TO_KEY, mShowTimeTo);
948  }
949 }
950 
951 /******************************************************************************
952 * Called when the Show Time To Alarms menu item is selected or deselected.
953 */
954 void MainWindow::slotShowTimeTo()
955 {
956  mShowTimeTo = !mShowTimeTo;
957  mActionShowTimeTo->setChecked(mShowTimeTo);
958  if (!mShowTimeTo && !mShowTime)
959  slotShowTime(); // at least one time column must be displayed
960  else
961  {
962  mListView->selectTimeColumns(mShowTime, mShowTimeTo);
963  KConfigGroup config(KGlobal::config(), VIEW_GROUP);
964  config.writeEntry(SHOW_TIME_KEY, mShowTime);
965  config.writeEntry(SHOW_TIME_TO_KEY, mShowTimeTo);
966  }
967 }
968 
969 /******************************************************************************
970 * Called when the Show Archived Alarms menu item is selected or deselected.
971 */
972 void MainWindow::slotShowArchived()
973 {
974  mShowArchived = !mShowArchived;
975  mActionShowArchived->setChecked(mShowArchived);
976  mActionShowArchived->setToolTip(mShowArchived ? i18nc("@info:tooltip", "Hide Archived Alarms")
977  : i18nc("@info:tooltip", "Show Archived Alarms"));
978 #ifdef USE_AKONADI
979  mListFilterModel->setEventTypeFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
980 #else
981  mListFilterModel->setStatusFilter(mShowArchived ? CalEvent::ACTIVE | CalEvent::ARCHIVED : CalEvent::ACTIVE);
982 #endif
983  mListView->reset();
984  KConfigGroup config(KGlobal::config(), VIEW_GROUP);
985  config.writeEntry(SHOW_ARCHIVED_KEY, mShowArchived);
986 }
987 
988 /******************************************************************************
989 * Called when the Spread Windows global shortcut is selected, to spread alarm
990 * windows so that they are all visible.
991 */
992 void MainWindow::slotSpreadWindowsShortcut()
993 {
994  mActionSpreadWindows->trigger();
995 }
996 
997 /******************************************************************************
998 * Called when the Wake From Suspend menu option is selected.
999 */
1000 void MainWindow::slotWakeFromSuspend()
1001 {
1002  (WakeFromSuspendDlg::create(this))->show();
1003 }
1004 
1005 /******************************************************************************
1006 * Called when the Import Alarms menu item is selected, to merge alarms from an
1007 * external calendar into the current calendars.
1008 */
1009 void MainWindow::slotImportAlarms()
1010 {
1011  AlarmCalendar::importAlarms(this);
1012 }
1013 
1014 /******************************************************************************
1015 * Called when the Export Alarms menu item is selected, to export the selected
1016 * alarms to an external calendar.
1017 */
1018 void MainWindow::slotExportAlarms()
1019 {
1020 #ifdef USE_AKONADI
1021  QVector<KAEvent> events = mListView->selectedEvents();
1022  if (!events.isEmpty())
1023  {
1024  KAEvent::List evts = KAEvent::ptrList(events);
1025  AlarmCalendar::exportAlarms(evts, this);
1026  }
1027 #else
1028  KAEvent::List events = mListView->selectedEvents();
1029  if (!events.isEmpty())
1030  AlarmCalendar::exportAlarms(events, this);
1031 #endif
1032 }
1033 
1034 /******************************************************************************
1035 * Called when the Import Birthdays menu item is selected, to display birthdays
1036 * from the address book for selection as alarms.
1037 */
1038 void MainWindow::slotBirthdays()
1039 {
1040  // Use AutoQPointer to guard against crash on application exit while
1041  // the dialogue is still open. It prevents double deletion (both on
1042  // deletion of MainWindow, and on return from this function).
1043  AutoQPointer<BirthdayDlg> dlg = new BirthdayDlg(this);
1044  if (dlg->exec() == QDialog::Accepted)
1045  {
1046  QVector<KAEvent> events = dlg->events();
1047  if (!events.isEmpty())
1048  {
1049  mListView->clearSelection();
1050  // Add alarm to the displayed lists and to the calendar file
1051  KAlarm::UpdateStatus status = KAlarm::addEvents(events, dlg, true, true);
1052 
1053  Undo::EventList undos;
1054  AlarmCalendar* resources = AlarmCalendar::resources();
1055  for (int i = 0, end = events.count(); i < end; ++i)
1056 #ifdef USE_AKONADI
1057  {
1058  Akonadi::Collection c = resources->collectionForEvent(events[i].itemId());
1059  undos.append(events[i], c);
1060  }
1061 #else
1062  undos.append(events[i], resources->resourceForEvent(events[i].id()));
1063 #endif
1064  Undo::saveAdds(undos, i18nc("@info", "Import birthdays"));
1065 
1066  if (status != KAlarm::UPDATE_FAILED)
1067  KAlarm::outputAlarmWarnings(dlg);
1068  }
1069  }
1070 }
1071 
1072 /******************************************************************************
1073 * Called when the Templates menu item is selected, to display the alarm
1074 * template editing dialog.
1075 */
1076 void MainWindow::slotTemplates()
1077 {
1078  if (!mTemplateDlg)
1079  {
1080  mTemplateDlg = TemplateDlg::create(this);
1081  enableTemplateMenuItem(false); // disable menu item in all windows
1082  connect(mTemplateDlg, SIGNAL(finished()), SLOT(slotTemplatesEnd()));
1083  mTemplateDlg->show();
1084  }
1085 }
1086 
1087 /******************************************************************************
1088 * Called when the alarm template editing dialog has exited.
1089 */
1090 void MainWindow::slotTemplatesEnd()
1091 {
1092  if (mTemplateDlg)
1093  {
1094  mTemplateDlg->delayedDestruct(); // this deletes the dialog once it is safe to do so
1095  mTemplateDlg = 0;
1096  enableTemplateMenuItem(true); // re-enable menu item in all windows
1097  }
1098 }
1099 
1100 /******************************************************************************
1101 * Called when the Display System Tray Icon menu item is selected.
1102 */
1103 void MainWindow::slotToggleTrayIcon()
1104 {
1105  theApp()->displayTrayIcon(!theApp()->trayIconDisplayed(), this);
1106 }
1107 
1108 /******************************************************************************
1109 * Called when the Show Resource Selector menu item is selected.
1110 */
1111 void MainWindow::slotToggleResourceSelector()
1112 {
1113  mShowResources = mActionToggleResourceSel->isChecked();
1114  if (mShowResources)
1115  {
1116  if (mResourcesWidth <= 0)
1117  {
1118  mResourcesWidth = mResourceSelector->sizeHint().width();
1119  mResourceSelector->resize(mResourcesWidth, mResourceSelector->height());
1120  QList<int> widths = mSplitter->sizes();
1121  if (widths.count() == 1)
1122  {
1123  int listwidth = widths[0] - mSplitter->handleWidth() - mResourcesWidth;
1124  mListView->resize(listwidth, mListView->height());
1125  widths.append(listwidth);
1126  widths[0] = mResourcesWidth;
1127  }
1128  mSplitter->setSizes(widths);
1129  }
1130  mResourceSelector->show();
1131  }
1132  else
1133  mResourceSelector->hide();
1134 
1135  KConfigGroup config(KGlobal::config(), VIEW_GROUP);
1136  config.writeEntry(SHOW_RESOURCES_KEY, mShowResources);
1137 }
1138 
1139 /******************************************************************************
1140 * Called when an error occurs in the resource calendar, to display a message.
1141 */
1142 void MainWindow::showErrorMessage(const QString& msg)
1143 {
1144  KAMessageBox::error(this, msg);
1145 }
1146 
1147 /******************************************************************************
1148 * Called when the system tray icon is created or destroyed.
1149 * Set the system tray icon menu text according to whether or not the system
1150 * tray icon is currently visible.
1151 */
1152 void MainWindow::updateTrayIconAction()
1153 {
1154  mActionToggleTrayIcon->setEnabled(KSystemTrayIcon::isSystemTrayAvailable());
1155  mActionToggleTrayIcon->setChecked(theApp()->trayIconDisplayed());
1156 }
1157 
1158 /******************************************************************************
1159 * Called when the active status of Find changes.
1160 */
1161 void MainWindow::slotFindActive(bool active)
1162 {
1163  mActionFindNext->setEnabled(active);
1164  mActionFindPrev->setEnabled(active);
1165 }
1166 
1167 /******************************************************************************
1168 * Called when the Undo action is selected.
1169 */
1170 void MainWindow::slotUndo()
1171 {
1172  Undo::undo(this, KGlobal::locale()->removeAcceleratorMarker(mActionUndo->text()));
1173 }
1174 
1175 /******************************************************************************
1176 * Called when the Redo action is selected.
1177 */
1178 void MainWindow::slotRedo()
1179 {
1180  Undo::redo(this, KGlobal::locale()->removeAcceleratorMarker(mActionRedo->text()));
1181 }
1182 
1183 /******************************************************************************
1184 * Called when an Undo item is selected.
1185 */
1186 void MainWindow::slotUndoItem(QAction* action)
1187 {
1188  int id = mUndoMenuIds[action];
1189  Undo::undo(id, this, Undo::actionText(Undo::UNDO, id));
1190 }
1191 
1192 /******************************************************************************
1193 * Called when a Redo item is selected.
1194 */
1195 void MainWindow::slotRedoItem(QAction* action)
1196 {
1197  int id = mUndoMenuIds[action];
1198  Undo::redo(id, this, Undo::actionText(Undo::REDO, id));
1199 }
1200 
1201 /******************************************************************************
1202 * Called when the Undo menu is about to show.
1203 * Populates the menu.
1204 */
1205 void MainWindow::slotInitUndoMenu()
1206 {
1207  initUndoMenu(mActionUndo->menu(), Undo::UNDO);
1208 }
1209 
1210 /******************************************************************************
1211 * Called when the Redo menu is about to show.
1212 * Populates the menu.
1213 */
1214 void MainWindow::slotInitRedoMenu()
1215 {
1216  initUndoMenu(mActionRedo->menu(), Undo::REDO);
1217 }
1218 
1219 /******************************************************************************
1220 * Populate the undo or redo menu.
1221 */
1222 void MainWindow::initUndoMenu(QMenu* menu, Undo::Type type)
1223 {
1224  menu->clear();
1225  mUndoMenuIds.clear();
1226  const QString& action = (type == Undo::UNDO) ? undoTextStripped : redoTextStripped;
1227  QList<int> ids = Undo::ids(type);
1228  for (int i = 0, end = ids.count(); i < end; ++i)
1229  {
1230  int id = ids[i];
1231  QString actText = Undo::actionText(type, id);
1232  QString descrip = Undo::description(type, id);
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;
1238  }
1239 }
1240 
1241 /******************************************************************************
1242 * Called when the status of the Undo or Redo list changes.
1243 * Change the Undo or Redo text to include the action which would be undone/redone.
1244 */
1245 void MainWindow::slotUndoStatus(const QString& undo, const QString& redo)
1246 {
1247  if (undo.isNull())
1248  {
1249  mActionUndo->setEnabled(false);
1250  mActionUndo->setText(undoText);
1251  }
1252  else
1253  {
1254  mActionUndo->setEnabled(true);
1255  mActionUndo->setText(QString::fromLatin1("%1 %2").arg(undoText).arg(undo));
1256  }
1257  if (redo.isNull())
1258  {
1259  mActionRedo->setEnabled(false);
1260  mActionRedo->setText(redoText);
1261  }
1262  else
1263  {
1264  mActionRedo->setEnabled(true);
1265  mActionRedo->setText(QString::fromLatin1("%1 %2").arg(redoText).arg(redo));
1266  }
1267 }
1268 
1269 /******************************************************************************
1270 * Called when the Refresh Alarms menu item is selected.
1271 */
1272 void MainWindow::slotRefreshAlarms()
1273 {
1274  KAlarm::refreshAlarms();
1275 }
1276 
1277 /******************************************************************************
1278 * Called when the "Configure KAlarm" menu item is selected.
1279 */
1280 void MainWindow::slotPreferences()
1281 {
1282  KAlarmPrefDlg::display();
1283 }
1284 
1285 /******************************************************************************
1286 * Called when the Configure Keys menu item is selected.
1287 */
1288 void MainWindow::slotConfigureKeys()
1289 {
1290  KShortcutsDialog::configure(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed, this);
1291 }
1292 
1293 /******************************************************************************
1294 * Called when the Configure Toolbars menu item is selected.
1295 */
1296 void MainWindow::slotConfigureToolbar()
1297 {
1298  saveMainWindowSettings(KGlobal::config()->group(WINDOW_NAME));
1299  KEditToolBar dlg(factory());
1300  connect(&dlg, SIGNAL(newToolBarConfig()), this, SLOT(slotNewToolbarConfig()));
1301  dlg.exec();
1302 }
1303 
1304 /******************************************************************************
1305 * Called when OK or Apply is clicked in the Configure Toolbars dialog, to save
1306 * the new configuration.
1307 */
1308 void MainWindow::slotNewToolbarConfig()
1309 {
1310  createGUI(UI_FILE);
1311  applyMainWindowSettings(KGlobal::config()->group(WINDOW_NAME));
1312 }
1313 
1314 /******************************************************************************
1315 * Called when the Quit menu item is selected.
1316 * Note that this must be called by the event loop, not directly from the menu
1317 * item, since otherwise the window will be deleted while still processing the
1318 * menu, resulting in a crash.
1319 */
1320 void MainWindow::slotQuit()
1321 {
1322  theApp()->doQuit(this);
1323 }
1324 
1325 /******************************************************************************
1326 * Called when the user or the session manager attempts to close the window.
1327 */
1328 void MainWindow::closeEvent(QCloseEvent* ce)
1329 {
1330  if (!theApp()->sessionClosingDown())
1331  {
1332  // The user (not the session manager) wants to close the window.
1333  if (isTrayParent())
1334  {
1335  // It's the parent window of the system tray icon, so just hide
1336  // it to prevent the system tray icon closing.
1337  hide();
1338  theApp()->quitIf();
1339  ce->ignore();
1340  return;
1341  }
1342  }
1343  ce->accept();
1344 }
1345 
1346 /******************************************************************************
1347 * Called when the drag cursor enters a main or system tray window, to accept
1348 * or reject the dragged object.
1349 */
1350 void MainWindow::executeDragEnterEvent(QDragEnterEvent* e)
1351 {
1352  const QMimeData* data = e->mimeData();
1353  bool accept = ICalDrag::canDecode(data) ? !e->source() // don't accept "text/calendar" objects from this application
1354  : data->hasText()
1355  || KUrl::List::canDecode(data)
1356  || KPIM::MailList::canDecode(data);
1357  if (accept)
1358  e->acceptProposedAction();
1359 }
1360 
1361 /******************************************************************************
1362 * Called when an object is dropped on the window.
1363 * If the object is recognised, the edit alarm dialog is opened appropriately.
1364 */
1365 void MainWindow::dropEvent(QDropEvent* e)
1366 {
1367  executeDropEvent(this, e);
1368 }
1369 
1370 static QString getMailHeader(const char* header, KMime::Content& content)
1371 {
1372  KMime::Headers::Base* hd = content.headerByType(header);
1373  return hd ? hd->asUnicodeString() : QString();
1374 }
1375 
1376 /******************************************************************************
1377 * Called when an object is dropped on a main or system tray window, to
1378 * evaluate the action required and extract the text.
1379 */
1380 void MainWindow::executeDropEvent(MainWindow* win, QDropEvent* e)
1381 {
1382  kDebug() << "Formats:" << e->mimeData()->formats();
1383  const QMimeData* data = e->mimeData();
1384  KAEvent::SubAction action = KAEvent::MESSAGE;
1385  QByteArray bytes;
1386  AlarmText alarmText;
1387  KPIM::MailList mailList;
1388  KUrl::List files;
1389 #ifdef USE_AKONADI
1390  MemoryCalendar::Ptr calendar(new MemoryCalendar(Preferences::timeZone(true)));
1391 #else
1392  CalendarLocal calendar(Preferences::timeZone(true));
1393 #endif
1394 #ifndef NDEBUG
1395  QString fmts = data->formats().join(QLatin1String(", "));
1396  kDebug() << fmts;
1397 #endif
1398 
1399  /* The order of the tests below matters, since some dropped objects
1400  * provide more than one mime type.
1401  * Don't change them without careful thought !!
1402  */
1403  if (!(bytes = data->data(QLatin1String("message/rfc822"))).isEmpty())
1404  {
1405  // Email message(s). Ignore all but the first.
1406  kDebug() << "email";
1407  KMime::Content content;
1408  content.setContent(bytes);
1409  content.parse();
1410  QString body;
1411  if (content.textContent())
1412  body = content.textContent()->decodedText(true, true); // strip trailing newlines & spaces
1413  unsigned long sernum = 0;
1414  if (KPIM::MailList::canDecode(data))
1415  {
1416  // Get its KMail serial number to allow the KMail message
1417  // to be called up from the alarm message window.
1418  mailList = KPIM::MailList::fromMimeData(data);
1419  if (!mailList.isEmpty())
1420  sernum = mailList[0].serialNumber();
1421  }
1422  alarmText.setEmail(getMailHeader("To", content),
1423  getMailHeader("From", content),
1424  getMailHeader("Cc", content),
1425  getMailHeader("Date", content),
1426  getMailHeader("Subject", content),
1427  body, sernum);
1428  }
1429 #ifdef KMAIL_SUPPORTED
1430  else if (KPIM::MailList::canDecode(data))
1431  {
1432  mailList = KPIM::MailList::fromMimeData(data);
1433  // KMail message(s). Ignore all but the first.
1434  kDebug() << "KMail_list";
1435  if (mailList.isEmpty())
1436  return;
1437  KPIM::MailSummary& summary = mailList[0];
1438  QDateTime dt;
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(),
1443  body, summary.serialNumber());
1444  }
1445 #endif
1446 #ifdef USE_AKONADI
1447  else if (ICalDrag::fromMimeData(data, calendar))
1448 #else
1449  else if (ICalDrag::fromMimeData(data, &calendar))
1450 #endif
1451  {
1452  // iCalendar - If events are included, use the first event
1453  kDebug() << "iCalendar";
1454 #ifdef USE_AKONADI
1455  Event::List events = calendar->rawEvents();
1456 #else
1457  Event::List events = calendar.rawEvents();
1458 #endif
1459  if (!events.isEmpty())
1460  {
1461  KAEvent ev(events[0]);
1462  KAlarm::editNewAlarm(&ev, win);
1463  return;
1464  }
1465  // If todos are included, use the first todo
1466 #ifdef USE_AKONADI
1467  Todo::List todos = calendar->rawTodos();
1468 #else
1469  Todo::List todos = calendar.rawTodos();
1470 #endif
1471  if (todos.isEmpty())
1472  return;
1473 #ifdef USE_AKONADI
1474  Todo::Ptr todo = todos[0];
1475 #else
1476  Todo* todo = todos[0];
1477 #endif
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;
1485  KAEvent ev(start, alarmText.displayText(), Preferences::defaultBgColour(), Preferences::defaultFgColour(),
1486  QFont(), KAEvent::MESSAGE, 0, flags, true);
1487  if (todo->recurs())
1488  {
1489  ev.setRecurrence(*todo->recurrence());
1490  ev.setNextOccurrence(KDateTime::currentUtcDateTime());
1491  }
1492  ev.endChanges();
1493  KAlarm::editNewAlarm(&ev, win);
1494  return;
1495  }
1496  else if (!(files = KUrl::List::fromMimeData(data)).isEmpty())
1497  {
1498  kDebug() << "URL";
1499  // Try to find the mime type of the file, without downloading a remote file
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());
1503  }
1504  else if (data->hasText())
1505  {
1506  QString text = data->text();
1507  kDebug() << "text";
1508  alarmText.setText(text);
1509  }
1510  else
1511  return;
1512 
1513  if (!alarmText.isEmpty())
1514  {
1515  if (action == KAEvent::MESSAGE
1516  && (alarmText.isEmail() || alarmText.isScript()))
1517  {
1518  // If the alarm text could be interpreted as an email or command script,
1519  // prompt for which type of alarm to create.
1520  QStringList types;
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");
1526  bool ok = false;
1527  QString type = KInputDialog::getItem(i18nc("@title:window", "Alarm Type"),
1528  i18nc("@info", "Choose alarm type to create:"), types, 0, false, &ok, mainMainWindow());
1529  if (!ok)
1530  return; // user didn't press OK
1531  int i = types.indexOf(type);
1532  if (i == 1)
1533  action = alarmText.isEmail() ? KAEvent::EMAIL : KAEvent::COMMAND;
1534  }
1535  KAlarm::editNewAlarm(action, win, &alarmText);
1536  }
1537 }
1538 
1539 /******************************************************************************
1540 * Called when the status of a calendar has changed.
1541 * Enable or disable actions appropriately.
1542 */
1543 void MainWindow::slotCalendarStatusChanged()
1544 {
1545  // Find whether there are any writable calendars
1546 #ifdef USE_AKONADI
1547  bool active = !CollectionControlModel::enabledCollections(CalEvent::ACTIVE, true).isEmpty();
1548  bool templat = !CollectionControlModel::enabledCollections(CalEvent::TEMPLATE, true).isEmpty();
1549 #else
1550  AlarmResources* resources = AlarmResources::instance();
1551  bool active = resources->activeCount(CalEvent::ACTIVE, true);
1552  bool templat = resources->activeCount(CalEvent::TEMPLATE, true);
1553 #endif
1554  for (int i = 0, end = mWindowList.count(); i < end; ++i)
1555  {
1556  MainWindow* w = mWindowList[i];
1557  w->mActionImportAlarms->setEnabled(active || templat);
1558  w->mActionImportBirthdays->setEnabled(active);
1559  w->mActionCreateTemplate->setEnabled(templat);
1560  // Note: w->mActionNew enabled status is set in the NewAlarmAction class.
1561  w->slotSelection();
1562  }
1563 }
1564 
1565 /******************************************************************************
1566 * Called when the selected items in the ListView change.
1567 * Enables the actions appropriately.
1568 */
1569 void MainWindow::slotSelection()
1570 {
1571  // Find which events have been selected
1572 #ifdef USE_AKONADI
1573  QVector<KAEvent> events = mListView->selectedEvents();
1574 #else
1575  KAEvent::List events = mListView->selectedEvents();
1576 #endif
1577  int count = events.count();
1578  if (!count)
1579  {
1580  selectionCleared(); // disable actions
1581  emit selectionChanged();
1582  return;
1583  }
1584 
1585  // Find whether there are any writable resources
1586  bool active = mActionNew->isEnabled();
1587 
1588  bool readOnly = false;
1589  bool allArchived = true;
1590  bool enableReactivate = true;
1591  bool enableEnableDisable = true;
1592  bool enableEnable = false;
1593  bool enableDisable = false;
1594  AlarmCalendar* resources = AlarmCalendar::resources();
1595  KDateTime now = KDateTime::currentUtcDateTime();
1596  for (int i = 0; i < count; ++i)
1597  {
1598 #ifdef USE_AKONADI
1599  KAEvent* ev = resources->event(EventId(events[i])); // get up-to-date status
1600  KAEvent* event = ev ? ev : &events[i];
1601 #else
1602  KAEvent* event = events[i];
1603 #endif
1604  bool expired = event->expired();
1605  if (!expired)
1606  allArchived = false;
1607 #ifdef USE_AKONADI
1608  if (resources->eventReadOnly(event->itemId()))
1609 #else
1610  if (resources->eventReadOnly(event->id()))
1611 #endif
1612  readOnly = true;
1613  if (enableReactivate
1614  && (!expired || !event->occursAfter(now, true)))
1615  enableReactivate = false;
1616  if (enableEnableDisable)
1617  {
1618  if (expired)
1619  enableEnableDisable = enableEnable = enableDisable = false;
1620  else
1621  {
1622  if (!enableEnable && !event->enabled())
1623  enableEnable = true;
1624  if (!enableDisable && event->enabled())
1625  enableDisable = true;
1626  }
1627  }
1628  }
1629 
1630  kDebug() << "true";
1631 #ifdef USE_AKONADI
1632  mActionCreateTemplate->setEnabled((count == 1) && !CollectionControlModel::enabledCollections(CalEvent::TEMPLATE, true).isEmpty());
1633 #else
1634  mActionCreateTemplate->setEnabled((count == 1) && (AlarmResources::instance()->activeCount(CalEvent::TEMPLATE, true) > 0));
1635 #endif
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);
1645 
1646  emit selectionChanged();
1647 }
1648 
1649 /******************************************************************************
1650 * Called when a context menu is requested in the ListView.
1651 * Displays a context menu to modify or delete the selected item.
1652 */
1653 void MainWindow::slotContextMenuRequested(const QPoint& globalPos)
1654 {
1655  kDebug();
1656  if (mContextMenu)
1657  mContextMenu->popup(globalPos);
1658 }
1659 
1660 /******************************************************************************
1661 * Disables actions when no item is selected.
1662 */
1663 void MainWindow::selectionCleared()
1664 {
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);
1673 }
1674 
1675 /******************************************************************************
1676 * Set the text of the Enable/Disable menu action.
1677 */
1678 void MainWindow::setEnableText(bool enable)
1679 {
1680  mActionEnableEnable = enable;
1681  mActionEnable->setText(enable ? i18nc("@action", "Ena&ble") : i18nc("@action", "Disa&ble"));
1682 }
1683 
1684 /******************************************************************************
1685 * Display or hide the specified main window.
1686 * This should only be called when the application doesn't run in the system tray.
1687 */
1688 MainWindow* MainWindow::toggleWindow(MainWindow* win)
1689 {
1690  if (win && mWindowList.indexOf(win) != -1)
1691  {
1692  // A window is specified (and it exists)
1693  if (win->isVisible())
1694  {
1695  // The window is visible, so close it
1696  win->close();
1697  return 0;
1698  }
1699  else
1700  {
1701  // The window is hidden, so display it
1702  win->hide(); // in case it's on a different desktop
1703  win->setWindowState(win->windowState() & ~Qt::WindowMinimized);
1704  win->raise();
1705  win->activateWindow();
1706  return win;
1707  }
1708  }
1709 
1710  // No window is specified, or the window doesn't exist. Open a new one.
1711  win = create();
1712  win->show();
1713  return win;
1714 }
1715 
1716 /******************************************************************************
1717 * Called when the Edit button is clicked in an alarm message window.
1718 * This controls the alarm edit dialog created by the alarm window, and allows
1719 * it to remain unaffected by the alarm window closing.
1720 * See MessageWin::slotEdit() for more information.
1721 */
1722 #ifdef USE_AKONADI
1723 void MainWindow::editAlarm(EditAlarmDlg* dlg, const KAEvent& event)
1724 #else
1725 void MainWindow::editAlarm(EditAlarmDlg* dlg, const KAEvent& event, AlarmResource* resource)
1726 #endif
1727 {
1728 #ifdef USE_AKONADI
1729  mEditAlarmMap[dlg] = event;
1730 #else
1731  KAEvent ev = event;
1732  ev.setResource(resource);
1733  mEditAlarmMap[dlg] = ev;
1734 #endif
1735  connect(dlg, SIGNAL(accepted()), SLOT(editAlarmOk()));
1736  connect(dlg, SIGNAL(destroyed(QObject*)), SLOT(editAlarmDeleted(QObject*)));
1737  dlg->setAttribute(Qt::WA_DeleteOnClose, true); // ensure no memory leaks
1738  dlg->show();
1739 }
1740 
1741 /******************************************************************************
1742 * Called when OK is clicked in the alarm edit dialog shown by editAlarm().
1743 * Updates the event which has been edited.
1744 */
1745 void MainWindow::editAlarmOk()
1746 {
1747  EditAlarmDlg* dlg = qobject_cast<EditAlarmDlg*>(sender());
1748  if (!dlg)
1749  return;
1750  QMap<EditAlarmDlg*, KAEvent>::Iterator it = mEditAlarmMap.find(dlg);
1751  if (it == mEditAlarmMap.end())
1752  return;
1753  KAEvent event = it.value();
1754  mEditAlarmMap.erase(it);
1755  if (!event.isValid())
1756  return;
1757  if (dlg->result() != QDialog::Accepted)
1758  return;
1759 #ifdef USE_AKONADI
1760  Akonadi::Collection c = AkonadiModel::instance()->collection(event);
1761  KAlarm::updateEditedAlarm(dlg, event, c);
1762 #else
1763  KAlarm::updateEditedAlarm(dlg, event, event.resource());
1764 #endif
1765 }
1766 
1767 /******************************************************************************
1768 * Called when the alarm edit dialog shown by editAlarm() is deleted.
1769 * Removes the dialog from the pending list.
1770 */
1771 void MainWindow::editAlarmDeleted(QObject* obj)
1772 {
1773  mEditAlarmMap.remove(static_cast<EditAlarmDlg*>(obj));
1774 }
1775 
1776 // vim: et sw=4:
Undo::emitChanged
static void emitChanged()
Definition: undo.cpp:590
Undo::haveRedo
static bool haveRedo()
Definition: undo.h:103
MainWindow::selectionChanged
void selectionChanged()
synchtimer.h
MainWindow::dropEvent
virtual void dropEvent(QDropEvent *)
Definition: mainwindow.cpp:1365
SHOW_TIME_TO_KEY
static const char * SHOW_TIME_TO_KEY
Definition: mainwindow.cpp:105
templatedlg.h
EventListView::selectedEvent
KAEvent * selectedEvent() const
Definition: eventlistview.cpp:134
MainWindow::hideEvent
virtual void hideEvent(QHideEvent *)
Definition: mainwindow.cpp:445
AlarmListFilterModel
Definition: alarmlistfiltermodel.h:31
AlarmListDelegate
Definition: alarmlistdelegate.h:29
Undo::redo
static bool redo(QWidget *parent, const QString &action)
Definition: undo.h:97
EventListModel::alarms
static EventListModel * alarms()
Definition: eventlistmodel.cpp:56
BirthdayDlg
Definition: birthdaydlg.h:43
Undo::UNDO
Definition: undo.h:47
AlarmListView::selectTimeColumns
void selectTimeColumns(bool time, bool timeTo)
Definition: alarmlistview.cpp:84
AlarmCalendar::importAlarms
static bool importAlarms(QWidget *, AlarmResource *=0)
Definition: alarmcalendar.cpp:875
MainWindow::count
static int count()
Definition: mainwindow.h:101
PreferencesBase::defaultBgColour
static QColor defaultBgColour()
Get Background color.
Definition: kalarmconfig.h:199
undoText
static QString undoText
Definition: mainwindow.cpp:109
AlarmCalendar::eventReadOnly
bool eventReadOnly(const QString &uniqueID) const
Definition: alarmcalendar.cpp:2093
text
virtual QByteArray text(quint32 serialNumber) const =0
newalarmaction.h
KPIM::MailSummary::date
time_t date() const
MainWindow::executeDragEnterEvent
static void executeDragEnterEvent(QDragEnterEvent *)
Definition: mainwindow.cpp:1350
MainWindowBase
The MainWindowBase class is a base class for KAlarm's main window and message window.
Definition: mainwindowbase.h:36
MainWindow::clearSelection
void clearSelection()
Definition: mainwindow.cpp:735
KAlarmApp::wantShowInSystemTray
bool wantShowInSystemTray() const
Definition: kalarmapp.cpp:1140
WakeFromSuspendDlg::create
static WakeFromSuspendDlg * create(QWidget *parent)
Definition: wakedlg.cpp:45
MainWindow::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: mainwindow.cpp:375
AlarmCalendar::resources
static AlarmCalendar * resources()
Definition: alarmcalendar.h:130
alarmlistfiltermodel.h
KAMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Options(Notify|WindowModal))
AlarmListView
Definition: alarmlistview.h:31
redoShortcut
static KShortcut redoShortcut
Definition: mainwindow.cpp:114
redoTextStripped
static QString redoTextStripped
Definition: mainwindow.cpp:113
Undo::description
static QString description(Type, int id)
Definition: undo.cpp:524
alarmcalendar.h
TrayWindow::assocMainWindow
MainWindow * assocMainWindow() const
Definition: traywindow.h:52
NewAlarmAction::fromTemplateAlarmAction
TemplateMenuAction * fromTemplateAlarmAction() const
Definition: newalarmaction.h:41
birthdaydlg.h
AlarmCalendar::resourceForEvent
AlarmResource * resourceForEvent(const QString &eventID) const
Definition: alarmcalendar.cpp:2120
KPIM::MailSummary::from
QString from() const
prefdlg.h
QObject
TrayWindow
Definition: traywindow.h:45
TemplateDlg::create
static TemplateDlg * create(QWidget *parent=0)
Definition: templatedlg.cpp:149
undoTextStripped
static QString undoTextStripped
Definition: mainwindow.cpp:110
Undo::saveDeletes
static void saveDeletes(const EventList &, const QString &name=QString())
Definition: undo.cpp:343
MainWindow::closeEvent
virtual void closeEvent(QCloseEvent *)
Definition: mainwindow.cpp:1328
EventListView::selectedEvents
KAEvent::List selectedEvents() const
Definition: eventlistview.cpp:152
PreferencesBase::archivedKeepDays
static int archivedKeepDays()
Get Days to keep expired alarms.
Definition: kalarmconfig.h:926
MainWindow::i18n_a_ShowAlarmTimes
static QString i18n_a_ShowAlarmTimes()
Definition: mainwindow.cpp:126
MainWindow::closeAll
static void closeAll()
Definition: mainwindow.cpp:319
EventListModel::TimeColumn
Definition: eventlistmodel.h:47
MainWindow::isTrayParent
bool isTrayParent() const
Definition: mainwindow.cpp:306
kalarmapp.h
the KAlarm application object
Undo::Type
Type
Definition: undo.h:47
Undo::saveAdds
static void saveAdds(const EventList &, const QString &name=QString())
Definition: undo.cpp:317
Undo::EventList
Definition: undo.h:67
TrayWindow::removeWindow
void removeWindow(MainWindow *)
Definition: traywindow.cpp:443
MainWindow::editAlarm
void editAlarm(EditAlarmDlg *, const KAEvent &, AlarmResource *)
Definition: mainwindow.cpp:1725
KAlarmApp::quitIf
bool quitIf()
Definition: kalarmapp.h:69
KPIM::MailList::fromMimeData
static MailList fromMimeData(const QMimeData *md)
templatepickdlg.h
Undo::ids
static QList< int > ids(Type)
Definition: undo.cpp:536
TrayWindow::setAssocMainWindow
void setAssocMainWindow(MainWindow *win)
Definition: traywindow.h:53
redoText
static QString redoText
Definition: mainwindow.cpp:112
autoqpointer.h
Preferences::timeZone
static KTimeZone timeZone(bool reload=false)
Definition: preferences.cpp:122
maillistdrag.h
AlarmListView::setModel
virtual void setModel(QAbstractItemModel *)
Definition: alarmlistview.cpp:49
NewAlarmAction::emailAlarmAction
KAction * emailAlarmAction() const
Definition: newalarmaction.h:39
AkonadiModel::instance
static AkonadiModel * instance()
Definition: akonadimodel.cpp:83
KAlarmPrefDlg::display
static void display()
Definition: prefdlg.cpp:129
MainWindow::selectEvent
void selectEvent(const QString &eventID)
Definition: mainwindow.cpp:704
UI_FILE
static const QString UI_FILE
Definition: mainwindow.cpp:100
EventListModel::reload
void reload()
Definition: eventlistmodel.cpp:679
KPIM::MailSummary::to
QString to() const
KPIM::MailSummary::subject
QString subject() const
WINDOW_NAME
static const char * WINDOW_NAME
Definition: mainwindow.cpp:101
eventlistmodel.h
KAlarmApp::checkCalendar
bool checkCalendar()
Definition: kalarmapp.h:61
AkonadiModel::Change
Change
Definition: akonadimodel.h:52
MainWindow::create
static MainWindow * create(bool restored=false)
Definition: mainwindow.cpp:137
NewAlarmAction::audioAlarmAction
KAction * audioAlarmAction() const
Definition: newalarmaction.h:40
messagebox.h
TemplateDlg
Definition: templatedlg.h:37
QMimeData
canDecode
static bool canDecode(const QMimeData *md)
SHOW_ARCHIVED_KEY
static const char * SHOW_ARCHIVED_KEY
Definition: mainwindow.cpp:106
theApp
KAlarmApp * theApp()
Definition: kalarmapp.h:259
MainWindow::readProperties
virtual void readProperties(const KConfigGroup &)
Definition: mainwindow.cpp:273
Undo::undo
static bool undo(QWidget *parent, const QString &action)
Definition: undo.h:93
ResourceSelector
This class provides a view of alarm calendar resources.
Definition: resourceselector.h:70
AutoQPointer
MainWindow::toggleWindow
static MainWindow * toggleWindow(MainWindow *)
Definition: mainwindow.cpp:1688
preferences.h
Preferences::connect
static void connect(const char *signal, const QObject *receiver, const char *member)
Definition: preferences.cpp:292
CollectionControlModel::enabledCollections
static Akonadi::Collection::List enabledCollections(CalEvent::Type, bool writable)
Return the enabled collections which contain a specified mime type.
Definition: collectionmodel.cpp:1227
NewAlarmAction::commandAlarmAction
KAction * commandAlarmAction() const
Definition: newalarmaction.h:38
templatemenuaction.h
MainWindow::i18n_o_ShowTimeToAlarms
static QString i18n_o_ShowTimeToAlarms()
Definition: mainwindow.cpp:128
QMenu
EventListModel::TimeToColumn
Definition: eventlistmodel.h:47
Preferences::CONFIRM_ALARM_DELETION
static const QLatin1String CONFIRM_ALARM_DELETION
Definition: preferences.h:86
SHOW_TIME_KEY
static const char * SHOW_TIME_KEY
Definition: mainwindow.cpp:104
kamail.h
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
KAMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, ButtonCode defaultButton, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const QString &dontAskAgainName=QString())
Undo::REDO
Definition: undo.h:47
Undo::saveReactivates
static void saveReactivates(const EventList &, const QString &name=QString())
Definition: undo.cpp:363
KPIM::MailSummary
traywindow.h
EditAlarmDlg::Type
Type
Definition: editdlg.h:65
MainWindow::eventFilter
virtual bool eventFilter(QObject *, QEvent *)
Definition: mainwindow.cpp:328
functions.h
miscellaneous functions
EditAlarmDlg
Definition: editdlg.h:61
Undo::haveUndo
static bool haveUndo()
Definition: undo.h:102
wakedlg.h
KPIM::MailList
VIEW_GROUP
static const char * VIEW_GROUP
Definition: mainwindow.cpp:103
PreferencesBase::defaultFgColour
static QColor defaultFgColour()
Get Foreground color.
Definition: kalarmconfig.h:172
alarmlistview.h
AkonadiModel::reload
void reload()
Reload all collections' data from Akonadi storage (not from the backend).
Definition: akonadimodel.cpp:1116
AkonadiModel::collection
Akonadi::Collection collection(const KAEvent &e) const
Definition: akonadimodel.h:124
MainWindow::i18n_chk_ShowAlarmTime
static QString i18n_chk_ShowAlarmTime()
Definition: mainwindow.cpp:127
kalarm.h
ResourceSelector::initActions
void initActions(KActionCollection *)
Definition: resourceselector.cpp:513
KAlarmApp::trayWindow
TrayWindow * trayWindow() const
Definition: kalarmapp.h:74
getMailHeader
static QString getMailHeader(const char *header, KMime::Content &content)
Definition: mainwindow.cpp:1370
MainWindow::executeDropEvent
static void executeDropEvent(MainWindow *, QDropEvent *)
Definition: mainwindow.cpp:1380
MainWindow::refresh
static void refresh()
Definition: mainwindow.cpp:676
KAlarmApp::displayTrayIcon
bool displayTrayIcon(bool show, MainWindow *=0)
Definition: kalarmapp.cpp:977
resourceselector.h
AlarmListModel::TimeToColumn
Definition: itemlistmodel.h:92
EventListView::clearSelection
void clearSelection()
Definition: eventlistview.cpp:102
Undo::actionText
static QString actionText(Type)
Definition: undo.cpp:506
AlarmCalendar
Provides read and write access to calendar files and resources.
Definition: alarmcalendar.h:58
NewAlarmAction
Definition: newalarmaction.h:31
MainWindow::~MainWindow
~MainWindow()
Definition: mainwindow.cpp:232
AlarmListFilterModel::setStatusFilter
void setStatusFilter(CalEvent::Types)
Definition: alarmlistfiltermodel.cpp:38
AlarmCalendar::exportAlarms
static bool exportAlarms(const KAEvent::List &, QWidget *parent)
Definition: alarmcalendar.cpp:1077
serialNumber
quint32 serialNumber() const
AlarmCalendar::event
KAEvent * event(const QString &uniqueId)
Definition: alarmcalendar.cpp:1820
MainWindow::show
virtual void show()
Definition: mainwindow.cpp:429
Preferences::confirmAlarmDeletion
static bool confirmAlarmDeletion()
Definition: preferences.h:65
undoShortcut
static KShortcut undoShortcut
Definition: mainwindow.cpp:111
alarmlistdelegate.h
MainWindow::mainMainWindow
static MainWindow * mainMainWindow()
Definition: mainwindow.cpp:288
Undo::EventList::append
void append(const KAEvent &e, AlarmResource *r)
Definition: undo.h:73
ResourceSelector::setContextMenu
void setContextMenu(KMenu *)
Definition: resourceselector.cpp:557
Undo::instance
static Undo * instance()
Definition: undo.cpp:283
MainWindow::saveProperties
virtual void saveProperties(KConfigGroup &)
Definition: mainwindow.cpp:259
SHOW_RESOURCES_KEY
static const char * SHOW_RESOURCES_KEY
Definition: mainwindow.cpp:107
MainWindow
Definition: mainwindow.h:71
KAlarmApp::doQuit
void doQuit(QWidget *parent)
Definition: kalarmapp.cpp:684
AlarmListModel
Definition: itemlistmodel.h:87
AlarmListModel::TimeColumn
Definition: itemlistmodel.h:92
MainWindow::i18n_chk_ShowTimeToAlarm
static QString i18n_chk_ShowTimeToAlarm()
Definition: mainwindow.cpp:129
NewAlarmAction::displayAlarmAction
KAction * displayAlarmAction() const
Definition: newalarmaction.h:37
QList
MainWindow::selectedEvent
KAEvent * selectedEvent() const
Definition: mainwindow.cpp:726
MainWindow::showEvent
virtual void showEvent(QShowEvent *)
Definition: mainwindow.cpp:413
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal