Merge lp:~renatofilho/buteo-syncfw/ubuntu-changes into lp:~phablet-team/buteo-syncfw/ubuntu

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Michael Sheldon
Approved revision: 280
Merged at revision: 278
Proposed branch: lp:~renatofilho/buteo-syncfw/ubuntu-changes
Merge into: lp:~phablet-team/buteo-syncfw/ubuntu
Diff against target: 3177 lines (+584/-1725)
28 files modified
debian/patches/0001-Check-for-WLAN-or-ETHERNET-connections.patch (+47/-0)
debian/patches/0001-Disable-sheduled-syncs-over-cellular-connections.patch (+25/-0)
debian/patches/0001-Ubuntu-phone-changes.patch (+0/-1544)
debian/patches/0002-Fixed-FUNCTION_CALL_TRACE-macro.patch (+36/-0)
debian/patches/0003-Added-upstart-service-file.patch (+59/-0)
debian/patches/series (+4/-1)
libbuteosyncfw/common/Logger.cpp (+2/-2)
libbuteosyncfw/common/NetworkManager.cpp (+79/-17)
libbuteosyncfw/common/NetworkManager.h (+15/-3)
libbuteosyncfw/common/SyncCommonDefs.h (+17/-0)
libbuteosyncfw/common/TransportTracker.cpp (+12/-12)
libbuteosyncfw/common/TransportTracker.h (+4/-3)
libbuteosyncfw/profile/ProfileManager.cpp (+9/-5)
libbuteosyncfw/profile/SyncProfile.cpp (+5/-8)
msyncd/AccountsHelper.cpp (+48/-16)
msyncd/AccountsHelper.h (+29/-30)
msyncd/SyncDBusAdaptor.cpp (+8/-0)
msyncd/SyncDBusAdaptor.h (+5/-0)
msyncd/SyncDBusInterface.h (+22/-15)
msyncd/SyncOnChangeScheduler.cpp (+9/-0)
msyncd/SyncOnChangeScheduler.h (+2/-1)
msyncd/SyncSession.h (+1/-1)
msyncd/gschemas/com.meego.msyncd.gschema.xml (+10/-0)
msyncd/msyncd-app.pro (+4/-1)
msyncd/msyncd-lib.pro (+1/-1)
msyncd/synchronizer.cpp (+115/-59)
msyncd/synchronizer.h (+14/-4)
unittests/tests/msyncdtests/TransportTrackerTest.cpp (+2/-2)
To merge this branch: bzr merge lp:~renatofilho/buteo-syncfw/ubuntu-changes
Reviewer Review Type Date Requested Status
Michael Sheldon (community) Approve
Ken VanDine Approve
Review via email: mp+271128@code.launchpad.net

Commit message

Remove patches already applied on trunk.
Create individual patches for ubuntu specific changes.

To post a comment you must log in.
279. By Renato Araujo Oliveira Filho

Remove patches already applied on trunk.

Create individual patches for ubuntu specific changes.

280. By Renato Araujo Oliveira Filho

Check for specific WLAN or ETHERNET connection to avoid problems with Unknown types.

Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks good

review: Approve
Revision history for this message
Michael Sheldon (michael-sheldon) wrote :

Looks good, I found one BOM added in msyncd/synchronizer.cpp that should be removed though.

review: Needs Fixing
Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

> Looks good, I found one BOM added in msyncd/synchronizer.cpp that should be
> removed though.

Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) :
Revision history for this message
Michael Sheldon (michael-sheldon) :
review: Approve
281. By Renato Araujo Oliveira Filho

Disable debug messages.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'debian/patches/0001-Check-for-WLAN-or-ETHERNET-connections.patch'
--- debian/patches/0001-Check-for-WLAN-or-ETHERNET-connections.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0001-Check-for-WLAN-or-ETHERNET-connections.patch 2015-09-30 18:13:56 +0000
@@ -0,0 +1,47 @@
1From 161e8b4ad64be49822630b601c87fa97ce030de1 Mon Sep 17 00:00:00 2001
2From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
3Date: Tue, 22 Sep 2015 12:41:16 -0300
4Subject: [PATCH] Check for WLAN or ETHERNET connections.
5
6Check for specific WLAN or ETHERNET connection to avoid problems with
7Unknown types.
8---
9 libbuteosyncfw/common/NetworkManager.cpp | 11 ++++++-----
10 1 file changed, 6 insertions(+), 5 deletions(-)
11
12diff --git a/libbuteosyncfw/common/NetworkManager.cpp b/libbuteosyncfw/common/NetworkManager.cpp
13index 811694c..418105a 100644
14--- a/libbuteosyncfw/common/NetworkManager.cpp
15+++ b/libbuteosyncfw/common/NetworkManager.cpp
16@@ -1,4 +1,4 @@
17-/*
18+/*
19 * This file is part of buteo-syncfw package
20 *
21 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
22@@ -167,17 +167,18 @@ void NetworkManager::idleRefresh()
23 {
24 // FIXME: due this bug lp:#1444162 on nm the QNetworkConfigurationManager
25 // returns the wrong default connection.
26- // We will consider the connection with the smallest bearer as the
27- // default connection, with that wifi and ethernet will be the first one
28- // https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1444162
29+ // We will consider the first active connection as default connection
30+ // unless that there is a WLAN or Ethernet connection active
31 connectionType = activeConfigs.first().bearerType();
32 bearerTypeName = activeConfigs.first().bearerTypeName();
33 foreach(const QNetworkConfiguration &conf, activeConfigs)
34 {
35- if (conf.bearerType() < connectionType)
36+ if ((conf.bearerType() == QNetworkConfiguration::BearerWLAN) ||
37+ (conf.bearerType() == QNetworkConfiguration::BearerEthernet))
38 {
39 connectionType = conf.bearerType();
40 bearerTypeName = conf.bearerTypeName();
41+ break;
42 }
43 }
44 }
45--
462.1.4
47
048
=== added file 'debian/patches/0001-Disable-sheduled-syncs-over-cellular-connections.patch'
--- debian/patches/0001-Disable-sheduled-syncs-over-cellular-connections.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0001-Disable-sheduled-syncs-over-cellular-connections.patch 2015-09-30 18:13:56 +0000
@@ -0,0 +1,25 @@
1From b8ebc30e204c977f5f25d6176d5a82be3e399c4a Mon Sep 17 00:00:00 2001
2From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
3Date: Tue, 15 Sep 2015 10:18:05 -0300
4Subject: [PATCH 1/3] Disable sheduled syncs over cellular connections.
5
6---
7 msyncd/gschemas/com.meego.msyncd.gschema.xml | 2 +-
8 1 file changed, 1 insertion(+), 1 deletion(-)
9
10diff --git a/msyncd/gschemas/com.meego.msyncd.gschema.xml b/msyncd/gschemas/com.meego.msyncd.gschema.xml
11index 4e410d5..f5b90fb 100644
12--- a/msyncd/gschemas/com.meego.msyncd.gschema.xml
13+++ b/msyncd/gschemas/com.meego.msyncd.gschema.xml
14@@ -4,7 +4,7 @@
15 <key name="allow-scheduled-sync-over-cellular" type="b">
16 <summary>Scheduled Sync over cellular</summary>
17 <description>Allow scheduled syncs to run over cellular connections.</description>
18- <default>true</default>
19+ <default>false</default>
20 </key>
21 </schema>
22 </schemalist>
23--
242.1.4
25
026
=== removed file 'debian/patches/0001-Ubuntu-phone-changes.patch'
--- debian/patches/0001-Ubuntu-phone-changes.patch 2015-09-11 14:15:49 +0000
+++ debian/patches/0001-Ubuntu-phone-changes.patch 1970-01-01 00:00:00 +0000
@@ -1,1544 +0,0 @@
1From 090b3f497a52d9bdf891bdac418705f5adb18e1c Mon Sep 17 00:00:00 2001
2From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
3Date: Fri, 3 Jul 2015 13:59:00 -0300
4Subject: [PATCH] Fire 'enableSOC' for accounts already created.
5
6Make sure the the signal 'enableSOC' is fired even for accounts that already exists.
7Fire 'AccountsHelper' signals on idle after the constructor, to allow connections after create object.
8
9Save profile before fire 'signalProfileChanged'.
10
11The profile should be saved before fire the signal 'signalProfileChanged', otherwise the receiver that retrieve the profile will have a old version of it.
12
13Start a sync just after create a new profile.
14
15After create a online-account we want that account to get sync.
16
17Wait untill network connection is available to sync.
18
19Wait for internet connection before sync scheduled sync requests.
20
21Does not run scheduled sync over mobile data connection.
22
23Check for internet connection type before run a scheduled sync.
24
25Added upstart service file.
26
27Create upstart file to start msyncd service.
28
29Avoid sync twice.
30
31Remove pending syncs from 'iWaitingOnlineSyncs' and 'iSyncOnChangeScheduler', before run a sync to avoid sync twice.
32
33Fixed compilation warnings.
34
35Create a gschema to store system-wide configuration.
36
37Check for '/com/meego/msyncd/allow-scheduled-sync-over-gsm' settings to confirm if sync over gsm is enabled for scheduled syncs.
38
39Add new profiles into the Sync On Change list.
40
41Profiles created while the server is running should be added to Sync On Change list.
42
43Fixed AccountsHelper 'scheduleUpdated' emission.
44
45Make sure that the signal get fired for the correct profile.
46
47Fire a new sync if profile data changes.
48
49Fixed profile creation for new accounts.
50
51Set the new profile enabled only if account and service are enabled.
52
53Fix 'lastSuccessfulSyncTime' function.
54
55Fixed an use case where the sync log only contains one failed sync.
56
57Expose "createProfileForAccount" in the DBUS service.
58
59Allow the client to create a profile for a specified account it it does not exists
60---
61 libbuteosyncfw/common/Logger.cpp | 4 +-
62 libbuteosyncfw/common/NetworkManager.cpp | 96 +++++++++---
63 libbuteosyncfw/common/NetworkManager.h | 18 ++-
64 libbuteosyncfw/common/SyncCommonDefs.h | 17 +++
65 libbuteosyncfw/common/TransportTracker.cpp | 24 +--
66 libbuteosyncfw/common/TransportTracker.h | 7 +-
67 libbuteosyncfw/profile/ProfileManager.cpp | 14 +-
68 libbuteosyncfw/profile/SyncProfile.cpp | 13 +-
69 msyncd/AccountsHelper.cpp | 66 +++++---
70 msyncd/AccountsHelper.h | 59 ++++---
71 msyncd/SyncDBusAdaptor.cpp | 8 +
72 msyncd/SyncDBusAdaptor.h | 5 +
73 msyncd/SyncDBusInterface.h | 37 +++--
74 msyncd/SyncOnChangeScheduler.cpp | 9 ++
75 msyncd/SyncOnChangeScheduler.h | 3 +-
76 msyncd/SyncSession.h | 2 +-
77 msyncd/bin/msyncd.conf | 15 ++
78 msyncd/gschemas/com.meego.msyncd.gschema.xml | 10 ++
79 msyncd/msyncd-app.pro | 8 +-
80 msyncd/msyncd-lib.pro | 2 +-
81 msyncd/synchronizer.cpp | 169 ++++++++++++++-------
82 msyncd/synchronizer.h | 18 ++-
83 .../tests/msyncdtests/TransportTrackerTest.cpp | 4 +-
84 23 files changed, 427 insertions(+), 181 deletions(-)
85 create mode 100644 msyncd/bin/msyncd.conf
86 create mode 100644 msyncd/gschemas/com.meego.msyncd.gschema.xml
87
88diff --git a/libbuteosyncfw/common/Logger.cpp b/libbuteosyncfw/common/Logger.cpp
89index c6468bd..557b725 100644
90--- a/libbuteosyncfw/common/Logger.cpp
91+++ b/libbuteosyncfw/common/Logger.cpp
92@@ -206,7 +206,7 @@ void Logger::write(int aLevel, const char *aMsg)
93 {
94 if(aLevel >= QtCriticalMsg)
95 {
96- syslog(LOG_CRIT, sysLogMsg.toLocal8Bit().data());
97+ syslog(LOG_CRIT, "%s", sysLogMsg.toLocal8Bit().data());
98 }
99 return;
100 }
101@@ -217,7 +217,7 @@ void Logger::write(int aLevel, const char *aMsg)
102 return;
103 }
104
105- syslog(syslogLevel[aLevel], sysLogMsg.toLocal8Bit().data());
106+ syslog(syslogLevel[aLevel], "%s", sysLogMsg.toLocal8Bit().data());
107
108 if (iFileStream != 0)
109 {
110diff --git a/libbuteosyncfw/common/NetworkManager.cpp b/libbuteosyncfw/common/NetworkManager.cpp
111index 6e430d4..811694c 100644
112--- a/libbuteosyncfw/common/NetworkManager.cpp
113+++ b/libbuteosyncfw/common/NetworkManager.cpp
114@@ -36,13 +36,40 @@ bool NetworkManager::m_isSessionActive = false;
115 NetworkManager::NetworkManager(QObject *parent /* = 0*/) :
116 QObject(parent), m_networkConfigManager(0), m_networkSession(0),
117 m_isOnline(false), m_errorEmitted(false),
118- m_sessionTimer(0)
119+ m_sessionTimer(0), m_connectionType(Sync::INTERNET_CONNECTION_UNKNOWN)
120 {
121 FUNCTION_CALL_TRACE;
122 m_networkConfigManager = new QNetworkConfigurationManager();
123 Q_ASSERT(m_networkConfigManager);
124- connect(m_networkConfigManager, SIGNAL(onlineStateChanged(bool)),
125- SLOT(slotOnlineStateChanged(bool)));
126+
127+ // check for network status and configuration change (switch wifi, ethernet, mobile) a
128+ connect(m_networkConfigManager,
129+ SIGNAL(onlineStateChanged(bool)),
130+ SLOT(slotConfigurationChanged()),
131+ Qt::QueuedConnection);
132+ connect(m_networkConfigManager,
133+ SIGNAL(configurationAdded(QNetworkConfiguration)),
134+ SLOT(slotConfigurationChanged()),
135+ Qt::QueuedConnection);
136+ connect(m_networkConfigManager,
137+ SIGNAL(configurationChanged(QNetworkConfiguration)),
138+ SLOT(slotConfigurationChanged()),
139+ Qt::QueuedConnection);
140+ connect(m_networkConfigManager,
141+ SIGNAL(configurationRemoved(QNetworkConfiguration)),
142+ SLOT(slotConfigurationChanged()),
143+ Qt::QueuedConnection);
144+ connect(m_networkConfigManager,
145+ SIGNAL(updateCompleted()),
146+ SLOT(slotConfigurationChanged()),
147+ Qt::QueuedConnection);
148+
149+ connect(&m_idleRefreshTimer,
150+ SIGNAL(timeout()),
151+ SLOT(idleRefresh()),
152+ Qt::QueuedConnection);
153+ m_idleRefreshTimer.setSingleShot(true);
154+
155 m_isOnline = m_networkConfigManager->isOnline();
156 LOG_DEBUG("Online status::" << m_isOnline);
157 m_sessionTimer = new QTimer(this);
158@@ -72,6 +99,11 @@ bool NetworkManager::isOnline()
159 return m_isOnline;
160 }
161
162+Sync::InternetConnectionType NetworkManager::connectionType() const
163+{
164+ return m_connectionType;
165+}
166+
167 void NetworkManager::connectSession(bool connectInBackground /* = false*/)
168 {
169 FUNCTION_CALL_TRACE;
170@@ -110,12 +142,55 @@ void NetworkManager::sessionConnectionTimeout()
171 {
172 if (!m_errorEmitted && m_networkSession) {
173 if (!m_networkSession->isOpen()) {
174- qWarning() << "No network reply received after 10 seconds, emitting session error.";
175+ LOG_WARNING("No network reply received after 10 seconds, emitting session error.");
176 slotSessionError(m_networkSession->error());
177 }
178 }
179 }
180
181+void NetworkManager::slotConfigurationChanged()
182+{
183+ // wait for 3 secs before update connection status
184+ // this avoid problems with connections that take a while to be stabilished
185+ m_idleRefreshTimer.start(3000);
186+}
187+
188+void NetworkManager::idleRefresh()
189+{
190+ FUNCTION_CALL_TRACE;
191+ QList<QNetworkConfiguration> activeConfigs = m_networkConfigManager->allConfigurations(QNetworkConfiguration::Active);
192+ QNetworkConfiguration::BearerType connectionType = QNetworkConfiguration::BearerUnknown;
193+ QString bearerTypeName;
194+
195+ bool isOnline = activeConfigs.size() > 0;
196+ if (isOnline)
197+ {
198+ // FIXME: due this bug lp:#1444162 on nm the QNetworkConfigurationManager
199+ // returns the wrong default connection.
200+ // We will consider the connection with the smallest bearer as the
201+ // default connection, with that wifi and ethernet will be the first one
202+ // https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1444162
203+ connectionType = activeConfigs.first().bearerType();
204+ bearerTypeName = activeConfigs.first().bearerTypeName();
205+ foreach(const QNetworkConfiguration &conf, activeConfigs)
206+ {
207+ if (conf.bearerType() < connectionType)
208+ {
209+ connectionType = conf.bearerType();
210+ bearerTypeName = conf.bearerTypeName();
211+ }
212+ }
213+ }
214+ LOG_DEBUG("New state:" << isOnline << " New type: " << bearerTypeName << "(" << connectionType << ")");
215+ if ((isOnline != m_isOnline) ||
216+ ((Sync::InternetConnectionType)connectionType != m_connectionType))
217+ {
218+ m_isOnline = isOnline;
219+ m_connectionType = (Sync::InternetConnectionType) connectionType;
220+ emit statusChanged(m_isOnline, m_connectionType);
221+ }
222+}
223+
224 void NetworkManager::disconnectSession()
225 {
226 FUNCTION_CALL_TRACE;
227@@ -134,19 +209,6 @@ void NetworkManager::disconnectSession()
228 }
229 }
230
231-void NetworkManager::slotOnlineStateChanged(bool isOnline)
232-{
233- FUNCTION_CALL_TRACE;
234- LOG_DEBUG("Online status changed, is online is now::" << isOnline);
235- if(m_isOnline != isOnline)
236- {
237- if (m_sessionTimer->isActive())
238- m_sessionTimer->stop();
239- m_isOnline = isOnline;
240- emit valueChanged(m_isOnline);
241- }
242-}
243-
244 void NetworkManager::slotSessionState(QNetworkSession::State status)
245 {
246 FUNCTION_CALL_TRACE;
247diff --git a/libbuteosyncfw/common/NetworkManager.h b/libbuteosyncfw/common/NetworkManager.h
248index 5a7c696..e375551 100644
249--- a/libbuteosyncfw/common/NetworkManager.h
250+++ b/libbuteosyncfw/common/NetworkManager.h
251@@ -24,8 +24,9 @@
252 #define NETWORKMANAGER_H_
253
254 #include <QNetworkSession>
255+#include <QTimer>
256+#include "SyncCommonDefs.h"
257
258-class QTimer;
259 class QNetworkConfigurationManager;
260
261 namespace Buteo
262@@ -61,6 +62,13 @@ namespace Buteo
263 */
264 bool isOnline();
265
266+ /*! \brief Returns the type of connection used by the device.
267+ *
268+
269+ * @return Sync::InternetConnectionType the type of connection.
270+ */
271+ Sync::InternetConnectionType connectionType() const;
272+
273 /*! \brief Connects a new network session. If a session was already
274 * open, the signal connectionSuccess will be emitted immediately,
275 * else the function will return and the signal connectionSuccess or
276@@ -84,7 +92,7 @@ signals:
277 *
278 * @param aConnected If true, the device is online
279 */
280- void valueChanged(bool aConnected);
281+ void statusChanged(bool aConnected, Sync::InternetConnectionType aType);
282
283 /*! \brief This signal is emitted when a network session gets
284 * connected
285@@ -105,11 +113,15 @@ signals:
286 static int m_refCount; // Reference counter for number of open connections
287 bool m_errorEmitted; // Network error emited flag
288 QTimer *m_sessionTimer;
289+ Sync::InternetConnectionType m_connectionType;
290+ QTimer m_idleRefreshTimer;
291+
292 private slots:
293- void slotOnlineStateChanged(bool isOnline);
294 void slotSessionState(QNetworkSession::State status);
295 void slotSessionError(QNetworkSession::SessionError error);
296 void sessionConnectionTimeout();
297+ void slotConfigurationChanged();
298+ void idleRefresh();
299 };
300 }
301
302diff --git a/libbuteosyncfw/common/SyncCommonDefs.h b/libbuteosyncfw/common/SyncCommonDefs.h
303index 495b71c..ab35d26 100644
304--- a/libbuteosyncfw/common/SyncCommonDefs.h
305+++ b/libbuteosyncfw/common/SyncCommonDefs.h
306@@ -26,6 +26,7 @@
307
308 #include <QMetaType>
309 #include <QDir>
310+#include <QtNetwork/QNetworkConfiguration>
311
312 namespace Sync {
313
314@@ -83,6 +84,22 @@ enum ConnectivityType {
315 CONNECTIVITY_INTERNET
316 };
317
318+enum InternetConnectionType {
319+ INTERNET_CONNECTION_UNKNOWN = QNetworkConfiguration::BearerUnknown,
320+ INTERNET_CONNECTION_ETHERNET = QNetworkConfiguration::BearerEthernet,
321+ INTERNET_CONNECTION_WLAN = QNetworkConfiguration::BearerWLAN,
322+ INTERNET_CONNECTION_2G = QNetworkConfiguration::Bearer2G,
323+ INTERNET_CONNECTION_3G = QNetworkConfiguration::Bearer3G,
324+ INTERNET_CONNECTION_4G = QNetworkConfiguration::Bearer4G,
325+ INTERNET_CONNECTION_CDMA2000 = QNetworkConfiguration::BearerCDMA2000,
326+ INTERNET_CONNECTION_WCDMA = QNetworkConfiguration::BearerWCDMA,
327+ INTERNET_CONNECTION_HSPA = QNetworkConfiguration::BearerHSPA,
328+ INTERNET_CONNECTION_BLUETOOTH = QNetworkConfiguration::BearerBluetooth,
329+ INTERNET_CONNECTION_WIMAX = QNetworkConfiguration::BearerWiMAX,
330+ INTERNET_CONNECTION_EVDO = QNetworkConfiguration::BearerEVDO,
331+ INTERNET_CONNECTION_LTE = QNetworkConfiguration::BearerLTE
332+};
333+
334 } // namespace Sync
335
336 Q_DECLARE_METATYPE( Sync::SyncStatus );
337diff --git a/libbuteosyncfw/common/TransportTracker.cpp b/libbuteosyncfw/common/TransportTracker.cpp
338index 7890cf5..0cd5632 100644
339--- a/libbuteosyncfw/common/TransportTracker.cpp
340+++ b/libbuteosyncfw/common/TransportTracker.cpp
341@@ -66,7 +66,7 @@ TransportTracker::TransportTracker(QObject *aParent) :
342
343 // BT
344 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
345-
346+
347 // Set the bluetooth state
348 iTransportStates[Sync::CONNECTIVITY_BT] = btConnectivityStatus();
349
350@@ -97,8 +97,9 @@ TransportTracker::TransportTracker(QObject *aParent) :
351 {
352 iTransportStates[Sync::CONNECTIVITY_INTERNET] =
353 iInternet->isOnline();
354- connect(iInternet, SIGNAL(valueChanged(bool)),
355- this, SLOT(onInternetStateChanged(bool)) /*, Qt::QueuedConnection*/);
356+ connect(iInternet,
357+ SIGNAL(statusChanged(bool, Sync::InternetConnectionType)),
358+ SLOT(onInternetStateChanged(bool, Sync::InternetConnectionType)) /*, Qt::QueuedConnection*/);
359 }
360 else
361 {
362@@ -143,7 +144,7 @@ void TransportTracker::onBtStateChanged(bool aState)
363 void TransportTracker::onBtStateChanged(QString aKey, QDBusVariant aValue)
364 {
365 FUNCTION_CALL_TRACE;
366-
367+
368 if (aKey == "Powered")
369 {
370 bool btPowered = aValue.variant().toBool();
371@@ -153,12 +154,13 @@ void TransportTracker::onBtStateChanged(QString aKey, QDBusVariant aValue)
372 }
373 #endif
374
375-void TransportTracker::onInternetStateChanged(bool aConnected)
376+void TransportTracker::onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType)
377 {
378 FUNCTION_CALL_TRACE;
379
380 LOG_DEBUG("Internet state changed:" << aConnected);
381 updateState(Sync::CONNECTIVITY_INTERNET, aConnected);
382+ emit networkStateChanged(aConnected, aType);
383 }
384
385 void TransportTracker::updateState(Sync::ConnectivityType aType,
386@@ -175,19 +177,17 @@ void TransportTracker::updateState(Sync::ConnectivityType aType,
387 }
388 if(oldState != aState)
389 {
390- if (aType != Sync::CONNECTIVITY_INTERNET) {
391+ if (aType != Sync::CONNECTIVITY_INTERNET)
392+ {
393 emit connectivityStateChanged(aType, aState);
394 }
395- else {
396- emit networkStateChanged(aState);
397- }
398 }
399 }
400
401 bool TransportTracker::btConnectivityStatus()
402 {
403 FUNCTION_CALL_TRACE;
404-
405+
406 bool btOn = false;
407 QDBusConnection *systemBus = new QDBusConnection(QDBusConnection::connectToBus(QDBusConnection::SystemBus,
408 QStringLiteral("buteo_system_bus2")));
409@@ -207,7 +207,7 @@ bool TransportTracker::btConnectivityStatus()
410 QList<QVariant> adapterList = reply.arguments();
411 // We will take the first adapter in the list
412 QString adapterPath = qdbus_cast<QDBusObjectPath>(adapterList.at(0)).path();
413-
414+
415 if (!adapterPath.isEmpty() || !adapterPath.isNull())
416 {
417 // Retrive the properties of the adapter and check for "Powered" key
418@@ -222,7 +222,7 @@ bool TransportTracker::btConnectivityStatus()
419 delete systemBus;
420 return btOn;
421 }
422-
423+
424 QDBusArgument arg = reply.arguments().at(0).value<QDBusArgument>();
425 if (arg.currentType() == QDBusArgument::MapType)
426 {
427diff --git a/libbuteosyncfw/common/TransportTracker.h b/libbuteosyncfw/common/TransportTracker.h
428index 67456cf..495ebcb 100644
429--- a/libbuteosyncfw/common/TransportTracker.h
430+++ b/libbuteosyncfw/common/TransportTracker.h
431@@ -78,8 +78,9 @@ signals:
432 /*! \brief Signal emitted when a n/w state changes
433 *
434 * @param aState New state. True if available, false if not.
435+ * @param aType Connection type. The type of connetcion with the Internet.
436 */
437- void networkStateChanged(bool aState);
438+ void networkStateChanged(bool aState, Sync::InternetConnectionType aType);
439
440 /*! \brief Signal emitted when a network session is successfully opened
441 */
442@@ -99,7 +100,7 @@ private slots:
443 void onBtStateChanged(QString aKey, QDBusVariant aValue);
444 #endif
445
446- void onInternetStateChanged(bool aConnected);
447+ void onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType);
448
449 private:
450
451@@ -127,7 +128,7 @@ private:
452 friend class TransportTrackerTest;
453 friend class SynchronizerTest;
454 #endif
455-
456+
457 bool btConnectivityStatus();
458
459 };
460diff --git a/libbuteosyncfw/profile/ProfileManager.cpp b/libbuteosyncfw/profile/ProfileManager.cpp
461index f1e4b2a..81406d9 100644
462--- a/libbuteosyncfw/profile/ProfileManager.cpp
463+++ b/libbuteosyncfw/profile/ProfileManager.cpp
464@@ -129,7 +129,6 @@ ProfileManagerPrivate::ProfileManagerPrivate(const QString &aPrimaryPath,
465
466 Profile *ProfileManagerPrivate::load(const QString &aName, const QString &aType)
467 {
468-
469 QString profilePath = findProfileFile(aName, aType);
470 QString backupProfilePath = profilePath + BACKUP_EXT;
471
472@@ -739,6 +738,14 @@ QString ProfileManager::updateProfile(const Profile &aProfile)
473 bool exists = d_ptr->profileExists(aProfile.name(),aProfile.type());
474
475 QString profileId("");
476+
477+ // We need to save before emit the signalProfileChanged, if this is the first
478+ // update the profile will only exists on disk after the save and any operation
479+ // using this profile triggered by the signal will fail.
480+ if(d_ptr->save(aProfile)) {
481+ profileId = aProfile.name();
482+ }
483+
484 // Profile did not exist, it was a new one. Add it and emit signal with "added" value:
485 if (!exists) {
486 emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_ADDED,aProfile.toString());
487@@ -746,9 +753,6 @@ QString ProfileManager::updateProfile(const Profile &aProfile)
488 emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_MODIFIED,aProfile.toString());
489 }
490
491- if(d_ptr->save(aProfile)) {
492- profileId = aProfile.name();
493- }
494 return profileId;
495 }
496
497@@ -1254,7 +1258,7 @@ QDateTime ProfileManager::getNextRetryInterval(const SyncProfile* aProfile)
498 !iSyncRetriesInfo[aProfile->name()].isEmpty())
499 {
500 quint32 mins = iSyncRetriesInfo[aProfile->name()].takeFirst();
501- nextRetryInterval = QDateTime::currentDateTime().addSecs(mins * 60);
502+ nextRetryInterval = QDateTime::currentDateTime().addSecs(mins * 60);
503 LOG_DEBUG("syncretries : retry for profile" << aProfile->name() << "in" << mins <<"minutes");
504 LOG_DEBUG("syncretries :" << iSyncRetriesInfo[aProfile->name()].count() <<"attempts remain");
505 }
506diff --git a/libbuteosyncfw/profile/SyncProfile.cpp b/libbuteosyncfw/profile/SyncProfile.cpp
507index 564aec5..7cd80d3 100644
508--- a/libbuteosyncfw/profile/SyncProfile.cpp
509+++ b/libbuteosyncfw/profile/SyncProfile.cpp
510@@ -259,14 +259,11 @@ QDateTime SyncProfile::lastSuccessfulSyncTime () const
511 if (d_ptr->iLog)
512 {
513 QList<const SyncResults*> allResults = d_ptr->iLog->allResults();
514- if (allResults.size () > 0)
515- {
516- lastSuccessSyncTime = allResults.at (0)->syncTime ();
517- foreach (const SyncResults* result, allResults) {
518- if ((result->majorCode () == SyncResults::SYNC_RESULT_SUCCESS) &&
519- (result->minorCode () == SyncResults::NO_ERROR) &&
520- (result->syncTime () > lastSuccessSyncTime))
521- lastSuccessSyncTime = result->syncTime ();
522+ foreach (const SyncResults* result, allResults) {
523+ if ((result->majorCode () == SyncResults::SYNC_RESULT_SUCCESS) &&
524+ (result->minorCode () == SyncResults::NO_ERROR) &&
525+ (lastSyncTime().isNull() || (result->syncTime () > lastSuccessSyncTime))) {
526+ lastSuccessSyncTime = result->syncTime ();
527 }
528 }
529 }
530diff --git a/msyncd/AccountsHelper.cpp b/msyncd/AccountsHelper.cpp
531index 064d14f..960132c 100644
532--- a/msyncd/AccountsHelper.cpp
533+++ b/msyncd/AccountsHelper.cpp
534@@ -26,6 +26,8 @@
535 #include "Profile.h"
536 #include "ProfileEngineDefs.h"
537
538+#include <QTimer>
539+
540 static const QString ACCOUNTS_GLOBAL_SERVICE("global");
541
542 using namespace Buteo;
543@@ -36,13 +38,15 @@ AccountsHelper::AccountsHelper(ProfileManager &aProfileManager, QObject *aParent
544 iAccountManager = new Accounts::Manager(this);
545 // Connect to signal for account creation, deletion, and modification
546 QObject::connect(iAccountManager, SIGNAL(accountCreated(Accounts::AccountId)),
547- this, SLOT(slotAccountCreated(Accounts::AccountId)));
548+ this, SLOT(createProfileForAccount(Accounts::AccountId)));
549 QObject::connect(iAccountManager, SIGNAL(accountRemoved(Accounts::AccountId)),
550 this, SLOT(slotAccountRemoved(Accounts::AccountId)));
551 QObject::connect(iAccountManager, SIGNAL(accountUpdated(Accounts::AccountId)),
552 this, SLOT(slotAccountUpdated(Accounts::AccountId)));
553
554- registerAccountListeners();
555+ // load accounts after return from contructor, to allow connection with class singals
556+ // that can be fired by 'registerAccountListeners' function
557+ QTimer::singleShot(0, this, SLOT(registerAccountListeners()));
558 }
559
560 AccountsHelper::~AccountsHelper()
561@@ -54,9 +58,10 @@ AccountsHelper::~AccountsHelper()
562 // their parent, aka, the manager
563 }
564
565-void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
566+QString AccountsHelper::createProfileForAccount(Accounts::AccountId id)
567 {
568 FUNCTION_CALL_TRACE;
569+ QString profileName;
570 Accounts::Account *newAccount = iAccountManager->account(id);
571 bool profileFoundAndCreated = false;
572
573@@ -66,7 +71,7 @@ void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
574 Accounts::ServiceList serviceList = newAccount->services();
575 foreach(Accounts::Service service, serviceList)
576 {
577- // Look for a sync profile that matches the service name
578+ // Look for a sync profile that matches the service name (template)
579 LOG_DEBUG("Looking for sync profile::" << service.name());
580 SyncProfile *syncProfile = iProfileManager.syncProfile(service.name());
581 LOG_DEBUG("Found profile::" << service.name());
582@@ -74,7 +79,7 @@ void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
583 (true == syncProfile->boolKey(KEY_USE_ACCOUNTS, false))
584 )
585 {
586- addAccountIfNotExists(newAccount, service, syncProfile);
587+ profileName = addAccountIfNotExists(newAccount, service, syncProfile);
588 profileFoundAndCreated = true;
589 }
590 if(0 != syncProfile)
591@@ -86,7 +91,7 @@ void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
592
593 if (profileFoundAndCreated == false)
594 {
595- // Fetch the key "remote_service_name" from the account settings and
596+ // Fetch the key "remote_service_name" from the account settings and
597 // use it to create a profile
598 QString profileName = newAccount->valueAsString(REMOTE_SERVICE_NAME);
599 LOG_DEBUG("Profile name from account setting:" << profileName);
600@@ -97,10 +102,15 @@ void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
601 if (syncProfile->boolKey (KEY_USE_ACCOUNTS, false) == true)
602 createProfileForAccount (newAccount, profileName, syncProfile);
603
604+ profileName = syncProfile->name();
605 delete syncProfile;
606 }
607 }
608+ } else {
609+ LOG_DEBUG("Account not found:" << id);
610 }
611+
612+ return profileName;
613 }
614
615 void AccountsHelper::slotAccountRemoved(Accounts::AccountId id)
616@@ -186,7 +196,7 @@ void AccountsHelper::slotAccountEnabledChanged(const QString &serviceName, bool
617 foreach(SyncProfile *profile, profiles)
618 {
619 // See if the service name matches
620- if(serviceName == profile->name())
621+ if(serviceName == profile->key(REMOTE_SERVICE_NAME))
622 {
623 // Check if the status really changed here
624 // saving the account can trigger the emition of enabledChanged()
625@@ -331,16 +341,16 @@ void AccountsHelper::createProfileForAccount(Accounts::Account *account,
626 delete newProfile;
627 }
628
629-void AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
630- Accounts::Service service,
631- const SyncProfile *baseProfile)
632+QString AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
633+ Accounts::Service service,
634+ const SyncProfile *baseProfile)
635 {
636 FUNCTION_CALL_TRACE;
637
638 Profile *serviceProfile = iProfileManager.profile(service.name(), Profile::TYPE_SYNC);
639 if (!serviceProfile) {
640 LOG_DEBUG ("!!!! Service not supported !!!!");
641- return;
642+ return QString();
643 }
644
645 QString profileName ;
646@@ -367,9 +377,11 @@ void AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
647 // Add the account ID to the profile
648 newProfile->setKey(KEY_ACCOUNT_ID, QString::number(account->id()));
649 // Check if service is enabled
650- LOG_DEBUG("Service:: " << service.displayName() << "enabled status::" << account->enabled());
651+ LOG_DEBUG("Service:: " << service.displayName() <<
652+ "enabled status::" << (account->enabled() && account->enabledServices().contains(service)));
653 // Set profile as enabled
654- newProfile->setEnabled(account->enabled());
655+ newProfile->setEnabled(account->enabled() &&
656+ account->enabledServices().contains(service));
657 setSyncSchedule (newProfile, account->id(), true);
658
659 // Save the newly created profile
660@@ -398,6 +410,8 @@ void AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
661 {
662 delete profile;
663 }
664+
665+ return profileName;
666 }
667
668 void AccountsHelper::addSetting(Accounts::AccountId id, QString key, QVariant value) {
669@@ -448,12 +462,27 @@ void AccountsHelper::slotSchedulerSettingsChanged(const char *aKey)
670 void AccountsHelper::registerAccountListener(Accounts::AccountId id)
671 {
672 FUNCTION_CALL_TRACE;
673+
674 Accounts::Account *account = iAccountManager->account(id);
675+ if (iAccountList.contains(account)) {
676+ return;
677+ }
678 iAccountList.append(account);
679 // Callback for account enabled/disabled
680- QObject::connect(account, SIGNAL(enabledChanged(const QString&, bool)),
681- this, SLOT(slotAccountEnabledChanged(const QString&, bool)));
682-
683+ QObject::connect(account,
684+ SIGNAL(enabledChanged(const QString&, bool)),
685+ SLOT(slotAccountEnabledChanged(const QString&, bool)),
686+ Qt::UniqueConnection);
687+
688+ // Account SyncOnChange
689+ QList<SyncProfile*> profiles = getProfilesByAccountId(id);
690+ foreach(SyncProfile *profile, profiles)
691+ {
692+ if(profile->isSOCProfile())
693+ {
694+ emit enableSOC(profile->name());
695+ }
696+ }
697 account->selectService();
698 account->beginGroup("scheduler");
699 LOG_DEBUG("Watching Group :" << account->group());
700@@ -463,5 +492,8 @@ void AccountsHelper::registerAccountListener(Accounts::AccountId id)
701 return;
702 }
703 iAcctWatchMap[watch] = id;
704- QObject::connect(watch, SIGNAL(notify(const char *)), this, SLOT(slotSchedulerSettingsChanged(const char *)));
705+ QObject::connect(watch,
706+ SIGNAL(notify(const char *)),
707+ SLOT(slotSchedulerSettingsChanged(const char *)),
708+ Qt::UniqueConnection);
709 }
710diff --git a/msyncd/AccountsHelper.h b/msyncd/AccountsHelper.h
711index 1f9508b..a2f8a9c 100644
712--- a/msyncd/AccountsHelper.h
713+++ b/msyncd/AccountsHelper.h
714@@ -29,12 +29,12 @@
715 #include <Accounts/account.h>
716
717 namespace Buteo {
718-
719+
720 class Profile;
721 class AccountsHelperTest;
722 class ProfileManager;
723 class SyncProfile;
724-
725+
726 const QString REMOTE_SERVICE_NAME("remote_service_name");
727
728 /*! \brief Helper Class towards Accounts::Manager and various SSO related
729@@ -57,7 +57,7 @@ public:
730 *
731 */
732 virtual ~AccountsHelper();
733-
734+
735 /*! \brief Returns sync profiles that correspond to a given account ID
736 *
737 * \param id - The account ID.
738@@ -68,30 +68,31 @@ public:
739
740 public Q_SLOTS:
741
742- /*! \brief slot for Accounts::Manager accountCreated signal
743- *
744- * \param id Accounts Id
745- */
746- void slotAccountCreated(Accounts::AccountId id);
747+ /*! \brief This method is used to create a profile for a specified
748+ * account
749+ * \param id Accounts Id
750+ * \return A string with the new profile name
751+ */
752+ QString createProfileForAccount(Accounts::AccountId id);
753
754- /*! \brief slot for Accounts::Manager accountRemoved signal
755- *
756- * \param id of the accounts
757- */
758+ /*! \brief slot for Accounts::Manager accountRemoved signal
759+ *
760+ * \param id of the accounts
761+ */
762 void slotAccountRemoved(Accounts::AccountId id);
763
764- /*! \brief slot for Accounts::Account enabledChanged signal
765- *
766- * \param serviceName The service that was enabled/disabled. Empty if the
767+ /*! \brief slot for Accounts::Account enabledChanged signal
768+ *
769+ * \param serviceName The service that was enabled/disabled. Empty if the
770 * entire account is enabled/disabled
771 * \param enabled Boolean indicating enabled (true) or disabled (false)
772- */
773+ */
774 void slotAccountEnabledChanged(const QString &serviceName, bool enabled);
775-
776- /*! \brief slot for Accounts::Manager displayNameChanged signal
777- * *
778- * \param id of the accounts
779- */
780+
781+ /*! \brief slot for Accounts::Manager displayNameChanged signal
782+ * *
783+ * \param id of the accounts
784+ */
785 void slotAccountUpdated(Accounts::AccountId id);
786
787 void slotSchedulerSettingsChanged(const char *aKey);
788@@ -102,22 +103,20 @@ Q_SIGNALS:
789 void removeProfile(QString profileId);
790 void removeScheduledSync(const QString& profileId);
791
792-private:
793+private Q_SLOTS:
794
795- /*!
796- * \brief This method is used to create a profile for a specified
797- * account
798- */
799+ void registerAccountListeners();
800+
801+private:
802 void createProfileForAccount(Accounts::Account* account,
803 const QString profileName,
804 const SyncProfile* baseProfile);
805
806- void addAccountIfNotExists(Accounts::Account *account,
807- Accounts::Service service,
808- const SyncProfile *baseProfile);
809+ QString addAccountIfNotExists(Accounts::Account *account,
810+ Accounts::Service service,
811+ const SyncProfile *baseProfile);
812
813 void setSyncSchedule(SyncProfile *syncProfile, Accounts::AccountId id, bool aCreateNew = false);
814- void registerAccountListeners();
815
816 void addSetting(Accounts::AccountId id, QString key, QVariant value);
817
818diff --git a/msyncd/SyncDBusAdaptor.cpp b/msyncd/SyncDBusAdaptor.cpp
819index 1b08b49..fd43324 100644
820--- a/msyncd/SyncDBusAdaptor.cpp
821+++ b/msyncd/SyncDBusAdaptor.cpp
822@@ -206,3 +206,11 @@ void SyncDBusAdaptor::isSyncedExternally(uint aAccountId, const QString aClientP
823 QMetaObject::invokeMethod(parent(), "isSyncedExternally", Q_ARG(uint, aAccountId), Q_ARG(QString, aClientProfileName));
824 }
825
826+QString SyncDBusAdaptor::createSyncProfileForAccount(uint aAccountId)
827+{
828+ // handle method call com.meego.msyncd.createSyncProfileForAccount
829+ QString out0;
830+ QMetaObject::invokeMethod(parent(), "createSyncProfileForAccount", Q_RETURN_ARG(QString, out0), Q_ARG(uint, aAccountId));
831+ return out0;
832+}
833+
834diff --git a/msyncd/SyncDBusAdaptor.h b/msyncd/SyncDBusAdaptor.h
835index 2aaf803..e15f50b 100644
836--- a/msyncd/SyncDBusAdaptor.h
837+++ b/msyncd/SyncDBusAdaptor.h
838@@ -157,6 +157,10 @@ class SyncDBusAdaptor: public QDBusAbstractAdaptor
839 " <arg direction=\"out\" type=\"au\"/>\n"
840 " <annotation value=\"QList&lt;uint>\" name=\"com.trolltech.QtDBus.QtTypeName.Out0\"/>\n"
841 " </method>\n"
842+" <method name=\"createSyncProfileForAccount\">\n"
843+" <arg direction=\"out\" type=\"s\"/>\n"
844+" <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"
845+" </method>\n"
846 " <method name=\"status\">\n"
847 " <arg direction=\"out\" type=\"i\"/>\n"
848 " <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"
849@@ -198,6 +202,7 @@ public Q_SLOTS: // METHODS
850 QList<uint> syncingAccounts();
851 bool updateProfile(const QString &aProfileAsXml);
852 Q_NOREPLY void isSyncedExternally(uint aAccountId, const QString aClientProfileName);
853+ QString createSyncProfileForAccount(uint aAccountId);
854 Q_SIGNALS: // SIGNALS
855 void backupDone();
856 void backupInProgress();
857diff --git a/msyncd/SyncDBusInterface.h b/msyncd/SyncDBusInterface.h
858index 27b5d21..21c9c0e 100644
859--- a/msyncd/SyncDBusInterface.h
860+++ b/msyncd/SyncDBusInterface.h
861@@ -103,29 +103,29 @@ signals:
862 *
863 */
864 void signalProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
865-
866-
867+
868+
869 /*! \brief Notifies about Backup start.
870 *
871 * This signal is sent when the backup framework is backing the sync related
872 * data
873 */
874 void backupInProgress ();
875-
876+
877 /*! \brief Notifies about Backup done.
878 *
879 * This signal is sent when the backup framework has completed backing the sync related
880 * data.
881 */
882 void backupDone();
883-
884+
885 /*! \brief Notifies about Restore start.
886 *
887 * This signal is sent when the backup framework is restoring the sync related
888 * data
889 */
890 void restoreInProgress();
891-
892+
893 /*! \brief Notifies about Restore Done.
894 *
895 * This signal is sent when the backup framework has restored the sync related
896@@ -160,7 +160,7 @@ signals:
897 * \param aNextSyncTime This is an out parameter. The next sync time.
898 */
899 void statusChanged(unsigned int aAccountId, int aNewStatus, int aFailedReason, qlonglong aPrevSyncTime, qlonglong aNextSyncTime);
900-
901+
902 /*! \brief Returns the connectivity state of a specific medium like
903 * bluetooth, USB or network.
904 * \see SyncCommonDefs::ConnectivityType for arguments
905@@ -257,16 +257,16 @@ public slots:
906 * \return Profile name list.
907 */
908 virtual QStringList runningSyncs() = 0;
909-
910-
911+
912+
913 /*!
914 * \brief This function returns true if backup/restore in progress else
915 * false.
916 */
917 virtual bool getBackUpRestoreState() = 0;
918-
919-
920- /*!
921+
922+
923+ /*!
924 * \brief sets the schedule for a profile
925 *
926 * This Function helps in setting a schedule to profile
927@@ -312,7 +312,7 @@ public slots:
928 * \return The sync profile as Xml string.
929 */
930 virtual QString syncProfile(const QString &aProfileId) = 0;
931-
932+
933 /*! \brief Gets a sync profiles matching the key-value.
934 *
935 * Loads and merges also all sub-profiles that are referenced from the
936@@ -323,7 +323,7 @@ public slots:
937 * \return The sync profiles as Xml string list.
938 */
939 virtual QStringList syncProfilesByKey(const QString &aKey, const QString &aValue) = 0;
940-
941+
942 /*! \brief Gets a profiles matching the profile type.
943 *
944 * \param aType Type of the profile service/storage/sync.
945@@ -336,13 +336,13 @@ public slots:
946 * \param aAccountId The account ID.
947 */
948 virtual Q_NOREPLY void start(unsigned int aAccountId) = 0;
949-
950+
951 /*! \brief Stops sync for all profiles matching the given account ID.
952 *
953 * \param aAccountId The account ID.
954 */
955 virtual Q_NOREPLY void stop(unsigned int aAccountId) = 0;
956-
957+
958 /*! \brief Returns the list of account IDs for which sync is ongoing
959 *
960 * \return The list of account IDs currectly syncing.
961@@ -373,6 +373,13 @@ public slots:
962 * having several services enabled
963 */
964 virtual Q_NOREPLY void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName) = 0;
965+
966+ /*! \brief Create a sync profile for the account if it does not exists
967+ *
968+ * \param aAccountId The account ID.
969+ * \return The profile name if the profile was created successful or empty if it fails
970+ */
971+ virtual QString createSyncProfileForAccount(uint aAccountId) = 0;
972 };
973
974 }
975diff --git a/msyncd/SyncOnChangeScheduler.cpp b/msyncd/SyncOnChangeScheduler.cpp
976index b7f5b75..389618d 100644
977--- a/msyncd/SyncOnChangeScheduler.cpp
978+++ b/msyncd/SyncOnChangeScheduler.cpp
979@@ -14,6 +14,11 @@ SyncOnChangeScheduler::SyncOnChangeScheduler()
980 SyncOnChangeScheduler::~SyncOnChangeScheduler()
981 {
982 FUNCTION_CALL_TRACE;
983+ foreach(QObject *o, iSOCTimers.values()) {
984+ delete o;
985+ }
986+ iSOCTimers.clear();
987+ iSOCProfileNames.clear();
988 }
989
990 bool SyncOnChangeScheduler::addProfile(const SyncProfile* aProfile)
991@@ -30,6 +35,7 @@ bool SyncOnChangeScheduler::addProfile(const SyncProfile* aProfile)
992 Qt::QueuedConnection);
993 SOCtimer->fire();
994 scheduled = true;
995+ iSOCTimers.insert(aProfile->name(), SOCtimer);
996 LOG_DEBUG("Sync on change scheduled for profile"<< aProfile->name());
997 }
998 else if(aProfile)
999@@ -43,12 +49,15 @@ void SyncOnChangeScheduler::removeProfile(const QString &aProfileName)
1000 {
1001 FUNCTION_CALL_TRACE;
1002 iSOCProfileNames.removeAll(aProfileName);
1003+ // cancel timer
1004+ delete iSOCTimers.take(aProfileName);
1005 }
1006
1007 void SyncOnChangeScheduler::sync(const SyncProfile* aProfile)
1008 {
1009 FUNCTION_CALL_TRACE;
1010 iSOCProfileNames.removeAll(aProfile->name());
1011+ iSOCTimers.remove(aProfile->name());
1012 SyncOnChangeTimer *SOCtimer = qobject_cast<SyncOnChangeTimer*>(sender());
1013 if(SOCtimer)
1014 {
1015diff --git a/msyncd/SyncOnChangeScheduler.h b/msyncd/SyncOnChangeScheduler.h
1016index 14168bf..aac2241 100644
1017--- a/msyncd/SyncOnChangeScheduler.h
1018+++ b/msyncd/SyncOnChangeScheduler.h
1019@@ -40,7 +40,7 @@ public:
1020 *
1021 * Once the SOC is initiated (by sending a syncNow signal), the profile is
1022 * removed automatically
1023- *
1024+ *
1025 * @param aProfile pointer to sync profile
1026 * @return true if SOC could be scheduled, false otherwise
1027 */
1028@@ -63,6 +63,7 @@ private Q_SLOTS:
1029
1030 private:
1031 QStringList iSOCProfileNames;
1032+ QMap<QString, QObject*> iSOCTimers;
1033 };
1034
1035 class SyncOnChangeTimer : public QObject
1036diff --git a/msyncd/SyncSession.h b/msyncd/SyncSession.h
1037index 401692c..4a3cde7 100644
1038--- a/msyncd/SyncSession.h
1039+++ b/msyncd/SyncSession.h
1040@@ -182,7 +182,7 @@ public:
1041 void setProfileCreated(bool aProfileCreated);
1042
1043 //! \brief Maps sync failure error code from stack to SyncStatus
1044- Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
1045+ Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
1046
1047 signals:
1048
1049diff --git a/msyncd/bin/msyncd.conf b/msyncd/bin/msyncd.conf
1050new file mode 100644
1051index 0000000..d383006
1052--- /dev/null
1053+++ b/msyncd/bin/msyncd.conf
1054@@ -0,0 +1,15 @@
1055+description "address-book-service"
1056+author "Bill Filler <bill.filler@canonical.com>"
1057+
1058+start on started unity8-dash
1059+stop on runlevel [06]
1060+
1061+# give some time to nm be ready
1062+pre-start script
1063+ sleep 10;
1064+end script
1065+
1066+respawn
1067+
1068+env MSYNCD_LOGGING_LEVEL=10
1069+exec /usr/bin/msyncd
1070diff --git a/msyncd/gschemas/com.meego.msyncd.gschema.xml b/msyncd/gschemas/com.meego.msyncd.gschema.xml
1071new file mode 100644
1072index 0000000..4e410d5
1073--- /dev/null
1074+++ b/msyncd/gschemas/com.meego.msyncd.gschema.xml
1075@@ -0,0 +1,10 @@
1076+<?xml version="1.0" encoding="UTF-8"?>
1077+<schemalist>
1078+ <schema id="com.meego.msyncd" path="/com/meego/msyncd/">
1079+ <key name="allow-scheduled-sync-over-cellular" type="b">
1080+ <summary>Scheduled Sync over cellular</summary>
1081+ <description>Allow scheduled syncs to run over cellular connections.</description>
1082+ <default>true</default>
1083+ </key>
1084+ </schema>
1085+</schemalist>
1086diff --git a/msyncd/msyncd-app.pro b/msyncd/msyncd-app.pro
1087index 1d5d338..5dd614e 100644
1088--- a/msyncd/msyncd-app.pro
1089+++ b/msyncd/msyncd-app.pro
1090@@ -59,13 +59,19 @@ target.path = /usr/bin/
1091 loglevel.files = bin/set_sync_log_level
1092 loglevel.path = /etc/buteo/
1093 service.files = bin/msyncd.service
1094+upstart.files = bin/msyncd.conf
1095 service.path = /usr/lib/systemd/user/
1096+upstart.path = /usr/share/upstart/sessions/
1097 syncwidget.path = /etc/syncwidget/
1098 syncwidget.files = com.meego.msyncd
1099+gschemas.path = /usr/share/glib-2.0/schemas
1100+gschemas.files = gschemas/com.meego.msyncd.gschema.xml
1101 INSTALLS += target \
1102 loglevel \
1103 syncwidget \
1104- service
1105+ service \
1106+ upstart \
1107+ gschemas
1108
1109 # #####################################################################
1110 # make coverage (debug)
1111diff --git a/msyncd/msyncd-lib.pro b/msyncd/msyncd-lib.pro
1112index 12a398c..ff7043e 100644
1113--- a/msyncd/msyncd-lib.pro
1114+++ b/msyncd/msyncd-lib.pro
1115@@ -19,7 +19,7 @@ INCLUDEPATH += . \
1116 ../libbuteosyncfw/profile
1117
1118
1119-PKGCONFIG += dbus-1
1120+PKGCONFIG += dbus-1 gio-2.0
1121
1122 equals(QT_MAJOR_VERSION, 4): {
1123 PKGCONFIG += libsignon-qt accounts-qt
1124diff --git a/msyncd/synchronizer.cpp b/msyncd/synchronizer.cpp
1125index b516ccd..6fccca6 100644
1126--- a/msyncd/synchronizer.cpp
1127+++ b/msyncd/synchronizer.cpp
1128@@ -1,4 +1,4 @@
1129-/*
1130+/*
1131 * This file is part of buteo-syncfw package
1132 *
1133 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
1134@@ -21,6 +21,7 @@
1135 * 02110-1301 USA
1136 *
1137 */
1138+#include <gio/gio.h>
1139 #include "synchronizer.h"
1140 #include "SyncDBusAdaptor.h"
1141 #include "SyncSession.h"
1142@@ -51,11 +52,11 @@
1143 #include <fcntl.h>
1144 #include <termios.h>
1145
1146+
1147 using namespace Buteo;
1148
1149 static const QString SYNC_DBUS_OBJECT = "/synchronizer";
1150 static const QString SYNC_DBUS_SERVICE = "com.meego.msyncd";
1151-
1152 static const QString BT_PROPERTIES_NAME = "Name";
1153
1154 // Maximum time in milliseconds to wait for a thread to stop
1155@@ -71,10 +72,9 @@ Synchronizer::Synchronizer( QCoreApplication* aApplication )
1156 iClosing(false),
1157 iSOCEnabled(false),
1158 iSyncUIInterface(NULL)
1159-
1160 {
1161+ iSettings = g_settings_new_with_path("com.meego.msyncd", "/com/meego/msyncd/");
1162 FUNCTION_CALL_TRACE;
1163-
1164 this->setParent(aApplication);
1165 }
1166
1167@@ -86,6 +86,7 @@ Synchronizer::~Synchronizer()
1168 delete iSyncUIInterface;
1169 iSyncUIInterface = NULL;
1170 }
1171+ g_object_unref(iSettings);
1172 }
1173
1174 bool Synchronizer::initialize()
1175@@ -115,8 +116,9 @@ bool Synchronizer::initialize()
1176 this, SLOT(slotSyncStatus(QString, int, QString, int)),
1177 Qt::QueuedConnection);
1178
1179+ // use queued connection because the profile will be stored after the signal
1180 connect(&iProfileManager ,SIGNAL(signalProfileChanged(QString,int,QString)),
1181- this, SIGNAL(signalProfileChanged(QString,int,QString)));
1182+ this, SLOT(slotProfileChanged(QString,int,QString)), Qt::QueuedConnection);
1183
1184 iNetworkManager = new NetworkManager(this);
1185 Q_ASSERT(iNetworkManager);
1186@@ -127,8 +129,9 @@ bool Synchronizer::initialize()
1187 {
1188 iServerActivator = new ServerActivator(iProfileManager,
1189 *iTransportTracker, this);
1190- connect(iTransportTracker, SIGNAL(networkStateChanged(bool)),
1191- this, SLOT(onNetworkStateChanged(bool)));
1192+ connect(iTransportTracker,
1193+ SIGNAL(networkStateChanged(bool,Sync::InternetConnectionType)),
1194+ SLOT(onNetworkStateChanged(bool,Sync::InternetConnectionType)));
1195 }
1196
1197 // Initialize account manager.
1198@@ -184,7 +187,7 @@ bool Synchronizer::initialize()
1199 else
1200 {
1201 QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(QString)),
1202- this, SLOT(startSync(QString)),
1203+ this, SLOT(startScheduledSync(QString)),
1204 Qt::QueuedConnection);
1205 iSOCEnabled = true;
1206 }
1207@@ -200,7 +203,7 @@ void Synchronizer::enableSOCSlot(const QString& aProfileName)
1208 {
1209 FUNCTION_CALL_TRACE;
1210 SyncProfile* profile = iProfileManager.syncProfile(aProfileName);
1211- if(!iSOCEnabled)
1212+ if(profile->isSOCProfile() && !iSOCEnabled)
1213 {
1214 QHash<QString,QList<SyncProfile*> > aSOCStorageMap;
1215 QList<SyncProfile*> SOCProfiles;
1216@@ -217,13 +220,13 @@ void Synchronizer::enableSOCSlot(const QString& aProfileName)
1217 else
1218 {
1219 QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(const QString&)),
1220- this, SLOT(startSync(const QString&)),
1221+ this, SLOT(startScheduledSync(const QString&)),
1222 Qt::QueuedConnection);
1223 iSOCEnabled = true;
1224 LOG_DEBUG("Sync on change enabled for profile" << aProfileName);
1225 }
1226 }
1227- else
1228+ else if (profile->isSOCProfile())
1229 {
1230 iSyncOnChange.addProfile("hcontacts", profile);
1231 }
1232@@ -291,55 +294,27 @@ bool Synchronizer::startScheduledSync(QString aProfileName)
1233 // All scheduled syncs are online syncs
1234 // Add this to the waiting online syncs and it will be started when we
1235 // receive a session connection status from the NetworkManager
1236- bool sessionConnected = !iWaitingOnlineSyncs.isEmpty();
1237- if(!iWaitingOnlineSyncs.contains(aProfileName))
1238+ bool accept = acceptScheduledSync(iNetworkManager->isOnline(), iNetworkManager->connectionType());
1239+ if(accept)
1240 {
1241- iWaitingOnlineSyncs.append(aProfileName);
1242+ startSync(aProfileName, true);
1243 }
1244- if(!sessionConnected)
1245+ else if (!iWaitingOnlineSyncs.contains(aProfileName))
1246 {
1247- QObject::connect(iNetworkManager, SIGNAL(connectionSuccess()), this,
1248- SLOT(slotNetworkSessionOpened()), Qt::QueuedConnection);
1249- QObject::connect(iNetworkManager, SIGNAL(connectionError()), this,
1250- SLOT(slotNetworkSessionError()), Qt::QueuedConnection);
1251- // Request for a network session
1252- iNetworkManager->connectSession(true);
1253+ LOG_DEBUG("Wait for internet connection:" << aProfileName);
1254+ if (iNetworkManager->isOnline())
1255+ {
1256+ LOG_DEBUG("Connection over mobile data plan. The sync will be postponed untill a full connection is available;");
1257+ }
1258+ else
1259+ {
1260+ LOG_DEBUG("Device offline. Wait for internet connection.");
1261+ }
1262+ iWaitingOnlineSyncs.append(aProfileName);
1263 }
1264 return true;
1265 }
1266
1267-void Synchronizer::slotNetworkSessionOpened()
1268-{
1269- FUNCTION_CALL_TRACE;
1270- QObject::disconnect(iNetworkManager, SIGNAL(connectionSuccess()), this,
1271- SLOT(slotNetworkSessionOpened()));
1272- QObject::disconnect(iNetworkManager, SIGNAL(connectionError()), this,
1273- SLOT(slotNetworkSessionError()));
1274- foreach(QString profileName, iWaitingOnlineSyncs)
1275- {
1276- startSync(profileName, true);
1277- }
1278- iWaitingOnlineSyncs.clear();
1279-}
1280-
1281-void Synchronizer::slotNetworkSessionError()
1282-{
1283- FUNCTION_CALL_TRACE;
1284- QObject::disconnect(iNetworkManager, SIGNAL(connectionSuccess()), this,
1285- SLOT(slotNetworkSessionOpened()));
1286- QObject::disconnect(iNetworkManager, SIGNAL(connectionError()), this,
1287- SLOT(slotNetworkSessionError()));
1288- // Cancel all open sessions
1289- foreach(QString profileName, iWaitingOnlineSyncs)
1290- {
1291- SyncResults syncResults(QDateTime::currentDateTime(), SyncResults::SYNC_RESULT_FAILED, SyncResults::CONNECTION_ERROR);
1292- iProfileManager.saveSyncResults(profileName, syncResults);
1293- reschedule(profileName);
1294- }
1295- iWaitingOnlineSyncs.clear();
1296- iNetworkManager->disconnectSession();
1297-}
1298-
1299 bool Synchronizer::setSyncSchedule(QString aProfileId , QString aScheduleAsXml)
1300 {
1301 bool status = false;
1302@@ -364,6 +339,11 @@ bool Synchronizer::saveSyncResults(QString aProfileId, QString aSyncResults)
1303 return status;
1304 }
1305
1306+QString Synchronizer::createSyncProfileForAccount(uint aAccountId)
1307+{
1308+ return iAccounts->createProfileForAccount(aAccountId);
1309+}
1310+
1311 bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)
1312 {
1313 FUNCTION_CALL_TRACE;
1314@@ -378,6 +358,12 @@ bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)
1315
1316 LOG_DEBUG( "Start sync requested for profile:" << aProfileName );
1317
1318+ // This function can be called from a client app as manual sync:
1319+ // If we receive a manual sync to a profile that is peding to sync due a
1320+ // data change we can remove it from the iSyncOnChangeScheduler, to avoid a
1321+ // second sync.
1322+ iSyncOnChangeScheduler.removeProfile(aProfileName);
1323+
1324 if (iActiveSessions.contains(aProfileName))
1325 {
1326 LOG_DEBUG( "Sync already in progress" );
1327@@ -389,6 +375,14 @@ bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)
1328 emit syncStatus(aProfileName, Sync::SYNC_QUEUED, "", 0);
1329 return true;
1330 }
1331+ else if (!aScheduled && iWaitingOnlineSyncs.contains(aProfileName))
1332+ {
1333+ // Manual sync is allowed to happen in any kind of connection
1334+ // if sync is not scheduled remove it from iWaitingOnlineSyncs to avoid
1335+ // sync it twice later
1336+ iWaitingOnlineSyncs.removeOne(aProfileName);
1337+ LOG_DEBUG("Removing" << aProfileName << "from online waiting list.");
1338+ }
1339
1340 SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
1341 if (!profile)
1342@@ -520,7 +514,7 @@ bool Synchronizer::startSyncNow(SyncSession *aSession)
1343 return false;
1344 }
1345
1346- LOG_DEBUG("Disable sync on change");
1347+ LOG_DEBUG("Disable sync on change:" << iSOCEnabled << profile->isSOCProfile());
1348 //As sync is ongoing, disable sync on change for now, we can query later if
1349 //there are changes.
1350 if(iSOCEnabled)
1351@@ -754,7 +748,7 @@ bool Synchronizer::startNextSync()
1352 }
1353
1354 QString profileName = session->profileName();
1355- LOG_DEBUG( "Trying to start next sync in queue. Profile:" << profileName );
1356+ LOG_DEBUG( "Trying to start next sync in queue. Profile:" << profileName << session->isScheduled());
1357
1358 #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
1359 QBatteryInfo iDeviceInfo;
1360@@ -1516,6 +1510,36 @@ void Synchronizer::onNewSession(const QString &aDestination)
1361 }
1362 }
1363
1364+void Synchronizer::slotProfileChanged(QString aProfileName, int aChangeType, QString aProfileAsXml)
1365+{
1366+ // start sync when a new profile is added
1367+ switch (aChangeType)
1368+ {
1369+ case ProfileManager::PROFILE_ADDED:
1370+ enableSOCSlot(aProfileName);
1371+ startSync(aProfileName);
1372+ break;
1373+
1374+ case ProfileManager::PROFILE_REMOVED:
1375+ iSyncOnChangeScheduler.removeProfile(aProfileName);
1376+ iWaitingOnlineSyncs.removeAll(aProfileName);
1377+ break;
1378+
1379+ case ProfileManager::PROFILE_MODIFIED:
1380+ {
1381+ // schedule a new sync in case of profile changed;
1382+ // Example if the profile change from disable -> enable
1383+ SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
1384+ if (profile->isEnabled()) {
1385+ startScheduledSync(aProfileName);
1386+ }
1387+ }
1388+ break;
1389+ }
1390+
1391+ emit signalProfileChanged(aProfileName, aChangeType, aProfileAsXml);
1392+}
1393+
1394 void Synchronizer::reschedule(const QString &aProfileName)
1395 {
1396 FUNCTION_CALL_TRACE;
1397@@ -1903,10 +1927,24 @@ QStringList Synchronizer::syncProfilesByType(const QString &aType)
1398 return iProfileManager.profileNames(aType);
1399 }
1400
1401-void Synchronizer::onNetworkStateChanged(bool aState)
1402+void Synchronizer::onNetworkStateChanged(bool aState, Sync::InternetConnectionType type)
1403 {
1404 FUNCTION_CALL_TRACE;
1405- if(!aState) {
1406+ LOG_DEBUG("Network state changed: OnLine:" << aState << " connection type:" << type);
1407+ if (acceptScheduledSync(aState, type))
1408+ {
1409+ LOG_DEBUG("Restart sync for profiles that need network");
1410+ QStringList profiles(iWaitingOnlineSyncs);
1411+ iWaitingOnlineSyncs.clear();
1412+ foreach(QString profileName, profiles)
1413+ {
1414+ // start sync now, we do not need to call 'startScheduledSync' since that function
1415+ // only checks for internet connection
1416+ startSync(profileName, true);
1417+ }
1418+ }
1419+ else if (!aState)
1420+ {
1421 QList<QString> profiles = iActiveSessions.keys();
1422 foreach(QString profileId, profiles)
1423 {
1424@@ -1919,8 +1957,8 @@ void Synchronizer::onNetworkStateChanged(bool aState)
1425 delete profile;
1426 profile = NULL;
1427 }
1428- else {
1429-
1430+ else
1431+ {
1432 LOG_DEBUG("No profile found with aProfileId"<<profileId);
1433 }
1434 }
1435@@ -2069,6 +2107,19 @@ void Synchronizer::removeExternalSyncStatus(const SyncProfile *aProfile)
1436 }
1437 }
1438
1439+bool Synchronizer::acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const
1440+{
1441+ static QList<Sync::InternetConnectionType> allowedTypes;
1442+ if (allowedTypes.isEmpty())
1443+ {
1444+ allowedTypes << Sync::INTERNET_CONNECTION_WLAN
1445+ << Sync::INTERNET_CONNECTION_ETHERNET;
1446+ }
1447+
1448+ return (aConnected && (g_settings_get_boolean(iSettings, "allow-scheduled-sync-over-cellular") ||
1449+ allowedTypes.contains(aType)));
1450+}
1451+
1452 void Synchronizer::isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName)
1453 {
1454 LOG_DEBUG("Received isSyncedExternally request for account:" << aAccountId);
1455diff --git a/msyncd/synchronizer.h b/msyncd/synchronizer.h
1456index 5564802..8c07eda 100644
1457--- a/msyncd/synchronizer.h
1458+++ b/msyncd/synchronizer.h
1459@@ -44,7 +44,9 @@
1460 #include <QMap>
1461 #include <QString>
1462 #include <QDBusInterface>
1463+#include <QScopedPointer>
1464
1465+struct _GSettings;
1466
1467 namespace Buteo {
1468
1469@@ -137,6 +139,9 @@ public slots:
1470 //! \see SyncDBusInterface::saveSyncResults
1471 virtual bool saveSyncResults(QString aProfileId,QString aSyncResults);
1472
1473+ //! \see SyncDBusInterface::createSyncProfileForAccount
1474+ virtual QString createSyncProfileForAccount(uint aAccountId);
1475+
1476 /*! \brief To get lastSyncResult.
1477 * \param aProfileId
1478 * \return QString of syncResult.
1479@@ -257,9 +262,7 @@ private slots:
1480
1481 void onNewSession(const QString &aDestination);
1482
1483- void slotNetworkSessionOpened();
1484-
1485- void slotNetworkSessionError();
1486+ void slotProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
1487
1488 /*! \brief Starts a server plug-in
1489 *
1490@@ -273,7 +276,7 @@ private slots:
1491 */
1492 void stopServer(const QString &aProfileName);
1493
1494- void onNetworkStateChanged(bool aState);
1495+ void onNetworkStateChanged(bool aState, Sync::InternetConnectionType type);
1496
1497 /*! \brief call this to request the sync daemon to enable soc
1498 * for a profile. The sync daemon decides as of now for which storages
1499@@ -385,6 +388,12 @@ private:
1500 */
1501 void removeExternalSyncStatus(const SyncProfile *aProfile);
1502
1503+ /*! \brief Check if sheduled sync is allowed for this type of connection.
1504+ *
1505+ * @param aType the connection type;
1506+ */
1507+ bool acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const;
1508+
1509 QMap<QString, SyncSession*> iActiveSessions;
1510
1511 QMap<QString, bool> iExternalSyncProfileStatus;
1512@@ -446,6 +455,7 @@ private:
1513 #endif
1514
1515 QDBusInterface *iSyncUIInterface;
1516+ _GSettings *iSettings;
1517 };
1518
1519 }
1520diff --git a/unittests/tests/msyncdtests/TransportTrackerTest.cpp b/unittests/tests/msyncdtests/TransportTrackerTest.cpp
1521index 8cc5309..c69a315 100644
1522--- a/unittests/tests/msyncdtests/TransportTrackerTest.cpp
1523+++ b/unittests/tests/msyncdtests/TransportTrackerTest.cpp
1524@@ -89,7 +89,7 @@ void TransportTrackerTest :: testStateChanged()
1525 {
1526 qRegisterMetaType<Sync::ConnectivityType>("Sync::ConnectivityType");
1527 QSignalSpy connectivityStateSpy(iTransportTracker, SIGNAL(connectivityStateChanged(Sync::ConnectivityType, bool)));
1528- QSignalSpy networkStateSpy(iTransportTracker, SIGNAL(networkStateChanged(bool)));
1529+ QSignalSpy networkStateSpy(iTransportTracker, SIGNAL(networkStateChanged(bool,Sync::InternetConnectionType)));
1530
1531 // change USB state and verify
1532 bool usbCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_USB);
1533@@ -115,7 +115,7 @@ void TransportTrackerTest :: testStateChanged()
1534
1535 // change internet state and verify
1536 bool internetCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET);
1537- iTransportTracker->onInternetStateChanged(!internetCurrentState);
1538+ iTransportTracker->onInternetStateChanged(!internetCurrentState, Sync::INTERNET_CONNECTION_UNKNOWN);
1539 QCOMPARE(iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET), !internetCurrentState);
1540 QEXPECT_FAIL("", "IMO connectivityStateChanged() should be emitted also for CONNECTIVITY_INTERNET", Continue);
1541 QCOMPARE(connectivityStateSpy.count(), 1);
1542--
15432.1.4
1544
15450
=== added file 'debian/patches/0002-Fixed-FUNCTION_CALL_TRACE-macro.patch'
--- debian/patches/0002-Fixed-FUNCTION_CALL_TRACE-macro.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0002-Fixed-FUNCTION_CALL_TRACE-macro.patch 2015-09-30 18:13:56 +0000
@@ -0,0 +1,36 @@
1From 512bdd8f480c0790797521884145e3e6d8661254 Mon Sep 17 00:00:00 2001
2From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
3Date: Mon, 14 Sep 2015 17:38:48 -0300
4Subject: [PATCH 2/3] Fixed 'FUNCTION_CALL_TRACE' macro.
5
6Make sure that the macro print the correct elapsed time during the debug.
7---
8 libbuteosyncfw/common/LogMacros.h | 5 ++++-
9 1 file changed, 4 insertions(+), 1 deletion(-)
10
11diff --git a/libbuteosyncfw/common/LogMacros.h b/libbuteosyncfw/common/LogMacros.h
12index bac9ef6..90f2c6f 100644
13--- a/libbuteosyncfw/common/LogMacros.h
14+++ b/libbuteosyncfw/common/LogMacros.h
15@@ -29,6 +29,7 @@
16 #include <QTime>
17 #include <QDebug>
18 #include <QDateTime>
19+#include <QScopedPointer>
20 #include "Logger.h"
21
22 //! Helper macro for writing log messages. Avoid using directly.
23@@ -52,7 +53,9 @@
24 * Creates a trace message to log when the function is entered and exited.
25 * Logs also to time spent in the function.
26 */
27-# define FUNCTION_CALL_TRACE if (Buteo::Logger::instance()->getLogLevel() >= 9) Buteo::LogTimer timerDebugVariable(QString(__PRETTY_FUNCTION__));
28+# define FUNCTION_CALL_TRACE QScopedPointer<Buteo::LogTimer> timerDebugVariable; \
29+ if (Buteo::Logger::instance()->getLogLevel() >= 9) \
30+ timerDebugVariable.reset(new Buteo::LogTimer(QString(__PRETTY_FUNCTION__)));
31
32 namespace Buteo {
33
34--
352.1.4
36
037
=== added file 'debian/patches/0003-Added-upstart-service-file.patch'
--- debian/patches/0003-Added-upstart-service-file.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/0003-Added-upstart-service-file.patch 2015-09-30 18:13:56 +0000
@@ -0,0 +1,59 @@
1From e10289937804ad6d779843753727b661d2e14e43 Mon Sep 17 00:00:00 2001
2From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
3Date: Fri, 3 Jul 2015 14:49:13 -0300
4Subject: [PATCH 1/2] Added upstart service file.
5
6Create upstart file to start msyncd service.
7---
8 msyncd/bin/msyncd.conf | 14 ++++++++++++++
9 msyncd/msyncd-app.pro | 5 ++++-
10 2 files changed, 18 insertions(+), 1 deletion(-)
11 create mode 100644 msyncd/bin/msyncd.conf
12
13diff --git a/msyncd/bin/msyncd.conf b/msyncd/bin/msyncd.conf
14new file mode 100644
15index 0000000..7224f87
16--- /dev/null
17+++ b/msyncd/bin/msyncd.conf
18@@ -0,0 +1,14 @@
19+description "address-book-service"
20+author "Bill Filler <bill.filler@canonical.com>"
21+
22+start on started unity8-dash
23+stop on runlevel [06]
24+
25+# give some time to nm be ready
26+pre-start script
27+ sleep 10;
28+end script
29+
30+respawn
31+
32+exec /usr/bin/msyncd
33diff --git a/msyncd/msyncd-app.pro b/msyncd/msyncd-app.pro
34index be59a8c..ca0a53d 100644
35--- a/msyncd/msyncd-app.pro
36+++ b/msyncd/msyncd-app.pro
37@@ -59,7 +59,9 @@ target.path = /usr/bin/
38 loglevel.files = bin/set_sync_log_level
39 loglevel.path = /etc/buteo/
40 service.files = bin/msyncd.service
41+upstart.files = bin/msyncd.conf
42 service.path = /usr/lib/systemd/user/
43+upstart.path = /usr/share/upstart/sessions/
44 syncwidget.path = /etc/syncwidget/
45 syncwidget.files = com.meego.msyncd
46 gschemas.path = /usr/share/glib-2.0/schemas
47@@ -68,7 +70,8 @@ INSTALLS += target \
48 loglevel \
49 syncwidget \
50 service \
51- gschemas
52+ gschemas \
53+ upstart
54
55 # #####################################################################
56 # make coverage (debug)
57--
582.1.4
59
060
=== modified file 'debian/patches/series'
--- debian/patches/series 2015-09-11 14:15:49 +0000
+++ debian/patches/series 2015-09-30 18:13:56 +0000
@@ -1,2 +1,5 @@
10001-Ubuntu-phone-changes.patch
2libdir.patch1libdir.patch
20001-Disable-sheduled-syncs-over-cellular-connections.patch
30002-Fixed-FUNCTION_CALL_TRACE-macro.patch
40003-Added-upstart-service-file.patch
50001-Check-for-WLAN-or-ETHERNET-connections.patch
36
=== modified file 'libbuteosyncfw/common/Logger.cpp'
--- libbuteosyncfw/common/Logger.cpp 2014-07-22 04:21:03 +0000
+++ libbuteosyncfw/common/Logger.cpp 2015-09-30 18:13:56 +0000
@@ -206,7 +206,7 @@
206 {206 {
207 if(aLevel >= QtCriticalMsg)207 if(aLevel >= QtCriticalMsg)
208 {208 {
209 syslog(LOG_CRIT, sysLogMsg.toLocal8Bit().data());209 syslog(LOG_CRIT, "%s", sysLogMsg.toLocal8Bit().data());
210 }210 }
211 return;211 return;
212 }212 }
@@ -217,7 +217,7 @@
217 return;217 return;
218 }218 }
219219
220 syslog(syslogLevel[aLevel], sysLogMsg.toLocal8Bit().data());220 syslog(syslogLevel[aLevel], "%s", sysLogMsg.toLocal8Bit().data());
221221
222 if (iFileStream != 0)222 if (iFileStream != 0)
223 {223 {
224224
=== modified file 'libbuteosyncfw/common/NetworkManager.cpp'
--- libbuteosyncfw/common/NetworkManager.cpp 2014-09-19 13:49:12 +0000
+++ libbuteosyncfw/common/NetworkManager.cpp 2015-09-30 18:13:56 +0000
@@ -36,13 +36,40 @@
36NetworkManager::NetworkManager(QObject *parent /* = 0*/) :36NetworkManager::NetworkManager(QObject *parent /* = 0*/) :
37 QObject(parent), m_networkConfigManager(0), m_networkSession(0),37 QObject(parent), m_networkConfigManager(0), m_networkSession(0),
38 m_isOnline(false), m_errorEmitted(false),38 m_isOnline(false), m_errorEmitted(false),
39 m_sessionTimer(0)39 m_sessionTimer(0), m_connectionType(Sync::INTERNET_CONNECTION_UNKNOWN)
40{40{
41 FUNCTION_CALL_TRACE;41 FUNCTION_CALL_TRACE;
42 m_networkConfigManager = new QNetworkConfigurationManager();42 m_networkConfigManager = new QNetworkConfigurationManager();
43 Q_ASSERT(m_networkConfigManager);43 Q_ASSERT(m_networkConfigManager);
44 connect(m_networkConfigManager, SIGNAL(onlineStateChanged(bool)),44
45 SLOT(slotOnlineStateChanged(bool)));45 // check for network status and configuration change (switch wifi, ethernet, mobile) a
46 connect(m_networkConfigManager,
47 SIGNAL(onlineStateChanged(bool)),
48 SLOT(slotConfigurationChanged()),
49 Qt::QueuedConnection);
50 connect(m_networkConfigManager,
51 SIGNAL(configurationAdded(QNetworkConfiguration)),
52 SLOT(slotConfigurationChanged()),
53 Qt::QueuedConnection);
54 connect(m_networkConfigManager,
55 SIGNAL(configurationChanged(QNetworkConfiguration)),
56 SLOT(slotConfigurationChanged()),
57 Qt::QueuedConnection);
58 connect(m_networkConfigManager,
59 SIGNAL(configurationRemoved(QNetworkConfiguration)),
60 SLOT(slotConfigurationChanged()),
61 Qt::QueuedConnection);
62 connect(m_networkConfigManager,
63 SIGNAL(updateCompleted()),
64 SLOT(slotConfigurationChanged()),
65 Qt::QueuedConnection);
66
67 connect(&m_idleRefreshTimer,
68 SIGNAL(timeout()),
69 SLOT(idleRefresh()),
70 Qt::QueuedConnection);
71 m_idleRefreshTimer.setSingleShot(true);
72
46 m_isOnline = m_networkConfigManager->isOnline();73 m_isOnline = m_networkConfigManager->isOnline();
47 LOG_DEBUG("Online status::" << m_isOnline);74 LOG_DEBUG("Online status::" << m_isOnline);
48 m_sessionTimer = new QTimer(this);75 m_sessionTimer = new QTimer(this);
@@ -72,6 +99,11 @@
72 return m_isOnline;99 return m_isOnline;
73}100}
74101
102Sync::InternetConnectionType NetworkManager::connectionType() const
103{
104 return m_connectionType;
105}
106
75void NetworkManager::connectSession(bool connectInBackground /* = false*/)107void NetworkManager::connectSession(bool connectInBackground /* = false*/)
76{108{
77 FUNCTION_CALL_TRACE;109 FUNCTION_CALL_TRACE;
@@ -110,12 +142,55 @@
110{142{
111 if (!m_errorEmitted && m_networkSession) {143 if (!m_errorEmitted && m_networkSession) {
112 if (!m_networkSession->isOpen()) {144 if (!m_networkSession->isOpen()) {
113 qWarning() << "No network reply received after 10 seconds, emitting session error.";145 LOG_WARNING("No network reply received after 10 seconds, emitting session error.");
114 slotSessionError(m_networkSession->error());146 slotSessionError(m_networkSession->error());
115 }147 }
116 }148 }
117}149}
118150
151void NetworkManager::slotConfigurationChanged()
152{
153 // wait for 3 secs before update connection status
154 // this avoid problems with connections that take a while to be stabilished
155 m_idleRefreshTimer.start(3000);
156}
157
158void NetworkManager::idleRefresh()
159{
160 FUNCTION_CALL_TRACE;
161 QList<QNetworkConfiguration> activeConfigs = m_networkConfigManager->allConfigurations(QNetworkConfiguration::Active);
162 QNetworkConfiguration::BearerType connectionType = QNetworkConfiguration::BearerUnknown;
163 QString bearerTypeName;
164
165 bool isOnline = activeConfigs.size() > 0;
166 if (isOnline)
167 {
168 // FIXME: due this bug lp:#1444162 on nm the QNetworkConfigurationManager
169 // returns the wrong default connection.
170 // We will consider the connection with the smallest bearer as the
171 // default connection, with that wifi and ethernet will be the first one
172 // https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1444162
173 connectionType = activeConfigs.first().bearerType();
174 bearerTypeName = activeConfigs.first().bearerTypeName();
175 foreach(const QNetworkConfiguration &conf, activeConfigs)
176 {
177 if (conf.bearerType() < connectionType)
178 {
179 connectionType = conf.bearerType();
180 bearerTypeName = conf.bearerTypeName();
181 }
182 }
183 }
184 LOG_DEBUG("New state:" << isOnline << " New type: " << bearerTypeName << "(" << connectionType << ")");
185 if ((isOnline != m_isOnline) ||
186 ((Sync::InternetConnectionType)connectionType != m_connectionType))
187 {
188 m_isOnline = isOnline;
189 m_connectionType = (Sync::InternetConnectionType) connectionType;
190 emit statusChanged(m_isOnline, m_connectionType);
191 }
192}
193
119void NetworkManager::disconnectSession()194void NetworkManager::disconnectSession()
120{195{
121 FUNCTION_CALL_TRACE;196 FUNCTION_CALL_TRACE;
@@ -134,19 +209,6 @@
134 }209 }
135}210}
136211
137void NetworkManager::slotOnlineStateChanged(bool isOnline)
138{
139 FUNCTION_CALL_TRACE;
140 LOG_DEBUG("Online status changed, is online is now::" << isOnline);
141 if(m_isOnline != isOnline)
142 {
143 if (m_sessionTimer->isActive())
144 m_sessionTimer->stop();
145 m_isOnline = isOnline;
146 emit valueChanged(m_isOnline);
147 }
148}
149
150void NetworkManager::slotSessionState(QNetworkSession::State status)212void NetworkManager::slotSessionState(QNetworkSession::State status)
151{213{
152 FUNCTION_CALL_TRACE;214 FUNCTION_CALL_TRACE;
153215
=== modified file 'libbuteosyncfw/common/NetworkManager.h'
--- libbuteosyncfw/common/NetworkManager.h 2014-05-28 03:22:34 +0000
+++ libbuteosyncfw/common/NetworkManager.h 2015-09-30 18:13:56 +0000
@@ -24,8 +24,9 @@
24#define NETWORKMANAGER_H_24#define NETWORKMANAGER_H_
2525
26#include <QNetworkSession>26#include <QNetworkSession>
27#include <QTimer>
28#include "SyncCommonDefs.h"
2729
28class QTimer;
29class QNetworkConfigurationManager;30class QNetworkConfigurationManager;
3031
31namespace Buteo32namespace Buteo
@@ -61,6 +62,13 @@
61 */62 */
62 bool isOnline();63 bool isOnline();
6364
65 /*! \brief Returns the type of connection used by the device.
66 *
67
68 * @return Sync::InternetConnectionType the type of connection.
69 */
70 Sync::InternetConnectionType connectionType() const;
71
64 /*! \brief Connects a new network session. If a session was already72 /*! \brief Connects a new network session. If a session was already
65 * open, the signal connectionSuccess will be emitted immediately,73 * open, the signal connectionSuccess will be emitted immediately,
66 * else the function will return and the signal connectionSuccess or74 * else the function will return and the signal connectionSuccess or
@@ -84,7 +92,7 @@
84 *92 *
85 * @param aConnected If true, the device is online93 * @param aConnected If true, the device is online
86 */94 */
87 void valueChanged(bool aConnected);95 void statusChanged(bool aConnected, Sync::InternetConnectionType aType);
8896
89 /*! \brief This signal is emitted when a network session gets97 /*! \brief This signal is emitted when a network session gets
90 * connected98 * connected
@@ -105,11 +113,15 @@
105 static int m_refCount; // Reference counter for number of open connections113 static int m_refCount; // Reference counter for number of open connections
106 bool m_errorEmitted; // Network error emited flag114 bool m_errorEmitted; // Network error emited flag
107 QTimer *m_sessionTimer;115 QTimer *m_sessionTimer;
116 Sync::InternetConnectionType m_connectionType;
117 QTimer m_idleRefreshTimer;
118
108private slots:119private slots:
109 void slotOnlineStateChanged(bool isOnline);
110 void slotSessionState(QNetworkSession::State status);120 void slotSessionState(QNetworkSession::State status);
111 void slotSessionError(QNetworkSession::SessionError error);121 void slotSessionError(QNetworkSession::SessionError error);
112 void sessionConnectionTimeout();122 void sessionConnectionTimeout();
123 void slotConfigurationChanged();
124 void idleRefresh();
113 };125 };
114}126}
115127
116128
=== modified file 'libbuteosyncfw/common/SyncCommonDefs.h'
--- libbuteosyncfw/common/SyncCommonDefs.h 2014-06-06 06:40:13 +0000
+++ libbuteosyncfw/common/SyncCommonDefs.h 2015-09-30 18:13:56 +0000
@@ -26,6 +26,7 @@
2626
27#include <QMetaType>27#include <QMetaType>
28#include <QDir>28#include <QDir>
29#include <QtNetwork/QNetworkConfiguration>
2930
30namespace Sync {31namespace Sync {
3132
@@ -83,6 +84,22 @@
83 CONNECTIVITY_INTERNET84 CONNECTIVITY_INTERNET
84};85};
8586
87enum InternetConnectionType {
88 INTERNET_CONNECTION_UNKNOWN = QNetworkConfiguration::BearerUnknown,
89 INTERNET_CONNECTION_ETHERNET = QNetworkConfiguration::BearerEthernet,
90 INTERNET_CONNECTION_WLAN = QNetworkConfiguration::BearerWLAN,
91 INTERNET_CONNECTION_2G = QNetworkConfiguration::Bearer2G,
92 INTERNET_CONNECTION_3G = QNetworkConfiguration::Bearer3G,
93 INTERNET_CONNECTION_4G = QNetworkConfiguration::Bearer4G,
94 INTERNET_CONNECTION_CDMA2000 = QNetworkConfiguration::BearerCDMA2000,
95 INTERNET_CONNECTION_WCDMA = QNetworkConfiguration::BearerWCDMA,
96 INTERNET_CONNECTION_HSPA = QNetworkConfiguration::BearerHSPA,
97 INTERNET_CONNECTION_BLUETOOTH = QNetworkConfiguration::BearerBluetooth,
98 INTERNET_CONNECTION_WIMAX = QNetworkConfiguration::BearerWiMAX,
99 INTERNET_CONNECTION_EVDO = QNetworkConfiguration::BearerEVDO,
100 INTERNET_CONNECTION_LTE = QNetworkConfiguration::BearerLTE
101};
102
86} // namespace Sync103} // namespace Sync
87104
88Q_DECLARE_METATYPE( Sync::SyncStatus );105Q_DECLARE_METATYPE( Sync::SyncStatus );
89106
=== modified file 'libbuteosyncfw/common/TransportTracker.cpp'
--- libbuteosyncfw/common/TransportTracker.cpp 2014-09-12 11:53:27 +0000
+++ libbuteosyncfw/common/TransportTracker.cpp 2015-09-30 18:13:56 +0000
@@ -66,7 +66,7 @@
6666
67 // BT67 // BT
68#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)68#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
69 69
70 // Set the bluetooth state70 // Set the bluetooth state
71 iTransportStates[Sync::CONNECTIVITY_BT] = btConnectivityStatus();71 iTransportStates[Sync::CONNECTIVITY_BT] = btConnectivityStatus();
7272
@@ -97,8 +97,9 @@
97 {97 {
98 iTransportStates[Sync::CONNECTIVITY_INTERNET] =98 iTransportStates[Sync::CONNECTIVITY_INTERNET] =
99 iInternet->isOnline();99 iInternet->isOnline();
100 connect(iInternet, SIGNAL(valueChanged(bool)),100 connect(iInternet,
101 this, SLOT(onInternetStateChanged(bool)) /*, Qt::QueuedConnection*/);101 SIGNAL(statusChanged(bool, Sync::InternetConnectionType)),
102 SLOT(onInternetStateChanged(bool, Sync::InternetConnectionType)) /*, Qt::QueuedConnection*/);
102 }103 }
103 else104 else
104 {105 {
@@ -143,7 +144,7 @@
143void TransportTracker::onBtStateChanged(QString aKey, QDBusVariant aValue)144void TransportTracker::onBtStateChanged(QString aKey, QDBusVariant aValue)
144{145{
145 FUNCTION_CALL_TRACE;146 FUNCTION_CALL_TRACE;
146 147
147 if (aKey == "Powered")148 if (aKey == "Powered")
148 {149 {
149 bool btPowered = aValue.variant().toBool();150 bool btPowered = aValue.variant().toBool();
@@ -153,12 +154,13 @@
153}154}
154#endif155#endif
155156
156void TransportTracker::onInternetStateChanged(bool aConnected)157void TransportTracker::onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType)
157{158{
158 FUNCTION_CALL_TRACE;159 FUNCTION_CALL_TRACE;
159160
160 LOG_DEBUG("Internet state changed:" << aConnected);161 LOG_DEBUG("Internet state changed:" << aConnected);
161 updateState(Sync::CONNECTIVITY_INTERNET, aConnected);162 updateState(Sync::CONNECTIVITY_INTERNET, aConnected);
163 emit networkStateChanged(aConnected, aType);
162}164}
163165
164void TransportTracker::updateState(Sync::ConnectivityType aType,166void TransportTracker::updateState(Sync::ConnectivityType aType,
@@ -175,19 +177,17 @@
175 }177 }
176 if(oldState != aState)178 if(oldState != aState)
177 {179 {
178 if (aType != Sync::CONNECTIVITY_INTERNET) {180 if (aType != Sync::CONNECTIVITY_INTERNET)
181 {
179 emit connectivityStateChanged(aType, aState);182 emit connectivityStateChanged(aType, aState);
180 }183 }
181 else {
182 emit networkStateChanged(aState);
183 }
184 }184 }
185}185}
186186
187bool TransportTracker::btConnectivityStatus()187bool TransportTracker::btConnectivityStatus()
188{188{
189 FUNCTION_CALL_TRACE;189 FUNCTION_CALL_TRACE;
190 190
191 bool btOn = false;191 bool btOn = false;
192 QDBusConnection *systemBus = new QDBusConnection(QDBusConnection::connectToBus(QDBusConnection::SystemBus,192 QDBusConnection *systemBus = new QDBusConnection(QDBusConnection::connectToBus(QDBusConnection::SystemBus,
193 QStringLiteral("buteo_system_bus2")));193 QStringLiteral("buteo_system_bus2")));
@@ -207,7 +207,7 @@
207 QList<QVariant> adapterList = reply.arguments();207 QList<QVariant> adapterList = reply.arguments();
208 // We will take the first adapter in the list208 // We will take the first adapter in the list
209 QString adapterPath = qdbus_cast<QDBusObjectPath>(adapterList.at(0)).path();209 QString adapterPath = qdbus_cast<QDBusObjectPath>(adapterList.at(0)).path();
210 210
211 if (!adapterPath.isEmpty() || !adapterPath.isNull())211 if (!adapterPath.isEmpty() || !adapterPath.isNull())
212 {212 {
213 // Retrive the properties of the adapter and check for "Powered" key213 // Retrive the properties of the adapter and check for "Powered" key
@@ -222,7 +222,7 @@
222 delete systemBus;222 delete systemBus;
223 return btOn;223 return btOn;
224 }224 }
225 225
226 QDBusArgument arg = reply.arguments().at(0).value<QDBusArgument>();226 QDBusArgument arg = reply.arguments().at(0).value<QDBusArgument>();
227 if (arg.currentType() == QDBusArgument::MapType)227 if (arg.currentType() == QDBusArgument::MapType)
228 {228 {
229229
=== modified file 'libbuteosyncfw/common/TransportTracker.h'
--- libbuteosyncfw/common/TransportTracker.h 2014-09-12 11:53:27 +0000
+++ libbuteosyncfw/common/TransportTracker.h 2015-09-30 18:13:56 +0000
@@ -78,8 +78,9 @@
78 /*! \brief Signal emitted when a n/w state changes78 /*! \brief Signal emitted when a n/w state changes
79 *79 *
80 * @param aState New state. True if available, false if not.80 * @param aState New state. True if available, false if not.
81 * @param aType Connection type. The type of connetcion with the Internet.
81 */82 */
82 void networkStateChanged(bool aState);83 void networkStateChanged(bool aState, Sync::InternetConnectionType aType);
8384
84 /*! \brief Signal emitted when a network session is successfully opened85 /*! \brief Signal emitted when a network session is successfully opened
85 */86 */
@@ -99,7 +100,7 @@
99 void onBtStateChanged(QString aKey, QDBusVariant aValue);100 void onBtStateChanged(QString aKey, QDBusVariant aValue);
100#endif101#endif
101102
102 void onInternetStateChanged(bool aConnected);103 void onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType);
103104
104private:105private:
105106
@@ -127,7 +128,7 @@
127 friend class TransportTrackerTest;128 friend class TransportTrackerTest;
128 friend class SynchronizerTest;129 friend class SynchronizerTest;
129#endif130#endif
130 131
131 bool btConnectivityStatus();132 bool btConnectivityStatus();
132133
133};134};
134135
=== modified file 'libbuteosyncfw/profile/ProfileManager.cpp'
--- libbuteosyncfw/profile/ProfileManager.cpp 2015-03-05 06:24:35 +0000
+++ libbuteosyncfw/profile/ProfileManager.cpp 2015-09-30 18:13:56 +0000
@@ -129,7 +129,6 @@
129129
130Profile *ProfileManagerPrivate::load(const QString &aName, const QString &aType)130Profile *ProfileManagerPrivate::load(const QString &aName, const QString &aType)
131{131{
132
133 QString profilePath = findProfileFile(aName, aType);132 QString profilePath = findProfileFile(aName, aType);
134 QString backupProfilePath = profilePath + BACKUP_EXT;133 QString backupProfilePath = profilePath + BACKUP_EXT;
135134
@@ -739,6 +738,14 @@
739 bool exists = d_ptr->profileExists(aProfile.name(),aProfile.type());738 bool exists = d_ptr->profileExists(aProfile.name(),aProfile.type());
740739
741 QString profileId("");740 QString profileId("");
741
742 // We need to save before emit the signalProfileChanged, if this is the first
743 // update the profile will only exists on disk after the save and any operation
744 // using this profile triggered by the signal will fail.
745 if(d_ptr->save(aProfile)) {
746 profileId = aProfile.name();
747 }
748
742 // Profile did not exist, it was a new one. Add it and emit signal with "added" value:749 // Profile did not exist, it was a new one. Add it and emit signal with "added" value:
743 if (!exists) {750 if (!exists) {
744 emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_ADDED,aProfile.toString());751 emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_ADDED,aProfile.toString());
@@ -746,9 +753,6 @@
746 emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_MODIFIED,aProfile.toString());753 emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_MODIFIED,aProfile.toString());
747 }754 }
748755
749 if(d_ptr->save(aProfile)) {
750 profileId = aProfile.name();
751 }
752 return profileId;756 return profileId;
753}757}
754758
@@ -1254,7 +1258,7 @@
1254 !iSyncRetriesInfo[aProfile->name()].isEmpty())1258 !iSyncRetriesInfo[aProfile->name()].isEmpty())
1255 {1259 {
1256 quint32 mins = iSyncRetriesInfo[aProfile->name()].takeFirst();1260 quint32 mins = iSyncRetriesInfo[aProfile->name()].takeFirst();
1257 nextRetryInterval = QDateTime::currentDateTime().addSecs(mins * 60); 1261 nextRetryInterval = QDateTime::currentDateTime().addSecs(mins * 60);
1258 LOG_DEBUG("syncretries : retry for profile" << aProfile->name() << "in" << mins <<"minutes");1262 LOG_DEBUG("syncretries : retry for profile" << aProfile->name() << "in" << mins <<"minutes");
1259 LOG_DEBUG("syncretries :" << iSyncRetriesInfo[aProfile->name()].count() <<"attempts remain");1263 LOG_DEBUG("syncretries :" << iSyncRetriesInfo[aProfile->name()].count() <<"attempts remain");
1260 }1264 }
12611265
=== modified file 'libbuteosyncfw/profile/SyncProfile.cpp'
--- libbuteosyncfw/profile/SyncProfile.cpp 2015-01-30 06:49:01 +0000
+++ libbuteosyncfw/profile/SyncProfile.cpp 2015-09-30 18:13:56 +0000
@@ -259,14 +259,11 @@
259 if (d_ptr->iLog)259 if (d_ptr->iLog)
260 {260 {
261 QList<const SyncResults*> allResults = d_ptr->iLog->allResults();261 QList<const SyncResults*> allResults = d_ptr->iLog->allResults();
262 if (allResults.size () > 0)262 foreach (const SyncResults* result, allResults) {
263 {263 if ((result->majorCode () == SyncResults::SYNC_RESULT_SUCCESS) &&
264 lastSuccessSyncTime = allResults.at (0)->syncTime ();264 (result->minorCode () == SyncResults::NO_ERROR) &&
265 foreach (const SyncResults* result, allResults) {265 (lastSyncTime().isNull() || (result->syncTime () > lastSuccessSyncTime))) {
266 if ((result->majorCode () == SyncResults::SYNC_RESULT_SUCCESS) &&266 lastSuccessSyncTime = result->syncTime ();
267 (result->minorCode () == SyncResults::NO_ERROR) &&
268 (result->syncTime () > lastSuccessSyncTime))
269 lastSuccessSyncTime = result->syncTime ();
270 }267 }
271 }268 }
272 }269 }
273270
=== modified file 'msyncd/AccountsHelper.cpp'
--- msyncd/AccountsHelper.cpp 2015-01-27 07:01:48 +0000
+++ msyncd/AccountsHelper.cpp 2015-09-30 18:13:56 +0000
@@ -26,6 +26,8 @@
26#include "Profile.h"26#include "Profile.h"
27#include "ProfileEngineDefs.h"27#include "ProfileEngineDefs.h"
2828
29#include <QTimer>
30
29static const QString ACCOUNTS_GLOBAL_SERVICE("global");31static const QString ACCOUNTS_GLOBAL_SERVICE("global");
3032
31using namespace Buteo;33using namespace Buteo;
@@ -36,13 +38,15 @@
36 iAccountManager = new Accounts::Manager(this);38 iAccountManager = new Accounts::Manager(this);
37 // Connect to signal for account creation, deletion, and modification39 // Connect to signal for account creation, deletion, and modification
38 QObject::connect(iAccountManager, SIGNAL(accountCreated(Accounts::AccountId)),40 QObject::connect(iAccountManager, SIGNAL(accountCreated(Accounts::AccountId)),
39 this, SLOT(slotAccountCreated(Accounts::AccountId)));41 this, SLOT(createProfileForAccount(Accounts::AccountId)));
40 QObject::connect(iAccountManager, SIGNAL(accountRemoved(Accounts::AccountId)),42 QObject::connect(iAccountManager, SIGNAL(accountRemoved(Accounts::AccountId)),
41 this, SLOT(slotAccountRemoved(Accounts::AccountId)));43 this, SLOT(slotAccountRemoved(Accounts::AccountId)));
42 QObject::connect(iAccountManager, SIGNAL(accountUpdated(Accounts::AccountId)),44 QObject::connect(iAccountManager, SIGNAL(accountUpdated(Accounts::AccountId)),
43 this, SLOT(slotAccountUpdated(Accounts::AccountId)));45 this, SLOT(slotAccountUpdated(Accounts::AccountId)));
4446
45 registerAccountListeners();47 // load accounts after return from contructor, to allow connection with class singals
48 // that can be fired by 'registerAccountListeners' function
49 QTimer::singleShot(0, this, SLOT(registerAccountListeners()));
46}50}
4751
48AccountsHelper::~AccountsHelper()52AccountsHelper::~AccountsHelper()
@@ -54,9 +58,10 @@
54 // their parent, aka, the manager58 // their parent, aka, the manager
55}59}
5660
57void AccountsHelper::slotAccountCreated(Accounts::AccountId id)61QString AccountsHelper::createProfileForAccount(Accounts::AccountId id)
58{62{
59 FUNCTION_CALL_TRACE;63 FUNCTION_CALL_TRACE;
64 QString profileName;
60 Accounts::Account *newAccount = iAccountManager->account(id);65 Accounts::Account *newAccount = iAccountManager->account(id);
61 bool profileFoundAndCreated = false;66 bool profileFoundAndCreated = false;
6267
@@ -66,7 +71,7 @@
66 Accounts::ServiceList serviceList = newAccount->services();71 Accounts::ServiceList serviceList = newAccount->services();
67 foreach(Accounts::Service service, serviceList)72 foreach(Accounts::Service service, serviceList)
68 {73 {
69 // Look for a sync profile that matches the service name74 // Look for a sync profile that matches the service name (template)
70 LOG_DEBUG("Looking for sync profile::" << service.name());75 LOG_DEBUG("Looking for sync profile::" << service.name());
71 SyncProfile *syncProfile = iProfileManager.syncProfile(service.name());76 SyncProfile *syncProfile = iProfileManager.syncProfile(service.name());
72 LOG_DEBUG("Found profile::" << service.name());77 LOG_DEBUG("Found profile::" << service.name());
@@ -74,7 +79,7 @@
74 (true == syncProfile->boolKey(KEY_USE_ACCOUNTS, false))79 (true == syncProfile->boolKey(KEY_USE_ACCOUNTS, false))
75 )80 )
76 {81 {
77 addAccountIfNotExists(newAccount, service, syncProfile);82 profileName = addAccountIfNotExists(newAccount, service, syncProfile);
78 profileFoundAndCreated = true;83 profileFoundAndCreated = true;
79 }84 }
80 if(0 != syncProfile)85 if(0 != syncProfile)
@@ -86,7 +91,7 @@
8691
87 if (profileFoundAndCreated == false)92 if (profileFoundAndCreated == false)
88 {93 {
89 // Fetch the key "remote_service_name" from the account settings and 94 // Fetch the key "remote_service_name" from the account settings and
90 // use it to create a profile95 // use it to create a profile
91 QString profileName = newAccount->valueAsString(REMOTE_SERVICE_NAME);96 QString profileName = newAccount->valueAsString(REMOTE_SERVICE_NAME);
92 LOG_DEBUG("Profile name from account setting:" << profileName);97 LOG_DEBUG("Profile name from account setting:" << profileName);
@@ -97,10 +102,15 @@
97 if (syncProfile->boolKey (KEY_USE_ACCOUNTS, false) == true)102 if (syncProfile->boolKey (KEY_USE_ACCOUNTS, false) == true)
98 createProfileForAccount (newAccount, profileName, syncProfile);103 createProfileForAccount (newAccount, profileName, syncProfile);
99104
105 profileName = syncProfile->name();
100 delete syncProfile;106 delete syncProfile;
101 }107 }
102 }108 }
109 } else {
110 LOG_DEBUG("Account not found:" << id);
103 }111 }
112
113 return profileName;
104}114}
105115
106void AccountsHelper::slotAccountRemoved(Accounts::AccountId id)116void AccountsHelper::slotAccountRemoved(Accounts::AccountId id)
@@ -186,7 +196,7 @@
186 foreach(SyncProfile *profile, profiles)196 foreach(SyncProfile *profile, profiles)
187 {197 {
188 // See if the service name matches198 // See if the service name matches
189 if(serviceName == profile->name())199 if(serviceName == profile->key(REMOTE_SERVICE_NAME))
190 {200 {
191 // Check if the status really changed here201 // Check if the status really changed here
192 // saving the account can trigger the emition of enabledChanged()202 // saving the account can trigger the emition of enabledChanged()
@@ -331,16 +341,16 @@
331 delete newProfile;341 delete newProfile;
332}342}
333343
334void AccountsHelper::addAccountIfNotExists(Accounts::Account *account,344QString AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
335 Accounts::Service service,345 Accounts::Service service,
336 const SyncProfile *baseProfile)346 const SyncProfile *baseProfile)
337{347{
338 FUNCTION_CALL_TRACE;348 FUNCTION_CALL_TRACE;
339349
340 Profile *serviceProfile = iProfileManager.profile(service.name(), Profile::TYPE_SYNC);350 Profile *serviceProfile = iProfileManager.profile(service.name(), Profile::TYPE_SYNC);
341 if (!serviceProfile) {351 if (!serviceProfile) {
342 LOG_DEBUG ("!!!! Service not supported !!!!");352 LOG_DEBUG ("!!!! Service not supported !!!!");
343 return;353 return QString();
344 }354 }
345355
346 QString profileName ;356 QString profileName ;
@@ -367,9 +377,11 @@
367 // Add the account ID to the profile377 // Add the account ID to the profile
368 newProfile->setKey(KEY_ACCOUNT_ID, QString::number(account->id()));378 newProfile->setKey(KEY_ACCOUNT_ID, QString::number(account->id()));
369 // Check if service is enabled379 // Check if service is enabled
370 LOG_DEBUG("Service:: " << service.displayName() << "enabled status::" << account->enabled());380 LOG_DEBUG("Service:: " << service.displayName() <<
381 "enabled status::" << (account->enabled() && account->enabledServices().contains(service)));
371 // Set profile as enabled382 // Set profile as enabled
372 newProfile->setEnabled(account->enabled());383 newProfile->setEnabled(account->enabled() &&
384 account->enabledServices().contains(service));
373 setSyncSchedule (newProfile, account->id(), true);385 setSyncSchedule (newProfile, account->id(), true);
374386
375 // Save the newly created profile387 // Save the newly created profile
@@ -398,6 +410,8 @@
398 {410 {
399 delete profile;411 delete profile;
400 }412 }
413
414 return profileName;
401}415}
402416
403void AccountsHelper::addSetting(Accounts::AccountId id, QString key, QVariant value) {417void AccountsHelper::addSetting(Accounts::AccountId id, QString key, QVariant value) {
@@ -448,12 +462,27 @@
448void AccountsHelper::registerAccountListener(Accounts::AccountId id)462void AccountsHelper::registerAccountListener(Accounts::AccountId id)
449{463{
450 FUNCTION_CALL_TRACE;464 FUNCTION_CALL_TRACE;
465
451 Accounts::Account *account = iAccountManager->account(id);466 Accounts::Account *account = iAccountManager->account(id);
467 if (iAccountList.contains(account)) {
468 return;
469 }
452 iAccountList.append(account);470 iAccountList.append(account);
453 // Callback for account enabled/disabled471 // Callback for account enabled/disabled
454 QObject::connect(account, SIGNAL(enabledChanged(const QString&, bool)),472 QObject::connect(account,
455 this, SLOT(slotAccountEnabledChanged(const QString&, bool)));473 SIGNAL(enabledChanged(const QString&, bool)),
474 SLOT(slotAccountEnabledChanged(const QString&, bool)),
475 Qt::UniqueConnection);
456476
477 // Account SyncOnChange
478 QList<SyncProfile*> profiles = getProfilesByAccountId(id);
479 foreach(SyncProfile *profile, profiles)
480 {
481 if(profile->isSOCProfile())
482 {
483 emit enableSOC(profile->name());
484 }
485 }
457 account->selectService();486 account->selectService();
458 account->beginGroup("scheduler");487 account->beginGroup("scheduler");
459 LOG_DEBUG("Watching Group :" << account->group());488 LOG_DEBUG("Watching Group :" << account->group());
@@ -463,5 +492,8 @@
463 return;492 return;
464 }493 }
465 iAcctWatchMap[watch] = id;494 iAcctWatchMap[watch] = id;
466 QObject::connect(watch, SIGNAL(notify(const char *)), this, SLOT(slotSchedulerSettingsChanged(const char *)));495 QObject::connect(watch,
496 SIGNAL(notify(const char *)),
497 SLOT(slotSchedulerSettingsChanged(const char *)),
498 Qt::UniqueConnection);
467}499}
468500
=== modified file 'msyncd/AccountsHelper.h'
--- msyncd/AccountsHelper.h 2014-11-07 07:26:49 +0000
+++ msyncd/AccountsHelper.h 2015-09-30 18:13:56 +0000
@@ -29,12 +29,12 @@
29#include <Accounts/account.h>29#include <Accounts/account.h>
3030
31namespace Buteo {31namespace Buteo {
32 32
33class Profile;33class Profile;
34class AccountsHelperTest;34class AccountsHelperTest;
35class ProfileManager;35class ProfileManager;
36class SyncProfile;36class SyncProfile;
37 37
38const QString REMOTE_SERVICE_NAME("remote_service_name");38const QString REMOTE_SERVICE_NAME("remote_service_name");
3939
40/*! \brief Helper Class towards Accounts::Manager and various SSO related40/*! \brief Helper Class towards Accounts::Manager and various SSO related
@@ -57,7 +57,7 @@
57 *57 *
58 */58 */
59 virtual ~AccountsHelper();59 virtual ~AccountsHelper();
60 60
61 /*! \brief Returns sync profiles that correspond to a given account ID61 /*! \brief Returns sync profiles that correspond to a given account ID
62 *62 *
63 * \param id - The account ID.63 * \param id - The account ID.
@@ -68,30 +68,31 @@
6868
69public Q_SLOTS:69public Q_SLOTS:
7070
71 /*! \brief slot for Accounts::Manager accountCreated signal71 /*! \brief This method is used to create a profile for a specified
72 *72 * account
73 * \param id Accounts Id73 * \param id Accounts Id
74 */74 * \return A string with the new profile name
75 void slotAccountCreated(Accounts::AccountId id);75 */
76 QString createProfileForAccount(Accounts::AccountId id);
7677
77 /*! \brief slot for Accounts::Manager accountRemoved signal78 /*! \brief slot for Accounts::Manager accountRemoved signal
78 *79 *
79 * \param id of the accounts80 * \param id of the accounts
80 */81 */
81 void slotAccountRemoved(Accounts::AccountId id);82 void slotAccountRemoved(Accounts::AccountId id);
8283
83 /*! \brief slot for Accounts::Account enabledChanged signal84 /*! \brief slot for Accounts::Account enabledChanged signal
84 *85 *
85 * \param serviceName The service that was enabled/disabled. Empty if the86 * \param serviceName The service that was enabled/disabled. Empty if the
86 * entire account is enabled/disabled87 * entire account is enabled/disabled
87 * \param enabled Boolean indicating enabled (true) or disabled (false)88 * \param enabled Boolean indicating enabled (true) or disabled (false)
88 */89 */
89 void slotAccountEnabledChanged(const QString &serviceName, bool enabled);90 void slotAccountEnabledChanged(const QString &serviceName, bool enabled);
90 91
91 /*! \brief slot for Accounts::Manager displayNameChanged signal92 /*! \brief slot for Accounts::Manager displayNameChanged signal
92 * *93 * *
93 * \param id of the accounts94 * \param id of the accounts
94 */95 */
95 void slotAccountUpdated(Accounts::AccountId id);96 void slotAccountUpdated(Accounts::AccountId id);
9697
97 void slotSchedulerSettingsChanged(const char *aKey);98 void slotSchedulerSettingsChanged(const char *aKey);
@@ -102,22 +103,20 @@
102 void removeProfile(QString profileId);103 void removeProfile(QString profileId);
103 void removeScheduledSync(const QString& profileId);104 void removeScheduledSync(const QString& profileId);
104105
106private Q_SLOTS:
107
108 void registerAccountListeners();
109
105private:110private:
106
107 /*!
108 * \brief This method is used to create a profile for a specified
109 * account
110 */
111 void createProfileForAccount(Accounts::Account* account,111 void createProfileForAccount(Accounts::Account* account,
112 const QString profileName,112 const QString profileName,
113 const SyncProfile* baseProfile);113 const SyncProfile* baseProfile);
114114
115 void addAccountIfNotExists(Accounts::Account *account,115 QString addAccountIfNotExists(Accounts::Account *account,
116 Accounts::Service service,116 Accounts::Service service,
117 const SyncProfile *baseProfile);117 const SyncProfile *baseProfile);
118118
119 void setSyncSchedule(SyncProfile *syncProfile, Accounts::AccountId id, bool aCreateNew = false);119 void setSyncSchedule(SyncProfile *syncProfile, Accounts::AccountId id, bool aCreateNew = false);
120 void registerAccountListeners();
121120
122 void addSetting(Accounts::AccountId id, QString key, QVariant value);121 void addSetting(Accounts::AccountId id, QString key, QVariant value);
123122
124123
=== modified file 'msyncd/SyncDBusAdaptor.cpp'
--- msyncd/SyncDBusAdaptor.cpp 2015-01-30 06:49:01 +0000
+++ msyncd/SyncDBusAdaptor.cpp 2015-09-30 18:13:56 +0000
@@ -206,3 +206,11 @@
206 QMetaObject::invokeMethod(parent(), "isSyncedExternally", Q_ARG(uint, aAccountId), Q_ARG(QString, aClientProfileName));206 QMetaObject::invokeMethod(parent(), "isSyncedExternally", Q_ARG(uint, aAccountId), Q_ARG(QString, aClientProfileName));
207}207}
208208
209QString SyncDBusAdaptor::createSyncProfileForAccount(uint aAccountId)
210{
211 // handle method call com.meego.msyncd.createSyncProfileForAccount
212 QString out0;
213 QMetaObject::invokeMethod(parent(), "createSyncProfileForAccount", Q_RETURN_ARG(QString, out0), Q_ARG(uint, aAccountId));
214 return out0;
215}
216
209217
=== modified file 'msyncd/SyncDBusAdaptor.h'
--- msyncd/SyncDBusAdaptor.h 2015-01-30 06:49:01 +0000
+++ msyncd/SyncDBusAdaptor.h 2015-09-30 18:13:56 +0000
@@ -157,6 +157,10 @@
157" <arg direction=\"out\" type=\"au\"/>\n"157" <arg direction=\"out\" type=\"au\"/>\n"
158" <annotation value=\"QList&lt;uint>\" name=\"com.trolltech.QtDBus.QtTypeName.Out0\"/>\n"158" <annotation value=\"QList&lt;uint>\" name=\"com.trolltech.QtDBus.QtTypeName.Out0\"/>\n"
159" </method>\n"159" </method>\n"
160" <method name=\"createSyncProfileForAccount\">\n"
161" <arg direction=\"out\" type=\"s\"/>\n"
162" <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"
163" </method>\n"
160" <method name=\"status\">\n"164" <method name=\"status\">\n"
161" <arg direction=\"out\" type=\"i\"/>\n"165" <arg direction=\"out\" type=\"i\"/>\n"
162" <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"166" <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"
@@ -198,6 +202,7 @@
198 QList<uint> syncingAccounts();202 QList<uint> syncingAccounts();
199 bool updateProfile(const QString &aProfileAsXml);203 bool updateProfile(const QString &aProfileAsXml);
200 Q_NOREPLY void isSyncedExternally(uint aAccountId, const QString aClientProfileName);204 Q_NOREPLY void isSyncedExternally(uint aAccountId, const QString aClientProfileName);
205 QString createSyncProfileForAccount(uint aAccountId);
201Q_SIGNALS: // SIGNALS206Q_SIGNALS: // SIGNALS
202 void backupDone();207 void backupDone();
203 void backupInProgress();208 void backupInProgress();
204209
=== modified file 'msyncd/SyncDBusInterface.h'
--- msyncd/SyncDBusInterface.h 2015-01-30 06:49:01 +0000
+++ msyncd/SyncDBusInterface.h 2015-09-30 18:13:56 +0000
@@ -103,29 +103,29 @@
103 *103 *
104 */104 */
105 void signalProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);105 void signalProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
106 106
107 107
108 /*! \brief Notifies about Backup start.108 /*! \brief Notifies about Backup start.
109 *109 *
110 * This signal is sent when the backup framework is backing the sync related110 * This signal is sent when the backup framework is backing the sync related
111 * data111 * data
112 */112 */
113 void backupInProgress ();113 void backupInProgress ();
114 114
115 /*! \brief Notifies about Backup done.115 /*! \brief Notifies about Backup done.
116 *116 *
117 * This signal is sent when the backup framework has completed backing the sync related117 * This signal is sent when the backup framework has completed backing the sync related
118 * data.118 * data.
119 */119 */
120 void backupDone();120 void backupDone();
121 121
122 /*! \brief Notifies about Restore start.122 /*! \brief Notifies about Restore start.
123 *123 *
124 * This signal is sent when the backup framework is restoring the sync related124 * This signal is sent when the backup framework is restoring the sync related
125 * data125 * data
126 */126 */
127 void restoreInProgress();127 void restoreInProgress();
128 128
129 /*! \brief Notifies about Restore Done.129 /*! \brief Notifies about Restore Done.
130 *130 *
131 * This signal is sent when the backup framework has restored the sync related131 * This signal is sent when the backup framework has restored the sync related
@@ -160,7 +160,7 @@
160 * \param aNextSyncTime This is an out parameter. The next sync time.160 * \param aNextSyncTime This is an out parameter. The next sync time.
161 */161 */
162 void statusChanged(unsigned int aAccountId, int aNewStatus, int aFailedReason, qlonglong aPrevSyncTime, qlonglong aNextSyncTime);162 void statusChanged(unsigned int aAccountId, int aNewStatus, int aFailedReason, qlonglong aPrevSyncTime, qlonglong aNextSyncTime);
163 163
164 /*! \brief Returns the connectivity state of a specific medium like164 /*! \brief Returns the connectivity state of a specific medium like
165 * bluetooth, USB or network.165 * bluetooth, USB or network.
166 * \see SyncCommonDefs::ConnectivityType for arguments166 * \see SyncCommonDefs::ConnectivityType for arguments
@@ -257,16 +257,16 @@
257 * \return Profile name list.257 * \return Profile name list.
258 */258 */
259 virtual QStringList runningSyncs() = 0;259 virtual QStringList runningSyncs() = 0;
260 260
261 261
262 /*!262 /*!
263 * \brief This function returns true if backup/restore in progress else263 * \brief This function returns true if backup/restore in progress else
264 * false.264 * false.
265 */265 */
266 virtual bool getBackUpRestoreState() = 0;266 virtual bool getBackUpRestoreState() = 0;
267 267
268 268
269 /*!269 /*!
270 * \brief sets the schedule for a profile270 * \brief sets the schedule for a profile
271 *271 *
272 * This Function helps in setting a schedule to profile272 * This Function helps in setting a schedule to profile
@@ -312,7 +312,7 @@
312 * \return The sync profile as Xml string.312 * \return The sync profile as Xml string.
313 */313 */
314 virtual QString syncProfile(const QString &aProfileId) = 0;314 virtual QString syncProfile(const QString &aProfileId) = 0;
315 315
316 /*! \brief Gets a sync profiles matching the key-value.316 /*! \brief Gets a sync profiles matching the key-value.
317 *317 *
318 * Loads and merges also all sub-profiles that are referenced from the318 * Loads and merges also all sub-profiles that are referenced from the
@@ -323,7 +323,7 @@
323 * \return The sync profiles as Xml string list.323 * \return The sync profiles as Xml string list.
324 */324 */
325 virtual QStringList syncProfilesByKey(const QString &aKey, const QString &aValue) = 0;325 virtual QStringList syncProfilesByKey(const QString &aKey, const QString &aValue) = 0;
326 326
327 /*! \brief Gets a profiles matching the profile type.327 /*! \brief Gets a profiles matching the profile type.
328 *328 *
329 * \param aType Type of the profile service/storage/sync.329 * \param aType Type of the profile service/storage/sync.
@@ -336,13 +336,13 @@
336 * \param aAccountId The account ID.336 * \param aAccountId The account ID.
337 */337 */
338 virtual Q_NOREPLY void start(unsigned int aAccountId) = 0;338 virtual Q_NOREPLY void start(unsigned int aAccountId) = 0;
339 339
340 /*! \brief Stops sync for all profiles matching the given account ID.340 /*! \brief Stops sync for all profiles matching the given account ID.
341 *341 *
342 * \param aAccountId The account ID.342 * \param aAccountId The account ID.
343 */343 */
344 virtual Q_NOREPLY void stop(unsigned int aAccountId) = 0;344 virtual Q_NOREPLY void stop(unsigned int aAccountId) = 0;
345 345
346 /*! \brief Returns the list of account IDs for which sync is ongoing346 /*! \brief Returns the list of account IDs for which sync is ongoing
347 *347 *
348 * \return The list of account IDs currectly syncing.348 * \return The list of account IDs currectly syncing.
@@ -373,6 +373,13 @@
373 * having several services enabled373 * having several services enabled
374 */374 */
375 virtual Q_NOREPLY void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName) = 0;375 virtual Q_NOREPLY void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName) = 0;
376
377 /*! \brief Create a sync profile for the account if it does not exists
378 *
379 * \param aAccountId The account ID.
380 * \return The profile name if the profile was created successful or empty if it fails
381 */
382 virtual QString createSyncProfileForAccount(uint aAccountId) = 0;
376};383};
377384
378}385}
379386
=== modified file 'msyncd/SyncOnChangeScheduler.cpp'
--- msyncd/SyncOnChangeScheduler.cpp 2014-02-20 07:06:08 +0000
+++ msyncd/SyncOnChangeScheduler.cpp 2015-09-30 18:13:56 +0000
@@ -14,6 +14,11 @@
14SyncOnChangeScheduler::~SyncOnChangeScheduler()14SyncOnChangeScheduler::~SyncOnChangeScheduler()
15{15{
16 FUNCTION_CALL_TRACE;16 FUNCTION_CALL_TRACE;
17 foreach(QObject *o, iSOCTimers.values()) {
18 delete o;
19 }
20 iSOCTimers.clear();
21 iSOCProfileNames.clear();
17}22}
1823
19bool SyncOnChangeScheduler::addProfile(const SyncProfile* aProfile)24bool SyncOnChangeScheduler::addProfile(const SyncProfile* aProfile)
@@ -30,6 +35,7 @@
30 Qt::QueuedConnection);35 Qt::QueuedConnection);
31 SOCtimer->fire();36 SOCtimer->fire();
32 scheduled = true;37 scheduled = true;
38 iSOCTimers.insert(aProfile->name(), SOCtimer);
33 LOG_DEBUG("Sync on change scheduled for profile"<< aProfile->name());39 LOG_DEBUG("Sync on change scheduled for profile"<< aProfile->name());
34 }40 }
35 else if(aProfile)41 else if(aProfile)
@@ -43,12 +49,15 @@
43{49{
44 FUNCTION_CALL_TRACE;50 FUNCTION_CALL_TRACE;
45 iSOCProfileNames.removeAll(aProfileName);51 iSOCProfileNames.removeAll(aProfileName);
52 // cancel timer
53 delete iSOCTimers.take(aProfileName);
46}54}
4755
48void SyncOnChangeScheduler::sync(const SyncProfile* aProfile)56void SyncOnChangeScheduler::sync(const SyncProfile* aProfile)
49{57{
50 FUNCTION_CALL_TRACE;58 FUNCTION_CALL_TRACE;
51 iSOCProfileNames.removeAll(aProfile->name());59 iSOCProfileNames.removeAll(aProfile->name());
60 iSOCTimers.remove(aProfile->name());
52 SyncOnChangeTimer *SOCtimer = qobject_cast<SyncOnChangeTimer*>(sender());61 SyncOnChangeTimer *SOCtimer = qobject_cast<SyncOnChangeTimer*>(sender());
53 if(SOCtimer)62 if(SOCtimer)
54 {63 {
5564
=== modified file 'msyncd/SyncOnChangeScheduler.h'
--- msyncd/SyncOnChangeScheduler.h 2011-02-02 09:39:11 +0000
+++ msyncd/SyncOnChangeScheduler.h 2015-09-30 18:13:56 +0000
@@ -40,7 +40,7 @@
40 *40 *
41 * Once the SOC is initiated (by sending a syncNow signal), the profile is41 * Once the SOC is initiated (by sending a syncNow signal), the profile is
42 * removed automatically42 * removed automatically
43 * 43 *
44 * @param aProfile pointer to sync profile44 * @param aProfile pointer to sync profile
45 * @return true if SOC could be scheduled, false otherwise45 * @return true if SOC could be scheduled, false otherwise
46 */46 */
@@ -63,6 +63,7 @@
6363
64private:64private:
65 QStringList iSOCProfileNames;65 QStringList iSOCProfileNames;
66 QMap<QString, QObject*> iSOCTimers;
66};67};
6768
68class SyncOnChangeTimer : public QObject69class SyncOnChangeTimer : public QObject
6970
=== modified file 'msyncd/SyncSession.h'
--- msyncd/SyncSession.h 2011-02-03 09:58:25 +0000
+++ msyncd/SyncSession.h 2015-09-30 18:13:56 +0000
@@ -182,7 +182,7 @@
182 void setProfileCreated(bool aProfileCreated);182 void setProfileCreated(bool aProfileCreated);
183183
184 //! \brief Maps sync failure error code from stack to SyncStatus184 //! \brief Maps sync failure error code from stack to SyncStatus
185 Sync::SyncStatus mapToSyncStatusError(int aErrorCode);185 Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
186186
187signals:187signals:
188188
189189
=== added directory 'msyncd/gschemas'
=== added file 'msyncd/gschemas/com.meego.msyncd.gschema.xml'
--- msyncd/gschemas/com.meego.msyncd.gschema.xml 1970-01-01 00:00:00 +0000
+++ msyncd/gschemas/com.meego.msyncd.gschema.xml 2015-09-30 18:13:56 +0000
@@ -0,0 +1,10 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<schemalist>
3 <schema id="com.meego.msyncd" path="/com/meego/msyncd/">
4 <key name="allow-scheduled-sync-over-cellular" type="b">
5 <summary>Scheduled Sync over cellular</summary>
6 <description>Allow scheduled syncs to run over cellular connections.</description>
7 <default>true</default>
8 </key>
9 </schema>
10</schemalist>
011
=== modified file 'msyncd/msyncd-app.pro'
--- msyncd/msyncd-app.pro 2014-06-19 06:03:32 +0000
+++ msyncd/msyncd-app.pro 2015-09-30 18:13:56 +0000
@@ -62,10 +62,13 @@
62service.path = /usr/lib/systemd/user/62service.path = /usr/lib/systemd/user/
63syncwidget.path = /etc/syncwidget/63syncwidget.path = /etc/syncwidget/
64syncwidget.files = com.meego.msyncd64syncwidget.files = com.meego.msyncd
65gschemas.path = /usr/share/glib-2.0/schemas
66gschemas.files = gschemas/com.meego.msyncd.gschema.xml
65INSTALLS += target \67INSTALLS += target \
66 loglevel \68 loglevel \
67 syncwidget \69 syncwidget \
68 service70 service \
71 gschemas
6972
70# #####################################################################73# #####################################################################
71# make coverage (debug)74# make coverage (debug)
7275
=== modified file 'msyncd/msyncd-lib.pro'
--- msyncd/msyncd-lib.pro 2014-06-19 06:03:32 +0000
+++ msyncd/msyncd-lib.pro 2015-09-30 18:13:56 +0000
@@ -19,7 +19,7 @@
19 ../libbuteosyncfw/profile19 ../libbuteosyncfw/profile
2020
2121
22PKGCONFIG += dbus-122PKGCONFIG += dbus-1 gio-2.0
2323
24equals(QT_MAJOR_VERSION, 4): {24equals(QT_MAJOR_VERSION, 4): {
25 PKGCONFIG += libsignon-qt accounts-qt25 PKGCONFIG += libsignon-qt accounts-qt
2626
=== modified file 'msyncd/synchronizer.cpp'
--- msyncd/synchronizer.cpp 2015-03-12 04:06:41 +0000
+++ msyncd/synchronizer.cpp 2015-09-30 18:13:56 +0000
@@ -1,4 +1,4 @@
1/*1/*
2 * This file is part of buteo-syncfw package2 * This file is part of buteo-syncfw package
3 *3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
@@ -21,6 +21,7 @@
21 * 02110-1301 USA21 * 02110-1301 USA
22 *22 *
23 */23 */
24#include <gio/gio.h>
24#include "synchronizer.h"25#include "synchronizer.h"
25#include "SyncDBusAdaptor.h"26#include "SyncDBusAdaptor.h"
26#include "SyncSession.h"27#include "SyncSession.h"
@@ -51,11 +52,11 @@
51#include <fcntl.h>52#include <fcntl.h>
52#include <termios.h>53#include <termios.h>
5354
55
54using namespace Buteo;56using namespace Buteo;
5557
56static const QString SYNC_DBUS_OBJECT = "/synchronizer";58static const QString SYNC_DBUS_OBJECT = "/synchronizer";
57static const QString SYNC_DBUS_SERVICE = "com.meego.msyncd";59static const QString SYNC_DBUS_SERVICE = "com.meego.msyncd";
58
59static const QString BT_PROPERTIES_NAME = "Name";60static const QString BT_PROPERTIES_NAME = "Name";
6061
61// Maximum time in milliseconds to wait for a thread to stop62// Maximum time in milliseconds to wait for a thread to stop
@@ -71,10 +72,9 @@
71 iClosing(false),72 iClosing(false),
72 iSOCEnabled(false),73 iSOCEnabled(false),
73 iSyncUIInterface(NULL)74 iSyncUIInterface(NULL)
74
75{75{
76 iSettings = g_settings_new_with_path("com.meego.msyncd", "/com/meego/msyncd/");
76 FUNCTION_CALL_TRACE;77 FUNCTION_CALL_TRACE;
77
78 this->setParent(aApplication);78 this->setParent(aApplication);
79}79}
8080
@@ -86,6 +86,7 @@
86 delete iSyncUIInterface;86 delete iSyncUIInterface;
87 iSyncUIInterface = NULL;87 iSyncUIInterface = NULL;
88 }88 }
89 g_object_unref(iSettings);
89}90}
9091
91bool Synchronizer::initialize()92bool Synchronizer::initialize()
@@ -115,8 +116,9 @@
115 this, SLOT(slotSyncStatus(QString, int, QString, int)),116 this, SLOT(slotSyncStatus(QString, int, QString, int)),
116 Qt::QueuedConnection);117 Qt::QueuedConnection);
117118
119 // use queued connection because the profile will be stored after the signal
118 connect(&iProfileManager ,SIGNAL(signalProfileChanged(QString,int,QString)),120 connect(&iProfileManager ,SIGNAL(signalProfileChanged(QString,int,QString)),
119 this, SIGNAL(signalProfileChanged(QString,int,QString)));121 this, SLOT(slotProfileChanged(QString,int,QString)), Qt::QueuedConnection);
120122
121 iNetworkManager = new NetworkManager(this);123 iNetworkManager = new NetworkManager(this);
122 Q_ASSERT(iNetworkManager);124 Q_ASSERT(iNetworkManager);
@@ -127,8 +129,9 @@
127 {129 {
128 iServerActivator = new ServerActivator(iProfileManager,130 iServerActivator = new ServerActivator(iProfileManager,
129 *iTransportTracker, this);131 *iTransportTracker, this);
130 connect(iTransportTracker, SIGNAL(networkStateChanged(bool)),132 connect(iTransportTracker,
131 this, SLOT(onNetworkStateChanged(bool)));133 SIGNAL(networkStateChanged(bool,Sync::InternetConnectionType)),
134 SLOT(onNetworkStateChanged(bool,Sync::InternetConnectionType)));
132 }135 }
133136
134 // Initialize account manager.137 // Initialize account manager.
@@ -184,7 +187,7 @@
184 else187 else
185 {188 {
186 QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(QString)),189 QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(QString)),
187 this, SLOT(startSync(QString)),190 this, SLOT(startScheduledSync(QString)),
188 Qt::QueuedConnection);191 Qt::QueuedConnection);
189 iSOCEnabled = true;192 iSOCEnabled = true;
190 }193 }
@@ -200,7 +203,7 @@
200{203{
201 FUNCTION_CALL_TRACE;204 FUNCTION_CALL_TRACE;
202 SyncProfile* profile = iProfileManager.syncProfile(aProfileName);205 SyncProfile* profile = iProfileManager.syncProfile(aProfileName);
203 if(!iSOCEnabled)206 if(profile->isSOCProfile() && !iSOCEnabled)
204 {207 {
205 QHash<QString,QList<SyncProfile*> > aSOCStorageMap;208 QHash<QString,QList<SyncProfile*> > aSOCStorageMap;
206 QList<SyncProfile*> SOCProfiles;209 QList<SyncProfile*> SOCProfiles;
@@ -217,13 +220,13 @@
217 else220 else
218 {221 {
219 QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(const QString&)),222 QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(const QString&)),
220 this, SLOT(startSync(const QString&)),223 this, SLOT(startScheduledSync(const QString&)),
221 Qt::QueuedConnection);224 Qt::QueuedConnection);
222 iSOCEnabled = true;225 iSOCEnabled = true;
223 LOG_DEBUG("Sync on change enabled for profile" << aProfileName);226 LOG_DEBUG("Sync on change enabled for profile" << aProfileName);
224 }227 }
225 }228 }
226 else229 else if (profile->isSOCProfile())
227 {230 {
228 iSyncOnChange.addProfile("hcontacts", profile);231 iSyncOnChange.addProfile("hcontacts", profile);
229 }232 }
@@ -291,55 +294,27 @@
291 // All scheduled syncs are online syncs294 // All scheduled syncs are online syncs
292 // Add this to the waiting online syncs and it will be started when we295 // Add this to the waiting online syncs and it will be started when we
293 // receive a session connection status from the NetworkManager296 // receive a session connection status from the NetworkManager
294 bool sessionConnected = !iWaitingOnlineSyncs.isEmpty();297 bool accept = acceptScheduledSync(iNetworkManager->isOnline(), iNetworkManager->connectionType());
295 if(!iWaitingOnlineSyncs.contains(aProfileName))298 if(accept)
296 {299 {
297 iWaitingOnlineSyncs.append(aProfileName);300 startSync(aProfileName, true);
298 }301 }
299 if(!sessionConnected)302 else if (!iWaitingOnlineSyncs.contains(aProfileName))
300 {303 {
301 QObject::connect(iNetworkManager, SIGNAL(connectionSuccess()), this,304 LOG_DEBUG("Wait for internet connection:" << aProfileName);
302 SLOT(slotNetworkSessionOpened()), Qt::QueuedConnection);305 if (iNetworkManager->isOnline())
303 QObject::connect(iNetworkManager, SIGNAL(connectionError()), this,306 {
304 SLOT(slotNetworkSessionError()), Qt::QueuedConnection);307 LOG_DEBUG("Connection over mobile data plan. The sync will be postponed untill a full connection is available;");
305 // Request for a network session308 }
306 iNetworkManager->connectSession(true);309 else
310 {
311 LOG_DEBUG("Device offline. Wait for internet connection.");
312 }
313 iWaitingOnlineSyncs.append(aProfileName);
307 }314 }
308 return true;315 return true;
309}316}
310317
311void Synchronizer::slotNetworkSessionOpened()
312{
313 FUNCTION_CALL_TRACE;
314 QObject::disconnect(iNetworkManager, SIGNAL(connectionSuccess()), this,
315 SLOT(slotNetworkSessionOpened()));
316 QObject::disconnect(iNetworkManager, SIGNAL(connectionError()), this,
317 SLOT(slotNetworkSessionError()));
318 foreach(QString profileName, iWaitingOnlineSyncs)
319 {
320 startSync(profileName, true);
321 }
322 iWaitingOnlineSyncs.clear();
323}
324
325void Synchronizer::slotNetworkSessionError()
326{
327 FUNCTION_CALL_TRACE;
328 QObject::disconnect(iNetworkManager, SIGNAL(connectionSuccess()), this,
329 SLOT(slotNetworkSessionOpened()));
330 QObject::disconnect(iNetworkManager, SIGNAL(connectionError()), this,
331 SLOT(slotNetworkSessionError()));
332 // Cancel all open sessions
333 foreach(QString profileName, iWaitingOnlineSyncs)
334 {
335 SyncResults syncResults(QDateTime::currentDateTime(), SyncResults::SYNC_RESULT_FAILED, SyncResults::CONNECTION_ERROR);
336 iProfileManager.saveSyncResults(profileName, syncResults);
337 reschedule(profileName);
338 }
339 iWaitingOnlineSyncs.clear();
340 iNetworkManager->disconnectSession();
341}
342
343bool Synchronizer::setSyncSchedule(QString aProfileId , QString aScheduleAsXml)318bool Synchronizer::setSyncSchedule(QString aProfileId , QString aScheduleAsXml)
344{319{
345 bool status = false;320 bool status = false;
@@ -364,6 +339,11 @@
364 return status;339 return status;
365}340}
366341
342QString Synchronizer::createSyncProfileForAccount(uint aAccountId)
343{
344 return iAccounts->createProfileForAccount(aAccountId);
345}
346
367bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)347bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)
368{348{
369 FUNCTION_CALL_TRACE;349 FUNCTION_CALL_TRACE;
@@ -378,6 +358,12 @@
378358
379 LOG_DEBUG( "Start sync requested for profile:" << aProfileName );359 LOG_DEBUG( "Start sync requested for profile:" << aProfileName );
380360
361 // This function can be called from a client app as manual sync:
362 // If we receive a manual sync to a profile that is peding to sync due a
363 // data change we can remove it from the iSyncOnChangeScheduler, to avoid a
364 // second sync.
365 iSyncOnChangeScheduler.removeProfile(aProfileName);
366
381 if (iActiveSessions.contains(aProfileName))367 if (iActiveSessions.contains(aProfileName))
382 {368 {
383 LOG_DEBUG( "Sync already in progress" );369 LOG_DEBUG( "Sync already in progress" );
@@ -389,6 +375,14 @@
389 emit syncStatus(aProfileName, Sync::SYNC_QUEUED, "", 0);375 emit syncStatus(aProfileName, Sync::SYNC_QUEUED, "", 0);
390 return true;376 return true;
391 }377 }
378 else if (!aScheduled && iWaitingOnlineSyncs.contains(aProfileName))
379 {
380 // Manual sync is allowed to happen in any kind of connection
381 // if sync is not scheduled remove it from iWaitingOnlineSyncs to avoid
382 // sync it twice later
383 iWaitingOnlineSyncs.removeOne(aProfileName);
384 LOG_DEBUG("Removing" << aProfileName << "from online waiting list.");
385 }
392386
393 SyncProfile *profile = iProfileManager.syncProfile(aProfileName);387 SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
394 if (!profile)388 if (!profile)
@@ -520,7 +514,7 @@
520 return false;514 return false;
521 }515 }
522516
523 LOG_DEBUG("Disable sync on change");517 LOG_DEBUG("Disable sync on change:" << iSOCEnabled << profile->isSOCProfile());
524 //As sync is ongoing, disable sync on change for now, we can query later if518 //As sync is ongoing, disable sync on change for now, we can query later if
525 //there are changes.519 //there are changes.
526 if(iSOCEnabled)520 if(iSOCEnabled)
@@ -754,7 +748,7 @@
754 }748 }
755749
756 QString profileName = session->profileName();750 QString profileName = session->profileName();
757 LOG_DEBUG( "Trying to start next sync in queue. Profile:" << profileName );751 LOG_DEBUG( "Trying to start next sync in queue. Profile:" << profileName << session->isScheduled());
758752
759#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)753#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
760 QBatteryInfo iDeviceInfo;754 QBatteryInfo iDeviceInfo;
@@ -1516,6 +1510,41 @@
1516 }1510 }
1517}1511}
15181512
1513void Synchronizer::slotProfileChanged(QString aProfileName, int aChangeType, QString aProfileAsXml)
1514{
1515 // start sync when a new profile is added
1516 switch (aChangeType)
1517 {
1518 case ProfileManager::PROFILE_ADDED:
1519 {
1520 enableSOCSlot(aProfileName);
1521 SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
1522 if (profile && profile->isEnabled()) {
1523 startSync(aProfileName);
1524 }
1525 }
1526 break;
1527
1528 case ProfileManager::PROFILE_REMOVED:
1529 iSyncOnChangeScheduler.removeProfile(aProfileName);
1530 iWaitingOnlineSyncs.removeAll(aProfileName);
1531 break;
1532
1533 case ProfileManager::PROFILE_MODIFIED:
1534 {
1535 // schedule a new sync in case of profile changed;
1536 // Example if the profile change from disable -> enable
1537 SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
1538 if (profile->isEnabled()) {
1539 startScheduledSync(aProfileName);
1540 }
1541 }
1542 break;
1543 }
1544
1545 emit signalProfileChanged(aProfileName, aChangeType, aProfileAsXml);
1546}
1547
1519void Synchronizer::reschedule(const QString &aProfileName)1548void Synchronizer::reschedule(const QString &aProfileName)
1520{1549{
1521 FUNCTION_CALL_TRACE;1550 FUNCTION_CALL_TRACE;
@@ -1903,10 +1932,24 @@
1903 return iProfileManager.profileNames(aType);1932 return iProfileManager.profileNames(aType);
1904}1933}
19051934
1906void Synchronizer::onNetworkStateChanged(bool aState)1935void Synchronizer::onNetworkStateChanged(bool aState, Sync::InternetConnectionType type)
1907{1936{
1908 FUNCTION_CALL_TRACE;1937 FUNCTION_CALL_TRACE;
1909 if(!aState) {1938 LOG_DEBUG("Network state changed: OnLine:" << aState << " connection type:" << type);
1939 if (acceptScheduledSync(aState, type))
1940 {
1941 LOG_DEBUG("Restart sync for profiles that need network");
1942 QStringList profiles(iWaitingOnlineSyncs);
1943 iWaitingOnlineSyncs.clear();
1944 foreach(QString profileName, profiles)
1945 {
1946 // start sync now, we do not need to call 'startScheduledSync' since that function
1947 // only checks for internet connection
1948 startSync(profileName, true);
1949 }
1950 }
1951 else if (!aState)
1952 {
1910 QList<QString> profiles = iActiveSessions.keys();1953 QList<QString> profiles = iActiveSessions.keys();
1911 foreach(QString profileId, profiles)1954 foreach(QString profileId, profiles)
1912 {1955 {
@@ -1919,8 +1962,8 @@
1919 delete profile;1962 delete profile;
1920 profile = NULL;1963 profile = NULL;
1921 }1964 }
1922 else {1965 else
19231966 {
1924 LOG_DEBUG("No profile found with aProfileId"<<profileId);1967 LOG_DEBUG("No profile found with aProfileId"<<profileId);
1925 }1968 }
1926 }1969 }
@@ -2069,6 +2112,19 @@
2069 }2112 }
2070}2113}
20712114
2115bool Synchronizer::acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const
2116{
2117 static QList<Sync::InternetConnectionType> allowedTypes;
2118 if (allowedTypes.isEmpty())
2119 {
2120 allowedTypes << Sync::INTERNET_CONNECTION_WLAN
2121 << Sync::INTERNET_CONNECTION_ETHERNET;
2122 }
2123
2124 return (aConnected && (g_settings_get_boolean(iSettings, "allow-scheduled-sync-over-cellular") ||
2125 allowedTypes.contains(aType)));
2126}
2127
2072void Synchronizer::isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName)2128void Synchronizer::isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName)
2073{2129{
2074 LOG_DEBUG("Received isSyncedExternally request for account:" << aAccountId);2130 LOG_DEBUG("Received isSyncedExternally request for account:" << aAccountId);
20752131
=== modified file 'msyncd/synchronizer.h'
--- msyncd/synchronizer.h 2015-03-06 13:13:09 +0000
+++ msyncd/synchronizer.h 2015-09-30 18:13:56 +0000
@@ -44,7 +44,9 @@
44#include <QMap>44#include <QMap>
45#include <QString>45#include <QString>
46#include <QDBusInterface>46#include <QDBusInterface>
47#include <QScopedPointer>
4748
49struct _GSettings;
4850
49namespace Buteo {51namespace Buteo {
5052
@@ -137,6 +139,9 @@
137 //! \see SyncDBusInterface::saveSyncResults139 //! \see SyncDBusInterface::saveSyncResults
138 virtual bool saveSyncResults(QString aProfileId,QString aSyncResults);140 virtual bool saveSyncResults(QString aProfileId,QString aSyncResults);
139141
142 //! \see SyncDBusInterface::createSyncProfileForAccount
143 virtual QString createSyncProfileForAccount(uint aAccountId);
144
140 /*! \brief To get lastSyncResult.145 /*! \brief To get lastSyncResult.
141 * \param aProfileId146 * \param aProfileId
142 * \return QString of syncResult.147 * \return QString of syncResult.
@@ -257,9 +262,7 @@
257262
258 void onNewSession(const QString &aDestination);263 void onNewSession(const QString &aDestination);
259264
260 void slotNetworkSessionOpened();265 void slotProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
261
262 void slotNetworkSessionError();
263266
264 /*! \brief Starts a server plug-in267 /*! \brief Starts a server plug-in
265 *268 *
@@ -273,7 +276,7 @@
273 */276 */
274 void stopServer(const QString &aProfileName);277 void stopServer(const QString &aProfileName);
275278
276 void onNetworkStateChanged(bool aState);279 void onNetworkStateChanged(bool aState, Sync::InternetConnectionType type);
277280
278 /*! \brief call this to request the sync daemon to enable soc281 /*! \brief call this to request the sync daemon to enable soc
279 * for a profile. The sync daemon decides as of now for which storages282 * for a profile. The sync daemon decides as of now for which storages
@@ -385,6 +388,12 @@
385 */388 */
386 void removeExternalSyncStatus(const SyncProfile *aProfile);389 void removeExternalSyncStatus(const SyncProfile *aProfile);
387390
391 /*! \brief Check if sheduled sync is allowed for this type of connection.
392 *
393 * @param aType the connection type;
394 */
395 bool acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const;
396
388 QMap<QString, SyncSession*> iActiveSessions;397 QMap<QString, SyncSession*> iActiveSessions;
389398
390 QMap<QString, bool> iExternalSyncProfileStatus;399 QMap<QString, bool> iExternalSyncProfileStatus;
@@ -446,6 +455,7 @@
446#endif455#endif
447456
448 QDBusInterface *iSyncUIInterface;457 QDBusInterface *iSyncUIInterface;
458 _GSettings *iSettings;
449};459};
450460
451}461}
452462
=== modified file 'unittests/tests/msyncdtests/TransportTrackerTest.cpp'
--- unittests/tests/msyncdtests/TransportTrackerTest.cpp 2014-06-19 06:03:36 +0000
+++ unittests/tests/msyncdtests/TransportTrackerTest.cpp 2015-09-30 18:13:56 +0000
@@ -89,7 +89,7 @@
89{89{
90 qRegisterMetaType<Sync::ConnectivityType>("Sync::ConnectivityType");90 qRegisterMetaType<Sync::ConnectivityType>("Sync::ConnectivityType");
91 QSignalSpy connectivityStateSpy(iTransportTracker, SIGNAL(connectivityStateChanged(Sync::ConnectivityType, bool)));91 QSignalSpy connectivityStateSpy(iTransportTracker, SIGNAL(connectivityStateChanged(Sync::ConnectivityType, bool)));
92 QSignalSpy networkStateSpy(iTransportTracker, SIGNAL(networkStateChanged(bool)));92 QSignalSpy networkStateSpy(iTransportTracker, SIGNAL(networkStateChanged(bool,Sync::InternetConnectionType)));
9393
94 // change USB state and verify94 // change USB state and verify
95 bool usbCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_USB);95 bool usbCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_USB);
@@ -115,7 +115,7 @@
115115
116 // change internet state and verify116 // change internet state and verify
117 bool internetCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET);117 bool internetCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET);
118 iTransportTracker->onInternetStateChanged(!internetCurrentState);118 iTransportTracker->onInternetStateChanged(!internetCurrentState, Sync::INTERNET_CONNECTION_UNKNOWN);
119 QCOMPARE(iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET), !internetCurrentState);119 QCOMPARE(iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET), !internetCurrentState);
120 QEXPECT_FAIL("", "IMO connectivityStateChanged() should be emitted also for CONNECTIVITY_INTERNET", Continue);120 QEXPECT_FAIL("", "IMO connectivityStateChanged() should be emitted also for CONNECTIVITY_INTERNET", Continue);
121 QCOMPARE(connectivityStateSpy.count(), 1);121 QCOMPARE(connectivityStateSpy.count(), 1);

Subscribers

People subscribed via source and target branches