[evolution-patches] addressbook main context menu -> epopup
- From: Not Zed <notzed ximian com>
- To: asdf <evolution-patches lists ximian com>
- Subject: [evolution-patches] addressbook main context menu -> epopup
- Date: Fri, 01 Oct 2004 18:32:44 +0800
This is the main popup menu in the addressbook, converted to use epopup.
Some of the stuff is a bit sub-optimal regards to selections, but some of it is cleaner now too.
diff -upr addressbook.save/ChangeLog addressbook/ChangeLog
--- addressbook.save/ChangeLog 2004-10-01 14:39:56.000000000 +0800
+++ addressbook/ChangeLog 2004-10-01 18:15:36.471002320 +0800
@@ -1,5 +1,24 @@
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.
+
+ * util/eab-popup.c (eab_popup_target_new_select): implement.
+
+2004-10-01 Not Zed <NotZed Ximian com>
+
* util/eab-popup.[ch]: addressbook popup driver.
* gui/component/addressbook-view.c (delete_addressbook_cb): use
Files addressbook.save/gui/component/.libs/addressbook-view.o and addressbook/gui/component/.libs/addressbook-view.o differ
Files addressbook.save/gui/component/.libs/libevolution-addressbook.so and addressbook/gui/component/.libs/libevolution-addressbook.so differ
Files addressbook.save/gui/component/.libs/libevolution-addressbook.soT and addressbook/gui/component/.libs/libevolution-addressbook.soT differ
diff -upr addressbook.save/gui/widgets/e-addressbook-view.c addressbook/gui/widgets/e-addressbook-view.c
--- addressbook.save/gui/widgets/e-addressbook-view.c 2004-09-30 09:56:34.000000000 +0800
+++ addressbook/gui/widgets/e-addressbook-view.c 2004-10-01 18:17:06.523312288 +0800
@@ -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/util/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 (Co
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;
-
- selection = contact_and_book_get_selection_model (contact_and_book);
+ int i;
- 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)
-{
- 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;
-
- 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)
+save_as (EPopup *ep, EPopupItem *pitem, void *data)
{
- 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;
-}
+ /*ContactAndBook *contact_and_book = data;*/
+ GList *contacts = get_contact_list ((EABPopupTargetSelect *)ep->target);
-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;
-
- 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));
- }
+ ContactAndBook *contact_and_book = data;
- /* 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);
+
+ 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);
+ }
- g_object_ref (contact_and_book->view);
+ 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;
- selection_model = contact_and_book_get_selection_model (contact_and_book);
- if (selection_model)
- selection = e_selection_model_selected_count (selection_model) > 0;
-
- 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);
-
- g_signal_connect (popup, "selection-done",
- G_CALLBACK (free_popup_info), contact_and_book);
- e_popup_menu (popup, event);
+ for (i=0;i<sizeof(eabv_popup_items)/sizeof(eabv_popup_items[0]);i++)
+ menus = g_slist_prepend(menus, &eabv_popup_items[i]);
+ 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
Only in addressbook/gui/widgets: e-addressbook-view.c.~1.149.~
Files addressbook.save/gui/widgets/.libs/e-addressbook-view.o and addressbook/gui/widgets/.libs/e-addressbook-view.o differ
Files addressbook.save/gui/widgets/.libs/libeabwidgets.a and addressbook/gui/widgets/.libs/libeabwidgets.a differ
diff -upr addressbook.save/util/eab-popup.c addressbook/util/eab-popup.c
--- addressbook.save/util/eab-popup.c 2004-10-01 15:34:23.000000000 +0800
+++ addressbook/util/eab-popup.c 2004-10-01 18:21:48.003520792 +0800
@@ -30,6 +30,7 @@
#include "eab-popup.h"
#include "widgets/misc/e-source-selector.h"
+#include <libebook/e-contact.h>
static GObjectClass *eabp_parent;
@@ -51,9 +52,13 @@ eabp_target_free(EPopup *ep, EPopupTarge
switch (t->type) {
case EAB_POPUP_TARGET_SELECT: {
EABPopupTargetSelect *s = (EABPopupTargetSelect *)t;
+ int i;
+
+ for (i=0;i<s->cards->len;i++)
+ g_object_unref(s->cards->pdata[i]);
+ g_ptr_array_free(s->cards, TRUE);
+ g_object_unref(s->book);
- /* FIXME: implement */
- s = s;
break; }
case EAB_POPUP_TARGET_SOURCE: {
EABPopupTargetSource *s = (EABPopupTargetSource *)t;
@@ -104,18 +109,50 @@ EABPopup *eab_popup_new(const char *menu
/**
* eab_popup_target_new_select:
- *
+ * @eabp: Address book popup.
+ * @book: Book the cards belong to.
+ * @readonly: Book is read-only mode. FIXME: Why can't we just get this off the book?
+ * @cards: Cards selected. This will be freed on completion.
+ *
* Create a new selection popup target.
*
* Return value:
**/
EABPopupTargetSelect *
-eab_popup_target_new_select(EABPopup *eabp)
+eab_popup_target_new_select(EABPopup *eabp, struct _EBook *book, int readonly, GPtrArray *cards)
{
EABPopupTargetSelect *t = e_popup_target_new(&eabp->popup, EAB_POPUP_TARGET_SELECT, sizeof(*t));
guint32 mask = ~0;
+ int has_email = FALSE, i;
+
+ t->book = book;
+ g_object_ref(book);
+ t->cards = cards;
+
+ for (i=0;i<cards->len && !has_email;i++) {
+ EContact *contact = cards->pdata[i];
+ GList *email;
+
+ email = e_contact_get(E_CONTACT(contact), E_CONTACT_EMAIL);
+ if (email) {
+ has_email = TRUE;
+
+ g_list_foreach(email, (GFunc)g_free, NULL);
+ g_list_free(email);
+ }
+ }
+
+ if (has_email)
+ mask &= ~EAB_POPUP_SELECT_EMAIL;
+
+ if (!readonly)
+ mask &= ~EAB_POPUP_SELECT_EDITABLE;
+
+ if (cards->len == 1)
+ mask &= ~EAB_POPUP_SELECT_ONE;
- /* FIXME: impelement */
+ if (cards->len >= 1)
+ mask &= ~EAB_POPUP_SELECT_MANY;
t->target.mask = mask;
diff -upr addressbook.save/util/eab-popup.h addressbook/util/eab-popup.h
--- addressbook.save/util/eab-popup.h 2004-10-01 15:34:30.000000000 +0800
+++ addressbook/util/eab-popup.h 2004-10-01 16:29:51.702553736 +0800
@@ -52,11 +52,14 @@ enum _eab_popup_target_t {
*
* @EAB_POPUP_SELECT_ONE: Only one item is selected.
* @EAB_POPUP_SELECT_MANY: One ore more items are selected.
- *
+ * @EAB_POPUP_SELECT_EDITABLE: Read/writable source.
+ * @EAB_POPUP_SELECT_EMAIL: Has an email address.
**/
enum _eab_popup_target_select_t {
- EAB_POPUP_SELECT_ONE = 1<<1,
- EAB_POPUP_SELECT_MANY = 1<<2,
+ EAB_POPUP_SELECT_ONE = 1<<0,
+ EAB_POPUP_SELECT_MANY = 1<<1,
+ EAB_POPUP_SELECT_EDITABLE = 1<<2,
+ EAB_POPUP_SELECT_EMAIL = 1<<3,
};
/**
@@ -79,15 +82,17 @@ typedef struct _EABPopupTargetSource EAB
* struct _EABPopupTargetSelect - A list of address cards.
*
* @target: Superclass.
+ * @book: Book the cards belong to.
+ * @cards: All selected cards.
*
* Used to represent a selection of cards as context for a popup
- * menu. All items may be NULL if the current view has no active
- * folder selected.
- *
- * FIXME: impelemnt me
+ * menu.
**/
struct _EABPopupTargetSelect {
EPopupTarget target;
+
+ struct _EBook *book;
+ GPtrArray *cards;
};
/**
@@ -121,7 +126,7 @@ GType eab_popup_get_type(void);
EABPopup *eab_popup_new(const char *menuid);
-EABPopupTargetSelect *eab_popup_target_new_select(EABPopup *eabp);
+EABPopupTargetSelect *eab_popup_target_new_select(EABPopup *eabp, struct _EBook *book, int readonly, GPtrArray *cards);
EABPopupTargetSource *eab_popup_target_new_source(EABPopup *eabp, struct _ESourceSelector *selector);
/* ********************************************************************** */
Files addressbook.save/util/.libs/eab-popup.o and addressbook/util/.libs/eab-popup.o differ
Files addressbook.save/util/.libs/libeabutil.a and addressbook/util/.libs/libeabutil.a differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]