libpurple/status.c

changeset 40709
55f4486bf6bc
parent 40613
55230eededd8
child 41137
3c1574216aed
equal deleted inserted replaced
40708:53a26c29d26c 40709:55f4486bf6bc
695 g_hash_table_destroy(attrs); 695 g_hash_table_destroy(attrs);
696 } 696 }
697 697
698 void 698 void
699 purple_status_set_active_with_attrs_dict(PurpleStatus *status, gboolean active, 699 purple_status_set_active_with_attrs_dict(PurpleStatus *status, gboolean active,
700 GHashTable *attrs) 700 GHashTable *attrs)
701 { 701 {
702 PurpleStatusPrivate *priv = NULL; 702 PurpleStatusPrivate *priv = NULL;
703 gboolean changed = FALSE; 703 gboolean changed = FALSE;
704 GHashTableIter iter;
705 gchar *id;
706 gpointer data;
707 GList *l; 704 GList *l;
708 GList *specified_attr_ids = NULL; 705 GList *specified_attr_ids = NULL;
709 PurpleStatusType *status_type; 706 PurpleStatusType *status_type;
710 707
711 g_return_if_fail(PURPLE_IS_STATUS(status)); 708 g_return_if_fail(PURPLE_IS_STATUS(status));
712 g_return_if_fail(attrs != NULL);
713 709
714 priv = purple_status_get_instance_private(status); 710 priv = purple_status_get_instance_private(status);
715 711
716 if (!active && purple_status_is_exclusive(status)) 712 if(!active && purple_status_is_exclusive(status)) {
717 {
718 purple_debug_error("status", 713 purple_debug_error("status",
719 "Cannot deactivate an exclusive status (%s).\n", 714 "Cannot deactivate an exclusive status (%s).",
720 purple_status_get_id(status)); 715 purple_status_get_id(status));
721 return; 716 return;
722 } 717 }
723 718
724 if (priv->active != active) 719 if(priv->active != active) {
725 {
726 changed = TRUE; 720 changed = TRUE;
727 } 721 }
728
729 priv->active = active; 722 priv->active = active;
730 723
731 /* Set any attributes */ 724 if(attrs != NULL) {
732 g_hash_table_iter_init(&iter, attrs); 725 GHashTableIter iter;
733 while (g_hash_table_iter_next(&iter, (gpointer *)&id, (gpointer *)&data)) { 726 gpointer key, data;
734 GValue *value; 727
735 728 /* Set any attributes */
736 value = purple_status_get_attr_value(status, id); 729 g_hash_table_iter_init(&iter, attrs);
737 if (value == NULL) 730 while(g_hash_table_iter_next(&iter, &key, &data)) {
738 { 731 gchar *id = (gchar *)key;
739 purple_debug_warning("status", "The attribute \"%s\" on the status \"%s\" is " 732 GValue *value = purple_status_get_attr_value(status, id);
740 "not supported.\n", id, priv->status_type->name); 733 if(value == NULL) {
741 /* Skip over the data and move on to the next attribute */ 734 purple_debug_warning("status",
742 continue; 735 "The attribute \"%s\" on the status "
743 } 736 "\"%s\" is not supported.",
744 737 id, priv->status_type->name);
745 specified_attr_ids = g_list_prepend(specified_attr_ids, (gpointer)id); 738
746 739 /* Skip over the data and move on to the next attribute */
747 if (G_VALUE_TYPE(value) == G_TYPE_STRING)
748 {
749 const gchar *string_data = data;
750 if (purple_strequal(string_data, g_value_get_string(value)))
751 continue; 740 continue;
752 status_set_attr_string(status, id, string_data); 741 }
753 changed = TRUE; 742
754 } 743 specified_attr_ids = g_list_prepend(specified_attr_ids, id);
755 else if (G_VALUE_TYPE(value) == G_TYPE_INT) 744
756 { 745 if(G_VALUE_HOLDS_STRING(value)) {
757 int int_data = GPOINTER_TO_INT(data); 746 const gchar *string_data = (const gchar *)data;
758 if (int_data == g_value_get_int(value)) 747
759 continue; 748 if(purple_strequal(string_data, g_value_get_string(value))) {
760 status_set_attr_int(status, id, int_data); 749 continue;
761 changed = TRUE; 750 }
762 } 751
763 else if (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN) 752 status_set_attr_string(status, id, string_data);
764 { 753 changed = TRUE;
765 gboolean boolean_data = GPOINTER_TO_INT(data); 754 } else if(G_VALUE_HOLDS_INT(value)) {
766 if (boolean_data == g_value_get_boolean(value)) 755 gint int_data = GPOINTER_TO_INT(data);
767 continue; 756
768 status_set_attr_boolean(status, id, boolean_data); 757 if(int_data == g_value_get_int(value)) {
769 changed = TRUE; 758 continue;
759 }
760
761 status_set_attr_int(status, id, int_data);
762 changed = TRUE;
763 } else if(G_VALUE_HOLDS_BOOLEAN(value)) {
764 gboolean boolean_data = GPOINTER_TO_INT(data);
765
766 if(boolean_data == g_value_get_boolean(value)) {
767 continue;
768 }
769
770 status_set_attr_boolean(status, id, boolean_data);
771 changed = TRUE;
772 }
770 } 773 }
771 } 774 }
772 775
773 /* Reset any unspecified attributes to their default value */ 776 /* Reset any unspecified attributes to their default value */
774 status_type = purple_status_get_status_type(status); 777 status_type = purple_status_get_status_type(status);
775 l = purple_status_type_get_attrs(status_type); 778 l = purple_status_type_get_attrs(status_type);
776 while (l != NULL) { 779 while(l != NULL) {
777 PurpleStatusAttribute *attr; 780 PurpleStatusAttribute *attr;
781 GList *found = NULL;
782 GValue *default_value = NULL;
783 default_value = NULL;
778 784
779 attr = l->data; 785 attr = l->data;
780 l = l->next; 786 l = l->next;
781 787
782 if (!g_list_find_custom(specified_attr_ids, attr->id, (GCompareFunc)strcmp)) { 788 found = g_list_find_custom(specified_attr_ids, attr->id,
783 GValue *default_value; 789 (GCompareFunc)g_strcmp0);
784 default_value = purple_status_attribute_get_value(attr); 790 if(found != NULL) {
785 if (G_VALUE_TYPE(default_value) == G_TYPE_STRING) { 791 continue;
786 const char *cur = purple_status_get_attr_string(status, attr->id); 792 }
787 const char *def = g_value_get_string(default_value); 793
788 if (purple_strequal(cur, def)) { 794 default_value = purple_status_attribute_get_value(attr);
789 continue; 795 if(G_VALUE_HOLDS_STRING(default_value)) {
790 } 796 const gchar *cur = purple_status_get_attr_string(status,
791 797 attr->id);
792 status_set_attr_string(status, attr->id, def); 798 const gchar *def = g_value_get_string(default_value);
793 } else if (G_VALUE_TYPE(default_value) == G_TYPE_INT) { 799
794 int cur = purple_status_get_attr_int(status, attr->id); 800 if (purple_strequal(cur, def)) {
795 int def = g_value_get_int(default_value); 801 continue;
796 if (cur == def)
797 continue;
798
799 status_set_attr_int(status, attr->id, def);
800 } else if (G_VALUE_TYPE(default_value) == G_TYPE_BOOLEAN) {
801 gboolean cur = purple_status_get_attr_boolean(status, attr->id);
802 gboolean def = g_value_get_boolean(default_value);
803 if (cur == def)
804 continue;
805
806 status_set_attr_boolean(status, attr->id, def);
807 } 802 }
808 changed = TRUE; 803
804 status_set_attr_string(status, attr->id, def);
805 } else if(G_VALUE_HOLDS_INT(default_value)) {
806 gint cur = purple_status_get_attr_int(status, attr->id);
807 gint def = g_value_get_int(default_value);
808
809 if(cur == def) {
810 continue;
811 }
812
813 status_set_attr_int(status, attr->id, def);
814 } else if(G_VALUE_HOLDS_BOOLEAN(default_value)) {
815 gboolean cur = purple_status_get_attr_boolean(status, attr->id);
816 gboolean def = g_value_get_boolean(default_value);
817
818 if(cur == def) {
819 continue;
820 }
821
822 status_set_attr_boolean(status, attr->id, def);
809 } 823 }
824 changed = TRUE;
810 } 825 }
811 g_list_free(specified_attr_ids); 826 g_list_free(specified_attr_ids);
812 827
813 if (!changed) 828 if(changed) {
814 return; 829 status_has_changed(status);
815 status_has_changed(status); 830 }
816 } 831 }
817 832
818 PurpleStatusType * 833 PurpleStatusType *
819 purple_status_get_status_type(PurpleStatus *status) 834 purple_status_get_status_type(PurpleStatus *status)
820 { 835 {

mercurial