2 * Copyright (C) 2013-2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "AccountsService.h"
18#include "AccountsServiceDBusAdaptor.h"
20#include <QDBusInterface>
27#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
28#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
29#define IFACE_UBUNTU_INPUT QStringLiteral("com.ubuntu.AccountsService.Input")
30#define IFACE_UBUNTU_SECURITY QStringLiteral("com.ubuntu.AccountsService.SecurityPrivacy")
31#define IFACE_UBUNTU_SECURITY_OLD QStringLiteral("com.ubuntu.touch.AccountsService.SecurityPrivacy")
32#define IFACE_UNITY QStringLiteral("com.canonical.unity.AccountsService")
33#define IFACE_UNITY_PRIVATE QStringLiteral("com.canonical.unity.AccountsService.Private")
35#define PROP_BACKGROUND_FILE QStringLiteral("BackgroundFile")
36#define PROP_DEMO_EDGES QStringLiteral("demo-edges")
37#define PROP_DEMO_EDGES_COMPLETED QStringLiteral("DemoEdgesCompleted")
38#define PROP_EMAIL QStringLiteral("Email")
39#define PROP_ENABLE_FINGERPRINT_IDENTIFICATION QStringLiteral("EnableFingerprintIdentification")
40#define PROP_ENABLE_INDICATORS_WHILE_LOCKED QStringLiteral("EnableIndicatorsWhileLocked")
41#define PROP_ENABLE_LAUNCHER_WHILE_LOCKED QStringLiteral("EnableLauncherWhileLocked")
42#define PROP_FAILED_FINGERPRINT_LOGINS QStringLiteral("FailedFingerprintLogins")
43#define PROP_FAILED_LOGINS QStringLiteral("FailedLogins")
44#define PROP_INPUT_SOURCES QStringLiteral("InputSources")
45#define PROP_LICENSE_ACCEPTED QStringLiteral("LicenseAccepted")
46#define PROP_LICENSE_BASE_PATH QStringLiteral("LicenseBasePath")
47#define PROP_MOUSE_CURSOR_SPEED QStringLiteral("MouseCursorSpeed")
48#define PROP_MOUSE_DOUBLE_CLICK_SPEED QStringLiteral("MouseDoubleClickSpeed")
49#define PROP_MOUSE_PRIMARY_BUTTON QStringLiteral("MousePrimaryButton")
50#define PROP_MOUSE_SCROLL_SPEED QStringLiteral("MouseScrollSpeed")
51#define PROP_PASSWORD_DISPLAY_HINT QStringLiteral("PasswordDisplayHint")
52#define PROP_REAL_NAME QStringLiteral("RealName")
53#define PROP_STATS_WELCOME_SCREEN QStringLiteral("StatsWelcomeScreen")
54#define PROP_TOUCHPAD_CURSOR_SPEED QStringLiteral("TouchpadCursorSpeed")
55#define PROP_TOUCHPAD_DISABLE_WHILE_TYPING QStringLiteral("TouchpadDisableWhileTyping")
56#define PROP_TOUCHPAD_DISABLE_WITH_MOUSE QStringLiteral("TouchpadDisableWithMouse")
57#define PROP_TOUCHPAD_DOUBLE_CLICK_SPEED QStringLiteral("TouchpadDoubleClickSpeed")
58#define PROP_TOUCHPAD_PRIMARY_BUTTON QStringLiteral("TouchpadPrimaryButton")
59#define PROP_TOUCHPAD_SCROLL_SPEED QStringLiteral("TouchpadScrollSpeed")
60#define PROP_TOUCHPAD_TAP_TO_CLICK QStringLiteral("TouchpadTapToClick")
61#define PROP_TOUCHPAD_TWO_FINGER_SCROLL QStringLiteral("TouchpadTwoFingerScroll")
63using StringMap = QMap<QString,QString>;
64using StringMapList = QList<StringMap>;
65Q_DECLARE_METATYPE(StringMapList)
68QVariant primaryButtonConverter(const QVariant &value)
70 QString stringValue = value.toString();
71 if (stringValue == "left") {
72 return QVariant::fromValue(0);
73 } else if (stringValue == "right") {
74 return QVariant::fromValue(1); // Mir is less clear on this -- any non-zero value is the same
76 return QVariant::fromValue(0); // default to left
80AccountsService::AccountsService(QObject* parent, const QString &user)
82 , m_service(new AccountsServiceDBusAdaptor(this))
84 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
85 QStringLiteral("/com/canonical/Unity/Input"),
86 QStringLiteral("com.canonical.Unity.Input"),
87 QDBusConnection::SM_BUSNAME(), this);
89 connect(m_service, &AccountsServiceDBusAdaptor::propertiesChanged, this, &AccountsService::onPropertiesChanged);
90 connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged, this, &AccountsService::onMaybeChanged);
92 registerProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE, QStringLiteral("backgroundFileChanged"));
93 registerProperty(IFACE_ACCOUNTS_USER, PROP_EMAIL, QStringLiteral("emailChanged"));
94 registerProperty(IFACE_ACCOUNTS_USER, PROP_REAL_NAME, QStringLiteral("realNameChanged"));
95 registerProperty(IFACE_ACCOUNTS_USER, PROP_INPUT_SOURCES, QStringLiteral("keymapsChanged"));
96 registerProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED, QStringLiteral("hereEnabledChanged"));
97 registerProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH, QStringLiteral("hereLicensePathChanged"));
98 registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_FINGERPRINT_IDENTIFICATION, QStringLiteral("enableFingerprintIdentificationChanged"));
99 registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED, QStringLiteral("enableLauncherWhileLockedChanged"));
100 registerProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED, QStringLiteral("enableIndicatorsWhileLockedChanged"));
101 registerProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT, QStringLiteral("passwordDisplayHintChanged"));
102 registerProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN, QStringLiteral("statsWelcomeScreenChanged"));
103 registerProperty(IFACE_UNITY, PROP_DEMO_EDGES, QStringLiteral("demoEdgesChanged"));
104 registerProperty(IFACE_UNITY, PROP_DEMO_EDGES_COMPLETED, QStringLiteral("demoEdgesCompletedChanged"));
105 registerProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_FINGERPRINT_LOGINS, QStringLiteral("failedFingerprintLoginsChanged"));
106 registerProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS, QStringLiteral("failedLoginsChanged"));
108 registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_CURSOR_SPEED,
109 m_unityInput, QStringLiteral("setMouseCursorSpeed"));
110 registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_DOUBLE_CLICK_SPEED,
111 m_unityInput, QStringLiteral("setMouseDoubleClickSpeed"));
112 registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_PRIMARY_BUTTON,
113 m_unityInput, QStringLiteral("setMousePrimaryButton"),
114 primaryButtonConverter);
115 registerProxy(IFACE_UBUNTU_INPUT, PROP_MOUSE_SCROLL_SPEED,
116 m_unityInput, QStringLiteral("setMouseScrollSpeed"));
117 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_CURSOR_SPEED,
118 m_unityInput, QStringLiteral("setTouchpadCursorSpeed"));
119 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_SCROLL_SPEED,
120 m_unityInput, QStringLiteral("setTouchpadScrollSpeed"));
121 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DISABLE_WHILE_TYPING,
122 m_unityInput, QStringLiteral("setTouchpadDisableWhileTyping"));
123 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DISABLE_WITH_MOUSE,
124 m_unityInput, QStringLiteral("setTouchpadDisableWithMouse"));
125 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_DOUBLE_CLICK_SPEED,
126 m_unityInput, QStringLiteral("setTouchpadDoubleClickSpeed"));
127 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_PRIMARY_BUTTON,
128 m_unityInput, QStringLiteral("setTouchpadPrimaryButton"),
129 primaryButtonConverter);
130 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TAP_TO_CLICK,
131 m_unityInput, QStringLiteral("setTouchpadTapToClick"));
132 registerProxy(IFACE_UBUNTU_INPUT, PROP_TOUCHPAD_TWO_FINGER_SCROLL,
133 m_unityInput, QStringLiteral("setTouchpadTwoFingerScroll"));
135 setUser(!user.isEmpty() ? user : QString::fromUtf8(g_get_user_name()));
138QString AccountsService::user() const
143void AccountsService::setUser(const QString &user)
145 if (user.isEmpty() || m_user == user)
148 bool wasEmpty = m_user.isEmpty();
151 Q_EMIT userChanged();
153 // Do the first update synchronously, as a cheap way to block rendering
154 // until we have the right values on bootup.
158bool AccountsService::demoEdges() const
160 auto value = getProperty(IFACE_UNITY, PROP_DEMO_EDGES);
161 return value.toBool();
164void AccountsService::setDemoEdges(bool demoEdges)
166 setProperty(IFACE_UNITY, PROP_DEMO_EDGES, demoEdges);
169QStringList AccountsService::demoEdgesCompleted() const
171 auto value = getProperty(IFACE_UNITY, PROP_DEMO_EDGES_COMPLETED);
172 return value.toStringList();
175void AccountsService::markDemoEdgeCompleted(const QString &edge)
177 auto currentList = demoEdgesCompleted();
178 if (!currentList.contains(edge)) {
179 setProperty(IFACE_UNITY, PROP_DEMO_EDGES_COMPLETED, currentList << edge);
183bool AccountsService::enableFingerprintIdentification() const
185 auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_FINGERPRINT_IDENTIFICATION);
186 return value.toBool();
189bool AccountsService::enableLauncherWhileLocked() const
191 auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_LAUNCHER_WHILE_LOCKED);
192 return value.toBool();
195bool AccountsService::enableIndicatorsWhileLocked() const
197 auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_ENABLE_INDICATORS_WHILE_LOCKED);
198 return value.toBool();
201QString AccountsService::backgroundFile() const
203 auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_BACKGROUND_FILE);
204 return value.toString();
207bool AccountsService::statsWelcomeScreen() const
209 auto value = getProperty(IFACE_UBUNTU_SECURITY_OLD, PROP_STATS_WELCOME_SCREEN);
210 return value.toBool();
213AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
215 auto value = getProperty(IFACE_UBUNTU_SECURITY, PROP_PASSWORD_DISPLAY_HINT);
216 return (PasswordDisplayHint)value.toInt();
219bool AccountsService::hereEnabled() const
221 auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED);
222 return value.toBool();
225void AccountsService::setHereEnabled(bool enabled)
227 setProperty(IFACE_LOCATION_HERE, PROP_LICENSE_ACCEPTED, enabled);
230QString AccountsService::hereLicensePath() const
232 auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH);
233 QString hereLicensePath = value.toString();
234 if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
235 hereLicensePath = QStringLiteral("");
236 return hereLicensePath;
239bool AccountsService::hereLicensePathValid() const
241 auto value = getProperty(IFACE_LOCATION_HERE, PROP_LICENSE_BASE_PATH);
242 return !value.toString().isNull();
245QString AccountsService::realName() const
247 auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_REAL_NAME);
248 return value.toString();
251void AccountsService::setRealName(const QString &realName)
253 setProperty(IFACE_ACCOUNTS_USER, PROP_REAL_NAME, realName);
256QString AccountsService::email() const
258 auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_EMAIL);
259 return value.toString();
262void AccountsService::setEmail(const QString &email)
264 setProperty(IFACE_ACCOUNTS_USER, PROP_EMAIL, email);
267QStringList AccountsService::keymaps() const
269 auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_INPUT_SOURCES);
270 QDBusArgument arg = value.value<QDBusArgument>();
271 StringMapList maps = qdbus_cast<StringMapList>(arg);
272 QStringList simplifiedMaps;
274 Q_FOREACH(const StringMap &map, maps) {
275 Q_FOREACH(const QString &entry, map) {
276 simplifiedMaps.append(entry);
280 if (!simplifiedMaps.isEmpty()) {
281 return simplifiedMaps;
284 return {QStringLiteral("us")};
287uint AccountsService::failedFingerprintLogins() const
289 return getProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_FINGERPRINT_LOGINS).toUInt();
292void AccountsService::setFailedFingerprintLogins(uint failedFingerprintLogins)
294 setProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_FINGERPRINT_LOGINS, failedFingerprintLogins);
297uint AccountsService::failedLogins() const
299 return getProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS).toUInt();
302void AccountsService::setFailedLogins(uint failedLogins)
304 setProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_LOGINS, failedLogins);
307// ====================================================
308// Everything below this line is generic helper methods
309// ====================================================
311void AccountsService::emitChangedForProperty(const QString &interface, const QString &property)
313 QString signalName = m_properties[interface][property].signal;
314 QMetaObject::invokeMethod(this, signalName.toUtf8().data());
317QVariant AccountsService::getProperty(const QString &interface, const QString &property) const
319 return m_properties[interface][property].value;
322void AccountsService::setProperty(const QString &interface, const QString &property, const QVariant &value)
324 if (m_properties[interface][property].value != value) {
325 m_properties[interface][property].value = value;
326 m_service->setUserPropertyAsync(m_user, interface, property, value);
327 emitChangedForProperty(interface, property);
331void AccountsService::updateCache(const QString &interface, const QString &property, const QVariant &value)
333 PropertyInfo &info = m_properties[interface][property];
335 if (info.proxyInterface) {
337 if (info.proxyConverter) {
338 finalValue = info.proxyConverter(value);
342 info.proxyInterface->asyncCall(info.proxyMethod, finalValue);
343 return; // don't bother saving a copy
346 if (info.value != value) {
348 emitChangedForProperty(interface, property);
352void AccountsService::updateProperty(const QString &interface, const QString &property)
354 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
357 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
359 connect(watcher, &QDBusPendingCallWatcher::finished,
360 this, [this, interface, property](QDBusPendingCallWatcher* watcher) {
362 QDBusPendingReply<QVariant> reply = *watcher;
363 watcher->deleteLater();
364 if (reply.isError()) {
365 qWarning() << "Failed to get '" << property << "' property:" << reply.error().message();
369 updateCache(interface, property, reply.value());
373void AccountsService::updateAllProperties(const QString &interface, bool async)
375 QDBusPendingCall pendingReply = m_service->getAllPropertiesAsync(m_user,
377 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
379 connect(watcher, &QDBusPendingCallWatcher::finished,
380 this, [this, interface](QDBusPendingCallWatcher* watcher) {
382 QDBusPendingReply< QHash<QString, QVariant> > reply = *watcher;
383 watcher->deleteLater();
384 if (reply.isError()) {
385 qWarning() << "Failed to get all properties for" << interface << ":" << reply.error().message();
389 auto valueHash = reply.value();
390 auto i = valueHash.constBegin();
391 while (i != valueHash.constEnd()) {
392 updateCache(interface, i.key(), i.value());
397 watcher->waitForFinished();
401void AccountsService::registerProxy(const QString &interface, const QString &property, QDBusInterface *iface, const QString &method, ProxyConverter converter)
403 registerProperty(interface, property, nullptr);
405 m_properties[interface][property].proxyInterface = iface;
406 m_properties[interface][property].proxyMethod = method;
407 m_properties[interface][property].proxyConverter = converter;
410void AccountsService::registerProperty(const QString &interface, const QString &property, const QString &signal)
412 m_properties[interface][property] = PropertyInfo();
413 m_properties[interface][property].signal = signal;
416void AccountsService::onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
418 if (m_user != user) {
422 auto propHash = m_properties.value(interface);
423 auto i = propHash.constBegin();
424 while (i != propHash.constEnd()) {
425 if (changed.contains(i.key())) {
426 updateProperty(interface, i.key());
432void AccountsService::onMaybeChanged(const QString &user)
434 if (m_user != user) {
438 // Any of the standard properties might have changed!
439 auto propHash = m_properties.value(IFACE_ACCOUNTS_USER);
440 auto i = propHash.constBegin();
441 while (i != propHash.constEnd()) {
442 updateProperty(IFACE_ACCOUNTS_USER, i.key());
447void AccountsService::refresh(bool async)
449 auto i = m_properties.constBegin();
450 while (i != m_properties.constEnd()) {
451 updateAllProperties(i.key(), async);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list