on xenial help sign in
Merge in wallpaper branch
8688555Michael Terry
Components/EdgeDemo.qml+2−2
@@ -40,7 +40,7 @@ Item {
40 }
40 }
41
41
42 function hideEdgeDemoInShell() {
42 function hideEdgeDemoInShell() {
43− AccountsService.setUserProperty(user, "demo-edges", false);
43+ AccountsService.demoEdges = false;
44 d.showEdgeDemo = false;
44 d.showEdgeDemo = false;
45 stopDemo();
45 stopDemo();
46 }
46 }
@@ -63,7 +63,7 @@ Item {
63 property QtObject bottomEdgeDemo
63 property QtObject bottomEdgeDemo
64 property QtObject leftEdgeDemo
64 property QtObject leftEdgeDemo
65 property QtObject finalEdgeDemo
65 property QtObject finalEdgeDemo
66− property bool showEdgeDemo: AccountsService.getUserProperty(user, "demo-edges")
66+ property bool showEdgeDemo: AccountsService.demoEdges
67
67
68 onShowEdgeDemoChanged: {
68 onShowEdgeDemoChanged: {
69 if (!d.overlay && d.showEdgeDemo) {
69 if (!d.overlay && d.showEdgeDemo) {
Greeter/GreeterContent.qml+19−2
@@ -15,6 +15,7 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18+import AccountsService 0.1
18import Ubuntu.Components 0.1
19import Ubuntu.Components 0.1
19import LightDM 0.1 as LightDM
20import LightDM 0.1 as LightDM
20import "../Components"
21import "../Components"
@@ -39,14 +40,30 @@ MouseArea {
39 color: "black"
40 color: "black"
40 }
41 }
41
42
43+ property url backgroundValue: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : shell.defaultBackground
44+ onBackgroundValueChanged: wallpaper.source = backgroundValue
45+
42 CrossFadeImage {
46 CrossFadeImage {
43 id: wallpaper
47 id: wallpaper
44−
45− source: shell.background
46 anchors.fill: parent
48 anchors.fill: parent
47 fadeInFirst: false
49 fadeInFirst: false
48 }
50 }
49
51
52+ // See Shell.qml's backgroundSettings treatment for why we need a separate
53+ // Image, but it boils down to avoiding binding loop detection.
54+ Image {
55+ source: wallpaper.source
56+ height: 0
57+ width: 0
58+ sourceSize.height: 0
59+ sourceSize.width: 0
60+ onStatusChanged: {
61+ if (status == Image.Error && source != shell.defaultBackground) {
62+ wallpaper.source = shell.defaultBackground
63+ }
64+ }
65+ }
66+
50 Rectangle {
67 Rectangle {
51 anchors.fill: parent
68 anchors.fill: parent
52 color: "black"
69 color: "black"
Greeter/GreeterEdgeDemo.qml+3−4
@@ -31,12 +31,11 @@ Item {
31 }
31 }
32
32
33 function hideEdgeDemoInShell() {
33 function hideEdgeDemoInShell() {
34− var user = LightDM.Users.data(greeter.currentIndex, LightDM.UserRoles.NameRole);
34+ AccountsService.demoEdges = false;
35− AccountsService.setUserProperty(user, "demo-edges", false);
36 }
35 }
37
36
38 function hideEdgeDemoInGreeter() {
37 function hideEdgeDemoInGreeter() {
39− AccountsService.setUserProperty("lightdm", "demo-edges", false);
38+ AccountsService.setDemoEdgesForUser("lightdm", false);
40 d.showEdgeDemoInGreeter = false;
39 d.showEdgeDemoInGreeter = false;
41 stopDemo();
40 stopDemo();
42 }
41 }
@@ -55,7 +54,7 @@ Item {
55 id: d
54 id: d
56 property Component overlay
55 property Component overlay
57 property QtObject rightEdgeDemo
56 property QtObject rightEdgeDemo
58− property bool showEdgeDemoInGreeter: AccountsService.getUserProperty("lightdm", "demo-edges")
57+ property bool showEdgeDemoInGreeter: AccountsService.getDemoEdgesForUser("lightdm")
59
58
60 onShowEdgeDemoInGreeterChanged: {
59 onShowEdgeDemoInGreeterChanged: {
61 if (!d.overlay && d.showEdgeDemoInGreeter) {
60 if (!d.overlay && d.showEdgeDemoInGreeter) {
GreeterShell.qml+1
@@ -110,6 +110,7 @@ BasicShell {
110 onSelected: {
110 onSelected: {
111 // Update launcher items for new user
111 // Update launcher items for new user
112 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
112 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
113+ AccountsService.setUser(user);
113 LauncherModel.setUser(user);
114 LauncherModel.setUser(user);
114 }
115 }
115
116
plugins/AccountsService/AccountsBindings.cppnew file+115
@@ -0,0 +1,115 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ *
16+ * Author: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#include "AccountsBindings.h"
20+#include "AccountsService.h"
21+
22+#include <QStringList>
23+
24+AccountsBindings::AccountsBindings(QObject* parent)
25+ : QObject(parent),
26+ m_service(new AccountsService(this)),
27+ m_user(qgetenv("USER"))
28+{
29+ connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
30+ this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
31+ connect(m_service, SIGNAL(maybeChanged(const QString &)),
32+ this, SLOT(maybeChanged(const QString &)));
33+}
34+
35+void AccountsBindings::setUser(const QString &user)
36+{
37+ m_user = user;
38+ updateDemoEdges();
39+ updateBackgroundFile();
40+}
41+
42+bool AccountsBindings::getDemoEdges()
43+{
44+ return m_demoEdges;
45+}
46+
47+void AccountsBindings::setDemoEdges(bool demoEdges)
48+{
49+ m_demoEdges = demoEdges;
50+ m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
51+}
52+
53+bool AccountsBindings::getDemoEdgesForUser(const QString &user)
54+{
55+ if (m_user == user) {
56+ return getDemoEdges();
57+ } else {
58+ return m_service->getUserProperty(user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
59+ }
60+}
61+
62+void AccountsBindings::setDemoEdgesForUser(const QString &user, bool demoEdges)
63+{
64+ if (m_user == user) {
65+ setDemoEdges(demoEdges);
66+ } else {
67+ m_service->setUserProperty(user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
68+ }
69+}
70+
71+QString AccountsBindings::getBackgroundFile()
72+{
73+ return m_backgroundFile;
74+}
75+
76+void AccountsBindings::updateDemoEdges()
77+{
78+ auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
79+ if (m_demoEdges != demoEdges) {
80+ m_demoEdges = demoEdges;
81+ Q_EMIT demoEdgesChanged();
82+ }
83+}
84+
85+void AccountsBindings::updateBackgroundFile()
86+{
87+ auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
88+ if (m_backgroundFile != backgroundFile) {
89+ m_backgroundFile = backgroundFile;
90+ Q_EMIT backgroundFileChanged();
91+ }
92+}
93+
94+void AccountsBindings::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
95+{
96+ if (m_user != user) {
97+ return;
98+ }
99+
100+ if (interface == "com.canonical.unity.AccountsService") {
101+ if (changed.contains("demo-edges")) {
102+ updateDemoEdges();
103+ }
104+ }
105+}
106+
107+void AccountsBindings::maybeChanged(const QString &user)
108+{
109+ if (m_user != user) {
110+ return;
111+ }
112+
113+ // Standard properties might have changed
114+ updateBackgroundFile();
115+}
plugins/AccountsService/AccountsBindings.hnew file+68
@@ -0,0 +1,68 @@
1+/*
2+ * Copyright (C) 2012,2013 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ *
16+ * Authors: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#ifndef UNITY_ACCOUNTSBINDINGS_H
20+#define UNITY_ACCOUNTSBINDINGS_H
21+
22+#include <QObject>
23+#include <QString>
24+
25+class AccountsService;
26+
27+class AccountsBindings: public QObject
28+{
29+ Q_OBJECT
30+ Q_PROPERTY (bool demoEdges
31+ READ getDemoEdges
32+ WRITE setDemoEdges
33+ NOTIFY demoEdgesChanged)
34+ Q_PROPERTY (QString backgroundFile
35+ READ getBackgroundFile
36+ NOTIFY backgroundFileChanged)
37+
38+public:
39+ explicit AccountsBindings(QObject *parent = 0);
40+
41+ Q_INVOKABLE void setUser(const QString &user);
42+
43+ bool getDemoEdges();
44+ void setDemoEdges(bool demoEdges);
45+ Q_INVOKABLE bool getDemoEdgesForUser(const QString &user);
46+ Q_INVOKABLE void setDemoEdgesForUser(const QString &user, bool demoEdges);
47+
48+ QString getBackgroundFile();
49+
50+Q_SIGNALS:
51+ void demoEdgesChanged();
52+ void backgroundFileChanged();
53+
54+private Q_SLOTS:
55+ void propertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
56+ void maybeChanged(const QString &user);
57+
58+private:
59+ void updateDemoEdges();
60+ void updateBackgroundFile();
61+
62+ AccountsService *m_service;
63+ QString m_user;
64+ bool m_demoEdges;
65+ QString m_backgroundFile;
66+};
67+
68+#endif
plugins/AccountsService/AccountsService.cpp+57−5
@@ -36,11 +36,11 @@ AccountsService::AccountsService(QObject* parent)
36 connection, this);
36 connection, this);
37}
37}
38
38
39−QVariant AccountsService::getUserProperty(const QString &user, const QString &property)
39+QVariant AccountsService::getUserProperty(const QString &user, const QString &interface, const QString &property)
40{
40{
41 auto iface = getUserInterface(user);
41 auto iface = getUserInterface(user);
42 if (iface != nullptr && iface->isValid()) {
42 if (iface != nullptr && iface->isValid()) {
43− auto answer = iface->call("Get", "com.canonical.unity.AccountsService", property);
43+ auto answer = iface->call("Get", interface, property);
44 if (answer.type() == QDBusMessage::ReplyMessage) {
44 if (answer.type() == QDBusMessage::ReplyMessage) {
45 return answer.arguments()[0].value<QDBusVariant>().variant();
45 return answer.arguments()[0].value<QDBusVariant>().variant();
46 }
46 }
@@ -48,25 +48,77 @@ QVariant AccountsService::getUserProperty(const QString &user, const QString &pr
48 return QVariant();
48 return QVariant();
49}
49}
50
50
51−void AccountsService::setUserProperty(const QString &user, const QString &property, const QVariant &value)
51+void AccountsService::setUserProperty(const QString &user, const QString &interface, const QString &property, const QVariant &value)
52{
52{
53 auto iface = getUserInterface(user);
53 auto iface = getUserInterface(user);
54 if (iface != nullptr && iface->isValid()) {
54 if (iface != nullptr && iface->isValid()) {
55 // The value needs to be carefully wrapped
55 // The value needs to be carefully wrapped
56− iface->call("Set", "com.canonical.unity.AccountsService", property, QVariant::fromValue(QDBusVariant(value)));
56+ iface->call("Set", interface, property, QVariant::fromValue(QDBusVariant(value)));
57 }
57 }
58}
58}
59
59
60+void AccountsService::propertiesChangedSlot(const QString &interface, const QVariantMap &changed, const QStringList &invalid)
61+{
62+ // Merge changed and invalidated together
63+ QStringList combined;
64+ combined << invalid;
65+ combined << changed.keys();
66+ combined.removeDuplicates();
67+
68+ Q_EMIT propertiesChanged(getUserForPath(message().path()), interface, combined);
69+}
70+
71+void AccountsService::maybeChangedSlot()
72+{
73+ Q_EMIT maybeChanged(getUserForPath(message().path()));
74+}
75+
76+QString AccountsService::getUserForPath(const QString &path)
77+{
78+ QMap<QString, QDBusInterface *>::const_iterator i;
79+ for (i = users.constBegin(); i != users.constEnd(); ++i) {
80+ if (i.value()->path() == path) {
81+ return i.key();
82+ }
83+ }
84+ return QString();
85+}
86+
60QDBusInterface *AccountsService::getUserInterface(const QString &user)
87QDBusInterface *AccountsService::getUserInterface(const QString &user)
61{
88{
62 auto iface = users.value(user);
89 auto iface = users.value(user);
63 if (iface == nullptr && accounts_manager->isValid()) {
90 if (iface == nullptr && accounts_manager->isValid()) {
64 auto answer = accounts_manager->call("FindUserByName", user);
91 auto answer = accounts_manager->call("FindUserByName", user);
65 if (answer.type() == QDBusMessage::ReplyMessage) {
92 if (answer.type() == QDBusMessage::ReplyMessage) {
93+ auto path = answer.arguments()[0].value<QDBusObjectPath>().path();
94+
66 iface = new QDBusInterface("org.freedesktop.Accounts",
95 iface = new QDBusInterface("org.freedesktop.Accounts",
67− answer.arguments()[0].value<QDBusObjectPath>().path(),
96+ path,
68 "org.freedesktop.DBus.Properties",
97 "org.freedesktop.DBus.Properties",
69 accounts_manager->connection(), this);
98 accounts_manager->connection(), this);
99+
100+ // With its own pre-defined properties, AccountsService is oddly
101+ // close-lipped. It won't send out proper DBus.Properties notices,
102+ // but it does have one catch-all Changed() signal. So let's
103+ // listen to that.
104+ iface->connection().connect(
105+ iface->service(),
106+ path,
107+ "org.freedesktop.Accounts.User",
108+ "Changed",
109+ this,
110+ SLOT(maybeChangedSlot()));
111+
112+ // But custom properties do send out the right notifications, so
113+ // let's still listen there.
114+ iface->connection().connect(
115+ iface->service(),
116+ path,
117+ "org.freedesktop.DBus.Properties",
118+ "PropertiesChanged",
119+ this,
120+ SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
121+
70 users.insert(user, iface);
122 users.insert(user, iface);
71 }
123 }
72 }
124 }
plugins/AccountsService/AccountsService.h+13−3
@@ -19,23 +19,33 @@
19#ifndef UNITY_ACCOUNTSSERVICE_H
19#ifndef UNITY_ACCOUNTSSERVICE_H
20#define UNITY_ACCOUNTSSERVICE_H
20#define UNITY_ACCOUNTSSERVICE_H
21
21
22+#include <QDBusContext>
22#include <QDBusInterface>
23#include <QDBusInterface>
23#include <QMap>
24#include <QMap>
24#include <QObject>
25#include <QObject>
25#include <QString>
26#include <QString>
26
27
27−class AccountsService: public QObject
28+class AccountsService: public QObject, public QDBusContext
28{
29{
29 Q_OBJECT
30 Q_OBJECT
30
31
31public:
32public:
32 explicit AccountsService(QObject *parent = 0);
33 explicit AccountsService(QObject *parent = 0);
33
34
34− Q_INVOKABLE QVariant getUserProperty(const QString &user, const QString &property);
35+ Q_INVOKABLE QVariant getUserProperty(const QString &user, const QString &interface, const QString &property);
35− Q_INVOKABLE void setUserProperty(const QString &user, const QString &property, const QVariant &value);
36+ Q_INVOKABLE void setUserProperty(const QString &user, const QString &interface, const QString &property, const QVariant &value);
37+
38+Q_SIGNALS:
39+ void propertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
40+ void maybeChanged(const QString &user); // Standard properties might have changed
41+
42+private Q_SLOTS:
43+ void propertiesChangedSlot(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
44+ void maybeChangedSlot();
36
45
37private:
46private:
38 QDBusInterface *getUserInterface(const QString &user);
47 QDBusInterface *getUserInterface(const QString &user);
48+ QString getUserForPath(const QString &path);
39
49
40 QDBusInterface *accounts_manager;
50 QDBusInterface *accounts_manager;
41 QMap<QString, QDBusInterface *> users;
51 QMap<QString, QDBusInterface *> users;
plugins/AccountsService/CMakeLists.txt+1
@@ -3,6 +3,7 @@ include(Plugins)
3add_definitions(-DSM_BUSNAME=systemBus)
3add_definitions(-DSM_BUSNAME=systemBus)
4
4
5add_library(AccountsService-qml MODULE
5add_library(AccountsService-qml MODULE
6+ AccountsBindings.cpp
6 AccountsService.cpp
7 AccountsService.cpp
7 plugin.cpp
8 plugin.cpp
8 )
9 )
plugins/AccountsService/plugin.cpp+3−3
@@ -17,7 +17,7 @@
17 */
17 */
18
18
19#include "plugin.h"
19#include "plugin.h"
20−#include "AccountsService.h"
20+#include "AccountsBindings.h"
21
21
22#include <QDBusMetaType>
22#include <QDBusMetaType>
23#include <QtQml>
23#include <QtQml>
@@ -26,12 +26,12 @@ static QObject *service_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
26{
26{
27 Q_UNUSED(engine)
27 Q_UNUSED(engine)
28 Q_UNUSED(scriptEngine)
28 Q_UNUSED(scriptEngine)
29− return new AccountsService();
29+ return new AccountsBindings();
30}
30}
31
31
32void AccountsServicePlugin::registerTypes(const char *uri)
32void AccountsServicePlugin::registerTypes(const char *uri)
33{
33{
34 Q_ASSERT(uri == QLatin1String("AccountsService"));
34 Q_ASSERT(uri == QLatin1String("AccountsService"));
35 qDBusRegisterMetaType<QList<QVariantMap>>();
35 qDBusRegisterMetaType<QList<QVariantMap>>();
36− qmlRegisterSingletonType<AccountsService>(uri, 0, 1, "AccountsService", service_provider);
36+ qmlRegisterSingletonType<AccountsBindings>(uri, 0, 1, "AccountsService", service_provider);
37}
37}
plugins/Unity/Launcher/backend/launcherbackend.cpp+2−2
@@ -172,7 +172,7 @@ void LauncherBackend::syncFromAccounts()
172 clearItems();
172 clearItems();
173
173
174 if (m_user != "" && m_accounts != nullptr) {
174 if (m_user != "" && m_accounts != nullptr) {
175− auto variant = m_accounts->getUserProperty(m_user, "launcher-items");
175+ auto variant = m_accounts->getUserProperty(m_user, "com.canonical.unity.AccountsService", "launcher-items");
176 apps = qdbus_cast<QList<QVariantMap>>(variant.value<QDBusArgument>());
176 apps = qdbus_cast<QList<QVariantMap>>(variant.value<QDBusArgument>());
177 defaults = isDefaultsItem(apps);
177 defaults = isDefaultsItem(apps);
178 }
178 }
@@ -208,7 +208,7 @@ void LauncherBackend::syncToAccounts()
208 items << makeAppDetails(app.settings->fileName(), app.pinned);
208 items << makeAppDetails(app.settings->fileName(), app.pinned);
209 }
209 }
210
210
211− m_accounts->setUserProperty(m_user, "launcher-items", QVariant::fromValue(items));
211+ m_accounts->setUserProperty(m_user, "com.canonical.unity.AccountsService", "launcher-items", QVariant::fromValue(items));
212 }
212 }
213}
213}
214
214
tests/mocks/AccountsService/AccountsService.cpp → tests/mocks/AccountsService/AccountsBindings.cpprenamed+14−5
@@ -16,18 +16,27 @@
16 * Author: Michael Terry <michael.terry@canonical.com>
16 * Author: Michael Terry <michael.terry@canonical.com>
17 */
17 */
18
18
19−#include "AccountsService.h"
19+#include "AccountsBindings.h"
20
20
21−AccountsService::AccountsService(QObject* parent)
21+AccountsBindings::AccountsBindings(QObject* parent)
22 : QObject(parent)
22 : QObject(parent)
23{
23{
24}
24}
25
25
26−QVariant AccountsService::getUserProperty(const QString &, const QString &)
26+void AccountsBindings::setUser(const QString &)
27{
27{
28− return QVariant(false);
29}
28}
30
29
31−void AccountsService::setUserProperty(const QString &, const QString &, const QVariant &)
30+bool AccountsBindings::getDemoEdges()
32{
31{
32+ return false;
33+}
34+
35+void AccountsBindings::setDemoEdges(bool)
36+{
37+}
38+
39+QString AccountsBindings::getBackgroundFile()
40+{
41+ return TOP_SRCDIR "/graphics/phone_background.jpg";
33}
42}
tests/mocks/AccountsService/AccountsService.h → tests/mocks/AccountsService/AccountsBindings.hrenamed+20−6
@@ -17,22 +17,36 @@
17 * Michael Terry <michael.terry@canonical.com>
17 * Michael Terry <michael.terry@canonical.com>
18 */
18 */
19
19
20−#ifndef UNITY_MOCK_ACCOUNTSSERVICE_H
20+#ifndef UNITY_MOCK_ACCOUNTSBINDINGS_H
21−#define UNITY_MOCK_ACCOUNTSSERVICE_H
21+#define UNITY_MOCK_ACCOUNTSBINDINGS_H
22
22
23#include <QObject>
23#include <QObject>
24#include <QString>
24#include <QString>
25#include <QVariant>
25#include <QVariant>
26
26
27−class AccountsService: public QObject
27+class AccountsBindings: public QObject
28{
28{
29 Q_OBJECT
29 Q_OBJECT
30+ Q_PROPERTY (bool demoEdges
31+ READ getDemoEdges
32+ WRITE setDemoEdges
33+ NOTIFY demoEdgesChanged)
34+ Q_PROPERTY (QString backgroundFile
35+ READ getBackgroundFile
36+ NOTIFY backgroundFileChanged)
30
37
31public:
38public:
32− explicit AccountsService(QObject *parent = 0);
39+ explicit AccountsBindings(QObject *parent = 0);
33
40
34− Q_INVOKABLE QVariant getUserProperty(const QString &user, const QString &property);
41+ Q_INVOKABLE void setUser(const QString &user);
35− Q_INVOKABLE void setUserProperty(const QString &user, const QString &property, const QVariant &value);
42+
43+ bool getDemoEdges();
44+ void setDemoEdges(bool demoEdges);
45+ QString getBackgroundFile();
46+
47+Q_SIGNALS:
48+ void demoEdgesChanged();
49+ void backgroundFileChanged();
36};
50};
37
51
38#endif
52#endif
tests/mocks/AccountsService/CMakeLists.txt+3−1
@@ -1,5 +1,7 @@
1+add_definitions(-DTOP_SRCDIR="${CMAKE_SOURCE_DIR}")
2+
1add_library(MockAccountsService-qml MODULE
3add_library(MockAccountsService-qml MODULE
2− AccountsService.cpp
4+ AccountsBindings.cpp
3 plugin.cpp
5 plugin.cpp
4 )
6 )
5
7
tests/mocks/AccountsService/plugin.cpp+3−3
@@ -18,7 +18,7 @@
18 */
18 */
19
19
20#include "plugin.h"
20#include "plugin.h"
21−#include "AccountsService.h"
21+#include "AccountsBindings.h"
22
22
23#include <QtQml>
23#include <QtQml>
24
24
@@ -26,11 +26,11 @@ static QObject *service_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
26{
26{
27 Q_UNUSED(engine)
27 Q_UNUSED(engine)
28 Q_UNUSED(scriptEngine)
28 Q_UNUSED(scriptEngine)
29− return new AccountsService();
29+ return new AccountsBindings();
30}
30}
31
31
32void AccountsServicePlugin::registerTypes(const char *uri)
32void AccountsServicePlugin::registerTypes(const char *uri)
33{
33{
34 Q_ASSERT(uri == QLatin1String("AccountsService"));
34 Q_ASSERT(uri == QLatin1String("AccountsService"));
35− qmlRegisterSingletonType<AccountsService>(uri, 0, 1, "AccountsService", service_provider);
35+ qmlRegisterSingletonType<AccountsBindings>(uri, 0, 1, "AccountsService", service_provider);
36}
36}
tests/plugins/AccountsService/CMakeLists.txt+1
@@ -25,6 +25,7 @@ qt5_use_modules(mock-server Core DBus)
25
25
26add_executable(test-accountsservice
26add_executable(test-accountsservice
27 ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsService.cpp
27 ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsService.cpp
28+ ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsBindings.cpp
28 client.cpp
29 client.cpp
29 )
30 )
30qt5_use_modules(test-accountsservice Core DBus Test)
31qt5_use_modules(test-accountsservice Core DBus Test)
tests/plugins/AccountsService/client.cpp+18−6
@@ -17,6 +17,7 @@
17 * Authored by: Michael Terry <michael.terry@canonical.com>
17 * Authored by: Michael Terry <michael.terry@canonical.com>
18 */
18 */
19
19
20+#include "AccountsBindings.h"
20#include "AccountsService.h"
21#include "AccountsService.h"
21#include <QSignalSpy>
22#include <QSignalSpy>
22#include <QTest>
23#include <QTest>
@@ -31,16 +32,27 @@ private Q_SLOTS:
31 {
32 {
32 // Test various invalid calls
33 // Test various invalid calls
33 AccountsService session;
34 AccountsService session;
34− QCOMPARE(session.getUserProperty("NOPE", "demo-edges"), QVariant());
35+ QCOMPARE(session.getUserProperty("NOPE", "com.canonical.unity.AccountsService", "demo-edges"), QVariant());
35− QCOMPARE(session.getUserProperty("testuser", "NOPE"), QVariant());
36+ QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "NOPE"), QVariant());
36 }
37 }
37
38
38− void testGetSet()
39+ void testGetSetService()
39 {
40 {
40 AccountsService session;
41 AccountsService session;
42+ session.setUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges", QVariant(true));
41− QCOMPARE(session.getUserProperty("testuser", "demo-edges"), QVariant(true));
43+ QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges"), QVariant(true));
42− session.setUserProperty("testuser", "demo-edges", QVariant(false));
44+ session.setUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges", QVariant(false));
43− QCOMPARE(session.getUserProperty("testuser", "demo-edges"), QVariant(false));
45+ QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges"), QVariant(false));
46+ }
47+
48+ void testGetSetBindings()
49+ {
50+ AccountsBindings bindings;
51+ bindings.setUser("testuser");
52+ bindings.setDemoEdges(true);
53+ QCOMPARE(bindings.getDemoEdges(), true);
54+ bindings.setDemoEdges(false);
55+ QCOMPARE(bindings.getDemoEdges(), false);
44 }
56 }
45};
57};
46
58