comparison src/status.c @ 10204:393f85d9f8dd

[gaim-migrate @ 11325] I moved some code from account.c to status.c. It's better there. This shouldn't hurt anything. In other news, the status API makes me hot. What makes you hot? Something that you want but you haven't got MartinFowlerSaysWhat? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 19 Nov 2004 03:08:27 +0000
parents f086269582b1
children 2a132b73a6e6
comparison
equal deleted inserted replaced
10203:7ff9b8b22e7d 10204:393f85d9f8dd
626 old_status, new_status); 626 old_status, new_status);
627 } 627 }
628 } 628 }
629 } 629 }
630 630
631 void 631 static void
632 gaim_status_set_active(GaimStatus *status, gboolean active) 632 status_has_changed(GaimStatus *status)
633 { 633 {
634 GaimStatusType *status_type;
635 GaimPresence *presence; 634 GaimPresence *presence;
636 GaimStatus *old_status; 635 GaimStatus *old_status;
637 636
638 g_return_if_fail(status != NULL);
639
640 if (status->active == active)
641 return;
642
643 status_type = gaim_status_get_type(status);
644
645 if (!active && gaim_status_type_is_exclusive(status_type))
646 {
647 gaim_debug_error("status",
648 "Cannot deactivate an exclusive status (%s).\n",
649 gaim_status_type_get_id(status_type));
650 return;
651 }
652
653 presence = gaim_status_get_presence(status); 637 presence = gaim_status_get_presence(status);
654 old_status = gaim_presence_get_active_status(presence); 638 old_status = gaim_presence_get_active_status(presence);
655 639
656 if (gaim_status_type_is_exclusive(status_type)) 640 /*
641 * If this status is exclusive, then we must be setting it to "active."
642 * Since we are setting it to active, we want to set the currently
643 * active status to "inactive."
644 */
645 if (gaim_status_is_exclusive(status))
657 { 646 {
658 const GList *l; 647 const GList *l;
659 648
660 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next) 649 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next)
661 { 650 {
662 GaimStatus *temp_status = l->data; 651 GaimStatus *temp_status = l->data;
663 GaimStatusType *temp_type; 652
664 653 if (temp_status == status)
665 temp_type = gaim_status_get_type(temp_status); 654 continue;
666 655
667 if (gaim_status_type_is_independent(temp_type)) 656 if (gaim_status_is_independent(temp_status))
668 continue; 657 continue;
669 658
670 if (gaim_status_is_active(temp_status)) 659 if (gaim_status_is_active(temp_status))
671 { 660 {
672 /* 661 /*
673 * Since we don't want an infinite loop, we have to set 662 * Since we don't want infinite recursion, we have to set
674 * the active variable ourself. 663 * the active variable ourself instead of calling
664 * gaim_status_set_active().
675 */ 665 */
676 temp_status->active = FALSE; 666 temp_status->active = FALSE;
677 667
678 notify_status_update(presence, old_status, temp_status); 668 notify_status_update(presence, old_status, temp_status);
679 669
680 break; 670 break;
681 } 671 }
682 } 672 }
683 } 673 }
684 674
675 notify_status_update(presence, old_status, status);
676 }
677
678 void
679 gaim_status_set_active(GaimStatus *status, gboolean active)
680 {
681 if (!active && gaim_status_is_exclusive(status))
682 {
683 gaim_debug_error("status",
684 "Cannot deactivate an exclusive status (%s).\n",
685 gaim_status_get_id(status));
686 return;
687 }
688
689 g_return_if_fail(status != NULL);
690
691 if (status->active == active)
692 return;
693
685 status->active = active; 694 status->active = active;
686 695
687 notify_status_update(presence, old_status, status); 696 status_has_changed(status);
697 }
698
699 void
700 gaim_status_set_active_with_attrs(GaimStatus *status, gboolean active, va_list args)
701 {
702 gboolean changed = FALSE;
703 const gchar *id;
704
705 if (!active && gaim_status_is_exclusive(status))
706 {
707 gaim_debug_error("status",
708 "Cannot deactivate an exclusive status (%s).\n",
709 gaim_status_get_id(status));
710 return;
711 }
712
713 g_return_if_fail(status != NULL);
714
715 if (status->active != active)
716 changed = TRUE;
717
718 status->active = active;
719
720 /* Set any attributes */
721 while ((id = va_arg(args, const char *)) != NULL)
722 {
723 GaimValue *value;
724 value = gaim_status_get_attr_value(status, id);
725 if (value->type == GAIM_TYPE_STRING)
726 {
727 const gchar *string_data = va_arg(args, const char *);
728 if (((string_data == NULL) && (value->data.string_data == NULL)) ||
729 ((string_data != NULL) && (value->data.string_data != NULL) &&
730 !strcmp(string_data, value->data.string_data)))
731 {
732 continue;
733 }
734 gaim_status_set_attr_string(status, id, string_data);
735 changed = TRUE;
736 }
737 else if (value->type == GAIM_TYPE_INT)
738 {
739 int int_data = va_arg(args, int);
740 if (int_data == value->data.int_data)
741 continue;
742 gaim_status_set_attr_int(status, id, int_data);
743 changed = TRUE;
744 }
745 else if (value->type == GAIM_TYPE_BOOLEAN)
746 {
747 gboolean boolean_data = va_arg(args, gboolean);
748 if (boolean_data == value->data.boolean_data)
749 continue;
750 gaim_status_set_attr_int(status, id, boolean_data);
751 changed = TRUE;
752 }
753 else
754 {
755 /* We don't know what the data is--skip over it */
756 va_arg(args, void *);
757 }
758 }
759
760 if (!changed)
761 return;
762
763 status_has_changed(status);
688 } 764 }
689 765
690 void 766 void
691 gaim_status_set_attr_boolean(GaimStatus *status, const char *id, 767 gaim_status_set_attr_boolean(GaimStatus *status, const char *id,
692 gboolean value) 768 gboolean value)