changeset 32569:547399434ca4

Replace GtkOptionMenu with GtkComboBox in the saved status editor for GTK+ 2.4 and up.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Thu, 09 Apr 2009 04:18:50 +0000
parents 6ab5ab8fc294
children d1f097ee5030
files pidgin/gtksavedstatuses.c
diffstat 1 files changed, 67 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtksavedstatuses.c	Thu Apr 09 04:13:52 2009 +0000
+++ b/pidgin/gtksavedstatuses.c	Thu Apr 09 04:18:50 2009 +0000
@@ -119,7 +119,11 @@
 
 	gchar *original_title;
 	GtkEntry *title;
+#if GTK_CHECK_VERSION(2,4,0)
+	GtkComboBox *type;
+#else
 	GtkOptionMenu *type;
+#endif
 	GtkIMHtml *message;
 } StatusEditor;
 
@@ -795,7 +799,11 @@
 		return;
 	}
 
+#if GTK_CHECK_VERSION(2,4,0)
+	type = gtk_combo_box_get_active(dialog->type) + (PURPLE_STATUS_UNSET + 1);
+#else
 	type = gtk_option_menu_get_history(dialog->type) + (PURPLE_STATUS_UNSET + 1);
+#endif
 	message = gtk_imhtml_get_markup(dialog->message);
 	unformatted = purple_markup_strip_html(message);
 
@@ -889,6 +897,58 @@
 	gtk_widget_set_sensitive(GTK_WIDGET(dialog->save_button), (*text != '\0'));
 }
 
+#if GTK_CHECK_VERSION(2,4,0)
+
+static GtkWidget *
+create_status_type_menu(PurpleStatusPrimitive type)
+{
+	int i;
+	GtkWidget *dropdown;
+	GtkListStore *store;
+	GtkTreeIter iter;
+	GtkCellRenderer *renderer;
+
+	store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
+
+	for (i = PURPLE_STATUS_UNSET + 1; i < PURPLE_STATUS_NUM_PRIMITIVES; i++)
+	{
+		if (i == PURPLE_STATUS_MOBILE || i == PURPLE_STATUS_TUNE)
+			/*
+			 * Special-case these.  They're intended to be independent
+			 * status types, so don't show them in the list.
+			 */
+			continue;
+
+		gtk_list_store_append(store, &iter);
+		/* TODO: how's this get the right size (since it seems to work fine)? */
+		gtk_list_store_set(store, &iter,
+		                   0, get_stock_icon_from_primitive(i),
+		                   1, purple_primitive_get_name_from_type(i),
+		                   -1);
+	}
+
+	dropdown = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
+
+	renderer = gtk_cell_renderer_pixbuf_new();
+	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropdown), renderer, FALSE);
+	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropdown), renderer,
+	                               "stock-id", 0,
+	                               NULL);
+
+	renderer = gtk_cell_renderer_text_new();
+	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropdown), renderer, TRUE);
+	gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropdown), renderer,
+	                               "text", 1,
+	                               NULL);
+
+	gtk_combo_box_set_active(GTK_COMBO_BOX(dropdown),
+	                         type - (PURPLE_STATUS_UNSET + 1));
+
+	return dropdown;
+}
+
+#else
+
 static GtkWidget *
 create_stock_item(const gchar *str, const gchar *icon)
 {
@@ -896,7 +956,7 @@
 	GtkWidget *label = gtk_label_new_with_mnemonic(str);
 	GtkWidget *hbox = gtk_hbox_new(FALSE, 4);
 	GtkIconSize icon_size = gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL);
-	GtkWidget *image = gtk_image_new_from_stock(icon, icon_size);;
+	GtkWidget *image = gtk_image_new_from_stock(icon, icon_size);
 
 	gtk_widget_show(label);
 	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
@@ -941,6 +1001,8 @@
 	return dropdown;
 }
 
+#endif
+
 static void edit_substatus(StatusEditor *status_editor, PurpleAccount *account);
 
 static void
@@ -1206,7 +1268,11 @@
 		dropdown = create_status_type_menu(purple_savedstatus_get_type(saved_status));
 	else
 		dropdown = create_status_type_menu(PURPLE_STATUS_AWAY);
+#if GTK_CHECK_VERSION(2,4,0)
+	dialog->type = GTK_COMBO_BOX(dropdown);
+#else
 	dialog->type = GTK_OPTION_MENU(dropdown);
+#endif
 	pidgin_add_widget_to_vbox(GTK_BOX(vbox), _("_Status:"), sg, dropdown, TRUE, NULL);
 
 	/* Status message */