Mercurial > pidgin.yaz
annotate src/connection.c @ 6410:37f30005ed2d
[gaim-migrate @ 6916]
0.67 update
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Fri, 08 Aug 2003 01:14:42 +0000 |
parents | 74ca311ceb2a |
children | ff4551719cc7 |
rev | line source |
---|---|
5563 | 1 /** |
2 * @file connection.c Connection API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
5631 | 8 * |
5563 | 9 * This program is free software; you can redistribute it and/or modify |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
23 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
24 #include "blist.h" |
5563 | 25 #include "connection.h" |
5717 | 26 #include "debug.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
27 #include "log.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
28 #include "notify.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
29 #include "prefs.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
30 #include "request.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
31 #include "server.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
32 #include "sound.h" |
6106 | 33 #include "util.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
34 |
5563 | 35 static GList *connections = NULL; |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
36 static GList *connections_connecting = NULL; |
5563 | 37 static GaimConnectionUiOps *connection_ui_ops = NULL; |
38 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
39 |
5563 | 40 GaimConnection * |
41 gaim_connection_new(GaimAccount *account) | |
42 { | |
43 GaimConnection *gc; | |
44 | |
45 g_return_val_if_fail(account != NULL, NULL); | |
46 | |
47 gc = g_new0(GaimConnection, 1); | |
48 | |
49 gc->prpl = gaim_find_prpl(gaim_account_get_protocol(account)); | |
50 | |
51 gaim_connection_set_account(gc, account); | |
52 gaim_account_set_connection(account, gc); | |
53 | |
54 return gc; | |
55 } | |
56 | |
57 void | |
58 gaim_connection_destroy(GaimConnection *gc) | |
59 { | |
5741
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
60 GaimAccount *account; |
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
61 |
5563 | 62 g_return_if_fail(gc != NULL); |
63 | |
64 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) { | |
65 gaim_connection_disconnect(gc); | |
66 | |
67 return; | |
68 } | |
69 | |
5930
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
70 gaim_debug(GAIM_DEBUG_INFO, "connection", |
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
71 "Destroying connection %p\n", gc); |
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
72 |
5741
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
73 account = gaim_connection_get_account(gc); |
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
74 gaim_account_set_connection(account, NULL); |
1b5e6e6e80e9
[gaim-migrate @ 6165]
Christian Hammond <chipx86@chipx86.com>
parents:
5740
diff
changeset
|
75 |
5563 | 76 if (gc->display_name != NULL) |
77 g_free(gc->display_name); | |
78 | |
79 if (gc->away != NULL) | |
80 g_free(gc->away); | |
81 | |
82 if (gc->away_state != NULL) | |
83 g_free(gc->away_state); | |
84 | |
6393 | 85 if (gc->disconnect_timeout) |
86 g_source_remove(gc->disconnect_timeout); | |
87 | |
5563 | 88 g_free(gc); |
89 } | |
90 | |
6110 | 91 static void request_pass_ok_cb(GaimAccount *account, const char *entry) |
6109 | 92 { |
93 gaim_account_set_password(account, (*entry != '\0') ? entry : NULL); | |
94 | |
6110 | 95 gaim_account_connect(account); |
6109 | 96 } |
97 | |
98 | |
5563 | 99 void |
100 gaim_connection_connect(GaimConnection *gc) | |
101 { | |
102 GaimAccount *account; | |
103 GaimConnectionUiOps *ops; | |
104 GaimPluginProtocolInfo *prpl_info = NULL; | |
105 | |
106 g_return_if_fail(gc != NULL); | |
107 | |
5930
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
108 gaim_debug(GAIM_DEBUG_INFO, "connection", |
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
109 "Connecting. gc = %p\n", gc); |
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
110 |
5563 | 111 ops = gaim_get_connection_ui_ops(); |
112 | |
6136
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
113 if (gc->prpl != NULL) |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
114 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
115 else { |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
116 gchar *message = g_strdup_printf(_("Missing protocol plugin for %s"), |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
117 gaim_account_get_username(gaim_connection_get_account(gc))); |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
118 |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
119 gaim_debug(GAIM_DEBUG_ERROR, "connection", |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
120 "Could not get prpl info for %p\n", gc); |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
121 gaim_notify_error(NULL, _("Connection Error"), |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
122 message, NULL); |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
123 g_free(message); |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
124 return; |
e391813214a6
[gaim-migrate @ 6610]
Christian Hammond <chipx86@chipx86.com>
parents:
6113
diff
changeset
|
125 } |
5563 | 126 |
127 account = gaim_connection_get_account(gc); | |
128 | |
6109 | 129 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) |
130 return; | |
131 | |
6036 | 132 if (!(prpl_info->options & OPT_PROTO_NO_PASSWORD) && |
6231 | 133 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL) && |
134 gaim_account_get_password(account) == NULL) { | |
6111 | 135 gchar *primary; |
6231 | 136 gchar *escaped; |
137 const gchar *username = gaim_account_get_username(account); | |
138 | |
5930
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
139 gaim_debug(GAIM_DEBUG_INFO, "connection", "Requesting password\n"); |
6231 | 140 escaped = g_markup_escape_text(username, strlen(username)); |
141 primary = g_strdup_printf(_("Enter password for %s"), escaped); | |
6111 | 142 gaim_request_input(gc, NULL, primary, NULL, NULL, FALSE, TRUE, |
6109 | 143 _("OK"), G_CALLBACK(request_pass_ok_cb), |
6110 | 144 _("Cancel"), NULL, account); |
6111 | 145 g_free(primary); |
6231 | 146 g_free(escaped); |
6110 | 147 gaim_connection_destroy(gc); |
5563 | 148 |
149 return; | |
150 } | |
151 | |
152 gaim_connection_set_state(gc, GAIM_CONNECTING); | |
153 | |
5581
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5571
diff
changeset
|
154 gaim_debug(GAIM_DEBUG_INFO, "connection", "Calling serv_login\n"); |
3a9b54f260e3
[gaim-migrate @ 5985]
Christian Hammond <chipx86@chipx86.com>
parents:
5571
diff
changeset
|
155 |
6297
ae8b0a12e6f3
[gaim-migrate @ 6796]
Christian Hammond <chipx86@chipx86.com>
parents:
6296
diff
changeset
|
156 connections = g_list_append(connections, gc); |
ae8b0a12e6f3
[gaim-migrate @ 6796]
Christian Hammond <chipx86@chipx86.com>
parents:
6296
diff
changeset
|
157 |
5563 | 158 serv_login(account); |
159 } | |
160 | |
161 void | |
162 gaim_connection_disconnect(GaimConnection *gc) | |
163 { | |
5926
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
164 GaimAccount *account; |
5563 | 165 GList *wins; |
166 | |
167 g_return_if_fail(gc != NULL); | |
168 | |
5926
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
169 account = gaim_connection_get_account(gc); |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
170 |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
171 if (gaim_account_get_connection(account) != NULL) { |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
172 gaim_account_disconnect(account); |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
173 return; |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
174 } |
6c22d37c6a3c
[gaim-migrate @ 6366]
Christian Hammond <chipx86@chipx86.com>
parents:
5905
diff
changeset
|
175 |
5930
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
176 gaim_debug(GAIM_DEBUG_INFO, "connection", |
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
177 "Disconnecting connection %p\n", gc); |
03f1d6cd784c
[gaim-migrate @ 6370]
Christian Hammond <chipx86@chipx86.com>
parents:
5926
diff
changeset
|
178 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
179 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) { |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
180 if (gaim_connection_get_state(gc) != GAIM_CONNECTING) |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
181 gaim_blist_remove_account(gaim_connection_get_account(gc)); |
5563 | 182 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
183 serv_close(gc); |
5563 | 184 |
6018 | 185 connections = g_list_remove(connections, gc); |
186 | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5788
diff
changeset
|
187 gaim_connection_set_state(gc, GAIM_DISCONNECTED); |
5563 | 188 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
189 gaim_event_broadcast(event_signoff, gc); |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
190 system_log(log_signoff, gc, NULL, |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
191 OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); |
5615
6500a6c8d679
[gaim-migrate @ 6022]
Christian Hammond <chipx86@chipx86.com>
parents:
5581
diff
changeset
|
192 |
5740
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
193 /* |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
194 * 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
|
195 * notification system. |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
196 */ |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
197 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
198 GaimWindow *win = (GaimWindow *)wins->data; |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
199 gaim_conversation_update(gaim_window_get_conversation_at(win, 0), |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
200 GAIM_CONV_ACCOUNT_OFFLINE); |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
201 } |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
202 |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
203 gaim_request_close_with_handle(gc); |
6ec7b32ab1df
[gaim-migrate @ 6164]
Christian Hammond <chipx86@chipx86.com>
parents:
5727
diff
changeset
|
204 gaim_notify_close_with_handle(gc); |
5563 | 205 } |
206 | |
5622
70ae81fc802f
[gaim-migrate @ 6029]
Christian Hammond <chipx86@chipx86.com>
parents:
5615
diff
changeset
|
207 gaim_connection_destroy(gc); |
5563 | 208 } |
209 | |
6029 | 210 gboolean |
211 gaim_connection_disconnect_cb(gpointer data) | |
212 { | |
6076 | 213 GaimAccount *account = data; |
214 GaimConnection *gc = gaim_account_get_connection(account); | |
6029 | 215 |
6076 | 216 if(gc) |
217 gaim_connection_disconnect(gc); | |
6029 | 218 |
219 return FALSE; | |
220 } | |
221 | |
5563 | 222 /* |
223 * d:)->-< | |
224 * | |
225 * d:O-\-< | |
226 * | |
227 * d:D-/-< | |
228 * | |
229 * d8D->-< DANCE! | |
230 */ | |
231 | |
232 void | |
233 gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state) | |
234 { | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
235 GaimConnectionUiOps *ops; |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
236 |
5563 | 237 g_return_if_fail(gc != NULL); |
238 | |
5784
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
239 if (gc->state == state) |
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
240 return; |
72fb22b9ac98
[gaim-migrate @ 6209]
Christian Hammond <chipx86@chipx86.com>
parents:
5741
diff
changeset
|
241 |
5563 | 242 gc->state = state; |
243 | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
244 ops = gaim_get_connection_ui_ops(); |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
245 |
5905
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
246 if (gc->state == GAIM_CONNECTING) { |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
247 connections_connecting = g_list_append(connections_connecting, gc); |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
248 } |
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
249 else { |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
250 connections_connecting = g_list_remove(connections_connecting, gc); |
5905
dbe2a2174be9
[gaim-migrate @ 6337]
Christian Hammond <chipx86@chipx86.com>
parents:
5885
diff
changeset
|
251 } |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
252 |
5563 | 253 if (gc->state == GAIM_CONNECTED) { |
254 GaimBlistNode *gnode,*bnode; | |
255 GList *wins; | |
256 GList *add_buds=NULL; | |
257 | |
258 /* Set the time the account came online */ | |
259 time(&gc->login_time); | |
260 | |
261 if (ops != NULL && ops->connected != NULL) | |
262 ops->connected(gc); | |
263 | |
264 gaim_blist_show(); | |
265 gaim_blist_add_account(gc->account); | |
266 | |
267 /* | |
268 * XXX This is a hack! Remove this and replace it with a better event | |
269 * notification system. | |
270 */ | |
271 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5631
diff
changeset
|
272 GaimWindow *win = (GaimWindow *)wins->data; |
5563 | 273 gaim_conversation_update(gaim_window_get_conversation_at(win, 0), |
274 GAIM_CONV_ACCOUNT_ONLINE); | |
275 } | |
276 | |
277 gaim_event_broadcast(event_signon, gc); | |
278 system_log(log_signon, gc, NULL, | |
279 OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); | |
280 | |
281 #if 0 | |
282 /* away option given? */ | |
283 if (opt_away) { | |
284 away_on_login(opt_away_arg); | |
285 /* don't do it again */ | |
286 opt_away = 0; | |
287 } else if (awaymessage) { | |
288 serv_set_away(gc, GAIM_AWAY_CUSTOM, awaymessage->message); | |
289 } | |
290 if (opt_away_arg != NULL) { | |
291 g_free(opt_away_arg); | |
292 opt_away_arg = NULL; | |
293 } | |
294 #endif | |
295 | |
296 /* let the prpl know what buddies we pulled out of the local list */ | |
297 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
298 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
299 continue; | |
300 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
301 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
302 struct buddy *b = (struct buddy *)bnode; | |
303 if(b->account == gc->account) { | |
304 add_buds = g_list_append(add_buds, b->name); | |
305 } | |
306 } | |
307 } | |
308 } | |
309 | |
310 if(add_buds) { | |
311 serv_add_buddies(gc, add_buds); | |
312 g_list_free(add_buds); | |
313 } | |
314 | |
315 serv_set_permit_deny(gc); | |
316 } | |
5885
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
317 else if (gc->state == GAIM_DISCONNECTED) { |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
318 if (ops != NULL && ops->disconnected != NULL) |
02569519d0cc
[gaim-migrate @ 6317]
Christian Hammond <chipx86@chipx86.com>
parents:
5883
diff
changeset
|
319 ops->disconnected(gc, NULL); |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
320 } |
5563 | 321 } |
322 | |
323 void | |
324 gaim_connection_set_account(GaimConnection *gc, GaimAccount *account) | |
325 { | |
326 g_return_if_fail(gc != NULL); | |
327 g_return_if_fail(account != NULL); | |
328 | |
329 gc->account = account; | |
330 } | |
331 | |
332 void | |
333 gaim_connection_set_display_name(GaimConnection *gc, const char *name) | |
334 { | |
335 g_return_if_fail(gc != NULL); | |
336 | |
337 if (gc->display_name != NULL) | |
338 g_free(gc->display_name); | |
339 | |
340 gc->display_name = (name == NULL ? NULL : g_strdup(name)); | |
341 } | |
342 | |
343 GaimConnectionState | |
344 gaim_connection_get_state(const GaimConnection *gc) | |
345 { | |
346 g_return_val_if_fail(gc != NULL, GAIM_DISCONNECTED); | |
347 | |
348 return gc->state; | |
349 } | |
350 | |
351 GaimAccount * | |
352 gaim_connection_get_account(const GaimConnection *gc) | |
353 { | |
354 g_return_val_if_fail(gc != NULL, NULL); | |
355 | |
356 return gc->account; | |
357 } | |
358 | |
359 const char * | |
360 gaim_connection_get_display_name(const GaimConnection *gc) | |
361 { | |
362 g_return_val_if_fail(gc != NULL, NULL); | |
363 | |
364 return gc->display_name; | |
365 } | |
366 | |
367 void | |
368 gaim_connection_update_progress(GaimConnection *gc, const char *text, | |
369 size_t step, size_t count) | |
370 { | |
371 GaimConnectionUiOps *ops; | |
372 | |
373 g_return_if_fail(gc != NULL); | |
374 g_return_if_fail(text != NULL); | |
375 g_return_if_fail(step < count); | |
376 g_return_if_fail(count > 1); | |
377 | |
378 ops = gaim_get_connection_ui_ops(); | |
379 | |
380 if (ops != NULL && ops->connect_progress != NULL) | |
381 ops->connect_progress(gc, text, step, count); | |
382 } | |
383 | |
384 void | |
5571
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
385 gaim_connection_notice(GaimConnection *gc, const char *text) |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
386 { |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
387 GaimConnectionUiOps *ops; |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
388 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
389 g_return_if_fail(gc != NULL); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
390 g_return_if_fail(text != NULL); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
391 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
392 ops = gaim_get_connection_ui_ops(); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
393 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
394 if (ops != NULL && ops->notice != NULL) |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
395 ops->notice(gc, text); |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
396 } |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
397 |
113090160626
[gaim-migrate @ 5973]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
398 void |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
399 gaim_connection_error(GaimConnection *gc, const char *text) |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
400 { |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
401 GaimConnectionUiOps *ops; |
6106 | 402 gchar *primary, *secondary; |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
403 |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
404 g_return_if_fail(gc != NULL); |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
405 g_return_if_fail(text != NULL); |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
406 |
6393 | 407 /* If we've already got one error, we don't need any more */ |
408 if(gc->disconnect_timeout) | |
409 return; | |
410 | |
6106 | 411 primary = g_strdup_printf(_("%s has been disconnected"), |
412 gaim_account_get_username(gaim_connection_get_account(gc))); | |
413 secondary = g_strdup_printf("%s\n%s", full_date(), | |
414 text ? text : _("Reason Unknown.")); | |
415 gaim_notify_error(NULL, _("Connection Error"), primary, secondary); | |
416 g_free(primary); | |
417 g_free(secondary); | |
418 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
419 ops = gaim_get_connection_ui_ops(); |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
420 |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
421 if (ops != NULL && ops->disconnected != NULL) |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
422 ops->disconnected(gc, text); |
5727 | 423 |
6393 | 424 gc->disconnect_timeout = g_timeout_add(0, gaim_connection_disconnect_cb, |
6076 | 425 gaim_connection_get_account(gc)); |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
426 } |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
427 |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
428 void |
5563 | 429 gaim_connections_disconnect_all(void) |
430 { | |
431 GList *l; | |
6113 | 432 GaimConnection *gc; |
5563 | 433 |
6113 | 434 while ((l = gaim_connections_get_all()) != NULL) { |
435 gc = l->data; | |
436 gc->wants_to_die = TRUE; | |
437 gaim_connection_destroy(gc); | |
438 } | |
5563 | 439 } |
440 | |
441 GList * | |
442 gaim_connections_get_all(void) | |
443 { | |
444 return connections; | |
445 } | |
446 | |
5788
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
447 GList * |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
448 gaim_connections_get_connecting(void) |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
449 { |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
450 return connections_connecting; |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
451 } |
8c237274189f
[gaim-migrate @ 6213]
Christian Hammond <chipx86@chipx86.com>
parents:
5784
diff
changeset
|
452 |
5563 | 453 void |
454 gaim_set_connection_ui_ops(GaimConnectionUiOps *ops) | |
455 { | |
456 connection_ui_ops = ops; | |
457 } | |
458 | |
459 GaimConnectionUiOps * | |
460 gaim_get_connection_ui_ops(void) | |
461 { | |
462 return connection_ui_ops; | |
463 } | |
464 |