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>
30 * @short_description: Application information and launch contexts.
31 * @stability: Unstable
33 * #GAppInfo and #GAppLaunchContext are used for describing and launching
34 * installed system applications.
36 * @Note: These may/will be moved to Gtk+ in the future.
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, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_add_supports_type not supported yet");
310 * g_app_info_can_remove_support_type:
311 * @appinfo: a #GAppInfo.
313 * Checks if a supported content type can be removed from an application.
315 * Returns: %TRUE if it is possible to remove supported
316 * content types from a given @appinfo, %FALSE if not.
319 g_app_info_can_remove_supports_type (GAppInfo *appinfo)
321 GAppInfoIface *iface;
323 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
325 iface = G_APP_INFO_GET_IFACE (appinfo);
327 if (iface->can_remove_supports_type)
328 return (* iface->can_remove_supports_type) (appinfo);
335 * g_app_info_remove_supports_type:
336 * @appinfo: a #GAppInfo.
337 * @content_type: a string.
340 * Removes a supported type from an application, if possible.
342 * Returns: %TRUE if @content_type support was removed
343 * from @appinfo. %FALSE if not.
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, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_remove_supports_type not supported yet");
366 * g_app_info_get_icon:
367 * @appinfo: a #GAppInfo.
369 * Gets the default icon for the application.
371 * Returns: the default #GIcon for @appinfo.
374 g_app_info_get_icon (GAppInfo *appinfo)
376 GAppInfoIface *iface;
378 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
380 iface = G_APP_INFO_GET_IFACE (appinfo);
382 return (* iface->get_icon) (appinfo);
388 * @appinfo: a #GAppInfo.
389 * @files: a #GList of #GFile objects.
390 * @launch_context: a #GAppLaunchContext.
393 * Launches the application. Passes @files to the launched application
394 * as arguments, and loads the @launch_context for managing the application
395 * once it has been launched. On error, @error will be set accordingly.
397 * Returns: %TRUE on successful launch, %FALSE otherwise.
400 g_app_info_launch (GAppInfo *appinfo,
402 GAppLaunchContext *launch_context,
405 GAppInfoIface *iface;
407 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
409 iface = G_APP_INFO_GET_IFACE (appinfo);
411 return (* iface->launch) (appinfo, files, launch_context, error);
416 * g_app_info_supports_uris:
417 * @appinfo: a #GAppInfo.
419 * Checks if the application supports reading files and directories from URIs.
421 * Returns: %TRUE if the @appinfo supports URIs.
424 g_app_info_supports_uris (GAppInfo *appinfo)
426 GAppInfoIface *iface;
428 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
430 iface = G_APP_INFO_GET_IFACE (appinfo);
432 return (* iface->supports_uris) (appinfo);
437 * g_app_info_launch_uris:
438 * @appinfo: a #GAppInfo.
439 * @uris: a #GList containing URIs to launch.
440 * @launch_context: a #GAppLaunchContext.
443 * Launches the application. Passes @uris to the launched application
444 * as arguments, and loads the @launch_context for managing the application
445 * once it has been launched. On error, @error will be set accordingly.
447 * Returns: %TRUE if the @appinfo was launched successfully, %FALSE otherwise.
450 g_app_info_launch_uris (GAppInfo *appinfo,
452 GAppLaunchContext *launch_context,
455 GAppInfoIface *iface;
457 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
459 iface = G_APP_INFO_GET_IFACE (appinfo);
461 return (* iface->launch) (appinfo, uris, launch_context, error);
466 * g_app_info_should_show:
467 * @appinfo: a #GAppInfo.
468 * @desktop_env: a string.
470 * Checks if the application info should be shown when listing
471 * applications available.
473 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
476 g_app_info_should_show (GAppInfo *appinfo,
477 const char *desktop_env)
479 GAppInfoIface *iface;
481 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
483 iface = G_APP_INFO_GET_IFACE (appinfo);
485 return (* iface->should_show) (appinfo, desktop_env);
488 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
491 * g_app_launch_context_new:
493 * Creates a new application launch context.
495 * Returns: a #GAppLaunchContext.
498 g_app_launch_context_new (void)
500 return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
504 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
509 g_app_launch_context_init (GAppLaunchContext *launch_context)
514 * g_app_launch_context_get_display:
515 * @context: a #GAppLaunchContext.
516 * @info: a #GAppInfo.
517 * @files: a #GList of files.
519 * Gets the DISPLAY for a launched application.
520 * TODO: can't find an implementation. DISPLAY as in X atom "DISPLAY"?
521 * Environmental variable "DISPLAY"?
523 * Returns: a display string.
526 g_app_launch_context_get_display (GAppLaunchContext *context,
530 GAppLaunchContextClass *class;
532 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
533 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
535 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
537 if (class->get_display == NULL)
540 return class->get_display (context, info, files);
543 /* should this be moved to the g_desktop_app_ implementation? */
545 * g_app_launch_context_get_startup_notify_id:
546 * @context: a #GAppLaunchContext.
547 * @info: a #GAppInfo.
548 * @files: a #GList of files.
550 * Gets the DESKTOP_STARTUP_ID for the launched application, if supported.
551 * Startup notification IDs are defined in the FreeDesktop.Org Startup Notifications standard,
552 * at <ulink url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt"/>.
554 * Returns: a startup notifaction ID for the application, or %NULL if not supported.
557 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
561 GAppLaunchContextClass *class;
563 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
564 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
566 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
568 if (class->get_startup_notify_id == NULL)
571 return class->get_startup_notify_id (context, info, files);
576 * g_app_launch_context_launch_failed:
577 * @context: a #GAppLaunchContext.
578 * @startup_notify_id: a string containing the DESKTOP_STARTUP_ID of the launched application.
580 * TODO: what does this do? Can't find it implemented anywhere.
584 g_app_launch_context_launch_failed (GAppLaunchContext *context,
585 const char *startup_notify_id)
587 GAppLaunchContextClass *class;
589 g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
590 g_return_if_fail (startup_notify_id != NULL);
592 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
594 if (class->launch_failed != NULL)
595 class->launch_failed (context, startup_notify_id);