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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-12-10 00:26:51 +0000
+++ CMakeLists.txt 2014-01-07 10:49:39 +0000
@@ -57,10 +57,13 @@
5757
58set(ANDR_PROP_LIB -landroid-properties)58set(ANDR_PROP_LIB -landroid-properties)
5959
60SET(CMAKE_INSTALL_RPATH "${PLUGIN_MODULE_DIR}")
61
60add_subdirectory(po)62add_subdirectory(po)
61add_subdirectory(schema)63add_subdirectory(schema)
62add_subdirectory(lib)64add_subdirectory(lib)
63include_directories(lib)65include_directories(lib)
66include_directories(src)
64add_subdirectory(plugins)67add_subdirectory(plugins)
65add_subdirectory(src)68add_subdirectory(src)
66add_subdirectory(tests)69add_subdirectory(tests)
6770
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2013-12-10 15:01:37 +0000
+++ src/CMakeLists.txt 2014-01-07 10:49:39 +0000
@@ -7,7 +7,7 @@
77
8add_subdirectory(SystemSettings)8add_subdirectory(SystemSettings)
99
10set(USS_SOURCES 10set(USS_SOURCES
11 debug.cpp11 debug.cpp
12 i18n.cpp12 i18n.cpp
13 item-model.cpp13 item-model.cpp
@@ -32,6 +32,11 @@
32target_link_libraries(system-settings SystemSettings)32target_link_libraries(system-settings SystemSettings)
33install(TARGETS system-settings RUNTIME DESTINATION bin)33install(TARGETS system-settings RUNTIME DESTINATION bin)
3434
35add_library(uss-accountsservice SHARED accountsservice.h accountsservice.cpp)
36qt5_use_modules(uss-accountsservice Core Qml DBus)
37set_target_properties(uss-accountsservice PROPERTIES VERSION 0.0 SOVERSION 0.0)
38install(TARGETS uss-accountsservice LIBRARY DESTINATION ${PLUGIN_MODULE_DIR} NAMELINK_SKIP)
39
35add_custom_target(po COMMAND40add_custom_target(po COMMAND
36${XGETTEXT_BIN} -o ${CMAKE_SOURCE_DIR}/po/ubuntu-system-settings.pot -d ubuntu-system-settings41${XGETTEXT_BIN} -o ${CMAKE_SOURCE_DIR}/po/ubuntu-system-settings.pot -d ubuntu-system-settings
37--keyword=_ ${USS_SOURCES}42--keyword=_ ${USS_SOURCES}
3843
=== added file 'src/accountsservice.cpp'
--- src/accountsservice.cpp 1970-01-01 00:00:00 +0000
+++ src/accountsservice.cpp 2014-01-07 10:49:39 +0000
@@ -0,0 +1,157 @@
1/*
2 * This file is part of system-settings
3 *
4 * Copyright (C) 2013 Canonical Ltd.
5 *
6 * Contact: Iain Lane <iain.lane@canonical.com>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "accountsservice.h"
22
23#include <QDBusReply>
24
25#include <unistd.h>
26#include <sys/types.h>
27
28#define AS_SERVICE "org.freedesktop.Accounts"
29#define AS_PATH "/org/freedesktop/Accounts"
30#define AS_IFACE "org.freedesktop.Accounts"
31
32AccountsService::AccountsService(QObject *parent)
33 : QObject(parent),
34 m_systemBusConnection(QDBusConnection::systemBus()),
35 m_serviceWatcher(AS_SERVICE,
36 m_systemBusConnection,
37 QDBusServiceWatcher::WatchForOwnerChange),
38 m_accountsserviceIface(AS_SERVICE,
39 AS_PATH,
40 AS_IFACE,
41 m_systemBusConnection)
42{
43 connect (&m_serviceWatcher,
44 SIGNAL (serviceOwnerChanged (QString, QString, QString)),
45 this,
46 SLOT (slotNameOwnerChanged (QString, QString, QString)));
47
48 if (m_accountsserviceIface.isValid()) {
49 setUpInterface();
50 }
51}
52
53void AccountsService::slotChanged(QString interface,
54 QVariantMap changed_properties,
55 QStringList invalidated_properties)
56{
57 Q_UNUSED (changed_properties);
58
59 Q_FOREACH (const QString prop, invalidated_properties)
60 Q_EMIT propertyChanged(interface, prop);
61}
62
63
64void AccountsService::slotNameOwnerChanged(QString name,
65 QString oldOwner,
66 QString newOwner)
67{
68 Q_UNUSED (oldOwner);
69 Q_UNUSED (newOwner);
70 if (name != "org.freedesktop.Accounts")
71 return;
72
73 setUpInterface();
74 Q_EMIT (nameOwnerChanged());
75}
76
77void AccountsService::setUpInterface()
78{
79 QDBusReply<QDBusObjectPath> qObjectPath = m_accountsserviceIface.call(
80 "FindUserById", qlonglong(getuid()));
81
82 if (qObjectPath.isValid()) {
83 m_objectPath = qObjectPath.value().path();
84 m_accountsserviceIface.connection().connect(
85 m_accountsserviceIface.service(),
86 m_objectPath,
87 "org.freedesktop.DBus.Properties",
88 "PropertiesChanged",
89 this,
90 SLOT(slotChanged(QString, QVariantMap, QStringList)));
91 m_accountsserviceIface.connection().connect(
92 m_accountsserviceIface.service(),
93 m_objectPath,
94 "org.freedesktop.Accounts.User",
95 "Changed",
96 this,
97 SIGNAL (changed ()));
98 }
99}
100
101QVariant AccountsService::getUserProperty(const QString &interface,
102 const QString &property)
103{
104 if (!m_accountsserviceIface.isValid())
105 return QVariant();
106
107 QDBusInterface iface (
108 "org.freedesktop.Accounts",
109 m_objectPath,
110 "org.freedesktop.DBus.Properties",
111 m_systemBusConnection,
112 this);
113
114 if (iface.isValid()) {
115 QDBusReply<QDBusVariant> answer = iface.call(
116 "Get",
117 interface,
118 property);
119 if (answer.isValid()) {
120 return answer.value().variant();
121 }
122 }
123 return QVariant();
124}
125
126void AccountsService::setUserProperty(const QString &interface,
127 const QString &property,
128 const QVariant &value)
129{
130 QDBusInterface iface (
131 "org.freedesktop.Accounts",
132 m_objectPath,
133 "org.freedesktop.DBus.Properties",
134 m_systemBusConnection,
135 this);
136 if (iface.isValid()) {
137 // The value needs to be carefully wrapped
138 iface.call("Set",
139 interface,
140 property,
141 QVariant::fromValue(QDBusVariant(value)));
142 }
143}
144
145void AccountsService::customSetUserProperty(const QString &method,
146 const QVariant &value)
147{
148 QDBusInterface iface ("org.freedesktop.Accounts",
149 m_objectPath,
150 "org.freedesktop.Accounts.User",
151 m_systemBusConnection,
152 this);
153
154 if (iface.isValid())
155 iface.call(method, value);
156
157}
0158
=== added file 'src/accountsservice.h'
--- src/accountsservice.h 1970-01-01 00:00:00 +0000
+++ src/accountsservice.h 2014-01-07 10:49:39 +0000
@@ -0,0 +1,64 @@
1/*
2 * This file is part of system-settings
3 *
4 * Copyright (C) 2013 Canonical Ltd.
5 *
6 * Contact: Iain Lane <iain.lane@canonical.com>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef ACCOUNTSSERVICE_H
22#define ACCOUNTSSERVICE_H
23
24#include <QDBusServiceWatcher>
25#include <QStringList>
26#include <QtDBus/QDBusInterface>
27
28class AccountsService : public QObject
29{
30 Q_OBJECT
31
32public:
33 explicit AccountsService (QObject *parent = 0);
34
35 QString getProperty (QString property);
36 QVariant getUserProperty(const QString &interface,
37 const QString &property);
38 void setUserProperty(const QString &interface,
39 const QString &property,
40 const QVariant &value);
41 void customSetUserProperty(const QString &method,
42 const QVariant &value);
43
44
45public Q_SLOTS:
46 void slotChanged(QString, QVariantMap, QStringList);
47 void slotNameOwnerChanged(QString, QString, QString);
48
49Q_SIGNALS:
50 void propertyChanged(QString interface, QString property);
51 void changed();
52 void nameOwnerChanged();
53
54private:
55 QDBusConnection m_systemBusConnection;
56 QDBusServiceWatcher m_serviceWatcher;
57 QDBusInterface m_accountsserviceIface;
58 QString m_objectPath;
59
60 void setUpInterface();
61
62};
63
64#endif // ACCOUNTSSERVICE_H

Subscribers

People subscribed via source and target branches