Tizen 2.1 base
[platform/upstream/glib2.0.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/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 GType                   g_settings_get_type                             (void);
73
74 const gchar * const *   g_settings_list_schemas                         (void);
75 const gchar * const *   g_settings_list_relocatable_schemas             (void);
76 GSettings *             g_settings_new                                  (const gchar        *schema_id);
77 GSettings *             g_settings_new_with_path                        (const gchar        *schema_id,
78                                                                          const gchar        *path);
79 GSettings *             g_settings_new_with_backend                     (const gchar        *schema_id,
80                                                                          GSettingsBackend   *backend);
81 GSettings *             g_settings_new_with_backend_and_path            (const gchar        *schema_id,
82                                                                          GSettingsBackend   *backend,
83                                                                          const gchar        *path);
84 GSettings *             g_settings_new_full                             (GSettingsSchema    *schema,
85                                                                          GSettingsBackend   *backend,
86                                                                          const gchar        *path);
87 gchar **                g_settings_list_children                        (GSettings          *settings);
88 gchar **                g_settings_list_keys                            (GSettings          *settings);
89 GVariant *              g_settings_get_range                            (GSettings          *settings,
90                                                                          const gchar        *key);
91 gboolean                g_settings_range_check                          (GSettings          *settings,
92                                                                          const gchar        *key,
93                                                                          GVariant           *value);
94
95 gboolean                g_settings_set_value                            (GSettings          *settings,
96                                                                          const gchar        *key,
97                                                                          GVariant           *value);
98 GVariant *              g_settings_get_value                            (GSettings          *settings,
99                                                                          const gchar        *key);
100
101 gboolean                g_settings_set                                  (GSettings          *settings,
102                                                                          const gchar        *key,
103                                                                          const gchar        *format,
104                                                                          ...);
105 void                    g_settings_get                                  (GSettings          *settings,
106                                                                          const gchar        *key,
107                                                                          const gchar        *format,
108                                                                          ...);
109 void                    g_settings_reset                                (GSettings          *settings,
110                                                                          const gchar        *key);
111
112 gint                    g_settings_get_int                              (GSettings          *settings,
113                                                                          const gchar        *key);
114 gboolean                g_settings_set_int                              (GSettings          *settings,
115                                                                          const gchar        *key,
116                                                                          gint                value);
117 guint                   g_settings_get_uint                             (GSettings          *settings,
118                                                                          const gchar        *key);
119 gboolean                g_settings_set_uint                             (GSettings          *settings,
120                                                                          const gchar        *key,
121                                                                          guint               value);
122 gchar *                 g_settings_get_string                           (GSettings          *settings,
123                                                                          const gchar        *key);
124 gboolean                g_settings_set_string                           (GSettings          *settings,
125                                                                          const gchar        *key,
126                                                                          const gchar        *value);
127 gboolean                g_settings_get_boolean                          (GSettings          *settings,
128                                                                          const gchar        *key);
129 gboolean                g_settings_set_boolean                          (GSettings          *settings,
130                                                                          const gchar        *key,
131                                                                          gboolean            value);
132 gdouble                 g_settings_get_double                           (GSettings          *settings,
133                                                                          const gchar        *key);
134 gboolean                g_settings_set_double                           (GSettings          *settings,
135                                                                          const gchar        *key,
136                                                                          gdouble             value);
137 gchar **                g_settings_get_strv                             (GSettings          *settings,
138                                                                          const gchar        *key);
139 gboolean                g_settings_set_strv                             (GSettings          *settings,
140                                                                          const gchar        *key,
141                                                                          const gchar *const *value);
142 gint                    g_settings_get_enum                             (GSettings          *settings,
143                                                                          const gchar        *key);
144 gboolean                g_settings_set_enum                             (GSettings          *settings,
145                                                                          const gchar        *key,
146                                                                          gint                value);
147 guint                   g_settings_get_flags                            (GSettings          *settings,
148                                                                          const gchar        *key);
149 gboolean                g_settings_set_flags                            (GSettings          *settings,
150                                                                          const gchar        *key,
151                                                                          guint               value);
152 GSettings *             g_settings_get_child                            (GSettings          *settings,
153                                                                          const gchar        *name);
154
155 gboolean                g_settings_is_writable                          (GSettings          *settings,
156                                                                          const gchar        *name);
157
158 void                    g_settings_delay                                (GSettings          *settings);
159 void                    g_settings_apply                                (GSettings          *settings);
160 void                    g_settings_revert                               (GSettings          *settings);
161 gboolean                g_settings_get_has_unapplied                    (GSettings          *settings);
162 void                    g_settings_sync                                 (void);
163
164 /**
165  * GSettingsBindSetMapping:
166  * @value: a #GValue containing the property value to map
167  * @expected_type: the #GVariantType to create
168  * @user_data: user data that was specified when the binding was created
169  *
170  * The type for the function that is used to convert an object property
171  * value to a #GVariant for storing it in #GSettings.
172  *
173  * Returns: a new #GVariant holding the data from @value,
174  *     or %NULL in case of an error
175  */
176 typedef GVariant *    (*GSettingsBindSetMapping)                        (const GValue       *value,
177                                                                          const GVariantType *expected_type,
178                                                                          gpointer            user_data);
179
180 /**
181  * GSettingsBindGetMapping:
182  * @value: return location for the property value
183  * @variant: the #GVariant
184  * @user_data: user data that was specified when the binding was created
185  *
186  * The type for the function that is used to convert from #GSettings to
187  * an object property. The @value is already initialized to hold values
188  * of the appropriate type.
189  *
190  * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
191  */
192 typedef gboolean      (*GSettingsBindGetMapping)                        (GValue             *value,
193                                                                          GVariant           *variant,
194                                                                          gpointer            user_data);
195
196 /**
197  * GSettingsGetMapping:
198  * @value: the #GVariant to map, or %NULL
199  * @result: (out): the result of the mapping
200  * @user_data: (closure): the user data that was passed to
201  * g_settings_get_mapped()
202  *
203  * The type of the function that is used to convert from a value stored
204  * in a #GSettings to a value that is useful to the application.
205  *
206  * If the value is successfully mapped, the result should be stored at
207  * @result and %TRUE returned.  If mapping fails (for example, if @value
208  * is not in the right format) then %FALSE should be returned.
209  *
210  * If @value is %NULL then it means that the mapping function is being
211  * given a "last chance" to successfully return a valid value.  %TRUE
212  * must be returned in this case.
213  *
214  * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
215  **/
216 typedef gboolean      (*GSettingsGetMapping)                            (GVariant           *value,
217                                                                          gpointer           *result,
218                                                                          gpointer            user_data);
219
220 /**
221  * GSettingsBindFlags:
222  * @G_SETTINGS_BIND_DEFAULT: Equivalent to <literal>G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET</literal>
223  * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
224  *     It is an error to use this flag if the property is not writable.
225  * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
226  *     It is an error to use this flag if the property is not readable.
227  * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
228  * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to #G_SETTINGS_BIND_GET, set the #GObject property
229  *     value initially from the setting, but do not listen for changes of the setting
230  * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
231  *     the boolean value when mapping between the setting and the property.  The setting and property must both
232  *     be booleans.  You cannot pass this flag to g_settings_bind_with_mapping().
233  *
234  * Flags used when creating a binding. These flags determine in which
235  * direction the binding works. The default is to synchronize in both
236  * directions.
237  */
238 typedef enum
239 {
240   G_SETTINGS_BIND_DEFAULT,
241   G_SETTINGS_BIND_GET            = (1<<0),
242   G_SETTINGS_BIND_SET            = (1<<1),
243   G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
244   G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
245   G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
246 } GSettingsBindFlags;
247
248 void                    g_settings_bind                                 (GSettings               *settings,
249                                                                          const gchar             *key,
250                                                                          gpointer                 object,
251                                                                          const gchar             *property,
252                                                                          GSettingsBindFlags       flags);
253 void                    g_settings_bind_with_mapping                    (GSettings               *settings,
254                                                                          const gchar             *key,
255                                                                          gpointer                 object,
256                                                                          const gchar             *property,
257                                                                          GSettingsBindFlags       flags,
258                                                                          GSettingsBindGetMapping  get_mapping,
259                                                                          GSettingsBindSetMapping  set_mapping,
260                                                                          gpointer                 user_data,
261                                                                          GDestroyNotify           destroy);
262 void                    g_settings_bind_writable                        (GSettings               *settings,
263                                                                          const gchar             *key,
264                                                                          gpointer                 object,
265                                                                          const gchar             *property,
266                                                                          gboolean                 inverted);
267 void                    g_settings_unbind                               (gpointer                 object,
268                                                                          const gchar             *property);
269
270 GAction *               g_settings_create_action                        (GSettings               *settings,
271                                                                          const gchar             *key);
272
273 gpointer                g_settings_get_mapped                           (GSettings               *settings,
274                                                                          const gchar             *key,
275                                                                          GSettingsGetMapping      mapping,
276                                                                          gpointer                 user_data);
277
278 G_END_DECLS
279
280 #endif  /* __G_SETTINGS_H__ */