Merge lp:~larsu/gsettings-qt/keep-propertymap-synced into lp:gsettings-qt

Proposed by Lars Karlitski
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 41
Merged at revision: 41
Proposed branch: lp:~larsu/gsettings-qt/keep-propertymap-synced
Merge into: lp:gsettings-qt
Diff against target: 94 lines (+38/-4)
4 files modified
GSettings/gsettings-qml.cpp (+9/-3)
src/qgsettings.cpp (+10/-1)
src/qgsettings.h (+12/-0)
tests/tst_GSettings.qml (+7/-0)
To merge this branch: bzr merge lp:~larsu/gsettings-qt/keep-propertymap-synced
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu Touch System Settings Pending
Review via email: mp+183191@code.launchpad.net

Commit message

Don't write values into the QQmlPropertyMap when the write failed

This makes sure that the property map doesn't get out of sync with the gsettings database.

Description of the change

Don't write values into the QQmlPropertyMap when the write failed

This makes sure that the property map doesn't get out of sync with the gsettings database.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:41
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~larsu/gsettings-qt/keep-propertymap-synced/+merge/183191/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/gsettings-qt-ci/16/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/gsettings-qt-saucy-amd64-ci/16

Click here to trigger a rebuild:
http://s-jenkins:8080/job/gsettings-qt-ci/16/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

looks fine to me, I'm not 100% sure it makes sense to have 2 different apis for a such small difference, but at the same time I don't like changing an api already in use so I guess that makes sense...

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

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-28 17:29:34 +0000
3+++ GSettings/gsettings-qml.cpp 2013-08-30 14:26:58 +0000
4@@ -134,8 +134,14 @@
5
6 QVariant GSettingsQml::updateValue(const QString& key, const QVariant &value)
7 {
8- if (priv->settings)
9- priv->settings->set(key, value);
10+ if (priv->settings == NULL)
11+ return QVariant();
12
13- return value;
14+ if (priv->settings->trySet(key, value)) {
15+ return value;
16+ }
17+ else {
18+ qWarning("unable to set key '%s' to value '%s'", key.toUtf8().constData(), value.toString().toUtf8().constData());
19+ return priv->settings->get(key);
20+ }
21 }
22
23=== modified file 'src/qgsettings.cpp'
24--- src/qgsettings.cpp 2013-08-28 17:29:34 +0000
25+++ src/qgsettings.cpp 2013-08-30 14:26:58 +0000
26@@ -71,17 +71,26 @@
27
28 void QGSettings::set(const QString &key, const QVariant &value)
29 {
30+ if (!this->trySet(key, value))
31+ qWarning("unable to set key '%s' to value '%s'", key.toUtf8().constData(), value.toString().toUtf8().constData());
32+}
33+
34+bool QGSettings::trySet(const QString &key, const QVariant &value)
35+{
36 gchar *gkey = unqtify_name(key);
37+ bool success = false;
38
39 /* fetch current value to find out the exact type */
40 GVariant *cur = g_settings_get_value(priv->settings, gkey);
41
42 GVariant *new_value = qconf_types_collect_from_variant(g_variant_get_type (cur), value);
43 if (new_value)
44- g_settings_set_value(priv->settings, gkey, new_value);
45+ success = g_settings_set_value(priv->settings, gkey, new_value);
46
47 g_free(gkey);
48 g_variant_unref (cur);
49+
50+ return success;
51 }
52
53 QStringList QGSettings::keys() const
54
55=== modified file 'src/qgsettings.h'
56--- src/qgsettings.h 2013-08-28 17:29:34 +0000
57+++ src/qgsettings.h 2013-08-30 14:26:58 +0000
58@@ -67,6 +67,18 @@
59 void set(const QString &key, const QVariant &value);
60
61 /**
62+ * @brief Sets the value at key to value
63+ * @key The key for which to set the value
64+ * @value The value to set
65+ *
66+ * Behaves just like ::set(key, value), but returns false instead of
67+ * printing a warning if the key couldn't be set.
68+ *
69+ * @return whether the key was set
70+ */
71+ bool trySet(const QString &key, const QVariant &value);
72+
73+ /**
74 * \brief Retrieves the list of avaliable keys
75 */
76 QStringList keys() const;
77
78=== modified file 'tests/tst_GSettings.qml'
79--- tests/tst_GSettings.qml 2013-08-29 11:32:58 +0000
80+++ tests/tst_GSettings.qml 2013-08-30 14:26:58 +0000
81@@ -45,6 +45,13 @@
82 compare(settings.testStringList, ['six']);
83 settings.testStringList = [];
84 compare(settings.testStringList, []);
85+
86+ settings.testEnum = 'two';
87+ compare(settings.testEnum, 'two');
88+
89+ // test whether writing an out-of-range key doesn't work
90+ settings.testEnum = 'notanumber';
91+ compare(settings.testEnum, 'two');
92 }
93
94 function test_changed() {

Subscribers

People subscribed via source and target branches

to all changes: