Storing dynamic data in GSettings

Is GSettings the right place to store an potentially large and dynamic list of key-value combinations?


I’m working on “braus”, a tool that lets you select the browser you want to open an URL with. My goal is to allow the user to configure which browser to use for certain domains - so that work company domain are always opened in the company browser profile, without asking.

To do this, I need to store associations of domain names and browser names:

  • tickets.company.com -> company-browser.desktop
  • wiki.company.com -> company-browser.desktop
  • twitter.com -> private-browser.desktop

This list can become pretty large.

Is GSettings the right place to store such configuration, or should I rather resort to custom configuration files?

If GSettings is right: How can I do this?
I read about schemas that are a “list-of”, but did not find any applications that use them in the real world.
Pathless schemas could also be an option, but I don’t know if list-of would be better.

It depends on what you define as “large”. Thousands of keys, with a value of multiple megabytes each?

If all you have is a map of domain → desktop files, then you can define a key with a value type of a(ss), i.e. an array of UTF-8 string pairs, if you plan to load them all up at once, and then populate your internal data structure. Alternatively, you could use a{ss}, if you want a dictionary.

Just remember that the value type is part of the GSettings schema, and that changing the value type is an ABI break, which means you cannot just change a(ss) to a more complex, or different, value type compatibly. Additionally, you have to remember that GSettings may have different backends, and those backends may have restrictions or very different performance envelopes.

Another option is to avoid GSettings, but still use GVariant to define your own on-disk storage; you can build up the data as a GVariant, dump it as bytes into a binary file; then load the binary file, and create a new GVariant instance from its contents.

1 Like

Thanks! I’ll probably use a dictionary.

The documentation about GVariant format strings helps to understand what a{ss} is.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.