on bionic help sign in
unity8/tests/plugins/AccountsService/PropertiesServer.cpp
142 lines 5.7 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>
28#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
30PropertiesServer::PropertiesServer(QObject *parent)
31 : QObject(parent)
33 qDBusRegisterMetaType<QList<QVariantMap>>();
34 qDBusRegisterMetaType<StringMap>();
35 qDBusRegisterMetaType<StringMapList>();
36 Reset();
39QDBusVariant PropertiesServer::Get(const QString &interface, const QString &property) const
41 if (m_properties.contains(interface) && m_properties[interface].contains(property)) {
42 return QDBusVariant(m_properties[interface][property]);
43 } else {
44 sendErrorReply(QDBusError::InvalidArgs, "Bad interface or property");
45 return QDBusVariant(QVariant());
46 }
49QVariantMap PropertiesServer::GetAll(const QString &interface) const
51 if (m_properties.contains(interface)) {
52 return m_properties[interface];
53 } else {
54 sendErrorReply(QDBusError::InvalidArgs, "Bad interface");
55 return QVariantMap();
56 }
59void PropertiesServer::Set(const QString &interface, const QString &property, const QDBusVariant &variant)
61 QVariant newValue = variant.variant();
63 if (interface == IFACE_ACCOUNTS_USER) {
64 sendErrorReply(QDBusError::InvalidArgs, QStringLiteral("Property is not writable"));
65 return;
66 }
68 internalSet(interface, property, newValue);
71void PropertiesServer::SetBackgroundFile(const QString &backgroundFile)
73 internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("BackgroundFile"), backgroundFile);
76void PropertiesServer::SetEmail(const QString &email)
78 internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("Email"), email);
81void PropertiesServer::SetInputSources(const StringMapList &inputSources)
83 internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("InputSources"), QVariant::fromValue(inputSources));
86void PropertiesServer::SetRealName(const QString &realName)
88 internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("RealName"), realName);
91void PropertiesServer::internalSet(const QString &interface, const QString &property, const QVariant &variant)
93 QVariant newValue = variant;
95 if (m_properties[interface].contains(property)) {
96 QVariant& oldValue = m_properties[interface][property];
97 if (oldValue != newValue) {
98 // complex types have an extra layer of wrapping via QDBusArgument
99 if (interface == QStringLiteral("com.canonical.unity.AccountsService") &&
100 property == QStringLiteral("LauncherItems")) {
101 newValue = QVariant::fromValue(qdbus_cast<QList<QVariantMap>>(newValue.value<QDBusArgument>()));
102 }
104 oldValue = newValue;
106 // Special case for user properties.
107 if (interface == IFACE_ACCOUNTS_USER) {
108 Q_EMIT Changed();
109 } else {
110 QVariantMap propertyChanges;
111 propertyChanges[property] = newValue;
112 Q_EMIT PropertiesChanged(interface, propertyChanges, QStringList());
114 // FIXME: Here to replicate current behaviour
115 // Not sure why accounts-service is triggering Changed when we're
116 // emitting PropertyChanges from org.freedesktop.DBus.Properties as well.
117 Q_EMIT Changed();
118 }
119 }
120 } else {
121 sendErrorReply(QDBusError::InvalidArgs, "Bad interface or property");
122 }
125void PropertiesServer::Reset()
127 m_properties["com.canonical.unity.AccountsService"]["demo-edges"] = false;
128 m_properties["com.canonical.unity.AccountsService"]["DemoEdgesCompleted"] = QStringList();
129 m_properties["com.canonical.unity.AccountsService"]["LauncherItems"] = QVariant::fromValue(QList<QVariantMap>());
130 m_properties["com.canonical.unity.AccountsService.Private"]["FailedLogins"] = 0;
131 m_properties["com.ubuntu.touch.AccountsService.SecurityPrivacy"]["StatsWelcomeScreen"] = true;
132 m_properties["com.ubuntu.AccountsService.Input"]["MousePrimaryButton"] = "right";
133 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableLauncherWhileLocked"] = true;
134 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["EnableIndicatorsWhileLocked"] = true;
135 m_properties["com.ubuntu.AccountsService.SecurityPrivacy"]["PasswordDisplayHint"] = AccountsService::Keyboard;
136 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseAccepted"] = false;
137 m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseBasePath"] = "";
138 m_properties["org.freedesktop.Accounts.User"]["BackgroundFile"] = "";
139 m_properties["org.freedesktop.Accounts.User"]["Email"] = "";
140 m_properties["org.freedesktop.Accounts.User"]["InputSources"] = QVariant::fromValue(StringMapList());
141 m_properties["org.freedesktop.Accounts.User"]["RealName"] = "";