Merge lp:~laney/ubuntu-system-settings/as-library into lp:ubuntu-system-settings

Proposed by Iain Lane
Status: Merged
Approved by: Ken VanDine
Approved revision: 549
Merged at revision: 548
Proposed branch: lp:~laney/ubuntu-system-settings/as-library
Merge into: lp:ubuntu-system-settings
Diff against target: 273 lines (+230/-1)
4 files modified
CMakeLists.txt (+3/-0)
src/CMakeLists.txt (+6/-1)
src/accountsservice.cpp (+157/-0)
src/accountsservice.h (+64/-0)
To merge this branch: bzr merge lp:~laney/ubuntu-system-settings/as-library
Reviewer Review Type Date Requested Status
Ken VanDine Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+200646@code.launchpad.net

Commit message

Create a private library for communicating with accountsservice.

Description of the change

Since we're about to be doing AS in yet another location, it makes sense to factor this stuff out. I made a private library called libuss-accountsservice, but another option would be to have a utilities library. Doesn't matter what we choose now, since we can do whatever is necessary as this is only an internal library.

To post a comment you must log in.
549. By Iain Lane

Set RPATH to have the runtime linker find the private libraries

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

looks great

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-12-10 00:26:51 +0000
3+++ CMakeLists.txt 2014-01-07 10:49:39 +0000
4@@ -57,10 +57,13 @@
5
6 set(ANDR_PROP_LIB -landroid-properties)
7
8+SET(CMAKE_INSTALL_RPATH "${PLUGIN_MODULE_DIR}")
9+
10 add_subdirectory(po)
11 add_subdirectory(schema)
12 add_subdirectory(lib)
13 include_directories(lib)
14+include_directories(src)
15 add_subdirectory(plugins)
16 add_subdirectory(src)
17 add_subdirectory(tests)
18
19=== modified file 'src/CMakeLists.txt'
20--- src/CMakeLists.txt 2013-12-10 15:01:37 +0000
21+++ src/CMakeLists.txt 2014-01-07 10:49:39 +0000
22@@ -7,7 +7,7 @@
23
24 add_subdirectory(SystemSettings)
25
26-set(USS_SOURCES
27+set(USS_SOURCES
28 debug.cpp
29 i18n.cpp
30 item-model.cpp
31@@ -32,6 +32,11 @@
32 target_link_libraries(system-settings SystemSettings)
33 install(TARGETS system-settings RUNTIME DESTINATION bin)
34
35+add_library(uss-accountsservice SHARED accountsservice.h accountsservice.cpp)
36+qt5_use_modules(uss-accountsservice Core Qml DBus)
37+set_target_properties(uss-accountsservice PROPERTIES VERSION 0.0 SOVERSION 0.0)
38+install(TARGETS uss-accountsservice LIBRARY DESTINATION ${PLUGIN_MODULE_DIR} NAMELINK_SKIP)
39+
40 add_custom_target(po COMMAND
41 ${XGETTEXT_BIN} -o ${CMAKE_SOURCE_DIR}/po/ubuntu-system-settings.pot -d ubuntu-system-settings
42 --keyword=_ ${USS_SOURCES}
43
44=== added file 'src/accountsservice.cpp'
45--- src/accountsservice.cpp 1970-01-01 00:00:00 +0000
46+++ src/accountsservice.cpp 2014-01-07 10:49:39 +0000
47@@ -0,0 +1,157 @@
48+/*
49+ * This file is part of system-settings
50+ *
51+ * Copyright (C) 2013 Canonical Ltd.
52+ *
53+ * Contact: Iain Lane <iain.lane@canonical.com>
54+ *
55+ * This program is free software: you can redistribute it and/or modify it
56+ * under the terms of the GNU General Public License version 3, as published
57+ * by the Free Software Foundation.
58+ *
59+ * This program is distributed in the hope that it will be useful, but
60+ * WITHOUT ANY WARRANTY; without even the implied warranties of
61+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
62+ * PURPOSE. See the GNU General Public License for more details.
63+ *
64+ * You should have received a copy of the GNU General Public License along
65+ * with this program. If not, see <http://www.gnu.org/licenses/>.
66+ */
67+
68+#include "accountsservice.h"
69+
70+#include <QDBusReply>
71+
72+#include <unistd.h>
73+#include <sys/types.h>
74+
75+#define AS_SERVICE "org.freedesktop.Accounts"
76+#define AS_PATH "/org/freedesktop/Accounts"
77+#define AS_IFACE "org.freedesktop.Accounts"
78+
79+AccountsService::AccountsService(QObject *parent)
80+ : QObject(parent),
81+ m_systemBusConnection(QDBusConnection::systemBus()),
82+ m_serviceWatcher(AS_SERVICE,
83+ m_systemBusConnection,
84+ QDBusServiceWatcher::WatchForOwnerChange),
85+ m_accountsserviceIface(AS_SERVICE,
86+ AS_PATH,
87+ AS_IFACE,
88+ m_systemBusConnection)
89+{
90+ connect (&m_serviceWatcher,
91+ SIGNAL (serviceOwnerChanged (QString, QString, QString)),
92+ this,
93+ SLOT (slotNameOwnerChanged (QString, QString, QString)));
94+
95+ if (m_accountsserviceIface.isValid()) {
96+ setUpInterface();
97+ }
98+}
99+
100+void AccountsService::slotChanged(QString interface,
101+ QVariantMap changed_properties,
102+ QStringList invalidated_properties)
103+{
104+ Q_UNUSED (changed_properties);
105+
106+ Q_FOREACH (const QString prop, invalidated_properties)
107+ Q_EMIT propertyChanged(interface, prop);
108+}
109+
110+
111+void AccountsService::slotNameOwnerChanged(QString name,
112+ QString oldOwner,
113+ QString newOwner)
114+{
115+ Q_UNUSED (oldOwner);
116+ Q_UNUSED (newOwner);
117+ if (name != "org.freedesktop.Accounts")
118+ return;
119+
120+ setUpInterface();
121+ Q_EMIT (nameOwnerChanged());
122+}
123+
124+void AccountsService::setUpInterface()
125+{
126+ QDBusReply<QDBusObjectPath> qObjectPath = m_accountsserviceIface.call(
127+ "FindUserById", qlonglong(getuid()));
128+
129+ if (qObjectPath.isValid()) {
130+ m_objectPath = qObjectPath.value().path();
131+ m_accountsserviceIface.connection().connect(
132+ m_accountsserviceIface.service(),
133+ m_objectPath,
134+ "org.freedesktop.DBus.Properties",
135+ "PropertiesChanged",
136+ this,
137+ SLOT(slotChanged(QString, QVariantMap, QStringList)));
138+ m_accountsserviceIface.connection().connect(
139+ m_accountsserviceIface.service(),
140+ m_objectPath,
141+ "org.freedesktop.Accounts.User",
142+ "Changed",
143+ this,
144+ SIGNAL (changed ()));
145+ }
146+}
147+
148+QVariant AccountsService::getUserProperty(const QString &interface,
149+ const QString &property)
150+{
151+ if (!m_accountsserviceIface.isValid())
152+ return QVariant();
153+
154+ QDBusInterface iface (
155+ "org.freedesktop.Accounts",
156+ m_objectPath,
157+ "org.freedesktop.DBus.Properties",
158+ m_systemBusConnection,
159+ this);
160+
161+ if (iface.isValid()) {
162+ QDBusReply<QDBusVariant> answer = iface.call(
163+ "Get",
164+ interface,
165+ property);
166+ if (answer.isValid()) {
167+ return answer.value().variant();
168+ }
169+ }
170+ return QVariant();
171+}
172+
173+void AccountsService::setUserProperty(const QString &interface,
174+ const QString &property,
175+ const QVariant &value)
176+{
177+ QDBusInterface iface (
178+ "org.freedesktop.Accounts",
179+ m_objectPath,
180+ "org.freedesktop.DBus.Properties",
181+ m_systemBusConnection,
182+ this);
183+ if (iface.isValid()) {
184+ // The value needs to be carefully wrapped
185+ iface.call("Set",
186+ interface,
187+ property,
188+ QVariant::fromValue(QDBusVariant(value)));
189+ }
190+}
191+
192+void AccountsService::customSetUserProperty(const QString &method,
193+ const QVariant &value)
194+{
195+ QDBusInterface iface ("org.freedesktop.Accounts",
196+ m_objectPath,
197+ "org.freedesktop.Accounts.User",
198+ m_systemBusConnection,
199+ this);
200+
201+ if (iface.isValid())
202+ iface.call(method, value);
203+
204+}
205
206=== added file 'src/accountsservice.h'
207--- src/accountsservice.h 1970-01-01 00:00:00 +0000
208+++ src/accountsservice.h 2014-01-07 10:49:39 +0000
209@@ -0,0 +1,64 @@
210+/*
211+ * This file is part of system-settings
212+ *
213+ * Copyright (C) 2013 Canonical Ltd.
214+ *
215+ * Contact: Iain Lane <iain.lane@canonical.com>
216+ *
217+ * This program is free software: you can redistribute it and/or modify it
218+ * under the terms of the GNU General Public License version 3, as published
219+ * by the Free Software Foundation.
220+ *
221+ * This program is distributed in the hope that it will be useful, but
222+ * WITHOUT ANY WARRANTY; without even the implied warranties of
223+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
224+ * PURPOSE. See the GNU General Public License for more details.
225+ *
226+ * You should have received a copy of the GNU General Public License along
227+ * with this program. If not, see <http://www.gnu.org/licenses/>.
228+ */
229+
230+#ifndef ACCOUNTSSERVICE_H
231+#define ACCOUNTSSERVICE_H
232+
233+#include <QDBusServiceWatcher>
234+#include <QStringList>
235+#include <QtDBus/QDBusInterface>
236+
237+class AccountsService : public QObject
238+{
239+ Q_OBJECT
240+
241+public:
242+ explicit AccountsService (QObject *parent = 0);
243+
244+ QString getProperty (QString property);
245+ QVariant getUserProperty(const QString &interface,
246+ const QString &property);
247+ void setUserProperty(const QString &interface,
248+ const QString &property,
249+ const QVariant &value);
250+ void customSetUserProperty(const QString &method,
251+ const QVariant &value);
252+
253+
254+public Q_SLOTS:
255+ void slotChanged(QString, QVariantMap, QStringList);
256+ void slotNameOwnerChanged(QString, QString, QString);
257+
258+Q_SIGNALS:
259+ void propertyChanged(QString interface, QString property);
260+ void changed();
261+ void nameOwnerChanged();
262+
263+private:
264+ QDBusConnection m_systemBusConnection;
265+ QDBusServiceWatcher m_serviceWatcher;
266+ QDBusInterface m_accountsserviceIface;
267+ QString m_objectPath;
268+
269+ void setUpInterface();
270+
271+};
272+
273+#endif // ACCOUNTSSERVICE_H

Subscribers

People subscribed via source and target branches