on xenial help sign in
More work on the plugin
commitae9aab3686c8bcffcc4e80152969992ab9da651a authorAndrea Cimitan <andrea.cimitan@canonical.com> dateThu 25 Jul 2013, 17:41 (13 years ago) parent5900ed6f6ecb84
8 files changed+178−100
Components/CrossFadeImage.qml+1−1 Greeter/GreeterContent.qml−1 Shell.qml+9−39 tests/mocks/GSettings/CMakeLists.txt−1 tests/mocks/GSettings/fake_gsettings.cpp+88−11 tests/mocks/GSettings/fake_gsettings.h+60−11 tests/mocks/GSettings/fake_schema.h → tests/mocks/GSettings/plugin.cpp+9−23 tests/mocks/GSettings/fake_schema.cpp → tests/mocks/GSettings/plugin.h+11−13
Components/CrossFadeImage.qml+1−1
@@ -85,7 +85,7 @@ Item {
8585 Connections {
8686 target: __nextImage
8787 onStatusChanged: {
88− if (__nextImage.status == Image.Ready) {
88+ if (__nextImage.status == Image.Ready || __nextImage.status == Image.Error) {
8989 swapImages();
9090 }
9191 }
Greeter/GreeterContent.qml−1
@@ -38,7 +38,6 @@ MouseArea {
3838
3939 source: shell.background
4040 anchors.fill: parent
41− crossFade: false
4241 fadeInFirst: false
4342 }
4443
Shell.qml+9−39
@@ -41,8 +41,8 @@ FocusScope {
4141 height: tablet ? units.gu(100) : units.gu(71)
4242
4343 property real edgeSize: units.gu(2)
44− property url default_background: shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg"
45− property url background: default_background
44+ property url defaultBackground: shell.width >= units.gu(60) ? "graphics/tablet_background.jpg" : "graphics/phone_background.jpg"
45+ property url background: backgroundSettings.pictureUri
4646 readonly property real panelHeight: panel.panelHeight
4747
4848 property bool dashShown: dash.shown
@@ -120,40 +120,6 @@ FocusScope {
120120 schema.id: "org.gnome.desktop.background"
121121 }
122122
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−
157123 VolumeControl {
158124 id: volumeControl
159125 }
@@ -184,11 +150,15 @@ FocusScope {
184150 // through the translucent parts of the shell surface.
185151 visible: !fullyCovered && !applicationSurfaceShouldBeSeen
186152
187− Image {
153+ CrossFadeImage {
188154 id: backgroundImage
189155 source: shell.background
190156 anchors.fill: parent
191− fillMode: Image.PreserveAspectCrop
157+ onStatusChanged: {
158+ if (status == Image.Error) {
159+ backgroundSettings.pictureUri = shell.defaultBackground
160+ }
161+ }
192162 }
193163
194164 Rectangle {
@@ -492,7 +462,7 @@ FocusScope {
492462 onUnlocked: greeter.hide()
493463 onSelected: {
494464 var bgPath = greeter.model.data(uid, LightDM.UserRoles.BackgroundPathRole)
495− shell.background = bgPath ? bgPath : default_background
465+ shell.background = bgPath ? bgPath : defaultBackground
496466 }
497467
498468 onLeftTeaserPressedChanged: {
tests/mocks/GSettings/CMakeLists.txt−1
@@ -14,7 +14,6 @@ add_definitions(-DQT_NO_KEYWORDS)
1414
1515set(GSettingsQML_SOURCES
1616 fake_gsettings.cpp
17− fake_schema.cpp
1817 plugin.cpp
1918)
2019
tests/mocks/GSettings/fake_gsettings.cpp+88−11
@@ -1,28 +1,105 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright 2013 Canonical Ltd.
33 *
44 * 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
66 * the Free Software Foundation; version 3.
77 *
88 * This program is distributed in the hope that it will be useful,
99 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1010 * 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.
1212 *
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
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
1717#include "fake_gsettings.h"
18−#include "fake_schema.h"
1918
20−GSettings::GSettings(QObject *parent) :
21− QObject(parent)
22−{
23− m_schema = new Schema();
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+
82+GSettingsQml::GSettingsQml(QObject *parent): QObject(parent) {
83+ GSettingsControllerQml::getInstance();
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;
2498}
2599
26−QObject GSettings::schema() const {
27− return m_schema;
100+void GSettingsQml::setPictureUri(const QString &str) {
101+ if (str != m_pictureUri) {
102+ m_pictureUri = str;
103+ Q_EMIT pictureUriChanged(m_pictureUri);
104+ }
28105}
tests/mocks/GSettings/fake_gsettings.h+60−11
@@ -1,40 +1,89 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright 2013 Canonical Ltd.
33 *
44 * 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
66 * the Free Software Foundation; version 3.
77 *
88 * This program is distributed in the hope that it will be useful,
99 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1010 * 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.
1212 *
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
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
1717#ifndef FAKE_GSETTINGS_H
1818#define FAKE_GSETTINGS_H
1919
20−#include <QObject>
20+#include <QtQml>
21+#include <QQmlParserStatus>
2122
22−class GSettings : public QObject
23+class GSettingsControllerQml: public QObject
2324{
2425 Q_OBJECT
2526
26− Q_PROPERTY(QObject schema READ schema NOTIFY schemaChanged)
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+
65+ Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
66+ Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
2767
2868public:
29− explicit GSettings(QObject *parent = 0);
69+ GSettingsQml(QObject *parent = NULL);
70+ ~GSettingsQml();
3071
31− QObject schema() const;
72+ GSettingsSchemaQml * schema() const;
73+ QString pictureUri() const;
74+
75+ void setPictureUri(const QString &str);
3276
3377Q_SIGNALS:
34− void schemaChanged(const QObject&);
78+ void schemaChanged();
79+ void pictureUriChanged(const QString&);
3580
3681private:
37− QObject m_schema;
82+ struct GSettingsQmlPrivate *priv;
83+
84+ QString m_pictureUri;
85+
86+ friend class GSettingsSchemaQml;
3887};
3988
4089#endif // FAKE_GSETTINGS_H
tests/mocks/GSettings/fake_schema.h → tests/mocks/GSettings/plugin.cpprenamed+9−23
@@ -14,29 +14,15 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef FAKE_SCHEMA_H
18−#define FAKE_SCHEMA_H
17+#include "plugin.h"
18+#include "fake_gsettings.h"
1919
20−#include <QObject>
20+#include <QtQml>
2121
22−class Schema : public QObject
22+void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
2323{
24− Q_OBJECT
25−
26− Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged)
27−
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−};
41−
42−#endif // FAKE_SCHEMA_H
24+ qmlRegisterType<GSettingsControllerQml>(uri, 1, 0, "GSettingsController");
25+ qmlRegisterType<GSettingsQml>(uri, 1, 0, "GSettings");
26+ qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
27+ "GSettingsSchema can only be used inside of a GSettings component");
28+}
tests/mocks/GSettings/fake_schema.cpp → tests/mocks/GSettings/plugin.hrenamed+11−13
@@ -14,20 +14,18 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#include "fake_schema.h"
17+#ifndef PLUGIN_H
18+#define PLUGIN_H
1819
19−Schema::Schema(QObject *parent) :
20− QObject(parent)
20+#include <QtQml/QQmlExtensionPlugin>
21+
22+class FakeGSettingsQmlPlugin : public QQmlExtensionPlugin
2123{
22−}
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
2326
24−QString Schema::id() const {
25− return m_id;
26−}
27+public:
28+ void registerTypes(const char *uri);
29+};
2730
28−void Schema::setId(const QString &str) {
29− if (str != m_id) {
30− m_id = str;
31− Q_EMIT idChanged(m_id);
32− }
33−}
31+#endif // PLUGIN_H