annotate src/gtksession.c @ 12830:3b4a6e426b99

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