on 75b8c19 help sign in
unity8/tests/plugins/AccountsService/PropertiesServer.cpp
92 lines 3.9 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Michael Terry <michael.terry@canonical.com>
18 */
20#include "PropertiesServer.h"
21#include "AccountsService.h"
23// Qt
24#include <QDebug>
25#include <QDBusMessage>
26#include <QDBusMetaType>
28PropertiesServer::PropertiesServer(QObject *parent)
29 : QObject(parent)
31 qDBusRegisterMetaType<QList<QVariantMap>>();
32 Reset();
35QDBusVariant PropertiesServer::Get(const QString &interface, const QString &property)
37 if (m_properties[interface].contains(property)) {
38 return QDBusVariant(m_properties[interface][property]);
39 } else {
40 sendErrorReply(QDBusError::InvalidArgs, "Bad interface or property");
41 return QDBusVariant(QVariant());
42 }
45void PropertiesServer::Set(const QString &interface, const QString &property, const QDBusVariant &variant)
47 QVariant newValue = variant.variant();
49 if (m_properties[interface].contains(property)) {
50 QVariant& oldValue = m_properties[interface][property];
51 if (oldValue != newValue) {
52 // complex types have an extra layer of wrapping via QDBusArgument
53 if (interface == QStringLiteral("com.canonical.unity.AccountsService") &&
54 property == QStringLiteral("LauncherItems")) {
55 newValue = QVariant::fromValue(qdbus_cast<QList<QVariantMap>>(newValue.value<QDBusArgument>()));
56 }
58 oldValue = newValue;
60 // Special case for Background file.
61 if (interface == "org.freedesktop.Accounts.User" && property == "BackgroundFile") {
62 Q_EMIT Changed();
63 } else {
64 QVariantMap propertyChanges;
65 propertyChanges[property] = newValue;
66 Q_EMIT PropertiesChanged(interface, propertyChanges, QStringList());
68 // FIXME: Here to replicate current behaviour
69 // Not sure why accounts-service is triggering Changed when we're
70 // emitting PropertyChanges from org.freedesktop.DBus.Properties as well.
71 Q_EMIT Changed();
72 }
73 }
74 } else {
75 sendErrorReply(QDBusError::InvalidArgs, "Bad interface or property");
76 }
79void PropertiesServer::Reset()
81 m_properties["com.canonical.unity.AccountsService"]["demo-edges"] = false;
82 m_properties["com.canonical.unity.AccountsService"]["DemoEdgesCompleted"] = QStringList();
83 m_properties["com.canonical.unity.AccountsService"]["LauncherItems"] = QVariant::fromValue(QList<QVariantMap>());
84 m_properties["com.canonical.unity.AccountsService.Private"]["FailedLogins"] = 0;
85 m_properties["com.ubuntu.touch.AccountsService.SecurityPrivacy"]["StatsWelcomeScreen"] = true;
86 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableLauncherWhileLocked"] = true;
87 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableIndicatorsWhileLocked"] = true;
88 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["PasswordDisplayHint"] = AccountsService::Keyboard;
89 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseAccepted"] = false;
90 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseBasePath"] = "";
91 m_properties["org.freedesktop.Accounts.User"]["BackgroundFile"] = "";