Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/usernick.c @ 17597:5f4dcaf1f886
User Nickname now sets the buddy's server_alias, which means that no UI changes are required for supporting this XEP. Also forgot to add usernick.[hc].
author | Andreas Monitzer <pidgin@monitzer.com> |
---|---|
date | Mon, 18 Jun 2007 15:05:39 +0000 |
parents | |
children | d32ed28cf645 |
comparison
equal
deleted
inserted
replaced
17596:6842cc73b1b7 | 17597:5f4dcaf1f886 |
---|---|
1 /* | |
2 * purple - Jabber Protocol Plugin | |
3 * | |
4 * Copyright (C) 2007, Andreas Monitzer <andy@monitzer.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #include "usernick.h" | |
23 #include "pep.h" | |
24 #include <assert.h> | |
25 #include <string.h> | |
26 #include "internal.h" | |
27 #include "request.h" | |
28 #include "status.h" | |
29 | |
30 static void jabber_nick_cb(JabberStream *js, const char *from, xmlnode *items) { | |
31 /* it doesn't make sense to have more than one item here, so let's just pick the first one */ | |
32 xmlnode *item = xmlnode_get_child(items, "item"); | |
33 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); | |
34 xmlnode *nick; | |
35 const char *nickname = NULL; | |
36 | |
37 /* ignore the tune of people not on our buddy list */ | |
38 if (!buddy || !item) | |
39 return; | |
40 | |
41 nick = xmlnode_get_child_with_namespace(item, "nick", "http://jabber.org/protocol/nick"); | |
42 if (!nick) | |
43 return; | |
44 nickname = xmlnode_get_data(nick); | |
45 | |
46 serv_got_alias(js->gc, from, nickname); | |
47 } | |
48 | |
49 static void do_nick_set(JabberStream *js, const char *nick) { | |
50 xmlnode *publish, *nicknode; | |
51 | |
52 publish = xmlnode_new("publish"); | |
53 xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/nick"); | |
54 nicknode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "nick"); | |
55 xmlnode_set_namespace(nicknode, "http://jabber.org/protocol/nick"); | |
56 | |
57 if(nick && nick[0] != '\0') | |
58 xmlnode_insert_data(nicknode, nick, -1); | |
59 | |
60 jabber_pep_publish(js, publish); | |
61 /* publish is freed by jabber_pep_publish -> jabber_iq_send -> jabber_iq_free | |
62 (yay for well-defined memory management rules) */ | |
63 } | |
64 | |
65 static void do_nick_got_own_nick_cb(JabberStream *js, const char *from, xmlnode *items) { | |
66 const char *oldnickname = NULL; | |
67 xmlnode *item = xmlnode_get_child(items,"item"); | |
68 | |
69 if(item) { | |
70 xmlnode *nick = xmlnode_get_child_with_namespace(item,"nick","http://jabber.org/protocol/nick"); | |
71 if(nick) | |
72 oldnickname = xmlnode_get_data(nick); | |
73 } | |
74 | |
75 purple_request_input(js->gc, _("Set User Nickname"), _("Please specify a new nickname for you."), | |
76 _("This information is visible to all contacts on your contact list, so choose something appropriate."), | |
77 oldnickname, FALSE, FALSE, NULL, _("Set"), PURPLE_CALLBACK(do_nick_set), _("Cancel"), NULL, | |
78 purple_connection_get_account(js->gc), NULL, NULL, js); | |
79 } | |
80 | |
81 static void do_nick_set_nick(PurplePluginAction *action) { | |
82 PurpleConnection *gc = (PurpleConnection *) action->context; | |
83 JabberStream *js = gc->proto_data; | |
84 char *jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
85 | |
86 /* since the nickname might have been changed by another resource of this account, we always have to request the old one | |
87 from the server to present as the default for the new one */ | |
88 jabber_pep_request_item(js, jid, "http://jabber.org/protocol/nick", NULL, do_nick_got_own_nick_cb); | |
89 g_free(jid); | |
90 } | |
91 | |
92 void jabber_nick_init(void) { | |
93 jabber_add_feature("nick", "http://jabber.org/protocol/nick", jabber_pep_namespace_only_when_pep_enabled_cb); | |
94 jabber_pep_register_handler("nickn", "http://jabber.org/protocol/nick", jabber_nick_cb); | |
95 } | |
96 | |
97 void jabber_nick_init_action(GList **m) { | |
98 PurplePluginAction *act = purple_plugin_action_new(_("Set Nickname..."), do_nick_set_nick); | |
99 *m = g_list_append(*m, act); | |
100 } |