File: AccountsService.cpp

package info (click to toggle)
lomiri 0.5.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,088 kB
  • sloc: cpp: 39,498; python: 2,559; javascript: 1,426; ansic: 1,012; sh: 289; xml: 252; makefile: 69
file content (507 lines) | stat: -rw-r--r-- 20,108 bytes parent folder | download | duplicates (2)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/*
 * Copyright (C) 2013-2016 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "AccountsService.h"
#include "AccountsServiceDBusAdaptor.h"

#include <QDBusInterface>
#include <QFile>
#include <QStringList>
#include <QDebug>

#include <glib.h>
#include <paths.h>

#define IFACE_ACCOUNTS_USER          QStringLiteral("org.freedesktop.Accounts.User")
#define IFACE_UBUNTU_INPUT           QStringLiteral("com.lomiri.AccountsService.Input")
#define IFACE_UBUNTU_SECURITY        QStringLiteral("com.lomiri.AccountsService.SecurityPrivacy")
#define IFACE_UBUNTU_SECURITY_OLD    QStringLiteral("com.lomiri.touch.AccountsService.SecurityPrivacy")
#define IFACE_LOMIRI                  QStringLiteral("com.lomiri.shell.AccountsService")
#define IFACE_LOMIRI_PRIVATE          QStringLiteral("com.lomiri.shell.AccountsService.Private")

#define PROP_BACKGROUND_FILE                   QStringLiteral("BackgroundFile")
#define PROP_DEMO_EDGES                        QStringLiteral("DemoEdges2")
#define PROP_DEMO_EDGES_COMPLETED              QStringLiteral("DemoEdgesCompleted")
#define PROP_EMAIL                             QStringLiteral("Email")
#define PROP_ENABLE_FINGERPRINT_IDENTIFICATION QStringLiteral("EnableFingerprintIdentification")
#define PROP_ENABLE_INDICATORS_WHILE_LOCKED    QStringLiteral("EnableIndicatorsWhileLocked")
#define PROP_HIDE_NOTIFICATION_CONTENT_WHILE_LOCKED QStringLiteral("HideNotificationContentWhileLocked")
#define PROP_ENABLE_LAUNCHER_WHILE_LOCKED      QStringLiteral("EnableLauncherWhileLocked")
#define PROP_FAILED_FINGERPRINT_LOGINS         QStringLiteral("FailedFingerprintLogins")
#define PROP_FAILED_LOGINS                     QStringLiteral("FailedLogins")
#define PROP_INPUT_SOURCES                     QStringLiteral("InputSources")
#define PROP_LICENSE_ACCEPTED                  QStringLiteral("LicenseAccepted")
#define PROP_LICENSE_BASE_PATH                 QStringLiteral("LicenseBasePath")
#define PROP_MOUSE_CURSOR_SPEED                QStringLiteral("MouseCursorSpeed")
#define PROP_MOUSE_DOUBLE_CLICK_SPEED          QStringLiteral("MouseDoubleClickSpeed")
#define PROP_MOUSE_PRIMARY_BUTTON              QStringLiteral("MousePrimaryButton")
#define PROP_MOUSE_SCROLL_SPEED                QStringLiteral("MouseScrollSpeed")
#define PROP_PASSWORD_DISPLAY_HINT             QStringLiteral("PasswordDisplayHint")
#define PROP_PINCODE_PROMPT_MANAGER            QStringLiteral("PinCodePromptManager")
#define PROP_PINCODE_LENGTH                    QStringLiteral("PinCodeLength")
#define PROP_REAL_NAME                         QStringLiteral("RealName")
#define PROP_STATS_WELCOME_SCREEN              QStringLiteral("StatsWelcomeScreen")
#define PROP_TOUCHPAD_CURSOR_SPEED             QStringLiteral("TouchpadCursorSpeed")
#define PROP_TOUCHPAD_DISABLE_WHILE_TYPING     QStringLiteral("TouchpadDisableWhileTyping")
#define PROP_TOUCHPAD_DISABLE_WITH_MOUSE       QStringLiteral("TouchpadDisableWithMouse")
#define PROP_TOUCHPAD_DOUBLE_CLICK_SPEED       QStringLiteral("TouchpadDoubleClickSpeed")
#define PROP_TOUCHPAD_PRIMARY_BUTTON           QStringLiteral("TouchpadPrimaryButton")
#define PROP_TOUCHPAD_SCROLL_SPEED             QStringLiteral("TouchpadScrollSpeed")
#define PROP_TOUCHPAD_TAP_TO_CLICK             QStringLiteral("TouchpadTapToClick")
#define PROP_TOUCHPAD_TWO_FINGER_SCROLL        QStringLiteral("TouchpadTwoFingerScroll")

using StringMap = QMap<QString,QString>;
using StringMapList = QList<StringMap>;
Q_DECLARE_METATYPE(StringMapList)


QVariant primaryButtonConverter(const QVariant &value)
{
    QString stringValue = value.toString();
    if (stringValue == QLatin1String("left")) {
        return QVariant::fromValue(0);
    } else if (stringValue == QLatin1String("right")) {
        return QVariant::fromValue(1); // Mir is less clear on this -- any non-zero value is the same
    } else {
        return QVariant::fromValue(0); // default to left
    }
}

AccountsService::AccountsService(QObject* parent, const QString &user)
    : QObject(parent)
    , m_defaultPinPromptManager("PinPrompt.qml")
    , m_service(new AccountsServiceDBusAdaptor(this))
{
    m_syscompInput = new QDBusInterface(QStringLiteral("com.lomiri.SystemCompositor.Input"),
                                        QStringLiteral("/com/lomiri/SystemCompositor/Input"),
                                        QStringLiteral("com.lomiri.SystemCompositor.Input"),
                                        QDBusConnection::SM_BUSNAME(), this);

    connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
    connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);

    #ifdef ENABLE_UBUNTU_ACCOUNTSSERVICE
        registerProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE, QStringLiteral("backgroundFileChanged"));
        registerProperty(IFACE_ACCOUNTS_USER, PROP_INPUT_SOURCES, QStringLiteral("keymapsChanged"));
    #else
        registerProperty(IFACE_LOMIRI, PROP_BACKGROUND_FILE, QStringLiteral("backgroundFileChanged"));
        registerProperty(IFACE_LOMIRI, PROP_INPUT_SOURCES, QStringLiteral("keymapsChanged"));
    #endif

    registerProperty(IFACE_ACCOUNTS_USER, PROP_EMAIL, QStringLiteral("emailChanged"));
    registerProperty(IFACE_ACCOUNTS_USER, PROP_REAL_NAME, QStringLiteral("realNameChanged"));
    registerProperty(IFACE_UBUNTU_SECURITY, PROP_PINCODE_PROMPT_MANAGER, QStringLiteral("pinCodePromptManagerChanged"));
    registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_FINGERPRINT_IDENTIFICATION, QStringLiteral("enableFingerprintIdentificationChanged"));
    registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED, QStringLiteral("enableLauncherWhileLockedChanged"));
    registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED, QStringLiteral("enableIndicatorsWhileLockedChanged"));
    registerProperty(IFACE_UBUNTU_SECURITY, PROP_HIDE_NOTIFICATION_CONTENT_WHILE_LOCKED, QStringLiteral("hideNotificationContentWhileLocked"));
    registerProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT, QStringLiteral("passwordDisplayHintChanged"));
    registerProperty(IFACE_UBUNTU_SECURITY, PROP_PINCODE_LENGTH, QStringLiteral("pincodeLengthChanged"));
    registerProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN, QStringLiteral("statsWelcomeScreenChanged"));
    registerProperty(IFACE_LOMIRI, PROP_DEMO_EDGES, QStringLiteral("demoEdgesChanged"));
    registerProperty(IFACE_LOMIRI, PROP_DEMO_EDGES_COMPLETED, QStringLiteral("demoEdgesCompletedChanged"));
    registerProperty(IFACE_LOMIRI_PRIVATE, PROP_FAILED_FINGERPRINT_LOGINS, QStringLiteral("failedFingerprintLoginsChanged"));
    registerProperty(IFACE_LOMIRI_PRIVATE, PROP_FAILED_LOGINS, QStringLiteral("failedLoginsChanged"));

    registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_CURSOR_SPEED,
                  m_syscompInput, QStringLiteral("setMouseCursorSpeed"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_DOUBLE_CLICK_SPEED,
                  m_syscompInput, QStringLiteral("setMouseDoubleClickSpeed"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_PRIMARY_BUTTON,
                  m_syscompInput, QStringLiteral("setMousePrimaryButton"),
                  primaryButtonConverter);
    registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_SCROLL_SPEED,
                  m_syscompInput, QStringLiteral("setMouseScrollSpeed"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_CURSOR_SPEED,
                  m_syscompInput, QStringLiteral("setTouchpadCursorSpeed"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_SCROLL_SPEED,
                  m_syscompInput, QStringLiteral("setTouchpadScrollSpeed"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DISABLE_WHILE_TYPING,
                  m_syscompInput, QStringLiteral("setTouchpadDisableWhileTyping"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DISABLE_WITH_MOUSE,
                  m_syscompInput, QStringLiteral("setTouchpadDisableWithMouse"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DOUBLE_CLICK_SPEED,
                  m_syscompInput, QStringLiteral("setTouchpadDoubleClickSpeed"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_PRIMARY_BUTTON,
                  m_syscompInput, QStringLiteral("setTouchpadPrimaryButton"),
                  primaryButtonConverter);
    registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TAP_TO_CLICK,
                  m_syscompInput, QStringLiteral("setTouchpadTapToClick"));
    registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
                  m_syscompInput, QStringLiteral("setTouchpadTwoFingerScroll"));

    setUser(!user.isEmpty() ? user : QString::fromUtf8(g_get_user_name()));
}

QString AccountsService::user() const
{
    return m_user;
}

void AccountsService::setUser(const QString &user)
{
    if (user.isEmpty() || m_user == user)
        return;

    bool wasEmpty = m_user.isEmpty();

    m_user = user;
    Q_EMIT userChanged();

    // Do the first update synchronously, as a cheap way to block rendering
    // until we have the right values on bootup.
    refresh(!wasEmpty);
}

bool AccountsService::demoEdges() const
{
    auto value = getProperty(IFACE_LOMIRI, PROP_DEMO_EDGES);
    return value.toBool();
}

void AccountsService::setDemoEdges(bool demoEdges)
{
    setProperty(IFACE_LOMIRI, PROP_DEMO_EDGES, demoEdges);
}

QStringList AccountsService::demoEdgesCompleted() const
{
    auto value = getProperty(IFACE_LOMIRI, PROP_DEMO_EDGES_COMPLETED);
    return value.toStringList();
}

void AccountsService::markDemoEdgeCompleted(const QString &edge)
{
    auto currentList = demoEdgesCompleted();
    if (!currentList.contains(edge)) {
        setProperty(IFACE_LOMIRI, PROP_DEMO_EDGES_COMPLETED, currentList << edge);
    }
}

bool AccountsService::enableFingerprintIdentification() const
{
    auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_FINGERPRINT_IDENTIFICATION);
    return value.toBool();
}

bool AccountsService::enableLauncherWhileLocked() const
{
    auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED);
    return value.toBool();
}

bool AccountsService::enableIndicatorsWhileLocked() const
{
    auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED);
    return value.toBool();
}

bool AccountsService::hideNotificationContentWhileLocked() const
{
    auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_HIDE_NOTIFICATION_CONTENT_WHILE_LOCKED);
    return value.toBool();
}

QString AccountsService::backgroundFile() const
{
    #ifdef ENABLE_UBUNTU_ACCOUNTSSERVICE
        auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE);
    #else
        auto value = getProperty(IFACE_LOMIRI, PROP_BACKGROUND_FILE);
    #endif

    return value.toString();
}

bool AccountsService::statsWelcomeScreen() const
{
    auto value = getProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN);
    return value.toBool();
}

AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
{
    auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT);
    return (PasswordDisplayHint)value.toInt();
}

QString AccountsService::pinCodePromptManager() const
{

    auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_PINCODE_PROMPT_MANAGER);
    if (!value.isValid()) {
        return m_defaultPinPromptManager;
    } else {
        QString file = value.toString() + ".qml";
        if (file == m_defaultPinPromptManager) {
            return m_defaultPinPromptManager;
        } else if (!QFile::exists(qmlDirectory() + "/Greeter/" + file)) {
            qWarning() << "failed to load pinCodePromptManager " << file << ", fallback to " << m_defaultPinPromptManager;
            return m_defaultPinPromptManager;
        } else {
            return file;
        }
    }
}

QString AccountsService::defaultPinCodePromptManager() const
{
    return m_defaultPinPromptManager;
}

uint AccountsService::pincodeLength() const
{
    return getProperty(IFACE_UBUNTU_SECURITY, PROP_PINCODE_LENGTH).toUInt();
}

QString AccountsService::realName() const
{
    auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_REAL_NAME);
    return value.toString();
}

void AccountsService::setRealName(const QString &realName)
{
    setProperty(IFACE_ACCOUNTS_USER, PROP_REAL_NAME, realName);
}

QString AccountsService::email() const
{
    auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_EMAIL);
    return value.toString();
}

void AccountsService::setEmail(const QString &email)
{
    setProperty(IFACE_ACCOUNTS_USER, PROP_EMAIL, email);
}

QStringList AccountsService::keymaps() const
{
    #ifdef ENABLE_UBUNTU_ACCOUNTSSERVICE
        auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_INPUT_SOURCES);
    #else
        auto value = getProperty(IFACE_LOMIRI, PROP_INPUT_SOURCES);
    #endif

    QDBusArgument arg = value.value<QDBusArgument>();
    StringMapList maps = qdbus_cast<StringMapList>(arg);
    QStringList simplifiedMaps;

    Q_FOREACH(const StringMap &map, maps) {
        Q_FOREACH(const QString &entry, map) {
            simplifiedMaps.append(entry);
        }
    }

    if (!simplifiedMaps.isEmpty()) {
        return simplifiedMaps;
    }

    return {QStringLiteral("us")};
}

void AccountsService::setKeymaps(const QStringList &keymaps)
{
    if (keymaps.isEmpty()) {
        qWarning() << "Setting empty keymaps is not supported";
        return;
    }

    StringMapList result;
    Q_FOREACH(const QString &keymap, keymaps) {
        StringMap map;
        map.insert(QStringLiteral("xkb"), keymap);
        result.append(map);
    }

    #ifdef ENABLE_UBUNTU_ACCOUNTSSERVICE
        setProperty(IFACE_ACCOUNTS_USER, PROP_INPUT_SOURCES, QVariant::fromValue(result));
    #else
        setProperty(IFACE_LOMIRI, PROP_INPUT_SOURCES, QVariant::fromValue(result));
    #endif

    Q_EMIT keymapsChanged();
}

uint AccountsService::failedFingerprintLogins() const
{
    return getProperty(IFACE_LOMIRI_PRIVATE, PROP_FAILED_FINGERPRINT_LOGINS).toUInt();
}

void AccountsService::setFailedFingerprintLogins(uint failedFingerprintLogins)
{
    setProperty(IFACE_LOMIRI_PRIVATE, PROP_FAILED_FINGERPRINT_LOGINS, failedFingerprintLogins);
}

uint AccountsService::failedLogins() const
{
    return getProperty(IFACE_LOMIRI_PRIVATE, PROP_FAILED_LOGINS).toUInt();
}

void AccountsService::setFailedLogins(uint failedLogins)
{
    setProperty(IFACE_LOMIRI_PRIVATE, PROP_FAILED_LOGINS, failedLogins);
}

// ====================================================
// Everything below this line is generic helper methods
// ====================================================

void AccountsService::emitChangedForProperty(const QString &interface, const QString &property)
{
    QString signalName = m_properties[interface][property].signal;
    QMetaObject::invokeMethod(this, signalName.toUtf8().data());
}

QVariant AccountsService::getProperty(const QString &interface, const QString &property) const
{
    return m_properties[interface][property].value;
}

void AccountsService::setProperty(const QString &interface, const QString &property, const QVariant &value)
{
    if (m_properties[interface][property].value != value) {
        m_properties[interface][property].value = value;
        m_service->setUserPropertyAsync(m_user, interface, property, value);
        emitChangedForProperty(interface, property);
    }
}

void AccountsService::updateCache(const QString &interface, const QString &property, const QVariant &value)
{
    PropertyInfo &info = m_properties[interface][property];

    if (info.proxyInterface) {
        QVariant finalValue;
        if (info.proxyConverter) {
            finalValue = info.proxyConverter(value);
        } else {
            finalValue = value;
        }
        info.proxyInterface->asyncCall(info.proxyMethod, finalValue);
        return; // don't bother saving a copy
    }

    if (info.value != value) {
        info.value = value;
        emitChangedForProperty(interface, property);
    }
}

void AccountsService::updateProperty(const QString &interface, const QString &property)
{
    QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
                                                                    interface,
                                                                    property);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);

    connect(watcher, &QDBusPendingCallWatcher::finished,
            this, [this, interface, property](QDBusPendingCallWatcher* watcher) {

        QDBusPendingReply<QVariant> reply = *watcher;
        watcher->deleteLater();
        if (reply.isError()) {
            qWarning() << "Failed to get '" << property << "' property:" << reply.error().message();
            return;
        }

        updateCache(interface, property, reply.value());
    });
}

void AccountsService::updateAllProperties(const QString &interface, bool async)
{
    QDBusPendingCall pendingReply = m_service->getAllPropertiesAsync(m_user,
                                                                     interface);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);

    connect(watcher, &QDBusPendingCallWatcher::finished,
            this, [this, interface](QDBusPendingCallWatcher* watcher) {

        QDBusPendingReply< QHash<QString, QVariant> > reply = *watcher;
        watcher->deleteLater();
        if (reply.isError()) {
            qWarning() << "Failed to get all properties for" << interface << ":" << reply.error().message();
            return;
        }

        auto valueHash = reply.value();
        auto i = valueHash.constBegin();
        while (i != valueHash.constEnd()) {
            updateCache(interface, i.key(), i.value());
            ++i;
        }
    });
    if (!async) {
        watcher->waitForFinished();
    }
}

void AccountsService::registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter)
{
    registerProperty(interface, property, nullptr);

    m_properties[interface][property].proxyInterface = iface;
    m_properties[interface][property].proxyMethod = method;
    m_properties[interface][property].proxyConverter = converter;
}

void AccountsService::registerProperty(const QString &interface, const QString &property, const QString &signal)
{
    m_properties[interface][property] = PropertyInfo();
    m_properties[interface][property].signal = signal;
}

void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
{
    if (m_user != user) {
        return;
    }

    auto propHash = m_properties.value(interface);
    auto i = propHash.constBegin();
    while (i != propHash.constEnd()) {
        if (changed.contains(i.key())) {
            updateProperty(interface, i.key());
        }
        ++i;
    }
}

void AccountsService::onMaybeChanged(const QString &user)
{
    if (m_user != user) {
        return;
    }

    // Any of the standard properties might have changed!
    auto propHash = m_properties.value(IFACE_ACCOUNTS_USER);
    auto i = propHash.constBegin();
    while (i != propHash.constEnd()) {
        updateProperty(IFACE_ACCOUNTS_USER, i.key());
        ++i;
    }
}

void AccountsService::refresh(bool async)
{
    auto i = m_properties.constBegin();
    while (i != m_properties.constEnd()) {
        updateAllProperties(i.key(), async);
        ++i;
    }
}