SyncSchedule.h
/*
* This file is part of buteo-syncfw package
*
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (C) 2020 Open Mobile Platform LLC.
*
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef SYNCSCHEDULE_H
#define SYNCSCHEDULE_H
#include <QTime>
#include <QFlags>
#include <QObject>
class QDomDocument;
class QDomElement;
namespace Buteo {
class SyncSchedulePrivate;
class SyncScheduleTest;
const QString SYNC_SCHEDULE_ENABLED_KEY_BOOL("scheduler/schedule_enabled");
const QString SYNC_SCHEDULE_PEAK_ENABLED_KEY_BOOL("scheduler/schedule_peak_enabled");
const QString SYNC_SCHEDULE_OFFPEAK_ENABLED_KEY_BOOL("scheduler/schedule_offpeak_enabled");
const QString SYNC_SCHEDULE_PEAK_DAYS_KEY_INT ("scheduler/schedule_peak_days");
const QString SYNC_SCHEDULE_PEAK_START_TIME_KEY_INT ("scheduler/schedule_peak_start_time");
const QString SYNC_SCHEDULE_PEAK_END_TIME_KEY_INT ("scheduler/schedule_peak_end_time");
const QString SYNC_SCHEDULE_PEAK_SCHEDULE_KEY_INT ("scheduler/schedule_peak");
const QString SYNC_SCHEDULE_OFFPEAK_SCHEDULE_KEY_INT ("scheduler/schedule_off_peak");
class SyncSchedule
{
Q_GADGET
Q_PROPERTY(QTime time READ time)
Q_PROPERTY(Days days READ days)
Q_PROPERTY(unsigned interval READ interval)
Q_PROPERTY(bool enabled READ scheduleEnabled)
Q_PROPERTY(QTime rushBegin READ rushBegin)
Q_PROPERTY(QTime rushEnd READ rushEnd)
Q_PROPERTY(Days rushDays READ rushDays)
Q_PROPERTY(unsigned rushInterval READ rushInterval)
Q_PROPERTY(bool rushEnabled READ rushEnabled)
public:
enum Day {
NoDays = 0x00,
Monday = 0x01,
Tuesday = 0x02,
Wednesday = 0x04,
Thursday = 0x08,
Friday = 0x10,
Saturday = 0x20,
Sunday = 0x40
};
Q_DECLARE_FLAGS(Days, Day)
Q_FLAG(Days)
SyncSchedule();
SyncSchedule(const SyncSchedule &aSource);
explicit SyncSchedule(const QDomElement &aRoot);
~SyncSchedule();
SyncSchedule &operator=(const SyncSchedule &aRhs);
bool operator==(const SyncSchedule &aRhs) const;
QDomElement toXml(QDomDocument &aDoc) const;
QString toString() const;
Days days() const;
void setDays(Days aDays);
QTime time() const;
void setTime(const QTime &aTime);
void setScheduleConfiguredTime(const QDateTime &aDateTime);
QDateTime scheduleConfiguredTime();
unsigned interval() const;
void setInterval(unsigned aInterval);
bool scheduleEnabled() const;
void setScheduleEnabled(bool aEnabled);
// ============== RUSH HOUR SETTINGS ============================
bool rushEnabled() const;
void setRushEnabled(bool aEnabled);
bool syncExternallyDuringRush() const;
void setSyncExternallyDuringRush(bool aEnabled);
Days rushDays() const;
void setRushDays(Days aDays);
QTime rushBegin() const;
QTime rushEnd() const;
void setRushTime(const QTime &aBegin, const QTime &aEnd);
unsigned rushInterval() const;
void setRushInterval(unsigned aInterval);
bool inExternalSyncRushPeriod(const QDateTime &aDateTime) const;
QDateTime nextSyncTime(const QDateTime &aPrevSync) const;
QDateTime nextRushSwitchTime(const QDateTime &aFromTime) const;
bool isSyncScheduled(const QDateTime &aActualDateTime, const QDateTime &aPreviousSyncTime = QDateTime()) const;
private:
SyncSchedulePrivate *d_ptr;
#ifdef SYNCFW_UNIT_TESTS
friend class SyncScheduleTest;
#endif
};
}
Q_DECLARE_METATYPE(Buteo::SyncSchedule)
#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::rushEnd
QTime rushEnd() const
Gets end time of rush hours.
Definition SyncSchedule.cpp:252
Buteo::SyncSchedule::rushDays
Days rushDays() const
Gets days enabled for rush hours.
Definition SyncSchedule.cpp:237
Buteo::SyncSchedule::toString
QString toString() const
Exports the sync schedule to QString.
Definition SyncSchedule.cpp:154
Buteo::SyncSchedule::operator==
bool operator==(const SyncSchedule &aRhs) const
Equal to operator.
Definition SyncSchedule.cpp:115
Buteo::SyncSchedule::SyncSchedule
SyncSchedule()
Constructs an empty schedule.
Definition SyncSchedule.cpp:64
Buteo::SyncSchedule::operator=
SyncSchedule & operator=(const SyncSchedule &aRhs)
Assignment operator.
Definition SyncSchedule.cpp:105
Buteo::SyncSchedule::rushEnabled
bool rushEnabled() const
Checks if rush hour schedule is to be obeyed.
Definition SyncSchedule.cpp:217
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:496
Buteo::SyncSchedule::scheduleConfiguredTime
QDateTime scheduleConfiguredTime()
To get the scheduled config time.
Definition SyncSchedule.cpp:182
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:192
Buteo::SyncSchedule::setScheduleEnabled
void setScheduleEnabled(bool aEnabled)
Sets if normal schedule is to be obeyed.
Definition SyncSchedule.cpp:212
Buteo::SyncSchedule::scheduleEnabled
bool scheduleEnabled() const
Checks if normal schedule is obeyed.
Definition SyncSchedule.cpp:207
Buteo::SyncSchedule::setInterval
void setInterval(unsigned aInterval)
Sets sync interval in minutes.
Definition SyncSchedule.cpp:202
Buteo::SyncSchedule::days
Days days() const
Gets the enabled week days of the sync schedule.
Definition SyncSchedule.cpp:167
Buteo::SyncSchedule::setDays
void setDays(Days aDays)
Sets the enabled week days.
Definition SyncSchedule.cpp:172
Buteo::SyncSchedule::time
QTime time() const
Gets the exact time set in sync schedule.
Definition SyncSchedule.cpp:187
Buteo::SyncSchedule::setRushDays
void setRushDays(Days aDays)
Sets days enabled for rush hours.
Definition SyncSchedule.cpp:242
Buteo::SyncSchedule::setScheduleConfiguredTime
void setScheduleConfiguredTime(const QDateTime &aDateTime)
Sets scheduled config time.
Definition SyncSchedule.cpp:177
Buteo::SyncSchedule::rushBegin
QTime rushBegin() const
Gets begin time of rush hours.
Definition SyncSchedule.cpp:247
Buteo::SyncSchedule::rushInterval
unsigned rushInterval() const
Gets sync interval for rush hours.
Definition SyncSchedule.cpp:263
Buteo::SyncSchedule::interval
unsigned interval() const
Gets sync interval in minutes.
Definition SyncSchedule.cpp:197
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:273
Buteo::SyncSchedule::syncExternallyDuringRush
bool syncExternallyDuringRush() const
Checks if rush schedule is controlled by a external process.
Definition SyncSchedule.cpp:227
Buteo::SyncSchedule::setRushTime
void setRushTime(const QTime &aBegin, const QTime &aEnd)
Sets begin and end times of rush hours.
Definition SyncSchedule.cpp:257
Buteo::SyncSchedule::~SyncSchedule
~SyncSchedule()
Destructor.
Definition SyncSchedule.cpp:99
Buteo::SyncSchedule::setSyncExternallyDuringRush
void setSyncExternallyDuringRush(bool aEnabled)
Sets if rush schedule is controlled by a external process.
Definition SyncSchedule.cpp:232
Buteo::SyncSchedule::setRushInterval
void setRushInterval(unsigned aInterval)
Sets sync interval for rush hours.
Definition SyncSchedule.cpp:268
Buteo::SyncSchedule::nextSyncTime
QDateTime nextSyncTime(const QDateTime &aPrevSync) const
Gets next sync time based on the sync schedule settings.
Definition SyncSchedule.cpp:283
Buteo::SyncSchedule::toXml
QDomElement toXml(QDomDocument &aDoc) const
Exports the sync schedule to XML.
Definition SyncSchedule.cpp:130
Buteo::SyncSchedule::setRushEnabled
void setRushEnabled(bool aEnabled)
Sets rush hour schedule is to be obeyed.
Definition SyncSchedule.cpp:222