comparison libpurple/protocols/mxit/roster.c @ 30351:085020c013eb

Add support for the standard Mood API.
author andrew.victor@mxit.com
date Tue, 11 May 2010 10:00:30 +0000
parents ecc6217baa1e
children d7325448badb
comparison
equal deleted inserted replaced
30350:df44288b44eb 30351:085020c013eb
79 NULL ); 79 NULL );
80 80
81 statuslist = g_list_append( statuslist, type ); 81 statuslist = g_list_append( statuslist, type );
82 } 82 }
83 83
84 /* add Mood option */
85 type = purple_status_type_new_with_attrs(PURPLE_STATUS_MOOD, "mood", NULL, FALSE, TRUE, TRUE,
86 PURPLE_MOOD_NAME, _("Mood Name"), purple_value_new( PURPLE_TYPE_STRING ),
87 NULL);
88 statuslist = g_list_append( statuslist, type );
89
84 return statuslist; 90 return statuslist;
85 } 91 }
86 92
87 93
88 /*------------------------------------------------------------------------ 94 /*------------------------------------------------------------------------
124 130
125 131
126 /*======================================================================================================================== 132 /*========================================================================================================================
127 * Moods 133 * Moods
128 */ 134 */
135
136 /* moods (reference: libpurple/status.h) */
137 static PurpleMood mxit_moods[] = {
138 {"angry", N_("Angry"), NULL},
139 {"excited", N_("Excited"), NULL},
140 {"grumpy", N_("Grumpy"), NULL},
141 {"happy", N_("Happy"), NULL},
142 {"in_love", N_("In love"), NULL},
143 {"invincible", N_("Invincible"), NULL},
144 {"sad", N_("Sad"), NULL},
145 {"hot", N_("Hot"), NULL},
146 {"sick", N_("Sick"), NULL},
147 {"sleepy", N_("Sleepy"), NULL},
148 /* Mark the last record. */
149 { NULL, NULL, NULL }
150 };
151
152
153 /*------------------------------------------------------------------------
154 * Returns the MXit mood code, given the unique mood ID.
155 *
156 * @param id The mood ID
157 * @return The MXit mood code
158 */
159 int mxit_convert_mood( const char* id )
160 {
161 unsigned int i;
162
163 /* Mood is being unset */
164 if ( id == NULL )
165 return MXIT_MOOD_NONE;
166
167 for ( i = 0; i < ARRAY_SIZE( mxit_moods ) - 1; i++ ) {
168 if ( strcmp( mxit_moods[i].mood, id ) == 0 ) /* mood found! */
169 return i + 1; /* because MXIT_MOOD_NONE is 0 */
170 }
171
172 return -1;
173 }
174
175
176 /*------------------------------------------------------------------------
177 * Return the list of MXit-supported moods.
178 *
179 * @param account The MXit account object
180 */
181 PurpleMood* mxit_get_moods(PurpleAccount *account)
182 {
183 return mxit_moods;
184 }
185
129 186
130 /*------------------------------------------------------------------------ 187 /*------------------------------------------------------------------------
131 * Returns the MXit mood as a string, given the MXit mood's ID. 188 * Returns the MXit mood as a string, given the MXit mood's ID.
132 * 189 *
133 * @param id The MXit mood ID (see roster.h) 190 * @param id The MXit mood ID (see roster.h)
257 if ( contact->statusMsg ) 314 if ( contact->statusMsg )
258 purple_prpl_got_user_status( session->acc, newbuddy->name, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL ); 315 purple_prpl_got_user_status( session->acc, newbuddy->name, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL );
259 else 316 else
260 purple_prpl_got_user_status( session->acc, newbuddy->name, mxit_statuses[contact->presence].id, NULL ); 317 purple_prpl_got_user_status( session->acc, newbuddy->name, mxit_statuses[contact->presence].id, NULL );
261 318
319 /* update the buddy's mood */
320 if ( contact->mood == MXIT_MOOD_NONE )
321 purple_prpl_got_user_status_deactive( session->acc, newbuddy->name, "mood" );
322 else
323 purple_prpl_got_user_status( session->acc, newbuddy->name, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL );
324
262 /* update avatar */ 325 /* update avatar */
263 if ( contact->avatarId ) { 326 if ( contact->avatarId ) {
264 mxit_get_avatar( session, newbuddy->name, contact->avatarId ); 327 mxit_get_avatar( session, newbuddy->name, contact->avatarId );
265 g_free( contact->avatarId ); 328 g_free( contact->avatarId );
266 contact->avatarId = NULL; 329 contact->avatarId = NULL;
344 else 407 else
345 contact->avatarId = NULL; 408 contact->avatarId = NULL;
346 409
347 /* update the buddy's status (reference: "libpurple/prpl.h") */ 410 /* update the buddy's status (reference: "libpurple/prpl.h") */
348 purple_prpl_got_user_status( session->acc, contact->username, mxit_statuses[contact->presence].id, NULL ); 411 purple_prpl_got_user_status( session->acc, contact->username, mxit_statuses[contact->presence].id, NULL );
412
413 /* update the buddy's mood */
414 if ( contact->mood == MXIT_MOOD_NONE )
415 purple_prpl_got_user_status_deactive( session->acc, contact->username, "mood" );
416 else
417 purple_prpl_got_user_status( session->acc, contact->username, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL );
349 } 418 }
350 419
351 420
352 /*------------------------------------------------------------------------ 421 /*------------------------------------------------------------------------
353 * A presence update packet was received from the MXit server, so update the buddy's 422 * A presence update packet was received from the MXit server, so update the buddy's
386 return; 455 return;
387 456
388 contact->presence = presence; 457 contact->presence = presence;
389 contact->mood = mood; 458 contact->mood = mood;
390 459
460 /* validate mood */
461 if (( contact->mood < MXIT_MOOD_NONE ) || ( contact->mood > MXIT_MOOD_SLEEPY ))
462 contact->mood = MXIT_MOOD_NONE;
463
391 g_strlcpy( contact->customMood, customMood, sizeof( contact->customMood ) ); 464 g_strlcpy( contact->customMood, customMood, sizeof( contact->customMood ) );
392 // TODO: Download custom mood frame. 465 // TODO: Download custom mood frame.
393 466
394 /* update status message */ 467 /* update status message */
395 if ( contact->statusMsg ) { 468 if ( contact->statusMsg ) {
417 /* update the buddy's status (reference: "libpurple/prpl.h") */ 490 /* update the buddy's status (reference: "libpurple/prpl.h") */
418 if ( contact->statusMsg ) 491 if ( contact->statusMsg )
419 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL ); 492 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL );
420 else 493 else
421 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, NULL ); 494 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, NULL );
495
496 /* update the buddy's mood */
497 if ( contact->mood == MXIT_MOOD_NONE )
498 purple_prpl_got_user_status_deactive( session->acc, username, "mood" );
499 else
500 purple_prpl_got_user_status( session->acc, username, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL );
422 } 501 }
423 502
424 503
425 /*------------------------------------------------------------------------ 504 /*------------------------------------------------------------------------
426 * update the blist cached by libPurple. We need to do this to keep 505 * update the blist cached by libPurple. We need to do this to keep