on xenial help sign in
fixed gsettings mock
commita2f95be0903630447dc34435a20f8a1dc342c6e7 authorNick Dedekind <nick.dedekind@canonical.com> dateWed 4 Mar 2015, 16:44 (12 years ago) parent3ecd12d
5 files changed+74−23
qml/Shell.qml+2−5 tests/mocks/GSettings.1.0/fake_gsettings.cpp+50−11 tests/mocks/GSettings.1.0/fake_gsettings.h+20−4 tests/qmltests/tst_DesktopShell.qml+1−1 tests/qmltests/tst_Shell.qml+1−2
qml/Shell.qml+2−5
@@ -78,8 +78,6 @@ Item {
7878 }
7979 }
8080
81− property string usageMode: usageModeSettings.usageMode
82−
8381 function activateApplication(appId) {
8482 if (ApplicationManager.findApplication(appId)) {
8583 ApplicationManager.requestFocusApplication(appId);
@@ -108,7 +106,6 @@ Item {
108106
109107 GSettings {
110108 id: backgroundSettings
111− objectName: "backgroundSettings"
112109 schema.id: "org.gnome.desktop.background"
113110 }
114111
@@ -231,7 +228,7 @@ Item {
231228 // the screen larger (maybe connects to monitor) and tries to enter
232229 // tablet mode.
233230 property bool tabletMode: shell.sideStageEnabled && !greeter.hasLockedApp
234− source: shell.usageMode === "Windowed" ? "Stages/DesktopStage.qml"
231+ source: usageModeSettings.usageMode === "Windowed" ? "Stages/DesktopStage.qml"
235232 : tabletMode ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
236233
237234 property bool interactive: tutorial.spreadEnabled
@@ -485,7 +482,7 @@ Item {
485482 available: tutorial.launcherEnabled
486483 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
487484 && !greeter.hasLockedApp
488− inverted: shell.usageMode === "Staged"
485+ inverted: usageModeSettings.usageMode === "Staged"
489486 shadeBackground: !tutorial.running
490487
491488 onShowDashHome: showHome()
tests/mocks/GSettings.1.0/fake_gsettings.cpp+50−11
@@ -17,6 +17,7 @@
1717#include "fake_gsettings.h"
1818
1919#include <QList>
20+#include <QDebug>
2021
2122GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
2223
@@ -42,12 +43,42 @@ void GSettingsControllerQml::unRegisterSettingsObject(GSettingsQml *obj) {
4243 m_registeredGSettings.removeOne(obj);
4344}
4445
45−void GSettingsControllerQml::setPictureUri(const QString &str) {
46− Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
47− obj->setPictureUri(str);
46+void GSettingsControllerQml::setPictureUri(const QByteArray &schemaId, const QString &str)
47+{
48+ if (m_pictureUri[schemaId] != str) {
49+ m_pictureUri[schemaId] = str;
50+
51+ Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
52+ if (obj->schema()->id() == schemaId) {
53+ Q_EMIT obj->pictureUriChanged(str);
54+ }
55+ }
4856 }
4957}
5058
59+QString GSettingsControllerQml::pictureUri(const QByteArray &schemaId) const
60+{
61+ return m_pictureUri.value(schemaId, "");
62+}
63+
64+void GSettingsControllerQml::setUsageMode(const QByteArray &schemaId, const QString &str)
65+{
66+ if (m_usageMode[schemaId] != str) {
67+ m_usageMode[schemaId] = str;
68+
69+ Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
70+ if (obj->schema()->id() == schemaId) {
71+ Q_EMIT obj->usageModeChanged(str);
72+ }
73+ }
74+ }
75+}
76+
77+QString GSettingsControllerQml::usageMode(const QByteArray &schemaId) const
78+{
79+ return m_usageMode.value(schemaId, "phone");
80+}
81+
5182GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
5283}
5384
@@ -56,12 +87,13 @@ QByteArray GSettingsSchemaQml::id() const {
5687}
5788
5889void GSettingsSchemaQml::setId(const QByteArray &id) {
59− if (m_id.isEmpty()) {
90+ if (!m_id.isEmpty()) {
6091 qWarning("GSettings.schema.id may only be set on construction");
6192 return;
6293 }
6394
6495 m_id = id;
96+ Q_EMIT idChanged(id);
6597}
6698
6799QByteArray GSettingsSchemaQml::path() const {
@@ -69,7 +101,7 @@ QByteArray GSettingsSchemaQml::path() const {
69101}
70102
71103void GSettingsSchemaQml::setPath(const QByteArray &path) {
72− if (m_path.isEmpty()) {
104+ if (!m_path.isEmpty()) {
73105 qWarning("GSettings.schema.path may only be set on construction");
74106 return;
75107 }
@@ -90,13 +122,20 @@ GSettingsSchemaQml * GSettingsQml::schema() const {
90122 return m_schema;
91123}
92124
125+void GSettingsQml::setPictureUri(const QString &str) {
126+ GSettingsControllerQml::instance()->setPictureUri(m_schema->id(), str);
127+}
128+
93129QString GSettingsQml::pictureUri() const {
94− return m_pictureUri;
130+ return GSettingsControllerQml::instance()->pictureUri(m_schema->id());
95131}
96132
97−void GSettingsQml::setPictureUri(const QString &str) {
98− if (str != m_pictureUri) {
99− m_pictureUri = str;
100− Q_EMIT pictureUriChanged(m_pictureUri);
101− }
133+void GSettingsQml::setUsageMode(const QString &str) {
134+ GSettingsControllerQml::instance()->setUsageMode(m_schema->id(), str);
102135}
136+
137+QString GSettingsQml::usageMode() const {
138+ return GSettingsControllerQml::instance()->usageMode(m_schema->id());
139+
140+}
141+
tests/mocks/GSettings.1.0/fake_gsettings.h+20−4
@@ -18,13 +18,14 @@
1818#define FAKE_GSETTINGS_H
1919
2020#include <QList>
21+#include <QHash>
2122#include <QObject>
2223
2324class GSettingsSchemaQml: public QObject
2425{
2526 Q_OBJECT
2627
27− Q_PROPERTY(QByteArray id READ id WRITE setId)
28+ Q_PROPERTY(QByteArray id READ id WRITE setId NOTIFY idChanged)
2829
2930public:
3031 GSettingsSchemaQml(QObject *parent = nullptr);
@@ -35,6 +36,9 @@ public:
3536 QByteArray path() const;
3637 void setPath(const QByteArray &path);
3738
39+Q_SIGNALS:
40+ void idChanged(const QByteArray &id);
41+
3842private:
3943 QByteArray m_id;
4044 QByteArray m_path;
@@ -46,23 +50,27 @@ class GSettingsQml: public QObject
4650
4751 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
4852 Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
53+ Q_PROPERTY(QString usageMode READ usageMode WRITE setUsageMode NOTIFY usageModeChanged)
4954
5055public:
5156 GSettingsQml(QObject *parent = nullptr);
5257 ~GSettingsQml();
5358
5459 GSettingsSchemaQml * schema() const;
55− QString pictureUri() const;
5660
5761 void setPictureUri(const QString &str);
62+ QString pictureUri() const;
63+
64+ void setUsageMode(const QString &str);
65+ QString usageMode() const;
5866
5967Q_SIGNALS:
6068 void schemaChanged();
6169 void pictureUriChanged(const QString&);
70+ void usageModeChanged(const QString&);
6271
6372private:
6473 GSettingsSchemaQml* m_schema;
65−
6674 QString m_pictureUri;
6775
6876 friend class GSettingsSchemaQml;
@@ -78,13 +86,21 @@ public:
7886
7987 void registerSettingsObject(GSettingsQml *obj);
8088 void unRegisterSettingsObject(GSettingsQml *obj);
81− Q_INVOKABLE void setPictureUri(const QString &str);
89+
90+ Q_INVOKABLE void setPictureUri(const QByteArray &id, const QString &str);
91+ QString pictureUri(const QByteArray &id) const;
92+
93+ Q_INVOKABLE void setUsageMode(const QByteArray &id, const QString &str);
94+ QString usageMode(const QByteArray &id) const;
8295
8396private:
8497 GSettingsControllerQml();
8598
8699 static GSettingsControllerQml* s_controllerInstance;
87100 QList<GSettingsQml *> m_registeredGSettings;
101+
102+ QHash<QString, QString> m_pictureUri;
103+ QHash<QString, QString> m_usageMode;
88104};
89105
90106#endif // FAKE_GSETTINGS_H
tests/qmltests/tst_DesktopShell.qml+1−1
@@ -41,6 +41,7 @@ Item {
4141 }
4242
4343 Component.onCompleted: {
44+ GSettingsController.setUsageMode("com.canonical.Unity8", "Windowed")
4445 // must set the mock mode before loading the Shell
4546 LightDM.Greeter.mockMode = "full";
4647 LightDM.Users.mockMode = "full";
@@ -83,7 +84,6 @@ Item {
8384 property bool itemDestroyed: false
8485 sourceComponent: Component {
8586 Shell {
86− usageMode: "Windowed"
8787 property string indicatorProfile: "desktop"
8888
8989 Component.onDestruction: {
tests/qmltests/tst_Shell.qml+1−2
@@ -867,8 +867,7 @@ Item {
867867 }
868868 function test_background(data) {
869869 AccountsService.backgroundFile = data.accounts;
870− var backgroundSettings = findInvisibleChild(shell, "backgroundSettings");
871− backgroundSettings.pictureUri = data.gsettings;
870+ GSettingsController.setPictureUri("org.gnome.desktop.background", data.gsettings);
872871 tryCompare(shell, "background", data.output);
873872 }
874873 }