on bbbdccd help sign in
unity8/tests/mocks/GSettings.1.0/fake_gsettings.cpp
200 lines 5.4 kB history raw
1/*
2 * Copyright 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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "fake_gsettings.h"
19#include <QList>
21GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
23GSettingsControllerQml::GSettingsControllerQml()
24 : m_usageMode("Staged")
28GSettingsControllerQml::~GSettingsControllerQml() {
29 s_controllerInstance = 0;
32GSettingsControllerQml* GSettingsControllerQml::instance() {
33 if (!s_controllerInstance) {
34 s_controllerInstance = new GSettingsControllerQml();
35 }
36 return s_controllerInstance;
39QString GSettingsControllerQml::pictureUri() const
41 return m_pictureUri;
44void GSettingsControllerQml::setPictureUri(const QString &str)
46 if (str != m_pictureUri) {
47 m_pictureUri = str;
48 Q_EMIT pictureUriChanged(m_pictureUri);
49 }
52QString GSettingsControllerQml::usageMode() const
54 return m_usageMode;
57void GSettingsControllerQml::setUsageMode(const QString &usageMode)
59 if (usageMode != m_usageMode) {
60 m_usageMode = usageMode;
61 Q_EMIT usageModeChanged(m_usageMode);
62 }
65qint64 GSettingsControllerQml::lockedOutTime() const
67 return m_lockedOutTime;
70void GSettingsControllerQml::setLockedOutTime(qint64 timestamp)
72 if (m_lockedOutTime != timestamp) {
73 m_lockedOutTime = timestamp;
74 Q_EMIT lockedOutTimeChanged(m_lockedOutTime);
75 }
78QStringList GSettingsControllerQml::lifecycleExemptAppids() const
80 return m_lifecycleExemptAppids;
83void GSettingsControllerQml::setLifecycleExemptAppids(const QStringList &appIds)
85 if (m_lifecycleExemptAppids != appIds) {
86 m_lifecycleExemptAppids = appIds;
87 Q_EMIT lifecycleExemptAppidsChanged(m_lifecycleExemptAppids);
88 }
91GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
94QByteArray GSettingsSchemaQml::id() const {
95 return m_id;
98void GSettingsSchemaQml::setId(const QByteArray &id) {
99 if (!m_id.isEmpty()) {
100 qWarning("GSettings.schema.id may only be set on construction");
101 return;
102 }
104 m_id = id;
107QByteArray GSettingsSchemaQml::path() const {
108 return m_path;
111void GSettingsSchemaQml::setPath(const QByteArray &path) {
112 if (!m_path.isEmpty()) {
113 qWarning("GSettings.schema.path may only be set on construction");
114 return;
115 }
117 m_path = path;
120GSettingsQml::GSettingsQml(QObject *parent)
121 : QObject(parent)
123 m_schema = new GSettingsSchemaQml(this);
124 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::pictureUriChanged,
125 this, &GSettingsQml::pictureUriChanged);
126 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::usageModeChanged,
127 this, &GSettingsQml::usageModeChanged);
128 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::lockedOutTimeChanged,
129 this, &GSettingsQml::lockedOutTimeChanged);
130 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::lifecycleExemptAppidsChanged,
131 this, &GSettingsQml::lifecycleExemptAppidsChanged);
134GSettingsSchemaQml * GSettingsQml::schema() const {
135 return m_schema;
138QString GSettingsQml::pictureUri() const
140 if (m_schema->id() == "org.gnome.desktop.background") {
141 return GSettingsControllerQml::instance()->pictureUri();
142 } else {
143 return "";
144 }
147void GSettingsQml::setPictureUri(const QString &str)
149 if (m_schema->id() == "org.gnome.desktop.background") {
150 GSettingsControllerQml::instance()->setPictureUri(str);
151 }
154QString GSettingsQml::usageMode() const
156 if (m_schema->id() == "com.canonical.Unity8") {
157 return GSettingsControllerQml::instance()->usageMode();
158 } else {
159 return "";
160 }
163void GSettingsQml::setUsageMode(const QString &usageMode)
165 if (m_schema->id() == "com.canonical.Unity8") {
166 GSettingsControllerQml::instance()->setUsageMode(usageMode);
167 }
170qint64 GSettingsQml::lockedOutTime() const
172 if (m_schema->id() == "com.canonical.Unity8.Greeter") {
173 return GSettingsControllerQml::instance()->lockedOutTime();
174 } else {
175 return 0;
176 }
179void GSettingsQml::setLockedOutTime(qint64 timestamp)
181 if (m_schema->id() == "com.canonical.Unity8.Greeter") {
182 GSettingsControllerQml::instance()->setLockedOutTime(timestamp);
183 }
186QStringList GSettingsQml::lifecycleExemptAppids() const
188 if (m_schema->id() == "com.canonical.qtmir") {
189 return GSettingsControllerQml::instance()->lifecycleExemptAppids();
190 } else {
191 return QStringList();
192 }
195void GSettingsQml::setLifecycleExemptAppids(const QStringList &appIds)
197 if (m_schema->id() == "com.canonical.qtmir") {
198 GSettingsControllerQml::instance()->setLifecycleExemptAppids(appIds);
199 }