2 * mainwindow.h - main application window
4 * Copyright © 2001-2011 by David Jarvie <djarvie@kde.org>
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.
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.
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.
24 /** @file mainwindow.h - main application window */
27 #include "alarmresources.h"
30 #include "mainwindowbase.h"
33 #include <kalarmcal/kaevent.h>
36 #include <akonadi/item.h>
37 #include <kcalcore/calendar.h>
39 #include <kcal/calendar.h>
45 class QDragEnterEvent
;
55 class KToolBarPopupAction
;
59 class AlarmListFilterModel
;
64 class TemplateMenuAction
;
65 class ResourceSelector
;
69 class MainWindow
: public MainWindowBase
, public KCalCore::Calendar::CalendarObserver
71 class MainWindow
: public MainWindowBase
, public KCal::Calendar::CalendarObserver
77 static MainWindow
* create(bool restored
= false);
79 bool isTrayParent() const;
80 bool isHiddenTrayParent() const { return mHiddenTrayParent
; }
81 bool showingArchived() const { return mShowArchived
; }
83 void selectEvent(Akonadi::Item::Id
);
84 KAEvent
selectedEvent() const;
85 void editAlarm(EditAlarmDlg
*, const KAEvent
&);
87 void selectEvent(const QString
& eventID
);
88 KAEvent
* selectedEvent() const;
89 void editAlarm(EditAlarmDlg
*, const KAEvent
&, AlarmResource
*);
91 void clearSelection();
92 virtual bool eventFilter(QObject
*, QEvent
*);
94 static void refresh();
95 static void executeDragEnterEvent(QDragEnterEvent
*);
96 static void executeDropEvent(MainWindow
*, QDropEvent
*);
97 static void closeAll();
98 static MainWindow
* toggleWindow(MainWindow
*);
99 static MainWindow
* mainMainWindow();
100 static MainWindow
* firstWindow() { return mWindowList
.isEmpty() ? 0 : mWindowList
[0]; }
101 static int count() { return mWindowList
.count(); }
103 static QString
i18n_a_ShowAlarmTimes(); // text of 'Show Alarm Times' action, with 'A' shortcut
104 static QString
i18n_chk_ShowAlarmTime(); // text of 'Show alarm time' checkbox
105 static QString
i18n_o_ShowTimeToAlarms(); // text of 'Show Time to Alarms' action, with 'O' shortcut
106 static QString
i18n_chk_ShowTimeToAlarm(); // text of 'Show time until alarm' checkbox
112 void selectionChanged();
115 virtual void resizeEvent(QResizeEvent
*);
116 virtual void showEvent(QShowEvent
*);
117 virtual void hideEvent(QHideEvent
*);
118 virtual void closeEvent(QCloseEvent
*);
119 virtual void dragEnterEvent(QDragEnterEvent
* e
) { executeDragEnterEvent(e
); }
120 virtual void dropEvent(QDropEvent
*);
121 virtual void saveProperties(KConfigGroup
&);
122 virtual void readProperties(const KConfigGroup
&);
125 void slotNew(EditAlarmDlg::Type
);
126 void slotNewDisplay() { slotNew(EditAlarmDlg::DISPLAY
); }
127 void slotNewCommand() { slotNew(EditAlarmDlg::COMMAND
); }
128 void slotNewEmail() { slotNew(EditAlarmDlg::EMAIL
); }
129 void slotNewAudio() { slotNew(EditAlarmDlg::AUDIO
); }
130 void slotNewFromTemplate(const KAEvent
*);
131 void slotNewTemplate();
134 void slotDeleteIf() { slotDelete(false); }
135 void slotDeleteForce() { slotDelete(true); }
136 void slotReactivate();
138 void slotToggleTrayIcon();
139 void slotRefreshAlarms();
140 void slotImportAlarms();
141 void slotExportAlarms();
142 void slotBirthdays();
143 void slotTemplates();
144 void slotTemplatesEnd();
145 void slotPreferences();
146 void slotConfigureKeys();
147 void slotConfigureToolbar();
148 void slotNewToolbarConfig();
150 void slotSelection();
151 void slotContextMenuRequested(const QPoint
& globalPos
);
153 void slotShowTimeTo();
154 void slotShowArchived();
155 void slotSpreadWindowsShortcut();
156 void slotWakeFromSuspend();
157 void updateKeepArchived(int days
);
159 void slotUndoItem(QAction
* id
);
161 void slotRedoItem(QAction
* id
);
162 void slotInitUndoMenu();
163 void slotInitRedoMenu();
164 void slotUndoStatus(const QString
&, const QString
&);
165 void slotFindActive(bool);
166 void updateTrayIconAction();
167 void slotToggleResourceSelector();
168 void slotCalendarStatusChanged();
169 void resourcesResized();
170 void showErrorMessage(const QString
&);
172 void editAlarmDeleted(QObject
*);
175 typedef QList
<MainWindow
*> WindowList
;
177 explicit MainWindow(bool restored
);
178 void createListView(bool recreate
);
180 void initCalendarResources();
181 void selectionCleared();
182 void setEnableText(bool enable
);
183 void initUndoMenu(QMenu
*, Undo::Type
);
184 void slotDelete(bool force
);
185 static KAEvent::SubAction
getDropAction(QDropEvent
*, QString
& text
);
186 static void setUpdateTimer();
187 static void enableTemplateMenuItem(bool);
189 static WindowList mWindowList
; // active main windows
190 static TemplateDlg
* mTemplateDlg
; // the one and only template dialog
193 AlarmListModel
* mListFilterModel
;
195 AlarmListFilterModel
* mListFilterModel
;
197 AlarmListView
* mListView
;
198 ResourceSelector
* mResourceSelector
; // resource selector widget
199 QSplitter
* mSplitter
; // splits window into list and resource selector
201 AlarmResources
* mAlarmResources
; // calendar resources to use for this window
203 QMap
<EditAlarmDlg
*, KAEvent
> mEditAlarmMap
; // edit alarm dialogs to be handled by this window
204 KToggleAction
* mActionToggleResourceSel
;
205 KAction
* mActionImportAlarms
;
206 KAction
* mActionExportAlarms
;
207 KAction
* mActionExport
;
208 KAction
* mActionImportBirthdays
;
209 KAction
* mActionTemplates
;
210 NewAlarmAction
* mActionNew
;
211 KAction
* mActionCreateTemplate
;
212 KAction
* mActionCopy
;
213 KAction
* mActionModify
;
214 KAction
* mActionDelete
;
215 KAction
* mActionDeleteForce
;
216 KAction
* mActionReactivate
;
217 KAction
* mActionEnable
;
218 KAction
* mActionFindNext
;
219 KAction
* mActionFindPrev
;
220 KToolBarPopupAction
* mActionUndo
;
221 KToolBarPopupAction
* mActionRedo
;
222 KToggleAction
* mActionToggleTrayIcon
;
223 KToggleAction
* mActionShowTime
;
224 KToggleAction
* mActionShowTimeTo
;
225 KToggleAction
* mActionShowArchived
;
226 KToggleAction
* mActionSpreadWindows
;
229 QMap
<QAction
*, int> mUndoMenuIds
; // items in the undo/redo menu, in order of appearance
230 int mResourcesWidth
; // width of resource selector widget
231 bool mHiddenTrayParent
; // on session restoration, hide this window
232 bool mShowResources
; // show resource selector
233 bool mShowArchived
; // include archived alarms in the displayed list
234 bool mShowTime
; // show alarm times
235 bool mShowTimeTo
; // show time-to-alarms
236 bool mShown
; // true once the window has been displayed
237 bool mActionEnableEnable
; // Enable/Disable action is set to "Enable"
238 bool mMenuError
; // error occurred creating menus: need to show error message
239 bool mResizing
; // window resize is in progress
242 #endif // MAINWINDOW_H