diff options
Diffstat (limited to 'addressbook/gui/component/select-names')
3 files changed, 122 insertions, 179 deletions
diff --git a/addressbook/gui/component/select-names/e-select-names-manager.c b/addressbook/gui/component/select-names/e-select-names-manager.c index b53cf924f2..a3875cea97 100644 --- a/addressbook/gui/component/select-names/e-select-names-manager.c +++ b/addressbook/gui/component/select-names/e-select-names-manager.c @@ -141,7 +141,7 @@ get_entry_info (EEntry *entry) } static void -popup_cb (EEntry *eentry, GdkEventButton *ev, gint pos, gpointer user_data) +populate_popup_cb (EEntry *eentry, GdkEventButton *ev, gint pos, GtkWidget *menu, gpointer user_data) { ESelectNamesTextModel *text_model; @@ -150,7 +150,7 @@ popup_cb (EEntry *eentry, GdkEventButton *ev, gint pos, gpointer user_data) NULL); g_assert (E_IS_SELECT_NAMES_TEXT_MODEL (text_model)); - e_select_names_popup (text_model, ev, pos, GTK_WIDGET (eentry)); + e_select_names_populate_popup (menu, text_model, ev, pos, GTK_WIDGET (eentry)); } #if 0 @@ -283,8 +283,8 @@ e_select_names_manager_entry_new (ESelectNamesManager *manager, ESelectNamesMode g_object_ref (model); g_signal_connect (entry->entry, - "popup", - G_CALLBACK (popup_cb), + "populate_popup", + G_CALLBACK (populate_popup_cb), entry); g_signal_connect (entry->entry->canvas, diff --git a/addressbook/gui/component/select-names/e-select-names-popup.c b/addressbook/gui/component/select-names/e-select-names-popup.c index 86779519f3..20f740b967 100644 --- a/addressbook/gui/component/select-names/e-select-names-popup.c +++ b/addressbook/gui/component/select-names/e-select-names-popup.c @@ -30,12 +30,14 @@ #include <string.h> #include <glib.h> +#include <gtk/gtkimage.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkimagemenuitem.h> #include <gtk/gtkcheckmenuitem.h> +#include <gtk/gtkradiomenuitem.h> +#include <gtk/gtkseparatormenuitem.h> #include <gtk/gtklabel.h> #include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-app.h> -#include <libgnomeui/gnome-app-helper.h> -#include <libgnomeui/gnome-popup-menu.h> #include <addressbook/backend/ebook/e-book-util.h> #include <addressbook/gui/contact-editor/e-contact-editor.h> @@ -43,6 +45,9 @@ #include "e-addressbook-util.h" #include "e-select-names-popup.h" +#define LIST_ICON_FILENAME "contact-list-16.png" +#define CONTACT_ICON_FILENAME "evolution-contacts-mini.png" + typedef struct _PopupInfo PopupInfo; struct _PopupInfo { ESelectNamesTextModel *text_model; @@ -156,14 +161,6 @@ remove_recipient_cb (GtkWidget *w, gpointer user_data) } static void -add_remove_recipient (GnomeUIInfo *uiinfo, PopupInfo *info) -{ - uiinfo->type = GNOME_APP_UI_ITEM; - uiinfo->label = _("Remove"); - uiinfo->moreinfo = remove_recipient_cb; -} - -static void remove_all_recipients_cb (GtkWidget *w, gpointer user_data) { PopupInfo *info = (PopupInfo *) user_data; @@ -171,14 +168,6 @@ remove_all_recipients_cb (GtkWidget *w, gpointer user_data) } static void -add_remove_all_recipients (GnomeUIInfo *uiinfo, PopupInfo *info) -{ - uiinfo->type = GNOME_APP_UI_ITEM; - uiinfo->label = _("Remove All"); - uiinfo->moreinfo = remove_all_recipients_cb; -} - -static void toggle_html_mail_cb (GtkWidget *w, gpointer user_data) { PopupInfo *info = (PopupInfo *) user_data; @@ -195,160 +184,124 @@ toggle_html_mail_cb (GtkWidget *w, gpointer user_data) } static void -add_html_mail (GnomeUIInfo *uiinfo, PopupInfo *info) -{ - uiinfo->type = GNOME_APP_UI_TOGGLEITEM; - uiinfo->label = _("Send HTML Mail?"); - uiinfo->moreinfo = toggle_html_mail_cb; -} - -static void -init_html_mail (GnomeUIInfo *uiinfo, PopupInfo *info) -{ - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (uiinfo->widget), - e_destination_get_html_mail_pref (info->dest)); -} - -static void -set_uiinfo_label (GnomeUIInfo *uiinfo, const gchar *str) -{ - GtkWidget *label; - GList *item_children; - - item_children = gtk_container_get_children (GTK_CONTAINER (uiinfo->widget)); - label = item_children->data; - g_list_free (item_children); - gtk_label_set_text (GTK_LABEL (label), str); -} - -#define ARBITRARY_UIINFO_LIMIT 64 -static GtkWidget * -popup_menu_card (PopupInfo *info) +populate_popup_card (GtkWidget *pop, gboolean list, PopupInfo *info) { - GnomeUIInfo uiinfo[ARBITRARY_UIINFO_LIMIT]; - GnomeUIInfo radioinfo[ARBITRARY_UIINFO_LIMIT]; - gboolean using_radio = FALSE; + GtkWidget *image; ECard *card; - gint i=0; - GtkWidget *pop; EIterator *iterator; - gint html_toggle; - gint mail_label = -1; - const gchar *mail_label_str = NULL; - - /* - * Build up our GnomeUIInfo array. - */ - - memset (uiinfo, 0, sizeof (uiinfo)); - memset (radioinfo, 0, sizeof (radioinfo)); + GtkWidget *menuitem; card = e_destination_get_card (info->dest); - /* Use an empty label for now, we'll fill it later. - If we set uiinfo label to contact name here, gnome_popup_menu_new - could screw it up trying make a "translation". */ - uiinfo[i].type = GNOME_APP_UI_ITEM; - uiinfo[i].label = ""; - ++i; - - uiinfo[i].type = GNOME_APP_UI_SEPARATOR; - ++i; +#if 0 + menuitem = gtk_separator_menu_item_new(); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); + + menuitem = gtk_menu_item_new_with_label (_("Remove All")); + g_signal_connect (menuitem, "activate", + G_CALLBACK (remove_all_recipients_cb), + info); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); + + menuitem = gtk_menu_item_new_with_label (_("Remove")); + g_signal_connect (menuitem, "activate", + G_CALLBACK (remove_recipient_cb), + info); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); + + menuitem = gtk_menu_item_new_with_label (list ? _("View Contact List") : _("View Contact Info")); + g_signal_connect (menuitem, "activate", + G_CALLBACK (edit_contact_info_cb), + info); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); + + menuitem = gtk_check_menu_item_new_with_label (_("Send HTML Mail?")); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), + e_destination_get_html_mail_pref (info->dest)); + g_signal_connect (menuitem, "toggled", + G_CALLBACK (toggle_html_mail_cb), + info); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); +#endif if (card->email) { + menuitem = gtk_separator_menu_item_new(); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); if (e_list_length (card->email) > 1) { - gint j = 0; - - using_radio = TRUE; + GSList *radiogroup = NULL; + gint n = e_destination_get_email_num (info->dest); + gint j = e_list_length (card->email) - 1; iterator = e_list_get_iterator (card->email); - for (e_iterator_reset (iterator); e_iterator_is_valid (iterator); e_iterator_next (iterator)) { - gchar *label = (gchar *)e_iterator_get (iterator); - if (label && *label) { - radioinfo[j].label = ""; - radioinfo[j].type = GNOME_APP_UI_ITEM; - radioinfo[j].moreinfo = change_email_num_cb; - ++j; + for (e_iterator_last (iterator); e_iterator_is_valid (iterator); e_iterator_prev (iterator)) { + char *email = (char *)e_iterator_get (iterator); + char *label = NULL; + + if (!strncmp (email, "<?xml", 5)) { + EDestination *dest = e_destination_import (email); + if (dest) { + label = g_strdup (e_destination_get_textrep (dest, TRUE)); + g_object_unref (dest); + } + } + else { + label = g_strdup (email); } - } - g_object_unref (iterator); - - radioinfo[j].type = GNOME_APP_UI_ENDOFINFO; - - uiinfo[i].type = GNOME_APP_UI_RADIOITEMS; - uiinfo[i].moreinfo = radioinfo; - ++i; - - } else { - uiinfo[i].type = GNOME_APP_UI_ITEM; - uiinfo[i].label = ""; - mail_label_str = e_destination_get_email (info->dest); - mail_label = i; - ++i; - } - - uiinfo[i].type = GNOME_APP_UI_SEPARATOR; - ++i; - } - - add_html_mail (&(uiinfo[i]), info); - html_toggle = i; - ++i; - - uiinfo[i].type = GNOME_APP_UI_ITEM; - uiinfo[i].label = N_("View Contact Info"); - uiinfo[i].moreinfo = edit_contact_info_cb; - ++i; - - add_remove_recipient (&(uiinfo[i]), info); - ++i; - - add_remove_all_recipients (&(uiinfo[i]), info); - ++i; - - uiinfo[i].type = GNOME_APP_UI_ENDOFINFO; - - /* - * Now do something with it... - */ - pop = gnome_popup_menu_new (uiinfo); + if (list) { + menuitem = gtk_menu_item_new_with_label (label); + } + else { + menuitem = gtk_radio_menu_item_new_with_label (radiogroup, label); + g_signal_connect (menuitem, "toggled", + G_CALLBACK (change_email_num_cb), + info); + if (j == n) + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE); + + g_object_set_data (G_OBJECT (menuitem), "number", GINT_TO_POINTER (j)); + radiogroup = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem)); + } - init_html_mail (&(uiinfo[html_toggle]), info); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); - /* Properly handle the names & e-mail addresses so that they don't get leaked and so that - underscores are interpreted as key accelerators. This sucks. */ + j--; - set_uiinfo_label (&(uiinfo[0]), e_destination_get_name (info->dest)); - - if (mail_label >= 0) { - set_uiinfo_label (&(uiinfo[mail_label]), e_destination_get_email (info->dest)); - } - - if (using_radio) { - gint n = e_destination_get_email_num (info->dest); - gint j = 0; - iterator = e_list_get_iterator (card->email); - for (e_iterator_reset (iterator); e_iterator_is_valid (iterator); e_iterator_next (iterator)) { - gchar *label = (gchar *)e_iterator_get (iterator); - if (label && *label) { - set_uiinfo_label (&(radioinfo[j]), label); - - g_object_set_data (G_OBJECT (radioinfo[j].widget), "number", GINT_TO_POINTER (j)); - - if (j == n) - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (radioinfo[n].widget), TRUE); - - ++j; + g_free (label); } + + g_object_unref (iterator); + } else { + menuitem = gtk_menu_item_new_with_label (e_destination_get_email (info->dest)); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); } - g_object_unref (iterator); } - return pop; + menuitem = gtk_separator_menu_item_new (); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); + + image = gtk_image_new_from_file (list + ? EVOLUTION_IMAGESDIR "/" LIST_ICON_FILENAME + : EVOLUTION_IMAGESDIR "/" CONTACT_ICON_FILENAME); + gtk_widget_show (image); + menuitem = gtk_image_menu_item_new_with_label (e_destination_get_name (info->dest)); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), + image); + gtk_widget_show (menuitem); + gtk_menu_shell_prepend (GTK_MENU_SHELL (pop), menuitem); } +#if 0 static GtkWidget * popup_menu_list (PopupInfo *info) { @@ -453,11 +406,9 @@ quick_add_cb (GtkWidget *w, gpointer user_data) static GtkWidget * popup_menu_nocard (PopupInfo *info) { - GnomeUIInfo uiinfo[ARBITRARY_UIINFO_LIMIT]; gint i=0; GtkWidget *pop; const gchar *str; - gint html_toggle; memset (uiinfo, 0, sizeof (uiinfo)); @@ -472,7 +423,6 @@ popup_menu_nocard (PopupInfo *info) ++i; add_html_mail (&(uiinfo[i]), info); - html_toggle = i; ++i; uiinfo[i].type = GNOME_APP_UI_ITEM; @@ -503,17 +453,19 @@ popup_menu_nocard (PopupInfo *info) return pop; } +#endif void -e_select_names_popup (ESelectNamesTextModel *text_model, GdkEventButton *ev, gint pos, GtkWidget *for_widget) +e_select_names_populate_popup (GtkWidget *menu, ESelectNamesTextModel *text_model, + GdkEventButton *ev, gint pos, GtkWidget *for_widget) { ESelectNamesModel *model; - GtkWidget *popup; PopupInfo *info; EDestination *dest; ECard *card; gint index; + g_return_if_fail (GTK_IS_MENU_SHELL (menu)); g_return_if_fail (E_IS_SELECT_NAMES_TEXT_MODEL (text_model)); g_return_if_fail (ev); g_return_if_fail (0 <= pos); @@ -534,26 +486,16 @@ e_select_names_popup (ESelectNamesTextModel *text_model, GdkEventButton *ev, gin info = popup_info_new (text_model, dest, pos, index); if (e_destination_contains_card (dest)) { - if (e_destination_is_evolution_list (dest)) - popup = popup_menu_list (info); - else - popup = popup_menu_card (info); + populate_popup_card (menu, e_destination_is_evolution_list (dest), info); } else { - popup = popup_menu_nocard (info); +#if 0 + popup_menu_nocard (info); +#endif } - if (popup) { - /* Clean up our info item after we've made our selection. */ - g_signal_connect (popup, - "selection-done", - G_CALLBACK (popup_info_cleanup), - info); - - gnome_popup_menu_do_popup (popup, NULL, NULL, ev, info, for_widget); - - } else { - - popup_info_free (info); - - } + /* Clean up our info item after we've made our selection. */ + g_signal_connect (menu, + "selection-done", + G_CALLBACK (popup_info_cleanup), + info); } diff --git a/addressbook/gui/component/select-names/e-select-names-popup.h b/addressbook/gui/component/select-names/e-select-names-popup.h index b88a480397..531275190b 100644 --- a/addressbook/gui/component/select-names/e-select-names-popup.h +++ b/addressbook/gui/component/select-names/e-select-names-popup.h @@ -29,7 +29,8 @@ #include "e-select-names-text-model.h" -void e_select_names_popup (ESelectNamesTextModel *text_model, GdkEventButton *ev, gint pos, GtkWidget *for_widget); +void e_select_names_populate_popup (GtkWidget *menu, ESelectNamesTextModel *text_model, + GdkEventButton *ev, gint pos, GtkWidget *for_widget); #endif /* __E_SELECT_NAMES_POPUP_H__ */ |