on ea45856 help sign in
unity8/plugins/AccountsService/AccountsService.cpp
104 lines 2.9 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"))
29 connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
30 this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
31 connect(m_service, SIGNAL(maybeChanged(const QString &)),
32 this, SLOT(maybeChanged(const QString &)));
35QString AccountsService::getUser()
37 return m_user;
40void AccountsService::setUser(const QString &user)
42 m_user = user;
43 Q_EMIT userChanged();
45 updateDemoEdges();
46 updateBackgroundFile();
49bool AccountsService::getDemoEdges()
51 return m_demoEdges;
54void AccountsService::setDemoEdges(bool demoEdges)
56 m_demoEdges = demoEdges;
57 m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
60QString AccountsService::getBackgroundFile()
62 return m_backgroundFile;
65void AccountsService::updateDemoEdges()
67 auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
68 if (m_demoEdges != demoEdges) {
69 m_demoEdges = demoEdges;
70 Q_EMIT demoEdgesChanged();
71 }
74void AccountsService::updateBackgroundFile()
76 auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
77 if (m_backgroundFile != backgroundFile) {
78 m_backgroundFile = backgroundFile;
79 Q_EMIT backgroundFileChanged();
80 }
83void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
85 if (m_user != user) {
86 return;
87 }
89 if (interface == "com.canonical.unity.AccountsService") {
90 if (changed.contains("demo-edges")) {
91 updateDemoEdges();
92 }
93 }
96void AccountsService::maybeChanged(const QString &user)
98 if (m_user != user) {
99 return;
100 }
102 // Standard properties might have changed
103 updateBackgroundFile();