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 its 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 * Returns: %TRUE on successful launch, %FALSE otherwise.
412 g_app_info_launch (GAppInfo *appinfo,
414 GAppLaunchContext *launch_context,
417 GAppInfoIface *iface;
419 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
421 iface = G_APP_INFO_GET_IFACE (appinfo);
423 return (* iface->launch) (appinfo, files, launch_context, error);
428 * g_app_info_supports_uris:
429 * @appinfo: a #GAppInfo.
431 * Checks if the application supports reading files and directories from URIs.
433 * Returns: %TRUE if the @appinfo supports URIs.
436 g_app_info_supports_uris (GAppInfo *appinfo)
438 GAppInfoIface *iface;
440 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
442 iface = G_APP_INFO_GET_IFACE (appinfo);
444 return (* iface->supports_uris) (appinfo);
449 * g_app_info_launch_uris:
450 * @appinfo: a #GAppInfo.
451 * @uris: a #GList containing URIs to launch.
452 * @launch_context: a #GAppLaunchContext.
455 * Launches the application. Passes @uris to the launched application
456 * as arguments, using the optional @launch_context to get information
457 * about the details of the launcher (like what screen its is on).
458 * On error, @error will be set accordingly.
460 * To lauch the application without arguments pass a %NULL @uris list.
462 * Note that even if the launch is successful the application launched
463 * can fail to start if it runs into problems during startup. There is
464 * no way to detect this.
466 * Returns: %TRUE on successful launch, %FALSE otherwise.
469 g_app_info_launch_uris (GAppInfo *appinfo,
471 GAppLaunchContext *launch_context,
474 GAppInfoIface *iface;
476 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
478 iface = G_APP_INFO_GET_IFACE (appinfo);
480 return (* iface->launch) (appinfo, uris, launch_context, error);
485 * g_app_info_should_show:
486 * @appinfo: a #GAppInfo.
487 * @desktop_env: A string specifying what desktop this is, or %NULL.
489 * Checks if the application info should be shown when listing
490 * applications available.
492 * @destkop_env is used to hide applications that are specified to
493 * just show up in specific desktops. For instance, passing in "GNOME"
494 * would show all applications specific to the Gnome desktop.
496 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
499 g_app_info_should_show (GAppInfo *appinfo,
500 const char *desktop_env)
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->should_show) (appinfo, desktop_env);
511 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
514 * g_app_launch_context_new:
516 * Creates a new application launch context. This is not normally used,
517 * instead you instantiate a subclass of this, such as #GdkAppLaunchContext.
519 * Returns: a #GAppLaunchContext.
522 g_app_launch_context_new (void)
524 return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
528 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
533 g_app_launch_context_init (GAppLaunchContext *launch_context)
538 * g_app_launch_context_get_display:
539 * @context: a #GAppLaunchContext.
540 * @info: a #GAppInfo.
541 * @files: a #GList of files.
543 * Gets the display string for the display. This is used to ensure new
544 * applications are started on the same display as the launching
547 * Returns: a display string for the display.
550 g_app_launch_context_get_display (GAppLaunchContext *context,
554 GAppLaunchContextClass *class;
556 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
557 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
559 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
561 if (class->get_display == NULL)
564 return class->get_display (context, info, files);
568 * g_app_launch_context_get_startup_notify_id:
569 * @context: a #GAppLaunchContext.
570 * @info: a #GAppInfo.
571 * @files: a #GList of files.
573 * Initiates startup notification for the applicaiont and returns the
574 * DESKTOP_STARTUP_ID for the launched operation, if supported.
576 * Startup notification IDs are defined in the FreeDesktop.Org Startup
577 * Notifications standard, at
578 * <ulink url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt"/>.
580 * Returns: a startup notification ID for the application, or %NULL if
584 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
588 GAppLaunchContextClass *class;
590 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
591 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
593 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
595 if (class->get_startup_notify_id == NULL)
598 return class->get_startup_notify_id (context, info, files);
603 * g_app_launch_context_launch_failed:
604 * @context: a #GAppLaunchContext.
605 * @startup_notify_id: the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
607 * Called when an application has failed to launch, so that it can cancel
608 * the application startup notification started in g_app_launch_context_get_startup_notify_id().
612 g_app_launch_context_launch_failed (GAppLaunchContext *context,
613 const char *startup_notify_id)
615 GAppLaunchContextClass *class;
617 g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
618 g_return_if_fail (startup_notify_id != NULL);
620 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
622 if (class->launch_failed != NULL)
623 class->launch_failed (context, startup_notify_id);
626 #define __G_APP_INFO_C__
627 #include "gioaliasdef.c"