kalarm

daemon.h
1 /*
2  * daemon.h - interface with alarm daemon
3  * Program: kalarm
4  * Copyright © 2001-2007 by David Jarvie <software@astrojar.org.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef DAEMON_H
22 #define DAEMON_H
23 
24 #include <tqobject.h>
25 #include <tqdatetime.h>
26 #include <tdeaction.h>
27 
28 #include <kalarmd/kalarmd.h>
29 #include <kalarmd/alarmguiiface.h>
30 
31 class TDEActionCollection;
32 class AlarmCalendar;
33 class AlarmEnableAction;
34 class NotificationHandler;
35 
36 
37 class Daemon : public TQObject
38 {
39  TQ_OBJECT
40 
41  public:
42  static void initialise();
43  static void createDcopHandler();
44  static bool isDcopHandlerReady() { return mDcopHandler; }
45  static AlarmEnableAction* createAlarmEnableAction(TDEActionCollection*, const char* name);
46  static bool start();
47  static bool reregister() { return registerWith(true); }
48  static bool reset();
49  static bool stop();
50  static bool autoStart();
51  static void enableAutoStart(bool enable);
52  static void notifyTimeChanged();
53  static void setAlarmsEnabled() { mInstance->setAlarmsEnabled(true); }
54  static void checkStatus() { checkIfRunning(); }
55  static bool monitoringAlarms();
56  static bool isRunning(bool startDaemon = true);
57  static int maxTimeSinceCheck();
58  static bool isRegistered() { return mStatus == REGISTERED; }
59  static void allowRegisterFailMsg() { mRegisterFailMsg = false; }
60 
61  static void queueEvent(const TQString& eventID);
62  static void savingEvent(const TQString& eventID);
63  static void eventHandled(const TQString& eventID, bool reloadCal);
64 
65  signals:
66  void daemonRunning(bool running);
67 
68  private slots:
69  void slotCalendarSaved(AlarmCalendar*);
70  void checkIfStarted();
71  void slotStarted() { updateRegisteredStatus(true); }
72  void registerTimerExpired() { registrationResult((mStatus == REGISTERED), KAlarmd::FAILURE); }
73 
74  void setAlarmsEnabled(bool enable);
75  void timerCheckIfRunning();
76  void slotPreferencesChanged();
77 
78  private:
79  enum Status // daemon status. KEEP IN THIS ORDER!!
80  {
81  STOPPED, // daemon is not registered with DCOP
82  RUNNING, // daemon is newly registered with DCOP
83  READY, // daemon is ready to accept DCOP calls
84  REGISTERED // we have registered with the daemon
85  };
86  Daemon() { }
87  static bool registerWith(bool reregister);
88  static void registrationResult(bool reregister, int result, int version = 0);
89  static void reload();
90  static void notifyEventHandled(const TQString& eventID, bool reloadCal);
91  static void updateRegisteredStatus(bool timeout = false);
92  static void enableCalendar(bool enable);
93  static void calendarIsEnabled(bool enabled);
94  static bool checkIfRunning();
95  static void setFastCheck();
96 
97  static Daemon* mInstance; // only one instance allowed
98  static NotificationHandler* mDcopHandler; // handles DCOP requests from daemon
99  static TQValueList<TQString> mQueuedEvents; // IDs of pending events that daemon has triggered
100  static TQValueList<TQString> mSavingEvents; // IDs of updated events that are currently being saved
101  static TQTimer* mStartTimer; // timer to check daemon status after starting daemon
102  static TQTimer* mRegisterTimer; // timer to check whether daemon has sent registration status
103  static TQTimer* mStatusTimer; // timer for checking daemon status
104  static int mStatusTimerCount; // countdown for fast status checking
105  static int mStatusTimerInterval; // timer interval (seconds) for checking daemon status
106  static int mStartTimeout; // remaining number of times to check if alarm daemon has started
107  static Status mStatus; // daemon status
108  static bool mRunning; // whether the alarm daemon is currently running
109  static bool mCalendarDisabled; // monitoring of calendar is currently disabled by daemon
110  static bool mEnableCalPending; // waiting to tell daemon to enable calendar
111  static bool mRegisterFailMsg; // true if registration failure message has been displayed
112 
113  friend class NotificationHandler;
114 };
115 
116 /*=============================================================================
117 = Class: AlarmEnableAction
118 =============================================================================*/
119 
120 class AlarmEnableAction : public TDEToggleAction
121 {
122  TQ_OBJECT
123 
124  public:
125  AlarmEnableAction(int accel, TQObject* parent, const char* name = 0);
126  public slots:
127  void setCheckedActual(bool); // set state and emit switched() signal
128  virtual void setChecked(bool); // request state change and emit userClicked() signal
129  signals:
130  void switched(bool); // state has changed (TDEToggleAction::toggled() is only emitted when clicked by user)
131  void userClicked(bool); // user has clicked the control (param = desired state)
132  private:
133  bool mInitialised;
134 };
135 
136 #endif // DAEMON_H
Provides read and write access to calendar files.
Definition: alarmcalendar.h:37