2 * purple - Jabber Protocol Plugin
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
33 static PurpleMood moods
[] = {
34 {"afraid", N_("Afraid"), NULL
},
35 {"amazed", N_("Amazed"), NULL
},
36 {"amorous", N_("Amorous"), NULL
},
37 {"angry", N_("Angry"), NULL
},
38 {"annoyed", N_("Annoyed"), NULL
},
39 {"anxious", N_("Anxious"), NULL
},
40 {"aroused", N_("Aroused"), NULL
},
41 {"ashamed", N_("Ashamed"), NULL
},
42 {"bored", N_("Bored"), NULL
},
43 {"brave", N_("Brave"), NULL
},
44 {"calm", N_("Calm"), NULL
},
45 {"cautious", N_("Cautious"), NULL
},
46 {"cold", N_("Cold"), NULL
},
47 {"confident", N_("Confident"), NULL
},
48 {"confused", N_("Confused"), NULL
},
49 {"contemplative", N_("Contemplative"), NULL
},
50 {"contented", N_("Contented"), NULL
},
51 {"cranky", N_("Cranky"), NULL
},
52 {"crazy", N_("Crazy"), NULL
},
53 {"creative", N_("Creative"), NULL
},
54 {"curious", N_("Curious"), NULL
},
55 {"dejected", N_("Dejected"), NULL
},
56 {"depressed", N_("Depressed"), NULL
},
57 {"disappointed", N_("Disappointed"), NULL
},
58 {"disgusted", N_("Disgusted"), NULL
},
59 {"dismayed", N_("Dismayed"), NULL
},
60 {"distracted", N_("Distracted"), NULL
},
61 {"embarrassed", N_("Embarrassed"), NULL
},
62 {"envious", N_("Envious"), NULL
},
63 {"excited", N_("Excited"), NULL
},
64 {"flirtatious", N_("Flirtatious"), NULL
},
65 {"frustrated", N_("Frustrated"), NULL
},
66 {"grateful", N_("Grateful"), NULL
},
67 {"grieving", N_("Grieving"), NULL
},
68 {"grumpy", N_("Grumpy"), NULL
},
69 {"guilty", N_("Guilty"), NULL
},
70 {"happy", N_("Happy"), NULL
},
71 {"hopeful", N_("Hopeful"), NULL
},
72 {"hot", N_("Hot"), NULL
},
73 {"humbled", N_("Humbled"), NULL
},
74 {"humiliated", N_("Humiliated"), NULL
},
75 {"hungry", N_("Hungry"), NULL
},
76 {"hurt", N_("Hurt"), NULL
},
77 {"impressed", N_("Impressed"), NULL
},
78 {"in_awe", N_("In awe"), NULL
},
79 {"in_love", N_("In love"), NULL
},
80 {"indignant", N_("Indignant"), NULL
},
81 {"interested", N_("Interested"), NULL
},
82 {"intoxicated", N_("Intoxicated"), NULL
},
83 {"invincible", N_("Invincible"), NULL
},
84 {"jealous", N_("Jealous"), NULL
},
85 {"lonely", N_("Lonely"), NULL
},
86 {"lost", N_("Lost"), NULL
},
87 {"lucky", N_("Lucky"), NULL
},
88 {"mean", N_("Mean"), NULL
},
89 {"moody", N_("Moody"), NULL
},
90 {"nervous", N_("Nervous"), NULL
},
91 {"neutral", N_("Neutral"), NULL
},
92 {"offended", N_("Offended"), NULL
},
93 {"outraged", N_("Outraged"), NULL
},
94 {"playful", N_("Playful"), NULL
},
95 {"proud", N_("Proud"), NULL
},
96 {"relaxed", N_("Relaxed"), NULL
},
97 {"relieved", N_("Relieved"), NULL
},
98 {"remorseful", N_("Remorseful"), NULL
},
99 {"restless", N_("Restless"), NULL
},
100 {"sad", N_("Sad"), NULL
},
101 {"sarcastic", N_("Sarcastic"), NULL
},
102 {"satisfied", N_("Satisfied"), NULL
},
103 {"serious", N_("Serious"), NULL
},
104 {"shocked", N_("Shocked"), NULL
},
105 {"shy", N_("Shy"), NULL
},
106 {"sick", N_("Sick"), NULL
},
107 {"sleepy", N_("Sleepy"), NULL
},
108 {"spontaneous", N_("Spontaneous"), NULL
},
109 {"stressed", N_("Stressed"), NULL
},
110 {"strong", N_("Strong"), NULL
},
111 {"surprised", N_("Surprised"), NULL
},
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 /* Mar last record. */
122 static const PurpleMood
*
123 find_mood_by_name(const gchar
*name
)
127 g_return_val_if_fail(name
&& *name
, NULL
);
129 for (i
= 0; moods
[i
].mood
!= NULL
; ++i
) {
130 if (g_str_equal(name
, moods
[i
].mood
)) {
138 static void jabber_mood_cb(JabberStream
*js
, const char *from
, PurpleXmlNode
*items
) {
139 /* it doesn't make sense to have more than one item here, so let's just pick the first one */
140 PurpleXmlNode
*item
= purple_xmlnode_get_child(items
, "item");
141 const char *newmood
= NULL
;
142 char *moodtext
= NULL
;
143 JabberBuddy
*buddy
= jabber_buddy_find(js
, from
, FALSE
);
144 PurpleXmlNode
*moodinfo
, *mood
;
145 /* ignore the mood of people not on our buddy list */
149 mood
= purple_xmlnode_get_child_with_namespace(item
, "mood", "http://jabber.org/protocol/mood");
152 for (moodinfo
= mood
->child
; moodinfo
; moodinfo
= moodinfo
->next
) {
153 if (moodinfo
->type
== PURPLE_XMLNODE_TYPE_TAG
) {
154 if (!strcmp(moodinfo
->name
, "text")) {
155 if (!moodtext
) /* only pick the first one */
156 moodtext
= purple_xmlnode_get_data(moodinfo
);
158 const PurpleMood
*target_mood
;
160 /* verify that the mood is known (valid) */
161 target_mood
= find_mood_by_name(moodinfo
->name
);
162 newmood
= target_mood
? target_mood
->mood
: NULL
;
166 if (newmood
!= NULL
&& moodtext
!= NULL
)
169 if (newmood
!= NULL
) {
170 purple_protocol_got_user_status(purple_connection_get_account(js
->gc
), from
, "mood",
171 PURPLE_MOOD_NAME
, newmood
,
172 PURPLE_MOOD_COMMENT
, moodtext
,
175 purple_protocol_got_user_status_deactive(purple_connection_get_account(js
->gc
), from
, "mood");
180 void jabber_mood_init(void) {
181 jabber_add_feature("http://jabber.org/protocol/mood", jabber_pep_namespace_only_when_pep_enabled_cb
);
182 jabber_pep_register_handler("http://jabber.org/protocol/mood", jabber_mood_cb
);
186 jabber_mood_set(JabberStream
*js
, const char *mood
, const char *text
)
188 const PurpleMood
*target_mood
= NULL
;
189 PurpleXmlNode
*publish
, *moodnode
;
192 target_mood
= find_mood_by_name(mood
);
193 /* Mood specified, but is invalid --
194 * fail so that the command can handle this.
200 publish
= purple_xmlnode_new("publish");
201 purple_xmlnode_set_attrib(publish
,"node","http://jabber.org/protocol/mood");
202 moodnode
= purple_xmlnode_new_child(purple_xmlnode_new_child(publish
, "item"), "mood");
203 purple_xmlnode_set_namespace(moodnode
, "http://jabber.org/protocol/mood");
206 /* If target_mood is not NULL, then
207 * target_mood->mood == mood, and is a valid element name.
209 purple_xmlnode_new_child(moodnode
, mood
);
211 /* Only set text when setting a mood */
213 PurpleXmlNode
*textnode
= purple_xmlnode_new_child(moodnode
, "text");
214 purple_xmlnode_insert_data(textnode
, text
, -1);
218 jabber_pep_publish(js
, publish
);
222 PurpleMood
*jabber_get_moods(PurpleAccount
*account
)