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 | |
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 | GIO_AVAILABLE_IN_ALL |
73 | GType g_settings_get_type (void); |
74 | |
75 | GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas) |
76 | const gchar * const * g_settings_list_schemas (void); |
77 | GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas) |
78 | const gchar * const * g_settings_list_relocatable_schemas (void); |
79 | GIO_AVAILABLE_IN_ALL |
80 | GSettings * g_settings_new (const gchar *schema_id); |
81 | GIO_AVAILABLE_IN_ALL |
82 | GSettings * g_settings_new_with_path (const gchar *schema_id, |
83 | const gchar *path); |
84 | GIO_AVAILABLE_IN_ALL |
85 | GSettings * g_settings_new_with_backend (const gchar *schema_id, |
86 | GSettingsBackend *backend); |
87 | GIO_AVAILABLE_IN_ALL |
88 | GSettings * g_settings_new_with_backend_and_path (const gchar *schema_id, |
89 | GSettingsBackend *backend, |
90 | const gchar *path); |
91 | GIO_AVAILABLE_IN_2_32 |
92 | GSettings * g_settings_new_full (GSettingsSchema *schema, |
93 | GSettingsBackend *backend, |
94 | const gchar *path); |
95 | GIO_AVAILABLE_IN_ALL |
96 | gchar ** g_settings_list_children (GSettings *settings); |
97 | GIO_DEPRECATED_IN_2_46_FOR(g_settings_schema_list_keys) |
98 | gchar ** g_settings_list_keys (GSettings *settings); |
99 | GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_get_range) |
100 | GVariant * g_settings_get_range (GSettings *settings, |
101 | const gchar *key); |
102 | GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_range_check) |
103 | gboolean g_settings_range_check (GSettings *settings, |
104 | const gchar *key, |
105 | GVariant *value); |
106 | |
107 | GIO_AVAILABLE_IN_ALL |
108 | gboolean g_settings_set_value (GSettings *settings, |
109 | const gchar *key, |
110 | GVariant *value); |
111 | GIO_AVAILABLE_IN_ALL |
112 | GVariant * g_settings_get_value (GSettings *settings, |
113 | const gchar *key); |
114 | |
115 | GIO_AVAILABLE_IN_2_40 |
116 | GVariant * g_settings_get_user_value (GSettings *settings, |
117 | const gchar *key); |
118 | GIO_AVAILABLE_IN_2_40 |
119 | GVariant * g_settings_get_default_value (GSettings *settings, |
120 | const gchar *key); |
121 | |
122 | GIO_AVAILABLE_IN_ALL |
123 | gboolean g_settings_set (GSettings *settings, |
124 | const gchar *key, |
125 | const gchar *format, |
126 | ...); |
127 | GIO_AVAILABLE_IN_ALL |
128 | void g_settings_get (GSettings *settings, |
129 | const gchar *key, |
130 | const gchar *format, |
131 | ...); |
132 | GIO_AVAILABLE_IN_ALL |
133 | void g_settings_reset (GSettings *settings, |
134 | const gchar *key); |
135 | |
136 | GIO_AVAILABLE_IN_ALL |
137 | gint g_settings_get_int (GSettings *settings, |
138 | const gchar *key); |
139 | GIO_AVAILABLE_IN_ALL |
140 | gboolean g_settings_set_int (GSettings *settings, |
141 | const gchar *key, |
142 | gint value); |
143 | GIO_AVAILABLE_IN_2_50 |
144 | gint64 g_settings_get_int64 (GSettings *settings, |
145 | const gchar *key); |
146 | GIO_AVAILABLE_IN_2_50 |
147 | gboolean g_settings_set_int64 (GSettings *settings, |
148 | const gchar *key, |
149 | gint64 value); |
150 | GIO_AVAILABLE_IN_2_32 |
151 | guint g_settings_get_uint (GSettings *settings, |
152 | const gchar *key); |
153 | GIO_AVAILABLE_IN_2_32 |
154 | gboolean g_settings_set_uint (GSettings *settings, |
155 | const gchar *key, |
156 | guint value); |
157 | GIO_AVAILABLE_IN_2_50 |
158 | guint64 g_settings_get_uint64 (GSettings *settings, |
159 | const gchar *key); |
160 | GIO_AVAILABLE_IN_2_50 |
161 | gboolean g_settings_set_uint64 (GSettings *settings, |
162 | const gchar *key, |
163 | guint64 value); |
164 | GIO_AVAILABLE_IN_ALL |
165 | gchar * g_settings_get_string (GSettings *settings, |
166 | const gchar *key); |
167 | GIO_AVAILABLE_IN_ALL |
168 | gboolean g_settings_set_string (GSettings *settings, |
169 | const gchar *key, |
170 | const gchar *value); |
171 | GIO_AVAILABLE_IN_ALL |
172 | gboolean g_settings_get_boolean (GSettings *settings, |
173 | const gchar *key); |
174 | GIO_AVAILABLE_IN_ALL |
175 | gboolean g_settings_set_boolean (GSettings *settings, |
176 | const gchar *key, |
177 | gboolean value); |
178 | GIO_AVAILABLE_IN_ALL |
179 | gdouble g_settings_get_double (GSettings *settings, |
180 | const gchar *key); |
181 | GIO_AVAILABLE_IN_ALL |
182 | gboolean g_settings_set_double (GSettings *settings, |
183 | const gchar *key, |
184 | gdouble value); |
185 | GIO_AVAILABLE_IN_ALL |
186 | gchar ** g_settings_get_strv (GSettings *settings, |
187 | const gchar *key); |
188 | GIO_AVAILABLE_IN_ALL |
189 | gboolean g_settings_set_strv (GSettings *settings, |
190 | const gchar *key, |
191 | const gchar *const *value); |
192 | GIO_AVAILABLE_IN_ALL |
193 | gint g_settings_get_enum (GSettings *settings, |
194 | const gchar *key); |
195 | GIO_AVAILABLE_IN_ALL |
196 | gboolean g_settings_set_enum (GSettings *settings, |
197 | const gchar *key, |
198 | gint value); |
199 | GIO_AVAILABLE_IN_ALL |
200 | guint g_settings_get_flags (GSettings *settings, |
201 | const gchar *key); |
202 | GIO_AVAILABLE_IN_ALL |
203 | gboolean g_settings_set_flags (GSettings *settings, |
204 | const gchar *key, |
205 | guint value); |
206 | GIO_AVAILABLE_IN_ALL |
207 | GSettings * g_settings_get_child (GSettings *settings, |
208 | const gchar *name); |
209 | |
210 | GIO_AVAILABLE_IN_ALL |
211 | gboolean g_settings_is_writable (GSettings *settings, |
212 | const gchar *name); |
213 | |
214 | GIO_AVAILABLE_IN_ALL |
215 | void g_settings_delay (GSettings *settings); |
216 | GIO_AVAILABLE_IN_ALL |
217 | void g_settings_apply (GSettings *settings); |
218 | GIO_AVAILABLE_IN_ALL |
219 | void g_settings_revert (GSettings *settings); |
220 | GIO_AVAILABLE_IN_ALL |
221 | gboolean g_settings_get_has_unapplied (GSettings *settings); |
222 | GIO_AVAILABLE_IN_ALL |
223 | void 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 | */ |
237 | typedef 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 | */ |
253 | typedef 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 | **/ |
277 | typedef 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 | */ |
299 | typedef 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 | |
309 | GIO_AVAILABLE_IN_ALL |
310 | void g_settings_bind (GSettings *settings, |
311 | const gchar *key, |
312 | gpointer object, |
313 | const gchar *property, |
314 | GSettingsBindFlags flags); |
315 | GIO_AVAILABLE_IN_ALL |
316 | void 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); |
325 | GIO_AVAILABLE_IN_ALL |
326 | void g_settings_bind_writable (GSettings *settings, |
327 | const gchar *key, |
328 | gpointer object, |
329 | const gchar *property, |
330 | gboolean inverted); |
331 | GIO_AVAILABLE_IN_ALL |
332 | void g_settings_unbind (gpointer object, |
333 | const gchar *property); |
334 | |
335 | GIO_AVAILABLE_IN_2_32 |
336 | GAction * g_settings_create_action (GSettings *settings, |
337 | const gchar *key); |
338 | |
339 | GIO_AVAILABLE_IN_ALL |
340 | gpointer g_settings_get_mapped (GSettings *settings, |
341 | const gchar *key, |
342 | GSettingsGetMapping mapping, |
343 | gpointer user_data); |
344 | |
345 | G_END_DECLS |
346 | |
347 | #endif /* __G_SETTINGS_H__ */ |
348 | |