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

kalarm

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

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