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