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