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