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 TQ_OBJECT
00052 public:
00053 ~KAlarmApp();
00054 virtual int newInstance();
00055 static KAlarmApp* getInstance();
00056 bool checkCalendarDaemon() { return initCheck(); }
00057 bool haveSystemTray() const { return mHaveSystemTray; }
00058 bool wantRunInSystemTray() const;
00059 bool alarmsDisabledIfStopped() const { return mDisableAlarmsIfStopped; }
00060 bool speechEnabled() const { return mSpeechEnabled; }
00061 bool korganizerEnabled() const { return mKOrganizerEnabled; }
00062 bool restoreSession();
00063 bool sessionClosingDown() const { return mSessionClosingDown; }
00064 void quitIf() { quitIf(0); }
00065 void doQuit(TQWidget* parent);
00066 static void displayFatalError(const TQString& message);
00067 void addWindow(TrayWindow* w) { mTrayWindow = w; }
00068 void removeWindow(TrayWindow*);
00069 TrayWindow* trayWindow() const { return mTrayWindow; }
00070 MainWindow* trayMainWindow() const;
00071 bool displayTrayIcon(bool show, MainWindow* = 0);
00072 bool trayIconDisplayed() const { return !!mTrayWindow; }
00073 bool editNewAlarm(MainWindow* = 0);
00074 virtual void commitData(TQSessionManager&);
00075
00076 void* execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
00077 void alarmShowing(KAEvent&, KAAlarm::Type, const DateTime&);
00078 void alarmCompleted(const KAEvent&);
00079 bool deleteEvent(const TQString& eventID) { return handleEvent(eventID, EVENT_CANCEL); }
00080 void commandMessage(ShellProcess*, TQWidget* parent);
00081
00082 bool scheduleEvent(KAEvent::Action, const TQString& text, const TQDateTime&,
00083 int lateCancel, int flags, const TQColor& bg, const TQColor& fg,
00084 const TQFont&, const TQString& audioFile, float audioVolume,
00085 int reminderMinutes, const KARecurrence& recurrence,
00086 int repeatInterval, int repeatCount,
00087 uint mailFromID = 0, const EmailAddressList& mailAddresses = EmailAddressList(),
00088 const TQString& mailSubject = TQString(),
00089 const TQStringList& mailAttachments = TQStringList());
00090 bool handleEvent(const TQString& calendarFile, const TQString& eventID) { return handleEvent(calendarFile, eventID, EVENT_HANDLE); }
00091 bool triggerEvent(const TQString& calendarFile, const TQString& eventID) { return handleEvent(calendarFile, eventID, EVENT_TRIGGER); }
00092 bool deleteEvent(const TQString& calendarFile, const TQString& 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 TQGuardedPtr<ShellProcess> logProcess;
00128 KAEvent* event;
00129 KAAlarm* alarm;
00130 TQGuardedPtr<TQWidget> messageBoxParent;
00131 TQStringList tempFiles;
00132 int flags;
00133 };
00134 struct DcopTQEntry
00135 {
00136 DcopTQEntry(EventFunc f, const TQString& id) : function(f), eventId(id) { }
00137 DcopTQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
00138 DcopTQEntry() { }
00139 EventFunc function;
00140 TQString 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 TQString& calendarFile, const TQString& eventID, EventFunc);
00151 bool handleEvent(const TQString& eventID, EventFunc);
00152 void rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay);
00153 void cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
00154 ShellProcess* doShellCommand(const TQString& command, const KAEvent&, const KAAlarm*, int flags = 0);
00155 TQString createTempScriptFile(const TQString& 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 TQString mFatalMessage;
00162 bool mInitialised;
00163 DcopHandler* mDcopHandler;
00164 #ifdef OLD_DCOP
00165 DcopHandlerOld* mDcopHandlerOld;
00166 #endif
00167 TrayWindow* mTrayWindow;
00168 TQTime mStartOfDay;
00169 TQColor mPrefsExpiredColour;
00170 int mPrefsExpiredKeepDays;
00171 TQValueList<ProcData*> mCommandProcesses;
00172 TQValueList<DcopTQEntry> 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 };
00187
00188 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
00189
00190 #endif // KALARMAPP_H