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>
29 static void g_app_info_base_init (gpointer g_class);
30 static void g_app_info_class_init (gpointer g_class,
35 g_app_info_get_type (void)
37 static GType app_info_type = 0;
41 static const GTypeInfo app_info_info =
43 sizeof (GAppInfoIface), /* class_size */
44 g_app_info_base_init, /* base_init */
45 NULL, /* base_finalize */
46 g_app_info_class_init,
47 NULL, /* class_finalize */
48 NULL, /* class_data */
55 g_type_register_static (G_TYPE_INTERFACE, I_("GAppInfo"),
58 g_type_interface_add_prerequisite (app_info_type, G_TYPE_OBJECT);
65 g_app_info_class_init (gpointer g_class,
71 g_app_info_base_init (gpointer g_class)
78 * @appinfo: a #GAppInfo.
80 * Returns: a duplicate of @appinfo.
83 g_app_info_dup (GAppInfo *appinfo)
87 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
89 iface = G_APP_INFO_GET_IFACE (appinfo);
91 return (* iface->dup) (appinfo);
96 * @appinfo1: the first #GAppInfo.
97 * @appinfo2: the second #GAppInfo.
99 * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
103 g_app_info_equal (GAppInfo *appinfo1,
106 GAppInfoIface *iface;
108 g_return_val_if_fail (G_IS_APP_INFO (appinfo1), FALSE);
109 g_return_val_if_fail (G_IS_APP_INFO (appinfo2), FALSE);
111 if (G_TYPE_FROM_INSTANCE (appinfo1) != G_TYPE_FROM_INSTANCE (appinfo2))
114 iface = G_APP_INFO_GET_IFACE (appinfo1);
116 return (* iface->equal) (appinfo1, appinfo2);
121 * @appinfo: a #GAppInfo.
126 g_app_info_get_id (GAppInfo *appinfo)
128 GAppInfoIface *iface;
130 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
132 iface = G_APP_INFO_GET_IFACE (appinfo);
134 return (* iface->get_id) (appinfo);
138 * g_app_info_get_name:
139 * @appinfo: a #GAppInfo.
141 * Returns: the name of the application for @appinfo.
144 g_app_info_get_name (GAppInfo *appinfo)
146 GAppInfoIface *iface;
148 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
150 iface = G_APP_INFO_GET_IFACE (appinfo);
152 return (* iface->get_name) (appinfo);
156 * g_app_info_get_description:
157 * @appinfo: a #GAppInfo.
159 * Returns: a string containing a description of the
160 * application @appinfo.
161 * The returned string should be not freed when no longer needed.
164 g_app_info_get_description (GAppInfo *appinfo)
166 GAppInfoIface *iface;
168 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
170 iface = G_APP_INFO_GET_IFACE (appinfo);
172 return (* iface->get_description) (appinfo);
176 * g_app_info_get_executable:
177 * @appinfo: a #GAppInfo.
179 * Returns: a string containing the @appinfo's application
183 g_app_info_get_executable (GAppInfo *appinfo)
185 GAppInfoIface *iface;
187 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
189 iface = G_APP_INFO_GET_IFACE (appinfo);
191 return (* iface->get_executable) (appinfo);
196 * g_app_info_set_as_default_for_type:
197 * @appinfo: a #GAppInfo.
198 * @content_type: the content type.
201 * Returns: %TRUE if the given @appinfo is the default
202 * for the given @content_type. %FALSE if not,
203 * or in case of an error.
206 g_app_info_set_as_default_for_type (GAppInfo *appinfo,
207 const char *content_type,
210 GAppInfoIface *iface;
212 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
213 g_return_val_if_fail (content_type != NULL, FALSE);
215 iface = G_APP_INFO_GET_IFACE (appinfo);
217 return (* iface->set_as_default_for_type) (appinfo, content_type, error);
222 * g_app_info_set_as_default_for_extension:
223 * @appinfo: a #GAppInfo.
224 * @extension: a string containing the file extension.
227 * Returns: %TRUE if the given @appinfo is the default
228 * for the given @extension. %FALSE if not,
229 * or in case of an error.
232 g_app_info_set_as_default_for_extension (GAppInfo *appinfo,
233 const char *extension,
236 GAppInfoIface *iface;
238 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
239 g_return_val_if_fail (extension != NULL, FALSE);
241 iface = G_APP_INFO_GET_IFACE (appinfo);
243 if (iface->set_as_default_for_extension)
244 return (* iface->set_as_default_for_extension) (appinfo, extension, error);
246 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_set_as_default_for_extension not supported yet");
252 * g_app_info_add_supports_type:
253 * @appinfo: a #GAppInfo.
254 * @content_type: a string.
257 * Returns: %TRUE if @appinfo supports @content_type.
258 * %FALSE if not, or in case of an error.
261 g_app_info_add_supports_type (GAppInfo *appinfo,
262 const char *content_type,
265 GAppInfoIface *iface;
267 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
268 g_return_val_if_fail (content_type != NULL, FALSE);
270 iface = G_APP_INFO_GET_IFACE (appinfo);
272 if (iface->add_supports_type)
273 return (* iface->add_supports_type) (appinfo, content_type, error);
275 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_add_supports_type not supported yet");
281 * g_app_info_can_remove_support_type:
282 * @appinfo: a #GAppInfo.
284 * Returns: %TRUE if it is possible to remove supported
285 * content types from a given @appinfo, %FALSE if not.
288 g_app_info_can_remove_supports_type (GAppInfo *appinfo)
290 GAppInfoIface *iface;
292 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
294 iface = G_APP_INFO_GET_IFACE (appinfo);
296 if (iface->can_remove_supports_type)
297 return (* iface->can_remove_supports_type) (appinfo);
304 * g_app_info_remove_supports_type:
305 * @appinfo: a #GAppInfo.
306 * @content_type: a string.
309 * Returns: %TRUE if @content_type support was removed
310 * from @appinfo. %FALSE if not.
313 g_app_info_remove_supports_type (GAppInfo *appinfo,
314 const char *content_type,
317 GAppInfoIface *iface;
319 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
320 g_return_val_if_fail (content_type != NULL, FALSE);
322 iface = G_APP_INFO_GET_IFACE (appinfo);
324 if (iface->remove_supports_type)
325 return (* iface->remove_supports_type) (appinfo, content_type, error);
327 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_remove_supports_type not supported yet");
333 * g_app_info_get_icon:
334 * @appinfo: a #GAppInfo.
336 * Returns: the default #GIcon for @appinfo.
339 g_app_info_get_icon (GAppInfo *appinfo)
341 GAppInfoIface *iface;
343 g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
345 iface = G_APP_INFO_GET_IFACE (appinfo);
347 return (* iface->get_icon) (appinfo);
353 * @appinfo: a #GAppInfo.
354 * @files: a #GList of #GFile objects.
355 * @launch_context: a #GAppLaunchContext.
358 * Returns: %TRUE on successful launch.
361 g_app_info_launch (GAppInfo *appinfo,
363 GAppLaunchContext *launch_context,
366 GAppInfoIface *iface;
368 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
370 iface = G_APP_INFO_GET_IFACE (appinfo);
372 return (* iface->launch) (appinfo, files, launch_context, error);
377 * g_app_info_supports_uris:
378 * @appinfo: a #GAppInfo.
380 * Returns: %TRUE if the @appinfo supports URIs.
383 g_app_info_supports_uris (GAppInfo *appinfo)
385 GAppInfoIface *iface;
387 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
389 iface = G_APP_INFO_GET_IFACE (appinfo);
391 return (* iface->supports_uris) (appinfo);
396 * g_app_info_launch_uris:
397 * @appinfo: a #GAppInfo.
398 * @uris: a #GList containing URIs to launch.
399 * @launch_context: a #GAppLaunchContext.
402 * Returns: %TRUE if the @appinfo was launched
403 * with the given @uris.
406 g_app_info_launch_uris (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, uris, launch_context, error);
422 * g_app_info_should_show:
423 * @appinfo: a #GAppInfo.
424 * @desktop_env: a string.
426 * Returns: %TRUE if the @GAppInfo should be shown,
430 g_app_info_should_show (GAppInfo *appinfo,
431 const char *desktop_env)
433 GAppInfoIface *iface;
435 g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
437 iface = G_APP_INFO_GET_IFACE (appinfo);
439 return (* iface->should_show) (appinfo, desktop_env);
442 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
445 * g_app_launch_context_new:
447 * Returns: A new #GAppLaunchContext.
450 g_app_launch_context_new (void)
452 return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
456 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
461 g_app_launch_context_init (GAppLaunchContext *launch_context)
466 * g_app_launch_context_get_display:
467 * @context: a #GAppLaunchContext.
468 * @info: a #GAppInfo.
469 * @files: a #GList of files.
473 g_app_launch_context_get_display (GAppLaunchContext *context,
477 GAppLaunchContextClass *class;
479 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
480 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
482 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
484 if (class->get_display == NULL)
487 return class->get_display (context, info, files);
491 * g_app_launch_context_get_startup_notify_id:
492 * @context: a #GAppLaunchContext.
493 * @info: a #GAppInfo.
494 * @files: a #GList of files.
498 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
502 GAppLaunchContextClass *class;
504 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
505 g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
507 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
509 if (class->get_startup_notify_id == NULL)
512 return class->get_startup_notify_id (context, info, files);
517 * g_app_launch_context_get_startup_notify_id:
518 * @context: a #GAppLaunchContext.
519 * @startup_notify_id: a string containing the startup ID of the application.
523 g_app_launch_context_launch_failed (GAppLaunchContext *context,
524 const char *startup_notify_id)
526 GAppLaunchContextClass *class;
528 g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
529 g_return_if_fail (startup_notify_id != NULL);
531 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
533 if (class->launch_failed != NULL)
534 class->launch_failed (context, startup_notify_id);