00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KALARMAPP_H
00022 #define KALARMAPP_H
00023
00026 #include <QPointer>
00027 #include <QQueue>
00028 #include <QList>
00029 class KDateTime;
00030
00031 #include <kuniqueapplication.h>
00032 #include <kurl.h>
00033 namespace KCal { class Event; }
00034
00035 #include "alarmevent.h"
00036 #include "kamail.h"
00037 class DBusHandler;
00038 class MainWindow;
00039 class TrayWindow;
00040 class ShellProcess;
00041
00042
00043 class KAlarmApp : public KUniqueApplication
00044 {
00045 Q_OBJECT
00046 public:
00047 ~KAlarmApp();
00048 virtual int newInstance();
00049 static KAlarmApp* getInstance();
00050 bool checkCalendar() { return initCheck(); }
00051 bool wantShowInSystemTray() const;
00052 bool alarmsEnabled() const { return mAlarmsEnabled; }
00053 bool speechEnabled() const { return mSpeechEnabled; }
00054 bool korganizerEnabled() const { return mKOrganizerEnabled; }
00055 bool restoreSession();
00056 bool sessionClosingDown() const { return mSessionClosingDown; }
00057 void quitIf() { quitIf(0); }
00058 void doQuit(QWidget* parent);
00059 static void displayFatalError(const QString& message);
00060 void addWindow(TrayWindow* w) { mTrayWindow = w; }
00061 void removeWindow(TrayWindow*);
00062 TrayWindow* trayWindow() const { return mTrayWindow; }
00063 MainWindow* trayMainWindow() const;
00064 bool displayTrayIcon(bool show, MainWindow* = 0);
00065 bool trayIconDisplayed() const { return mTrayWindow; }
00066 bool editNewAlarm(MainWindow* = 0);
00067 virtual void commitData(QSessionManager&);
00068
00069 void* execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
00070 ShellProcess* execCommandAlarm(const KAEvent&, const KAAlarm&, const QObject* receiver = 0, const char* slot = 0);
00071 void alarmCompleted(const KAEvent&);
00072 void rescheduleAlarm(KAEvent& e, const KAAlarm& a) { rescheduleAlarm(e, a, true); }
00073 bool deleteEvent(const QString& eventID) { return handleEvent(eventID, EVENT_CANCEL); }
00074 void purgeAll() { purge(0); }
00075 void commandMessage(ShellProcess*, QWidget* parent);
00076
00077 bool scheduleEvent(KAEvent::Action, const QString& text, const KDateTime&,
00078 int lateCancel, int flags, const QColor& bg, const QColor& fg,
00079 const QFont&, const QString& audioFile, float audioVolume,
00080 int reminderMinutes, const KARecurrence& recurrence,
00081 int repeatInterval, int repeatCount,
00082 uint mailFromID = 0, const EmailAddressList& mailAddresses = EmailAddressList(),
00083 const QString& mailSubject = QString(),
00084 const QStringList& mailAttachments = QStringList());
00085 bool dbusTriggerEvent(const QString& eventID) { return dbusHandleEvent(eventID, EVENT_TRIGGER); }
00086 bool dbusDeleteEvent(const QString& eventID) { return dbusHandleEvent(eventID, EVENT_CANCEL); }
00087 public slots:
00088 void processQueue();
00089 void setAlarmsEnabled(bool);
00090 void emailSent(KAMail::JobData&, const QStringList& errmsgs, bool copyerr = false);
00091 signals:
00092 void trayIconToggled();
00093 void alarmEnabledToggled(bool);
00094 void execAlarmSuccess();
00095 protected:
00096 KAlarmApp();
00097 private:
00098 typedef Preferences::Feb29Type Feb29Type;
00099 private slots:
00100 void quitFatal();
00101 void checkNextDueAlarm();
00102 void slotShowInSystemTrayChanged();
00103 void changeStartOfDay();
00104 void slotFeb29TypeChanged(Feb29Type);
00105 void setArchivePurgeDays();
00106 void slotPurge() { purge(mArchivedPurgeDays); }
00107 void slotCommandExited(ShellProcess*);
00108 private:
00109 enum EventFunc
00110 {
00111 EVENT_HANDLE,
00112 EVENT_TRIGGER,
00113 EVENT_CANCEL
00114 };
00115 struct ProcData
00116 {
00117 ProcData(ShellProcess*, KAEvent*, KAAlarm*, int flags = 0);
00118 ~ProcData();
00119 enum { PRE_ACTION = 0x01, POST_ACTION = 0x02, RESCHEDULE = 0x04, ALLOW_DEFER = 0x08,
00120 TEMP_FILE = 0x10, EXEC_IN_XTERM = 0x20, DISP_OUTPUT = 0x40 };
00121 bool preAction() const { return flags & PRE_ACTION; }
00122 bool postAction() const { return flags & POST_ACTION; }
00123 bool reschedule() const { return flags & RESCHEDULE; }
00124 bool allowDefer() const { return flags & ALLOW_DEFER; }
00125 bool tempFile() const { return flags & TEMP_FILE; }
00126 bool execInXterm() const { return flags & EXEC_IN_XTERM; }
00127 bool dispOutput() const { return flags & DISP_OUTPUT; }
00128 ShellProcess* process;
00129 KAEvent* event;
00130 KAAlarm* alarm;
00131 QPointer<QWidget> messageBoxParent;
00132 QStringList tempFiles;
00133 int flags;
00134 };
00135 struct DcopQEntry
00136 {
00137 DcopQEntry(EventFunc f, const QString& id) : function(f), eventId(id) { }
00138 DcopQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
00139 DcopQEntry() { }
00140 EventFunc function;
00141 QString eventId;
00142 KAEvent event;
00143 };
00144
00145 bool initCheck(bool calendarOnly = false);
00146 void quitIf(int exitCode, bool force = false);
00147 bool checkSystemTray();
00148 void startProcessQueue();
00149 void queueAlarmId(const QString& id);
00150 bool dbusHandleEvent(const QString& eventID, EventFunc);
00151 bool handleEvent(const QString& eventID, EventFunc);
00152 void rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay);
00153 bool cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
00154 ShellProcess* doShellCommand(const QString& command, const KAEvent&, const KAAlarm*, int flags = 0, const QObject* receiver = 0, const char* slot = 0);
00155 QString createTempScriptFile(const QString& command, bool insertShell, const KAEvent&, const KAAlarm&);
00156 void commandErrorMsg(const ShellProcess*, const KAEvent&, const KAAlarm*, int flags = 0);
00157 void purge(int daysToKeep);
00158
00159 static KAlarmApp* theInstance;
00160 static int mActiveCount;
00161 static int mFatalError;
00162 static QString mFatalMessage;
00163 bool mInitialised;
00164 bool mQuitting;
00165 bool mLoginAlarmsDone;
00166 DBusHandler* mDBusHandler;
00167 TrayWindow* mTrayWindow;
00168 QTimer* mAlarmTimer;
00169 QTime mStartOfDay;
00170 QColor mPrefsArchivedColour;
00171 int mArchivedPurgeDays;
00172 int mPurgeDaysQueued;
00173 QList<ProcData*> mCommandProcesses;
00174 QQueue<DcopQEntry> mDcopQueue;
00175 int mPendingQuitCode;
00176 bool mPendingQuit;
00177 bool mProcessingQueue;
00178 bool mNoSystemTray;
00179 bool mSessionClosingDown;
00180 bool mOldShowInSystemTray;
00181 bool mAlarmsEnabled;
00182 bool mSpeechEnabled;
00183 bool mKOrganizerEnabled;
00184 };
00185
00186 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
00187
00188 #endif // KALARMAPP_H