Remove double margin
[kdepim.git] / kalarm / kalarmapp.h
blobed35d13c5bfa05b69b663656503fc41992253d5f
1 /*
2 * kalarmapp.h - the KAlarm application object
3 * Program: kalarm
4 * Copyright © 2001-2015 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.
21 #ifndef KALARMAPP_H
22 #define KALARMAPP_H
24 /** @file kalarmapp.h - the KAlarm application object */
26 #include "eventid.h"
27 #include "kamail.h"
28 #include "preferences.h"
30 #include <kalarmcal/kaevent.h>
32 #include <kuniqueapplication.h>
34 #include <QPointer>
35 #include <QQueue>
36 #include <QList>
38 class KDateTime;
39 namespace KCal { class Event; }
40 namespace Akonadi { class Collection; }
41 class DBusHandler;
42 class MainWindow;
43 class TrayWindow;
44 class ShellProcess;
46 using namespace KAlarmCal;
49 class KAlarmApp : public KUniqueApplication
51 Q_OBJECT
52 public:
53 ~KAlarmApp();
54 int newInstance() Q_DECL_OVERRIDE;
55 static KAlarmApp* getInstance();
56 bool checkCalendar() { return initCheck(); }
57 bool wantShowInSystemTray() const;
58 bool alarmsEnabled() const { return mAlarmsEnabled; }
59 bool korganizerEnabled() const { return mKOrganizerEnabled; }
60 bool restoreSession();
61 bool sessionClosingDown() const { return mSessionClosingDown; }
62 bool quitIf() { return quitIf(0); }
63 void doQuit(QWidget* parent);
64 static void displayFatalError(const QString& message);
65 void addWindow(TrayWindow* w) { mTrayWindow = w; }
66 void removeWindow(TrayWindow*);
67 TrayWindow* trayWindow() const { return mTrayWindow; }
68 MainWindow* trayMainWindow() const;
69 bool displayTrayIcon(bool show, MainWindow* = Q_NULLPTR);
70 bool trayIconDisplayed() const { return mTrayWindow; }
71 bool editNewAlarm(MainWindow* = Q_NULLPTR);
72 virtual void commitData(QSessionManager&);
74 void* execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
75 ShellProcess* execCommandAlarm(const KAEvent&, const KAAlarm&, const QObject* receiver = Q_NULLPTR, const char* slot = Q_NULLPTR);
76 void alarmCompleted(const KAEvent&);
77 void rescheduleAlarm(KAEvent& e, const KAAlarm& a) { rescheduleAlarm(e, a, true); }
78 void purgeAll() { purge(0); }
79 void commandMessage(ShellProcess*, QWidget* parent);
80 void notifyAudioPlaying(bool playing);
81 void setSpreadWindowsState(bool spread);
82 bool windowFocusBroken() const;
83 bool needWindowFocusFix() const;
84 // Methods called indirectly by the DCOP interface
85 bool scheduleEvent(KAEvent::SubAction, const QString& text, const KDateTime&,
86 int lateCancel, KAEvent::Flags flags, const QColor& bg, const QColor& fg,
87 const QFont&, const QString& audioFile, float audioVolume,
88 int reminderMinutes, const KARecurrence& recurrence,
89 KCalCore::Duration repeatInterval, int repeatCount,
90 uint mailFromID = 0, const KCalCore::Person::List& mailAddresses = KCalCore::Person::List(),
91 const QString& mailSubject = QString(),
92 const QStringList& mailAttachments = QStringList());
93 bool dbusTriggerEvent(const EventId& eventID) { return dbusHandleEvent(eventID, EVENT_TRIGGER); }
94 bool dbusDeleteEvent(const EventId& eventID) { return dbusHandleEvent(eventID, EVENT_CANCEL); }
95 QString dbusList();
97 public Q_SLOTS:
98 void processQueue();
99 void setAlarmsEnabled(bool);
100 void purgeNewArchivedDefault(const Akonadi::Collection&);
101 void atLoginEventAdded(const KAEvent&);
102 void notifyAudioStopped() { notifyAudioPlaying(false); }
103 void stopAudio();
104 void spreadWindows(bool);
105 void emailSent(KAMail::JobData&, const QStringList& errmsgs, bool copyerr = false);
107 Q_SIGNALS:
108 void trayIconToggled();
109 void alarmEnabledToggled(bool);
110 void audioPlaying(bool);
111 void spreadWindowsToggled(bool);
112 void execAlarmSuccess();
114 protected:
115 KAlarmApp();
117 private:
118 typedef Preferences::Feb29Type Feb29Type; // allow it to be used in SIGNAL mechanism
120 private Q_SLOTS:
121 void quitFatal();
122 void checkNextDueAlarm();
123 void checkKtimezoned();
124 void slotShowInSystemTrayChanged();
125 void changeStartOfDay();
126 void slotWorkTimeChanged(const QTime& start, const QTime& end, const QBitArray& days);
127 void slotHolidaysChanged(const KHolidays::HolidayRegion&);
128 void slotFeb29TypeChanged(Feb29Type);
129 void checkWritableCalendar();
130 void slotMessageFontChanged(const QFont&);
131 void setArchivePurgeDays();
132 void slotPurge() { purge(mArchivedPurgeDays); }
133 void purgeAfterDelay();
134 void slotCommandExited(ShellProcess*);
136 private:
137 enum EventFunc
139 EVENT_HANDLE, // if the alarm is due, execute it and then reschedule it
140 EVENT_TRIGGER, // execute the alarm regardless, and then reschedule it if it already due
141 EVENT_CANCEL // delete the alarm
143 struct ProcData
145 ProcData(ShellProcess*, KAEvent*, KAAlarm*, int flags = 0);
146 ~ProcData();
147 enum { PRE_ACTION = 0x01, POST_ACTION = 0x02, RESCHEDULE = 0x04, ALLOW_DEFER = 0x08,
148 TEMP_FILE = 0x10, EXEC_IN_XTERM = 0x20, DISP_OUTPUT = 0x40 };
149 bool preAction() const { return flags & PRE_ACTION; }
150 bool postAction() const { return flags & POST_ACTION; }
151 bool reschedule() const { return flags & RESCHEDULE; }
152 bool allowDefer() const { return flags & ALLOW_DEFER; }
153 bool tempFile() const { return flags & TEMP_FILE; }
154 bool execInXterm() const { return flags & EXEC_IN_XTERM; }
155 bool dispOutput() const { return flags & DISP_OUTPUT; }
156 ShellProcess* process;
157 KAEvent* event;
158 KAAlarm* alarm;
159 QPointer<QWidget> messageBoxParent;
160 QStringList tempFiles;
161 int flags;
163 struct ActionQEntry
165 ActionQEntry(EventFunc f, const EventId& id) : function(f), eventId(id) { }
166 ActionQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
167 ActionQEntry() { }
168 EventFunc function;
169 EventId eventId;
170 KAEvent event;
173 bool initialise();
174 bool initCheck(bool calendarOnly = false, bool waitForCollection = false, Akonadi::Collection::Id = -1);
175 bool quitIf(int exitCode, bool force = false);
176 bool checkSystemTray();
177 void startProcessQueue();
178 void queueAlarmId(const KAEvent&);
179 bool dbusHandleEvent(const EventId&, EventFunc);
180 bool handleEvent(const EventId&, EventFunc, bool checkDuplicates = false);
181 int rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay,
182 const KDateTime& nextDt = KDateTime());
183 bool cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
184 bool cancelReminderAndDeferral(KAEvent&);
185 ShellProcess* doShellCommand(const QString& command, const KAEvent&, const KAAlarm*,
186 int flags = 0, const QObject* receiver = Q_NULLPTR, const char* slot = Q_NULLPTR);
187 QString composeXTermCommand(const QString& command, const KAEvent&, const KAAlarm*,
188 int flags, QString& tempScriptFile) const;
189 QString createTempScriptFile(const QString& command, bool insertShell, const KAEvent&, const KAAlarm&) const;
190 void commandErrorMsg(const ShellProcess*, const KAEvent&, const KAAlarm*, int flags = 0);
191 void purge(int daysToKeep);
192 QStringList scheduledAlarmList();
194 static KAlarmApp* theInstance; // the one and only KAlarmApp instance
195 static int mActiveCount; // number of active instances without main windows
196 static int mFatalError; // a fatal error has occurred - just wait to exit
197 static QString mFatalMessage; // fatal error message to output
198 bool mInitialised; // initialisation complete: ready to process execution queue
199 bool mRedisplayAlarms; // need to redisplay alarms when collection tree fetched
200 bool mQuitting; // a forced quit is in progress
201 bool mReadOnly; // only read-only access to calendars is needed
202 bool mLoginAlarmsDone; // alarms repeated at login have been processed
203 DBusHandler* mDBusHandler; // the parent of the main DCOP receiver object
204 TrayWindow* mTrayWindow; // active system tray icon
205 QTimer* mAlarmTimer; // activates KAlarm when next alarm is due
206 QColor mPrefsArchivedColour; // archived alarms text colour
207 int mArchivedPurgeDays; // how long to keep archived alarms, 0 = don't keep, -1 = keep indefinitely
208 int mPurgeDaysQueued; // >= 0 to purge the archive calendar from KAlarmApp::processLoop()
209 QList<ProcData*> mCommandProcesses; // currently active command alarm processes
210 QQueue<ActionQEntry> mActionQueue; // queued commands and actions
211 int mPendingQuitCode; // exit code for a pending quit
212 bool mPendingQuit; // quit once the DCOP command and shell command queues have been processed
213 bool mCancelRtcWake; // cancel RTC wake on quitting
214 bool mProcessingQueue; // a mActionQueue entry is currently being processed
215 bool mNoSystemTray; // no system tray exists
216 bool mSessionClosingDown; // session manager is closing the application
217 bool mOldShowInSystemTray; // showing in system tray was selected
218 bool mAlarmsEnabled; // alarms are enabled
219 bool mKOrganizerEnabled; // KOrganizer options are enabled (korganizer exists)
220 bool mWindowFocusBroken; // keyboard focus transfer between windows doesn't work
223 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
225 #endif // KALARMAPP_H
227 // vim: et sw=4: