on xenial help sign in
Merge from wallpaper branch
3609dc0Michael Terry
Shell.qml+1−1
@@ -15,11 +15,11 @@
15 */
15 */
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18+import GSettings 1.0
18import Ubuntu.Application 0.1
19import Ubuntu.Application 0.1
19import Ubuntu.Components 0.1
20import Ubuntu.Components 0.1
20import Ubuntu.Gestures 0.1
21import Ubuntu.Gestures 0.1
21import Unity.Launcher 0.1
22import Unity.Launcher 0.1
22−import GSettings 1.0
23import Powerd 0.1
23import Powerd 0.1
24import SessionManager 0.1
24import SessionManager 0.1
25import "Dash"
25import "Dash"
plugins/AccountsService/AccountsBindings.cppdeleted−125
@@ -1,125 +0,0 @@
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−{
28− connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
29− this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
30− connect(m_service, SIGNAL(maybeChanged(const QString &)),
31− this, SLOT(maybeChanged(const QString &)));
32−
33− setUser(qgetenv("USER"));
34− updateDemoEdgesForCurrentUser();
35−}
36−
37−QString AccountsBindings::getUser()
38−{
39− return m_user;
40−}
41−
42−void AccountsBindings::setUser(const QString &user)
43−{
44− m_user = user;
45− Q_EMIT userChanged();
46−
47− updateDemoEdges();
48− updateBackgroundFile();
49−}
50−
51−bool AccountsBindings::getDemoEdges()
52−{
53− return m_demoEdges;
54−}
55−
56−void AccountsBindings::setDemoEdges(bool demoEdges)
57−{
58− m_demoEdges = demoEdges;
59− m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
60−}
61−
62−bool AccountsBindings::getDemoEdgesForCurrentUser()
63−{
64− return m_demoEdgesForCurrentUser;
65−}
66−
67−void AccountsBindings::setDemoEdgesForCurrentUser(bool demoEdgesForCurrentUser)
68−{
69− m_demoEdgesForCurrentUser = demoEdgesForCurrentUser;
70− m_service->setUserProperty(qgetenv("USER"), "com.canonical.unity.AccountsService", "demo-edges", demoEdgesForCurrentUser);
71−}
72−
73−QString AccountsBindings::getBackgroundFile()
74−{
75− return m_backgroundFile;
76−}
77−
78−void AccountsBindings::updateDemoEdges()
79−{
80− auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
81− if (m_demoEdges != demoEdges) {
82− m_demoEdges = demoEdges;
83− Q_EMIT demoEdgesChanged();
84− }
85−}
86−
87−void AccountsBindings::updateDemoEdgesForCurrentUser()
88−{
89− auto demoEdgesForCurrentUser = m_service->getUserProperty(qgetenv("USER"), "com.canonical.unity.AccountsService", "demo-edges").toBool();
90− if (m_demoEdgesForCurrentUser != demoEdgesForCurrentUser) {
91− m_demoEdgesForCurrentUser = demoEdgesForCurrentUser;
92− Q_EMIT demoEdgesForCurrentUserChanged();
93− }
94−}
95−
96−void AccountsBindings::updateBackgroundFile()
97−{
98− auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
99− if (m_backgroundFile != backgroundFile) {
100− m_backgroundFile = backgroundFile;
101− Q_EMIT backgroundFileChanged();
102− }
103−}
104−
105−void AccountsBindings::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
106−{
107− if (interface == "com.canonical.unity.AccountsService") {
108− if (changed.contains("demo-edges")) {
109− if (qgetenv("USER") == user) {
110− updateDemoEdgesForCurrentUser();
111− }
112− if (m_user != user) {
113− updateDemoEdges();
114− }
115− }
116− }
117−}
118−
119−void AccountsBindings::maybeChanged(const QString &user)
120−{
121− if (m_user == user) {
122− // Standard properties might have changed
123− updateBackgroundFile();
124− }
125−}
plugins/AccountsService/AccountsBindings.hdeleted−80
@@ -1,80 +0,0 @@
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 (QString user
31− READ getUser
32− WRITE setUser
33− NOTIFY userChanged)
34− Q_PROPERTY (bool demoEdges
35− READ getDemoEdges
36− WRITE setDemoEdges
37− NOTIFY demoEdgesChanged)
38− Q_PROPERTY (bool demoEdgesForCurrentUser
39− READ getDemoEdgesForCurrentUser
40− WRITE setDemoEdgesForCurrentUser
41− NOTIFY demoEdgesForCurrentUserChanged)
42− Q_PROPERTY (QString backgroundFile
43− READ getBackgroundFile
44− NOTIFY backgroundFileChanged)
45−
46−public:
47− explicit AccountsBindings(QObject *parent = 0);
48−
49− QString getUser();
50− void setUser(const QString &user);
51− bool getDemoEdges();
52− void setDemoEdges(bool demoEdges);
53− bool getDemoEdgesForCurrentUser();
54− void setDemoEdgesForCurrentUser(bool demoEdgesForCurrentUser);
55−
56− QString getBackgroundFile();
57−
58−Q_SIGNALS:
59− void userChanged();
60− void demoEdgesChanged();
61− void demoEdgesForCurrentUserChanged();
62− void backgroundFileChanged();
63−
64−private Q_SLOTS:
65− void propertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
66− void maybeChanged(const QString &user);
67−
68−private:
69− void updateDemoEdges();
70− void updateDemoEdgesForCurrentUser();
71− void updateBackgroundFile();
72−
73− AccountsService *m_service;
74− QString m_user;
75− bool m_demoEdges;
76− bool m_demoEdgesForCurrentUser;
77− QString m_backgroundFile;
78−};
79−
80−#endif
plugins/AccountsService/AccountsService.cpp+79−80
@@ -17,110 +17,109 @@
17 */
17 */
18
18
19#include "AccountsService.h"
19#include "AccountsService.h"
20−#include <QDBusConnection>
20+#include "AccountsServiceDBusAdaptor.h"
21−#include <QDBusConnectionInterface>
21+
22−#include <QDBusMessage>
22+#include <QStringList>
23−#include <QDBusVariant>
24
23
25AccountsService::AccountsService(QObject* parent)
24AccountsService::AccountsService(QObject* parent)
26 : QObject(parent),
25 : QObject(parent),
27− accounts_manager(NULL),
26+ m_service(new AccountsServiceDBusAdaptor(this))
28− users()
29{
27{
30− auto connection = QDBusConnection::SM_BUSNAME();
28+ connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
31− auto interface = connection.interface();
29+ this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
32− interface->startService("org.freedesktop.Accounts");
30+ connect(m_service, SIGNAL(maybeChanged(const QString &)),
33− accounts_manager = new QDBusInterface("org.freedesktop.Accounts",
31+ this, SLOT(maybeChanged(const QString &)));
34− "/org/freedesktop/Accounts",
32+
35− "org.freedesktop.Accounts",
33+ setUser(qgetenv("USER"));
36− connection, this);
34+ updateDemoEdgesForCurrentUser();
37}
35}
38
36
39−QVariant AccountsService::getUserProperty(const QString &user, const QString &interface, const QString &property)
37+QString AccountsService::getUser()
40{
38{
41− auto iface = getUserInterface(user);
39+ return m_user;
42− if (iface != nullptr && iface->isValid()) {
43− auto answer = iface->call("Get", interface, property);
44− if (answer.type() == QDBusMessage::ReplyMessage) {
45− return answer.arguments()[0].value<QDBusVariant>().variant();
46− }
47− }
48− return QVariant();
49}
40}
50
41
51−void AccountsService::setUserProperty(const QString &user, const QString &interface, const QString &property, const QVariant &value)
42+void AccountsService::setUser(const QString &user)
52{
43{
53− auto iface = getUserInterface(user);
44+ m_user = user;
54− if (iface != nullptr && iface->isValid()) {
45+ Q_EMIT userChanged();
55− // The value needs to be carefully wrapped
46+
56− iface->call("Set", interface, property, QVariant::fromValue(QDBusVariant(value)));
47+ updateDemoEdges();
48+ updateBackgroundFile();
57− }
49+}
50+
51+bool AccountsService::getDemoEdges()
52+{
53+ return m_demoEdges;
58}
54}
59
55
60−void AccountsService::propertiesChangedSlot(const QString &interface, const QVariantMap &changed, const QStringList &invalid)
56+void AccountsService::setDemoEdges(bool demoEdges)
61{
57{
62− // Merge changed and invalidated together
58+ m_demoEdges = demoEdges;
63− QStringList combined;
59+ m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
64− combined << invalid;
60+}
65− combined << changed.keys();
66− combined.removeDuplicates();
67
61
68− Q_EMIT propertiesChanged(getUserForPath(message().path()), interface, combined);
62+bool AccountsService::getDemoEdgesForCurrentUser()
63+{
64+ return m_demoEdgesForCurrentUser;
69}
65}
70
66
71−void AccountsService::maybeChangedSlot()
67+void AccountsService::setDemoEdgesForCurrentUser(bool demoEdgesForCurrentUser)
72{
68{
73− Q_EMIT maybeChanged(getUserForPath(message().path()));
69+ m_demoEdgesForCurrentUser = demoEdgesForCurrentUser;
70+ m_service->setUserProperty(qgetenv("USER"), "com.canonical.unity.AccountsService", "demo-edges", demoEdgesForCurrentUser);
74}
71}
75
72
76−QString AccountsService::getUserForPath(const QString &path)
73+QString AccountsService::getBackgroundFile()
77{
74{
78− QMap<QString, QDBusInterface *>::const_iterator i;
75+ return m_backgroundFile;
79− for (i = users.constBegin(); i != users.constEnd(); ++i) {
80− if (i.value()->path() == path) {
81− return i.key();
82− }
76+}
77+
78+void AccountsService::updateDemoEdges()
79+{
80+ auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
81+ if (m_demoEdges != demoEdges) {
82+ m_demoEdges = demoEdges;
83+ Q_EMIT demoEdgesChanged();
83 }
84 }
84− return QString();
85}
85}
86
86
87−QDBusInterface *AccountsService::getUserInterface(const QString &user)
87+void AccountsService::updateDemoEdgesForCurrentUser()
88{
88{
89− auto iface = users.value(user);
89+ auto demoEdgesForCurrentUser = m_service->getUserProperty(qgetenv("USER"), "com.canonical.unity.AccountsService", "demo-edges").toBool();
90− if (iface == nullptr && accounts_manager->isValid()) {
90+ if (m_demoEdgesForCurrentUser != demoEdgesForCurrentUser) {
91− auto answer = accounts_manager->call("FindUserByName", user);
91+ m_demoEdgesForCurrentUser = demoEdgesForCurrentUser;
92− if (answer.type() == QDBusMessage::ReplyMessage) {
92+ Q_EMIT demoEdgesForCurrentUserChanged();
93− auto path = answer.arguments()[0].value<QDBusObjectPath>().path();
93+ }
94−
94+}
95− iface = new QDBusInterface("org.freedesktop.Accounts",
95+
96− path,
96+void AccountsService::updateBackgroundFile()
97− "org.freedesktop.DBus.Properties",
97+{
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",
98+ auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
108− "Changed",
99+ if (m_backgroundFile != backgroundFile) {
109− this,
100+ m_backgroundFile = backgroundFile;
110− SLOT(maybeChangedSlot()));
101+ Q_EMIT backgroundFileChanged();
111−
102+ }
112− // But custom properties do send out the right notifications, so
103+}
113− // let's still listen there.
104+
114− iface->connection().connect(
105+void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
115− iface->service(),
106+{
116− path,
107+ if (interface == "com.canonical.unity.AccountsService") {
117− "org.freedesktop.DBus.Properties",
108+ if (changed.contains("demo-edges")) {
118− "PropertiesChanged",
109+ if (qgetenv("USER") == user) {
119− this,
110+ updateDemoEdgesForCurrentUser();
120− SLOT(propertiesChangedSlot(QString, QVariantMap, QStringList)));
111+ }
121−
112+ if (m_user != user) {
122− users.insert(user, iface);
113+ updateDemoEdges();
114+ }
123 }
115 }
124 }
116 }
125− return iface;
117+}
118+
119+void AccountsService::maybeChanged(const QString &user)
120+{
121+ if (m_user == user) {
122+ // Standard properties might have changed
123+ updateBackgroundFile();
124+ }
126}
125}
plugins/AccountsService/AccountsService.h+40−15
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2012,2013 Canonical, Ltd.
2+ * Copyright (C) 2013 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -19,36 +19,61 @@
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>
23−#include <QDBusInterface>
24−#include <QMap>
25#include <QObject>
22#include <QObject>
26#include <QString>
23#include <QString>
27
24
25+class AccountsServiceDBusAdaptor;
26+
28−class AccountsService: public QObject, public QDBusContext
27+class AccountsService: public QObject
29{
28{
30 Q_OBJECT
29 Q_OBJECT
30+ Q_PROPERTY (QString user
31+ READ getUser
32+ WRITE setUser
33+ NOTIFY userChanged)
34+ Q_PROPERTY (bool demoEdges
35+ READ getDemoEdges
36+ WRITE setDemoEdges
37+ NOTIFY demoEdgesChanged)
38+ Q_PROPERTY (bool demoEdgesForCurrentUser
39+ READ getDemoEdgesForCurrentUser
40+ WRITE setDemoEdgesForCurrentUser
41+ NOTIFY demoEdgesForCurrentUserChanged)
42+ Q_PROPERTY (QString backgroundFile
43+ READ getBackgroundFile
44+ NOTIFY backgroundFileChanged)
31
45
32public:
46public:
33 explicit AccountsService(QObject *parent = 0);
47 explicit AccountsService(QObject *parent = 0);
34
48
35− Q_INVOKABLE QVariant getUserProperty(const QString &user, const QString &interface, const QString &property);
49+ QString getUser();
36− Q_INVOKABLE void setUserProperty(const QString &user, const QString &interface, const QString &property, const QVariant &value);
50+ void setUser(const QString &user);
51+ bool getDemoEdges();
52+ void setDemoEdges(bool demoEdges);
53+ bool getDemoEdgesForCurrentUser();
54+ void setDemoEdgesForCurrentUser(bool demoEdgesForCurrentUser);
55+ QString getBackgroundFile();
37
56
38Q_SIGNALS:
57Q_SIGNALS:
39− void propertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
58+ void userChanged();
40− void maybeChanged(const QString &user); // Standard properties might have changed
59+ void demoEdgesChanged();
60+ void demoEdgesForCurrentUserChanged();
61+ void backgroundFileChanged();
41
62
42private Q_SLOTS:
63private Q_SLOTS:
43− void propertiesChangedSlot(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
64+ void propertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
44− void maybeChangedSlot();
65+ void maybeChanged(const QString &user);
45
66
46private:
67private:
47− QDBusInterface *getUserInterface(const QString &user);
68+ void updateDemoEdges();
48− QString getUserForPath(const QString &path);
69+ void updateDemoEdgesForCurrentUser();
70+ void updateBackgroundFile();
49
71
50− QDBusInterface *accounts_manager;
72+ AccountsServiceDBusAdaptor *m_service;
51− QMap<QString, QDBusInterface *> users;
73+ QString m_user;
74+ bool m_demoEdges;
75+ bool m_demoEdgesForCurrentUser;
76+ QString m_backgroundFile;
52};
77};
53
78
54#endif
79#endif
plugins/AccountsService/AccountsServiceDBusAdaptor.cppnew file+126
@@ -0,0 +1,126 @@
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 "AccountsServiceDBusAdaptor.h"
20+#include <QDBusConnection>
21+#include <QDBusConnectionInterface>
22+#include <QDBusMessage>
23+#include <QDBusVariant>
24+
25+AccountsServiceDBusAdaptor::AccountsServiceDBusAdaptor(QObject* parent)
26+ : QObject(parent),
27+ accounts_manager(NULL),
28+ users()
29+{
30+ auto connection = QDBusConnection::SM_BUSNAME();
31+ auto interface = connection.interface();
32+ interface->startService("org.freedesktop.Accounts");
33+ accounts_manager = new QDBusInterface("org.freedesktop.Accounts",
34+ "/org/freedesktop/Accounts",
35+ "org.freedesktop.Accounts",
36+ connection, this);
37+}
38+
39+QVariant AccountsServiceDBusAdaptor::getUserProperty(const QString &user, const QString &interface, const QString &property)
40+{
41+ auto iface = getUserInterface(user);
42+ if (iface != nullptr && iface->isValid()) {
43+ auto answer = iface->call("Get", interface, property);
44+ if (answer.type() == QDBusMessage::ReplyMessage) {
45+ return answer.arguments()[0].value<QDBusVariant>().variant();
46+ }
47+ }
48+ return QVariant();
49+}
50+
51+void AccountsServiceDBusAdaptor::setUserProperty(const QString &user, const QString &interface, const QString &property, const QVariant &value)
52+{
53+ auto iface = getUserInterface(user);
54+ if (iface != nullptr && iface->isValid()) {
55+ // The value needs to be carefully wrapped
56+ iface->call("Set", interface, property, QVariant::fromValue(QDBusVariant(value)));
57+ }
58+}
59+
60+void AccountsServiceDBusAdaptor::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 AccountsServiceDBusAdaptor::maybeChangedSlot()
72+{
73+ Q_EMIT maybeChanged(getUserForPath(message().path()));
74+}
75+
76+QString AccountsServiceDBusAdaptor::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+
87+QDBusInterface *AccountsServiceDBusAdaptor::getUserInterface(const QString &user)
88+{
89+ auto iface = users.value(user);
90+ if (iface == nullptr && accounts_manager->isValid()) {
91+ auto answer = accounts_manager->call("FindUserByName", user);
92+ if (answer.type() == QDBusMessage::ReplyMessage) {
93+ auto path = answer.arguments()[0].value<QDBusObjectPath>().path();
94+
95+ iface = new QDBusInterface("org.freedesktop.Accounts",
96+ path,
97+ "org.freedesktop.DBus.Properties",
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+
122+ users.insert(user, iface);
123+ }
124+ }
125+ return iface;
126+}
plugins/AccountsService/AccountsServiceDBusAdaptor.hnew file+54
@@ -0,0 +1,54 @@
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+ * Authors: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+#ifndef UNITY_ACCOUNTSSERVICEDBUSADAPTOR_H
20+#define UNITY_ACCOUNTSSERVICEDBUSADAPTOR_H
21+
22+#include <QDBusContext>
23+#include <QDBusInterface>
24+#include <QMap>
25+#include <QObject>
26+#include <QString>
27+
28+class AccountsServiceDBusAdaptor: public QObject, public QDBusContext
29+{
30+ Q_OBJECT
31+
32+public:
33+ explicit AccountsServiceDBusAdaptor(QObject *parent = 0);
34+
35+ Q_INVOKABLE QVariant getUserProperty(const QString &user, const QString &interface, const QString &property);
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();
45+
46+private:
47+ QDBusInterface *getUserInterface(const QString &user);
48+ QString getUserForPath(const QString &path);
49+
50+ QDBusInterface *accounts_manager;
51+ QMap<QString, QDBusInterface *> users;
52+};
53+
54+#endif
plugins/AccountsService/CMakeLists.txt+1−1
@@ -3,8 +3,8 @@ 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
7 AccountsService.cpp
6 AccountsService.cpp
7+ AccountsServiceDBusAdaptor.cpp
8 plugin.cpp
8 plugin.cpp
9 )
9 )
10
10
plugins/AccountsService/plugin.cpp+3−3
@@ -17,7 +17,7 @@
17 */
17 */
18
18
19#include "plugin.h"
19#include "plugin.h"
20−#include "AccountsBindings.h"
20+#include "AccountsService.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 AccountsBindings();
29+ return new AccountsService();
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<AccountsBindings>(uri, 0, 1, "AccountsService", service_provider);
36+ qmlRegisterSingletonType<AccountsService>(uri, 0, 1, "AccountsService", service_provider);
37}
37}
plugins/Unity/Launcher/CMakeLists.txt+1−1
@@ -17,7 +17,7 @@ set(QMLLAUNCHERPLUGIN_SRC
17 quicklistmodel.cpp
17 quicklistmodel.cpp
18 common/quicklistentry.cpp
18 common/quicklistentry.cpp
19 backend/launcherbackend.cpp
19 backend/launcherbackend.cpp
20− ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsService.cpp
20+ ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsServiceDBusAdaptor.cpp
21 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
21 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
22 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
22 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
23 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
23 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
plugins/Unity/Launcher/backend/launcherbackend.cpp+2−2
@@ -18,7 +18,7 @@
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
19 */
20
20
21−#include "AccountsService.h"
21+#include "AccountsServiceDBusAdaptor.h"
22#include "launcherbackend.h"
22#include "launcherbackend.h"
23
23
24#include <QDir>
24#include <QDir>
@@ -43,7 +43,7 @@ LauncherBackend::LauncherBackend(bool useStorage, QObject *parent):
43 m_accounts(nullptr)
43 m_accounts(nullptr)
44{
44{
45 if (useStorage) {
45 if (useStorage) {
46− m_accounts = new AccountsService(this);
46+ m_accounts = new AccountsServiceDBusAdaptor(this);
47 }
47 }
48 m_user = qgetenv("USER");
48 m_user = qgetenv("USER");
49 syncFromAccounts();
49 syncFromAccounts();
plugins/Unity/Launcher/backend/launcherbackend.h+2−2
@@ -25,7 +25,7 @@
25#include <QSettings>
25#include <QSettings>
26#include <QStringList>
26#include <QStringList>
27
27
28−class AccountsService;
28+class AccountsServiceDBusAdaptor;
29
29
30/**
30/**
31 * @brief An interface that provides all the data needed by the launcher.
31 * @brief An interface that provides all the data needed by the launcher.
@@ -156,7 +156,7 @@ private:
156 QList<QString> m_storedApps;
156 QList<QString> m_storedApps;
157 mutable QHash<QString, LauncherBackendItem*> m_itemCache;
157 mutable QHash<QString, LauncherBackendItem*> m_itemCache;
158
158
159− AccountsService *m_accounts;
159+ AccountsServiceDBusAdaptor *m_accounts;
160 QString m_user;
160 QString m_user;
161};
161};
162
162
tests/mocks/AccountsService/AccountsBindings.cpp → tests/mocks/AccountsService/AccountsService.cpprenamed+11−9
@@ -16,41 +16,43 @@
16 * Author: Michael Terry <michael.terry@canonical.com>
16 * Author: Michael Terry <michael.terry@canonical.com>
17 */
17 */
18
18
19−#include "AccountsBindings.h"
19+#include "AccountsService.h"
20
20
21−AccountsBindings::AccountsBindings(QObject* parent)
21+AccountsService::AccountsService(QObject* parent)
22 : QObject(parent)
22 : QObject(parent)
23{
23{
24}
24}
25
25
26−QString AccountsBindings::getUser()
26+QString AccountsService::getUser()
27{
27{
28 return "testuser";
28 return "testuser";
29}
29}
30
30
31−void AccountsBindings::setUser(const QString &)
31+void AccountsService::setUser(const QString &user)
32{
32{
33+ Q_UNUSED(user)
33}
34}
34
35
35−bool AccountsBindings::getDemoEdges()
36+bool AccountsService::getDemoEdges()
36{
37{
37 return false;
38 return false;
38}
39}
39
40
40−void AccountsBindings::setDemoEdges(bool)
41+void AccountsService::setDemoEdges(bool demoEdges)
41{
42{
43+ Q_UNUSED(demoEdges)
42}
44}
43
45
44−bool AccountsBindings::getDemoEdgesForCurrentUser()
46+bool AccountsService::getDemoEdgesForCurrentUser()
45{
47{
46 return false;
48 return false;
47}
49}
48
50
49−void AccountsBindings::setDemoEdgesForCurrentUser(bool)
51+void AccountsService::setDemoEdgesForCurrentUser(bool)
50{
52{
51}
53}
52
54
53−QString AccountsBindings::getBackgroundFile()
55+QString AccountsService::getBackgroundFile()
54{
56{
55 return TOP_SRCDIR "/graphics/phone_background.jpg";
57 return TOP_SRCDIR "/graphics/phone_background.jpg";
56}
58}
tests/mocks/AccountsService/AccountsBindings.h → tests/mocks/AccountsService/AccountsService.hrenamed+5−5
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2012,2013 Canonical, Ltd.
2+ * Copyright (C) 2013 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -17,14 +17,14 @@
17 * Michael Terry <michael.terry@canonical.com>
17 * Michael Terry <michael.terry@canonical.com>
18 */
18 */
19
19
20−#ifndef UNITY_MOCK_ACCOUNTSBINDINGS_H
20+#ifndef UNITY_MOCK_ACCOUNTSSERVICE_H
21−#define UNITY_MOCK_ACCOUNTSBINDINGS_H
21+#define UNITY_MOCK_ACCOUNTSSERVICE_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 AccountsBindings: public QObject
27+class AccountsService: public QObject
28{
28{
29 Q_OBJECT
29 Q_OBJECT
30 Q_PROPERTY (QString user
30 Q_PROPERTY (QString user
@@ -44,7 +44,7 @@ class AccountsBindings: public QObject
44 NOTIFY backgroundFileChanged)
44 NOTIFY backgroundFileChanged)
45
45
46public:
46public:
47− explicit AccountsBindings(QObject *parent = 0);
47+ explicit AccountsService(QObject *parent = 0);
48
48
49 QString getUser();
49 QString getUser();
50 void setUser(const QString &user);
50 void setUser(const QString &user);
tests/mocks/AccountsService/CMakeLists.txt+1−1
@@ -1,7 +1,7 @@
1add_definitions(-DTOP_SRCDIR="${CMAKE_SOURCE_DIR}")
1add_definitions(-DTOP_SRCDIR="${CMAKE_SOURCE_DIR}")
2
2
3add_library(MockAccountsService-qml MODULE
3add_library(MockAccountsService-qml MODULE
4− AccountsBindings.cpp
4+ AccountsService.cpp
5 plugin.cpp
5 plugin.cpp
6 )
6 )
7
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 "AccountsBindings.h"
21+#include "AccountsService.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 AccountsBindings();
29+ return new AccountsService();
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<AccountsBindings>(uri, 0, 1, "AccountsService", service_provider);
35+ qmlRegisterSingletonType<AccountsService>(uri, 0, 1, "AccountsService", service_provider);
36}
36}
tests/plugins/AccountsService/CMakeLists.txt+1−1
@@ -25,7 +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+ ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsServiceDBusAdaptor.cpp
29 client.cpp
29 client.cpp
30 )
30 )
31qt5_use_modules(test-accountsservice Core DBus Test)
31qt5_use_modules(test-accountsservice Core DBus Test)
tests/plugins/AccountsService/client.cpp+11−11
@@ -17,8 +17,8 @@
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"
21#include "AccountsService.h"
20#include "AccountsService.h"
21+#include "AccountsServiceDBusAdaptor.h"
22#include <QSignalSpy>
22#include <QSignalSpy>
23#include <QTest>
23#include <QTest>
24
24
@@ -31,28 +31,28 @@ private Q_SLOTS:
31 void testInvalids()
31 void testInvalids()
32 {
32 {
33 // Test various invalid calls
33 // Test various invalid calls
34− AccountsService session;
34+ AccountsServiceDBusAdaptor session;
35 QCOMPARE(session.getUserProperty("NOPE", "com.canonical.unity.AccountsService", "demo-edges"), QVariant());
35 QCOMPARE(session.getUserProperty("NOPE", "com.canonical.unity.AccountsService", "demo-edges"), QVariant());
36 QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "NOPE"), QVariant());
36 QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "NOPE"), QVariant());
37 }
37 }
38
38
39− void testGetSetService()
39+ void testGetSetServiceDBusAdaptor()
40 {
40 {
41− AccountsService session;
41+ AccountsServiceDBusAdaptor session;
42 session.setUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges", QVariant(true));
42 session.setUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges", QVariant(true));
43 QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges"), QVariant(true));
43 QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges"), QVariant(true));
44 session.setUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges", QVariant(false));
44 session.setUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges", QVariant(false));
45 QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges"), QVariant(false));
45 QCOMPARE(session.getUserProperty("testuser", "com.canonical.unity.AccountsService", "demo-edges"), QVariant(false));
46 }
46 }
47
47
48− void testGetSetBindings()
48+ void testGetSetService()
49 {
49 {
50− AccountsBindings bindings;
50+ AccountsService session;
51− bindings.setUser("testuser");
51+ session.setUser("testuser");
52− bindings.setDemoEdges(true);
52+ session.setDemoEdges(true);
53− QCOMPARE(bindings.getDemoEdges(), true);
53+ QCOMPARE(session.getDemoEdges(), true);
54− bindings.setDemoEdges(false);
54+ session.setDemoEdges(false);
55− QCOMPARE(bindings.getDemoEdges(), false);
55+ QCOMPARE(session.getDemoEdges(), false);
56 }
56 }
57};
57};
58
58
tests/plugins/Unity/Launcher/CMakeLists.txt+2−2
@@ -21,7 +21,7 @@ add_test(NAME launcherbackendtest COMMAND ${testBackendCommand})
21add_custom_target(launcherbackendtest ${testBackendCommand})
21add_custom_target(launcherbackendtest ${testBackendCommand})
22add_executable(launcherbackendtestExec
22add_executable(launcherbackendtestExec
23 launcherbackendtest.cpp
23 launcherbackendtest.cpp
24− ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsService.cpp
24+ ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsServiceDBusAdaptor.cpp
25 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/backend/launcherbackend.cpp
25 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/backend/launcherbackend.cpp
26 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/common/quicklistentry.cpp
26 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/common/quicklistentry.cpp
27 )
27 )
@@ -39,7 +39,7 @@ add_executable(launchermodeltestExec
39 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/launchermodel.cpp
39 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/launchermodel.cpp
40 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/launcheritem.cpp
40 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/launcheritem.cpp
41 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/quicklistmodel.cpp
41 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/quicklistmodel.cpp
42− ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsService.cpp
42+ ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsServiceDBusAdaptor.cpp
43 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/backend/launcherbackend.cpp
43 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/backend/launcherbackend.cpp
44 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/common/quicklistentry.cpp
44 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/common/quicklistentry.cpp
45 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
45 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h