Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 29658:a0fd6a41d127
propagate from branch 'im.pidgin.pidgin' (head 1203a733696f95eef53b04b5078e0a779371b4d3)
to branch 'im.pidgin.cpw.attention_ui' (head 37530586a02ebf04f4d6002ba9e30f0ff49eb527)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Sun, 07 Dec 2008 01:37:06 +0000 |
parents | fb5a11ec8be6 24aa608c5388 |
children | 9ea6842536ba |
comparison
equal
deleted
inserted
replaced
24604:918738a0bba4 | 29658:a0fd6a41d127 |
---|---|
1650 GList *jabber_status_types(PurpleAccount *account) | 1650 GList *jabber_status_types(PurpleAccount *account) |
1651 { | 1651 { |
1652 PurpleStatusType *type; | 1652 PurpleStatusType *type; |
1653 GList *types = NULL; | 1653 GList *types = NULL; |
1654 PurpleValue *priority_value; | 1654 PurpleValue *priority_value; |
1655 PurpleValue *buzz_enabled; | |
1655 | 1656 |
1656 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1657 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1657 purple_value_set_int(priority_value, 1); | 1658 purple_value_set_int(priority_value, 1); |
1659 buzz_enabled = purple_value_new(PURPLE_TYPE_BOOLEAN); | |
1660 purple_value_set_boolean(buzz_enabled, TRUE); | |
1658 type = purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE, | 1661 type = purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE, |
1659 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_ONLINE), | 1662 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_ONLINE), |
1660 NULL, TRUE, TRUE, FALSE, | 1663 NULL, TRUE, TRUE, FALSE, |
1661 "priority", _("Priority"), priority_value, | 1664 "priority", _("Priority"), priority_value, |
1662 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1665 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1663 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1666 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1664 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1667 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1665 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1668 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1666 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | 1669 "buzz", _("Allow Buzz"), buzz_enabled, |
1667 NULL); | 1670 NULL); |
1668 types = g_list_append(types, type); | 1671 types = g_list_append(types, type); |
1669 | 1672 |
1670 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1673 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1671 purple_value_set_int(priority_value, 1); | 1674 purple_value_set_int(priority_value, 1); |
1675 "priority", _("Priority"), priority_value, | 1678 "priority", _("Priority"), priority_value, |
1676 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1679 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1677 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1680 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1678 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1681 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1679 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1682 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1680 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | 1683 "buzz", _("Allow Buzz"), buzz_enabled, |
1681 NULL); | 1684 NULL); |
1682 types = g_list_append(types, type); | 1685 types = g_list_append(types, type); |
1683 | 1686 |
1684 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1687 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1685 purple_value_set_int(priority_value, 0); | 1688 purple_value_set_int(priority_value, 0); |
1689 "priority", _("Priority"), priority_value, | 1692 "priority", _("Priority"), priority_value, |
1690 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1693 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1691 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1694 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1692 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1695 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1693 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1696 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1694 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | 1697 "buzz", _("Allow Buzz"), buzz_enabled, |
1695 NULL); | 1698 NULL); |
1696 types = g_list_append(types, type); | 1699 types = g_list_append(types, type); |
1697 | 1700 |
1698 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1701 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1699 purple_value_set_int(priority_value, 0); | 1702 purple_value_set_int(priority_value, 0); |
1703 "priority", _("Priority"), priority_value, | 1706 "priority", _("Priority"), priority_value, |
1704 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1707 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1705 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1708 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1706 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1709 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1707 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1710 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1708 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | 1711 "buzz", _("Allow Buzz"), buzz_enabled, |
1709 NULL); | 1712 NULL); |
1710 types = g_list_append(types, type); | 1713 types = g_list_append(types, type); |
1711 | 1714 |
1712 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1715 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1713 purple_value_set_int(priority_value, 0); | 1716 purple_value_set_int(priority_value, 0); |
1717 "priority", _("Priority"), priority_value, | 1720 "priority", _("Priority"), priority_value, |
1718 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1721 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1719 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1722 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1720 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1723 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1721 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1724 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1722 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | |
1723 NULL); | 1725 NULL); |
1724 types = g_list_append(types, type); | 1726 types = g_list_append(types, type); |
1725 | 1727 |
1726 /* | 1728 /* |
1727 if(js->protocol_version == JABBER_PROTO_0_9) | 1729 if(js->protocol_version == JABBER_PROTO_0_9) |
2300 | 2302 |
2301 static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) { | 2303 static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) { |
2302 | 2304 |
2303 JabberBuddy *jb; | 2305 JabberBuddy *jb; |
2304 JabberBuddyResource *jbr; | 2306 JabberBuddyResource *jbr; |
2305 GList *iter; | 2307 PurpleConnection *gc = js->gc; |
2306 | 2308 PurpleAccount *account = purple_connection_get_account(gc); |
2309 PurpleConversation *conv = | |
2310 purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, username, | |
2311 account); | |
2312 gchar *str; | |
2313 | |
2307 if(!username) | 2314 if(!username) |
2308 return FALSE; | 2315 return FALSE; |
2309 | 2316 |
2310 jb = jabber_buddy_find(js, username, FALSE); | 2317 jb = jabber_buddy_find(js, username, FALSE); |
2311 if(!jb) { | 2318 if(!jb) { |
2312 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); | 2319 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); |
2313 return FALSE; | 2320 return FALSE; |
2314 } | 2321 } |
2315 | 2322 |
2316 jbr = jabber_buddy_find_resource(jb, NULL); | 2323 jbr = jabber_buddy_find_resource(jb, NULL); |
2317 if(!jbr) { | 2324 if (!jbr) { |
2318 *error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), username); | 2325 *error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), |
2326 username); | |
2319 return FALSE; | 2327 return FALSE; |
2320 } | 2328 } |
2321 | 2329 |
2322 if(!jbr->caps) { | 2330 if (jabber_resource_has_capability(jbr, XEP_0224_NAMESPACE)) { |
2323 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); | 2331 xmlnode *buzz, *msg = xmlnode_new("message"); |
2332 gchar *to; | |
2333 | |
2334 to = g_strdup_printf("%s/%s", username, jbr->name); | |
2335 xmlnode_set_attrib(msg, "to", to); | |
2336 g_free(to); | |
2337 | |
2338 /* avoid offline storage */ | |
2339 xmlnode_set_attrib(msg, "type", "headline"); | |
2340 | |
2341 buzz = xmlnode_new_child(msg, "attention"); | |
2342 xmlnode_set_namespace(buzz, XEP_0224_NAMESPACE); | |
2343 | |
2344 jabber_send(js, msg); | |
2345 xmlnode_free(msg); | |
2346 | |
2347 str = g_strdup_printf(_("Buzzing %s..."), username); | |
2348 purple_conversation_write(conv, NULL, str, | |
2349 PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL)); | |
2350 g_free(str); | |
2351 | |
2352 return TRUE; | |
2353 } else { | |
2354 *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); | |
2324 return FALSE; | 2355 return FALSE; |
2325 } | 2356 } |
2326 | |
2327 for(iter = jbr->caps->features; iter; iter = g_list_next(iter)) { | |
2328 if(!strcmp(iter->data, "http://www.xmpp.org/extensions/xep-0224.html#ns")) { | |
2329 xmlnode *buzz, *msg = xmlnode_new("message"); | |
2330 gchar *to; | |
2331 | |
2332 to = g_strdup_printf("%s/%s", username, jbr->name); | |
2333 xmlnode_set_attrib(msg, "to", to); | |
2334 g_free(to); | |
2335 | |
2336 /* avoid offline storage */ | |
2337 xmlnode_set_attrib(msg, "type", "headline"); | |
2338 | |
2339 buzz = xmlnode_new_child(msg, "attention"); | |
2340 xmlnode_set_namespace(buzz, "http://www.xmpp.org/extensions/xep-0224.html#ns"); | |
2341 | |
2342 jabber_send(js, msg); | |
2343 xmlnode_free(msg); | |
2344 | |
2345 return TRUE; | |
2346 } | |
2347 } | |
2348 | |
2349 *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); | |
2350 return FALSE; | |
2351 } | 2357 } |
2352 | 2358 |
2353 static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv, | 2359 static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv, |
2354 const char *cmd, char **args, char **error, void *data) | 2360 const char *cmd, char **args, char **error, void *data) |
2355 { | 2361 { |
2356 JabberStream *js = conv->account->gc->proto_data; | 2362 JabberStream *js = conv->account->gc->proto_data; |
2357 | 2363 const gchar *who; |
2358 if(!args || !args[0]) | 2364 |
2359 return PURPLE_CMD_RET_FAILED; | 2365 if (!args || !args[0]) { |
2360 | 2366 /* use the buddy from conversation, if it's a one-to-one conversation */ |
2361 return _jabber_send_buzz(js, args[0], error) ? PURPLE_CMD_RET_OK : PURPLE_CMD_RET_FAILED; | 2367 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) { |
2368 who = purple_conversation_get_name(conv); | |
2369 } else { | |
2370 return PURPLE_CMD_RET_FAILED; | |
2371 } | |
2372 } else { | |
2373 who = args[0]; | |
2374 } | |
2375 | |
2376 purple_conversation_attention(conv, who, 0, PURPLE_MESSAGE_SEND, time(NULL)); | |
2377 return _jabber_send_buzz(js, who, error) ? PURPLE_CMD_RET_OK : PURPLE_CMD_RET_FAILED; | |
2362 } | 2378 } |
2363 | 2379 |
2364 GList *jabber_attention_types(PurpleAccount *account) | 2380 GList *jabber_attention_types(PurpleAccount *account) |
2365 { | 2381 { |
2366 static GList *types = NULL; | 2382 static GList *types = NULL; |
2377 { | 2393 { |
2378 JabberStream *js = gc->proto_data; | 2394 JabberStream *js = gc->proto_data; |
2379 gchar *error = NULL; | 2395 gchar *error = NULL; |
2380 | 2396 |
2381 if (!_jabber_send_buzz(js, username, &error)) { | 2397 if (!_jabber_send_buzz(js, username, &error)) { |
2398 PurpleAccount *account = purple_connection_get_account(gc); | |
2399 PurpleConversation *conv = | |
2400 purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, | |
2401 username, account); | |
2382 purple_debug_error("jabber", "jabber_send_attention: jabber_cmd_buzz failed with error: %s\n", error ? error : "(NULL)"); | 2402 purple_debug_error("jabber", "jabber_send_attention: jabber_cmd_buzz failed with error: %s\n", error ? error : "(NULL)"); |
2403 purple_conversation_write(conv, username, error, | |
2404 PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL)); | |
2383 g_free(error); | 2405 g_free(error); |
2384 return FALSE; | 2406 return FALSE; |
2385 } | 2407 } |
2386 | 2408 |
2387 return TRUE; | 2409 return TRUE; |
2469 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | | 2491 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | |
2470 PURPLE_CMD_FLAG_PRPL_ONLY, | 2492 PURPLE_CMD_FLAG_PRPL_ONLY, |
2471 "prpl-jabber", jabber_cmd_ping, | 2493 "prpl-jabber", jabber_cmd_ping, |
2472 _("ping <jid>: Ping a user/component/server."), | 2494 _("ping <jid>: Ping a user/component/server."), |
2473 NULL); | 2495 NULL); |
2474 purple_cmd_register("buzz", "s", PURPLE_CMD_P_PRPL, | 2496 purple_cmd_register("buzz", "w", PURPLE_CMD_P_PRPL, |
2475 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, | 2497 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY | |
2498 PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, | |
2476 "prpl-jabber", jabber_cmd_buzz, | 2499 "prpl-jabber", jabber_cmd_buzz, |
2477 _("buzz: Buzz a user to get their attention"), NULL); | 2500 _("buzz: Buzz a user to get their attention"), NULL); |
2478 } | 2501 } |
2479 | 2502 |
2480 void | 2503 void |