Sat, 21 Sep 2013 11:54:03 +0200
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
| 12246 | 1 | /* |
| 2 | * @file gtksession.c X Windows session management API | |
|
16254
eeb2bba4dc94
Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents:
15931
diff
changeset
|
3 | * @ingroup pidgin |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* Pidgin is the legal property of its developers, whose names are too numerous |
| 12246 | 7 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 8 | * source distribution. | |
| 9 | * | |
| 10 | * This program is free software; you can redistribute it and/or modify | |
| 11 | * it under the terms of the GNU General Public License as published by | |
| 12 | * the Free Software Foundation; either version 2 of the License, or | |
| 13 | * (at your option) any later version. | |
| 14 | * | |
| 15 | * This program is distributed in the hope that it will be useful, | |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | * GNU General Public License for more details. | |
| 19 | * | |
| 20 | * You should have received a copy of the GNU General Public License | |
| 21 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
16254
diff
changeset
|
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 12246 | 23 | * |
| 24 | */ | |
| 25 | #include "internal.h" | |
| 26 | ||
| 27 | #include "core.h" | |
| 28 | #include "debug.h" | |
| 29 | #include "eventloop.h" | |
|
12410
98d8abd3db98
[gaim-migrate @ 14717]
Richard Laager <rlaager@pidgin.im>
parents:
12246
diff
changeset
|
30 | #include "gtksession.h" |
| 12246 | 31 | |
| 32 | #ifdef USE_SM | |
| 33 | ||
| 34 | #include <X11/ICE/ICElib.h> | |
| 35 | #include <X11/SM/SMlib.h> | |
| 36 | #include <gdk/gdkx.h> | |
| 37 | #include <unistd.h> | |
| 38 | #include <fcntl.h> | |
|
20347
b7de12671217
Save default Gtk+ display in the command line for session restoration.
Ethan Blanton <elb@pidgin.im>
parents:
20147
diff
changeset
|
39 | #include <gdk/gdk.h> |
|
22637
26a7edb3cc75
gdk_display_get_name() and gdk_display_get_default() are new in Gtk 2.2
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
22104
diff
changeset
|
40 | #include <gtk/gtk.h> |
| 12246 | 41 | |
|
33170
ce4447562d64
Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
42 | #include "gtk3compat.h" |
|
ce4447562d64
Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
43 | |
| 12246 | 44 | #define ERROR_LENGTH 512 |
| 45 | ||
| 46 | static IceIOErrorHandler ice_installed_io_error_handler; | |
| 47 | static SmcConn session = NULL; | |
| 48 | static gchar *myself = NULL; | |
| 49 | static gboolean had_first_save = FALSE; | |
| 50 | static gboolean session_managed = FALSE; | |
| 51 | ||
| 52 | /* ICE belt'n'braces stuff */ | |
| 53 | ||
| 54 | struct ice_connection_info { | |
| 55 | IceConn connection; | |
| 56 | guint input_id; | |
| 57 | }; | |
| 58 | ||
| 59 | static void ice_process_messages(gpointer data, gint fd, | |
| 15884 | 60 | PurpleInputCondition condition) { |
| 12246 | 61 | struct ice_connection_info *conninfo = (struct ice_connection_info*) data; |
| 62 | IceProcessMessagesStatus status; | |
| 63 | ||
| 64 | /* please don't block... please! */ | |
| 65 | status = IceProcessMessages(conninfo->connection, NULL, NULL); | |
| 66 | ||
| 67 | if (status == IceProcessMessagesIOError) { | |
| 15884 | 68 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 69 | "ICE IO error, closing connection... "); |
| 70 | ||
| 71 | /* IO error, please disconnect */ | |
| 72 | IceSetShutdownNegotiation(conninfo->connection, False); | |
| 73 | IceCloseConnection(conninfo->connection); | |
| 74 | ||
|
34297
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
75 | if (purple_debug_is_verbose()) { |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
76 | purple_debug_misc("Session Management", |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
77 | "Connection closed."); |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
78 | } |
| 12246 | 79 | |
| 80 | /* cancel the handler */ | |
| 15884 | 81 | purple_input_remove(conninfo->input_id); |
| 12246 | 82 | } |
| 83 | } | |
| 84 | ||
| 85 | static void ice_connection_watch(IceConn connection, IcePointer client_data, | |
| 86 | Bool opening, IcePointer *watch_data) { | |
| 87 | struct ice_connection_info *conninfo = NULL; | |
| 88 | ||
| 89 | if (opening) { | |
|
34297
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
90 | purple_debug_misc("Session Management", |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
91 | "Handling new ICE connection..."); |
| 12246 | 92 | |
| 93 | /* ensure ICE connection is not passed to child processes */ | |
| 94 | fcntl(IceConnectionNumber(connection), F_SETFD, FD_CLOEXEC); | |
| 95 | ||
| 96 | conninfo = g_new(struct ice_connection_info, 1); | |
| 97 | conninfo->connection = connection; | |
| 98 | ||
| 99 | /* watch the connection */ | |
| 15884 | 100 | conninfo->input_id = purple_input_add(IceConnectionNumber(connection), PURPLE_INPUT_READ, |
| 12246 | 101 | ice_process_messages, conninfo); |
| 102 | *watch_data = conninfo; | |
| 103 | } else { | |
| 15884 | 104 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
|
21124
c293f3c40d4a
Add some missing debugging newlines.
Daniel Atallah <datallah@pidgin.im>
parents:
20347
diff
changeset
|
105 | "Handling closed ICE connection... \n"); |
| 12246 | 106 | |
| 107 | /* get the input ID back and stop watching it */ | |
| 108 | conninfo = (struct ice_connection_info*) *watch_data; | |
| 15884 | 109 | purple_input_remove(conninfo->input_id); |
| 12246 | 110 | g_free(conninfo); |
| 111 | } | |
| 112 | ||
|
34297
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
113 | if (purple_debug_is_verbose()) { |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
114 | purple_debug_misc("Session Management", |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
115 | "ICE connection handled."); |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
116 | } |
| 12246 | 117 | } |
| 118 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
22637
diff
changeset
|
119 | /* We call any handler installed before (or after) ice_init but |
| 12246 | 120 | * avoid calling the default libICE handler which does an exit(). |
| 121 | * | |
| 122 | * This means we do nothing by default, which is probably correct, | |
| 123 | * the connection will get closed by libICE | |
| 124 | */ | |
| 125 | ||
| 126 | static void ice_io_error_handler(IceConn connection) { | |
| 15884 | 127 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 128 | "Handling ICE IO error... "); |
| 129 | ||
| 130 | if (ice_installed_io_error_handler) | |
| 131 | (*ice_installed_io_error_handler)(connection); | |
| 132 | ||
|
34297
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
133 | if (purple_debug_is_verbose()) { |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
134 | purple_debug_misc("Session Management", |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
135 | "ICE IO error handled."); |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
136 | } |
| 12246 | 137 | } |
| 138 | ||
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
21124
diff
changeset
|
139 | static void ice_init(void) { |
| 12246 | 140 | IceIOErrorHandler default_handler; |
| 141 | ||
| 142 | ice_installed_io_error_handler = IceSetIOErrorHandler(NULL); | |
| 143 | default_handler = IceSetIOErrorHandler(ice_io_error_handler); | |
| 144 | ||
| 145 | if (ice_installed_io_error_handler == default_handler) | |
| 146 | ice_installed_io_error_handler = NULL; | |
| 147 | ||
| 148 | IceAddConnectionWatch(ice_connection_watch, NULL); | |
| 149 | ||
|
34297
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
150 | if (purple_debug_is_verbose()) { |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
151 | purple_debug_misc("Session Management", "ICE initialized."); |
|
0f1f0b8c84f8
Fix some debug log warnings, adjust verbosity level
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33170
diff
changeset
|
152 | } |
| 12246 | 153 | } |
| 154 | ||
| 155 | /* my magic utility function */ | |
| 156 | ||
| 157 | static gchar **session_make_command(gchar *client_id, gchar *config_dir) { | |
|
20347
b7de12671217
Save default Gtk+ display in the command line for session restoration.
Ethan Blanton <elb@pidgin.im>
parents:
20147
diff
changeset
|
158 | gint i = 4; |
| 12246 | 159 | gint j = 0; |
| 160 | gchar **ret; | |
| 161 | ||
| 162 | if (client_id) i += 2; | |
| 15884 | 163 | if (config_dir) i += 2; /* we will specify purple's user dir */ |
| 12246 | 164 | |
| 165 | ret = g_new(gchar *, i); | |
| 166 | ret[j++] = g_strdup(myself); | |
| 167 | ||
| 168 | if (client_id) { | |
| 169 | ret[j++] = g_strdup("--session"); | |
| 170 | ret[j++] = g_strdup(client_id); | |
| 171 | } | |
| 172 | ||
| 173 | if (config_dir) { | |
| 174 | ret[j++] = g_strdup("--config"); | |
| 175 | ret[j++] = g_strdup(config_dir); | |
| 176 | } | |
| 177 | ||
|
20347
b7de12671217
Save default Gtk+ display in the command line for session restoration.
Ethan Blanton <elb@pidgin.im>
parents:
20147
diff
changeset
|
178 | ret[j++] = g_strdup("--display"); |
|
b7de12671217
Save default Gtk+ display in the command line for session restoration.
Ethan Blanton <elb@pidgin.im>
parents:
20147
diff
changeset
|
179 | ret[j++] = g_strdup((gchar *)gdk_display_get_name(gdk_display_get_default())); |
|
b7de12671217
Save default Gtk+ display in the command line for session restoration.
Ethan Blanton <elb@pidgin.im>
parents:
20147
diff
changeset
|
180 | |
|
30702
8a1938367841
These are dead increments.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
30269
diff
changeset
|
181 | ret[j] = NULL; |
| 12246 | 182 | |
| 183 | return ret; | |
| 184 | } | |
| 185 | ||
| 186 | /* SM callback handlers */ | |
| 187 | ||
| 188 | static void session_save_yourself(SmcConn conn, SmPointer data, int save_type, | |
| 189 | Bool shutdown, int interact_style, Bool fast) { | |
| 190 | if (had_first_save == FALSE && save_type == SmSaveLocal && | |
| 191 | interact_style == SmInteractStyleNone && !shutdown && | |
| 192 | !fast) { | |
| 193 | /* this is just a dry run, spit it back */ | |
| 15884 | 194 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 195 | "Received first save_yourself\n"); |
| 196 | SmcSaveYourselfDone(conn, True); | |
| 197 | had_first_save = TRUE; | |
| 198 | return; | |
| 199 | } | |
| 200 | ||
| 201 | /* tum ti tum... don't add anything else here without * | |
| 202 | * reading SMlib.PS from an X.org ftp server near you */ | |
| 203 | ||
| 15884 | 204 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 205 | "Received save_yourself\n"); |
| 206 | ||
| 207 | if (save_type == SmSaveGlobal || save_type == SmSaveBoth) { | |
| 208 | /* may as well do something ... */ | |
| 209 | /* or not -- save_prefs(); */ | |
| 210 | } | |
| 211 | ||
| 212 | SmcSaveYourselfDone(conn, True); | |
| 213 | } | |
| 214 | ||
| 215 | static void session_die(SmcConn conn, SmPointer data) { | |
| 15884 | 216 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 217 | "Received die\n"); |
| 15884 | 218 | purple_core_quit(); |
| 12246 | 219 | } |
| 220 | ||
| 221 | static void session_save_complete(SmcConn conn, SmPointer data) { | |
| 15884 | 222 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 223 | "Received save_complete\n"); |
| 224 | } | |
| 225 | ||
| 226 | static void session_shutdown_cancelled(SmcConn conn, SmPointer data) { | |
| 15884 | 227 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 228 | "Received shutdown_cancelled\n"); |
| 229 | } | |
| 230 | ||
| 231 | /* utility functions stolen from Gnome-client */ | |
| 232 | ||
| 233 | static void session_set_value(SmcConn conn, gchar *name, char *type, | |
| 234 | int num_vals, SmPropValue *vals) { | |
| 235 | SmProp *proplist[1]; | |
| 236 | SmProp prop; | |
| 237 | ||
| 238 | g_return_if_fail(conn); | |
| 239 | ||
| 240 | prop.name = name; | |
| 241 | prop.type = type; | |
| 242 | prop.num_vals = num_vals; | |
| 243 | prop.vals = vals; | |
| 244 | ||
| 245 | proplist[0] = ∝ | |
| 246 | SmcSetProperties(conn, 1, proplist); | |
| 247 | } | |
| 248 | ||
| 249 | static void session_set_string(SmcConn conn, gchar *name, gchar *value) { | |
| 250 | SmPropValue val; | |
| 251 | ||
| 252 | g_return_if_fail(name); | |
| 253 | ||
| 254 | val.length = strlen (value)+1; | |
| 255 | val.value = value; | |
| 256 | ||
| 257 | session_set_value(conn, name, SmARRAY8, 1, &val); | |
| 258 | } | |
| 259 | ||
| 260 | static void session_set_gchar(SmcConn conn, gchar *name, gchar value) { | |
| 261 | SmPropValue val; | |
| 262 | ||
| 263 | g_return_if_fail(name); | |
| 264 | ||
| 265 | val.length = 1; | |
| 266 | val.value = &value; | |
| 267 | ||
| 268 | session_set_value(conn, name, SmCARD8, 1, &val); | |
| 269 | } | |
| 270 | ||
| 271 | static void session_set_array(SmcConn conn, gchar *name, gchar *array[]) { | |
| 272 | gint argc; | |
| 273 | gchar **ptr; | |
| 274 | gint i; | |
| 275 | ||
| 276 | SmPropValue *vals; | |
| 277 | ||
| 278 | g_return_if_fail (name); | |
| 279 | ||
| 280 | /* We count the number of elements in our array. */ | |
| 281 | for (ptr = array, argc = 0; *ptr ; ptr++, argc++) /* LOOP */; | |
| 282 | ||
| 283 | /* Now initialize the 'vals' array. */ | |
| 284 | vals = g_new (SmPropValue, argc); | |
| 285 | for (ptr = array, i = 0 ; i < argc ; ptr++, i++) { | |
| 286 | vals[i].length = strlen (*ptr); | |
| 287 | vals[i].value = *ptr; | |
| 288 | } | |
| 289 | ||
| 290 | session_set_value(conn, name, SmLISTofARRAY8, argc, vals); | |
| 291 | ||
| 292 | g_free (vals); | |
| 293 | } | |
| 294 | ||
| 295 | #endif /* USE_SM */ | |
| 296 | ||
| 297 | /* setup functions */ | |
| 298 | ||
| 299 | void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
300 | pidgin_session_init(gchar *argv0, gchar *previous_id, gchar *config_dir) |
| 12246 | 301 | { |
| 302 | #ifdef USE_SM | |
| 303 | SmcCallbacks callbacks; | |
| 304 | gchar *client_id = NULL; | |
| 305 | gchar error[ERROR_LENGTH] = ""; | |
| 306 | gchar *tmp = NULL; | |
| 307 | gchar **cmd = NULL; | |
| 308 | ||
| 309 | if (session != NULL) { | |
| 310 | /* session is already established, what the hell is going on? */ | |
| 15884 | 311 | purple_debug(PURPLE_DEBUG_WARNING, "Session Management", |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
312 | "Duplicated call to pidgin_session_init!\n"); |
| 12246 | 313 | return; |
| 314 | } | |
| 315 | ||
| 316 | if (g_getenv("SESSION_MANAGER") == NULL) { | |
| 15884 | 317 | purple_debug(PURPLE_DEBUG_ERROR, "Session Management", |
| 12246 | 318 | "No SESSION_MANAGER found, aborting.\n"); |
| 319 | return; | |
| 320 | } | |
| 321 | ||
| 322 | ice_init(); | |
| 323 | ||
| 324 | callbacks.save_yourself.callback = session_save_yourself; | |
| 325 | callbacks.die.callback = session_die; | |
| 326 | callbacks.save_complete.callback = session_save_complete; | |
| 327 | callbacks.shutdown_cancelled.callback = session_shutdown_cancelled; | |
| 328 | ||
| 329 | callbacks.save_yourself.client_data = NULL; | |
| 330 | callbacks.die.client_data = NULL; | |
| 331 | callbacks.save_complete.client_data = NULL; | |
| 332 | callbacks.shutdown_cancelled.client_data = NULL; | |
| 333 | ||
| 334 | if (previous_id) { | |
| 15884 | 335 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 336 | "Connecting with previous ID %s\n", previous_id); |
| 337 | } else { | |
| 15884 | 338 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 339 | "Connecting with no previous ID\n"); |
| 340 | } | |
| 341 | ||
| 342 | session = SmcOpenConnection(NULL, "session", SmProtoMajor, SmProtoMinor, SmcSaveYourselfProcMask | | |
| 343 | SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, | |
| 344 | &callbacks, previous_id, &client_id, ERROR_LENGTH, error); | |
| 345 | ||
| 346 | if (session == NULL) { | |
| 347 | if (error[0] != '\0') { | |
| 15884 | 348 | purple_debug(PURPLE_DEBUG_ERROR, "Session Management", |
| 12246 | 349 | "Connection failed with error: %s\n", error); |
| 350 | } else { | |
| 15884 | 351 | purple_debug(PURPLE_DEBUG_ERROR, "Session Management", |
| 12246 | 352 | "Connetion failed with unknown error.\n"); |
| 353 | } | |
| 354 | return; | |
| 355 | } | |
| 356 | ||
| 357 | tmp = SmcVendor(session); | |
| 15884 | 358 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 359 | "Connected to manager (%s) with client ID %s\n", |
| 360 | tmp, client_id); | |
|
30269
d2943f2cf2fb
The returned value from SmcVendor() should be free'd with free() not
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
29499
diff
changeset
|
361 | free(tmp); |
| 12246 | 362 | |
| 363 | session_managed = TRUE; | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32438
diff
changeset
|
364 | gdk_x11_set_sm_client_id(client_id); |
| 12246 | 365 | |
| 366 | tmp = g_get_current_dir(); | |
| 367 | session_set_string(session, SmCurrentDirectory, tmp); | |
| 368 | g_free(tmp); | |
| 369 | ||
| 370 | tmp = g_strdup_printf("%d", (int) getpid()); | |
| 371 | session_set_string(session, SmProcessID, tmp); | |
| 372 | g_free(tmp); | |
| 373 | ||
| 374 | tmp = g_strdup(g_get_user_name()); | |
| 375 | session_set_string(session, SmUserID, tmp); | |
| 376 | g_free(tmp); | |
| 377 | ||
| 378 | session_set_gchar(session, SmRestartStyleHint, (gchar) SmRestartIfRunning); | |
| 379 | session_set_string(session, SmProgram, g_get_prgname()); | |
| 380 | ||
| 381 | myself = g_strdup(argv0); | |
| 15884 | 382 | purple_debug(PURPLE_DEBUG_MISC, "Session Management", |
| 12246 | 383 | "Using %s as command\n", myself); |
| 384 | ||
| 385 | cmd = session_make_command(NULL, config_dir); | |
| 386 | session_set_array(session, SmCloneCommand, cmd); | |
| 387 | g_strfreev(cmd); | |
| 388 | ||
| 389 | /* this is currently useless, but gnome-session warns 'the following applications will not | |
| 390 | save their current status' bla bla if we don't have it and the user checks 'Save Session' | |
| 391 | when they log out */ | |
| 392 | cmd = g_new(gchar *, 2); | |
| 393 | cmd[0] = g_strdup("/bin/true"); | |
| 394 | cmd[1] = NULL; | |
| 395 | session_set_array(session, SmDiscardCommand, cmd); | |
| 396 | g_strfreev(cmd); | |
| 397 | ||
| 398 | cmd = session_make_command(client_id, config_dir); | |
| 399 | session_set_array(session, SmRestartCommand, cmd); | |
| 400 | g_strfreev(cmd); | |
| 401 | ||
| 402 | g_free(client_id); | |
| 403 | #endif /* USE_SM */ | |
| 404 | } | |
| 405 | ||
| 406 | void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
407 | pidgin_session_end() |
| 12246 | 408 | { |
| 409 | #ifdef USE_SM | |
| 410 | if (session == NULL) /* no session to close */ | |
| 411 | return; | |
| 412 | ||
| 413 | SmcCloseConnection(session, 0, NULL); | |
| 414 | ||
| 15884 | 415 | purple_debug(PURPLE_DEBUG_INFO, "Session Management", |
| 12246 | 416 | "Connection closed.\n"); |
| 417 | #endif /* USE_SM */ | |
| 418 | } |