Mercurial > pidgin.yaz
comparison libpurple/protocols/mxit/roster.c @ 30837:8e9b04071e79
propagate from branch 'im.pidgin.pidgin' (head 9166d0ffe82472b17cee09aabbef61d8ec6e3e44)
to branch 'im.pidgin.soc.2010.icq-tlc' (head 4c9bb4231e46e234d01e6dc64bf4be49fb12c27c)
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 12 Aug 2010 15:30:11 +0000 |
parents | 18a903a3b474 |
children | a8cc50c2279f |
comparison
equal
deleted
inserted
replaced
30836:a4d7d154d00d | 30837:8e9b04071e79 |
---|---|
42 */ | 42 */ |
43 | 43 |
44 /* statuses (reference: libpurple/status.h) */ | 44 /* statuses (reference: libpurple/status.h) */ |
45 static struct status | 45 static struct status |
46 { | 46 { |
47 PurpleStatusPrimitive primative; | 47 PurpleStatusPrimitive primitive; |
48 int mxit; | 48 int mxit; |
49 const char* id; | 49 const char* id; |
50 const char* name; | 50 const char* name; |
51 } const mxit_statuses[] = { | 51 } const mxit_statuses[] = { |
52 /* primative, no, id, name */ | 52 /* primitive, no, id, name */ |
53 { PURPLE_STATUS_OFFLINE, MXIT_PRESENCE_OFFLINE, "offline", N_( "Offline" ) }, /* 0 */ | 53 { PURPLE_STATUS_OFFLINE, MXIT_PRESENCE_OFFLINE, "offline", N_( "Offline" ) }, /* 0 */ |
54 { PURPLE_STATUS_AVAILABLE, MXIT_PRESENCE_ONLINE, "online", N_( "Available" ) }, /* 1 */ | 54 { PURPLE_STATUS_AVAILABLE, MXIT_PRESENCE_ONLINE, "online", N_( "Available" ) }, /* 1 */ |
55 { PURPLE_STATUS_AWAY, MXIT_PRESENCE_AWAY, "away", N_( "Away" ) }, /* 2 */ | 55 { PURPLE_STATUS_AWAY, MXIT_PRESENCE_AWAY, "away", N_( "Away" ) }, /* 2 */ |
56 { PURPLE_STATUS_AVAILABLE, MXIT_PRESENCE_AVAILABLE, "chat", N_( "Chatty" ) }, /* 3 */ | 56 { PURPLE_STATUS_AVAILABLE, MXIT_PRESENCE_AVAILABLE, "chat", N_( "Chatty" ) }, /* 3 */ |
57 { PURPLE_STATUS_UNAVAILABLE, MXIT_PRESENCE_DND, "dnd", N_( "Do Not Disturb" ) } /* 4 */ | 57 { PURPLE_STATUS_UNAVAILABLE, MXIT_PRESENCE_DND, "dnd", N_( "Do Not Disturb" ) } /* 4 */ |
72 | 72 |
73 for ( i = 0; i < ARRAY_SIZE( mxit_statuses ); i++ ) { | 73 for ( i = 0; i < ARRAY_SIZE( mxit_statuses ); i++ ) { |
74 const struct status* status = &mxit_statuses[i]; | 74 const struct status* status = &mxit_statuses[i]; |
75 | 75 |
76 /* add mxit status (reference: "libpurple/status.h") */ | 76 /* add mxit status (reference: "libpurple/status.h") */ |
77 type = purple_status_type_new_with_attrs( status->primative, status->id, _( status->name ), TRUE, TRUE, FALSE, | 77 type = purple_status_type_new_with_attrs( status->primitive, status->id, _( status->name ), TRUE, TRUE, FALSE, |
78 "message", _( "Message" ), purple_value_new( PURPLE_TYPE_STRING ), | 78 "message", _( "Message" ), purple_value_new( PURPLE_TYPE_STRING ), |
79 NULL ); | 79 NULL ); |
80 | 80 |
81 statuslist = g_list_append( statuslist, type ); | 81 statuslist = g_list_append( statuslist, type ); |
82 } | 82 } |
143 {"invincible", N_("Invincible"), NULL}, | 143 {"invincible", N_("Invincible"), NULL}, |
144 {"sad", N_("Sad"), NULL}, | 144 {"sad", N_("Sad"), NULL}, |
145 {"hot", N_("Hot"), NULL}, | 145 {"hot", N_("Hot"), NULL}, |
146 {"sick", N_("Sick"), NULL}, | 146 {"sick", N_("Sick"), NULL}, |
147 {"sleepy", N_("Sleepy"), NULL}, | 147 {"sleepy", N_("Sleepy"), NULL}, |
148 {"bored", N_("Bored"), NULL}, | |
149 {"cold", N_("Cold"), NULL}, | |
150 {"confused", N_("Confused"), NULL}, | |
151 {"hungry", N_("Hungry"), NULL}, | |
152 {"stressed", N_("Stressed"), NULL}, | |
148 /* Mark the last record. */ | 153 /* Mark the last record. */ |
149 { NULL, NULL, NULL } | 154 { NULL, NULL, NULL } |
150 }; | 155 }; |
151 | 156 |
152 | 157 |
211 return _( "Hot" ); | 216 return _( "Hot" ); |
212 case MXIT_MOOD_SICK : | 217 case MXIT_MOOD_SICK : |
213 return _( "Sick" ); | 218 return _( "Sick" ); |
214 case MXIT_MOOD_SLEEPY : | 219 case MXIT_MOOD_SLEEPY : |
215 return _( "Sleepy" ); | 220 return _( "Sleepy" ); |
221 case MXIT_MOOD_BORED : | |
222 return _( "Bored" ); | |
223 case MXIT_MOOD_COLD : | |
224 return _( "Cold" ); | |
225 case MXIT_MOOD_CONFUSED : | |
226 return _( "Confused" ); | |
227 case MXIT_MOOD_HUNGRY : | |
228 return _( "Hungry" ); | |
229 case MXIT_MOOD_STRESSED : | |
230 return _( "Stressed" ); | |
216 case MXIT_MOOD_NONE : | 231 case MXIT_MOOD_NONE : |
217 default : | 232 default : |
218 return ""; | 233 return ""; |
219 } | 234 } |
220 } | 235 } |
290 | 305 |
291 /* | 306 /* |
292 * XXX: libPurple does not currently provide an API to change or rename the group name | 307 * XXX: libPurple does not currently provide an API to change or rename the group name |
293 * for a specific buddy. One option is to remove the buddy from the list and re-adding | 308 * for a specific buddy. One option is to remove the buddy from the list and re-adding |
294 * him in the new group, but by doing that makes the buddy go offline and then online | 309 * him in the new group, but by doing that makes the buddy go offline and then online |
295 * again. This is really not ideal and very iretating, but how else then? | 310 * again. This is really not ideal and very irritating, but how else then? |
296 */ | 311 */ |
297 | 312 |
298 /* create new buddy */ | 313 /* create new buddy */ |
299 newbuddy = purple_buddy_new( session->acc, buddy->name, buddy->alias ); | 314 newbuddy = purple_buddy_new( session->acc, buddy->name, buddy->alias ); |
300 newbuddy->proto_data = buddy->proto_data; | 315 newbuddy->proto_data = buddy->proto_data; |
356 /* | 371 /* |
357 * libPurple requires all contacts to be in a group. | 372 * libPurple requires all contacts to be in a group. |
358 * So if this MXit contact isn't in a group, pretend it is. | 373 * So if this MXit contact isn't in a group, pretend it is. |
359 */ | 374 */ |
360 if ( *contact->groupname == '\0' ) { | 375 if ( *contact->groupname == '\0' ) { |
361 strcpy( contact->groupname, MXIT_DEFAULT_GROUP ); | 376 g_strlcpy( contact->groupname, MXIT_DEFAULT_GROUP, sizeof( contact->groupname ) ); |
362 } | 377 } |
363 | 378 |
364 /* find or create a group for this contact */ | 379 /* find or create a group for this contact */ |
365 group = purple_find_group( contact->groupname ); | 380 group = purple_find_group( contact->groupname ); |
366 if ( !group ) | 381 if ( !group ) |
426 * @param username The contact which presence to update | 441 * @param username The contact which presence to update |
427 * @param presence The new presence state for the contact | 442 * @param presence The new presence state for the contact |
428 * @param mood The new mood for the contact | 443 * @param mood The new mood for the contact |
429 * @param customMood The custom mood identifier | 444 * @param customMood The custom mood identifier |
430 * @param statusMsg This is the contact's status message | 445 * @param statusMsg This is the contact's status message |
431 * @param avatarId This is the contact's avatar id | 446 */ |
432 */ | 447 void mxit_update_buddy_presence( struct MXitSession* session, const char* username, short presence, short mood, const char* customMood, const char* statusMsg ) |
433 void mxit_update_buddy_presence( struct MXitSession* session, const char* username, short presence, short mood, const char* customMood, const char* statusMsg, const char* avatarId ) | |
434 { | 448 { |
435 PurpleBuddy* buddy = NULL; | 449 PurpleBuddy* buddy = NULL; |
436 struct contact* contact = NULL; | 450 struct contact* contact = NULL; |
437 | 451 |
438 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: user='%s' presence=%i mood=%i customMood='%s' statusMsg='%s' avatar='%s'\n", | 452 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: user='%s' presence=%i mood=%i customMood='%s' statusMsg='%s'\n", |
439 username, presence, mood, customMood, statusMsg, avatarId ); | 453 username, presence, mood, customMood, statusMsg ); |
440 | 454 |
441 if ( ( presence < MXIT_PRESENCE_OFFLINE ) || ( presence > MXIT_PRESENCE_DND ) ) { | 455 if ( ( presence < MXIT_PRESENCE_OFFLINE ) || ( presence > MXIT_PRESENCE_DND ) ) { |
442 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: invalid presence state %i\n", presence ); | 456 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: invalid presence state %i\n", presence ); |
443 return; /* ignore packet */ | 457 return; /* ignore packet */ |
444 } | 458 } |
456 | 470 |
457 contact->presence = presence; | 471 contact->presence = presence; |
458 contact->mood = mood; | 472 contact->mood = mood; |
459 | 473 |
460 /* validate mood */ | 474 /* validate mood */ |
461 if (( contact->mood < MXIT_MOOD_NONE ) || ( contact->mood > MXIT_MOOD_SLEEPY )) | 475 if (( contact->mood < MXIT_MOOD_NONE ) || ( contact->mood > MXIT_MOOD_STRESSED )) |
462 contact->mood = MXIT_MOOD_NONE; | 476 contact->mood = MXIT_MOOD_NONE; |
463 | 477 |
464 g_strlcpy( contact->customMood, customMood, sizeof( contact->customMood ) ); | 478 g_strlcpy( contact->customMood, customMood, sizeof( contact->customMood ) ); |
465 // TODO: Download custom mood frame. | 479 // TODO: Download custom mood frame. |
466 | 480 |
469 g_free( contact->statusMsg ); | 483 g_free( contact->statusMsg ); |
470 contact->statusMsg = NULL; | 484 contact->statusMsg = NULL; |
471 } | 485 } |
472 if ( statusMsg[0] != '\0' ) | 486 if ( statusMsg[0] != '\0' ) |
473 contact->statusMsg = g_markup_escape_text( statusMsg, -1 ); | 487 contact->statusMsg = g_markup_escape_text( statusMsg, -1 ); |
474 | |
475 /* update avatarId */ | |
476 if ( ( contact->avatarId ) && ( g_ascii_strcasecmp( contact->avatarId, avatarId ) == 0 ) ) { | |
477 /* avatar has not changed - do nothing */ | |
478 } | |
479 else if ( avatarId[0] != '\0' ) { /* avatar has changed */ | |
480 if ( contact->avatarId ) | |
481 g_free( contact->avatarId ); | |
482 contact->avatarId = g_strdup( avatarId ); | |
483 | |
484 /* Send request to download new avatar image */ | |
485 mxit_get_avatar( session, username, avatarId ); | |
486 } | |
487 else /* clear current avatar */ | |
488 purple_buddy_icons_set_for_user( session->acc, username, NULL, 0, NULL ); | |
489 | 488 |
490 /* update the buddy's status (reference: "libpurple/prpl.h") */ | 489 /* update the buddy's status (reference: "libpurple/prpl.h") */ |
491 if ( contact->statusMsg ) | 490 if ( contact->statusMsg ) |
492 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL ); | 491 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL ); |
493 else | 492 else |
496 /* update the buddy's mood */ | 495 /* update the buddy's mood */ |
497 if ( contact->mood == MXIT_MOOD_NONE ) | 496 if ( contact->mood == MXIT_MOOD_NONE ) |
498 purple_prpl_got_user_status_deactive( session->acc, username, "mood" ); | 497 purple_prpl_got_user_status_deactive( session->acc, username, "mood" ); |
499 else | 498 else |
500 purple_prpl_got_user_status( session->acc, username, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL ); | 499 purple_prpl_got_user_status( session->acc, username, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL ); |
500 } | |
501 | |
502 | |
503 /*------------------------------------------------------------------------ | |
504 * Update the buddy's avatar. | |
505 * Either a presence update packet was received from the MXit server, or a profile response. | |
506 * | |
507 * @param session The MXit session object | |
508 * @param username The contact which presence to update | |
509 * @param avatarId This is the contact's avatar id | |
510 */ | |
511 void mxit_update_buddy_avatar( struct MXitSession* session, const char* username, const char* avatarId ) | |
512 { | |
513 PurpleBuddy* buddy = NULL; | |
514 struct contact* contact = NULL; | |
515 | |
516 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_avatar: user='%s' avatar='%s'\n", username, avatarId ); | |
517 | |
518 /* find the buddy information for this contact (reference: "libpurple/blist.h") */ | |
519 buddy = purple_find_buddy( session->acc, username ); | |
520 if ( !buddy ) { | |
521 purple_debug_warning( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: unable to find the buddy '%s'\n", username ); | |
522 return; | |
523 } | |
524 | |
525 contact = purple_buddy_get_protocol_data( buddy ); | |
526 if ( !contact ) | |
527 return; | |
528 | |
529 if ( ( contact->avatarId ) && ( g_ascii_strcasecmp( contact->avatarId, avatarId ) == 0 ) ) { | |
530 /* avatar has not changed - do nothing */ | |
531 } | |
532 else if ( avatarId[0] != '\0' ) { /* avatar has changed */ | |
533 if ( contact->avatarId ) | |
534 g_free( contact->avatarId ); | |
535 contact->avatarId = g_strdup( avatarId ); | |
536 | |
537 /* Send request to download new avatar image */ | |
538 mxit_get_avatar( session, username, avatarId ); | |
539 } | |
540 else /* clear current avatar */ | |
541 purple_buddy_icons_set_for_user( session->acc, username, NULL, 0, NULL ); | |
501 } | 542 } |
502 | 543 |
503 | 544 |
504 /*------------------------------------------------------------------------ | 545 /*------------------------------------------------------------------------ |
505 * update the blist cached by libPurple. We need to do this to keep | 546 * update the blist cached by libPurple. We need to do this to keep |