on xenial help sign in
fixed gsettings mock
a2f95beNick Dedekind
qml/Shell.qml+2−5
@@ -78,8 +78,6 @@ Item {
78 }
78 }
79 }
79 }
80
80
81− property string usageMode: usageModeSettings.usageMode
82−
83 function activateApplication(appId) {
81 function activateApplication(appId) {
84 if (ApplicationManager.findApplication(appId)) {
82 if (ApplicationManager.findApplication(appId)) {
85 ApplicationManager.requestFocusApplication(appId);
83 ApplicationManager.requestFocusApplication(appId);
@@ -108,7 +106,6 @@ Item {
108
106
109 GSettings {
107 GSettings {
110 id: backgroundSettings
108 id: backgroundSettings
111− objectName: "backgroundSettings"
112 schema.id: "org.gnome.desktop.background"
109 schema.id: "org.gnome.desktop.background"
113 }
110 }
114
111
@@ -231,7 +228,7 @@ Item {
231 // the screen larger (maybe connects to monitor) and tries to enter
228 // the screen larger (maybe connects to monitor) and tries to enter
232 // tablet mode.
229 // tablet mode.
233 property bool tabletMode: shell.sideStageEnabled && !greeter.hasLockedApp
230 property bool tabletMode: shell.sideStageEnabled && !greeter.hasLockedApp
234− source: shell.usageMode === "Windowed" ? "Stages/DesktopStage.qml"
231+ source: usageModeSettings.usageMode === "Windowed" ? "Stages/DesktopStage.qml"
235 : tabletMode ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
232 : tabletMode ? "Stages/TabletStage.qml" : "Stages/PhoneStage.qml"
236
233
237 property bool interactive: tutorial.spreadEnabled
234 property bool interactive: tutorial.spreadEnabled
@@ -485,7 +482,7 @@ Item {
485 available: tutorial.launcherEnabled
482 available: tutorial.launcherEnabled
486 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
483 && (!greeter.locked || AccountsService.enableLauncherWhileLocked)
487 && !greeter.hasLockedApp
484 && !greeter.hasLockedApp
488− inverted: shell.usageMode === "Staged"
485+ inverted: usageModeSettings.usageMode === "Staged"
489 shadeBackground: !tutorial.running
486 shadeBackground: !tutorial.running
490
487
491 onShowDashHome: showHome()
488 onShowDashHome: showHome()
tests/mocks/GSettings.1.0/fake_gsettings.cpp+50−11
@@ -17,6 +17,7 @@
17#include "fake_gsettings.h"
17#include "fake_gsettings.h"
18
18
19#include <QList>
19#include <QList>
20+#include <QDebug>
20
21
21GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
22GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
22
23
@@ -42,12 +43,42 @@ void GSettingsControllerQml::unRegisterSettingsObject(GSettingsQml *obj) {
42 m_registeredGSettings.removeOne(obj);
43 m_registeredGSettings.removeOne(obj);
43}
44}
44
45
45−void GSettingsControllerQml::setPictureUri(const QString &str) {
46+void GSettingsControllerQml::setPictureUri(const QByteArray &schemaId, const QString &str)
47+{
48+ if (m_pictureUri[schemaId] != str) {
49+ m_pictureUri[schemaId] = str;
50+
46− Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
51+ Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
47− obj->setPictureUri(str);
52+ if (obj->schema()->id() == schemaId) {
53+ Q_EMIT obj->pictureUriChanged(str);
54+ }
55+ }
48 }
56 }
49}
57}
50
58
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+
51GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
82GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
52}
83}
53
84
@@ -56,12 +87,13 @@ QByteArray GSettingsSchemaQml::id() const {
56}
87}
57
88
58void GSettingsSchemaQml::setId(const QByteArray &id) {
89void GSettingsSchemaQml::setId(const QByteArray &id) {
59− if (m_id.isEmpty()) {
90+ if (!m_id.isEmpty()) {
60 qWarning("GSettings.schema.id may only be set on construction");
91 qWarning("GSettings.schema.id may only be set on construction");
61 return;
92 return;
62 }
93 }
63
94
64 m_id = id;
95 m_id = id;
96+ Q_EMIT idChanged(id);
65}
97}
66
98
67QByteArray GSettingsSchemaQml::path() const {
99QByteArray GSettingsSchemaQml::path() const {
@@ -69,7 +101,7 @@ QByteArray GSettingsSchemaQml::path() const {
69}
101}
70
102
71void GSettingsSchemaQml::setPath(const QByteArray &path) {
103void GSettingsSchemaQml::setPath(const QByteArray &path) {
72− if (m_path.isEmpty()) {
104+ if (!m_path.isEmpty()) {
73 qWarning("GSettings.schema.path may only be set on construction");
105 qWarning("GSettings.schema.path may only be set on construction");
74 return;
106 return;
75 }
107 }
@@ -90,13 +122,20 @@ GSettingsSchemaQml * GSettingsQml::schema() const {
90 return m_schema;
122 return m_schema;
91}
123}
92
124
125+void GSettingsQml::setPictureUri(const QString &str) {
126+ GSettingsControllerQml::instance()->setPictureUri(m_schema->id(), str);
127+}
128+
93QString GSettingsQml::pictureUri() const {
129QString GSettingsQml::pictureUri() const {
94− return m_pictureUri;
130+ return GSettingsControllerQml::instance()->pictureUri(m_schema->id());
95}
131}
96
132
97−void GSettingsQml::setPictureUri(const QString &str) {
133+void GSettingsQml::setUsageMode(const QString &str) {
98− if (str != m_pictureUri) {
134+ GSettingsControllerQml::instance()->setUsageMode(m_schema->id(), str);
99− m_pictureUri = str;
100− Q_EMIT pictureUriChanged(m_pictureUri);
101− }
102}
135}
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 @@
18#define FAKE_GSETTINGS_H
18#define FAKE_GSETTINGS_H
19
19
20#include <QList>
20#include <QList>
21+#include <QHash>
21#include <QObject>
22#include <QObject>
22
23
23class GSettingsSchemaQml: public QObject
24class GSettingsSchemaQml: public QObject
24{
25{
25 Q_OBJECT
26 Q_OBJECT
26
27
27− Q_PROPERTY(QByteArray id READ id WRITE setId)
28+ Q_PROPERTY(QByteArray id READ id WRITE setId NOTIFY idChanged)
28
29
29public:
30public:
30 GSettingsSchemaQml(QObject *parent = nullptr);
31 GSettingsSchemaQml(QObject *parent = nullptr);
@@ -35,6 +36,9 @@ public:
35 QByteArray path() const;
36 QByteArray path() const;
36 void setPath(const QByteArray &path);
37 void setPath(const QByteArray &path);
37
38
39+Q_SIGNALS:
40+ void idChanged(const QByteArray &id);
41+
38private:
42private:
39 QByteArray m_id;
43 QByteArray m_id;
40 QByteArray m_path;
44 QByteArray m_path;
@@ -46,23 +50,27 @@ class GSettingsQml: public QObject
46
50
47 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
51 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
48 Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
52 Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
53+ Q_PROPERTY(QString usageMode READ usageMode WRITE setUsageMode NOTIFY usageModeChanged)
49
54
50public:
55public:
51 GSettingsQml(QObject *parent = nullptr);
56 GSettingsQml(QObject *parent = nullptr);
52 ~GSettingsQml();
57 ~GSettingsQml();
53
58
54 GSettingsSchemaQml * schema() const;
59 GSettingsSchemaQml * schema() const;
55− QString pictureUri() const;
56
60
57 void setPictureUri(const QString &str);
61 void setPictureUri(const QString &str);
62+ QString pictureUri() const;
63+
64+ void setUsageMode(const QString &str);
65+ QString usageMode() const;
58
66
59Q_SIGNALS:
67Q_SIGNALS:
60 void schemaChanged();
68 void schemaChanged();
61 void pictureUriChanged(const QString&);
69 void pictureUriChanged(const QString&);
70+ void usageModeChanged(const QString&);
62
71
63private:
72private:
64 GSettingsSchemaQml* m_schema;
73 GSettingsSchemaQml* m_schema;
65−
66 QString m_pictureUri;
74 QString m_pictureUri;
67
75
68 friend class GSettingsSchemaQml;
76 friend class GSettingsSchemaQml;
@@ -78,13 +86,21 @@ public:
78
86
79 void registerSettingsObject(GSettingsQml *obj);
87 void registerSettingsObject(GSettingsQml *obj);
80 void unRegisterSettingsObject(GSettingsQml *obj);
88 void unRegisterSettingsObject(GSettingsQml *obj);
89+
81− Q_INVOKABLE void setPictureUri(const QString &str);
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;
82
95
83private:
96private:
84 GSettingsControllerQml();
97 GSettingsControllerQml();
85
98
86 static GSettingsControllerQml* s_controllerInstance;
99 static GSettingsControllerQml* s_controllerInstance;
87 QList<GSettingsQml *> m_registeredGSettings;
100 QList<GSettingsQml *> m_registeredGSettings;
101+
102+ QHash<QString, QString> m_pictureUri;
103+ QHash<QString, QString> m_usageMode;
88};
104};
89
105
90#endif // FAKE_GSETTINGS_H
106#endif // FAKE_GSETTINGS_H
tests/qmltests/tst_DesktopShell.qml+1−1
@@ -41,6 +41,7 @@ Item {
41 }
41 }
42
42
43 Component.onCompleted: {
43 Component.onCompleted: {
44+ GSettingsController.setUsageMode("com.canonical.Unity8", "Windowed")
44 // must set the mock mode before loading the Shell
45 // must set the mock mode before loading the Shell
45 LightDM.Greeter.mockMode = "full";
46 LightDM.Greeter.mockMode = "full";
46 LightDM.Users.mockMode = "full";
47 LightDM.Users.mockMode = "full";
@@ -83,7 +84,6 @@ Item {
83 property bool itemDestroyed: false
84 property bool itemDestroyed: false
84 sourceComponent: Component {
85 sourceComponent: Component {
85 Shell {
86 Shell {
86− usageMode: "Windowed"
87 property string indicatorProfile: "desktop"
87 property string indicatorProfile: "desktop"
88
88
89 Component.onDestruction: {
89 Component.onDestruction: {
tests/qmltests/tst_Shell.qml+1−2
@@ -867,8 +867,7 @@ Item {
867 }
867 }
868 function test_background(data) {
868 function test_background(data) {
869 AccountsService.backgroundFile = data.accounts;
869 AccountsService.backgroundFile = data.accounts;
870− var backgroundSettings = findInvisibleChild(shell, "backgroundSettings");
870+ GSettingsController.setPictureUri("org.gnome.desktop.background", data.gsettings);
871− backgroundSettings.pictureUri = data.gsettings;
872 tryCompare(shell, "background", data.output);
871 tryCompare(shell, "background", data.output);
873 }
872 }
874 }
873 }