1 /*
2   This file is part of KOrganizer.
3 
4   SPDX-FileCopyrightText: 2002 Adriaan de Groot <groot@kde.org>
5   SPDX-FileCopyrightText: 2004 Cornelius Schumacher <schumacher@kde.org>
6 
7   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
8 */
9 
10 #pragma once
11 
12 #include <QDate>
13 #include <QObject>
14 
15 class QTimer;
16 
17 class DateChecker : public QObject
18 {
19     Q_OBJECT
20 public:
21     explicit DateChecker(QObject *parent = nullptr);
22     ~DateChecker() override;
23 
24     /**
25       The DateChecker automatically checks for
26       the passage of midnight. If rollover type is
27       set to None, no signals are emitted and no
28       processing is done. With rollover set to
29       FollowDay, the day highlighter changes at
30       midnight and dayPassed() is emitted.
31       With FollowMonth, it has the same effect
32       as FollowDay but also adjusts the month that is
33       visible and emits monthPassed() when the month changes.
34     */
35     enum RolloverType { None, FollowDay, FollowMonth };
36     void enableRollover(RolloverType);
37 
38 Q_SIGNALS:
39     // Signals emitted at midnight carrying the new date.
40     void dayPassed(const QDate &);
41     void monthPassed(const QDate &);
42 
43 protected Q_SLOTS:
44     /**
45       Called regularly to see if we need to update the view
46       wrt. the today box and the month box. Only important
47       if you leave KOrganizer idle for long periods of time.
48 
49       Until we have a reliable way of setting QTimers to go
50       off at a particular wall-clock time, we need this,
51       which calls passedMidnight() at the right moments.
52     */
53     void possiblyPastMidnight();
54 
55     /**
56       Handles updating the view when midnight has come by due to idle time.
57     */
58     void passedMidnight();
59 
60 private:
61     QTimer *mUpdateTimer = nullptr;
62     QDate mLastDayChecked;
63     RolloverType mUpdateRollover;
64 };
65 
66