on xenial help sign in
Add initial AccountsService plugin, to record whether we've demo'd the edges yet
commita3b84e7bae0c5e4018f6023bf53f2dc3568b1b76 authorMichael Terry <michael.terry@canonical.com> dateWed 24 Jul 2013, 14:29 (13 years ago) parent260287a
10 files changed+262−3
plugins/AccountsService/AccountsService.cpp+70 plugins/AccountsService/AccountsService.h+47 plugins/AccountsService/CMakeLists.txt+34 plugins/AccountsService/com.canonical.unity.AccountsService.policy+13 plugins/AccountsService/com.canonical.unity.AccountsService.rules+5 plugins/AccountsService/com.canonical.unity.AccountsService.xml+14 plugins/AccountsService/plugin.cpp+37 plugins/AccountsService/plugin.h+35 plugins/AccountsService/qmldir+3 plugins/CMakeLists.txt+4−3
plugins/AccountsService/AccountsService.cppnew file+70
@@ -0,0 +1,70 @@
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 "AccountsService.h"
20+#include <QtCore/QEvent>
21+#include <QtDBus/QDBusPendingReply>
22+
23+AccountsService::AccountsService(QObject* parent)
24+ : QObject(parent),
25+ accounts_manager(NULL),
26+ users()
27+{
28+ accounts_manager = new QDBusInterface("org.freedesktop.Accounts",
29+ "/org/freedesktop/Accounts",
30+ "org.freedesktop.Accounts",
31+ QDBusConnection::SM_BUSNAME(), this);
32+}
33+
34+QVariant AccountsService::getUserProperty(const QString &user, const QString &property)
35+{
36+ auto iface = getUserInterface(user);
37+ if (iface != nullptr && iface->isValid()) {
38+ auto answer = iface->call("Get", "com.canonical.unity.AccountsService", property);
39+ if (answer.type() == QDBusMessage::ReplyMessage) {
40+ return answer.arguments()[0].value<QDBusVariant>().variant();
41+ }
42+ }
43+ return QVariant();
44+}
45+
46+void AccountsService::setUserProperty(const QString &user, const QString &property, const QVariant &value)
47+{
48+ auto iface = getUserInterface(user);
49+ if (iface != nullptr && iface->isValid()) {
50+ // The value needs to be carefully wrapped thrice
51+ iface->call("Set", "com.canonical.unity.AccountsService", property, QVariant::fromValue(QDBusVariant(value)));
52+ }
53+}
54+
55+QDBusInterface *AccountsService::getUserInterface(const QString &user)
56+{
57+ auto iface = users.value(user);
58+ if (iface == nullptr && accounts_manager->isValid()) {
59+ auto answer = accounts_manager->call("FindUserByName", user);
60+ if (answer.type() == QDBusMessage::ReplyMessage) {
61+ iface = new QDBusInterface("org.freedesktop.Accounts",
62+ answer.arguments()[0].value<QDBusObjectPath>().path(),
63+ "org.freedesktop.DBus.Properties",
64+ accounts_manager->connection(), this);
65+ users.insert(user, iface);
66+ }
67+ }
68+ return iface;
69+}
70+
plugins/AccountsService/AccountsService.hnew file+47
@@ -0,0 +1,47 @@
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: Gerry Boland <gerry.boland@canonical.com>
17+ * Michael Terry <michael.terry@canonical.com>
18+ */
19+
20+#ifndef UNITY_ACCOUNTSSERVICE_H
21+#define UNITY_ACCOUNTSSERVICE_H
22+
23+#include <QtDBus/QDBusInterface>
24+#include <QtCore/QMap>
25+#include <QtCore/QObject>
26+#include <QtCore/QString>
27+
28+class AccountsService: public QObject
29+{
30+ Q_OBJECT
31+
32+public:
33+ explicit AccountsService(QObject *parent = 0);
34+
35+public Q_SLOTS:
36+ QVariant getUserProperty(const QString &user, const QString &property);
37+ void setUserProperty(const QString &user, const QString &property, const QVariant &value);
38+
39+private Q_SLOTS:
40+ QDBusInterface *getUserInterface(const QString &user);
41+
42+private:
43+ QDBusInterface *accounts_manager;
44+ QMap<QString, QDBusInterface *> users;
45+};
46+
47+#endif
plugins/AccountsService/CMakeLists.txtnew file+34
@@ -0,0 +1,34 @@
1+include(Plugins)
2+
3+add_definitions(-DSM_BUSNAME=systemBus)
4+
5+add_library(AccountsService-qml MODULE
6+ AccountsService.cpp
7+ plugin.cpp
8+ )
9+
10+qt5_use_modules(AccountsService-qml DBus Qml)
11+
12+export_qmlplugin(AccountsService 0.1 AccountsService TARGETS AccountsService-qml)
13+
14+set(POLICYKIT_DIR "${CMAKE_INSTALL_PREFIX}/share/polkit-1")
15+set(DBUS_IFACE_DIR "${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces")
16+set(ACCOUNTS_IFACE_DIR "${CMAKE_INSTALL_PREFIX}/share/accountsservice/interfaces")
17+
18+install(FILES com.canonical.unity.AccountsService.xml
19+ DESTINATION "${DBUS_IFACE_DIR}"
20+ )
21+
22+# Create accountsservice symlink for above dbus interface
23+install(CODE "
24+execute_process(COMMAND mkdir -p \"${ACCOUNTS_IFACE_DIR}\"
25+ COMMAND ln -s ../../dbus-1/interfaces/com.canonical.unity.AccountsService.xml \"${ACCOUNTS_IFACE_DIR}\"
26+ )")
27+
28+install(FILES com.canonical.unity.AccountsService.policy
29+ DESTINATION "${POLICYKIT_DIR}/actions"
30+ )
31+
32+install(FILES com.canonical.unity.AccountsService.rules
33+ DESTINATION "${POLICYKIT_DIR}/rules.d"
34+ )
plugins/AccountsService/com.canonical.unity.AccountsService.policynew file+13
@@ -0,0 +1,13 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+
3+<policyconfig>
4+ <action id="com.canonical.unity.AccountsService.ModifyUsers">
5+ <description>Set properties of any user</description>
6+ <message>Authentication is required to set another user's unity properties.</message>
7+ <defaults>
8+ <allow_any>auth_admin_keep</allow_any>
9+ <allow_inactive>auth_admin_keep</allow_inactive>
10+ <allow_active>auth_admin_keep</allow_active>
11+ </defaults>
12+ </action>
13+</policyconfig>
plugins/AccountsService/com.canonical.unity.AccountsService.rulesnew file+5
@@ -0,0 +1,5 @@
1+polkit.addAdminRule(function(action, subject) {
2+ if (action.id == "com.canonical.unity.AccountsService.ModifyUsers") {
3+ return "unix-user:lightdm";
4+ }
5+});
plugins/AccountsService/com.canonical.unity.AccountsService.xmlnew file+14
@@ -0,0 +1,14 @@
1+<node>
2+ <interface name="com.canonical.unity.AccountsService">
3+
4+ <annotation name="org.freedesktop.Accounts.VendorExtension" value="true"/>
5+
6+ <annotation name="org.freedesktop.Accounts.Authentication.ChangeAny"
7+ value="com.canonical.unity.AccountsService.ModifyUsers"/>
8+
9+ <property name="demo-edges" type="b" access="readwrite">
10+ <annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
11+ </property>
12+
13+ </interface>
14+</node>
plugins/AccountsService/plugin.cppnew file+37
@@ -0,0 +1,37 @@
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: Gerry Boland <gerry.boland@canonical.com>
17+ * Michael Terry <michael.terry@canonical.com>
18+ */
19+
20+#include "plugin.h"
21+#include "AccountsService.h"
22+
23+#include <QtQml/QtQml>
24+
25+static QObject *service_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
26+{
27+ Q_UNUSED(engine)
28+ Q_UNUSED(scriptEngine)
29+ return new AccountsService();
30+}
31+
32+void LightDMPlugin::registerTypes(const char *uri)
33+{
34+ Q_ASSERT(uri == QLatin1String("AccountsService"));
35+ qmlRegisterSingletonType<AccountsService>(uri, 0, 1, "AccountsService", service_provider);
36+}
37+
plugins/AccountsService/plugin.hnew file+35
@@ -0,0 +1,35 @@
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: Gerry Boland <gerry.boland@canonical.com>
17+ * Michael Terry <michael.terry@canonical.com>
18+ */
19+
20+#ifndef ACCOUNTSSERVICE_PLUGIN_H
21+#define ACCOUNTSSERVICE_PLUGIN_H
22+
23+#include <QtQml/QQmlEngine>
24+#include <QtQml/QQmlExtensionPlugin>
25+
26+class LightDMPlugin : public QQmlExtensionPlugin
27+{
28+ Q_OBJECT
29+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
30+
31+public:
32+ void registerTypes(const char *uri);
33+};
34+
35+#endif
plugins/AccountsService/qmldirnew file+3
@@ -0,0 +1,3 @@
1+module AccountsService
2+plugin AccountsService-qml
3+typeinfo plugin.qmltypes
plugins/CMakeLists.txt+4−3
@@ -1,6 +1,7 @@
1−add_subdirectory(Ubuntu)
2−add_subdirectory(Utils)
3−add_subdirectory(Unity)
1+add_subdirectory(AccountsService)
42add_subdirectory(HudClient)
53add_subdirectory(LightDM)
64add_subdirectory(ListViewWithPageHeader)
5+add_subdirectory(Ubuntu)
6+add_subdirectory(Unity)
7+add_subdirectory(Utils)