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