diff src/gtkstatusbox.c @ 12125:3c1bac709234

[gaim-migrate @ 14425] Change /core/savedstatus/current and /core/savedstatus/idleaway to ints (they used to be strings, where the value was the title of a GaimSavedStatus). The value is now equal to the "creation" timestamp of a saved_status. The creation timestamp is used as the unique key. The primary reason for this is to allow for saved statuses to have NULL titles. NULL titles are needed for transient statuses. I also added a "last_used" timestamp. This all paves the way for keeping track of recently used statuses committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 18 Nov 2005 07:23:29 +0000
parents 355c7acbb61d
children 152748df85cf
line wrap: on
line diff
--- a/src/gtkstatusbox.c	Fri Nov 18 06:35:07 2005 +0000
+++ b/src/gtkstatusbox.c	Fri Nov 18 07:23:29 2005 +0000
@@ -306,15 +306,15 @@
 static void
 update_to_reflect_current_status(GtkGaimStatusBox *status_box)
 {
-	const char *current_savedstatus_name;
 	GaimSavedStatus *saved_status;
+	GaimStatusPrimitive primitive;
+	const char *message;
 
 	/* this function is inappropriate for ones with accounts */
 	if (status_box->account)
 		return;
 
-	current_savedstatus_name = gaim_prefs_get_string("/core/savedstatus/current");
-	saved_status = gaim_savedstatus_find(current_savedstatus_name);
+	saved_status = gaim_savedstatus_get_current();
 
 	/*
 	 * Suppress the "changed" signal because the status
@@ -322,58 +322,47 @@
 	 */
 	gtk_widget_set_sensitive(GTK_WIDGET(status_box), FALSE);
 
-	if (saved_status == NULL)
+	primitive = gaim_savedstatus_get_type(saved_status);
+	if (gaim_savedstatus_has_substatuses(saved_status) ||
+	    ((primitive != GAIM_STATUS_AVAILABLE) &&
+	     (primitive != GAIM_STATUS_OFFLINE) &&
+	     (primitive != GAIM_STATUS_AWAY) &&
+	     (primitive != GAIM_STATUS_HIDDEN)))
 	{
-		/* Default to "available" */
-		gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0);
+		gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 5);
 	}
 	else
 	{
-		GaimStatusPrimitive primitive;
-		const char *message;
+		if (primitive == GAIM_STATUS_AVAILABLE)
+			gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0);
+		if (primitive == GAIM_STATUS_OFFLINE)
+			gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3);
+		else if (primitive == GAIM_STATUS_AWAY)
+			gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1);
+		else if (primitive == GAIM_STATUS_HIDDEN)
+			gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2);
+	}
 
-		primitive = gaim_savedstatus_get_type(saved_status);
-		if (gaim_savedstatus_has_substatuses(saved_status) ||
-		    ((primitive != GAIM_STATUS_AVAILABLE) &&
-		     (primitive != GAIM_STATUS_OFFLINE) &&
-		     (primitive != GAIM_STATUS_AWAY) &&
-		     (primitive != GAIM_STATUS_HIDDEN)))
-		{
-			gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 5);
-		}
-		else
-		{
-			if (primitive == GAIM_STATUS_AVAILABLE)
-				gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 0);
-			if (primitive == GAIM_STATUS_OFFLINE)
-				gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 3);
-			else if (primitive == GAIM_STATUS_AWAY)
-				gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 1);
-			else if (primitive == GAIM_STATUS_HIDDEN)
-				gtk_combo_box_set_active(GTK_COMBO_BOX(status_box), 2);
-		}
+	message = gaim_savedstatus_get_message(saved_status);
+	if (!message || !*message)
+	{
+		status_box->imhtml_visible = FALSE;
+		gtk_widget_hide_all(status_box->vbox);
+	}
+	else
+	{
+		status_box->imhtml_visible = TRUE;
+		gtk_widget_show_all(status_box->vbox);
 
-		message = gaim_savedstatus_get_message(saved_status);
-		if (!message || !*message)
-		{
-			status_box->imhtml_visible = FALSE;
-			gtk_widget_hide_all(status_box->vbox);
-		}
-		else
-		{
-			status_box->imhtml_visible = TRUE;
-			gtk_widget_show_all(status_box->vbox);
+		/*
+		 * Suppress the "changed" signal because the status
+		 * was changed programmatically.
+		 */
+		gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE);
 
-			/*
-			 * Suppress the "changed" signal because the status
-			 * was changed programmatically.
-			 */
-			gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), FALSE);
-
-			gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml));
-			gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0);
-			gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE);
-		}
+		gtk_imhtml_clear(GTK_IMHTML(status_box->imhtml));
+		gtk_imhtml_append_text(GTK_IMHTML(status_box->imhtml), message, 0);
+		gtk_widget_set_sensitive(GTK_WIDGET(status_box->imhtml), TRUE);
 	}
 
 	/* Stop suppressing the "changed" signal. */
@@ -815,8 +804,6 @@
 	if ((type < 0) || (type >= GAIM_STATUS_NUM_PRIMITIVES))
 		return;
 
-	/* TODO: Should save the previous status as a transient status? */
-
 	if (status_box->account) {
 		gint active;
 		GaimStatusType *status_type;
@@ -848,13 +835,10 @@
 		}
 	} else {
 		/* Save the newly selected status to prefs.xml and status.xml */
-		/* TODO: This should be saved as transient. */
-		const char *current = NULL;
 
 		/* Has the status been really changed? */
-		current = gaim_prefs_get_string("/core/savedstatus/current");
-		saved_status = gaim_savedstatus_find(current);
-		if (saved_status && gaim_savedstatus_get_type(saved_status) == type)
+		saved_status = gaim_savedstatus_get_current();
+		if (gaim_savedstatus_get_type(saved_status) == type)
 		{
 			if (!message_changed(gaim_savedstatus_get_message(saved_status), message))
 				changed = FALSE;
@@ -862,9 +846,8 @@
 
 		if (changed)
 		{
-			saved_status = gaim_savedstatus_find(_("Default"));
-			if (saved_status == NULL)
-				saved_status = gaim_savedstatus_new(_("Default"), type);
+			/* Create a new transient saved status */
+			saved_status = gaim_savedstatus_new(NULL, type);
 			gaim_savedstatus_set_type(saved_status, type);
 			gaim_savedstatus_set_message(saved_status, message);