diff options
author | Not Zed <NotZed@Ximian.com> | 2004-10-06 11:22:22 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-10-06 11:22:22 +0800 |
commit | f745553229591ed3f620761b91e7ed447d1800fa (patch) | |
tree | beae7ddecdf59e907a4fea5d300ae38e9c58cc46 /addressbook/gui/widgets/e-addressbook-view.c | |
parent | d80f89af7503afd6460698e7cc0f84cf84a6eb4d (diff) | |
download | gsoc2013-evolution-f745553229591ed3f620761b91e7ed447d1800fa.tar gsoc2013-evolution-f745553229591ed3f620761b91e7ed447d1800fa.tar.gz gsoc2013-evolution-f745553229591ed3f620761b91e7ed447d1800fa.tar.bz2 gsoc2013-evolution-f745553229591ed3f620761b91e7ed447d1800fa.tar.lz gsoc2013-evolution-f745553229591ed3f620761b91e7ed447d1800fa.tar.xz gsoc2013-evolution-f745553229591ed3f620761b91e7ed447d1800fa.tar.zst gsoc2013-evolution-f745553229591ed3f620761b91e7ed447d1800fa.zip |
convert to using EABPopup. (sources): remove dead code.
2004-10-01 Not Zed <NotZed@Ximian.com>
* gui/widgets/e-addressbook-view.c (do_popup_menu): convert to
using EABPopup.
(sources): remove dead code.
(has_email_address_1, get_has_email_address): removed now
redundant code.
(save_as, send_as, send_to, print, copy, paste, cut, delete)
(copy_to_folder, move_to_folder, new_card, new_list): new api.
(free_popup_info): dead.
(print_envelope): not pining.
(get_contact_list): take a popup target instead, don't ref.
(get_contact_list_1): not required no more.
(contact_and_book_free): same.
(delete): call eab_view_delete_selection.
(eab_view_delete_selection): do the actual delete here.
* gui/widgets/eab-popup.c (eab_popup_target_new_select): implement.
2004-10-01 Not Zed <NotZed@Ximian.com>
* gui/widgets/eab-popup.[ch]: addressbook popup driver.
* gui/component/addressbook-view.c (delete_addressbook_cb): use
e-error for the message prompt. don't bother keeping it around,
it can never be re-sensitised anyway.
(book_removed): no longer destroy the original dialogue.
* addressbook-errors.xml: add ask-delete for deleting
addressbooks.
* gui/component/addressbook-view.c (addressbook_view_init):
connect to popup_event rather than fill_popup_menu now.
(fill_popup_menu_callback): renamed to popup_event_callback,
changed to use epopup.
(add_popup_menu_item): remove, no longer needed.
svn path=/trunk/; revision=27466
Diffstat (limited to 'addressbook/gui/widgets/e-addressbook-view.c')
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-view.c | 418 |
1 files changed, 149 insertions, 269 deletions
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c index e4fe2e287a..f716ea8624 100644 --- a/addressbook/gui/widgets/e-addressbook-view.c +++ b/addressbook/gui/widgets/e-addressbook-view.c @@ -29,7 +29,6 @@ #include <gtk/gtkscrolledwindow.h> #include <gal/e-table/e-table-scrolled.h> #include <gal/e-table/e-table-model.h> -#include <gal/widgets/e-popup-menu.h> #include <gal/widgets/e-gui-utils.h> #include <gal/menus/gal-view-factory-etable.h> #include <gal/menus/gal-view-etable.h> @@ -44,6 +43,7 @@ #include "addressbook/printing/e-contact-print.h" #include "addressbook/printing/e-contact-print-envelope.h" #include "addressbook/gui/search/e-addressbook-search-dialog.h" +#include "addressbook/gui/widgets/eab-popup.h" #include "e-util/e-categories-master-list-wombat.h" #include "e-util/e-sexp.h" @@ -771,7 +771,6 @@ get_selection_model (EABView *view) /* Popup menu stuff */ typedef struct { EABView *view; - EPopupMenu *submenu; gpointer closure; } ContactAndBook; @@ -781,371 +780,221 @@ contact_and_book_get_selection_model (ContactAndBook *contact_and_book) return get_selection_model (contact_and_book->view); } -static void -contact_and_book_free (ContactAndBook *contact_and_book) -{ - EABView *view = contact_and_book->view; - ESelectionModel *selection; - - if (contact_and_book->submenu) - gal_view_instance_free_popup_menu (view->view_instance, - contact_and_book->submenu); - - selection = contact_and_book_get_selection_model (contact_and_book); - if (selection) - e_selection_model_right_click_up(selection); - - g_object_unref (view); -} - -static void -get_contact_list_1(gint model_row, - gpointer closure) -{ - ContactAndBook *contact_and_book; - GList **list; - EABView *view; - EContact *contact; - - contact_and_book = closure; - list = contact_and_book->closure; - view = contact_and_book->view; - - contact = eab_model_get_contact(view->model, model_row); - *list = g_list_prepend(*list, contact); -} - static GList * -get_contact_list (ContactAndBook *contact_and_book) +get_contact_list (EABPopupTargetSelect *t) { GList *list = NULL; - ESelectionModel *selection; + int i; - selection = contact_and_book_get_selection_model (contact_and_book); - - if (selection) { - contact_and_book->closure = &list; - e_selection_model_foreach (selection, get_contact_list_1, contact_and_book); - } + for (i=0;i<t->cards->len;i++) + list = g_list_prepend(list, t->cards->pdata[i]); return list; } static void -has_email_address_1(gint model_row, - gpointer closure) +save_as (EPopup *ep, EPopupItem *pitem, void *data) { - ContactAndBook *contact_and_book; - gboolean *has_email; - EABView *view; - const EContact *contact; - GList *email; - - contact_and_book = closure; - has_email = contact_and_book->closure; - view = contact_and_book->view; + /*ContactAndBook *contact_and_book = data;*/ + GList *contacts = get_contact_list ((EABPopupTargetSelect *)ep->target); - if (*has_email) - return; - - contact = eab_model_contact_at(view->model, model_row); - - email = e_contact_get (E_CONTACT (contact), E_CONTACT_EMAIL); - - if (g_list_length (email) > 0) - *has_email = TRUE; - - g_list_foreach (email, (GFunc)g_free, NULL); - g_list_free (email); -} - -static gboolean -get_has_email_address (ContactAndBook *contact_and_book) -{ - ESelectionModel *selection; - gboolean has_email = FALSE; - - selection = contact_and_book_get_selection_model (contact_and_book); - - if (selection) { - contact_and_book->closure = &has_email; - e_selection_model_foreach (selection, has_email_address_1, contact_and_book); - } - - return has_email; -} - -static void -save_as (GtkWidget *widget, ContactAndBook *contact_and_book) -{ - GList *contacts = get_contact_list (contact_and_book); if (contacts) { eab_contact_list_save(_("Save as VCard..."), contacts, NULL); - e_free_object_list(contacts); + g_list_free(contacts); } } static void -send_as (GtkWidget *widget, ContactAndBook *contact_and_book) +send_as (EPopup *ep, EPopupItem *pitem, void *data) { - GList *contacts = get_contact_list (contact_and_book); + /*ContactAndBook *contact_and_book = data;*/ + GList *contacts = get_contact_list ((EABPopupTargetSelect *)ep->target); + if (contacts) { eab_send_contact_list(contacts, EAB_DISPOSITION_AS_ATTACHMENT); - e_free_object_list(contacts); + g_list_free(contacts); } } static void -send_to (GtkWidget *widget, ContactAndBook *contact_and_book) - +send_to (EPopup *ep, EPopupItem *pitem, void *data) { - GList *contacts = get_contact_list (contact_and_book); + /*ContactAndBook *contact_and_book = data;*/ + GList *contacts = get_contact_list ((EABPopupTargetSelect *)ep->target); if (contacts) { eab_send_contact_list(contacts, EAB_DISPOSITION_AS_TO); - e_free_object_list(contacts); + g_list_free(contacts); } } static void -print (GtkWidget *widget, ContactAndBook *contact_and_book) +print (EPopup *ep, EPopupItem *pitem, void *data) { - GList *contacts = get_contact_list (contact_and_book); - if (contacts) { - if (contacts->next) - gtk_widget_show(e_contact_print_contact_list_dialog_new(contacts)); - else - gtk_widget_show(e_contact_print_contact_dialog_new(contacts->data)); - e_free_object_list(contacts); - } -} + /*ContactAndBook *contact_and_book = data;*/ + EABPopupTargetSelect *t = (EABPopupTargetSelect *)ep->target; -#if 0 /* Envelope printing is disabled for Evolution 1.0. */ -static void -print_envelope (GtkWidget *widget, ContactAndBook *contact_and_book) -{ - GList *cards = get_card_list (contact_and_book); - if (cards) { - gtk_widget_show(e_contact_list_print_envelope_dialog_new(contact_and_book->card)); - e_free_object_list(cards); + if (t->cards->len == 1) { + gtk_widget_show(e_contact_print_contact_dialog_new(t->cards->pdata[0])); + } else { + GList *contacts = get_contact_list(t); + + gtk_widget_show(e_contact_print_contact_list_dialog_new(contacts)); + g_list_free(contacts); } } -#endif static void -copy (GtkWidget *widget, ContactAndBook *contact_and_book) +copy (EPopup *ep, EPopupItem *pitem, void *data) { + ContactAndBook *contact_and_book = data; + eab_view_copy (contact_and_book->view); } static void -paste (GtkWidget *widget, ContactAndBook *contact_and_book) +paste (EPopup *ep, EPopupItem *pitem, void *data) { + ContactAndBook *contact_and_book = data; + eab_view_paste (contact_and_book->view); } static void -cut (GtkWidget *widget, ContactAndBook *contact_and_book) +cut (EPopup *ep, EPopupItem *pitem, void *data) { + ContactAndBook *contact_and_book = data; + eab_view_cut (contact_and_book->view); } static void -delete (GtkWidget *widget, ContactAndBook *contact_and_book) +delete (EPopup *ep, EPopupItem *pitem, void *data) { - if (eab_editor_confirm_delete(GTK_WINDOW(gtk_widget_get_toplevel(contact_and_book->view->widget)))) { - EBook *book; - GList *list = get_contact_list(contact_and_book); - GList *iterator; - gboolean bulk_remove = FALSE; + ContactAndBook *contact_and_book = data; - bulk_remove = e_book_check_static_capability (contact_and_book->view->model->book, - "bulk-remove"); - - g_object_get(contact_and_book->view->model, - "book", &book, - NULL); - - if (bulk_remove) { - GList *ids = NULL; - - for (iterator = list; iterator; iterator = iterator->next) { - EContact *contact = iterator->data; - ids = g_list_prepend (ids, (char*)e_contact_get_const (contact, E_CONTACT_UID)); - } - - /* Remove the cards all at once. */ - /* XXX no callback specified... ugh */ - e_book_async_remove_contacts (book, - ids, - NULL, - NULL); - - g_list_free (ids); - } - else { - for (iterator = list; iterator; iterator = iterator->next) { - EContact *contact = iterator->data; - /* Remove the card. */ - /* XXX no callback specified... ugh */ - e_book_async_remove_contact (book, - contact, - NULL, - NULL); - } - } - e_free_object_list(list); - g_object_unref(book); - } + eab_view_delete_selection(contact_and_book->view); } static void -copy_to_folder (GtkWidget *widget, ContactAndBook *contact_and_book) +copy_to_folder (EPopup *ep, EPopupItem *pitem, void *data) { + ContactAndBook *contact_and_book = data; + eab_view_copy_to_folder (contact_and_book->view); } static void -move_to_folder (GtkWidget *widget, ContactAndBook *contact_and_book) +move_to_folder (EPopup *ep, EPopupItem *pitem, void *data) { - eab_view_move_to_folder (contact_and_book->view); -} + ContactAndBook *contact_and_book = data; -static void -free_popup_info (GtkWidget *w, ContactAndBook *contact_and_book) -{ - contact_and_book_free (contact_and_book); + eab_view_move_to_folder (contact_and_book->view); } static void -new_card (GtkWidget *widget, ContactAndBook *contact_and_book) +new_card (EPopup *ep, EPopupItem *pitem, void *data) { - EBook *book; + /*ContactAndBook *contact_and_book = data;*/ EContact *contact = e_contact_new(); - g_object_get(contact_and_book->view->model, - "book", &book, - NULL); - - eab_show_contact_editor (book, contact, TRUE, TRUE); - g_object_unref (book); + eab_show_contact_editor (((EABPopupTargetSelect *)ep->target)->book, contact, TRUE, TRUE); g_object_unref (contact); } static void -new_list (GtkWidget *widget, ContactAndBook *contact_and_book) +new_list (EPopup *ep, EPopupItem *pitem, void *data) { - EBook *book; + /*ContactAndBook *contact_and_book = data;*/ EContact *contact = e_contact_new (); - g_object_get(contact_and_book->view->model, - "book", &book, - NULL); - eab_show_contact_list_editor (book, contact, TRUE, TRUE); - g_object_unref(book); + eab_show_contact_list_editor (((EABPopupTargetSelect *)ep->target)->book, contact, TRUE, TRUE); g_object_unref(contact); } -#if 0 +static EPopupItem eabv_popup_items[] = { + { E_POPUP_ITEM, "10.new", N_("New Contact..."), new_card, NULL, "stock_contact", EAB_POPUP_SELECT_EDITABLE}, + { E_POPUP_ITEM, "15.newlist", N_("New Contact List..."), new_list, NULL, "stock_contact-list", EAB_POPUP_SELECT_EDITABLE }, + + { E_POPUP_BAR, "20.bar" }, + { E_POPUP_ITEM, "30.saveas", N_("Save as VCard..."), save_as, NULL, "stock_save-as", EAB_POPUP_SELECT_MANY }, + { E_POPUP_ITEM, "40.forward", N_("Forward Contact"), send_as, NULL, "stock_mail-forward", EAB_POPUP_SELECT_MANY }, + { E_POPUP_ITEM, "50.mailto", N_("Send Message to Contact"), send_to, NULL, "stock_mail-send", EAB_POPUP_SELECT_MANY|EAB_POPUP_SELECT_EMAIL }, + { E_POPUP_ITEM, "60.print", N_("Print"), print, NULL, "stock_print", EAB_POPUP_SELECT_MANY }, + + { E_POPUP_BAR, "70.bar" }, + { E_POPUP_ITEM, "80.copyto", N_("Copy to Address Book..."), copy_to_folder, NULL, NULL, EAB_POPUP_SELECT_MANY }, + { E_POPUP_ITEM, "90.moveto", N_("Move to Address Book..."), move_to_folder, NULL, NULL, EAB_POPUP_SELECT_MANY|EAB_POPUP_SELECT_EDITABLE }, + + { E_POPUP_BAR, "a0.bar" }, + { E_POPUP_BAR, "b0.cut", N_("Cut"), cut, NULL, "stock_cut", EAB_POPUP_SELECT_MANY|EAB_POPUP_SELECT_EDITABLE }, + { E_POPUP_ITEM, "c0.copy", N_("Copy"), copy, NULL, "stock_copy", EAB_POPUP_SELECT_MANY }, + { E_POPUP_ITEM, "d0.paste", N_("Paste"), paste, NULL, "stock_paste", EAB_POPUP_SELECT_EDITABLE }, + { E_POPUP_ITEM, "e0.delete", N_("Delete"), delete, NULL, "stock_delete", EAB_POPUP_SELECT_EDITABLE|EAB_POPUP_SELECT_MANY }, +}; + static void -sources (GtkWidget *widget, ContactAndBook *contact_and_book) +get_card_1(gint model_row, void *data) { - BonoboControl *control; - GNOME_Evolution_ShellView shell_view; - CORBA_Environment ev; + ContactAndBook *contact_and_book = data; + EContact *contact; - control = g_object_get_data (G_OBJECT (gcal), "control"); - if (control == NULL) - return; + contact = eab_model_get_contact(contact_and_book->view->model, model_row); + if (contact) + g_ptr_array_add((GPtrArray *)contact_and_book->closure, contact); +} - shell_view = get_shell_view_interface (control); - if (shell_view == CORBA_OBJECT_NIL) - return; +static void +eabv_popup_free(EPopup *ep, GSList *list, void *data) +{ + ContactAndBook *cab = data; + ESelectionModel *selection; - CORBA_exception_init (&ev); - - GNOME_Evolution_ShellView_showSettings (shell_view, &ev); - - if (BONOBO_EX (&ev)) - g_message ("control_util_show_settings(): Could not show settings"); + /* NB: this looks strange to me */ + selection = contact_and_book_get_selection_model(cab); + if (selection) + e_selection_model_right_click_up(selection); - CORBA_exception_free (&ev); + g_slist_free(list); + g_object_unref(cab->view); + g_free(cab); } -#endif - -#define POPUP_READONLY_MASK 0x1 -#define POPUP_NOSELECTION_MASK 0x2 -#define POPUP_NOEMAIL_MASK 0x4 static void do_popup_menu(EABView *view, GdkEvent *event) { + EABPopup *ep; + EABPopupTargetSelect *t; + GSList *menus = NULL; + int i; + GtkMenu *menu; + GPtrArray *cards = g_ptr_array_new(); ContactAndBook *contact_and_book; - GtkMenu *popup; - EPopupMenu *submenu = NULL; ESelectionModel *selection_model; - gboolean selection = FALSE; - - EPopupMenu menu[] = { - E_POPUP_ITEM (N_("New Contact..."), G_CALLBACK(new_card), POPUP_READONLY_MASK), - E_POPUP_ITEM (N_("New Contact List..."), G_CALLBACK(new_list), POPUP_READONLY_MASK), - E_POPUP_SEPARATOR, -#if 0 - E_POPUP_ITEM (N_("Go to Folder..."), G_CALLBACK (goto_folder), 0), - E_POPUP_ITEM (N_("Import..."), G_CALLBACK (import), POPUP_READONLY_MASK), - E_POPUP_SEPARATOR, - E_POPUP_ITEM (N_("Search for Contacts..."), G_CALLBACK (search), 0), - E_POPUP_ITEM (N_("Address Book Sources..."), G_CALLBACK (sources), 0), - E_POPUP_SEPARATOR, - E_POPUP_ITEM (N_("Pilot Settings..."), G_CALLBACK (pilot_settings), 0), -#endif - E_POPUP_SEPARATOR, - E_POPUP_ITEM (N_("Save as VCard..."), G_CALLBACK(save_as), POPUP_NOSELECTION_MASK), - E_POPUP_ITEM (N_("Forward Contact"), G_CALLBACK(send_as), POPUP_NOSELECTION_MASK), - E_POPUP_ITEM (N_("Send Message to Contact"), G_CALLBACK(send_to), POPUP_NOSELECTION_MASK | POPUP_NOEMAIL_MASK), - E_POPUP_ITEM (N_("Print"), G_CALLBACK(print), POPUP_NOSELECTION_MASK), -#if 0 /* Envelope printing is disabled for Evolution 1.0. */ - E_POPUP_ITEM (N_("Print Envelope"), G_CALLBACK(print_envelope), POPUP_NOSELECTION_MASK), -#endif - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("Copy to Address Book..."), G_CALLBACK(copy_to_folder), POPUP_NOSELECTION_MASK), - E_POPUP_ITEM (N_("Move to Address Book..."), G_CALLBACK(move_to_folder), POPUP_READONLY_MASK | POPUP_NOSELECTION_MASK), - E_POPUP_SEPARATOR, - - E_POPUP_ITEM (N_("Cut"), G_CALLBACK (cut), POPUP_READONLY_MASK | POPUP_NOSELECTION_MASK), - E_POPUP_ITEM (N_("Copy"), G_CALLBACK (copy), POPUP_NOSELECTION_MASK), - E_POPUP_ITEM (N_("Paste"), G_CALLBACK (paste), POPUP_READONLY_MASK), - E_POPUP_ITEM (N_("Delete"), G_CALLBACK(delete), POPUP_READONLY_MASK | POPUP_NOSELECTION_MASK), - E_POPUP_SEPARATOR, - -#if 0 - E_POPUP_SUBMENU (N_("Current View"), submenu = gal_view_instance_get_popup_menu (view->view_instance), 0), -#endif - E_POPUP_TERMINATOR - }; contact_and_book = g_new(ContactAndBook, 1); contact_and_book->view = view; - contact_and_book->submenu = submenu; + g_object_ref(contact_and_book->view); - g_object_ref (contact_and_book->view); + selection_model = contact_and_book_get_selection_model(contact_and_book); + if (selection_model) { + contact_and_book->closure = cards; + e_selection_model_foreach(selection_model, get_card_1, contact_and_book); + } - selection_model = contact_and_book_get_selection_model (contact_and_book); - if (selection_model) - selection = e_selection_model_selected_count (selection_model) > 0; + ep = eab_popup_new("com.novell.evolution.addressbook.view.popup"); + t = eab_popup_target_new_select(ep, view->book, !eab_model_editable(view->model), cards); + t->target.widget = (GtkWidget *)view; - popup = e_popup_menu_create (menu, - 0, - (eab_model_editable (view->model) ? 0 : POPUP_READONLY_MASK) + - (selection ? 0 : POPUP_NOSELECTION_MASK) + - (get_has_email_address (contact_and_book) ? 0 : POPUP_NOEMAIL_MASK), - contact_and_book); + for (i=0;i<sizeof(eabv_popup_items)/sizeof(eabv_popup_items[0]);i++) + menus = g_slist_prepend(menus, &eabv_popup_items[i]); - g_signal_connect (popup, "selection-done", - G_CALLBACK (free_popup_info), contact_and_book); - e_popup_menu (popup, event); + e_popup_add_items((EPopup *)ep, menus, eabv_popup_free, contact_and_book); + /* visibility is disabled, we only disable menu items */ + /* FIXME: when enable is implemented in e-popup */ + menu = e_popup_create_menu_once((EPopup *)ep, (EPopupTarget *)t, 0, t->target.mask); + gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event?event->button.button:0, event?event->button.time:gtk_get_current_event_time()); } static void @@ -1985,12 +1834,43 @@ eab_view_print_preview(EABView *view) void eab_view_delete_selection(EABView *view) { - ContactAndBook contact_and_book; + GList *list, *l; + + if (!eab_editor_confirm_delete(GTK_WINDOW(gtk_widget_get_toplevel(view->widget)))) + return; + + list = get_selected_contacts(view); + if (e_book_check_static_capability (view->book, "bulk-remove")) { + GList *ids = NULL; + + for (l=list;l;l=g_list_next(l)) { + EContact *contact = l->data; + + ids = g_list_prepend (ids, (char*)e_contact_get_const (contact, E_CONTACT_UID)); + } - memset (&contact_and_book, 0, sizeof (contact_and_book)); - contact_and_book.view = view; + /* Remove the cards all at once. */ + /* XXX no callback specified... ugh */ + e_book_async_remove_contacts (view->book, + ids, + NULL, + NULL); + + g_list_free (ids); + } + else { + for (l=list;l;l=g_list_next(l)) { + EContact *contact = l->data; + /* Remove the card. */ + /* XXX no callback specified... ugh */ + e_book_async_remove_contact (view->book, + contact, + NULL, + NULL); + } + } - delete (GTK_WIDGET (view), &contact_and_book); + e_free_object_list(list); } static void |