annotate src/libeggsmclient/eggdesktopfile.c @ 4847:d13bf8d71b99

Updated Catalan translation from Ernest Adrogu¸«± (bug #25)
author John Lindgren <john.lindgren@tds.net>
date Sun, 12 Apr 2009 19:58:12 -0400
parents 7f318fa97ea3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4315
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1 /* eggdesktopfile.c - Freedesktop.Org Desktop Files
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
2 * Copyright (C) 2007 Novell, Inc.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
3 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
4 * Based on gnome-desktop-item.c
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
5 * Copyright (C) 1999, 2000 Red Hat Inc.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
6 * Copyright (C) 2001 George Lebl
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
7 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
8 * This library is free software; you can redistribute it and/or
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
10 * as published by the Free Software Foundation; either version 2 of
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
11 * the License, or (at your option) any later version.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
12 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
13 * This library is distributed in the hope that it will be useful, but
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
16 * Lesser General Public License for more details.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
17 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
19 * License along with this library; see the file COPYING.LIB. If not,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
20 * write to the Free Software Foundation, Inc., 59 Temple Place -
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
21 * Suite 330, Boston, MA 02111-1307, USA.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
22 */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
23
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
25 #include "config.h"
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
26 #endif
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
27
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
28 #include "eggdesktopfile.h"
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
29
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
30 #include <string.h>
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
31 #include <unistd.h>
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
32
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
33 #include <glib/gi18n.h>
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
34 #include <gdk/gdk.h>
4793
7f318fa97ea3 Only gtk.h should be included, as per -DGTK_DISABLE_SINGLE_INCLUDES (GTK+ 3 compatibility project).
Tony Vroon <chainsaw@gentoo.org>
parents: 4430
diff changeset
35 #include <gtk/gtk.h>
4315
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
36 #include <gdk/gdkx.h>
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
37
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
38 struct EggDesktopFile {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
39 GKeyFile *key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
40 char *source;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
41
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
42 char *name, *icon;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
43 EggDesktopFileType type;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
44 char document_code;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
45 };
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
46
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
47 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
48 * egg_desktop_file_new:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
49 * @desktop_file_path: path to a Freedesktop-style Desktop file
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
50 * @error: error pointer
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
51 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
52 * Creates a new #EggDesktopFile for @desktop_file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
53 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
54 * Return value: the new #EggDesktopFile, or %NULL on error.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
55 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
56 EggDesktopFile *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
57 egg_desktop_file_new (const char *desktop_file_path, GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
58 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
59 EggDesktopFile *desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
60 GKeyFile *key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
61
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
62 key_file = g_key_file_new ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
63 if (!g_key_file_load_from_file (key_file, desktop_file_path, 0, error))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
64 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
65 g_key_file_free (key_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
66 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
67 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
68
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
69 desktop_file = egg_desktop_file_new_from_key_file (key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
70 desktop_file_path,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
71 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
72 if (!desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
73 g_key_file_free (key_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
74
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
75 return desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
76 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
77
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
78 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
79 * egg_desktop_file_new_from_data_dirs:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
80 * @desktop_file_path: relative path to a Freedesktop-style Desktop file
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
81 * @error: error pointer
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
82 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
83 * Looks for @desktop_file_path in the paths returned from
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
84 * g_get_user_data_dir() and g_get_system_data_dirs(), and creates
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
85 * a new #EggDesktopFile from it.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
86 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
87 * Return value: the new #EggDesktopFile, or %NULL on error.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
88 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
89 EggDesktopFile *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
90 egg_desktop_file_new_from_data_dirs (const char *desktop_file_path,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
91 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
92 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
93 EggDesktopFile *desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
94 GKeyFile *key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
95 char *full_path;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
96
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
97 key_file = g_key_file_new ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
98 if (!g_key_file_load_from_data_dirs (key_file, desktop_file_path,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
99 &full_path, 0, error))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
100 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
101 g_key_file_free (key_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
102 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
103 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
104
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
105 desktop_file = egg_desktop_file_new_from_key_file (key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
106 full_path,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
107 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
108 g_free (full_path);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
109 if (!desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
110 g_key_file_free (key_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
111
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
112 return desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
113 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
114
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
115 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
116 * egg_desktop_file_new_from_key_file:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
117 * @key_file: a #GKeyFile representing a desktop file
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
118 * @source: the path or URI that @key_file was loaded from, or %NULL
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
119 * @error: error pointer
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
120 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
121 * Creates a new #EggDesktopFile for @key_file. Assumes ownership of
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
122 * @key_file on success (meaning it will be freed when the desktop_file
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
123 * is freed).
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
124 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
125 * Return value: the new #EggDesktopFile, or %NULL on error.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
126 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
127 EggDesktopFile *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
128 egg_desktop_file_new_from_key_file (GKeyFile *key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
129 const char *source,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
130 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
131 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
132 EggDesktopFile *desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
133 char *version, *type;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
134
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
135 if (!g_key_file_has_group (key_file, EGG_DESKTOP_FILE_GROUP))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
136 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
137 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
138 EGG_DESKTOP_FILE_ERROR_INVALID,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
139 _("File is not a valid .desktop file"));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
140 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
141 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
142
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
143 version = g_key_file_get_value (key_file, EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
144 EGG_DESKTOP_FILE_KEY_VERSION,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
145 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
146 if (version)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
147 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
148 double version_num;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
149 char *end;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
150
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
151 version_num = g_ascii_strtod (version, &end);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
152 if (*end)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
153 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
154 g_warning ("Invalid Version string '%s' in %s",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
155 version, source ? source : "(unknown)");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
156 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
157 else if (version_num > 1.0)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
158 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
159 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
160 EGG_DESKTOP_FILE_ERROR_INVALID,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
161 _("Unrecognized desktop file Version '%s'"), version);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
162 g_free (version);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
163 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
164 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
165 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
166 g_free (version);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
167 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
168
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
169 desktop_file = g_new0 (EggDesktopFile, 1);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
170
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
171 if (g_path_is_absolute (source))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
172 desktop_file->source = g_filename_to_uri (source, NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
173 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
174 desktop_file->source = g_strdup (source);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
175
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
176 desktop_file->name = g_key_file_get_string (key_file, EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
177 EGG_DESKTOP_FILE_KEY_NAME, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
178 if (!desktop_file->name)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
179 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
180 egg_desktop_file_free (desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
181 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
182 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
183
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
184 type = g_key_file_get_string (key_file, EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
185 EGG_DESKTOP_FILE_KEY_TYPE, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
186 if (!type)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
187 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
188 egg_desktop_file_free (desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
189 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
190 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
191
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
192 if (!strcmp (type, "Application"))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
193 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
194 char *exec, *p;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
195
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
196 desktop_file->type = EGG_DESKTOP_FILE_TYPE_APPLICATION;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
197
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
198 exec = g_key_file_get_string (key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
199 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
200 EGG_DESKTOP_FILE_KEY_EXEC,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
201 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
202 if (!exec)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
203 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
204 egg_desktop_file_free (desktop_file);
4362
0ea092cbb49f eggsmclient: egg_desktop_file_new_from_key_file leaks memory (Bugzilla #209)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4315
diff changeset
205 g_free(type);
4315
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
206 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
207 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
208
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
209 /* See if it takes paths or URIs or neither */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
210 for (p = exec; *p; p++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
211 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
212 if (*p == '%')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
213 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
214 if (p[1] == '\0' || strchr ("FfUu", p[1]))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
215 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
216 desktop_file->document_code = p[1];
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
217 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
218 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
219 p++;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
220 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
221 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
222
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
223 g_free (exec);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
224 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
225 else if (!strcmp (type, "Link"))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
226 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
227 char *url;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
228
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
229 desktop_file->type = EGG_DESKTOP_FILE_TYPE_LINK;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
230
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
231 url = g_key_file_get_string (key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
232 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
233 EGG_DESKTOP_FILE_KEY_URL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
234 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
235 if (!url)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
236 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
237 egg_desktop_file_free (desktop_file);
4362
0ea092cbb49f eggsmclient: egg_desktop_file_new_from_key_file leaks memory (Bugzilla #209)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4315
diff changeset
238 g_free(type);
4315
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
239 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
240 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
241 g_free (url);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
242 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
243 else if (!strcmp (type, "Directory"))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
244 desktop_file->type = EGG_DESKTOP_FILE_TYPE_DIRECTORY;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
245 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
246 desktop_file->type = EGG_DESKTOP_FILE_TYPE_UNRECOGNIZED;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
247
4362
0ea092cbb49f eggsmclient: egg_desktop_file_new_from_key_file leaks memory (Bugzilla #209)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4315
diff changeset
248 g_free(type);
0ea092cbb49f eggsmclient: egg_desktop_file_new_from_key_file leaks memory (Bugzilla #209)
Jussi Judin <jjudin+audacious@iki.fi>
parents: 4315
diff changeset
249
4315
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
250 /* Check the Icon key */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
251 desktop_file->icon = g_key_file_get_string (key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
252 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
253 EGG_DESKTOP_FILE_KEY_ICON,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
254 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
255 if (desktop_file->icon && !g_path_is_absolute (desktop_file->icon))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
256 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
257 char *ext;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
258
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
259 /* Lots of .desktop files still get this wrong */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
260 ext = strrchr (desktop_file->icon, '.');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
261 if (ext && (!strcmp (ext, ".png") ||
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
262 !strcmp (ext, ".xpm") ||
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
263 !strcmp (ext, ".svg")))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
264 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
265 g_warning ("Desktop file '%s' has malformed Icon key '%s'"
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
266 "(should not include extension)",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
267 source ? source : "(unknown)",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
268 desktop_file->icon);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
269 *ext = '\0';
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
270 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
271 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
272
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
273 desktop_file->key_file = key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
274 return desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
275 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
276
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
277 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
278 * egg_desktop_file_free:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
279 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
280 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
281 * Frees @desktop_file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
282 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
283 void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
284 egg_desktop_file_free (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
285 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
286 g_key_file_free (desktop_file->key_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
287 g_free (desktop_file->source);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
288 g_free (desktop_file->name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
289 g_free (desktop_file->icon);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
290 g_free (desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
291 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
292
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
293 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
294 * egg_desktop_file_get_key_file:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
295 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
296 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
297 * Gets the #GKeyFile associated with @desktop_file. You must not free
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
298 * this value, and changes made to it will not be reflected by
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
299 * @desktop_file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
300 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
301 * Return value: the #GKeyFile associated with @desktop_file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
302 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
303 GKeyFile *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
304 egg_desktop_file_get_key_file (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
305 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
306 return desktop_file->key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
307 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
308
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
309 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
310 * egg_desktop_file_get_source:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
311 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
312 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
313 * Gets the URI that @desktop_file was loaded from.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
314 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
315 * Return value: @desktop_file's source URI
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
316 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
317 const char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
318 egg_desktop_file_get_source (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
319 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
320 return desktop_file->source;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
321 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
322
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
323 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
324 * egg_desktop_file_get_desktop_file_type:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
325 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
326 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
327 * Gets the desktop file type of @desktop_file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
328 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
329 * Return value: @desktop_file's type
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
330 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
331 EggDesktopFileType
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
332 egg_desktop_file_get_desktop_file_type (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
333 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
334 return desktop_file->type;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
335 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
336
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
337 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
338 * egg_desktop_file_get_name:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
339 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
340 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
341 * Gets the (localized) value of @desktop_file's "Name" key.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
342 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
343 * Return value: the application/link name
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
344 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
345 const char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
346 egg_desktop_file_get_name (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
347 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
348 return desktop_file->name;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
349 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
350
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
351 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
352 * egg_desktop_file_get_icon:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
353 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
354 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
355 * Gets the value of @desktop_file's "Icon" key.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
356 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
357 * If the icon string is a full path (that is, if g_path_is_absolute()
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
358 * returns %TRUE when called on it), it points to a file containing an
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
359 * unthemed icon. If the icon string is not a full path, it is the
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
360 * name of a themed icon, which can be looked up with %GtkIconTheme,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
361 * or passed directly to a theme-aware widget like %GtkImage or
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
362 * %GtkCellRendererPixbuf.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
363 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
364 * Return value: the icon path or name
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
365 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
366 const char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
367 egg_desktop_file_get_icon (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
368 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
369 return desktop_file->icon;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
370 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
371
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
372 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
373 * egg_desktop_file_can_launch:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
374 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
375 * @desktop_environment: the name of the running desktop environment,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
376 * or %NULL
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
377 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
378 * Tests if @desktop_file can/should be launched in the current
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
379 * environment. If @desktop_environment is non-%NULL, @desktop_file's
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
380 * "OnlyShowIn" and "NotShowIn" keys are checked to make sure that
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
381 * this desktop_file is appropriate for the named environment.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
382 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
383 * Furthermore, if @desktop_file has type
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
384 * %EGG_DESKTOP_FILE_TYPE_APPLICATION, its "TryExec" key (if any) is
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
385 * also checked, to make sure the binary it points to exists.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
386 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
387 * egg_desktop_file_can_launch() does NOT check the value of the
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
388 * "Hidden" key.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
389 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
390 * Return value: %TRUE if @desktop_file can be launched
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
391 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
392 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
393 egg_desktop_file_can_launch (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
394 const char *desktop_environment)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
395 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
396 char *try_exec, *found_program;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
397 char **only_show_in, **not_show_in;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
398 gboolean found;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
399 int i;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
400
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
401 if (desktop_file->type != EGG_DESKTOP_FILE_TYPE_APPLICATION &&
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
402 desktop_file->type != EGG_DESKTOP_FILE_TYPE_LINK)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
403 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
404
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
405 if (desktop_environment)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
406 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
407 only_show_in = g_key_file_get_string_list (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
408 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
409 EGG_DESKTOP_FILE_KEY_ONLY_SHOW_IN,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
410 NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
411 if (only_show_in)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
412 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
413 for (i = 0, found = FALSE; only_show_in[i] && !found; i++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
414 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
415 if (!strcmp (only_show_in[i], desktop_environment))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
416 found = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
417 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
418
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
419 g_strfreev (only_show_in);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
420
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
421 if (!found)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
422 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
423 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
424
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
425 not_show_in = g_key_file_get_string_list (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
426 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
427 EGG_DESKTOP_FILE_KEY_NOT_SHOW_IN,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
428 NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
429 if (not_show_in)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
430 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
431 for (i = 0, found = FALSE; not_show_in[i] && !found; i++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
432 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
433 if (!strcmp (not_show_in[i], desktop_environment))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
434 found = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
435 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
436
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
437 g_strfreev (not_show_in);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
438
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
439 if (found)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
440 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
441 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
442 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
443
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
444 if (desktop_file->type == EGG_DESKTOP_FILE_TYPE_APPLICATION)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
445 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
446 try_exec = g_key_file_get_string (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
447 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
448 EGG_DESKTOP_FILE_KEY_TRY_EXEC,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
449 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
450 if (try_exec)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
451 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
452 found_program = g_find_program_in_path (try_exec);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
453 g_free (try_exec);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
454
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
455 if (!found_program)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
456 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
457 g_free (found_program);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
458 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
459 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
460
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
461 return TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
462 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
463
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
464 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
465 * egg_desktop_file_accepts_documents:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
466 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
467 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
468 * Tests if @desktop_file represents an application that can accept
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
469 * documents on the command line.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
470 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
471 * Return value: %TRUE or %FALSE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
472 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
473 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
474 egg_desktop_file_accepts_documents (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
475 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
476 return desktop_file->document_code != 0;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
477 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
478
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
479 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
480 * egg_desktop_file_accepts_multiple:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
481 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
482 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
483 * Tests if @desktop_file can accept multiple documents at once.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
484 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
485 * If this returns %FALSE, you can still pass multiple documents to
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
486 * egg_desktop_file_launch(), but that will result in multiple copies
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
487 * of the application being launched. See egg_desktop_file_launch()
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
488 * for more details.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
489 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
490 * Return value: %TRUE or %FALSE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
491 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
492 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
493 egg_desktop_file_accepts_multiple (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
494 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
495 return (desktop_file->document_code == 'F' ||
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
496 desktop_file->document_code == 'U');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
497 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
498
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
499 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
500 * egg_desktop_file_accepts_uris:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
501 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
502 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
503 * Tests if @desktop_file can accept (non-"file:") URIs as documents to
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
504 * open.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
505 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
506 * Return value: %TRUE or %FALSE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
507 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
508 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
509 egg_desktop_file_accepts_uris (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
510 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
511 return (desktop_file->document_code == 'U' ||
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
512 desktop_file->document_code == 'u');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
513 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
514
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
515 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
516 append_quoted_word (GString *str,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
517 const char *s,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
518 gboolean in_single_quotes,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
519 gboolean in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
520 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
521 const char *p;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
522
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
523 if (!in_single_quotes && !in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
524 g_string_append_c (str, '\'');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
525 else if (!in_single_quotes && in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
526 g_string_append (str, "\"'");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
527
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
528 if (!strchr (s, '\''))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
529 g_string_append (str, s);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
530 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
531 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
532 for (p = s; *p != '\0'; p++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
533 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
534 if (*p == '\'')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
535 g_string_append (str, "'\\''");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
536 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
537 g_string_append_c (str, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
538 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
539 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
540
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
541 if (!in_single_quotes && !in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
542 g_string_append_c (str, '\'');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
543 else if (!in_single_quotes && in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
544 g_string_append (str, "'\"");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
545 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
546
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
547 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
548 do_percent_subst (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
549 char code,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
550 GString *str,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
551 GSList **documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
552 gboolean in_single_quotes,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
553 gboolean in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
554 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
555 GSList *d;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
556 char *doc;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
557
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
558 switch (code)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
559 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
560 case '%':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
561 g_string_append_c (str, '%');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
562 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
563
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
564 case 'F':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
565 case 'U':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
566 for (d = *documents; d; d = d->next)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
567 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
568 doc = d->data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
569 g_string_append (str, " ");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
570 append_quoted_word (str, doc, in_single_quotes, in_double_quotes);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
571 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
572 *documents = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
573 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
574
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
575 case 'f':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
576 case 'u':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
577 if (*documents)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
578 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
579 doc = (*documents)->data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
580 g_string_append (str, " ");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
581 append_quoted_word (str, doc, in_single_quotes, in_double_quotes);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
582 *documents = (*documents)->next;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
583 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
584 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
585
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
586 case 'i':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
587 if (desktop_file->icon)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
588 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
589 g_string_append (str, "--icon ");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
590 append_quoted_word (str, desktop_file->icon,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
591 in_single_quotes, in_double_quotes);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
592 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
593 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
594
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
595 case 'c':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
596 if (desktop_file->name)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
597 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
598 append_quoted_word (str, desktop_file->name,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
599 in_single_quotes, in_double_quotes);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
600 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
601 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
602
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
603 case 'k':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
604 if (desktop_file->source)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
605 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
606 append_quoted_word (str, desktop_file->source,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
607 in_single_quotes, in_double_quotes);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
608 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
609 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
610
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
611 case 'D':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
612 case 'N':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
613 case 'd':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
614 case 'n':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
615 case 'v':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
616 case 'm':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
617 /* Deprecated; skip */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
618 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
619
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
620 default:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
621 g_warning ("Unrecognized %%-code '%%%c' in Exec", code);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
622 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
623 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
624 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
625
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
626 static char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
627 parse_exec (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
628 GSList **documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
629 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
630 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
631 char *exec, *p, *command;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
632 gboolean escape, single_quot, double_quot;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
633 GString *gs;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
634
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
635 exec = g_key_file_get_string (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
636 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
637 EGG_DESKTOP_FILE_KEY_EXEC,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
638 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
639 if (!exec)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
640 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
641
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
642 /* Build the command */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
643 gs = g_string_new (NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
644 escape = single_quot = double_quot = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
645
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
646 for (p = exec; *p != '\0'; p++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
647 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
648 if (escape)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
649 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
650 escape = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
651 g_string_append_c (gs, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
652 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
653 else if (*p == '\\')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
654 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
655 if (!single_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
656 escape = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
657 g_string_append_c (gs, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
658 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
659 else if (*p == '\'')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
660 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
661 g_string_append_c (gs, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
662 if (!single_quot && !double_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
663 single_quot = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
664 else if (single_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
665 single_quot = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
666 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
667 else if (*p == '"')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
668 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
669 g_string_append_c (gs, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
670 if (!single_quot && !double_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
671 double_quot = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
672 else if (double_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
673 double_quot = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
674 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
675 else if (*p == '%' && p[1])
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
676 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
677 do_percent_subst (desktop_file, p[1], gs, documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
678 single_quot, double_quot);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
679 p++;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
680 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
681 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
682 g_string_append_c (gs, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
683 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
684
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
685 g_free (exec);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
686 command = g_string_free (gs, FALSE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
687
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
688 /* Prepend "xdg-terminal " if needed (FIXME: use gvfs) */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
689 if (g_key_file_has_key (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
690 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
691 EGG_DESKTOP_FILE_KEY_TERMINAL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
692 NULL))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
693 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
694 GError *terminal_error = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
695 gboolean use_terminal =
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
696 g_key_file_get_boolean (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
697 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
698 EGG_DESKTOP_FILE_KEY_TERMINAL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
699 &terminal_error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
700 if (terminal_error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
701 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
702 g_free (command);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
703 g_propagate_error (error, terminal_error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
704 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
705 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
706
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
707 if (use_terminal)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
708 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
709 gs = g_string_new ("xdg-terminal ");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
710 append_quoted_word (gs, command, FALSE, FALSE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
711 g_free (command);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
712 command = g_string_free (gs, FALSE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
713 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
714 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
715
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
716 return command;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
717 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
718
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
719 static GSList *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
720 translate_document_list (EggDesktopFile *desktop_file, GSList *documents)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
721 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
722 gboolean accepts_uris = egg_desktop_file_accepts_uris (desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
723 GSList *ret, *d;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
724
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
725 for (d = documents, ret = NULL; d; d = d->next)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
726 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
727 const char *document = d->data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
728 gboolean is_uri = !g_path_is_absolute (document);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
729 char *translated;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
730
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
731 if (accepts_uris)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
732 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
733 if (is_uri)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
734 translated = g_strdup (document);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
735 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
736 translated = g_filename_to_uri (document, NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
737 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
738 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
739 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
740 if (is_uri)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
741 translated = g_filename_from_uri (document, NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
742 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
743 translated = g_strdup (document);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
744 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
745
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
746 if (translated)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
747 ret = g_slist_prepend (ret, translated);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
748 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
749
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
750 return g_slist_reverse (ret);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
751 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
752
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
753 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
754 free_document_list (GSList *documents)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
755 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
756 GSList *d;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
757
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
758 for (d = documents; d; d = d->next)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
759 g_free (d->data);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
760 g_slist_free (documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
761 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
762
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
763 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
764 * egg_desktop_file_parse_exec:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
765 * @desktop_file: a #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
766 * @documents: a list of document paths or URIs
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
767 * @error: error pointer
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
768 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
769 * Parses @desktop_file's Exec key, inserting @documents into it, and
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
770 * returns the result.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
771 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
772 * If @documents contains non-file: URIs and @desktop_file does not
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
773 * accept URIs, those URIs will be ignored. Likewise, if @documents
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
774 * contains more elements than @desktop_file accepts, the extra
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
775 * documents will be ignored.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
776 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
777 * Return value: the parsed Exec string
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
778 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
779 char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
780 egg_desktop_file_parse_exec (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
781 GSList *documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
782 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
783 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
784 GSList *translated, *docs;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
785 char *command;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
786
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
787 docs = translated = translate_document_list (desktop_file, documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
788 command = parse_exec (desktop_file, &docs, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
789 free_document_list (translated);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
790
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
791 return command;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
792 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
793
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
794 static gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
795 parse_link (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
796 EggDesktopFile **app_desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
797 GSList **documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
798 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
799 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
800 char *url;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
801 GKeyFile *key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
802
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
803 url = g_key_file_get_string (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
804 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
805 EGG_DESKTOP_FILE_KEY_URL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
806 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
807 if (!url)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
808 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
809 *documents = g_slist_prepend (NULL, url);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
810
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
811 /* FIXME: use gvfs */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
812 key_file = g_key_file_new ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
813 g_key_file_set_string (key_file, EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
814 EGG_DESKTOP_FILE_KEY_NAME,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
815 "xdg-open");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
816 g_key_file_set_string (key_file, EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
817 EGG_DESKTOP_FILE_KEY_TYPE,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
818 "Application");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
819 g_key_file_set_string (key_file, EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
820 EGG_DESKTOP_FILE_KEY_EXEC,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
821 "xdg-open %u");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
822 *app_desktop_file = egg_desktop_file_new_from_key_file (key_file, NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
823 return TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
824 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
825
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
826 #ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
827 static char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
828 start_startup_notification (GdkDisplay *display,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
829 EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
830 const char *argv0,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
831 int screen,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
832 int workspace,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
833 guint32 launch_time)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
834 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
835 static int sequence = 0;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
836 char *startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
837 char *description, *wmclass;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
838 char *screen_str, *workspace_str;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
839
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
840 if (g_key_file_has_key (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
841 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
842 EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
843 NULL))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
844 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
845 if (!g_key_file_get_boolean (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
846 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
847 EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
848 NULL))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
849 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
850 wmclass = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
851 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
852 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
853 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
854 wmclass = g_key_file_get_string (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
855 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
856 EGG_DESKTOP_FILE_KEY_STARTUP_WM_CLASS,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
857 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
858 if (!wmclass)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
859 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
860 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
861
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
862 if (launch_time == (guint32)-1)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
863 launch_time = gdk_x11_display_get_user_time (display);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
864 startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
865 g_get_prgname (),
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
866 (unsigned long)getpid (),
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
867 g_get_host_name (),
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
868 argv0,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
869 sequence++,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
870 (unsigned long)launch_time);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
871
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
872 description = g_strdup_printf (_("Starting %s"), desktop_file->name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
873 screen_str = g_strdup_printf ("%d", screen);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
874 workspace_str = workspace == -1 ? NULL : g_strdup_printf ("%d", workspace);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
875
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
876 gdk_x11_display_broadcast_startup_message (display, "new",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
877 "ID", startup_id,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
878 "NAME", desktop_file->name,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
879 "SCREEN", screen_str,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
880 "BIN", argv0,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
881 "ICON", desktop_file->icon,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
882 "DESKTOP", workspace_str,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
883 "DESCRIPTION", description,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
884 "WMCLASS", wmclass,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
885 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
886
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
887 g_free (description);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
888 g_free (wmclass);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
889 g_free (screen_str);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
890 g_free (workspace_str);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
891
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
892 return startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
893 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
894
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
895 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
896 end_startup_notification (GdkDisplay *display,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
897 const char *startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
898 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
899 gdk_x11_display_broadcast_startup_message (display, "remove",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
900 "ID", startup_id,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
901 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
902 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
903
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
904 #define EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH (30 /* seconds */ * 1000)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
905
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
906 typedef struct {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
907 GdkDisplay *display;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
908 char *startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
909 } StartupNotificationData;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
910
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
911 static gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
912 startup_notification_timeout (gpointer data)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
913 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
914 StartupNotificationData *sn_data = data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
915
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
916 end_startup_notification (sn_data->display, sn_data->startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
917 g_object_unref (sn_data->display);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
918 g_free (sn_data->startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
919 g_free (sn_data);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
920
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
921 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
922 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
923
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
924 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
925 set_startup_notification_timeout (GdkDisplay *display,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
926 const char *startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
927 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
928 StartupNotificationData *sn_data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
929
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
930 sn_data = g_new (StartupNotificationData, 1);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
931 sn_data->display = g_object_ref (display);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
932 sn_data->startup_id = g_strdup (startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
933
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
934 g_timeout_add (EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
935 startup_notification_timeout, sn_data);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
936 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
937 #endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
938
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
939 extern char **environ;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
940
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
941 static GPtrArray *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
942 array_putenv (GPtrArray *env, char *variable)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
943 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
944 int i, keylen;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
945
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
946 if (!env)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
947 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
948 env = g_ptr_array_new ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
949
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
950 for (i = 0; environ[i]; i++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
951 g_ptr_array_add (env, g_strdup (environ[i]));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
952 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
953
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
954 keylen = strcspn (variable, "=");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
955
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
956 /* Remove old value of key */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
957 for (i = 0; i < env->len; i++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
958 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
959 char *envvar = env->pdata[i];
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
960
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
961 if (!strncmp (envvar, variable, keylen) && envvar[keylen] == '=')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
962 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
963 g_free (envvar);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
964 g_ptr_array_remove_index_fast (env, i);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
965 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
966 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
967 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
968
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
969 /* Add new value */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
970 g_ptr_array_add (env, g_strdup (variable));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
971
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
972 return env;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
973 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
974
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
975 static gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
976 egg_desktop_file_launchv (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
977 GSList *documents, va_list args,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
978 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
979 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
980 EggDesktopFileLaunchOption option;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
981 GSList *translated_documents, *docs;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
982 char *command, **argv;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
983 int argc, i, screen_num;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
984 gboolean success, current_success;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
985 GdkDisplay *display;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
986 char *startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
987
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
988 GPtrArray *env = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
989 char **variables = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
990 GdkScreen *screen = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
991 int workspace = -1;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
992 const char *directory = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
993 guint32 launch_time = (guint32)-1;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
994 GSpawnFlags flags = G_SPAWN_SEARCH_PATH;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
995 GSpawnChildSetupFunc setup_func = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
996 gpointer setup_data = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
997 docs = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
998 translated_documents = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
999
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1000 GPid *ret_pid = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1001 int *ret_stdin = NULL, *ret_stdout = NULL, *ret_stderr = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1002 char **ret_startup_id = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1003
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1004 if (documents && desktop_file->document_code == 0)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1005 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1006 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1007 EGG_DESKTOP_FILE_ERROR_NOT_LAUNCHABLE,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1008 _("Application does not accept documents on command line"));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1009 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1010 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1011
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1012 /* Read the options: technically it's incorrect for the caller to
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1013 * NULL-terminate the list of options (rather than 0-terminating
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1014 * it), but NULL-terminating lets us use G_GNUC_NULL_TERMINATED,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1015 * it's more consistent with other glib/gtk methods, and it will
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1016 * work as long as sizeof (int) <= sizeof (NULL), and NULL is
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1017 * represented as 0. (Which is true everywhere we care about.)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1018 */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1019 while ((option = va_arg (args, EggDesktopFileLaunchOption)))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1020 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1021 switch (option)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1022 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1023 case EGG_DESKTOP_FILE_LAUNCH_CLEARENV:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1024 if (env)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1025 g_ptr_array_free (env, TRUE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1026 env = g_ptr_array_new ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1027 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1028 case EGG_DESKTOP_FILE_LAUNCH_PUTENV:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1029 variables = va_arg (args, char **);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1030 for (i = 0; variables[i]; i++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1031 env = array_putenv (env, variables[i]);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1032 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1033
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1034 case EGG_DESKTOP_FILE_LAUNCH_SCREEN:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1035 screen = va_arg (args, GdkScreen *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1036 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1037 case EGG_DESKTOP_FILE_LAUNCH_WORKSPACE:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1038 workspace = va_arg (args, int);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1039 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1040
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1041 case EGG_DESKTOP_FILE_LAUNCH_DIRECTORY:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1042 directory = va_arg (args, const char *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1043 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1044 case EGG_DESKTOP_FILE_LAUNCH_TIME:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1045 launch_time = va_arg (args, guint32);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1046 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1047 case EGG_DESKTOP_FILE_LAUNCH_FLAGS:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1048 flags |= va_arg (args, GSpawnFlags);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1049 /* Make sure they didn't set any flags that don't make sense. */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1050 flags &= ~G_SPAWN_FILE_AND_ARGV_ZERO;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1051 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1052 case EGG_DESKTOP_FILE_LAUNCH_SETUP_FUNC:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1053 setup_func = va_arg (args, GSpawnChildSetupFunc);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1054 setup_data = va_arg (args, gpointer);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1055 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1056
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1057 case EGG_DESKTOP_FILE_LAUNCH_RETURN_PID:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1058 ret_pid = va_arg (args, GPid *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1059 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1060 case EGG_DESKTOP_FILE_LAUNCH_RETURN_STDIN_PIPE:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1061 ret_stdin = va_arg (args, int *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1062 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1063 case EGG_DESKTOP_FILE_LAUNCH_RETURN_STDOUT_PIPE:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1064 ret_stdout = va_arg (args, int *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1065 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1066 case EGG_DESKTOP_FILE_LAUNCH_RETURN_STDERR_PIPE:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1067 ret_stderr = va_arg (args, int *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1068 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1069 case EGG_DESKTOP_FILE_LAUNCH_RETURN_STARTUP_ID:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1070 ret_startup_id = va_arg (args, char **);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1071 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1072
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1073 default:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1074 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1075 EGG_DESKTOP_FILE_ERROR_UNRECOGNIZED_OPTION,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1076 _("Unrecognized launch option: %d"),
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1077 GPOINTER_TO_INT (option));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1078 success = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1079 goto out;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1080 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1081 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1082
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1083 if (screen)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1084 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1085 char *display_name = gdk_screen_make_display_name (screen);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1086 char *display_env = g_strdup_printf ("DISPLAY=%s", display_name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1087 env = array_putenv (env, display_env);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1088 g_free (display_name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1089 g_free (display_env);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1090
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1091 display = gdk_screen_get_display (screen);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1092 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1093 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1094 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1095 display = gdk_display_get_default ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1096 screen = gdk_display_get_default_screen (display);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1097 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1098 screen_num = gdk_screen_get_number (screen);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1099
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1100 translated_documents = translate_document_list (desktop_file, documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1101 docs = translated_documents;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1102
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1103 success = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1104
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1105 do
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1106 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1107 command = parse_exec (desktop_file, &docs, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1108 if (!command)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1109 goto out;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1110
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1111 if (!g_shell_parse_argv (command, &argc, &argv, error))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1112 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1113 g_free (command);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1114 goto out;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1115 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1116 g_free (command);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1117
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1118 #ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1119 startup_id = start_startup_notification (display, desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1120 argv[0], screen_num,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1121 workspace, launch_time);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1122 if (startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1123 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1124 char *startup_id_env = g_strdup_printf ("DESKTOP_STARTUP_ID=%s",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1125 startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1126 env = array_putenv (env, startup_id_env);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1127 g_free (startup_id_env);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1128 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1129 #else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1130 startup_id = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1131 #endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1132
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1133 current_success =
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1134 g_spawn_async_with_pipes (directory,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1135 argv,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1136 env ? (char **)(env->pdata) : NULL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1137 flags,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1138 setup_func, setup_data,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1139 ret_pid,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1140 ret_stdin, ret_stdout, ret_stderr,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1141 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1142 g_strfreev (argv);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1143
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1144 if (startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1145 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1146 #ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1147 if (current_success)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1148 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1149 set_startup_notification_timeout (display, startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1150
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1151 if (ret_startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1152 *ret_startup_id = startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1153 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1154 g_free (startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1155 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1156 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1157 #endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1158 g_free (startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1159 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1160 else if (ret_startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1161 *ret_startup_id = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1162
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1163 if (current_success)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1164 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1165 /* If we successfully launch any instances of the app, make
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1166 * sure we return TRUE and don't set @error.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1167 */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1168 success = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1169 error = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1170
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1171 /* Also, only set the output params on the first one */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1172 ret_pid = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1173 ret_stdin = ret_stdout = ret_stderr = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1174 ret_startup_id = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1175 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1176 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1177 while (docs && current_success);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1178
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1179 out:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1180 if (env)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1181 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1182 g_strfreev ((char **)env->pdata);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1183 g_ptr_array_free (env, FALSE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1184 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1185 free_document_list (translated_documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1186
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1187 return success;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1188 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1189
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1190 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1191 * egg_desktop_file_launch:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1192 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1193 * @documents: a list of URIs or paths to documents to open
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1194 * @error: error pointer
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1195 * @...: additional options
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1196 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1197 * Launches @desktop_file with the given arguments. Additional options
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1198 * can be specified as follows:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1199 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1200 * %EGG_DESKTOP_FILE_LAUNCH_CLEARENV: (no arguments)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1201 * clears the environment in the child process
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1202 * %EGG_DESKTOP_FILE_LAUNCH_PUTENV: (char **variables)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1203 * adds the NAME=VALUE strings in the given %NULL-terminated
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1204 * array to the child process's environment
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1205 * %EGG_DESKTOP_FILE_LAUNCH_SCREEN: (GdkScreen *screen)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1206 * causes the application to be launched on the given screen
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1207 * %EGG_DESKTOP_FILE_LAUNCH_WORKSPACE: (int workspace)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1208 * causes the application to be launched on the given workspace
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1209 * %EGG_DESKTOP_FILE_LAUNCH_DIRECTORY: (char *dir)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1210 * causes the application to be launched in the given directory
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1211 * %EGG_DESKTOP_FILE_LAUNCH_TIME: (guint32 launch_time)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1212 * sets the "launch time" for the application. If the user
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1213 * interacts with another window after @launch_time but before
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1214 * the launched application creates its first window, the window
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1215 * manager may choose to not give focus to the new application.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1216 * Passing 0 for @launch_time will explicitly request that the
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1217 * application not receive focus.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1218 * %EGG_DESKTOP_FILE_LAUNCH_FLAGS (GSpawnFlags flags)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1219 * Sets additional #GSpawnFlags to use. See g_spawn_async() for
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1220 * more details.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1221 * %EGG_DESKTOP_FILE_LAUNCH_SETUP_FUNC (GSpawnChildSetupFunc, gpointer)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1222 * Sets the child setup callback and the data to pass to it.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1223 * (See g_spawn_async() for more details.)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1224 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1225 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_PID (GPid **pid)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1226 * On a successful launch, sets *@pid to the PID of the launched
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1227 * application.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1228 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_STARTUP_ID (char **startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1229 * On a successful launch, sets *@startup_id to the Startup
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1230 * Notification "startup id" of the launched application.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1231 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_STDIN_PIPE (int *fd)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1232 * On a successful launch, sets *@fd to the file descriptor of
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1233 * a pipe connected to the application's stdin.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1234 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_STDOUT_PIPE (int *fd)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1235 * On a successful launch, sets *@fd to the file descriptor of
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1236 * a pipe connected to the application's stdout.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1237 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_STDERR_PIPE (int *fd)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1238 * On a successful launch, sets *@fd to the file descriptor of
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1239 * a pipe connected to the application's stderr.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1240 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1241 * The options should be terminated with a single %NULL.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1242 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1243 * If @documents contains multiple documents, but
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1244 * egg_desktop_file_accepts_multiple() returns %FALSE for
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1245 * @desktop_file, then egg_desktop_file_launch() will actually launch
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1246 * multiple instances of the application. In that case, the return
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1247 * value (as well as any values passed via
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1248 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_PID, etc) will only reflect the
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1249 * first instance of the application that was launched (but the
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1250 * %EGG_DESKTOP_FILE_LAUNCH_SETUP_FUNC will be called for each
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1251 * instance).
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1252 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1253 * Return value: %TRUE if the application was successfully launched.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1254 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1255 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1256 egg_desktop_file_launch (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1257 GSList *documents, GError **error,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1258 ...)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1259 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1260 va_list args;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1261 gboolean success;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1262 EggDesktopFile *app_desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1263
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1264 switch (desktop_file->type)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1265 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1266 case EGG_DESKTOP_FILE_TYPE_APPLICATION:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1267 va_start (args, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1268 success = egg_desktop_file_launchv (desktop_file, documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1269 args, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1270 va_end (args);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1271 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1272
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1273 case EGG_DESKTOP_FILE_TYPE_LINK:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1274 if (documents)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1275 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1276 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1277 EGG_DESKTOP_FILE_ERROR_NOT_LAUNCHABLE,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1278 _("Can't pass document URIs to a 'Type=Link' desktop entry"));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1279 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1280 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1281
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1282 if (!parse_link (desktop_file, &app_desktop_file, &documents, error))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1283 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1284
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1285 va_start (args, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1286 success = egg_desktop_file_launchv (app_desktop_file, documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1287 args, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1288 va_end (args);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1289
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1290 egg_desktop_file_free (app_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1291 free_document_list (documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1292 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1293
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1294 default:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1295 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1296 EGG_DESKTOP_FILE_ERROR_NOT_LAUNCHABLE,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1297 _("Not a launchable item"));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1298 success = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1299 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1300 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1301
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1302 return success;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1303 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1304
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1305
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1306 GQuark
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1307 egg_desktop_file_error_quark (void)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1308 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1309 return g_quark_from_static_string ("egg-desktop_file-error-quark");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1310 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1311
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1312
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1313 G_LOCK_DEFINE_STATIC (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1314 static EggDesktopFile *egg_desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1315
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1316 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1317 * egg_set_desktop_file:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1318 * @desktop_file_path: path to the application's desktop file
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1319 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1320 * Creates an #EggDesktopFile for the application from the data at
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1321 * @desktop_file_path. This will also call g_set_application_name()
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1322 * with the localized application name from the desktop file, and
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1323 * gtk_window_set_default_icon_name() or
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1324 * gtk_window_set_default_icon_from_file() with the application's
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1325 * icon. Other code may use additional information from the desktop
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1326 * file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1327 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1328 * Note that for thread safety reasons, this function can only
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1329 * be called once.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1330 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1331 void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1332 egg_set_desktop_file (const char *desktop_file_path)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1333 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1334 GError *error = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1335
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1336 G_LOCK (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1337 if (egg_desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1338 egg_desktop_file_free (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1339
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1340 egg_desktop_file = egg_desktop_file_new (desktop_file_path, &error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1341 if (error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1342 {
4430
72443cd1061a Add a note about possibility of session management not working if the
Matti Hamalainen <ccr@tnsp.org>
parents: 4429
diff changeset
1343 g_warning ("Could not load desktop file '%s': %s"
72443cd1061a Add a note about possibility of session management not working if the
Matti Hamalainen <ccr@tnsp.org>
parents: 4429
diff changeset
1344 " - Session management may not work now.",
4315
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1345 desktop_file_path, error->message);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1346 g_error_free (error);
4429
f207e3099f7f Return in case the desktop file cannot be loaded.
Matti Hamalainen <ccr@tnsp.org>
parents: 4362
diff changeset
1347 G_UNLOCK (egg_desktop_file);
f207e3099f7f Return in case the desktop file cannot be loaded.
Matti Hamalainen <ccr@tnsp.org>
parents: 4362
diff changeset
1348 return;
4315
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1349 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1350
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1351 /* Set localized application name and default window icon */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1352 if (egg_desktop_file->name)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1353 g_set_application_name (egg_desktop_file->name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1354 if (egg_desktop_file->icon)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1355 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1356 if (g_path_is_absolute (egg_desktop_file->icon))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1357 gtk_window_set_default_icon_from_file (egg_desktop_file->icon, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1358 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1359 gtk_window_set_default_icon_name (egg_desktop_file->icon);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1360 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1361
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1362 G_UNLOCK (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1363 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1364
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1365 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1366 * egg_get_desktop_file:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1367 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1368 * Gets the application's #EggDesktopFile, as set by
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1369 * egg_set_desktop_file().
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1370 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1371 * Return value: the #EggDesktopFile, or %NULL if it hasn't been set.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1372 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1373 EggDesktopFile *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1374 egg_get_desktop_file (void)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1375 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1376 EggDesktopFile *retval;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1377
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1378 G_LOCK (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1379 retval = egg_desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1380 G_UNLOCK (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1381
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1382 return retval;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1383 }