Merge remote-tracking branch 'gvdb/master'
[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 #include <gfile.h>
28
29
30 /**
31  * SECTION:gappinfo
32  * @short_description: Application information and launch contexts
33  * @include: gio/gio.h
34  * 
35  * #GAppInfo and #GAppLaunchContext are used for describing and launching
36  * applications installed on the system.
37  *
38  * As of GLib 2.20, URIs will always be converted to POSIX paths
39  * (using g_file_get_path()) when using g_app_info_launch() even if
40  * the application requested an URI and not a POSIX path. For example
41  * for an desktop-file based application with Exec key <literal>totem
42  * &percnt;U</literal> and a single URI,
43  * <literal>sftp://foo/file.avi</literal>, then
44  * <literal>/home/user/.gvfs/sftp on foo/file.avi</literal> will be
45  * passed. This will only work if a set of suitable GIO extensions
46  * (such as gvfs 2.26 compiled with FUSE support), is available and
47  * operational; if this is not the case, the URI will be passed
48  * unmodified to the application. Some URIs, such as
49  * <literal>mailto:</literal>, of course cannot be mapped to a POSIX
50  * path (in gvfs there's no FUSE mount for it); such URIs will be
51  * passed unmodified to the application.
52  *
53  * Specifically for gvfs 2.26 and later, the POSIX URI will be mapped
54  * back to the GIO URI in the #GFile constructors (since gvfs
55  * implements the #GVfs extension point). As such, if the application
56  * needs to examine the URI, it needs to use g_file_get_uri() or
57  * similar on #GFile. In other words, an application cannot assume
58  * that the URI passed to e.g. g_file_new_for_commandline_arg() is
59  * equal to the result of g_file_get_uri(). The following snippet
60  * illustrates this:
61  *
62  * <programlisting>
63  * GFile *f;
64  * char *uri;
65  *
66  * file = g_file_new_for_commandline_arg (uri_from_commandline);
67  *
68  * uri = g_file_get_uri (file);
69  * strcmp (uri, uri_from_commandline) == 0; // FALSE
70  * g_free (uri);
71  *
72  * if (g_file_has_uri_scheme (file, "cdda"))
73  *   {
74  *     // do something special with uri
75  *   }
76  * g_object_unref (file);
77  * </programlisting>
78  *
79  * This code will work when both <literal>cdda://sr0/Track
80  * 1.wav</literal> and <literal>/home/user/.gvfs/cdda on sr0/Track
81  * 1.wav</literal> is passed to the application. It should be noted
82  * that it's generally not safe for applications to rely on the format
83  * of a particular URIs. Different launcher applications (e.g. file
84  * managers) may have different ideas of what a given URI means.
85  *
86  **/
87
88 typedef GAppInfoIface GAppInfoInterface;
89 G_DEFINE_INTERFACE (GAppInfo, g_app_info, G_TYPE_OBJECT)
90
91 static void
92 g_app_info_default_init (GAppInfoInterface *iface)
93 {
94 }
95
96
97 /**
98  * g_app_info_dup:
99  * @appinfo: a #GAppInfo.
100  * 
101  * Creates a duplicate of a #GAppInfo.
102  *
103  * Returns: (transfer full): a duplicate of @appinfo.
104  **/
105 GAppInfo *
106 g_app_info_dup (GAppInfo *appinfo)
107 {
108   GAppInfoIface *iface;
109
110   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
111
112   iface = G_APP_INFO_GET_IFACE (appinfo);
113
114   return (* iface->dup) (appinfo);
115 }
116
117 /**
118  * g_app_info_equal:
119  * @appinfo1: the first #GAppInfo.
120  * @appinfo2: the second #GAppInfo.
121  *
122  * Checks if two #GAppInfo<!-- -->s are equal.
123  *
124  * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
125  **/
126 gboolean
127 g_app_info_equal (GAppInfo *appinfo1,
128                   GAppInfo *appinfo2)
129 {
130   GAppInfoIface *iface;
131
132   g_return_val_if_fail (G_IS_APP_INFO (appinfo1), FALSE);
133   g_return_val_if_fail (G_IS_APP_INFO (appinfo2), FALSE);
134
135   if (G_TYPE_FROM_INSTANCE (appinfo1) != G_TYPE_FROM_INSTANCE (appinfo2))
136     return FALSE;
137   
138   iface = G_APP_INFO_GET_IFACE (appinfo1);
139
140   return (* iface->equal) (appinfo1, appinfo2);
141 }
142
143 /**
144  * g_app_info_get_id:
145  * @appinfo: a #GAppInfo.
146  * 
147  * Gets the ID of an application. An id is a string that
148  * identifies the application. The exact format of the id is
149  * platform dependent. For instance, on Unix this is the
150  * desktop file id from the xdg menu specification.
151  *
152  * Note that the returned ID may be %NULL, depending on how
153  * the @appinfo has been constructed.
154  *
155  * Returns: a string containing the application's ID.
156  **/
157 const char *
158 g_app_info_get_id (GAppInfo *appinfo)
159 {
160   GAppInfoIface *iface;
161   
162   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
163
164   iface = G_APP_INFO_GET_IFACE (appinfo);
165
166   return (* iface->get_id) (appinfo);
167 }
168
169 /**
170  * g_app_info_get_name:
171  * @appinfo: a #GAppInfo.
172  * 
173  * Gets the installed name of the application. 
174  *
175  * Returns: the name of the application for @appinfo.
176  **/
177 const char *
178 g_app_info_get_name (GAppInfo *appinfo)
179 {
180   GAppInfoIface *iface;
181   
182   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
183
184   iface = G_APP_INFO_GET_IFACE (appinfo);
185
186   return (* iface->get_name) (appinfo);
187 }
188
189 /**
190  * g_app_info_get_display_name:
191  * @appinfo: a #GAppInfo.
192  *
193  * Gets the display name of the application. The display name is often more
194  * descriptive to the user than the name itself.
195  *
196  * Returns: the display name of the application for @appinfo, or the name if
197  * no display name is available.
198  *
199  * Since: 2.24
200  **/
201 const char *
202 g_app_info_get_display_name (GAppInfo *appinfo)
203 {
204   GAppInfoIface *iface;
205
206   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
207
208   iface = G_APP_INFO_GET_IFACE (appinfo);
209
210   if (iface->get_display_name == NULL)
211     return (* iface->get_name) (appinfo);
212
213   return (* iface->get_display_name) (appinfo);
214 }
215
216 /**
217  * g_app_info_get_description:
218  * @appinfo: a #GAppInfo.
219  * 
220  * Gets a human-readable description of an installed application.
221  *
222  * Returns: a string containing a description of the 
223  * application @appinfo, or %NULL if none. 
224  **/
225 const char *
226 g_app_info_get_description (GAppInfo *appinfo)
227 {
228   GAppInfoIface *iface;
229   
230   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
231
232   iface = G_APP_INFO_GET_IFACE (appinfo);
233
234   return (* iface->get_description) (appinfo);
235 }
236
237 /**
238  * g_app_info_get_executable:
239  * @appinfo: a #GAppInfo
240  * 
241  * Gets the executable's name for the installed application.
242  *
243  * Returns: a string containing the @appinfo's application 
244  * binaries name
245  **/
246 const char *
247 g_app_info_get_executable (GAppInfo *appinfo)
248 {
249   GAppInfoIface *iface;
250   
251   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
252
253   iface = G_APP_INFO_GET_IFACE (appinfo);
254
255   return (* iface->get_executable) (appinfo);
256 }
257
258
259 /**
260  * g_app_info_get_commandline:
261  * @appinfo: a #GAppInfo
262  * 
263  * Gets the commandline with which the application will be
264  * started.  
265  *
266  * Returns: a string containing the @appinfo's commandline, 
267  *     or %NULL if this information is not available
268  *
269  * Since: 2.20
270  **/
271 const char *
272 g_app_info_get_commandline (GAppInfo *appinfo)
273 {
274   GAppInfoIface *iface;
275   
276   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
277
278   iface = G_APP_INFO_GET_IFACE (appinfo);
279
280   if (iface->get_commandline)
281     return (* iface->get_commandline) (appinfo);
282  
283   return NULL;
284 }
285
286 /**
287  * g_app_info_set_as_default_for_type:
288  * @appinfo: a #GAppInfo.
289  * @content_type: the content type.
290  * @error: a #GError.
291  * 
292  * Sets the application as the default handler for a given type.
293  *
294  * Returns: %TRUE on success, %FALSE on error.
295  **/
296 gboolean
297 g_app_info_set_as_default_for_type (GAppInfo    *appinfo,
298                                     const char  *content_type,
299                                     GError     **error)
300 {
301   GAppInfoIface *iface;
302   
303   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
304   g_return_val_if_fail (content_type != NULL, FALSE);
305
306   iface = G_APP_INFO_GET_IFACE (appinfo);
307
308   return (* iface->set_as_default_for_type) (appinfo, content_type, error);
309 }
310
311 /**
312  * g_app_info_set_as_last_used_for_type:
313  * @appinfo: a #GAppInfo.
314  * @content_type: the content type.
315  * @error: a #GError.
316  *
317  * Sets the application as the last used application for a given type.
318  * This will make the application appear as first in the list returned
319  * by g_app_info_get_recommended_for_type(), regardless of the default
320  * application for that content type.
321  *
322  * Returns: %TRUE on success, %FALSE on error.
323  **/
324 gboolean
325 g_app_info_set_as_last_used_for_type (GAppInfo    *appinfo,
326                                       const char  *content_type,
327                                       GError     **error)
328 {
329   GAppInfoIface *iface;
330   
331   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
332   g_return_val_if_fail (content_type != NULL, FALSE);
333
334   iface = G_APP_INFO_GET_IFACE (appinfo);
335
336   return (* iface->set_as_last_used_for_type) (appinfo, content_type, error);
337 }
338
339 /**
340  * g_app_info_set_as_default_for_extension:
341  * @appinfo: a #GAppInfo.
342  * @extension: a string containing the file extension (without the dot).
343  * @error: a #GError.
344  * 
345  * Sets the application as the default handler for the given file extension.
346  *
347  * Returns: %TRUE on success, %FALSE on error.
348  **/
349 gboolean
350 g_app_info_set_as_default_for_extension (GAppInfo    *appinfo,
351                                          const char  *extension,
352                                          GError     **error)
353 {
354   GAppInfoIface *iface;
355   
356   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
357   g_return_val_if_fail (extension != NULL, FALSE);
358
359   iface = G_APP_INFO_GET_IFACE (appinfo);
360
361   if (iface->set_as_default_for_extension)
362     return (* iface->set_as_default_for_extension) (appinfo, extension, error);
363
364   g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
365                        "g_app_info_set_as_default_for_extension not supported yet");
366   return FALSE;
367 }
368
369
370 /**
371  * g_app_info_add_supports_type:
372  * @appinfo: a #GAppInfo.
373  * @content_type: a string.
374  * @error: a #GError.
375  * 
376  * Adds a content type to the application information to indicate the 
377  * application is capable of opening files with the given content type.
378  *
379  * Returns: %TRUE on success, %FALSE on error.
380  **/
381 gboolean
382 g_app_info_add_supports_type (GAppInfo    *appinfo,
383                               const char  *content_type,
384                               GError     **error)
385 {
386   GAppInfoIface *iface;
387   
388   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
389   g_return_val_if_fail (content_type != NULL, FALSE);
390
391   iface = G_APP_INFO_GET_IFACE (appinfo);
392
393   if (iface->add_supports_type)
394     return (* iface->add_supports_type) (appinfo, content_type, error);
395
396   g_set_error_literal (error, G_IO_ERROR, 
397                        G_IO_ERROR_NOT_SUPPORTED, 
398                        "g_app_info_add_supports_type not supported yet");
399
400   return FALSE;
401 }
402
403
404 /**
405  * g_app_info_can_remove_supports_type:
406  * @appinfo: a #GAppInfo.
407  * 
408  * Checks if a supported content type can be removed from an application.
409  *
410  * Returns: %TRUE if it is possible to remove supported 
411  *     content types from a given @appinfo, %FALSE if not.
412  **/
413 gboolean
414 g_app_info_can_remove_supports_type (GAppInfo *appinfo)
415 {
416   GAppInfoIface *iface;
417   
418   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
419
420   iface = G_APP_INFO_GET_IFACE (appinfo);
421
422   if (iface->can_remove_supports_type)
423     return (* iface->can_remove_supports_type) (appinfo);
424
425   return FALSE;
426 }
427
428
429 /**
430  * g_app_info_remove_supports_type:
431  * @appinfo: a #GAppInfo.
432  * @content_type: a string.
433  * @error: a #GError.
434  *
435  * Removes a supported type from an application, if possible.
436  * 
437  * Returns: %TRUE on success, %FALSE on error.
438  **/
439 gboolean
440 g_app_info_remove_supports_type (GAppInfo    *appinfo,
441                                  const char  *content_type,
442                                  GError     **error)
443 {
444   GAppInfoIface *iface;
445   
446   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
447   g_return_val_if_fail (content_type != NULL, FALSE);
448
449   iface = G_APP_INFO_GET_IFACE (appinfo);
450
451   if (iface->remove_supports_type)
452     return (* iface->remove_supports_type) (appinfo, content_type, error);
453
454   g_set_error_literal (error, G_IO_ERROR, 
455                        G_IO_ERROR_NOT_SUPPORTED, 
456                        "g_app_info_remove_supports_type not supported yet");
457
458   return FALSE;
459 }
460
461
462 /**
463  * g_app_info_get_icon:
464  * @appinfo: a #GAppInfo.
465  * 
466  * Gets the icon for the application.
467  *
468  * Returns: (transfer none): the default #GIcon for @appinfo or %NULL
469  * if there is no default icon.
470  **/
471 GIcon *
472 g_app_info_get_icon (GAppInfo *appinfo)
473 {
474   GAppInfoIface *iface;
475   
476   g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
477
478   iface = G_APP_INFO_GET_IFACE (appinfo);
479
480   return (* iface->get_icon) (appinfo);
481 }
482
483
484 /**
485  * g_app_info_launch:
486  * @appinfo: a #GAppInfo
487  * @files: (element-type GFile): a #GList of #GFile objects
488  * @launch_context: (allow-none): a #GAppLaunchContext or %NULL
489  * @error: a #GError
490  * 
491  * Launches the application. Passes @files to the launched application
492  * as arguments, using the optional @launch_context to get information
493  * about the details of the launcher (like what screen it is on).
494  * On error, @error will be set accordingly.
495  *
496  * To launch the application without arguments pass a %NULL @files list.
497  *
498  * Note that even if the launch is successful the application launched
499  * can fail to start if it runs into problems during startup. There is
500  * no way to detect this.
501  *
502  * Some URIs can be changed when passed through a GFile (for instance
503  * unsupported URIs with strange formats like mailto:), so if you have
504  * a textual URI you want to pass in as argument, consider using
505  * g_app_info_launch_uris() instead.
506  *
507  * The launched application inherits the environment of the launching
508  * process, but it can be modified with g_app_launch_context_setenv() and
509  * g_app_launch_context_unsetenv().
510  *
511  * On UNIX, this function sets the <envar>GIO_LAUNCHED_DESKTOP_FILE</envar>
512  * environment variable with the path of the launched desktop file and
513  * <envar>GIO_LAUNCHED_DESKTOP_FILE_PID</envar> to the process
514  * id of the launched process. This can be used to ignore
515  * <envar>GIO_LAUNCHED_DESKTOP_FILE</envar>, should it be inherited
516  * by further processes. The <envar>DISPLAY</envar> and
517  * <envar>DESKTOP_STARTUP_ID</envar> environment variables are also
518  * set, based on information provided in @launch_context.
519  *
520  * Returns: %TRUE on successful launch, %FALSE otherwise.
521  **/
522 gboolean
523 g_app_info_launch (GAppInfo           *appinfo,
524                    GList              *files,
525                    GAppLaunchContext  *launch_context,
526                    GError            **error)
527 {
528   GAppInfoIface *iface;
529   
530   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
531
532   iface = G_APP_INFO_GET_IFACE (appinfo);
533
534   return (* iface->launch) (appinfo, files, launch_context, error);
535 }
536
537
538 /**
539  * g_app_info_supports_uris:
540  * @appinfo: a #GAppInfo.
541  * 
542  * Checks if the application supports reading files and directories from URIs.
543  *
544  * Returns: %TRUE if the @appinfo supports URIs.
545  **/
546 gboolean
547 g_app_info_supports_uris (GAppInfo *appinfo)
548 {
549   GAppInfoIface *iface;
550   
551   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
552
553   iface = G_APP_INFO_GET_IFACE (appinfo);
554
555   return (* iface->supports_uris) (appinfo);
556 }
557
558
559 /**
560  * g_app_info_supports_files:
561  * @appinfo: a #GAppInfo.
562  * 
563  * Checks if the application accepts files as arguments.
564  *
565  * Returns: %TRUE if the @appinfo supports files.
566  **/
567 gboolean
568 g_app_info_supports_files (GAppInfo *appinfo)
569 {
570   GAppInfoIface *iface;
571   
572   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
573
574   iface = G_APP_INFO_GET_IFACE (appinfo);
575
576   return (* iface->supports_files) (appinfo);
577 }
578
579
580 /**
581  * g_app_info_launch_uris:
582  * @appinfo: a #GAppInfo
583  * @uris: (element-type utf8): a #GList containing URIs to launch.
584  * @launch_context: (allow-none): a #GAppLaunchContext or %NULL
585  * @error: a #GError
586  * 
587  * Launches the application. This passes the @uris to the launched application
588  * as arguments, using the optional @launch_context to get information
589  * about the details of the launcher (like what screen it is on).
590  * On error, @error will be set accordingly.
591  *
592  * To launch the application without arguments pass a %NULL @uris list.
593  *
594  * Note that even if the launch is successful the application launched
595  * can fail to start if it runs into problems during startup. There is
596  * no way to detect this.
597  *
598  * Returns: %TRUE on successful launch, %FALSE otherwise.
599  **/
600 gboolean
601 g_app_info_launch_uris (GAppInfo           *appinfo,
602                         GList              *uris,
603                         GAppLaunchContext  *launch_context,
604                         GError            **error)
605 {
606   GAppInfoIface *iface;
607   
608   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
609
610   iface = G_APP_INFO_GET_IFACE (appinfo);
611
612   return (* iface->launch_uris) (appinfo, uris, launch_context, error);
613 }
614
615
616 /**
617  * g_app_info_should_show:
618  * @appinfo: a #GAppInfo.
619  *
620  * Checks if the application info should be shown in menus that 
621  * list available applications.
622  * 
623  * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
624  **/
625 gboolean
626 g_app_info_should_show (GAppInfo *appinfo)
627 {
628   GAppInfoIface *iface;
629   
630   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
631
632   iface = G_APP_INFO_GET_IFACE (appinfo);
633
634   return (* iface->should_show) (appinfo);
635 }
636
637 /**
638  * g_app_info_launch_default_for_uri:
639  * @uri: the uri to show
640  * @launch_context: (allow-none): an optional #GAppLaunchContext.
641  * @error: a #GError.
642  *
643  * Utility function that launches the default application
644  * registered to handle the specified uri. Synchronous I/O
645  * is done on the uri to detect the type of the file if
646  * required.
647  * 
648  * Returns: %TRUE on success, %FALSE on error.
649  **/
650 gboolean
651 g_app_info_launch_default_for_uri (const char         *uri,
652                                    GAppLaunchContext  *launch_context,
653                                    GError            **error)
654 {
655   GAppInfo *app_info;
656   GFile *file;
657   GList l;
658   gboolean res;
659
660   file = g_file_new_for_uri (uri);
661   app_info = g_file_query_default_handler (file, NULL, error);
662   g_object_unref (file);
663   if (app_info == NULL)
664     return FALSE;
665
666   /* Use the uri, not the GFile, as the GFile roundtrip may
667    * affect the uri which we don't want (for instance for a
668    * mailto: uri).
669    */
670   l.data = (char *)uri;
671   l.next = l.prev = NULL;
672   res = g_app_info_launch_uris (app_info, &l,
673                                 launch_context, error);
674
675   g_object_unref (app_info);
676   
677   return res;
678 }
679
680 /**
681  * g_app_info_can_delete:
682  * @appinfo: a #GAppInfo
683  *
684  * Obtains the information whether the #GAppInfo can be deleted.
685  * See g_app_info_delete().
686  *
687  * Returns: %TRUE if @appinfo can be deleted
688  *
689  * Since: 2.20
690  */
691 gboolean
692 g_app_info_can_delete (GAppInfo *appinfo)
693 {
694   GAppInfoIface *iface;
695   
696   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
697
698   iface = G_APP_INFO_GET_IFACE (appinfo);
699
700   if (iface->can_delete)
701     return (* iface->can_delete) (appinfo);
702  
703   return FALSE; 
704 }
705
706
707 /**
708  * g_app_info_delete:
709  * @appinfo: a #GAppInfo
710  *
711  * Tries to delete a #GAppInfo.
712  *
713  * On some platforms, there may be a difference between user-defined
714  * #GAppInfo<!-- -->s which can be deleted, and system-wide ones which
715  * cannot. See g_app_info_can_delete().
716  *
717  * Virtual: do_delete
718  * Returns: %TRUE if @appinfo has been deleted
719  *
720  * Since: 2.20
721  */
722 gboolean
723 g_app_info_delete (GAppInfo *appinfo)
724 {
725   GAppInfoIface *iface;
726   
727   g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
728
729   iface = G_APP_INFO_GET_IFACE (appinfo);
730
731   if (iface->do_delete)
732     return (* iface->do_delete) (appinfo);
733  
734   return FALSE; 
735 }
736
737
738 G_DEFINE_TYPE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT);
739
740 struct _GAppLaunchContextPrivate {
741   char **envp;
742 };
743
744 /**
745  * g_app_launch_context_new:
746  * 
747  * Creates a new application launch context. This is not normally used,
748  * instead you instantiate a subclass of this, such as #GdkAppLaunchContext.
749  *
750  * Returns: a #GAppLaunchContext.
751  **/
752 GAppLaunchContext *
753 g_app_launch_context_new (void)
754 {
755   return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
756 }
757
758 static void
759 g_app_launch_context_finalize (GObject *object)
760 {
761   GAppLaunchContext *context = G_APP_LAUNCH_CONTEXT (object);
762
763   g_strfreev (context->priv->envp);
764
765   G_OBJECT_CLASS (g_app_launch_context_parent_class)->finalize (object);
766 }
767
768 static void
769 g_app_launch_context_class_init (GAppLaunchContextClass *klass)
770 {
771   GObjectClass *object_class = G_OBJECT_CLASS (klass);
772
773   g_type_class_add_private (klass, sizeof (GAppLaunchContextPrivate));
774
775   object_class->finalize = g_app_launch_context_finalize;
776 }
777
778 static void
779 g_app_launch_context_init (GAppLaunchContext *context)
780 {
781   context->priv = G_TYPE_INSTANCE_GET_PRIVATE (context, G_TYPE_APP_LAUNCH_CONTEXT, GAppLaunchContextPrivate);
782 }
783
784 /**
785  * g_app_launch_context_setenv:
786  * @context: a #GAppLaunchContext
787  * @variable: the environment variable to set
788  * @value: the value for to set the variable to.
789  *
790  * Arranges for @variable to be set to @value in the child's
791  * environment when @context is used to launch an application.
792  *
793  * Since: 2.32
794  */
795 void
796 g_app_launch_context_setenv (GAppLaunchContext *context,
797                              const char        *variable,
798                              const char        *value)
799 {
800   if (!context->priv->envp)
801     context->priv->envp = g_get_environ ();
802
803   context->priv->envp =
804     g_environ_setenv (context->priv->envp, variable, value, TRUE);
805 }
806
807 /**
808  * g_app_launch_context_unsetenv:
809  * @context: a #GAppLaunchContext
810  * @variable: the environment variable to remove
811  *
812  * Arranges for @variable to be unset in the child's environment
813  * when @context is used to launch an application.
814  *
815  * Since: 2.32
816  */
817 void
818 g_app_launch_context_unsetenv (GAppLaunchContext *context,
819                                const char        *variable)
820 {
821   if (!context->priv->envp)
822     context->priv->envp = g_get_environ ();
823
824   context->priv->envp =
825     g_environ_unsetenv (context->priv->envp, variable);
826 }
827
828 /**
829  * g_app_launch_context_get_environment:
830  * @context: a #GAppLaunchContext
831  *
832  * Gets the complete environment variable list to be passed to
833  * the child process when @context is used to launch an application.
834  * This is a %NULL-terminated array of strings, where each string has
835  * the form <literal>KEY=VALUE</literal>.
836  *
837  * Return value: (array zero-terminated=1) (transfer full): the
838  *     child's environment
839  *
840  * Since: 2.32
841  */
842 char **
843 g_app_launch_context_get_environment (GAppLaunchContext *context)
844 {
845   if (!context->priv->envp)
846     context->priv->envp = g_get_environ ();
847
848   return g_strdupv (context->priv->envp);
849 }
850
851 /**
852  * g_app_launch_context_get_display:
853  * @context: a #GAppLaunchContext
854  * @info: a #GAppInfo
855  * @files: (element-type GFile): a #GList of #GFile objects
856  *
857  * Gets the display string for the @context. This is used to ensure new
858  * applications are started on the same display as the launching
859  * application, by setting the <envar>DISPLAY</envar> environment variable.
860  *
861  * Returns: a display string for the display.
862  */
863 char *
864 g_app_launch_context_get_display (GAppLaunchContext *context,
865                                   GAppInfo          *info,
866                                   GList             *files)
867 {
868   GAppLaunchContextClass *class;
869
870   g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
871   g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
872
873   class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
874
875   if (class->get_display == NULL)
876     return NULL;
877
878   return class->get_display (context, info, files);
879 }
880
881 /**
882  * g_app_launch_context_get_startup_notify_id:
883  * @context: a #GAppLaunchContext
884  * @info: a #GAppInfo
885  * @files: (element-type GFile): a #GList of of #GFile objects
886  * 
887  * Initiates startup notification for the application and returns the
888  * <envar>DESKTOP_STARTUP_ID</envar> for the launched operation,
889  * if supported.
890  *
891  * Startup notification IDs are defined in the <ulink
892  * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">
893  * FreeDesktop.Org Startup Notifications standard</ulink>.
894  *
895  * Returns: a startup notification ID for the application, or %NULL if
896  *     not supported.
897  **/
898 char *
899 g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
900                                             GAppInfo          *info,
901                                             GList             *files)
902 {
903   GAppLaunchContextClass *class;
904
905   g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
906   g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
907
908   class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
909
910   if (class->get_startup_notify_id == NULL)
911     return NULL;
912
913   return class->get_startup_notify_id (context, info, files);
914 }
915
916
917 /**
918  * g_app_launch_context_launch_failed:
919  * @context: a #GAppLaunchContext.
920  * @startup_notify_id: the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
921  *
922  * Called when an application has failed to launch, so that it can cancel
923  * the application startup notification started in g_app_launch_context_get_startup_notify_id().
924  * 
925  **/
926 void
927 g_app_launch_context_launch_failed (GAppLaunchContext *context,
928                                     const char        *startup_notify_id)
929 {
930   GAppLaunchContextClass *class;
931
932   g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
933   g_return_if_fail (startup_notify_id != NULL);
934
935   class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
936
937   if (class->launch_failed != NULL)
938     class->launch_failed (context, startup_notify_id);
939 }