• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm/lib

  • sources
  • kde-4.14
  • kdepim
  • kalarm
  • lib
synchtimer.h
Go to the documentation of this file.
1 /*
2  * synchtimer.h - timers which synchronize to time boundaries
3  * Program: kalarm
4  * Copyright © 2004,2005 by David Jarvie <djarvie@kde.org>
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 SYNCHTIMER_H
22 #define SYNCHTIMER_H
23 
24 /* @file synchtimer.h - timers which synchronize to time boundaries */
25 
26 #include <QObject>
27 #include <QList>
28 #include <QByteArray>
29 #include <QDateTime>
30 class QTimer;
31 
37 class SynchTimer : public QObject
38 {
39  Q_OBJECT
40  public:
41  virtual ~SynchTimer();
42 
43  struct Connection
44  {
45  Connection() { }
46  Connection(QObject* r, const char* s) : receiver(r), slot(s) { }
47  bool operator==(const Connection& c) const { return receiver == c.receiver && slot == c.slot; }
48  QObject* receiver;
49  QByteArray slot;
50  };
51  protected:
52  SynchTimer();
53  virtual void start() = 0;
54  void connecT(QObject* receiver, const char* member);
55  void disconnecT(QObject* receiver, const char* member = 0);
56  bool hasConnections() const { return !mConnections.isEmpty(); }
57 
58  QTimer* mTimer;
59 
60  protected slots:
61  virtual void slotTimer() = 0;
62 
63  private slots:
64  void slotReceiverGone(QObject* r) { disconnecT(r); }
65 
66  private:
67  SynchTimer(const SynchTimer&); // prohibit copying
68  QList<Connection> mConnections; // list of current clients
69 };
70 
71 
76 class MinuteTimer : public SynchTimer
77 {
78  Q_OBJECT
79  public:
80  virtual ~MinuteTimer() { mInstance = 0; }
85  static void connect(QObject* receiver, const char* member)
86  { instance()->connecT(receiver, member); }
92  static void disconnect(QObject* receiver, const char* member = 0)
93  { if (mInstance) mInstance->disconnecT(receiver, member); }
94 
95  protected:
96  MinuteTimer() : SynchTimer() { }
97  static MinuteTimer* instance();
98  virtual void start() { slotTimer(); }
99 
100  protected slots:
101  virtual void slotTimer();
102 
103  private:
104  static MinuteTimer* mInstance; // the one and only instance
105 };
106 
107 
115 class DailyTimer : public SynchTimer
116 {
117  Q_OBJECT
118  public:
119  virtual ~DailyTimer();
126  static void connect(const QTime& timeOfDay, QObject* receiver, const char* member)
127  { fixedInstance(timeOfDay)->connecT(receiver, member); }
135  static void disconnect(const QTime& timeOfDay, QObject* receiver, const char* member = 0);
142  void changeTime(const QTime& newTimeOfDay, bool triggerMissed = true);
144  QTime timeOfDay() const { return mTime; }
145 
146  protected:
152  DailyTimer(const QTime&, bool fixed);
160  static DailyTimer* fixedInstance(const QTime& timeOfDay, bool create = true);
161  virtual void start();
162 
163  protected slots:
164  virtual void slotTimer();
165 
166  private:
167  static QList<DailyTimer*> mFixedTimers; // list of timers whose trigger time is fixed
168  QTime mTime;
169  QDate mLastDate; // the date on which the timer was last triggered
170  bool mFixed; // the time at which the timer triggers cannot be changed
171 };
172 
173 
178 class MidnightTimer
179 {
180  public:
185  static void connect(QObject* receiver, const char* member)
186  { DailyTimer::connect(QTime(0,0), receiver, member); }
192  static void disconnect(QObject* receiver, const char* member = 0)
193  { DailyTimer::disconnect(QTime(0,0), receiver, member); }
194 
195 };
196 
197 #endif // SYNCHTIMER_H
198 
199 // vim: et sw=4:
DailyTimer
DailyTimer is an application-wide timer synchronized to a specified time of day, local time...
Definition: synchtimer.h:115
DailyTimer::timeOfDay
QTime timeOfDay() const
Return the current time of day at which this variable timer triggers.
Definition: synchtimer.h:144
QByteArray
MidnightTimer::connect
static void connect(QObject *receiver, const char *member)
Connect to the timer signal.
Definition: synchtimer.h:185
SynchTimer::mTimer
QTimer * mTimer
Definition: synchtimer.h:58
MidnightTimer
MidnightTimer is an application-wide timer synchronized to midnight, local time.
Definition: synchtimer.h:178
DailyTimer::slotTimer
virtual void slotTimer()
Definition: synchtimer.cpp:229
SynchTimer::start
virtual void start()=0
SynchTimer::SynchTimer
SynchTimer()
Definition: synchtimer.cpp:32
MinuteTimer::instance
static MinuteTimer * instance()
Definition: synchtimer.cpp:101
DailyTimer::connect
static void connect(const QTime &timeOfDay, QObject *receiver, const char *member)
Connect to the timer signal which triggers at the given fixed time of day.
Definition: synchtimer.h:126
SynchTimer::Connection::receiver
QObject * receiver
Definition: synchtimer.h:48
QTime
DailyTimer::DailyTimer
DailyTimer(const QTime &, bool fixed)
Construct an instance.
Definition: synchtimer.cpp:129
MinuteTimer::slotTimer
virtual void slotTimer()
Definition: synchtimer.cpp:114
SynchTimer::Connection::slot
QByteArray slot
Definition: synchtimer.h:49
SynchTimer::~SynchTimer
virtual ~SynchTimer()
Definition: synchtimer.cpp:38
DailyTimer::start
virtual void start()
Definition: synchtimer.cpp:201
QTimer
QObject
SynchTimer::disconnecT
void disconnecT(QObject *receiver, const char *member=0)
Definition: synchtimer.cpp:64
QDate
MinuteTimer::disconnect
static void disconnect(QObject *receiver, const char *member=0)
Disconnect from the timer signal.
Definition: synchtimer.h:92
MinuteTimer::connect
static void connect(QObject *receiver, const char *member)
Connect to the timer signal.
Definition: synchtimer.h:85
MinuteTimer
MinuteTimer is an application-wide timer synchronized to the minute boundary.
Definition: synchtimer.h:76
QList
DailyTimer::fixedInstance
static DailyTimer * fixedInstance(const QTime &timeOfDay, bool create=true)
Return the instance which triggers at the specified fixed time of day, optionally creating a new inst...
Definition: synchtimer.cpp:143
SynchTimer::hasConnections
bool hasConnections() const
Definition: synchtimer.h:56
SynchTimer::Connection::Connection
Connection(QObject *r, const char *s)
Definition: synchtimer.h:46
SynchTimer::Connection::Connection
Connection()
Definition: synchtimer.h:45
DailyTimer::disconnect
static void disconnect(const QTime &timeOfDay, QObject *receiver, const char *member=0)
Disconnect from the timer signal which triggers at the given fixed time of day.
Definition: synchtimer.cpp:155
DailyTimer::~DailyTimer
virtual ~DailyTimer()
Definition: synchtimer.cpp:137
MinuteTimer::MinuteTimer
MinuteTimer()
Definition: synchtimer.h:96
MinuteTimer::start
virtual void start()
Definition: synchtimer.h:98
SynchTimer::connecT
void connecT(QObject *receiver, const char *member)
Definition: synchtimer.cpp:47
MidnightTimer::disconnect
static void disconnect(QObject *receiver, const char *member=0)
Disconnect from the timer signal.
Definition: synchtimer.h:192
SynchTimer
SynchTimer is a virtual base class for application-wide timers synchronized to a time boundary...
Definition: synchtimer.h:37
MinuteTimer::~MinuteTimer
virtual ~MinuteTimer()
Definition: synchtimer.h:80
SynchTimer::Connection
Definition: synchtimer.h:43
DailyTimer::changeTime
void changeTime(const QTime &newTimeOfDay, bool triggerMissed=true)
Change the time at which this variable timer triggers.
Definition: synchtimer.cpp:168
SynchTimer::Connection::operator==
bool operator==(const Connection &c) const
Definition: synchtimer.h:47
SynchTimer::slotTimer
virtual void slotTimer()=0
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:35:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm/lib

Skip menu "kalarm/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal