on xenial help sign in
More work on the plugin
ae9aab3Andrea Cimitan
Components/CrossFadeImage.qml+1−1
@@ -85,7 +85,7 @@ Item {
85 Connections {
85 Connections {
86 target: __nextImage
86 target: __nextImage
87 onStatusChanged: {
87 onStatusChanged: {
88− if (__nextImage.status == Image.Ready) {
88+ if (__nextImage.status == Image.Ready || __nextImage.status == Image.Error) {
89 swapImages();
89 swapImages();
90 }
90 }
91 }
91 }
Greeter/GreeterContent.qml−1
@@ -38,7 +38,6 @@ MouseArea {
38
38
39 source: shell.background
39 source: shell.background
40 anchors.fill: parent
40 anchors.fill: parent
41− crossFade: false
42 fadeInFirst: false
41 fadeInFirst: false
43 }
42 }
44
43
Shell.qml+9−39
@@ -41,8 +41,8 @@ FocusScope {
41 height: tablet ? units.gu(100) : units.gu(71)
41 height: tablet ? units.gu(100) : units.gu(71)
42
42
43 property real edgeSize: units.gu(2)
43 property real edgeSize: units.gu(2)
44− property url default_background: shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg"
44+ property url defaultBackground: shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg"
45− property url background: default_background
45+ property url background: backgroundSettings.pictureUri
46 readonly property real panelHeight: panel.panelHeight
46 readonly property real panelHeight: panel.panelHeight
47
47
48 property bool dashShown: dash.shown
48 property bool dashShown: dash.shown
@@ -120,40 +120,6 @@ FocusScope {
120 schema.id: "org.gnome.desktop.background"
120 schema.id: "org.gnome.desktop.background"
121 }
121 }
122
122
123− function updateImage() {
124− if (testImage.source == "")
125− return
126−
127− if (testImage.status == Image.Ready) {
128− if (shell.width / shell.height <= testImage.sourceSize.width / testImage.sourceSize.height) {
129− backgroundImage.sourceSize.width = 0
130− backgroundImage.sourceSize.height = Qt.binding(function() { return shell.height })
131− } else {
132− backgroundImage.sourceSize.height = 0
133− backgroundImage.sourceSize.width = Qt.binding(function() { return shell.width })
134− }
135−
136− shell.background = testImage.source
137− } else if (testImage.status == Image.Error) {
138− shell.background = shell.default_background
139− }
140−
141− // unload testImage source to save memory
142− testImage.source = ""
143− }
144−
145− Image {
146− id: testImage
147−
148− property url gsettingsImage: backgroundSettings.pictureUri
149−
150− source: gsettingsImage
151− visible: false
152−
153− onGsettingsImageChanged: source = gsettingsImage
154− onStatusChanged: updateImage()
155− }
156−
157 VolumeControl {
123 VolumeControl {
158 id: volumeControl
124 id: volumeControl
159 }
125 }
@@ -184,11 +150,15 @@ FocusScope {
184 // through the translucent parts of the shell surface.
150 // through the translucent parts of the shell surface.
185 visible: !fullyCovered && !applicationSurfaceShouldBeSeen
151 visible: !fullyCovered && !applicationSurfaceShouldBeSeen
186
152
187− Image {
153+ CrossFadeImage {
188 id: backgroundImage
154 id: backgroundImage
189 source: shell.background
155 source: shell.background
190 anchors.fill: parent
156 anchors.fill: parent
191− fillMode: Image.PreserveAspectCrop
157+ onStatusChanged: {
158+ if (status == Image.Error) {
159+ backgroundSettings.pictureUri = shell.defaultBackground
160+ }
161+ }
192 }
162 }
193
163
194 Rectangle {
164 Rectangle {
@@ -492,7 +462,7 @@ FocusScope {
492 onUnlocked: greeter.hide()
462 onUnlocked: greeter.hide()
493 onSelected: {
463 onSelected: {
494 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
464 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
495− shell.background = bgPath ? bgPath : default_background
465+ shell.background = bgPath ? bgPath : defaultBackground
496 }
466 }
497
467
498 onLeftTeaserPressedChanged: {
468 onLeftTeaserPressedChanged: {
tests/mocks/GSettings/CMakeLists.txt−1
@@ -14,7 +14,6 @@ add_definitions(-DQT_NO_KEYWORDS)
14
14
15set(GSettingsQML_SOURCES
15set(GSettingsQML_SOURCES
16 fake_gsettings.cpp
16 fake_gsettings.cpp
17− fake_schema.cpp
18 plugin.cpp
17 plugin.cpp
19)
18)
20
19
tests/mocks/GSettings/fake_gsettings.cpp+88−11
@@ -1,28 +1,105 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright 2013 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5+ * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
6 * the Free Software Foundation; version 3.
7 *
7 *
8 * This program is distributed in the hope that it will be useful,
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
11+ * GNU Lesser General Public License for more details.
12 *
12 *
13− * You should have received a copy of the GNU General Public License
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/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17#include "fake_gsettings.h"
17#include "fake_gsettings.h"
18−#include "fake_schema.h"
19
18
20−GSettings::GSettings(QObject *parent) :
19+struct GSettingsSchemaQmlPrivate {
20+ QByteArray id;
21+ QByteArray path;
22+};
23+
24+struct GSettingsQmlPrivate {
25+ GSettingsSchemaQml *schema;
26+};
27+
28+bool GSettingsControllerQml::instance_exists;
29+GSettingsControllerQml* GSettingsControllerQml::_controllerInstance;
30+
31+GSettingsControllerQml::GSettingsControllerQml() {
32+}
33+
34+GSettingsControllerQml::~GSettingsControllerQml() {
35+ instance_exists = false;
36+}
37+
38+GSettingsControllerQml* GSettingsControllerQml::getInstance() {
39+ if(!instance_exists) {
40+ _controllerInstance = new GSettingsControllerQml();
41+ instance_exists = true;
42+ return _controllerInstance;
43+ } else {
44+ return _controllerInstance;
45+ }
46+}
47+
48+GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
49+ priv = new GSettingsSchemaQmlPrivate;
50+}
51+
52+GSettingsSchemaQml::~GSettingsSchemaQml() {
53+ delete priv;
54+}
55+
56+QByteArray GSettingsSchemaQml::id() const {
57+ return priv->id;
58+}
59+
60+void GSettingsSchemaQml::setId(const QByteArray &id) {
61+ if (!priv->id.isEmpty()) {
62+ qWarning("GSettings.schema.id may only be set on construction");
63+ return;
64+ }
65+
66+ priv->id = id;
67+}
68+
69+QByteArray GSettingsSchemaQml::path() const {
70+ return priv->path;
71+}
72+
73+void GSettingsSchemaQml::setPath(const QByteArray &path) {
74+ if (!priv->path.isEmpty()) {
75+ qWarning("GSettings.schema.path may only be set on construction");
76+ return;
77+ }
78+
79+ priv->path = path;
80+}
81+
21− QObject(parent)
82+GSettingsQml::GSettingsQml(QObject *parent): QObject(parent) {
22−{
83+ GSettingsControllerQml::getInstance();
23− m_schema = new Schema();
84+ priv = new GSettingsQmlPrivate;
85+ priv->schema = new GSettingsSchemaQml(this);
86+}
87+
88+GSettingsQml::~GSettingsQml() {
89+ delete priv;
90+}
91+
92+GSettingsSchemaQml * GSettingsQml::schema() const {
93+ return priv->schema;
94+}
95+
96+QString GSettingsQml::pictureUri() const {
97+ return m_pictureUri;
24}
98}
25
99
26−QObject GSettings::schema() const {
100+void GSettingsQml::setPictureUri(const QString &str) {
27− return m_schema;
101+ if (str != m_pictureUri) {
102+ m_pictureUri = str;
103+ Q_EMIT pictureUriChanged(m_pictureUri);
104+ }
28}
105}
tests/mocks/GSettings/fake_gsettings.h+60−11
@@ -1,40 +1,89 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright 2013 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5+ * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
6 * the Free Software Foundation; version 3.
7 *
7 *
8 * This program is distributed in the hope that it will be useful,
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
11+ * GNU Lesser General Public License for more details.
12 *
12 *
13− * You should have received a copy of the GNU General Public License
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/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17#ifndef FAKE_GSETTINGS_H
17#ifndef FAKE_GSETTINGS_H
18#define FAKE_GSETTINGS_H
18#define FAKE_GSETTINGS_H
19
19
20−#include <QObject>
20+#include <QtQml>
21+#include <QQmlParserStatus>
21
22
22−class GSettings : public QObject
23+class GSettingsControllerQml: public QObject
23{
24{
24 Q_OBJECT
25 Q_OBJECT
25
26
27+public:
28+ static GSettingsControllerQml* getInstance();
29+ ~GSettingsControllerQml();
30+
31+private:
32+ GSettingsControllerQml();
33+ GSettingsControllerQml(const GSettingsControllerQml&);
34+ GSettingsControllerQml& operator=(const GSettingsControllerQml&);
35+
36+ static bool instance_exists;
37+
38+ static GSettingsControllerQml* _controllerInstance;
39+};
40+
41+class GSettingsSchemaQml: public QObject
42+{
43+ Q_OBJECT
44+
45+ Q_PROPERTY(QByteArray id READ id WRITE setId)
46+
47+public:
48+ GSettingsSchemaQml(QObject *parent = NULL);
49+ ~GSettingsSchemaQml();
50+
51+ QByteArray id() const;
52+ void setId(const QByteArray &id);
53+
54+ QByteArray path() const;
55+ void setPath(const QByteArray &path);
56+
57+private:
58+ struct GSettingsSchemaQmlPrivate *priv;
59+};
60+
61+class GSettingsQml: public QObject
62+{
63+ Q_OBJECT
64+
26− Q_PROPERTY(QObject schema READ schema NOTIFY schemaChanged)
65+ Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
66+ Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
27
67
28public:
68public:
29− explicit GSettings(QObject *parent = 0);
69+ GSettingsQml(QObject *parent = NULL);
70+ ~GSettingsQml();
30
71
31− QObject schema() const;
72+ GSettingsSchemaQml * schema() const;
73+ QString pictureUri() const;
74+
75+ void setPictureUri(const QString &str);
32
76
33Q_SIGNALS:
77Q_SIGNALS:
34− void schemaChanged(const QObject&);
78+ void schemaChanged();
79+ void pictureUriChanged(const QString&);
35
80
36private:
81private:
37− QObject m_schema;
82+ struct GSettingsQmlPrivate *priv;
83+
84+ QString m_pictureUri;
85+
86+ friend class GSettingsSchemaQml;
38};
87};
39
88
40#endif // FAKE_GSETTINGS_H
89#endif // FAKE_GSETTINGS_H
tests/mocks/GSettings/fake_schema.h → tests/mocks/GSettings/plugin.cpprenamed+9−23
@@ -14,29 +14,15 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#ifndef FAKE_SCHEMA_H
17+#include "plugin.h"
18−#define FAKE_SCHEMA_H
18+#include "fake_gsettings.h"
19
19
20−#include <QObject>
20+#include <QtQml>
21
21
22−class Schema : public QObject
22+void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
23{
23{
24− Q_OBJECT
24+ qmlRegisterType<GSettingsControllerQml>(uri, 1, 0, "GSettingsController");
25−
25+ qmlRegisterType<GSettingsQml>(uri, 1, 0, "GSettings");
26− Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged)
26+ qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
27−
27+ "GSettingsSchema can only be used inside of a GSettings component");
28−public:
29− explicit Schema(QObject *parent = 0);
30−
31− QString id() const;
32−
33− void setId(const QString& str);
34−
35−Q_SIGNALS:
36− void idChanged(const QString&);
37−
38−private:
39− QString m_id;
40−};
28+}
41−
42−#endif // FAKE_SCHEMA_H
tests/mocks/GSettings/fake_schema.cpp → tests/mocks/GSettings/plugin.hrenamed+11−13
@@ -14,20 +14,18 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#include "fake_schema.h"
17+#ifndef PLUGIN_H
18+#define PLUGIN_H
18
19
19−Schema::Schema(QObject *parent) :
20+#include <QtQml/QQmlExtensionPlugin>
20− QObject(parent)
21+
22+class FakeGSettingsQmlPlugin : public QQmlExtensionPlugin
21{
23{
22−}
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
23
26
24−QString Schema::id() const {
27+public:
25− return m_id;
28+ void registerTypes(const char *uri);
26−}
29+};
27
30
28−void Schema::setId(const QString &str) {
31+#endif // PLUGIN_H
29− if (str != m_id) {
30− m_id = str;
31− Q_EMIT idChanged(m_id);
32− }
33−}