Mercurial > pidgin
annotate src/connection.c @ 10742:4228b6d78506
[gaim-migrate @ 12344]
Combine gaim_connection_destroy and gaim_connection_disconnect
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 27 Mar 2005 00:20:43 +0000 |
parents | 94cc67130789 |
children | ca69d597a5e2 |
rev | line source |
---|---|
5563 | 1 /** |
2 * @file connection.c Connection API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
5631 | 10 * |
5563 | 11 * This program is free software; you can redistribute it and/or modify |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
25 #include "internal.h" |
10740 | 26 #include "account.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
27 #include "blist.h" |
5563 | 28 #include "connection.h" |
5717 | 29 #include "debug.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
30 #include "log.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
31 #include "notify.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
32 #include "prefs.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
33 #include "request.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
34 #include "server.h" |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
35 #include "signals.h" |
6106 | 36 #include "util.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
37 |
5563 | 38 static GList *connections = NULL; |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
39 static GList *connections_connecting = NULL; |
5563 | 40 static GaimConnectionUiOps *connection_ui_ops = NULL; |
41 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
42 static int connections_handle; |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
43 |
10740 | 44 void |
45 gaim_connection_new(GaimAccount *account, gboolean regist, const char *password) | |
5563 | 46 { |
47 GaimConnection *gc; | |
10740 | 48 GaimPlugin *prpl; |
49 GaimPluginProtocolInfo *prpl_info; | |
5563 | 50 |
10740 | 51 g_return_if_fail(account != NULL); |
52 | |
53 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
54 | |
55 if (prpl != NULL) | |
56 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
57 else { | |
58 gchar *message; | |
59 | |
60 message = g_strdup_printf(_("Missing protocol plugin for %s"), | |
61 gaim_account_get_username(account)); | |
62 gaim_notify_error(NULL, regist ? _("Registration Error") : | |
63 _("Connection Error"), message, NULL); | |
64 g_free(message); | |
65 return; | |
66 } | |
67 | |
68 if (regist) | |
69 { | |
70 if (prpl_info->register_user == NULL) | |
71 return; | |
72 } | |
73 else | |
74 { | |
75 if ((password == NULL) && | |
76 !(prpl_info->options & OPT_PROTO_NO_PASSWORD) && | |
77 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL)) | |
78 { | |
79 gaim_debug_error("connection", "Can not connect to account %s without " | |
80 "a password.\n", gaim_account_get_username(account)); | |
81 return; | |
82 } | |
83 } | |
5563 | 84 |
85 gc = g_new0(GaimConnection, 1); | |
10740 | 86 gc->prpl = prpl; |
87 gc->password = g_strdup(password); | |
5563 | 88 gaim_connection_set_account(gc, account); |
10740 | 89 gaim_connection_set_state(gc, GAIM_CONNECTING); |
90 connections = g_list_append(connections, gc); | |
5563 | 91 gaim_account_set_connection(account, gc); |
92 | |
10740 | 93 gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc); |
94 | |
95 if (regist) | |
96 { | |
97 gaim_debug_info("connection", "Registering. gc = %p\n", gc); | |
98 | |
99 /* set this so we don't auto-reconnect after registering */ | |
100 gc->wants_to_die = TRUE; | |
101 | |
102 prpl_info->register_user(account); | |
103 } | |
104 else | |
105 { | |
106 gaim_debug_info("connection", "Connecting. gc = %p\n", gc); | |
107 | |
108 gaim_signal_emit(gaim_accounts_get_handle(), "account-connecting", account); | |
109 prpl_info->login(account, gaim_account_get_active_status(account)); | |
110 } | |
5563 | 111 } |
112 | |
113 void | |
114 gaim_connection_destroy(GaimConnection *gc) | |
115 { | |
5741
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
116 GaimAccount *account; |
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
117 |
5563 | 118 g_return_if_fail(gc != NULL); |
119 | |
5926
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
120 account = gaim_connection_get_account(gc); |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
121 |
10742 | 122 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) { |
123 GList *wins; | |
124 GaimPresence *presence = NULL; | |
5926
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
125 |
10742 | 126 gaim_debug_info("connection", "Disconnecting connection %p\n", gc); |
5930
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
127 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
128 if (gaim_connection_get_state(gc) != GAIM_CONNECTING) |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
129 gaim_blist_remove_account(gaim_connection_get_account(gc)); |
5563 | 130 |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
131 gaim_signal_emit(gaim_connections_get_handle(), "signing-off", gc); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
132 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
133 serv_close(gc); |
5563 | 134 |
6533 | 135 connections = g_list_remove(connections, gc); |
136 | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5788
diff
changeset
|
137 gaim_connection_set_state(gc, GAIM_DISCONNECTED); |
5563 | 138 |
7431 | 139 /* LOG system_log(log_signoff, gc, NULL, |
140 OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */ | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
141 gaim_signal_emit(gaim_connections_get_handle(), "signed-off", gc); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
142 |
10052 | 143 presence = gaim_account_get_presence(account); |
144 if (gaim_presence_is_online(presence) == TRUE) | |
145 gaim_presence_set_status_active(presence, "offline", TRUE); | |
5615
6500a6c8d679
[gaim-migrate @ 6022]
Christian Hammond <chipx86@chipx86.com>
parents:
5581
diff
changeset
|
146 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
147 /* |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
148 * XXX This is a hack! Remove this and replace it with a better event |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
149 * notification system. |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
150 */ |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
151 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
152 GaimConvWindow *win = (GaimConvWindow *)wins->data; |
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
153 gaim_conversation_update(gaim_conv_window_get_conversation_at(win, 0), |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
154 GAIM_CONV_ACCOUNT_OFFLINE); |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
155 } |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
156 |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
157 gaim_request_close_with_handle(gc); |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
158 gaim_notify_close_with_handle(gc); |
10742 | 159 |
160 return; | |
5563 | 161 } |
162 | |
10742 | 163 gaim_debug_info("connection", "Destroying connection %p\n", gc); |
164 | |
165 gaim_account_set_connection(account, NULL); | |
166 | |
167 if (gc->password != NULL) | |
168 g_free(gc->password); | |
5563 | 169 |
10742 | 170 if (gc->display_name != NULL) |
171 g_free(gc->display_name); | |
9848 | 172 |
10742 | 173 if (gc->disconnect_timeout) |
174 gaim_timeout_remove(gc->disconnect_timeout); | |
6029 | 175 |
10742 | 176 g_free(gc); |
6029 | 177 } |
178 | |
5563 | 179 /* |
8130
ff88d4cbf4db
[gaim-migrate @ 8835]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
180 * d:)->-< |
5563 | 181 * |
182 * d:O-\-< | |
8130
ff88d4cbf4db
[gaim-migrate @ 8835]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
183 * |
5563 | 184 * d:D-/-< |
185 * | |
186 * d8D->-< DANCE! | |
187 */ | |
188 | |
189 void | |
190 gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state) | |
191 { | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
192 GaimConnectionUiOps *ops; |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
193 |
5563 | 194 g_return_if_fail(gc != NULL); |
195 | |
5784
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
196 if (gc->state == state) |
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
197 return; |
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
198 |
5563 | 199 gc->state = state; |
200 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
201 ops = gaim_connections_get_ui_ops(); |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
202 |
5905
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
203 if (gc->state == GAIM_CONNECTING) { |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
204 connections_connecting = g_list_append(connections_connecting, gc); |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
205 } |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
206 else { |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
207 connections_connecting = g_list_remove(connections_connecting, gc); |
5905
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
208 } |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
209 |
5563 | 210 if (gc->state == GAIM_CONNECTED) { |
6695 | 211 GaimBlistNode *gnode,*cnode,*bnode; |
5563 | 212 GList *wins; |
9285 | 213 GList *add_buds = NULL; |
10052 | 214 GaimAccount *account; |
215 GaimPresence *presence; | |
216 | |
217 account = gaim_connection_get_account(gc); | |
218 presence = gaim_account_get_presence(account); | |
5563 | 219 |
220 /* Set the time the account came online */ | |
221 time(&gc->login_time); | |
222 | |
10301 | 223 if (gaim_prefs_get_bool("/core/logging/log_system") && |
224 gaim_prefs_get_bool("/core/logging/log_own_states")){ | |
225 GaimLog *log = gaim_account_get_log(account); | |
226 char *msg = g_strdup_printf("+++ %s signed on", | |
227 gaim_account_get_username(account)); | |
228 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
229 gaim_account_get_username(account), gc->login_time, | |
230 msg); | |
231 g_free(msg); | |
232 } | |
233 | |
5563 | 234 if (ops != NULL && ops->connected != NULL) |
235 ops->connected(gc); | |
236 | |
237 gaim_blist_show(); | |
8573 | 238 gaim_blist_add_account(account); |
5563 | 239 |
240 /* | |
241 * XXX This is a hack! Remove this and replace it with a better event | |
242 * notification system. | |
243 */ | |
244 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
245 GaimConvWindow *win = (GaimConvWindow *)wins->data; |
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
246 gaim_conversation_update(gaim_conv_window_get_conversation_at(win, 0), |
5563 | 247 GAIM_CONV_ACCOUNT_ONLINE); |
248 } | |
249 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
250 gaim_signal_emit(gaim_connections_get_handle(), "signed-on", gc); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
251 |
5563 | 252 /* let the prpl know what buddies we pulled out of the local list */ |
10301 | 253 /* XXX - Remove this and let the prpl take care of it itself? */ |
5563 | 254 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
255 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
256 continue; | |
6695 | 257 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
258 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
259 continue; | |
260 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
261 GaimBuddy *b; | |
262 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
263 continue; | |
264 | |
265 b = (GaimBuddy *)bnode; | |
5563 | 266 if(b->account == gc->account) { |
9285 | 267 add_buds = g_list_append(add_buds, b); |
5563 | 268 } |
269 } | |
270 } | |
271 } | |
272 | |
273 if(add_buds) { | |
274 serv_add_buddies(gc, add_buds); | |
275 g_list_free(add_buds); | |
276 } | |
277 | |
278 serv_set_permit_deny(gc); | |
279 } | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
280 else if (gc->state == GAIM_DISCONNECTED) { |
8573 | 281 GaimAccount *account = gaim_connection_get_account(gc); |
282 | |
283 if(gaim_prefs_get_bool("/core/logging/log_system") && | |
284 gaim_prefs_get_bool("/core/logging/log_own_states")){ | |
285 GaimLog *log = gaim_account_get_log(account); | |
286 char *msg = g_strdup_printf("+++ %s signed off", | |
287 gaim_account_get_username(account)); | |
288 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, | |
289 gaim_account_get_username(account), time(NULL), | |
290 msg); | |
9190
9e3289499977
[gaim-migrate @ 9985]
Christian Hammond <chipx86@chipx86.com>
parents:
9019
diff
changeset
|
291 g_free(msg); |
8573 | 292 } |
293 | |
294 gaim_account_destroy_log(account); | |
295 | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
296 if (ops != NULL && ops->disconnected != NULL) |
9190
9e3289499977
[gaim-migrate @ 9985]
Christian Hammond <chipx86@chipx86.com>
parents:
9019
diff
changeset
|
297 ops->disconnected(gc); |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
298 } |
5563 | 299 } |
300 | |
301 void | |
302 gaim_connection_set_account(GaimConnection *gc, GaimAccount *account) | |
303 { | |
304 g_return_if_fail(gc != NULL); | |
305 g_return_if_fail(account != NULL); | |
306 | |
307 gc->account = account; | |
308 } | |
309 | |
310 void | |
311 gaim_connection_set_display_name(GaimConnection *gc, const char *name) | |
312 { | |
313 g_return_if_fail(gc != NULL); | |
314 | |
315 if (gc->display_name != NULL) | |
316 g_free(gc->display_name); | |
317 | |
318 gc->display_name = (name == NULL ? NULL : g_strdup(name)); | |
319 } | |
320 | |
321 GaimConnectionState | |
322 gaim_connection_get_state(const GaimConnection *gc) | |
323 { | |
324 g_return_val_if_fail(gc != NULL, GAIM_DISCONNECTED); | |
325 | |
326 return gc->state; | |
327 } | |
328 | |
329 GaimAccount * | |
330 gaim_connection_get_account(const GaimConnection *gc) | |
331 { | |
332 g_return_val_if_fail(gc != NULL, NULL); | |
333 | |
334 return gc->account; | |
335 } | |
336 | |
337 const char * | |
10740 | 338 gaim_connection_get_password(const GaimConnection *gc) |
339 { | |
340 g_return_val_if_fail(gc != NULL, NULL); | |
341 | |
342 return gc->password; | |
343 } | |
344 | |
345 const char * | |
5563 | 346 gaim_connection_get_display_name(const GaimConnection *gc) |
347 { | |
348 g_return_val_if_fail(gc != NULL, NULL); | |
349 | |
350 return gc->display_name; | |
351 } | |
352 | |
353 void | |
354 gaim_connection_update_progress(GaimConnection *gc, const char *text, | |
355 size_t step, size_t count) | |
356 { | |
357 GaimConnectionUiOps *ops; | |
358 | |
359 g_return_if_fail(gc != NULL); | |
360 g_return_if_fail(text != NULL); | |
361 g_return_if_fail(step < count); | |
362 g_return_if_fail(count > 1); | |
363 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
364 ops = gaim_connections_get_ui_ops(); |
5563 | 365 |
366 if (ops != NULL && ops->connect_progress != NULL) | |
367 ops->connect_progress(gc, text, step, count); | |
368 } | |
369 | |
370 void | |
5571
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
371 gaim_connection_notice(GaimConnection *gc, const char *text) |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
372 { |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
373 GaimConnectionUiOps *ops; |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
374 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
375 g_return_if_fail(gc != NULL); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
376 g_return_if_fail(text != NULL); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
377 |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
378 ops = gaim_connections_get_ui_ops(); |
5571
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
379 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
380 if (ops != NULL && ops->notice != NULL) |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
381 ops->notice(gc, text); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
382 } |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
383 |
10742 | 384 gboolean |
385 gaim_connection_disconnect_cb(gpointer data) | |
386 { | |
387 GaimAccount *account = data; | |
388 | |
389 gaim_account_disconnect(account); | |
390 | |
391 return FALSE; | |
392 } | |
393 | |
5571
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
394 void |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
395 gaim_connection_error(GaimConnection *gc, const char *text) |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
396 { |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
397 GaimConnectionUiOps *ops; |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
398 |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
399 g_return_if_fail(gc != NULL); |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
400 g_return_if_fail(text != NULL); |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
401 |
6393 | 402 /* If we've already got one error, we don't need any more */ |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
403 if (gc->disconnect_timeout) |
6393 | 404 return; |
405 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
406 ops = gaim_connections_get_ui_ops(); |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
407 |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
408 if (ops != NULL) { |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
409 if (ops->report_disconnect != NULL) |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
410 ops->report_disconnect(gc, text); |
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6393
diff
changeset
|
411 } |
5727 | 412 |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8131
diff
changeset
|
413 gc->disconnect_timeout = gaim_timeout_add(0, gaim_connection_disconnect_cb, |
6076 | 414 gaim_connection_get_account(gc)); |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
415 } |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
416 |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
417 void |
5563 | 418 gaim_connections_disconnect_all(void) |
419 { | |
420 GList *l; | |
6113 | 421 GaimConnection *gc; |
5563 | 422 |
6113 | 423 while ((l = gaim_connections_get_all()) != NULL) { |
424 gc = l->data; | |
425 gc->wants_to_die = TRUE; | |
10742 | 426 gaim_account_disconnect(gc->account); |
6113 | 427 } |
5563 | 428 } |
429 | |
430 GList * | |
431 gaim_connections_get_all(void) | |
432 { | |
433 return connections; | |
434 } | |
435 | |
5788
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
436 GList * |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
437 gaim_connections_get_connecting(void) |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
438 { |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
439 return connections_connecting; |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
440 } |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
441 |
5563 | 442 void |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
443 gaim_connections_set_ui_ops(GaimConnectionUiOps *ops) |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
444 { |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
445 connection_ui_ops = ops; |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
446 } |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
447 |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
448 GaimConnectionUiOps * |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
449 gaim_connections_get_ui_ops(void) |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
450 { |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
451 return connection_ui_ops; |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
452 } |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
453 |
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
454 void |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
455 gaim_connections_init(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
456 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
457 void *handle = gaim_connections_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
458 |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
459 gaim_signal_register(handle, "signing-on", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
460 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
461 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6597
fe569b675cd2
[gaim-migrate @ 7121]
Christian Hammond <chipx86@chipx86.com>
parents:
6581
diff
changeset
|
462 GAIM_SUBTYPE_CONNECTION)); |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
463 |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
464 gaim_signal_register(handle, "signed-on", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
465 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
466 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6597
fe569b675cd2
[gaim-migrate @ 7121]
Christian Hammond <chipx86@chipx86.com>
parents:
6581
diff
changeset
|
467 GAIM_SUBTYPE_CONNECTION)); |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
468 |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
469 gaim_signal_register(handle, "signing-off", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
470 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
471 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6597
fe569b675cd2
[gaim-migrate @ 7121]
Christian Hammond <chipx86@chipx86.com>
parents:
6581
diff
changeset
|
472 GAIM_SUBTYPE_CONNECTION)); |
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
473 |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
474 gaim_signal_register(handle, "signed-off", |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
475 gaim_marshal_VOID__POINTER, NULL, 1, |
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6533
diff
changeset
|
476 gaim_value_new(GAIM_TYPE_SUBTYPE, |
6597
fe569b675cd2
[gaim-migrate @ 7121]
Christian Hammond <chipx86@chipx86.com>
parents:
6581
diff
changeset
|
477 GAIM_SUBTYPE_CONNECTION)); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
478 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
479 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
480 void |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
481 gaim_connections_uninit(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
482 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
483 gaim_signals_unregister_by_instance(gaim_connections_get_handle()); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
484 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
485 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
486 void * |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
487 gaim_connections_get_handle(void) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
488 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
489 return &connections_handle; |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6468
diff
changeset
|
490 } |