Mercurial > pidgin
changeset 32622:02c755cfef37
Apply final changes from nix_nix's patch.
Closes #1332.
committer: Elliott Sales de Andrade <qulogic@pidgin.im>
author | Gabriel Schulhof <nix@go-nix.ca> |
---|---|
date | Mon, 26 Jul 2010 05:35:10 +0000 |
parents | 673c545af5b0 |
children | 14061184692c |
files | pidgin/gtkaccount.c pidgin/gtkutils.c pidgin/plugins/contact_priority.c |
diffstat | 3 files changed, 98 insertions(+), 124 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkaccount.c Mon Jul 26 04:24:36 2010 +0000 +++ b/pidgin/gtkaccount.c Mon Jul 26 05:35:10 2010 +0000 @@ -160,6 +160,37 @@ 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 @@ GtkWidget *hbox; GtkWidget *vbox; GtkWidget *entry; - GtkWidget *menu; - GtkWidget *item; GList *user_splits; GList *l, *l2; char *username = NULL; @@ -557,11 +586,8 @@ 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 @@ purple_signals_disconnect_by_handle(pidgin_account_get_handle()); purple_signals_unregister_by_instance(pidgin_account_get_handle()); } - -
--- a/pidgin/gtkutils.c Mon Jul 26 04:24:36 2010 +0000 +++ b/pidgin/gtkutils.c Mon Jul 26 05:35:10 2010 +0000 @@ -70,7 +70,7 @@ #include "pidgin/minidialog.h" typedef struct { - GtkWidget *menu; + GtkTreeModel *model; gint default_item; } AopMenu; @@ -527,68 +527,35 @@ } 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 @@ static GtkWidget * aop_option_menu_new(AopMenu *aop_menu, GCallback cb, gpointer user_data) { - GtkWidget *optmenu; - - optmenu = gtk_option_menu_new(); + GtkWidget *optmenu = NULL; + GtkCellRenderer *cr = NULL; + + optmenu = gtk_combo_box_new(); gtk_widget_show(optmenu); - gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), aop_menu->menu); - - 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); + 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); + + 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 -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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ GdkPixbuf *pixbuf = NULL; GList *list; GList *p; - GtkSizeGroup *sg; + GtkListStore *ls; + GtkTreeIter iter; int i; char buf[256]; @@ -777,11 +731,11 @@ 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 @@ 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 @@ if (default_account && account == default_account) aop_menu->default_item = i; } - - g_object_unref(sg); - return aop_menu; } @@ -842,7 +793,7 @@ 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");
--- a/pidgin/plugins/contact_priority.c Mon Jul 26 04:24:36 2010 +0000 +++ b/pidgin/plugins/contact_priority.c Mon Jul 26 05:35:10 2010 +0000 @@ -35,11 +35,11 @@ } 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 @@ 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));