kalarm

daemon.h

00001 /*
00002  *  daemon.h  -  interface with alarm daemon
00003  *  Program:  kalarm
00004  *  Copyright (C) 2001 - 2004 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(bool defaultSetting);
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     signals:
00060         void             daemonRunning(bool running);
00061 
00062     private slots:
00063         void             slotCalendarSaved(AlarmCalendar*);
00064         void             checkIfStarted();
00065         void             slotStarted()           { updateRegisteredStatus(true); }
00066         void             registerTimerExpired()  { registrationResult((mStatus == REGISTERED), KAlarmd::FAILURE); }
00067 
00068         void             setAlarmsEnabled(bool enable);
00069         void             timerCheckIfRunning();
00070         void             slotPreferencesChanged();
00071 
00072     private:
00073         enum Status    // daemon status.  KEEP IN THIS ORDER!!
00074         {
00075             STOPPED,     // daemon is not registered with DCOP
00076             RUNNING,     // daemon is newly registered with DCOP
00077             READY,       // daemon is ready to accept DCOP calls
00078             REGISTERED   // we have registered with the daemon
00079         };
00080         Daemon() { }
00081         static bool      registerWith(bool reregister);
00082         static void      registrationResult(bool reregister, int result);
00083         static void      reload();
00084         static void      updateRegisteredStatus(bool timeout = false);
00085         static void      enableCalendar(bool enable);
00086         static void      calendarIsEnabled(bool enabled);
00087         static bool      checkIfRunning();
00088         static void      setFastCheck();
00089 
00090         static Daemon*   mInstance;            // only one instance allowed
00091         static NotificationHandler* mDcopHandler; // handles DCOP requests from daemon
00092         static QTimer*   mStartTimer;          // timer to check daemon status after starting daemon
00093         static QTimer*   mRegisterTimer;       // timer to check whether daemon has sent registration status
00094         static QTimer*   mStatusTimer;         // timer for checking daemon status
00095         static int       mStatusTimerCount;    // countdown for fast status checking
00096         static int       mStatusTimerInterval; // timer interval (seconds) for checking daemon status
00097         static int       mStartTimeout;        // remaining number of times to check if alarm daemon has started
00098         static Status    mStatus;              // daemon status
00099         static bool      mRunning;             // whether the alarm daemon is currently running
00100         static bool      mCalendarDisabled;    // monitoring of calendar is currently disabled by daemon
00101         static bool      mEnableCalPending;    // waiting to tell daemon to enable calendar
00102         static bool      mRegisterFailMsg;     // true if registration failure message has been displayed
00103 
00104         friend class NotificationHandler;
00105 };
00106 
00107 /*=============================================================================
00108 =  Class: AlarmEnableAction
00109 =============================================================================*/
00110 
00111 class AlarmEnableAction : public KToggleAction
00112 {
00113         Q_OBJECT
00114     public:
00115         AlarmEnableAction(int accel, QObject* parent, const char* name = 0);
00116     public slots:
00117         void         setCheckedActual(bool);  // set state and emit switched() signal
00118         virtual void setChecked(bool);        // request state change and emit userClicked() signal
00119     signals:
00120         void         switched(bool);          // state has changed (KToggleAction::toggled() is only emitted when clicked by user)
00121         void         userClicked(bool);       // user has clicked the control (param = desired state)
00122     private:
00123         bool         mInitialised;
00124 };
00125 
00126 #endif // DAEMON_H
KDE Home | KDE Accessibility Home | Description of Access Keys