Sun, 16 Nov 2008 18:53:25 +0000
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
http://xmpp.org/extensions/xep-0107.html
| 17776 | 1 | /* |
| 2 | * purple - Jabber Protocol Plugin | |
| 3 | * | |
| 4 | * Copyright (C) 2007, Andreas Monitzer <andy@monitzer.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17776 | 14 | * GNU General Public License for more details. |
| 15 | * | |
| 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 | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17776 | 19 | * |
| 20 | */ | |
| 21 | ||
|
19898
218e4bb04853
Fix mingw build of xmpp prpl
Daniel Atallah <datallah@pidgin.im>
parents:
19391
diff
changeset
|
22 | #include "internal.h" |
|
218e4bb04853
Fix mingw build of xmpp prpl
Daniel Atallah <datallah@pidgin.im>
parents:
19391
diff
changeset
|
23 | |
| 17776 | 24 | #include "usermood.h" |
| 25 | #include "pep.h" | |
| 26 | #include <string.h> | |
|
17780
749862fd4a87
Fixed a few small mistakes I discovered while testing user mood in Adium.
Andreas Monitzer <am@adiumx.com>
parents:
17779
diff
changeset
|
27 | #include "internal.h" |
|
17784
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
28 | #include "request.h" |
|
20226
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
29 | #include "debug.h" |
| 17776 | 30 | |
|
21091
07fe1a99c47b
Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@pidgin.im>
parents:
20226
diff
changeset
|
31 | static const char * const moodstrings[] = { |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
32 | "afraid", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
33 | "amazed", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
34 | "amorous", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
35 | "angry", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
36 | "annoyed", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
37 | "anxious", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
38 | "aroused", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
39 | "ashamed", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
40 | "bored", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
41 | "brave", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
42 | "calm", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
43 | "cautious", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
44 | "cold", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
45 | "confident", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
46 | "confused", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
47 | "contemplative", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
48 | "contented", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
49 | "cranky", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
50 | "crazy", |
|
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
51 | "creative", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
52 | "curious", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
53 | "dejected", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
54 | "depressed", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
55 | "disappointed", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
56 | "disgusted", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
57 | "dismayed", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
58 | "distracted", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
59 | "embarrassed", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
60 | "envious", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
61 | "excited", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
62 | "flirtatious", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
63 | "frustrated", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
64 | "grateful", |
|
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
65 | "grieving", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
66 | "grumpy", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
67 | "guilty", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
68 | "happy", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
69 | "hopeful", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
70 | "hot", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
71 | "humbled", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
72 | "humiliated", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
73 | "hungry", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
74 | "hurt", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
75 | "impressed", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
76 | "in_awe", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
77 | "in_love", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
78 | "indignant", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
79 | "interested", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
80 | "intoxicated", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
81 | "invincible", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
82 | "jealous", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
83 | "lonely", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
84 | "lost", |
|
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
85 | "lucky", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
86 | "mean", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
87 | "moody", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
88 | "nervous", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
89 | "neutral", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
90 | "offended", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
91 | "outraged", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
92 | "playful", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
93 | "proud", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
94 | "relaxed", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
95 | "relieved", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
96 | "remorseful", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
97 | "restless", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
98 | "sad", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
99 | "sarcastic", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
100 | "satisfied", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
101 | "serious", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
102 | "shocked", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
103 | "shy", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
104 | "sick", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
105 | "sleepy", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
106 | "spontaneous", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
107 | "stressed", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
108 | "strong", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
109 | "surprised", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
110 | "thankful", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
111 | "thirsty", |
|
24902
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
112 | "tired", |
|
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
113 | "undefined", |
|
30e71eca7c3b
Added the additional moods defined in XEP-0107 version 1.2 (2008-10-29):
Richard Laager <rlaager@pidgin.im>
parents:
22943
diff
changeset
|
114 | "weak", |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
115 | "worried", |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
116 | NULL |
| 17776 | 117 | }; |
| 118 | ||
| 119 | static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) { | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
120 | /* it doesn't make sense to have more than one item here, so let's just pick the first one */ |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
121 | xmlnode *item = xmlnode_get_child(items, "item"); |
|
19391
e9a2be88e565
Initialize newmood to NULL, as there are codepaths by which we can check against whether it is NULL or not before setting it, and that's bad.
Evan Schoenberg <evands@pidgin.im>
parents:
17803
diff
changeset
|
122 | const char *newmood = NULL; |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
123 | char *moodtext = NULL; |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
124 | JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
125 | xmlnode *moodinfo, *mood; |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
126 | /* ignore the mood of people not on our buddy list */ |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
127 | if (!buddy || !item) |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
128 | return; |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
129 | |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
130 | mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood"); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
131 | if (!mood) |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
132 | return; |
|
17790
02519364ff3f
Fixed a minor mistake which could leave the usermood to be parsed incompletely.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
133 | for (moodinfo = mood->child; moodinfo; moodinfo = moodinfo->next) { |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
134 | if (moodinfo->type == XMLNODE_TYPE_TAG) { |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
135 | if (!strcmp(moodinfo->name, "text")) { |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
136 | if (!moodtext) /* only pick the first one */ |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
137 | moodtext = xmlnode_get_data(moodinfo); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
138 | } else { |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
139 | int i; |
|
17781
d11010274b7a
Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
140 | for (i = 0; moodstrings[i]; ++i) { |
|
d11010274b7a
Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
141 | /* verify that the mood is known (valid) */ |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
142 | if (!strcmp(moodinfo->name, moodstrings[i])) { |
|
17781
d11010274b7a
Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
143 | newmood = moodstrings[i]; |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
144 | break; |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
145 | } |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
146 | } |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
147 | } |
|
17781
d11010274b7a
Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
148 | if (newmood != NULL && moodtext != NULL) |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
149 | break; |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
150 | } |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
151 | } |
|
17781
d11010274b7a
Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
152 | if (newmood != NULL) { |
|
19899
483c4f495a6c
Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents:
19898
diff
changeset
|
153 | const char *status_id; |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
154 | JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); |
|
17803
882abe4d932e
Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <am@adiumx.com>
parents:
17790
diff
changeset
|
155 | if(!resource) { /* huh? */ |
|
19899
483c4f495a6c
Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents:
19898
diff
changeset
|
156 | g_free(moodtext); |
|
17803
882abe4d932e
Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <am@adiumx.com>
parents:
17790
diff
changeset
|
157 | return; |
|
882abe4d932e
Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <am@adiumx.com>
parents:
17790
diff
changeset
|
158 | } |
|
19899
483c4f495a6c
Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents:
19898
diff
changeset
|
159 | status_id = jabber_buddy_state_get_status_id(resource->state); |
|
483c4f495a6c
Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents:
19898
diff
changeset
|
160 | |
|
17781
d11010274b7a
Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
161 | purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", _(newmood), "moodtext", moodtext?moodtext:"", NULL); |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
162 | } |
|
19899
483c4f495a6c
Various warning fixes for the xmpp prpl.
Daniel Atallah <datallah@pidgin.im>
parents:
19898
diff
changeset
|
163 | g_free(moodtext); |
| 17776 | 164 | } |
| 165 | ||
| 166 | void jabber_mood_init(void) { | |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17786
diff
changeset
|
167 | jabber_add_feature("mood", "http://jabber.org/protocol/mood", jabber_pep_namespace_only_when_pep_enabled_cb); |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
168 | jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); |
| 17776 | 169 | } |
| 170 | ||
|
17784
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
171 | static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) { |
|
20226
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
172 | JabberStream *js; |
|
22943
489cf7a4ac62
Don't count the size of an array at runtime if it's known at compile time.
Ethan Blanton <elb@pidgin.im>
parents:
21630
diff
changeset
|
173 | const int max_mood_idx = sizeof(moodstrings) / sizeof(moodstrings[0]) - 1; |
|
20226
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
174 | int selected_mood = purple_request_fields_get_choice(fields, "mood"); |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
175 | |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
176 | if (!PURPLE_CONNECTION_IS_VALID(gc)) { |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
177 | purple_debug_error("jabber", "Unable to set mood; account offline.\n"); |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
178 | return; |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
179 | } |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
180 | |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
181 | js = gc->proto_data; |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
182 | |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
183 | if (selected_mood < 0 || selected_mood >= max_mood_idx) { |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
184 | purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood); |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
185 | return; |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
186 | } |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
187 | |
|
282d0c1feb58
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
Luke Schierer <lschiere@pidgin.im>
parents:
19994
diff
changeset
|
188 | jabber_mood_set(js, moodstrings[selected_mood], purple_request_fields_get_string(fields, "text")); |
|
17784
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
189 | } |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
190 | |
|
17782
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
191 | static void do_mood_set_mood(PurplePluginAction *action) { |
|
17784
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
192 | PurpleConnection *gc = (PurpleConnection *) action->context; |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
193 | |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
194 | PurpleRequestFields *fields; |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
195 | PurpleRequestFieldGroup *group; |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
196 | PurpleRequestField *field; |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
197 | int i; |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
198 | |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
199 | fields = purple_request_fields_new(); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
200 | group = purple_request_field_group_new(NULL); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
201 | purple_request_fields_add_group(fields, group); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
202 | |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
203 | field = purple_request_field_choice_new("mood", |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
204 | _("Mood"), 0); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
205 | |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
206 | for(i = 0; moodstrings[i]; ++i) |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
207 | purple_request_field_choice_add(field, _(moodstrings[i])); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
208 | |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
209 | purple_request_field_set_required(field, TRUE); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
210 | purple_request_field_group_add_field(group, field); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
211 | |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
212 | field = purple_request_field_string_new("text", |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
213 | _("Description"), NULL, |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
214 | FALSE); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
215 | purple_request_field_group_add_field(group, field); |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
216 | |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
217 | purple_request_fields(gc, _("Edit User Mood"), |
|
17784
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
218 | _("Edit User Mood"), |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
219 | _("Please select your mood from the list."), |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
220 | fields, |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
221 | _("Set"), G_CALLBACK(do_mood_set_from_fields), |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
222 | _("Cancel"), NULL, |
|
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
223 | purple_connection_get_account(gc), NULL, NULL, |
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
224 | gc); |
|
17782
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
225 | |
|
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
226 | } |
|
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
227 | |
|
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
228 | void jabber_mood_init_action(GList **m) { |
|
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
229 | PurplePluginAction *act = purple_plugin_action_new(_("Set Mood..."), do_mood_set_mood); |
|
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
230 | *m = g_list_append(*m, act); |
|
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
231 | } |
|
83af68644d0a
Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <am@adiumx.com>
parents:
17781
diff
changeset
|
232 | |
|
17784
6aab6554431e
Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <am@adiumx.com>
parents:
17783
diff
changeset
|
233 | void jabber_mood_set(JabberStream *js, const char *mood, const char *text) { |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
234 | xmlnode *publish, *moodnode; |
|
19994
854d2a4c99b6
There shouldn't be assert()s in pretty much any libpurple code.
Daniel Atallah <datallah@pidgin.im>
parents:
19899
diff
changeset
|
235 | |
|
854d2a4c99b6
There shouldn't be assert()s in pretty much any libpurple code.
Daniel Atallah <datallah@pidgin.im>
parents:
19899
diff
changeset
|
236 | g_return_if_fail(mood != NULL); |
|
854d2a4c99b6
There shouldn't be assert()s in pretty much any libpurple code.
Daniel Atallah <datallah@pidgin.im>
parents:
19899
diff
changeset
|
237 | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
238 | publish = xmlnode_new("publish"); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
239 | xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood"); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
240 | moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood"); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
241 | xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood"); |
|
17781
d11010274b7a
Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
242 | xmlnode_new_child(moodnode, mood); |
| 17776 | 243 | |
|
17786
23e2e1e131cc
Fixed usermood memory management and removed publishing empty <text/>s.
Andreas Monitzer <am@adiumx.com>
parents:
17785
diff
changeset
|
244 | if (text && text[0] != '\0') { |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
245 | xmlnode *textnode = xmlnode_new_child(moodnode, "text"); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
246 | xmlnode_insert_data(textnode, text, -1); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
247 | } |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
248 | |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17778
diff
changeset
|
249 | jabber_pep_publish(js, publish); |
|
17786
23e2e1e131cc
Fixed usermood memory management and removed publishing empty <text/>s.
Andreas Monitzer <am@adiumx.com>
parents:
17785
diff
changeset
|
250 | /* publish is freed by jabber_pep_publish -> jabber_iq_send -> jabber_iq_free |
|
23e2e1e131cc
Fixed usermood memory management and removed publishing empty <text/>s.
Andreas Monitzer <am@adiumx.com>
parents:
17785
diff
changeset
|
251 | (yay for well-defined memory management rules) */ |
| 17776 | 252 | } |