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 <QSet>
30 
31 class QDomDocument;
32 class QDomElement;
33 
34 namespace Buteo {
35 
36 class SyncSchedulePrivate;
37 class SyncScheduleTest;
38 
39 typedef QSet<int> DaySet;
40 
41 const QString SYNC_SCHEDULE_ENABLED_KEY_BOOL("scheduler/schedule_enabled");
42 const QString SYNC_SCHEDULE_PEAK_ENABLED_KEY_BOOL("scheduler/schedule_peak_enabled");
43 const QString SYNC_SCHEDULE_OFFPEAK_ENABLED_KEY_BOOL("scheduler/schedule_offpeak_enabled");
44 const QString SYNC_SCHEDULE_PEAK_DAYS_KEY_INT ("scheduler/schedule_peak_days");
45 const QString SYNC_SCHEDULE_PEAK_START_TIME_KEY_INT ("scheduler/schedule_peak_start_time");
46 const QString SYNC_SCHEDULE_PEAK_END_TIME_KEY_INT ("scheduler/schedule_peak_end_time");
47 const QString SYNC_SCHEDULE_PEAK_SCHEDULE_KEY_INT ("scheduler/schedule_peak");
48 const QString SYNC_SCHEDULE_OFFPEAK_SCHEDULE_KEY_INT ("scheduler/schedule_off_peak");
49 
54 {
55 public:
59  SyncSchedule();
60 
65  SyncSchedule(const SyncSchedule &aSource);
66 
71  explicit SyncSchedule(const QDomElement &aRoot);
72 
75  ~SyncSchedule();
76 
81  SyncSchedule &operator=(const SyncSchedule &aRhs);
82 
87  bool operator==(const SyncSchedule &aRhs);
88 
94  QDomElement toXml(QDomDocument &aDoc) const;
95 
100  QString toString() const;
101 
108  DaySet days() const;
109 
114  void setDays(const DaySet &aDays);
115 
120  QTime time() const;
121 
127  void setTime(const QTime &aTime);
128 
133  void setScheduleConfiguredTime(const QDateTime &aDateTime);
134 
139  QDateTime scheduleConfiguredTime();
140 
145  unsigned interval() const;
146 
152  void setInterval(unsigned aInterval);
153 
158  bool scheduleEnabled() const;
159 
164  void setScheduleEnabled(bool aEnabled);
165 
166  // ============== RUSH HOUR SETTINGS ============================
167 
168 
173  bool rushEnabled() const;
174 
179  void setRushEnabled(bool aEnabled);
180 
187  bool syncExternallyDuringRush() const;
188 
193  void setSyncExternallyDuringRush(bool aEnabled);
194 
199  DaySet rushDays() const;
200 
205  void setRushDays(const DaySet &aDays);
206 
211  QTime rushBegin() const;
212 
217  QTime rushEnd() const;
218 
224  void setRushTime(const QTime &aBegin, const QTime &aEnd);
225 
230  unsigned rushInterval() const;
231 
236  void setRushInterval(unsigned aInterval);
237 
242  bool inExternalSyncRushPeriod(const QDateTime &aDateTime) const;
243 
249  QDateTime nextSyncTime(const QDateTime &aPrevSync) const;
250 
257  QDateTime nextRushSwitchTime(const QDateTime &aFromTime) const;
258 
265  bool isSyncScheduled(const QDateTime &aActualDateTime, const QDateTime &aPreviousSyncTime = QDateTime()) const;
266 
267 private:
268 
269  SyncSchedulePrivate *d_ptr;
270 
271 #ifdef SYNCFW_UNIT_TESTS
272  friend class SyncScheduleTest;
273 #endif
274 
275 };
276 
277 }
278 
279 #endif // SYNCSCHEDULE_H
Private implementation class for SyncSchedule.
Definition: SyncSchedule_p.h:34
Class for handling sync schedule settings.
Definition: SyncSchedule.h:54
QTime rushEnd() const
Gets end time of rush hours.
Definition: SyncSchedule.cpp:254
DaySet days() const
Gets the enabled week days of the sync schedule.
Definition: SyncSchedule.cpp:169
bool operator==(const SyncSchedule &aRhs)
Equal to operator.
Definition: SyncSchedule.cpp:108
QString toString() const
Exports the sync schedule to QString.
Definition: SyncSchedule.cpp:156
SyncSchedule()
Constructs an empty schedule.
Definition: SyncSchedule.cpp:58
SyncSchedule & operator=(const SyncSchedule &aRhs)
Assignment operator.
Definition: SyncSchedule.cpp:98
bool rushEnabled() const
Checks if rush hour schedule is to be obeyed.
Definition: SyncSchedule.cpp:219
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(const DaySet &aDays)
Sets the enabled week days.
Definition: SyncSchedule.cpp:174
QTime time() const
Gets the exact time set in sync schedule.
Definition: SyncSchedule.cpp:189
void setScheduleConfiguredTime(const QDateTime &aDateTime)
Sets scheduled config time.
Definition: SyncSchedule.cpp:179
void setRushDays(const DaySet &aDays)
Sets days enabled for rush hours.
Definition: SyncSchedule.cpp:244
QTime rushBegin() const
Gets begin time of rush hours.
Definition: SyncSchedule.cpp:249
unsigned rushInterval() const
Gets sync interval for rush hours.
Definition: SyncSchedule.cpp:265
unsigned interval() const
Gets sync interval in minutes.
Definition: SyncSchedule.cpp:199
DaySet rushDays() const
Gets days enabled for rush hours.
Definition: SyncSchedule.cpp:239
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