Buteo Synchronization Framework
SyncSchedule.h
1/*
2 * This file is part of buteo-syncfw package
3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 * Copyright (C) 2014-2019 Jolla Ltd.
6 * Copyright (C) 2020 Open Mobile Platform LLC.
7 *
8 * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * version 2.1 as published by the Free Software Foundation.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25#ifndef SYNCSCHEDULE_H
26#define SYNCSCHEDULE_H
27
28#include <QTime>
29#include <QFlags>
30#include <QObject>
31
32class QDomDocument;
33class QDomElement;
34
35namespace Buteo {
36
37class SyncSchedulePrivate;
38class SyncScheduleTest;
39
40const QString SYNC_SCHEDULE_ENABLED_KEY_BOOL("scheduler/schedule_enabled");
41const QString SYNC_SCHEDULE_PEAK_ENABLED_KEY_BOOL("scheduler/schedule_peak_enabled");
42const QString SYNC_SCHEDULE_OFFPEAK_ENABLED_KEY_BOOL("scheduler/schedule_offpeak_enabled");
43const QString SYNC_SCHEDULE_PEAK_DAYS_KEY_INT ("scheduler/schedule_peak_days");
44const QString SYNC_SCHEDULE_PEAK_START_TIME_KEY_INT ("scheduler/schedule_peak_start_time");
45const QString SYNC_SCHEDULE_PEAK_END_TIME_KEY_INT ("scheduler/schedule_peak_end_time");
46const QString SYNC_SCHEDULE_PEAK_SCHEDULE_KEY_INT ("scheduler/schedule_peak");
47const QString SYNC_SCHEDULE_OFFPEAK_SCHEDULE_KEY_INT ("scheduler/schedule_off_peak");
48
53{
54 Q_GADGET
55 Q_PROPERTY(QTime time READ time)
56 Q_PROPERTY(Days days READ days)
57 Q_PROPERTY(unsigned interval READ interval)
58 Q_PROPERTY(bool enabled READ scheduleEnabled)
59 Q_PROPERTY(QTime rushBegin READ rushBegin)
60 Q_PROPERTY(QTime rushEnd READ rushEnd)
61 Q_PROPERTY(Days rushDays READ rushDays)
62 Q_PROPERTY(unsigned rushInterval READ rushInterval)
63 Q_PROPERTY(bool rushEnabled READ rushEnabled)
64public:
65 enum Day {
66 NoDays = 0x00,
67 Monday = 0x01,
68 Tuesday = 0x02,
69 Wednesday = 0x04,
70 Thursday = 0x08,
71 Friday = 0x10,
72 Saturday = 0x20,
73 Sunday = 0x40
74 };
75 Q_DECLARE_FLAGS(Days, Day)
76 Q_FLAG(Days)
77
78
82
87 SyncSchedule(const SyncSchedule &aSource);
88
93 explicit SyncSchedule(const QDomElement &aRoot);
94
98
103 SyncSchedule &operator=(const SyncSchedule &aRhs);
104
109 bool operator==(const SyncSchedule &aRhs) const;
110
116 QDomElement toXml(QDomDocument &aDoc) const;
117
122 QString toString() const;
123
129 Days days() const;
130
135 void setDays(Days aDays);
136
141 QTime time() const;
142
148 void setTime(const QTime &aTime);
149
154 void setScheduleConfiguredTime(const QDateTime &aDateTime);
155
160 QDateTime scheduleConfiguredTime();
161
166 unsigned interval() const;
167
173 void setInterval(unsigned aInterval);
174
179 bool scheduleEnabled() const;
180
185 void setScheduleEnabled(bool aEnabled);
186
187 // ============== RUSH HOUR SETTINGS ============================
188
189
194 bool rushEnabled() const;
195
200 void setRushEnabled(bool aEnabled);
201
208 bool syncExternallyDuringRush() const;
209
214 void setSyncExternallyDuringRush(bool aEnabled);
215
220 Days rushDays() const;
221
226 void setRushDays(Days aDays);
227
232 QTime rushBegin() const;
233
238 QTime rushEnd() const;
239
245 void setRushTime(const QTime &aBegin, const QTime &aEnd);
246
251 unsigned rushInterval() const;
252
257 void setRushInterval(unsigned aInterval);
258
263 bool inExternalSyncRushPeriod(const QDateTime &aDateTime) const;
264
270 QDateTime nextSyncTime(const QDateTime &aPrevSync) const;
271
278 QDateTime nextRushSwitchTime(const QDateTime &aFromTime) const;
279
286 bool isSyncScheduled(const QDateTime &aActualDateTime, const QDateTime &aPreviousSyncTime = QDateTime()) const;
287
288private:
289
290 SyncSchedulePrivate *d_ptr;
291
292#ifdef SYNCFW_UNIT_TESTS
293 friend class SyncScheduleTest;
294#endif
295
296};
297
298}
299
300Q_DECLARE_METATYPE(Buteo::SyncSchedule)
301
302#endif // SYNCSCHEDULE_H
Private implementation class for SyncSchedule.
Definition SyncSchedule_p.h:36
Class for handling sync schedule settings.
Definition SyncSchedule.h:53
QString toString() const
Exports the sync schedule to QString.
Definition SyncSchedule.cpp:156
bool operator==(const SyncSchedule &aRhs) const
Equal to operator.
Definition SyncSchedule.cpp:108
SyncSchedule()
Constructs an empty schedule.
Definition SyncSchedule.cpp:58
SyncSchedule & operator=(const SyncSchedule &aRhs)
Assignment operator.
Definition SyncSchedule.cpp:98
bool isSyncScheduled(const QDateTime &aActualDateTime, const QDateTime &aPreviousSyncTime=QDateTime()) const
Returns true if aDateTime is within a scheduled period.
Definition SyncSchedule.cpp:495
QDateTime scheduleConfiguredTime()
To get the scheduled config time.
Definition SyncSchedule.cpp:184
QDateTime nextRushSwitchTime(const QDateTime &aFromTime) const
Gets next time to switch rush/off-rush schedule intervals.
Definition SyncSchedule.cpp:471
void setTime(const QTime &aTime)
Sets the exact time for sync.
Definition SyncSchedule.cpp:194
void setScheduleEnabled(bool aEnabled)
Sets if normal schedule is to be obeyed.
Definition SyncSchedule.cpp:214
bool scheduleEnabled() const
Checks if normal schedule is obeyed.
Definition SyncSchedule.cpp:209
void setInterval(unsigned aInterval)
Sets sync interval in minutes.
Definition SyncSchedule.cpp:204
void setDays(Days aDays)
Sets the enabled week days.
Definition SyncSchedule.cpp:174
void setRushDays(Days aDays)
Sets days enabled for rush hours.
Definition SyncSchedule.cpp:244
void setScheduleConfiguredTime(const QDateTime &aDateTime)
Sets scheduled config time.
Definition SyncSchedule.cpp:179
bool inExternalSyncRushPeriod(const QDateTime &aDateTime) const
Checks if a given time is inside rush hour and if the sync is controlled by a external process.
Definition SyncSchedule.cpp:275
bool syncExternallyDuringRush() const
Checks if rush schedule is controlled by a external process.
Definition SyncSchedule.cpp:229
void setRushTime(const QTime &aBegin, const QTime &aEnd)
Sets begin and end times of rush hours.
Definition SyncSchedule.cpp:259
~SyncSchedule()
Destructor.
Definition SyncSchedule.cpp:92
void setSyncExternallyDuringRush(bool aEnabled)
Sets if rush schedule is controlled by a external process.
Definition SyncSchedule.cpp:234
void setRushInterval(unsigned aInterval)
Sets sync interval for rush hours.
Definition SyncSchedule.cpp:270
QDateTime nextSyncTime(const QDateTime &aPrevSync) const
Gets next sync time based on the sync schedule settings.
Definition SyncSchedule.cpp:285
QDomElement toXml(QDomDocument &aDoc) const
Exports the sync schedule to XML.
Definition SyncSchedule.cpp:132
void setRushEnabled(bool aEnabled)
Sets rush hour schedule is to be obeyed.
Definition SyncSchedule.cpp:224