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 glib.c.functions;
40 public  import gobject.ObjectG;
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 a 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 	alias delet = delete_;
154 	/**
155 	 * Tries to delete a #GAppInfo.
156 	 *
157 	 * On some platforms, there may be a difference between user-defined
158 	 * #GAppInfos which can be deleted, and system-wide ones which cannot.
159 	 * See g_app_info_can_delete().
160 	 *
161 	 * Returns: %TRUE if @appinfo has been deleted
162 	 *
163 	 * Since: 2.20
164 	 */
165 	public bool delete_()
166 	{
167 		return g_app_info_delete(getAppInfoStruct()) != 0;
168 	}
169 
170 	/**
171 	 * Creates a duplicate of a #GAppInfo.
172 	 *
173 	 * Returns: a duplicate of @appinfo.
174 	 */
175 	public AppInfoIF dup()
176 	{
177 		auto __p = g_app_info_dup(getAppInfoStruct());
178 
179 		if(__p is null)
180 		{
181 			return null;
182 		}
183 
184 		return ObjectG.getDObject!(AppInfoIF)(cast(GAppInfo*) __p, true);
185 	}
186 
187 	/**
188 	 * Checks if two #GAppInfos are equal.
189 	 *
190 	 * Note that the check *may not* compare each individual
191 	 * field, and only does an identity check. In case detecting changes in the
192 	 * contents is needed, program code must additionally compare relevant fields.
193 	 *
194 	 * Params:
195 	 *     appinfo2 = the second #GAppInfo.
196 	 *
197 	 * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
198 	 */
199 	public bool equal(AppInfoIF appinfo2)
200 	{
201 		return g_app_info_equal(getAppInfoStruct(), (appinfo2 is null) ? null : appinfo2.getAppInfoStruct()) != 0;
202 	}
203 
204 	/**
205 	 * Gets the commandline with which the application will be
206 	 * started.
207 	 *
208 	 * Returns: a string containing the @appinfo's commandline,
209 	 *     or %NULL if this information is not available
210 	 *
211 	 * Since: 2.20
212 	 */
213 	public string getCommandline()
214 	{
215 		return Str.toString(g_app_info_get_commandline(getAppInfoStruct()));
216 	}
217 
218 	/**
219 	 * Gets a human-readable description of an installed application.
220 	 *
221 	 * Returns: a string containing a description of the
222 	 *     application @appinfo, or %NULL if none.
223 	 */
224 	public string getDescription()
225 	{
226 		return Str.toString(g_app_info_get_description(getAppInfoStruct()));
227 	}
228 
229 	/**
230 	 * Gets the display name of the application. The display name is often more
231 	 * descriptive to the user than the name itself.
232 	 *
233 	 * Returns: the display name of the application for @appinfo, or the name if
234 	 *     no display name is available.
235 	 *
236 	 * Since: 2.24
237 	 */
238 	public string getDisplayName()
239 	{
240 		return Str.toString(g_app_info_get_display_name(getAppInfoStruct()));
241 	}
242 
243 	/**
244 	 * Gets the executable's name for the installed application.
245 	 *
246 	 * Returns: a string containing the @appinfo's application
247 	 *     binaries name
248 	 */
249 	public string getExecutable()
250 	{
251 		return Str.toString(g_app_info_get_executable(getAppInfoStruct()));
252 	}
253 
254 	/**
255 	 * Gets the icon for the application.
256 	 *
257 	 * Returns: the default #GIcon for @appinfo or %NULL
258 	 *     if there is no default icon.
259 	 */
260 	public IconIF getIcon()
261 	{
262 		auto __p = g_app_info_get_icon(getAppInfoStruct());
263 
264 		if(__p is null)
265 		{
266 			return null;
267 		}
268 
269 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p);
270 	}
271 
272 	/**
273 	 * Gets the ID of an application. An id is a string that
274 	 * identifies the application. The exact format of the id is
275 	 * platform dependent. For instance, on Unix this is the
276 	 * desktop file id from the xdg menu specification.
277 	 *
278 	 * Note that the returned ID may be %NULL, depending on how
279 	 * the @appinfo has been constructed.
280 	 *
281 	 * Returns: a string containing the application's ID.
282 	 */
283 	public string getId()
284 	{
285 		return Str.toString(g_app_info_get_id(getAppInfoStruct()));
286 	}
287 
288 	/**
289 	 * Gets the installed name of the application.
290 	 *
291 	 * Returns: the name of the application for @appinfo.
292 	 */
293 	public string getName()
294 	{
295 		return Str.toString(g_app_info_get_name(getAppInfoStruct()));
296 	}
297 
298 	/**
299 	 * Retrieves the list of content types that @app_info claims to support.
300 	 * If this information is not provided by the environment, this function
301 	 * will return %NULL.
302 	 * This function does not take in consideration associations added with
303 	 * g_app_info_add_supports_type(), but only those exported directly by
304 	 * the application.
305 	 *
306 	 * Returns: a list of content types.
307 	 *
308 	 * Since: 2.34
309 	 */
310 	public string[] getSupportedTypes()
311 	{
312 		return Str.toStringArray(g_app_info_get_supported_types(getAppInfoStruct()));
313 	}
314 
315 	/**
316 	 * Launches the application. Passes @files to the launched application
317 	 * as arguments, using the optional @context to get information
318 	 * about the details of the launcher (like what screen it is on).
319 	 * On error, @error will be set accordingly.
320 	 *
321 	 * To launch the application without arguments pass a %NULL @files list.
322 	 *
323 	 * Note that even if the launch is successful the application launched
324 	 * can fail to start if it runs into problems during startup. There is
325 	 * no way to detect this.
326 	 *
327 	 * Some URIs can be changed when passed through a GFile (for instance
328 	 * unsupported URIs with strange formats like mailto:), so if you have
329 	 * a textual URI you want to pass in as argument, consider using
330 	 * g_app_info_launch_uris() instead.
331 	 *
332 	 * The launched application inherits the environment of the launching
333 	 * process, but it can be modified with g_app_launch_context_setenv()
334 	 * and g_app_launch_context_unsetenv().
335 	 *
336 	 * On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE`
337 	 * environment variable with the path of the launched desktop file and
338 	 * `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched
339 	 * process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`,
340 	 * should it be inherited by further processes. The `DISPLAY` and
341 	 * `DESKTOP_STARTUP_ID` environment variables are also set, based
342 	 * on information provided in @context.
343 	 *
344 	 * Params:
345 	 *     files = a #GList of #GFile objects
346 	 *     context = a #GAppLaunchContext or %NULL
347 	 *
348 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
349 	 *
350 	 * Throws: GException on failure.
351 	 */
352 	public bool launch(ListG files, AppLaunchContext context)
353 	{
354 		GError* err = null;
355 
356 		auto __p = g_app_info_launch(getAppInfoStruct(), (files is null) ? null : files.getListGStruct(), (context is null) ? null : context.getAppLaunchContextStruct(), &err) != 0;
357 
358 		if (err !is null)
359 		{
360 			throw new GException( new ErrorG(err) );
361 		}
362 
363 		return __p;
364 	}
365 
366 	/**
367 	 * Launches the application. This passes the @uris to the launched application
368 	 * as arguments, using the optional @context to get information
369 	 * about the details of the launcher (like what screen it is on).
370 	 * On error, @error will be set accordingly.
371 	 *
372 	 * To launch the application without arguments pass a %NULL @uris list.
373 	 *
374 	 * Note that even if the launch is successful the application launched
375 	 * can fail to start if it runs into problems during startup. There is
376 	 * no way to detect this.
377 	 *
378 	 * Params:
379 	 *     uris = a #GList containing URIs to launch.
380 	 *     context = a #GAppLaunchContext or %NULL
381 	 *
382 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
383 	 *
384 	 * Throws: GException on failure.
385 	 */
386 	public bool launchUris(ListG uris, AppLaunchContext context)
387 	{
388 		GError* err = null;
389 
390 		auto __p = g_app_info_launch_uris(getAppInfoStruct(), (uris is null) ? null : uris.getListGStruct(), (context is null) ? null : context.getAppLaunchContextStruct(), &err) != 0;
391 
392 		if (err !is null)
393 		{
394 			throw new GException( new ErrorG(err) );
395 		}
396 
397 		return __p;
398 	}
399 
400 	/**
401 	 * Async version of g_app_info_launch_uris().
402 	 *
403 	 * The @callback is invoked immediately after the application launch, but it
404 	 * waits for activation in case of D-Bus–activated applications and also provides
405 	 * extended error information for sandboxed applications, see notes for
406 	 * g_app_info_launch_default_for_uri_async().
407 	 *
408 	 * Params:
409 	 *     uris = a #GList containing URIs to launch.
410 	 *     context = a #GAppLaunchContext or %NULL
411 	 *     cancellable = a #GCancellable
412 	 *     callback = a #GAsyncReadyCallback to call when the request is done
413 	 *     userData = data to pass to @callback
414 	 *
415 	 * Since: 2.60
416 	 */
417 	public void launchUrisAsync(ListG uris, AppLaunchContext context, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
418 	{
419 		g_app_info_launch_uris_async(getAppInfoStruct(), (uris is null) ? null : uris.getListGStruct(), (context is null) ? null : context.getAppLaunchContextStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
420 	}
421 
422 	/**
423 	 * Finishes a g_app_info_launch_uris_async() operation.
424 	 *
425 	 * Params:
426 	 *     result = a #GAsyncResult
427 	 *
428 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
429 	 *
430 	 * Since: 2.60
431 	 *
432 	 * Throws: GException on failure.
433 	 */
434 	public bool launchUrisFinish(AsyncResultIF result)
435 	{
436 		GError* err = null;
437 
438 		auto __p = g_app_info_launch_uris_finish(getAppInfoStruct(), (result is null) ? null : result.getAsyncResultStruct(), &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 	 * Removes a supported type from an application, if possible.
450 	 *
451 	 * Params:
452 	 *     contentType = a string.
453 	 *
454 	 * Returns: %TRUE on success, %FALSE on error.
455 	 *
456 	 * Throws: GException on failure.
457 	 */
458 	public bool removeSupportsType(string contentType)
459 	{
460 		GError* err = null;
461 
462 		auto __p = g_app_info_remove_supports_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 default handler for the given file extension.
474 	 *
475 	 * Params:
476 	 *     extension = a string containing the file extension
477 	 *         (without the dot).
478 	 *
479 	 * Returns: %TRUE on success, %FALSE on error.
480 	 *
481 	 * Throws: GException on failure.
482 	 */
483 	public bool setAsDefaultForExtension(string extension)
484 	{
485 		GError* err = null;
486 
487 		auto __p = g_app_info_set_as_default_for_extension(getAppInfoStruct(), Str.toStringz(extension), &err) != 0;
488 
489 		if (err !is null)
490 		{
491 			throw new GException( new ErrorG(err) );
492 		}
493 
494 		return __p;
495 	}
496 
497 	/**
498 	 * Sets the application as the default handler for a given type.
499 	 *
500 	 * Params:
501 	 *     contentType = the content type.
502 	 *
503 	 * Returns: %TRUE on success, %FALSE on error.
504 	 *
505 	 * Throws: GException on failure.
506 	 */
507 	public bool setAsDefaultForType(string contentType)
508 	{
509 		GError* err = null;
510 
511 		auto __p = g_app_info_set_as_default_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0;
512 
513 		if (err !is null)
514 		{
515 			throw new GException( new ErrorG(err) );
516 		}
517 
518 		return __p;
519 	}
520 
521 	/**
522 	 * Sets the application as the last used application for a given type.
523 	 * This will make the application appear as first in the list returned
524 	 * by g_app_info_get_recommended_for_type(), regardless of the default
525 	 * application for that content type.
526 	 *
527 	 * Params:
528 	 *     contentType = the content type.
529 	 *
530 	 * Returns: %TRUE on success, %FALSE on error.
531 	 *
532 	 * Throws: GException on failure.
533 	 */
534 	public bool setAsLastUsedForType(string contentType)
535 	{
536 		GError* err = null;
537 
538 		auto __p = g_app_info_set_as_last_used_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0;
539 
540 		if (err !is null)
541 		{
542 			throw new GException( new ErrorG(err) );
543 		}
544 
545 		return __p;
546 	}
547 
548 	/**
549 	 * Checks if the application info should be shown in menus that
550 	 * list available applications.
551 	 *
552 	 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
553 	 */
554 	public bool shouldShow()
555 	{
556 		return g_app_info_should_show(getAppInfoStruct()) != 0;
557 	}
558 
559 	/**
560 	 * Checks if the application accepts files as arguments.
561 	 *
562 	 * Returns: %TRUE if the @appinfo supports files.
563 	 */
564 	public bool supportsFiles()
565 	{
566 		return g_app_info_supports_files(getAppInfoStruct()) != 0;
567 	}
568 
569 	/**
570 	 * Checks if the application supports reading files and directories from URIs.
571 	 *
572 	 * Returns: %TRUE if the @appinfo supports URIs.
573 	 */
574 	public bool supportsUris()
575 	{
576 		return g_app_info_supports_uris(getAppInfoStruct()) != 0;
577 	}
578 }