on 00a39ec help sign in
unity8/plugins/AccountsService/AccountsService.cpp
125 lines 3.8 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))
28 connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
29 this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
30 connect(m_service, SIGNAL(maybeChanged(const QString &)),
31 this, SLOT(maybeChanged(const QString &)));
33 setUser(qgetenv("USER"));
34 updateDemoEdgesForCurrentUser();
37QString AccountsService::user() const
39 return m_user;
42void AccountsService::setUser(const QString &user)
44 m_user = user;
45 Q_EMIT userChanged();
47 updateDemoEdges();
48 updateBackgroundFile();
51bool AccountsService::demoEdges() const
53 return m_demoEdges;
56void AccountsService::setDemoEdges(bool demoEdges)
58 m_demoEdges = demoEdges;
59 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
62bool AccountsService::demoEdgesForCurrentUser() const
64 return m_demoEdgesForCurrentUser;
67void AccountsService::setDemoEdgesForCurrentUser(bool demoEdgesForCurrentUser)
69 m_demoEdgesForCurrentUser = demoEdgesForCurrentUser;
70 m_service->setUserProperty(qgetenv("USER"), "com.canonical.unity.AccountsService", "demo-edges", demoEdgesForCurrentUser);
73QString AccountsService::backgroundFile() const
75 return m_backgroundFile;
78void AccountsService::updateDemoEdges()
80 auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
81 if (m_demoEdges != demoEdges) {
82 m_demoEdges = demoEdges;
83 Q_EMIT demoEdgesChanged();
84 }
87void AccountsService::updateDemoEdgesForCurrentUser()
89 auto demoEdgesForCurrentUser = m_service->getUserProperty(qgetenv("USER"), "com.canonical.unity.AccountsService", "demo-edges").toBool();
90 if (m_demoEdgesForCurrentUser != demoEdgesForCurrentUser) {
91 m_demoEdgesForCurrentUser = demoEdgesForCurrentUser;
92 Q_EMIT demoEdgesForCurrentUserChanged();
93 }
96void AccountsService::updateBackgroundFile()
98 auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
99 if (m_backgroundFile != backgroundFile) {
100 m_backgroundFile = backgroundFile;
101 Q_EMIT backgroundFileChanged();
102 }
105void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
107 if (interface == "com.canonical.unity.AccountsService") {
108 if (changed.contains("demo-edges")) {
109 if (qgetenv("USER") == user) {
110 updateDemoEdgesForCurrentUser();
111 }
112 if (m_user != user) {
113 updateDemoEdges();
114 }
115 }
116 }
119void AccountsService::maybeChanged(const QString &user)
121 if (m_user == user) {
122 // Standard properties might have changed
123 updateBackgroundFile();
124 }