Mercurial > pidgin
comparison src/connection.c @ 5563:9eb5b13fd412
[gaim-migrate @ 5965]
Just a taste of what's coming.
Standard "This won't compile" thing. Plugin authors, you're going to hate
me, but that's okay, because I have friends too!
It's really late. My brain resembles that of fish swimming in jello pudding
with neon lights flying around chanting musicals. I'm not on drugs. I'm
just that tired.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Fri, 30 May 2003 09:38:29 +0000 |
parents | |
children | 187c740f2a4e |
comparison
equal
deleted
inserted
replaced
5562:3c8d34574601 | 5563:9eb5b13fd412 |
---|---|
1 /** | |
2 * @file connection.c Connection API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
8 * | |
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 */ | |
23 #include "connection.h" | |
24 | |
25 static GList *connections = NULL; | |
26 static GaimConnectionUiOps *connection_ui_ops = NULL; | |
27 | |
28 GaimConnection * | |
29 gaim_connection_new(GaimAccount *account) | |
30 { | |
31 GaimConnection *gc; | |
32 | |
33 g_return_val_if_fail(account != NULL, NULL); | |
34 | |
35 gc = g_new0(GaimConnection, 1); | |
36 | |
37 gc->prpl = gaim_find_prpl(gaim_account_get_protocol(account)); | |
38 | |
39 gaim_connection_set_account(gc, account); | |
40 gaim_account_set_connection(account, gc); | |
41 | |
42 connections = g_list_append(connections, gc); | |
43 | |
44 return gc; | |
45 } | |
46 | |
47 void | |
48 gaim_connection_destroy(GaimConnection *gc) | |
49 { | |
50 g_return_if_fail(gc != NULL); | |
51 | |
52 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) { | |
53 gaim_connection_disconnect(gc); | |
54 | |
55 return; | |
56 } | |
57 | |
58 if (gc->display_name != NULL) | |
59 g_free(gc->display_name); | |
60 | |
61 if (gc->away != NULL) | |
62 g_free(gc->away); | |
63 | |
64 if (gc->away_state != NULL) | |
65 g_free(gc->away_state); | |
66 | |
67 connections = g_list_remove(connections, gc); | |
68 | |
69 g_free(gc); | |
70 } | |
71 | |
72 void | |
73 gaim_connection_connect(GaimConnection *gc) | |
74 { | |
75 GaimAccount *account; | |
76 GaimConnectionUiOps *ops; | |
77 GaimPluginProtocolInfo *prpl_info = NULL; | |
78 | |
79 g_return_if_fail(gc != NULL); | |
80 | |
81 ops = gaim_get_connection_ui_ops(); | |
82 | |
83 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
84 | |
85 account = gaim_connection_get_account(gc); | |
86 | |
87 if ((prpl_info->options & OPT_PROTO_NO_PASSWORD) && | |
88 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL) && | |
89 gaim_account_get_password(account) == NULL) { | |
90 | |
91 if (ops != NULL && ops->request_pass != NULL) | |
92 ops->request_pass(gc); | |
93 | |
94 return; | |
95 } | |
96 | |
97 gaim_connection_set_state(gc, GAIM_CONNECTING); | |
98 | |
99 serv_login(account); | |
100 } | |
101 | |
102 void | |
103 gaim_connection_disconnect(GaimConnection *gc) | |
104 { | |
105 GList *wins; | |
106 | |
107 g_return_if_fail(gc != NULL); | |
108 g_return_if_fail(gaim_connection_get_state(gc) != GAIM_DISCONNECTED); | |
109 | |
110 if (gaim_connection_get_state(gc) != GAIM_CONNECTING) | |
111 gaim_blist_remove_account(gaim_connection_get_account(gc)); | |
112 | |
113 gaim_event_broadcast(event_signoff, gc); | |
114 system_log(log_signoff, gc, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); | |
115 | |
116 serv_close(gc); | |
117 | |
118 gaim_connection_set_state(gc, GAIM_DISCONNECTED); | |
119 | |
120 /* XXX Evil UI stuff!! */ | |
121 do_away_menu(); | |
122 do_proto_menu(); | |
123 | |
124 /* | |
125 * XXX This is a hack! Remove this and replace it with a better event | |
126 * notification system. | |
127 */ | |
128 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { | |
129 struct gaim_window *win = (struct gaim_window *)wins->data; | |
130 gaim_conversation_update(gaim_window_get_conversation_at(win, 0), | |
131 GAIM_CONV_ACCOUNT_OFFLINE); | |
132 } | |
133 | |
134 gaim_request_close_with_handle(gc); | |
135 gaim_notify_close_with_handle(gc); | |
136 | |
137 update_privacy_connections(); | |
138 | |
139 /* XXX More UI stuff! */ | |
140 if (connections != NULL) | |
141 return; | |
142 | |
143 destroy_all_dialogs(); | |
144 gaim_blist_destroy(); | |
145 | |
146 show_login(); | |
147 } | |
148 | |
149 /* | |
150 * d:)->-< | |
151 * | |
152 * d:O-\-< | |
153 * | |
154 * d:D-/-< | |
155 * | |
156 * d8D->-< DANCE! | |
157 */ | |
158 | |
159 void | |
160 gaim_connection_set_state(GaimConnection *gc, GaimConnectionState state) | |
161 { | |
162 g_return_if_fail(gc != NULL); | |
163 | |
164 gc->state = state; | |
165 | |
166 if (gc->state == GAIM_CONNECTED) { | |
167 GaimConnectionUiOps *ops = gaim_get_connection_ui_ops(); | |
168 GaimBlistNode *gnode,*bnode; | |
169 GList *wins; | |
170 GList *add_buds=NULL; | |
171 | |
172 /* Set the time the account came online */ | |
173 time(&gc->login_time); | |
174 | |
175 if (ops != NULL && ops->connected != NULL) | |
176 ops->connected(gc); | |
177 | |
178 gaim_blist_show(); | |
179 gaim_blist_add_account(gc->account); | |
180 | |
181 /* I hate this. -- ChipX86 */ | |
182 gaim_setup(gc); | |
183 | |
184 /* | |
185 * XXX This is a hack! Remove this and replace it with a better event | |
186 * notification system. | |
187 */ | |
188 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { | |
189 struct gaim_window *win = (struct gaim_window *)wins->data; | |
190 gaim_conversation_update(gaim_window_get_conversation_at(win, 0), | |
191 GAIM_CONV_ACCOUNT_ONLINE); | |
192 } | |
193 | |
194 gaim_event_broadcast(event_signon, gc); | |
195 system_log(log_signon, gc, NULL, | |
196 OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); | |
197 | |
198 #if 0 | |
199 /* away option given? */ | |
200 if (opt_away) { | |
201 away_on_login(opt_away_arg); | |
202 /* don't do it again */ | |
203 opt_away = 0; | |
204 } else if (awaymessage) { | |
205 serv_set_away(gc, GAIM_AWAY_CUSTOM, awaymessage->message); | |
206 } | |
207 if (opt_away_arg != NULL) { | |
208 g_free(opt_away_arg); | |
209 opt_away_arg = NULL; | |
210 } | |
211 #endif | |
212 | |
213 /* let the prpl know what buddies we pulled out of the local list */ | |
214 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
215 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
216 continue; | |
217 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
218 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
219 struct buddy *b = (struct buddy *)bnode; | |
220 if(b->account == gc->account) { | |
221 add_buds = g_list_append(add_buds, b->name); | |
222 } | |
223 } | |
224 } | |
225 } | |
226 | |
227 if(add_buds) { | |
228 serv_add_buddies(gc, add_buds); | |
229 g_list_free(add_buds); | |
230 } | |
231 | |
232 serv_set_permit_deny(gc); | |
233 } | |
234 } | |
235 | |
236 void | |
237 gaim_connection_set_account(GaimConnection *gc, GaimAccount *account) | |
238 { | |
239 g_return_if_fail(gc != NULL); | |
240 g_return_if_fail(account != NULL); | |
241 | |
242 gc->account = account; | |
243 } | |
244 | |
245 void | |
246 gaim_connection_set_display_name(GaimConnection *gc, const char *name) | |
247 { | |
248 g_return_if_fail(gc != NULL); | |
249 | |
250 if (gc->display_name != NULL) | |
251 g_free(gc->display_name); | |
252 | |
253 gc->display_name = (name == NULL ? NULL : g_strdup(name)); | |
254 } | |
255 | |
256 GaimConnectionState | |
257 gaim_connection_get_state(const GaimConnection *gc) | |
258 { | |
259 g_return_val_if_fail(gc != NULL, GAIM_DISCONNECTED); | |
260 | |
261 return gc->state; | |
262 } | |
263 | |
264 GaimAccount * | |
265 gaim_connection_get_account(const GaimConnection *gc) | |
266 { | |
267 g_return_val_if_fail(gc != NULL, NULL); | |
268 | |
269 return gc->account; | |
270 } | |
271 | |
272 const char * | |
273 gaim_connection_get_display_name(const GaimConnection *gc) | |
274 { | |
275 g_return_val_if_fail(gc != NULL, NULL); | |
276 | |
277 return gc->display_name; | |
278 } | |
279 | |
280 void | |
281 gaim_connection_update_progress(GaimConnection *gc, const char *text, | |
282 size_t step, size_t count) | |
283 { | |
284 GaimConnectionUiOps *ops; | |
285 | |
286 g_return_if_fail(gc != NULL); | |
287 g_return_if_fail(text != NULL); | |
288 g_return_if_fail(step < count); | |
289 g_return_if_fail(count > 1); | |
290 | |
291 ops = gaim_get_connection_ui_ops(); | |
292 | |
293 if (ops != NULL && ops->connect_progress != NULL) | |
294 ops->connect_progress(gc, text, step, count); | |
295 } | |
296 | |
297 void | |
298 gaim_connections_disconnect_all(void) | |
299 { | |
300 GList *l; | |
301 | |
302 for (l = gaim_connections_get_all(); l != NULL; l = l->next) | |
303 gaim_connection_destroy(l->data); | |
304 } | |
305 | |
306 GList * | |
307 gaim_connections_get_all(void) | |
308 { | |
309 return connections; | |
310 } | |
311 | |
312 void | |
313 gaim_set_connection_ui_ops(GaimConnectionUiOps *ops) | |
314 { | |
315 connection_ui_ops = ops; | |
316 } | |
317 | |
318 GaimConnectionUiOps * | |
319 gaim_get_connection_ui_ops(void) | |
320 { | |
321 return connection_ui_ops; | |
322 } | |
323 |