Buteo Synchronization Framework: SyncSchedule.h Source File

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
52 class SyncSchedule
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
81 SyncSchedule();
82
87 SyncSchedule(const SyncSchedule &aSource);
88
93 explicit SyncSchedule(const QDomElement &aRoot);
94
97 ~SyncSchedule();
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
Buteo::SyncSchedulePrivate
Private implementation class for SyncSchedule.
Definition: SyncSchedule_p.h:36
Buteo::SyncSchedule
Class for handling sync schedule settings.
Definition: SyncSchedule.h:53
Buteo::SyncSchedule::toString
QString toString() const
Exports the sync schedule to QString.
Definition: SyncSchedule.cpp:156
Buteo::SyncSchedule::operator==
bool operator==(const SyncSchedule &aRhs) const
Equal to operator.
Definition: SyncSchedule.cpp:108
Buteo::SyncSchedule::SyncSchedule
SyncSchedule()
Constructs an empty schedule.
Definition: SyncSchedule.cpp:58
Buteo::SyncSchedule::operator=
SyncSchedule & operator=(const SyncSchedule &aRhs)
Assignment operator.
Definition: SyncSchedule.cpp:98
Buteo::SyncSchedule::isSyncScheduled
bool isSyncScheduled(const QDateTime &aActualDateTime, const QDateTime &aPreviousSyncTime=QDateTime()) const
Returns true if aDateTime is within a scheduled period.
Definition: SyncSchedule.cpp:495
Buteo::SyncSchedule::scheduleConfiguredTime
QDateTime scheduleConfiguredTime()
To get the scheduled config time.
Definition: SyncSchedule.cpp:184
Buteo::SyncSchedule::nextRushSwitchTime
QDateTime nextRushSwitchTime(const QDateTime &aFromTime) const
Gets next time to switch rush/off-rush schedule intervals.
Definition: SyncSchedule.cpp:471
Buteo::SyncSchedule::setTime
void setTime(const QTime &aTime)
Sets the exact time for sync.
Definition: SyncSchedule.cpp:194
Buteo::SyncSchedule::setScheduleEnabled
void setScheduleEnabled(bool aEnabled)
Sets if normal schedule is to be obeyed.
Definition: SyncSchedule.cpp:214
Buteo::SyncSchedule::scheduleEnabled
bool scheduleEnabled() const
Checks if normal schedule is obeyed.
Definition: SyncSchedule.cpp:209
Buteo::SyncSchedule::setInterval
void setInterval(unsigned aInterval)
Sets sync interval in minutes.
Definition: SyncSchedule.cpp:204
Buteo::SyncSchedule::setDays
void setDays(Days aDays)
Sets the enabled week days.
Definition: SyncSchedule.cpp:174
Buteo::SyncSchedule::setRushDays
void setRushDays(Days aDays)
Sets days enabled for rush hours.
Definition: SyncSchedule.cpp:244
Buteo::SyncSchedule::setScheduleConfiguredTime
void setScheduleConfiguredTime(const QDateTime &aDateTime)
Sets scheduled config time.
Definition: SyncSchedule.cpp:179
Buteo::SyncSchedule::inExternalSyncRushPeriod
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
Buteo::SyncSchedule::syncExternallyDuringRush
bool syncExternallyDuringRush() const
Checks if rush schedule is controlled by a external process.
Definition: SyncSchedule.cpp:229
Buteo::SyncSchedule::setRushTime
void setRushTime(const QTime &aBegin, const QTime &aEnd)
Sets begin and end times of rush hours.
Definition: SyncSchedule.cpp:259
Buteo::SyncSchedule::~SyncSchedule
~SyncSchedule()
Destructor.
Definition: SyncSchedule.cpp:92
Buteo::SyncSchedule::setSyncExternallyDuringRush
void setSyncExternallyDuringRush(bool aEnabled)
Sets if rush schedule is controlled by a external process.
Definition: SyncSchedule.cpp:234
Buteo::SyncSchedule::setRushInterval
void setRushInterval(unsigned aInterval)
Sets sync interval for rush hours.
Definition: SyncSchedule.cpp:270
Buteo::SyncSchedule::nextSyncTime
QDateTime nextSyncTime(const QDateTime &aPrevSync) const
Gets next sync time based on the sync schedule settings.
Definition: SyncSchedule.cpp:285
Buteo::SyncSchedule::toXml
QDomElement toXml(QDomDocument &aDoc) const
Exports the sync schedule to XML.
Definition: SyncSchedule.cpp:132
Buteo::SyncSchedule::setRushEnabled
void setRushEnabled(bool aEnabled)
Sets rush hour schedule is to be obeyed.
Definition: SyncSchedule.cpp:224