summaryrefslogtreecommitdiffstats
path: root/kalarm/daemon.h
blob: df3fdd4d2aa5146f606974d49a8b751d5bd8d1b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 *  daemon.h  -  interface with alarm daemon
 *  Program:  kalarm
 *  Copyright © 2001-2007 by David Jarvie <software@astrojar.org.uk>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef DAEMON_H
#define DAEMON_H

#include <tqobject.h>
#include <tqdatetime.h>
#include <kaction.h>

#include <kalarmd/kalarmd.h>
#include <kalarmd/alarmguiiface.h>

class KActionCollection;
class AlarmCalendar;
class AlarmEnableAction;
class NotificationHandler;


class Daemon : public TQObject
{
		Q_OBJECT
  TQ_OBJECT
	public:
		static void      initialise();
		static void      createDcopHandler();
		static bool      isDcopHandlerReady()    { return mDcopHandler; }
		static AlarmEnableAction* createAlarmEnableAction(KActionCollection*, const char* name);
		static bool      start();
		static bool      reregister()            { return registerWith(true); }
		static bool      reset();
		static bool      stop();
		static bool      autoStart();
		static void      enableAutoStart(bool enable);
		static void      notifyTimeChanged();
		static void      setAlarmsEnabled()      { mInstance->setAlarmsEnabled(true); }
		static void      checktqStatus()           { checkIfRunning(); }
		static bool      monitoringAlarms();
		static bool      isRunning(bool startDaemon = true);
		static int       maxTimeSinceCheck();
		static bool      isRegistered()          { return mtqStatus == REGISTERED; }
		static void      allowRegisterFailMsg()  { mRegisterFailMsg = false; }

		static void      queueEvent(const TQString& eventID);
		static void      savingEvent(const TQString& eventID);
		static void      eventHandled(const TQString& eventID, bool reloadCal);

	signals:
		void             daemonRunning(bool running);

	private slots:
		void             slotCalendarSaved(AlarmCalendar*);
		void             checkIfStarted();
		void             slotStarted()           { updateRegisteredtqStatus(true); }
		void             registerTimerExpired()  { registrationResult((mtqStatus == REGISTERED), KAlarmd::FAILURE); }

		void             setAlarmsEnabled(bool enable);
		void             timerCheckIfRunning();
		void             slotPreferencesChanged();

	private:
		enum tqStatus    // daemon status.  KEEP IN THIS ORDER!!
		{
			STOPPED,     // daemon is not registered with DCOP
			RUNNING,     // daemon is newly registered with DCOP
			READY,       // daemon is ready to accept DCOP calls
			REGISTERED   // we have registered with the daemon
		};
		Daemon() { }
		static bool      registerWith(bool reregister);
		static void      registrationResult(bool reregister, int result, int version = 0);
		static void      reload();
		static void      notifyEventHandled(const TQString& eventID, bool reloadCal);
		static void      updateRegisteredtqStatus(bool timeout = false);
		static void      enableCalendar(bool enable);
		static void      calendarIsEnabled(bool enabled);
		static bool      checkIfRunning();
		static void      setFastCheck();

		static Daemon*   mInstance;            // only one instance allowed
		static NotificationHandler* mDcopHandler;  // handles DCOP requests from daemon
		static TQValueList<TQString>  mQueuedEvents; // IDs of pending events that daemon has triggered
		static TQValueList<TQString>  mSavingEvents; // IDs of updated events that are currently being saved
		static TQTimer*   mStartTimer;          // timer to check daemon status after starting daemon
		static TQTimer*   mRegisterTimer;       // timer to check whether daemon has sent registration status
		static TQTimer*   mStatusTimer;         // timer for checking daemon status
		static int       mStatusTimerCount;    // countdown for fast status checking
		static int       mStatusTimerInterval; // timer interval (seconds) for checking daemon status
		static int       mStartTimeout;        // remaining number of times to check if alarm daemon has started
		static tqStatus    mtqStatus;              // daemon status
		static bool      mRunning;             // whether the alarm daemon is currently running
		static bool      mCalendarDisabled;    // monitoring of calendar is currently disabled by daemon
		static bool      mEnableCalPending;    // waiting to tell daemon to enable calendar
		static bool      mRegisterFailMsg;     // true if registration failure message has been displayed

		friend class NotificationHandler;
};

/*=============================================================================
=  Class: AlarmEnableAction
=============================================================================*/

class AlarmEnableAction : public KToggleAction
{
		Q_OBJECT
  TQ_OBJECT
	public:
		AlarmEnableAction(int accel, TQObject* parent, const char* name = 0);
	public slots:
		void         setCheckedActual(bool);  // set state and emit switched() signal
		virtual void setChecked(bool);        // request state change and emit userClicked() signal
	signals:
		void         switched(bool);          // state has changed (KToggleAction::toggled() is only emitted when clicked by user)
		void         userClicked(bool);       // user has clicked the control (param = desired state)
	private:
		bool         mInitialised;
};

#endif // DAEMON_H