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.SettingsSchema; 26 27 private import gio.SettingsSchemaKey; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gtkc.Loader; 31 private import gtkc.gio; 32 public import gtkc.giotypes; 33 private import gtkc.paths; 34 35 36 /** 37 * The #GSettingsSchemaSource and #GSettingsSchema APIs provide a 38 * mechanism for advanced control over the loading of schemas and a 39 * mechanism for introspecting their content. 40 * 41 * Plugin loading systems that wish to provide plugins a way to access 42 * settings face the problem of how to make the schemas for these 43 * settings visible to GSettings. Typically, a plugin will want to ship 44 * the schema along with itself and it won't be installed into the 45 * standard system directories for schemas. 46 * 47 * #GSettingsSchemaSource provides a mechanism for dealing with this by 48 * allowing the creation of a new 'schema source' from which schemas can 49 * be acquired. This schema source can then become part of the metadata 50 * associated with the plugin and queried whenever the plugin requires 51 * access to some settings. 52 * 53 * Consider the following example: 54 * 55 * |[<!-- language="C" --> 56 * typedef struct 57 * { 58 * ... 59 * GSettingsSchemaSource *schema_source; 60 * ... 61 * } Plugin; 62 * 63 * Plugin * 64 * initialise_plugin (const gchar *dir) 65 * { 66 * Plugin *plugin; 67 * 68 * ... 69 * 70 * plugin->schema_source = 71 * g_settings_new_schema_source_from_directory (dir, 72 * g_settings_schema_source_get_default (), FALSE, NULL); 73 * 74 * ... 75 * 76 * return plugin; 77 * } 78 * 79 * ... 80 * 81 * GSettings * 82 * plugin_get_settings (Plugin *plugin, 83 * const gchar *schema_id) 84 * { 85 * GSettingsSchema *schema; 86 * 87 * if (schema_id == NULL) 88 * schema_id = plugin->identifier; 89 * 90 * schema = g_settings_schema_source_lookup (plugin->schema_source, 91 * schema_id, FALSE); 92 * 93 * if (schema == NULL) 94 * { 95 * ... disable the plugin or abort, etc ... 96 * } 97 * 98 * return g_settings_new_full (schema, NULL, NULL); 99 * } 100 * ]| 101 * 102 * The code above shows how hooks should be added to the code that 103 * initialises (or enables) the plugin to create the schema source and 104 * how an API can be added to the plugin system to provide a convenient 105 * way for the plugin to access its settings, using the schemas that it 106 * ships. 107 * 108 * From the standpoint of the plugin, it would need to ensure that it 109 * ships a gschemas.compiled file as part of itself, and then simply do 110 * the following: 111 * 112 * |[<!-- language="C" --> 113 * { 114 * GSettings *settings; 115 * gint some_value; 116 * 117 * settings = plugin_get_settings (self, NULL); 118 * some_value = g_settings_get_int (settings, "some-value"); 119 * ... 120 * } 121 * ]| 122 * 123 * It's also possible that the plugin system expects the schema source 124 * files (ie: .gschema.xml files) instead of a gschemas.compiled file. 125 * In that case, the plugin loading system must compile the schemas for 126 * itself before attempting to create the settings source. 127 * 128 * Since: 2.32 129 */ 130 public class SettingsSchema 131 { 132 /** the main Gtk struct */ 133 protected GSettingsSchema* gSettingsSchema; 134 protected bool ownedRef; 135 136 /** Get the main Gtk struct */ 137 public GSettingsSchema* getSettingsSchemaStruct() 138 { 139 return gSettingsSchema; 140 } 141 142 /** the main Gtk struct as a void* */ 143 protected void* getStruct() 144 { 145 return cast(void*)gSettingsSchema; 146 } 147 148 /** 149 * Sets our main struct and passes it to the parent class. 150 */ 151 public this (GSettingsSchema* gSettingsSchema, bool ownedRef = false) 152 { 153 this.gSettingsSchema = gSettingsSchema; 154 this.ownedRef = ownedRef; 155 } 156 157 ~this() 158 { 159 if ( Linker.isLoaded(LIBRARY.GIO) && ownedRef ) 160 { 161 g_settings_schema_unref(gSettingsSchema); 162 } 163 } 164 165 /** 166 */ 167 168 /** */ 169 public static GType getType() 170 { 171 return g_settings_schema_get_type(); 172 } 173 174 /** 175 * Get the ID of @schema. 176 * 177 * Return: the ID 178 */ 179 public string getId() 180 { 181 return Str.toString(g_settings_schema_get_id(gSettingsSchema)); 182 } 183 184 /** 185 * Gets the key named @name from @schema. 186 * 187 * It is a programmer error to request a key that does not exist. See 188 * g_settings_schema_list_keys(). 189 * 190 * Params: 191 * name = the name of a key 192 * 193 * Return: the #GSettingsSchemaKey for @name 194 * 195 * Since: 2.40 196 */ 197 public SettingsSchemaKey getKey(string name) 198 { 199 auto p = g_settings_schema_get_key(gSettingsSchema, Str.toStringz(name)); 200 201 if(p is null) 202 { 203 return null; 204 } 205 206 return ObjectG.getDObject!(SettingsSchemaKey)(cast(GSettingsSchemaKey*) p, true); 207 } 208 209 /** 210 * Gets the path associated with @schema, or %NULL. 211 * 212 * Schemas may be single-instance or relocatable. Single-instance 213 * schemas correspond to exactly one set of keys in the backend 214 * database: those located at the path returned by this function. 215 * 216 * Relocatable schemas can be referenced by other schemas and can 217 * threfore describe multiple sets of keys at different locations. For 218 * relocatable schemas, this function will return %NULL. 219 * 220 * Return: the path of the schema, or %NULL 221 * 222 * Since: 2.32 223 */ 224 public string getPath() 225 { 226 return Str.toString(g_settings_schema_get_path(gSettingsSchema)); 227 } 228 229 /** 230 * Checks if @schema has a key named @name. 231 * 232 * Params: 233 * name = the name of a key 234 * 235 * Return: %TRUE if such a key exists 236 * 237 * Since: 2.40 238 */ 239 public bool hasKey(string name) 240 { 241 return g_settings_schema_has_key(gSettingsSchema, Str.toStringz(name)) != 0; 242 } 243 244 /** 245 * Gets the list of children in @schema. 246 * 247 * You should free the return value with g_strfreev() when you are done 248 * with it. 249 * 250 * Return: a list of the children on @settings 251 * 252 * Since: 2.44 253 */ 254 public string[] listChildren() 255 { 256 auto retStr = g_settings_schema_list_children(gSettingsSchema); 257 258 scope(exit) Str.freeStringArray(retStr); 259 return Str.toStringArray(retStr); 260 } 261 262 /** 263 * Introspects the list of keys on @schema. 264 * 265 * You should probably not be calling this function from "normal" code 266 * (since you should already know what keys are in your schema). This 267 * function is intended for introspection reasons. 268 * 269 * Return: a list of the keys on 270 * @schema 271 * 272 * Since: 2.46 273 */ 274 public string[] listKeys() 275 { 276 auto retStr = g_settings_schema_list_keys(gSettingsSchema); 277 278 scope(exit) Str.freeStringArray(retStr); 279 return Str.toStringArray(retStr); 280 } 281 282 /** 283 * Increase the reference count of @schema, returning a new reference. 284 * 285 * Return: a new reference to @schema 286 * 287 * Since: 2.32 288 */ 289 public SettingsSchema doref() 290 { 291 auto p = g_settings_schema_ref(gSettingsSchema); 292 293 if(p is null) 294 { 295 return null; 296 } 297 298 return ObjectG.getDObject!(SettingsSchema)(cast(GSettingsSchema*) p, true); 299 } 300 301 /** 302 * Decrease the reference count of @schema, possibly freeing it. 303 * 304 * Since: 2.32 305 */ 306 public void unref() 307 { 308 g_settings_schema_unref(gSettingsSchema); 309 } 310 }