Merge lp:~mhr3/gsettings-qt/fix-1209235 into lp:gsettings-qt

Proposed by Michal Hruby
Status: Merged
Approved by: Lars Karlitski
Approved revision: 47
Merged at revision: 46
Proposed branch: lp:~mhr3/gsettings-qt/fix-1209235
Merge into: lp:gsettings-qt
Diff against target: 175 lines (+73/-10)
6 files modified
GSettings/gsettings-qml.cpp (+29/-8)
GSettings/gsettings-qml.h (+9/-2)
debian/changelog (+6/-0)
src/qgsettings.cpp (+12/-0)
src/qgsettings.h (+5/-0)
tests/tst_GSettings.qml (+12/-0)
To merge this branch: bzr merge lp:~mhr3/gsettings-qt/fix-1209235
Reviewer Review Type Date Requested Status
Lars Karlitski (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+214703@code.launchpad.net

Commit message

Added API to check if a schema is installed.

Description of the change

Added API to check if a schema is installed.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Nice work, thanks!

I'm a bit worried that we're not even printing a warning anymore when an uninstalled schema is requested. I guess this is more consistent with how the rest of qml (and javascript) works though.

review: Approve
Revision history for this message
Alberto Mardegan (mardy) wrote :

A better name for the property would be "valid". Compare with QML Item's "enabled", "visible", etc.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'GSettings/gsettings-qml.cpp'
2--- GSettings/gsettings-qml.cpp 2013-08-30 14:24:40 +0000
3+++ GSettings/gsettings-qml.cpp 2014-04-08 09:43:29 +0000
4@@ -23,6 +23,9 @@
5 {
6 QByteArray id;
7 QByteArray path;
8+ bool isValid;
9+
10+ GSettingsSchemaQmlPrivate() : isValid(false) {}
11 };
12
13 struct GSettingsQmlPrivate
14@@ -71,6 +74,19 @@
15 priv->path = path;
16 }
17
18+bool GSettingsSchemaQml::isValid() const
19+{
20+ return priv->isValid;
21+}
22+
23+void GSettingsSchemaQml::setIsValid(bool valid)
24+{
25+ if (valid != priv->isValid) {
26+ priv->isValid = valid;
27+ Q_EMIT isValidChanged();
28+ }
29+}
30+
31 QVariantList GSettingsSchemaQml::choices(const QByteArray &key) const
32 {
33 GSettingsQml *parent = (GSettingsQml *) this->parent();
34@@ -115,14 +131,19 @@
35
36 void GSettingsQml::componentComplete()
37 {
38- priv->settings = new QGSettings(priv->schema->id(), priv->schema->path(), this);
39-
40- connect(priv->settings, SIGNAL(changed(const QString &)), this, SLOT(settingChanged(const QString &)));
41-
42- Q_FOREACH(QString key, priv->settings->keys())
43- this->insert(key, priv->settings->get(key));
44-
45- Q_EMIT(schemaChanged());
46+ bool schemaValid = QGSettings::isSchemaInstalled(priv->schema->id());
47+ if (schemaValid) {
48+ priv->settings = new QGSettings(priv->schema->id(), priv->schema->path(), this);
49+
50+ connect(priv->settings, SIGNAL(changed(const QString &)), this, SLOT(settingChanged(const QString &)));
51+
52+ Q_FOREACH(QString key, priv->settings->keys())
53+ this->insert(key, priv->settings->get(key));
54+
55+ Q_EMIT(schemaChanged());
56+ }
57+ // emit isValid notification only once everything is setup
58+ priv->schema->setIsValid(schemaValid);
59 }
60
61 void GSettingsQml::settingChanged(const QString &key)
62
63=== modified file 'GSettings/gsettings-qml.h'
64--- GSettings/gsettings-qml.h 2013-08-28 17:29:34 +0000
65+++ GSettings/gsettings-qml.h 2014-04-08 09:43:29 +0000
66@@ -22,8 +22,9 @@
67 class GSettingsSchemaQml: public QObject
68 {
69 Q_OBJECT
70- Q_PROPERTY(QByteArray id READ id WRITE setId)
71- Q_PROPERTY(QByteArray path READ path WRITE setPath)
72+ Q_PROPERTY(QByteArray id READ id WRITE setId)
73+ Q_PROPERTY(QByteArray path READ path WRITE setPath)
74+ Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged)
75
76 public:
77 GSettingsSchemaQml(QObject *parent = NULL);
78@@ -35,9 +36,15 @@
79 QByteArray path() const;
80 void setPath(const QByteArray &path);
81
82+ bool isValid() const;
83+ void setIsValid(bool valid);
84+
85 Q_INVOKABLE QVariantList choices(const QByteArray &key) const;
86 Q_INVOKABLE void reset(const QByteArray &key);
87
88+Q_SIGNALS:
89+ void isValidChanged();
90+
91 private:
92 struct GSettingsSchemaQmlPrivate *priv;
93 };
94
95=== modified file 'debian/changelog'
96--- debian/changelog 2014-03-17 08:26:08 +0000
97+++ debian/changelog 2014-04-08 09:43:29 +0000
98@@ -1,3 +1,9 @@
99+gsettings-qt (0.1-0ubuntu1) UNRELEASED; urgency=medium
100+
101+ * Added API to check if a schema is installed
102+
103+ -- Michal Hruby <michal.hruby@canonical.com> Tue, 08 Apr 2014 10:30:43 +0100
104+
105 gsettings-qt (0.0+13.10.20130902.1-0ubuntu2) trusty; urgency=medium
106
107 * Rebuild against Qt 5.2.1
108
109=== modified file 'src/qgsettings.cpp'
110--- src/qgsettings.cpp 2013-08-30 14:24:40 +0000
111+++ src/qgsettings.cpp 2014-04-08 09:43:29 +0000
112@@ -141,3 +141,15 @@
113 g_settings_reset(priv->settings, key);
114 g_free(key);
115 }
116+
117+bool QGSettings::isSchemaInstalled(const QByteArray &schema_id)
118+{
119+ GSettingsSchemaSource *source = g_settings_schema_source_get_default ();
120+ GSettingsSchema *schema = g_settings_schema_source_lookup (source, schema_id.constData(), TRUE);
121+ if (schema) {
122+ g_object_unref (schema);
123+ return true;
124+ } else {
125+ return false;
126+ }
127+}
128
129=== modified file 'src/qgsettings.h'
130--- src/qgsettings.h 2013-08-30 14:24:40 +0000
131+++ src/qgsettings.h 2014-04-08 09:43:29 +0000
132@@ -96,6 +96,11 @@
133 */
134 void reset(const QString &key);
135
136+ /**
137+ * @brief Checks if a schema with the given id is installed.
138+ */
139+ static bool isSchemaInstalled(const QByteArray &schema_id);
140+
141 Q_SIGNALS:
142 /**
143 * \brief Emitted when the value associated with key has changed
144
145=== modified file 'tests/tst_GSettings.qml'
146--- tests/tst_GSettings.qml 2013-08-30 14:24:40 +0000
147+++ tests/tst_GSettings.qml 2014-04-08 09:43:29 +0000
148@@ -15,10 +15,17 @@
149 onChanged: changes.push([key, value]);
150 }
151
152+ GSettings {
153+ id: invalid_settings
154+
155+ schema.id: "com.canonical.gsettings.NonExisting"
156+ }
157+
158 property string bindingTest: settings.testString
159
160 // this test must run first (others overwrite keys), hence the 'aaa'
161 function test_aaa_read_defaults() {
162+ compare(settings.schema.isValid, true);
163 compare(settings.testInteger, 42);
164 compare(settings.testDouble, 1.5);
165 compare(settings.testBoolean, false);
166@@ -79,4 +86,9 @@
167 settings.schema.reset('testInteger');
168 compare(settings.testInteger, 42);
169 }
170+
171+ function test_invalid_schema() {
172+ compare(invalid_settings.schema.isValid, false);
173+ compare(invalid_settings.schema.testInteger, undefined);
174+ }
175 }

Subscribers

People subscribed via source and target branches

to all changes: