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 135 /** Get the main Gtk struct */ 136 public GSettingsSchema* getSettingsSchemaStruct() 137 { 138 return gSettingsSchema; 139 } 140 141 /** the main Gtk struct as a void* */ 142 protected void* getStruct() 143 { 144 return cast(void*)gSettingsSchema; 145 } 146 147 /** 148 * Sets our main struct and passes it to the parent class. 149 */ 150 public this (GSettingsSchema* gSettingsSchema) 151 { 152 this.gSettingsSchema = gSettingsSchema; 153 } 154 155 ~this() 156 { 157 if ( Linker.isLoaded(LIBRARY.GIO) && gSettingsSchema != null) 158 { 159 g_settings_schema_unref(gSettingsSchema); 160 } 161 } 162 163 /** 164 */ 165 166 public static GType getType() 167 { 168 return g_settings_schema_get_type(); 169 } 170 171 /** 172 * Get the ID of @schema. 173 * 174 * Return: the ID 175 */ 176 public string getId() 177 { 178 return Str.toString(g_settings_schema_get_id(gSettingsSchema)); 179 } 180 181 /** 182 * Gets the key named @name from @schema. 183 * 184 * It is a programmer error to request a key that does not exist. See 185 * g_settings_schema_list_keys(). 186 * 187 * Params: 188 * name = the name of a key 189 * 190 * Return: the #GSettingsSchemaKey for @name 191 * 192 * Since: 2.40 193 */ 194 public SettingsSchemaKey getKey(string name) 195 { 196 auto p = g_settings_schema_get_key(gSettingsSchema, Str.toStringz(name)); 197 198 if(p is null) 199 { 200 return null; 201 } 202 203 return ObjectG.getDObject!(SettingsSchemaKey)(cast(GSettingsSchemaKey*) p); 204 } 205 206 /** 207 * Gets the path associated with @schema, or %NULL. 208 * 209 * Schemas may be single-instance or relocatable. Single-instance 210 * schemas correspond to exactly one set of keys in the backend 211 * database: those located at the path returned by this function. 212 * 213 * Relocatable schemas can be referenced by other schemas and can 214 * threfore describe multiple sets of keys at different locations. For 215 * relocatable schemas, this function will return %NULL. 216 * 217 * Return: the path of the schema, or %NULL 218 * 219 * Since: 2.32 220 */ 221 public string getPath() 222 { 223 return Str.toString(g_settings_schema_get_path(gSettingsSchema)); 224 } 225 226 /** 227 * Checks if @schema has a key named @name. 228 * 229 * Params: 230 * name = the name of a key 231 * 232 * Return: %TRUE if such a key exists 233 * 234 * Since: 2.40 235 */ 236 public bool hasKey(string name) 237 { 238 return g_settings_schema_has_key(gSettingsSchema, Str.toStringz(name)) != 0; 239 } 240 241 /** 242 * Gets the list of children in @schema. 243 * 244 * You should free the return value with g_strfreev() when you are done 245 * with it. 246 * 247 * Return: a list of the children on @settings 248 * 249 * Since: 2.44 250 */ 251 public string[] listChildren() 252 { 253 return Str.toStringArray(g_settings_schema_list_children(gSettingsSchema)); 254 } 255 256 /** 257 * Introspects the list of keys on @schema. 258 * 259 * You should probably not be calling this function from "normal" code 260 * (since you should already know what keys are in your schema). This 261 * function is intended for introspection reasons. 262 * 263 * Return: a list of the keys on 264 * @schema 265 * 266 * Since: 2.46 267 */ 268 public string[] listKeys() 269 { 270 return Str.toStringArray(g_settings_schema_list_keys(gSettingsSchema)); 271 } 272 273 /** 274 * Increase the reference count of @schema, returning a new reference. 275 * 276 * Return: a new reference to @schema 277 * 278 * Since: 2.32 279 */ 280 public SettingsSchema doref() 281 { 282 auto p = g_settings_schema_ref(gSettingsSchema); 283 284 if(p is null) 285 { 286 return null; 287 } 288 289 return ObjectG.getDObject!(SettingsSchema)(cast(GSettingsSchema*) p); 290 } 291 292 /** 293 * Decrease the reference count of @schema, possibly freeing it. 294 * 295 * Since: 2.32 296 */ 297 public void unref() 298 { 299 g_settings_schema_unref(gSettingsSchema); 300 } 301 }