kalarm

daemon.h

00001 /*
00002  *  daemon.h  -  interface with alarm daemon
00003  *  Program:  kalarm
00004  *  Copyright (c) 2001-2006 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 <qobject.h>
00025 #include <qdatetime.h>
00026 #include <kaction.h>
00027 
00028 #include <kalarmd/kalarmd.h>
00029 #include <kalarmd/alarmguiiface.h>
00030 
00031 class KActionCollection;
00032 class AlarmCalendar;
00033 class AlarmEnableAction;
00034 class NotificationHandler;
00035 
00036 
00037 class Daemon : public QObject
00038 {
00039         Q_OBJECT
00040     public:
00041         static void      initialise();
00042         static void      createDcopHandler();
00043         static bool      isDcopHandlerReady()    { return mDcopHandler; }
00044         static AlarmEnableAction* createAlarmEnableAction(KActionCollection*, const char* name);
00045         static bool      start();
00046         static bool      reregister()            { return registerWith(true); }
00047         static bool      reset();
00048         static bool      stop();
00049         static bool      autoStart();
00050         static void      enableAutoStart(bool enable);
00051         static void      setAlarmsEnabled()      { mInstance->setAlarmsEnabled(true); }
00052         static void      checkStatus()           { checkIfRunning(); }
00053         static bool      monitoringAlarms();
00054         static bool      isRunning(bool startDaemon = true);
00055         static int       maxTimeSinceCheck();
00056         static bool      isRegistered()          { return mStatus == REGISTERED; }
00057         static void      allowRegisterFailMsg()  { mRegisterFailMsg = false; }
00058 
00059         static void      queueEvent(const QString& eventID);
00060         static void      savingEvent(const QString& eventID);
00061         static void      eventHandled(const QString& eventID, bool reloadCal);
00062 
00063     signals:
00064         void             daemonRunning(bool running);
00065 
00066     private slots:
00067         void             slotCalendarSaved(AlarmCalendar*);
00068         void             checkIfStarted();
00069         void             slotStarted()           { updateRegisteredStatus(true); }
00070         void             registerTimerExpired()  { registrationResult((mStatus == REGISTERED), KAlarmd::FAILURE); }
00071 
00072         void             setAlarmsEnabled(bool enable);
00073         void             timerCheckIfRunning();
00074         void             slotPreferencesChanged();
00075 
00076     private:
00077         enum Status    // daemon status.  KEEP IN THIS ORDER!!
00078         {
00079             STOPPED,     // daemon is not registered with DCOP
00080             RUNNING,     // daemon is newly registered with DCOP
00081             READY,       // daemon is ready to accept DCOP calls
00082             REGISTERED   // we have registered with the daemon
00083         };
00084         Daemon() { }
00085         static bool      registerWith(bool reregister);
00086         static void      registrationResult(bool reregister, int result);
00087         static void      reload();
00088         static void      notifyEventHandled(const QString& eventID, bool reloadCal);
00089         static void      updateRegisteredStatus(bool timeout = false);
00090         static void      enableCalendar(bool enable);
00091         static void      calendarIsEnabled(bool enabled);
00092         static bool      checkIfRunning();
00093         static void      setFastCheck();
00094 
00095         static Daemon*   mInstance;            // only one instance allowed
00096         static NotificationHandler* mDcopHandler;  // handles DCOP requests from daemon
00097         static QValueList<QString>  mQueuedEvents; // IDs of pending events that daemon has triggered
00098         static QValueList<QString>  mSavingEvents; // IDs of updated events that are currently being saved
00099         static QTimer*   mStartTimer;          // timer to check daemon status after starting daemon
00100         static QTimer*   mRegisterTimer;       // timer to check whether daemon has sent registration status
00101         static QTimer*   mStatusTimer;         // timer for checking daemon status
00102         static int       mStatusTimerCount;    // countdown for fast status checking
00103         static int       mStatusTimerInterval; // timer interval (seconds) for checking daemon status
00104         static int       mStartTimeout;        // remaining number of times to check if alarm daemon has started
00105         static Status    mStatus;              // daemon status
00106         static bool      mRunning;             // whether the alarm daemon is currently running
00107         static bool      mCalendarDisabled;    // monitoring of calendar is currently disabled by daemon
00108         static bool      mEnableCalPending;    // waiting to tell daemon to enable calendar
00109         static bool      mRegisterFailMsg;     // true if registration failure message has been displayed
00110 
00111         friend class NotificationHandler;
00112 };
00113 
00114 /*=============================================================================
00115 =  Class: AlarmEnableAction
00116 =============================================================================*/
00117 
00118 class AlarmEnableAction : public KToggleAction
00119 {
00120         Q_OBJECT
00121     public:
00122         AlarmEnableAction(int accel, QObject* parent, const char* name = 0);
00123     public slots:
00124         void         setCheckedActual(bool);  // set state and emit switched() signal
00125         virtual void setChecked(bool);        // request state change and emit userClicked() signal
00126     signals:
00127         void         switched(bool);          // state has changed (KToggleAction::toggled() is only emitted when clicked by user)
00128         void         userClicked(bool);       // user has clicked the control (param = desired state)
00129     private:
00130         bool         mInitialised;
00131 };
00132 
00133 #endif // DAEMON_H
KDE Home | KDE Accessibility Home | Description of Access Keys