Package: buteo-syncfw / 0.11.10-1

2004_Add-method-to-enable-disable-sync-profiles-for-a-specific-service.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Subject: [PATCH] [msyncd] Add method to enable/disable sync profiles for a specific service Ensure the profile is created if it does not already exist.
Author: Lionel Duboeuf <lionel@ouvaton.org>

---
--- a/msyncd/AccountsHelper.cpp
+++ b/msyncd/AccountsHelper.cpp
@@ -173,6 +173,42 @@
     account->selectService();
 }
 
+void AccountsHelper::syncEnableWithService(Accounts::Account *account, const QString &serviceName, bool enabled)
+{
+    account->selectService();
+    // Always use the current enabled value since signals may be emitted with delays.
+    bool accountEnabled = account->enabled();
+    bool serviceExists = false;
+    const QList<SyncProfile *> profiles = getProfilesByAccountId(account->id());
+    for (SyncProfile *profile : profiles) {
+
+        if (!profile) {
+            continue;
+        }
+
+        // Global account is disabled, unconditionally disable all profiles
+        if(!accountEnabled && profile->isEnabled()) {
+            profile->setEnabled(false);
+            iProfileManager.updateProfile(*profile);
+            emit removeScheduledSync(profile->name());
+        } else if (profile->key(REMOTE_SERVICE_NAME, "") == serviceName) {
+            serviceExists = true;
+            if (profile->isEnabled() != enabled) {
+                profile->setEnabled(enabled);
+                iProfileManager.updateProfile(*profile);
+                emit scheduleUpdated(profile->name());
+            }
+        }
+        delete profile;
+    }
+
+    if (!serviceExists && accountEnabled) {
+        addProfileForAccount(account, serviceName, enabled);
+    }
+
+    account->selectService();
+}
+
 void AccountsHelper::setSyncSchedule(SyncProfile *syncProfile, Accounts::AccountId id, bool aCreateNew)
 {
     FUNCTION_CALL_TRACE(lcButeoTrace);
@@ -336,9 +372,10 @@
     QObject::connect(account, &Accounts::Account::enabledChanged,
                      [this, account] (const QString & serviceName, bool enabled) {
         qCDebug(lcButeoMsyncd) << "Received account enabled changed signal" << serviceName << enabled << account->displayName();
-        syncEnableWithAccount(account);
+        syncEnableWithService(account, serviceName, enabled);
     });
 
+
 #ifndef USE_ACCOUNTSHELPER_SCHEDULER_WATCHER
     qCDebug(lcButeoMsyncd) << "AccountsHelper::registerAccountListener() is disabled!  Not listening to scheduler change signals for account:"
                            << id;
--- a/msyncd/AccountsHelper.h
+++ b/msyncd/AccountsHelper.h
@@ -89,6 +89,7 @@
 
 private:
     void syncEnableWithAccount(Accounts::Account *account);
+    void syncEnableWithService(Accounts::Account *account, const QString &serviceName, bool enabled);
     bool addProfileForAccount(Accounts::Account *account,
                               const QString &serviceName,
                               bool serviceEnabled,