23 #include <tqiconset.h>
24 #include <tqdragobject.h>
27 #include <tdemenubar.h>
28 #include <tdetoolbar.h>
29 #include <tdepopupmenu.h>
31 #include <tdeaction.h>
32 #include <tdeactionclasses.h>
33 #include <kstdaction.h>
34 #include <kiconloader.h>
35 #include <tdemessagebox.h>
37 #include <tdelocale.h>
38 #include <tdeglobalsettings.h>
39 #include <tdeconfig.h>
40 #include <kkeydialog.h>
41 #include <kedittoolbar.h>
42 #include <tdeaboutdata.h>
43 #include <dcopclient.h>
46 #include <libtdepim/maillistdrag.h>
47 #include <libkmime/kmime_content.h>
48 #include <libkcal/calendarlocal.h>
49 #include <libkcal/icaldrag.h>
51 #include "alarmcalendar.h"
53 #include "alarmlistview.h"
54 #include "alarmtext.h"
55 #include "birthdaydlg.h"
62 #include "preferences.h"
63 #include "synchtimer.h"
64 #include "templatepickdlg.h"
65 #include "templatedlg.h"
66 #include "traywindow.h"
67 #include "mainwindow.moc"
71 static const char* UI_FILE =
"kalarmui.rc";
72 static const char* WINDOW_NAME =
"MainWindow";
74 static const TQString VIEW_GROUP = TQString::fromLatin1(
"View");
75 static const TQString SHOW_TIME_KEY = TQString::fromLatin1(
"ShowAlarmTime");
76 static const TQString SHOW_TIME_TO_KEY = TQString::fromLatin1(
"ShowTimeToAlarm");
77 static const TQString SHOW_ARCHIVED_KEY = TQString::fromLatin1(
"ShowArchivedAlarms");
78 static const TQString SHOW_RESOURCES_KEY = TQString::fromLatin1(
"ShowResources");
80 static TQString undoText;
81 static TQString undoTextStripped;
82 static TQString undoIcon;
83 static TDEShortcut undoShortcut;
84 static TQString redoText;
85 static TQString redoTextStripped;
86 static TQString redoIcon;
87 static TDEShortcut redoShortcut;
94 MainWindow::WindowList MainWindow::mWindowList;
95 TemplateDlg* MainWindow::mTemplateDlg = 0;
99 TQString MainWindow::i18n_a_ShowAlarmTimes() {
return i18n(
"Show &Alarm Times"); }
100 TQString MainWindow::i18n_m_ShowAlarmTime() {
return i18n(
"Show alarm ti&me"); }
101 TQString MainWindow::i18n_o_ShowTimeToAlarms() {
return i18n(
"Show Time t&o Alarms"); }
102 TQString MainWindow::i18n_l_ShowTimeToAlarm() {
return i18n(
"Show time unti&l alarm"); }
103 TQString MainWindow::i18n_ShowExpiredAlarms() {
return i18n(
"Show Expired Alarms"); }
104 TQString MainWindow::i18n_e_ShowExpiredAlarms() {
return i18n(
"Show &Expired Alarms"); }
105 TQString MainWindow::i18n_HideExpiredAlarms() {
return i18n(
"Hide Expired Alarms"); }
106 TQString MainWindow::i18n_e_HideExpiredAlarms() {
return i18n(
"Hide &Expired Alarms"); }
114 MainWindow* MainWindow::create(
bool restored)
116 theApp()->checkCalendarDaemon();
117 return new MainWindow(restored);
120 MainWindow::MainWindow(
bool restored)
121 :
MainWindowBase(0,
"MainWin", WGroupLeader | WStyle_ContextHelp | WDestructiveClose),
122 mMinuteTimerActive(false),
123 mHiddenTrayParent(false)
125 kdDebug(5950) <<
"MainWindow::MainWindow()\n";
126 setAutoSaveSettings(TQString::fromLatin1(WINDOW_NAME));
127 setPlainCaption(kapp->aboutData()->programName());
128 TDEConfig* config = TDEGlobal::config();
129 config->setGroup(VIEW_GROUP);
130 mShowExpired = config->readBoolEntry(SHOW_ARCHIVED_KEY,
false);
131 mShowTime = config->readBoolEntry(SHOW_TIME_KEY,
true);
132 mShowTimeTo = config->readBoolEntry(SHOW_TIME_TO_KEY,
false);
136 if (KAlarm::readConfigWindowSize(WINDOW_NAME, s))
139 config->setGroup(TQString::fromLatin1(WINDOW_NAME));
140 TQValueList<int> order = config->readIntListEntry(TQString::fromLatin1(
"ColumnOrder"));
142 setAcceptDrops(
true);
145 mListView =
new AlarmListView(order,
this,
"listView");
146 mListView->selectTimeColumns(mShowTime, mShowTimeTo);
147 mListView->showExpired(mShowExpired);
148 setCentralWidget(mListView);
149 mListView->refresh();
150 mListView->clearSelection();
152 connect(mListView, TQ_SIGNAL(itemDeleted()), TQ_SLOT(slotDeletion()));
153 connect(mListView, TQ_SIGNAL(selectionChanged()), TQ_SLOT(slotSelection()));
154 connect(mListView, TQ_SIGNAL(contextMenuRequested(TQListViewItem*,
const TQPoint&,
int)),
155 TQ_SLOT(slotContextMenuRequested(TQListViewItem*,
const TQPoint&,
int)));
156 connect(mListView, TQ_SIGNAL(mouseButtonClicked(
int, TQListViewItem*,
const TQPoint&,
int)),
157 TQ_SLOT(slotMouseClicked(
int, TQListViewItem*,
const TQPoint&,
int)));
158 connect(mListView, TQ_SIGNAL(executed(TQListViewItem*)), TQ_SLOT(slotDoubleClicked(TQListViewItem*)));
159 connect(mListView->header(), TQ_SIGNAL(indexChange(
int,
int,
int)), TQ_SLOT(columnsReordered()));
162 mWindowList.append(
this);
163 if (mWindowList.count() == 1 && Daemon::isDcopHandlerReady())
166 if (theApp()->wantRunInSystemTray())
167 theApp()->displayTrayIcon(
true,
this);
168 else if (theApp()->trayWindow())
169 theApp()->trayWindow()->setAssocMainWindow(
this);
174 MainWindow::~MainWindow()
176 kdDebug(5950) <<
"MainWindow::~MainWindow()\n";
177 mWindowList.remove(
this);
178 if (theApp()->trayWindow())
181 delete theApp()->trayWindow();
183 theApp()->trayWindow()->removeWindow(
this);
185 MinuteTimer::disconnect(
this);
186 mMinuteTimerActive =
false;
188 MainWindow* main = mainMainWindow();
190 KAlarm::writeConfigWindowSize(WINDOW_NAME, main->size());
191 TDEToolBar* tb = toolBar();
193 tb->saveSettings(TDEGlobal::config(),
"Toolbars");
194 TDEGlobal::config()->sync();
202 void MainWindow::saveProperties(TDEConfig* config)
204 config->writeEntry(TQString::fromLatin1(
"HiddenTrayParent"), isTrayParent() && isHidden());
205 config->writeEntry(TQString::fromLatin1(
"ShowExpired"), mShowExpired);
206 config->writeEntry(TQString::fromLatin1(
"ShowTime"), mShowTime);
207 config->writeEntry(TQString::fromLatin1(
"ShowTimeTo"), mShowTimeTo);
215 void MainWindow::readProperties(TDEConfig* config)
217 mHiddenTrayParent = config->readBoolEntry(TQString::fromLatin1(
"HiddenTrayParent"));
218 mShowExpired = config->readBoolEntry(TQString::fromLatin1(
"ShowExpired"));
219 mShowTime = config->readBoolEntry(TQString::fromLatin1(
"ShowTime"));
220 mShowTimeTo = config->readBoolEntry(TQString::fromLatin1(
"ShowTimeTo"));
228 MainWindow* MainWindow::mainMainWindow()
230 MainWindow* tray = theApp()->trayWindow() ? theApp()->trayWindow()->assocMainWindow() : 0;
231 if (tray && tray->isVisible())
233 for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
234 if ((*it)->isVisible())
238 if (mWindowList.isEmpty())
240 return mWindowList.first();
246 bool MainWindow::isTrayParent()
const
248 return theApp()->wantRunInSystemTray() && theApp()->trayMainWindow() ==
this;
254 void MainWindow::closeAll()
256 while (!mWindowList.isEmpty())
257 delete mWindowList.first();
266 void MainWindow::resizeEvent(TQResizeEvent* re)
269 if (mainMainWindow() ==
this)
270 KAlarm::writeConfigWindowSize(WINDOW_NAME, re->size());
271 MainWindowBase::resizeEvent(re);
279 void MainWindow::showEvent(TQShowEvent* se)
283 MainWindowBase::showEvent(se);
289 void MainWindow::show()
291 MainWindowBase::show();
297 KMessageBox::error(
this, i18n(
"Failure to create menus\n(perhaps %1 missing or corrupted)").arg(TQString::fromLatin1(UI_FILE)));
305 void MainWindow::hideEvent(TQHideEvent* he)
308 MainWindowBase::hideEvent(he);
315 void MainWindow::columnsReordered()
317 TDEConfig* config = TDEGlobal::config();
318 config->setGroup(TQString::fromLatin1(WINDOW_NAME));
319 config->writeEntry(TQString::fromLatin1(
"ColumnOrder"), mListView->columnOrder());
326 void MainWindow::initActions()
328 TDEActionCollection* actions = actionCollection();
329 mActionTemplates =
new TDEAction(i18n(
"&Templates..."), 0,
this, TQ_SLOT(slotTemplates()), actions,
"templates");
330 mActionNew = KAlarm::createNewAlarmAction(i18n(
"&New..."),
this, TQ_SLOT(slotNew()), actions,
"new");
331 mActionNewFromTemplate = KAlarm::createNewFromTemplateAction(i18n(
"New &From Template"),
this, TQ_SLOT(slotNewFromTemplate(
const KAEvent&)), actions,
"newFromTempl");
332 mActionCreateTemplate =
new TDEAction(i18n(
"Create Tem&plate..."), 0,
this, TQ_SLOT(slotNewTemplate()), actions,
"createTemplate");
333 mActionCopy =
new TDEAction(i18n(
"&Copy..."),
"edit-copy", TQt::SHIFT+TQt::Key_Insert,
this, TQ_SLOT(slotCopy()), actions,
"copy");
334 mActionModify =
new TDEAction(i18n(
"&Edit..."),
"edit", TQt::CTRL+TQt::Key_E,
this, TQ_SLOT(slotModify()), actions,
"modify");
335 mActionDelete =
new TDEAction(i18n(
"&Delete"),
"edit-delete", TQt::Key_Delete,
this, TQ_SLOT(slotDelete()), actions,
"delete");
336 mActionReactivate =
new TDEAction(i18n(
"Reac&tivate"), 0, TQt::CTRL+TQt::Key_R,
this, TQ_SLOT(slotReactivate()), actions,
"undelete");
337 mActionEnable =
new TDEAction(TQString(), 0, TQt::CTRL+TQt::Key_B,
this, TQ_SLOT(slotEnable()), actions,
"disable");
338 mActionView =
new TDEAction(i18n(
"&View"),
"viewmag", TQt::CTRL+TQt::Key_W,
this, TQ_SLOT(slotView()), actions,
"view");
339 mActionShowTime =
new TDEToggleAction(i18n_a_ShowAlarmTimes(), TQt::CTRL+TQt::Key_M,
this, TQ_SLOT(slotShowTime()), actions,
"showAlarmTimes");
340 mActionShowTime->setCheckedState(i18n(
"Hide &Alarm Times"));
341 mActionShowTimeTo =
new TDEToggleAction(i18n_o_ShowTimeToAlarms(), TQt::CTRL+TQt::Key_I,
this, TQ_SLOT(slotShowTimeTo()), actions,
"showTimeToAlarms");
342 mActionShowTimeTo->setCheckedState(i18n(
"Hide Time t&o Alarms"));
343 mActionShowExpired =
new TDEToggleAction(i18n_e_ShowExpiredAlarms(),
"history", TQt::CTRL+TQt::Key_P,
this, TQ_SLOT(slotShowExpired()), actions,
"showExpiredAlarms");
344 mActionShowExpired->setCheckedState(i18n_e_HideExpiredAlarms());
345 mActionToggleTrayIcon =
new TDEToggleAction(i18n(
"Show in System &Tray"), 0,
this, TQ_SLOT(slotToggleTrayIcon()), actions,
"showInSystemTray");
346 mActionToggleTrayIcon->setCheckedState(i18n(
"Hide From System &Tray"));
347 new TDEAction(i18n(
"Import &Alarms..."), 0,
this, TQ_SLOT(slotImportAlarms()), actions,
"importAlarms");
348 new TDEAction(i18n(
"Import &Birthdays..."), 0,
this, TQ_SLOT(slotBirthdays()), actions,
"importBirthdays");
349 new TDEAction(i18n(
"&Refresh Alarms"),
"reload", 0,
this, TQ_SLOT(slotResetDaemon()), actions,
"refreshAlarms");
350 Daemon::createAlarmEnableAction(actions,
"alarmEnable");
351 if (undoText.isNull())
354 TDEAction* act = KStdAction::undo(
this, 0, actions);
355 undoIcon = act->icon();
356 undoShortcut = act->shortcut();
357 undoText = act->text();
358 undoTextStripped = KAlarm::stripAccel(undoText);
360 act = KStdAction::redo(
this, 0, actions);
361 redoIcon = act->icon();
362 redoShortcut = act->shortcut();
363 redoText = act->text();
364 redoTextStripped = KAlarm::stripAccel(redoText);
367 mActionUndo =
new TDEToolBarPopupAction(undoText, undoIcon, undoShortcut,
this, TQ_SLOT(slotUndo()), actions,
"edit_undo");
368 mActionRedo =
new TDEToolBarPopupAction(redoText, redoIcon, redoShortcut,
this, TQ_SLOT(slotRedo()), actions,
"edit_redo");
369 KStdAction::find(mListView, TQ_SLOT(slotFind()), actions);
370 mActionFindNext = KStdAction::findNext(mListView, TQ_SLOT(slotFindNext()), actions);
371 mActionFindPrev = KStdAction::findPrev(mListView, TQ_SLOT(slotFindPrev()), actions);
372 KStdAction::selectAll(mListView, TQ_SLOT(slotSelectAll()), actions);
373 KStdAction::deselect(mListView, TQ_SLOT(slotDeselect()), actions);
374 KStdAction::quit(
this, TQ_SLOT(slotQuit()), actions);
375 KStdAction::keyBindings(
this, TQ_SLOT(slotConfigureKeys()), actions);
376 KStdAction::configureToolbars(
this, TQ_SLOT(slotConfigureToolbar()), actions);
377 KStdAction::preferences(
this, TQ_SLOT(slotPreferences()), actions);
378 setStandardToolBarMenuEnabled(
true);
381 mContextMenu =
static_cast<TDEPopupMenu*
>(factory()->container(
"listContext",
this));
382 mActionsMenu =
static_cast<TDEPopupMenu*
>(factory()->container(
"actions",
this));
383 mMenuError = (!mContextMenu || !mActionsMenu);
384 connect(mActionsMenu, TQ_SIGNAL(aboutToShow()), TQ_SLOT(updateActionsMenu()));
385 connect(mActionUndo->popupMenu(), TQ_SIGNAL(aboutToShow()), TQ_SLOT(slotInitUndoMenu()));
386 connect(mActionUndo->popupMenu(), TQ_SIGNAL(activated(
int)), TQ_SLOT(slotUndoItem(
int)));
387 connect(mActionRedo->popupMenu(), TQ_SIGNAL(aboutToShow()), TQ_SLOT(slotInitRedoMenu()));
388 connect(mActionRedo->popupMenu(), TQ_SIGNAL(activated(
int)), TQ_SLOT(slotRedoItem(
int)));
389 connect(Undo::instance(), TQ_SIGNAL(changed(
const TQString&,
const TQString&)), TQ_SLOT(slotUndoStatus(
const TQString&,
const TQString&)));
390 connect(mListView, TQ_SIGNAL(findActive(
bool)), TQ_SLOT(slotFindActive(
bool)));
391 Preferences::connect(TQ_SIGNAL(preferencesChanged()),
this, TQ_SLOT(slotPrefsChanged()));
392 connect(theApp(), TQ_SIGNAL(trayIconToggled()), TQ_SLOT(updateTrayIconAction()));
396 mActionShowTime->setChecked(mShowTime);
397 mActionShowTimeTo->setChecked(mShowTimeTo);
398 mActionShowExpired->setChecked(mShowExpired);
400 mActionUndo->setEnabled(Undo::haveUndo());
401 mActionRedo->setEnabled(Undo::haveRedo());
402 mActionFindNext->setEnabled(
false);
403 mActionFindPrev->setEnabled(
false);
405 mActionCopy->setEnabled(
false);
406 mActionModify->setEnabled(
false);
407 mActionDelete->setEnabled(
false);
408 mActionReactivate->setEnabled(
false);
409 mActionView->setEnabled(
false);
410 mActionEnable->setEnabled(
false);
411 mActionCreateTemplate->setEnabled(
false);
413 TDEToolBar* tb = toolBar();
415 tb->applySettings(TDEGlobal::config(),
"Toolbars");
418 Daemon::checkStatus();
419 Daemon::monitoringAlarms();
425 void MainWindow::enableTemplateMenuItem(
bool enable)
427 for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
428 (*it)->mActionTemplates->setEnabled(enable);
434 void MainWindow::refresh()
436 kdDebug(5950) <<
"MainWindow::refresh()\n";
437 for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
438 (*it)->mListView->refresh();
446 void MainWindow::updateExpired()
448 kdDebug(5950) <<
"MainWindow::updateExpired()\n";
449 bool enableShowExpired = Preferences::expiredKeepDays();
450 for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
455 if (!enableShowExpired)
456 w->slotShowExpired();
458 w->mListView->refresh();
460 w->mActionShowExpired->setEnabled(enableShowExpired);
469 void MainWindow::setUpdateTimer()
472 MainWindow* needTimer = 0;
473 MainWindow* timerWindow = 0;
474 for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
477 if (w->isVisible() && w->mListView->showingTimeTo())
479 if (w->mMinuteTimerActive)
484 if (needTimer && !timerWindow)
487 needTimer->mMinuteTimerActive =
true;
488 MinuteTimer::connect(needTimer, TQ_SLOT(slotUpdateTimeTo()));
489 kdDebug(5950) <<
"MainWindow::setUpdateTimer(): started timer" << endl;
491 else if (!needTimer && timerWindow)
493 timerWindow->mMinuteTimerActive =
false;
494 MinuteTimer::disconnect(timerWindow);
495 kdDebug(5950) <<
"MainWindow::setUpdateTimer(): stopped timer" << endl;
501 void MainWindow::slotUpdateTimeTo()
503 kdDebug(5950) <<
"MainWindow::slotUpdateTimeTo()" << endl;
504 for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
507 if (w->isVisible() && w->mListView->showingTimeTo())
508 w->mListView->updateTimeToAlarms();
515 void MainWindow::selectEvent(
const TQString& eventID)
517 mListView->clearSelection();
518 AlarmListViewItem* item = mListView->getEntry(eventID);
521 mListView->setSelected(item,
true);
522 mListView->setCurrentItem(item);
523 mListView->ensureItemVisible(item);
530 void MainWindow::slotNew()
539 void MainWindow::executeNew(MainWindow* win,
const KAEvent* evnt, KAEvent::Action action,
const AlarmText& text)
541 EditAlarmDlg editDlg(
false, i18n(
"New Alarm"), win, 0, evnt);
543 editDlg.setAction(action, text);
544 if (editDlg.exec() == TQDialog::Accepted)
547 editDlg.getEvent(event);
550 if (KAlarm::addEvent(event, (win ? win->mListView : 0), &editDlg) == KAlarm::UPDATE_KORG_ERR)
551 KAlarm::displayKOrgUpdateError(&editDlg, KAlarm::KORG_ERR_ADD, 1);
552 Undo::saveAdd(event);
554 KAlarm::outputAlarmWarnings(&editDlg, &event);
562 void MainWindow::slotNewFromTemplate(
const KAEvent& tmplate)
564 executeNew(
this, &tmplate);
571 void MainWindow::slotNewTemplate()
573 AlarmListViewItem* item = mListView->selectedItem();
577 TemplateDlg::createTemplate(&event,
this);
585 void MainWindow::slotCopy()
587 AlarmListViewItem* item = mListView->selectedItem();
589 executeNew(
this, &item->event());
596 void MainWindow::slotModify()
598 AlarmListViewItem* item = mListView->selectedItem();
602 executeEdit(event,
this);
609 void MainWindow::executeEdit(
KAEvent& event, MainWindow* win)
611 EditAlarmDlg editDlg(
false, i18n(
"Edit Alarm"), win, 0, &event);
612 if (editDlg.exec() == TQDialog::Accepted)
615 bool changeDeferral = !editDlg.getEvent(newEvent);
618 AlarmListView*
view = win ? win->mListView : 0;
622 if (KAlarm::updateEvent(newEvent, view, &editDlg,
true,
false) != KAlarm::UPDATE_OK)
627 if (KAlarm::modifyEvent(event, newEvent, view, &editDlg) == KAlarm::UPDATE_KORG_ERR)
628 KAlarm::displayKOrgUpdateError(&editDlg, KAlarm::KORG_ERR_MODIFY, 1);
630 Undo::saveEdit(event, newEvent);
632 KAlarm::outputAlarmWarnings(&editDlg, &newEvent);
640 void MainWindow::slotView()
642 AlarmListViewItem* item = mListView->selectedItem();
646 EditAlarmDlg editDlg(
false, (event.expired() ? i18n(
"Expired Alarm") +
" [" + i18n(
"read-only") +
']'
647 : i18n(
"View Alarm")),
648 this, 0, &event,
true);
657 void MainWindow::slotDelete()
659 TQValueList<EventListViewItemBase*> items = mListView->selectedItems();
662 TQValueList<KAEvent> events;
663 TQValueList<KAEvent> origEvents;
664 for (TQValueList<EventListViewItemBase*>::Iterator iit = items.begin(); iit != items.end(); ++iit)
666 AlarmListViewItem* item = (AlarmListViewItem*)(*iit);
667 events.append(item->event());
668 origEvents.append(item->event());
670 if (Preferences::confirmAlarmDeletion())
672 int n = items.count();
673 if (KMessageBox::warningContinueCancel(
this, i18n(
"Do you really want to delete the selected alarm?",
674 "Do you really want to delete the %n selected alarms?", n),
675 i18n(
"Delete Alarm",
"Delete Alarms", n),
676 KGuiItem(i18n(
"&Delete"),
"edit-delete"),
677 Preferences::CONFIRM_ALARM_DELETION)
678 != KMessageBox::Continue)
684 AlarmCalendar::activeCalendar()->startUpdate();
685 AlarmCalendar::expiredCalendar()->startUpdate();
686 for (TQValueList<KAEvent>::Iterator it = events.begin(); it != events.end(); ++it)
689 switch (KAlarm::deleteEvent(*it))
691 case KAlarm::UPDATE_ERROR:
692 case KAlarm::UPDATE_FAILED:
693 case KAlarm::SAVE_FAILED:
696 case KAlarm::UPDATE_KORG_ERR:
703 if (!AlarmCalendar::activeCalendar()->endUpdate())
704 warnErr = events.count();
705 AlarmCalendar::expiredCalendar()->endUpdate();
706 Undo::saveDeletes(origEvents);
709 KAlarm::displayUpdateError(
this, KAlarm::UPDATE_FAILED, KAlarm::ERR_DELETE, warnErr);
711 KAlarm::displayKOrgUpdateError(
this, KAlarm::KORG_ERR_DELETE, warnKOrg);
718 void MainWindow::slotReactivate()
722 TQValueList<KAEvent> events;
723 TQValueList<EventListViewItemBase*> items = mListView->selectedItems();
724 mListView->clearSelection();
725 AlarmCalendar::activeCalendar()->startUpdate();
726 AlarmCalendar::expiredCalendar()->startUpdate();
727 for (TQValueList<EventListViewItemBase*>::Iterator it = items.begin(); it != items.end(); ++it)
730 AlarmListViewItem* item = (AlarmListViewItem*)(*it);
732 events.append(event);
733 switch (KAlarm::reactivateEvent(event, mListView,
true))
735 case KAlarm::UPDATE_ERROR:
736 case KAlarm::UPDATE_FAILED:
737 case KAlarm::SAVE_FAILED:
740 case KAlarm::UPDATE_KORG_ERR:
747 if (!AlarmCalendar::activeCalendar()->endUpdate())
748 warnErr = items.count();
749 AlarmCalendar::expiredCalendar()->endUpdate();
750 Undo::saveReactivates(events);
753 KAlarm::displayUpdateError(
this, KAlarm::UPDATE_FAILED, KAlarm::ERR_REACTIVATE, warnErr);
755 KAlarm::displayKOrgUpdateError(
this, KAlarm::KORG_ERR_ADD, warnKOrg);
762 void MainWindow::slotEnable()
764 bool enable = mActionEnableEnable;
766 TQValueList<EventListViewItemBase*> items = mListView->selectedItems();
767 AlarmCalendar::activeCalendar()->startUpdate();
768 for (TQValueList<EventListViewItemBase*>::Iterator it = items.begin(); it != items.end(); ++it)
770 AlarmListViewItem* item = (AlarmListViewItem*)(*it);
774 if (KAlarm::enableEvent(event, mListView, enable) != KAlarm::UPDATE_OK)
777 if (!AlarmCalendar::activeCalendar()->endUpdate())
778 warnErr = items.count();
780 KAlarm::displayUpdateError(
this, KAlarm::UPDATE_FAILED, KAlarm::ERR_ADD, warnErr);
786 void MainWindow::slotShowTime()
788 mShowTime = !mShowTime;
789 mActionShowTime->setChecked(mShowTime);
790 if (!mShowTime && !mShowTimeTo)
794 mListView->selectTimeColumns(mShowTime, mShowTimeTo);
795 TDEConfig* config = TDEGlobal::config();
796 config->setGroup(VIEW_GROUP);
797 config->writeEntry(SHOW_TIME_KEY, mShowTime);
798 config->writeEntry(SHOW_TIME_TO_KEY, mShowTimeTo);
805 void MainWindow::slotShowTimeTo()
807 mShowTimeTo = !mShowTimeTo;
808 mActionShowTimeTo->setChecked(mShowTimeTo);
809 if (!mShowTimeTo && !mShowTime)
813 mListView->selectTimeColumns(mShowTime, mShowTimeTo);
814 TDEConfig* config = TDEGlobal::config();
815 config->setGroup(VIEW_GROUP);
816 config->writeEntry(SHOW_TIME_KEY, mShowTime);
817 config->writeEntry(SHOW_TIME_TO_KEY, mShowTimeTo);
825 void MainWindow::slotShowExpired()
827 mShowExpired = !mShowExpired;
828 mActionShowExpired->setChecked(mShowExpired);
829 mActionShowExpired->setToolTip(mShowExpired ? i18n_HideExpiredAlarms() : i18n_ShowExpiredAlarms());
830 mListView->showExpired(mShowExpired);
831 mListView->refresh();
832 TDEConfig* config = TDEGlobal::config();
833 config->setGroup(VIEW_GROUP);
834 config->writeEntry(SHOW_ARCHIVED_KEY, mShowExpired);
841 void MainWindow::slotImportAlarms()
843 if (AlarmCalendar::importAlarms(
this))
844 mListView->refresh();
851 void MainWindow::slotBirthdays()
853 BirthdayDlg dlg(
this);
854 if (dlg.exec() == TQDialog::Accepted)
856 TQValueList<KAEvent> events = dlg.events();
859 mListView->clearSelection();
862 for (TQValueList<KAEvent>::Iterator ev = events.begin(); ev != events.end(); ++ev)
865 switch (KAlarm::addEvent(*ev, mListView))
867 case KAlarm::UPDATE_ERROR:
868 case KAlarm::UPDATE_FAILED:
869 case KAlarm::SAVE_FAILED:
872 case KAlarm::UPDATE_KORG_ERR:
880 KAlarm::displayUpdateError(
this, KAlarm::UPDATE_FAILED, KAlarm::ERR_ADD, warnErr);
882 KAlarm::displayKOrgUpdateError(
this, KAlarm::KORG_ERR_ADD, warnKOrg);
883 KAlarm::outputAlarmWarnings(&dlg);
892 void MainWindow::slotTemplates()
896 mTemplateDlg = TemplateDlg::create(
this);
897 enableTemplateMenuItem(
false);
898 connect(mTemplateDlg, TQ_SIGNAL(finished()), TQ_SLOT(slotTemplatesEnd()));
899 mTemplateDlg->show();
906 void MainWindow::slotTemplatesEnd()
910 mTemplateDlg->delayedDestruct();
912 enableTemplateMenuItem(
true);
919 void MainWindow::slotToggleTrayIcon()
921 theApp()->displayTrayIcon(!theApp()->trayIconDisplayed(),
this);
927 void MainWindow::slotPrefsChanged()
929 mActionShowExpired->setEnabled(Preferences::expiredKeepDays());
930 updateTrayIconAction();
938 void MainWindow::updateTrayIconAction()
940 mActionToggleTrayIcon->setEnabled(theApp()->haveSystemTray() && !theApp()->wantRunInSystemTray());
941 mActionToggleTrayIcon->setChecked(theApp()->trayIconDisplayed());
948 void MainWindow::updateActionsMenu()
950 Daemon::checkStatus();
956 void MainWindow::slotFindActive(
bool active)
958 mActionFindNext->setEnabled(active);
959 mActionFindPrev->setEnabled(active);
965 void MainWindow::slotUndo()
967 Undo::undo(
this, KAlarm::stripAccel(mActionUndo->text()));
973 void MainWindow::slotRedo()
975 Undo::redo(
this, KAlarm::stripAccel(mActionRedo->text()));
981 void MainWindow::slotUndoItem(
int id)
983 Undo::undo(
id,
this, Undo::actionText(Undo::UNDO,
id));
989 void MainWindow::slotRedoItem(
int id)
991 Undo::redo(
id,
this, Undo::actionText(Undo::REDO,
id));
998 void MainWindow::slotInitUndoMenu()
1000 initUndoMenu(mActionUndo->popupMenu(), Undo::UNDO);
1007 void MainWindow::slotInitRedoMenu()
1009 initUndoMenu(mActionRedo->popupMenu(), Undo::REDO);
1015 void MainWindow::initUndoMenu(TDEPopupMenu* menu, Undo::Type type)
1018 const TQString& action = (type == Undo::UNDO) ? undoTextStripped : redoTextStripped;
1019 TQValueList<int> ids = Undo::ids(type);
1020 for (TQValueList<int>::ConstIterator it = ids.begin(); it != ids.end(); ++it)
1023 TQString actText = Undo::actionText(type,
id);
1024 TQString descrip = Undo::description(type,
id);
1025 TQString text = descrip.isEmpty()
1026 ? i18n(
"Undo/Redo [action]",
"%1 %2").arg(action).arg(actText)
1027 : i18n(
"Undo [action]: message",
"%1 %2: %3").arg(action).arg(actText).arg(descrip);
1028 menu->insertItem(text,
id);
1036 void MainWindow::slotUndoStatus(
const TQString& undo,
const TQString& redo)
1040 mActionUndo->setEnabled(
false);
1041 mActionUndo->setText(undoText);
1045 mActionUndo->setEnabled(
true);
1046 mActionUndo->setText(TQString(
"%1 %2").arg(undoText).arg(undo));
1050 mActionRedo->setEnabled(
false);
1051 mActionRedo->setText(redoText);
1055 mActionRedo->setEnabled(
true);
1056 mActionRedo->setText(TQString(
"%1 %2").arg(redoText).arg(redo));
1063 void MainWindow::slotResetDaemon()
1065 KAlarm::resetDaemon();
1071 void MainWindow::slotPreferences()
1073 KAlarmPrefDlg::display();
1079 void MainWindow::slotConfigureKeys()
1081 KKeyDialog::configure(actionCollection(),
this);
1087 void MainWindow::slotConfigureToolbar()
1089 saveMainWindowSettings(TDEGlobal::config(), WINDOW_NAME);
1090 KEditToolbar dlg(factory());
1091 connect(&dlg, TQ_SIGNAL(newToolbarConfig()),
this, TQ_SLOT(slotNewToolbarConfig()));
1099 void MainWindow::slotNewToolbarConfig()
1102 applyMainWindowSettings(TDEGlobal::config(), WINDOW_NAME);
1108 void MainWindow::slotQuit()
1110 theApp()->doQuit(
this);
1116 void MainWindow::closeEvent(TQCloseEvent* ce)
1118 if (!theApp()->sessionClosingDown() && isTrayParent())
1135 void MainWindow::slotDeletion()
1137 if (!mListView->selectedCount())
1139 kdDebug(5950) <<
"MainWindow::slotDeletion(true)\n";
1140 mActionCreateTemplate->setEnabled(
false);
1141 mActionCopy->setEnabled(
false);
1142 mActionModify->setEnabled(
false);
1143 mActionView->setEnabled(
false);
1144 mActionDelete->setEnabled(
false);
1145 mActionReactivate->setEnabled(
false);
1146 mActionEnable->setEnabled(
false);
1153 void MainWindow::dragEnterEvent(TQDragEnterEvent* e)
1155 executeDragEnterEvent(e);
1162 void MainWindow::executeDragEnterEvent(TQDragEnterEvent* e)
1165 e->accept(!AlarmListView::dragging());
1167 e->accept(TQTextDrag::canDecode(e)
1168 || KURLDrag::canDecode(e)
1169 || KPIM::MailListDrag::canDecode(e));
1176 void MainWindow::dropEvent(TQDropEvent* e)
1178 executeDropEvent(
this, e);
1181 static TQString getMailHeader(
const char* header, KMime::Content& content)
1183 KMime::Headers::Base* hd = content.getHeaderByType(header);
1184 return hd ? hd->asUnicodeString() : TQString();
1191 void MainWindow::executeDropEvent(MainWindow* win, TQDropEvent* e)
1193 KAEvent::Action action = KAEvent::MESSAGE;
1196 AlarmText alarmText;
1197 KPIM::MailList mailList;
1200 calendar.setLocalTime();
1203 for (
int idbg = 0; e->format(idbg); ++idbg)
1205 if (idbg) fmts +=
", ";
1206 fmts += e->format(idbg);
1208 kdDebug(5950) <<
"MainWindow::executeDropEvent(): " << fmts << endl;
1215 if (e->provides(
"message/rfc822")
1216 && !(bytes = e->encodedData(
"message/rfc822")).isEmpty())
1219 kdDebug(5950) <<
"MainWindow::executeDropEvent(email)" << endl;
1220 TQCString mails(bytes.data(), bytes.size());
1221 KMime::Content content;
1222 content.setContent(mails);
1225 if (content.textContent())
1226 content.textContent()->decodedText(body,
true,
true);
1227 unsigned long sernum = 0;
1228 if (e->provides(KPIM::MailListDrag::format())
1229 && KPIM::MailListDrag::decode(e, mailList)
1230 && mailList.count())
1234 sernum = mailList.first().serialNumber();
1236 alarmText.setEmail(getMailHeader(
"To", content),
1237 getMailHeader(
"From", content),
1238 getMailHeader(
"Cc", content),
1239 getMailHeader(
"Date", content),
1240 getMailHeader(
"Subject", content),
1243 else if (KURLDrag::decode(e, files) && files.count())
1245 kdDebug(5950) <<
"MainWindow::executeDropEvent(URL)" << endl;
1246 action = KAEvent::FILE;
1247 alarmText.setText(files.first().prettyURL());
1249 else if (e->provides(KPIM::MailListDrag::format())
1250 && KPIM::MailListDrag::decode(e, mailList))
1253 kdDebug(5950) <<
"MainWindow::executeDropEvent(KMail_list)" << endl;
1254 if (!mailList.count())
1256 KPIM::MailSummary& summary = mailList.first();
1258 dt.setTime_t(summary.date());
1259 TQString body = KAMail::getMailBody(summary.serialNumber());
1260 alarmText.setEmail(summary.to(), summary.from(), TQString(),
1261 TDEGlobal::locale()->formatDateTime(dt), summary.subject(),
1262 body, summary.serialNumber());
1267 kdDebug(5950) <<
"MainWindow::executeDropEvent(iCalendar)" << endl;
1268 KCal::Event::List events = calendar.rawEvents();
1269 if (!events.isEmpty())
1272 executeNew(win, &ev);
1276 else if (TQTextDrag::decode(e, text))
1278 kdDebug(5950) <<
"MainWindow::executeDropEvent(text)" << endl;
1279 alarmText.setText(text);
1284 if (!alarmText.isEmpty())
1285 executeNew(win, 0, action, alarmText);
1292 void MainWindow::slotSelection()
1295 TQValueList<EventListViewItemBase*> items = mListView->selectedItems();
1296 int count = items.count();
1297 AlarmListViewItem* item = (AlarmListViewItem*)((count == 1) ? items.first() : 0);
1298 bool enableReactivate =
true;
1299 bool enableEnableDisable =
true;
1300 bool enableEnable =
false;
1301 bool enableDisable =
false;
1302 TQDateTime now = TQDateTime::currentDateTime();
1303 for (TQValueList<EventListViewItemBase*>::Iterator it = items.begin(); it != items.end(); ++it)
1305 const KAEvent&
event = ((AlarmListViewItem*)(*it))->event();
1306 if (enableReactivate
1307 && (!event.expired() || !
event.occursAfter(now,
true)))
1308 enableReactivate =
false;
1309 if (enableEnableDisable)
1311 if (event.expired())
1312 enableEnableDisable = enableEnable = enableDisable =
false;
1315 if (!enableEnable && !event.enabled())
1316 enableEnable =
true;
1317 if (!enableDisable && event.enabled())
1318 enableDisable =
true;
1323 kdDebug(5950) <<
"MainWindow::slotSelection(true)\n";
1324 mActionCreateTemplate->setEnabled(count == 1);
1325 mActionCopy->setEnabled(count == 1);
1326 mActionModify->setEnabled(item && !mListView->expired(item));
1327 mActionView->setEnabled(count == 1);
1328 mActionDelete->setEnabled(count);
1329 mActionReactivate->setEnabled(count && enableReactivate);
1330 mActionEnable->setEnabled(enableEnable || enableDisable);
1331 if (enableEnable || enableDisable)
1332 setEnableText(enableEnable);
1339 void MainWindow::slotContextMenuRequested(TQListViewItem* item,
const TQPoint& pt,
int)
1341 kdDebug(5950) <<
"MainWindow::slotContextMenuRequested()" << endl;
1343 mContextMenu->popup(pt);
1351 void MainWindow::slotMouseClicked(
int button, TQListViewItem* item,
const TQPoint& pt,
int)
1353 if (button != TQt::RightButton && !item)
1355 kdDebug(5950) <<
"MainWindow::slotMouseClicked(left)" << endl;
1356 mListView->clearSelection();
1357 mActionCreateTemplate->setEnabled(
false);
1358 mActionCopy->setEnabled(
false);
1359 mActionModify->setEnabled(
false);
1360 mActionView->setEnabled(
false);
1361 mActionDelete->setEnabled(
false);
1362 mActionReactivate->setEnabled(
false);
1363 mActionEnable->setEnabled(
false);
1371 void MainWindow::slotDoubleClicked(TQListViewItem* item)
1373 kdDebug(5950) <<
"MainWindow::slotDoubleClicked()\n";
1376 if (mListView->expired((AlarmListViewItem*)item))
1388 void MainWindow::setEnableText(
bool enable)
1390 mActionEnableEnable = enable;
1391 mActionEnable->setText(enable ? i18n(
"Ena&ble") : i18n(
"Disa&ble"));
1398 MainWindow* MainWindow::toggleWindow(MainWindow* win)
1400 if (win && mWindowList.find(win) != mWindowList.end())
1403 if (win->isVisible())
1415 win->setActiveWindow();
represents calendar alarms and events
KAEvent corresponds to a KCal::Event instance.
static bool canDecode(TQMimeSource *)
static bool decode(TQMimeSource *e, Calendar *cal)
The MainWindowBase class is a base class for KAlarm's main window and message window.
the KAlarm application object
bool view(TQWidget *parent, Attachment *attachment)