Mercurial > pidgin
comparison libpurple/protocols/jabber/usermood.c @ 17845:2e0799b916b9
Fixed whitespace to match the coding convention used in libpurple
author | Andreas Monitzer <pidgin@monitzer.com> |
---|---|
date | Tue, 12 Jun 2007 01:25:46 +0000 |
parents | 2f23a77eaa04 |
children | 2f067d8fb19a |
comparison
equal
deleted
inserted
replaced
17844:2f23a77eaa04 | 17845:2e0799b916b9 |
---|---|
8 * the Free Software Foundation; either version 2 of the License, or | 8 * the Free Software Foundation; either version 2 of the License, or |
9 * (at your option) any later version. | 9 * (at your option) any later version. |
10 * | 10 * |
11 * This program is distributed in the hope that it will be useful, | 11 * This program is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 * GNU General Public License for more details. | 14 * GNU General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU General Public License | 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 | 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 | 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 * | 19 * |
20 */ | 20 */ |
21 | 21 |
22 #include "usermood.h" | 22 #include "usermood.h" |
23 #include "pep.h" | 23 #include "pep.h" |
24 | 24 |
25 #include <string.h> | 25 #include <string.h> |
26 | 26 |
27 static char *moodstrings[] = { | 27 static char *moodstrings[] = { |
28 "unknown", | 28 "unknown", |
29 "afraid", | 29 "afraid", |
30 "amazed", | 30 "amazed", |
31 "angry", | 31 "angry", |
32 "annoyed", | 32 "annoyed", |
33 "anxious", | 33 "anxious", |
34 "aroused", | 34 "aroused", |
35 "ashamed", | 35 "ashamed", |
36 "bored", | 36 "bored", |
37 "brave", | 37 "brave", |
38 "calm", | 38 "calm", |
39 "cold", | 39 "cold", |
40 "confused", | 40 "confused", |
41 "contented", | 41 "contented", |
42 "cranky", | 42 "cranky", |
43 "curious", | 43 "curious", |
44 "depressed", | 44 "depressed", |
45 "disappointed", | 45 "disappointed", |
46 "disgusted", | 46 "disgusted", |
47 "distracted", | 47 "distracted", |
48 "embarrassed", | 48 "embarrassed", |
49 "excited", | 49 "excited", |
50 "flirtatious", | 50 "flirtatious", |
51 "frustrated", | 51 "frustrated", |
52 "grumpy", | 52 "grumpy", |
53 "guilty", | 53 "guilty", |
54 "happy", | 54 "happy", |
55 "hot", | 55 "hot", |
56 "humbled", | 56 "humbled", |
57 "humiliated", | 57 "humiliated", |
58 "hungry", | 58 "hungry", |
59 "hurt", | 59 "hurt", |
60 "impressed", | 60 "impressed", |
61 "in_awe", | 61 "in_awe", |
62 "in_love", | 62 "in_love", |
63 "indignant", | 63 "indignant", |
64 "interested", | 64 "interested", |
65 "intoxicated", | 65 "intoxicated", |
66 "invincible", | 66 "invincible", |
67 "jealous", | 67 "jealous", |
68 "lonely", | 68 "lonely", |
69 "mean", | 69 "mean", |
70 "moody", | 70 "moody", |
71 "nervous", | 71 "nervous", |
72 "neutral", | 72 "neutral", |
73 "offended", | 73 "offended", |
74 "playful", | 74 "playful", |
75 "proud", | 75 "proud", |
76 "relieved", | 76 "relieved", |
77 "remorseful", | 77 "remorseful", |
78 "restless", | 78 "restless", |
79 "sad", | 79 "sad", |
80 "sarcastic", | 80 "sarcastic", |
81 "serious", | 81 "serious", |
82 "shocked", | 82 "shocked", |
83 "shy", | 83 "shy", |
84 "sick", | 84 "sick", |
85 "sleepy", | 85 "sleepy", |
86 "stressed", | 86 "stressed", |
87 "surprised", | 87 "surprised", |
88 "thirsty", | 88 "thirsty", |
89 "worried", | 89 "worried", |
90 NULL | 90 NULL |
91 }; | 91 }; |
92 | 92 |
93 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) { |
94 /* 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 */ |
95 xmlnode *item = xmlnode_get_child(items, "item"); | 95 xmlnode *item = xmlnode_get_child(items, "item"); |
96 JabberMood newmood = UNKNOWN; | 96 JabberMood newmood = UNKNOWN; |
97 char *moodtext = NULL; | 97 char *moodtext = NULL; |
98 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); | 98 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); |
99 xmlnode *moodinfo, *mood; | 99 xmlnode *moodinfo, *mood; |
100 /* ignore the mood of people not on our buddy list */ | 100 /* ignore the mood of people not on our buddy list */ |
101 if (!buddy || !item) | 101 if (!buddy || !item) |
102 return; | 102 return; |
103 | 103 |
104 mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood"); | 104 mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood"); |
105 if (!mood) | 105 if (!mood) |
106 return; | 106 return; |
107 for (moodinfo = mood->child; moodinfo != mood->lastchild; moodinfo = moodinfo->next) { | 107 for (moodinfo = mood->child; moodinfo != mood->lastchild; moodinfo = moodinfo->next) { |
108 if (moodinfo->type == XMLNODE_TYPE_TAG) { | 108 if (moodinfo->type == XMLNODE_TYPE_TAG) { |
109 if (!strcmp(moodinfo->name, "text")) { | 109 if (!strcmp(moodinfo->name, "text")) { |
110 if (!moodtext) /* only pick the first one */ | 110 if (!moodtext) /* only pick the first one */ |
111 moodtext = xmlnode_get_data(moodinfo); | 111 moodtext = xmlnode_get_data(moodinfo); |
112 } else { | 112 } else { |
113 int i; | 113 int i; |
114 for (i = 1; moodstrings[i]; ++i) { | 114 for (i = 1; moodstrings[i]; ++i) { |
115 if (!strcmp(moodinfo->name, moodstrings[i])) { | 115 if (!strcmp(moodinfo->name, moodstrings[i])) { |
116 newmood = (JabberMood)i; | 116 newmood = (JabberMood)i; |
117 break; | 117 break; |
118 } | 118 } |
119 } | 119 } |
120 } | 120 } |
121 if (newmood != UNKNOWN && moodtext != NULL) | 121 if (newmood != UNKNOWN && moodtext != NULL) |
122 break; | 122 break; |
123 } | 123 } |
124 } | 124 } |
125 if (newmood != UNKNOWN) { | 125 if (newmood != UNKNOWN) { |
126 JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); | 126 JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); |
127 const char *status_id = jabber_buddy_state_get_status_id(resource->state); | 127 const char *status_id = jabber_buddy_state_get_status_id(resource->state); |
128 | 128 |
129 purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", newmood, "moodtext", moodtext?moodtext:"", NULL); | 129 purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", newmood, "moodtext", moodtext?moodtext:"", NULL); |
130 } | 130 } |
131 if (moodtext) | 131 if (moodtext) |
132 g_free(moodtext); | 132 g_free(moodtext); |
133 } | 133 } |
134 | 134 |
135 void jabber_mood_init(void) { | 135 void jabber_mood_init(void) { |
136 jabber_add_feature("mood", "http://jabber.org/protocol/mood"); | 136 jabber_add_feature("mood", "http://jabber.org/protocol/mood"); |
137 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); | 137 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); |
138 } | 138 } |
139 | 139 |
140 void jabber_set_mood(JabberStream *js, JabberMood mood, const char *text) { | 140 void jabber_set_mood(JabberStream *js, JabberMood mood, const char *text) { |
141 xmlnode *publish, *moodnode; | 141 xmlnode *publish, *moodnode; |
142 if (mood == UNKNOWN) | 142 if (mood == UNKNOWN) |
143 return; | 143 return; |
144 | 144 |
145 publish = xmlnode_new("publish"); | 145 publish = xmlnode_new("publish"); |
146 xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood"); | 146 xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood"); |
147 moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood"); | 147 moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood"); |
148 xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood"); | 148 xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood"); |
149 xmlnode_new_child(moodnode, moodstrings[mood]); | 149 xmlnode_new_child(moodnode, moodstrings[mood]); |
150 | 150 |
151 if (text) { | 151 if (text) { |
152 xmlnode *textnode = xmlnode_new_child(moodnode, "text"); | 152 xmlnode *textnode = xmlnode_new_child(moodnode, "text"); |
153 xmlnode_insert_data(textnode, text, -1); | 153 xmlnode_insert_data(textnode, text, -1); |
154 } | 154 } |
155 | 155 |
156 jabber_pep_publish(js, publish); | 156 jabber_pep_publish(js, publish); |
157 | 157 |
158 xmlnode_free(publish); | 158 xmlnode_free(publish); |
159 } | 159 } |