1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.SettingsBackend;
26 
27 private import gio.c.functions;
28 public  import gio.c.types;
29 private import glib.BBTree;
30 private import glib.Str;
31 private import glib.Variant;
32 private import glib.c.functions;
33 private import gobject.ObjectG;
34 
35 
36 /**
37  * The #GSettingsBackend interface defines a generic interface for
38  * non-strictly-typed data that is stored in a hierarchy. To implement
39  * an alternative storage backend for #GSettings, you need to implement
40  * the #GSettingsBackend interface and then make it implement the
41  * extension point #G_SETTINGS_BACKEND_EXTENSION_POINT_NAME.
42  * 
43  * The interface defines methods for reading and writing values, a
44  * method for determining if writing of certain values will fail
45  * (lockdown) and a change notification mechanism.
46  * 
47  * The semantics of the interface are very precisely defined and
48  * implementations must carefully adhere to the expectations of
49  * callers that are documented on each of the interface methods.
50  * 
51  * Some of the #GSettingsBackend functions accept or return a #GTree.
52  * These trees always have strings as keys and #GVariant as values.
53  * g_settings_backend_create_tree() is a convenience function to create
54  * suitable trees.
55  * 
56  * The #GSettingsBackend API is exported to allow third-party
57  * implementations, but does not carry the same stability guarantees
58  * as the public GIO API. For this reason, you have to define the
59  * C preprocessor symbol %G_SETTINGS_ENABLE_BACKEND before including
60  * `gio/gsettingsbackend.h`.
61  */
62 public class SettingsBackend : ObjectG
63 {
64 	/** the main Gtk struct */
65 	protected GSettingsBackend* gSettingsBackend;
66 
67 	/** Get the main Gtk struct */
68 	public GSettingsBackend* getSettingsBackendStruct(bool transferOwnership = false)
69 	{
70 		if (transferOwnership)
71 			ownedRef = false;
72 		return gSettingsBackend;
73 	}
74 
75 	/** the main Gtk struct as a void* */
76 	protected override void* getStruct()
77 	{
78 		return cast(void*)gSettingsBackend;
79 	}
80 
81 	/**
82 	 * Sets our main struct and passes it to the parent class.
83 	 */
84 	public this (GSettingsBackend* gSettingsBackend, bool ownedRef = false)
85 	{
86 		this.gSettingsBackend = gSettingsBackend;
87 		super(cast(GObject*)gSettingsBackend, ownedRef);
88 	}
89 
90 
91 	/** */
92 	public static GType getType()
93 	{
94 		return g_settings_backend_get_type();
95 	}
96 
97 	/**
98 	 * Calculate the longest common prefix of all keys in a tree and write
99 	 * out an array of the key names relative to that prefix and,
100 	 * optionally, the value to store at each of those keys.
101 	 *
102 	 * You must free the value returned in @path, @keys and @values using
103 	 * g_free().  You should not attempt to free or unref the contents of
104 	 * @keys or @values.
105 	 *
106 	 * Params:
107 	 *     tree = a #GTree containing the changes
108 	 *     path = the location to save the path
109 	 *     keys = the
110 	 *         location to save the relative keys
111 	 *     values = the location to save the values, or %NULL
112 	 *
113 	 * Since: 2.26
114 	 */
115 	public static void flattenTree(BBTree tree, out string path, out string[] keys, out Variant[] values)
116 	{
117 		char* outpath = null;
118 		char** outkeys = null;
119 		GVariant** outvalues = null;
120 
121 		g_settings_backend_flatten_tree((tree is null) ? null : tree.getBBTreeStruct(), &outpath, &outkeys, &outvalues);
122 
123 		path = Str.toString(outpath);
124 		keys = Str.toStringArray(outkeys);
125 
126 		values = new Variant[getArrayLength(outvalues)];
127 		for(size_t i = 0; i < getArrayLength(outvalues); i++)
128 		{
129 			values[i] = new Variant(cast(GVariant*) outvalues[i]);
130 		}
131 	}
132 
133 	/**
134 	 * Returns the default #GSettingsBackend. It is possible to override
135 	 * the default by setting the `GSETTINGS_BACKEND` environment variable
136 	 * to the name of a settings backend.
137 	 *
138 	 * The user gets a reference to the backend.
139 	 *
140 	 * Returns: the default #GSettingsBackend,
141 	 *     which will be a dummy (memory) settings backend if no other settings
142 	 *     backend is available.
143 	 *
144 	 * Since: 2.28
145 	 */
146 	public static SettingsBackend getDefault()
147 	{
148 		auto __p = g_settings_backend_get_default();
149 
150 		if(__p is null)
151 		{
152 			return null;
153 		}
154 
155 		return ObjectG.getDObject!(SettingsBackend)(cast(GSettingsBackend*) __p, true);
156 	}
157 
158 	/**
159 	 * Signals that a single key has possibly changed.  Backend
160 	 * implementations should call this if a key has possibly changed its
161 	 * value.
162 	 *
163 	 * @key must be a valid key (ie starting with a slash, not containing
164 	 * '//', and not ending with a slash).
165 	 *
166 	 * The implementation must call this function during any call to
167 	 * g_settings_backend_write(), before the call returns (except in the
168 	 * case that no keys are actually changed and it cares to detect this
169 	 * fact).  It may not rely on the existence of a mainloop for
170 	 * dispatching the signal later.
171 	 *
172 	 * The implementation may call this function at any other time it likes
173 	 * in response to other events (such as changes occurring outside of the
174 	 * program).  These calls may originate from a mainloop or may originate
175 	 * in response to any other action (including from calls to
176 	 * g_settings_backend_write()).
177 	 *
178 	 * In the case that this call is in response to a call to
179 	 * g_settings_backend_write() then @origin_tag must be set to the same
180 	 * value that was passed to that call.
181 	 *
182 	 * Params:
183 	 *     key = the name of the key
184 	 *     originTag = the origin tag
185 	 *
186 	 * Since: 2.26
187 	 */
188 	public void changed(string key, void* originTag)
189 	{
190 		g_settings_backend_changed(gSettingsBackend, Str.toStringz(key), originTag);
191 	}
192 
193 	/**
194 	 * This call is a convenience wrapper.  It gets the list of changes from
195 	 * @tree, computes the longest common prefix and calls
196 	 * g_settings_backend_changed().
197 	 *
198 	 * Params:
199 	 *     tree = a #GTree containing the changes
200 	 *     originTag = the origin tag
201 	 *
202 	 * Since: 2.26
203 	 */
204 	public void changedTree(BBTree tree, void* originTag)
205 	{
206 		g_settings_backend_changed_tree(gSettingsBackend, (tree is null) ? null : tree.getBBTreeStruct(), originTag);
207 	}
208 
209 	/**
210 	 * Signals that a list of keys have possibly changed.  Backend
211 	 * implementations should call this if keys have possibly changed their
212 	 * values.
213 	 *
214 	 * @path must be a valid path (ie starting and ending with a slash and
215 	 * not containing '//').  Each string in @items must form a valid key
216 	 * name when @path is prefixed to it (ie: each item must not start or
217 	 * end with '/' and must not contain '//').
218 	 *
219 	 * The meaning of this signal is that any of the key names resulting
220 	 * from the contatenation of @path with each item in @items may have
221 	 * changed.
222 	 *
223 	 * The same rules for when notifications must occur apply as per
224 	 * g_settings_backend_changed().  These two calls can be used
225 	 * interchangeably if exactly one item has changed (although in that
226 	 * case g_settings_backend_changed() is definitely preferred).
227 	 *
228 	 * For efficiency reasons, the implementation should strive for @path to
229 	 * be as long as possible (ie: the longest common prefix of all of the
230 	 * keys that were changed) but this is not strictly required.
231 	 *
232 	 * Params:
233 	 *     path = the path containing the changes
234 	 *     items = the %NULL-terminated list of changed keys
235 	 *     originTag = the origin tag
236 	 *
237 	 * Since: 2.26
238 	 */
239 	public void keysChanged(string path, string[] items, void* originTag)
240 	{
241 		g_settings_backend_keys_changed(gSettingsBackend, Str.toStringz(path), Str.toStringzArray(items), originTag);
242 	}
243 
244 	/**
245 	 * Signals that all keys below a given path may have possibly changed.
246 	 * Backend implementations should call this if an entire path of keys
247 	 * have possibly changed their values.
248 	 *
249 	 * @path must be a valid path (ie starting and ending with a slash and
250 	 * not containing '//').
251 	 *
252 	 * The meaning of this signal is that any of the key which has a name
253 	 * starting with @path may have changed.
254 	 *
255 	 * The same rules for when notifications must occur apply as per
256 	 * g_settings_backend_changed().  This call might be an appropriate
257 	 * reasponse to a 'reset' call but implementations are also free to
258 	 * explicitly list the keys that were affected by that call if they can
259 	 * easily do so.
260 	 *
261 	 * For efficiency reasons, the implementation should strive for @path to
262 	 * be as long as possible (ie: the longest common prefix of all of the
263 	 * keys that were changed) but this is not strictly required.  As an
264 	 * example, if this function is called with the path of "/" then every
265 	 * single key in the application will be notified of a possible change.
266 	 *
267 	 * Params:
268 	 *     path = the path containing the changes
269 	 *     originTag = the origin tag
270 	 *
271 	 * Since: 2.26
272 	 */
273 	public void pathChanged(string path, void* originTag)
274 	{
275 		g_settings_backend_path_changed(gSettingsBackend, Str.toStringz(path), originTag);
276 	}
277 
278 	/**
279 	 * Signals that the writability of all keys below a given path may have
280 	 * changed.
281 	 *
282 	 * Since GSettings performs no locking operations for itself, this call
283 	 * will always be made in response to external events.
284 	 *
285 	 * Params:
286 	 *     path = the name of the path
287 	 *
288 	 * Since: 2.26
289 	 */
290 	public void pathWritableChanged(string path)
291 	{
292 		g_settings_backend_path_writable_changed(gSettingsBackend, Str.toStringz(path));
293 	}
294 
295 	/**
296 	 * Signals that the writability of a single key has possibly changed.
297 	 *
298 	 * Since GSettings performs no locking operations for itself, this call
299 	 * will always be made in response to external events.
300 	 *
301 	 * Params:
302 	 *     key = the name of the key
303 	 *
304 	 * Since: 2.26
305 	 */
306 	public void writableChanged(string key)
307 	{
308 		g_settings_backend_writable_changed(gSettingsBackend, Str.toStringz(key));
309 	}
310 
311 	/**
312 	 * Creates a keyfile-backed #GSettingsBackend.
313 	 *
314 	 * The filename of the keyfile to use is given by @filename.
315 	 *
316 	 * All settings read to or written from the backend must fall under the
317 	 * path given in @root_path (which must start and end with a slash and
318 	 * not contain two consecutive slashes).  @root_path may be "/".
319 	 *
320 	 * If @root_group is non-%NULL then it specifies the name of the keyfile
321 	 * group used for keys that are written directly below @root_path.  For
322 	 * example, if @root_path is "/apps/example/" and @root_group is
323 	 * "toplevel", then settings the key "/apps/example/enabled" to a value
324 	 * of %TRUE will cause the following to appear in the keyfile:
325 	 *
326 	 * |[
327 	 * [toplevel]
328 	 * enabled=true
329 	 * ]|
330 	 *
331 	 * If @root_group is %NULL then it is not permitted to store keys
332 	 * directly below the @root_path.
333 	 *
334 	 * For keys not stored directly below @root_path (ie: in a sub-path),
335 	 * the name of the subpath (with the final slash stripped) is used as
336 	 * the name of the keyfile group.  To continue the example, if
337 	 * "/apps/example/profiles/default/font-size" were set to
338 	 * 12 then the following would appear in the keyfile:
339 	 *
340 	 * |[
341 	 * [profiles/default]
342 	 * font-size=12
343 	 * ]|
344 	 *
345 	 * The backend will refuse writes (and return writability as being
346 	 * %FALSE) for keys outside of @root_path and, in the event that
347 	 * @root_group is %NULL, also for keys directly under @root_path.
348 	 * Writes will also be refused if the backend detects that it has the
349 	 * inability to rewrite the keyfile (ie: the containing directory is not
350 	 * writable).
351 	 *
352 	 * There is no checking done for your key namespace clashing with the
353 	 * syntax of the key file format.  For example, if you have '[' or ']'
354 	 * characters in your path names or '=' in your key names you may be in
355 	 * trouble.
356 	 *
357 	 * The backend reads default values from a keyfile called `defaults` in
358 	 * the directory specified by the #GKeyfileSettingsBackend:defaults-dir property,
359 	 * and a list of locked keys from a text file with the name `locks` in
360 	 * the same location.
361 	 *
362 	 * Params:
363 	 *     filename = the filename of the keyfile
364 	 *     rootPath = the path under which all settings keys appear
365 	 *     rootGroup = the group name corresponding to
366 	 *         @root_path, or %NULL
367 	 *
368 	 * Returns: a keyfile-backed #GSettingsBackend
369 	 */
370 	public static SettingsBackend keyfileSettingsBackendNew(string filename, string rootPath, string rootGroup)
371 	{
372 		auto __p = g_keyfile_settings_backend_new(Str.toStringz(filename), Str.toStringz(rootPath), Str.toStringz(rootGroup));
373 
374 		if(__p is null)
375 		{
376 			return null;
377 		}
378 
379 		return ObjectG.getDObject!(SettingsBackend)(cast(GSettingsBackend*) __p, true);
380 	}
381 
382 	/**
383 	 * Creates a memory-backed #GSettingsBackend.
384 	 *
385 	 * This backend allows changes to settings, but does not write them
386 	 * to any backing storage, so the next time you run your application,
387 	 * the memory backend will start out with the default values again.
388 	 *
389 	 * Returns: a newly created #GSettingsBackend
390 	 *
391 	 * Since: 2.28
392 	 */
393 	public static SettingsBackend memorySettingsBackendNew()
394 	{
395 		auto __p = g_memory_settings_backend_new();
396 
397 		if(__p is null)
398 		{
399 			return null;
400 		}
401 
402 		return ObjectG.getDObject!(SettingsBackend)(cast(GSettingsBackend*) __p, true);
403 	}
404 
405 	/**
406 	 * Creates a readonly #GSettingsBackend.
407 	 *
408 	 * This backend does not allow changes to settings, so all settings
409 	 * will always have their default values.
410 	 *
411 	 * Returns: a newly created #GSettingsBackend
412 	 *
413 	 * Since: 2.28
414 	 */
415 	public static SettingsBackend nullSettingsBackendNew()
416 	{
417 		auto __p = g_null_settings_backend_new();
418 
419 		if(__p is null)
420 		{
421 			return null;
422 		}
423 
424 		return ObjectG.getDObject!(SettingsBackend)(cast(GSettingsBackend*) __p, true);
425 	}
426 }