Add single-include guards to new headers
[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 <glib-object.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 typedef struct _GSettings                                   GSettings;
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 GSettings *             g_settings_new                                  (const gchar        *schema);
75 GSettings *             g_settings_new_with_path                        (const gchar        *schema,
76                                                                          const gchar        *path);
77 gboolean                g_settings_supports_context                     (const gchar        *context);
78 GSettings *             g_settings_new_with_context                     (const gchar        *schema,
79                                                                          const gchar        *context);
80 GSettings *             g_settings_new_with_context_and_path            (const gchar        *schema,
81                                                                          const gchar        *context,
82                                                                          const gchar        *path);
83
84 gboolean                g_settings_set_value                            (GSettings          *settings,
85                                                                          const gchar        *key,
86                                                                          GVariant           *value);
87 GVariant *              g_settings_get_value                            (GSettings          *settings,
88                                                                          const gchar        *key);
89
90 gboolean                g_settings_set                                  (GSettings          *settings,
91                                                                          const gchar        *key,
92                                                                          const gchar        *format,
93                                                                          ...);
94 void                    g_settings_get                                  (GSettings          *settings,
95                                                                          const gchar        *key,
96                                                                          const gchar        *format,
97                                                                          ...);
98
99 gint                    g_settings_get_int                              (GSettings          *settings,
100                                                                          const gchar        *key);
101 gboolean                g_settings_set_int                              (GSettings          *settings,
102                                                                          const gchar        *key,
103                                                                          gint                value);
104 gchar *                 g_settings_get_string                           (GSettings          *settings,
105                                                                          const gchar        *key);
106 gboolean                g_settings_set_string                           (GSettings          *settings,
107                                                                          const gchar        *key,
108                                                                          const gchar        *value);
109 gboolean                g_settings_get_boolean                          (GSettings          *settings,
110                                                                          const gchar        *key);
111 gboolean                g_settings_set_boolean                          (GSettings          *settings,
112                                                                          const gchar        *key,
113                                                                          gboolean            value);
114 gdouble                 g_settings_get_double                           (GSettings          *settings,
115                                                                          const gchar        *key);
116 gboolean                g_settings_set_double                           (GSettings          *settings,
117                                                                          const gchar        *key,
118                                                                          gdouble             value);
119 gchar **                g_settings_get_strv                             (GSettings          *settings,
120                                                                          const gchar        *key);
121 gboolean                g_settings_set_strv                             (GSettings          *settings,
122                                                                          const gchar        *key,
123                                                                          const gchar *const *value);
124
125 GSettings *             g_settings_get_child                            (GSettings          *settings,
126                                                                          const gchar        *name);
127
128 gboolean                g_settings_is_writable                          (GSettings          *settings,
129                                                                          const gchar        *name);
130
131 void                    g_settings_delay                                (GSettings          *settings);
132 void                    g_settings_apply                                (GSettings          *settings);
133 void                    g_settings_revert                               (GSettings          *settings);
134 gboolean                g_settings_get_has_unapplied                    (GSettings          *settings);
135
136 /**
137  * GSettingsBindSetMapping:
138  * @value: a #GValue containing the property value to map
139  * @expected_type: the #GVariantType to create
140  * @user_data: user data that was specified when the binding was created
141  * @returns: a new #GVariant holding the data from @value,
142  *     or %NULL in case of an error
143  *
144  * The type for the function that is used to convert an object property
145  * value to a #GVariant for storing it in #GSettings.
146  */
147 typedef GVariant *    (*GSettingsBindSetMapping)                        (const GValue       *value,
148                                                                          const GVariantType *expected_type,
149                                                                          gpointer            user_data);
150
151 /**
152  * GSettingsBindGetMapping:
153  * @value: return location for the property value
154  * @variant: the #GVariant
155  * @user_data: user data that was specified when the binding was created
156  * @returns: %TRUE if the conversion succeeded, %FALSE in case of an error
157  *
158  * The type for the function that is used to convert from #GSettings to
159  * an object property. The @value is already initialized to hold values
160  * of the appropriate type.
161  */
162 typedef gboolean      (*GSettingsBindGetMapping)                        (GValue             *value,
163                                                                          GVariant           *variant,
164                                                                          gpointer            user_data);
165
166 /**
167  * GSettingsBindFlags:
168  * @G_SETTINGS_BIND_DEFAULT: Equivalent to <literal>G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET</literal>
169  * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
170  *     It is an error to use this flag if the property is not writable.
171  * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
172  *     It is an error to use this flag if the property is not readable.
173  * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
174  * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to #G_SETTINGS_BIND_GET, set the #GObject property
175  *     value initially from the setting, but do not listen for changes of the setting
176  *
177  * Flags used when creating a binding. These flags determine in which
178  * direction the binding works. The default is to synchronize in both
179  * directions.
180  */
181 typedef enum
182 {
183   G_SETTINGS_BIND_DEFAULT,
184   G_SETTINGS_BIND_GET            = (1<<0),
185   G_SETTINGS_BIND_SET            = (1<<1),
186   G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
187   G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3)
188 } GSettingsBindFlags;
189
190 void                    g_settings_bind                                 (GSettings               *settings,
191                                                                          const gchar             *key,
192                                                                          gpointer                 object,
193                                                                          const gchar             *property,
194                                                                          GSettingsBindFlags       flags);
195 void                    g_settings_bind_with_mapping                    (GSettings               *settings,
196                                                                          const gchar             *key,
197                                                                          gpointer                 object,
198                                                                          const gchar             *property,
199                                                                          GSettingsBindFlags       flags,
200                                                                          GSettingsBindGetMapping  get_mapping,
201                                                                          GSettingsBindSetMapping  set_mapping,
202                                                                          gpointer                 user_data,
203                                                                          GDestroyNotify           destroy);
204 void                    g_settings_bind_writable                        (GSettings               *settings,
205                                                                          const gchar             *key,
206                                                                          gpointer                 object,
207                                                                          const gchar             *property,
208                                                                          gboolean                 inverted);
209 void                    g_settings_unbind                               (gpointer                 object,
210                                                                          const gchar             *property);
211
212 G_END_DECLS
213
214 #endif  /* __G_SETTINGS_H__ */