2 * Copyright © 2009, 2010 Codethink Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Ryan Lortie <desrt@desrt.ca>
20 #ifndef __G_SETTINGS_H__
21 #define __G_SETTINGS_H__
23 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
24 #error "Only <gio/gio.h> can be included directly."
27 #include <gio/gsettingsschema.h>
28 #include <gio/giotypes.h>
32 #define G_TYPE_SETTINGS (g_settings_get_type ())
33 #define G_SETTINGS(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
34 G_TYPE_SETTINGS, GSettings))
35 #define G_SETTINGS_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
36 G_TYPE_SETTINGS, GSettingsClass))
37 #define G_IS_SETTINGS(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_SETTINGS))
38 #define G_IS_SETTINGS_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_SETTINGS))
39 #define G_SETTINGS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
40 G_TYPE_SETTINGS, GSettingsClass))
42 typedef struct _GSettingsPrivate GSettingsPrivate;
43 typedef struct _GSettingsClass GSettingsClass;
45 struct _GSettingsClass
47 GObjectClass parent_class;
50 void (*writable_changed) (GSettings *settings,
52 void (*changed) (GSettings *settings,
54 gboolean (*writable_change_event) (GSettings *settings,
56 gboolean (*change_event) (GSettings *settings,
65 GObject parent_instance;
66 GSettingsPrivate *priv;
71 GType g_settings_get_type (void);
73 GLIB_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas)
74 const gchar * const * g_settings_list_schemas (void);
75 GLIB_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas)
76 const gchar * const * g_settings_list_relocatable_schemas (void);
78 GSettings * g_settings_new (const gchar *schema_id);
80 GSettings * g_settings_new_with_path (const gchar *schema_id,
83 GSettings * g_settings_new_with_backend (const gchar *schema_id,
84 GSettingsBackend *backend);
86 GSettings * g_settings_new_with_backend_and_path (const gchar *schema_id,
87 GSettingsBackend *backend,
89 GLIB_AVAILABLE_IN_2_32
90 GSettings * g_settings_new_full (GSettingsSchema *schema,
91 GSettingsBackend *backend,
94 gchar ** g_settings_list_children (GSettings *settings);
96 gchar ** g_settings_list_keys (GSettings *settings);
97 GLIB_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_get_range)
98 GVariant * g_settings_get_range (GSettings *settings,
100 GLIB_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_range_check)
101 gboolean g_settings_range_check (GSettings *settings,
105 GLIB_AVAILABLE_IN_ALL
106 gboolean g_settings_set_value (GSettings *settings,
109 GLIB_AVAILABLE_IN_ALL
110 GVariant * g_settings_get_value (GSettings *settings,
113 GLIB_AVAILABLE_IN_2_40
114 GVariant * g_settings_get_user_value (GSettings *settings,
116 GLIB_AVAILABLE_IN_2_40
117 GVariant * g_settings_get_default_value (GSettings *settings,
120 GLIB_AVAILABLE_IN_ALL
121 gboolean g_settings_set (GSettings *settings,
125 GLIB_AVAILABLE_IN_ALL
126 void g_settings_get (GSettings *settings,
130 GLIB_AVAILABLE_IN_ALL
131 void g_settings_reset (GSettings *settings,
134 GLIB_AVAILABLE_IN_ALL
135 gint g_settings_get_int (GSettings *settings,
137 GLIB_AVAILABLE_IN_ALL
138 gboolean g_settings_set_int (GSettings *settings,
141 GLIB_AVAILABLE_IN_2_32
142 guint g_settings_get_uint (GSettings *settings,
144 GLIB_AVAILABLE_IN_2_32
145 gboolean g_settings_set_uint (GSettings *settings,
148 GLIB_AVAILABLE_IN_ALL
149 gchar * g_settings_get_string (GSettings *settings,
151 GLIB_AVAILABLE_IN_ALL
152 gboolean g_settings_set_string (GSettings *settings,
155 GLIB_AVAILABLE_IN_ALL
156 gboolean g_settings_get_boolean (GSettings *settings,
158 GLIB_AVAILABLE_IN_ALL
159 gboolean g_settings_set_boolean (GSettings *settings,
162 GLIB_AVAILABLE_IN_ALL
163 gdouble g_settings_get_double (GSettings *settings,
165 GLIB_AVAILABLE_IN_ALL
166 gboolean g_settings_set_double (GSettings *settings,
169 GLIB_AVAILABLE_IN_ALL
170 gchar ** g_settings_get_strv (GSettings *settings,
172 GLIB_AVAILABLE_IN_ALL
173 gboolean g_settings_set_strv (GSettings *settings,
175 const gchar *const *value);
176 GLIB_AVAILABLE_IN_ALL
177 gint g_settings_get_enum (GSettings *settings,
179 GLIB_AVAILABLE_IN_ALL
180 gboolean g_settings_set_enum (GSettings *settings,
183 GLIB_AVAILABLE_IN_ALL
184 guint g_settings_get_flags (GSettings *settings,
186 GLIB_AVAILABLE_IN_ALL
187 gboolean g_settings_set_flags (GSettings *settings,
190 GLIB_AVAILABLE_IN_ALL
191 GSettings * g_settings_get_child (GSettings *settings,
194 GLIB_AVAILABLE_IN_ALL
195 gboolean g_settings_is_writable (GSettings *settings,
198 GLIB_AVAILABLE_IN_ALL
199 void g_settings_delay (GSettings *settings);
200 GLIB_AVAILABLE_IN_ALL
201 void g_settings_apply (GSettings *settings);
202 GLIB_AVAILABLE_IN_ALL
203 void g_settings_revert (GSettings *settings);
204 GLIB_AVAILABLE_IN_ALL
205 gboolean g_settings_get_has_unapplied (GSettings *settings);
206 GLIB_AVAILABLE_IN_ALL
207 void g_settings_sync (void);
210 * GSettingsBindSetMapping:
211 * @value: a #GValue containing the property value to map
212 * @expected_type: the #GVariantType to create
213 * @user_data: user data that was specified when the binding was created
215 * The type for the function that is used to convert an object property
216 * value to a #GVariant for storing it in #GSettings.
218 * Returns: a new #GVariant holding the data from @value,
219 * or %NULL in case of an error
221 typedef GVariant * (*GSettingsBindSetMapping) (const GValue *value,
222 const GVariantType *expected_type,
226 * GSettingsBindGetMapping:
227 * @value: return location for the property value
228 * @variant: the #GVariant
229 * @user_data: user data that was specified when the binding was created
231 * The type for the function that is used to convert from #GSettings to
232 * an object property. The @value is already initialized to hold values
233 * of the appropriate type.
235 * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
237 typedef gboolean (*GSettingsBindGetMapping) (GValue *value,
242 * GSettingsGetMapping:
243 * @value: the #GVariant to map, or %NULL
244 * @result: (out): the result of the mapping
245 * @user_data: (closure): the user data that was passed to
246 * g_settings_get_mapped()
248 * The type of the function that is used to convert from a value stored
249 * in a #GSettings to a value that is useful to the application.
251 * If the value is successfully mapped, the result should be stored at
252 * @result and %TRUE returned. If mapping fails (for example, if @value
253 * is not in the right format) then %FALSE should be returned.
255 * If @value is %NULL then it means that the mapping function is being
256 * given a "last chance" to successfully return a valid value. %TRUE
257 * must be returned in this case.
259 * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
261 typedef gboolean (*GSettingsGetMapping) (GVariant *value,
266 * GSettingsBindFlags:
267 * @G_SETTINGS_BIND_DEFAULT: Equivalent to <literal>G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET</literal>
268 * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
269 * It is an error to use this flag if the property is not writable.
270 * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
271 * It is an error to use this flag if the property is not readable.
272 * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
273 * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to #G_SETTINGS_BIND_GET, set the #GObject property
274 * value initially from the setting, but do not listen for changes of the setting
275 * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
276 * the boolean value when mapping between the setting and the property. The setting and property must both
277 * be booleans. You cannot pass this flag to g_settings_bind_with_mapping().
279 * Flags used when creating a binding. These flags determine in which
280 * direction the binding works. The default is to synchronize in both
285 G_SETTINGS_BIND_DEFAULT,
286 G_SETTINGS_BIND_GET = (1<<0),
287 G_SETTINGS_BIND_SET = (1<<1),
288 G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
289 G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
290 G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
291 } GSettingsBindFlags;
293 GLIB_AVAILABLE_IN_ALL
294 void g_settings_bind (GSettings *settings,
297 const gchar *property,
298 GSettingsBindFlags flags);
299 GLIB_AVAILABLE_IN_ALL
300 void g_settings_bind_with_mapping (GSettings *settings,
303 const gchar *property,
304 GSettingsBindFlags flags,
305 GSettingsBindGetMapping get_mapping,
306 GSettingsBindSetMapping set_mapping,
308 GDestroyNotify destroy);
309 GLIB_AVAILABLE_IN_ALL
310 void g_settings_bind_writable (GSettings *settings,
313 const gchar *property,
315 GLIB_AVAILABLE_IN_ALL
316 void g_settings_unbind (gpointer object,
317 const gchar *property);
319 GLIB_AVAILABLE_IN_2_32
320 GAction * g_settings_create_action (GSettings *settings,
323 GLIB_AVAILABLE_IN_ALL
324 gpointer g_settings_get_mapped (GSettings *settings,
326 GSettingsGetMapping mapping,
331 #endif /* __G_SETTINGS_H__ */