19 #include "AccountsService.h"
20 #include "AccountsServiceDBusAdaptor.h"
23 #include <QStringList>
25 AccountsService::AccountsService(QObject* parent)
27 m_service(new AccountsServiceDBusAdaptor(this)),
30 m_enableLauncherWhileLocked(false),
31 m_enableIndicatorsWhileLocked(false),
32 m_statsWelcomeScreen(false),
33 m_passwordDisplayHint(Keyboard),
38 connect(m_service, SIGNAL(propertiesChanged(
const QString &,
const QString &,
const QStringList &)),
39 this, SLOT(propertiesChanged(
const QString &,
const QString &,
const QStringList &)));
40 connect(m_service, SIGNAL(maybeChanged(
const QString &)),
41 this, SLOT(maybeChanged(
const QString &)));
43 setUser(qgetenv(
"USER"));
46 QString AccountsService::user()
const
51 void AccountsService::setUser(
const QString &user)
53 if (user.isEmpty() || m_user == user)
60 updateEnableLauncherWhileLocked();
61 updateEnableIndicatorsWhileLocked();
62 updateBackgroundFile();
63 updateStatsWelcomeScreen();
64 updatePasswordDisplayHint();
67 updateHereLicensePath();
70 bool AccountsService::demoEdges()
const
75 void AccountsService::setDemoEdges(
bool demoEdges)
77 m_demoEdges = demoEdges;
78 m_service->setUserProperty(m_user,
"com.canonical.unity.AccountsService",
"demo-edges", demoEdges);
81 bool AccountsService::enableLauncherWhileLocked()
const
83 return m_enableLauncherWhileLocked;
86 bool AccountsService::enableIndicatorsWhileLocked()
const
88 return m_enableIndicatorsWhileLocked;
91 QString AccountsService::backgroundFile()
const
93 return m_backgroundFile;
96 bool AccountsService::statsWelcomeScreen()
const
98 return m_statsWelcomeScreen;
101 AccountsService::PasswordDisplayHint AccountsService::passwordDisplayHint()
const
103 return m_passwordDisplayHint;
106 bool AccountsService::hereEnabled()
const
108 return m_hereEnabled;
111 void AccountsService::setHereEnabled(
bool enabled)
113 m_service->setUserProperty(m_user,
"com.ubuntu.location.providers.here.AccountsService",
"LicenseAccepted", enabled);
116 QString AccountsService::hereLicensePath()
const
118 return m_hereLicensePath;
121 bool AccountsService::hereLicensePathValid()
const
123 return !m_hereLicensePath.isNull();
126 void AccountsService::updateDemoEdges()
128 auto demoEdges = m_service->getUserProperty(m_user,
"com.canonical.unity.AccountsService",
"demo-edges").toBool();
129 if (m_demoEdges != demoEdges) {
130 m_demoEdges = demoEdges;
131 Q_EMIT demoEdgesChanged();
135 void AccountsService::updateEnableLauncherWhileLocked()
137 auto enableLauncherWhileLocked = m_service->getUserProperty(m_user,
"com.ubuntu.AccountsService.SecurityPrivacy",
"EnableLauncherWhileLocked").toBool();
138 if (m_enableLauncherWhileLocked != enableLauncherWhileLocked) {
139 m_enableLauncherWhileLocked = enableLauncherWhileLocked;
140 Q_EMIT enableLauncherWhileLockedChanged();
144 void AccountsService::updateEnableIndicatorsWhileLocked()
146 auto enableIndicatorsWhileLocked = m_service->getUserProperty(m_user,
"com.ubuntu.AccountsService.SecurityPrivacy",
"EnableIndicatorsWhileLocked").toBool();
147 if (m_enableIndicatorsWhileLocked != enableIndicatorsWhileLocked) {
148 m_enableIndicatorsWhileLocked = enableIndicatorsWhileLocked;
149 Q_EMIT enableIndicatorsWhileLockedChanged();
153 void AccountsService::updateBackgroundFile()
155 QString backgroundFile = m_service->getUserProperty(m_user,
"org.freedesktop.Accounts.User",
"BackgroundFile").toString();
156 if (m_backgroundFile != backgroundFile) {
157 m_backgroundFile = backgroundFile;
158 Q_EMIT backgroundFileChanged();
162 void AccountsService::updateStatsWelcomeScreen()
164 bool statsWelcomeScreen = m_service->getUserProperty(m_user,
"com.ubuntu.touch.AccountsService.SecurityPrivacy",
"StatsWelcomeScreen").toBool();
165 if (m_statsWelcomeScreen != statsWelcomeScreen) {
166 m_statsWelcomeScreen = statsWelcomeScreen;
167 Q_EMIT statsWelcomeScreenChanged();
171 void AccountsService::updatePasswordDisplayHint()
173 PasswordDisplayHint passwordDisplayHint = (PasswordDisplayHint)m_service->getUserProperty(m_user,
"com.ubuntu.AccountsService.SecurityPrivacy",
"PasswordDisplayHint").toInt();
174 if (m_passwordDisplayHint != passwordDisplayHint) {
175 m_passwordDisplayHint = passwordDisplayHint;
176 Q_EMIT passwordDisplayHintChanged();
180 void AccountsService::updateFailedLogins()
182 uint failedLogins = m_service->getUserProperty(m_user,
"com.canonical.unity.AccountsService.Private",
"FailedLogins").toUInt();
183 if (m_failedLogins != failedLogins) {
184 m_failedLogins = failedLogins;
185 Q_EMIT failedLoginsChanged();
189 void AccountsService::updateHereEnabled()
191 bool hereEnabled = m_service->getUserProperty(m_user,
"com.ubuntu.location.providers.here.AccountsService",
"LicenseAccepted").toBool();
192 if (m_hereEnabled != hereEnabled) {
193 m_hereEnabled = hereEnabled;
194 Q_EMIT hereEnabledChanged();
198 void AccountsService::updateHereLicensePath()
200 QString hereLicensePath = m_service->getUserProperty(m_user,
"com.ubuntu.location.providers.here.AccountsService",
"LicenseBasePath").toString();
202 if (hereLicensePath.isEmpty() || !QFile::exists(hereLicensePath))
203 hereLicensePath =
"";
205 if (m_hereLicensePath.isNull() || m_hereLicensePath != hereLicensePath) {
206 m_hereLicensePath = hereLicensePath;
207 Q_EMIT hereLicensePathChanged();
211 uint AccountsService::failedLogins()
const
213 return m_failedLogins;
216 void AccountsService::setFailedLogins(uint failedLogins)
218 m_failedLogins = failedLogins;
219 m_service->setUserProperty(m_user,
"com.canonical.unity.AccountsService.Private",
"FailedLogins", failedLogins);
222 void AccountsService::propertiesChanged(
const QString &user,
const QString &interface,
const QStringList &changed)
224 if (m_user != user) {
228 if (interface ==
"com.canonical.unity.AccountsService") {
229 if (changed.contains(
"demo-edges")) {
232 }
else if (interface ==
"com.canonical.unity.AccountsService.Private") {
233 if (changed.contains(
"FailedLogins")) {
234 updateFailedLogins();
236 }
else if (interface ==
"com.ubuntu.touch.AccountsService.SecurityPrivacy") {
237 if (changed.contains(
"StatsWelcomeScreen")) {
238 updateStatsWelcomeScreen();
240 }
else if (interface ==
"com.ubuntu.AccountsService.SecurityPrivacy") {
241 if (changed.contains(
"PasswordDisplayHint")) {
242 updatePasswordDisplayHint();
244 if (changed.contains(
"EnableLauncherWhileLocked")) {
245 updateEnableLauncherWhileLocked();
247 if (changed.contains(
"EnableIndicatorsWhileLocked")) {
248 updateEnableIndicatorsWhileLocked();
250 }
else if (interface ==
"com.ubuntu.location.providers.here.AccountsService") {
251 if (changed.contains(
"LicenseAccepted")) {
254 if (changed.contains(
"LicenseBasePath")) {
255 updateHereLicensePath();
260 void AccountsService::maybeChanged(
const QString &user)
262 if (m_user != user) {
267 updateBackgroundFile();