0ee4399efcf7561d7524ab1554602bcc23a990b3
[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 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
23 #error "Only <gio/gio.h> can be included directly."
24 #endif
25
26 #ifndef __G_SETTINGS_H__
27 #define __G_SETTINGS_H__
28
29 #include <gio/giotypes.h>
30
31 G_BEGIN_DECLS
32
33 #define G_TYPE_SETTINGS                                     (g_settings_get_type ())
34 #define G_SETTINGS(inst)                                    (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
35                                                              G_TYPE_SETTINGS, GSettings))
36 #define G_SETTINGS_CLASS(class)                             (G_TYPE_CHECK_CLASS_CAST ((class),                       \
37                                                              G_TYPE_SETTINGS, GSettingsClass))
38 #define G_IS_SETTINGS(inst)                                 (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_SETTINGS))
39 #define G_IS_SETTINGS_CLASS(class)                          (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_SETTINGS))
40 #define G_SETTINGS_GET_CLASS(inst)                          (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
41                                                              G_TYPE_SETTINGS, GSettingsClass))
42
43 typedef struct _GSettingsPrivate                            GSettingsPrivate;
44 typedef struct _GSettingsClass                              GSettingsClass;
45
46 struct _GSettingsClass
47 {
48   GObjectClass parent_class;
49
50   /* Signals */
51   void        (*writable_changed)      (GSettings    *settings,
52                                         const gchar  *key);
53   void        (*changed)               (GSettings    *settings,
54                                         const gchar  *key);
55   gboolean    (*writable_change_event) (GSettings    *settings,
56                                         GQuark        key);
57   gboolean    (*change_event)          (GSettings    *settings,
58                                         const GQuark *keys,
59                                         gint          n_keys);
60
61   gpointer padding[20];
62 };
63
64 struct _GSettings
65 {
66   GObject parent_instance;
67   GSettingsPrivate *priv;
68 };
69
70
71 GType                   g_settings_get_type                             (void);
72
73 const gchar * const *   g_settings_list_schemas                         (void);
74 GSettings *             g_settings_new                                  (const gchar        *schema);
75 GSettings *             g_settings_new_with_path                        (const gchar        *schema,
76                                                                          const gchar        *path);
77 GSettings *             g_settings_new_with_backend                     (const gchar        *schema,
78                                                                          GSettingsBackend   *backend);
79 GSettings *             g_settings_new_with_backend_and_path            (const gchar        *schema,
80                                                                          GSettingsBackend   *backend,
81                                                                          const gchar        *path);
82 gchar **                g_settings_list_children                        (GSettings          *settings);
83 gchar **                g_settings_list_keys                            (GSettings          *settings);
84
85 gboolean                g_settings_set_value                            (GSettings          *settings,
86                                                                          const gchar        *key,
87                                                                          GVariant           *value);
88 GVariant *              g_settings_get_value                            (GSettings          *settings,
89                                                                          const gchar        *key);
90
91 gboolean                g_settings_set                                  (GSettings          *settings,
92                                                                          const gchar        *key,
93                                                                          const gchar        *format,
94                                                                          ...);
95 void                    g_settings_get                                  (GSettings          *settings,
96                                                                          const gchar        *key,
97                                                                          const gchar        *format,
98                                                                          ...);
99 void                    g_settings_reset                                (GSettings          *settings,
100                                                                          const gchar        *key);
101
102 gint                    g_settings_get_int                              (GSettings          *settings,
103                                                                          const gchar        *key);
104 gboolean                g_settings_set_int                              (GSettings          *settings,
105                                                                          const gchar        *key,
106                                                                          gint                value);
107 gchar *                 g_settings_get_string                           (GSettings          *settings,
108                                                                          const gchar        *key);
109 gboolean                g_settings_set_string                           (GSettings          *settings,
110                                                                          const gchar        *key,
111                                                                          const gchar        *value);
112 gboolean                g_settings_get_boolean                          (GSettings          *settings,
113                                                                          const gchar        *key);
114 gboolean                g_settings_set_boolean                          (GSettings          *settings,
115                                                                          const gchar        *key,
116                                                                          gboolean            value);
117 gdouble                 g_settings_get_double                           (GSettings          *settings,
118                                                                          const gchar        *key);
119 gboolean                g_settings_set_double                           (GSettings          *settings,
120                                                                          const gchar        *key,
121                                                                          gdouble             value);
122 gchar **                g_settings_get_strv                             (GSettings          *settings,
123                                                                          const gchar        *key);
124 gboolean                g_settings_set_strv                             (GSettings          *settings,
125                                                                          const gchar        *key,
126                                                                          const gchar *const *value);
127 gint                    g_settings_get_enum                             (GSettings          *settings,
128                                                                          const gchar        *key);
129 gboolean                g_settings_set_enum                             (GSettings          *settings,
130                                                                          const gchar        *key,
131                                                                          gint                value);
132 guint                   g_settings_get_flags                            (GSettings          *settings,
133                                                                          const gchar        *key);
134 gboolean                g_settings_set_flags                            (GSettings          *settings,
135                                                                          const gchar        *key,
136                                                                          guint               value);
137 GSettings *             g_settings_get_child                            (GSettings          *settings,
138                                                                          const gchar        *name);
139
140 gboolean                g_settings_is_writable                          (GSettings          *settings,
141                                                                          const gchar        *name);
142
143 void                    g_settings_delay                                (GSettings          *settings);
144 void                    g_settings_apply                                (GSettings          *settings);
145 void                    g_settings_revert                               (GSettings          *settings);
146 gboolean                g_settings_get_has_unapplied                    (GSettings          *settings);
147 void                    g_settings_sync                                 (void);
148
149 /**
150  * GSettingsBindSetMapping:
151  * @value: a #GValue containing the property value to map
152  * @expected_type: the #GVariantType to create
153  * @user_data: user data that was specified when the binding was created
154  * @returns: a new #GVariant holding the data from @value,
155  *     or %NULL in case of an error
156  *
157  * The type for the function that is used to convert an object property
158  * value to a #GVariant for storing it in #GSettings.
159  */
160 typedef GVariant *    (*GSettingsBindSetMapping)                        (const GValue       *value,
161                                                                          const GVariantType *expected_type,
162                                                                          gpointer            user_data);
163
164 /**
165  * GSettingsBindGetMapping:
166  * @value: return location for the property value
167  * @variant: the #GVariant
168  * @user_data: user data that was specified when the binding was created
169  * @returns: %TRUE if the conversion succeeded, %FALSE in case of an error
170  *
171  * The type for the function that is used to convert from #GSettings to
172  * an object property. The @value is already initialized to hold values
173  * of the appropriate type.
174  */
175 typedef gboolean      (*GSettingsBindGetMapping)                        (GValue             *value,
176                                                                          GVariant           *variant,
177                                                                          gpointer            user_data);
178
179 /**
180  * GSettingsGetMapping:
181  * @value: the #GVariant to map, or %NULL
182  * @result: the result of the mapping
183  * @user_data: the user data that was passed to g_settings_get_mapped()
184  * @returns: %TRUE if the conversion succeeded, %FALSE in case of an error
185  *
186  * The type of the function that is used to convert from a value stored
187  * in a #GSettings to a value that is useful to the application.
188  *
189  * If the value is successfully mapped, the result should be stored at
190  * @result and %TRUE returned.  If mapping fails (for example, if @value
191  * is not in the right format) then %FALSE should be returned.
192  *
193  * If @value is %NULL then it means that the mapping function is being
194  * given a "last chance" to successfully return a valid value.  %TRUE
195  * must be returned in this case.
196  **/
197 typedef gboolean      (*GSettingsGetMapping)                            (GVariant           *value,
198                                                                          gpointer           *result,
199                                                                          gpointer            user_data);
200
201 /**
202  * GSettingsBindFlags:
203  * @G_SETTINGS_BIND_DEFAULT: Equivalent to <literal>G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET</literal>
204  * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
205  *     It is an error to use this flag if the property is not writable.
206  * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
207  *     It is an error to use this flag if the property is not readable.
208  * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
209  * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to #G_SETTINGS_BIND_GET, set the #GObject property
210  *     value initially from the setting, but do not listen for changes of the setting
211  * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
212  *     the boolean value when mapping between the setting and the property.  The setting and property must both
213  *     be booleans.  You can not pass this flag to g_settings_bind_with_mapping().
214  *
215  * Flags used when creating a binding. These flags determine in which
216  * direction the binding works. The default is to synchronize in both
217  * directions.
218  */
219 typedef enum
220 {
221   G_SETTINGS_BIND_DEFAULT,
222   G_SETTINGS_BIND_GET            = (1<<0),
223   G_SETTINGS_BIND_SET            = (1<<1),
224   G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
225   G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
226   G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
227 } GSettingsBindFlags;
228
229 void                    g_settings_bind                                 (GSettings               *settings,
230                                                                          const gchar             *key,
231                                                                          gpointer                 object,
232                                                                          const gchar             *property,
233                                                                          GSettingsBindFlags       flags);
234 void                    g_settings_bind_with_mapping                    (GSettings               *settings,
235                                                                          const gchar             *key,
236                                                                          gpointer                 object,
237                                                                          const gchar             *property,
238                                                                          GSettingsBindFlags       flags,
239                                                                          GSettingsBindGetMapping  get_mapping,
240                                                                          GSettingsBindSetMapping  set_mapping,
241                                                                          gpointer                 user_data,
242                                                                          GDestroyNotify           destroy);
243 void                    g_settings_bind_writable                        (GSettings               *settings,
244                                                                          const gchar             *key,
245                                                                          gpointer                 object,
246                                                                          const gchar             *property,
247                                                                          gboolean                 inverted);
248 void                    g_settings_unbind                               (gpointer                 object,
249                                                                          const gchar             *property);
250
251 gpointer                g_settings_get_mapped                           (GSettings               *settings,
252                                                                          const gchar             *key,
253                                                                          GSettingsGetMapping      mapping,
254                                                                          gpointer                 user_data);
255
256 G_END_DECLS
257
258 #endif  /* __G_SETTINGS_H__ */