Unity 8
 All Classes Functions Properties
AccountsService.cpp
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  */
18 
19 #include "AccountsService.h"
20 #include "AccountsServiceDBusAdaptor.h"
21 
22 #include <QStringList>
23 
24 AccountsService::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 {
31  connect(m_service, SIGNAL(propertiesChanged(const QString &, const QString &, const QStringList &)),
32  this, SLOT(propertiesChanged(const QString &, const QString &, const QStringList &)));
33  connect(m_service, SIGNAL(maybeChanged(const QString &)),
34  this, SLOT(maybeChanged(const QString &)));
35 }
36 
37 QString AccountsService::user() const
38 {
39  return m_user;
40 }
41 
42 void AccountsService::setUser(const QString &user)
43 {
44  m_user = user;
45  Q_EMIT userChanged();
46 
47  updateDemoEdges();
48  updateBackgroundFile();
49  updateStatsWelcomeScreen();
50 }
51 
52 bool AccountsService::demoEdges() const
53 {
54  return m_demoEdges;
55 }
56 
57 void AccountsService::setDemoEdges(bool demoEdges)
58 {
59  m_demoEdges = demoEdges;
60  m_service->setUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges", demoEdges);
61 }
62 
63 QString AccountsService::backgroundFile() const
64 {
65  return m_backgroundFile;
66 }
67 
68 bool AccountsService::statsWelcomeScreen() const
69 {
70  return m_statsWelcomeScreen;
71 }
72 
73 void AccountsService::updateDemoEdges()
74 {
75  auto demoEdges = m_service->getUserProperty(m_user, "com.canonical.unity.AccountsService", "demo-edges").toBool();
76  if (m_demoEdges != demoEdges) {
77  m_demoEdges = demoEdges;
78  Q_EMIT demoEdgesChanged();
79  }
80 }
81 
82 void AccountsService::updateBackgroundFile()
83 {
84  auto backgroundFile = m_service->getUserProperty(m_user, "org.freedesktop.Accounts.User", "BackgroundFile").toString();
85  if (m_backgroundFile != backgroundFile) {
86  m_backgroundFile = backgroundFile;
87  Q_EMIT backgroundFileChanged();
88  }
89 }
90 
91 void AccountsService::updateStatsWelcomeScreen()
92 {
93  bool statsWelcomeScreen = m_service->getUserProperty(m_user, "com.ubuntu.touch.AccountsService.SecurityPrivacy", "StatsWelcomeScreen").toBool();
94  if (m_statsWelcomeScreen != statsWelcomeScreen) {
95  m_statsWelcomeScreen = statsWelcomeScreen;
96  Q_EMIT statsWelcomeScreenChanged();
97  }
98 }
99 
100 void AccountsService::propertiesChanged(const QString &user, const QString &interface, const QStringList &changed)
101 {
102  if (m_user != user) {
103  return;
104  }
105 
106  if (interface == "com.canonical.unity.AccountsService") {
107  if (changed.contains("demo-edges")) {
108  updateDemoEdges();
109  }
110  } else if (interface == "com.ubuntu.touch.AccountsService.SecurityPrivacy") {
111  if (changed.contains("StatsWelcomeScreen")) {
112  updateStatsWelcomeScreen();
113  }
114  }
115 }
116 
117 void AccountsService::maybeChanged(const QString &user)
118 {
119  if (m_user != user) {
120  return;
121  }
122 
123  // Standard properties might have changed
124  updateBackgroundFile();
125 }