changeset 12195:d040123d2b69

[gaim-migrate @ 14497] A saved status dropdown. I don't know if it works, because the only way for me to test it right now is through remote X, over 3000 miles away. And I ain't puttin up with that for long. I'm going to check it out when I get home and fix it up locally. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Wed, 23 Nov 2005 02:04:59 +0000
parents a1a835fae1dc
children 2f379ed0c26b
files src/gtkprefs.c src/gtksavedstatuses.c src/gtksavedstatuses.h
diffstat 3 files changed, 70 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkprefs.c	Wed Nov 23 01:13:02 2005 +0000
+++ b/src/gtkprefs.c	Wed Nov 23 02:04:59 2005 +0000
@@ -32,6 +32,7 @@
 #include "proxy.h"
 #include "prpl.h"
 #include "request.h"
+#include "savedstatuses.h"
 #include "sound.h"
 #include "util.h"
 #include "network.h"
@@ -43,6 +44,7 @@
 #include "gtkimhtml.h"
 #include "gtkimhtmltoolbar.h"
 #include "gtkprefs.h"
+#include "gtksavedstatuses.h"
 #include "gtksound.h"
 #include "gtkthemes.h"
 #include "gtkutils.h"
@@ -1632,28 +1634,12 @@
 	return ret;
 }
 
-/* XXX CORE/UI */
-#if 0
+
 static void
-set_default_away(GtkWidget *w, gpointer data)
+set_idle_away(GaimSavedStatus *status)
 {
-	struct away_message *default_away = NULL;
-	int length = g_slist_length(away_messages);
-	int i = GPOINTER_TO_INT(data);
-
-	if (away_messages == NULL)
-		default_away = NULL;
-	else if (i >= length)
-		default_away = g_slist_nth_data(away_messages, length - 1);
-	else
-		default_away = g_slist_nth_data(away_messages, i);
-
-	if(default_away)
-		gaim_prefs_set_string("/core/away/default_message", default_away->name);
-	else
-		gaim_prefs_set_string("/core/away/default_message", "");
+	gaim_prefs_set_int("/core/savedstatus/idleaway", gaim_savedstatus_get_creation_time(status));
 }
-#endif
 
 static GtkWidget *
 away_page()
@@ -1664,6 +1650,7 @@
 	GtkWidget *label;
 	GtkWidget *button;
 	GtkWidget *select;
+	GtkWidget *menu;
 	GtkSizeGroup *sg;
 
 	ret = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE);
@@ -1702,6 +1689,10 @@
 	g_signal_connect(G_OBJECT(button), "clicked",
 					 G_CALLBACK(gaim_gtk_toggle_sensitive), label);
 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+	menu = gaim_gtk_status_menu(gaim_savedstatus_get_idleaway(), G_CALLBACK(set_idle_away));
+	gtk_box_pack_start(GTK_BOX(hbox), menu, FALSE, FALSE, 0);
+	g_signal_connect(G_OBJECT(button), "clicked",
+			 G_CALLBACK(gaim_gtk_toggle_sensitive), menu);
 
 	/*
 	 * TODO: Need to allow users to choose a GaimSavedStatus
@@ -1713,6 +1704,7 @@
 	 */
 
 	if (!gaim_prefs_get_bool("/core/away/away_when_idle")) {
+		gtk_widget_set_sensitive(GTK_WIDGET(menu), FALSE);
 		gtk_widget_set_sensitive(GTK_WIDGET(select), FALSE);
 		gtk_widget_set_sensitive(GTK_WIDGET(label), FALSE);
 	}
--- a/src/gtksavedstatuses.c	Wed Nov 23 01:13:02 2005 +0000
+++ b/src/gtksavedstatuses.c	Wed Nov 23 02:04:59 2005 +0000
@@ -1450,6 +1450,56 @@
 	gtk_widget_show(win);
 }
 
+/**************************************************************************
+ * Utilities                                                              *
+ **************************************************************************/
+
+void status_menu_cb(GtkComboBox *widget, void(*callback)(GaimSavedStatus*))
+{
+	GtkTreeIter iter;
+	char *title;
+	gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter);
+	gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)), &iter,
+			   STATUS_WINDOW_COLUMN_TITLE, &title,
+			   -1);	
+	callback(gaim_savedstatus_find(title));
+}
+
+GtkWidget *gaim_gtk_status_menu(GaimSavedStatus *current_status, GCallback callback)
+{
+	GtkWidget *combobox;
+	const GList *saved_statuses;
+	GtkCellRenderer *rend;
+	int i;
+	int index = -1;
+	GtkListStore *ls = gtk_list_store_new(STATUS_WINDOW_NUM_COLUMNS,
+					      G_TYPE_STRING,
+					      G_TYPE_STRING,
+					      G_TYPE_STRING);
+	
+	
+	for (saved_statuses = gaim_savedstatuses_get_all(), i = 0;
+	     saved_statuses != NULL;
+	     saved_statuses = g_list_next(saved_statuses), i++) {
+		add_status_to_saved_status_list(ls, saved_statuses->data);
+		if (saved_statuses->data == current_status)
+			index = i;
+	}
+	
+	combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ls));
+	rend = gtk_cell_renderer_text_new();
+	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), rend, TRUE);
+	gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combobox), rend, "text",
+					   STATUS_WINDOW_COLUMN_TITLE);
+#if GTK_CHECK_VERSION(2,6,0)
+	g_object_set(rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+#endif
+	
+	gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), index);
+	g_signal_connect(G_OBJECT(combobox), "changed", G_CALLBACK(status_menu_cb), callback);
+	return combobox;
+}
+
 
 /**************************************************************************
 * GTK+ saved status glue
--- a/src/gtksavedstatuses.h	Wed Nov 23 01:13:02 2005 +0000
+++ b/src/gtksavedstatuses.h	Wed Nov 23 02:04:59 2005 +0000
@@ -64,4 +64,13 @@
  */
 void gaim_gtk_status_uninit(void);
 
+/**
+ * Creates a dropdown menu of saved statuses and calls a callback
+ * when one is selected
+ *
+ * @param callback The callback to call when the selection changes
+ * @return         The menu widget
+ */
+GtkWidget *gaim_gtk_status_menu(GaimSavedStatus *status, GCallback callback);
+
 #endif /* _GAIM_GTKSAVEDSTATUSES_H_ */