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 <tqguardedptr.h>
00027 class TQTimer;
00028 class TQDateTime;
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(TQWidget* parent);
00065 static void displayFatalError(const TQString& 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 TQString& eventID) { return handleEvent(eventID, EVENT_CANCEL); }
00079 void commandMessage(ShellProcess*, TQWidget* parent);
00080
00081 bool scheduleEvent(KAEvent::Action, const TQString& text, const TQDateTime&,
00082 int lateCancel, int flags, const TQColor& bg, const TQColor& fg,
00083 const TQFont&, const TQString& audioFile, float audioVolume,
00084 int reminderMinutes, const KARecurrence& recurrence,
00085 int repeatInterval, int repeatCount,
00086 uint mailFromID = 0, const EmailAddressList& mailAddresses = EmailAddressList(),
00087 const TQString& mailSubject = TQString::null,
00088 const TQStringList& mailAttachments = TQStringList());
00089 bool handleEvent(const TQString& calendarFile, const TQString& eventID) { return handleEvent(calendarFile, eventID, EVENT_HANDLE); }
00090 bool triggerEvent(const TQString& calendarFile, const TQString& eventID) { return handleEvent(calendarFile, eventID, EVENT_TRIGGER); }
00091 bool deleteEvent(const TQString& calendarFile, const TQString& eventID) { return handleEvent(calendarFile, eventID, EVENT_CANCEL); }
00092 public slots:
00093 void processQueue();
00094 signals:
00095 void trayIconToggled();
00096 protected:
00097 KAlarmApp();
00098 private slots:
00099 void quitFatal();
00100 void slotPreferencesChanged();
00101 void slotCommandOutput(KProcess*, char* buffer, int bufflen);
00102 void slotLogProcExited(ShellProcess*);
00103 void slotCommandExited(ShellProcess*);
00104 void slotSystemTrayTimer();
00105 void slotExpiredPurged();
00106 private:
00107 enum EventFunc
00108 {
00109 EVENT_HANDLE,
00110 EVENT_TRIGGER,
00111 EVENT_CANCEL
00112 };
00113 struct ProcData
00114 {
00115 ProcData(ShellProcess* p, ShellProcess* logp, KAEvent* e, KAAlarm* a, int f = 0);
00116 ~ProcData();
00117 enum { PRE_ACTION = 0x01, POST_ACTION = 0x02, RESCHEDULE = 0x04, ALLOW_DEFER = 0x08,
00118 TEMP_FILE = 0x10, EXEC_IN_XTERM = 0x20 };
00119 bool preAction() const { return flags & PRE_ACTION; }
00120 bool postAction() const { return flags & POST_ACTION; }
00121 bool reschedule() const { return flags & RESCHEDULE; }
00122 bool allowDefer() const { return flags & ALLOW_DEFER; }
00123 bool tempFile() const { return flags & TEMP_FILE; }
00124 bool execInXterm() const { return flags & EXEC_IN_XTERM; }
00125 ShellProcess* process;
00126 TQGuardedPtr<ShellProcess> logProcess;
00127 KAEvent* event;
00128 KAAlarm* alarm;
00129 TQGuardedPtr<TQWidget> messageBoxParent;
00130 TQStringList tempFiles;
00131 int flags;
00132 };
00133 struct DcopQEntry
00134 {
00135 DcopQEntry(EventFunc f, const TQString& id) : function(f), eventId(id) { }
00136 DcopQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
00137 DcopQEntry() { }
00138 EventFunc function;
00139 TQString eventId;
00140 KAEvent event;
00141 };
00142
00143 bool initCheck(bool calendarOnly = false);
00144 void quitIf(int exitCode, bool force = false);
00145 void redisplayAlarms();
00146 bool checkSystemTray();
00147 void changeStartOfDay();
00148 void setUpDcop();
00149 bool handleEvent(const TQString& calendarFile, const TQString& eventID, EventFunc);
00150 bool handleEvent(const TQString& eventID, EventFunc);
00151 void rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay);
00152 void cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
00153 ShellProcess* doShellCommand(const TQString& command, const KAEvent&, const KAAlarm*, int flags = 0);
00154 TQString createTempScriptFile(const TQString& command, bool insertShell, const KAEvent&, const KAAlarm&);
00155 void commandErrorMsg(const ShellProcess*, const KAEvent&, const KAAlarm*, int flags = 0);
00156
00157 static KAlarmApp* theInstance;
00158 static int mActiveCount;
00159 static int mFatalError;
00160 static TQString mFatalMessage;
00161 bool mInitialised;
00162 DcopHandler* mDcopHandler;
00163 #ifdef OLD_DCOP
00164 DcopHandlerOld* mDcopHandlerOld;
00165 #endif
00166 TrayWindow* mTrayWindow;
00167 TQTime mStartOfDay;
00168 TQColor mPrefsExpiredColour;
00169 int mPrefsExpiredKeepDays;
00170 TQValueList<ProcData*> mCommandProcesses;
00171 TQValueList<DcopQEntry> mDcopQueue;
00172 int mPendingQuitCode;
00173 bool mPendingQuit;
00174 bool mProcessingQueue;
00175 bool mHaveSystemTray;
00176 bool mNoSystemTray;
00177 bool mSavedNoSystemTray;
00178 bool mCheckingSystemTray;
00179 bool mSessionClosingDown;
00180 bool mOldRunInSystemTray;
00181 bool mDisableAlarmsIfStopped;
00182 bool mRefreshExpiredAlarms;
00183 bool mSpeechEnabled;
00184 bool mKOrganizerEnabled;
00185 };
00186
00187 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
00188
00189 #endif // KALARMAPP_H