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
33 * @stability: Unstable
35 * #GAppInfo and #GAppLaunchContext are used for describing and launching
36 * installed system applications.
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.
139 * Returns: a string containing the application's ID.
142 g_app_info_get_id (GAppInfo *appinfo)
144 GAppInfoIface *iface;
146 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
148 iface = G_APP_INFO_GET_IFACE (appinfo);
150 return (* iface->get_id) (appinfo);
154 * g_app_info_get_name:
155 * @appinfo: a #GAppInfo.
157 * Gets the installed name of the application.
159 * Returns: the name of the application for @appinfo.
162 g_app_info_get_name (GAppInfo *appinfo)
164 GAppInfoIface *iface;
166 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
168 iface = G_APP_INFO_GET_IFACE (appinfo);
170 return (* iface->get_name) (appinfo);
174 * g_app_info_get_description:
175 * @appinfo: a #GAppInfo.
177 * Gets a human-readable description of an installed application.
179 * Returns: a string containing a description of the
180 * application @appinfo. The returned string should be not freed
181 * when no longer needed.
184 g_app_info_get_description (GAppInfo *appinfo)
186 GAppInfoIface *iface;
188 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
190 iface = G_APP_INFO_GET_IFACE (appinfo);
192 return (* iface->get_description) (appinfo);
196 * g_app_info_get_executable:
197 * @appinfo: a #GAppInfo.
199 * Gets the executable's name for the installed application.
201 * Returns: a string containing the @appinfo's application
205 g_app_info_get_executable (GAppInfo *appinfo)
207 GAppInfoIface *iface;
209 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
211 iface = G_APP_INFO_GET_IFACE (appinfo);
213 return (* iface->get_executable) (appinfo);
218 * g_app_info_set_as_default_for_type:
219 * @appinfo: a #GAppInfo.
220 * @content_type: the content type.
223 * Sets an application as the default handler for a given type.
225 * Returns: %TRUE if the given @appinfo is the default
226 * for the given @content_type. %FALSE if not,
227 * or in case of an error.
230 g_app_info_set_as_default_for_type (GAppInfo *appinfo,
231 const char *content_type,
234 GAppInfoIface *iface;
236 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
237 g_return_val_if_fail (content_type != NULL, FALSE);
239 iface = G_APP_INFO_GET_IFACE (appinfo);
241 return (* iface->set_as_default_for_type) (appinfo, content_type, error);
246 * g_app_info_set_as_default_for_extension:
247 * @appinfo: a #GAppInfo.
248 * @extension: a string containing the file extension.
251 * Sets an application as the default handler for the given file extention.
253 * Returns: %TRUE if the given @appinfo is the default
254 * for the given @extension. %FALSE if not,
255 * or in case of an error.
258 g_app_info_set_as_default_for_extension (GAppInfo *appinfo,
259 const char *extension,
262 GAppInfoIface *iface;
264 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
265 g_return_val_if_fail (extension != NULL, FALSE);
267 iface = G_APP_INFO_GET_IFACE (appinfo);
269 if (iface->set_as_default_for_extension)
270 return (* iface->set_as_default_for_extension) (appinfo, extension, error);
272 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_set_as_default_for_extension not supported yet");
278 * g_app_info_add_supports_type:
279 * @appinfo: a #GAppInfo.
280 * @content_type: a string.
283 * Adds a content type to the application information to indicate the
284 * application is capable of opening files with the given content type.
286 * Returns: %TRUE if @appinfo supports @content_type.
287 * %FALSE if not, or in case of an 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 if @content_type support was removed
346 * from @appinfo. %FALSE if not.
349 g_app_info_remove_supports_type (GAppInfo *appinfo,
350 const char *content_type,
353 GAppInfoIface *iface;
355 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
356 g_return_val_if_fail (content_type != NULL, FALSE);
358 iface = G_APP_INFO_GET_IFACE (appinfo);
360 if (iface->remove_supports_type)
361 return (* iface->remove_supports_type) (appinfo, content_type, error);
363 g_set_error (error, G_IO_ERROR,
364 G_IO_ERROR_NOT_SUPPORTED,
365 "g_app_info_remove_supports_type not supported yet");
372 * g_app_info_get_icon:
373 * @appinfo: a #GAppInfo.
375 * Gets the default icon for the application.
377 * Returns: the default #GIcon for @appinfo.
380 g_app_info_get_icon (GAppInfo *appinfo)
382 GAppInfoIface *iface;
384 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
386 iface = G_APP_INFO_GET_IFACE (appinfo);
388 return (* iface->get_icon) (appinfo);
394 * @appinfo: a #GAppInfo.
395 * @files: a #GList of #GFile objects.
396 * @launch_context: a #GAppLaunchContext.
399 * Launches the application. Passes @files to the launched application
400 * as arguments, and loads the @launch_context for managing the application
401 * once it has been launched. On error, @error will be set accordingly.
403 * Returns: %TRUE on successful launch, %FALSE otherwise.
406 g_app_info_launch (GAppInfo *appinfo,
408 GAppLaunchContext *launch_context,
411 GAppInfoIface *iface;
413 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
415 iface = G_APP_INFO_GET_IFACE (appinfo);
417 return (* iface->launch) (appinfo, files, launch_context, error);
422 * g_app_info_supports_uris:
423 * @appinfo: a #GAppInfo.
425 * Checks if the application supports reading files and directories from URIs.
427 * Returns: %TRUE if the @appinfo supports URIs.
430 g_app_info_supports_uris (GAppInfo *appinfo)
432 GAppInfoIface *iface;
434 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
436 iface = G_APP_INFO_GET_IFACE (appinfo);
438 return (* iface->supports_uris) (appinfo);
443 * g_app_info_launch_uris:
444 * @appinfo: a #GAppInfo.
445 * @uris: a #GList containing URIs to launch.
446 * @launch_context: a #GAppLaunchContext.
449 * Launches the application. Passes @uris to the launched application
450 * as arguments, and loads the @launch_context for managing the application
451 * once it has been launched. On error, @error will be set accordingly.
453 * Returns: %TRUE if the @appinfo was launched successfully, %FALSE otherwise.
456 g_app_info_launch_uris (GAppInfo *appinfo,
458 GAppLaunchContext *launch_context,
461 GAppInfoIface *iface;
463 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
465 iface = G_APP_INFO_GET_IFACE (appinfo);
467 return (* iface->launch) (appinfo, uris, launch_context, error);
472 * g_app_info_should_show:
473 * @appinfo: a #GAppInfo.
474 * @desktop_env: a string.
476 * Checks if the application info should be shown when listing
477 * applications available.
479 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
482 g_app_info_should_show (GAppInfo *appinfo,
483 const char *desktop_env)
485 GAppInfoIface *iface;
487 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
489 iface = G_APP_INFO_GET_IFACE (appinfo);
491 return (* iface->should_show) (appinfo, desktop_env);
494 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
497 * g_app_launch_context_new:
499 * Creates a new application launch context.
501 * Returns: a #GAppLaunchContext.
504 g_app_launch_context_new (void)
506 return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
510 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
515 g_app_launch_context_init (GAppLaunchContext *launch_context)
520 * g_app_launch_context_get_display:
521 * @context: a #GAppLaunchContext.
522 * @info: a #GAppInfo.
523 * @files: a #GList of files.
525 * Gets the DISPLAY for a launched application.
526 * TODO: can't find an implementation. DISPLAY as in X atom "DISPLAY"?
527 * Environmental variable "DISPLAY"?
529 * Returns: a display string.
532 g_app_launch_context_get_display (GAppLaunchContext *context,
536 GAppLaunchContextClass *class;
538 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
539 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
541 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
543 if (class->get_display == NULL)
546 return class->get_display (context, info, files);
549 /* should this be moved to the g_desktop_app_ implementation? */
551 * g_app_launch_context_get_startup_notify_id:
552 * @context: a #GAppLaunchContext.
553 * @info: a #GAppInfo.
554 * @files: a #GList of files.
556 * Gets the DESKTOP_STARTUP_ID for the launched application, if supported.
557 * Startup notification IDs are defined in the FreeDesktop.Org Startup
558 * Notifications standard, at
559 * <ulink url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt"/>.
561 * Returns: a startup notifaction ID for the application, or %NULL if
565 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
569 GAppLaunchContextClass *class;
571 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
572 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
574 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
576 if (class->get_startup_notify_id == NULL)
579 return class->get_startup_notify_id (context, info, files);
584 * g_app_launch_context_launch_failed:
585 * @context: a #GAppLaunchContext.
586 * @startup_notify_id: a string containing the DESKTOP_STARTUP_ID
587 * of the launched application.
589 * TODO: what does this do? Can't find it implemented anywhere.
592 g_app_launch_context_launch_failed (GAppLaunchContext *context,
593 const char *startup_notify_id)
595 GAppLaunchContextClass *class;
597 g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
598 g_return_if_fail (startup_notify_id != NULL);
600 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
602 if (class->launch_failed != NULL)
603 class->launch_failed (context, startup_notify_id);
606 #define __G_APP_INFO_C__
607 #include "gioaliasdef.c"