Mercurial > pidgin.yaz
annotate src/protocols/icq/gaim_icq.c @ 2090:b66aca8e8dce
[gaim-migrate @ 2100]
change ../config.h to <config.h> because that's better. change from GdkInput functions to GaimInput for reasons mentioned elsewhere.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 31 Jul 2001 23:23:40 +0000 |
parents | 424a40f12a6c |
children | 56c4382f2909 |
rev | line source |
---|---|
2086 | 1 #include <gtk/gtk.h> |
2 #include <string.h> | |
3 #include <stdlib.h> | |
4 #include "icq.h" /* well, we're doing ICQ, right? */ | |
5 #include "multi.h" /* needed for gaim_connection */ | |
6 #include "prpl.h" /* needed for prpl */ | |
7 #include "gaim.h" /* needed for every other damn thing */ | |
8 #include "proxy.h" | |
9 | |
10 #include "pixmaps/gnomeicu-online.xpm" | |
11 #include "pixmaps/gnomeicu-away.xpm" | |
12 #include "pixmaps/gnomeicu-dnd.xpm" | |
13 #include "pixmaps/gnomeicu-na.xpm" | |
14 #include "pixmaps/gnomeicu-occ.xpm" | |
15 #include "pixmaps/gnomeicu-ffc.xpm" | |
16 | |
17 #define USEROPT_NICK 0 | |
18 | |
19 struct icq_data { | |
20 icq_Link *link; | |
21 int cur_status; | |
22 GSList *thru_serv; | |
23 }; | |
24 | |
25 static guint ack_timer = 0; | |
26 | |
27 static struct gaim_connection *find_gaim_conn_by_icq_link(icq_Link *link) { | |
28 GSList *c = connections; | |
29 struct gaim_connection *gc = NULL; | |
30 struct icq_data *id; | |
31 | |
32 while (c) { | |
33 gc = (struct gaim_connection *)c->data; | |
34 if (gc->protocol == PROTO_ICQ) { | |
35 id = (struct icq_data *)gc->proto_data; | |
36 if (id->link == link) | |
37 break; | |
38 } | |
39 gc = NULL; | |
40 c = c->next; | |
41 } | |
42 | |
43 return gc; | |
44 } | |
45 | |
46 static char *icq_name() { | |
47 return "ICQ"; | |
48 } | |
49 | |
50 static void icq_do_log(icq_Link *link, time_t time, unsigned char level, const char *log) { | |
51 debug_printf("ICQ debug %d: %s", level, log); | |
52 } | |
53 | |
54 GList *sockets = NULL; | |
55 struct gaim_sock { | |
56 int socket; | |
57 int type; | |
58 gint inpa; | |
59 }; | |
60 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
61 static void gaim_icq_handler(gpointer data, gint source, GaimInputCondition cond) { |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
62 if (cond & GAIM_INPUT_READ) |
2086 | 63 icq_HandleReadySocket(source, ICQ_SOCKET_READ); |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
64 if (cond & GAIM_INPUT_WRITE) |
2086 | 65 icq_HandleReadySocket(source, ICQ_SOCKET_WRITE); |
66 } | |
67 | |
68 static void icq_sock_notify(int socket, int type, int status) { | |
69 struct gaim_sock *gs = NULL; | |
70 if (status) { | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
71 GaimInputCondition cond; |
2086 | 72 if (type == ICQ_SOCKET_READ) |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
73 cond = GAIM_INPUT_READ; |
2086 | 74 else |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
75 cond = GAIM_INPUT_WRITE; |
2086 | 76 gs = g_new0(struct gaim_sock, 1); |
77 gs->socket = socket; | |
78 gs->type = type; | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
79 gs->inpa = gaim_input_add(socket, cond, gaim_icq_handler, NULL); |
2086 | 80 sockets = g_list_append(sockets, gs); |
81 debug_printf("Adding socket notifier: %d %d (%d)\n", socket, type, gs->inpa); | |
82 } else { | |
83 GList *m = sockets; | |
84 while (m) { | |
85 gs = m->data; | |
86 if ((gs->socket == socket) && (gs->type == type)) | |
87 break; | |
88 m = g_list_next(m); | |
89 } | |
90 if (m) { | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
91 gaim_input_remove(gs->inpa); |
2086 | 92 sockets = g_list_remove(sockets, gs); |
93 debug_printf("Removing socket notifier: %d %d (%d)\n", socket, type, gs->inpa); | |
94 g_free(gs); | |
95 } | |
96 } | |
97 } | |
98 | |
99 static void icq_online(icq_Link *link) { | |
100 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
101 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
102 debug_printf("%s is now online.\n", gc->username); | |
103 account_online(gc); | |
104 /*gc->options |= OPT_USR_KEEPALV; this is always-on now */ | |
105 serv_finish_login(gc); | |
106 | |
107 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
108 } | |
109 | |
110 static void icq_logged_off(icq_Link *link) { | |
111 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
112 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
113 | |
114 if (icq_Connect(link, "icq.mirabilis.com", 4000) < 1) { | |
115 hide_login_progress(gc, "Unable to connect"); | |
116 signoff(gc); | |
117 return; | |
118 } | |
119 | |
120 icq_Login(link, STATUS_ONLINE); | |
121 id->cur_status = STATUS_ONLINE; | |
122 } | |
123 | |
124 void strip_linefeed(gchar *text) | |
125 { | |
126 int i, j; | |
127 gchar *text2 = g_malloc(strlen(text) + 1); | |
128 | |
129 for (i = 0, j = 0; text[i]; i++) | |
130 if (text[i] != '\r') | |
131 text2[j++] = text[i]; | |
132 text2[j] = '\0'; | |
133 | |
134 strcpy(text, text2); | |
135 g_free(text2); | |
136 } | |
137 | |
138 static void icq_msg_incoming(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
139 unsigned char day, unsigned char month, unsigned short year, const char *data) { | |
140 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
141 char buf[256], *tmp = g_malloc(BUF_LONG); | |
142 g_snprintf(tmp, BUF_LONG, "%s", data); | |
143 g_snprintf(buf, sizeof buf, "%lu", uin); | |
144 strip_linefeed(tmp); | |
145 serv_got_im(gc, buf, tmp, 0, time((time_t)NULL)); | |
146 g_free(tmp); | |
147 } | |
148 | |
149 static void icq_user_online(icq_Link *link, unsigned long uin, unsigned long st, | |
150 unsigned long ip, unsigned short port, unsigned long real_ip, | |
151 unsigned char tcp_flags) { | |
152 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
153 guint status; | |
154 char buf[256]; | |
155 | |
156 g_snprintf(buf, sizeof buf, "%lu", uin); | |
157 status = (st == STATUS_ONLINE) ? UC_NORMAL : UC_UNAVAILABLE | (st << 5); | |
158 serv_got_update(gc, buf, 1, 0, 0, 0, status, 0); | |
159 } | |
160 | |
161 static void icq_user_offline(icq_Link *link, unsigned long uin) { | |
162 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
163 char buf[256]; g_snprintf(buf, sizeof buf, "%lu", uin); | |
164 serv_got_update(gc, buf, 0, 0, 0, 0, 0, 0); | |
165 } | |
166 | |
167 static void icq_user_status(icq_Link *link, unsigned long uin, unsigned long st) { | |
168 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
169 guint status; | |
170 char buf[256]; | |
171 | |
172 g_snprintf(buf, sizeof buf, "%lu", uin); | |
173 status = (st == STATUS_ONLINE) ? UC_NORMAL : UC_UNAVAILABLE | (st << 5); | |
174 serv_got_update(gc, buf, 1, 0, 0, 0, status, 0); | |
175 } | |
176 | |
177 static gint icq_set_timeout_cb() { | |
178 icq_HandleTimeout(); | |
179 ack_timer = 0; | |
180 return FALSE; | |
181 } | |
182 | |
183 static void icq_set_timeout(long interval) { | |
184 debug_printf("icq_SetTimeout: %ld\n", interval); | |
185 if (interval > 0 && ack_timer == 0) | |
186 ack_timer = gtk_timeout_add(interval * 1000, (GtkFunction)icq_set_timeout_cb, NULL); | |
187 else if (ack_timer > 0) { | |
188 gtk_timeout_remove(ack_timer); | |
189 ack_timer = 0; | |
190 } | |
191 } | |
192 | |
193 static void icq_url_incoming(icq_Link *link, unsigned long uin, unsigned char hour, | |
194 unsigned char minute, unsigned char day, unsigned char month, | |
195 unsigned short year, const char *url, const char *descr) { | |
196 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
197 char *msg = g_malloc(BUF_LONG), buf[256]; | |
198 g_snprintf(msg, BUF_LONG, "<A HREF=\"%s\">%s</A>", url, descr); | |
199 g_snprintf(buf, 256, "%lu", uin); | |
200 serv_got_im(gc, buf, msg, 0, time((time_t)NULL)); | |
201 g_free(msg); | |
202 } | |
203 | |
204 static void icq_wrong_passwd(icq_Link *link) { | |
205 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
206 hide_login_progress(gc, "Invalid password."); | |
207 signoff(gc); | |
208 } | |
209 | |
210 static void icq_invalid_uin(icq_Link *link) { | |
211 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
212 hide_login_progress(gc, "Invalid UIN."); | |
213 signoff(gc); | |
214 } | |
215 | |
216 static void icq_info_reply(icq_Link *link, unsigned long uin, const char *nick, | |
217 const char *first, const char *last, const char *email, char auth) { | |
218 char buf[16 * 1024]; | |
219 | |
220 g_snprintf(buf, sizeof buf, | |
221 "<B>UIN:</B> %lu<BR>" | |
222 "<B>Nick:</B> %s<BR>" | |
223 "<B>Name:</B> %s %s<BR>" | |
224 "<B>Email:</B> %s\n", | |
225 uin, | |
226 nick, | |
227 first, last, | |
228 email); | |
229 g_show_info_text(buf); | |
230 } | |
231 | |
232 static void icq_web_pager(icq_Link *link, unsigned char hour, unsigned char minute, | |
233 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
234 const char *email, const char *msg) { | |
235 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
236 char *who = g_strdup_printf("ICQ Web Pager: %s (%s)", nick, email); | |
237 char *what = g_malloc(BUF_LONG); | |
238 g_snprintf(what, BUF_LONG, "%s", msg); | |
239 serv_got_im(gc, who, what, 0, time((time_t)NULL)); | |
240 g_free(who); | |
241 g_free(what); | |
242 } | |
243 | |
244 static void icq_mail_express(icq_Link *link, unsigned char hour, unsigned char minute, | |
245 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
246 const char *email, const char *msg) { | |
247 struct gaim_connection *gc = find_gaim_conn_by_icq_link(link); | |
248 char *who = g_strdup_printf("ICQ Mail Express: %s (%s)", nick, email); | |
249 char *what = g_malloc(BUF_LONG); | |
250 g_snprintf(what, BUF_LONG, "%s", msg); | |
251 serv_got_im(gc, who, what, 0, time((time_t)NULL)); | |
252 g_free(who); | |
253 g_free(what); | |
254 } | |
255 | |
256 static void icq_req_not(icq_Link *link, unsigned long id, int type, int arg, void *data) { | |
257 if (type == ICQ_NOTIFY_FAILED) | |
258 do_error_dialog("Failure in sending packet", "ICQ error"); | |
259 return; | |
260 } | |
261 | |
262 struct icq_auth { | |
263 icq_Link *link; | |
264 unsigned long uin; | |
265 }; | |
266 | |
267 static void icq_den_auth(gpointer x, struct icq_auth *iq) | |
268 { | |
269 g_free(iq); | |
270 } | |
271 | |
272 static void icq_acc_auth(gpointer x, struct icq_auth *iq) | |
273 { | |
274 icq_SendAuthMsg(iq->link, iq->uin); | |
275 } | |
276 | |
277 static void icq_auth_req(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, | |
278 unsigned char day, unsigned char month, unsigned short year, const char *nick, | |
279 const char *first, const char *last, const char *email, const char *reason) | |
280 { | |
281 char msg[8192]; | |
282 struct icq_auth *iq = g_new0(struct icq_auth, 1); | |
283 iq->link = link; | |
284 iq->uin = uin; | |
285 | |
286 g_snprintf(msg, sizeof(msg), "The user %s (%s%s%s%s%s) wants you to authorize them.", | |
287 nick, first ? first : "", first && last ? " " : "", last ? last : "", | |
288 (first || last) && email ? ", " : "", email ? email : ""); | |
289 do_ask_dialog(msg, iq, icq_acc_auth, icq_den_auth); | |
290 } | |
291 | |
292 static void icq_login(struct aim_user *user) { | |
293 struct gaim_connection *gc = new_gaim_conn(user); | |
294 struct icq_data *id = gc->proto_data = g_new0(struct icq_data, 1); | |
295 icq_Link *link; | |
296 char ps[9]; | |
297 | |
298 icq_LogLevel = ICQ_LOG_MESSAGE; | |
299 | |
300 g_snprintf(ps, sizeof(ps), "%s", user->password); | |
301 link = id->link = icq_ICQLINKNew(atol(user->username), ps, | |
302 user->proto_opt[USEROPT_NICK][0] ? user->proto_opt[USEROPT_NICK] : "gaim user", | |
303 TRUE); | |
304 | |
305 link->icq_Logged = icq_online; | |
306 link->icq_Disconnected = icq_logged_off; | |
307 link->icq_RecvMessage = icq_msg_incoming; | |
308 link->icq_RecvURL = icq_url_incoming; | |
309 link->icq_RecvWebPager = icq_web_pager; | |
310 link->icq_RecvMailExpress = icq_mail_express; | |
311 link->icq_RecvAuthReq = icq_auth_req; | |
312 link->icq_UserOnline = icq_user_online; | |
313 link->icq_UserOffline = icq_user_offline; | |
314 link->icq_UserStatusUpdate = icq_user_status; | |
315 link->icq_InfoReply = icq_info_reply; | |
316 link->icq_WrongPassword = icq_wrong_passwd; | |
317 link->icq_InvalidUIN = icq_invalid_uin; | |
318 link->icq_Log = icq_do_log; | |
319 link->icq_RequestNotify = icq_req_not; | |
320 | |
321 if (proxytype == PROXY_SOCKS5) | |
322 icq_SetProxy(link, proxyhost, proxyport, proxyuser[0], proxyuser, proxypass); | |
323 | |
324 icq_ContactClear(id->link); | |
325 if (bud_list_cache_exists(gc)) | |
326 do_import(NULL, gc); | |
327 | |
328 if (icq_Connect(link, "icq.mirabilis.com", 4000) < 1) { | |
329 hide_login_progress(gc, "Unable to connect"); | |
330 signoff(gc); | |
331 return; | |
332 } | |
333 | |
334 icq_Login(link, STATUS_ONLINE); | |
335 id->cur_status = STATUS_ONLINE; | |
336 | |
337 set_login_progress(gc, 0, "Connecting..."); | |
338 } | |
339 | |
340 static void icq_close(struct gaim_connection *gc) { | |
341 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
342 | |
343 icq_Logout(id->link); | |
344 icq_Disconnect(id->link); | |
345 icq_ICQLINKDelete(id->link); | |
346 g_slist_free(id->thru_serv); | |
347 g_free(id); | |
348 } | |
349 | |
350 static void icq_send_msg(struct gaim_connection *gc, char *who, char *msg, int away) { | |
351 if (!away && (strlen(msg) > 0)) { | |
352 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
353 GSList *l = id->thru_serv; | |
354 long w = atol(who); | |
355 while (l) { | |
356 if (w == (long)l->data) | |
357 break; | |
358 l = l->next; | |
359 } | |
360 icq_SendMessage(id->link, w, msg, l ? ICQ_SEND_THRUSERVER : ICQ_SEND_BESTWAY); | |
361 } | |
362 } | |
363 | |
364 static void icq_keepalive(struct gaim_connection *gc) { | |
365 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
366 icq_KeepAlive(id->link); | |
367 } | |
368 | |
369 static void icq_add_buddy(struct gaim_connection *gc, char *who) { | |
370 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
371 icq_ContactAdd(id->link, atol(who)); | |
372 icq_ContactSetVis(id->link, atol(who), TRUE); | |
373 } | |
374 | |
375 static void icq_add_buddies(struct gaim_connection *gc, GList *whos) { | |
376 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
377 while (whos) { | |
378 icq_ContactAdd(id->link, atol(whos->data)); | |
379 icq_ContactSetVis(id->link, atol(whos->data), TRUE); | |
380 whos = whos->next; | |
381 } | |
382 } | |
383 | |
384 static void icq_rem_buddy(struct gaim_connection *gc, char *who) { | |
385 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
386 icq_ContactRemove(id->link, atol(who)); | |
387 } | |
388 | |
389 static void icq_set_away(struct gaim_connection *gc, char *state, char *msg) { | |
390 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
391 | |
392 if (gc->away) | |
393 gc->away = NULL; | |
394 | |
395 if (!strcmp(state, "Online")) | |
396 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
397 else if (!strcmp(state, "Away")) { | |
398 icq_ChangeStatus(id->link, STATUS_AWAY); | |
399 gc->away = ""; | |
400 } else if (!strcmp(state, "Do Not Disturb")) { | |
401 icq_ChangeStatus(id->link, STATUS_DND); | |
402 gc->away = ""; | |
403 } else if (!strcmp(state, "Not Available")) { | |
404 icq_ChangeStatus(id->link, STATUS_NA); | |
405 gc->away = ""; | |
406 } else if (!strcmp(state, "Occupied")) { | |
407 icq_ChangeStatus(id->link, STATUS_OCCUPIED); | |
408 gc->away = ""; | |
409 } else if (!strcmp(state, "Free For Chat")) { | |
410 icq_ChangeStatus(id->link, STATUS_FREE_CHAT); | |
411 gc->away = ""; | |
412 } else if (!strcmp(state, "Invisible")) { | |
413 icq_ChangeStatus(id->link, STATUS_INVISIBLE); | |
414 gc->away = ""; | |
415 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
416 if (msg) { | |
417 icq_ChangeStatus(id->link, STATUS_NA); | |
418 gc->away = ""; | |
419 } else { | |
420 icq_ChangeStatus(id->link, STATUS_ONLINE); | |
421 } | |
422 } | |
423 } | |
424 | |
425 static char **icq_list_icon(int uc) { | |
426 guint status; | |
427 if (uc == UC_NORMAL) | |
428 return icon_online_xpm; | |
429 status = uc >> 5; | |
430 if (status & STATUS_NA) | |
431 return icon_na_xpm; | |
432 if (status & STATUS_DND) | |
433 return icon_dnd_xpm; | |
434 if (status & STATUS_OCCUPIED) | |
435 return icon_occ_xpm; | |
436 if (status & STATUS_AWAY) | |
437 return icon_away_xpm; | |
438 if (status & STATUS_FREE_CHAT) | |
439 return icon_ffc_xpm; | |
440 if (status & STATUS_INVISIBLE) | |
441 return NULL; | |
442 return icon_online_xpm; | |
443 } | |
444 | |
445 static void icq_get_info(struct gaim_connection *gc, char *who) { | |
446 struct icq_data *id = (struct icq_data *)gc->proto_data; | |
447 icq_SendInfoReq(id->link, atol(who)); | |
448 } | |
449 | |
450 static void icq_info(GtkObject *obj, char *who) { | |
451 serv_get_info(gtk_object_get_user_data(obj), who); | |
452 } | |
453 | |
454 static void icq_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { | |
455 GtkWidget *button; | |
456 | |
457 button = gtk_menu_item_new_with_label(_("Get Info")); | |
458 gtk_signal_connect(GTK_OBJECT(button), "activate", | |
459 GTK_SIGNAL_FUNC(icq_info), who); | |
460 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
461 gtk_menu_append(GTK_MENU(menu), button); | |
462 gtk_widget_show(button); | |
463 } | |
464 | |
465 static void icq_print_option(GtkEntry *entry, struct aim_user *user) { | |
466 int entrynum; | |
467 | |
468 entrynum = (int) gtk_object_get_user_data(GTK_OBJECT(entry)); | |
469 | |
470 if (entrynum == USEROPT_NICK) | |
471 g_snprintf(user->proto_opt[USEROPT_NICK], | |
472 sizeof(user->proto_opt[USEROPT_NICK]), | |
473 "%s", gtk_entry_get_text(entry)); | |
474 } | |
475 | |
476 static void icq_user_opts(GtkWidget *book, struct aim_user *user) { | |
477 GtkWidget *vbox; | |
478 GtkWidget *hbox; | |
479 GtkWidget *label; | |
480 GtkWidget *entry; | |
481 | |
482 vbox = gtk_vbox_new(FALSE, 5); | |
483 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | |
484 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, | |
485 gtk_label_new("ICQ Options")); | |
486 gtk_widget_show(vbox); | |
487 | |
488 hbox = gtk_hbox_new(FALSE, 5); | |
489 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
490 gtk_widget_show(hbox); | |
491 | |
492 label = gtk_label_new("Nick"); | |
493 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
494 gtk_widget_show(label); | |
495 | |
496 entry = gtk_entry_new(); | |
497 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
498 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_NICK); | |
499 gtk_signal_connect(GTK_OBJECT(entry), "changed", | |
500 GTK_SIGNAL_FUNC(icq_print_option), user); | |
501 if (user->proto_opt[USEROPT_NICK][0]) | |
502 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_NICK]); | |
503 else | |
504 gtk_entry_set_text(GTK_ENTRY(entry), "gaim user"); | |
505 gtk_widget_show(entry); | |
506 | |
507 hbox = gtk_hbox_new(FALSE, 5); | |
508 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
509 gtk_widget_show(hbox); | |
510 } | |
511 | |
512 static GList *icq_away_states() { | |
513 GList *m = NULL; | |
514 | |
515 m = g_list_append(m, "Online"); | |
516 m = g_list_append(m, "Away"); | |
517 m = g_list_append(m, "Do Not Disturb"); | |
518 m = g_list_append(m, "Not Available"); | |
519 m = g_list_append(m, "Occupied"); | |
520 m = g_list_append(m, "Free For Chat"); | |
521 m = g_list_append(m, "Invisible"); | |
522 | |
523 return m; | |
524 } | |
525 | |
526 static void toggle_thru_serv(GtkToggleButton *button, struct conversation *c) | |
527 { | |
528 struct gaim_connection *gc = gtk_object_get_user_data(GTK_OBJECT(button)); | |
529 struct icq_data *id = gc->proto_data; | |
530 GSList *l = id->thru_serv; | |
531 long who = atol(c->name); | |
532 | |
533 while (l) { | |
534 if (who == (long)l->data) | |
535 break; | |
536 l = l->next; | |
537 } | |
538 if (l) | |
539 id->thru_serv = g_slist_remove(id->thru_serv, (void *)who); | |
540 else | |
541 id->thru_serv = g_slist_append(id->thru_serv, (void *)who); | |
542 } | |
543 | |
544 static void icq_insert_convo(struct gaim_connection *gc, struct conversation *c) | |
545 { | |
546 GtkWidget *button; | |
547 struct icq_data *id = gc->proto_data; | |
548 GSList *l = id->thru_serv; | |
549 long who = atol(c->name); | |
550 | |
551 button = gtk_check_button_new_with_label("Send message through server"); | |
552 gtk_box_pack_start(GTK_BOX(c->lbox), button, FALSE, FALSE, 5); | |
553 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_thru_serv), c); | |
554 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
555 while (l) { | |
556 if (who == (long)l->data) | |
557 break; | |
558 l = l->next; | |
559 } | |
560 if (l) | |
561 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
562 gtk_widget_show(button); | |
563 } | |
564 | |
565 static void icq_remove_convo(struct gaim_connection *gc, struct conversation *c) | |
566 { | |
567 while (GTK_BOX(c->lbox)->children) | |
568 gtk_container_remove(GTK_CONTAINER(c->lbox), | |
569 ((GtkBoxChild *)GTK_BOX(c->lbox)->children->data)->widget); | |
570 } | |
571 | |
572 static struct prpl *my_protocol = NULL; | |
573 | |
574 void icq_init(struct prpl *ret) { | |
575 ret->protocol = PROTO_ICQ; | |
576 ret->name = icq_name; | |
577 ret->list_icon = icq_list_icon; | |
578 ret->away_states = icq_away_states; | |
579 ret->buddy_menu = icq_buddy_menu; | |
580 ret->user_opts = icq_user_opts; | |
581 ret->insert_convo = icq_insert_convo; | |
582 ret->remove_convo = icq_remove_convo; | |
583 ret->login = icq_login; | |
584 ret->close = icq_close; | |
585 ret->send_im = icq_send_msg; | |
586 ret->add_buddy = icq_add_buddy; | |
587 ret->add_buddies = icq_add_buddies; | |
588 ret->remove_buddy = icq_rem_buddy; | |
589 ret->get_info = icq_get_info; | |
590 ret->set_away = icq_set_away; | |
591 ret->keepalive = icq_keepalive; | |
592 | |
593 my_protocol = ret; | |
594 | |
595 icq_SocketNotify = icq_sock_notify; | |
596 icq_SetTimeout = icq_set_timeout; | |
597 } | |
598 | |
599 #ifndef STATIC | |
600 | |
601 char *gaim_plugin_init(GModule *handle) | |
602 { | |
603 load_protocol(icq_init, sizeof(struct prpl)); | |
604 return NULL; | |
605 } | |
606 | |
607 void gaim_plugin_remove() | |
608 { | |
609 struct prpl *p = find_prpl(PROTO_ICQ); | |
610 if (p == my_protocol) | |
611 unload_protocol(p); | |
612 } | |
613 | |
614 char *name() | |
615 { | |
616 return "ICQ"; | |
617 } | |
618 | |
619 char *description() | |
620 { | |
621 return "Allows gaim to use the ICQ protocol"; | |
622 } | |
623 | |
624 #endif |