Skip to content

common: Add CcNumberObject and CcNumberList

GtkStringObject and GtkStringList are perfect for adding strings to things like an AdwComboRow. However, things like delay times are harder to set up, as the underlying GSettings take integer values directly, and so require mapping from strings to integers if GtkStringList would be used.

Using an AdwEnumList is an option, but is not flexible as no new values can be added, which is required if wanting to represent values that were set to dconf (by the user or using older Settings version) which are not in the enum.

To solve this, we add CcNumberObject, with a similar api to GtkStringObject. It contains an integer value, and an (optional) representing string and (optional) custom order. These objects are stored in a CcNumberList which wraps a GListStore and implements GListModel. It has convenient methods for adding values directly. The CcNumberList is always sorted, either ascending or descending, but also takes into account any special ordering of CcNumberObjects.

Properties of CcNumberList are set up so that "values" can be added in .ui files with a simple array notation, and one "special-value" CcNumberObject (with string and/or custom order) can be added in .ui files as well.

Using CcNumberObjects/CcNumberList in an AdwComboRow is very easy, it just requires a function that takes a CcNumberObject and returns a string. Two example functions are provided, which assume the CcNumberObject contains a time duration value in either seconds or minutes.

Complexity
It looks massive, but most of the code is just GObject boilerplate. The implementation is fairly simply imo.

Example
As an example, I have ported the delays from Privacy/Screen to CcNumberList. I think it shows the simplicity of the API and how much code can be removed or moved to .ui files.

Edited by Matthijs Velsink

Merge request reports