daemon.h
00001 /* 00002 * daemon.h - interface with alarm daemon 00003 * Program: kalarm 00004 * Copyright © 2001-2007 by David Jarvie <software@astrojar.org.uk> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program; if not, write to the Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef DAEMON_H 00022 #define DAEMON_H 00023 00024 #include <tqobject.h> 00025 #include <tqdatetime.h> 00026 #include <tdeaction.h> 00027 00028 #include <kalarmd/kalarmd.h> 00029 #include <kalarmd/alarmguiiface.h> 00030 00031 class TDEActionCollection; 00032 class AlarmCalendar; 00033 class AlarmEnableAction; 00034 class NotificationHandler; 00035 00036 00037 class Daemon : public TQObject 00038 { 00039 Q_OBJECT 00040 00041 public: 00042 static void initialise(); 00043 static void createDcopHandler(); 00044 static bool isDcopHandlerReady() { return mDcopHandler; } 00045 static AlarmEnableAction* createAlarmEnableAction(TDEActionCollection*, const char* name); 00046 static bool start(); 00047 static bool reregister() { return registerWith(true); } 00048 static bool reset(); 00049 static bool stop(); 00050 static bool autoStart(); 00051 static void enableAutoStart(bool enable); 00052 static void notifyTimeChanged(); 00053 static void setAlarmsEnabled() { mInstance->setAlarmsEnabled(true); } 00054 static void checkStatus() { checkIfRunning(); } 00055 static bool monitoringAlarms(); 00056 static bool isRunning(bool startDaemon = true); 00057 static int maxTimeSinceCheck(); 00058 static bool isRegistered() { return mStatus == REGISTERED; } 00059 static void allowRegisterFailMsg() { mRegisterFailMsg = false; } 00060 00061 static void queueEvent(const TQString& eventID); 00062 static void savingEvent(const TQString& eventID); 00063 static void eventHandled(const TQString& eventID, bool reloadCal); 00064 00065 signals: 00066 void daemonRunning(bool running); 00067 00068 private slots: 00069 void slotCalendarSaved(AlarmCalendar*); 00070 void checkIfStarted(); 00071 void slotStarted() { updateRegisteredStatus(true); } 00072 void registerTimerExpired() { registrationResult((mStatus == REGISTERED), KAlarmd::FAILURE); } 00073 00074 void setAlarmsEnabled(bool enable); 00075 void timerCheckIfRunning(); 00076 void slotPreferencesChanged(); 00077 00078 private: 00079 enum Status // daemon status. KEEP IN THIS ORDER!! 00080 { 00081 STOPPED, // daemon is not registered with DCOP 00082 RUNNING, // daemon is newly registered with DCOP 00083 READY, // daemon is ready to accept DCOP calls 00084 REGISTERED // we have registered with the daemon 00085 }; 00086 Daemon() { } 00087 static bool registerWith(bool reregister); 00088 static void registrationResult(bool reregister, int result, int version = 0); 00089 static void reload(); 00090 static void notifyEventHandled(const TQString& eventID, bool reloadCal); 00091 static void updateRegisteredStatus(bool timeout = false); 00092 static void enableCalendar(bool enable); 00093 static void calendarIsEnabled(bool enabled); 00094 static bool checkIfRunning(); 00095 static void setFastCheck(); 00096 00097 static Daemon* mInstance; // only one instance allowed 00098 static NotificationHandler* mDcopHandler; // handles DCOP requests from daemon 00099 static TQValueList<TQString> mQueuedEvents; // IDs of pending events that daemon has triggered 00100 static TQValueList<TQString> mSavingEvents; // IDs of updated events that are currently being saved 00101 static TQTimer* mStartTimer; // timer to check daemon status after starting daemon 00102 static TQTimer* mRegisterTimer; // timer to check whether daemon has sent registration status 00103 static TQTimer* mStatusTimer; // timer for checking daemon status 00104 static int mStatusTimerCount; // countdown for fast status checking 00105 static int mStatusTimerInterval; // timer interval (seconds) for checking daemon status 00106 static int mStartTimeout; // remaining number of times to check if alarm daemon has started 00107 static Status mStatus; // daemon status 00108 static bool mRunning; // whether the alarm daemon is currently running 00109 static bool mCalendarDisabled; // monitoring of calendar is currently disabled by daemon 00110 static bool mEnableCalPending; // waiting to tell daemon to enable calendar 00111 static bool mRegisterFailMsg; // true if registration failure message has been displayed 00112 00113 friend class NotificationHandler; 00114 }; 00115 00116 /*============================================================================= 00117 = Class: AlarmEnableAction 00118 =============================================================================*/ 00119 00120 class AlarmEnableAction : public TDEToggleAction 00121 { 00122 Q_OBJECT 00123 00124 public: 00125 AlarmEnableAction(int accel, TQObject* parent, const char* name = 0); 00126 public slots: 00127 void setCheckedActual(bool); // set state and emit switched() signal 00128 virtual void setChecked(bool); // request state change and emit userClicked() signal 00129 signals: 00130 void switched(bool); // state has changed (TDEToggleAction::toggled() is only emitted when clicked by user) 00131 void userClicked(bool); // user has clicked the control (param = desired state) 00132 private: 00133 bool mInitialised; 00134 }; 00135 00136 #endif // DAEMON_H