After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 668233 - Unable to determine if a key is set to the default / what the default value is
Unable to determine if a key is set to the default / what the default value is
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gsettings
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Allison Karlitskaya (desrt)
gtkdev
: 669324 697130 705463 (view as bug list)
Depends on:
Blocks: 668234
 
 
Reported: 2012-01-19 02:37 UTC by Robert Ancell
Modified: 2013-10-28 18:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GSettingsBackend: add read_user_value() API (4.83 KB, patch)
2013-10-27 17:35 UTC, Allison Karlitskaya (desrt)
committed Details | Review
GSettings: small internal refactor (3.72 KB, patch)
2013-10-27 17:35 UTC, Allison Karlitskaya (desrt)
committed Details | Review
GSettings: add getters for user/default value (5.63 KB, patch)
2013-10-27 17:35 UTC, Allison Karlitskaya (desrt)
committed Details | Review
GSettings: implement _read_user_value() (4.58 KB, patch)
2013-10-27 18:11 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Robert Ancell 2012-01-19 02:37:24 UTC
There is no API to determine if a key is set to the default / what the default value is.

Perhaps:

GVariant *g_settings_get_default (GSettings *settings, const gchar *key);
gboolean g_settings_is_default (GSettings *settings, const gchar *key);
Comment 1 Allison Karlitskaya (desrt) 2012-01-19 03:08:22 UTC
the reason that this API isn't exposed is because 'default' has a lot of meanings.  default per the schema?  default as per the sysadmin default?  how about lockdown?

fwiw, there is a bit of a well-known trick: create a GSettings, delay it, reset the keys and query their values -- you will get the value that the key has as if it were reset which is some sort of reasonable definition of 'default', i guess.

we should definitely be able to expose the default-per-schema value via the new schema/schemasource APIs.
Comment 2 Robert Ancell 2012-01-19 03:44:42 UTC
what I really need to know is "g_settings_is_set" - i.e. is there a value that has been set at some point and stored in the backend.
Comment 3 Robert Ancell 2012-01-19 03:46:15 UTC
And I guess g_settings_get_default () would get the value if the key was unset.
Comment 4 Robert Ancell 2012-01-19 03:48:16 UTC
The current API this relates to is g_settings_reset.  i.e. g_settings_is_set() tests if g_settings_reset() would do anything, g_settings_get_default() returns the value that will be returned after g_settings_reset() is called.
Comment 5 Allison Karlitskaya (desrt) 2012-05-09 22:04:14 UTC
This can't be solved without changing the backend API.

The current API allows us to ask two questions:

  1) What is the value?

  2) What is the default value?

We can't just compare because it could be that the user has explicitly set the default value as their preference.
Comment 6 David Gomes 2013-04-02 18:14:38 UTC
*** Bug 697130 has been marked as a duplicate of this bug. ***
Comment 7 David Gomes 2013-04-02 18:21:50 UTC
There are use cases for this. There was somebody on IRC complaining that he could revert but that he couldn't tell the user what it was going to be reverted to which is quite dangerous.
Comment 8 John Stowers 2013-04-15 20:31:44 UTC
FWIW I'd like to use this API in tweak-tool
Comment 9 Allison Karlitskaya (desrt) 2013-10-27 17:35:10 UTC
Created attachment 258239 [details] [review]
GSettingsBackend: add read_user_value() API

This will get the 'user' value from the database (ie: the one that the user has
control over).

Provide a default implementation that chains to ->read().  That will work for
all of our internal backends which don't have a concept of layering or
lockdown.

We will use this for g_settings_get_user_value().
Comment 10 Allison Karlitskaya (desrt) 2013-10-27 17:35:13 UTC
Created attachment 258240 [details] [review]
GSettings: small internal refactor

Add two boolean parameters to our internal getter utility function in
anticipation of the coming addition of g_settings_get_user_value() and
g_settings_get_default_value() APIs.
Comment 11 Allison Karlitskaya (desrt) 2013-10-27 17:35:15 UTC
Created attachment 258241 [details] [review]
GSettings: add getters for user/default value

Add two new APIs: g_settings_get_user_value() and
g_settings_get_default_value().   Together, these should allow the
inspection of all interesting cases of "is this key set?" and "what
would happen if I reset this key?"
Comment 12 Lars Karlitski 2013-10-27 17:55:29 UTC
Review of attachment 258239 [details] [review]:

Ok.
Comment 13 Lars Karlitski 2013-10-27 17:56:51 UTC
Review of attachment 258240 [details] [review]:

Ok.
Comment 14 Lars Karlitski 2013-10-27 18:03:10 UTC
Review of attachment 258241 [details] [review]:

Looks good to me.

How will this interact with delayed settings?
Comment 15 Allison Karlitskaya (desrt) 2013-10-27 18:11:54 UTC
Created attachment 258242 [details] [review]
GSettings: implement _read_user_value()

Implement g_settings_backend_read_user_value() in DConfSettingsBackend.

This will help us support g_settings_get_user_value() properly.

We add a new engine API to support this as well.  It takes a
read_through queue, even though we don't bother using that from
DConfSettingsBackend.
Comment 16 Allison Karlitskaya (desrt) 2013-10-28 00:30:12 UTC
> How will this interact with delayed settings?

hm.  Poorly.  I think I need to implement the new vfunc on the backend and pass it through in the case that it's not set on the delayed object itself... Will post a new patch.
Comment 17 Allison Karlitskaya (desrt) 2013-10-28 14:47:34 UTC
*** Bug 669324 has been marked as a duplicate of this bug. ***
Comment 18 Allison Karlitskaya (desrt) 2013-10-28 17:20:08 UTC
Attachment 258239 [details] pushed as 84a6e65 - GSettingsBackend: add read_user_value() API
Attachment 258240 [details] pushed as 2d06dbe - GSettings: small internal refactor
Attachment 258241 [details] pushed as bebdfb8 - GSettings: add getters for user/default value
Comment 19 Allison Karlitskaya (desrt) 2013-10-28 17:24:30 UTC
Attachment 258242 [details] pushed as 863fa5c - GSettings: implement _read_user_value()
Comment 20 Allison Karlitskaya (desrt) 2013-10-28 18:28:42 UTC
*** Bug 705463 has been marked as a duplicate of this bug. ***