Mercurial > pidgin
annotate src/session.c @ 8348:9f11f793c19e
[gaim-migrate @ 9072]
use the account alias before the buddy alias, if it exists
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Thu, 26 Feb 2004 17:54:40 +0000 |
| parents | 084ed9f7ac19 |
| children | 56360561af5e |
| rev | line source |
|---|---|
| 4158 | 1 /* |
| 2 * session management for Gaim | |
| 3 * | |
| 8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 * source distribution. | |
| 4158 | 7 * |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5593
diff
changeset
|
23 #include "internal.h" |
| 4158 | 24 |
| 6245 | 25 #include "core.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5593
diff
changeset
|
26 #include "debug.h" |
|
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
27 #include "eventloop.h" |
| 4158 | 28 |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5593
diff
changeset
|
29 extern char *opt_rcfile_arg; |
| 4158 | 30 |
| 31 #ifdef USE_SM | |
| 32 | |
| 33 #include <X11/ICE/ICElib.h> | |
| 34 #include <X11/SM/SMlib.h> | |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6245
diff
changeset
|
35 #include <gdk/gdkx.h> |
| 4158 | 36 #include <unistd.h> |
| 37 #include <fcntl.h> | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5593
diff
changeset
|
38 |
| 4158 | 39 #define ERROR_LENGTH 512 |
| 40 | |
| 41 static IceIOErrorHandler ice_installed_io_error_handler; | |
| 42 static SmcConn session = NULL; | |
| 43 static gchar *myself = NULL; | |
| 44 static gboolean had_first_save = FALSE; | |
| 45 gboolean session_managed = FALSE; | |
| 46 | |
| 47 /* ICE belt'n'braces stuff */ | |
| 48 | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
49 struct ice_connection_info { |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
50 IceConn connection; |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
51 guint input_id; |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
52 }; |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
53 |
|
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
54 static void ice_process_messages(gpointer data, gint fd, |
|
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
55 GaimInputCondition condition) { |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
56 struct ice_connection_info *conninfo = (struct ice_connection_info*) data; |
| 4158 | 57 IceProcessMessagesStatus status; |
| 58 | |
| 59 /* please don't block... please! */ | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
60 status = IceProcessMessages(conninfo->connection, NULL, NULL); |
| 4158 | 61 |
| 62 if (status == IceProcessMessagesIOError) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
63 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
64 "ICE IO error, closing connection... "); |
| 4158 | 65 |
| 66 /* IO error, please disconnect */ | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
67 IceSetShutdownNegotiation(conninfo->connection, False); |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
68 IceCloseConnection(conninfo->connection); |
| 4158 | 69 |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
70 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n"); |
| 4158 | 71 |
| 72 /* cancel the handler */ | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
73 gaim_input_remove(conninfo->input_id); |
| 4158 | 74 } |
| 75 } | |
| 76 | |
| 77 static void ice_connection_watch(IceConn connection, IcePointer client_data, | |
| 78 Bool opening, IcePointer *watch_data) { | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
79 struct ice_connection_info *conninfo = NULL; |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
80 |
| 4158 | 81 if (opening) { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
82 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
83 "Handling new ICE connection... "); |
| 4158 | 84 |
| 85 /* ensure ICE connection is not passed to child processes */ | |
| 86 fcntl(IceConnectionNumber(connection), F_SETFD, FD_CLOEXEC); | |
| 87 | |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
88 conninfo = g_new(struct ice_connection_info, 1); |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
89 conninfo->connection = connection; |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
90 |
|
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
91 /* watch the connection */ |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
92 conninfo->input_id = gaim_input_add(IceConnectionNumber(connection), GAIM_INPUT_READ, |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
93 ice_process_messages, conninfo); |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
94 *watch_data = conninfo; |
| 4158 | 95 } else { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
96 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
97 "Handling closed ICE connection... "); |
| 4158 | 98 |
|
8280
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
99 /* get the input ID back and stop watching it */ |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
100 conninfo = (struct ice_connection_info*) *watch_data; |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
101 gaim_input_remove(conninfo->input_id); |
|
084ed9f7ac19
[gaim-migrate @ 9004]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
102 g_free(conninfo); |
| 4158 | 103 } |
| 104 | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
105 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n"); |
| 4158 | 106 } |
| 107 | |
| 108 /* We call any handler installed before (or after) ice_init but | |
| 109 * avoid calling the default libICE handler which does an exit(). | |
| 110 * | |
| 111 * This means we do nothing by default, which is probably correct, | |
| 112 * the connection will get closed by libICE | |
| 113 */ | |
| 114 | |
| 115 static void ice_io_error_handler(IceConn connection) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
116 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
117 "Handling ICE IO error... "); |
| 4158 | 118 |
| 119 if (ice_installed_io_error_handler) | |
| 120 (*ice_installed_io_error_handler)(connection); | |
| 121 | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
122 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n"); |
| 4158 | 123 } |
| 124 | |
| 125 static void ice_init() { | |
| 126 IceIOErrorHandler default_handler; | |
| 127 | |
| 128 ice_installed_io_error_handler = IceSetIOErrorHandler(NULL); | |
| 129 default_handler = IceSetIOErrorHandler(ice_io_error_handler); | |
| 130 | |
| 131 if (ice_installed_io_error_handler == default_handler) | |
| 132 ice_installed_io_error_handler = NULL; | |
| 133 | |
| 134 IceAddConnectionWatch(ice_connection_watch, NULL); | |
| 135 | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
136 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
137 "ICE initialized.\n"); |
| 4158 | 138 } |
| 139 | |
| 4281 | 140 /* my magic utility function */ |
| 141 | |
| 142 static gchar **session_make_command(gchar *client_id) { | |
| 143 gint i = 2; | |
| 144 gint j = 0; | |
| 145 gchar **ret; | |
| 146 | |
| 147 if (client_id) i += 2; | |
| 148 if (opt_rcfile_arg) i += 2; | |
| 149 | |
| 150 ret = g_new(gchar *, i); | |
| 151 ret[j++] = g_strdup(myself); | |
| 152 | |
| 153 if (client_id) { | |
| 154 ret[j++] = g_strdup("--session"); | |
| 155 ret[j++] = g_strdup(client_id); | |
| 156 } | |
| 157 | |
| 158 if (opt_rcfile_arg) { | |
| 159 ret[j++] = g_strdup("--file"); | |
| 160 ret[j++] = g_strdup(opt_rcfile_arg); | |
| 161 } | |
| 162 | |
| 163 ret[j++] = NULL; | |
| 164 | |
| 165 return ret; | |
| 166 } | |
| 167 | |
| 4158 | 168 /* SM callback handlers */ |
| 169 | |
| 170 void session_save_yourself(SmcConn conn, SmPointer data, int save_type, | |
| 171 Bool shutdown, int interact_style, Bool fast) { | |
| 172 if (had_first_save == FALSE && save_type == SmSaveLocal && | |
| 173 interact_style == SmInteractStyleNone && !shutdown && | |
| 174 !fast) { | |
| 175 /* this is just a dry run, spit it back */ | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
176 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
177 "Received first save_yourself\n"); |
| 4158 | 178 SmcSaveYourselfDone(conn, True); |
| 179 had_first_save = TRUE; | |
| 180 return; | |
| 181 } | |
| 182 | |
| 183 /* tum ti tum... don't add anything else here without * | |
| 184 * reading SMlib.PS from an X.org ftp server near you */ | |
| 185 | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
186 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
187 "Received save_yourself\n"); |
| 4158 | 188 |
| 189 if (save_type == SmSaveGlobal || save_type == SmSaveBoth) { | |
| 190 /* may as well do something ... */ | |
|
5593
b07aa997ddd8
[gaim-migrate @ 5997]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
191 /* or not -- save_prefs(); */ |
| 4158 | 192 } |
| 193 | |
| 194 SmcSaveYourselfDone(conn, True); | |
| 195 } | |
| 196 | |
| 197 void session_die(SmcConn conn, SmPointer data) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
198 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
199 "Received die\n"); |
|
6179
16e384bb7fbf
[gaim-migrate @ 6664]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
200 gaim_core_quit(); |
| 4158 | 201 } |
| 202 | |
| 203 void session_save_complete(SmcConn conn, SmPointer data) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
204 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
205 "Received save_complete\n"); |
| 4158 | 206 } |
| 207 | |
| 208 void session_shutdown_cancelled(SmcConn conn, SmPointer data) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
209 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
210 "Received shutdown_cancelled\n"); |
| 4158 | 211 } |
| 212 | |
| 213 /* utility functions stolen from Gnome-client */ | |
| 214 | |
| 215 static void session_set_value(SmcConn conn, gchar *name, char *type, | |
| 216 int num_vals, SmPropValue *vals) { | |
| 217 SmProp *proplist[1]; | |
| 218 SmProp prop; | |
| 219 | |
| 220 g_return_if_fail(conn); | |
| 221 | |
| 222 prop.name = name; | |
| 223 prop.type = type; | |
| 224 prop.num_vals = num_vals; | |
| 225 prop.vals = vals; | |
| 226 | |
| 227 proplist[0] = ∝ | |
| 228 SmcSetProperties(conn, 1, proplist); | |
| 229 } | |
| 230 | |
| 231 static void session_set_string(SmcConn conn, gchar *name, gchar *value) { | |
| 232 SmPropValue val; | |
| 233 | |
| 234 g_return_if_fail(name); | |
| 235 | |
| 236 val.length = strlen (value)+1; | |
| 237 val.value = value; | |
| 238 | |
| 239 session_set_value(conn, name, SmARRAY8, 1, &val); | |
| 240 } | |
| 241 | |
| 242 static void session_set_gchar(SmcConn conn, gchar *name, gchar value) { | |
| 243 SmPropValue val; | |
| 244 | |
| 245 g_return_if_fail(name); | |
| 246 | |
| 247 val.length = 1; | |
| 248 val.value = &value; | |
| 249 | |
| 250 session_set_value(conn, name, SmCARD8, 1, &val); | |
| 251 } | |
| 252 | |
| 253 static void session_set_array(SmcConn conn, gchar *name, gchar *array[]) { | |
| 254 gint argc; | |
| 255 gchar **ptr; | |
| 256 gint i; | |
| 257 | |
| 258 SmPropValue *vals; | |
| 259 | |
| 260 g_return_if_fail (name); | |
| 261 | |
| 262 /* We count the number of elements in our array. */ | |
| 263 for (ptr = array, argc = 0; *ptr ; ptr++, argc++) /* LOOP */; | |
| 264 | |
| 265 /* Now initialize the 'vals' array. */ | |
| 266 vals = g_new (SmPropValue, argc); | |
| 267 for (ptr = array, i = 0 ; i < argc ; ptr++, i++) { | |
| 268 vals[i].length = strlen (*ptr); | |
| 269 vals[i].value = *ptr; | |
| 270 } | |
| 271 | |
| 272 session_set_value(conn, name, SmLISTofARRAY8, argc, vals); | |
| 273 | |
| 274 g_free (vals); | |
| 275 } | |
| 276 | |
| 277 #endif /* USE_SM */ | |
| 278 | |
| 279 /* setup functions */ | |
| 280 | |
| 281 void session_init(gchar *argv0, gchar *previous_id) { | |
| 282 #ifdef USE_SM | |
| 283 SmcCallbacks callbacks; | |
| 284 gchar *client_id = NULL; | |
| 285 gchar error[ERROR_LENGTH] = ""; | |
| 286 gchar *tmp = NULL; | |
| 4281 | 287 gchar **cmd = NULL; |
| 4158 | 288 |
| 289 if (session != NULL) { | |
| 290 /* session is already established, what the hell is going on? */ | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
291 gaim_debug(GAIM_DEBUG_WARNING, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
292 "Duplicated call to session_init!\n"); |
| 4158 | 293 return; |
| 294 } | |
| 295 | |
| 296 if (g_getenv("SESSION_MANAGER") == NULL) { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
297 gaim_debug(GAIM_DEBUG_ERROR, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
298 "No SESSION_MANAGER found, aborting.\n"); |
| 4158 | 299 return; |
| 300 } | |
| 301 | |
| 302 ice_init(); | |
| 303 | |
| 304 callbacks.save_yourself.callback = session_save_yourself; | |
| 305 callbacks.die.callback = session_die; | |
| 306 callbacks.save_complete.callback = session_save_complete; | |
| 307 callbacks.shutdown_cancelled.callback = session_shutdown_cancelled; | |
| 308 | |
| 309 callbacks.save_yourself.client_data = NULL; | |
| 310 callbacks.die.client_data = NULL; | |
| 311 callbacks.save_complete.client_data = NULL; | |
| 312 callbacks.shutdown_cancelled.client_data = NULL; | |
| 313 | |
| 4544 | 314 if (previous_id) { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
315 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
316 "Connecting with previous ID %s\n", previous_id); |
| 4544 | 317 } else { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
318 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
319 "Connecting with no previous ID\n"); |
| 4544 | 320 } |
| 4158 | 321 |
| 322 session = SmcOpenConnection(NULL, "session", SmProtoMajor, SmProtoMinor, SmcSaveYourselfProcMask | | |
| 323 SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, | |
| 324 &callbacks, previous_id, &client_id, ERROR_LENGTH, error); | |
| 325 | |
| 326 if (session == NULL) { | |
| 327 if (error[0] != '\0') { | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
328 gaim_debug(GAIM_DEBUG_ERROR, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
329 "Connection failed with error: %s\n", error); |
| 4158 | 330 } else { |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
331 gaim_debug(GAIM_DEBUG_ERROR, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
332 "Connetion failed with unknown error.\n"); |
| 4158 | 333 } |
| 334 return; | |
| 335 } | |
| 336 | |
| 337 tmp = SmcVendor(session); | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
338 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
339 "Connected to manager (%s) with client ID %s\n", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
340 tmp, client_id); |
| 4158 | 341 g_free(tmp); |
| 342 | |
| 343 session_managed = TRUE; | |
| 344 gdk_set_sm_client_id(client_id); | |
| 345 | |
| 4265 | 346 tmp = g_get_current_dir(); |
| 347 session_set_string(session, SmCurrentDirectory, tmp); | |
| 348 g_free(tmp); | |
| 349 | |
| 4210 | 350 tmp = g_strdup_printf("%d", (int) getpid()); |
| 4158 | 351 session_set_string(session, SmProcessID, tmp); |
| 352 g_free(tmp); | |
| 353 | |
| 4210 | 354 tmp = g_strdup(g_get_user_name()); |
| 4158 | 355 session_set_string(session, SmUserID, tmp); |
| 356 g_free(tmp); | |
| 357 | |
| 358 session_set_gchar(session, SmRestartStyleHint, (gchar) SmRestartIfRunning); | |
| 359 session_set_string(session, SmProgram, g_get_prgname()); | |
| 360 | |
| 361 myself = g_strdup(argv0); | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
362 gaim_debug(GAIM_DEBUG_MISC, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
363 "Using %s as command\n", myself); |
| 4158 | 364 |
| 4281 | 365 cmd = session_make_command(NULL); |
| 4158 | 366 session_set_array(session, SmCloneCommand, cmd); |
| 4281 | 367 g_strfreev(cmd); |
| 4158 | 368 |
| 4265 | 369 /* this is currently useless, but gnome-session warns 'the following applications will not |
| 370 save their current status' bla bla if we don't have it and the user checks 'Save Session' | |
| 371 when they log out */ | |
| 4281 | 372 cmd = g_new(gchar *, 2); |
| 373 cmd[0] = g_strdup("/bin/true"); | |
| 374 cmd[1] = NULL; | |
| 4158 | 375 session_set_array(session, SmDiscardCommand, cmd); |
| 4281 | 376 g_strfreev(cmd); |
| 4158 | 377 |
| 4281 | 378 cmd = session_make_command(client_id); |
| 4158 | 379 session_set_array(session, SmRestartCommand, cmd); |
| 4281 | 380 g_strfreev(cmd); |
| 381 | |
| 4158 | 382 g_free(client_id); |
| 383 #endif /* USE_SM */ | |
| 384 } | |
| 385 | |
| 386 void session_end() { | |
| 387 #ifdef USE_SM | |
| 388 if (session == NULL) /* no session to close */ | |
| 389 return; | |
| 390 | |
| 391 SmcCloseConnection(session, 0, NULL); | |
| 392 | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
393 gaim_debug(GAIM_DEBUG_INFO, "Session Management", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
4544
diff
changeset
|
394 "Connection closed.\n"); |
| 4158 | 395 #endif /* USE_SM */ |
| 396 } |
