Buteo Synchronization Framework
BackgroundSync.h
1 /*
2  * This file is part of buteo-syncfw package
3  *
4  * Copyright (C) 2014 Jolla Ltd.
5  *
6  * Contact: Valerio Valerio <valerio.valerio@jolla.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 
24 #ifndef BACKGROUNDSYNC_H
25 #define BACKGROUNDSYNC_H
26 
27 #include <QObject>
28 #include <QMap>
29 #include <QDateTime>
30 #include <keepalive/backgroundactivity.h>
31 
32 class BackgroundActivity;
33 
37 class BackgroundSync : public QObject
38 {
39  Q_OBJECT
40 
42  struct BActivityStruct {
43  QString id;
44  BackgroundActivity *backgroundActivity;
45  BackgroundActivity::Frequency frequency;
46  };
47 
49  struct BActivitySwitchStruct {
50  QString id;
51  BackgroundActivity *backgroundActivity;
52  QDateTime nextSwitch;
53  };
54 
55 public:
59  BackgroundSync(QObject *aParent);
60 
64  virtual ~BackgroundSync();
65 
74  bool set(const QString &aProfName, int seconds);
75 
80  bool remove(const QString &aProfName);
81 
84  void removeAll();
85 
86  // Sync switch
87 
95  bool setSwitch(const QString &aProfName, const QDateTime &aSwitchTime);
96 
101  bool removeSwitch(const QString &aProfName);
102 
103 signals:
104 
109  void onBackgroundSyncRunning(QString aProfName);
110 
115  void onBackgroundSwitchRunning(const QString &aProfName);
116 
117 public slots:
122  void onBackgroundSyncCompleted(QString aProfName);
123 
124 private slots:
125 
128  void onBackgroundSyncStarted();
129 
132  void onBackgroundSwitchStarted();
133 
134 private:
135 
141  QString getProfNameFromId(const QString activityId) const;
142 
149  BackgroundActivity::Frequency frequencyFromSeconds(int seconds);
150 
151  // Sync switch
152 
155  void removeAllSwitches();
156 
162  QString getProfNameFromSwitchId(const QString activityId) const;
163 
164 private:
165 
167  QMap<QString, BActivityStruct> iScheduledSyncs;
168 
170  QMap<QString, BActivitySwitchStruct> iScheduledSwitch;
171 };
172 
173 #endif // BACKGROUNDSYNC_H
BackgroundSync implementation.
Definition: BackgroundSync.h:38
void onBackgroundSyncCompleted(QString aProfName)
Called when background sync is completed.
Definition: BackgroundSync.cpp:151
BackgroundSync(QObject *aParent)
Constructor.
Definition: BackgroundSync.cpp:32
virtual ~BackgroundSync()
Destructor.
Definition: BackgroundSync.cpp:38
void onBackgroundSwitchRunning(const QString &aProfName)
This signal will be emitted when a switch timer for particular profile is triggered.
Definition: moc_BackgroundSync.cpp:167
bool set(const QString &aProfName, int seconds)
Schedules a background sync for this profile.
Definition: BackgroundSync.cpp:82
void removeAll()
Removes all background syncs for all profiles.
Definition: BackgroundSync.cpp:45
bool removeSwitch(const QString &aProfName)
Removes a switch(rush/off-rush) for a profile.
Definition: BackgroundSync.cpp:225
void onBackgroundSyncRunning(QString aProfName)
This signal will be emitted when a background sync timer for particular profile is triggered.
Definition: moc_BackgroundSync.cpp:160
bool setSwitch(const QString &aProfName, const QDateTime &aSwitchTime)
Schedules a switch(rush/off-rush) for a background sync running for this profile, the switch should b...
Definition: BackgroundSync.cpp:241
bool remove(const QString &aProfName)
Removes background sync for a profile.
Definition: BackgroundSync.cpp:64