Tue, 12 Jun 2007 00:28:06 +0000
Fixed naming to adhere to the libpurple convention
| 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 | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 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 | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | * | |
| 20 | */ | |
| 21 | ||
| 22 | #include "usermood.h" | |
| 23 | #include "pep.h" | |
| 24 | ||
| 25 | #include <string.h> | |
| 26 | ||
| 27 | static char *moodstrings[] = { | |
| 28 | "afraid", | |
| 29 | "amazed", | |
| 30 | "angry", | |
| 31 | "annoyed", | |
| 32 | "anxious", | |
| 33 | "aroused", | |
| 34 | "ashamed", | |
| 35 | "bored", | |
| 36 | "brave", | |
| 37 | "calm", | |
| 38 | "cold", | |
| 39 | "confused", | |
| 40 | "contented", | |
| 41 | "cranky", | |
| 42 | "curious", | |
| 43 | "depressed", | |
| 44 | "disappointed", | |
| 45 | "disgusted", | |
| 46 | "distracted", | |
| 47 | "embarrassed", | |
| 48 | "excited", | |
| 49 | "flirtatious", | |
| 50 | "frustrated", | |
| 51 | "grumpy", | |
| 52 | "guilty", | |
| 53 | "happy", | |
| 54 | "hot", | |
| 55 | "humbled", | |
| 56 | "humiliated", | |
| 57 | "hungry", | |
| 58 | "hurt", | |
| 59 | "impressed", | |
| 60 | "in_awe", | |
| 61 | "in_love", | |
| 62 | "indignant", | |
| 63 | "interested", | |
| 64 | "intoxicated", | |
| 65 | "invincible", | |
| 66 | "jealous", | |
| 67 | "lonely", | |
| 68 | "mean", | |
| 69 | "moody", | |
| 70 | "nervous", | |
| 71 | "neutral", | |
| 72 | "offended", | |
| 73 | "playful", | |
| 74 | "proud", | |
| 75 | "relieved", | |
| 76 | "remorseful", | |
| 77 | "restless", | |
| 78 | "sad", | |
| 79 | "sarcastic", | |
| 80 | "serious", | |
| 81 | "shocked", | |
| 82 | "shy", | |
| 83 | "sick", | |
| 84 | "sleepy", | |
| 85 | "stressed", | |
| 86 | "surprised", | |
| 87 | "thirsty", | |
| 88 | "worried", | |
| 89 | NULL | |
| 90 | }; | |
| 91 | ||
| 92 | static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) { | |
| 93 | /* it doesn't make sense to have more than one item here, so let's just pick the first one */ | |
| 94 | xmlnode *item = xmlnode_get_child(items, "item"); | |
|
17777
746809864dde
Fixed naming to adhere to the libpurple convention
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
95 | JabberMood newmood = UNKNOWN; |
| 17776 | 96 | char *moodtext = NULL; |
| 97 | JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); | |
| 98 | /* ignore the mood of people not on our buddy list */ | |
| 99 | if(!buddy) | |
| 100 | return; | |
| 101 | ||
| 102 | if(item) { | |
| 103 | xmlnode *mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood"); | |
| 104 | if(mood) { | |
| 105 | xmlnode *moodinfo; | |
| 106 | for(moodinfo = mood->child; moodinfo != mood->lastchild; moodinfo = moodinfo->next) { | |
| 107 | if(moodinfo->type == XMLNODE_TYPE_TAG) { | |
| 108 | if(!strcmp(moodinfo->name, "text")) { | |
| 109 | if(!moodtext) /* only pick the first one */ | |
| 110 | moodtext = xmlnode_get_data(moodinfo); | |
| 111 | } else { | |
| 112 | int i; | |
| 113 | for(i = 0; moodstrings[i]; ++i) { | |
| 114 | if(!strcmp(moodinfo->name, moodstrings[i])) { | |
|
17777
746809864dde
Fixed naming to adhere to the libpurple convention
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
115 | newmood = (JabberMood)(i+1); /* 0 is "unknown", so we have to add 1 */ |
| 17776 | 116 | break; |
| 117 | } | |
| 118 | } | |
| 119 | } | |
|
17777
746809864dde
Fixed naming to adhere to the libpurple convention
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
120 | if(newmood != UNKNOWN && moodtext != NULL) |
| 17776 | 121 | break; |
| 122 | } | |
| 123 | } | |
| 124 | } | |
| 125 | } | |
|
17777
746809864dde
Fixed naming to adhere to the libpurple convention
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
126 | if(newmood != UNKNOWN) { |
| 17776 | 127 | JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); |
| 128 | const char *status_id = jabber_buddy_state_get_status_id(resource->state); | |
| 129 | ||
| 130 | purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", newmood, "moodtext", moodtext?moodtext:"", NULL); | |
| 131 | } | |
| 132 | if(moodtext) | |
| 133 | g_free(moodtext); | |
| 134 | } | |
| 135 | ||
| 136 | void jabber_mood_init(void) { | |
| 137 | jabber_add_feature("mood", "http://jabber.org/protocol/mood"); | |
| 138 | jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); | |
| 139 | } | |
| 140 | ||
|
17777
746809864dde
Fixed naming to adhere to the libpurple convention
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
141 | void jabber_set_mood(JabberStream *js, JabberMood mood, const char *text) { |
| 17776 | 142 | xmlnode *publish, *moodnode; |
|
17777
746809864dde
Fixed naming to adhere to the libpurple convention
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
143 | if(mood == UNKNOWN) |
| 17776 | 144 | return; |
| 145 | ||
| 146 | publish = xmlnode_new("publish"); | |
| 147 | xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood"); | |
| 148 | moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood"); | |
| 149 | xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood"); | |
| 150 | xmlnode_new_child(moodnode, moodstrings[mood-1]); | |
| 151 | ||
| 152 | if(text) { | |
| 153 | xmlnode *textnode = xmlnode_new_child(moodnode, "text"); | |
| 154 | xmlnode_insert_data(textnode, text, -1); | |
| 155 | } | |
| 156 | ||
| 157 | jabber_pep_publish(js, publish); | |
| 158 | ||
| 159 | xmlnode_free(publish); | |
| 160 | } |