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.SettingsSchemaSource;
26 
27 private import gio.SettingsSchema;
28 private import glib.ConstructionException;
29 private import glib.ErrorG;
30 private import glib.GException;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 private import gtkc.Loader;
34 private import gtkc.gio;
35 public  import gtkc.giotypes;
36 private import gtkc.paths;
37 
38 
39 /**
40  * This is an opaque structure type.  You may not access it directly.
41  *
42  * Since: 2.32
43  */
44 public class SettingsSchemaSource
45 {
46 	/** the main Gtk struct */
47 	protected GSettingsSchemaSource* gSettingsSchemaSource;
48 	protected bool ownedRef;
49 
50 	/** Get the main Gtk struct */
51 	public GSettingsSchemaSource* getSettingsSchemaSourceStruct()
52 	{
53 		return gSettingsSchemaSource;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected void* getStruct()
58 	{
59 		return cast(void*)gSettingsSchemaSource;
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (GSettingsSchemaSource* gSettingsSchemaSource, bool ownedRef = false)
66 	{
67 		this.gSettingsSchemaSource = gSettingsSchemaSource;
68 		this.ownedRef = ownedRef;
69 	}
70 
71 	~this()
72 	{
73 		if ( Linker.isLoaded(LIBRARY.GIO) && ownedRef )
74 		{
75 			g_settings_schema_source_unref(gSettingsSchemaSource);
76 		}
77 	}
78 
79 	/**
80 	 */
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return g_settings_schema_source_get_type();
86 	}
87 
88 	/**
89 	 * Attempts to create a new schema source corresponding to the contents
90 	 * of the given directory.
91 	 *
92 	 * This function is not required for normal uses of #GSettings but it
93 	 * may be useful to authors of plugin management systems.
94 	 *
95 	 * The directory should contain a file called `gschemas.compiled` as
96 	 * produced by the [glib-compile-schemas][glib-compile-schemas] tool.
97 	 *
98 	 * If @trusted is %TRUE then `gschemas.compiled` is trusted not to be
99 	 * corrupted. This assumption has a performance advantage, but can result
100 	 * in crashes or inconsistent behaviour in the case of a corrupted file.
101 	 * Generally, you should set @trusted to %TRUE for files installed by the
102 	 * system and to %FALSE for files in the home directory.
103 	 *
104 	 * If @parent is non-%NULL then there are two effects.
105 	 *
106 	 * First, if g_settings_schema_source_lookup() is called with the
107 	 * @recursive flag set to %TRUE and the schema can not be found in the
108 	 * source, the lookup will recurse to the parent.
109 	 *
110 	 * Second, any references to other schemas specified within this
111 	 * source (ie: `child` or `extends`) references may be resolved
112 	 * from the @parent.
113 	 *
114 	 * For this second reason, except in very unusual situations, the
115 	 * @parent should probably be given as the default schema source, as
116 	 * returned by g_settings_schema_source_get_default().
117 	 *
118 	 * Params:
119 	 *     directory = the filename of a directory
120 	 *     parent = a #GSettingsSchemaSource, or %NULL
121 	 *     trusted = %TRUE, if the directory is trusted
122 	 *
123 	 * Since: 2.32
124 	 *
125 	 * Throws: GException on failure.
126 	 * Throws: ConstructionException GTK+ fails to create the object.
127 	 */
128 	public this(string directory, SettingsSchemaSource parent, bool trusted)
129 	{
130 		GError* err = null;
131 		
132 		auto p = g_settings_schema_source_new_from_directory(Str.toStringz(directory), (parent is null) ? null : parent.getSettingsSchemaSourceStruct(), trusted, &err);
133 		
134 		if (err !is null)
135 		{
136 			throw new GException( new ErrorG(err) );
137 		}
138 		
139 		if(p is null)
140 		{
141 			throw new ConstructionException("null returned by new_from_directory");
142 		}
143 		
144 		this(cast(GSettingsSchemaSource*) p);
145 	}
146 
147 	/**
148 	 * Lists the schemas in a given source.
149 	 *
150 	 * If @recursive is %TRUE then include parent sources.  If %FALSE then
151 	 * only include the schemas from one source (ie: one directory).  You
152 	 * probably want %TRUE.
153 	 *
154 	 * Non-relocatable schemas are those for which you can call
155 	 * g_settings_new().  Relocatable schemas are those for which you must
156 	 * use g_settings_new_with_path().
157 	 *
158 	 * Do not call this function from normal programs.  This is designed for
159 	 * use by database editors, commandline tools, etc.
160 	 *
161 	 * Params:
162 	 *     recursive = if we should recurse
163 	 *     nonRelocatable = the
164 	 *         list of non-relocatable schemas
165 	 *     relocatable = the list
166 	 *         of relocatable schemas
167 	 *
168 	 * Since: 2.40
169 	 */
170 	public void listSchemas(bool recursive, out string[] nonRelocatable, out string[] relocatable)
171 	{
172 		char** outnonRelocatable = null;
173 		char** outrelocatable = null;
174 		
175 		g_settings_schema_source_list_schemas(gSettingsSchemaSource, recursive, &outnonRelocatable, &outrelocatable);
176 		
177 		nonRelocatable = Str.toStringArray(outnonRelocatable);
178 		relocatable = Str.toStringArray(outrelocatable);
179 	}
180 
181 	/**
182 	 * Looks up a schema with the identifier @schema_id in @source.
183 	 *
184 	 * This function is not required for normal uses of #GSettings but it
185 	 * may be useful to authors of plugin management systems or to those who
186 	 * want to introspect the content of schemas.
187 	 *
188 	 * If the schema isn't found directly in @source and @recursive is %TRUE
189 	 * then the parent sources will also be checked.
190 	 *
191 	 * If the schema isn't found, %NULL is returned.
192 	 *
193 	 * Params:
194 	 *     schemaId = a schema ID
195 	 *     recursive = %TRUE if the lookup should be recursive
196 	 *
197 	 * Return: a new #GSettingsSchema
198 	 *
199 	 * Since: 2.32
200 	 */
201 	public SettingsSchema lookup(string schemaId, bool recursive)
202 	{
203 		auto p = g_settings_schema_source_lookup(gSettingsSchemaSource, Str.toStringz(schemaId), recursive);
204 		
205 		if(p is null)
206 		{
207 			return null;
208 		}
209 		
210 		return ObjectG.getDObject!(SettingsSchema)(cast(GSettingsSchema*) p, true);
211 	}
212 
213 	/**
214 	 * Increase the reference count of @source, returning a new reference.
215 	 *
216 	 * Return: a new reference to @source
217 	 *
218 	 * Since: 2.32
219 	 */
220 	public SettingsSchemaSource doref()
221 	{
222 		auto p = g_settings_schema_source_ref(gSettingsSchemaSource);
223 		
224 		if(p is null)
225 		{
226 			return null;
227 		}
228 		
229 		return ObjectG.getDObject!(SettingsSchemaSource)(cast(GSettingsSchemaSource*) p, true);
230 	}
231 
232 	/**
233 	 * Decrease the reference count of @source, possibly freeing it.
234 	 *
235 	 * Since: 2.32
236 	 */
237 	public void unref()
238 	{
239 		g_settings_schema_source_unref(gSettingsSchemaSource);
240 	}
241 
242 	/**
243 	 * Gets the default system schema source.
244 	 *
245 	 * This function is not required for normal uses of #GSettings but it
246 	 * may be useful to authors of plugin management systems or to those who
247 	 * want to introspect the content of schemas.
248 	 *
249 	 * If no schemas are installed, %NULL will be returned.
250 	 *
251 	 * The returned source may actually consist of multiple schema sources
252 	 * from different directories, depending on which directories were given
253 	 * in `XDG_DATA_DIRS` and `GSETTINGS_SCHEMA_DIR`. For this reason, all
254 	 * lookups performed against the default source should probably be done
255 	 * recursively.
256 	 *
257 	 * Return: the default schema source
258 	 *
259 	 * Since: 2.32
260 	 */
261 	public static SettingsSchemaSource getDefault()
262 	{
263 		auto p = g_settings_schema_source_get_default();
264 		
265 		if(p is null)
266 		{
267 			return null;
268 		}
269 		
270 		return ObjectG.getDObject!(SettingsSchemaSource)(cast(GSettingsSchemaSource*) p);
271 	}
272 }