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.ContentType;
26 
27 private import gio.FileIF;
28 private import gio.IconIF;
29 private import gio.c.functions;
30 public  import gio.c.types;
31 private import glib.ListG;
32 private import glib.Str;
33 private import glib.c.functions;
34 private import gobject.ObjectG;
35 
36 
37 /** */
38 public struct ContentType
39 {
40 
41 	/**
42 	 * Checks if a content type can be executable. Note that for instance
43 	 * things like text files can be executables (i.e. scripts and batch files).
44 	 *
45 	 * Params:
46 	 *     type = a content type string
47 	 *
48 	 * Returns: %TRUE if the file type corresponds to a type that
49 	 *     can be executable, %FALSE otherwise.
50 	 */
51 	public static bool canBeExecutable(string type)
52 	{
53 		return g_content_type_can_be_executable(Str.toStringz(type)) != 0;
54 	}
55 
56 	/**
57 	 * Compares two content types for equality.
58 	 *
59 	 * Params:
60 	 *     type1 = a content type string
61 	 *     type2 = a content type string
62 	 *
63 	 * Returns: %TRUE if the two strings are identical or equivalent,
64 	 *     %FALSE otherwise.
65 	 */
66 	public static bool equals(string type1, string type2)
67 	{
68 		return g_content_type_equals(Str.toStringz(type1), Str.toStringz(type2)) != 0;
69 	}
70 
71 	/**
72 	 * Tries to find a content type based on the mime type name.
73 	 *
74 	 * Params:
75 	 *     mimeType = a mime type string
76 	 *
77 	 * Returns: Newly allocated string with content type or
78 	 *     %NULL. Free with g_free()
79 	 *
80 	 * Since: 2.18
81 	 */
82 	public static string fromMimeType(string mimeType)
83 	{
84 		auto retStr = g_content_type_from_mime_type(Str.toStringz(mimeType));
85 
86 		scope(exit) Str.freeString(retStr);
87 		return Str.toString(retStr);
88 	}
89 
90 	/**
91 	 * Gets the human readable description of the content type.
92 	 *
93 	 * Params:
94 	 *     type = a content type string
95 	 *
96 	 * Returns: a short description of the content type @type. Free the
97 	 *     returned string with g_free()
98 	 */
99 	public static string getDescription(string type)
100 	{
101 		auto retStr = g_content_type_get_description(Str.toStringz(type));
102 
103 		scope(exit) Str.freeString(retStr);
104 		return Str.toString(retStr);
105 	}
106 
107 	/**
108 	 * Gets the generic icon name for a content type.
109 	 *
110 	 * See the
111 	 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
112 	 * specification for more on the generic icon name.
113 	 *
114 	 * Params:
115 	 *     type = a content type string
116 	 *
117 	 * Returns: the registered generic icon name for the given @type,
118 	 *     or %NULL if unknown. Free with g_free()
119 	 *
120 	 * Since: 2.34
121 	 */
122 	public static string getGenericIconName(string type)
123 	{
124 		auto retStr = g_content_type_get_generic_icon_name(Str.toStringz(type));
125 
126 		scope(exit) Str.freeString(retStr);
127 		return Str.toString(retStr);
128 	}
129 
130 	/**
131 	 * Gets the icon for a content type.
132 	 *
133 	 * Params:
134 	 *     type = a content type string
135 	 *
136 	 * Returns: #GIcon corresponding to the content type. Free the returned
137 	 *     object with g_object_unref()
138 	 */
139 	public static IconIF getIcon(string type)
140 	{
141 		auto __p = g_content_type_get_icon(Str.toStringz(type));
142 
143 		if(__p is null)
144 		{
145 			return null;
146 		}
147 
148 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p, true);
149 	}
150 
151 	/**
152 	 * Gets the mime type for the content type, if one is registered.
153 	 *
154 	 * Params:
155 	 *     type = a content type string
156 	 *
157 	 * Returns: the registered mime type for the
158 	 *     given @type, or %NULL if unknown; free with g_free().
159 	 */
160 	public static string getMimeType(string type)
161 	{
162 		auto retStr = g_content_type_get_mime_type(Str.toStringz(type));
163 
164 		scope(exit) Str.freeString(retStr);
165 		return Str.toString(retStr);
166 	}
167 
168 	/**
169 	 * Gets the symbolic icon for a content type.
170 	 *
171 	 * Params:
172 	 *     type = a content type string
173 	 *
174 	 * Returns: symbolic #GIcon corresponding to the content type.
175 	 *     Free the returned object with g_object_unref()
176 	 *
177 	 * Since: 2.34
178 	 */
179 	public static IconIF getSymbolicIcon(string type)
180 	{
181 		auto __p = g_content_type_get_symbolic_icon(Str.toStringz(type));
182 
183 		if(__p is null)
184 		{
185 			return null;
186 		}
187 
188 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p, true);
189 	}
190 
191 	/**
192 	 * Guesses the content type based on example data. If the function is
193 	 * uncertain, @result_uncertain will be set to %TRUE. Either @filename
194 	 * or @data may be %NULL, in which case the guess will be based solely
195 	 * on the other argument.
196 	 *
197 	 * Params:
198 	 *     filename = a string, or %NULL
199 	 *     data = a stream of data, or %NULL
200 	 *     resultUncertain = return location for the certainty
201 	 *         of the result, or %NULL
202 	 *
203 	 * Returns: a string indicating a guessed content type for the
204 	 *     given data. Free with g_free()
205 	 */
206 	public static string typeGuess(string filename, char[] data, out bool resultUncertain)
207 	{
208 		int outresultUncertain;
209 
210 		auto retStr = g_content_type_guess(Str.toStringz(filename), data.ptr, cast(size_t)data.length, &outresultUncertain);
211 
212 		resultUncertain = (outresultUncertain == 1);
213 
214 		scope(exit) Str.freeString(retStr);
215 		return Str.toString(retStr);
216 	}
217 
218 	/**
219 	 * Tries to guess the type of the tree with root @root, by
220 	 * looking at the files it contains. The result is an array
221 	 * of content types, with the best guess coming first.
222 	 *
223 	 * The types returned all have the form x-content/foo, e.g.
224 	 * x-content/audio-cdda (for audio CDs) or x-content/image-dcf
225 	 * (for a camera memory card). See the
226 	 * [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
227 	 * specification for more on x-content types.
228 	 *
229 	 * This function is useful in the implementation of
230 	 * g_mount_guess_content_type().
231 	 *
232 	 * Params:
233 	 *     root = the root of the tree to guess a type for
234 	 *
235 	 * Returns: an %NULL-terminated
236 	 *     array of zero or more content types. Free with g_strfreev()
237 	 *
238 	 * Since: 2.18
239 	 */
240 	public static string[] guessForTree(FileIF root)
241 	{
242 		auto retStr = g_content_type_guess_for_tree((root is null) ? null : root.getFileStruct());
243 
244 		scope(exit) Str.freeStringArray(retStr);
245 		return Str.toStringArray(retStr);
246 	}
247 
248 	/**
249 	 * Determines if @type is a subset of @supertype.
250 	 *
251 	 * Params:
252 	 *     type = a content type string
253 	 *     supertype = a content type string
254 	 *
255 	 * Returns: %TRUE if @type is a kind of @supertype,
256 	 *     %FALSE otherwise.
257 	 */
258 	public static bool isA(string type, string supertype)
259 	{
260 		return g_content_type_is_a(Str.toStringz(type), Str.toStringz(supertype)) != 0;
261 	}
262 
263 	/**
264 	 * Checks if the content type is the generic "unknown" type.
265 	 * On UNIX this is the "application/octet-stream" mimetype,
266 	 * while on win32 it is "*" and on OSX it is a dynamic type
267 	 * or octet-stream.
268 	 *
269 	 * Params:
270 	 *     type = a content type string
271 	 *
272 	 * Returns: %TRUE if the type is the unknown type.
273 	 */
274 	public static bool isUnknown(string type)
275 	{
276 		return g_content_type_is_unknown(Str.toStringz(type)) != 0;
277 	}
278 
279 	/**
280 	 * Gets a list of strings containing all the registered content types
281 	 * known to the system. The list and its data should be freed using
282 	 * `g_list_free_full (list, g_free)`.
283 	 *
284 	 * Returns: list of the registered
285 	 *     content types
286 	 */
287 	public static ListG contentTypesGetRegistered()
288 	{
289 		auto __p = g_content_types_get_registered();
290 
291 		if(__p is null)
292 		{
293 			return null;
294 		}
295 
296 		return new ListG(cast(GList*) __p, true);
297 	}
298 
299 	/**
300 	 * Determines if @type is a subset of @mime_type.
301 	 * Convenience wrapper around g_content_type_is_a().
302 	 *
303 	 * Params:
304 	 *     type = a content type string
305 	 *     mimeType = a mime type string
306 	 *
307 	 * Returns: %TRUE if @type is a kind of @mime_type,
308 	 *     %FALSE otherwise.
309 	 *
310 	 * Since: 2.52
311 	 */
312 	public static bool isMimeType(string type, string mimeType)
313 	{
314 		return g_content_type_is_mime_type(Str.toStringz(type), Str.toStringz(mimeType)) != 0;
315 	}
316 
317 	/**
318 	 * Get the list of directories which MIME data is loaded from. See
319 	 * g_content_type_set_mime_dirs() for details.
320 	 *
321 	 * Returns: %NULL-terminated list of
322 	 *     directories to load MIME data from, including any `mime/` subdirectory,
323 	 *     and with the first directory to try listed first
324 	 *
325 	 * Since: 2.60
326 	 */
327 	public static string[] getMimeDirs()
328 	{
329 		return Str.toStringArray(g_content_type_get_mime_dirs());
330 	}
331 
332 	/**
333 	 * Set the list of directories used by GIO to load the MIME database.
334 	 * If @dirs is %NULL, the directories used are the default:
335 	 *
336 	 * - the `mime` subdirectory of the directory in `$XDG_DATA_HOME`
337 	 * - the `mime` subdirectory of every directory in `$XDG_DATA_DIRS`
338 	 *
339 	 * This function is intended to be used when writing tests that depend on
340 	 * information stored in the MIME database, in order to control the data.
341 	 *
342 	 * Typically, in case your tests use %G_TEST_OPTION_ISOLATE_DIRS, but they
343 	 * depend on the system’s MIME database, you should call this function
344 	 * with @dirs set to %NULL before calling g_test_init(), for instance:
345 	 *
346 	 * |[<!-- language="C" -->
347 	 * // Load MIME data from the system
348 	 * g_content_type_set_mime_dirs (NULL);
349 	 * // Isolate the environment
350 	 * g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
351 	 *
352 	 * …
353 	 *
354 	 * return g_test_run ();
355 	 * ]|
356 	 *
357 	 * Params:
358 	 *     dirs = %NULL-terminated list of
359 	 *         directories to load MIME data from, including any `mime/` subdirectory,
360 	 *         and with the first directory to try listed first
361 	 *
362 	 * Since: 2.60
363 	 */
364 	public static void setMimeDirs(string[] dirs)
365 	{
366 		g_content_type_set_mime_dirs(Str.toStringzArray(dirs));
367 	}
368 }