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
1=== added file 'debian/patches/0001-Check-for-WLAN-or-ETHERNET-connections.patch'
2--- debian/patches/0001-Check-for-WLAN-or-ETHERNET-connections.patch 1970-01-01 00:00:00 +0000
3+++ debian/patches/0001-Check-for-WLAN-or-ETHERNET-connections.patch 2015-09-30 18:13:56 +0000
4@@ -0,0 +1,47 @@
5+From 161e8b4ad64be49822630b601c87fa97ce030de1 Mon Sep 17 00:00:00 2001
6+From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
7+Date: Tue, 22 Sep 2015 12:41:16 -0300
8+Subject: [PATCH] Check for WLAN or ETHERNET connections.
9+
10+Check for specific WLAN or ETHERNET connection to avoid problems with
11+Unknown types.
12+---
13+ libbuteosyncfw/common/NetworkManager.cpp | 11 ++++++-----
14+ 1 file changed, 6 insertions(+), 5 deletions(-)
15+
16+diff --git a/libbuteosyncfw/common/NetworkManager.cpp b/libbuteosyncfw/common/NetworkManager.cpp
17+index 811694c..418105a 100644
18+--- a/libbuteosyncfw/common/NetworkManager.cpp
19++++ b/libbuteosyncfw/common/NetworkManager.cpp
20+@@ -1,4 +1,4 @@
21+-/*
22++/*
23+ * This file is part of buteo-syncfw package
24+ *
25+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
26+@@ -167,17 +167,18 @@ void NetworkManager::idleRefresh()
27+ {
28+ // FIXME: due this bug lp:#1444162 on nm the QNetworkConfigurationManager
29+ // returns the wrong default connection.
30+- // We will consider the connection with the smallest bearer as the
31+- // default connection, with that wifi and ethernet will be the first one
32+- // https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1444162
33++ // We will consider the first active connection as default connection
34++ // unless that there is a WLAN or Ethernet connection active
35+ connectionType = activeConfigs.first().bearerType();
36+ bearerTypeName = activeConfigs.first().bearerTypeName();
37+ foreach(const QNetworkConfiguration &conf, activeConfigs)
38+ {
39+- if (conf.bearerType() < connectionType)
40++ if ((conf.bearerType() == QNetworkConfiguration::BearerWLAN) ||
41++ (conf.bearerType() == QNetworkConfiguration::BearerEthernet))
42+ {
43+ connectionType = conf.bearerType();
44+ bearerTypeName = conf.bearerTypeName();
45++ break;
46+ }
47+ }
48+ }
49+--
50+2.1.4
51+
52
53=== added file 'debian/patches/0001-Disable-sheduled-syncs-over-cellular-connections.patch'
54--- debian/patches/0001-Disable-sheduled-syncs-over-cellular-connections.patch 1970-01-01 00:00:00 +0000
55+++ debian/patches/0001-Disable-sheduled-syncs-over-cellular-connections.patch 2015-09-30 18:13:56 +0000
56@@ -0,0 +1,25 @@
57+From b8ebc30e204c977f5f25d6176d5a82be3e399c4a Mon Sep 17 00:00:00 2001
58+From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
59+Date: Tue, 15 Sep 2015 10:18:05 -0300
60+Subject: [PATCH 1/3] Disable sheduled syncs over cellular connections.
61+
62+---
63+ msyncd/gschemas/com.meego.msyncd.gschema.xml | 2 +-
64+ 1 file changed, 1 insertion(+), 1 deletion(-)
65+
66+diff --git a/msyncd/gschemas/com.meego.msyncd.gschema.xml b/msyncd/gschemas/com.meego.msyncd.gschema.xml
67+index 4e410d5..f5b90fb 100644
68+--- a/msyncd/gschemas/com.meego.msyncd.gschema.xml
69++++ b/msyncd/gschemas/com.meego.msyncd.gschema.xml
70+@@ -4,7 +4,7 @@
71+ <key name="allow-scheduled-sync-over-cellular" type="b">
72+ <summary>Scheduled Sync over cellular</summary>
73+ <description>Allow scheduled syncs to run over cellular connections.</description>
74+- <default>true</default>
75++ <default>false</default>
76+ </key>
77+ </schema>
78+ </schemalist>
79+--
80+2.1.4
81+
82
83=== removed file 'debian/patches/0001-Ubuntu-phone-changes.patch'
84--- debian/patches/0001-Ubuntu-phone-changes.patch 2015-09-11 14:15:49 +0000
85+++ debian/patches/0001-Ubuntu-phone-changes.patch 1970-01-01 00:00:00 +0000
86@@ -1,1544 +0,0 @@
87-From 090b3f497a52d9bdf891bdac418705f5adb18e1c Mon Sep 17 00:00:00 2001
88-From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
89-Date: Fri, 3 Jul 2015 13:59:00 -0300
90-Subject: [PATCH] Fire 'enableSOC' for accounts already created.
91-
92-Make sure the the signal 'enableSOC' is fired even for accounts that already exists.
93-Fire 'AccountsHelper' signals on idle after the constructor, to allow connections after create object.
94-
95-Save profile before fire 'signalProfileChanged'.
96-
97-The profile should be saved before fire the signal 'signalProfileChanged', otherwise the receiver that retrieve the profile will have a old version of it.
98-
99-Start a sync just after create a new profile.
100-
101-After create a online-account we want that account to get sync.
102-
103-Wait untill network connection is available to sync.
104-
105-Wait for internet connection before sync scheduled sync requests.
106-
107-Does not run scheduled sync over mobile data connection.
108-
109-Check for internet connection type before run a scheduled sync.
110-
111-Added upstart service file.
112-
113-Create upstart file to start msyncd service.
114-
115-Avoid sync twice.
116-
117-Remove pending syncs from 'iWaitingOnlineSyncs' and 'iSyncOnChangeScheduler', before run a sync to avoid sync twice.
118-
119-Fixed compilation warnings.
120-
121-Create a gschema to store system-wide configuration.
122-
123-Check for '/com/meego/msyncd/allow-scheduled-sync-over-gsm' settings to confirm if sync over gsm is enabled for scheduled syncs.
124-
125-Add new profiles into the Sync On Change list.
126-
127-Profiles created while the server is running should be added to Sync On Change list.
128-
129-Fixed AccountsHelper 'scheduleUpdated' emission.
130-
131-Make sure that the signal get fired for the correct profile.
132-
133-Fire a new sync if profile data changes.
134-
135-Fixed profile creation for new accounts.
136-
137-Set the new profile enabled only if account and service are enabled.
138-
139-Fix 'lastSuccessfulSyncTime' function.
140-
141-Fixed an use case where the sync log only contains one failed sync.
142-
143-Expose "createProfileForAccount" in the DBUS service.
144-
145-Allow the client to create a profile for a specified account it it does not exists
146----
147- libbuteosyncfw/common/Logger.cpp | 4 +-
148- libbuteosyncfw/common/NetworkManager.cpp | 96 +++++++++---
149- libbuteosyncfw/common/NetworkManager.h | 18 ++-
150- libbuteosyncfw/common/SyncCommonDefs.h | 17 +++
151- libbuteosyncfw/common/TransportTracker.cpp | 24 +--
152- libbuteosyncfw/common/TransportTracker.h | 7 +-
153- libbuteosyncfw/profile/ProfileManager.cpp | 14 +-
154- libbuteosyncfw/profile/SyncProfile.cpp | 13 +-
155- msyncd/AccountsHelper.cpp | 66 +++++---
156- msyncd/AccountsHelper.h | 59 ++++---
157- msyncd/SyncDBusAdaptor.cpp | 8 +
158- msyncd/SyncDBusAdaptor.h | 5 +
159- msyncd/SyncDBusInterface.h | 37 +++--
160- msyncd/SyncOnChangeScheduler.cpp | 9 ++
161- msyncd/SyncOnChangeScheduler.h | 3 +-
162- msyncd/SyncSession.h | 2 +-
163- msyncd/bin/msyncd.conf | 15 ++
164- msyncd/gschemas/com.meego.msyncd.gschema.xml | 10 ++
165- msyncd/msyncd-app.pro | 8 +-
166- msyncd/msyncd-lib.pro | 2 +-
167- msyncd/synchronizer.cpp | 169 ++++++++++++++-------
168- msyncd/synchronizer.h | 18 ++-
169- .../tests/msyncdtests/TransportTrackerTest.cpp | 4 +-
170- 23 files changed, 427 insertions(+), 181 deletions(-)
171- create mode 100644 msyncd/bin/msyncd.conf
172- create mode 100644 msyncd/gschemas/com.meego.msyncd.gschema.xml
173-
174-diff --git a/libbuteosyncfw/common/Logger.cpp b/libbuteosyncfw/common/Logger.cpp
175-index c6468bd..557b725 100644
176---- a/libbuteosyncfw/common/Logger.cpp
177-+++ b/libbuteosyncfw/common/Logger.cpp
178-@@ -206,7 +206,7 @@ void Logger::write(int aLevel, const char *aMsg)
179- {
180- if(aLevel >= QtCriticalMsg)
181- {
182-- syslog(LOG_CRIT, sysLogMsg.toLocal8Bit().data());
183-+ syslog(LOG_CRIT, "%s", sysLogMsg.toLocal8Bit().data());
184- }
185- return;
186- }
187-@@ -217,7 +217,7 @@ void Logger::write(int aLevel, const char *aMsg)
188- return;
189- }
190-
191-- syslog(syslogLevel[aLevel], sysLogMsg.toLocal8Bit().data());
192-+ syslog(syslogLevel[aLevel], "%s", sysLogMsg.toLocal8Bit().data());
193-
194- if (iFileStream != 0)
195- {
196-diff --git a/libbuteosyncfw/common/NetworkManager.cpp b/libbuteosyncfw/common/NetworkManager.cpp
197-index 6e430d4..811694c 100644
198---- a/libbuteosyncfw/common/NetworkManager.cpp
199-+++ b/libbuteosyncfw/common/NetworkManager.cpp
200-@@ -36,13 +36,40 @@ bool NetworkManager::m_isSessionActive = false;
201- NetworkManager::NetworkManager(QObject *parent /* = 0*/) :
202- QObject(parent), m_networkConfigManager(0), m_networkSession(0),
203- m_isOnline(false), m_errorEmitted(false),
204-- m_sessionTimer(0)
205-+ m_sessionTimer(0), m_connectionType(Sync::INTERNET_CONNECTION_UNKNOWN)
206- {
207- FUNCTION_CALL_TRACE;
208- m_networkConfigManager = new QNetworkConfigurationManager();
209- Q_ASSERT(m_networkConfigManager);
210-- connect(m_networkConfigManager, SIGNAL(onlineStateChanged(bool)),
211-- SLOT(slotOnlineStateChanged(bool)));
212-+
213-+ // check for network status and configuration change (switch wifi, ethernet, mobile) a
214-+ connect(m_networkConfigManager,
215-+ SIGNAL(onlineStateChanged(bool)),
216-+ SLOT(slotConfigurationChanged()),
217-+ Qt::QueuedConnection);
218-+ connect(m_networkConfigManager,
219-+ SIGNAL(configurationAdded(QNetworkConfiguration)),
220-+ SLOT(slotConfigurationChanged()),
221-+ Qt::QueuedConnection);
222-+ connect(m_networkConfigManager,
223-+ SIGNAL(configurationChanged(QNetworkConfiguration)),
224-+ SLOT(slotConfigurationChanged()),
225-+ Qt::QueuedConnection);
226-+ connect(m_networkConfigManager,
227-+ SIGNAL(configurationRemoved(QNetworkConfiguration)),
228-+ SLOT(slotConfigurationChanged()),
229-+ Qt::QueuedConnection);
230-+ connect(m_networkConfigManager,
231-+ SIGNAL(updateCompleted()),
232-+ SLOT(slotConfigurationChanged()),
233-+ Qt::QueuedConnection);
234-+
235-+ connect(&m_idleRefreshTimer,
236-+ SIGNAL(timeout()),
237-+ SLOT(idleRefresh()),
238-+ Qt::QueuedConnection);
239-+ m_idleRefreshTimer.setSingleShot(true);
240-+
241- m_isOnline = m_networkConfigManager->isOnline();
242- LOG_DEBUG("Online status::" << m_isOnline);
243- m_sessionTimer = new QTimer(this);
244-@@ -72,6 +99,11 @@ bool NetworkManager::isOnline()
245- return m_isOnline;
246- }
247-
248-+Sync::InternetConnectionType NetworkManager::connectionType() const
249-+{
250-+ return m_connectionType;
251-+}
252-+
253- void NetworkManager::connectSession(bool connectInBackground /* = false*/)
254- {
255- FUNCTION_CALL_TRACE;
256-@@ -110,12 +142,55 @@ void NetworkManager::sessionConnectionTimeout()
257- {
258- if (!m_errorEmitted && m_networkSession) {
259- if (!m_networkSession->isOpen()) {
260-- qWarning() << "No network reply received after 10 seconds, emitting session error.";
261-+ LOG_WARNING("No network reply received after 10 seconds, emitting session error.");
262- slotSessionError(m_networkSession->error());
263- }
264- }
265- }
266-
267-+void NetworkManager::slotConfigurationChanged()
268-+{
269-+ // wait for 3 secs before update connection status
270-+ // this avoid problems with connections that take a while to be stabilished
271-+ m_idleRefreshTimer.start(3000);
272-+}
273-+
274-+void NetworkManager::idleRefresh()
275-+{
276-+ FUNCTION_CALL_TRACE;
277-+ QList<QNetworkConfiguration> activeConfigs = m_networkConfigManager->allConfigurations(QNetworkConfiguration::Active);
278-+ QNetworkConfiguration::BearerType connectionType = QNetworkConfiguration::BearerUnknown;
279-+ QString bearerTypeName;
280-+
281-+ bool isOnline = activeConfigs.size() > 0;
282-+ if (isOnline)
283-+ {
284-+ // FIXME: due this bug lp:#1444162 on nm the QNetworkConfigurationManager
285-+ // returns the wrong default connection.
286-+ // We will consider the connection with the smallest bearer as the
287-+ // default connection, with that wifi and ethernet will be the first one
288-+ // https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1444162
289-+ connectionType = activeConfigs.first().bearerType();
290-+ bearerTypeName = activeConfigs.first().bearerTypeName();
291-+ foreach(const QNetworkConfiguration &conf, activeConfigs)
292-+ {
293-+ if (conf.bearerType() < connectionType)
294-+ {
295-+ connectionType = conf.bearerType();
296-+ bearerTypeName = conf.bearerTypeName();
297-+ }
298-+ }
299-+ }
300-+ LOG_DEBUG("New state:" << isOnline << " New type: " << bearerTypeName << "(" << connectionType << ")");
301-+ if ((isOnline != m_isOnline) ||
302-+ ((Sync::InternetConnectionType)connectionType != m_connectionType))
303-+ {
304-+ m_isOnline = isOnline;
305-+ m_connectionType = (Sync::InternetConnectionType) connectionType;
306-+ emit statusChanged(m_isOnline, m_connectionType);
307-+ }
308-+}
309-+
310- void NetworkManager::disconnectSession()
311- {
312- FUNCTION_CALL_TRACE;
313-@@ -134,19 +209,6 @@ void NetworkManager::disconnectSession()
314- }
315- }
316-
317--void NetworkManager::slotOnlineStateChanged(bool isOnline)
318--{
319-- FUNCTION_CALL_TRACE;
320-- LOG_DEBUG("Online status changed, is online is now::" << isOnline);
321-- if(m_isOnline != isOnline)
322-- {
323-- if (m_sessionTimer->isActive())
324-- m_sessionTimer->stop();
325-- m_isOnline = isOnline;
326-- emit valueChanged(m_isOnline);
327-- }
328--}
329--
330- void NetworkManager::slotSessionState(QNetworkSession::State status)
331- {
332- FUNCTION_CALL_TRACE;
333-diff --git a/libbuteosyncfw/common/NetworkManager.h b/libbuteosyncfw/common/NetworkManager.h
334-index 5a7c696..e375551 100644
335---- a/libbuteosyncfw/common/NetworkManager.h
336-+++ b/libbuteosyncfw/common/NetworkManager.h
337-@@ -24,8 +24,9 @@
338- #define NETWORKMANAGER_H_
339-
340- #include <QNetworkSession>
341-+#include <QTimer>
342-+#include "SyncCommonDefs.h"
343-
344--class QTimer;
345- class QNetworkConfigurationManager;
346-
347- namespace Buteo
348-@@ -61,6 +62,13 @@ namespace Buteo
349- */
350- bool isOnline();
351-
352-+ /*! \brief Returns the type of connection used by the device.
353-+ *
354-+
355-+ * @return Sync::InternetConnectionType the type of connection.
356-+ */
357-+ Sync::InternetConnectionType connectionType() const;
358-+
359- /*! \brief Connects a new network session. If a session was already
360- * open, the signal connectionSuccess will be emitted immediately,
361- * else the function will return and the signal connectionSuccess or
362-@@ -84,7 +92,7 @@ signals:
363- *
364- * @param aConnected If true, the device is online
365- */
366-- void valueChanged(bool aConnected);
367-+ void statusChanged(bool aConnected, Sync::InternetConnectionType aType);
368-
369- /*! \brief This signal is emitted when a network session gets
370- * connected
371-@@ -105,11 +113,15 @@ signals:
372- static int m_refCount; // Reference counter for number of open connections
373- bool m_errorEmitted; // Network error emited flag
374- QTimer *m_sessionTimer;
375-+ Sync::InternetConnectionType m_connectionType;
376-+ QTimer m_idleRefreshTimer;
377-+
378- private slots:
379-- void slotOnlineStateChanged(bool isOnline);
380- void slotSessionState(QNetworkSession::State status);
381- void slotSessionError(QNetworkSession::SessionError error);
382- void sessionConnectionTimeout();
383-+ void slotConfigurationChanged();
384-+ void idleRefresh();
385- };
386- }
387-
388-diff --git a/libbuteosyncfw/common/SyncCommonDefs.h b/libbuteosyncfw/common/SyncCommonDefs.h
389-index 495b71c..ab35d26 100644
390---- a/libbuteosyncfw/common/SyncCommonDefs.h
391-+++ b/libbuteosyncfw/common/SyncCommonDefs.h
392-@@ -26,6 +26,7 @@
393-
394- #include <QMetaType>
395- #include <QDir>
396-+#include <QtNetwork/QNetworkConfiguration>
397-
398- namespace Sync {
399-
400-@@ -83,6 +84,22 @@ enum ConnectivityType {
401- CONNECTIVITY_INTERNET
402- };
403-
404-+enum InternetConnectionType {
405-+ INTERNET_CONNECTION_UNKNOWN = QNetworkConfiguration::BearerUnknown,
406-+ INTERNET_CONNECTION_ETHERNET = QNetworkConfiguration::BearerEthernet,
407-+ INTERNET_CONNECTION_WLAN = QNetworkConfiguration::BearerWLAN,
408-+ INTERNET_CONNECTION_2G = QNetworkConfiguration::Bearer2G,
409-+ INTERNET_CONNECTION_3G = QNetworkConfiguration::Bearer3G,
410-+ INTERNET_CONNECTION_4G = QNetworkConfiguration::Bearer4G,
411-+ INTERNET_CONNECTION_CDMA2000 = QNetworkConfiguration::BearerCDMA2000,
412-+ INTERNET_CONNECTION_WCDMA = QNetworkConfiguration::BearerWCDMA,
413-+ INTERNET_CONNECTION_HSPA = QNetworkConfiguration::BearerHSPA,
414-+ INTERNET_CONNECTION_BLUETOOTH = QNetworkConfiguration::BearerBluetooth,
415-+ INTERNET_CONNECTION_WIMAX = QNetworkConfiguration::BearerWiMAX,
416-+ INTERNET_CONNECTION_EVDO = QNetworkConfiguration::BearerEVDO,
417-+ INTERNET_CONNECTION_LTE = QNetworkConfiguration::BearerLTE
418-+};
419-+
420- } // namespace Sync
421-
422- Q_DECLARE_METATYPE( Sync::SyncStatus );
423-diff --git a/libbuteosyncfw/common/TransportTracker.cpp b/libbuteosyncfw/common/TransportTracker.cpp
424-index 7890cf5..0cd5632 100644
425---- a/libbuteosyncfw/common/TransportTracker.cpp
426-+++ b/libbuteosyncfw/common/TransportTracker.cpp
427-@@ -66,7 +66,7 @@ TransportTracker::TransportTracker(QObject *aParent) :
428-
429- // BT
430- #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
431--
432-+
433- // Set the bluetooth state
434- iTransportStates[Sync::CONNECTIVITY_BT] = btConnectivityStatus();
435-
436-@@ -97,8 +97,9 @@ TransportTracker::TransportTracker(QObject *aParent) :
437- {
438- iTransportStates[Sync::CONNECTIVITY_INTERNET] =
439- iInternet->isOnline();
440-- connect(iInternet, SIGNAL(valueChanged(bool)),
441-- this, SLOT(onInternetStateChanged(bool)) /*, Qt::QueuedConnection*/);
442-+ connect(iInternet,
443-+ SIGNAL(statusChanged(bool, Sync::InternetConnectionType)),
444-+ SLOT(onInternetStateChanged(bool, Sync::InternetConnectionType)) /*, Qt::QueuedConnection*/);
445- }
446- else
447- {
448-@@ -143,7 +144,7 @@ void TransportTracker::onBtStateChanged(bool aState)
449- void TransportTracker::onBtStateChanged(QString aKey, QDBusVariant aValue)
450- {
451- FUNCTION_CALL_TRACE;
452--
453-+
454- if (aKey == "Powered")
455- {
456- bool btPowered = aValue.variant().toBool();
457-@@ -153,12 +154,13 @@ void TransportTracker::onBtStateChanged(QString aKey, QDBusVariant aValue)
458- }
459- #endif
460-
461--void TransportTracker::onInternetStateChanged(bool aConnected)
462-+void TransportTracker::onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType)
463- {
464- FUNCTION_CALL_TRACE;
465-
466- LOG_DEBUG("Internet state changed:" << aConnected);
467- updateState(Sync::CONNECTIVITY_INTERNET, aConnected);
468-+ emit networkStateChanged(aConnected, aType);
469- }
470-
471- void TransportTracker::updateState(Sync::ConnectivityType aType,
472-@@ -175,19 +177,17 @@ void TransportTracker::updateState(Sync::ConnectivityType aType,
473- }
474- if(oldState != aState)
475- {
476-- if (aType != Sync::CONNECTIVITY_INTERNET) {
477-+ if (aType != Sync::CONNECTIVITY_INTERNET)
478-+ {
479- emit connectivityStateChanged(aType, aState);
480- }
481-- else {
482-- emit networkStateChanged(aState);
483-- }
484- }
485- }
486-
487- bool TransportTracker::btConnectivityStatus()
488- {
489- FUNCTION_CALL_TRACE;
490--
491-+
492- bool btOn = false;
493- QDBusConnection *systemBus = new QDBusConnection(QDBusConnection::connectToBus(QDBusConnection::SystemBus,
494- QStringLiteral("buteo_system_bus2")));
495-@@ -207,7 +207,7 @@ bool TransportTracker::btConnectivityStatus()
496- QList<QVariant> adapterList = reply.arguments();
497- // We will take the first adapter in the list
498- QString adapterPath = qdbus_cast<QDBusObjectPath>(adapterList.at(0)).path();
499--
500-+
501- if (!adapterPath.isEmpty() || !adapterPath.isNull())
502- {
503- // Retrive the properties of the adapter and check for "Powered" key
504-@@ -222,7 +222,7 @@ bool TransportTracker::btConnectivityStatus()
505- delete systemBus;
506- return btOn;
507- }
508--
509-+
510- QDBusArgument arg = reply.arguments().at(0).value<QDBusArgument>();
511- if (arg.currentType() == QDBusArgument::MapType)
512- {
513-diff --git a/libbuteosyncfw/common/TransportTracker.h b/libbuteosyncfw/common/TransportTracker.h
514-index 67456cf..495ebcb 100644
515---- a/libbuteosyncfw/common/TransportTracker.h
516-+++ b/libbuteosyncfw/common/TransportTracker.h
517-@@ -78,8 +78,9 @@ signals:
518- /*! \brief Signal emitted when a n/w state changes
519- *
520- * @param aState New state. True if available, false if not.
521-+ * @param aType Connection type. The type of connetcion with the Internet.
522- */
523-- void networkStateChanged(bool aState);
524-+ void networkStateChanged(bool aState, Sync::InternetConnectionType aType);
525-
526- /*! \brief Signal emitted when a network session is successfully opened
527- */
528-@@ -99,7 +100,7 @@ private slots:
529- void onBtStateChanged(QString aKey, QDBusVariant aValue);
530- #endif
531-
532-- void onInternetStateChanged(bool aConnected);
533-+ void onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType);
534-
535- private:
536-
537-@@ -127,7 +128,7 @@ private:
538- friend class TransportTrackerTest;
539- friend class SynchronizerTest;
540- #endif
541--
542-+
543- bool btConnectivityStatus();
544-
545- };
546-diff --git a/libbuteosyncfw/profile/ProfileManager.cpp b/libbuteosyncfw/profile/ProfileManager.cpp
547-index f1e4b2a..81406d9 100644
548---- a/libbuteosyncfw/profile/ProfileManager.cpp
549-+++ b/libbuteosyncfw/profile/ProfileManager.cpp
550-@@ -129,7 +129,6 @@ ProfileManagerPrivate::ProfileManagerPrivate(const QString &aPrimaryPath,
551-
552- Profile *ProfileManagerPrivate::load(const QString &aName, const QString &aType)
553- {
554--
555- QString profilePath = findProfileFile(aName, aType);
556- QString backupProfilePath = profilePath + BACKUP_EXT;
557-
558-@@ -739,6 +738,14 @@ QString ProfileManager::updateProfile(const Profile &aProfile)
559- bool exists = d_ptr->profileExists(aProfile.name(),aProfile.type());
560-
561- QString profileId("");
562-+
563-+ // We need to save before emit the signalProfileChanged, if this is the first
564-+ // update the profile will only exists on disk after the save and any operation
565-+ // using this profile triggered by the signal will fail.
566-+ if(d_ptr->save(aProfile)) {
567-+ profileId = aProfile.name();
568-+ }
569-+
570- // Profile did not exist, it was a new one. Add it and emit signal with "added" value:
571- if (!exists) {
572- emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_ADDED,aProfile.toString());
573-@@ -746,9 +753,6 @@ QString ProfileManager::updateProfile(const Profile &aProfile)
574- emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_MODIFIED,aProfile.toString());
575- }
576-
577-- if(d_ptr->save(aProfile)) {
578-- profileId = aProfile.name();
579-- }
580- return profileId;
581- }
582-
583-@@ -1254,7 +1258,7 @@ QDateTime ProfileManager::getNextRetryInterval(const SyncProfile* aProfile)
584- !iSyncRetriesInfo[aProfile->name()].isEmpty())
585- {
586- quint32 mins = iSyncRetriesInfo[aProfile->name()].takeFirst();
587-- nextRetryInterval = QDateTime::currentDateTime().addSecs(mins * 60);
588-+ nextRetryInterval = QDateTime::currentDateTime().addSecs(mins * 60);
589- LOG_DEBUG("syncretries : retry for profile" << aProfile->name() << "in" << mins <<"minutes");
590- LOG_DEBUG("syncretries :" << iSyncRetriesInfo[aProfile->name()].count() <<"attempts remain");
591- }
592-diff --git a/libbuteosyncfw/profile/SyncProfile.cpp b/libbuteosyncfw/profile/SyncProfile.cpp
593-index 564aec5..7cd80d3 100644
594---- a/libbuteosyncfw/profile/SyncProfile.cpp
595-+++ b/libbuteosyncfw/profile/SyncProfile.cpp
596-@@ -259,14 +259,11 @@ QDateTime SyncProfile::lastSuccessfulSyncTime () const
597- if (d_ptr->iLog)
598- {
599- QList<const SyncResults*> allResults = d_ptr->iLog->allResults();
600-- if (allResults.size () > 0)
601-- {
602-- lastSuccessSyncTime = allResults.at (0)->syncTime ();
603-- foreach (const SyncResults* result, allResults) {
604-- if ((result->majorCode () == SyncResults::SYNC_RESULT_SUCCESS) &&
605-- (result->minorCode () == SyncResults::NO_ERROR) &&
606-- (result->syncTime () > lastSuccessSyncTime))
607-- lastSuccessSyncTime = result->syncTime ();
608-+ foreach (const SyncResults* result, allResults) {
609-+ if ((result->majorCode () == SyncResults::SYNC_RESULT_SUCCESS) &&
610-+ (result->minorCode () == SyncResults::NO_ERROR) &&
611-+ (lastSyncTime().isNull() || (result->syncTime () > lastSuccessSyncTime))) {
612-+ lastSuccessSyncTime = result->syncTime ();
613- }
614- }
615- }
616-diff --git a/msyncd/AccountsHelper.cpp b/msyncd/AccountsHelper.cpp
617-index 064d14f..960132c 100644
618---- a/msyncd/AccountsHelper.cpp
619-+++ b/msyncd/AccountsHelper.cpp
620-@@ -26,6 +26,8 @@
621- #include "Profile.h"
622- #include "ProfileEngineDefs.h"
623-
624-+#include <QTimer>
625-+
626- static const QString ACCOUNTS_GLOBAL_SERVICE("global");
627-
628- using namespace Buteo;
629-@@ -36,13 +38,15 @@ AccountsHelper::AccountsHelper(ProfileManager &aProfileManager, QObject *aParent
630- iAccountManager = new Accounts::Manager(this);
631- // Connect to signal for account creation, deletion, and modification
632- QObject::connect(iAccountManager, SIGNAL(accountCreated(Accounts::AccountId)),
633-- this, SLOT(slotAccountCreated(Accounts::AccountId)));
634-+ this, SLOT(createProfileForAccount(Accounts::AccountId)));
635- QObject::connect(iAccountManager, SIGNAL(accountRemoved(Accounts::AccountId)),
636- this, SLOT(slotAccountRemoved(Accounts::AccountId)));
637- QObject::connect(iAccountManager, SIGNAL(accountUpdated(Accounts::AccountId)),
638- this, SLOT(slotAccountUpdated(Accounts::AccountId)));
639-
640-- registerAccountListeners();
641-+ // load accounts after return from contructor, to allow connection with class singals
642-+ // that can be fired by 'registerAccountListeners' function
643-+ QTimer::singleShot(0, this, SLOT(registerAccountListeners()));
644- }
645-
646- AccountsHelper::~AccountsHelper()
647-@@ -54,9 +58,10 @@ AccountsHelper::~AccountsHelper()
648- // their parent, aka, the manager
649- }
650-
651--void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
652-+QString AccountsHelper::createProfileForAccount(Accounts::AccountId id)
653- {
654- FUNCTION_CALL_TRACE;
655-+ QString profileName;
656- Accounts::Account *newAccount = iAccountManager->account(id);
657- bool profileFoundAndCreated = false;
658-
659-@@ -66,7 +71,7 @@ void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
660- Accounts::ServiceList serviceList = newAccount->services();
661- foreach(Accounts::Service service, serviceList)
662- {
663-- // Look for a sync profile that matches the service name
664-+ // Look for a sync profile that matches the service name (template)
665- LOG_DEBUG("Looking for sync profile::" << service.name());
666- SyncProfile *syncProfile = iProfileManager.syncProfile(service.name());
667- LOG_DEBUG("Found profile::" << service.name());
668-@@ -74,7 +79,7 @@ void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
669- (true == syncProfile->boolKey(KEY_USE_ACCOUNTS, false))
670- )
671- {
672-- addAccountIfNotExists(newAccount, service, syncProfile);
673-+ profileName = addAccountIfNotExists(newAccount, service, syncProfile);
674- profileFoundAndCreated = true;
675- }
676- if(0 != syncProfile)
677-@@ -86,7 +91,7 @@ void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
678-
679- if (profileFoundAndCreated == false)
680- {
681-- // Fetch the key "remote_service_name" from the account settings and
682-+ // Fetch the key "remote_service_name" from the account settings and
683- // use it to create a profile
684- QString profileName = newAccount->valueAsString(REMOTE_SERVICE_NAME);
685- LOG_DEBUG("Profile name from account setting:" << profileName);
686-@@ -97,10 +102,15 @@ void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
687- if (syncProfile->boolKey (KEY_USE_ACCOUNTS, false) == true)
688- createProfileForAccount (newAccount, profileName, syncProfile);
689-
690-+ profileName = syncProfile->name();
691- delete syncProfile;
692- }
693- }
694-+ } else {
695-+ LOG_DEBUG("Account not found:" << id);
696- }
697-+
698-+ return profileName;
699- }
700-
701- void AccountsHelper::slotAccountRemoved(Accounts::AccountId id)
702-@@ -186,7 +196,7 @@ void AccountsHelper::slotAccountEnabledChanged(const QString &serviceName, bool
703- foreach(SyncProfile *profile, profiles)
704- {
705- // See if the service name matches
706-- if(serviceName == profile->name())
707-+ if(serviceName == profile->key(REMOTE_SERVICE_NAME))
708- {
709- // Check if the status really changed here
710- // saving the account can trigger the emition of enabledChanged()
711-@@ -331,16 +341,16 @@ void AccountsHelper::createProfileForAccount(Accounts::Account *account,
712- delete newProfile;
713- }
714-
715--void AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
716-- Accounts::Service service,
717-- const SyncProfile *baseProfile)
718-+QString AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
719-+ Accounts::Service service,
720-+ const SyncProfile *baseProfile)
721- {
722- FUNCTION_CALL_TRACE;
723-
724- Profile *serviceProfile = iProfileManager.profile(service.name(), Profile::TYPE_SYNC);
725- if (!serviceProfile) {
726- LOG_DEBUG ("!!!! Service not supported !!!!");
727-- return;
728-+ return QString();
729- }
730-
731- QString profileName ;
732-@@ -367,9 +377,11 @@ void AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
733- // Add the account ID to the profile
734- newProfile->setKey(KEY_ACCOUNT_ID, QString::number(account->id()));
735- // Check if service is enabled
736-- LOG_DEBUG("Service:: " << service.displayName() << "enabled status::" << account->enabled());
737-+ LOG_DEBUG("Service:: " << service.displayName() <<
738-+ "enabled status::" << (account->enabled() && account->enabledServices().contains(service)));
739- // Set profile as enabled
740-- newProfile->setEnabled(account->enabled());
741-+ newProfile->setEnabled(account->enabled() &&
742-+ account->enabledServices().contains(service));
743- setSyncSchedule (newProfile, account->id(), true);
744-
745- // Save the newly created profile
746-@@ -398,6 +410,8 @@ void AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
747- {
748- delete profile;
749- }
750-+
751-+ return profileName;
752- }
753-
754- void AccountsHelper::addSetting(Accounts::AccountId id, QString key, QVariant value) {
755-@@ -448,12 +462,27 @@ void AccountsHelper::slotSchedulerSettingsChanged(const char *aKey)
756- void AccountsHelper::registerAccountListener(Accounts::AccountId id)
757- {
758- FUNCTION_CALL_TRACE;
759-+
760- Accounts::Account *account = iAccountManager->account(id);
761-+ if (iAccountList.contains(account)) {
762-+ return;
763-+ }
764- iAccountList.append(account);
765- // Callback for account enabled/disabled
766-- QObject::connect(account, SIGNAL(enabledChanged(const QString&, bool)),
767-- this, SLOT(slotAccountEnabledChanged(const QString&, bool)));
768--
769-+ QObject::connect(account,
770-+ SIGNAL(enabledChanged(const QString&, bool)),
771-+ SLOT(slotAccountEnabledChanged(const QString&, bool)),
772-+ Qt::UniqueConnection);
773-+
774-+ // Account SyncOnChange
775-+ QList<SyncProfile*> profiles = getProfilesByAccountId(id);
776-+ foreach(SyncProfile *profile, profiles)
777-+ {
778-+ if(profile->isSOCProfile())
779-+ {
780-+ emit enableSOC(profile->name());
781-+ }
782-+ }
783- account->selectService();
784- account->beginGroup("scheduler");
785- LOG_DEBUG("Watching Group :" << account->group());
786-@@ -463,5 +492,8 @@ void AccountsHelper::registerAccountListener(Accounts::AccountId id)
787- return;
788- }
789- iAcctWatchMap[watch] = id;
790-- QObject::connect(watch, SIGNAL(notify(const char *)), this, SLOT(slotSchedulerSettingsChanged(const char *)));
791-+ QObject::connect(watch,
792-+ SIGNAL(notify(const char *)),
793-+ SLOT(slotSchedulerSettingsChanged(const char *)),
794-+ Qt::UniqueConnection);
795- }
796-diff --git a/msyncd/AccountsHelper.h b/msyncd/AccountsHelper.h
797-index 1f9508b..a2f8a9c 100644
798---- a/msyncd/AccountsHelper.h
799-+++ b/msyncd/AccountsHelper.h
800-@@ -29,12 +29,12 @@
801- #include <Accounts/account.h>
802-
803- namespace Buteo {
804--
805-+
806- class Profile;
807- class AccountsHelperTest;
808- class ProfileManager;
809- class SyncProfile;
810--
811-+
812- const QString REMOTE_SERVICE_NAME("remote_service_name");
813-
814- /*! \brief Helper Class towards Accounts::Manager and various SSO related
815-@@ -57,7 +57,7 @@ public:
816- *
817- */
818- virtual ~AccountsHelper();
819--
820-+
821- /*! \brief Returns sync profiles that correspond to a given account ID
822- *
823- * \param id - The account ID.
824-@@ -68,30 +68,31 @@ public:
825-
826- public Q_SLOTS:
827-
828-- /*! \brief slot for Accounts::Manager accountCreated signal
829-- *
830-- * \param id Accounts Id
831-- */
832-- void slotAccountCreated(Accounts::AccountId id);
833-+ /*! \brief This method is used to create a profile for a specified
834-+ * account
835-+ * \param id Accounts Id
836-+ * \return A string with the new profile name
837-+ */
838-+ QString createProfileForAccount(Accounts::AccountId id);
839-
840-- /*! \brief slot for Accounts::Manager accountRemoved signal
841-- *
842-- * \param id of the accounts
843-- */
844-+ /*! \brief slot for Accounts::Manager accountRemoved signal
845-+ *
846-+ * \param id of the accounts
847-+ */
848- void slotAccountRemoved(Accounts::AccountId id);
849-
850-- /*! \brief slot for Accounts::Account enabledChanged signal
851-- *
852-- * \param serviceName The service that was enabled/disabled. Empty if the
853-+ /*! \brief slot for Accounts::Account enabledChanged signal
854-+ *
855-+ * \param serviceName The service that was enabled/disabled. Empty if the
856- * entire account is enabled/disabled
857- * \param enabled Boolean indicating enabled (true) or disabled (false)
858-- */
859-+ */
860- void slotAccountEnabledChanged(const QString &serviceName, bool enabled);
861--
862-- /*! \brief slot for Accounts::Manager displayNameChanged signal
863-- * *
864-- * \param id of the accounts
865-- */
866-+
867-+ /*! \brief slot for Accounts::Manager displayNameChanged signal
868-+ * *
869-+ * \param id of the accounts
870-+ */
871- void slotAccountUpdated(Accounts::AccountId id);
872-
873- void slotSchedulerSettingsChanged(const char *aKey);
874-@@ -102,22 +103,20 @@ Q_SIGNALS:
875- void removeProfile(QString profileId);
876- void removeScheduledSync(const QString& profileId);
877-
878--private:
879-+private Q_SLOTS:
880-
881-- /*!
882-- * \brief This method is used to create a profile for a specified
883-- * account
884-- */
885-+ void registerAccountListeners();
886-+
887-+private:
888- void createProfileForAccount(Accounts::Account* account,
889- const QString profileName,
890- const SyncProfile* baseProfile);
891-
892-- void addAccountIfNotExists(Accounts::Account *account,
893-- Accounts::Service service,
894-- const SyncProfile *baseProfile);
895-+ QString addAccountIfNotExists(Accounts::Account *account,
896-+ Accounts::Service service,
897-+ const SyncProfile *baseProfile);
898-
899- void setSyncSchedule(SyncProfile *syncProfile, Accounts::AccountId id, bool aCreateNew = false);
900-- void registerAccountListeners();
901-
902- void addSetting(Accounts::AccountId id, QString key, QVariant value);
903-
904-diff --git a/msyncd/SyncDBusAdaptor.cpp b/msyncd/SyncDBusAdaptor.cpp
905-index 1b08b49..fd43324 100644
906---- a/msyncd/SyncDBusAdaptor.cpp
907-+++ b/msyncd/SyncDBusAdaptor.cpp
908-@@ -206,3 +206,11 @@ void SyncDBusAdaptor::isSyncedExternally(uint aAccountId, const QString aClientP
909- QMetaObject::invokeMethod(parent(), "isSyncedExternally", Q_ARG(uint, aAccountId), Q_ARG(QString, aClientProfileName));
910- }
911-
912-+QString SyncDBusAdaptor::createSyncProfileForAccount(uint aAccountId)
913-+{
914-+ // handle method call com.meego.msyncd.createSyncProfileForAccount
915-+ QString out0;
916-+ QMetaObject::invokeMethod(parent(), "createSyncProfileForAccount", Q_RETURN_ARG(QString, out0), Q_ARG(uint, aAccountId));
917-+ return out0;
918-+}
919-+
920-diff --git a/msyncd/SyncDBusAdaptor.h b/msyncd/SyncDBusAdaptor.h
921-index 2aaf803..e15f50b 100644
922---- a/msyncd/SyncDBusAdaptor.h
923-+++ b/msyncd/SyncDBusAdaptor.h
924-@@ -157,6 +157,10 @@ class SyncDBusAdaptor: public QDBusAbstractAdaptor
925- " <arg direction=\"out\" type=\"au\"/>\n"
926- " <annotation value=\"QList&lt;uint>\" name=\"com.trolltech.QtDBus.QtTypeName.Out0\"/>\n"
927- " </method>\n"
928-+" <method name=\"createSyncProfileForAccount\">\n"
929-+" <arg direction=\"out\" type=\"s\"/>\n"
930-+" <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"
931-+" </method>\n"
932- " <method name=\"status\">\n"
933- " <arg direction=\"out\" type=\"i\"/>\n"
934- " <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"
935-@@ -198,6 +202,7 @@ public Q_SLOTS: // METHODS
936- QList<uint> syncingAccounts();
937- bool updateProfile(const QString &aProfileAsXml);
938- Q_NOREPLY void isSyncedExternally(uint aAccountId, const QString aClientProfileName);
939-+ QString createSyncProfileForAccount(uint aAccountId);
940- Q_SIGNALS: // SIGNALS
941- void backupDone();
942- void backupInProgress();
943-diff --git a/msyncd/SyncDBusInterface.h b/msyncd/SyncDBusInterface.h
944-index 27b5d21..21c9c0e 100644
945---- a/msyncd/SyncDBusInterface.h
946-+++ b/msyncd/SyncDBusInterface.h
947-@@ -103,29 +103,29 @@ signals:
948- *
949- */
950- void signalProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
951--
952--
953-+
954-+
955- /*! \brief Notifies about Backup start.
956- *
957- * This signal is sent when the backup framework is backing the sync related
958- * data
959- */
960- void backupInProgress ();
961--
962-+
963- /*! \brief Notifies about Backup done.
964- *
965- * This signal is sent when the backup framework has completed backing the sync related
966- * data.
967- */
968- void backupDone();
969--
970-+
971- /*! \brief Notifies about Restore start.
972- *
973- * This signal is sent when the backup framework is restoring the sync related
974- * data
975- */
976- void restoreInProgress();
977--
978-+
979- /*! \brief Notifies about Restore Done.
980- *
981- * This signal is sent when the backup framework has restored the sync related
982-@@ -160,7 +160,7 @@ signals:
983- * \param aNextSyncTime This is an out parameter. The next sync time.
984- */
985- void statusChanged(unsigned int aAccountId, int aNewStatus, int aFailedReason, qlonglong aPrevSyncTime, qlonglong aNextSyncTime);
986--
987-+
988- /*! \brief Returns the connectivity state of a specific medium like
989- * bluetooth, USB or network.
990- * \see SyncCommonDefs::ConnectivityType for arguments
991-@@ -257,16 +257,16 @@ public slots:
992- * \return Profile name list.
993- */
994- virtual QStringList runningSyncs() = 0;
995--
996--
997-+
998-+
999- /*!
1000- * \brief This function returns true if backup/restore in progress else
1001- * false.
1002- */
1003- virtual bool getBackUpRestoreState() = 0;
1004--
1005--
1006-- /*!
1007-+
1008-+
1009-+ /*!
1010- * \brief sets the schedule for a profile
1011- *
1012- * This Function helps in setting a schedule to profile
1013-@@ -312,7 +312,7 @@ public slots:
1014- * \return The sync profile as Xml string.
1015- */
1016- virtual QString syncProfile(const QString &aProfileId) = 0;
1017--
1018-+
1019- /*! \brief Gets a sync profiles matching the key-value.
1020- *
1021- * Loads and merges also all sub-profiles that are referenced from the
1022-@@ -323,7 +323,7 @@ public slots:
1023- * \return The sync profiles as Xml string list.
1024- */
1025- virtual QStringList syncProfilesByKey(const QString &aKey, const QString &aValue) = 0;
1026--
1027-+
1028- /*! \brief Gets a profiles matching the profile type.
1029- *
1030- * \param aType Type of the profile service/storage/sync.
1031-@@ -336,13 +336,13 @@ public slots:
1032- * \param aAccountId The account ID.
1033- */
1034- virtual Q_NOREPLY void start(unsigned int aAccountId) = 0;
1035--
1036-+
1037- /*! \brief Stops sync for all profiles matching the given account ID.
1038- *
1039- * \param aAccountId The account ID.
1040- */
1041- virtual Q_NOREPLY void stop(unsigned int aAccountId) = 0;
1042--
1043-+
1044- /*! \brief Returns the list of account IDs for which sync is ongoing
1045- *
1046- * \return The list of account IDs currectly syncing.
1047-@@ -373,6 +373,13 @@ public slots:
1048- * having several services enabled
1049- */
1050- virtual Q_NOREPLY void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName) = 0;
1051-+
1052-+ /*! \brief Create a sync profile for the account if it does not exists
1053-+ *
1054-+ * \param aAccountId The account ID.
1055-+ * \return The profile name if the profile was created successful or empty if it fails
1056-+ */
1057-+ virtual QString createSyncProfileForAccount(uint aAccountId) = 0;
1058- };
1059-
1060- }
1061-diff --git a/msyncd/SyncOnChangeScheduler.cpp b/msyncd/SyncOnChangeScheduler.cpp
1062-index b7f5b75..389618d 100644
1063---- a/msyncd/SyncOnChangeScheduler.cpp
1064-+++ b/msyncd/SyncOnChangeScheduler.cpp
1065-@@ -14,6 +14,11 @@ SyncOnChangeScheduler::SyncOnChangeScheduler()
1066- SyncOnChangeScheduler::~SyncOnChangeScheduler()
1067- {
1068- FUNCTION_CALL_TRACE;
1069-+ foreach(QObject *o, iSOCTimers.values()) {
1070-+ delete o;
1071-+ }
1072-+ iSOCTimers.clear();
1073-+ iSOCProfileNames.clear();
1074- }
1075-
1076- bool SyncOnChangeScheduler::addProfile(const SyncProfile* aProfile)
1077-@@ -30,6 +35,7 @@ bool SyncOnChangeScheduler::addProfile(const SyncProfile* aProfile)
1078- Qt::QueuedConnection);
1079- SOCtimer->fire();
1080- scheduled = true;
1081-+ iSOCTimers.insert(aProfile->name(), SOCtimer);
1082- LOG_DEBUG("Sync on change scheduled for profile"<< aProfile->name());
1083- }
1084- else if(aProfile)
1085-@@ -43,12 +49,15 @@ void SyncOnChangeScheduler::removeProfile(const QString &aProfileName)
1086- {
1087- FUNCTION_CALL_TRACE;
1088- iSOCProfileNames.removeAll(aProfileName);
1089-+ // cancel timer
1090-+ delete iSOCTimers.take(aProfileName);
1091- }
1092-
1093- void SyncOnChangeScheduler::sync(const SyncProfile* aProfile)
1094- {
1095- FUNCTION_CALL_TRACE;
1096- iSOCProfileNames.removeAll(aProfile->name());
1097-+ iSOCTimers.remove(aProfile->name());
1098- SyncOnChangeTimer *SOCtimer = qobject_cast<SyncOnChangeTimer*>(sender());
1099- if(SOCtimer)
1100- {
1101-diff --git a/msyncd/SyncOnChangeScheduler.h b/msyncd/SyncOnChangeScheduler.h
1102-index 14168bf..aac2241 100644
1103---- a/msyncd/SyncOnChangeScheduler.h
1104-+++ b/msyncd/SyncOnChangeScheduler.h
1105-@@ -40,7 +40,7 @@ public:
1106- *
1107- * Once the SOC is initiated (by sending a syncNow signal), the profile is
1108- * removed automatically
1109-- *
1110-+ *
1111- * @param aProfile pointer to sync profile
1112- * @return true if SOC could be scheduled, false otherwise
1113- */
1114-@@ -63,6 +63,7 @@ private Q_SLOTS:
1115-
1116- private:
1117- QStringList iSOCProfileNames;
1118-+ QMap<QString, QObject*> iSOCTimers;
1119- };
1120-
1121- class SyncOnChangeTimer : public QObject
1122-diff --git a/msyncd/SyncSession.h b/msyncd/SyncSession.h
1123-index 401692c..4a3cde7 100644
1124---- a/msyncd/SyncSession.h
1125-+++ b/msyncd/SyncSession.h
1126-@@ -182,7 +182,7 @@ public:
1127- void setProfileCreated(bool aProfileCreated);
1128-
1129- //! \brief Maps sync failure error code from stack to SyncStatus
1130-- Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
1131-+ Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
1132-
1133- signals:
1134-
1135-diff --git a/msyncd/bin/msyncd.conf b/msyncd/bin/msyncd.conf
1136-new file mode 100644
1137-index 0000000..d383006
1138---- /dev/null
1139-+++ b/msyncd/bin/msyncd.conf
1140-@@ -0,0 +1,15 @@
1141-+description "address-book-service"
1142-+author "Bill Filler <bill.filler@canonical.com>"
1143-+
1144-+start on started unity8-dash
1145-+stop on runlevel [06]
1146-+
1147-+# give some time to nm be ready
1148-+pre-start script
1149-+ sleep 10;
1150-+end script
1151-+
1152-+respawn
1153-+
1154-+env MSYNCD_LOGGING_LEVEL=10
1155-+exec /usr/bin/msyncd
1156-diff --git a/msyncd/gschemas/com.meego.msyncd.gschema.xml b/msyncd/gschemas/com.meego.msyncd.gschema.xml
1157-new file mode 100644
1158-index 0000000..4e410d5
1159---- /dev/null
1160-+++ b/msyncd/gschemas/com.meego.msyncd.gschema.xml
1161-@@ -0,0 +1,10 @@
1162-+<?xml version="1.0" encoding="UTF-8"?>
1163-+<schemalist>
1164-+ <schema id="com.meego.msyncd" path="/com/meego/msyncd/">
1165-+ <key name="allow-scheduled-sync-over-cellular" type="b">
1166-+ <summary>Scheduled Sync over cellular</summary>
1167-+ <description>Allow scheduled syncs to run over cellular connections.</description>
1168-+ <default>true</default>
1169-+ </key>
1170-+ </schema>
1171-+</schemalist>
1172-diff --git a/msyncd/msyncd-app.pro b/msyncd/msyncd-app.pro
1173-index 1d5d338..5dd614e 100644
1174---- a/msyncd/msyncd-app.pro
1175-+++ b/msyncd/msyncd-app.pro
1176-@@ -59,13 +59,19 @@ target.path = /usr/bin/
1177- loglevel.files = bin/set_sync_log_level
1178- loglevel.path = /etc/buteo/
1179- service.files = bin/msyncd.service
1180-+upstart.files = bin/msyncd.conf
1181- service.path = /usr/lib/systemd/user/
1182-+upstart.path = /usr/share/upstart/sessions/
1183- syncwidget.path = /etc/syncwidget/
1184- syncwidget.files = com.meego.msyncd
1185-+gschemas.path = /usr/share/glib-2.0/schemas
1186-+gschemas.files = gschemas/com.meego.msyncd.gschema.xml
1187- INSTALLS += target \
1188- loglevel \
1189- syncwidget \
1190-- service
1191-+ service \
1192-+ upstart \
1193-+ gschemas
1194-
1195- # #####################################################################
1196- # make coverage (debug)
1197-diff --git a/msyncd/msyncd-lib.pro b/msyncd/msyncd-lib.pro
1198-index 12a398c..ff7043e 100644
1199---- a/msyncd/msyncd-lib.pro
1200-+++ b/msyncd/msyncd-lib.pro
1201-@@ -19,7 +19,7 @@ INCLUDEPATH += . \
1202- ../libbuteosyncfw/profile
1203-
1204-
1205--PKGCONFIG += dbus-1
1206-+PKGCONFIG += dbus-1 gio-2.0
1207-
1208- equals(QT_MAJOR_VERSION, 4): {
1209- PKGCONFIG += libsignon-qt accounts-qt
1210-diff --git a/msyncd/synchronizer.cpp b/msyncd/synchronizer.cpp
1211-index b516ccd..6fccca6 100644
1212---- a/msyncd/synchronizer.cpp
1213-+++ b/msyncd/synchronizer.cpp
1214-@@ -1,4 +1,4 @@
1215--/*
1216-+/*
1217- * This file is part of buteo-syncfw package
1218- *
1219- * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
1220-@@ -21,6 +21,7 @@
1221- * 02110-1301 USA
1222- *
1223- */
1224-+#include <gio/gio.h>
1225- #include "synchronizer.h"
1226- #include "SyncDBusAdaptor.h"
1227- #include "SyncSession.h"
1228-@@ -51,11 +52,11 @@
1229- #include <fcntl.h>
1230- #include <termios.h>
1231-
1232-+
1233- using namespace Buteo;
1234-
1235- static const QString SYNC_DBUS_OBJECT = "/synchronizer";
1236- static const QString SYNC_DBUS_SERVICE = "com.meego.msyncd";
1237--
1238- static const QString BT_PROPERTIES_NAME = "Name";
1239-
1240- // Maximum time in milliseconds to wait for a thread to stop
1241-@@ -71,10 +72,9 @@ Synchronizer::Synchronizer( QCoreApplication* aApplication )
1242- iClosing(false),
1243- iSOCEnabled(false),
1244- iSyncUIInterface(NULL)
1245--
1246- {
1247-+ iSettings = g_settings_new_with_path("com.meego.msyncd", "/com/meego/msyncd/");
1248- FUNCTION_CALL_TRACE;
1249--
1250- this->setParent(aApplication);
1251- }
1252-
1253-@@ -86,6 +86,7 @@ Synchronizer::~Synchronizer()
1254- delete iSyncUIInterface;
1255- iSyncUIInterface = NULL;
1256- }
1257-+ g_object_unref(iSettings);
1258- }
1259-
1260- bool Synchronizer::initialize()
1261-@@ -115,8 +116,9 @@ bool Synchronizer::initialize()
1262- this, SLOT(slotSyncStatus(QString, int, QString, int)),
1263- Qt::QueuedConnection);
1264-
1265-+ // use queued connection because the profile will be stored after the signal
1266- connect(&iProfileManager ,SIGNAL(signalProfileChanged(QString,int,QString)),
1267-- this, SIGNAL(signalProfileChanged(QString,int,QString)));
1268-+ this, SLOT(slotProfileChanged(QString,int,QString)), Qt::QueuedConnection);
1269-
1270- iNetworkManager = new NetworkManager(this);
1271- Q_ASSERT(iNetworkManager);
1272-@@ -127,8 +129,9 @@ bool Synchronizer::initialize()
1273- {
1274- iServerActivator = new ServerActivator(iProfileManager,
1275- *iTransportTracker, this);
1276-- connect(iTransportTracker, SIGNAL(networkStateChanged(bool)),
1277-- this, SLOT(onNetworkStateChanged(bool)));
1278-+ connect(iTransportTracker,
1279-+ SIGNAL(networkStateChanged(bool,Sync::InternetConnectionType)),
1280-+ SLOT(onNetworkStateChanged(bool,Sync::InternetConnectionType)));
1281- }
1282-
1283- // Initialize account manager.
1284-@@ -184,7 +187,7 @@ bool Synchronizer::initialize()
1285- else
1286- {
1287- QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(QString)),
1288-- this, SLOT(startSync(QString)),
1289-+ this, SLOT(startScheduledSync(QString)),
1290- Qt::QueuedConnection);
1291- iSOCEnabled = true;
1292- }
1293-@@ -200,7 +203,7 @@ void Synchronizer::enableSOCSlot(const QString& aProfileName)
1294- {
1295- FUNCTION_CALL_TRACE;
1296- SyncProfile* profile = iProfileManager.syncProfile(aProfileName);
1297-- if(!iSOCEnabled)
1298-+ if(profile->isSOCProfile() && !iSOCEnabled)
1299- {
1300- QHash<QString,QList<SyncProfile*> > aSOCStorageMap;
1301- QList<SyncProfile*> SOCProfiles;
1302-@@ -217,13 +220,13 @@ void Synchronizer::enableSOCSlot(const QString& aProfileName)
1303- else
1304- {
1305- QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(const QString&)),
1306-- this, SLOT(startSync(const QString&)),
1307-+ this, SLOT(startScheduledSync(const QString&)),
1308- Qt::QueuedConnection);
1309- iSOCEnabled = true;
1310- LOG_DEBUG("Sync on change enabled for profile" << aProfileName);
1311- }
1312- }
1313-- else
1314-+ else if (profile->isSOCProfile())
1315- {
1316- iSyncOnChange.addProfile("hcontacts", profile);
1317- }
1318-@@ -291,55 +294,27 @@ bool Synchronizer::startScheduledSync(QString aProfileName)
1319- // All scheduled syncs are online syncs
1320- // Add this to the waiting online syncs and it will be started when we
1321- // receive a session connection status from the NetworkManager
1322-- bool sessionConnected = !iWaitingOnlineSyncs.isEmpty();
1323-- if(!iWaitingOnlineSyncs.contains(aProfileName))
1324-+ bool accept = acceptScheduledSync(iNetworkManager->isOnline(), iNetworkManager->connectionType());
1325-+ if(accept)
1326- {
1327-- iWaitingOnlineSyncs.append(aProfileName);
1328-+ startSync(aProfileName, true);
1329- }
1330-- if(!sessionConnected)
1331-+ else if (!iWaitingOnlineSyncs.contains(aProfileName))
1332- {
1333-- QObject::connect(iNetworkManager, SIGNAL(connectionSuccess()), this,
1334-- SLOT(slotNetworkSessionOpened()), Qt::QueuedConnection);
1335-- QObject::connect(iNetworkManager, SIGNAL(connectionError()), this,
1336-- SLOT(slotNetworkSessionError()), Qt::QueuedConnection);
1337-- // Request for a network session
1338-- iNetworkManager->connectSession(true);
1339-+ LOG_DEBUG("Wait for internet connection:" << aProfileName);
1340-+ if (iNetworkManager->isOnline())
1341-+ {
1342-+ LOG_DEBUG("Connection over mobile data plan. The sync will be postponed untill a full connection is available;");
1343-+ }
1344-+ else
1345-+ {
1346-+ LOG_DEBUG("Device offline. Wait for internet connection.");
1347-+ }
1348-+ iWaitingOnlineSyncs.append(aProfileName);
1349- }
1350- return true;
1351- }
1352-
1353--void Synchronizer::slotNetworkSessionOpened()
1354--{
1355-- FUNCTION_CALL_TRACE;
1356-- QObject::disconnect(iNetworkManager, SIGNAL(connectionSuccess()), this,
1357-- SLOT(slotNetworkSessionOpened()));
1358-- QObject::disconnect(iNetworkManager, SIGNAL(connectionError()), this,
1359-- SLOT(slotNetworkSessionError()));
1360-- foreach(QString profileName, iWaitingOnlineSyncs)
1361-- {
1362-- startSync(profileName, true);
1363-- }
1364-- iWaitingOnlineSyncs.clear();
1365--}
1366--
1367--void Synchronizer::slotNetworkSessionError()
1368--{
1369-- FUNCTION_CALL_TRACE;
1370-- QObject::disconnect(iNetworkManager, SIGNAL(connectionSuccess()), this,
1371-- SLOT(slotNetworkSessionOpened()));
1372-- QObject::disconnect(iNetworkManager, SIGNAL(connectionError()), this,
1373-- SLOT(slotNetworkSessionError()));
1374-- // Cancel all open sessions
1375-- foreach(QString profileName, iWaitingOnlineSyncs)
1376-- {
1377-- SyncResults syncResults(QDateTime::currentDateTime(), SyncResults::SYNC_RESULT_FAILED, SyncResults::CONNECTION_ERROR);
1378-- iProfileManager.saveSyncResults(profileName, syncResults);
1379-- reschedule(profileName);
1380-- }
1381-- iWaitingOnlineSyncs.clear();
1382-- iNetworkManager->disconnectSession();
1383--}
1384--
1385- bool Synchronizer::setSyncSchedule(QString aProfileId , QString aScheduleAsXml)
1386- {
1387- bool status = false;
1388-@@ -364,6 +339,11 @@ bool Synchronizer::saveSyncResults(QString aProfileId, QString aSyncResults)
1389- return status;
1390- }
1391-
1392-+QString Synchronizer::createSyncProfileForAccount(uint aAccountId)
1393-+{
1394-+ return iAccounts->createProfileForAccount(aAccountId);
1395-+}
1396-+
1397- bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)
1398- {
1399- FUNCTION_CALL_TRACE;
1400-@@ -378,6 +358,12 @@ bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)
1401-
1402- LOG_DEBUG( "Start sync requested for profile:" << aProfileName );
1403-
1404-+ // This function can be called from a client app as manual sync:
1405-+ // If we receive a manual sync to a profile that is peding to sync due a
1406-+ // data change we can remove it from the iSyncOnChangeScheduler, to avoid a
1407-+ // second sync.
1408-+ iSyncOnChangeScheduler.removeProfile(aProfileName);
1409-+
1410- if (iActiveSessions.contains(aProfileName))
1411- {
1412- LOG_DEBUG( "Sync already in progress" );
1413-@@ -389,6 +375,14 @@ bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)
1414- emit syncStatus(aProfileName, Sync::SYNC_QUEUED, "", 0);
1415- return true;
1416- }
1417-+ else if (!aScheduled && iWaitingOnlineSyncs.contains(aProfileName))
1418-+ {
1419-+ // Manual sync is allowed to happen in any kind of connection
1420-+ // if sync is not scheduled remove it from iWaitingOnlineSyncs to avoid
1421-+ // sync it twice later
1422-+ iWaitingOnlineSyncs.removeOne(aProfileName);
1423-+ LOG_DEBUG("Removing" << aProfileName << "from online waiting list.");
1424-+ }
1425-
1426- SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
1427- if (!profile)
1428-@@ -520,7 +514,7 @@ bool Synchronizer::startSyncNow(SyncSession *aSession)
1429- return false;
1430- }
1431-
1432-- LOG_DEBUG("Disable sync on change");
1433-+ LOG_DEBUG("Disable sync on change:" << iSOCEnabled << profile->isSOCProfile());
1434- //As sync is ongoing, disable sync on change for now, we can query later if
1435- //there are changes.
1436- if(iSOCEnabled)
1437-@@ -754,7 +748,7 @@ bool Synchronizer::startNextSync()
1438- }
1439-
1440- QString profileName = session->profileName();
1441-- LOG_DEBUG( "Trying to start next sync in queue. Profile:" << profileName );
1442-+ LOG_DEBUG( "Trying to start next sync in queue. Profile:" << profileName << session->isScheduled());
1443-
1444- #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
1445- QBatteryInfo iDeviceInfo;
1446-@@ -1516,6 +1510,36 @@ void Synchronizer::onNewSession(const QString &aDestination)
1447- }
1448- }
1449-
1450-+void Synchronizer::slotProfileChanged(QString aProfileName, int aChangeType, QString aProfileAsXml)
1451-+{
1452-+ // start sync when a new profile is added
1453-+ switch (aChangeType)
1454-+ {
1455-+ case ProfileManager::PROFILE_ADDED:
1456-+ enableSOCSlot(aProfileName);
1457-+ startSync(aProfileName);
1458-+ break;
1459-+
1460-+ case ProfileManager::PROFILE_REMOVED:
1461-+ iSyncOnChangeScheduler.removeProfile(aProfileName);
1462-+ iWaitingOnlineSyncs.removeAll(aProfileName);
1463-+ break;
1464-+
1465-+ case ProfileManager::PROFILE_MODIFIED:
1466-+ {
1467-+ // schedule a new sync in case of profile changed;
1468-+ // Example if the profile change from disable -> enable
1469-+ SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
1470-+ if (profile->isEnabled()) {
1471-+ startScheduledSync(aProfileName);
1472-+ }
1473-+ }
1474-+ break;
1475-+ }
1476-+
1477-+ emit signalProfileChanged(aProfileName, aChangeType, aProfileAsXml);
1478-+}
1479-+
1480- void Synchronizer::reschedule(const QString &aProfileName)
1481- {
1482- FUNCTION_CALL_TRACE;
1483-@@ -1903,10 +1927,24 @@ QStringList Synchronizer::syncProfilesByType(const QString &aType)
1484- return iProfileManager.profileNames(aType);
1485- }
1486-
1487--void Synchronizer::onNetworkStateChanged(bool aState)
1488-+void Synchronizer::onNetworkStateChanged(bool aState, Sync::InternetConnectionType type)
1489- {
1490- FUNCTION_CALL_TRACE;
1491-- if(!aState) {
1492-+ LOG_DEBUG("Network state changed: OnLine:" << aState << " connection type:" << type);
1493-+ if (acceptScheduledSync(aState, type))
1494-+ {
1495-+ LOG_DEBUG("Restart sync for profiles that need network");
1496-+ QStringList profiles(iWaitingOnlineSyncs);
1497-+ iWaitingOnlineSyncs.clear();
1498-+ foreach(QString profileName, profiles)
1499-+ {
1500-+ // start sync now, we do not need to call 'startScheduledSync' since that function
1501-+ // only checks for internet connection
1502-+ startSync(profileName, true);
1503-+ }
1504-+ }
1505-+ else if (!aState)
1506-+ {
1507- QList<QString> profiles = iActiveSessions.keys();
1508- foreach(QString profileId, profiles)
1509- {
1510-@@ -1919,8 +1957,8 @@ void Synchronizer::onNetworkStateChanged(bool aState)
1511- delete profile;
1512- profile = NULL;
1513- }
1514-- else {
1515--
1516-+ else
1517-+ {
1518- LOG_DEBUG("No profile found with aProfileId"<<profileId);
1519- }
1520- }
1521-@@ -2069,6 +2107,19 @@ void Synchronizer::removeExternalSyncStatus(const SyncProfile *aProfile)
1522- }
1523- }
1524-
1525-+bool Synchronizer::acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const
1526-+{
1527-+ static QList<Sync::InternetConnectionType> allowedTypes;
1528-+ if (allowedTypes.isEmpty())
1529-+ {
1530-+ allowedTypes << Sync::INTERNET_CONNECTION_WLAN
1531-+ << Sync::INTERNET_CONNECTION_ETHERNET;
1532-+ }
1533-+
1534-+ return (aConnected && (g_settings_get_boolean(iSettings, "allow-scheduled-sync-over-cellular") ||
1535-+ allowedTypes.contains(aType)));
1536-+}
1537-+
1538- void Synchronizer::isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName)
1539- {
1540- LOG_DEBUG("Received isSyncedExternally request for account:" << aAccountId);
1541-diff --git a/msyncd/synchronizer.h b/msyncd/synchronizer.h
1542-index 5564802..8c07eda 100644
1543---- a/msyncd/synchronizer.h
1544-+++ b/msyncd/synchronizer.h
1545-@@ -44,7 +44,9 @@
1546- #include <QMap>
1547- #include <QString>
1548- #include <QDBusInterface>
1549-+#include <QScopedPointer>
1550-
1551-+struct _GSettings;
1552-
1553- namespace Buteo {
1554-
1555-@@ -137,6 +139,9 @@ public slots:
1556- //! \see SyncDBusInterface::saveSyncResults
1557- virtual bool saveSyncResults(QString aProfileId,QString aSyncResults);
1558-
1559-+ //! \see SyncDBusInterface::createSyncProfileForAccount
1560-+ virtual QString createSyncProfileForAccount(uint aAccountId);
1561-+
1562- /*! \brief To get lastSyncResult.
1563- * \param aProfileId
1564- * \return QString of syncResult.
1565-@@ -257,9 +262,7 @@ private slots:
1566-
1567- void onNewSession(const QString &aDestination);
1568-
1569-- void slotNetworkSessionOpened();
1570--
1571-- void slotNetworkSessionError();
1572-+ void slotProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
1573-
1574- /*! \brief Starts a server plug-in
1575- *
1576-@@ -273,7 +276,7 @@ private slots:
1577- */
1578- void stopServer(const QString &aProfileName);
1579-
1580-- void onNetworkStateChanged(bool aState);
1581-+ void onNetworkStateChanged(bool aState, Sync::InternetConnectionType type);
1582-
1583- /*! \brief call this to request the sync daemon to enable soc
1584- * for a profile. The sync daemon decides as of now for which storages
1585-@@ -385,6 +388,12 @@ private:
1586- */
1587- void removeExternalSyncStatus(const SyncProfile *aProfile);
1588-
1589-+ /*! \brief Check if sheduled sync is allowed for this type of connection.
1590-+ *
1591-+ * @param aType the connection type;
1592-+ */
1593-+ bool acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const;
1594-+
1595- QMap<QString, SyncSession*> iActiveSessions;
1596-
1597- QMap<QString, bool> iExternalSyncProfileStatus;
1598-@@ -446,6 +455,7 @@ private:
1599- #endif
1600-
1601- QDBusInterface *iSyncUIInterface;
1602-+ _GSettings *iSettings;
1603- };
1604-
1605- }
1606-diff --git a/unittests/tests/msyncdtests/TransportTrackerTest.cpp b/unittests/tests/msyncdtests/TransportTrackerTest.cpp
1607-index 8cc5309..c69a315 100644
1608---- a/unittests/tests/msyncdtests/TransportTrackerTest.cpp
1609-+++ b/unittests/tests/msyncdtests/TransportTrackerTest.cpp
1610-@@ -89,7 +89,7 @@ void TransportTrackerTest :: testStateChanged()
1611- {
1612- qRegisterMetaType<Sync::ConnectivityType>("Sync::ConnectivityType");
1613- QSignalSpy connectivityStateSpy(iTransportTracker, SIGNAL(connectivityStateChanged(Sync::ConnectivityType, bool)));
1614-- QSignalSpy networkStateSpy(iTransportTracker, SIGNAL(networkStateChanged(bool)));
1615-+ QSignalSpy networkStateSpy(iTransportTracker, SIGNAL(networkStateChanged(bool,Sync::InternetConnectionType)));
1616-
1617- // change USB state and verify
1618- bool usbCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_USB);
1619-@@ -115,7 +115,7 @@ void TransportTrackerTest :: testStateChanged()
1620-
1621- // change internet state and verify
1622- bool internetCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET);
1623-- iTransportTracker->onInternetStateChanged(!internetCurrentState);
1624-+ iTransportTracker->onInternetStateChanged(!internetCurrentState, Sync::INTERNET_CONNECTION_UNKNOWN);
1625- QCOMPARE(iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET), !internetCurrentState);
1626- QEXPECT_FAIL("", "IMO connectivityStateChanged() should be emitted also for CONNECTIVITY_INTERNET", Continue);
1627- QCOMPARE(connectivityStateSpy.count(), 1);
1628---
1629-2.1.4
1630-
1631
1632=== added file 'debian/patches/0002-Fixed-FUNCTION_CALL_TRACE-macro.patch'
1633--- debian/patches/0002-Fixed-FUNCTION_CALL_TRACE-macro.patch 1970-01-01 00:00:00 +0000
1634+++ debian/patches/0002-Fixed-FUNCTION_CALL_TRACE-macro.patch 2015-09-30 18:13:56 +0000
1635@@ -0,0 +1,36 @@
1636+From 512bdd8f480c0790797521884145e3e6d8661254 Mon Sep 17 00:00:00 2001
1637+From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
1638+Date: Mon, 14 Sep 2015 17:38:48 -0300
1639+Subject: [PATCH 2/3] Fixed 'FUNCTION_CALL_TRACE' macro.
1640+
1641+Make sure that the macro print the correct elapsed time during the debug.
1642+---
1643+ libbuteosyncfw/common/LogMacros.h | 5 ++++-
1644+ 1 file changed, 4 insertions(+), 1 deletion(-)
1645+
1646+diff --git a/libbuteosyncfw/common/LogMacros.h b/libbuteosyncfw/common/LogMacros.h
1647+index bac9ef6..90f2c6f 100644
1648+--- a/libbuteosyncfw/common/LogMacros.h
1649++++ b/libbuteosyncfw/common/LogMacros.h
1650+@@ -29,6 +29,7 @@
1651+ #include <QTime>
1652+ #include <QDebug>
1653+ #include <QDateTime>
1654++#include <QScopedPointer>
1655+ #include "Logger.h"
1656+
1657+ //! Helper macro for writing log messages. Avoid using directly.
1658+@@ -52,7 +53,9 @@
1659+ * Creates a trace message to log when the function is entered and exited.
1660+ * Logs also to time spent in the function.
1661+ */
1662+-# define FUNCTION_CALL_TRACE if (Buteo::Logger::instance()->getLogLevel() >= 9) Buteo::LogTimer timerDebugVariable(QString(__PRETTY_FUNCTION__));
1663++# define FUNCTION_CALL_TRACE QScopedPointer<Buteo::LogTimer> timerDebugVariable; \
1664++ if (Buteo::Logger::instance()->getLogLevel() >= 9) \
1665++ timerDebugVariable.reset(new Buteo::LogTimer(QString(__PRETTY_FUNCTION__)));
1666+
1667+ namespace Buteo {
1668+
1669+--
1670+2.1.4
1671+
1672
1673=== added file 'debian/patches/0003-Added-upstart-service-file.patch'
1674--- debian/patches/0003-Added-upstart-service-file.patch 1970-01-01 00:00:00 +0000
1675+++ debian/patches/0003-Added-upstart-service-file.patch 2015-09-30 18:13:56 +0000
1676@@ -0,0 +1,59 @@
1677+From e10289937804ad6d779843753727b661d2e14e43 Mon Sep 17 00:00:00 2001
1678+From: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
1679+Date: Fri, 3 Jul 2015 14:49:13 -0300
1680+Subject: [PATCH 1/2] Added upstart service file.
1681+
1682+Create upstart file to start msyncd service.
1683+---
1684+ msyncd/bin/msyncd.conf | 14 ++++++++++++++
1685+ msyncd/msyncd-app.pro | 5 ++++-
1686+ 2 files changed, 18 insertions(+), 1 deletion(-)
1687+ create mode 100644 msyncd/bin/msyncd.conf
1688+
1689+diff --git a/msyncd/bin/msyncd.conf b/msyncd/bin/msyncd.conf
1690+new file mode 100644
1691+index 0000000..7224f87
1692+--- /dev/null
1693++++ b/msyncd/bin/msyncd.conf
1694+@@ -0,0 +1,14 @@
1695++description "address-book-service"
1696++author "Bill Filler <bill.filler@canonical.com>"
1697++
1698++start on started unity8-dash
1699++stop on runlevel [06]
1700++
1701++# give some time to nm be ready
1702++pre-start script
1703++ sleep 10;
1704++end script
1705++
1706++respawn
1707++
1708++exec /usr/bin/msyncd
1709+diff --git a/msyncd/msyncd-app.pro b/msyncd/msyncd-app.pro
1710+index be59a8c..ca0a53d 100644
1711+--- a/msyncd/msyncd-app.pro
1712++++ b/msyncd/msyncd-app.pro
1713+@@ -59,7 +59,9 @@ target.path = /usr/bin/
1714+ loglevel.files = bin/set_sync_log_level
1715+ loglevel.path = /etc/buteo/
1716+ service.files = bin/msyncd.service
1717++upstart.files = bin/msyncd.conf
1718+ service.path = /usr/lib/systemd/user/
1719++upstart.path = /usr/share/upstart/sessions/
1720+ syncwidget.path = /etc/syncwidget/
1721+ syncwidget.files = com.meego.msyncd
1722+ gschemas.path = /usr/share/glib-2.0/schemas
1723+@@ -68,7 +70,8 @@ INSTALLS += target \
1724+ loglevel \
1725+ syncwidget \
1726+ service \
1727+- gschemas
1728++ gschemas \
1729++ upstart
1730+
1731+ # #####################################################################
1732+ # make coverage (debug)
1733+--
1734+2.1.4
1735+
1736
1737=== modified file 'debian/patches/series'
1738--- debian/patches/series 2015-09-11 14:15:49 +0000
1739+++ debian/patches/series 2015-09-30 18:13:56 +0000
1740@@ -1,2 +1,5 @@
1741-0001-Ubuntu-phone-changes.patch
1742 libdir.patch
1743+0001-Disable-sheduled-syncs-over-cellular-connections.patch
1744+0002-Fixed-FUNCTION_CALL_TRACE-macro.patch
1745+0003-Added-upstart-service-file.patch
1746+0001-Check-for-WLAN-or-ETHERNET-connections.patch
1747
1748=== modified file 'libbuteosyncfw/common/Logger.cpp'
1749--- libbuteosyncfw/common/Logger.cpp 2014-07-22 04:21:03 +0000
1750+++ libbuteosyncfw/common/Logger.cpp 2015-09-30 18:13:56 +0000
1751@@ -206,7 +206,7 @@
1752 {
1753 if(aLevel >= QtCriticalMsg)
1754 {
1755- syslog(LOG_CRIT, sysLogMsg.toLocal8Bit().data());
1756+ syslog(LOG_CRIT, "%s", sysLogMsg.toLocal8Bit().data());
1757 }
1758 return;
1759 }
1760@@ -217,7 +217,7 @@
1761 return;
1762 }
1763
1764- syslog(syslogLevel[aLevel], sysLogMsg.toLocal8Bit().data());
1765+ syslog(syslogLevel[aLevel], "%s", sysLogMsg.toLocal8Bit().data());
1766
1767 if (iFileStream != 0)
1768 {
1769
1770=== modified file 'libbuteosyncfw/common/NetworkManager.cpp'
1771--- libbuteosyncfw/common/NetworkManager.cpp 2014-09-19 13:49:12 +0000
1772+++ libbuteosyncfw/common/NetworkManager.cpp 2015-09-30 18:13:56 +0000
1773@@ -36,13 +36,40 @@
1774 NetworkManager::NetworkManager(QObject *parent /* = 0*/) :
1775 QObject(parent), m_networkConfigManager(0), m_networkSession(0),
1776 m_isOnline(false), m_errorEmitted(false),
1777- m_sessionTimer(0)
1778+ m_sessionTimer(0), m_connectionType(Sync::INTERNET_CONNECTION_UNKNOWN)
1779 {
1780 FUNCTION_CALL_TRACE;
1781 m_networkConfigManager = new QNetworkConfigurationManager();
1782 Q_ASSERT(m_networkConfigManager);
1783- connect(m_networkConfigManager, SIGNAL(onlineStateChanged(bool)),
1784- SLOT(slotOnlineStateChanged(bool)));
1785+
1786+ // check for network status and configuration change (switch wifi, ethernet, mobile) a
1787+ connect(m_networkConfigManager,
1788+ SIGNAL(onlineStateChanged(bool)),
1789+ SLOT(slotConfigurationChanged()),
1790+ Qt::QueuedConnection);
1791+ connect(m_networkConfigManager,
1792+ SIGNAL(configurationAdded(QNetworkConfiguration)),
1793+ SLOT(slotConfigurationChanged()),
1794+ Qt::QueuedConnection);
1795+ connect(m_networkConfigManager,
1796+ SIGNAL(configurationChanged(QNetworkConfiguration)),
1797+ SLOT(slotConfigurationChanged()),
1798+ Qt::QueuedConnection);
1799+ connect(m_networkConfigManager,
1800+ SIGNAL(configurationRemoved(QNetworkConfiguration)),
1801+ SLOT(slotConfigurationChanged()),
1802+ Qt::QueuedConnection);
1803+ connect(m_networkConfigManager,
1804+ SIGNAL(updateCompleted()),
1805+ SLOT(slotConfigurationChanged()),
1806+ Qt::QueuedConnection);
1807+
1808+ connect(&m_idleRefreshTimer,
1809+ SIGNAL(timeout()),
1810+ SLOT(idleRefresh()),
1811+ Qt::QueuedConnection);
1812+ m_idleRefreshTimer.setSingleShot(true);
1813+
1814 m_isOnline = m_networkConfigManager->isOnline();
1815 LOG_DEBUG("Online status::" << m_isOnline);
1816 m_sessionTimer = new QTimer(this);
1817@@ -72,6 +99,11 @@
1818 return m_isOnline;
1819 }
1820
1821+Sync::InternetConnectionType NetworkManager::connectionType() const
1822+{
1823+ return m_connectionType;
1824+}
1825+
1826 void NetworkManager::connectSession(bool connectInBackground /* = false*/)
1827 {
1828 FUNCTION_CALL_TRACE;
1829@@ -110,12 +142,55 @@
1830 {
1831 if (!m_errorEmitted && m_networkSession) {
1832 if (!m_networkSession->isOpen()) {
1833- qWarning() << "No network reply received after 10 seconds, emitting session error.";
1834+ LOG_WARNING("No network reply received after 10 seconds, emitting session error.");
1835 slotSessionError(m_networkSession->error());
1836 }
1837 }
1838 }
1839
1840+void NetworkManager::slotConfigurationChanged()
1841+{
1842+ // wait for 3 secs before update connection status
1843+ // this avoid problems with connections that take a while to be stabilished
1844+ m_idleRefreshTimer.start(3000);
1845+}
1846+
1847+void NetworkManager::idleRefresh()
1848+{
1849+ FUNCTION_CALL_TRACE;
1850+ QList<QNetworkConfiguration> activeConfigs = m_networkConfigManager->allConfigurations(QNetworkConfiguration::Active);
1851+ QNetworkConfiguration::BearerType connectionType = QNetworkConfiguration::BearerUnknown;
1852+ QString bearerTypeName;
1853+
1854+ bool isOnline = activeConfigs.size() > 0;
1855+ if (isOnline)
1856+ {
1857+ // FIXME: due this bug lp:#1444162 on nm the QNetworkConfigurationManager
1858+ // returns the wrong default connection.
1859+ // We will consider the connection with the smallest bearer as the
1860+ // default connection, with that wifi and ethernet will be the first one
1861+ // https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1444162
1862+ connectionType = activeConfigs.first().bearerType();
1863+ bearerTypeName = activeConfigs.first().bearerTypeName();
1864+ foreach(const QNetworkConfiguration &conf, activeConfigs)
1865+ {
1866+ if (conf.bearerType() < connectionType)
1867+ {
1868+ connectionType = conf.bearerType();
1869+ bearerTypeName = conf.bearerTypeName();
1870+ }
1871+ }
1872+ }
1873+ LOG_DEBUG("New state:" << isOnline << " New type: " << bearerTypeName << "(" << connectionType << ")");
1874+ if ((isOnline != m_isOnline) ||
1875+ ((Sync::InternetConnectionType)connectionType != m_connectionType))
1876+ {
1877+ m_isOnline = isOnline;
1878+ m_connectionType = (Sync::InternetConnectionType) connectionType;
1879+ emit statusChanged(m_isOnline, m_connectionType);
1880+ }
1881+}
1882+
1883 void NetworkManager::disconnectSession()
1884 {
1885 FUNCTION_CALL_TRACE;
1886@@ -134,19 +209,6 @@
1887 }
1888 }
1889
1890-void NetworkManager::slotOnlineStateChanged(bool isOnline)
1891-{
1892- FUNCTION_CALL_TRACE;
1893- LOG_DEBUG("Online status changed, is online is now::" << isOnline);
1894- if(m_isOnline != isOnline)
1895- {
1896- if (m_sessionTimer->isActive())
1897- m_sessionTimer->stop();
1898- m_isOnline = isOnline;
1899- emit valueChanged(m_isOnline);
1900- }
1901-}
1902-
1903 void NetworkManager::slotSessionState(QNetworkSession::State status)
1904 {
1905 FUNCTION_CALL_TRACE;
1906
1907=== modified file 'libbuteosyncfw/common/NetworkManager.h'
1908--- libbuteosyncfw/common/NetworkManager.h 2014-05-28 03:22:34 +0000
1909+++ libbuteosyncfw/common/NetworkManager.h 2015-09-30 18:13:56 +0000
1910@@ -24,8 +24,9 @@
1911 #define NETWORKMANAGER_H_
1912
1913 #include <QNetworkSession>
1914+#include <QTimer>
1915+#include "SyncCommonDefs.h"
1916
1917-class QTimer;
1918 class QNetworkConfigurationManager;
1919
1920 namespace Buteo
1921@@ -61,6 +62,13 @@
1922 */
1923 bool isOnline();
1924
1925+ /*! \brief Returns the type of connection used by the device.
1926+ *
1927+
1928+ * @return Sync::InternetConnectionType the type of connection.
1929+ */
1930+ Sync::InternetConnectionType connectionType() const;
1931+
1932 /*! \brief Connects a new network session. If a session was already
1933 * open, the signal connectionSuccess will be emitted immediately,
1934 * else the function will return and the signal connectionSuccess or
1935@@ -84,7 +92,7 @@
1936 *
1937 * @param aConnected If true, the device is online
1938 */
1939- void valueChanged(bool aConnected);
1940+ void statusChanged(bool aConnected, Sync::InternetConnectionType aType);
1941
1942 /*! \brief This signal is emitted when a network session gets
1943 * connected
1944@@ -105,11 +113,15 @@
1945 static int m_refCount; // Reference counter for number of open connections
1946 bool m_errorEmitted; // Network error emited flag
1947 QTimer *m_sessionTimer;
1948+ Sync::InternetConnectionType m_connectionType;
1949+ QTimer m_idleRefreshTimer;
1950+
1951 private slots:
1952- void slotOnlineStateChanged(bool isOnline);
1953 void slotSessionState(QNetworkSession::State status);
1954 void slotSessionError(QNetworkSession::SessionError error);
1955 void sessionConnectionTimeout();
1956+ void slotConfigurationChanged();
1957+ void idleRefresh();
1958 };
1959 }
1960
1961
1962=== modified file 'libbuteosyncfw/common/SyncCommonDefs.h'
1963--- libbuteosyncfw/common/SyncCommonDefs.h 2014-06-06 06:40:13 +0000
1964+++ libbuteosyncfw/common/SyncCommonDefs.h 2015-09-30 18:13:56 +0000
1965@@ -26,6 +26,7 @@
1966
1967 #include <QMetaType>
1968 #include <QDir>
1969+#include <QtNetwork/QNetworkConfiguration>
1970
1971 namespace Sync {
1972
1973@@ -83,6 +84,22 @@
1974 CONNECTIVITY_INTERNET
1975 };
1976
1977+enum InternetConnectionType {
1978+ INTERNET_CONNECTION_UNKNOWN = QNetworkConfiguration::BearerUnknown,
1979+ INTERNET_CONNECTION_ETHERNET = QNetworkConfiguration::BearerEthernet,
1980+ INTERNET_CONNECTION_WLAN = QNetworkConfiguration::BearerWLAN,
1981+ INTERNET_CONNECTION_2G = QNetworkConfiguration::Bearer2G,
1982+ INTERNET_CONNECTION_3G = QNetworkConfiguration::Bearer3G,
1983+ INTERNET_CONNECTION_4G = QNetworkConfiguration::Bearer4G,
1984+ INTERNET_CONNECTION_CDMA2000 = QNetworkConfiguration::BearerCDMA2000,
1985+ INTERNET_CONNECTION_WCDMA = QNetworkConfiguration::BearerWCDMA,
1986+ INTERNET_CONNECTION_HSPA = QNetworkConfiguration::BearerHSPA,
1987+ INTERNET_CONNECTION_BLUETOOTH = QNetworkConfiguration::BearerBluetooth,
1988+ INTERNET_CONNECTION_WIMAX = QNetworkConfiguration::BearerWiMAX,
1989+ INTERNET_CONNECTION_EVDO = QNetworkConfiguration::BearerEVDO,
1990+ INTERNET_CONNECTION_LTE = QNetworkConfiguration::BearerLTE
1991+};
1992+
1993 } // namespace Sync
1994
1995 Q_DECLARE_METATYPE( Sync::SyncStatus );
1996
1997=== modified file 'libbuteosyncfw/common/TransportTracker.cpp'
1998--- libbuteosyncfw/common/TransportTracker.cpp 2014-09-12 11:53:27 +0000
1999+++ libbuteosyncfw/common/TransportTracker.cpp 2015-09-30 18:13:56 +0000
2000@@ -66,7 +66,7 @@
2001
2002 // BT
2003 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
2004-
2005+
2006 // Set the bluetooth state
2007 iTransportStates[Sync::CONNECTIVITY_BT] = btConnectivityStatus();
2008
2009@@ -97,8 +97,9 @@
2010 {
2011 iTransportStates[Sync::CONNECTIVITY_INTERNET] =
2012 iInternet->isOnline();
2013- connect(iInternet, SIGNAL(valueChanged(bool)),
2014- this, SLOT(onInternetStateChanged(bool)) /*, Qt::QueuedConnection*/);
2015+ connect(iInternet,
2016+ SIGNAL(statusChanged(bool, Sync::InternetConnectionType)),
2017+ SLOT(onInternetStateChanged(bool, Sync::InternetConnectionType)) /*, Qt::QueuedConnection*/);
2018 }
2019 else
2020 {
2021@@ -143,7 +144,7 @@
2022 void TransportTracker::onBtStateChanged(QString aKey, QDBusVariant aValue)
2023 {
2024 FUNCTION_CALL_TRACE;
2025-
2026+
2027 if (aKey == "Powered")
2028 {
2029 bool btPowered = aValue.variant().toBool();
2030@@ -153,12 +154,13 @@
2031 }
2032 #endif
2033
2034-void TransportTracker::onInternetStateChanged(bool aConnected)
2035+void TransportTracker::onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType)
2036 {
2037 FUNCTION_CALL_TRACE;
2038
2039 LOG_DEBUG("Internet state changed:" << aConnected);
2040 updateState(Sync::CONNECTIVITY_INTERNET, aConnected);
2041+ emit networkStateChanged(aConnected, aType);
2042 }
2043
2044 void TransportTracker::updateState(Sync::ConnectivityType aType,
2045@@ -175,19 +177,17 @@
2046 }
2047 if(oldState != aState)
2048 {
2049- if (aType != Sync::CONNECTIVITY_INTERNET) {
2050+ if (aType != Sync::CONNECTIVITY_INTERNET)
2051+ {
2052 emit connectivityStateChanged(aType, aState);
2053 }
2054- else {
2055- emit networkStateChanged(aState);
2056- }
2057 }
2058 }
2059
2060 bool TransportTracker::btConnectivityStatus()
2061 {
2062 FUNCTION_CALL_TRACE;
2063-
2064+
2065 bool btOn = false;
2066 QDBusConnection *systemBus = new QDBusConnection(QDBusConnection::connectToBus(QDBusConnection::SystemBus,
2067 QStringLiteral("buteo_system_bus2")));
2068@@ -207,7 +207,7 @@
2069 QList<QVariant> adapterList = reply.arguments();
2070 // We will take the first adapter in the list
2071 QString adapterPath = qdbus_cast<QDBusObjectPath>(adapterList.at(0)).path();
2072-
2073+
2074 if (!adapterPath.isEmpty() || !adapterPath.isNull())
2075 {
2076 // Retrive the properties of the adapter and check for "Powered" key
2077@@ -222,7 +222,7 @@
2078 delete systemBus;
2079 return btOn;
2080 }
2081-
2082+
2083 QDBusArgument arg = reply.arguments().at(0).value<QDBusArgument>();
2084 if (arg.currentType() == QDBusArgument::MapType)
2085 {
2086
2087=== modified file 'libbuteosyncfw/common/TransportTracker.h'
2088--- libbuteosyncfw/common/TransportTracker.h 2014-09-12 11:53:27 +0000
2089+++ libbuteosyncfw/common/TransportTracker.h 2015-09-30 18:13:56 +0000
2090@@ -78,8 +78,9 @@
2091 /*! \brief Signal emitted when a n/w state changes
2092 *
2093 * @param aState New state. True if available, false if not.
2094+ * @param aType Connection type. The type of connetcion with the Internet.
2095 */
2096- void networkStateChanged(bool aState);
2097+ void networkStateChanged(bool aState, Sync::InternetConnectionType aType);
2098
2099 /*! \brief Signal emitted when a network session is successfully opened
2100 */
2101@@ -99,7 +100,7 @@
2102 void onBtStateChanged(QString aKey, QDBusVariant aValue);
2103 #endif
2104
2105- void onInternetStateChanged(bool aConnected);
2106+ void onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType);
2107
2108 private:
2109
2110@@ -127,7 +128,7 @@
2111 friend class TransportTrackerTest;
2112 friend class SynchronizerTest;
2113 #endif
2114-
2115+
2116 bool btConnectivityStatus();
2117
2118 };
2119
2120=== modified file 'libbuteosyncfw/profile/ProfileManager.cpp'
2121--- libbuteosyncfw/profile/ProfileManager.cpp 2015-03-05 06:24:35 +0000
2122+++ libbuteosyncfw/profile/ProfileManager.cpp 2015-09-30 18:13:56 +0000
2123@@ -129,7 +129,6 @@
2124
2125 Profile *ProfileManagerPrivate::load(const QString &aName, const QString &aType)
2126 {
2127-
2128 QString profilePath = findProfileFile(aName, aType);
2129 QString backupProfilePath = profilePath + BACKUP_EXT;
2130
2131@@ -739,6 +738,14 @@
2132 bool exists = d_ptr->profileExists(aProfile.name(),aProfile.type());
2133
2134 QString profileId("");
2135+
2136+ // We need to save before emit the signalProfileChanged, if this is the first
2137+ // update the profile will only exists on disk after the save and any operation
2138+ // using this profile triggered by the signal will fail.
2139+ if(d_ptr->save(aProfile)) {
2140+ profileId = aProfile.name();
2141+ }
2142+
2143 // Profile did not exist, it was a new one. Add it and emit signal with "added" value:
2144 if (!exists) {
2145 emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_ADDED,aProfile.toString());
2146@@ -746,9 +753,6 @@
2147 emit signalProfileChanged(aProfile.name(),ProfileManager::PROFILE_MODIFIED,aProfile.toString());
2148 }
2149
2150- if(d_ptr->save(aProfile)) {
2151- profileId = aProfile.name();
2152- }
2153 return profileId;
2154 }
2155
2156@@ -1254,7 +1258,7 @@
2157 !iSyncRetriesInfo[aProfile->name()].isEmpty())
2158 {
2159 quint32 mins = iSyncRetriesInfo[aProfile->name()].takeFirst();
2160- nextRetryInterval = QDateTime::currentDateTime().addSecs(mins * 60);
2161+ nextRetryInterval = QDateTime::currentDateTime().addSecs(mins * 60);
2162 LOG_DEBUG("syncretries : retry for profile" << aProfile->name() << "in" << mins <<"minutes");
2163 LOG_DEBUG("syncretries :" << iSyncRetriesInfo[aProfile->name()].count() <<"attempts remain");
2164 }
2165
2166=== modified file 'libbuteosyncfw/profile/SyncProfile.cpp'
2167--- libbuteosyncfw/profile/SyncProfile.cpp 2015-01-30 06:49:01 +0000
2168+++ libbuteosyncfw/profile/SyncProfile.cpp 2015-09-30 18:13:56 +0000
2169@@ -259,14 +259,11 @@
2170 if (d_ptr->iLog)
2171 {
2172 QList<const SyncResults*> allResults = d_ptr->iLog->allResults();
2173- if (allResults.size () > 0)
2174- {
2175- lastSuccessSyncTime = allResults.at (0)->syncTime ();
2176- foreach (const SyncResults* result, allResults) {
2177- if ((result->majorCode () == SyncResults::SYNC_RESULT_SUCCESS) &&
2178- (result->minorCode () == SyncResults::NO_ERROR) &&
2179- (result->syncTime () > lastSuccessSyncTime))
2180- lastSuccessSyncTime = result->syncTime ();
2181+ foreach (const SyncResults* result, allResults) {
2182+ if ((result->majorCode () == SyncResults::SYNC_RESULT_SUCCESS) &&
2183+ (result->minorCode () == SyncResults::NO_ERROR) &&
2184+ (lastSyncTime().isNull() || (result->syncTime () > lastSuccessSyncTime))) {
2185+ lastSuccessSyncTime = result->syncTime ();
2186 }
2187 }
2188 }
2189
2190=== modified file 'msyncd/AccountsHelper.cpp'
2191--- msyncd/AccountsHelper.cpp 2015-01-27 07:01:48 +0000
2192+++ msyncd/AccountsHelper.cpp 2015-09-30 18:13:56 +0000
2193@@ -26,6 +26,8 @@
2194 #include "Profile.h"
2195 #include "ProfileEngineDefs.h"
2196
2197+#include <QTimer>
2198+
2199 static const QString ACCOUNTS_GLOBAL_SERVICE("global");
2200
2201 using namespace Buteo;
2202@@ -36,13 +38,15 @@
2203 iAccountManager = new Accounts::Manager(this);
2204 // Connect to signal for account creation, deletion, and modification
2205 QObject::connect(iAccountManager, SIGNAL(accountCreated(Accounts::AccountId)),
2206- this, SLOT(slotAccountCreated(Accounts::AccountId)));
2207+ this, SLOT(createProfileForAccount(Accounts::AccountId)));
2208 QObject::connect(iAccountManager, SIGNAL(accountRemoved(Accounts::AccountId)),
2209 this, SLOT(slotAccountRemoved(Accounts::AccountId)));
2210 QObject::connect(iAccountManager, SIGNAL(accountUpdated(Accounts::AccountId)),
2211 this, SLOT(slotAccountUpdated(Accounts::AccountId)));
2212
2213- registerAccountListeners();
2214+ // load accounts after return from contructor, to allow connection with class singals
2215+ // that can be fired by 'registerAccountListeners' function
2216+ QTimer::singleShot(0, this, SLOT(registerAccountListeners()));
2217 }
2218
2219 AccountsHelper::~AccountsHelper()
2220@@ -54,9 +58,10 @@
2221 // their parent, aka, the manager
2222 }
2223
2224-void AccountsHelper::slotAccountCreated(Accounts::AccountId id)
2225+QString AccountsHelper::createProfileForAccount(Accounts::AccountId id)
2226 {
2227 FUNCTION_CALL_TRACE;
2228+ QString profileName;
2229 Accounts::Account *newAccount = iAccountManager->account(id);
2230 bool profileFoundAndCreated = false;
2231
2232@@ -66,7 +71,7 @@
2233 Accounts::ServiceList serviceList = newAccount->services();
2234 foreach(Accounts::Service service, serviceList)
2235 {
2236- // Look for a sync profile that matches the service name
2237+ // Look for a sync profile that matches the service name (template)
2238 LOG_DEBUG("Looking for sync profile::" << service.name());
2239 SyncProfile *syncProfile = iProfileManager.syncProfile(service.name());
2240 LOG_DEBUG("Found profile::" << service.name());
2241@@ -74,7 +79,7 @@
2242 (true == syncProfile->boolKey(KEY_USE_ACCOUNTS, false))
2243 )
2244 {
2245- addAccountIfNotExists(newAccount, service, syncProfile);
2246+ profileName = addAccountIfNotExists(newAccount, service, syncProfile);
2247 profileFoundAndCreated = true;
2248 }
2249 if(0 != syncProfile)
2250@@ -86,7 +91,7 @@
2251
2252 if (profileFoundAndCreated == false)
2253 {
2254- // Fetch the key "remote_service_name" from the account settings and
2255+ // Fetch the key "remote_service_name" from the account settings and
2256 // use it to create a profile
2257 QString profileName = newAccount->valueAsString(REMOTE_SERVICE_NAME);
2258 LOG_DEBUG("Profile name from account setting:" << profileName);
2259@@ -97,10 +102,15 @@
2260 if (syncProfile->boolKey (KEY_USE_ACCOUNTS, false) == true)
2261 createProfileForAccount (newAccount, profileName, syncProfile);
2262
2263+ profileName = syncProfile->name();
2264 delete syncProfile;
2265 }
2266 }
2267+ } else {
2268+ LOG_DEBUG("Account not found:" << id);
2269 }
2270+
2271+ return profileName;
2272 }
2273
2274 void AccountsHelper::slotAccountRemoved(Accounts::AccountId id)
2275@@ -186,7 +196,7 @@
2276 foreach(SyncProfile *profile, profiles)
2277 {
2278 // See if the service name matches
2279- if(serviceName == profile->name())
2280+ if(serviceName == profile->key(REMOTE_SERVICE_NAME))
2281 {
2282 // Check if the status really changed here
2283 // saving the account can trigger the emition of enabledChanged()
2284@@ -331,16 +341,16 @@
2285 delete newProfile;
2286 }
2287
2288-void AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
2289- Accounts::Service service,
2290- const SyncProfile *baseProfile)
2291+QString AccountsHelper::addAccountIfNotExists(Accounts::Account *account,
2292+ Accounts::Service service,
2293+ const SyncProfile *baseProfile)
2294 {
2295 FUNCTION_CALL_TRACE;
2296
2297 Profile *serviceProfile = iProfileManager.profile(service.name(), Profile::TYPE_SYNC);
2298 if (!serviceProfile) {
2299 LOG_DEBUG ("!!!! Service not supported !!!!");
2300- return;
2301+ return QString();
2302 }
2303
2304 QString profileName ;
2305@@ -367,9 +377,11 @@
2306 // Add the account ID to the profile
2307 newProfile->setKey(KEY_ACCOUNT_ID, QString::number(account->id()));
2308 // Check if service is enabled
2309- LOG_DEBUG("Service:: " << service.displayName() << "enabled status::" << account->enabled());
2310+ LOG_DEBUG("Service:: " << service.displayName() <<
2311+ "enabled status::" << (account->enabled() && account->enabledServices().contains(service)));
2312 // Set profile as enabled
2313- newProfile->setEnabled(account->enabled());
2314+ newProfile->setEnabled(account->enabled() &&
2315+ account->enabledServices().contains(service));
2316 setSyncSchedule (newProfile, account->id(), true);
2317
2318 // Save the newly created profile
2319@@ -398,6 +410,8 @@
2320 {
2321 delete profile;
2322 }
2323+
2324+ return profileName;
2325 }
2326
2327 void AccountsHelper::addSetting(Accounts::AccountId id, QString key, QVariant value) {
2328@@ -448,12 +462,27 @@
2329 void AccountsHelper::registerAccountListener(Accounts::AccountId id)
2330 {
2331 FUNCTION_CALL_TRACE;
2332+
2333 Accounts::Account *account = iAccountManager->account(id);
2334+ if (iAccountList.contains(account)) {
2335+ return;
2336+ }
2337 iAccountList.append(account);
2338 // Callback for account enabled/disabled
2339- QObject::connect(account, SIGNAL(enabledChanged(const QString&, bool)),
2340- this, SLOT(slotAccountEnabledChanged(const QString&, bool)));
2341+ QObject::connect(account,
2342+ SIGNAL(enabledChanged(const QString&, bool)),
2343+ SLOT(slotAccountEnabledChanged(const QString&, bool)),
2344+ Qt::UniqueConnection);
2345
2346+ // Account SyncOnChange
2347+ QList<SyncProfile*> profiles = getProfilesByAccountId(id);
2348+ foreach(SyncProfile *profile, profiles)
2349+ {
2350+ if(profile->isSOCProfile())
2351+ {
2352+ emit enableSOC(profile->name());
2353+ }
2354+ }
2355 account->selectService();
2356 account->beginGroup("scheduler");
2357 LOG_DEBUG("Watching Group :" << account->group());
2358@@ -463,5 +492,8 @@
2359 return;
2360 }
2361 iAcctWatchMap[watch] = id;
2362- QObject::connect(watch, SIGNAL(notify(const char *)), this, SLOT(slotSchedulerSettingsChanged(const char *)));
2363+ QObject::connect(watch,
2364+ SIGNAL(notify(const char *)),
2365+ SLOT(slotSchedulerSettingsChanged(const char *)),
2366+ Qt::UniqueConnection);
2367 }
2368
2369=== modified file 'msyncd/AccountsHelper.h'
2370--- msyncd/AccountsHelper.h 2014-11-07 07:26:49 +0000
2371+++ msyncd/AccountsHelper.h 2015-09-30 18:13:56 +0000
2372@@ -29,12 +29,12 @@
2373 #include <Accounts/account.h>
2374
2375 namespace Buteo {
2376-
2377+
2378 class Profile;
2379 class AccountsHelperTest;
2380 class ProfileManager;
2381 class SyncProfile;
2382-
2383+
2384 const QString REMOTE_SERVICE_NAME("remote_service_name");
2385
2386 /*! \brief Helper Class towards Accounts::Manager and various SSO related
2387@@ -57,7 +57,7 @@
2388 *
2389 */
2390 virtual ~AccountsHelper();
2391-
2392+
2393 /*! \brief Returns sync profiles that correspond to a given account ID
2394 *
2395 * \param id - The account ID.
2396@@ -68,30 +68,31 @@
2397
2398 public Q_SLOTS:
2399
2400- /*! \brief slot for Accounts::Manager accountCreated signal
2401- *
2402- * \param id Accounts Id
2403- */
2404- void slotAccountCreated(Accounts::AccountId id);
2405+ /*! \brief This method is used to create a profile for a specified
2406+ * account
2407+ * \param id Accounts Id
2408+ * \return A string with the new profile name
2409+ */
2410+ QString createProfileForAccount(Accounts::AccountId id);
2411
2412- /*! \brief slot for Accounts::Manager accountRemoved signal
2413- *
2414- * \param id of the accounts
2415- */
2416+ /*! \brief slot for Accounts::Manager accountRemoved signal
2417+ *
2418+ * \param id of the accounts
2419+ */
2420 void slotAccountRemoved(Accounts::AccountId id);
2421
2422- /*! \brief slot for Accounts::Account enabledChanged signal
2423- *
2424- * \param serviceName The service that was enabled/disabled. Empty if the
2425+ /*! \brief slot for Accounts::Account enabledChanged signal
2426+ *
2427+ * \param serviceName The service that was enabled/disabled. Empty if the
2428 * entire account is enabled/disabled
2429 * \param enabled Boolean indicating enabled (true) or disabled (false)
2430- */
2431+ */
2432 void slotAccountEnabledChanged(const QString &serviceName, bool enabled);
2433-
2434- /*! \brief slot for Accounts::Manager displayNameChanged signal
2435- * *
2436- * \param id of the accounts
2437- */
2438+
2439+ /*! \brief slot for Accounts::Manager displayNameChanged signal
2440+ * *
2441+ * \param id of the accounts
2442+ */
2443 void slotAccountUpdated(Accounts::AccountId id);
2444
2445 void slotSchedulerSettingsChanged(const char *aKey);
2446@@ -102,22 +103,20 @@
2447 void removeProfile(QString profileId);
2448 void removeScheduledSync(const QString& profileId);
2449
2450+private Q_SLOTS:
2451+
2452+ void registerAccountListeners();
2453+
2454 private:
2455-
2456- /*!
2457- * \brief This method is used to create a profile for a specified
2458- * account
2459- */
2460 void createProfileForAccount(Accounts::Account* account,
2461 const QString profileName,
2462 const SyncProfile* baseProfile);
2463
2464- void addAccountIfNotExists(Accounts::Account *account,
2465- Accounts::Service service,
2466- const SyncProfile *baseProfile);
2467+ QString addAccountIfNotExists(Accounts::Account *account,
2468+ Accounts::Service service,
2469+ const SyncProfile *baseProfile);
2470
2471 void setSyncSchedule(SyncProfile *syncProfile, Accounts::AccountId id, bool aCreateNew = false);
2472- void registerAccountListeners();
2473
2474 void addSetting(Accounts::AccountId id, QString key, QVariant value);
2475
2476
2477=== modified file 'msyncd/SyncDBusAdaptor.cpp'
2478--- msyncd/SyncDBusAdaptor.cpp 2015-01-30 06:49:01 +0000
2479+++ msyncd/SyncDBusAdaptor.cpp 2015-09-30 18:13:56 +0000
2480@@ -206,3 +206,11 @@
2481 QMetaObject::invokeMethod(parent(), "isSyncedExternally", Q_ARG(uint, aAccountId), Q_ARG(QString, aClientProfileName));
2482 }
2483
2484+QString SyncDBusAdaptor::createSyncProfileForAccount(uint aAccountId)
2485+{
2486+ // handle method call com.meego.msyncd.createSyncProfileForAccount
2487+ QString out0;
2488+ QMetaObject::invokeMethod(parent(), "createSyncProfileForAccount", Q_RETURN_ARG(QString, out0), Q_ARG(uint, aAccountId));
2489+ return out0;
2490+}
2491+
2492
2493=== modified file 'msyncd/SyncDBusAdaptor.h'
2494--- msyncd/SyncDBusAdaptor.h 2015-01-30 06:49:01 +0000
2495+++ msyncd/SyncDBusAdaptor.h 2015-09-30 18:13:56 +0000
2496@@ -157,6 +157,10 @@
2497 " <arg direction=\"out\" type=\"au\"/>\n"
2498 " <annotation value=\"QList&lt;uint>\" name=\"com.trolltech.QtDBus.QtTypeName.Out0\"/>\n"
2499 " </method>\n"
2500+" <method name=\"createSyncProfileForAccount\">\n"
2501+" <arg direction=\"out\" type=\"s\"/>\n"
2502+" <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"
2503+" </method>\n"
2504 " <method name=\"status\">\n"
2505 " <arg direction=\"out\" type=\"i\"/>\n"
2506 " <arg direction=\"in\" type=\"u\" name=\"aAccountId\"/>\n"
2507@@ -198,6 +202,7 @@
2508 QList<uint> syncingAccounts();
2509 bool updateProfile(const QString &aProfileAsXml);
2510 Q_NOREPLY void isSyncedExternally(uint aAccountId, const QString aClientProfileName);
2511+ QString createSyncProfileForAccount(uint aAccountId);
2512 Q_SIGNALS: // SIGNALS
2513 void backupDone();
2514 void backupInProgress();
2515
2516=== modified file 'msyncd/SyncDBusInterface.h'
2517--- msyncd/SyncDBusInterface.h 2015-01-30 06:49:01 +0000
2518+++ msyncd/SyncDBusInterface.h 2015-09-30 18:13:56 +0000
2519@@ -103,29 +103,29 @@
2520 *
2521 */
2522 void signalProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
2523-
2524-
2525+
2526+
2527 /*! \brief Notifies about Backup start.
2528 *
2529 * This signal is sent when the backup framework is backing the sync related
2530 * data
2531 */
2532 void backupInProgress ();
2533-
2534+
2535 /*! \brief Notifies about Backup done.
2536 *
2537 * This signal is sent when the backup framework has completed backing the sync related
2538 * data.
2539 */
2540 void backupDone();
2541-
2542+
2543 /*! \brief Notifies about Restore start.
2544 *
2545 * This signal is sent when the backup framework is restoring the sync related
2546 * data
2547 */
2548 void restoreInProgress();
2549-
2550+
2551 /*! \brief Notifies about Restore Done.
2552 *
2553 * This signal is sent when the backup framework has restored the sync related
2554@@ -160,7 +160,7 @@
2555 * \param aNextSyncTime This is an out parameter. The next sync time.
2556 */
2557 void statusChanged(unsigned int aAccountId, int aNewStatus, int aFailedReason, qlonglong aPrevSyncTime, qlonglong aNextSyncTime);
2558-
2559+
2560 /*! \brief Returns the connectivity state of a specific medium like
2561 * bluetooth, USB or network.
2562 * \see SyncCommonDefs::ConnectivityType for arguments
2563@@ -257,16 +257,16 @@
2564 * \return Profile name list.
2565 */
2566 virtual QStringList runningSyncs() = 0;
2567-
2568-
2569+
2570+
2571 /*!
2572 * \brief This function returns true if backup/restore in progress else
2573 * false.
2574 */
2575 virtual bool getBackUpRestoreState() = 0;
2576-
2577-
2578- /*!
2579+
2580+
2581+ /*!
2582 * \brief sets the schedule for a profile
2583 *
2584 * This Function helps in setting a schedule to profile
2585@@ -312,7 +312,7 @@
2586 * \return The sync profile as Xml string.
2587 */
2588 virtual QString syncProfile(const QString &aProfileId) = 0;
2589-
2590+
2591 /*! \brief Gets a sync profiles matching the key-value.
2592 *
2593 * Loads and merges also all sub-profiles that are referenced from the
2594@@ -323,7 +323,7 @@
2595 * \return The sync profiles as Xml string list.
2596 */
2597 virtual QStringList syncProfilesByKey(const QString &aKey, const QString &aValue) = 0;
2598-
2599+
2600 /*! \brief Gets a profiles matching the profile type.
2601 *
2602 * \param aType Type of the profile service/storage/sync.
2603@@ -336,13 +336,13 @@
2604 * \param aAccountId The account ID.
2605 */
2606 virtual Q_NOREPLY void start(unsigned int aAccountId) = 0;
2607-
2608+
2609 /*! \brief Stops sync for all profiles matching the given account ID.
2610 *
2611 * \param aAccountId The account ID.
2612 */
2613 virtual Q_NOREPLY void stop(unsigned int aAccountId) = 0;
2614-
2615+
2616 /*! \brief Returns the list of account IDs for which sync is ongoing
2617 *
2618 * \return The list of account IDs currectly syncing.
2619@@ -373,6 +373,13 @@
2620 * having several services enabled
2621 */
2622 virtual Q_NOREPLY void isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName) = 0;
2623+
2624+ /*! \brief Create a sync profile for the account if it does not exists
2625+ *
2626+ * \param aAccountId The account ID.
2627+ * \return The profile name if the profile was created successful or empty if it fails
2628+ */
2629+ virtual QString createSyncProfileForAccount(uint aAccountId) = 0;
2630 };
2631
2632 }
2633
2634=== modified file 'msyncd/SyncOnChangeScheduler.cpp'
2635--- msyncd/SyncOnChangeScheduler.cpp 2014-02-20 07:06:08 +0000
2636+++ msyncd/SyncOnChangeScheduler.cpp 2015-09-30 18:13:56 +0000
2637@@ -14,6 +14,11 @@
2638 SyncOnChangeScheduler::~SyncOnChangeScheduler()
2639 {
2640 FUNCTION_CALL_TRACE;
2641+ foreach(QObject *o, iSOCTimers.values()) {
2642+ delete o;
2643+ }
2644+ iSOCTimers.clear();
2645+ iSOCProfileNames.clear();
2646 }
2647
2648 bool SyncOnChangeScheduler::addProfile(const SyncProfile* aProfile)
2649@@ -30,6 +35,7 @@
2650 Qt::QueuedConnection);
2651 SOCtimer->fire();
2652 scheduled = true;
2653+ iSOCTimers.insert(aProfile->name(), SOCtimer);
2654 LOG_DEBUG("Sync on change scheduled for profile"<< aProfile->name());
2655 }
2656 else if(aProfile)
2657@@ -43,12 +49,15 @@
2658 {
2659 FUNCTION_CALL_TRACE;
2660 iSOCProfileNames.removeAll(aProfileName);
2661+ // cancel timer
2662+ delete iSOCTimers.take(aProfileName);
2663 }
2664
2665 void SyncOnChangeScheduler::sync(const SyncProfile* aProfile)
2666 {
2667 FUNCTION_CALL_TRACE;
2668 iSOCProfileNames.removeAll(aProfile->name());
2669+ iSOCTimers.remove(aProfile->name());
2670 SyncOnChangeTimer *SOCtimer = qobject_cast<SyncOnChangeTimer*>(sender());
2671 if(SOCtimer)
2672 {
2673
2674=== modified file 'msyncd/SyncOnChangeScheduler.h'
2675--- msyncd/SyncOnChangeScheduler.h 2011-02-02 09:39:11 +0000
2676+++ msyncd/SyncOnChangeScheduler.h 2015-09-30 18:13:56 +0000
2677@@ -40,7 +40,7 @@
2678 *
2679 * Once the SOC is initiated (by sending a syncNow signal), the profile is
2680 * removed automatically
2681- *
2682+ *
2683 * @param aProfile pointer to sync profile
2684 * @return true if SOC could be scheduled, false otherwise
2685 */
2686@@ -63,6 +63,7 @@
2687
2688 private:
2689 QStringList iSOCProfileNames;
2690+ QMap<QString, QObject*> iSOCTimers;
2691 };
2692
2693 class SyncOnChangeTimer : public QObject
2694
2695=== modified file 'msyncd/SyncSession.h'
2696--- msyncd/SyncSession.h 2011-02-03 09:58:25 +0000
2697+++ msyncd/SyncSession.h 2015-09-30 18:13:56 +0000
2698@@ -182,7 +182,7 @@
2699 void setProfileCreated(bool aProfileCreated);
2700
2701 //! \brief Maps sync failure error code from stack to SyncStatus
2702- Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
2703+ Sync::SyncStatus mapToSyncStatusError(int aErrorCode);
2704
2705 signals:
2706
2707
2708=== added directory 'msyncd/gschemas'
2709=== added file 'msyncd/gschemas/com.meego.msyncd.gschema.xml'
2710--- msyncd/gschemas/com.meego.msyncd.gschema.xml 1970-01-01 00:00:00 +0000
2711+++ msyncd/gschemas/com.meego.msyncd.gschema.xml 2015-09-30 18:13:56 +0000
2712@@ -0,0 +1,10 @@
2713+<?xml version="1.0" encoding="UTF-8"?>
2714+<schemalist>
2715+ <schema id="com.meego.msyncd" path="/com/meego/msyncd/">
2716+ <key name="allow-scheduled-sync-over-cellular" type="b">
2717+ <summary>Scheduled Sync over cellular</summary>
2718+ <description>Allow scheduled syncs to run over cellular connections.</description>
2719+ <default>true</default>
2720+ </key>
2721+ </schema>
2722+</schemalist>
2723
2724=== modified file 'msyncd/msyncd-app.pro'
2725--- msyncd/msyncd-app.pro 2014-06-19 06:03:32 +0000
2726+++ msyncd/msyncd-app.pro 2015-09-30 18:13:56 +0000
2727@@ -62,10 +62,13 @@
2728 service.path = /usr/lib/systemd/user/
2729 syncwidget.path = /etc/syncwidget/
2730 syncwidget.files = com.meego.msyncd
2731+gschemas.path = /usr/share/glib-2.0/schemas
2732+gschemas.files = gschemas/com.meego.msyncd.gschema.xml
2733 INSTALLS += target \
2734 loglevel \
2735 syncwidget \
2736- service
2737+ service \
2738+ gschemas
2739
2740 # #####################################################################
2741 # make coverage (debug)
2742
2743=== modified file 'msyncd/msyncd-lib.pro'
2744--- msyncd/msyncd-lib.pro 2014-06-19 06:03:32 +0000
2745+++ msyncd/msyncd-lib.pro 2015-09-30 18:13:56 +0000
2746@@ -19,7 +19,7 @@
2747 ../libbuteosyncfw/profile
2748
2749
2750-PKGCONFIG += dbus-1
2751+PKGCONFIG += dbus-1 gio-2.0
2752
2753 equals(QT_MAJOR_VERSION, 4): {
2754 PKGCONFIG += libsignon-qt accounts-qt
2755
2756=== modified file 'msyncd/synchronizer.cpp'
2757--- msyncd/synchronizer.cpp 2015-03-12 04:06:41 +0000
2758+++ msyncd/synchronizer.cpp 2015-09-30 18:13:56 +0000
2759@@ -1,4 +1,4 @@
2760-/*
2761+/*
2762 * This file is part of buteo-syncfw package
2763 *
2764 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
2765@@ -21,6 +21,7 @@
2766 * 02110-1301 USA
2767 *
2768 */
2769+#include <gio/gio.h>
2770 #include "synchronizer.h"
2771 #include "SyncDBusAdaptor.h"
2772 #include "SyncSession.h"
2773@@ -51,11 +52,11 @@
2774 #include <fcntl.h>
2775 #include <termios.h>
2776
2777+
2778 using namespace Buteo;
2779
2780 static const QString SYNC_DBUS_OBJECT = "/synchronizer";
2781 static const QString SYNC_DBUS_SERVICE = "com.meego.msyncd";
2782-
2783 static const QString BT_PROPERTIES_NAME = "Name";
2784
2785 // Maximum time in milliseconds to wait for a thread to stop
2786@@ -71,10 +72,9 @@
2787 iClosing(false),
2788 iSOCEnabled(false),
2789 iSyncUIInterface(NULL)
2790-
2791 {
2792+ iSettings = g_settings_new_with_path("com.meego.msyncd", "/com/meego/msyncd/");
2793 FUNCTION_CALL_TRACE;
2794-
2795 this->setParent(aApplication);
2796 }
2797
2798@@ -86,6 +86,7 @@
2799 delete iSyncUIInterface;
2800 iSyncUIInterface = NULL;
2801 }
2802+ g_object_unref(iSettings);
2803 }
2804
2805 bool Synchronizer::initialize()
2806@@ -115,8 +116,9 @@
2807 this, SLOT(slotSyncStatus(QString, int, QString, int)),
2808 Qt::QueuedConnection);
2809
2810+ // use queued connection because the profile will be stored after the signal
2811 connect(&iProfileManager ,SIGNAL(signalProfileChanged(QString,int,QString)),
2812- this, SIGNAL(signalProfileChanged(QString,int,QString)));
2813+ this, SLOT(slotProfileChanged(QString,int,QString)), Qt::QueuedConnection);
2814
2815 iNetworkManager = new NetworkManager(this);
2816 Q_ASSERT(iNetworkManager);
2817@@ -127,8 +129,9 @@
2818 {
2819 iServerActivator = new ServerActivator(iProfileManager,
2820 *iTransportTracker, this);
2821- connect(iTransportTracker, SIGNAL(networkStateChanged(bool)),
2822- this, SLOT(onNetworkStateChanged(bool)));
2823+ connect(iTransportTracker,
2824+ SIGNAL(networkStateChanged(bool,Sync::InternetConnectionType)),
2825+ SLOT(onNetworkStateChanged(bool,Sync::InternetConnectionType)));
2826 }
2827
2828 // Initialize account manager.
2829@@ -184,7 +187,7 @@
2830 else
2831 {
2832 QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(QString)),
2833- this, SLOT(startSync(QString)),
2834+ this, SLOT(startScheduledSync(QString)),
2835 Qt::QueuedConnection);
2836 iSOCEnabled = true;
2837 }
2838@@ -200,7 +203,7 @@
2839 {
2840 FUNCTION_CALL_TRACE;
2841 SyncProfile* profile = iProfileManager.syncProfile(aProfileName);
2842- if(!iSOCEnabled)
2843+ if(profile->isSOCProfile() && !iSOCEnabled)
2844 {
2845 QHash<QString,QList<SyncProfile*> > aSOCStorageMap;
2846 QList<SyncProfile*> SOCProfiles;
2847@@ -217,13 +220,13 @@
2848 else
2849 {
2850 QObject::connect(&iSyncOnChangeScheduler, SIGNAL(syncNow(const QString&)),
2851- this, SLOT(startSync(const QString&)),
2852+ this, SLOT(startScheduledSync(const QString&)),
2853 Qt::QueuedConnection);
2854 iSOCEnabled = true;
2855 LOG_DEBUG("Sync on change enabled for profile" << aProfileName);
2856 }
2857 }
2858- else
2859+ else if (profile->isSOCProfile())
2860 {
2861 iSyncOnChange.addProfile("hcontacts", profile);
2862 }
2863@@ -291,55 +294,27 @@
2864 // All scheduled syncs are online syncs
2865 // Add this to the waiting online syncs and it will be started when we
2866 // receive a session connection status from the NetworkManager
2867- bool sessionConnected = !iWaitingOnlineSyncs.isEmpty();
2868- if(!iWaitingOnlineSyncs.contains(aProfileName))
2869+ bool accept = acceptScheduledSync(iNetworkManager->isOnline(), iNetworkManager->connectionType());
2870+ if(accept)
2871 {
2872- iWaitingOnlineSyncs.append(aProfileName);
2873+ startSync(aProfileName, true);
2874 }
2875- if(!sessionConnected)
2876+ else if (!iWaitingOnlineSyncs.contains(aProfileName))
2877 {
2878- QObject::connect(iNetworkManager, SIGNAL(connectionSuccess()), this,
2879- SLOT(slotNetworkSessionOpened()), Qt::QueuedConnection);
2880- QObject::connect(iNetworkManager, SIGNAL(connectionError()), this,
2881- SLOT(slotNetworkSessionError()), Qt::QueuedConnection);
2882- // Request for a network session
2883- iNetworkManager->connectSession(true);
2884+ LOG_DEBUG("Wait for internet connection:" << aProfileName);
2885+ if (iNetworkManager->isOnline())
2886+ {
2887+ LOG_DEBUG("Connection over mobile data plan. The sync will be postponed untill a full connection is available;");
2888+ }
2889+ else
2890+ {
2891+ LOG_DEBUG("Device offline. Wait for internet connection.");
2892+ }
2893+ iWaitingOnlineSyncs.append(aProfileName);
2894 }
2895 return true;
2896 }
2897
2898-void Synchronizer::slotNetworkSessionOpened()
2899-{
2900- FUNCTION_CALL_TRACE;
2901- QObject::disconnect(iNetworkManager, SIGNAL(connectionSuccess()), this,
2902- SLOT(slotNetworkSessionOpened()));
2903- QObject::disconnect(iNetworkManager, SIGNAL(connectionError()), this,
2904- SLOT(slotNetworkSessionError()));
2905- foreach(QString profileName, iWaitingOnlineSyncs)
2906- {
2907- startSync(profileName, true);
2908- }
2909- iWaitingOnlineSyncs.clear();
2910-}
2911-
2912-void Synchronizer::slotNetworkSessionError()
2913-{
2914- FUNCTION_CALL_TRACE;
2915- QObject::disconnect(iNetworkManager, SIGNAL(connectionSuccess()), this,
2916- SLOT(slotNetworkSessionOpened()));
2917- QObject::disconnect(iNetworkManager, SIGNAL(connectionError()), this,
2918- SLOT(slotNetworkSessionError()));
2919- // Cancel all open sessions
2920- foreach(QString profileName, iWaitingOnlineSyncs)
2921- {
2922- SyncResults syncResults(QDateTime::currentDateTime(), SyncResults::SYNC_RESULT_FAILED, SyncResults::CONNECTION_ERROR);
2923- iProfileManager.saveSyncResults(profileName, syncResults);
2924- reschedule(profileName);
2925- }
2926- iWaitingOnlineSyncs.clear();
2927- iNetworkManager->disconnectSession();
2928-}
2929-
2930 bool Synchronizer::setSyncSchedule(QString aProfileId , QString aScheduleAsXml)
2931 {
2932 bool status = false;
2933@@ -364,6 +339,11 @@
2934 return status;
2935 }
2936
2937+QString Synchronizer::createSyncProfileForAccount(uint aAccountId)
2938+{
2939+ return iAccounts->createProfileForAccount(aAccountId);
2940+}
2941+
2942 bool Synchronizer::startSync(const QString &aProfileName, bool aScheduled)
2943 {
2944 FUNCTION_CALL_TRACE;
2945@@ -378,6 +358,12 @@
2946
2947 LOG_DEBUG( "Start sync requested for profile:" << aProfileName );
2948
2949+ // This function can be called from a client app as manual sync:
2950+ // If we receive a manual sync to a profile that is peding to sync due a
2951+ // data change we can remove it from the iSyncOnChangeScheduler, to avoid a
2952+ // second sync.
2953+ iSyncOnChangeScheduler.removeProfile(aProfileName);
2954+
2955 if (iActiveSessions.contains(aProfileName))
2956 {
2957 LOG_DEBUG( "Sync already in progress" );
2958@@ -389,6 +375,14 @@
2959 emit syncStatus(aProfileName, Sync::SYNC_QUEUED, "", 0);
2960 return true;
2961 }
2962+ else if (!aScheduled && iWaitingOnlineSyncs.contains(aProfileName))
2963+ {
2964+ // Manual sync is allowed to happen in any kind of connection
2965+ // if sync is not scheduled remove it from iWaitingOnlineSyncs to avoid
2966+ // sync it twice later
2967+ iWaitingOnlineSyncs.removeOne(aProfileName);
2968+ LOG_DEBUG("Removing" << aProfileName << "from online waiting list.");
2969+ }
2970
2971 SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
2972 if (!profile)
2973@@ -520,7 +514,7 @@
2974 return false;
2975 }
2976
2977- LOG_DEBUG("Disable sync on change");
2978+ LOG_DEBUG("Disable sync on change:" << iSOCEnabled << profile->isSOCProfile());
2979 //As sync is ongoing, disable sync on change for now, we can query later if
2980 //there are changes.
2981 if(iSOCEnabled)
2982@@ -754,7 +748,7 @@
2983 }
2984
2985 QString profileName = session->profileName();
2986- LOG_DEBUG( "Trying to start next sync in queue. Profile:" << profileName );
2987+ LOG_DEBUG( "Trying to start next sync in queue. Profile:" << profileName << session->isScheduled());
2988
2989 #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
2990 QBatteryInfo iDeviceInfo;
2991@@ -1516,6 +1510,41 @@
2992 }
2993 }
2994
2995+void Synchronizer::slotProfileChanged(QString aProfileName, int aChangeType, QString aProfileAsXml)
2996+{
2997+ // start sync when a new profile is added
2998+ switch (aChangeType)
2999+ {
3000+ case ProfileManager::PROFILE_ADDED:
3001+ {
3002+ enableSOCSlot(aProfileName);
3003+ SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
3004+ if (profile && profile->isEnabled()) {
3005+ startSync(aProfileName);
3006+ }
3007+ }
3008+ break;
3009+
3010+ case ProfileManager::PROFILE_REMOVED:
3011+ iSyncOnChangeScheduler.removeProfile(aProfileName);
3012+ iWaitingOnlineSyncs.removeAll(aProfileName);
3013+ break;
3014+
3015+ case ProfileManager::PROFILE_MODIFIED:
3016+ {
3017+ // schedule a new sync in case of profile changed;
3018+ // Example if the profile change from disable -> enable
3019+ SyncProfile *profile = iProfileManager.syncProfile(aProfileName);
3020+ if (profile->isEnabled()) {
3021+ startScheduledSync(aProfileName);
3022+ }
3023+ }
3024+ break;
3025+ }
3026+
3027+ emit signalProfileChanged(aProfileName, aChangeType, aProfileAsXml);
3028+}
3029+
3030 void Synchronizer::reschedule(const QString &aProfileName)
3031 {
3032 FUNCTION_CALL_TRACE;
3033@@ -1903,10 +1932,24 @@
3034 return iProfileManager.profileNames(aType);
3035 }
3036
3037-void Synchronizer::onNetworkStateChanged(bool aState)
3038+void Synchronizer::onNetworkStateChanged(bool aState, Sync::InternetConnectionType type)
3039 {
3040 FUNCTION_CALL_TRACE;
3041- if(!aState) {
3042+ LOG_DEBUG("Network state changed: OnLine:" << aState << " connection type:" << type);
3043+ if (acceptScheduledSync(aState, type))
3044+ {
3045+ LOG_DEBUG("Restart sync for profiles that need network");
3046+ QStringList profiles(iWaitingOnlineSyncs);
3047+ iWaitingOnlineSyncs.clear();
3048+ foreach(QString profileName, profiles)
3049+ {
3050+ // start sync now, we do not need to call 'startScheduledSync' since that function
3051+ // only checks for internet connection
3052+ startSync(profileName, true);
3053+ }
3054+ }
3055+ else if (!aState)
3056+ {
3057 QList<QString> profiles = iActiveSessions.keys();
3058 foreach(QString profileId, profiles)
3059 {
3060@@ -1919,8 +1962,8 @@
3061 delete profile;
3062 profile = NULL;
3063 }
3064- else {
3065-
3066+ else
3067+ {
3068 LOG_DEBUG("No profile found with aProfileId"<<profileId);
3069 }
3070 }
3071@@ -2069,6 +2112,19 @@
3072 }
3073 }
3074
3075+bool Synchronizer::acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const
3076+{
3077+ static QList<Sync::InternetConnectionType> allowedTypes;
3078+ if (allowedTypes.isEmpty())
3079+ {
3080+ allowedTypes << Sync::INTERNET_CONNECTION_WLAN
3081+ << Sync::INTERNET_CONNECTION_ETHERNET;
3082+ }
3083+
3084+ return (aConnected && (g_settings_get_boolean(iSettings, "allow-scheduled-sync-over-cellular") ||
3085+ allowedTypes.contains(aType)));
3086+}
3087+
3088 void Synchronizer::isSyncedExternally(unsigned int aAccountId, const QString aClientProfileName)
3089 {
3090 LOG_DEBUG("Received isSyncedExternally request for account:" << aAccountId);
3091
3092=== modified file 'msyncd/synchronizer.h'
3093--- msyncd/synchronizer.h 2015-03-06 13:13:09 +0000
3094+++ msyncd/synchronizer.h 2015-09-30 18:13:56 +0000
3095@@ -44,7 +44,9 @@
3096 #include <QMap>
3097 #include <QString>
3098 #include <QDBusInterface>
3099+#include <QScopedPointer>
3100
3101+struct _GSettings;
3102
3103 namespace Buteo {
3104
3105@@ -137,6 +139,9 @@
3106 //! \see SyncDBusInterface::saveSyncResults
3107 virtual bool saveSyncResults(QString aProfileId,QString aSyncResults);
3108
3109+ //! \see SyncDBusInterface::createSyncProfileForAccount
3110+ virtual QString createSyncProfileForAccount(uint aAccountId);
3111+
3112 /*! \brief To get lastSyncResult.
3113 * \param aProfileId
3114 * \return QString of syncResult.
3115@@ -257,9 +262,7 @@
3116
3117 void onNewSession(const QString &aDestination);
3118
3119- void slotNetworkSessionOpened();
3120-
3121- void slotNetworkSessionError();
3122+ void slotProfileChanged(QString aProfileName, int aChangeType , QString aProfileAsXml);
3123
3124 /*! \brief Starts a server plug-in
3125 *
3126@@ -273,7 +276,7 @@
3127 */
3128 void stopServer(const QString &aProfileName);
3129
3130- void onNetworkStateChanged(bool aState);
3131+ void onNetworkStateChanged(bool aState, Sync::InternetConnectionType type);
3132
3133 /*! \brief call this to request the sync daemon to enable soc
3134 * for a profile. The sync daemon decides as of now for which storages
3135@@ -385,6 +388,12 @@
3136 */
3137 void removeExternalSyncStatus(const SyncProfile *aProfile);
3138
3139+ /*! \brief Check if sheduled sync is allowed for this type of connection.
3140+ *
3141+ * @param aType the connection type;
3142+ */
3143+ bool acceptScheduledSync(bool aConnected, Sync::InternetConnectionType aType) const;
3144+
3145 QMap<QString, SyncSession*> iActiveSessions;
3146
3147 QMap<QString, bool> iExternalSyncProfileStatus;
3148@@ -446,6 +455,7 @@
3149 #endif
3150
3151 QDBusInterface *iSyncUIInterface;
3152+ _GSettings *iSettings;
3153 };
3154
3155 }
3156
3157=== modified file 'unittests/tests/msyncdtests/TransportTrackerTest.cpp'
3158--- unittests/tests/msyncdtests/TransportTrackerTest.cpp 2014-06-19 06:03:36 +0000
3159+++ unittests/tests/msyncdtests/TransportTrackerTest.cpp 2015-09-30 18:13:56 +0000
3160@@ -89,7 +89,7 @@
3161 {
3162 qRegisterMetaType<Sync::ConnectivityType>("Sync::ConnectivityType");
3163 QSignalSpy connectivityStateSpy(iTransportTracker, SIGNAL(connectivityStateChanged(Sync::ConnectivityType, bool)));
3164- QSignalSpy networkStateSpy(iTransportTracker, SIGNAL(networkStateChanged(bool)));
3165+ QSignalSpy networkStateSpy(iTransportTracker, SIGNAL(networkStateChanged(bool,Sync::InternetConnectionType)));
3166
3167 // change USB state and verify
3168 bool usbCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_USB);
3169@@ -115,7 +115,7 @@
3170
3171 // change internet state and verify
3172 bool internetCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET);
3173- iTransportTracker->onInternetStateChanged(!internetCurrentState);
3174+ iTransportTracker->onInternetStateChanged(!internetCurrentState, Sync::INTERNET_CONNECTION_UNKNOWN);
3175 QCOMPARE(iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_INTERNET), !internetCurrentState);
3176 QEXPECT_FAIL("", "IMO connectivityStateChanged() should be emitted also for CONNECTIVITY_INTERNET", Continue);
3177 QCOMPARE(connectivityStateSpy.count(), 1);

Subscribers

People subscribed via source and target branches