comparison src/gtkstatusbox.c @ 12076:4fb1edd43f45

[gaim-migrate @ 14373] Sadrul fixed the status message updating to only apply the new message if it isn't the same as the current one. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 14 Nov 2005 03:29:27 +0000
parents f62022e07351
children 3b52d94437f3
comparison
equal deleted inserted replaced
12075:f62022e07351 12076:4fb1edd43f45
819 } 819 }
820 820
821 return NULL; 821 return NULL;
822 } 822 }
823 823
824 static gboolean
825 message_changed(const char *one, const char *two)
826 {
827 if (one == NULL && two == NULL)
828 return FALSE;
829
830 if (one == NULL || two == NULL)
831 return TRUE;
832
833 return (g_utf8_collate(one, two) != 0);
834 }
835
824 static void 836 static void
825 activate_currently_selected_status(GtkGaimStatusBox *status_box) 837 activate_currently_selected_status(GtkGaimStatusBox *status_box)
826 { 838 {
827 GtkGaimStatusBoxItemType type; 839 GtkGaimStatusBoxItemType type;
828 gchar *title; 840 gchar *title;
829 GtkTreeIter iter; 841 GtkTreeIter iter;
830 char *message; 842 char *message;
831 GaimSavedStatus *saved_status; 843 GaimSavedStatus *saved_status;
844 gboolean changed = TRUE;
832 845
833 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter)) 846 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(status_box), &iter))
834 return; 847 return;
835 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter, 848 gtk_tree_model_get(GTK_TREE_MODEL(status_box->dropdown_store), &iter,
836 TYPE_COLUMN, &type, 849 TYPE_COLUMN, &type,
857 /* TODO: Should save the previous status as a transient status? */ 870 /* TODO: Should save the previous status as a transient status? */
858 871
859 if (status_box->account) { 872 if (status_box->account) {
860 gint active; 873 gint active;
861 GaimStatusType *status_type; 874 GaimStatusType *status_type;
875 GaimStatus *status;
876 const char *id = NULL;
877
878 status = gaim_account_get_active_status(status_box->account);
862 879
863 g_object_get(G_OBJECT(status_box), "active", &active, NULL); 880 g_object_get(G_OBJECT(status_box), "active", &active, NULL);
864 881
865 status_type = find_status_type_by_index(status_box->account, active); 882 status_type = find_status_type_by_index(status_box->account, active);
866 if (message) 883 id = gaim_status_type_get_id(status_type);
867 gaim_account_set_status(status_box->account, gaim_status_type_get_id(status_type), 884
868 TRUE, "message", message, NULL); 885 if (strncmp(id, gaim_status_get_id(status), strlen(id)) == 0)
869 else 886 {
870 gaim_account_set_status(status_box->account, gaim_status_type_get_id(status_type), 887 /* Selected status and previous status is the same */
871 TRUE, NULL); 888 if (!message_changed(message, gaim_status_get_attr_string(status, "message")))
872 889 changed = FALSE;
890 }
891
892 if (changed)
893 {
894 if (message)
895 gaim_account_set_status(status_box->account, id,
896 TRUE, "message", message, NULL);
897 else
898 gaim_account_set_status(status_box->account, id,
899 TRUE, NULL);
900 }
873 } else { 901 } else {
874 /* Save the newly selected status to prefs.xml and status.xml */ 902 /* Save the newly selected status to prefs.xml and status.xml */
875 /* TODO: This should be saved as transient. */ 903 /* TODO: This should be saved as transient. */
876 saved_status = gaim_savedstatus_find(_("Default")); 904 const char *current = NULL;
877 if (saved_status == NULL) 905
878 saved_status = gaim_savedstatus_new(_("Default"), type); 906 /* Has the status been really changed? */
879 gaim_savedstatus_set_type(saved_status, type); 907 current = gaim_prefs_get_string("/core/status/current");
880 gaim_savedstatus_set_message(saved_status, message); 908 saved_status = gaim_savedstatus_find(current);
881 gaim_prefs_set_string("/core/status/current", _("Default")); 909 if (saved_status && gaim_savedstatus_get_type(saved_status) == type)
882 910 {
883 /* Set the status for each account */ 911 if (!message_changed(gaim_savedstatus_get_message(saved_status), message))
884 gaim_savedstatus_activate(saved_status); 912 changed = FALSE;
913 }
914
915 if (changed)
916 {
917 saved_status = gaim_savedstatus_find(_("Default"));
918 if (saved_status == NULL)
919 saved_status = gaim_savedstatus_new(_("Default"), type);
920 gaim_savedstatus_set_type(saved_status, type);
921 gaim_savedstatus_set_message(saved_status, message);
922 gaim_prefs_set_string("/core/status/current", _("Default"));
923
924 /* Set the status for each account */
925 gaim_savedstatus_activate(saved_status);
926 }
885 } 927 }
886 928
887 g_free(title); 929 g_free(title);
888 g_free(message); 930 g_free(message);
889 } 931 }