Improvde #include order consistency
[glib.git] / gio / gsettings.h
blob918c932144ce86f24d99e02ac7772ce1968773ce
1 /*
2 * Copyright © 2009, 2010 Codethink Limited
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.
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.
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.
19 * Author: Ryan Lortie <desrt@desrt.ca>
22 #ifndef __G_SETTINGS_H__
23 #define __G_SETTINGS_H__
25 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
26 #error "Only <gio/gio.h> can be included directly."
27 #endif
29 #include <gio/gsettingsschema.h>
30 #include <gio/giotypes.h>
32 G_BEGIN_DECLS
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))
44 typedef struct _GSettingsPrivate GSettingsPrivate;
45 typedef struct _GSettingsClass GSettingsClass;
47 struct _GSettingsClass
49 GObjectClass parent_class;
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);
62 gpointer padding[20];
65 struct _GSettings
67 GObject parent_instance;
68 GSettingsPrivate *priv;
72 GType g_settings_get_type (void);
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 GLIB_AVAILABLE_IN_2_32
85 GSettings * g_settings_new_full (GSettingsSchema *schema,
86 GSettingsBackend *backend,
87 const gchar *path);
88 gchar ** g_settings_list_children (GSettings *settings);
89 gchar ** g_settings_list_keys (GSettings *settings);
90 GVariant * g_settings_get_range (GSettings *settings,
91 const gchar *key);
92 gboolean g_settings_range_check (GSettings *settings,
93 const gchar *key,
94 GVariant *value);
96 gboolean g_settings_set_value (GSettings *settings,
97 const gchar *key,
98 GVariant *value);
99 GVariant * g_settings_get_value (GSettings *settings,
100 const gchar *key);
102 gboolean g_settings_set (GSettings *settings,
103 const gchar *key,
104 const gchar *format,
105 ...);
106 void g_settings_get (GSettings *settings,
107 const gchar *key,
108 const gchar *format,
109 ...);
110 void g_settings_reset (GSettings *settings,
111 const gchar *key);
113 gint g_settings_get_int (GSettings *settings,
114 const gchar *key);
115 gboolean g_settings_set_int (GSettings *settings,
116 const gchar *key,
117 gint value);
118 guint g_settings_get_uint (GSettings *settings,
119 const gchar *key);
120 gboolean g_settings_set_uint (GSettings *settings,
121 const gchar *key,
122 guint value);
123 gchar * g_settings_get_string (GSettings *settings,
124 const gchar *key);
125 gboolean g_settings_set_string (GSettings *settings,
126 const gchar *key,
127 const gchar *value);
128 gboolean g_settings_get_boolean (GSettings *settings,
129 const gchar *key);
130 gboolean g_settings_set_boolean (GSettings *settings,
131 const gchar *key,
132 gboolean value);
133 gdouble g_settings_get_double (GSettings *settings,
134 const gchar *key);
135 gboolean g_settings_set_double (GSettings *settings,
136 const gchar *key,
137 gdouble value);
138 gchar ** g_settings_get_strv (GSettings *settings,
139 const gchar *key);
140 gboolean g_settings_set_strv (GSettings *settings,
141 const gchar *key,
142 const gchar *const *value);
143 gint g_settings_get_enum (GSettings *settings,
144 const gchar *key);
145 gboolean g_settings_set_enum (GSettings *settings,
146 const gchar *key,
147 gint value);
148 guint g_settings_get_flags (GSettings *settings,
149 const gchar *key);
150 gboolean g_settings_set_flags (GSettings *settings,
151 const gchar *key,
152 guint value);
153 GSettings * g_settings_get_child (GSettings *settings,
154 const gchar *name);
156 gboolean g_settings_is_writable (GSettings *settings,
157 const gchar *name);
159 void g_settings_delay (GSettings *settings);
160 void g_settings_apply (GSettings *settings);
161 void g_settings_revert (GSettings *settings);
162 gboolean g_settings_get_has_unapplied (GSettings *settings);
163 void g_settings_sync (void);
166 * GSettingsBindSetMapping:
167 * @value: a #GValue containing the property value to map
168 * @expected_type: the #GVariantType to create
169 * @user_data: user data that was specified when the binding was created
171 * The type for the function that is used to convert an object property
172 * value to a #GVariant for storing it in #GSettings.
174 * Returns: a new #GVariant holding the data from @value,
175 * or %NULL in case of an error
177 typedef GVariant * (*GSettingsBindSetMapping) (const GValue *value,
178 const GVariantType *expected_type,
179 gpointer user_data);
182 * GSettingsBindGetMapping:
183 * @value: return location for the property value
184 * @variant: the #GVariant
185 * @user_data: user data that was specified when the binding was created
187 * The type for the function that is used to convert from #GSettings to
188 * an object property. The @value is already initialized to hold values
189 * of the appropriate type.
191 * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
193 typedef gboolean (*GSettingsBindGetMapping) (GValue *value,
194 GVariant *variant,
195 gpointer user_data);
198 * GSettingsGetMapping:
199 * @value: the #GVariant to map, or %NULL
200 * @result: (out): the result of the mapping
201 * @user_data: (closure): the user data that was passed to
202 * g_settings_get_mapped()
204 * The type of the function that is used to convert from a value stored
205 * in a #GSettings to a value that is useful to the application.
207 * If the value is successfully mapped, the result should be stored at
208 * @result and %TRUE returned. If mapping fails (for example, if @value
209 * is not in the right format) then %FALSE should be returned.
211 * If @value is %NULL then it means that the mapping function is being
212 * given a "last chance" to successfully return a valid value. %TRUE
213 * must be returned in this case.
215 * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
217 typedef gboolean (*GSettingsGetMapping) (GVariant *value,
218 gpointer *result,
219 gpointer user_data);
222 * GSettingsBindFlags:
223 * @G_SETTINGS_BIND_DEFAULT: Equivalent to <literal>G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET</literal>
224 * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
225 * It is an error to use this flag if the property is not writable.
226 * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
227 * It is an error to use this flag if the property is not readable.
228 * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
229 * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to #G_SETTINGS_BIND_GET, set the #GObject property
230 * value initially from the setting, but do not listen for changes of the setting
231 * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
232 * the boolean value when mapping between the setting and the property. The setting and property must both
233 * be booleans. You cannot pass this flag to g_settings_bind_with_mapping().
235 * Flags used when creating a binding. These flags determine in which
236 * direction the binding works. The default is to synchronize in both
237 * directions.
239 typedef enum
241 G_SETTINGS_BIND_DEFAULT,
242 G_SETTINGS_BIND_GET = (1<<0),
243 G_SETTINGS_BIND_SET = (1<<1),
244 G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
245 G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
246 G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
247 } GSettingsBindFlags;
249 void g_settings_bind (GSettings *settings,
250 const gchar *key,
251 gpointer object,
252 const gchar *property,
253 GSettingsBindFlags flags);
254 void g_settings_bind_with_mapping (GSettings *settings,
255 const gchar *key,
256 gpointer object,
257 const gchar *property,
258 GSettingsBindFlags flags,
259 GSettingsBindGetMapping get_mapping,
260 GSettingsBindSetMapping set_mapping,
261 gpointer user_data,
262 GDestroyNotify destroy);
263 void g_settings_bind_writable (GSettings *settings,
264 const gchar *key,
265 gpointer object,
266 const gchar *property,
267 gboolean inverted);
268 void g_settings_unbind (gpointer object,
269 const gchar *property);
271 GLIB_AVAILABLE_IN_2_32
272 GAction * g_settings_create_action (GSettings *settings,
273 const gchar *key);
275 gpointer g_settings_get_mapped (GSettings *settings,
276 const gchar *key,
277 GSettingsGetMapping mapping,
278 gpointer user_data);
280 G_END_DECLS
282 #endif /* __G_SETTINGS_H__ */