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
00024 class QDateTime;
00025
00026 #include <kuniqueapp.h>
00027 #include <kurl.h>
00028 class KAction;
00029
00030 #include "msgevent.h"
00031 class AlarmCalendar;
00032 class KAlarmMainWindow;
00033 class MessageWin;
00034 class TrayWindow;
00035 class DaemonGuiHandler;
00036 class Settings;
00037 class ActionAlarmsEnabled;
00038
00039 extern const char* DAEMON_APP_NAME;
00040 extern const char* DAEMON_DCOP_OBJECT;
00041 extern const char* GUI_DCOP_OBJECT_NAME;
00042
00043
00044 class DcopHandler : public QWidget, DCOPObject
00045 {
00046 Q_OBJECT
00047 public:
00048 DcopHandler(const char* name);
00049 ~DcopHandler() { }
00050 virtual bool process(const QCString& func, const QByteArray& data, QCString& replyType, QByteArray& replyData);
00051 };
00052
00053
00054 class KAlarmApp : public KUniqueApplication
00055 {
00056 Q_OBJECT
00057 public:
00058 ~KAlarmApp();
00059 virtual int newInstance();
00060 static KAlarmApp* getInstance();
00061 AlarmCalendar& getCalendar() { return *mCalendar; }
00062 void checkCalendar() { initCheck(); }
00063 Settings* settings() { return mSettings; }
00064 bool KDEDesktop() const { return mKDEDesktop; }
00065 bool runInSystemTray() const;
00066 bool restoreSession();
00067 bool sessionClosingDown() const { return mSessionClosingDown; }
00068 void quitIf() { quitIf(0); }
00069 void addWindow(TrayWindow* w) { mTrayWindow = w; }
00070 void removeWindow(TrayWindow*);
00071 TrayWindow* trayWindow() const { return mTrayWindow; }
00072 KAlarmMainWindow* trayMainWindow() const;
00073 bool displayTrayIcon(bool show, KAlarmMainWindow* = 0L);
00074 bool trayIconDisplayed() const { return !!mTrayWindow; }
00075 DaemonGuiHandler* daemonGuiHandler() const { return mDaemonGuiHandler; }
00076 ActionAlarmsEnabled* actionAlarmEnable() const { return mActionAlarmEnable; }
00077 KAction* actionPreferences() const { return mActionPrefs; }
00078 KAction* actionDaemonControl() const { return mActionDaemonControl; }
00079 void resetDaemon();
00080 bool isDaemonRunning();
00081 void readDaemonCheckInterval();
00082 QSize readConfigWindowSize(const char* window, const QSize& defaultSize);
00083 void writeConfigWindowSize(const char* window, const QSize&);
00084 virtual void commitData(QSessionManager&);
00085
00086 bool addEvent(const KAlarmEvent&, KAlarmMainWindow*);
00087 void modifyEvent(const QString& oldEventID, const KAlarmEvent& newEvent, KAlarmMainWindow*);
00088 void updateEvent(const KAlarmEvent&, KAlarmMainWindow*);
00089 void deleteEvent(KAlarmEvent&, KAlarmMainWindow*, bool tellDaemon = true);
00090 bool execAlarm(KAlarmEvent&, const KAlarmAlarm&, bool reschedule, bool allowDefer = true);
00091 void rescheduleAlarm(KAlarmEvent&, int alarmID);
00092 void deleteEvent(const QString& eventID) { handleEvent(eventID, EVENT_CANCEL); }
00093 int maxLateness();
00094
00095 bool scheduleEvent(const QString& text, const QDateTime&, const QColor& bg, int flags,
00096 const QString& audioFile, KAlarmAlarm::Type, KAlarmEvent::RecurType,
00097 int repeatInterval, int repeatCount, const QDateTime& endTime);
00098 void handleEvent(const QString& calendarFile, const QString& eventID) { handleEvent(calendarFile, eventID, EVENT_HANDLE); }
00099 void triggerEvent(const QString& calendarFile, const QString& eventID) { handleEvent(calendarFile, eventID, EVENT_TRIGGER); }
00100 void deleteEvent(const QString& calendarFile, const QString& eventID) { handleEvent(calendarFile, eventID, EVENT_CANCEL); }
00101
00102 static int isTextFile(const KURL&);
00103 public slots:
00104 void displayMainWindow();
00105 void slotDaemonControl();
00106 signals:
00107 void trayIconToggled();
00108 protected:
00109 KAlarmApp();
00110 private slots:
00111 void slotPreferences();
00112 void toggleAlarmsEnabled();
00113 void slotSettingsChanged();
00114 private:
00115 enum EventFunc { EVENT_HANDLE, EVENT_TRIGGER, EVENT_CANCEL };
00116 enum AlarmFunc { ALARM_TRIGGER, ALARM_CANCEL, ALARM_RESCHEDULE };
00117 bool initCheck(bool calendarOnly = false);
00118 void quitIf(int exitCode);
00119 void changeStartOfDay();
00120 void setUpDcop();
00121 bool stopDaemon();
00122 void startDaemon();
00123 void reloadDaemon();
00124 void registerWithDaemon(bool reregister);
00125 void handleEvent(const QString& calendarFile, const QString& eventID, EventFunc);
00126 bool handleEvent(const QString& eventID, EventFunc);
00127 void handleAlarm(KAlarmEvent&, KAlarmAlarm&, AlarmFunc, bool updateCalAndDisplay);
00128
00129 static KAlarmApp* theInstance;
00130 static int activeCount;
00131 DcopHandler* mDcopHandler;
00132 DaemonGuiHandler* mDaemonGuiHandler;
00133 TrayWindow* mTrayWindow;
00134 AlarmCalendar* mCalendar;
00135 ActionAlarmsEnabled* mActionAlarmEnable;
00136 KAction* mActionPrefs;
00137 KAction* mActionDaemonControl;
00138 Settings* mSettings;
00139 QDateTime mLastDaemonCheck;
00140 QDateTime mNextDaemonCheck;
00141 QTime mStartOfDay;
00142 int mDaemonCheckInterval;
00143 bool mDaemonRegistered;
00144 bool mKDEDesktop;
00145 bool mDaemonRunning;
00146 bool mSessionClosingDown;
00147 bool mOldRunInSystemTray;
00148 bool mDisableAlarmsIfStopped;
00149 };
00150
00151 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
00152
00153 #endif // KALARMAPP_H