Mercurial > pidgin
comparison libpurple/protocols/jabber/usermood.c @ 29458:a538cb73f897
propagate from branch 'im.pidgin.pidgin' (head b0098e2250f135d121960d8152e144e7e344125e)
to branch 'im.pidgin.cpw.rekkanoryo.icqxstatus' (head dcd3ab65d5cfcd79b00a7b95ab5fe788da64c112)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Sun, 07 Feb 2010 19:31:56 +0000 |
parents | ecca39fe50d7 5391094529c6 |
children | f3654983e1da |
comparison
equal
deleted
inserted
replaced
28982:791606778223 | 29458:a538cb73f897 |
---|---|
28 #include <string.h> | 28 #include <string.h> |
29 #include "internal.h" | 29 #include "internal.h" |
30 #include "request.h" | 30 #include "request.h" |
31 #include "debug.h" | 31 #include "debug.h" |
32 | 32 |
33 static const char * const moodstrings[] = { | 33 static PurpleMood moods[] = { |
34 "afraid", | 34 {"afraid", N_("Afraid"), NULL}, |
35 "amazed", | 35 {"amazed", N_("Amazed"), NULL}, |
36 "amorous", | 36 {"amorous", N_("Amorous"), NULL}, |
37 "angry", | 37 {"angry", N_("Angry"), NULL}, |
38 "annoyed", | 38 {"annoyed", N_("Annoyed"), NULL}, |
39 "anxious", | 39 {"anxious", N_("Anxious"), NULL}, |
40 "aroused", | 40 {"aroused", N_("Aroused"), NULL}, |
41 "ashamed", | 41 {"ashamed", N_("Ashamed"), NULL}, |
42 "bored", | 42 {"bored", N_("Bored"), NULL}, |
43 "brave", | 43 {"brave", N_("Brave"), NULL}, |
44 "calm", | 44 {"calm", N_("Calm"), NULL}, |
45 "cautious", | 45 {"cautious", N_("Cautious"), NULL}, |
46 "cold", | 46 {"cold", N_("Cold"), NULL}, |
47 "confident", | 47 {"confident", N_("Confident"), NULL}, |
48 "confused", | 48 {"confused", N_("Confused"), NULL}, |
49 "contemplative", | 49 {"contemplative", N_("Contemplative"), NULL}, |
50 "contented", | 50 {"contented", N_("Contented"), NULL}, |
51 "cranky", | 51 {"cranky", N_("Cranky"), NULL}, |
52 "crazy", | 52 {"crazy", N_("Crazy"), NULL}, |
53 "creative", | 53 {"creative", N_("Creative"), NULL}, |
54 "curious", | 54 {"curious", N_("Curious"), NULL}, |
55 "dejected", | 55 {"dejected", N_("Dejected"), NULL}, |
56 "depressed", | 56 {"depressed", N_("Depressed"), NULL}, |
57 "disappointed", | 57 {"disappointed", N_("Disappointed"), NULL}, |
58 "disgusted", | 58 {"disgusted", N_("Disgusted"), NULL}, |
59 "dismayed", | 59 {"dismayed", N_("Dismayed"), NULL}, |
60 "distracted", | 60 {"distracted", N_("Distracted"), NULL}, |
61 "embarrassed", | 61 {"embarrassed", N_("Embarrassed"), NULL}, |
62 "envious", | 62 {"envious", N_("Envious"), NULL}, |
63 "excited", | 63 {"excited", N_("Excited"), NULL}, |
64 "flirtatious", | 64 {"flirtatious", N_("Flirtatious"), NULL}, |
65 "frustrated", | 65 {"frustrated", N_("Frustrated"), NULL}, |
66 "grumpy", | 66 {"grateful", N_("Grateful"), NULL}, |
67 "guilty", | 67 {"grieving", N_("Grieving"), NULL}, |
68 "happy", | 68 {"grumpy", N_("Grumpy"), NULL}, |
69 "hopeful", | 69 {"guilty", N_("Guilty"), NULL}, |
70 "hot", | 70 {"happy", N_("Happy"), NULL}, |
71 "humbled", | 71 {"hopeful", N_("Hopeful"), NULL}, |
72 "humiliated", | 72 {"hot", N_("Hot"), NULL}, |
73 "hungry", | 73 {"humbled", N_("Humbled"), NULL}, |
74 "hurt", | 74 {"humiliated", N_("Humiliated"), NULL}, |
75 "impressed", | 75 {"hungry", N_("Hungry"), NULL}, |
76 "in_awe", | 76 {"hurt", N_("Hurt"), NULL}, |
77 "in_love", | 77 {"impressed", N_("Impressed"), NULL}, |
78 "indignant", | 78 {"in_awe", N_("In_awe"), NULL}, |
79 "interested", | 79 {"in_love", N_("In_love"), NULL}, |
80 "intoxicated", | 80 {"indignant", N_("Indignant"), NULL}, |
81 "invincible", | 81 {"interested", N_("Interested"), NULL}, |
82 "jealous", | 82 {"intoxicated", N_("Intoxicated"), NULL}, |
83 "lonely", | 83 {"invincible", N_("Invincible"), NULL}, |
84 "lucky", | 84 {"jealous", N_("Jealous"), NULL}, |
85 "mean", | 85 {"lonely", N_("Lonely"), NULL}, |
86 "moody", | 86 {"lost", N_("Lost"), NULL}, |
87 "nervous", | 87 {"lucky", N_("Lucky"), NULL}, |
88 "neutral", | 88 {"mean", N_("Mean"), NULL}, |
89 "offended", | 89 {"moody", N_("Moody"), NULL}, |
90 "outraged", | 90 {"nervous", N_("Nervous"), NULL}, |
91 "playful", | 91 {"neutral", N_("Neutral"), NULL}, |
92 "proud", | 92 {"offended", N_("Offended"), NULL}, |
93 "relaxed", | 93 {"outraged", N_("Outraged"), NULL}, |
94 "relieved", | 94 {"playful", N_("Playful"), NULL}, |
95 "remorseful", | 95 {"proud", N_("Proud"), NULL}, |
96 "restless", | 96 {"relaxed", N_("Relaxed"), NULL}, |
97 "sad", | 97 {"relieved", N_("Relieved"), NULL}, |
98 "sarcastic", | 98 {"remorseful", N_("Remorseful"), NULL}, |
99 "serious", | 99 {"restless", N_("Restless"), NULL}, |
100 "shocked", | 100 {"sad", N_("Sad"), NULL}, |
101 "shy", | 101 {"sarcastic", N_("Sarcastic"), NULL}, |
102 "sick", | 102 {"satisfied", N_("Satisfied"), NULL}, |
103 "sleepy", | 103 {"serious", N_("Serious"), NULL}, |
104 "spontaneous", | 104 {"shocked", N_("Shocked"), NULL}, |
105 "stressed", | 105 {"shy", N_("Shy"), NULL}, |
106 "strong", | 106 {"sick", N_("Sick"), NULL}, |
107 "surprised", | 107 {"sleepy", N_("Sleepy"), NULL}, |
108 "thankful", | 108 {"spontaneous", N_("Spontaneous"), NULL}, |
109 "thirsty", | 109 {"stressed", N_("Stressed"), NULL}, |
110 "tired", | 110 {"strong", N_("Strong"), NULL}, |
111 "weak", | 111 {"surprised", N_("Surprised"), NULL}, |
112 "worried" | 112 {"thankful", N_("Thankful"), NULL}, |
113 {"thirsty", N_("Thirsty"), NULL}, | |
114 {"tired", N_("Tired"), NULL}, | |
115 {"undefined", N_("Undefined"), NULL}, | |
116 {"weak", N_("Weak"), NULL}, | |
117 {"worried", N_("Worried"), NULL}, | |
118 /* Mark the last record. */ | |
119 {NULL, NULL, NULL} | |
113 }; | 120 }; |
114 | 121 |
115 static void | 122 static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) { |
116 jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) | 123 /* it doesn't make sense to have more than one item here, so let's just pick the first one */ |
117 { | 124 xmlnode *item = xmlnode_get_child(items, "item"); |
118 xmlnode *item; | |
119 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); | |
120 const char *newmood = NULL; | 125 const char *newmood = NULL; |
121 char *moodtext = NULL; | 126 char *moodtext = NULL; |
122 xmlnode *child, *mood; | 127 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); |
123 | 128 xmlnode *moodinfo, *mood; |
124 /* it doesn't make sense to have more than one item here, so let's just pick the first one */ | |
125 item = xmlnode_get_child(items, "item"); | |
126 | |
127 /* ignore the mood of people not on our buddy list */ | 129 /* ignore the mood of people not on our buddy list */ |
128 if (!buddy || !item) | 130 if (!buddy || !item) |
129 return; | 131 return; |
130 | 132 |
131 mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood"); | 133 mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood"); |
132 if (!mood) | 134 if (!mood) |
133 return; | 135 return; |
134 for (child = mood->child; child; child = child->next) { | 136 for (moodinfo = mood->child; moodinfo; moodinfo = moodinfo->next) { |
135 if (child->type != XMLNODE_TYPE_TAG) | 137 if (moodinfo->type == XMLNODE_TYPE_TAG) { |
136 continue; | 138 if (!strcmp(moodinfo->name, "text")) { |
137 | 139 if (!moodtext) /* only pick the first one */ |
138 if (g_str_equal("text", child->name) && moodtext == NULL) | 140 moodtext = xmlnode_get_data(moodinfo); |
139 moodtext = xmlnode_get_data(child); | 141 } else { |
140 else { | 142 int i; |
141 int i; | 143 for (i = 0; moods[i].mood; ++i) { |
142 for (i = 0; i < G_N_ELEMENTS(moodstrings); ++i) { | 144 /* verify that the mood is known (valid) */ |
143 /* verify that the mood is known (valid) */ | 145 if (!strcmp(moodinfo->name, moods[i].mood)) { |
144 if (g_str_equal(child->name, moodstrings[i])) { | 146 newmood = moods[i].mood; |
145 newmood = moodstrings[i]; | 147 break; |
146 break; | 148 } |
147 } | 149 } |
148 } | 150 } |
151 if (newmood != NULL && moodtext != NULL) | |
152 break; | |
149 } | 153 } |
150 if (newmood != NULL && moodtext != NULL) | 154 if (newmood != NULL && moodtext != NULL) |
151 break; | 155 break; |
152 } | 156 } |
153 if (newmood != NULL) { | 157 if (newmood != NULL) { |
154 PurpleAccount *account; | 158 purple_prpl_got_user_status(js->gc->account, from, "mood", |
155 const char *status_id; | 159 PURPLE_MOOD_NAME, mood, |
156 JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); | 160 PURPLE_MOOD_COMMENT, moodtext, |
157 if (!resource) { /* huh? */ | 161 NULL); |
158 g_free(moodtext); | 162 } else { |
159 return; | 163 purple_prpl_got_user_status_deactive(js->gc->account, from, "mood"); |
160 } | |
161 status_id = jabber_buddy_state_get_status_id(resource->state); | |
162 | |
163 account = purple_connection_get_account(js->gc); | |
164 purple_prpl_got_user_status(account, from, status_id, "mood", | |
165 _(newmood), "moodtext", | |
166 moodtext ? moodtext : "", NULL); | |
167 } | 164 } |
168 g_free(moodtext); | 165 g_free(moodtext); |
169 } | 166 } |
170 | 167 |
171 void jabber_mood_init(void) { | 168 void jabber_mood_init(void) { |
173 jabber_pep_register_handler("http://jabber.org/protocol/mood", jabber_mood_cb); | 170 jabber_pep_register_handler("http://jabber.org/protocol/mood", jabber_mood_cb); |
174 } | 171 } |
175 | 172 |
176 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) { | 173 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) { |
177 JabberStream *js; | 174 JabberStream *js; |
175 const int max_mood_idx = sizeof(moods) / sizeof(moods[0]) - 1; | |
178 int selected_mood = purple_request_fields_get_choice(fields, "mood"); | 176 int selected_mood = purple_request_fields_get_choice(fields, "mood"); |
179 | 177 |
180 if (!PURPLE_CONNECTION_IS_VALID(gc)) { | 178 if (!PURPLE_CONNECTION_IS_VALID(gc)) { |
181 purple_debug_error("jabber", "Unable to set mood; account offline.\n"); | 179 purple_debug_error("jabber", "Unable to set mood; account offline.\n"); |
182 return; | 180 return; |
183 } | 181 } |
184 | 182 |
185 js = gc->proto_data; | 183 js = gc->proto_data; |
186 | 184 |
187 if (selected_mood < 0 || selected_mood >= G_N_ELEMENTS(moodstrings)) { | 185 if (selected_mood < 0 || selected_mood >= max_mood_idx) { |
188 purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood); | 186 purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood); |
189 return; | 187 return; |
190 } | 188 } |
191 | 189 |
192 jabber_mood_set(js, moodstrings[selected_mood], purple_request_fields_get_string(fields, "text")); | 190 jabber_mood_set(js, moods[selected_mood].mood, purple_request_fields_get_string(fields, "text")); |
193 } | 191 } |
194 | 192 |
195 static void do_mood_set_mood(PurplePluginAction *action) { | 193 static void do_mood_set_mood(PurplePluginAction *action) { |
196 PurpleConnection *gc = (PurpleConnection *) action->context; | 194 PurpleConnection *gc = (PurpleConnection *) action->context; |
197 | 195 |
205 purple_request_fields_add_group(fields, group); | 203 purple_request_fields_add_group(fields, group); |
206 | 204 |
207 field = purple_request_field_choice_new("mood", | 205 field = purple_request_field_choice_new("mood", |
208 _("Mood"), 0); | 206 _("Mood"), 0); |
209 | 207 |
210 for(i = 0; i < G_N_ELEMENTS(moodstrings); ++i) | 208 for(i = 0; moods[i].mood; ++i) |
211 purple_request_field_choice_add(field, _(moodstrings[i])); | 209 purple_request_field_choice_add(field, _(moods[i].description)); |
212 | 210 |
213 purple_request_field_set_required(field, TRUE); | 211 purple_request_field_set_required(field, TRUE); |
214 purple_request_field_group_add_field(group, field); | 212 purple_request_field_group_add_field(group, field); |
215 | 213 |
216 field = purple_request_field_string_new("text", | 214 field = purple_request_field_string_new("text", |