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 * Returns: a string containing the application's ID.
145 g_app_info_get_id (GAppInfo *appinfo)
147 GAppInfoIface *iface;
149 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
151 iface = G_APP_INFO_GET_IFACE (appinfo);
153 return (* iface->get_id) (appinfo);
157 * g_app_info_get_name:
158 * @appinfo: a #GAppInfo.
160 * Gets the installed name of the application.
162 * Returns: the name of the application for @appinfo.
165 g_app_info_get_name (GAppInfo *appinfo)
167 GAppInfoIface *iface;
169 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
171 iface = G_APP_INFO_GET_IFACE (appinfo);
173 return (* iface->get_name) (appinfo);
177 * g_app_info_get_description:
178 * @appinfo: a #GAppInfo.
180 * Gets a human-readable description of an installed application.
182 * Returns: a string containing a description of the
183 * application @appinfo, or %NULL if none. The returned string should be not freed
184 * when no longer needed.
187 g_app_info_get_description (GAppInfo *appinfo)
189 GAppInfoIface *iface;
191 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
193 iface = G_APP_INFO_GET_IFACE (appinfo);
195 return (* iface->get_description) (appinfo);
199 * g_app_info_get_executable:
200 * @appinfo: a #GAppInfo.
202 * Gets the executable's name for the installed application.
204 * Returns: a string containing the @appinfo's application
208 g_app_info_get_executable (GAppInfo *appinfo)
210 GAppInfoIface *iface;
212 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
214 iface = G_APP_INFO_GET_IFACE (appinfo);
216 return (* iface->get_executable) (appinfo);
221 * g_app_info_set_as_default_for_type:
222 * @appinfo: a #GAppInfo.
223 * @content_type: the content type.
226 * Sets the application as the default handler for a given type.
228 * Returns: %TRUE on success, %FALSE on error.
231 g_app_info_set_as_default_for_type (GAppInfo *appinfo,
232 const char *content_type,
235 GAppInfoIface *iface;
237 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
238 g_return_val_if_fail (content_type != NULL, FALSE);
240 iface = G_APP_INFO_GET_IFACE (appinfo);
242 return (* iface->set_as_default_for_type) (appinfo, content_type, error);
247 * g_app_info_set_as_default_for_extension:
248 * @appinfo: a #GAppInfo.
249 * @extension: a string containing the file extension (without the dot).
252 * Sets the application as the default handler for the given file extention.
254 * Returns: %TRUE on success, %FALSE on error.
257 g_app_info_set_as_default_for_extension (GAppInfo *appinfo,
258 const char *extension,
261 GAppInfoIface *iface;
263 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
264 g_return_val_if_fail (extension != NULL, FALSE);
266 iface = G_APP_INFO_GET_IFACE (appinfo);
268 if (iface->set_as_default_for_extension)
269 return (* iface->set_as_default_for_extension) (appinfo, extension, error);
271 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_set_as_default_for_extension not supported yet");
277 * g_app_info_add_supports_type:
278 * @appinfo: a #GAppInfo.
279 * @content_type: a string.
282 * Adds a content type to the application information to indicate the
283 * application is capable of opening files with the given content type.
285 * Returns: %TRUE on success, %FALSE on error.
288 g_app_info_add_supports_type (GAppInfo *appinfo,
289 const char *content_type,
292 GAppInfoIface *iface;
294 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
295 g_return_val_if_fail (content_type != NULL, FALSE);
297 iface = G_APP_INFO_GET_IFACE (appinfo);
299 if (iface->add_supports_type)
300 return (* iface->add_supports_type) (appinfo, content_type, error);
302 g_set_error (error, G_IO_ERROR,
303 G_IO_ERROR_NOT_SUPPORTED,
304 "g_app_info_add_supports_type not supported yet");
311 * g_app_info_can_remove_supports_type:
312 * @appinfo: a #GAppInfo.
314 * Checks if a supported content type can be removed from an application.
316 * Returns: %TRUE if it is possible to remove supported
317 * content types from a given @appinfo, %FALSE if not.
320 g_app_info_can_remove_supports_type (GAppInfo *appinfo)
322 GAppInfoIface *iface;
324 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
326 iface = G_APP_INFO_GET_IFACE (appinfo);
328 if (iface->can_remove_supports_type)
329 return (* iface->can_remove_supports_type) (appinfo);
336 * g_app_info_remove_supports_type:
337 * @appinfo: a #GAppInfo.
338 * @content_type: a string.
341 * Removes a supported type from an application, if possible.
343 * Returns: %TRUE on success, %FALSE on error.
346 g_app_info_remove_supports_type (GAppInfo *appinfo,
347 const char *content_type,
350 GAppInfoIface *iface;
352 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
353 g_return_val_if_fail (content_type != NULL, FALSE);
355 iface = G_APP_INFO_GET_IFACE (appinfo);
357 if (iface->remove_supports_type)
358 return (* iface->remove_supports_type) (appinfo, content_type, error);
360 g_set_error (error, G_IO_ERROR,
361 G_IO_ERROR_NOT_SUPPORTED,
362 "g_app_info_remove_supports_type not supported yet");
369 * g_app_info_get_icon:
370 * @appinfo: a #GAppInfo.
372 * Gets the icon for the application.
374 * Returns: the default #GIcon for @appinfo.
377 g_app_info_get_icon (GAppInfo *appinfo)
379 GAppInfoIface *iface;
381 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
383 iface = G_APP_INFO_GET_IFACE (appinfo);
385 return (* iface->get_icon) (appinfo);
391 * @appinfo: a #GAppInfo.
392 * @files: a #GList of #GFile objects.
393 * @launch_context: a #GAppLaunchContext.
396 * Launches the application. Passes @files to the launched application
397 * as arguments, using the optional @launch_context to get information
398 * about the details of the launcher (like what screen its is on).
399 * On error, @error will be set accordingly.
401 * To lauch the application without arguments pass a %NULL @files list.
403 * Note that even if the launch is successful the application launched
404 * can fail to start if it runs into problems during startup. There is
405 * no way to detect this.
407 * Returns: %TRUE on successful launch, %FALSE otherwise.
410 g_app_info_launch (GAppInfo *appinfo,
412 GAppLaunchContext *launch_context,
415 GAppInfoIface *iface;
417 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
419 iface = G_APP_INFO_GET_IFACE (appinfo);
421 return (* iface->launch) (appinfo, files, launch_context, error);
426 * g_app_info_supports_uris:
427 * @appinfo: a #GAppInfo.
429 * Checks if the application supports reading files and directories from URIs.
431 * Returns: %TRUE if the @appinfo supports URIs.
434 g_app_info_supports_uris (GAppInfo *appinfo)
436 GAppInfoIface *iface;
438 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
440 iface = G_APP_INFO_GET_IFACE (appinfo);
442 return (* iface->supports_uris) (appinfo);
447 * g_app_info_launch_uris:
448 * @appinfo: a #GAppInfo.
449 * @uris: a #GList containing URIs to launch.
450 * @launch_context: a #GAppLaunchContext.
453 * Launches the application. Passes @uris to the launched application
454 * as arguments, using the optional @launch_context to get information
455 * about the details of the launcher (like what screen its is on).
456 * On error, @error will be set accordingly.
458 * To lauch the application without arguments pass a %NULL @uris list.
460 * Note that even if the launch is successful the application launched
461 * can fail to start if it runs into problems during startup. There is
462 * no way to detect this.
464 * Returns: %TRUE on successful launch, %FALSE otherwise.
467 g_app_info_launch_uris (GAppInfo *appinfo,
469 GAppLaunchContext *launch_context,
472 GAppInfoIface *iface;
474 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
476 iface = G_APP_INFO_GET_IFACE (appinfo);
478 return (* iface->launch) (appinfo, uris, launch_context, error);
483 * g_app_info_should_show:
484 * @appinfo: a #GAppInfo.
485 * @desktop_env: A string specifying what desktop this is, or %NULL.
487 * Checks if the application info should be shown when listing
488 * applications available.
490 * @destkop_env is used to hide applications that are specified to
491 * just show up in specific desktops. For instance, passing in "GNOME"
492 * would show all applications specific to the Gnome desktop.
494 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
497 g_app_info_should_show (GAppInfo *appinfo,
498 const char *desktop_env)
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->should_show) (appinfo, desktop_env);
509 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
512 * g_app_launch_context_new:
514 * Creates a new application launch context. This is not normally used,
515 * instead you instantiate a subclass of this, such as GdkLaunchContext.
517 * Returns: a #GAppLaunchContext.
520 g_app_launch_context_new (void)
522 return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
526 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
531 g_app_launch_context_init (GAppLaunchContext *launch_context)
536 * g_app_launch_context_get_display:
537 * @context: a #GAppLaunchContext.
538 * @info: a #GAppInfo.
539 * @files: a #GList of files.
541 * Gets the display string for the display. This is used to ensure new
542 * applications are started on the same display as the launching
545 * Returns: a display string for the display.
548 g_app_launch_context_get_display (GAppLaunchContext *context,
552 GAppLaunchContextClass *class;
554 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
555 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
557 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
559 if (class->get_display == NULL)
562 return class->get_display (context, info, files);
566 * g_app_launch_context_get_startup_notify_id:
567 * @context: a #GAppLaunchContext.
568 * @info: a #GAppInfo.
569 * @files: a #GList of files.
571 * Initiates startup notification for the applicaiont and returns the
572 * DESKTOP_STARTUP_ID for the launched operation, if supported.
574 * Startup notification IDs are defined in the FreeDesktop.Org Startup
575 * Notifications standard, at
576 * <ulink url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt"/>.
578 * Returns: a startup notification ID for the application, or %NULL if
582 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
586 GAppLaunchContextClass *class;
588 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
589 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
591 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
593 if (class->get_startup_notify_id == NULL)
596 return class->get_startup_notify_id (context, info, files);
601 * g_app_launch_context_launch_failed:
602 * @context: a #GAppLaunchContext.
603 * @startup_notify_id: the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
605 * Called when an application has failed to launch, so that it can cancel
606 * the application startup notification started in g_app_launch_context_get_startup_notify_id().
610 g_app_launch_context_launch_failed (GAppLaunchContext *context,
611 const char *startup_notify_id)
613 GAppLaunchContextClass *class;
615 g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
616 g_return_if_fail (startup_notify_id != NULL);
618 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
620 if (class->launch_failed != NULL)
621 class->launch_failed (context, startup_notify_id);
624 #define __G_APP_INFO_C__
625 #include "gioaliasdef.c"