on ded80f4 help sign in
unity8/plugins/AccountsService/AccountsService.cpp
145 lines 4.4 kB history raw
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 */
19#include "AccountsService.h"
20#include "AccountsServiceDBusAdaptor.h"
22#include <QStringList>
24AccountsService::AccountsService(QObject* parent)
25 : QObject(parent),
26 m_service(new AccountsServiceDBusAdaptor(this)),
27 m_user(qgetenv("USER")),
28 m_demoEdges(false),
29 m_statsWelcomeScreen(false),
30 m_passwordDisplayHint(Keyboard)
32 connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
33 this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
34 connect(m_service, SIGNAL(maybeChanged(const QString &)),
35 this, SLOT(maybeChanged(const QString &)));
38QString AccountsService::user() const
40 return m_user;
43void AccountsService::setUser(const QString &user)
45 m_user = user;
46 Q_EMIT userChanged();
48 updateDemoEdges();
49 updateBackgroundFile();
50 updateStatsWelcomeScreen();
51 updatePasswordDisplayHint();
54bool AccountsService::demoEdges() const
56 return m_demoEdges;
59void AccountsService::setDemoEdges(bool demoEdges)
61 m_demoEdges = demoEdges;
62 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
65QString AccountsService::backgroundFile() const
67 return m_backgroundFile;
70bool AccountsService::statsWelcomeScreen() const
72 return m_statsWelcomeScreen;
75AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint() const
77 return m_passwordDisplayHint;
80void AccountsService::updateDemoEdges()
82 auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
83 if (m_demoEdges != demoEdges) {
84 m_demoEdges = demoEdges;
85 Q_EMIT demoEdgesChanged();
86 }
89void AccountsService::updateBackgroundFile()
91 auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
92 if (m_backgroundFile != backgroundFile) {
93 m_backgroundFile = backgroundFile;
94 Q_EMIT backgroundFileChanged();
95 }
98void AccountsService::updateStatsWelcomeScreen()
100 bool statsWelcomeScreen = m_service->getUserProperty(m_user, "com.ubuntu.touch.AccountsService.SecurityPrivacy", "StatsWelcomeScreen").toBool();
101 if (m_statsWelcomeScreen != statsWelcomeScreen) {
102 m_statsWelcomeScreen = statsWelcomeScreen;
103 Q_EMIT statsWelcomeScreenChanged();
104 }
107void AccountsService::updatePasswordDisplayHint()
109 PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)m_service->getUserProperty(m_user, "com.ubuntu.AccountsService.SecurityPrivacy", "PasswordDisplayHint").toInt();
110 if (m_passwordDisplayHint != passwordDisplayHint) {
111 m_passwordDisplayHint = passwordDisplayHint;
112 Q_EMIT passwordDisplayHintChanged();
113 }
116void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
118 if (m_user != user) {
119 return;
120 }
122 if (interface == "com.canonical.unity.AccountsService") {
123 if (changed.contains("demo-edges")) {
124 updateDemoEdges();
125 }
126 } else if (interface == "com.ubuntu.touch.AccountsService.SecurityPrivacy") {
127 if (changed.contains("StatsWelcomeScreen")) {
128 updateStatsWelcomeScreen();
129 }
130 } else if (interface == "com.ubuntu.AccountsService.SecurityPrivacy") {
131 if (changed.contains("PasswordDisplayHint")) {
132 updatePasswordDisplayHint();
133 }
134 }
137void AccountsService::maybeChanged(const QString &user)
139 if (m_user != user) {
140 return;
141 }
143 // Standard properties might have changed
144 updateBackgroundFile();