Mercurial > pidgin
comparison src/status.c @ 10754:8a97b59f0071
[gaim-migrate @ 12357]
Some fairly clutch changes to how accounts set their statuses. This
gets rid of a lot of those g_assertion warnings.
My Girlfriend: Dad, why do we have so many forks?
Her Dad: Well, it's like the lord said, "Go fork and multiply."
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 27 Mar 2005 19:12:52 +0000 |
parents | 55af3fa46329 |
children | f93ed7f6ecc7 |
comparison
equal
deleted
inserted
replaced
10753:b40a67d45dbb | 10754:8a97b59f0071 |
---|---|
581 } | 581 } |
582 | 582 |
583 return status; | 583 return status; |
584 } | 584 } |
585 | 585 |
586 /* | |
587 * TODO: If the GaimStatus is in a GaimPresence, then | |
588 * remove it from the GaimPresence? | |
589 */ | |
586 void | 590 void |
587 gaim_status_destroy(GaimStatus *status) | 591 gaim_status_destroy(GaimStatus *status) |
588 { | 592 { |
589 g_return_if_fail(status != NULL); | 593 g_return_if_fail(status != NULL); |
590 | 594 |
595 /* TODO: Don't do this is if the status is exclusive */ | |
591 gaim_status_set_active(status, FALSE); | 596 gaim_status_set_active(status, FALSE); |
592 | 597 |
593 g_hash_table_destroy(status->attr_values); | 598 g_hash_table_destroy(status->attr_values); |
594 | 599 |
595 g_free(status); | 600 g_free(status); |
706 { | 711 { |
707 GaimPresence *presence; | 712 GaimPresence *presence; |
708 GaimStatus *old_status; | 713 GaimStatus *old_status; |
709 | 714 |
710 presence = gaim_status_get_presence(status); | 715 presence = gaim_status_get_presence(status); |
711 old_status = gaim_presence_get_active_status(presence); | |
712 | 716 |
713 /* | 717 /* |
714 * If this status is exclusive, then we must be setting it to "active." | 718 * If this status is exclusive, then we must be setting it to "active." |
715 * Since we are setting it to active, we want to set the currently | 719 * Since we are setting it to active, we want to set the currently |
716 * active status to "inactive." | 720 * active status to "inactive." |
717 */ | 721 */ |
718 if (gaim_status_is_exclusive(status)) | 722 if (gaim_status_is_exclusive(status)) |
719 { | 723 { |
720 const GList *l; | 724 old_status = gaim_presence_get_active_status(presence); |
721 | 725 if (old_status != NULL) |
722 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next) | 726 old_status->active = FALSE; |
723 { | 727 presence->active_status = status; |
724 GaimStatus *temp_status = l->data; | 728 } |
725 | 729 else |
726 if (temp_status == status) | 730 old_status = NULL; |
727 continue; | |
728 | |
729 if (gaim_status_is_independent(temp_status)) | |
730 continue; | |
731 | |
732 if (gaim_status_is_active(temp_status)) | |
733 { | |
734 /* | |
735 * Since we don't want infinite recursion, we have to set | |
736 * the active variable ourself instead of calling | |
737 * gaim_status_set_active(). | |
738 */ | |
739 temp_status->active = FALSE; | |
740 | |
741 notify_status_update(presence, old_status, temp_status); | |
742 | |
743 break; | |
744 } | |
745 } | |
746 } | |
747 | 731 |
748 notify_status_update(presence, old_status, status); | 732 notify_status_update(presence, old_status, status); |
749 } | 733 } |
750 | 734 |
751 void | 735 void |
752 gaim_status_set_active(GaimStatus *status, gboolean active) | 736 gaim_status_set_active(GaimStatus *status, gboolean active) |
753 { | 737 { |
738 gaim_status_set_active_with_attrs(status, active, NULL); | |
739 } | |
740 | |
741 void | |
742 gaim_status_set_active_with_attrs(GaimStatus *status, gboolean active, va_list args) | |
743 { | |
744 gboolean changed = FALSE; | |
745 const gchar *id; | |
746 | |
747 g_return_if_fail(status != NULL); | |
748 | |
754 if (!active && gaim_status_is_exclusive(status)) | 749 if (!active && gaim_status_is_exclusive(status)) |
755 { | 750 { |
756 gaim_debug_error("status", | 751 gaim_debug_error("status", |
757 "Cannot deactivate an exclusive status (%s).\n", | 752 "Cannot deactivate an exclusive status (%s).\n", |
758 gaim_status_get_id(status)); | 753 gaim_status_get_id(status)); |
759 return; | 754 return; |
760 } | 755 } |
761 | 756 |
762 g_return_if_fail(status != NULL); | 757 if (status->active != active) |
763 | 758 { |
764 if (status->active == active) | 759 changed = TRUE; |
765 return; | 760 } |
766 | 761 |
767 status->active = active; | 762 status->active = active; |
768 | 763 |
769 status_has_changed(status); | |
770 } | |
771 | |
772 void | |
773 gaim_status_set_active_with_attrs(GaimStatus *status, gboolean active, va_list args) | |
774 { | |
775 gboolean changed = FALSE; | |
776 const gchar *id; | |
777 | |
778 g_return_if_fail(status != NULL); | |
779 | |
780 if (!active && gaim_status_is_exclusive(status)) | |
781 { | |
782 gaim_debug_error("status", | |
783 "Cannot deactivate an exclusive status (%s).\n", | |
784 gaim_status_get_id(status)); | |
785 return; | |
786 } | |
787 | |
788 if (status->active != active) | |
789 { | |
790 changed = TRUE; | |
791 } | |
792 | |
793 status->active = active; | |
794 | |
795 /* Set any attributes */ | 764 /* Set any attributes */ |
765 if (args != NULL) | |
796 while ((id = va_arg(args, const char *)) != NULL) | 766 while ((id = va_arg(args, const char *)) != NULL) |
797 { | 767 { |
798 GaimValue *value; | 768 GaimValue *value; |
799 value = gaim_status_get_attr_value(status, id); | 769 value = gaim_status_get_attr_value(status, id); |
800 if (value == NULL) | 770 if (value == NULL) |
1274 "(%s) inactive. Only independent statuses " | 1244 "(%s) inactive. Only independent statuses " |
1275 "can be specifically marked inactive.", | 1245 "can be specifically marked inactive.", |
1276 status_id); | 1246 status_id); |
1277 return; | 1247 return; |
1278 } | 1248 } |
1279 | |
1280 if (presence->active_status != NULL) | |
1281 gaim_status_set_active(presence->active_status, FALSE); | |
1282 presence->active_status = status; | |
1283 } | 1249 } |
1284 | 1250 |
1285 gaim_status_set_active(status, active); | 1251 gaim_status_set_active(status, active); |
1286 } | 1252 } |
1287 | 1253 |
1288 void | 1254 void |
1289 gaim_presence_switch_status(GaimPresence *presence, const char *status_id) | 1255 gaim_presence_switch_status(GaimPresence *presence, const char *status_id) |
1290 { | 1256 { |
1291 GaimStatus *status; | 1257 gaim_presence_set_status_active(presence, status_id, TRUE); |
1292 | |
1293 g_return_if_fail(presence != NULL); | |
1294 g_return_if_fail(status_id != NULL); | |
1295 | |
1296 status = gaim_presence_get_status(presence, status_id); | |
1297 | |
1298 g_return_if_fail(status != NULL); | |
1299 | |
1300 if (gaim_status_is_independent(status)) | |
1301 return; | |
1302 | |
1303 if (presence->active_status != NULL) | |
1304 gaim_status_set_active(presence->active_status, FALSE); | |
1305 | |
1306 gaim_status_set_active(status, TRUE); | |
1307 } | 1258 } |
1308 | 1259 |
1309 static void | 1260 static void |
1310 update_buddy_idle(GaimBuddy *buddy, GaimPresence *presence, | 1261 update_buddy_idle(GaimBuddy *buddy, GaimPresence *presence, |
1311 time_t current_time, gboolean old_idle, gboolean idle) | 1262 time_t current_time, gboolean old_idle, gboolean idle) |