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