Geany dev
|
Lightweight library for reading/writing GKeyFile
settings and synchronizing widgets with C variables.
More...
Typedefs | |
typedef struct StashGroup | StashGroup |
Opaque type for a group of settings. | |
typedef gconstpointer | StashWidgetID |
Can be GtkWidget* or gchar* depending on whether the owner argument is used for stash_group_display() and stash_group_update(). | |
Functions | |
void | stash_group_add_boolean (StashGroup *group, gboolean *setting, const gchar *key_name, gboolean default_value) |
Adds boolean setting. More... | |
void | stash_group_add_combo_box (StashGroup *group, gint *setting, const gchar *key_name, gint default_value, StashWidgetID widget_id) |
Adds a GtkComboBox widget pref. More... | |
void | stash_group_add_combo_box_entry (StashGroup *group, gchar **setting, const gchar *key_name, const gchar *default_value, StashWidgetID widget_id) |
Adds a GtkComboBoxEntry widget pref. More... | |
void | stash_group_add_double (StashGroup *group, gdouble *setting, const gchar *key_name, gdouble default_value) |
Adds double setting. More... | |
void | stash_group_add_entry (StashGroup *group, gchar **setting, const gchar *key_name, const gchar *default_value, StashWidgetID widget_id) |
Adds a GtkEntry widget pref. More... | |
void | stash_group_add_integer (StashGroup *group, gint *setting, const gchar *key_name, gint default_value) |
Adds integer setting. More... | |
void | stash_group_add_radio_buttons (StashGroup *group, gint *setting, const gchar *key_name, gint default_value, StashWidgetID widget_id, gint enum_id,...) G_GNUC_NULL_TERMINATED |
Adds a GtkRadioButton widget group pref. More... | |
void | stash_group_add_spin_button_integer (StashGroup *group, gint *setting, const gchar *key_name, gint default_value, StashWidgetID widget_id) |
Adds a GtkSpinButton widget pref. More... | |
void | stash_group_add_string (StashGroup *group, gchar **setting, const gchar *key_name, const gchar *default_value) |
Adds string setting. More... | |
void | stash_group_add_string_vector (StashGroup *group, gchar ***setting, const gchar *key_name, const gchar **default_value) |
Adds string vector setting (array of strings). More... | |
void | stash_group_add_toggle_button (StashGroup *group, gboolean *setting, const gchar *key_name, gboolean default_value, StashWidgetID widget_id) |
Adds a GtkToggleButton (or GtkCheckButton ) widget pref. More... | |
void | stash_group_add_widget_property (StashGroup *group, gpointer setting, const gchar *key_name, gpointer default_value, StashWidgetID widget_id, const gchar *property_name, GType type) |
Adds a widget's read/write property to the stash group. More... | |
void | stash_group_display (StashGroup *group, GtkWidget *owner) |
Applies Stash settings to widgets, usually called before displaying the widgets. More... | |
void | stash_group_free (StashGroup *group) |
Frees a group. More... | |
void | stash_group_free_settings (StashGroup *group) |
Frees the memory allocated for setting values in a group. More... | |
gboolean | stash_group_load_from_file (StashGroup *group, const gchar *filename) |
Reads group settings from a configuration file using GKeyFile . More... | |
void | stash_group_load_from_key_file (StashGroup *group, GKeyFile *keyfile) |
Reads key values from keyfile into the group settings. More... | |
StashGroup * | stash_group_new (const gchar *name) |
Creates a new group. More... | |
gint | stash_group_save_to_file (StashGroup *group, const gchar *filename, GKeyFileFlags flags) |
Writes group settings to a configuration file using GKeyFile . More... | |
void | stash_group_save_to_key_file (StashGroup *group, GKeyFile *keyfile) |
Writes group settings into key values in keyfile. More... | |
void | stash_group_update (StashGroup *group, GtkWidget *owner) |
Applies widget values to Stash settings, usually called after displaying the widgets. More... | |
Lightweight library for reading/writing GKeyFile
settings and synchronizing widgets with C variables.
Note: Stash should only depend on GLib and GTK, but currently has some minor dependencies on Geany's utils.c.
'Setting' is used only for data stored on disk or in memory. 'Pref' can also include visual widget information.
Stash will not duplicate strings if they are normally static arrays, such as keyfile group names and key names, string default values, widget_id names, property names.
String settings and other dynamically allocated settings will be initialized to NULL when added to a StashGroup (so they can safely be reassigned later).
Widgets very commonly used in configuration dialogs will be supported with their own function. Widgets less commonly used such as GtkExpander
or widget settings that aren't commonly needed to be persistent won't be directly supported, to keep the library lightweight. However, you can use stash_group_add_widget_property() to also save these settings for any read/write widget property. Macros could be added for common widget properties such as GtkExpander:"expanded"
.
Here we have some settings for a cup - whether it is made of porcelain, who made it, how many we have, and how much they cost. (Yes, it's a stupid example).
For prefs, it's the same as the above example but you tell Stash to add widget prefs instead of just data settings.
This example uses lookup strings for widgets as they are more flexible than widget pointers. Code to load and save the settings is omitted - see the first example instead.
Here we show a dialog with a toggle button for whether the cup should have a handle.
void stash_group_add_boolean | ( | StashGroup * | group, |
gboolean * | setting, | ||
const gchar * | key_name, | ||
gboolean | default_value | ||
) |
Adds boolean setting.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
void stash_group_add_combo_box | ( | StashGroup * | group, |
gint * | setting, | ||
const gchar * | key_name, | ||
gint | default_value, | ||
StashWidgetID | widget_id | ||
) |
Adds a GtkComboBox
widget pref.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
widget_id | GtkWidget pointer or string to lookup widget later. |
void stash_group_add_combo_box_entry | ( | StashGroup * | group, |
gchar ** | setting, | ||
const gchar * | key_name, | ||
const gchar * | default_value, | ||
StashWidgetID | widget_id | ||
) |
Adds a GtkComboBoxEntry
widget pref.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
widget_id | GtkWidget pointer or string to lookup widget later. |
void stash_group_add_double | ( | StashGroup * | group, |
gdouble * | setting, | ||
const gchar * | key_name, | ||
gdouble | default_value | ||
) |
Adds double setting.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
void stash_group_add_entry | ( | StashGroup * | group, |
gchar ** | setting, | ||
const gchar * | key_name, | ||
const gchar * | default_value, | ||
StashWidgetID | widget_id | ||
) |
Adds a GtkEntry
widget pref.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
widget_id | GtkWidget pointer or string to lookup widget later. |
void stash_group_add_integer | ( | StashGroup * | group, |
gint * | setting, | ||
const gchar * | key_name, | ||
gint | default_value | ||
) |
Adds integer setting.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
void stash_group_add_radio_buttons | ( | StashGroup * | group, |
gint * | setting, | ||
const gchar * | key_name, | ||
gint | default_value, | ||
StashWidgetID | widget_id, | ||
gint | enum_id, | ||
... | |||
) |
Adds a GtkRadioButton
widget group pref.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
widget_id | GtkWidget pointer or string to lookup widget later. |
enum_id | Enum value for widget_id. |
... | pairs of widget_id, enum_id. Example (using widget lookup strings, but widget pointers can also work): enum {FOO, BAR};
stash_group_add_radio_buttons(group, &which_one_setting, "which_one", BAR,
"radio_foo", FOO, "radio_bar", BAR, NULL);
void stash_group_add_radio_buttons(StashGroup *group, gint *setting, const gchar *key_name, gint default_value, StashWidgetID widget_id, gint enum_id,...) G_GNUC_NULL_TERMINATED Adds a GtkRadioButton widget group pref. Definition: stash.c:892 |
void stash_group_add_spin_button_integer | ( | StashGroup * | group, |
gint * | setting, | ||
const gchar * | key_name, | ||
gint | default_value, | ||
StashWidgetID | widget_id | ||
) |
Adds a GtkSpinButton
widget pref.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
widget_id | GtkWidget pointer or string to lookup widget later. |
void stash_group_add_string | ( | StashGroup * | group, |
gchar ** | setting, | ||
const gchar * | key_name, | ||
const gchar * | default_value | ||
) |
Adds string setting.
The contents of setting will be initialized to NULL
.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | String to copy if the key doesn't exist when loading, or NULL . |
void stash_group_add_string_vector | ( | StashGroup * | group, |
gchar *** | setting, | ||
const gchar * | key_name, | ||
const gchar ** | default_value | ||
) |
Adds string vector setting (array of strings).
The contents of setting will be initialized to NULL
.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Vector to copy if the key doesn't exist when loading. Usually NULL . |
void stash_group_add_toggle_button | ( | StashGroup * | group, |
gboolean * | setting, | ||
const gchar * | key_name, | ||
gboolean | default_value, | ||
StashWidgetID | widget_id | ||
) |
Adds a GtkToggleButton
(or GtkCheckButton
) widget pref.
group | . |
setting | Address of setting variable. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. |
widget_id | GtkWidget pointer or string to lookup widget later. |
void stash_group_add_widget_property | ( | StashGroup * | group, |
gpointer | setting, | ||
const gchar * | key_name, | ||
gpointer | default_value, | ||
StashWidgetID | widget_id, | ||
const gchar * | property_name, | ||
GType | type | ||
) |
Adds a widget's read/write property to the stash group.
The property will be set when calling stash_group_display(), and read when calling stash_group_update().
group | . |
setting | Address of e.g. an integer if using an integer property. |
key_name | Name for key in a GKeyFile . |
default_value | Value to use if the key doesn't exist when loading. Should be cast into a pointer e.g. with GINT_TO_POINTER() . |
widget_id | GtkWidget pointer or string to lookup widget later. |
property_name | . |
type | can be 0 if passing a GtkWidget as the widget_id argument to look it up from the GObject data. |
handle_widget_property()
. void stash_group_display | ( | StashGroup * | group, |
GtkWidget * | owner | ||
) |
Applies Stash settings to widgets, usually called before displaying the widgets.
The owner argument depends on which type you use for StashWidgetID.
group | . |
owner | If non-NULL, used to lookup widgets by name, otherwise widget pointers are assumed. |
void stash_group_free | ( | StashGroup * | group | ) |
Frees a group.
group | . |
void stash_group_free_settings | ( | StashGroup * | group | ) |
Frees the memory allocated for setting values in a group.
Useful e.g. to avoid freeing strings individually.
group | . |
gboolean stash_group_load_from_file | ( | StashGroup * | group, |
const gchar * | filename | ||
) |
Reads group settings from a configuration file using GKeyFile
.
group | . |
filename | Filename of the file to read, in locale encoding. |
TRUE
if a key file could be loaded. void stash_group_load_from_key_file | ( | StashGroup * | group, |
GKeyFile * | keyfile | ||
) |
Reads key values from keyfile into the group settings.
group | . |
keyfile | Usually loaded from a configuration file first. |
StashGroup * stash_group_new | ( | const gchar * | name | ) |
Creates a new group.
name | Name used for GKeyFile group. |
gint stash_group_save_to_file | ( | StashGroup * | group, |
const gchar * | filename, | ||
GKeyFileFlags | flags | ||
) |
Writes group settings to a configuration file using GKeyFile
.
group | . |
filename | Filename of the file to write, in locale encoding. |
flags | Keyfile options - G_KEY_FILE_NONE is the most efficient. |
errno
of the failed operation is returned. void stash_group_save_to_key_file | ( | StashGroup * | group, |
GKeyFile * | keyfile | ||
) |
Writes group settings into key values in keyfile.
keyfile is usually written to a configuration file afterwards.
group | . |
keyfile | . |
void stash_group_update | ( | StashGroup * | group, |
GtkWidget * | owner | ||
) |
Applies widget values to Stash settings, usually called after displaying the widgets.
The owner argument depends on which type you use for StashWidgetID.
group | . |
owner | If non-NULL, used to lookup widgets by name, otherwise widget pointers are assumed. |