on xenial help sign in
implement saving/loading Email and RealName fields in AS
commit9a4ba2f0ada1500dbab6a285aa5f8d035ab9f8e8 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateWed 9 Sep 2015, 19:26 (11 years ago) parent5dbcf6f
4 files changed+132−15
plugins/AccountsService/AccountsService.cpp+83−3 plugins/AccountsService/AccountsService.h+14−4 tests/mocks/AccountsService/AccountsService.cpp+23−3 tests/mocks/AccountsService/AccountsService.h+12−5
plugins/AccountsService/AccountsService.cpp+83−3
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -12,8 +12,6 @@
1212 *
1313 * You should have received a copy of the GNU General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Author: Michael Terry <michael.terry@canonical.com>
1715 */
1816
1917#include "AccountsService.h"
@@ -130,6 +128,34 @@ bool AccountsService::hereLicensePathValid() const
130128 return !m_hereLicensePath.isNull();
131129}
132130
131+QString AccountsService::realName() const
132+{
133+ return m_realName;
134+}
135+
136+void AccountsService::setRealName(const QString &realName)
137+{
138+ if (realName != m_realName) {
139+ m_realName = realName;
140+ m_service->setUserProperty(m_user, "org.freedesktop.Accounts.User", "RealName", m_realName);
141+ Q_EMIT realNameChanged();
142+ }
143+}
144+
145+QString AccountsService::email() const
146+{
147+ return m_email;
148+}
149+
150+void AccountsService::setEmail(const QString &email)
151+{
152+ if (email != m_email) {
153+ m_email = email;
154+ m_service->setUserProperty(m_user, "org.freedesktop.Accounts.User", "Email", m_email);
155+ Q_EMIT emailChanged();
156+ }
157+}
158+
133159void AccountsService::updateDemoEdges(bool async)
134160{
135161 QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user,
@@ -394,6 +420,58 @@ void AccountsService::updateHereLicensePath(bool async)
394420 }
395421}
396422
423+void AccountsService::updateRealName(bool async)
424+{
425+ QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user, "org.freedesktop.Accounts.User", "RealName");
426+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
427+
428+ connect(watcher, &QDBusPendingCallWatcher::finished,
429+ this, [this](QDBusPendingCallWatcher* watcher) {
430+ QDBusPendingReply<QVariant> reply = *watcher;
431+ watcher->deleteLater();
432+ if (reply.isError()) {
433+ qWarning() << "Failed to get 'RealName' property - " << reply.error().message();
434+ return;
435+ }
436+
437+ const QString realName = reply.value().toString();
438+ if (m_realName != realName) {
439+ m_realName = realName;
440+ Q_EMIT realNameChanged();
441+ }
442+ });
443+ if (!async) {
444+ watcher->waitForFinished();
445+ delete watcher;
446+ }
447+}
448+
449+void AccountsService::updateEmail(bool async)
450+{
451+ QDBusPendingCall pendingReply = m_service->getUserPropertyAsync(m_user, "org.freedesktop.Accounts.User", "Email");
452+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingReply, this);
453+
454+ connect(watcher, &QDBusPendingCallWatcher::finished,
455+ this, [this](QDBusPendingCallWatcher* watcher) {
456+ QDBusPendingReply<QVariant> reply = *watcher;
457+ watcher->deleteLater();
458+ if (reply.isError()) {
459+ qWarning() << "Failed to get 'Email' property - " << reply.error().message();
460+ return;
461+ }
462+
463+ const QString email = reply.value().toString();
464+ if (m_email != email) {
465+ m_email = email;
466+ Q_EMIT emailChanged();
467+ }
468+ });
469+ if (!async) {
470+ watcher->waitForFinished();
471+ delete watcher;
472+ }
473+}
474+
397475uint AccountsService::failedLogins() const
398476{
399477 return m_failedLogins;
@@ -455,4 +533,6 @@ void AccountsService::onMaybeChanged(const QString &user)
455533
456534 // Standard properties might have changed
457535 updateBackgroundFile();
536+ updateRealName();
537+ updateEmail();
458538}
plugins/AccountsService/AccountsService.h+14−4
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -12,8 +12,6 @@
1212 *
1313 * You should have received a copy of the GNU General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors: Michael Terry <michael.terry@canonical.com>
1715 */
1816
1917#ifndef UNITY_ACCOUNTSSERVICE_H
@@ -65,11 +63,13 @@ class AccountsService: public QObject
6563 Q_PROPERTY(bool hereLicensePathValid // qml sees a null string as "", so we use proxy setting for that
6664 READ hereLicensePathValid
6765 NOTIFY hereLicensePathChanged)
66+ Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
67+ Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
6868
6969public:
7070 enum PasswordDisplayHint {
7171 Keyboard,
72− Numeric,
72+ Numeric
7373 };
7474
7575 explicit AccountsService(QObject *parent = 0, const QString & user = QString());
@@ -90,6 +90,10 @@ public:
9090 void setHereEnabled(bool enabled);
9191 QString hereLicensePath() const;
9292 bool hereLicensePathValid() const;
93+ QString realName() const;
94+ void setRealName(const QString &realName);
95+ QString email() const;
96+ void setEmail(const QString &email);
9397
9498Q_SIGNALS:
9599 void userChanged();
@@ -102,6 +106,8 @@ Q_SIGNALS:
102106 void failedLoginsChanged();
103107 void hereEnabledChanged();
104108 void hereLicensePathChanged();
109+ void realNameChanged();
110+ void emailChanged();
105111
106112private Q_SLOTS:
107113 void onPropertiesChanged(const QString &user, const QString &interface, const QStringList &changed);
@@ -117,6 +123,8 @@ private:
117123 void updateFailedLogins(bool async = true);
118124 void updateHereEnabled(bool async = true);
119125 void updateHereLicensePath(bool async = true);
126+ void updateRealName(bool async = true);
127+ void updateEmail(bool async = true);
120128
121129 AccountsServiceDBusAdaptor *m_service;
122130 QString m_user;
@@ -129,6 +137,8 @@ private:
129137 uint m_failedLogins;
130138 bool m_hereEnabled;
131139 QString m_hereLicensePath;
140+ QString m_realName;
141+ QString m_email;
132142};
133143
134144#endif
tests/mocks/AccountsService/AccountsService.cpp+23−3
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -12,8 +12,6 @@
1212 *
1313 * You should have received a copy of the GNU General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Author: Michael Terry <michael.terry@canonical.com>
1715 */
1816
1917#include "AccountsService.h"
@@ -152,3 +150,25 @@ bool AccountsService::hereLicensePathValid() const
152150{
153151 return !m_hereLicensePath.isNull();
154152}
153+
154+QString AccountsService::realName() const
155+{
156+ return m_realName;
157+}
158+
159+void AccountsService::setRealName(const QString &realName)
160+{
161+ m_realName = realName;
162+ Q_EMIT realNameChanged();
163+}
164+
165+QString AccountsService::email() const
166+{
167+ return m_email;
168+}
169+
170+void AccountsService::setEmail(const QString &email)
171+{
172+ m_email = email;
173+ Q_EMIT emailChanged();
174+}
tests/mocks/AccountsService/AccountsService.h+12−5
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013, 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -12,9 +12,6 @@
1212 *
1313 * You should have received a copy of the GNU General Public License
1414 * 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>
1815 */
1916
2017#ifndef UNITY_MOCK_ACCOUNTSSERVICE_H
@@ -70,11 +67,13 @@ class AccountsService: public QObject
7067 Q_PROPERTY(bool hereLicensePathValid // qml sees a null string as "", so we use proxy setting for that
7168 READ hereLicensePathValid
7269 NOTIFY hereLicensePathChanged)
70+ Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
71+ Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
7372
7473public:
7574 enum PasswordDisplayHint {
7675 Keyboard,
77− Numeric,
76+ Numeric
7877 };
7978
8079 explicit AccountsService(QObject *parent = 0);
@@ -99,6 +98,10 @@ public:
9998 QString hereLicensePath() const;
10099 void setHereLicensePath(const QString &path);
101100 bool hereLicensePathValid() const;
101+ QString realName() const;
102+ void setRealName(const QString &realName);
103+ QString email() const;
104+ void setEmail(const QString &email);
102105
103106Q_SIGNALS:
104107 void userChanged();
@@ -111,6 +114,8 @@ Q_SIGNALS:
111114 void failedLoginsChanged();
112115 void hereEnabledChanged();
113116 void hereLicensePathChanged();
117+ void realNameChanged();
118+ void emailChanged();
114119
115120private:
116121 bool m_enableLauncherWhileLocked;
@@ -122,6 +127,8 @@ private:
122127 bool m_demoEdges;
123128 bool m_hereEnabled;
124129 QString m_hereLicensePath;
130+ QString m_realName;
131+ QString m_email;
125132};
126133
127134#endif