ButeoSynchronizationFramework
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  {
44  QString id;
45  BackgroundActivity* backgroundActivity;
46  BackgroundActivity::Frequency frequency;
47  };
48 
50  struct BActivitySwitchStruct
51  {
52  QString id;
53  BackgroundActivity* backgroundActivity;
54  QDateTime nextSwitch;
55  };
56 
57 public:
61  BackgroundSync(QObject *aParent);
62 
66  virtual ~BackgroundSync();
67 
76  bool set(const QString& aProfName, int seconds);
77 
82  bool remove(const QString& aProfName);
83 
86  void removeAll();
87 
88  // Sync switch
89 
97  bool setSwitch(const QString& aProfName, const QDateTime& aSwitchTime);
98 
103  bool removeSwitch(const QString& aProfName);
104 
105 signals:
106 
111  void onBackgroundSyncRunning(QString aProfName);
112 
117  void onBackgroundSwitchRunning(const QString& aProfName);
118 
119 public slots:
124  void onBackgroundSyncCompleted(QString aProfName);
125 
126 private slots:
127 
130  void onBackgroundSyncStarted();
131 
134  void onBackgroundSwitchStarted();
135 
136 private:
137 
143  QString getProfNameFromId(const QString activityId) const;
144 
151  BackgroundActivity::Frequency frequencyFromSeconds(int seconds);
152 
153  // Sync switch
154 
157  void removeAllSwitches();
158 
164  QString getProfNameFromSwitchId(const QString activityId) const;
165 
166 private:
167 
169  QMap<QString, BActivityStruct> iScheduledSyncs;
170 
172  QMap<QString, BActivitySwitchStruct> iScheduledSwitch;
173 };
174 
175 #endif // BACKGROUNDSYNC_H
virtual ~BackgroundSync()
Destructor.
Definition: BackgroundSync.cpp:38
bool set(const QString &aProfName, int seconds)
Schedules a background sync for this profile.
Definition: BackgroundSync.cpp:82
void onBackgroundSwitchRunning(const QString &aProfName)
This signal will be emitted when a switch timer for particular profile is triggered.
BackgroundSync implementation.
Definition: BackgroundSync.h:37
void removeAll()
Removes all background syncs for all profiles.
Definition: BackgroundSync.cpp:45
void onBackgroundSyncRunning(QString aProfName)
This signal will be emitted when a background sync timer for particular profile is triggered...
void onBackgroundSyncCompleted(QString aProfName)
Called when background sync is completed.
Definition: BackgroundSync.cpp:147
BackgroundSync(QObject *aParent)
Constructor.
Definition: BackgroundSync.cpp:32
bool removeSwitch(const QString &aProfName)
Removes a switch(rush/off-rush) for a profile.
Definition: BackgroundSync.cpp:220
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:236