Mercurial > pidgin.yaz
comparison plugins/yay/yay.c @ 1143:403989ecc1cc
[gaim-migrate @ 1153]
wow, yahoo is getting better. now i just have to figure out the UI for setting an actual away status as opposed to a custom one every time. hm...
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 27 Nov 2000 12:21:51 +0000 |
parents | c8615d023aaf |
children | 8fabc3349254 |
comparison
equal
deleted
inserted
replaced
1142:4593153a956c | 1143:403989ecc1cc |
---|---|
40 #include "multi.h" | 40 #include "multi.h" |
41 #include "prpl.h" | 41 #include "prpl.h" |
42 #include "gaim.h" | 42 #include "gaim.h" |
43 #include "libyahoo.h" | 43 #include "libyahoo.h" |
44 | 44 |
45 #include "pixmaps/free_icon.xpm" | |
46 #include "pixmaps/away_icon.xpm" | |
47 #include "pixmaps/dt_icon.xpm" | |
48 | |
45 struct yahoo_data { | 49 struct yahoo_data { |
46 struct yahoo_context *ctxt; | 50 struct yahoo_context *ctxt; |
51 int current_status; | |
52 GHashTable *hash; | |
47 }; | 53 }; |
48 | 54 |
49 static char *yahoo_name() { | 55 static char *yahoo_name() { |
50 return "Yahoo"; | 56 return "Yahoo"; |
51 } | 57 } |
61 static void process_packet_status(struct gaim_connection *gc, struct yahoo_packet *pkt) { | 67 static void process_packet_status(struct gaim_connection *gc, struct yahoo_packet *pkt) { |
62 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | 68 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
63 int i; | 69 int i; |
64 | 70 |
65 if (pkt->service == YAHOO_SERVICE_LOGOFF && !strcasecmp(pkt->active_id, gc->username)) { | 71 if (pkt->service == YAHOO_SERVICE_LOGOFF && !strcasecmp(pkt->active_id, gc->username)) { |
72 hide_login_progress(gc, "Disconnected"); | |
66 signoff(gc); | 73 signoff(gc); |
67 return; | 74 return; |
68 } | 75 } |
69 | 76 |
70 for (i = 0; i < pkt->idstatus_count; i++) { | 77 for (i = 0; i < pkt->idstatus_count; i++) { |
79 struct yahoo_buddy *bud = *buddy; | 86 struct yahoo_buddy *bud = *buddy; |
80 | 87 |
81 if (!strcasecmp(rec->id, bud->id)) | 88 if (!strcasecmp(rec->id, bud->id)) |
82 b = add_buddy(gc, bud->group, bud->id, bud->id); | 89 b = add_buddy(gc, bud->group, bud->id, bud->id); |
83 } | 90 } |
91 if (!b) | |
92 continue; /* ???!!! */ | |
84 } | 93 } |
85 if (pkt->service == YAHOO_SERVICE_LOGOFF) | 94 if (pkt->service == YAHOO_SERVICE_LOGOFF) |
86 serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0); | 95 serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0); |
87 else | 96 else { |
88 serv_got_update(gc, b->name, 1, 0, 0, 0, rec->status, 0); | 97 if (rec->status == YAHOO_STATUS_IDLE) |
98 serv_got_update(gc, b->name, 1, 0, 0, 10, UC_NORMAL, 0); | |
99 else if (rec->status == YAHOO_STATUS_AVAILABLE) | |
100 serv_got_update(gc, b->name, 1, 0, 0, 0, UC_NORMAL, 0); | |
101 else | |
102 serv_got_update(gc, b->name, 1, 0, 0, 0, | |
103 (rec->status << 5) | UC_UNAVAILABLE, 0); | |
104 if (rec->status == YAHOO_STATUS_CUSTOM) { | |
105 gpointer val = g_hash_table_lookup(yd->hash, b->name); | |
106 if (val) | |
107 g_free(val); | |
108 g_hash_table_insert(yd->hash, | |
109 g_strdup(b->name), g_strdup(rec->status_msg)); | |
110 } | |
111 } | |
89 } | 112 } |
90 } | 113 } |
91 | 114 |
92 static void process_packet_message(struct gaim_connection *gc, struct yahoo_packet *pkt) { | 115 static void process_packet_message(struct gaim_connection *gc, struct yahoo_packet *pkt) { |
93 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | 116 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
143 | 166 |
144 struct yahoo_rawpacket *rawpkt; | 167 struct yahoo_rawpacket *rawpkt; |
145 struct yahoo_packet *pkt; | 168 struct yahoo_packet *pkt; |
146 | 169 |
147 if (!yahoo_getdata(yd->ctxt)) { | 170 if (!yahoo_getdata(yd->ctxt)) { |
171 hide_login_progress(gc, "Disconnected"); | |
148 signoff(gc); | 172 signoff(gc); |
149 } | 173 } |
150 | 174 |
151 while ((rawpkt = yahoo_getpacket(yd->ctxt)) != NULL) { | 175 while ((rawpkt = yahoo_getpacket(yd->ctxt)) != NULL) { |
152 pkt = yahoo_parsepacket(yd->ctxt, rawpkt); | 176 pkt = yahoo_parsepacket(yd->ctxt, rawpkt); |
164 case YAHOO_SERVICE_MESSAGE: | 188 case YAHOO_SERVICE_MESSAGE: |
165 case YAHOO_SERVICE_CHATMSG: | 189 case YAHOO_SERVICE_CHATMSG: |
166 case YAHOO_SERVICE_SYSMESSAGE: | 190 case YAHOO_SERVICE_SYSMESSAGE: |
167 process_packet_message(gc, pkt); | 191 process_packet_message(gc, pkt); |
168 break; | 192 break; |
193 case YAHOO_SERVICE_NEWCONTACT: | |
194 if (pkt->msg) | |
195 process_packet_message(gc, pkt); | |
196 else | |
197 process_packet_status(gc, pkt); | |
198 break; | |
169 case YAHOO_SERVICE_CONFINVITE: | 199 case YAHOO_SERVICE_CONFINVITE: |
170 process_packet_conf_invite(gc, pkt); | 200 process_packet_conf_invite(gc, pkt); |
171 break; | 201 break; |
172 case YAHOO_SERVICE_CONFADDINVITE: | 202 case YAHOO_SERVICE_CONFADDINVITE: |
173 process_packet_conf_add_invite(gc, pkt); | 203 process_packet_conf_add_invite(gc, pkt); |
204 struct yahoo_context *ctxt; | 234 struct yahoo_context *ctxt; |
205 opt.connect_mode = YAHOO_CONNECT_NORMAL; | 235 opt.connect_mode = YAHOO_CONNECT_NORMAL; |
206 opt.proxy_host = NULL; | 236 opt.proxy_host = NULL; |
207 ctxt = yahoo_init(user->username, user->password, &opt); | 237 ctxt = yahoo_init(user->username, user->password, &opt); |
208 yd->ctxt = ctxt; | 238 yd->ctxt = ctxt; |
239 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
240 yd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
209 | 241 |
210 set_login_progress(gc, 1, "Connecting"); | 242 set_login_progress(gc, 1, "Connecting"); |
211 while (gtk_events_pending()) | 243 while (gtk_events_pending()) |
212 gtk_main_iteration(); | 244 gtk_main_iteration(); |
213 if (!g_slist_find(connections, gc)) | 245 if (!g_slist_find(connections, gc)) |
256 | 288 |
257 gc->inpa = gdk_input_add(ctxt->sockfd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, | 289 gc->inpa = gdk_input_add(ctxt->sockfd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, |
258 yahoo_callback, gc); | 290 yahoo_callback, gc); |
259 } | 291 } |
260 | 292 |
293 static gboolean yahoo_destroy_hash(gpointer key, gpointer val, gpointer data) { | |
294 g_free(key); | |
295 g_free(val); | |
296 return TRUE; | |
297 } | |
298 | |
261 static void yahoo_close(struct gaim_connection *gc) { | 299 static void yahoo_close(struct gaim_connection *gc) { |
262 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | 300 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
263 if (gc->inpa) | 301 if (gc->inpa) |
264 gdk_input_remove(gc->inpa); | 302 gdk_input_remove(gc->inpa); |
265 gc->inpa = -1; | 303 gc->inpa = -1; |
266 yahoo_cmd_logoff(yd->ctxt); | 304 yahoo_cmd_logoff(yd->ctxt); |
305 g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL); | |
306 g_hash_table_destroy(yd->hash); | |
267 g_free(yd); | 307 g_free(yd); |
268 } | 308 } |
269 | 309 |
270 static void yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int away) { | 310 static void yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int away) { |
271 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | 311 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
272 | 312 |
273 yahoo_cmd_msg(yd->ctxt, gc->username, who, message); | 313 yahoo_cmd_msg(yd->ctxt, gc->username, who, message); |
274 } | 314 } |
275 | 315 |
316 static void yahoo_set_away(struct gaim_connection *gc, char *msg) { | |
317 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
318 | |
319 if (msg) { | |
320 yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_CUSTOM, msg); | |
321 yd->current_status = YAHOO_STATUS_CUSTOM; | |
322 } else if (gc->is_idle) { | |
323 yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_IDLE, NULL); | |
324 yd->current_status = YAHOO_STATUS_IDLE; | |
325 } else { | |
326 yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_AVAILABLE, NULL); | |
327 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
328 } | |
329 } | |
330 | |
276 static void yahoo_set_idle(struct gaim_connection *gc, int idle) { | 331 static void yahoo_set_idle(struct gaim_connection *gc, int idle) { |
277 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | 332 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
278 | 333 |
279 if (idle) | 334 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { |
280 yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_IDLE, NULL); | 335 yahoo_cmd_set_away_mode(yd->ctxt, YAHOO_STATUS_IDLE, NULL); |
281 else | 336 yd->current_status = YAHOO_STATUS_IDLE; |
337 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
282 yahoo_cmd_set_back_mode(yd->ctxt, YAHOO_STATUS_AVAILABLE, NULL); | 338 yahoo_cmd_set_back_mode(yd->ctxt, YAHOO_STATUS_AVAILABLE, NULL); |
339 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
340 } | |
283 } | 341 } |
284 | 342 |
285 static void yahoo_keepalive(struct gaim_connection *gc) { | 343 static void yahoo_keepalive(struct gaim_connection *gc) { |
286 yahoo_cmd_ping(((struct yahoo_data *)gc->proto_data)->ctxt); | 344 yahoo_cmd_ping(((struct yahoo_data *)gc->proto_data)->ctxt); |
287 } | 345 } |
301 | 359 |
302 if (group) | 360 if (group) |
303 yahoo_add_buddy(yd->ctxt, name, gc->username, group, ""); | 361 yahoo_add_buddy(yd->ctxt, name, gc->username, group, ""); |
304 } | 362 } |
305 | 363 |
364 static char **yahoo_list_icon(int uc) { | |
365 if (uc & UC_NORMAL) | |
366 return free_icon_xpm; | |
367 if ((uc >> 5) == YAHOO_STATUS_CUSTOM) | |
368 return dt_icon_xpm; | |
369 return away_icon_xpm; | |
370 } | |
371 | |
372 static void yahoo_action_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { | |
373 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
374 GtkWidget *button; | |
375 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, | |
376 segfault and get the bug report. */ | |
377 char buf[1024]; | |
378 | |
379 if (b->uc & UC_NORMAL) | |
380 return; | |
381 | |
382 if ((b->uc >> 5) != YAHOO_STATUS_CUSTOM) | |
383 g_snprintf(buf, sizeof buf, "Status: %s", yahoo_get_status_string(b->uc >> 5)); | |
384 else | |
385 g_snprintf(buf, sizeof buf, "Custom Status: %s", g_hash_table_lookup(yd->hash, b->name)); | |
386 button = gtk_menu_item_new_with_label(buf); | |
387 gtk_menu_append(GTK_MENU(menu), button); | |
388 gtk_widget_show(button); | |
389 } | |
390 | |
306 static struct prpl *my_protocol = NULL; | 391 static struct prpl *my_protocol = NULL; |
307 | 392 |
308 void Yahoo_init(struct prpl *ret) { | 393 void Yahoo_init(struct prpl *ret) { |
309 /* the NULL's aren't required but they're nice to have */ | 394 /* the NULL's aren't required but they're nice to have */ |
310 ret->protocol = PROTO_YAHOO; | 395 ret->protocol = PROTO_YAHOO; |
311 ret->name = yahoo_name; | 396 ret->name = yahoo_name; |
312 ret->list_icon = NULL; | 397 ret->list_icon = yahoo_list_icon; |
313 ret->action_menu = NULL; | 398 ret->action_menu = yahoo_action_menu; |
314 ret->login = yahoo_login; | 399 ret->login = yahoo_login; |
315 ret->close = yahoo_close; | 400 ret->close = yahoo_close; |
316 ret->send_im = yahoo_send_im; | 401 ret->send_im = yahoo_send_im; |
317 ret->set_info = NULL; | 402 ret->set_info = NULL; |
318 ret->get_info = NULL; | 403 ret->get_info = NULL; |
319 ret->set_away = NULL; | 404 ret->set_away = yahoo_set_away; |
320 ret->get_away_msg = NULL; | 405 ret->get_away_msg = NULL; |
321 ret->set_dir = NULL; | 406 ret->set_dir = NULL; |
322 ret->get_dir = NULL; | 407 ret->get_dir = NULL; |
323 ret->dir_search = NULL; | 408 ret->dir_search = NULL; |
324 ret->set_idle = yahoo_set_idle; | 409 ret->set_idle = yahoo_set_idle; |