comparison libpurple/protocols/jabber/usermood.c @ 17574:267f614152c4

Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
author Andreas Monitzer <pidgin@monitzer.com>
date Tue, 12 Jun 2007 23:43:06 +0000
parents 2f067d8fb19a
children 5fc8a8a25008
comparison
equal deleted inserted replaced
17573:2f067d8fb19a 17574:267f614152c4
19 * 19 *
20 */ 20 */
21 21
22 #include "usermood.h" 22 #include "usermood.h"
23 #include "pep.h" 23 #include "pep.h"
24 24 #include <assert.h>
25 #include <string.h> 25 #include <string.h>
26 #include "internal.h" 26 #include "internal.h"
27 27
28 static char *moodstrings[] = { 28 static char *moodstrings[] = {
29 "unknown",
30 "afraid", 29 "afraid",
31 "amazed", 30 "amazed",
32 "angry", 31 "angry",
33 "annoyed", 32 "annoyed",
34 "anxious", 33 "anxious",
92 }; 91 };
93 92
94 static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) { 93 static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) {
95 /* it doesn't make sense to have more than one item here, so let's just pick the first one */ 94 /* it doesn't make sense to have more than one item here, so let's just pick the first one */
96 xmlnode *item = xmlnode_get_child(items, "item"); 95 xmlnode *item = xmlnode_get_child(items, "item");
97 JabberMood newmood = UNKNOWN; 96 char *newmood;
98 char *moodtext = NULL; 97 char *moodtext = NULL;
99 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); 98 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE);
100 xmlnode *moodinfo, *mood; 99 xmlnode *moodinfo, *mood;
101 /* ignore the mood of people not on our buddy list */ 100 /* ignore the mood of people not on our buddy list */
102 if (!buddy || !item) 101 if (!buddy || !item)
110 if (!strcmp(moodinfo->name, "text")) { 109 if (!strcmp(moodinfo->name, "text")) {
111 if (!moodtext) /* only pick the first one */ 110 if (!moodtext) /* only pick the first one */
112 moodtext = xmlnode_get_data(moodinfo); 111 moodtext = xmlnode_get_data(moodinfo);
113 } else { 112 } else {
114 int i; 113 int i;
115 for (i = 1; moodstrings[i]; ++i) { 114 for (i = 0; moodstrings[i]; ++i) {
115 /* verify that the mood is known (valid) */
116 if (!strcmp(moodinfo->name, moodstrings[i])) { 116 if (!strcmp(moodinfo->name, moodstrings[i])) {
117 newmood = (JabberMood)i; 117 newmood = moodstrings[i];
118 break; 118 break;
119 } 119 }
120 } 120 }
121 } 121 }
122 if (newmood != UNKNOWN && moodtext != NULL) 122 if (newmood != NULL && moodtext != NULL)
123 break; 123 break;
124 } 124 }
125 } 125 }
126 if (newmood != UNKNOWN) { 126 if (newmood != NULL) {
127 JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); 127 JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL);
128 const char *status_id = jabber_buddy_state_get_status_id(resource->state); 128 const char *status_id = jabber_buddy_state_get_status_id(resource->state);
129 129
130 purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", _(moodstrings[newmood]), "moodtext", moodtext?moodtext:"", NULL); 130 purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", _(newmood), "moodtext", moodtext?moodtext:"", NULL);
131 } 131 }
132 if (moodtext) 132 if (moodtext)
133 g_free(moodtext); 133 g_free(moodtext);
134 } 134 }
135 135
136 void jabber_mood_init(void) { 136 void jabber_mood_init(void) {
137 jabber_add_feature("mood", "http://jabber.org/protocol/mood"); 137 jabber_add_feature("mood", "http://jabber.org/protocol/mood");
138 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); 138 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb);
139 } 139 }
140 140
141 void jabber_set_mood(JabberStream *js, JabberMood mood, const char *text) { 141 void jabber_set_mood(JabberStream *js, const char *mood, const char *text) {
142 xmlnode *publish, *moodnode; 142 xmlnode *publish, *moodnode;
143 if (mood == UNKNOWN) 143
144 return; 144 assert(mood != NULL);
145 145
146 publish = xmlnode_new("publish"); 146 publish = xmlnode_new("publish");
147 xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood"); 147 xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood");
148 moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood"); 148 moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood");
149 xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood"); 149 xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood");
150 xmlnode_new_child(moodnode, moodstrings[mood]); 150 xmlnode_new_child(moodnode, mood);
151 151
152 if (text) { 152 if (text) {
153 xmlnode *textnode = xmlnode_new_child(moodnode, "text"); 153 xmlnode *textnode = xmlnode_new_child(moodnode, "text");
154 xmlnode_insert_data(textnode, text, -1); 154 xmlnode_insert_data(textnode, text, -1);
155 } 155 }