cpw.qulogic.gtk3: 64488ef6: Apply final changes from nix_nix's patch...

qulogic at pidgin.im qulogic at pidgin.im
Mon Jul 26 01:59:06 EDT 2010


----------------------------------------------------------------------
Revision: 64488ef619d9fcf97f132e33f0cf632a78620def
Parent:   7efc5a908ae60643722b66f934b7d7869a1b8187
Author:   nix at go-nix.ca
Date:     07/26/10 01:35:10
Branch:   im.pidgin.cpw.qulogic.gtk3
URL: http://d.pidgin.im/viewmtn/revision/info/64488ef619d9fcf97f132e33f0cf632a78620def

Changelog: 

Apply final changes from nix_nix's patch.

Closes #1332.

Changes against parent 7efc5a908ae60643722b66f934b7d7869a1b8187

  patched  pidgin/gtkaccount.c
  patched  pidgin/gtkutils.c
  patched  pidgin/plugins/contact_priority.c

-------------- next part --------------
============================================================
--- pidgin/gtkutils.c	20a88cb894059ff89c37b3fc0fdad9c870d5ab99
+++ pidgin/gtkutils.c	29305633c9ab1c5b07863d7b69afc69ce015ab41
@@ -70,7 +70,7 @@ typedef struct {
 #include "pidgin/minidialog.h"
 
 typedef struct {
-	GtkWidget *menu;
+	GtkTreeModel *model;
 	gint default_item;
 } AopMenu;
 
@@ -527,68 +527,35 @@ static gpointer
 }
 
 static gpointer
-aop_option_menu_get_selected(GtkWidget *optmenu, GtkWidget **p_item)
+aop_option_menu_get_selected(GtkWidget *optmenu)
 {
-	GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
-	GtkWidget *item = gtk_menu_get_active(GTK_MENU(menu));
-	if (p_item)
-		(*p_item) = item;
-	return item ? g_object_get_data(G_OBJECT(item), "aop_per_item_data") : NULL;
+	gpointer data = NULL;
+	GtkTreeIter iter;
+
+	g_return_val_if_fail(optmenu != NULL, NULL);
+
+	if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(optmenu), &iter))
+		gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)), &iter, 2, &data, -1);
+
+	return data;
 }
 
 static void
 aop_menu_cb(GtkWidget *optmenu, GCallback cb)
 {
-	GtkWidget *item;
-	gpointer per_item_data;
-
-	per_item_data = aop_option_menu_get_selected(optmenu, &item);
-
 	if (cb != NULL) {
-		((void (*)(GtkWidget *, gpointer, gpointer))cb)(item, per_item_data, g_object_get_data(G_OBJECT(optmenu), "user_data"));
+		((void (*)(GtkWidget *, gpointer, gpointer))cb)(NULL,
+			aop_option_menu_get_selected(optmenu),
+			g_object_get_data(G_OBJECT(optmenu), "user_data"));
 	}
 }
 
-static GtkWidget *
-aop_menu_item_new(GtkSizeGroup *sg, GdkPixbuf *pixbuf, const char *lbl, gpointer per_item_data, const char *data)
+static void
+aop_option_menu_replace_menu(GtkWidget *optmenu, AopMenu *new_aop_menu)
 {
-	GtkWidget *item;
-	GtkWidget *hbox;
-	GtkWidget *image;
-	GtkWidget *label;
-
-	item = gtk_menu_item_new();
-	gtk_widget_show(item);
-
-	hbox = gtk_hbox_new(FALSE, 4);
-	gtk_widget_show(hbox);
-
-	/* Create the image */
-	if (pixbuf == NULL)
-		image = gtk_image_new();
-	else
-		image = gtk_image_new_from_pixbuf(pixbuf);
-	gtk_widget_show(image);
-
-	if (sg)
-		gtk_size_group_add_widget(sg, image);
-
-	/* Create the label */
-	label = gtk_label_new (lbl);
-	gtk_widget_show (label);
-	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
-	gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
-
-	gtk_container_add(GTK_CONTAINER(item), hbox);
-	gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
-	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
-
-	g_object_set_data(G_OBJECT (item), data, per_item_data);
-	g_object_set_data(G_OBJECT (item), "aop_per_item_data", per_item_data);
-
-	pidgin_set_accessible_label(item, label);
-
-	return item;
+	gtk_combo_box_set_model(GTK_COMBO_BOX(optmenu), new_aop_menu->model);
+	gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), new_aop_menu->default_item);
+	g_object_set_data_full(G_OBJECT(optmenu), "aop_menu", new_aop_menu, (GDestroyNotify)g_free);
 }
 
 static GdkPixbuf *
@@ -629,16 +596,19 @@ aop_option_menu_new(AopMenu *aop_menu, G
 static GtkWidget *
 aop_option_menu_new(AopMenu *aop_menu, GCallback cb, gpointer user_data)
 {
-	GtkWidget *optmenu;
+	GtkWidget *optmenu = NULL;
+	GtkCellRenderer *cr = NULL;
 
-	optmenu = gtk_option_menu_new();
+	optmenu = gtk_combo_box_new();
 	gtk_widget_show(optmenu);
-	gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), aop_menu->menu);
+	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(optmenu), cr = gtk_cell_renderer_pixbuf_new(), FALSE);
+	gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(optmenu), cr, "pixbuf", 0);
+	gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(optmenu), cr = gtk_cell_renderer_text_new(), TRUE);
+	gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(optmenu), cr, "text", 1);
 
-	if (aop_menu->default_item != -1)
-		gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), aop_menu->default_item);
-
-	g_object_set_data_full(G_OBJECT(optmenu), "aop_menu", aop_menu, (GDestroyNotify)g_free);
+	aop_option_menu_replace_menu(optmenu, aop_menu);
+	if (aop_menu->default_item == -1)
+		gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), 0);
 	g_object_set_data(G_OBJECT(optmenu), "user_data", user_data);
 
 	g_signal_connect(G_OBJECT(optmenu), "changed", G_CALLBACK(aop_menu_cb), cb);
@@ -647,32 +617,20 @@ static void
 }
 
 static void
-aop_option_menu_replace_menu(GtkWidget *optmenu, AopMenu *new_aop_menu)
-{
-	if (gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)))
-		gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu));
-
-	gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), new_aop_menu->menu);
-
-	if (new_aop_menu->default_item != -1)
-		gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), new_aop_menu->default_item);
-
-	g_object_set_data_full(G_OBJECT(optmenu), "aop_menu", new_aop_menu, (GDestroyNotify)g_free);
-}
-
-static void
 aop_option_menu_select_by_data(GtkWidget *optmenu, gpointer data)
 {
-	guint idx;
-	GList *llItr = NULL;
-
-	for (idx = 0, llItr = GTK_MENU_SHELL(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)))->children;
-	     llItr != NULL;
-	     llItr = llItr->next, idx++) {
-		if (data == g_object_get_data(G_OBJECT(llItr->data), "aop_per_item_data")) {
-			gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), idx);
-			break;
-		}
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	gpointer iter_data;
+	model = gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu));
+	if (gtk_tree_model_get_iter_first(model, &iter)) {
+		do {
+			gtk_tree_model_get(model, &iter, 2, &iter_data, -1);
+			if (iter_data == data) {
+				gtk_combo_box_set_active_iter(GTK_COMBO_BOX(optmenu), &iter);
+				return;
+			}
+		} while (gtk_tree_model_iter_next(model, &iter));
 	}
 }
 
@@ -683,16 +641,17 @@ create_protocols_menu(const char *defaul
 	PurplePluginProtocolInfo *prpl_info;
 	PurplePlugin *plugin;
 	GdkPixbuf *pixbuf = NULL;
-	GtkSizeGroup *sg;
+	GtkTreeIter iter;
+	GtkListStore *ls;
 	GList *p;
 	const char *gtalk_name = NULL;
 	int i;
 
+	ls = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
+
 	aop_menu = g_malloc0(sizeof(AopMenu));
 	aop_menu->default_item = -1;
-	aop_menu->menu = gtk_menu_new();
-	gtk_widget_show(aop_menu->menu);
-	sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+	aop_menu->model = GTK_TREE_MODEL(ls);
 
 	if (purple_find_prpl("prpl-jabber"))
 		gtalk_name = _("Google Talk");
@@ -707,14 +666,11 @@ create_protocols_menu(const char *defaul
 		if (gtalk_name && strcmp(gtalk_name, plugin->info->name) < 0) {
 			char *filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols",
 			                                  "16", "google-talk.png", NULL);
-			GtkWidget *item;
-
 			pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
 			g_free(filename);
 
-			gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu),
-				item = aop_menu_item_new(sg, pixbuf, gtalk_name, "prpl-jabber", "protocol"));
-			g_object_set_data(G_OBJECT(item), "fake", GINT_TO_POINTER(1));
+			gtk_list_store_append(ls, &iter);
+			gtk_list_store_set(ls, &iter, 0, pixbuf, 1, gtalk_name, 2, "prpl-jabber", -1);
 
 			if (pixbuf)
 				g_object_unref(pixbuf);
@@ -725,8 +681,8 @@ create_protocols_menu(const char *defaul
 
 		pixbuf = pidgin_create_prpl_icon_from_prpl(plugin, PIDGIN_PRPL_ICON_SMALL, NULL);
 
-		gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu),
-			aop_menu_item_new(sg, pixbuf, plugin->info->name, plugin->info->id, "protocol"));
+		gtk_list_store_append(ls, &iter);
+		gtk_list_store_set(ls, &iter, 0, pixbuf, 1, plugin->info->name, 2, plugin->info->id, -1);
 
 		if (pixbuf)
 			g_object_unref(pixbuf);
@@ -734,9 +690,6 @@ create_protocols_menu(const char *defaul
 		if (default_proto_id != NULL && !strcmp(plugin->info->id, default_proto_id))
 			aop_menu->default_item = i;
 	}
-
-	g_object_unref(sg);
-
 	return aop_menu;
 }
 
@@ -750,13 +703,13 @@ pidgin_protocol_option_menu_get_selected
 const char *
 pidgin_protocol_option_menu_get_selected(GtkWidget *optmenu)
 {
-	return (const char *)aop_option_menu_get_selected(optmenu, NULL);
+	return (const char *)aop_option_menu_get_selected(optmenu);
 }
 
 PurpleAccount *
 pidgin_account_option_menu_get_selected(GtkWidget *optmenu)
 {
-	return (PurpleAccount *)aop_option_menu_get_selected(optmenu, NULL);
+	return (PurpleAccount *)aop_option_menu_get_selected(optmenu);
 }
 
 static AopMenu *
@@ -768,7 +721,8 @@ create_account_menu(PurpleAccount *defau
 	GdkPixbuf *pixbuf = NULL;
 	GList *list;
 	GList *p;
-	GtkSizeGroup *sg;
+	GtkListStore *ls;
+	GtkTreeIter iter;
 	int i;
 	char buf[256];
 
@@ -777,11 +731,11 @@ create_account_menu(PurpleAccount *defau
 	else
 		list = purple_connections_get_all();
 
+	ls = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
+
 	aop_menu = g_malloc0(sizeof(AopMenu));
 	aop_menu->default_item = -1;
-	aop_menu->menu = gtk_menu_new();
-	gtk_widget_show(aop_menu->menu);
-	sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+	aop_menu->model = GTK_TREE_MODEL(ls);
 
 	for (p = list, i = 0; p != NULL; p = p->next, i++) {
 		PurplePlugin *plugin;
@@ -820,8 +774,8 @@ create_account_menu(PurpleAccount *defau
 					   purple_account_get_protocol_name(account));
 		}
 
-		gtk_menu_shell_append(GTK_MENU_SHELL(aop_menu->menu),
-			aop_menu_item_new(sg, pixbuf, buf, account, "account"));
+		gtk_list_store_append(ls, &iter);
+		gtk_list_store_set(ls, &iter, 0, pixbuf, 1, buf, 2, account, -1);
 
 		if (pixbuf)
 			g_object_unref(pixbuf);
@@ -829,9 +783,6 @@ create_account_menu(PurpleAccount *defau
 		if (default_account && account == default_account)
 			aop_menu->default_item = i;
 	}
-
-	g_object_unref(sg);
-
 	return aop_menu;
 }
 
@@ -842,7 +793,7 @@ regenerate_account_menu(GtkWidget *optme
 	PurpleAccount *account;
 	PurpleFilterAccountFunc filter_func;
 
-	account = (PurpleAccount *)aop_option_menu_get_selected(optmenu, NULL);
+	account = (PurpleAccount *)aop_option_menu_get_selected(optmenu);
 	show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu), "show_all"));
 	filter_func = g_object_get_data(G_OBJECT(optmenu), "filter_func");
 
============================================================
--- pidgin/gtkaccount.c	ed07c413bd0c6898814f2599871a3319dbf4755a
+++ pidgin/gtkaccount.c	a7f38abdd936279e2973d909129b00c88f1063e6
@@ -160,6 +160,37 @@ static void add_proxy_options(AccountPre
 static void add_protocol_options(AccountPrefsDialog *dialog);
 static void add_proxy_options(AccountPrefsDialog *dialog, GtkWidget *parent);
 
+static const char *
+google_talk_default_domain_hackery(GtkWidget *protocol_combo, const char *value_if_gtalk)
+{
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	const char *value = NULL;
+
+	model = gtk_combo_box_get_model(GTK_COMBO_BOX(protocol_combo));
+	if (model != NULL && gtk_combo_box_get_active_iter(GTK_COMBO_BOX(protocol_combo), &iter)) {
+		char *protocol = NULL;
+
+		/* protocol is not stored as G_TYPE_STRING in the model so no g_free necessary */
+		gtk_tree_model_get(model, &iter, 2, &protocol, -1);
+		if (protocol && !strcmp("prpl-jabber", protocol)) {
+			char *item_name = NULL;
+
+			gtk_tree_model_get(model, &iter, 1, &item_name, -1);
+			if (item_name) {
+				if (!strcmp(item_name, _("Google Talk")))
+					value = value_if_gtalk;
+				g_free(item_name);
+			}
+			/* If it's not GTalk, but still Jabber then the value is not NULL, it's empty */
+			if (NULL == value)
+				value = "";
+		}
+	}
+
+	return value;
+}
+
 static GtkWidget *
 add_pref_box(AccountPrefsDialog *dialog, GtkWidget *parent,
 			 const char *text, GtkWidget *widget)
@@ -417,8 +448,6 @@ add_login_options(AccountPrefsDialog *di
 	GtkWidget *hbox;
 	GtkWidget *vbox;
 	GtkWidget *entry;
-	GtkWidget *menu;
-	GtkWidget *item;
 	GList *user_splits;
 	GList *l, *l2;
 	char *username = NULL;
@@ -557,11 +586,8 @@ add_login_options(AccountPrefsDialog *di
 			value = purple_account_user_split_get_default_value(split);
 
 		/* Google Talk default domain hackery! */
-		menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(dialog->protocol_menu));
-		item = gtk_menu_get_active(GTK_MENU(menu));
-		if (value == NULL && g_object_get_data(G_OBJECT(item), "fake") &&
-			!strcmp(purple_account_user_split_get_text(split), _("Domain")))
-			value = "gmail.com";
+		if (!strcmp(_("Domain"), purple_account_user_split_get_text(split)) && !value)
+			value = google_talk_default_domain_hackery(dialog->protocol_menu, "gmail.com");
 
 		if (value != NULL)
 			gtk_entry_set_text(GTK_ENTRY(entry), value);
@@ -2607,5 +2633,3 @@ pidgin_account_uninit(void)
 	purple_signals_disconnect_by_handle(pidgin_account_get_handle());
 	purple_signals_unregister_by_instance(pidgin_account_get_handle());
 }
-
-
============================================================
--- pidgin/plugins/contact_priority.c	05cb2a07698773ca597cc8b6b0536895b74fba05
+++ pidgin/plugins/contact_priority.c	b98d3468b8a654740033da9db214f3323356b614
@@ -35,11 +35,11 @@ static void
 }
 
 static void
-account_update(GtkWidget *widget, GtkOptionMenu *optmenu)
+account_update(GtkWidget *widget, GtkWidget *optmenu)
 {
 	PurpleAccount *account = NULL;
 
-	account = g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(optmenu)))), "account");
+	account = pidgin_account_option_menu_get_selected(optmenu);
 	purple_account_set_int(account, "score", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)));
 }
 
@@ -147,8 +147,7 @@ get_config_frame(PurplePlugin *plugin)
 	gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
 
 	/* this is where we set up the spin button we made above */
-	account = g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu))))),
-	                            "account");
+	account = pidgin_account_option_menu_get_selected(optmenu);
 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
 	                          (gdouble)purple_account_get_int(account, "score", 0));
 	gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT(adj));


More information about the Commits mailing list