comparison libpurple/protocols/jabber/usermood.c @ 17850:2e41e74dabd0

Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
author Andreas Monitzer <pidgin@monitzer.com>
date Fri, 15 Jun 2007 07:44:05 +0000
parents e49b259fc7dd
children 460b4bf797e7
comparison
equal deleted inserted replaced
17849:e49b259fc7dd 17850:2e41e74dabd0
22 #include "usermood.h" 22 #include "usermood.h"
23 #include "pep.h" 23 #include "pep.h"
24 #include <assert.h> 24 #include <assert.h>
25 #include <string.h> 25 #include <string.h>
26 #include "internal.h" 26 #include "internal.h"
27 #include "request.h"
27 28
28 static char *moodstrings[] = { 29 static char *moodstrings[] = {
29 "afraid", 30 "afraid",
30 "amazed", 31 "amazed",
31 "angry", 32 "angry",
132 if (moodtext) 133 if (moodtext)
133 g_free(moodtext); 134 g_free(moodtext);
134 } 135 }
135 136
136 static gboolean is_mood_supported(JabberStream *js, const gchar *shortname, const gchar *namespace) { 137 static gboolean is_mood_supported(JabberStream *js, const gchar *shortname, const gchar *namespace) {
137 purple_debug_info("jabber", "is_mood_supported: have pep: %s\n", js->pep?"YES":"NO");
138 return js->pep; 138 return js->pep;
139 } 139 }
140 140
141 void jabber_mood_init(void) { 141 void jabber_mood_init(void) {
142 jabber_add_feature("mood", "http://jabber.org/protocol/mood", is_mood_supported); 142 jabber_add_feature("mood", "http://jabber.org/protocol/mood", is_mood_supported);
143 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); 143 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb);
144 } 144 }
145 145
146 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) {
147 JabberStream *js = gc->proto_data;
148
149 jabber_mood_set(js, moodstrings[purple_request_fields_get_choice(fields, "mood")], purple_request_fields_get_string(fields, "text"));
150 }
151
146 static void do_mood_set_mood(PurplePluginAction *action) { 152 static void do_mood_set_mood(PurplePluginAction *action) {
153 PurpleConnection *gc = (PurpleConnection *) action->context;
154
155 PurpleRequestFields *fields;
156 PurpleRequestFieldGroup *group;
157 PurpleRequestField *field;
158 int i;
159
160 fields = purple_request_fields_new();
161 group = purple_request_field_group_new(NULL);
162 purple_request_fields_add_group(fields, group);
163
164 field = purple_request_field_choice_new("mood",
165 _("Mood"), 0);
166
167 for(i = 0; moodstrings[i]; ++i)
168 purple_request_field_choice_add(field, _(moodstrings[i]));
169
170 purple_request_field_set_required(field, TRUE);
171 purple_request_field_group_add_field(group, field);
172
173 field = purple_request_field_string_new("text",
174 _("Description"), NULL,
175 FALSE);
176 purple_request_field_group_add_field(group, field);
177
178 purple_request_fields(gc, _("Edit User Mood"),
179 _("Edit User Mood"),
180 _("Please select your mood from the list."),
181 fields,
182 _("Set"), G_CALLBACK(do_mood_set_from_fields),
183 _("Cancel"), NULL,
184 purple_connection_get_account(gc), NULL, NULL,
185 gc);
147 186
148 } 187 }
149 188
150 void jabber_mood_init_action(GList **m) { 189 void jabber_mood_init_action(GList **m) {
151 PurplePluginAction *act = purple_plugin_action_new(_("Set Mood..."), do_mood_set_mood); 190 PurplePluginAction *act = purple_plugin_action_new(_("Set Mood..."), do_mood_set_mood);
152 *m = g_list_append(*m, act); 191 *m = g_list_append(*m, act);
153 } 192 }
154 193
155 void jabber_set_mood(JabberStream *js, const char *mood, const char *text) { 194 void jabber_mood_set(JabberStream *js, const char *mood, const char *text) {
156 xmlnode *publish, *moodnode; 195 xmlnode *publish, *moodnode;
157 196
158 assert(mood != NULL); 197 assert(mood != NULL);
159 198
160 publish = xmlnode_new("publish"); 199 publish = xmlnode_new("publish");