1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
32 * @short_description: Application information and launch contexts
35 * #GAppInfo and #GAppLaunchContext are used for describing and launching
36 * applications installed on the system.
40 static void g_app_info_base_init (gpointer g_class);
41 static void g_app_info_class_init (gpointer g_class,
46 g_app_info_get_type (void)
48 static GType app_info_type = 0;
52 static const GTypeInfo app_info_info =
54 sizeof (GAppInfoIface), /* class_size */
55 g_app_info_base_init, /* base_init */
56 NULL, /* base_finalize */
57 g_app_info_class_init,
58 NULL, /* class_finalize */
59 NULL, /* class_data */
66 g_type_register_static (G_TYPE_INTERFACE, I_("GAppInfo"),
69 g_type_interface_add_prerequisite (app_info_type, G_TYPE_OBJECT);
76 g_app_info_class_init (gpointer g_class,
82 g_app_info_base_init (gpointer g_class)
89 * @appinfo: a #GAppInfo.
91 * Creates a duplicate of a #GAppInfo.
93 * Returns: a duplicate of @appinfo.
96 g_app_info_dup (GAppInfo *appinfo)
100 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
102 iface = G_APP_INFO_GET_IFACE (appinfo);
104 return (* iface->dup) (appinfo);
109 * @appinfo1: the first #GAppInfo.
110 * @appinfo2: the second #GAppInfo.
112 * Checks if two #GAppInfos are equal.
114 * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
117 g_app_info_equal (GAppInfo *appinfo1,
120 GAppInfoIface *iface;
122 g_return_val_if_fail (G_IS_APP_INFO (appinfo1), FALSE);
123 g_return_val_if_fail (G_IS_APP_INFO (appinfo2), FALSE);
125 if (G_TYPE_FROM_INSTANCE (appinfo1) != G_TYPE_FROM_INSTANCE (appinfo2))
128 iface = G_APP_INFO_GET_IFACE (appinfo1);
130 return (* iface->equal) (appinfo1, appinfo2);
135 * @appinfo: a #GAppInfo.
137 * Gets the ID of an application. An id is a string that
138 * identifies the application. The exact format of the id is
139 * platform dependent. For instance, on Unix this is the
140 * desktop file id from the xdg menu specification.
142 * Note that the returned ID may be %NULL, depending on how
143 * the @appinfo has been constructed.
145 * Returns: a string containing the application's ID.
148 g_app_info_get_id (GAppInfo *appinfo)
150 GAppInfoIface *iface;
152 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
154 iface = G_APP_INFO_GET_IFACE (appinfo);
156 return (* iface->get_id) (appinfo);
160 * g_app_info_get_name:
161 * @appinfo: a #GAppInfo.
163 * Gets the installed name of the application.
165 * Returns: the name of the application for @appinfo.
168 g_app_info_get_name (GAppInfo *appinfo)
170 GAppInfoIface *iface;
172 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
174 iface = G_APP_INFO_GET_IFACE (appinfo);
176 return (* iface->get_name) (appinfo);
180 * g_app_info_get_description:
181 * @appinfo: a #GAppInfo.
183 * Gets a human-readable description of an installed application.
185 * Returns: a string containing a description of the
186 * application @appinfo, or %NULL if none.
189 g_app_info_get_description (GAppInfo *appinfo)
191 GAppInfoIface *iface;
193 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
195 iface = G_APP_INFO_GET_IFACE (appinfo);
197 return (* iface->get_description) (appinfo);
201 * g_app_info_get_executable:
202 * @appinfo: a #GAppInfo.
204 * Gets the executable's name for the installed application.
206 * Returns: a string containing the @appinfo's application
210 g_app_info_get_executable (GAppInfo *appinfo)
212 GAppInfoIface *iface;
214 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
216 iface = G_APP_INFO_GET_IFACE (appinfo);
218 return (* iface->get_executable) (appinfo);
223 * g_app_info_set_as_default_for_type:
224 * @appinfo: a #GAppInfo.
225 * @content_type: the content type.
228 * Sets the application as the default handler for a given type.
230 * Returns: %TRUE on success, %FALSE on error.
233 g_app_info_set_as_default_for_type (GAppInfo *appinfo,
234 const char *content_type,
237 GAppInfoIface *iface;
239 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
240 g_return_val_if_fail (content_type != NULL, FALSE);
242 iface = G_APP_INFO_GET_IFACE (appinfo);
244 return (* iface->set_as_default_for_type) (appinfo, content_type, error);
249 * g_app_info_set_as_default_for_extension:
250 * @appinfo: a #GAppInfo.
251 * @extension: a string containing the file extension (without the dot).
254 * Sets the application as the default handler for the given file extention.
256 * Returns: %TRUE on success, %FALSE on error.
259 g_app_info_set_as_default_for_extension (GAppInfo *appinfo,
260 const char *extension,
263 GAppInfoIface *iface;
265 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
266 g_return_val_if_fail (extension != NULL, FALSE);
268 iface = G_APP_INFO_GET_IFACE (appinfo);
270 if (iface->set_as_default_for_extension)
271 return (* iface->set_as_default_for_extension) (appinfo, extension, error);
273 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_set_as_default_for_extension not supported yet");
279 * g_app_info_add_supports_type:
280 * @appinfo: a #GAppInfo.
281 * @content_type: a string.
284 * Adds a content type to the application information to indicate the
285 * application is capable of opening files with the given content type.
287 * Returns: %TRUE on success, %FALSE on error.
290 g_app_info_add_supports_type (GAppInfo *appinfo,
291 const char *content_type,
294 GAppInfoIface *iface;
296 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
297 g_return_val_if_fail (content_type != NULL, FALSE);
299 iface = G_APP_INFO_GET_IFACE (appinfo);
301 if (iface->add_supports_type)
302 return (* iface->add_supports_type) (appinfo, content_type, error);
304 g_set_error (error, G_IO_ERROR,
305 G_IO_ERROR_NOT_SUPPORTED,
306 "g_app_info_add_supports_type not supported yet");
313 * g_app_info_can_remove_supports_type:
314 * @appinfo: a #GAppInfo.
316 * Checks if a supported content type can be removed from an application.
318 * Returns: %TRUE if it is possible to remove supported
319 * content types from a given @appinfo, %FALSE if not.
322 g_app_info_can_remove_supports_type (GAppInfo *appinfo)
324 GAppInfoIface *iface;
326 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
328 iface = G_APP_INFO_GET_IFACE (appinfo);
330 if (iface->can_remove_supports_type)
331 return (* iface->can_remove_supports_type) (appinfo);
338 * g_app_info_remove_supports_type:
339 * @appinfo: a #GAppInfo.
340 * @content_type: a string.
343 * Removes a supported type from an application, if possible.
345 * Returns: %TRUE on success, %FALSE on error.
348 g_app_info_remove_supports_type (GAppInfo *appinfo,
349 const char *content_type,
352 GAppInfoIface *iface;
354 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
355 g_return_val_if_fail (content_type != NULL, FALSE);
357 iface = G_APP_INFO_GET_IFACE (appinfo);
359 if (iface->remove_supports_type)
360 return (* iface->remove_supports_type) (appinfo, content_type, error);
362 g_set_error (error, G_IO_ERROR,
363 G_IO_ERROR_NOT_SUPPORTED,
364 "g_app_info_remove_supports_type not supported yet");
371 * g_app_info_get_icon:
372 * @appinfo: a #GAppInfo.
374 * Gets the icon for the application.
376 * Returns: the default #GIcon for @appinfo.
379 g_app_info_get_icon (GAppInfo *appinfo)
381 GAppInfoIface *iface;
383 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
385 iface = G_APP_INFO_GET_IFACE (appinfo);
387 return (* iface->get_icon) (appinfo);
393 * @appinfo: a #GAppInfo.
394 * @files: a #GList of #GFile objects.
395 * @launch_context: a #GAppLaunchContext.
398 * Launches the application. Passes @files to the launched application
399 * as arguments, using the optional @launch_context to get information
400 * about the details of the launcher (like what screen it is on).
401 * On error, @error will be set accordingly.
403 * To lauch the application without arguments pass a %NULL @files list.
405 * Note that even if the launch is successful the application launched
406 * can fail to start if it runs into problems during startup. There is
407 * no way to detect this.
409 * Some URIs can be changed when passed through a GFile (for instance
410 * unsupported uris with strange formats like mailto:), so if you have
411 * a textual uri you want to pass in as argument, consider using
412 * g_app_info_launch_uris() instead.
414 * Returns: %TRUE on successful launch, %FALSE otherwise.
417 g_app_info_launch (GAppInfo *appinfo,
419 GAppLaunchContext *launch_context,
422 GAppInfoIface *iface;
424 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
426 iface = G_APP_INFO_GET_IFACE (appinfo);
428 return (* iface->launch) (appinfo, files, launch_context, error);
433 * g_app_info_supports_uris:
434 * @appinfo: a #GAppInfo.
436 * Checks if the application supports reading files and directories from URIs.
438 * Returns: %TRUE if the @appinfo supports URIs.
441 g_app_info_supports_uris (GAppInfo *appinfo)
443 GAppInfoIface *iface;
445 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
447 iface = G_APP_INFO_GET_IFACE (appinfo);
449 return (* iface->supports_uris) (appinfo);
454 * g_app_info_supports_files:
455 * @appinfo: a #GAppInfo.
457 * Checks if the application accepts files as arguments.
459 * Returns: %TRUE if the @appinfo supports files.
462 g_app_info_supports_files (GAppInfo *appinfo)
464 GAppInfoIface *iface;
466 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
468 iface = G_APP_INFO_GET_IFACE (appinfo);
470 return (* iface->supports_files) (appinfo);
475 * g_app_info_launch_uris:
476 * @appinfo: a #GAppInfo.
477 * @uris: a #GList containing URIs to launch.
478 * @launch_context: a #GAppLaunchContext.
481 * Launches the application. Passes @uris to the launched application
482 * as arguments, using the optional @launch_context to get information
483 * about the details of the launcher (like what screen it is on).
484 * On error, @error will be set accordingly.
486 * To lauch the application without arguments pass a %NULL @uris list.
488 * Note that even if the launch is successful the application launched
489 * can fail to start if it runs into problems during startup. There is
490 * no way to detect this.
492 * Returns: %TRUE on successful launch, %FALSE otherwise.
495 g_app_info_launch_uris (GAppInfo *appinfo,
497 GAppLaunchContext *launch_context,
500 GAppInfoIface *iface;
502 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
504 iface = G_APP_INFO_GET_IFACE (appinfo);
506 return (* iface->launch) (appinfo, uris, launch_context, error);
511 * g_app_info_should_show:
512 * @appinfo: a #GAppInfo.
514 * Checks if the application info should be shown in menus that
515 * list available applications.
517 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
520 g_app_info_should_show (GAppInfo *appinfo)
522 GAppInfoIface *iface;
524 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
526 iface = G_APP_INFO_GET_IFACE (appinfo);
528 return (* iface->should_show) (appinfo);
532 * g_app_info_launch_default_for_uri:
533 * @uri: the uri to show
534 * @context: an optional #GAppLaunchContext.
537 * Utility function that launches the default application
538 * registered to handle the specified uri. Synchronous I/O
539 * is done on the uri to detext the type of the file if
542 * Returns: %TRUE on success, %FALSE on error.
545 g_app_info_launch_default_for_uri (const char *uri,
546 GAppLaunchContext *launch_context,
554 file = g_file_new_for_uri (uri);
555 app_info = g_file_query_default_handler (file, NULL, error);
556 g_object_unref (file);
557 if (app_info == NULL)
560 /* Use the uri, not the GFile, as the GFile roundtrip may
561 * affect the uri which we don't want (for instance for a
565 l.next = l.prev = NULL;
566 res = g_app_info_launch_uris (app_info, &l,
567 launch_context, error);
572 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
575 * g_app_launch_context_new:
577 * Creates a new application launch context. This is not normally used,
578 * instead you instantiate a subclass of this, such as #GdkAppLaunchContext.
580 * Returns: a #GAppLaunchContext.
583 g_app_launch_context_new (void)
585 return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
589 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
594 g_app_launch_context_init (GAppLaunchContext *launch_context)
599 * g_app_launch_context_get_display:
600 * @context: a #GAppLaunchContext.
601 * @info: a #GAppInfo.
602 * @files: a #GList of files.
604 * Gets the display string for the display. This is used to ensure new
605 * applications are started on the same display as the launching
608 * Returns: a display string for the display.
611 g_app_launch_context_get_display (GAppLaunchContext *context,
615 GAppLaunchContextClass *class;
617 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
618 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
620 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
622 if (class->get_display == NULL)
625 return class->get_display (context, info, files);
629 * g_app_launch_context_get_startup_notify_id:
630 * @context: a #GAppLaunchContext.
631 * @info: a #GAppInfo.
632 * @files: a #GList of files.
634 * Initiates startup notification for the applicaiont and returns the
635 * DESKTOP_STARTUP_ID for the launched operation, if supported.
637 * Startup notification IDs are defined in the FreeDesktop.Org Startup
638 * Notifications standard, at
639 * <ulink url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt"/>.
641 * Returns: a startup notification ID for the application, or %NULL if
645 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
649 GAppLaunchContextClass *class;
651 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
652 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
654 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
656 if (class->get_startup_notify_id == NULL)
659 return class->get_startup_notify_id (context, info, files);
664 * g_app_launch_context_launch_failed:
665 * @context: a #GAppLaunchContext.
666 * @startup_notify_id: the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
668 * Called when an application has failed to launch, so that it can cancel
669 * the application startup notification started in g_app_launch_context_get_startup_notify_id().
673 g_app_launch_context_launch_failed (GAppLaunchContext *context,
674 const char *startup_notify_id)
676 GAppLaunchContextClass *class;
678 g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
679 g_return_if_fail (startup_notify_id != NULL);
681 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
683 if (class->launch_failed != NULL)
684 class->launch_failed (context, startup_notify_id);
687 #define __G_APP_INFO_C__
688 #include "gioaliasdef.c"