gio/ docs/reference/gio Merged gio-standalone into glib.
[platform/upstream/glib.git] / gio / gappinfo.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include <config.h>
24 #include "gappinfo.h"
25 #include "glibintl.h"
26 #include <gioerror.h>
27
28
29 static void g_app_info_base_init (gpointer g_class);
30 static void g_app_info_class_init (gpointer g_class,
31                                    gpointer class_data);
32
33
34 GType
35 g_app_info_get_type (void)
36 {
37   static GType app_info_type = 0;
38
39   if (! app_info_type)
40     {
41       static const GTypeInfo app_info_info =
42       {
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 */
49         0,
50         0,              /* n_preallocs */
51         NULL
52       };
53
54       app_info_type =
55         g_type_register_static (G_TYPE_INTERFACE, I_("GAppInfo"),
56                                 &app_info_info, 0);
57
58       g_type_interface_add_prerequisite (app_info_type, G_TYPE_OBJECT);
59     }
60
61   return app_info_type;
62 }
63
64 static void
65 g_app_info_class_init (gpointer g_class,
66                        gpointer class_data)
67 {
68 }
69
70 static void
71 g_app_info_base_init (gpointer g_class)
72 {
73 }
74
75
76 /**
77  * g_app_info_dup:
78  * @appinfo: a #GAppInfo.
79  *
80  * Returns: a duplicate of @appinfo.
81  **/
82 GAppInfo *
83 g_app_info_dup (GAppInfo *appinfo)
84 {
85   GAppInfoIface *iface;
86
87   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
88
89   iface = G_APP_INFO_GET_IFACE (appinfo);
90
91   return (* iface->dup) (appinfo);
92 }
93
94 /**
95  * g_app_info_equal:
96  * @appinfo1: the first #GAppInfo.  
97  * @appinfo2: the second #GAppInfo.
98  *
99  * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
100  *  
101  **/
102 gboolean
103 g_app_info_equal (GAppInfo    *appinfo1,
104                   GAppInfo    *appinfo2)
105 {
106   GAppInfoIface *iface;
107
108   g_return_val_if_fail (G_IS_APP_INFO (appinfo1), FALSE);
109   g_return_val_if_fail (G_IS_APP_INFO (appinfo2), FALSE);
110
111   if (G_TYPE_FROM_INSTANCE (appinfo1) != G_TYPE_FROM_INSTANCE (appinfo2))
112     return FALSE;
113   
114   iface = G_APP_INFO_GET_IFACE (appinfo1);
115
116   return (* iface->equal) (appinfo1, appinfo2);
117 }
118
119 /**
120  * g_app_info_get_id:
121  * @appinfo: a #GAppInfo.
122  *
123  * Returns: 
124  **/
125 const char *
126 g_app_info_get_id (GAppInfo *appinfo)
127 {
128   GAppInfoIface *iface;
129   
130   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
131
132   iface = G_APP_INFO_GET_IFACE (appinfo);
133
134   return (* iface->get_id) (appinfo);
135 }
136
137 /**
138  * g_app_info_get_name:
139  * @appinfo: a #GAppInfo.
140  *
141  * Returns: the name of the application for @appinfo.
142  **/
143 const char *
144 g_app_info_get_name (GAppInfo *appinfo)
145 {
146   GAppInfoIface *iface;
147   
148   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
149
150   iface = G_APP_INFO_GET_IFACE (appinfo);
151
152   return (* iface->get_name) (appinfo);
153 }
154
155 /**
156  * g_app_info_get_description:
157  * @appinfo: a #GAppInfo.
158  *
159  * Returns: a string containing a description of the 
160  * application @appinfo.  
161  * The returned string should be not freed when no longer needed.
162  **/
163 const char *
164 g_app_info_get_description (GAppInfo *appinfo)
165 {
166   GAppInfoIface *iface;
167   
168   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
169
170   iface = G_APP_INFO_GET_IFACE (appinfo);
171
172   return (* iface->get_description) (appinfo);
173 }
174
175 /**
176  * g_app_info_get_executable:
177  * @appinfo: a #GAppInfo.
178  *
179  * Returns: a string containing the @appinfo's application 
180  * binary's name.
181  **/
182 const char *
183 g_app_info_get_executable (GAppInfo *appinfo)
184 {
185   GAppInfoIface *iface;
186   
187   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
188
189   iface = G_APP_INFO_GET_IFACE (appinfo);
190
191   return (* iface->get_executable) (appinfo);
192 }
193
194
195 /**
196  * g_app_info_set_as_default_for_type:
197  * @appinfo: a #GAppInfo.
198  * @content_type: the content type.
199  * @error: a #GError.
200  *
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.
204  **/
205 gboolean
206 g_app_info_set_as_default_for_type (GAppInfo    *appinfo,
207                                     const char  *content_type,
208                                     GError     **error)
209 {
210   GAppInfoIface *iface;
211   
212   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
213   g_return_val_if_fail (content_type != NULL, FALSE);
214
215   iface = G_APP_INFO_GET_IFACE (appinfo);
216
217   return (* iface->set_as_default_for_type) (appinfo, content_type, error);
218 }
219
220
221 /**
222  * g_app_info_set_as_default_for_extension:
223  * @appinfo: a #GAppInfo.
224  * @extension: a string containing the file extension.
225  * @error: a #GError.
226  *
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.
230  **/
231 gboolean
232 g_app_info_set_as_default_for_extension (GAppInfo  *appinfo,
233                                          const char *extension,
234                                          GError **error)
235 {
236   GAppInfoIface *iface;
237   
238   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
239   g_return_val_if_fail (extension != NULL, FALSE);
240
241   iface = G_APP_INFO_GET_IFACE (appinfo);
242
243   if (iface->set_as_default_for_extension)
244     return (* iface->set_as_default_for_extension) (appinfo, extension, error);
245
246   g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_set_as_default_for_extension not supported yet");
247   return FALSE;
248 }
249
250
251 /**
252  * g_app_info_add_supports_type:
253  * @appinfo: a #GAppInfo.
254  * @content_type: a string.
255  * @error: a #GError.
256  *
257  * Returns: %TRUE if @appinfo supports @content_type.
258  * %FALSE if not, or in case of an error.
259  **/
260 gboolean
261 g_app_info_add_supports_type (GAppInfo             *appinfo,
262                               const char           *content_type,
263                               GError              **error)
264 {
265   GAppInfoIface *iface;
266   
267   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
268   g_return_val_if_fail (content_type != NULL, FALSE);
269
270   iface = G_APP_INFO_GET_IFACE (appinfo);
271
272   if (iface->add_supports_type)
273     return (* iface->add_supports_type) (appinfo, content_type, error);
274
275   g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_add_supports_type not supported yet");
276   return FALSE;
277 }
278
279
280 /**
281  * g_app_info_can_remove_support_type:
282  * @appinfo: a #GAppInfo.
283  *
284  * Returns: %TRUE if it is possible to remove supported 
285  * content types from a given @appinfo, %FALSE if not.
286  **/
287 gboolean
288 g_app_info_can_remove_supports_type (GAppInfo *appinfo)
289 {
290   GAppInfoIface *iface;
291   
292   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
293
294   iface = G_APP_INFO_GET_IFACE (appinfo);
295
296   if (iface->can_remove_supports_type)
297     return (* iface->can_remove_supports_type) (appinfo);
298
299   return FALSE;
300 }
301
302
303 /**
304  * g_app_info_remove_supports_type:
305  * @appinfo: a #GAppInfo.
306  * @content_type: a string.
307  * @error: a #GError.
308  *
309  * Returns: %TRUE if @content_type support was removed
310  * from @appinfo. %FALSE if not.
311  **/
312 gboolean
313 g_app_info_remove_supports_type (GAppInfo *appinfo,
314                                  const char *content_type,
315                                  GError **error)
316 {
317   GAppInfoIface *iface;
318   
319   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
320   g_return_val_if_fail (content_type != NULL, FALSE);
321
322   iface = G_APP_INFO_GET_IFACE (appinfo);
323
324   if (iface->remove_supports_type)
325     return (* iface->remove_supports_type) (appinfo, content_type, error);
326
327   g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "g_app_info_remove_supports_type not supported yet");
328   return FALSE;
329 }
330
331
332 /**
333  * g_app_info_get_icon:
334  * @appinfo: a #GAppInfo.
335  *
336  * Returns: the default #GIcon for @appinfo.
337  **/
338 GIcon *
339 g_app_info_get_icon (GAppInfo *appinfo)
340 {
341   GAppInfoIface *iface;
342   
343   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
344
345   iface = G_APP_INFO_GET_IFACE (appinfo);
346
347   return (* iface->get_icon) (appinfo);
348 }
349
350
351 /**
352  * g_app_info_launch:
353  * @appinfo: a #GAppInfo.
354  * @files: a #GList of #GFile objects.
355  * @launch_context: a #GAppLaunchContext.
356  * @error: a #GError.
357  *
358  * Returns: %TRUE on successful launch.
359  **/
360 gboolean
361 g_app_info_launch (GAppInfo    *appinfo,
362                    GList       *files,
363                    GAppLaunchContext *launch_context,
364                    GError     **error)
365 {
366   GAppInfoIface *iface;
367   
368   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
369
370   iface = G_APP_INFO_GET_IFACE (appinfo);
371
372   return (* iface->launch) (appinfo, files, launch_context, error);
373 }
374
375
376 /**
377  * g_app_info_supports_uris:
378  * @appinfo: a #GAppInfo.
379  *
380  * Returns: %TRUE if the @appinfo supports URIs.
381  **/
382 gboolean
383 g_app_info_supports_uris (GAppInfo *appinfo)
384 {
385   GAppInfoIface *iface;
386   
387   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
388
389   iface = G_APP_INFO_GET_IFACE (appinfo);
390
391   return (* iface->supports_uris) (appinfo);
392 }
393
394
395 /**
396  * g_app_info_launch_uris:
397  * @appinfo: a #GAppInfo.
398  * @uris: a #GList containing URIs to launch. 
399  * @launch_context: a #GAppLaunchContext.
400  * @error: a #GError.
401  *
402  * Returns: %TRUE if the @appinfo was launched 
403  * with the given @uris.
404  **/
405 gboolean
406 g_app_info_launch_uris (GAppInfo    *appinfo,
407                         GList       *uris,
408                         GAppLaunchContext *launch_context,
409                         GError     **error)
410 {
411   GAppInfoIface *iface;
412   
413   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
414
415   iface = G_APP_INFO_GET_IFACE (appinfo);
416
417   return (* iface->launch) (appinfo, uris, launch_context, error);
418 }
419
420
421 /**
422  * g_app_info_should_show:
423  * @appinfo: a #GAppInfo.
424  * @desktop_env: a string.
425  *
426  * Returns: %TRUE if the @GAppInfo should be shown,
427  * %FALSE otherwise.
428  **/
429 gboolean
430 g_app_info_should_show (GAppInfo    *appinfo,
431                         const char  *desktop_env)
432 {
433   GAppInfoIface *iface;
434   
435   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
436
437   iface = G_APP_INFO_GET_IFACE (appinfo);
438
439   return (* iface->should_show) (appinfo, desktop_env);
440 }
441
442 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
443
444 /**
445  * g_app_launch_context_new:
446  *
447  * Returns: A new #GAppLaunchContext.
448  **/
449 GAppLaunchContext *
450 g_app_launch_context_new (void)
451 {
452   return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
453 }
454
455 static void
456 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
457 {
458 }
459
460 static void
461 g_app_launch_context_init (GAppLaunchContext *launch_context)
462 {
463 }
464
465 /**
466  * g_app_launch_context_get_display:
467  * @context: a #GAppLaunchContext.  
468  * @info: a #GAppInfo. 
469  * @files: a #GList of files.
470  *
471  **/
472 char *
473 g_app_launch_context_get_display (GAppLaunchContext *context,
474                                   GAppInfo          *info,
475                                   GList             *files)
476 {
477   GAppLaunchContextClass *class;
478
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);
481
482   class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
483
484   if (class->get_display == NULL)
485     return NULL;
486
487   return class->get_display (context, info, files);
488 }
489
490 /**
491  * g_app_launch_context_get_startup_notify_id:
492  * @context: a #GAppLaunchContext.
493  * @info: a #GAppInfo.
494  * @files: a #GList of files.
495  *
496  **/
497 char *
498 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
499                                             GAppInfo          *info,
500                                             GList             *files)
501 {
502   GAppLaunchContextClass *class;
503
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);
506
507   class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
508
509   if (class->get_startup_notify_id == NULL)
510     return NULL;
511
512   return class->get_startup_notify_id (context, info, files);
513 }
514
515
516 /**
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.
520  *
521  **/
522 void
523 g_app_launch_context_launch_failed (GAppLaunchContext *context,
524                                     const char *startup_notify_id)
525 {
526   GAppLaunchContextClass *class;
527
528   g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
529   g_return_if_fail (startup_notify_id != NULL);
530
531   class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
532
533   if (class->launch_failed != NULL)
534     class->launch_failed (context, startup_notify_id);
535 }