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