1/*
2 * Copyright © 2009, 2010 Codethink Limited
3 *
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.1 of the License, or (at your option) any later version.
8 *
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.
13 *
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/>.
16 *
17 * Author: Ryan Lortie <desrt@desrt.ca>
18 */
19
20#ifndef __G_SETTINGS_H__
21#define __G_SETTINGS_H__
22
23#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
24#error "Only <gio/gio.h> can be included directly."
25#endif
26
27#include <gio/gsettingsschema.h>
28#include <gio/giotypes.h>
29
30G_BEGIN_DECLS
31
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))
41
42typedef struct _GSettingsPrivate GSettingsPrivate;
43typedef struct _GSettingsClass GSettingsClass;
44
45struct _GSettingsClass
46{
47 GObjectClass parent_class;
48
49 /* Signals */
50 void (*writable_changed) (GSettings *settings,
51 const gchar *key);
52 void (*changed) (GSettings *settings,
53 const gchar *key);
54 gboolean (*writable_change_event) (GSettings *settings,
55 GQuark key);
56 gboolean (*change_event) (GSettings *settings,
57 const GQuark *keys,
58 gint n_keys);
59
60 gpointer padding[20];
61};
62
63struct _GSettings
64{
65 GObject parent_instance;
66 GSettingsPrivate *priv;
67};
68
69
70GLIB_AVAILABLE_IN_ALL
71GType g_settings_get_type (void);
72
73GLIB_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas)
74const gchar * const * g_settings_list_schemas (void);
75GLIB_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas)
76const gchar * const * g_settings_list_relocatable_schemas (void);
77GLIB_AVAILABLE_IN_ALL
78GSettings * g_settings_new (const gchar *schema_id);
79GLIB_AVAILABLE_IN_ALL
80GSettings * g_settings_new_with_path (const gchar *schema_id,
81 const gchar *path);
82GLIB_AVAILABLE_IN_ALL
83GSettings * g_settings_new_with_backend (const gchar *schema_id,
84 GSettingsBackend *backend);
85GLIB_AVAILABLE_IN_ALL
86GSettings * g_settings_new_with_backend_and_path (const gchar *schema_id,
87 GSettingsBackend *backend,
88 const gchar *path);
89GLIB_AVAILABLE_IN_2_32
90GSettings * g_settings_new_full (GSettingsSchema *schema,
91 GSettingsBackend *backend,
92 const gchar *path);
93GLIB_AVAILABLE_IN_ALL
94gchar ** g_settings_list_children (GSettings *settings);
95GLIB_DEPRECATED_IN_2_46_FOR(g_settings_schema_list_keys)
96gchar ** g_settings_list_keys (GSettings *settings);
97GLIB_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_get_range)
98GVariant * g_settings_get_range (GSettings *settings,
99 const gchar *key);
100GLIB_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_range_check)
101gboolean g_settings_range_check (GSettings *settings,
102 const gchar *key,
103 GVariant *value);
104
105GLIB_AVAILABLE_IN_ALL
106gboolean g_settings_set_value (GSettings *settings,
107 const gchar *key,
108 GVariant *value);
109GLIB_AVAILABLE_IN_ALL
110GVariant * g_settings_get_value (GSettings *settings,
111 const gchar *key);
112
113GLIB_AVAILABLE_IN_2_40
114GVariant * g_settings_get_user_value (GSettings *settings,
115 const gchar *key);
116GLIB_AVAILABLE_IN_2_40
117GVariant * g_settings_get_default_value (GSettings *settings,
118 const gchar *key);
119
120GLIB_AVAILABLE_IN_ALL
121gboolean g_settings_set (GSettings *settings,
122 const gchar *key,
123 const gchar *format,
124 ...);
125GLIB_AVAILABLE_IN_ALL
126void g_settings_get (GSettings *settings,
127 const gchar *key,
128 const gchar *format,
129 ...);
130GLIB_AVAILABLE_IN_ALL
131void g_settings_reset (GSettings *settings,
132 const gchar *key);
133
134GLIB_AVAILABLE_IN_ALL
135gint g_settings_get_int (GSettings *settings,
136 const gchar *key);
137GLIB_AVAILABLE_IN_ALL
138gboolean g_settings_set_int (GSettings *settings,
139 const gchar *key,
140 gint value);
141GLIB_AVAILABLE_IN_2_50
142gint64 g_settings_get_int64 (GSettings *settings,
143 const gchar *key);
144GLIB_AVAILABLE_IN_2_50
145gboolean g_settings_set_int64 (GSettings *settings,
146 const gchar *key,
147 gint64 value);
148GLIB_AVAILABLE_IN_2_32
149guint g_settings_get_uint (GSettings *settings,
150 const gchar *key);
151GLIB_AVAILABLE_IN_2_32
152gboolean g_settings_set_uint (GSettings *settings,
153 const gchar *key,
154 guint value);
155GLIB_AVAILABLE_IN_2_50
156guint64 g_settings_get_uint64 (GSettings *settings,
157 const gchar *key);
158GLIB_AVAILABLE_IN_2_50
159gboolean g_settings_set_uint64 (GSettings *settings,
160 const gchar *key,
161 guint64 value);
162GLIB_AVAILABLE_IN_ALL
163gchar * g_settings_get_string (GSettings *settings,
164 const gchar *key);
165GLIB_AVAILABLE_IN_ALL
166gboolean g_settings_set_string (GSettings *settings,
167 const gchar *key,
168 const gchar *value);
169GLIB_AVAILABLE_IN_ALL
170gboolean g_settings_get_boolean (GSettings *settings,
171 const gchar *key);
172GLIB_AVAILABLE_IN_ALL
173gboolean g_settings_set_boolean (GSettings *settings,
174 const gchar *key,
175 gboolean value);
176GLIB_AVAILABLE_IN_ALL
177gdouble g_settings_get_double (GSettings *settings,
178 const gchar *key);
179GLIB_AVAILABLE_IN_ALL
180gboolean g_settings_set_double (GSettings *settings,
181 const gchar *key,
182 gdouble value);
183GLIB_AVAILABLE_IN_ALL
184gchar ** g_settings_get_strv (GSettings *settings,
185 const gchar *key);
186GLIB_AVAILABLE_IN_ALL
187gboolean g_settings_set_strv (GSettings *settings,
188 const gchar *key,
189 const gchar *const *value);
190GLIB_AVAILABLE_IN_ALL
191gint g_settings_get_enum (GSettings *settings,
192 const gchar *key);
193GLIB_AVAILABLE_IN_ALL
194gboolean g_settings_set_enum (GSettings *settings,
195 const gchar *key,
196 gint value);
197GLIB_AVAILABLE_IN_ALL
198guint g_settings_get_flags (GSettings *settings,
199 const gchar *key);
200GLIB_AVAILABLE_IN_ALL
201gboolean g_settings_set_flags (GSettings *settings,
202 const gchar *key,
203 guint value);
204GLIB_AVAILABLE_IN_ALL
205GSettings * g_settings_get_child (GSettings *settings,
206 const gchar *name);
207
208GLIB_AVAILABLE_IN_ALL
209gboolean g_settings_is_writable (GSettings *settings,
210 const gchar *name);
211
212GLIB_AVAILABLE_IN_ALL
213void g_settings_delay (GSettings *settings);
214GLIB_AVAILABLE_IN_ALL
215void g_settings_apply (GSettings *settings);
216GLIB_AVAILABLE_IN_ALL
217void g_settings_revert (GSettings *settings);
218GLIB_AVAILABLE_IN_ALL
219gboolean g_settings_get_has_unapplied (GSettings *settings);
220GLIB_AVAILABLE_IN_ALL
221void g_settings_sync (void);
222
223/**
224 * GSettingsBindSetMapping:
225 * @value: a #GValue containing the property value to map
226 * @expected_type: the #GVariantType to create
227 * @user_data: user data that was specified when the binding was created
228 *
229 * The type for the function that is used to convert an object property
230 * value to a #GVariant for storing it in #GSettings.
231 *
232 * Returns: a new #GVariant holding the data from @value,
233 * or %NULL in case of an error
234 */
235typedef GVariant * (*GSettingsBindSetMapping) (const GValue *value,
236 const GVariantType *expected_type,
237 gpointer user_data);
238
239/**
240 * GSettingsBindGetMapping:
241 * @value: return location for the property value
242 * @variant: the #GVariant
243 * @user_data: user data that was specified when the binding was created
244 *
245 * The type for the function that is used to convert from #GSettings to
246 * an object property. The @value is already initialized to hold values
247 * of the appropriate type.
248 *
249 * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
250 */
251typedef gboolean (*GSettingsBindGetMapping) (GValue *value,
252 GVariant *variant,
253 gpointer user_data);
254
255/**
256 * GSettingsGetMapping:
257 * @value: the #GVariant to map, or %NULL
258 * @result: (out): the result of the mapping
259 * @user_data: (closure): the user data that was passed to
260 * g_settings_get_mapped()
261 *
262 * The type of the function that is used to convert from a value stored
263 * in a #GSettings to a value that is useful to the application.
264 *
265 * If the value is successfully mapped, the result should be stored at
266 * @result and %TRUE returned. If mapping fails (for example, if @value
267 * is not in the right format) then %FALSE should be returned.
268 *
269 * If @value is %NULL then it means that the mapping function is being
270 * given a "last chance" to successfully return a valid value. %TRUE
271 * must be returned in this case.
272 *
273 * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
274 **/
275typedef gboolean (*GSettingsGetMapping) (GVariant *value,
276 gpointer *result,
277 gpointer user_data);
278
279/**
280 * GSettingsBindFlags:
281 * @G_SETTINGS_BIND_DEFAULT: Equivalent to `G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET`
282 * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
283 * It is an error to use this flag if the property is not writable.
284 * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
285 * It is an error to use this flag if the property is not readable.
286 * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
287 * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to %G_SETTINGS_BIND_GET, set the #GObject property
288 * value initially from the setting, but do not listen for changes of the setting
289 * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
290 * the boolean value when mapping between the setting and the property. The setting and property must both
291 * be booleans. You cannot pass this flag to g_settings_bind_with_mapping().
292 *
293 * Flags used when creating a binding. These flags determine in which
294 * direction the binding works. The default is to synchronize in both
295 * directions.
296 */
297typedef enum
298{
299 G_SETTINGS_BIND_DEFAULT,
300 G_SETTINGS_BIND_GET = (1<<0),
301 G_SETTINGS_BIND_SET = (1<<1),
302 G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
303 G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
304 G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
305} GSettingsBindFlags;
306
307GLIB_AVAILABLE_IN_ALL
308void g_settings_bind (GSettings *settings,
309 const gchar *key,
310 gpointer object,
311 const gchar *property,
312 GSettingsBindFlags flags);
313GLIB_AVAILABLE_IN_ALL
314void g_settings_bind_with_mapping (GSettings *settings,
315 const gchar *key,
316 gpointer object,
317 const gchar *property,
318 GSettingsBindFlags flags,
319 GSettingsBindGetMapping get_mapping,
320 GSettingsBindSetMapping set_mapping,
321 gpointer user_data,
322 GDestroyNotify destroy);
323GLIB_AVAILABLE_IN_ALL
324void g_settings_bind_writable (GSettings *settings,
325 const gchar *key,
326 gpointer object,
327 const gchar *property,
328 gboolean inverted);
329GLIB_AVAILABLE_IN_ALL
330void g_settings_unbind (gpointer object,
331 const gchar *property);
332
333GLIB_AVAILABLE_IN_2_32
334GAction * g_settings_create_action (GSettings *settings,
335 const gchar *key);
336
337GLIB_AVAILABLE_IN_ALL
338gpointer g_settings_get_mapped (GSettings *settings,
339 const gchar *key,
340 GSettingsGetMapping mapping,
341 gpointer user_data);
342
343G_END_DECLS
344
345#endif /* __G_SETTINGS_H__ */
346

source code of include/glib-2.0/gio/gsettings.h