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 haveSystemTray() const { return mHaveSystemTray; }
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 ~ProcData();
00118 enum { PRE_ACTION = 0x01, POST_ACTION = 0x02, RESCHEDULE = 0x04, ALLOW_DEFER = 0x08,
00119 TEMP_FILE = 0x10, EXEC_IN_XTERM = 0x20 };
00120 bool preAction() const { return flags & PRE_ACTION; }
00121 bool postAction() const { return flags & POST_ACTION; }
00122 bool reschedule() const { return flags & RESCHEDULE; }
00123 bool allowDefer() const { return flags & ALLOW_DEFER; }
00124 bool tempFile() const { return flags & TEMP_FILE; }
00125 bool execInXterm() const { return flags & EXEC_IN_XTERM; }
00126 ShellProcess* process;
00127 QGuardedPtr<ShellProcess> logProcess;
00128 KAEvent* event;
00129 KAAlarm* alarm;
00130 QGuardedPtr<QWidget> messageBoxParent;
00131 QStringList tempFiles;
00132 int flags;
00133 };
00134 struct DcopQEntry
00135 {
00136 DcopQEntry(EventFunc f, const QString& id) : function(f), eventId(id) { }
00137 DcopQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
00138 DcopQEntry() { }
00139 EventFunc function;
00140 QString eventId;
00141 KAEvent event;
00142 };
00143
00144 bool initCheck(bool calendarOnly = false);
00145 void quitIf(int exitCode, bool force = false);
00146 void redisplayAlarms();
00147 bool checkSystemTray();
00148 void changeStartOfDay();
00149 void setUpDcop();
00150 bool handleEvent(const QString& calendarFile, const QString& eventID, EventFunc);
00151 bool handleEvent(const QString& eventID, EventFunc);
00152 void rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay);
00153 void cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
00154 ShellProcess* doShellCommand(const QString& command, const KAEvent&, const KAAlarm*, int flags = 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
00158 static KAlarmApp* theInstance;
00159 static int mActiveCount;
00160 static int mFatalError;
00161 static QString mFatalMessage;
00162 bool mInitialised;
00163 DcopHandler* mDcopHandler;
00164 #ifdef OLD_DCOP
00165 DcopHandlerOld* mDcopHandlerOld;
00166 #endif
00167 TrayWindow* mTrayWindow;
00168 QTime mStartOfDay;
00169 QColor mPrefsExpiredColour;
00170 int mPrefsExpiredKeepDays;
00171 QValueList<ProcData*> mCommandProcesses;
00172 QValueList<DcopQEntry> mDcopQueue;
00173 int mPendingQuitCode;
00174 bool mPendingQuit;
00175 bool mProcessingQueue;
00176 bool mHaveSystemTray;
00177 bool mNoSystemTray;
00178 bool mSavedNoSystemTray;
00179 bool mCheckingSystemTray;
00180 bool mSessionClosingDown;
00181 bool mOldRunInSystemTray;
00182 bool mDisableAlarmsIfStopped;
00183 bool mRefreshExpiredAlarms;
00184 bool mSpeechEnabled;
00185 bool mKOrganizerEnabled;
00186 bool mPrefsShowTime;
00187 bool mPrefsShowTimeTo;
00188 };
00189
00190 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
00191
00192 #endif // KALARMAPP_H