comparison libpurple/protocols/jabber/usermood.c @ 29835:086b26f60913

Convert XMPP to use an array of PurpleMoods internally.
author Richard Laager <rlaager@wiktel.com>
date Mon, 17 Nov 2008 08:00:25 +0000
parents 1fb503adb2ae
children 5391094529c6
comparison
equal deleted inserted replaced
29834:1fb503adb2ae 29835:086b26f60913
26 #include <string.h> 26 #include <string.h>
27 #include "internal.h" 27 #include "internal.h"
28 #include "request.h" 28 #include "request.h"
29 #include "debug.h" 29 #include "debug.h"
30 30
31 static const char * const moodstrings[] = { 31 static PurpleMood moods[] = {
32 "afraid", 32 {"afraid", N_("Afraid"), NULL},
33 "amazed", 33 {"amazed", N_("Amazed"), NULL},
34 "amorous", 34 {"amorous", N_("Amorous"), NULL},
35 "angry", 35 {"angry", N_("Angry"), NULL},
36 "annoyed", 36 {"annoyed", N_("Annoyed"), NULL},
37 "anxious", 37 {"anxious", N_("Anxious"), NULL},
38 "aroused", 38 {"aroused", N_("Aroused"), NULL},
39 "ashamed", 39 {"ashamed", N_("Ashamed"), NULL},
40 "bored", 40 {"bored", N_("Bored"), NULL},
41 "brave", 41 {"brave", N_("Brave"), NULL},
42 "calm", 42 {"calm", N_("Calm"), NULL},
43 "cautious", 43 {"cautious", N_("Cautious"), NULL},
44 "cold", 44 {"cold", N_("Cold"), NULL},
45 "confident", 45 {"confident", N_("Confident"), NULL},
46 "confused", 46 {"confused", N_("Confused"), NULL},
47 "contemplative", 47 {"contemplative", N_("Contemplative"), NULL},
48 "contented", 48 {"contented", N_("Contented"), NULL},
49 "cranky", 49 {"cranky", N_("Cranky"), NULL},
50 "crazy", 50 {"crazy", N_("Crazy"), NULL},
51 "creative", 51 {"creative", N_("Creative"), NULL},
52 "curious", 52 {"curious", N_("Curious"), NULL},
53 "dejected", 53 {"dejected", N_("Dejected"), NULL},
54 "depressed", 54 {"depressed", N_("Depressed"), NULL},
55 "disappointed", 55 {"disappointed", N_("Disappointed"), NULL},
56 "disgusted", 56 {"disgusted", N_("Disgusted"), NULL},
57 "dismayed", 57 {"dismayed", N_("Dismayed"), NULL},
58 "distracted", 58 {"distracted", N_("Distracted"), NULL},
59 "embarrassed", 59 {"embarrassed", N_("Embarrassed"), NULL},
60 "envious", 60 {"envious", N_("Envious"), NULL},
61 "excited", 61 {"excited", N_("Excited"), NULL},
62 "flirtatious", 62 {"flirtatious", N_("Flirtatious"), NULL},
63 "frustrated", 63 {"frustrated", N_("Frustrated"), NULL},
64 "grateful", 64 {"grateful", N_("Grateful"), NULL},
65 "grieving", 65 {"grieving", N_("Grieving"), NULL},
66 "grumpy", 66 {"grumpy", N_("Grumpy"), NULL},
67 "guilty", 67 {"guilty", N_("Guilty"), NULL},
68 "happy", 68 {"happy", N_("Happy"), NULL},
69 "hopeful", 69 {"hopeful", N_("Hopeful"), NULL},
70 "hot", 70 {"hot", N_("Hot"), NULL},
71 "humbled", 71 {"humbled", N_("Humbled"), NULL},
72 "humiliated", 72 {"humiliated", N_("Humiliated"), NULL},
73 "hungry", 73 {"hungry", N_("Hungry"), NULL},
74 "hurt", 74 {"hurt", N_("Hurt"), NULL},
75 "impressed", 75 {"impressed", N_("Impressed"), NULL},
76 "in_awe", 76 {"in_awe", N_("In_awe"), NULL},
77 "in_love", 77 {"in_love", N_("In_love"), NULL},
78 "indignant", 78 {"indignant", N_("Indignant"), NULL},
79 "interested", 79 {"interested", N_("Interested"), NULL},
80 "intoxicated", 80 {"intoxicated", N_("Intoxicated"), NULL},
81 "invincible", 81 {"invincible", N_("Invincible"), NULL},
82 "jealous", 82 {"jealous", N_("Jealous"), NULL},
83 "lonely", 83 {"lonely", N_("Lonely"), NULL},
84 "lost", 84 {"lost", N_("Lost"), NULL},
85 "lucky", 85 {"lucky", N_("Lucky"), NULL},
86 "mean", 86 {"mean", N_("Mean"), NULL},
87 "moody", 87 {"moody", N_("Moody"), NULL},
88 "nervous", 88 {"nervous", N_("Nervous"), NULL},
89 "neutral", 89 {"neutral", N_("Neutral"), NULL},
90 "offended", 90 {"offended", N_("Offended"), NULL},
91 "outraged", 91 {"outraged", N_("Outraged"), NULL},
92 "playful", 92 {"playful", N_("Playful"), NULL},
93 "proud", 93 {"proud", N_("Proud"), NULL},
94 "relaxed", 94 {"relaxed", N_("Relaxed"), NULL},
95 "relieved", 95 {"relieved", N_("Relieved"), NULL},
96 "remorseful", 96 {"remorseful", N_("Remorseful"), NULL},
97 "restless", 97 {"restless", N_("Restless"), NULL},
98 "sad", 98 {"sad", N_("Sad"), NULL},
99 "sarcastic", 99 {"sarcastic", N_("Sarcastic"), NULL},
100 "satisfied", 100 {"satisfied", N_("Satisfied"), NULL},
101 "serious", 101 {"serious", N_("Serious"), NULL},
102 "shocked", 102 {"shocked", N_("Shocked"), NULL},
103 "shy", 103 {"shy", N_("Shy"), NULL},
104 "sick", 104 {"sick", N_("Sick"), NULL},
105 "sleepy", 105 {"sleepy", N_("Sleepy"), NULL},
106 "spontaneous", 106 {"spontaneous", N_("Spontaneous"), NULL},
107 "stressed", 107 {"stressed", N_("Stressed"), NULL},
108 "strong", 108 {"strong", N_("Strong"), NULL},
109 "surprised", 109 {"surprised", N_("Surprised"), NULL},
110 "thankful", 110 {"thankful", N_("Thankful"), NULL},
111 "thirsty", 111 {"thirsty", N_("Thirsty"), NULL},
112 "tired", 112 {"tired", N_("Tired"), NULL},
113 "undefined", 113 {"undefined", N_("Undefined"), NULL},
114 "weak", 114 {"weak", N_("Weak"), NULL},
115 "worried", 115 {"worried", N_("Worried"), NULL},
116 NULL 116 /* Mark the last record. */
117 {NULL, NULL, NULL}
117 }; 118 };
118 119
119 static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) { 120 static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) {
120 /* it doesn't make sense to have more than one item here, so let's just pick the first one */ 121 /* it doesn't make sense to have more than one item here, so let's just pick the first one */
121 xmlnode *item = xmlnode_get_child(items, "item"); 122 xmlnode *item = xmlnode_get_child(items, "item");
135 if (!strcmp(moodinfo->name, "text")) { 136 if (!strcmp(moodinfo->name, "text")) {
136 if (!moodtext) /* only pick the first one */ 137 if (!moodtext) /* only pick the first one */
137 moodtext = xmlnode_get_data(moodinfo); 138 moodtext = xmlnode_get_data(moodinfo);
138 } else { 139 } else {
139 int i; 140 int i;
140 for (i = 0; moodstrings[i]; ++i) { 141 for (i = 0; moods[i].mood; ++i) {
141 /* verify that the mood is known (valid) */ 142 /* verify that the mood is known (valid) */
142 if (!strcmp(moodinfo->name, moodstrings[i])) { 143 if (!strcmp(moodinfo->name, moods[i].mood)) {
143 newmood = moodstrings[i]; 144 newmood = moods[i].mood;
144 break; 145 break;
145 } 146 }
146 } 147 }
147 } 148 }
148 if (newmood != NULL && moodtext != NULL) 149 if (newmood != NULL && moodtext != NULL)
165 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); 166 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb);
166 } 167 }
167 168
168 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) { 169 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) {
169 JabberStream *js; 170 JabberStream *js;
170 const int max_mood_idx = sizeof(moodstrings) / sizeof(moodstrings[0]) - 1; 171 const int max_mood_idx = sizeof(moods) / sizeof(moods[0]) - 1;
171 int selected_mood = purple_request_fields_get_choice(fields, "mood"); 172 int selected_mood = purple_request_fields_get_choice(fields, "mood");
172 173
173 if (!PURPLE_CONNECTION_IS_VALID(gc)) { 174 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
174 purple_debug_error("jabber", "Unable to set mood; account offline.\n"); 175 purple_debug_error("jabber", "Unable to set mood; account offline.\n");
175 return; 176 return;
180 if (selected_mood < 0 || selected_mood >= max_mood_idx) { 181 if (selected_mood < 0 || selected_mood >= max_mood_idx) {
181 purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood); 182 purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood);
182 return; 183 return;
183 } 184 }
184 185
185 jabber_mood_set(js, moodstrings[selected_mood], purple_request_fields_get_string(fields, "text")); 186 jabber_mood_set(js, moods[selected_mood].mood, purple_request_fields_get_string(fields, "text"));
186 } 187 }
187 188
188 static void do_mood_set_mood(PurplePluginAction *action) { 189 static void do_mood_set_mood(PurplePluginAction *action) {
189 PurpleConnection *gc = (PurpleConnection *) action->context; 190 PurpleConnection *gc = (PurpleConnection *) action->context;
190 191
198 purple_request_fields_add_group(fields, group); 199 purple_request_fields_add_group(fields, group);
199 200
200 field = purple_request_field_choice_new("mood", 201 field = purple_request_field_choice_new("mood",
201 _("Mood"), 0); 202 _("Mood"), 0);
202 203
203 for(i = 0; moodstrings[i]; ++i) 204 for(i = 0; moods[i].mood; ++i)
204 purple_request_field_choice_add(field, _(moodstrings[i])); 205 purple_request_field_choice_add(field, _(moods[i].description));
205 206
206 purple_request_field_set_required(field, TRUE); 207 purple_request_field_set_required(field, TRUE);
207 purple_request_field_group_add_field(group, field); 208 purple_request_field_group_add_field(group, field);
208 209
209 field = purple_request_field_string_new("text", 210 field = purple_request_field_string_new("text",