Mercurial > pidgin
comparison libpurple/protocols/myspace/myspace.c @ 19242:f60192409e7f
merge of '0ae78c5d891099ade8e599dc2087ff9411b98d5f'
and '615e30de07cd1a72f9af2a7949cd9b4ebdab63a0'
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Tue, 14 Aug 2007 02:45:41 +0000 |
parents | abb5b6ec99a6 6ea5602643ea |
children | a242e014ab8c |
comparison
equal
deleted
inserted
replaced
19241:0651af21ceee | 19242:f60192409e7f |
---|---|
35 | 35 |
36 #include "message.h" | 36 #include "message.h" |
37 #include "persist.h" | 37 #include "persist.h" |
38 #include "myspace.h" | 38 #include "myspace.h" |
39 | 39 |
40 /* Globals */ | 40 |
41 /* Loosely based on Miranda plugin by Scott Ellis, formatting.cpp, | |
42 * https://server.scottellis.com.au/websvn/filedetails.php?repname=Miranda+Plugins&path=%2FMySpace%2Fformatting.cpp&rev=0&sc=0 */ | |
41 | 43 |
42 /* The names in in emoticon_names (for <i n=whatever>) map to corresponding | 44 /* The names in in emoticon_names (for <i n=whatever>) map to corresponding |
43 * entries in emoticon_symbols (for the ASCII representation of the emoticon). | 45 * entries in emoticon_symbols (for the ASCII representation of the emoticon). |
44 * | 46 * |
45 * Multiple emoticon symbols in Pidgin can map to one name. List the | 47 * Multiple emoticon symbols in Pidgin can map to one name. List the |
46 * canonical form, as inserted by the "Smile!" dialog, first. For example, | 48 * canonical form, as inserted by the "Smile!" dialog, first. For example, |
47 * :) comes before :-), because although both are recognized as 'happy', | 49 * :) comes before :-), because although both are recognized as 'happy', |
48 * the first is inserted by the smiley button (first symbol in theme). | 50 * the first is inserted by the smiley button. |
49 * | 51 * |
50 * Note that symbols are case-sensitive in Pidgin -- :-X is not :-x. */ | 52 * Note that symbols are case-sensitive in Pidgin -- :-X is not :-x. */ |
51 static struct MSIM_EMOTICON | 53 static struct MSIM_EMOTICON |
52 { | 54 { |
53 gchar *name; | 55 gchar *name; |
91 { "kiss", ":x" }, | 93 { "kiss", ":x" }, |
92 { NULL, NULL } | 94 { NULL, NULL } |
93 }; | 95 }; |
94 | 96 |
95 /* Internal functions */ | 97 /* Internal functions */ |
96 static gboolean msim_send_zap(MsimSession *session, const gchar *username, guint code); | 98 static void msim_send_zap(PurpleBlistNode *node, gpointer zap_num_ptr); |
97 static void msim_send_zap_from_menu(PurpleBlistNode *node, gpointer zap_num_ptr); | |
98 | 99 |
99 #ifdef MSIM_DEBUG_MSG | 100 #ifdef MSIM_DEBUG_MSG |
100 static void print_hash_item(gpointer key, gpointer value, gpointer user_data); | 101 static void print_hash_item(gpointer key, gpointer value, gpointer user_data); |
101 #endif | 102 #endif |
102 | 103 |
280 | 281 |
281 | 282 |
282 return types; | 283 return types; |
283 } | 284 } |
284 | 285 |
285 /** Get zap types. */ | |
286 GList * | |
287 msim_attention_types(PurpleAccount *acct) | |
288 { | |
289 static GList *types = NULL; | |
290 PurpleAttentionType* attn; | |
291 | |
292 if (!types) { | |
293 #define _MSIM_ADD_NEW_ATTENTION(icn, des, incoming, outgoing) \ | |
294 attn = g_new0(PurpleAttentionType, 1); \ | |
295 attn->icon = icn; \ | |
296 attn->description = des; \ | |
297 attn->incoming_description = incoming; \ | |
298 attn->outgoing_description = outgoing; \ | |
299 types = g_list_append(types, attn); | |
300 | |
301 /* TODO: icons for each zap */ | |
302 _MSIM_ADD_NEW_ATTENTION(NULL, _("zap"), _("zapped"), _("Zapping")); | |
303 _MSIM_ADD_NEW_ATTENTION(NULL, _("whack"), _("whacked"), _("Whacking")); | |
304 _MSIM_ADD_NEW_ATTENTION(NULL, _("torch"), _("torched"), _("Torching")); | |
305 _MSIM_ADD_NEW_ATTENTION(NULL, _("smooch"), _("smooched"), _("Smooching")); | |
306 _MSIM_ADD_NEW_ATTENTION(NULL, _("hug"), _("hugged"), _("Hugging")); | |
307 _MSIM_ADD_NEW_ATTENTION(NULL, _("bslap"), _("bslapped"), _("Bslapping")); | |
308 _MSIM_ADD_NEW_ATTENTION(NULL, _("goose"), _("goosed"), _("Goosing")); | |
309 _MSIM_ADD_NEW_ATTENTION(NULL, _("hi-five"), _("hi-fived"), _("Hi-fiving")); | |
310 _MSIM_ADD_NEW_ATTENTION(NULL, _("punk"), _("punk'd"), _("Punking")); | |
311 _MSIM_ADD_NEW_ATTENTION(NULL, _("raspberry"), _("raspberried"), _("Raspberry'ing")); | |
312 } | |
313 | |
314 return types; | |
315 } | |
316 | |
317 /** Send a zap */ | |
318 gboolean | |
319 msim_send_attention(PurpleConnection *gc, gchar *username, guint code) | |
320 { | |
321 GList *types; | |
322 MsimSession *session; | |
323 PurpleAttentionType *attn; | |
324 PurpleBuddy *buddy; | |
325 | |
326 session = (MsimSession *)gc->proto_data; | |
327 | |
328 /* Look for this attention type, by the code index given. */ | |
329 types = msim_attention_types(gc->account); | |
330 attn = (PurpleAttentionType *)g_list_nth_data(types, code); | |
331 | |
332 if (!attn) { | |
333 purple_debug_info("msim_send_attention", "got invalid zap code %d\n", code); | |
334 return FALSE; | |
335 } | |
336 | |
337 buddy = purple_find_buddy(session->account, username); | |
338 if (!buddy) { | |
339 return FALSE; | |
340 } | |
341 | |
342 /* TODO: make use of the PurpleAttentionType we found, instead of | |
343 * doing it all over in msim_send_zap_from_menu. */ | |
344 msim_send_zap_from_menu(&buddy->node, GUINT_TO_POINTER(code)); | |
345 | |
346 return TRUE; | |
347 } | |
348 | |
349 /** Send a zap to a user. */ | |
350 static gboolean | |
351 msim_send_zap(MsimSession *session, const gchar *username, guint code) | |
352 { | |
353 gchar *zap_string; | |
354 #ifndef MSIM_USE_ATTENTION_API | |
355 gchar *zap_description; | |
356 #endif | |
357 GList *types; | |
358 PurpleAttentionType *attn; | |
359 gboolean rc; | |
360 | |
361 g_return_val_if_fail(session != NULL, FALSE); | |
362 g_return_val_if_fail(username != NULL, FALSE); | |
363 | |
364 types = msim_attention_types(session->account); | |
365 | |
366 attn = g_list_nth_data(types, code); | |
367 if (!attn) { | |
368 return FALSE; | |
369 } | |
370 | |
371 | |
372 #ifdef MSIM_USE_ATTENTION_API | |
373 serv_got_attention(session->gc, username, attn, FALSE); | |
374 #else | |
375 zap_description = g_strdup_printf("*** Attention: %s %s ***", attn->outgoing_description, | |
376 username); | |
377 | |
378 serv_got_im(session->gc, username, zap_description, | |
379 PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
380 | |
381 g_free(zap_description); | |
382 #endif | |
383 | |
384 /* Construct and send the actual zap command. */ | |
385 zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", code); | |
386 | |
387 if (!msim_send_bm(session, username, zap_string, MSIM_BM_ACTION)) { | |
388 purple_debug_info("msim_send_zap_from_menu", "msim_send_bm failed: zapping %s with %s", | |
389 username, zap_string); | |
390 rc = FALSE; | |
391 } else { | |
392 rc = TRUE; | |
393 } | |
394 | |
395 g_free(zap_string); | |
396 | |
397 return rc; | |
398 | |
399 } | |
400 | |
401 /** Zap someone. Callback from msim_blist_node_menu zap menu. */ | 286 /** Zap someone. Callback from msim_blist_node_menu zap menu. */ |
402 static void | 287 static void |
403 msim_send_zap_from_menu(PurpleBlistNode *node, gpointer zap_num_ptr) | 288 msim_send_zap(PurpleBlistNode *node, gpointer zap_num_ptr) |
404 { | 289 { |
405 PurpleBuddy *buddy; | 290 PurpleBuddy *buddy; |
406 PurpleAccount *account; | |
407 PurpleConnection *gc; | 291 PurpleConnection *gc; |
408 MsimSession *session; | 292 MsimSession *session; |
293 gchar *username, *zap_string, *zap_text; | |
409 guint zap; | 294 guint zap; |
295 const gchar *zap_gerund[10]; | |
410 | 296 |
411 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) { | 297 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
412 /* Only know about buddies for now. */ | 298 /* Only know about buddies for now. */ |
413 return; | 299 return; |
414 } | 300 } |
415 | 301 |
302 zap_gerund[0] = _("Zapping"); | |
303 zap_gerund[1] = _("Whacking"); | |
304 zap_gerund[2] = _("Torching"); | |
305 zap_gerund[3] = _("Smooching"); | |
306 zap_gerund[4] = _("Hugging"); | |
307 zap_gerund[5] = _("Bslapping"); | |
308 zap_gerund[6] = _("Goosing"); | |
309 zap_gerund[7] = _("Hi-fiving"); | |
310 zap_gerund[8] = _("Punking"); | |
311 zap_gerund[9] = _("Raspberry'ing"); | |
312 | |
416 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); | 313 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
417 | 314 |
418 buddy = (PurpleBuddy *)node; | 315 buddy = (PurpleBuddy *)node; |
419 | 316 gc = purple_account_get_connection(buddy->account); |
420 /* Find the session */ | 317 g_return_if_fail(gc != NULL); |
421 account = buddy->account; | 318 |
422 gc = purple_account_get_connection(account); | |
423 session = (MsimSession *)gc->proto_data; | 319 session = (MsimSession *)gc->proto_data; |
320 g_return_if_fail(session != NULL); | |
321 | |
322 username = buddy->name; | |
323 g_return_if_fail(username != NULL); | |
424 | 324 |
425 zap = GPOINTER_TO_INT(zap_num_ptr); | 325 zap = GPOINTER_TO_INT(zap_num_ptr); |
426 | 326 zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", zap); |
427 g_return_if_fail(msim_send_zap(session, buddy->name, zap)); | 327 zap_text = g_strdup_printf("*** %s! ***", zap_gerund[zap]); |
328 | |
329 serv_got_im(session->gc, username, zap_text, | |
330 PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
331 | |
332 if (!msim_send_bm(session, username, zap_string, MSIM_BM_ACTION)) { | |
333 purple_debug_info("msim_send_zap", "msim_send_bm failed: zapping %s with %s", | |
334 username, zap_string); | |
335 } | |
336 | |
337 g_free(zap_string); | |
338 g_free(zap_text); | |
339 return; | |
428 } | 340 } |
429 | 341 |
430 | 342 |
431 /** Return menu, if any, for a buddy list node. */ | 343 /** Return menu, if any, for a buddy list node. */ |
432 GList * | 344 GList * |
433 msim_blist_node_menu(PurpleBlistNode *node) | 345 msim_blist_node_menu(PurpleBlistNode *node) |
434 { | 346 { |
435 GList *menu, *zap_menu; | 347 GList *menu, *zap_menu; |
436 GList *types; | |
437 PurpleMenuAction *act; | 348 PurpleMenuAction *act; |
438 /* Warning: hardcoded to match that in msim_attention_types. */ | |
439 const gchar *zap_names[10]; | 349 const gchar *zap_names[10]; |
440 guint i; | 350 guint i; |
441 | 351 |
442 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) { | 352 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
443 /* Only know about buddies for now. */ | 353 /* Only know about buddies for now. */ |
444 return NULL; | 354 return NULL; |
445 } | 355 } |
446 | 356 |
447 /* Names from official client. */ | 357 /* Names from official client. */ |
448 types = msim_attention_types(NULL); | 358 zap_names[0] = _("zap"); |
449 i = 0; | 359 zap_names[1] = _("whack"); |
450 do | 360 zap_names[2] = _("torch"); |
451 { | 361 zap_names[3] = _("smooch"); |
452 PurpleAttentionType *attn; | 362 zap_names[4] = _("hug"); |
453 | 363 zap_names[5] = _("bslap"); |
454 attn = (PurpleAttentionType *)types->data; | 364 zap_names[6] = _("goose"); |
455 zap_names[i] = attn->description; | 365 zap_names[7] = _("hi-five"); |
456 ++i; | 366 zap_names[8] = _("punk'd"); |
457 } while ((types = g_list_next(types))); | 367 zap_names[9] = _("raspberry"); |
458 | 368 |
459 menu = zap_menu = NULL; | 369 menu = zap_menu = NULL; |
460 | 370 |
461 /* TODO: get rid of once is accessible directly in GUI */ | 371 /* TODO: move to / command, or better yet new API */ |
462 for (i = 0; i < sizeof(zap_names) / sizeof(zap_names[0]); ++i) { | 372 for (i = 0; i < sizeof(zap_names) / sizeof(zap_names[0]); ++i) { |
463 act = purple_menu_action_new(zap_names[i], PURPLE_CALLBACK(msim_send_zap_from_menu), | 373 act = purple_menu_action_new(zap_names[i], PURPLE_CALLBACK(msim_send_zap), |
464 GUINT_TO_POINTER(i), NULL); | 374 GUINT_TO_POINTER(i), NULL); |
465 zap_menu = g_list_append(zap_menu, act); | 375 zap_menu = g_list_append(zap_menu, act); |
466 } | 376 } |
467 | 377 |
468 act = purple_menu_action_new(_("Zap"), NULL, NULL, zap_menu); | 378 act = purple_menu_action_new(_("Zap"), NULL, NULL, zap_menu); |
1680 | 1590 |
1681 /** Process an incoming zap. */ | 1591 /** Process an incoming zap. */ |
1682 static gboolean | 1592 static gboolean |
1683 msim_incoming_zap(MsimSession *session, MsimMessage *msg) | 1593 msim_incoming_zap(MsimSession *session, MsimMessage *msg) |
1684 { | 1594 { |
1685 gchar *msg_text, *username; | 1595 gchar *msg_text, *username, *zap_text; |
1686 gint zap; | 1596 gint zap; |
1687 const gchar *zap_past_tense[10]; | 1597 const gchar *zap_past_tense[10]; |
1688 #ifdef MSIM_USE_ATTENTION_API | |
1689 PurpleAttentionType attn; | |
1690 #else | |
1691 gchar *zap_text; | |
1692 #endif | |
1693 | 1598 |
1694 zap_past_tense[0] = _("zapped"); | 1599 zap_past_tense[0] = _("zapped"); |
1695 zap_past_tense[1] = _("whacked"); | 1600 zap_past_tense[1] = _("whacked"); |
1696 zap_past_tense[2] = _("torched"); | 1601 zap_past_tense[2] = _("torched"); |
1697 zap_past_tense[3] = _("smooched"); | 1602 zap_past_tense[3] = _("smooched"); |
1710 | 1615 |
1711 g_return_val_if_fail(sscanf(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", &zap) == 1, FALSE); | 1616 g_return_val_if_fail(sscanf(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", &zap) == 1, FALSE); |
1712 | 1617 |
1713 zap = CLAMP(zap, 0, sizeof(zap_past_tense) / sizeof(zap_past_tense[0])); | 1618 zap = CLAMP(zap, 0, sizeof(zap_past_tense) / sizeof(zap_past_tense[0])); |
1714 | 1619 |
1715 /* TODO:ZAP: use msim_attention_types */ | |
1716 #ifdef MSIM_USE_ATTENTION_API | |
1717 attn.incoming_description = zap_past_tense[zap]; | |
1718 attn.outgoing_description = NULL; | |
1719 attn.icon = NULL; /* TODO: icon */ | |
1720 | |
1721 serv_got_attention(session->gc, username, &attn, TRUE); | |
1722 #else | |
1723 zap_text = g_strdup_printf(_("*** You have been %s! ***"), zap_past_tense[zap]); | 1620 zap_text = g_strdup_printf(_("*** You have been %s! ***"), zap_past_tense[zap]); |
1621 | |
1724 serv_got_im(session->gc, username, zap_text, | 1622 serv_got_im(session->gc, username, zap_text, |
1725 PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, time(NULL)); | 1623 PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, time(NULL)); |
1624 | |
1726 g_free(zap_text); | 1625 g_free(zap_text); |
1727 #endif | |
1728 | |
1729 g_free(msg_text); | 1626 g_free(msg_text); |
1730 g_free(username); | 1627 g_free(username); |
1731 | 1628 |
1732 return TRUE; | 1629 return TRUE; |
1733 } | 1630 } |
3966 NULL, /* roomlist_cancel */ | 3863 NULL, /* roomlist_cancel */ |
3967 NULL, /* roomlist_expand_category */ | 3864 NULL, /* roomlist_expand_category */ |
3968 NULL, /* can_receive_file */ | 3865 NULL, /* can_receive_file */ |
3969 NULL, /* send_file */ | 3866 NULL, /* send_file */ |
3970 NULL, /* new_xfer */ | 3867 NULL, /* new_xfer */ |
3971 msim_offline_message, /* offline_message */ | 3868 msim_offline_message, /* offline_message */ |
3972 NULL, /* whiteboard_prpl_ops */ | 3869 NULL, /* whiteboard_prpl_ops */ |
3973 msim_send_really_raw, /* send_raw */ | 3870 msim_send_really_raw, /* send_raw */ |
3974 NULL, /* roomlist_room_serialize */ | 3871 NULL, /* roomlist_room_serialize */ |
3975 #ifdef MSIM_USE_ATTENTION_API | |
3976 msim_send_attention, /* send_attention */ | |
3977 msim_attention_types, /* attention_types */ | |
3978 #else | |
3979 NULL, /* _purple_reserved1 */ | 3872 NULL, /* _purple_reserved1 */ |
3980 NULL, /* _purple_reserved2 */ | 3873 NULL, /* _purple_reserved2 */ |
3981 #endif | |
3982 NULL, /* _purple_reserved3 */ | 3874 NULL, /* _purple_reserved3 */ |
3983 NULL /* _purple_reserved4 */ | 3875 NULL /* _purple_reserved4 */ |
3984 }; | 3876 }; |
3985 | 3877 |
3986 | 3878 |