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 <qguardedptr.h>
00027 class QTimer;
00028 class QDateTime;
00029
00030 #include <kuniqueapplication.h>
00031 #include <kurl.h>
00032 class KProcess;
00033 namespace KCal { class Event; }
00034
00035 #include "alarmevent.h"
00036 class DcopHandler;
00037 #ifdef OLD_DCOP
00038 class DcopHandlerOld;
00039 #endif
00040 class AlarmCalendar;
00041 class MainWindow;
00042 class AlarmListView;
00043 class MessageWin;
00044 class TrayWindow;
00045 class ShellProcess;
00046
00047
00048 class KAlarmApp : public KUniqueApplication
00049 {
00050 Q_OBJECT
00051 public:
00052 ~KAlarmApp();
00053 virtual int newInstance();
00054 static KAlarmApp* getInstance();
00055 bool checkCalendarDaemon() { return initCheck(); }
00056 bool KDEDesktop() const { return mKDEDesktop; }
00057 bool wantRunInSystemTray() const;
00058 bool alarmsDisabledIfStopped() const { return mDisableAlarmsIfStopped; }
00059 bool speechEnabled() const { return mSpeechEnabled; }
00060 bool korganizerEnabled() const { return mKOrganizerEnabled; }
00061 bool restoreSession();
00062 bool sessionClosingDown() const { return mSessionClosingDown; }
00063 void quitIf() { quitIf(0); }
00064 void doQuit(QWidget* parent);
00065 static void displayFatalError(const QString& message);
00066 void addWindow(TrayWindow* w) { mTrayWindow = w; }
00067 void removeWindow(TrayWindow*);
00068 TrayWindow* trayWindow() const { return mTrayWindow; }
00069 MainWindow* trayMainWindow() const;
00070 bool displayTrayIcon(bool show, MainWindow* = 0);
00071 bool trayIconDisplayed() const { return !!mTrayWindow; }
00072 bool editNewAlarm(MainWindow* = 0);
00073 virtual void commitData(QSessionManager&);
00074
00075 void* execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
00076 void alarmShowing(KAEvent&, KAAlarm::Type, const DateTime&);
00077 void alarmCompleted(const KAEvent&);
00078 bool deleteEvent(const QString& eventID) { return handleEvent(eventID, EVENT_CANCEL); }
00079 void commandMessage(ShellProcess*, QWidget* parent);
00080
00081 bool scheduleEvent(KAEvent::Action, const QString& text, const QDateTime&,
00082 int lateCancel, int flags, const QColor& bg, const QColor& fg,
00083 const QFont&, const QString& audioFile, float audioVolume,
00084 int reminderMinutes, const KARecurrence& recurrence,
00085 int repeatInterval, int repeatCount,
00086 const QString& mailFromID = QString::null,
00087 const EmailAddressList& mailAddresses = EmailAddressList(),
00088 const QString& mailSubject = QString::null,
00089 const QStringList& mailAttachments = QStringList());
00090 bool handleEvent(const QString& calendarFile, const QString& eventID) { return handleEvent(calendarFile, eventID, EVENT_HANDLE); }
00091 bool triggerEvent(const QString& calendarFile, const QString& eventID) { return handleEvent(calendarFile, eventID, EVENT_TRIGGER); }
00092 bool deleteEvent(const QString& calendarFile, const QString& eventID) { return handleEvent(calendarFile, eventID, EVENT_CANCEL); }
00093 public slots:
00094 void processQueue();
00095 signals:
00096 void trayIconToggled();
00097 protected:
00098 KAlarmApp();
00099 private slots:
00100 void quitFatal();
00101 void slotPreferencesChanged();
00102 void slotCommandOutput(KProcess*, char* buffer, int bufflen);
00103 void slotLogProcExited(ShellProcess*);
00104 void slotCommandExited(ShellProcess*);
00105 void slotSystemTrayTimer();
00106 void slotExpiredPurged();
00107 private:
00108 enum EventFunc
00109 {
00110 EVENT_HANDLE,
00111 EVENT_TRIGGER,
00112 EVENT_CANCEL
00113 };
00114 struct ProcData
00115 {
00116 ProcData(ShellProcess* p, ShellProcess* logp, KAEvent* e, KAAlarm* a, int f = 0)
00117 : process(p), logProcess(logp), event(e), alarm(a), messageBoxParent(0), flags(f) { }
00118 ~ProcData();
00119 enum { PRE_ACTION = 0x01, POST_ACTION = 0x02, RESCHEDULE = 0x04, ALLOW_DEFER = 0x08,
00120 TEMP_FILE = 0x10, EXEC_IN_XTERM = 0x20 };
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 ShellProcess* process;
00128 QGuardedPtr<ShellProcess> logProcess;
00129 KAEvent* event;
00130 KAAlarm* alarm;
00131 QGuardedPtr<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 void redisplayAlarms();
00148 bool checkSystemTray();
00149 void changeStartOfDay();
00150 void setUpDcop();
00151 bool handleEvent(const QString& calendarFile, const QString& eventID, EventFunc);
00152 bool handleEvent(const QString& eventID, EventFunc);
00153 void rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay);
00154 void cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
00155 ShellProcess* doShellCommand(const QString& command, const KAEvent&, const KAAlarm*, int flags = 0);
00156 QString createTempScriptFile(const QString& command, bool insertShell, const KAEvent&, const KAAlarm&);
00157 void commandErrorMsg(const ShellProcess*, const KAEvent&, const KAAlarm*, int flags = 0);
00158
00159 static KAlarmApp* theInstance;
00160 static int mActiveCount;
00161 static int mFatalError;
00162 static QString mFatalMessage;
00163 bool mInitialised;
00164 DcopHandler* mDcopHandler;
00165 #ifdef OLD_DCOP
00166 DcopHandlerOld* mDcopHandlerOld;
00167 #endif
00168 TrayWindow* mTrayWindow;
00169 QTime mStartOfDay;
00170 QColor mPrefsExpiredColour;
00171 int mPrefsExpiredKeepDays;
00172 QValueList<ProcData*> mCommandProcesses;
00173 QValueList<DcopQEntry> mDcopQueue;
00174 int mPendingQuitCode;
00175 bool mPendingQuit;
00176 bool mProcessingQueue;
00177 bool mKDEDesktop;
00178 bool mNoSystemTray;
00179 bool mSavedNoSystemTray;
00180 bool mCheckingSystemTray;
00181 bool mSessionClosingDown;
00182 bool mOldRunInSystemTray;
00183 bool mDisableAlarmsIfStopped;
00184 bool mRefreshExpiredAlarms;
00185 bool mSpeechEnabled;
00186 bool mKOrganizerEnabled;
00187 bool mPrefsShowTime;
00188 bool mPrefsShowTimeTo;
00189 };
00190
00191 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
00192
00193 #endif // KALARMAPP_H