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>
33 * @short_description: Application information and launch contexts
36 * #GAppInfo and #GAppLaunchContext are used for describing and launching
37 * applications installed on the system.
41 static void g_app_info_base_init (gpointer g_class);
42 static void g_app_info_class_init (gpointer g_class,
47 g_app_info_get_type (void)
49 static GType app_info_type = 0;
53 static const GTypeInfo app_info_info =
55 sizeof (GAppInfoIface), /* class_size */
56 g_app_info_base_init, /* base_init */
57 NULL, /* base_finalize */
58 g_app_info_class_init,
59 NULL, /* class_finalize */
60 NULL, /* class_data */
67 g_type_register_static (G_TYPE_INTERFACE, I_("GAppInfo"),
70 g_type_interface_add_prerequisite (app_info_type, G_TYPE_OBJECT);
77 g_app_info_class_init (gpointer g_class,
83 g_app_info_base_init (gpointer g_class)
90 * @appinfo: a #GAppInfo.
92 * Creates a duplicate of a #GAppInfo.
94 * Returns: a duplicate of @appinfo.
97 g_app_info_dup (GAppInfo *appinfo)
101 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
103 iface = G_APP_INFO_GET_IFACE (appinfo);
105 return (* iface->dup) (appinfo);
110 * @appinfo1: the first #GAppInfo.
111 * @appinfo2: the second #GAppInfo.
113 * Checks if two #GAppInfos are equal.
115 * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
118 g_app_info_equal (GAppInfo *appinfo1,
121 GAppInfoIface *iface;
123 g_return_val_if_fail (G_IS_APP_INFO (appinfo1), FALSE);
124 g_return_val_if_fail (G_IS_APP_INFO (appinfo2), FALSE);
126 if (G_TYPE_FROM_INSTANCE (appinfo1) != G_TYPE_FROM_INSTANCE (appinfo2))
129 iface = G_APP_INFO_GET_IFACE (appinfo1);
131 return (* iface->equal) (appinfo1, appinfo2);
136 * @appinfo: a #GAppInfo.
138 * Gets the ID of an application. An id is a string that
139 * identifies the application. The exact format of the id is
140 * platform dependent. For instance, on Unix this is the
141 * desktop file id from the xdg menu specification.
143 * Note that the returned ID may be %NULL, depending on how
144 * the @appinfo has been constructed.
146 * Returns: a string containing the application's ID.
149 g_app_info_get_id (GAppInfo *appinfo)
151 GAppInfoIface *iface;
153 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
155 iface = G_APP_INFO_GET_IFACE (appinfo);
157 return (* iface->get_id) (appinfo);
161 * g_app_info_get_name:
162 * @appinfo: a #GAppInfo.
164 * Gets the installed name of the application.
166 * Returns: the name of the application for @appinfo.
169 g_app_info_get_name (GAppInfo *appinfo)
171 GAppInfoIface *iface;
173 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
175 iface = G_APP_INFO_GET_IFACE (appinfo);
177 return (* iface->get_name) (appinfo);
181 * g_app_info_get_description:
182 * @appinfo: a #GAppInfo.
184 * Gets a human-readable description of an installed application.
186 * Returns: a string containing a description of the
187 * application @appinfo, or %NULL if none.
190 g_app_info_get_description (GAppInfo *appinfo)
192 GAppInfoIface *iface;
194 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
196 iface = G_APP_INFO_GET_IFACE (appinfo);
198 return (* iface->get_description) (appinfo);
202 * g_app_info_get_executable:
203 * @appinfo: a #GAppInfo.
205 * Gets the executable's name for the installed application.
207 * Returns: a string containing the @appinfo's application
211 g_app_info_get_executable (GAppInfo *appinfo)
213 GAppInfoIface *iface;
215 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
217 iface = G_APP_INFO_GET_IFACE (appinfo);
219 return (* iface->get_executable) (appinfo);
224 * g_app_info_set_as_default_for_type:
225 * @appinfo: a #GAppInfo.
226 * @content_type: the content type.
229 * Sets the application as the default handler for a given type.
231 * Returns: %TRUE on success, %FALSE on error.
234 g_app_info_set_as_default_for_type (GAppInfo *appinfo,
235 const char *content_type,
238 GAppInfoIface *iface;
240 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
241 g_return_val_if_fail (content_type != NULL, FALSE);
243 iface = G_APP_INFO_GET_IFACE (appinfo);
245 return (* iface->set_as_default_for_type) (appinfo, content_type, error);
250 * g_app_info_set_as_default_for_extension:
251 * @appinfo: a #GAppInfo.
252 * @extension: a string containing the file extension (without the dot).
255 * Sets the application as the default handler for the given file extention.
257 * Returns: %TRUE on success, %FALSE on error.
260 g_app_info_set_as_default_for_extension (GAppInfo *appinfo,
261 const char *extension,
264 GAppInfoIface *iface;
266 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
267 g_return_val_if_fail (extension != NULL, FALSE);
269 iface = G_APP_INFO_GET_IFACE (appinfo);
271 if (iface->set_as_default_for_extension)
272 return (* iface->set_as_default_for_extension) (appinfo, extension, error);
274 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
275 "g_app_info_set_as_default_for_extension not supported yet");
281 * g_app_info_add_supports_type:
282 * @appinfo: a #GAppInfo.
283 * @content_type: a string.
286 * Adds a content type to the application information to indicate the
287 * application is capable of opening files with the given content type.
289 * Returns: %TRUE on success, %FALSE on error.
292 g_app_info_add_supports_type (GAppInfo *appinfo,
293 const char *content_type,
296 GAppInfoIface *iface;
298 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
299 g_return_val_if_fail (content_type != NULL, FALSE);
301 iface = G_APP_INFO_GET_IFACE (appinfo);
303 if (iface->add_supports_type)
304 return (* iface->add_supports_type) (appinfo, content_type, error);
306 g_set_error_literal (error, G_IO_ERROR,
307 G_IO_ERROR_NOT_SUPPORTED,
308 "g_app_info_add_supports_type not supported yet");
315 * g_app_info_can_remove_supports_type:
316 * @appinfo: a #GAppInfo.
318 * Checks if a supported content type can be removed from an application.
320 * Returns: %TRUE if it is possible to remove supported
321 * content types from a given @appinfo, %FALSE if not.
324 g_app_info_can_remove_supports_type (GAppInfo *appinfo)
326 GAppInfoIface *iface;
328 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
330 iface = G_APP_INFO_GET_IFACE (appinfo);
332 if (iface->can_remove_supports_type)
333 return (* iface->can_remove_supports_type) (appinfo);
340 * g_app_info_remove_supports_type:
341 * @appinfo: a #GAppInfo.
342 * @content_type: a string.
345 * Removes a supported type from an application, if possible.
347 * Returns: %TRUE on success, %FALSE on error.
350 g_app_info_remove_supports_type (GAppInfo *appinfo,
351 const char *content_type,
354 GAppInfoIface *iface;
356 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
357 g_return_val_if_fail (content_type != NULL, FALSE);
359 iface = G_APP_INFO_GET_IFACE (appinfo);
361 if (iface->remove_supports_type)
362 return (* iface->remove_supports_type) (appinfo, content_type, error);
364 g_set_error_literal (error, G_IO_ERROR,
365 G_IO_ERROR_NOT_SUPPORTED,
366 "g_app_info_remove_supports_type not supported yet");
373 * g_app_info_get_icon:
374 * @appinfo: a #GAppInfo.
376 * Gets the icon for the application.
378 * Returns: the default #GIcon for @appinfo.
381 g_app_info_get_icon (GAppInfo *appinfo)
383 GAppInfoIface *iface;
385 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
387 iface = G_APP_INFO_GET_IFACE (appinfo);
389 return (* iface->get_icon) (appinfo);
395 * @appinfo: a #GAppInfo.
396 * @files: a #GList of #GFile objects.
397 * @launch_context: a #GAppLaunchContext.
400 * Launches the application. Passes @files to the launched application
401 * as arguments, using the optional @launch_context to get information
402 * about the details of the launcher (like what screen it is on).
403 * On error, @error will be set accordingly.
405 * To lauch the application without arguments pass a %NULL @files list.
407 * Note that even if the launch is successful the application launched
408 * can fail to start if it runs into problems during startup. There is
409 * no way to detect this.
411 * Some URIs can be changed when passed through a GFile (for instance
412 * unsupported uris with strange formats like mailto:), so if you have
413 * a textual uri you want to pass in as argument, consider using
414 * g_app_info_launch_uris() instead.
416 * Returns: %TRUE on successful launch, %FALSE otherwise.
419 g_app_info_launch (GAppInfo *appinfo,
421 GAppLaunchContext *launch_context,
424 GAppInfoIface *iface;
426 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
428 iface = G_APP_INFO_GET_IFACE (appinfo);
430 return (* iface->launch) (appinfo, files, launch_context, error);
435 * g_app_info_supports_uris:
436 * @appinfo: a #GAppInfo.
438 * Checks if the application supports reading files and directories from URIs.
440 * Returns: %TRUE if the @appinfo supports URIs.
443 g_app_info_supports_uris (GAppInfo *appinfo)
445 GAppInfoIface *iface;
447 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
449 iface = G_APP_INFO_GET_IFACE (appinfo);
451 return (* iface->supports_uris) (appinfo);
456 * g_app_info_supports_files:
457 * @appinfo: a #GAppInfo.
459 * Checks if the application accepts files as arguments.
461 * Returns: %TRUE if the @appinfo supports files.
464 g_app_info_supports_files (GAppInfo *appinfo)
466 GAppInfoIface *iface;
468 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
470 iface = G_APP_INFO_GET_IFACE (appinfo);
472 return (* iface->supports_files) (appinfo);
477 * g_app_info_launch_uris:
478 * @appinfo: a #GAppInfo.
479 * @uris: a #GList containing URIs to launch.
480 * @launch_context: a #GAppLaunchContext.
483 * Launches the application. Passes @uris to the launched application
484 * as arguments, using the optional @launch_context to get information
485 * about the details of the launcher (like what screen it is on).
486 * On error, @error will be set accordingly.
488 * To lauch the application without arguments pass a %NULL @uris list.
490 * Note that even if the launch is successful the application launched
491 * can fail to start if it runs into problems during startup. There is
492 * no way to detect this.
494 * Returns: %TRUE on successful launch, %FALSE otherwise.
497 g_app_info_launch_uris (GAppInfo *appinfo,
499 GAppLaunchContext *launch_context,
502 GAppInfoIface *iface;
504 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
506 iface = G_APP_INFO_GET_IFACE (appinfo);
508 return (* iface->launch_uris) (appinfo, uris, launch_context, error);
513 * g_app_info_should_show:
514 * @appinfo: a #GAppInfo.
516 * Checks if the application info should be shown in menus that
517 * list available applications.
519 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
522 g_app_info_should_show (GAppInfo *appinfo)
524 GAppInfoIface *iface;
526 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
528 iface = G_APP_INFO_GET_IFACE (appinfo);
530 return (* iface->should_show) (appinfo);
534 * g_app_info_launch_default_for_uri:
535 * @uri: the uri to show
536 * @launch_context: an optional #GAppLaunchContext.
539 * Utility function that launches the default application
540 * registered to handle the specified uri. Synchronous I/O
541 * is done on the uri to detext the type of the file if
544 * Returns: %TRUE on success, %FALSE on error.
547 g_app_info_launch_default_for_uri (const char *uri,
548 GAppLaunchContext *launch_context,
556 file = g_file_new_for_uri (uri);
557 app_info = g_file_query_default_handler (file, NULL, error);
558 g_object_unref (file);
559 if (app_info == NULL)
562 /* Use the uri, not the GFile, as the GFile roundtrip may
563 * affect the uri which we don't want (for instance for a
566 l.data = (char *)uri;
567 l.next = l.prev = NULL;
568 res = g_app_info_launch_uris (app_info, &l,
569 launch_context, error);
571 g_object_unref (app_info);
577 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
580 * g_app_launch_context_new:
582 * Creates a new application launch context. This is not normally used,
583 * instead you instantiate a subclass of this, such as #GdkAppLaunchContext.
585 * Returns: a #GAppLaunchContext.
588 g_app_launch_context_new (void)
590 return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
594 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
599 g_app_launch_context_init (GAppLaunchContext *launch_context)
604 * g_app_launch_context_get_display:
605 * @context: a #GAppLaunchContext.
606 * @info: a #GAppInfo.
607 * @files: a #GList of @GFile<!-- -->s.
609 * Gets the display string for the display. This is used to ensure new
610 * applications are started on the same display as the launching
613 * Returns: a display string for the display.
616 g_app_launch_context_get_display (GAppLaunchContext *context,
620 GAppLaunchContextClass *class;
622 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
623 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
625 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
627 if (class->get_display == NULL)
630 return class->get_display (context, info, files);
634 * g_app_launch_context_get_startup_notify_id:
635 * @context: a #GAppLaunchContext.
636 * @info: a #GAppInfo.
637 * @files: a #GList of files.
639 * Initiates startup notification for the application and returns the
640 * DESKTOP_STARTUP_ID for the launched operation, if supported.
642 * Startup notification IDs are defined in the <ulink
643 * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">
644 * FreeDesktop.Org Startup Notifications standard</ulink>.
646 * Returns: a startup notification ID for the application, or %NULL if
650 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
654 GAppLaunchContextClass *class;
656 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
657 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
659 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
661 if (class->get_startup_notify_id == NULL)
664 return class->get_startup_notify_id (context, info, files);
669 * g_app_launch_context_launch_failed:
670 * @context: a #GAppLaunchContext.
671 * @startup_notify_id: the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
673 * Called when an application has failed to launch, so that it can cancel
674 * the application startup notification started in g_app_launch_context_get_startup_notify_id().
678 g_app_launch_context_launch_failed (GAppLaunchContext *context,
679 const char *startup_notify_id)
681 GAppLaunchContextClass *class;
683 g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
684 g_return_if_fail (startup_notify_id != NULL);
686 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
688 if (class->launch_failed != NULL)
689 class->launch_failed (context, startup_notify_id);
692 #define __G_APP_INFO_C__
693 #include "gioaliasdef.c"