1/*
2 * Copyright © 2009, 2010 Codethink Limited
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Ryan Lortie <desrt@desrt.ca>
20 */
21
22#ifndef __G_SETTINGS_H__
23#define __G_SETTINGS_H__
24
25#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
26#error "Only <gio/gio.h> can be included directly."
27#endif
28
29#include <gio/gsettingsschema.h>
30#include <gio/giotypes.h>
31
32G_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
44typedef struct _GSettingsPrivate GSettingsPrivate;
45typedef struct _GSettingsClass GSettingsClass;
46
47struct _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
65struct _GSettings
66{
67 GObject parent_instance;
68 GSettingsPrivate *priv;
69};
70
71
72GIO_AVAILABLE_IN_ALL
73GType g_settings_get_type (void);
74
75GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas)
76const gchar * const * g_settings_list_schemas (void);
77GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas)
78const gchar * const * g_settings_list_relocatable_schemas (void);
79GIO_AVAILABLE_IN_ALL
80GSettings * g_settings_new (const gchar *schema_id);
81GIO_AVAILABLE_IN_ALL
82GSettings * g_settings_new_with_path (const gchar *schema_id,
83 const gchar *path);
84GIO_AVAILABLE_IN_ALL
85GSettings * g_settings_new_with_backend (const gchar *schema_id,
86 GSettingsBackend *backend);
87GIO_AVAILABLE_IN_ALL
88GSettings * g_settings_new_with_backend_and_path (const gchar *schema_id,
89 GSettingsBackend *backend,
90 const gchar *path);
91GIO_AVAILABLE_IN_2_32
92GSettings * g_settings_new_full (GSettingsSchema *schema,
93 GSettingsBackend *backend,
94 const gchar *path);
95GIO_AVAILABLE_IN_ALL
96gchar ** g_settings_list_children (GSettings *settings);
97GIO_DEPRECATED_IN_2_46_FOR(g_settings_schema_list_keys)
98gchar ** g_settings_list_keys (GSettings *settings);
99GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_get_range)
100GVariant * g_settings_get_range (GSettings *settings,
101 const gchar *key);
102GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_range_check)
103gboolean g_settings_range_check (GSettings *settings,
104 const gchar *key,
105 GVariant *value);
106
107GIO_AVAILABLE_IN_ALL
108gboolean g_settings_set_value (GSettings *settings,
109 const gchar *key,
110 GVariant *value);
111GIO_AVAILABLE_IN_ALL
112GVariant * g_settings_get_value (GSettings *settings,
113 const gchar *key);
114
115GIO_AVAILABLE_IN_2_40
116GVariant * g_settings_get_user_value (GSettings *settings,
117 const gchar *key);
118GIO_AVAILABLE_IN_2_40
119GVariant * g_settings_get_default_value (GSettings *settings,
120 const gchar *key);
121
122GIO_AVAILABLE_IN_ALL
123gboolean g_settings_set (GSettings *settings,
124 const gchar *key,
125 const gchar *format,
126 ...);
127GIO_AVAILABLE_IN_ALL
128void g_settings_get (GSettings *settings,
129 const gchar *key,
130 const gchar *format,
131 ...);
132GIO_AVAILABLE_IN_ALL
133void g_settings_reset (GSettings *settings,
134 const gchar *key);
135
136GIO_AVAILABLE_IN_ALL
137gint g_settings_get_int (GSettings *settings,
138 const gchar *key);
139GIO_AVAILABLE_IN_ALL
140gboolean g_settings_set_int (GSettings *settings,
141 const gchar *key,
142 gint value);
143GIO_AVAILABLE_IN_2_50
144gint64 g_settings_get_int64 (GSettings *settings,
145 const gchar *key);
146GIO_AVAILABLE_IN_2_50
147gboolean g_settings_set_int64 (GSettings *settings,
148 const gchar *key,
149 gint64 value);
150GIO_AVAILABLE_IN_2_32
151guint g_settings_get_uint (GSettings *settings,
152 const gchar *key);
153GIO_AVAILABLE_IN_2_32
154gboolean g_settings_set_uint (GSettings *settings,
155 const gchar *key,
156 guint value);
157GIO_AVAILABLE_IN_2_50
158guint64 g_settings_get_uint64 (GSettings *settings,
159 const gchar *key);
160GIO_AVAILABLE_IN_2_50
161gboolean g_settings_set_uint64 (GSettings *settings,
162 const gchar *key,
163 guint64 value);
164GIO_AVAILABLE_IN_ALL
165gchar * g_settings_get_string (GSettings *settings,
166 const gchar *key);
167GIO_AVAILABLE_IN_ALL
168gboolean g_settings_set_string (GSettings *settings,
169 const gchar *key,
170 const gchar *value);
171GIO_AVAILABLE_IN_ALL
172gboolean g_settings_get_boolean (GSettings *settings,
173 const gchar *key);
174GIO_AVAILABLE_IN_ALL
175gboolean g_settings_set_boolean (GSettings *settings,
176 const gchar *key,
177 gboolean value);
178GIO_AVAILABLE_IN_ALL
179gdouble g_settings_get_double (GSettings *settings,
180 const gchar *key);
181GIO_AVAILABLE_IN_ALL
182gboolean g_settings_set_double (GSettings *settings,
183 const gchar *key,
184 gdouble value);
185GIO_AVAILABLE_IN_ALL
186gchar ** g_settings_get_strv (GSettings *settings,
187 const gchar *key);
188GIO_AVAILABLE_IN_ALL
189gboolean g_settings_set_strv (GSettings *settings,
190 const gchar *key,
191 const gchar *const *value);
192GIO_AVAILABLE_IN_ALL
193gint g_settings_get_enum (GSettings *settings,
194 const gchar *key);
195GIO_AVAILABLE_IN_ALL
196gboolean g_settings_set_enum (GSettings *settings,
197 const gchar *key,
198 gint value);
199GIO_AVAILABLE_IN_ALL
200guint g_settings_get_flags (GSettings *settings,
201 const gchar *key);
202GIO_AVAILABLE_IN_ALL
203gboolean g_settings_set_flags (GSettings *settings,
204 const gchar *key,
205 guint value);
206GIO_AVAILABLE_IN_ALL
207GSettings * g_settings_get_child (GSettings *settings,
208 const gchar *name);
209
210GIO_AVAILABLE_IN_ALL
211gboolean g_settings_is_writable (GSettings *settings,
212 const gchar *name);
213
214GIO_AVAILABLE_IN_ALL
215void g_settings_delay (GSettings *settings);
216GIO_AVAILABLE_IN_ALL
217void g_settings_apply (GSettings *settings);
218GIO_AVAILABLE_IN_ALL
219void g_settings_revert (GSettings *settings);
220GIO_AVAILABLE_IN_ALL
221gboolean g_settings_get_has_unapplied (GSettings *settings);
222GIO_AVAILABLE_IN_ALL
223void g_settings_sync (void);
224
225/**
226 * GSettingsBindSetMapping:
227 * @value: a #GValue containing the property value to map
228 * @expected_type: the #GVariantType to create
229 * @user_data: user data that was specified when the binding was created
230 *
231 * The type for the function that is used to convert an object property
232 * value to a #GVariant for storing it in #GSettings.
233 *
234 * Returns: a new #GVariant holding the data from @value,
235 * or %NULL in case of an error
236 */
237typedef GVariant * (*GSettingsBindSetMapping) (const GValue *value,
238 const GVariantType *expected_type,
239 gpointer user_data);
240
241/**
242 * GSettingsBindGetMapping:
243 * @value: return location for the property value
244 * @variant: the #GVariant
245 * @user_data: user data that was specified when the binding was created
246 *
247 * The type for the function that is used to convert from #GSettings to
248 * an object property. The @value is already initialized to hold values
249 * of the appropriate type.
250 *
251 * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
252 */
253typedef gboolean (*GSettingsBindGetMapping) (GValue *value,
254 GVariant *variant,
255 gpointer user_data);
256
257/**
258 * GSettingsGetMapping:
259 * @value: the #GVariant to map, or %NULL
260 * @result: (out): the result of the mapping
261 * @user_data: (closure): the user data that was passed to
262 * g_settings_get_mapped()
263 *
264 * The type of the function that is used to convert from a value stored
265 * in a #GSettings to a value that is useful to the application.
266 *
267 * If the value is successfully mapped, the result should be stored at
268 * @result and %TRUE returned. If mapping fails (for example, if @value
269 * is not in the right format) then %FALSE should be returned.
270 *
271 * If @value is %NULL then it means that the mapping function is being
272 * given a "last chance" to successfully return a valid value. %TRUE
273 * must be returned in this case.
274 *
275 * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
276 **/
277typedef gboolean (*GSettingsGetMapping) (GVariant *value,
278 gpointer *result,
279 gpointer user_data);
280
281/**
282 * GSettingsBindFlags:
283 * @G_SETTINGS_BIND_DEFAULT: Equivalent to `G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET`
284 * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
285 * It is an error to use this flag if the property is not writable.
286 * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
287 * It is an error to use this flag if the property is not readable.
288 * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
289 * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to %G_SETTINGS_BIND_GET, set the #GObject property
290 * value initially from the setting, but do not listen for changes of the setting
291 * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
292 * the boolean value when mapping between the setting and the property. The setting and property must both
293 * be booleans. You cannot pass this flag to g_settings_bind_with_mapping().
294 *
295 * Flags used when creating a binding. These flags determine in which
296 * direction the binding works. The default is to synchronize in both
297 * directions.
298 */
299typedef enum
300{
301 G_SETTINGS_BIND_DEFAULT,
302 G_SETTINGS_BIND_GET = (1<<0),
303 G_SETTINGS_BIND_SET = (1<<1),
304 G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
305 G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
306 G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
307} GSettingsBindFlags;
308
309GIO_AVAILABLE_IN_ALL
310void g_settings_bind (GSettings *settings,
311 const gchar *key,
312 gpointer object,
313 const gchar *property,
314 GSettingsBindFlags flags);
315GIO_AVAILABLE_IN_ALL
316void g_settings_bind_with_mapping (GSettings *settings,
317 const gchar *key,
318 gpointer object,
319 const gchar *property,
320 GSettingsBindFlags flags,
321 GSettingsBindGetMapping get_mapping,
322 GSettingsBindSetMapping set_mapping,
323 gpointer user_data,
324 GDestroyNotify destroy);
325GIO_AVAILABLE_IN_ALL
326void g_settings_bind_writable (GSettings *settings,
327 const gchar *key,
328 gpointer object,
329 const gchar *property,
330 gboolean inverted);
331GIO_AVAILABLE_IN_ALL
332void g_settings_unbind (gpointer object,
333 const gchar *property);
334
335GIO_AVAILABLE_IN_2_32
336GAction * g_settings_create_action (GSettings *settings,
337 const gchar *key);
338
339GIO_AVAILABLE_IN_ALL
340gpointer g_settings_get_mapped (GSettings *settings,
341 const gchar *key,
342 GSettingsGetMapping mapping,
343 gpointer user_data);
344
345G_END_DECLS
346
347#endif /* __G_SETTINGS_H__ */
348