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.AppInfoT;
26 
27 public  import gio.AppInfoIF;
28 public  import gio.AppLaunchContext;
29 public  import gio.AsyncResultIF;
30 public  import gio.Cancellable;
31 public  import gio.FileIF;
32 public  import gio.IconIF;
33 public  import gio.c.functions;
34 public  import gio.c.types;
35 public  import glib.ErrorG;
36 public  import glib.GException;
37 public  import glib.ListG;
38 public  import glib.Str;
39 public  import gobject.ObjectG;
40 public  import gtkc.giotypes;
41 
42 
43 /**
44  * #GAppInfo and #GAppLaunchContext are used for describing and launching
45  * applications installed on the system.
46  * 
47  * As of GLib 2.20, URIs will always be converted to POSIX paths
48  * (using g_file_get_path()) when using g_app_info_launch() even if
49  * the application requested an URI and not a POSIX path. For example
50  * for an desktop-file based application with Exec key `totem
51  * %U` and a single URI, `sftp://foo/file.avi`, then
52  * `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will
53  * only work if a set of suitable GIO extensions (such as gvfs 2.26
54  * compiled with FUSE support), is available and operational; if this
55  * is not the case, the URI will be passed unmodified to the application.
56  * Some URIs, such as `mailto:`, of course cannot be mapped to a POSIX
57  * path (in gvfs there's no FUSE mount for it); such URIs will be
58  * passed unmodified to the application.
59  * 
60  * Specifically for gvfs 2.26 and later, the POSIX URI will be mapped
61  * back to the GIO URI in the #GFile constructors (since gvfs
62  * implements the #GVfs extension point). As such, if the application
63  * needs to examine the URI, it needs to use g_file_get_uri() or
64  * similar on #GFile. In other words, an application cannot assume
65  * that the URI passed to e.g. g_file_new_for_commandline_arg() is
66  * equal to the result of g_file_get_uri(). The following snippet
67  * illustrates this:
68  * 
69  * |[
70  * GFile *f;
71  * char *uri;
72  * 
73  * file = g_file_new_for_commandline_arg (uri_from_commandline);
74  * 
75  * uri = g_file_get_uri (file);
76  * strcmp (uri, uri_from_commandline) == 0;
77  * g_free (uri);
78  * 
79  * if (g_file_has_uri_scheme (file, "cdda"))
80  * {
81  * // do something special with uri
82  * }
83  * g_object_unref (file);
84  * ]|
85  * 
86  * This code will work when both `cdda://sr0/Track 1.wav` and
87  * `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the
88  * application. It should be noted that it's generally not safe
89  * for applications to rely on the format of a particular URIs.
90  * Different launcher applications (e.g. file managers) may have
91  * different ideas of what a given URI means.
92  */
93 public template AppInfoT(TStruct)
94 {
95 	/** Get the main Gtk struct */
96 	public GAppInfo* getAppInfoStruct(bool transferOwnership = false)
97 	{
98 		if (transferOwnership)
99 			ownedRef = false;
100 		return cast(GAppInfo*)getStruct();
101 	}
102 
103 
104 	/**
105 	 * Adds a content type to the application information to indicate the
106 	 * application is capable of opening files with the given content type.
107 	 *
108 	 * Params:
109 	 *     contentType = a string.
110 	 *
111 	 * Returns: %TRUE on success, %FALSE on error.
112 	 *
113 	 * Throws: GException on failure.
114 	 */
115 	public bool addSupportsType(string contentType)
116 	{
117 		GError* err = null;
118 
119 		auto p = g_app_info_add_supports_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0;
120 
121 		if (err !is null)
122 		{
123 			throw new GException( new ErrorG(err) );
124 		}
125 
126 		return p;
127 	}
128 
129 	/**
130 	 * Obtains the information whether the #GAppInfo can be deleted.
131 	 * See g_app_info_delete().
132 	 *
133 	 * Returns: %TRUE if @appinfo can be deleted
134 	 *
135 	 * Since: 2.20
136 	 */
137 	public bool canDelete()
138 	{
139 		return g_app_info_can_delete(getAppInfoStruct()) != 0;
140 	}
141 
142 	/**
143 	 * Checks if a supported content type can be removed from an application.
144 	 *
145 	 * Returns: %TRUE if it is possible to remove supported
146 	 *     content types from a given @appinfo, %FALSE if not.
147 	 */
148 	public bool canRemoveSupportsType()
149 	{
150 		return g_app_info_can_remove_supports_type(getAppInfoStruct()) != 0;
151 	}
152 
153 	/**
154 	 * Tries to delete a #GAppInfo.
155 	 *
156 	 * On some platforms, there may be a difference between user-defined
157 	 * #GAppInfos which can be deleted, and system-wide ones which cannot.
158 	 * See g_app_info_can_delete().
159 	 *
160 	 * Returns: %TRUE if @appinfo has been deleted
161 	 *
162 	 * Since: 2.20
163 	 */
164 	public bool delet()
165 	{
166 		return g_app_info_delete(getAppInfoStruct()) != 0;
167 	}
168 
169 	/**
170 	 * Creates a duplicate of a #GAppInfo.
171 	 *
172 	 * Returns: a duplicate of @appinfo.
173 	 */
174 	public AppInfoIF dup()
175 	{
176 		auto p = g_app_info_dup(getAppInfoStruct());
177 
178 		if(p is null)
179 		{
180 			return null;
181 		}
182 
183 		return ObjectG.getDObject!(AppInfoIF)(cast(GAppInfo*) p, true);
184 	}
185 
186 	/**
187 	 * Checks if two #GAppInfos are equal.
188 	 *
189 	 * Note that the check <em>may not</em> compare each individual field, and
190 	 * only does an identity check. In case detecting changes in the contents
191 	 * is needed, program code must additionally compare relevant fields.
192 	 *
193 	 * Params:
194 	 *     appinfo2 = the second #GAppInfo.
195 	 *
196 	 * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
197 	 */
198 	public bool equal(AppInfoIF appinfo2)
199 	{
200 		return g_app_info_equal(getAppInfoStruct(), (appinfo2 is null) ? null : appinfo2.getAppInfoStruct()) != 0;
201 	}
202 
203 	/**
204 	 * Gets the commandline with which the application will be
205 	 * started.
206 	 *
207 	 * Returns: a string containing the @appinfo's commandline,
208 	 *     or %NULL if this information is not available
209 	 *
210 	 * Since: 2.20
211 	 */
212 	public string getCommandline()
213 	{
214 		return Str.toString(g_app_info_get_commandline(getAppInfoStruct()));
215 	}
216 
217 	/**
218 	 * Gets a human-readable description of an installed application.
219 	 *
220 	 * Returns: a string containing a description of the
221 	 *     application @appinfo, or %NULL if none.
222 	 */
223 	public string getDescription()
224 	{
225 		return Str.toString(g_app_info_get_description(getAppInfoStruct()));
226 	}
227 
228 	/**
229 	 * Gets the display name of the application. The display name is often more
230 	 * descriptive to the user than the name itself.
231 	 *
232 	 * Returns: the display name of the application for @appinfo, or the name if
233 	 *     no display name is available.
234 	 *
235 	 * Since: 2.24
236 	 */
237 	public string getDisplayName()
238 	{
239 		return Str.toString(g_app_info_get_display_name(getAppInfoStruct()));
240 	}
241 
242 	/**
243 	 * Gets the executable's name for the installed application.
244 	 *
245 	 * Returns: a string containing the @appinfo's application
246 	 *     binaries name
247 	 */
248 	public string getExecutable()
249 	{
250 		return Str.toString(g_app_info_get_executable(getAppInfoStruct()));
251 	}
252 
253 	/**
254 	 * Gets the icon for the application.
255 	 *
256 	 * Returns: the default #GIcon for @appinfo or %NULL
257 	 *     if there is no default icon.
258 	 */
259 	public IconIF getIcon()
260 	{
261 		auto p = g_app_info_get_icon(getAppInfoStruct());
262 
263 		if(p is null)
264 		{
265 			return null;
266 		}
267 
268 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) p);
269 	}
270 
271 	/**
272 	 * Gets the ID of an application. An id is a string that
273 	 * identifies the application. The exact format of the id is
274 	 * platform dependent. For instance, on Unix this is the
275 	 * desktop file id from the xdg menu specification.
276 	 *
277 	 * Note that the returned ID may be %NULL, depending on how
278 	 * the @appinfo has been constructed.
279 	 *
280 	 * Returns: a string containing the application's ID.
281 	 */
282 	public string getId()
283 	{
284 		return Str.toString(g_app_info_get_id(getAppInfoStruct()));
285 	}
286 
287 	/**
288 	 * Gets the installed name of the application.
289 	 *
290 	 * Returns: the name of the application for @appinfo.
291 	 */
292 	public string getName()
293 	{
294 		return Str.toString(g_app_info_get_name(getAppInfoStruct()));
295 	}
296 
297 	/**
298 	 * Retrieves the list of content types that @app_info claims to support.
299 	 * If this information is not provided by the environment, this function
300 	 * will return %NULL.
301 	 * This function does not take in consideration associations added with
302 	 * g_app_info_add_supports_type(), but only those exported directly by
303 	 * the application.
304 	 *
305 	 * Returns: a list of content types.
306 	 *
307 	 * Since: 2.34
308 	 */
309 	public string[] getSupportedTypes()
310 	{
311 		return Str.toStringArray(g_app_info_get_supported_types(getAppInfoStruct()));
312 	}
313 
314 	/**
315 	 * Launches the application. Passes @files to the launched application
316 	 * as arguments, using the optional @launch_context to get information
317 	 * about the details of the launcher (like what screen it is on).
318 	 * On error, @error will be set accordingly.
319 	 *
320 	 * To launch the application without arguments pass a %NULL @files list.
321 	 *
322 	 * Note that even if the launch is successful the application launched
323 	 * can fail to start if it runs into problems during startup. There is
324 	 * no way to detect this.
325 	 *
326 	 * Some URIs can be changed when passed through a GFile (for instance
327 	 * unsupported URIs with strange formats like mailto:), so if you have
328 	 * a textual URI you want to pass in as argument, consider using
329 	 * g_app_info_launch_uris() instead.
330 	 *
331 	 * The launched application inherits the environment of the launching
332 	 * process, but it can be modified with g_app_launch_context_setenv()
333 	 * and g_app_launch_context_unsetenv().
334 	 *
335 	 * On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE`
336 	 * environment variable with the path of the launched desktop file and
337 	 * `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched
338 	 * process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`,
339 	 * should it be inherited by further processes. The `DISPLAY` and
340 	 * `DESKTOP_STARTUP_ID` environment variables are also set, based
341 	 * on information provided in @launch_context.
342 	 *
343 	 * Params:
344 	 *     files = a #GList of #GFile objects
345 	 *     launchContext = a #GAppLaunchContext or %NULL
346 	 *
347 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
348 	 *
349 	 * Throws: GException on failure.
350 	 */
351 	public bool launch(ListG files, AppLaunchContext launchContext)
352 	{
353 		GError* err = null;
354 
355 		auto p = g_app_info_launch(getAppInfoStruct(), (files is null) ? null : files.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), &err) != 0;
356 
357 		if (err !is null)
358 		{
359 			throw new GException( new ErrorG(err) );
360 		}
361 
362 		return p;
363 	}
364 
365 	/**
366 	 * Launches the application. This passes the @uris to the launched application
367 	 * as arguments, using the optional @launch_context to get information
368 	 * about the details of the launcher (like what screen it is on).
369 	 * On error, @error will be set accordingly.
370 	 *
371 	 * To launch the application without arguments pass a %NULL @uris list.
372 	 *
373 	 * Note that even if the launch is successful the application launched
374 	 * can fail to start if it runs into problems during startup. There is
375 	 * no way to detect this.
376 	 *
377 	 * Params:
378 	 *     uris = a #GList containing URIs to launch.
379 	 *     launchContext = a #GAppLaunchContext or %NULL
380 	 *
381 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
382 	 *
383 	 * Throws: GException on failure.
384 	 */
385 	public bool launchUris(ListG uris, AppLaunchContext launchContext)
386 	{
387 		GError* err = null;
388 
389 		auto p = g_app_info_launch_uris(getAppInfoStruct(), (uris is null) ? null : uris.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), &err) != 0;
390 
391 		if (err !is null)
392 		{
393 			throw new GException( new ErrorG(err) );
394 		}
395 
396 		return p;
397 	}
398 
399 	/**
400 	 * Removes a supported type from an application, if possible.
401 	 *
402 	 * Params:
403 	 *     contentType = a string.
404 	 *
405 	 * Returns: %TRUE on success, %FALSE on error.
406 	 *
407 	 * Throws: GException on failure.
408 	 */
409 	public bool removeSupportsType(string contentType)
410 	{
411 		GError* err = null;
412 
413 		auto p = g_app_info_remove_supports_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0;
414 
415 		if (err !is null)
416 		{
417 			throw new GException( new ErrorG(err) );
418 		}
419 
420 		return p;
421 	}
422 
423 	/**
424 	 * Sets the application as the default handler for the given file extension.
425 	 *
426 	 * Params:
427 	 *     extension = a string containing the file extension
428 	 *         (without the dot).
429 	 *
430 	 * Returns: %TRUE on success, %FALSE on error.
431 	 *
432 	 * Throws: GException on failure.
433 	 */
434 	public bool setAsDefaultForExtension(string extension)
435 	{
436 		GError* err = null;
437 
438 		auto p = g_app_info_set_as_default_for_extension(getAppInfoStruct(), Str.toStringz(extension), &err) != 0;
439 
440 		if (err !is null)
441 		{
442 			throw new GException( new ErrorG(err) );
443 		}
444 
445 		return p;
446 	}
447 
448 	/**
449 	 * Sets the application as the default handler for a given type.
450 	 *
451 	 * Params:
452 	 *     contentType = the content type.
453 	 *
454 	 * Returns: %TRUE on success, %FALSE on error.
455 	 *
456 	 * Throws: GException on failure.
457 	 */
458 	public bool setAsDefaultForType(string contentType)
459 	{
460 		GError* err = null;
461 
462 		auto p = g_app_info_set_as_default_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0;
463 
464 		if (err !is null)
465 		{
466 			throw new GException( new ErrorG(err) );
467 		}
468 
469 		return p;
470 	}
471 
472 	/**
473 	 * Sets the application as the last used application for a given type.
474 	 * This will make the application appear as first in the list returned
475 	 * by g_app_info_get_recommended_for_type(), regardless of the default
476 	 * application for that content type.
477 	 *
478 	 * Params:
479 	 *     contentType = the content type.
480 	 *
481 	 * Returns: %TRUE on success, %FALSE on error.
482 	 *
483 	 * Throws: GException on failure.
484 	 */
485 	public bool setAsLastUsedForType(string contentType)
486 	{
487 		GError* err = null;
488 
489 		auto p = g_app_info_set_as_last_used_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0;
490 
491 		if (err !is null)
492 		{
493 			throw new GException( new ErrorG(err) );
494 		}
495 
496 		return p;
497 	}
498 
499 	/**
500 	 * Checks if the application info should be shown in menus that
501 	 * list available applications.
502 	 *
503 	 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
504 	 */
505 	public bool shouldShow()
506 	{
507 		return g_app_info_should_show(getAppInfoStruct()) != 0;
508 	}
509 
510 	/**
511 	 * Checks if the application accepts files as arguments.
512 	 *
513 	 * Returns: %TRUE if the @appinfo supports files.
514 	 */
515 	public bool supportsFiles()
516 	{
517 		return g_app_info_supports_files(getAppInfoStruct()) != 0;
518 	}
519 
520 	/**
521 	 * Checks if the application supports reading files and directories from URIs.
522 	 *
523 	 * Returns: %TRUE if the @appinfo supports URIs.
524 	 */
525 	public bool supportsUris()
526 	{
527 		return g_app_info_supports_uris(getAppInfoStruct()) != 0;
528 	}
529 }