annotate src/libeggsmclient/eggdesktopfile.c @ 4346:6a87d1c1da32

remove more ui_* references
author mf0102 <0102@gmx.at>
date Sat, 15 Mar 2008 00:26:49 +0100
parents c942eaef7bc6
children 0ea092cbb49f
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>
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
35 #include <gtk/gtkwindow.h>
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);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
205 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
206 }
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 /* See if it takes paths or URIs or neither */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
209 for (p = exec; *p; p++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
210 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
211 if (*p == '%')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
212 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
213 if (p[1] == '\0' || strchr ("FfUu", p[1]))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
214 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
215 desktop_file->document_code = p[1];
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
216 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
217 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
218 p++;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
219 }
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 g_free (exec);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
223 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
224 else if (!strcmp (type, "Link"))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
225 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
226 char *url;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
227
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
228 desktop_file->type = EGG_DESKTOP_FILE_TYPE_LINK;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
229
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
230 url = g_key_file_get_string (key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
231 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
232 EGG_DESKTOP_FILE_KEY_URL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
233 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
234 if (!url)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
235 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
236 egg_desktop_file_free (desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
237 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
238 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
239 g_free (url);
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 else if (!strcmp (type, "Directory"))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
242 desktop_file->type = EGG_DESKTOP_FILE_TYPE_DIRECTORY;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
243 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
244 desktop_file->type = EGG_DESKTOP_FILE_TYPE_UNRECOGNIZED;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
245
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
246 /* Check the Icon key */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
247 desktop_file->icon = g_key_file_get_string (key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
248 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
249 EGG_DESKTOP_FILE_KEY_ICON,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
250 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
251 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
252 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
253 char *ext;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
254
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
255 /* Lots of .desktop files still get this wrong */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
256 ext = strrchr (desktop_file->icon, '.');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
257 if (ext && (!strcmp (ext, ".png") ||
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
258 !strcmp (ext, ".xpm") ||
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
259 !strcmp (ext, ".svg")))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
260 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
261 g_warning ("Desktop file '%s' has malformed Icon key '%s'"
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
262 "(should not include extension)",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
263 source ? source : "(unknown)",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
264 desktop_file->icon);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
265 *ext = '\0';
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
266 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
267 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
268
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
269 desktop_file->key_file = key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
270 return desktop_file;
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 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
274 * egg_desktop_file_free:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
275 * @desktop_file: an #EggDesktopFile
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 * Frees @desktop_file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
278 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
279 void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
280 egg_desktop_file_free (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
281 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
282 g_key_file_free (desktop_file->key_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
283 g_free (desktop_file->source);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
284 g_free (desktop_file->name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
285 g_free (desktop_file->icon);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
286 g_free (desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
287 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
288
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
289 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
290 * egg_desktop_file_get_key_file:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
291 * @desktop_file: an #EggDesktopFile
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 * 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
294 * 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
295 * @desktop_file.
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 * Return value: the #GKeyFile associated with @desktop_file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
298 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
299 GKeyFile *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
300 egg_desktop_file_get_key_file (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
301 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
302 return desktop_file->key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
303 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
304
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 * egg_desktop_file_get_source:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
307 * @desktop_file: an #EggDesktopFile
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 * Gets the URI that @desktop_file was loaded from.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
310 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
311 * Return value: @desktop_file's source URI
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 const char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
314 egg_desktop_file_get_source (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
315 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
316 return desktop_file->source;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
317 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
318
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 * egg_desktop_file_get_desktop_file_type:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
321 * @desktop_file: an #EggDesktopFile
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 * Gets the desktop file type of @desktop_file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
324 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
325 * Return value: @desktop_file's type
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 EggDesktopFileType
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
328 egg_desktop_file_get_desktop_file_type (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
329 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
330 return desktop_file->type;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
331 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
332
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 * egg_desktop_file_get_name:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
335 * @desktop_file: an #EggDesktopFile
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 * Gets the (localized) value of @desktop_file's "Name" key.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
338 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
339 * Return value: the application/link name
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 const char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
342 egg_desktop_file_get_name (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
343 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
344 return desktop_file->name;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
345 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
346
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 * egg_desktop_file_get_icon:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
349 * @desktop_file: an #EggDesktopFile
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 * Gets the value of @desktop_file's "Icon" key.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
352 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
353 * 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
354 * 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
355 * 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
356 * 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
357 * 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
358 * %GtkCellRendererPixbuf.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
359 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
360 * Return value: the icon path or name
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
361 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
362 const char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
363 egg_desktop_file_get_icon (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
364 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
365 return desktop_file->icon;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
366 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
367
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 * egg_desktop_file_can_launch:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
370 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
371 * @desktop_environment: the name of the running desktop environment,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
372 * or %NULL
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
373 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
374 * 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
375 * environment. If @desktop_environment is non-%NULL, @desktop_file's
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
376 * "OnlyShowIn" and "NotShowIn" keys are checked to make sure that
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
377 * this desktop_file is appropriate for the named environment.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
378 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
379 * Furthermore, if @desktop_file has type
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
380 * %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
381 * 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
382 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
383 * 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
384 * "Hidden" key.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
385 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
386 * Return value: %TRUE if @desktop_file can be launched
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
387 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
388 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
389 egg_desktop_file_can_launch (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
390 const char *desktop_environment)
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 char *try_exec, *found_program;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
393 char **only_show_in, **not_show_in;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
394 gboolean found;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
395 int i;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
396
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
397 if (desktop_file->type != EGG_DESKTOP_FILE_TYPE_APPLICATION &&
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
398 desktop_file->type != EGG_DESKTOP_FILE_TYPE_LINK)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
399 return FALSE;
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_environment)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
402 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
403 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
404 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
405 EGG_DESKTOP_FILE_KEY_ONLY_SHOW_IN,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
406 NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
407 if (only_show_in)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
408 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
409 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
410 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
411 if (!strcmp (only_show_in[i], desktop_environment))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
412 found = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
413 }
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 g_strfreev (only_show_in);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
416
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
417 if (!found)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
418 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
419 }
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 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
422 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
423 EGG_DESKTOP_FILE_KEY_NOT_SHOW_IN,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
424 NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
425 if (not_show_in)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
426 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
427 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
428 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
429 if (!strcmp (not_show_in[i], desktop_environment))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
430 found = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
431 }
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 g_strfreev (not_show_in);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
434
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
435 if (found)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
436 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
437 }
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
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
440 if (desktop_file->type == EGG_DESKTOP_FILE_TYPE_APPLICATION)
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 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
443 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
444 EGG_DESKTOP_FILE_KEY_TRY_EXEC,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
445 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
446 if (try_exec)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
447 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
448 found_program = g_find_program_in_path (try_exec);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
449 g_free (try_exec);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
450
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
451 if (!found_program)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
452 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
453 g_free (found_program);
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 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
456
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
457 return TRUE;
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 * egg_desktop_file_accepts_documents:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
462 * @desktop_file: an #EggDesktopFile
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 * Tests if @desktop_file represents an application that can accept
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
465 * documents on the command line.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
466 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
467 * Return value: %TRUE or %FALSE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
468 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
469 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
470 egg_desktop_file_accepts_documents (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
471 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
472 return desktop_file->document_code != 0;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
473 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
474
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 * egg_desktop_file_accepts_multiple:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
477 * @desktop_file: an #EggDesktopFile
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 * Tests if @desktop_file can accept multiple documents at once.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
480 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
481 * 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
482 * 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
483 * of the application being launched. See egg_desktop_file_launch()
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
484 * for more details.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
485 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
486 * Return value: %TRUE or %FALSE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
487 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
488 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
489 egg_desktop_file_accepts_multiple (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
490 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
491 return (desktop_file->document_code == 'F' ||
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
492 desktop_file->document_code == 'U');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
493 }
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 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
496 * egg_desktop_file_accepts_uris:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
497 * @desktop_file: an #EggDesktopFile
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 * 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
500 * open.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
501 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
502 * Return value: %TRUE or %FALSE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
503 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
504 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
505 egg_desktop_file_accepts_uris (EggDesktopFile *desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
506 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
507 return (desktop_file->document_code == 'U' ||
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
508 desktop_file->document_code == 'u');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
509 }
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 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
512 append_quoted_word (GString *str,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
513 const char *s,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
514 gboolean in_single_quotes,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
515 gboolean in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
516 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
517 const char *p;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
518
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
519 if (!in_single_quotes && !in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
520 g_string_append_c (str, '\'');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
521 else if (!in_single_quotes && in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
522 g_string_append (str, "\"'");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
523
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
524 if (!strchr (s, '\''))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
525 g_string_append (str, s);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
526 else
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 for (p = s; *p != '\0'; p++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
529 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
530 if (*p == '\'')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
531 g_string_append (str, "'\\''");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
532 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
533 g_string_append_c (str, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
534 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
535 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
536
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
537 if (!in_single_quotes && !in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
538 g_string_append_c (str, '\'');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
539 else if (!in_single_quotes && in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
540 g_string_append (str, "'\"");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
541 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
542
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
543 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
544 do_percent_subst (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
545 char code,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
546 GString *str,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
547 GSList **documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
548 gboolean in_single_quotes,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
549 gboolean in_double_quotes)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
550 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
551 GSList *d;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
552 char *doc;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
553
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
554 switch (code)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
555 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
556 case '%':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
557 g_string_append_c (str, '%');
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
558 break;
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 'F':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
561 case 'U':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
562 for (d = *documents; d; d = d->next)
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 doc = d->data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
565 g_string_append (str, " ");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
566 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
567 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
568 *documents = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
569 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
570
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
571 case 'f':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
572 case 'u':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
573 if (*documents)
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 doc = (*documents)->data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
576 g_string_append (str, " ");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
577 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
578 *documents = (*documents)->next;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
579 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
580 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
581
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
582 case 'i':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
583 if (desktop_file->icon)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
584 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
585 g_string_append (str, "--icon ");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
586 append_quoted_word (str, desktop_file->icon,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
587 in_single_quotes, in_double_quotes);
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 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
590
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
591 case 'c':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
592 if (desktop_file->name)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
593 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
594 append_quoted_word (str, desktop_file->name,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
595 in_single_quotes, in_double_quotes);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
596 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
597 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
598
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
599 case 'k':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
600 if (desktop_file->source)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
601 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
602 append_quoted_word (str, desktop_file->source,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
603 in_single_quotes, in_double_quotes);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
604 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
605 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
606
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
607 case 'D':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
608 case 'N':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
609 case 'd':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
610 case 'n':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
611 case 'v':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
612 case 'm':
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
613 /* Deprecated; skip */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
614 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
615
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
616 default:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
617 g_warning ("Unrecognized %%-code '%%%c' in Exec", code);
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 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
621
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
622 static char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
623 parse_exec (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
624 GSList **documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
625 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
626 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
627 char *exec, *p, *command;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
628 gboolean escape, single_quot, double_quot;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
629 GString *gs;
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 exec = g_key_file_get_string (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
632 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
633 EGG_DESKTOP_FILE_KEY_EXEC,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
634 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
635 if (!exec)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
636 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
637
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
638 /* Build the command */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
639 gs = g_string_new (NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
640 escape = single_quot = double_quot = FALSE;
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 for (p = exec; *p != '\0'; p++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
643 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
644 if (escape)
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 escape = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
647 g_string_append_c (gs, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
648 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
649 else if (*p == '\\')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
650 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
651 if (!single_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
652 escape = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
653 g_string_append_c (gs, *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 else if (*p == '\'')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
656 {
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 if (!single_quot && !double_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
659 single_quot = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
660 else if (single_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
661 single_quot = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
662 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
663 else if (*p == '"')
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
664 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
665 g_string_append_c (gs, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
666 if (!single_quot && !double_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
667 double_quot = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
668 else if (double_quot)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
669 double_quot = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
670 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
671 else if (*p == '%' && p[1])
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
672 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
673 do_percent_subst (desktop_file, p[1], gs, documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
674 single_quot, double_quot);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
675 p++;
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 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
678 g_string_append_c (gs, *p);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
679 }
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 g_free (exec);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
682 command = g_string_free (gs, FALSE);
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 /* Prepend "xdg-terminal " if needed (FIXME: use gvfs) */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
685 if (g_key_file_has_key (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
686 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
687 EGG_DESKTOP_FILE_KEY_TERMINAL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
688 NULL))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
689 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
690 GError *terminal_error = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
691 gboolean use_terminal =
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
692 g_key_file_get_boolean (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
693 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
694 EGG_DESKTOP_FILE_KEY_TERMINAL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
695 &terminal_error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
696 if (terminal_error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
697 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
698 g_free (command);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
699 g_propagate_error (error, terminal_error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
700 return NULL;
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
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
703 if (use_terminal)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
704 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
705 gs = g_string_new ("xdg-terminal ");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
706 append_quoted_word (gs, command, FALSE, FALSE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
707 g_free (command);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
708 command = g_string_free (gs, FALSE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
709 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
710 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
711
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
712 return command;
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 static GSList *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
716 translate_document_list (EggDesktopFile *desktop_file, GSList *documents)
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 gboolean accepts_uris = egg_desktop_file_accepts_uris (desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
719 GSList *ret, *d;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
720
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
721 for (d = documents, ret = NULL; d; d = d->next)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
722 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
723 const char *document = d->data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
724 gboolean is_uri = !g_path_is_absolute (document);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
725 char *translated;
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 if (accepts_uris)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
728 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
729 if (is_uri)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
730 translated = g_strdup (document);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
731 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
732 translated = g_filename_to_uri (document, NULL, NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
733 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
734 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
735 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
736 if (is_uri)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
737 translated = g_filename_from_uri (document, NULL, NULL);
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 translated = g_strdup (document);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
740 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
741
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
742 if (translated)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
743 ret = g_slist_prepend (ret, translated);
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 return g_slist_reverse (ret);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
747 }
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 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
750 free_document_list (GSList *documents)
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 GSList *d;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
753
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
754 for (d = documents; d; d = d->next)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
755 g_free (d->data);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
756 g_slist_free (documents);
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
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
759 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
760 * egg_desktop_file_parse_exec:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
761 * @desktop_file: a #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
762 * @documents: a list of document paths or URIs
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
763 * @error: error pointer
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
764 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
765 * 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
766 * returns the result.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
767 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
768 * 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
769 * accept URIs, those URIs will be ignored. Likewise, if @documents
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
770 * contains more elements than @desktop_file accepts, the extra
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
771 * documents will be ignored.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
772 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
773 * Return value: the parsed Exec string
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
774 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
775 char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
776 egg_desktop_file_parse_exec (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
777 GSList *documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
778 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
779 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
780 GSList *translated, *docs;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
781 char *command;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
782
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
783 docs = translated = translate_document_list (desktop_file, documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
784 command = parse_exec (desktop_file, &docs, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
785 free_document_list (translated);
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 return command;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
788 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
789
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
790 static gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
791 parse_link (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
792 EggDesktopFile **app_desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
793 GSList **documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
794 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
795 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
796 char *url;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
797 GKeyFile *key_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
798
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
799 url = g_key_file_get_string (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
800 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
801 EGG_DESKTOP_FILE_KEY_URL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
802 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
803 if (!url)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
804 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
805 *documents = g_slist_prepend (NULL, url);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
806
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
807 /* FIXME: use gvfs */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
808 key_file = g_key_file_new ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
809 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
810 EGG_DESKTOP_FILE_KEY_NAME,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
811 "xdg-open");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
812 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
813 EGG_DESKTOP_FILE_KEY_TYPE,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
814 "Application");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
815 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
816 EGG_DESKTOP_FILE_KEY_EXEC,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
817 "xdg-open %u");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
818 *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
819 return TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
820 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
821
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
822 #ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
823 static char *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
824 start_startup_notification (GdkDisplay *display,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
825 EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
826 const char *argv0,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
827 int screen,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
828 int workspace,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
829 guint32 launch_time)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
830 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
831 static int sequence = 0;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
832 char *startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
833 char *description, *wmclass;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
834 char *screen_str, *workspace_str;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
835
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
836 if (g_key_file_has_key (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
837 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
838 EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
839 NULL))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
840 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
841 if (!g_key_file_get_boolean (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
842 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
843 EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
844 NULL))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
845 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
846 wmclass = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
847 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
848 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
849 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
850 wmclass = g_key_file_get_string (desktop_file->key_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
851 EGG_DESKTOP_FILE_GROUP,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
852 EGG_DESKTOP_FILE_KEY_STARTUP_WM_CLASS,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
853 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
854 if (!wmclass)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
855 return NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
856 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
857
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
858 if (launch_time == (guint32)-1)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
859 launch_time = gdk_x11_display_get_user_time (display);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
860 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
861 g_get_prgname (),
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
862 (unsigned long)getpid (),
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
863 g_get_host_name (),
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
864 argv0,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
865 sequence++,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
866 (unsigned long)launch_time);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
867
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
868 description = g_strdup_printf (_("Starting %s"), desktop_file->name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
869 screen_str = g_strdup_printf ("%d", screen);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
870 workspace_str = workspace == -1 ? NULL : g_strdup_printf ("%d", workspace);
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 gdk_x11_display_broadcast_startup_message (display, "new",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
873 "ID", startup_id,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
874 "NAME", desktop_file->name,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
875 "SCREEN", screen_str,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
876 "BIN", argv0,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
877 "ICON", desktop_file->icon,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
878 "DESKTOP", workspace_str,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
879 "DESCRIPTION", description,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
880 "WMCLASS", wmclass,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
881 NULL);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
882
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
883 g_free (description);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
884 g_free (wmclass);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
885 g_free (screen_str);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
886 g_free (workspace_str);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
887
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
888 return startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
889 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
890
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
891 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
892 end_startup_notification (GdkDisplay *display,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
893 const char *startup_id)
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 gdk_x11_display_broadcast_startup_message (display, "remove",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
896 "ID", startup_id,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
897 NULL);
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
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
900 #define EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH (30 /* seconds */ * 1000)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
901
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
902 typedef struct {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
903 GdkDisplay *display;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
904 char *startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
905 } StartupNotificationData;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
906
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
907 static gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
908 startup_notification_timeout (gpointer data)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
909 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
910 StartupNotificationData *sn_data = data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
911
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
912 end_startup_notification (sn_data->display, sn_data->startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
913 g_object_unref (sn_data->display);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
914 g_free (sn_data->startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
915 g_free (sn_data);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
916
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
917 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
918 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
919
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
920 static void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
921 set_startup_notification_timeout (GdkDisplay *display,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
922 const char *startup_id)
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 StartupNotificationData *sn_data;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
925
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
926 sn_data = g_new (StartupNotificationData, 1);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
927 sn_data->display = g_object_ref (display);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
928 sn_data->startup_id = g_strdup (startup_id);
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 g_timeout_add (EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
931 startup_notification_timeout, sn_data);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
932 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
933 #endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
934
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
935 extern char **environ;
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 static GPtrArray *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
938 array_putenv (GPtrArray *env, char *variable)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
939 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
940 int i, keylen;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
941
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
942 if (!env)
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 env = g_ptr_array_new ();
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 for (i = 0; environ[i]; i++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
947 g_ptr_array_add (env, g_strdup (environ[i]));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
948 }
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 keylen = strcspn (variable, "=");
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
951
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
952 /* Remove old value of key */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
953 for (i = 0; i < env->len; i++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
954 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
955 char *envvar = env->pdata[i];
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
956
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
957 if (!strncmp (envvar, variable, keylen) && envvar[keylen] == '=')
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 g_free (envvar);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
960 g_ptr_array_remove_index_fast (env, i);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
961 break;
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 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
964
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
965 /* Add new value */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
966 g_ptr_array_add (env, g_strdup (variable));
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 return env;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
969 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
970
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
971 static gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
972 egg_desktop_file_launchv (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
973 GSList *documents, va_list args,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
974 GError **error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
975 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
976 EggDesktopFileLaunchOption option;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
977 GSList *translated_documents, *docs;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
978 char *command, **argv;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
979 int argc, i, screen_num;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
980 gboolean success, current_success;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
981 GdkDisplay *display;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
982 char *startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
983
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
984 GPtrArray *env = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
985 char **variables = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
986 GdkScreen *screen = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
987 int workspace = -1;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
988 const char *directory = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
989 guint32 launch_time = (guint32)-1;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
990 GSpawnFlags flags = G_SPAWN_SEARCH_PATH;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
991 GSpawnChildSetupFunc setup_func = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
992 gpointer setup_data = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
993 docs = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
994 translated_documents = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
995
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
996 GPid *ret_pid = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
997 int *ret_stdin = NULL, *ret_stdout = NULL, *ret_stderr = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
998 char **ret_startup_id = 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 if (documents && desktop_file->document_code == 0)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1001 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1002 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1003 EGG_DESKTOP_FILE_ERROR_NOT_LAUNCHABLE,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1004 _("Application does not accept documents on command line"));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1005 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1006 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1007
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1008 /* 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
1009 * NULL-terminate the list of options (rather than 0-terminating
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1010 * 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
1011 * 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
1012 * 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
1013 * represented as 0. (Which is true everywhere we care about.)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1014 */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1015 while ((option = va_arg (args, EggDesktopFileLaunchOption)))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1016 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1017 switch (option)
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 case EGG_DESKTOP_FILE_LAUNCH_CLEARENV:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1020 if (env)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1021 g_ptr_array_free (env, TRUE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1022 env = g_ptr_array_new ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1023 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1024 case EGG_DESKTOP_FILE_LAUNCH_PUTENV:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1025 variables = va_arg (args, char **);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1026 for (i = 0; variables[i]; i++)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1027 env = array_putenv (env, variables[i]);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1028 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1029
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1030 case EGG_DESKTOP_FILE_LAUNCH_SCREEN:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1031 screen = va_arg (args, GdkScreen *);
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 case EGG_DESKTOP_FILE_LAUNCH_WORKSPACE:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1034 workspace = va_arg (args, int);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1035 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1036
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1037 case EGG_DESKTOP_FILE_LAUNCH_DIRECTORY:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1038 directory = va_arg (args, const char *);
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 case EGG_DESKTOP_FILE_LAUNCH_TIME:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1041 launch_time = va_arg (args, guint32);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1042 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1043 case EGG_DESKTOP_FILE_LAUNCH_FLAGS:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1044 flags |= va_arg (args, GSpawnFlags);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1045 /* 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
1046 flags &= ~G_SPAWN_FILE_AND_ARGV_ZERO;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1047 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1048 case EGG_DESKTOP_FILE_LAUNCH_SETUP_FUNC:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1049 setup_func = va_arg (args, GSpawnChildSetupFunc);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1050 setup_data = va_arg (args, gpointer);
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
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1053 case EGG_DESKTOP_FILE_LAUNCH_RETURN_PID:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1054 ret_pid = va_arg (args, GPid *);
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 case EGG_DESKTOP_FILE_LAUNCH_RETURN_STDIN_PIPE:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1057 ret_stdin = va_arg (args, int *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1058 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1059 case EGG_DESKTOP_FILE_LAUNCH_RETURN_STDOUT_PIPE:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1060 ret_stdout = va_arg (args, int *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1061 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1062 case EGG_DESKTOP_FILE_LAUNCH_RETURN_STDERR_PIPE:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1063 ret_stderr = va_arg (args, int *);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1064 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1065 case EGG_DESKTOP_FILE_LAUNCH_RETURN_STARTUP_ID:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1066 ret_startup_id = va_arg (args, char **);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1067 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1068
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1069 default:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1070 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1071 EGG_DESKTOP_FILE_ERROR_UNRECOGNIZED_OPTION,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1072 _("Unrecognized launch option: %d"),
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1073 GPOINTER_TO_INT (option));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1074 success = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1075 goto out;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1076 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1077 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1078
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1079 if (screen)
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 char *display_name = gdk_screen_make_display_name (screen);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1082 char *display_env = g_strdup_printf ("DISPLAY=%s", display_name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1083 env = array_putenv (env, display_env);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1084 g_free (display_name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1085 g_free (display_env);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1086
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1087 display = gdk_screen_get_display (screen);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1088 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1089 else
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_display_get_default ();
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1092 screen = gdk_display_get_default_screen (display);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1093 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1094 screen_num = gdk_screen_get_number (screen);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1095
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1096 translated_documents = translate_document_list (desktop_file, documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1097 docs = translated_documents;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1098
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1099 success = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1100
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1101 do
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 command = parse_exec (desktop_file, &docs, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1104 if (!command)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1105 goto out;
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 if (!g_shell_parse_argv (command, &argc, &argv, error))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1108 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1109 g_free (command);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1110 goto out;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1111 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1112 g_free (command);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1113
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1114 #ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1115 startup_id = start_startup_notification (display, desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1116 argv[0], screen_num,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1117 workspace, launch_time);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1118 if (startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1119 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1120 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
1121 startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1122 env = array_putenv (env, startup_id_env);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1123 g_free (startup_id_env);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1124 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1125 #else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1126 startup_id = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1127 #endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
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 current_success =
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1130 g_spawn_async_with_pipes (directory,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1131 argv,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1132 env ? (char **)(env->pdata) : NULL,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1133 flags,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1134 setup_func, setup_data,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1135 ret_pid,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1136 ret_stdin, ret_stdout, ret_stderr,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1137 error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1138 g_strfreev (argv);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1139
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1140 if (startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1141 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1142 #ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1143 if (current_success)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1144 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1145 set_startup_notification_timeout (display, startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1146
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1147 if (ret_startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1148 *ret_startup_id = startup_id;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1149 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1150 g_free (startup_id);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1151 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1152 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1153 #endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
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 if (ret_startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1157 *ret_startup_id = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1158
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1159 if (current_success)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1160 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1161 /* If we successfully launch any instances of the app, make
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1162 * sure we return TRUE and don't set @error.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1163 */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1164 success = TRUE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1165 error = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1166
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1167 /* Also, only set the output params on the first one */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1168 ret_pid = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1169 ret_stdin = ret_stdout = ret_stderr = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1170 ret_startup_id = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1171 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1172 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1173 while (docs && current_success);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1174
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1175 out:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1176 if (env)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1177 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1178 g_strfreev ((char **)env->pdata);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1179 g_ptr_array_free (env, FALSE);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1180 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1181 free_document_list (translated_documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1182
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1183 return success;
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
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 * egg_desktop_file_launch:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1188 * @desktop_file: an #EggDesktopFile
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1189 * @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
1190 * @error: error pointer
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1191 * @...: additional options
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1192 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1193 * Launches @desktop_file with the given arguments. Additional options
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1194 * can be specified as follows:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1195 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1196 * %EGG_DESKTOP_FILE_LAUNCH_CLEARENV: (no arguments)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1197 * clears the environment in the child process
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1198 * %EGG_DESKTOP_FILE_LAUNCH_PUTENV: (char **variables)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1199 * adds the NAME=VALUE strings in the given %NULL-terminated
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1200 * array to the child process's environment
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1201 * %EGG_DESKTOP_FILE_LAUNCH_SCREEN: (GdkScreen *screen)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1202 * causes the application to be launched on the given screen
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1203 * %EGG_DESKTOP_FILE_LAUNCH_WORKSPACE: (int workspace)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1204 * causes the application to be launched on the given workspace
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1205 * %EGG_DESKTOP_FILE_LAUNCH_DIRECTORY: (char *dir)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1206 * causes the application to be launched in the given directory
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1207 * %EGG_DESKTOP_FILE_LAUNCH_TIME: (guint32 launch_time)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1208 * sets the "launch time" for the application. If the user
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1209 * interacts with another window after @launch_time but before
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1210 * the launched application creates its first window, the window
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1211 * 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
1212 * Passing 0 for @launch_time will explicitly request that the
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1213 * application not receive focus.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1214 * %EGG_DESKTOP_FILE_LAUNCH_FLAGS (GSpawnFlags flags)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1215 * Sets additional #GSpawnFlags to use. See g_spawn_async() for
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1216 * more details.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1217 * %EGG_DESKTOP_FILE_LAUNCH_SETUP_FUNC (GSpawnChildSetupFunc, gpointer)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1218 * 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
1219 * (See g_spawn_async() for more details.)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1220 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1221 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_PID (GPid **pid)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1222 * 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
1223 * application.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1224 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_STARTUP_ID (char **startup_id)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1225 * On a successful launch, sets *@startup_id to the Startup
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1226 * Notification "startup id" of the launched application.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1227 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_STDIN_PIPE (int *fd)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1228 * 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
1229 * a pipe connected to the application's stdin.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1230 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_STDOUT_PIPE (int *fd)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1231 * 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
1232 * a pipe connected to the application's stdout.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1233 * %EGG_DESKTOP_FILE_LAUNCH_RETURN_STDERR_PIPE (int *fd)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1234 * 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
1235 * a pipe connected to the application's stderr.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1236 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1237 * The options should be terminated with a single %NULL.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1238 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1239 * If @documents contains multiple documents, but
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1240 * egg_desktop_file_accepts_multiple() returns %FALSE for
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1241 * @desktop_file, then egg_desktop_file_launch() will actually launch
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1242 * multiple instances of the application. In that case, the return
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1243 * value (as well as any values passed via
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1244 * %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
1245 * first instance of the application that was launched (but the
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1246 * %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
1247 * instance).
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1248 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1249 * Return value: %TRUE if the application was successfully launched.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1250 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1251 gboolean
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1252 egg_desktop_file_launch (EggDesktopFile *desktop_file,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1253 GSList *documents, GError **error,
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 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1256 va_list args;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1257 gboolean success;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1258 EggDesktopFile *app_desktop_file;
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 switch (desktop_file->type)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1261 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1262 case EGG_DESKTOP_FILE_TYPE_APPLICATION:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1263 va_start (args, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1264 success = egg_desktop_file_launchv (desktop_file, documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1265 args, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1266 va_end (args);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1267 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1268
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1269 case EGG_DESKTOP_FILE_TYPE_LINK:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1270 if (documents)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1271 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1272 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1273 EGG_DESKTOP_FILE_ERROR_NOT_LAUNCHABLE,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1274 _("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
1275 return FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1276 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1277
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1278 if (!parse_link (desktop_file, &app_desktop_file, &documents, error))
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 va_start (args, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1282 success = egg_desktop_file_launchv (app_desktop_file, documents,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1283 args, error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1284 va_end (args);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1285
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1286 egg_desktop_file_free (app_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1287 free_document_list (documents);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1288 break;
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 default:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1291 g_set_error (error, EGG_DESKTOP_FILE_ERROR,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1292 EGG_DESKTOP_FILE_ERROR_NOT_LAUNCHABLE,
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1293 _("Not a launchable item"));
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1294 success = FALSE;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1295 break;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1296 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1297
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1298 return success;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1299 }
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 GQuark
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1303 egg_desktop_file_error_quark (void)
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 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
1306 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1307
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 G_LOCK_DEFINE_STATIC (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1310 static EggDesktopFile *egg_desktop_file;
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 * egg_set_desktop_file:
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1314 * @desktop_file_path: path to the application's 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 * Creates an #EggDesktopFile for the application from the data at
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1317 * @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
1318 * with the localized application name from the desktop file, and
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1319 * gtk_window_set_default_icon_name() or
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1320 * 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
1321 * icon. Other code may use additional information from the desktop
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1322 * file.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1323 *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1324 * Note that for thread safety reasons, this function can only
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1325 * be called once.
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1326 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1327 void
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1328 egg_set_desktop_file (const char *desktop_file_path)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1329 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1330 GError *error = NULL;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1331
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1332 G_LOCK (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1333 if (egg_desktop_file)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1334 egg_desktop_file_free (egg_desktop_file);
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 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
1337 if (error)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1338 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1339 g_warning ("Could not load desktop file '%s': %s",
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1340 desktop_file_path, error->message);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1341 g_error_free (error);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1342 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1343
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1344 /* Set localized application name and default window icon */
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1345 if (egg_desktop_file->name)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1346 g_set_application_name (egg_desktop_file->name);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1347 if (egg_desktop_file->icon)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1348 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1349 if (g_path_is_absolute (egg_desktop_file->icon))
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1350 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
1351 else
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1352 gtk_window_set_default_icon_name (egg_desktop_file->icon);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1353 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1354
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1355 G_UNLOCK (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1356 }
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1357
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1358 /**
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1359 * egg_get_desktop_file:
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 * Gets the application's #EggDesktopFile, as set by
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1362 * egg_set_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 * 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
1365 **/
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1366 EggDesktopFile *
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1367 egg_get_desktop_file (void)
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1368 {
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1369 EggDesktopFile *retval;
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 G_LOCK (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1372 retval = egg_desktop_file;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1373 G_UNLOCK (egg_desktop_file);
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1374
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1375 return retval;
c942eaef7bc6 Implement session management.
Ivan N. Zlatev <contact@i-nz.net>
parents:
diff changeset
1376 }