source: appstream-generator/build/girepo/gio/SettingsSchema.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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