diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2008-09-18 10:32:04 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2008-09-18 10:32:04 +0800 |
commit | 8d21ab98d99ca43ee7873adba8172b699d8a007f (patch) | |
tree | d6a85918167907daf7c4dcf87b8b7feee89f12af | |
parent | bb7cb1d677117a938ae18d9cae7acc7a56678b6f (diff) | |
download | gsoc2013-evolution-8d21ab98d99ca43ee7873adba8172b699d8a007f.tar gsoc2013-evolution-8d21ab98d99ca43ee7873adba8172b699d8a007f.tar.gz gsoc2013-evolution-8d21ab98d99ca43ee7873adba8172b699d8a007f.tar.bz2 gsoc2013-evolution-8d21ab98d99ca43ee7873adba8172b699d8a007f.tar.lz gsoc2013-evolution-8d21ab98d99ca43ee7873adba8172b699d8a007f.tar.xz gsoc2013-evolution-8d21ab98d99ca43ee7873adba8172b699d8a007f.tar.zst gsoc2013-evolution-8d21ab98d99ca43ee7873adba8172b699d8a007f.zip |
Progress update:
- Get context menus working in the contact preview pane.
- Kill EABPopup.
- Yet more code refactoring.
- Add a handy utility function: e_shell_window_show_popup_menu()
Takes a widget path in the shell window's UI definition.
svn path=/branches/kill-bonobo/; revision=36366
20 files changed, 807 insertions, 1596 deletions
diff --git a/addressbook/gui/component/e-book-shell-view-actions.c b/addressbook/gui/component/e-book-shell-view-actions.c index a6a97d9229..814b69d82c 100644 --- a/addressbook/gui/component/e-book-shell-view-actions.c +++ b/addressbook/gui/component/e-book-shell-view-actions.c @@ -393,6 +393,7 @@ action_search_execute_cb (GtkAction *action, EShellContent *shell_content; GString *string; EAddressbookView *view; + EABContactDisplay *display; const gchar *search_format; const gchar *search_text; gchar *search_query; @@ -463,10 +464,8 @@ action_search_execute_cb (GtkAction *action, g_object_set (view, "query", search_query, NULL); g_free (search_query); - /* FIXME view->displayed_contact = -1; */ - eab_contact_display_render ( - EAB_CONTACT_DISPLAY (book_shell_view->priv->preview), - NULL, EAB_CONTACT_DISPLAY_RENDER_NORMAL); + display = EAB_CONTACT_DISPLAY (book_shell_view->priv->preview); + eab_contact_display_set_contact (display, NULL); } static GtkActionEntry contact_entries[] = { @@ -747,12 +746,12 @@ e_book_shell_view_actions_init (EBookShellView *book_shell_view) } void -e_book_shell_view_actions_update (EBookShellView *book_shell_view, - EAddressbookView *view) +e_book_shell_view_actions_update (EBookShellView *book_shell_view) { EShellView *shell_view; EShellWindow *shell_window; EAddressbookModel *model; + EAddressbookView *view; EBookShellSidebar *book_shell_sidebar; ESelectionModel *selection_model; ESourceSelector *selector; @@ -764,11 +763,9 @@ e_book_shell_view_actions_update (EBookShellView *book_shell_view, gint n_contacts; gint n_selected; - if (e_book_shell_view_get_current_view (book_shell_view) != view) - return; - shell_view = E_SHELL_VIEW (book_shell_view); shell_window = e_shell_view_get_shell_window (shell_view); + view = e_book_shell_view_get_current_view (book_shell_view); book_shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); selector = e_book_shell_sidebar_get_selector (book_shell_sidebar); diff --git a/addressbook/gui/component/e-book-shell-view-private.c b/addressbook/gui/component/e-book-shell-view-private.c index 530d3fd1ed..ce995a1859 100644 --- a/addressbook/gui/component/e-book-shell-view-private.c +++ b/addressbook/gui/component/e-book-shell-view-private.c @@ -26,6 +26,22 @@ #include <addressbook.h> static void +popup_event (EBookShellView *book_shell_view, + GdkEventButton *event) +{ + EShellView *shell_view; + EShellWindow *shell_window; + const gchar *widget_path; + + widget_path = "/contact-popup"; + shell_view = E_SHELL_VIEW (book_shell_view); + shell_window = e_shell_view_get_shell_window (shell_view); + + e_book_shell_view_actions_update (book_shell_view); + e_shell_window_show_popup_menu (shell_window, widget_path, event); +} + +static void set_status_message (EAddressbookView *view, const gchar *message, EBookShellView *book_shell_view) @@ -56,20 +72,90 @@ set_status_message (EAddressbookView *view, } static void -preview_contact (EBookShellView *book_shell_view, - EContact *contact, - EAddressbookView *view) +book_shell_view_selection_change_foreach (gint row, + EBookShellView *book_shell_view) +{ + EAddressbookView *view; + EAddressbookModel *model; + EABContactDisplay *display; + EContact *contact; + + /* XXX A "foreach" function is kind of a silly way to retrieve + * the one and only selected contact, but this is the only + * means that ESelectionModel provides. */ + + view = e_book_shell_view_get_current_view (book_shell_view); + model = e_addressbook_view_get_model (view); + contact = e_addressbook_model_get_contact (model, row); + + display = EAB_CONTACT_DISPLAY (book_shell_view->priv->preview); + eab_contact_display_set_contact (display, contact); +} + +static void +selection_change (EBookShellView *book_shell_view, + EAddressbookView *view) { EAddressbookView *current_view; + ESelectionModel *selection_model; + EABContactDisplay *display; current_view = e_book_shell_view_get_current_view (book_shell_view); if (view != current_view) return; - eab_contact_display_render ( - EAB_CONTACT_DISPLAY (book_shell_view->priv->preview), - contact, EAB_CONTACT_DISPLAY_RENDER_NORMAL); + e_book_shell_view_actions_update (book_shell_view); + + display = EAB_CONTACT_DISPLAY (book_shell_view->priv->preview); + selection_model = e_addressbook_view_get_selection_model (view); + + if (e_selection_model_selected_count (selection_model) == 1) + e_selection_model_foreach ( + selection_model, (EForeachFunc) + book_shell_view_selection_change_foreach, + book_shell_view); + else + eab_contact_display_set_contact (display, NULL); +} + +static void +contact_changed (EBookShellView *book_shell_view, + EContact *contact) +{ + EABContactDisplay *display; + EContact *displayed_contact; + + display = EAB_CONTACT_DISPLAY (book_shell_view->priv->preview); + displayed_contact = eab_contact_display_get_contact (display); + + if (contact != displayed_contact) + return; + + /* Re-render the same contact. */ + eab_contact_display_set_contact (display, contact); +} + +static void +contacts_removed (EBookShellView *book_shell_view, + GArray *removed_indices, + EAddressbookModel *model) +{ + EABContactDisplay *display; + EContact *displayed_contact; + + display = EAB_CONTACT_DISPLAY (book_shell_view->priv->preview); + displayed_contact = eab_contact_display_get_contact (display); + + if (displayed_contact == NULL) + return; + + /* Is the displayed contact still in the model? */ + if (e_addressbook_model_find (model, displayed_contact) < 0) + return; + + /* If not, clear the contact display. */ + eab_contact_display_set_contact (display, NULL); } static void @@ -84,10 +170,6 @@ book_open_cb (EBook *book, source = e_book_get_source (book); model = e_addressbook_view_get_model (view); - /* We always set the "source" property on the EAddressbookView - * since we use it to reload a previously failed book. */ - g_object_set (view, "source", source, NULL); - if (status == E_BOOK_ERROR_OK) { e_addressbook_model_set_book (model, book); e_addressbook_model_force_folder_bar_message (model); @@ -133,23 +215,13 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, * suggests a previous load failed, so try again. */ view = E_ADDRESSBOOK_VIEW (widget); model = e_addressbook_view_get_model (view); - book = e_addressbook_model_get_book (model); + source = e_addressbook_view_get_source (view); - if (book != NULL) - g_object_unref (book); - else { - g_object_get (view, "source", &source, NULL); - - /* Source can be NULL if a previous load - * has not yet reached book_open_cb(). */ - if (source != NULL) { - book = e_book_new (source, NULL); + if (e_addressbook_model_get_book (model) == NULL) { + book = e_book_new (source, NULL); - if (book != NULL) - addressbook_load (book, book_open_cb, view); - - g_object_unref (source); - } + if (book != NULL) + addressbook_load (book, book_open_cb, view); } } else { @@ -158,7 +230,7 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, /* Create a view for this UID. */ shell_view = E_SHELL_VIEW (book_shell_view); - widget = e_addressbook_view_new (shell_view); + widget = e_addressbook_view_new (shell_view, source); g_object_set (widget, "type", E_ADDRESSBOOK_VIEW_TABLE, NULL); gtk_widget_show (widget); @@ -166,6 +238,10 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, gtk_notebook_append_page (notebook, widget, NULL); g_hash_table_insert (hash_table, g_strdup (uid), widget); + g_signal_connect_swapped ( + widget, "popup-event", + G_CALLBACK (popup_event), book_shell_view); + g_signal_connect ( widget, "status-message", G_CALLBACK (set_status_message), book_shell_view); @@ -176,8 +252,8 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, book_shell_view); g_signal_connect_swapped ( - widget, "preview-contact", - G_CALLBACK (preview_contact), book_shell_view); + widget, "selection-change", + G_CALLBACK (selection_change), book_shell_view); book = e_book_new (source, NULL); @@ -186,34 +262,33 @@ book_shell_view_activate_selected_source (EBookShellView *book_shell_view, view = E_ADDRESSBOOK_VIEW (widget); model = e_addressbook_view_get_model (view); + + g_signal_connect_swapped ( + model, "contact-changed", + G_CALLBACK (contact_changed), book_shell_view); + + g_signal_connect_swapped ( + model, "contacts-removed", + G_CALLBACK (contacts_removed), book_shell_view); } page_num = gtk_notebook_page_num (notebook, widget); gtk_notebook_set_current_page (notebook, page_num); e_addressbook_model_force_folder_bar_message (model); + selection_change (book_shell_view, view); } static gboolean book_shell_view_show_popup_menu (GdkEventButton *event, EShellView *shell_view) { - GtkWidget *menu; EShellWindow *shell_window; const gchar *widget_path; widget_path = "/address-book-popup"; shell_window = e_shell_view_get_shell_window (shell_view); - menu = e_shell_window_get_managed_widget (shell_window, widget_path); - - if (event != NULL) - gtk_menu_popup ( - GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button, event->time); - else - gtk_menu_popup ( - GTK_MENU (menu), NULL, NULL, NULL, NULL, - 0, gtk_get_current_event_time ()); + e_shell_window_show_popup_menu (shell_window, widget_path, event); return TRUE; } @@ -376,6 +451,9 @@ e_book_shell_view_private_constructed (EBookShellView *book_shell_view) container = widget; widget = eab_contact_display_new (); + eab_contact_display_set_mode ( + EAB_CONTACT_DISPLAY (widget), + EAB_CONTACT_DISPLAY_RENDER_NORMAL); gtk_container_add (GTK_CONTAINER (container), widget); priv->preview = g_object_ref (widget); gtk_widget_show (widget); @@ -408,20 +486,19 @@ e_book_shell_view_private_constructed (EBookShellView *book_shell_view) G_CALLBACK (book_shell_view_activate_selected_source), book_shell_view); - book_shell_view_activate_selected_source (book_shell_view, selector); - e_categories_register_change_listener ( G_CALLBACK (book_shell_view_categories_changed_cb), book_shell_view); e_book_shell_view_actions_init (book_shell_view); e_book_shell_view_update_search_filter (book_shell_view); + book_shell_view_activate_selected_source (book_shell_view, selector); /* Bind GObject properties to GConf keys. */ bridge = gconf_bridge_get (); - object = G_OBJECT (ACTION (CONTACT_PREVIEW)); + object = G_OBJECT (book_shell_view->priv->paned); key = "/apps/evolution/addressbook/display/vpane_position"; gconf_bridge_bind_property_delayed (bridge, key, object, "position"); } diff --git a/addressbook/gui/component/e-book-shell-view-private.h b/addressbook/gui/component/e-book-shell-view-private.h index 1dffd59cbf..6eda9a08e8 100644 --- a/addressbook/gui/component/e-book-shell-view-private.h +++ b/addressbook/gui/component/e-book-shell-view-private.h @@ -122,8 +122,7 @@ void e_book_shell_view_private_finalize void e_book_shell_view_actions_init (EBookShellView *book_shell_view); void e_book_shell_view_actions_update - (EBookShellView *book_shell_view, - EAddressbookView *view); + (EBookShellView *book_shell_view); EAddressbookView * e_book_shell_view_get_current_view (EBookShellView *book_shell_view); diff --git a/addressbook/gui/component/e-book-shell-view.c b/addressbook/gui/component/e-book-shell-view.c index 2f9edf9e01..9a90b1d1f5 100644 --- a/addressbook/gui/component/e-book-shell-view.c +++ b/addressbook/gui/component/e-book-shell-view.c @@ -33,7 +33,6 @@ book_shell_view_source_list_changed_cb (EBookShellView *book_shell_view, ESourceList *source_list) { EBookShellViewPrivate *priv = book_shell_view->priv; - EAddressbookView *view; GtkNotebook *notebook; GList *keys, *iter; @@ -76,14 +75,7 @@ book_shell_view_source_list_changed_cb (EBookShellView *book_shell_view, } g_list_free (keys); - /* Select and update the current view. */ - view = e_book_shell_view_get_current_view (book_shell_view); - if (view != NULL) { -#if 0 - eab_view_setup_menus (view, bonobo_uic); -#endif - e_book_shell_view_actions_update (book_shell_view, view); - } + e_book_shell_view_actions_update (book_shell_view); } static void diff --git a/addressbook/gui/merging/eab-contact-merging.c b/addressbook/gui/merging/eab-contact-merging.c index a912a4f08e..96fccd1b13 100644 --- a/addressbook/gui/merging/eab-contact-merging.c +++ b/addressbook/gui/merging/eab-contact-merging.c @@ -472,12 +472,18 @@ match_query_callback (EContact *contact, EContact *match, EABContactMatchType ty } widget = glade_xml_get_widget (ui, "custom-old-contact"); - eab_contact_display_render (EAB_CONTACT_DISPLAY (widget), - match, EAB_CONTACT_DISPLAY_RENDER_COMPACT); + eab_contact_display_set_mode ( + EAB_CONTACT_DISPLAY (widget), + EAB_CONTACT_DISPLAY_RENDER_COMPACT); + eab_contact_display_set_contact ( + EAB_CONTACT_DISPLAY (widget), match); widget = glade_xml_get_widget (ui, "custom-new-contact"); - eab_contact_display_render (EAB_CONTACT_DISPLAY (widget), - contact, EAB_CONTACT_DISPLAY_RENDER_COMPACT); + eab_contact_display_set_mode ( + EAB_CONTACT_DISPLAY (widget), + EAB_CONTACT_DISPLAY_RENDER_COMPACT); + eab_contact_display_set_contact ( + EAB_CONTACT_DISPLAY (widget), contact); widget = glade_xml_get_widget (ui, "dialog-duplicate-contact"); diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am index af8a069800..827757c4f1 100644 --- a/addressbook/gui/widgets/Makefile.am +++ b/addressbook/gui/widgets/Makefile.am @@ -25,8 +25,7 @@ eabincludedir = $(privincludedir)/addressbook/gui/widgets eabinclude_HEADERS = \ eab-config.h \ - eab-menu.h \ - eab-popup.h + eab-menu.h libeabwidgets_la_SOURCES = \ $(MARSHAL_GENERATED) \ @@ -36,10 +35,6 @@ libeabwidgets_la_SOURCES = \ eab-gui-util.c \ eab-gui-util.h \ eab-menu.c \ - eab-popup.c \ - eab-popup.h \ - eab-popup-control.c \ - eab-popup-control.h \ eab-vcard-control.c \ eab-vcard-control.h \ e-minicard.c \ diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c index 6d84cca2e4..b26c68e755 100644 --- a/addressbook/gui/widgets/e-addressbook-model.c +++ b/addressbook/gui/widgets/e-addressbook-model.c @@ -233,8 +233,11 @@ modify_contact(EBookView *book_view, continue; g_object_unref (array->pdata[ii]); - array->pdata[ii] = e_contact_duplicate (contact); - g_signal_emit (model, signals[CONTACT_CHANGED], 0, ii); + contact = e_contact_duplicate (contact); + array->pdata[ii] = contact; + + g_signal_emit ( + model, signals[CONTACT_CHANGED], 0, contact); break; } @@ -591,8 +594,8 @@ addressbook_model_class_init (EAddressbookModelClass *class) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (EAddressbookModelClass, contact_changed), NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, E_TYPE_CONTACT); signals[MODEL_CHANGED] = g_signal_new ("model_changed", @@ -726,6 +729,32 @@ e_addressbook_model_contact_at (EAddressbookModel *model, return model->priv->contacts->pdata[index]; } +gint +e_addressbook_model_find (EAddressbookModel *model, + EContact *contact) +{ + GPtrArray *array; + gint ii; + + /* XXX This searches for a particular EContact instance, + * as opposed to an equivalent but possibly different + * EContact instance. Might have to revise this in + * the future. */ + + g_return_val_if_fail (E_IS_ADDRESSBOOK_MODEL (model), -1); + g_return_val_if_fail (E_IS_CONTACT (contact), -1); + + array = model->priv->contacts; + for (ii = 0; ii < array->len; ii++) { + EContact *candidate = array->pdata[ii]; + + if (contact == candidate) + return ii; + } + + return -1; +} + EBook * e_addressbook_model_get_book (EAddressbookModel *model) { diff --git a/addressbook/gui/widgets/e-addressbook-model.h b/addressbook/gui/widgets/e-addressbook-model.h index d4f7cae332..1a7be828f6 100644 --- a/addressbook/gui/widgets/e-addressbook-model.h +++ b/addressbook/gui/widgets/e-addressbook-model.h @@ -75,7 +75,7 @@ struct _EAddressbookModelClass { void (*contacts_removed) (EAddressbookModel *model, gpointer id_list); void (*contact_changed) (EAddressbookModel *model, - gint index); + EContact *contact); void (*model_changed) (EAddressbookModel *model); void (*stop_state_changed) (EAddressbookModel *model); void (*backend_died) (EAddressbookModel *model); @@ -99,6 +99,8 @@ gint e_addressbook_model_contact_count (EAddressbookModel *model); EContact * e_addressbook_model_contact_at (EAddressbookModel *model, gint index); +gint e_addressbook_model_find (EAddressbookModel *model, + EContact *contact); EBook * e_addressbook_model_get_book (EAddressbookModel *model); void e_addressbook_model_set_book (EAddressbookModel *model, EBook *book); diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c index 920daeae78..6ba56ae7a4 100644 --- a/addressbook/gui/widgets/e-addressbook-view.c +++ b/addressbook/gui/widgets/e-addressbook-view.c @@ -32,7 +32,6 @@ #include <e-shell-sidebar.h> #include "addressbook/printing/e-contact-print.h" -#include "addressbook/gui/widgets/eab-popup.h" #include "addressbook/gui/widgets/eab-menu.h" #include "a11y/addressbook/ea-addressbook.h" @@ -73,8 +72,6 @@ static void search_result (EAddressbookView *view, EBookViewStatus status); static void folder_bar_message (EAddressbookView *view, const gchar *status); static void stop_state_changed (GtkObject *object, EAddressbookView *view); static void backend_died (EAddressbookView *view); -static void contact_changed (EAddressbookModel *model, gint index, EAddressbookView *view); -static void contacts_removed (EAddressbookModel *model, gpointer data, EAddressbookView *view); static GList *get_selected_contacts (EAddressbookView *view); static void command_state_change (EAddressbookView *view); @@ -87,7 +84,6 @@ struct _EAddressbookViewPrivate { GList *clipboard_contacts; ESource *source; - gint displayed_contact; GObject *object; GtkWidget *widget; @@ -106,9 +102,10 @@ enum { }; enum { + POPUP_EVENT, STATUS_MESSAGE, COMMAND_STATE_CHANGE, - PREVIEW_CONTACT, + SELECTION_CHANGE, LAST_SIGNAL }; @@ -127,6 +124,19 @@ static guint signals[LAST_SIGNAL]; static GdkAtom clipboard_atom = GDK_NONE; static void +addressbook_view_emit_popup_event (EAddressbookView *view, + GdkEvent *event) +{ + g_signal_emit (view, signals[POPUP_EVENT], 0, event); +} + +static void +addressbook_view_emit_selection_change (EAddressbookView *view) +{ + g_signal_emit (view, signals[SELECTION_CHANGE], 0); +} + +static void addressbook_view_selection_get_cb (EAddressbookView *view, GtkSelectionData *selection_data, guint info, @@ -211,6 +221,15 @@ addressbook_view_set_shell_view (EAddressbookView *view, } static void +addressbook_view_set_source (EAddressbookView *view, + ESource *source) +{ + g_return_if_fail (view->priv->source == NULL); + + view->priv->source = g_object_ref (source); +} + +static void addressbook_view_set_property (GObject *object, guint property_id, const GValue *value, @@ -219,31 +238,21 @@ addressbook_view_set_property (GObject *object, EAddressbookView *view = E_ADDRESSBOOK_VIEW (object); switch (property_id){ - case PROP_SHELL_VIEW: - addressbook_view_set_shell_view ( - E_ADDRESSBOOK_VIEW (object), - g_value_get_object (value)); - return; + case PROP_SHELL_VIEW: + addressbook_view_set_shell_view ( + E_ADDRESSBOOK_VIEW (object), + g_value_get_object (value)); + return; - case PROP_SOURCE: - if (view->priv->source) { - g_warning ("EAddressbookView at present does not support multiple writes on the \"source\" property."); + case PROP_SOURCE: + addressbook_view_set_source ( + E_ADDRESSBOOK_VIEW (object), + g_value_get_object (value)); return; - } - else { - if (g_value_get_object (value)) { - view->priv->source = E_SOURCE(g_value_get_object (value)); - g_object_ref (view->priv->source); - } - else { - view->priv->source = NULL; - } - } - return; - case PROP_TYPE: - change_view_type(view, g_value_get_int (value)); - return; + case PROP_TYPE: + change_view_type(view, g_value_get_int (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -271,7 +280,9 @@ addressbook_view_get_property (GObject *object, return; case PROP_SOURCE: - g_value_set_object (value, view->priv->source); + g_value_set_object ( + value, e_addressbook_view_get_source ( + E_ADDRESSBOOK_VIEW (object))); return; case PROP_TYPE: @@ -336,20 +347,20 @@ addressbook_view_constructed (GObject *object) EShellView *shell_view; EShellViewClass *shell_view_class; GalViewCollection *view_collection; - EAddressbookModel *model; - EBook *book; - const gchar *uri; + ESource *source; + gchar *uri; shell_view = e_addressbook_view_get_shell_view (view); shell_view_class = E_SHELL_VIEW_GET_CLASS (shell_view); view_collection = shell_view_class->view_collection; - model = e_addressbook_view_get_model (view); - book = e_addressbook_model_get_book (model); - uri = e_book_get_uri (book); + source = e_addressbook_view_get_source (view); + uri = e_source_get_uri (source); view->priv->view_instance = gal_view_instance_new (view_collection, uri); + + g_free (uri); } static void @@ -395,7 +406,8 @@ addressbook_view_class_init (EAddressbookViewClass *class) _("Source"), NULL, E_TYPE_SOURCE, - G_PARAM_READWRITE)); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property ( object_class, @@ -409,6 +421,16 @@ addressbook_view_class_init (EAddressbookViewClass *class) E_ADDRESSBOOK_VIEW_NONE, G_PARAM_READWRITE)); + signals[POPUP_EVENT] = g_signal_new ( + "popup-event", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EAddressbookViewClass, popup_event), + NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); + signals[STATUS_MESSAGE] = g_signal_new ( "status-message", G_OBJECT_CLASS_TYPE (object_class), @@ -428,15 +450,14 @@ addressbook_view_class_init (EAddressbookViewClass *class) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals[PREVIEW_CONTACT] = g_signal_new ( - "preview-contact", + signals[SELECTION_CHANGE] = g_signal_new ( + "selection-change", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EAddressbookViewClass, preview_contact), + G_STRUCT_OFFSET (EAddressbookViewClass, selection_change), NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - E_TYPE_CONTACT); + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); if (clipboard_atom == NULL) clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); @@ -453,7 +474,6 @@ addressbook_view_init (EAddressbookView *view) view->priv->model = e_addressbook_model_new (); view->priv->view_type = E_ADDRESSBOOK_VIEW_NONE; - view->priv->displayed_contact = -1; view->priv->invisible = gtk_invisible_new (); @@ -499,7 +519,8 @@ e_addressbook_view_get_type (void) } GtkWidget * -e_addressbook_view_new (EShellView *shell_view) +e_addressbook_view_new (EShellView *shell_view, + ESource *source) { GtkWidget *widget; EAddressbookView *view; @@ -507,8 +528,8 @@ e_addressbook_view_new (EShellView *shell_view) g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); widget = g_object_new ( - E_TYPE_ADDRESSBOOK_VIEW, - "shell-view", shell_view, NULL); + E_TYPE_ADDRESSBOOK_VIEW, "shell-view", + shell_view, "source", source, NULL); view = E_ADDRESSBOOK_VIEW (widget); @@ -528,10 +549,6 @@ e_addressbook_view_new (EShellView *shell_view) g_signal_connect_swapped ( view->priv->model, "backend_died", G_CALLBACK (backend_died), view); - g_signal_connect (view->priv->model, "contact_changed", - G_CALLBACK (contact_changed), view); - g_signal_connect (view->priv->model, "contacts_removed", - G_CALLBACK (contacts_removed), view); return widget; } @@ -610,6 +627,14 @@ e_addressbook_view_get_shell_view (EAddressbookView *view) return view->priv->shell_view; } +ESource * +e_addressbook_view_get_source (EAddressbookView *view) +{ + g_return_val_if_fail (E_IS_ADDRESSBOOK_VIEW (view), NULL); + + return view->priv->source; +} + static void display_view(GalViewInstance *instance, GalView *view, @@ -631,41 +656,6 @@ display_view(GalViewInstance *instance, } static void -do_popup_menu(EAddressbookView *view, GdkEvent *event) -{ - /* FIXME */ -} - -static void -render_contact (int row, EAddressbookView *view) -{ - EContact *contact; - - view->priv->displayed_contact = row; - contact = e_addressbook_model_get_contact (view->priv->model, row); - g_signal_emit (view, signals[PREVIEW_CONTACT], 0, contact); -} - -static void -selection_changed (GObject *o, EAddressbookView *view) -{ - ESelectionModel *selection_model; - - command_state_change (view); - - selection_model = e_addressbook_view_get_selection_model (view); - - if (e_selection_model_selected_count (selection_model) == 1) - e_selection_model_foreach (selection_model, - (EForeachFunc)render_contact, view); - else { - view->priv->displayed_contact = -1; - g_signal_emit (view, signals[PREVIEW_CONTACT], 0, NULL); - } - -} - -static void table_double_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, EAddressbookView *view) { EAddressbookModel *model; @@ -693,7 +683,7 @@ table_double_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, E static gint table_right_click(ETableScrolled *table, gint row, gint col, GdkEvent *event, EAddressbookView *view) { - do_popup_menu(view, event); + addressbook_view_emit_popup_event (view, event); return TRUE; } @@ -701,7 +691,7 @@ static gint table_white_space_event(ETableScrolled *table, GdkEvent *event, EAddressbookView *view) { if (event->type == GDK_BUTTON_PRESS && ((GdkEventButton *)event)->button == 3) { - do_popup_menu(view, event); + addressbook_view_emit_popup_event (view, event); return TRUE; } else { return FALSE; @@ -839,35 +829,6 @@ backend_died (EAddressbookView *view) } static void -contact_changed (EAddressbookModel *model, gint index, EAddressbookView *view) -{ - /* if the contact that's presently displayed is changed, re-render it */ - if (view->priv->displayed_contact == index) - render_contact (index, view); -} - -static void -contacts_removed (EAddressbookModel *model, gpointer data, EAddressbookView *view) -{ - GArray *indices = (GArray *) data; - int count = indices->len; - gboolean found = FALSE; - gint i; - - for (i = 0; i < count && !found; i++) { - if (view->priv->displayed_contact == g_array_index (indices, gint, i)) - found = TRUE; - } - - if (found) { - /* if the contact that's presently displayed is changed, - * clear the display */ - g_signal_emit (view, signals[PREVIEW_CONTACT], 0, NULL); - view->priv->displayed_contact = -1; - } -} - -static void create_minicard_view (EAddressbookView *view) { GtkWidget *scrolled_window; @@ -877,12 +838,13 @@ create_minicard_view (EAddressbookView *view) adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(e_addressbook_reflow_adapter_new (view->priv->model)); minicard_view = e_minicard_view_widget_new(adapter); - g_signal_connect(minicard_view, "selection_change", - G_CALLBACK(selection_changed), view); + g_signal_connect_swapped ( + minicard_view, "selection_change", + G_CALLBACK (addressbook_view_emit_selection_change), view); g_signal_connect_swapped ( minicard_view, "right_click", - G_CALLBACK (do_popup_menu), view); + G_CALLBACK (addressbook_view_emit_popup_event), view); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN); @@ -930,8 +892,10 @@ create_table_view (EAddressbookView *view) G_CALLBACK(table_right_click), view); g_signal_connect(e_table_scrolled_get_table(E_TABLE_SCROLLED(table)), "white_space_event", G_CALLBACK(table_white_space_event), view); - g_signal_connect(e_table_scrolled_get_table(E_TABLE_SCROLLED(table)), "selection_change", - G_CALLBACK(selection_changed), view); + g_signal_connect_swapped ( + e_table_scrolled_get_table (E_TABLE_SCROLLED(table)), + "selection_change", G_CALLBACK ( + addressbook_view_emit_selection_change), view); /* drag & drop signals */ e_table_drag_source_set ( diff --git a/addressbook/gui/widgets/e-addressbook-view.h b/addressbook/gui/widgets/e-addressbook-view.h index bdae1d553a..283b5d6cd0 100644 --- a/addressbook/gui/widgets/e-addressbook-view.h +++ b/addressbook/gui/widgets/e-addressbook-view.h @@ -73,17 +73,17 @@ struct _EAddressbookViewClass { GtkVBoxClass parent_class; /* Signals */ + void (*popup_event) (EAddressbookView *view, + GdkEvent *event); void (*status_message) (EAddressbookView *view, const gchar *message); - void (*folder_bar_message) (EAddressbookView *view, - const gchar *message); void (*command_state_change) (EAddressbookView *view); - void (*preview_contact) (EAddressbookView *view, - EContact *contact); + void (*selection_change) (EAddressbookView *view); }; GType e_addressbook_view_get_type (void); -GtkWidget * e_addressbook_view_new (EShellView *shell_view); +GtkWidget * e_addressbook_view_new (EShellView *shell_view, + ESource *source); EAddressbookModel * e_addressbook_view_get_model (EAddressbookView *view); GalViewInstance * @@ -98,6 +98,7 @@ ESelectionModel * (EAddressbookView *view); EShellView * e_addressbook_view_get_shell_view (EAddressbookView *view); +ESource * e_addressbook_view_get_source (EAddressbookView *view); void e_addressbook_view_save_as (EAddressbookView *view, gboolean all); void e_addressbook_view_view (EAddressbookView *view); diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c index bc2e32c338..5e1dc2d62a 100644 --- a/addressbook/gui/widgets/eab-contact-display.c +++ b/addressbook/gui/widgets/eab-contact-display.c @@ -25,11 +25,11 @@ #endif #include "eab-contact-display.h" -#include "eab-popup.h" #include "eab-gui-util.h" #include "e-util/e-html-utils.h" #include "e-util/e-icon-factory.h" +#include "e-util/e-plugin-ui.h" #include <string.h> #include <glib/gi18n.h> @@ -37,15 +37,29 @@ #include <gtkhtml/gtkhtml.h> #include <gtkhtml/gtkhtml-stream.h> -#define HANDLE_MAILTO_INTERNALLY 1 +#define EAB_CONTACT_DISPLAY_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), EAB_TYPE_CONTACT_DISPLAY, EABContactDisplayPrivate)) -#define PARENT_TYPE (GTK_TYPE_HTML) +#define HANDLE_MAILTO_INTERNALLY 1 struct _EABContactDisplayPrivate { EContact *contact; + EABContactDisplayMode mode; + GtkUIManager *ui_manager; + GtkActionGroup *email_actions; + GtkActionGroup *uri_actions; GtkWidget *invisible; - char *selection_uri; + + gchar *selected_uri; + gchar *clipboard_uri; +}; + +enum { + PROP_0, + PROP_CONTACT, + PROP_MODE }; static struct { @@ -76,155 +90,159 @@ common_location [] = #define MAX_COMPACT_IMAGE_DIMENSION 48 -static void -eab_uri_popup_link_open(EPopup *ep, EPopupItem *item, void *data) -{ - EABPopupTargetURI *t = (EABPopupTargetURI *)ep->target; - GError *err = NULL; +static const gchar *ui = +"<ui>" +" <popup>" +" <menuitem action='open-link'/>" +" <menuitem action='copy-link'/>" +" <menuitem action='send-message'/>" +" <menuitem action='copy-address'/>" +" </popup>" +"</ui>"; - gnome_url_show(t->uri, &err); - if (err) { - g_warning("gnome_url_show: %s", err->message); - g_error_free(err); - } -} +static gpointer parent_class; static void -eab_uri_popup_email_address_copy(EPopup *ep, EPopupItem *item, void *data) +action_copy_address_cb (GtkAction *action, + EABContactDisplay *display) { - EABContactDisplay *display = data; - struct _EABContactDisplayPrivate *p = display->priv; - EABPopupTargetURI *t = (EABPopupTargetURI *)ep->target; - const char *url = t->uri; - char *html=NULL; - int i=0; - GList *email_list, *l; - int email_num = atoi (url + strlen ("internal-mailto:")); - - email_list = e_contact_get (p->contact, E_CONTACT_EMAIL); - for (l = email_list; l; l=l->next) { - if(i==email_num) - html = e_text_to_html (l->data, 0); - i++; - } - - g_free(p->selection_uri); - p->selection_uri = g_strdup(html); - g_free (html); - - gtk_selection_owner_set(p->invisible, GDK_SELECTION_PRIMARY, gtk_get_current_event_time()); - gtk_selection_owner_set(p->invisible, GDK_SELECTION_CLIPBOARD, gtk_get_current_event_time()); + EContact *contact; + GList *list; + const gchar *uri; + gchar *html; + gint index; + + uri = display->priv->selected_uri; + index = atoi (uri + strlen ("internal-mailto:")); + contact = eab_contact_display_get_contact (display); + + list = e_contact_get (contact, E_CONTACT_EMAIL); + html = e_text_to_html (g_list_nth_data (list, index), 0); + g_list_foreach (list, (GFunc) g_free, NULL); + g_list_free (list); + + display->priv->clipboard_uri = html; + display->priv->selected_uri = NULL; + + gtk_selection_owner_set ( + display->priv->invisible, GDK_SELECTION_PRIMARY, + gtk_get_current_event_time ()); + gtk_selection_owner_set ( + display->priv->invisible, GDK_SELECTION_CLIPBOARD, + gtk_get_current_event_time ()); } static void -eab_uri_popup_link_copy(EPopup *ep, EPopupItem *pitem, void *data) +action_copy_link_cb (GtkAction *action, + EABContactDisplay *display) { - EABContactDisplay *display = data; - struct _EABContactDisplayPrivate *p = display->priv; - - g_free(p->selection_uri); - p->selection_uri = g_strdup(pitem->user_data); - - gtk_selection_owner_set(p->invisible, GDK_SELECTION_PRIMARY, gtk_get_current_event_time()); - gtk_selection_owner_set(p->invisible, GDK_SELECTION_CLIPBOARD, gtk_get_current_event_time()); + display->priv->clipboard_uri = display->priv->selected_uri; + display->priv->selected_uri = NULL; + + gtk_selection_owner_set ( + display->priv->invisible, GDK_SELECTION_PRIMARY, + gtk_get_current_event_time ()); + gtk_selection_owner_set ( + display->priv->invisible, GDK_SELECTION_CLIPBOARD, + gtk_get_current_event_time ()); } static void -eab_uri_popup_address_send(EPopup *ep, EPopupItem *item, void *data) +action_open_link_cb (GtkAction *action, + EABContactDisplay *display) { - EABPopupTargetURI *t = (EABPopupTargetURI *)ep->target; - const char *url = t->uri; - EABContactDisplay *display = data; - struct _EABContactDisplayPrivate *p = display->priv; - - int mail_num = atoi (url + strlen ("internal-mailto:")); + GdkScreen *screen; + const gchar *uri; + GError *error = NULL; - if (mail_num == -1) - return; - - eab_send_contact (p->contact, mail_num, EAB_DISPOSITION_AS_TO); + screen = gtk_widget_get_screen (GTK_WIDGET (display)); + uri = display->priv->selected_uri; + g_return_if_fail (uri != NULL); + if (!gtk_show_uri (screen, uri, GDK_CURRENT_TIME, &error)) { + g_warning ("%s", error->message); + g_error_free (error); + } } static void -eab_selection_get(GtkWidget *widget, GtkSelectionData *data, guint info, guint time_stamp, EABContactDisplay *display) +action_send_message_cb (GtkAction *action, + EABContactDisplay *display) { - struct _EABContactDisplayPrivate *p = display->priv; - - if (p->selection_uri == NULL) - return; - - gtk_selection_data_set(data, data->target, 8, (guchar *)p->selection_uri, strlen(p->selection_uri)); -} + EContact *contact; + const gchar *uri; + gint row; -static void -eab_selection_clear_event(GtkWidget *widget, GdkEventSelection *event, EABContactDisplay *display) -{ -#if 0 - struct _EABContactDisplayPrivate *p = display->priv; + uri = display->priv->selected_uri; + row = atoi (uri + strlen ("internal-mailto:")); + g_return_if_fail (row >= 0); - g_free(p->selection_uri); - p->selection_uri = NULL; -#endif + contact = eab_contact_display_get_contact (display); + eab_send_contact (contact, row, EAB_DISPOSITION_AS_TO); } -static EPopupItem eab_uri_popups[] = { - { E_POPUP_ITEM, "05.open", N_("_Open Link in Browser"), eab_uri_popup_link_open, NULL, NULL, EAB_POPUP_URI_NOT_MAILTO }, - { E_POPUP_ITEM, "10.copy", N_("_Copy Link Location"), eab_uri_popup_link_copy, NULL, "edit-copy", EAB_POPUP_URI_NOT_MAILTO }, - { E_POPUP_ITEM, "15.send", N_("_Send New Message To..."), eab_uri_popup_address_send, NULL, "mail-message-new", EAB_POPUP_URI_MAILTO}, - { E_POPUP_ITEM, "20.copy", N_("Copy _Email Address"), eab_uri_popup_email_address_copy, NULL, "edit-copy", EAB_POPUP_URI_MAILTO}, - }; +static GtkActionEntry email_entries[] = { + + { "copy-address", + NULL, + N_("Copy _Email Address"), + NULL, + NULL, + G_CALLBACK (action_copy_address_cb) }, + + { "send-message", + NULL, + N_("_Send New Message To..."), + NULL, + NULL, + G_CALLBACK (action_send_message_cb) } +}; +static GtkActionEntry uri_entries[] = { + + { "copy-link", + NULL, + N_("_Copy Link Location"), + NULL, + NULL, + G_CALLBACK (action_copy_link_cb) }, + + { "open-link", + NULL, + N_("_Open Link in Browser"), + NULL, + NULL, + G_CALLBACK (action_open_link_cb) } +}; static void -eab_uri_popup_free(EPopup *ep, GSList *list, void *data) +contact_display_selection_get (EABContactDisplay *display, + GtkSelectionData *data, + guint info, + guint time_stamp) { - while (list){ - GSList *n = list->next; - struct _EPopupItem *item = list->data; - - g_free(item->user_data); - item->user_data = NULL; - g_slist_free_1(list); + if (display->priv->clipboard_uri == NULL) + return; - list = n; - } + gtk_selection_data_set ( + data, data->target, 8, + (guchar *) display->priv->clipboard_uri, + strlen (display->priv->clipboard_uri)); } -static int -eab_uri_popup_event(EABContactDisplay *display, GdkEvent *event, const char *uri) +static void +contact_display_selection_clear_event (EABContactDisplay *display, + GdkEventSelection *event) { - EABPopup *emp; - EABPopupTargetURI *t ; - GtkMenu *menu; - GSList *menus = NULL; - int i; - - emp = eab_popup_new("org.gnome.evolution.addressbook.contactdisplay.popup"); - - t = eab_popup_target_new_uri(emp, uri); - t->target.widget = (GtkWidget *)display; - - for (i=0;i<sizeof(eab_uri_popups)/sizeof(eab_uri_popups[0]);i++) { - eab_uri_popups[i].user_data = g_strdup(t->uri); - menus = g_slist_prepend(menus, &eab_uri_popups[i]); - } - e_popup_add_items((EPopup *)emp, menus, NULL, eab_uri_popup_free, display); - - menu = e_popup_create_menu_once((EPopup *)emp,(EPopupTarget*)t, 0); - - if (event == NULL) { - gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); - } else { - gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event->button.button, event->button.time); - } - - return TRUE; + g_free (display->priv->clipboard_uri); + display->priv->clipboard_uri = NULL; } static void -on_url_requested (GtkHTML *html, const char *url, GtkHTMLStream *handle, - EABContactDisplay *display) +contact_display_on_url_requested (GtkHTML *html, + const gchar *url, + GtkHTMLStream *handle, + EABContactDisplay *display) { if (!strcmp (url, "internal-contact-photo:")) { EContactPhoto *photo; @@ -257,7 +275,9 @@ on_url_requested (GtkHTML *html, const char *url, GtkHTMLStream *handle, } static void -on_link_clicked (GtkHTML *html, const char *url, EABContactDisplay *display) +contact_display_on_link_clicked (GtkHTML *html, + const gchar *url, + EABContactDisplay *display) { GError *err = NULL; @@ -282,44 +302,6 @@ on_link_clicked (GtkHTML *html, const char *url, EABContactDisplay *display) } } -#if 0 -static void -render_address (GtkHTMLStream *html_stream, EContact *contact, const char *html_label, EContactField adr_field, EContactField label_field) -{ - EContactAddress *adr; - const char *label; - - label = e_contact_get_const (contact, label_field); - if (label) { - char *html = e_text_to_html (label, E_TEXT_TO_HTML_CONVERT_NL); - - gtk_html_stream_printf (html_stream, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td><td valign=\"top\" width=\"100\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\">%s</td></tr>", html_label, _("(map)"), html); - -This shoul g_free (html); - return; - } - - adr = e_contact_get (contact, adr_field); - if (adr && - (adr->po || adr->ext || adr->street || adr->locality || adr->region || adr->code || adr->country)) { - - gtk_html_stream_printf (html_stream, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td><td valign=\"top\" width=\"100\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\">", html_label, _("map")); - - if (adr->po && *adr->po) gtk_html_stream_printf (html_stream, "%s<br>", adr->po); - if (adr->ext && *adr->ext) gtk_html_stream_printf (html_stream, "%s<br>", adr->ext); - if (adr->street && *adr->street) gtk_html_stream_printf (html_stream, "%s<br>", adr->street); - if (adr->locality && *adr->locality) gtk_html_stream_printf (html_stream, "%s<br>", adr->locality); - if (adr->region && *adr->region) gtk_html_stream_printf (html_stream, "%s<br>", adr->region); - if (adr->code && *adr->code) gtk_html_stream_printf (html_stream, "%s<br>", adr->code); - if (adr->country && *adr->country) gtk_html_stream_printf (html_stream, "%s<br>", adr->country); - - gtk_html_stream_printf (html_stream, "</td></tr>"); - } - if (adr) - e_contact_address_free (adr); -} -#endif - static void render_name_value (GtkHTMLStream *html_stream, const char *label, const char *str, const char *icon, unsigned int html_flags) { @@ -677,12 +659,6 @@ eab_contact_display_render_normal (EABContactDisplay *display, EContact *contact GtkHTMLStream *html_stream; gboolean is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL); - if (display->priv->contact) - g_object_unref (display->priv->contact); - display->priv->contact = contact; - if (display->priv->contact) - g_object_ref (display->priv->contact); - html_stream = gtk_html_begin (GTK_HTML (display)); gtk_html_stream_write (html_stream, HTML_HEADER, sizeof (HTML_HEADER) - 1); gtk_html_stream_printf (html_stream, "<body><table width=\"100%%\"><tr><td %s>\n", is_rtl ? " align=\"right\" " : ""); @@ -733,16 +709,11 @@ eab_contact_display_render_normal (EABContactDisplay *display, EContact *contact } static void -eab_contact_display_render_compact (EABContactDisplay *display, EContact *contact) +eab_contact_display_render_compact (EABContactDisplay *display, + EContact *contact) { GtkHTMLStream *html_stream; - if (display->priv->contact) - g_object_unref (display->priv->contact); - display->priv->contact = contact; - if (display->priv->contact) - g_object_ref (display->priv->contact); - html_stream = gtk_html_begin (GTK_HTML (display)); gtk_html_stream_write (html_stream, HTML_HEADER, sizeof (HTML_HEADER) - 1); gtk_html_stream_write (html_stream, "<body>\n", 7); @@ -916,98 +887,254 @@ eab_contact_display_render_compact (EABContactDisplay *display, EContact *contac gtk_html_end (GTK_HTML (display), html_stream, GTK_HTML_STREAM_OK); } -void -eab_contact_display_render (EABContactDisplay *display, EContact *contact, - EABContactDisplayRenderMode mode) +static int +contact_display_button_press_event (GtkWidget *widget, + GdkEvent *event, + EABContactDisplay *display) { - switch (mode) { - case EAB_CONTACT_DISPLAY_RENDER_NORMAL: - eab_contact_display_render_normal (display, contact); - break; - case EAB_CONTACT_DISPLAY_RENDER_COMPACT: - eab_contact_display_render_compact (display, contact); - break; + GtkUIManager *ui_manager; + GtkActionGroup *action_group; + GtkWidget *menu; + gboolean has_email; + gchar *uri; + + if (event->button.button != 3) + return FALSE; + + uri = gtk_html_get_url_at ( + GTK_HTML (widget), + event->button.x, event->button.y); + + if (uri == NULL) + return FALSE; + + g_free (display->priv->selected_uri); + display->priv->selected_uri = uri; + + ui_manager = display->priv->ui_manager; + menu = gtk_ui_manager_get_widget (ui_manager, "/popup"); + g_return_val_if_fail (GTK_IS_MENU (menu), FALSE); + + has_email = (g_ascii_strncasecmp (uri, "internal-mailto:", 16) == 0); + + /* Show the appropriate actions. */ + action_group = display->priv->email_actions; + gtk_action_group_set_visible (action_group, has_email); + action_group = display->priv->uri_actions; + gtk_action_group_set_visible (action_group, !has_email); + + if (event != NULL) + gtk_menu_popup ( + GTK_MENU (menu), NULL, NULL, NULL, NULL, + event->button.button, event->button.time); + else + gtk_menu_popup ( + GTK_MENU (menu), NULL, NULL, NULL, NULL, + 0, gtk_get_current_event_time ()); + + return TRUE; +} + +static void +contact_display_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_CONTACT: + eab_contact_display_set_contact ( + EAB_CONTACT_DISPLAY (object), + g_value_get_object (value)); + return; + + case PROP_MODE: + eab_contact_display_set_mode ( + EAB_CONTACT_DISPLAY (object), + g_value_get_int (value)); + return; } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } -static int -eab_html_press_event (GtkWidget *widget, GdkEvent *event,EABContactDisplay *display) +static void +contact_display_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - char *uri; - gboolean res = FALSE; + switch (property_id) { + case PROP_CONTACT: + g_value_set_object ( + value, eab_contact_display_get_contact ( + EAB_CONTACT_DISPLAY (object))); + return; + case PROP_MODE: + g_value_set_int ( + value, eab_contact_display_get_mode ( + EAB_CONTACT_DISPLAY (object))); + return; + } - if (event->button.button!= 3 ) - return FALSE; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +contact_display_dispose (GObject *object) +{ + EABContactDisplayPrivate *priv; - uri = gtk_html_get_url_at (GTK_HTML (widget), event->button.x, event->button.y); - if (uri){ - eab_uri_popup_event(display,event,uri); - } + priv = EAB_CONTACT_DISPLAY_GET_PRIVATE (object); - g_free(uri); + if (priv->contact != NULL) { + g_object_unref (priv->contact); + priv->contact = NULL; + } - return res; + if (priv->ui_manager != NULL) { + g_object_unref (priv->ui_manager); + priv->ui_manager = NULL; + } + + if (priv->email_actions != NULL) { + g_object_unref (priv->email_actions); + priv->email_actions = NULL; + } + + if (priv->uri_actions != NULL) { + g_object_unref (priv->uri_actions); + priv->uri_actions = NULL; + } + + if (priv->invisible != NULL) { + g_object_unref (priv->invisible); + priv->invisible = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); } -GtkWidget* -eab_contact_display_new (void) +static void +contact_display_finalize (GObject *object) { - EABContactDisplay *display; - - struct _EABContactDisplayPrivate *p; - - display = g_object_new (EAB_TYPE_CONTACT_DISPLAY, NULL); - p=display->priv = g_new0 (EABContactDisplayPrivate, 1); - - gtk_html_set_default_content_type (GTK_HTML (display), "text/html; charset=utf-8"); - - gtk_html_set_editable (GTK_HTML (display), FALSE); - - g_signal_connect (display, "url_requested", - G_CALLBACK (on_url_requested), - display); - g_signal_connect (display, "link_clicked", - G_CALLBACK (on_link_clicked), - display); - g_signal_connect(display, "button_press_event", - G_CALLBACK(eab_html_press_event), - display); - p->invisible = gtk_invisible_new(); - g_signal_connect(p->invisible, "selection_get", G_CALLBACK(eab_selection_get), display); - g_signal_connect(p->invisible, "selection_clear_event", G_CALLBACK(eab_selection_clear_event), display); - gtk_selection_add_target(p->invisible, GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, 0); - gtk_selection_add_target(p->invisible, GDK_SELECTION_CLIPBOARD, GDK_SELECTION_TYPE_STRING, 1); - -#if 0 - g_signal_connect (display, "object_requested", - G_CALLBACK (on_object_requested), - mail_display); - g_signal_connect (display, "button_press_event", - G_CALLBACK (html_button_press_event), mail_display); - g_signal_connect (display, "motion_notify_event", - G_CALLBACK (html_motion_notify_event), mail_display); - g_signal_connect (display, "enter_notify_event", - G_CALLBACK (html_enter_notify_event), mail_display); - g_signal_connect (display, "iframe_created", - G_CALLBACK (html_iframe_created), mail_display); - g_signal_connect (display, "on_url", - G_CALLBACK (html_on_url), mail_display); -#endif + EABContactDisplayPrivate *priv; + + priv = EAB_CONTACT_DISPLAY_GET_PRIVATE (object); - return GTK_WIDGET (display); + g_free (priv->selected_uri); + g_free (priv->clipboard_uri); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); } static void -eab_contact_display_init (GObject *object) +eab_contact_display_class_init (EABContactDisplayClass *class) { - gtk_html_construct ((GtkHTML *)object); + GObjectClass *object_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EABContactDisplayPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = contact_display_set_property; + object_class->get_property = contact_display_get_property; + object_class->dispose = contact_display_dispose; + object_class->finalize = contact_display_finalize; + + g_object_class_install_property ( + object_class, + PROP_CONTACT, + g_param_spec_object ( + "contact", + NULL, + NULL, + E_TYPE_CONTACT, + G_PARAM_READWRITE)); + + /* XXX Make this a real enum property. */ + g_object_class_install_property ( + object_class, + PROP_MODE, + g_param_spec_int ( + "mode", + NULL, + NULL, + EAB_CONTACT_DISPLAY_RENDER_NORMAL, + EAB_CONTACT_DISPLAY_RENDER_COMPACT, + EAB_CONTACT_DISPLAY_RENDER_NORMAL, + G_PARAM_READWRITE)); } static void -eab_contact_display_class_init (GtkObjectClass *object_class) +eab_contact_display_init (EABContactDisplay *display) { - /* object_class->destroy = mail_display_destroy;*/ + GtkActionGroup *action_group; + GtkHTML *html; + + display->priv = EAB_CONTACT_DISPLAY_GET_PRIVATE (display); + display->priv->mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL; + display->priv->ui_manager = gtk_ui_manager_new (); + display->priv->invisible = gtk_invisible_new (); + + g_object_ref_sink (display->priv->invisible); + + action_group = gtk_action_group_new ("email"); + gtk_action_group_set_translation_domain ( + action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions ( + action_group, email_entries, + G_N_ELEMENTS (email_entries), display); + gtk_ui_manager_insert_action_group ( + display->priv->ui_manager, action_group, 0); + display->priv->email_actions = action_group; + + action_group = gtk_action_group_new ("uri"); + gtk_action_group_set_translation_domain ( + action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions ( + action_group, uri_entries, + G_N_ELEMENTS (uri_entries), display); + gtk_ui_manager_insert_action_group ( + display->priv->ui_manager, action_group, 0); + display->priv->uri_actions = action_group; + + gtk_ui_manager_add_ui_from_string ( + display->priv->ui_manager, ui, -1, NULL); + + html = GTK_HTML (display); + gtk_html_construct (html); + gtk_html_set_editable (html, FALSE); + gtk_html_set_default_content_type (html, "text/html; charset=utf-8"); + + g_signal_connect ( + display, "url-requested", + G_CALLBACK (contact_display_on_url_requested), display); + g_signal_connect ( + display, "link-clicked", + G_CALLBACK (contact_display_on_link_clicked), display); + g_signal_connect ( + display, "button-press-event", + G_CALLBACK (contact_display_button_press_event), display); + + g_signal_connect_swapped ( + display->priv->invisible, "selection-get", + G_CALLBACK (contact_display_selection_get), display); + g_signal_connect_swapped ( + display->priv->invisible, "selection-clear-event", + G_CALLBACK (contact_display_selection_clear_event), display); + gtk_selection_add_target ( + display->priv->invisible, + GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, 0); + gtk_selection_add_target ( + display->priv->invisible, + GDK_SELECTION_CLIPBOARD, GDK_SELECTION_TYPE_STRING, 1); + + e_plugin_ui_register_manager ( + "contact-display", display->priv->ui_manager, display); } GType @@ -1015,21 +1142,98 @@ eab_contact_display_get_type (void) { static GType type = 0; - if (!type) { - static const GTypeInfo info = { + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { sizeof (EABContactDisplayClass), - NULL, /* base_init */ - NULL, /* base_finalize */ + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, (GClassInitFunc) eab_contact_display_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ sizeof (EABContactDisplay), - 0, /* n_preallocs */ + 0, /* n_preallocs */ (GInstanceInitFunc) eab_contact_display_init, + NULL /* value_table */ }; - type = g_type_register_static (PARENT_TYPE, "EABContactDisplay", &info, 0); + type = g_type_register_static ( + GTK_TYPE_HTML, "EABContactDisplay", &type_info, 0); } return type; } + +GtkWidget * +eab_contact_display_new (void) +{ + return g_object_new (EAB_TYPE_CONTACT_DISPLAY, NULL); +} + +EContact * +eab_contact_display_get_contact (EABContactDisplay *display) +{ + g_return_val_if_fail (EAB_IS_CONTACT_DISPLAY (display), NULL); + + return display->priv->contact; +} + +void +eab_contact_display_set_contact (EABContactDisplay *display, + EContact *contact) +{ + EABContactDisplayMode mode; + + g_return_if_fail (EAB_IS_CONTACT_DISPLAY (display)); + + mode = eab_contact_display_get_mode (display); + + if (contact != NULL) + g_object_ref (contact); + if (display->priv->contact != NULL) + g_object_unref (display->priv->contact); + display->priv->contact = contact; + + switch (mode) { + case EAB_CONTACT_DISPLAY_RENDER_NORMAL: + eab_contact_display_render_normal (display, contact); + break; + + case EAB_CONTACT_DISPLAY_RENDER_COMPACT: + eab_contact_display_render_compact (display, contact); + break; + } + + g_object_notify (G_OBJECT (display), "contact"); +} + +EABContactDisplayMode +eab_contact_display_get_mode (EABContactDisplay *display) +{ + g_return_val_if_fail (EAB_IS_CONTACT_DISPLAY (display), 0); + + return display->priv->mode; +} + +void +eab_contact_display_set_mode (EABContactDisplay *display, + EABContactDisplayMode mode) +{ + EContact *contact; + + g_return_if_fail (EAB_IS_CONTACT_DISPLAY (display)); + + display->priv->mode = mode; + contact = eab_contact_display_get_contact (display); + + switch (mode) { + case EAB_CONTACT_DISPLAY_RENDER_NORMAL: + eab_contact_display_render_normal (display, contact); + break; + + case EAB_CONTACT_DISPLAY_RENDER_COMPACT: + eab_contact_display_render_compact (display, contact); + break; + } + + g_object_notify (G_OBJECT (display), "mode"); +} diff --git a/addressbook/gui/widgets/eab-contact-display.h b/addressbook/gui/widgets/eab-contact-display.h index c7b7f1a476..803a23d79f 100644 --- a/addressbook/gui/widgets/eab-contact-display.h +++ b/addressbook/gui/widgets/eab-contact-display.h @@ -20,30 +20,44 @@ * */ -#ifndef _EAB_CONTACT_DISPLAY_H_ -#define _EAB_CONTACT_DISPLAY_H_ +#ifndef EAB_CONTACT_DISPLAY_H +#define EAB_CONTACT_DISPLAY_H #include <gtkhtml/gtkhtml.h> #include <libebook/e-contact.h> -#define EAB_TYPE_CONTACT_DISPLAY (eab_contact_display_get_type ()) -#define EAB_CONTACT_DISPLAY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EAB_TYPE_CONTACT_DISPLAY, EABContactDisplay)) -#define EAB_CONTACT_DISPLAY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EAB_TYPE_CONTACT_DISPLAY, EABContactDisplayClass)) -#define IS_EAB_CONTACT_DISPLAY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EAB_TYPE_CONTACT_DISPLAY)) -#define IS_EAB_CONTACT_DISPLAY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EAB_TYPE_CONTACT_DISPLAY)) +/* Standard GObject macros */ +#define EAB_TYPE_CONTACT_DISPLAY \ + (eab_contact_display_get_type ()) +#define EAB_CONTACT_DISPLAY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), EAB_TYPE_CONTACT_DISPLAY, EABContactDisplay)) +#define EAB_CONTACT_DISPLAY_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), EAB_TYPE_CONTACT_DISPLAY, EABContactDisplayClass)) +#define EAB_IS_CONTACT_DISPLAY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), EAB_TYPE_CONTACT_DISPLAY)) +#define EAB_IS_CONTACT_DISPLAY_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), EAB_TYPE_CONTACT_DISPLAY)) +#define EAB_CONTACT_DISPLAY_GET_CLASS(obj) \ + (G_TYPE_ISNTANCE_GET_CLASS \ + ((obj), EAB_TYPE_CONTACT_DISPLAY, EABContactDisplayClass)) + +G_BEGIN_DECLS typedef struct _EABContactDisplay EABContactDisplay; -typedef struct _EABContactDisplayPrivate EABContactDisplayPrivate; typedef struct _EABContactDisplayClass EABContactDisplayClass; +typedef struct _EABContactDisplayPrivate EABContactDisplayPrivate; typedef enum { EAB_CONTACT_DISPLAY_RENDER_NORMAL, /* for use in the preview pane */ EAB_CONTACT_DISPLAY_RENDER_COMPACT /* for use with embedded vcards (e.g, the EABVCardControl) */ -} EABContactDisplayRenderMode; +} EABContactDisplayMode; struct _EABContactDisplay { GtkHTML parent; - EABContactDisplayPrivate *priv; }; @@ -51,10 +65,18 @@ struct _EABContactDisplayClass { GtkHTMLClass parent_class; }; -GType eab_contact_display_get_type (void); -GtkWidget * eab_contact_display_new (void); +GType eab_contact_display_get_type (void); +GtkWidget * eab_contact_display_new (void); + +EContact * eab_contact_display_get_contact (EABContactDisplay *display); +void eab_contact_display_set_contact (EABContactDisplay *display, + EContact *contact); +EABContactDisplayMode + eab_contact_display_get_mode (EABContactDisplay *display); +void eab_contact_display_set_mode (EABContactDisplay *display, + EABContactDisplayMode mode); + -void eab_contact_display_render (EABContactDisplay *display, EContact *contact, - EABContactDisplayRenderMode render_mode); +G_END_DECLS -#endif /* _EAB_CONTACT_DISPLAY_H_ */ +#endif /* EAB_CONTACT_DISPLAY_H */ diff --git a/addressbook/gui/widgets/eab-popup-control.c b/addressbook/gui/widgets/eab-popup-control.c deleted file mode 100644 index de3d21b7d6..0000000000 --- a/addressbook/gui/widgets/eab-popup-control.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - * This file is too big and this widget is too complicated. Forgive me. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - */ - -#include <config.h> -#include <string.h> -#include "addressbook.h" -#include "eab-popup-control.h" -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-property-bag.h> -#include <bonobo/bonobo-generic-factory.h> -#include <addressbook/util/eab-book-util.h> -#include <addressbook/gui/contact-editor/e-contact-editor.h> -#include <addressbook/gui/contact-editor/e-contact-quick-add.h> -#include <addressbook/gui/widgets/eab-contact-display.h> -#include <addressbook/gui/widgets/eab-gui-util.h> -#include "e-util/e-gui-utils.h" - -static void eab_popup_control_set_name (EABPopupControl *pop, const gchar *name); -static void eab_popup_control_set_email (EABPopupControl *pop, const gchar *email); -static void eab_popup_control_set_vcard (EABPopupControl *pop, const gchar *vcard); - -static GtkObjectClass *parent_class; - -static void eab_popup_control_dispose (GObject *); -static void eab_popup_control_query (EABPopupControl *); - - -static void -eab_popup_control_class_init (EABPopupControlClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->dispose = eab_popup_control_dispose; -} - -static void -eab_popup_control_init (EABPopupControl *pop) -{ - pop->transitory = TRUE; -} - -static void -eab_popup_control_cleanup (EABPopupControl *pop) -{ - if (pop->contact) { - g_object_unref (pop->contact); - pop->contact = NULL; - } - - if (pop->scheduled_refresh) { - g_source_remove (pop->scheduled_refresh); - pop->scheduled_refresh = 0; - } - - if (pop->query_tag) { -#ifdef notyet - e_book_simple_query_cancel (pop->book, pop->query_tag); -#endif - pop->query_tag = 0; - } - - if (pop->book) { - g_object_unref (pop->book); - pop->book = NULL; - } - - g_free (pop->name); - pop->name = NULL; - - g_free (pop->email); - pop->email = NULL; - - g_free (pop->vcard); - pop->vcard = NULL; -} - -static void -eab_popup_control_dispose (GObject *obj) -{ - EABPopupControl *pop = EAB_POPUP_CONTROL (obj); - - eab_popup_control_cleanup (pop); - - if (G_OBJECT_CLASS (parent_class)->dispose) - G_OBJECT_CLASS (parent_class)->dispose (obj); -} - -GType -eab_popup_control_get_type (void) -{ - static GType pop_type = 0; - - if (!pop_type) { - static const GTypeInfo pop_info = { - sizeof (EABPopupControlClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) eab_popup_control_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EABPopupControl), - 0, /* n_preallocs */ - (GInstanceInitFunc) eab_popup_control_init, - }; - - pop_type = g_type_register_static (gtk_event_box_get_type (), "EABPopupControl", &pop_info, 0); - } - - return pop_type; -} - -static void -eab_popup_control_refresh_names (EABPopupControl *pop) -{ - if (pop->name_widget) { - if (pop->name && *pop->name) { - gtk_label_set_text (GTK_LABEL (pop->name_widget), pop->name); - gtk_widget_show (pop->name_widget); - } else { - gtk_widget_hide (pop->name_widget); - } - } - - if (pop->email_widget) { - if (pop->email && *pop->email) { - gtk_label_set_text (GTK_LABEL (pop->email_widget), pop->email); - gtk_widget_show (pop->email_widget); - } else { - gtk_widget_hide (pop->email_widget); - } - } - - eab_popup_control_query (pop); -} - -static gint -refresh_timeout_cb (gpointer ptr) -{ - EABPopupControl *pop = EAB_POPUP_CONTROL (ptr); - eab_popup_control_refresh_names (pop); - pop->scheduled_refresh = 0; - return 0; -} - -static void -eab_popup_control_schedule_refresh (EABPopupControl *pop) -{ - if (pop->scheduled_refresh == 0) - pop->scheduled_refresh = g_timeout_add (20, refresh_timeout_cb, pop); -} - -/* If we are handed something of the form "Foo <bar@bar.com>", - do the right thing. */ -static gboolean -eab_popup_control_set_free_form (EABPopupControl *pop, const gchar *txt) -{ - gchar *lt, *gt = NULL; - - g_return_val_if_fail (pop && EAB_IS_POPUP_CONTROL (pop), FALSE); - - if (txt == NULL) - return FALSE; - - lt = strchr (txt, '<'); - if (lt) - gt = strchr (txt, '>'); - - if (lt && gt && lt+1 < gt) { - gchar *name = g_strndup (txt, lt-txt); - gchar *email = g_strndup (lt+1, gt-lt-1); - eab_popup_control_set_name (pop, name); - eab_popup_control_set_email (pop, email); - g_free(name); - g_free(email); - - return TRUE; - } - - return FALSE; -} - -static void -eab_popup_control_set_name (EABPopupControl *pop, const gchar *name) -{ - g_return_if_fail (pop && EAB_IS_POPUP_CONTROL (pop)); - - /* We only allow the name to be set once. */ - if (pop->name) - return; - - if (!eab_popup_control_set_free_form (pop, name)) { - pop->name = g_strdup (name); - if (pop->name) - g_strstrip (pop->name); - } - - eab_popup_control_schedule_refresh (pop); -} - -static void -eab_popup_control_set_email (EABPopupControl *pop, const gchar *email) -{ - g_return_if_fail (pop && EAB_IS_POPUP_CONTROL (pop)); - - /* We only allow the e-mail to be set once. */ - if (pop->email) - return; - - if (!eab_popup_control_set_free_form (pop, email)) { - pop->email = g_strdup (email); - if (pop->email) - g_strstrip (pop->email); - } - - eab_popup_control_schedule_refresh (pop); -} - -static void -eab_popup_control_set_vcard (EABPopupControl *pop, const gchar *vcard) -{ - g_return_if_fail (pop && EAB_IS_POPUP_CONTROL (pop)); - - /* We only allow the vcard to be set once. */ - if (pop->vcard) - return; - - g_free (pop->name); - g_free (pop->email); - - pop->name = NULL; - pop->email = NULL; - - pop->vcard = g_strdup (vcard); - - eab_popup_control_schedule_refresh (pop); -} - -void -eab_popup_control_construct (EABPopupControl *pop) -{ - GtkWidget *vbox, *name_holder; - GdkColor color = { 0x0, 0xffff, 0xffff, 0xffff }; - - g_return_if_fail (pop && EAB_IS_POPUP_CONTROL (pop)); - - pop->main_vbox = gtk_vbox_new (FALSE, 0); - - /* Build Generic View */ - - name_holder = gtk_event_box_new (); - vbox = gtk_vbox_new (FALSE, 2); - pop->name_widget = gtk_label_new (""); - pop->email_widget = gtk_label_new (""); - - gtk_box_pack_start (GTK_BOX (vbox), pop->name_widget, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (vbox), pop->email_widget, TRUE, TRUE, 2); - gtk_container_add (GTK_CONTAINER (name_holder), GTK_WIDGET (vbox)); - - if (gdk_colormap_alloc_color (gtk_widget_get_colormap (GTK_WIDGET (name_holder)), &color, FALSE, TRUE)) { - GtkStyle *style = gtk_style_copy (gtk_widget_get_style (GTK_WIDGET (name_holder))); - style->bg[0] = color; - gtk_widget_set_style (GTK_WIDGET (name_holder), style); - g_object_unref (style); - } - - pop->generic_view = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (pop->generic_view), name_holder); - gtk_box_pack_start (GTK_BOX (pop->main_vbox), pop->generic_view, TRUE, TRUE, 0); - gtk_widget_show_all (pop->generic_view); - - pop->query_msg = gtk_label_new (_("Querying Address Book...")); - gtk_box_pack_start (GTK_BOX (pop->main_vbox), pop->query_msg, TRUE, TRUE, 0); - gtk_widget_show (pop->query_msg); - - /* Build ContactDisplay */ - pop->contact_display = eab_contact_display_new (); - gtk_box_pack_start (GTK_BOX (pop->main_vbox), pop->contact_display, TRUE, TRUE, 0); - - - /* Final assembly */ - - gtk_container_add (GTK_CONTAINER (pop), pop->main_vbox); - gtk_widget_show (pop->main_vbox); - - gtk_container_set_border_width (GTK_CONTAINER (vbox), 3); - gtk_container_set_border_width (GTK_CONTAINER (pop), 2); -} - -static GtkWidget * -eab_popup_new (void) -{ - EABPopupControl *pop = g_object_new (EAB_TYPE_POPUP_CONTROL, NULL); - eab_popup_control_construct (pop); - return GTK_WIDGET (pop); -} - -static void -emit_event (EABPopupControl *pop, const char *event) -{ - if (pop->es) { - BonoboArg *arg; - - arg = bonobo_arg_new (BONOBO_ARG_BOOLEAN); - BONOBO_ARG_SET_BOOLEAN (arg, TRUE); - bonobo_event_source_notify_listeners_full (pop->es, - "GNOME/Evolution/Addressbook/AddressPopup", - "Event", - event, - arg, NULL); - bonobo_arg_release (arg); - } -} - -static void -eab_popup_control_no_matches (EABPopupControl *pop) -{ - if (pop->vcard && *pop->vcard) - e_contact_quick_add_vcard (pop->vcard, NULL, NULL); - else if (pop->email && *pop->email) { - if (pop->name && *pop->name) - e_contact_quick_add (pop->name, pop->email, NULL, NULL); - else - e_contact_quick_add_free_form (pop->email, NULL, NULL); - - } - eab_popup_control_cleanup (pop); - emit_event (pop, "Destroy"); -} - -static void -eab_popup_control_query (EABPopupControl *pop) -{ - g_return_if_fail (pop && EAB_IS_POPUP_CONTROL (pop)); - - g_object_ref (pop); - - eab_popup_control_no_matches (pop) ; - - g_object_unref (pop); - -} - -/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/ - -enum { - PROPERTY_NAME, - PROPERTY_EMAIL, - PROPERTY_TRANSITORY, - PROPERTY_VCARD -}; - -static void -set_prop (BonoboPropertyBag *bag, const BonoboArg *arg, guint arg_id, CORBA_Environment *ev, gpointer user_data) -{ - EABPopupControl *pop = EAB_POPUP_CONTROL (user_data); - - switch (arg_id) { - - case PROPERTY_NAME: - eab_popup_control_set_name (pop, BONOBO_ARG_GET_STRING (arg)); - break; - - case PROPERTY_EMAIL: - eab_popup_control_set_email (pop, BONOBO_ARG_GET_STRING (arg)); - break; - - case PROPERTY_VCARD: - eab_popup_control_set_vcard (pop, BONOBO_ARG_GET_STRING (arg)); - break; - - default: - g_return_if_reached (); - } -} - -static void -get_prop (BonoboPropertyBag *bag, BonoboArg *arg, guint arg_id, CORBA_Environment *ev, gpointer user_data) -{ - EABPopupControl *pop = EAB_POPUP_CONTROL (user_data); - - switch (arg_id) { - - case PROPERTY_NAME: - BONOBO_ARG_SET_STRING (arg, pop->name); - break; - - case PROPERTY_EMAIL: - BONOBO_ARG_SET_STRING (arg, pop->email); - break; - - case PROPERTY_TRANSITORY: - BONOBO_ARG_SET_BOOLEAN (arg, pop->transitory); - break; - - case PROPERTY_VCARD: - BONOBO_ARG_SET_STRING (arg, pop->vcard); - break; - - default: - g_return_if_reached (); - } -} - -BonoboControl * -eab_popup_control_new (void) -{ - BonoboControl *control; - BonoboPropertyBag *bag; - EABPopupControl *addy; - GtkWidget *w; - - w = eab_popup_new (); - addy = EAB_POPUP_CONTROL (w); - - control = bonobo_control_new (w); - gtk_widget_show (w); - - bag = bonobo_property_bag_new (get_prop, set_prop, w); - bonobo_property_bag_add (bag, "name", PROPERTY_NAME, - BONOBO_ARG_STRING, NULL, NULL, - BONOBO_PROPERTY_WRITEABLE | BONOBO_PROPERTY_READABLE); - - bonobo_property_bag_add (bag, "email", PROPERTY_EMAIL, - BONOBO_ARG_STRING, NULL, NULL, - BONOBO_PROPERTY_WRITEABLE | BONOBO_PROPERTY_READABLE); - - bonobo_property_bag_add (bag, "transitory", PROPERTY_TRANSITORY, - BONOBO_ARG_BOOLEAN, NULL, NULL, - BONOBO_PROPERTY_READABLE); - - bonobo_property_bag_add (bag, "vcard", PROPERTY_VCARD, - BONOBO_ARG_STRING, NULL, NULL, - BONOBO_PROPERTY_WRITEABLE | BONOBO_PROPERTY_READABLE); - - bonobo_control_set_properties (control, bonobo_object_corba_objref (BONOBO_OBJECT (bag)), NULL); - bonobo_object_unref (BONOBO_OBJECT (bag)); - - addy->es = bonobo_event_source_new (); - bonobo_object_add_interface (BONOBO_OBJECT (control), - BONOBO_OBJECT (addy->es)); - - return control; -} diff --git a/addressbook/gui/widgets/eab-popup-control.h b/addressbook/gui/widgets/eab-popup-control.h deleted file mode 100644 index 4a6539e29c..0000000000 --- a/addressbook/gui/widgets/eab-popup-control.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Jon Trowbridge <trow@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __EAB_POPUP_CONTROL_H__ -#define __EAB_POPUP_CONTROL_H__ - -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-event-source.h> -#include <libebook/e-book.h> -#include <libebook/e-contact.h> - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define EAB_TYPE_POPUP_CONTROL (eab_popup_control_get_type ()) -#define EAB_POPUP_CONTROL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EAB_TYPE_POPUP_CONTROL, EABPopupControl)) -#define EAB_POPUP_CONTROL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EAB_TYPE_POPUP_CONTROL, EABPopupControlClass)) -#define EAB_IS_POPUP_CONTROL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EAB_TYPE_POPUP_CONTROL)) -#define EAB_IS_POPUP_CONTROL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EAB_TYPE_POPUP_CONTROL)) - -typedef struct _EABPopupControl EABPopupControl; -typedef struct _EABPopupControlClass EABPopupControlClass; - -struct _EABPopupControl { - GtkEventBox parent; - - gchar *name; - gchar *email; - gchar *vcard; - - GtkWidget *name_widget; - GtkWidget *email_widget; - GtkWidget *query_msg; - - GtkWidget *main_vbox; - GtkWidget *generic_view; - GtkWidget *contact_display; - - gboolean transitory; - - guint scheduled_refresh; - EBook *book; - guint query_tag; - gboolean multiple_matches; - EContact *contact; - - BonoboEventSource *es; -}; - -struct _EABPopupControlClass { - GtkEventBoxClass parent_class; -}; - -GType eab_popup_control_get_type (void); - -void eab_popup_control_construct (EABPopupControl *); - -BonoboControl *eab_popup_control_new (void); - -G_END_DECLS - -#endif /* __EAB_POPUP_CONTROL_H__ */ - diff --git a/addressbook/gui/widgets/eab-popup.c b/addressbook/gui/widgets/eab-popup.c deleted file mode 100644 index 17f979734b..0000000000 --- a/addressbook/gui/widgets/eab-popup.c +++ /dev/null @@ -1,368 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Michael Zucchi <notzed@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <stdlib.h> - -#include <glib.h> - -#include "eab-popup.h" -#include <libedataserverui/e-source-selector.h> -#include <libebook/e-contact.h> - -static GObjectClass *eabp_parent; - -static void -eabp_init(GObject *o) -{ - /*EABPopup *eabp = (EABPopup *)o; */ -} - -static void -eabp_finalise(GObject *o) -{ - ((GObjectClass *)eabp_parent)->finalize(o); -} - -static void -eabp_target_free(EPopup *ep, EPopupTarget *t) -{ - 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); - - break; } - case EAB_POPUP_TARGET_URI: { - EABPopupTargetURI *s = (EABPopupTargetURI *)t; - - g_free(s->uri); - break; } - case EAB_POPUP_TARGET_SOURCE: { - EABPopupTargetSource *s = (EABPopupTargetSource *)t; - - g_object_unref(s->selector); - break; } - -#ifdef ADAPTED_TO_E_NAME_SELECTOR - - case EAB_POPUP_TARGET_SELECT_NAMES: { - EABPopupTargetSelectNames *s = (EABPopupTargetSelectNames *)t; - - g_object_unref(s->model); - break; } - -#endif - - } - - ((EPopupClass *)eabp_parent)->target_free(ep, t); -} - -static void -eabp_class_init(GObjectClass *klass) -{ - klass->finalize = eabp_finalise; - ((EPopupClass *)klass)->target_free = eabp_target_free; -} - -GType -eab_popup_get_type(void) -{ - static GType type = 0; - - if (type == 0) { - static const GTypeInfo info = { - sizeof(EABPopupClass), - NULL, NULL, - (GClassInitFunc)eabp_class_init, - NULL, NULL, - sizeof(EABPopup), 0, - (GInstanceInitFunc)eabp_init - }; - eabp_parent = g_type_class_ref(e_popup_get_type()); - type = g_type_register_static(e_popup_get_type(), "EABPopup", &info, 0); - } - - return type; -} - -EABPopup *eab_popup_new(const char *menuid) -{ - EABPopup *eabp = g_object_new(eab_popup_get_type(), NULL); - - e_popup_construct(&eabp->popup, menuid); - - return eabp; -} - -/** - * 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: - **/ - - -EABPopupTargetURI * -eab_popup_target_new_uri(EABPopup *emp, const char *uri) -{ - EABPopupTargetURI *t = e_popup_target_new(&emp->popup, EAB_POPUP_TARGET_URI, sizeof(*t)); - guint32 mask = ~0; - - t->uri = g_strdup(uri); - - if (g_ascii_strncasecmp(uri, "http:", 5) == 0 - || g_ascii_strncasecmp(uri, "https:", 6) == 0) - mask &= ~EAB_POPUP_URI_HTTP; - if (g_ascii_strncasecmp(uri, "internal-mailto:", 16) == 0) - mask &= ~EAB_POPUP_URI_MAILTO; - else - mask &= ~EAB_POPUP_URI_NOT_MAILTO; - - t->target.mask = mask; - - return t; -} - - - - -EABPopupTargetSelect * -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; - - /* FIXME: duplicated in eab-menu.c */ - - 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 (cards->len == 1) { - if (e_contact_get (E_CONTACT(cards->pdata[0]), E_CONTACT_IS_LIST)) - mask &= ~EAB_POPUP_LIST; - else - mask &= ~EAB_POPUP_CONTACT; - } - - if (has_email) - mask &= ~EAB_POPUP_SELECT_EMAIL; - - if (!readonly) - mask &= ~EAB_POPUP_SELECT_EDITABLE; - - if (cards->len == 1) - mask &= ~EAB_POPUP_SELECT_ONE; - - if (cards->len > 1) - mask &= ~EAB_POPUP_SELECT_MANY; - - if (cards->len >= 1) - mask &= ~EAB_POPUP_SELECT_ANY; - - t->target.mask = mask; - - return t; -} - -EABPopupTargetSource * -eab_popup_target_new_source(EABPopup *eabp, ESourceSelector *selector) -{ - EABPopupTargetSource *t = e_popup_target_new(&eabp->popup, EAB_POPUP_TARGET_SOURCE, sizeof(*t)); - guint32 mask = ~0; - const char *source_uri; - ESource *source; - - /* TODO: this is duplicated for calendar and tasks too */ - - t->selector = selector; - g_object_ref(selector); - - /* TODO: perhaps we need to copy this so it doesn't change during the lifecycle */ - source = e_source_selector_peek_primary_selection(selector); - if (source) - mask &= ~EAB_POPUP_SOURCE_PRIMARY; - - /* FIXME Gross hack, should have a property or something */ - source_uri = e_source_peek_relative_uri(source); - if (source_uri && !strcmp("system", source_uri)) - mask &= ~EAB_POPUP_SOURCE_SYSTEM; - else - mask &= ~EAB_POPUP_SOURCE_USER; - - t->target.mask = mask; - - return t; -} - -#ifdef ADAPTED_TO_E_NAME_SELECTOR - -EABPopupTargetSelectNames * -eab_popup_target_new_select_names(EABPopup *eabp, struct _ESelectNamesModel *model, int row) -{ - EABPopupTargetSelectNames *t = e_popup_target_new(&eabp->popup, EAB_POPUP_TARGET_SELECT_NAMES, sizeof(*t)); - - /* TODO: this is sort of not very useful, maybe the popup which uses it doesn't - need to be pluggable */ - - t->model = model; - g_object_ref(model); - t->row = row; - - return t; -} - -#endif - -/* ********************************************************************** */ -/* Popup menu plugin handler */ - -/* -<e-plugin - class="org.gnome.mail.plugin.popup:1.0" - id="org.gnome.mail.plugin.popup.iteab:1.0" - type="shlib" - location="/opt/gnome2/lib/camel/1.0/libcamelimap.so" - name="imap" - description="IMAP4 and IMAP4v1 mail store"> - <hook class="org.gnome.mail.popupMenu:1.0" - handler="HandlePopup"> - <menu id="any" target="select"> - <iteab - type="iteab|toggle|radio|image|submenu|bar" - active - path="foo/bar" - label="label" - icon="foo" - mask="select_one" - activate="eabp_view_eabacs"/> - </menu> - </extension> - -*/ - -static void *eabph_parent_class; -#define eabph ((EABPopupHook *)eph) - -static const EPopupHookTargetMask eabph_select_masks[] = { - { "one", EAB_POPUP_SELECT_ONE }, - { "many", EAB_POPUP_SELECT_MANY }, - { "any", EAB_POPUP_SELECT_ANY }, - { "editable", EAB_POPUP_SELECT_EDITABLE }, - { "email", EAB_POPUP_SELECT_EMAIL }, - { NULL } -}; - -static const EPopupHookTargetMask eabph_source_masks[] = { - { "primary", EAB_POPUP_SOURCE_PRIMARY }, - { "system", EAB_POPUP_SOURCE_SYSTEM }, - { NULL } -}; - -static const EPopupHookTargetMask eabph_uri_masks[] = { - { "http", EAB_POPUP_URI_HTTP }, - { "internal-mailto", EAB_POPUP_URI_MAILTO }, - { "notmailto", EAB_POPUP_URI_NOT_MAILTO }, - { NULL } -}; - -static const EPopupHookTargetMask eabph_select_names_masks[] = { - { NULL } -}; - -static const EPopupHookTargetMap eabph_targets[] = { - { "select", EAB_POPUP_TARGET_SELECT, eabph_select_masks }, - { "uri", EAB_POPUP_TARGET_URI, eabph_uri_masks }, - { "source", EAB_POPUP_TARGET_SOURCE, eabph_source_masks }, - { "select-names", EAB_POPUP_TARGET_SELECT_NAMES, eabph_select_names_masks }, - { NULL } -}; - -static void -eabph_finalise(GObject *o) -{ - /*EPluginHook *eph = (EPluginHook *)o;*/ - - ((GObjectClass *)eabph_parent_class)->finalize(o); -} - -static void -eabph_class_init(EPluginHookClass *klass) -{ - int i; - - ((GObjectClass *)klass)->finalize = eabph_finalise; - ((EPluginHookClass *)klass)->id = "org.gnome.evolution.addressbook.popup:1.0"; - - for (i=0;eabph_targets[i].type;i++) - e_popup_hook_class_add_target_map((EPopupHookClass *)klass, &eabph_targets[i]); - - ((EPopupHookClass *)klass)->popup_class = g_type_class_ref(eab_popup_get_type()); -} - -GType -eab_popup_hook_get_type(void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof(EABPopupHookClass), NULL, NULL, (GClassInitFunc) eabph_class_init, NULL, NULL, - sizeof(EABPopupHook), 0, (GInstanceInitFunc) NULL, - }; - - eabph_parent_class = g_type_class_ref(e_popup_hook_get_type()); - type = g_type_register_static(e_popup_hook_get_type(), "EABPopupHook", &info, 0); - } - - return type; -} diff --git a/addressbook/gui/widgets/eab-popup.h b/addressbook/gui/widgets/eab-popup.h deleted file mode 100644 index 933c815af8..0000000000 --- a/addressbook/gui/widgets/eab-popup.h +++ /dev/null @@ -1,201 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Michael Zucchi <notzed@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __EAB_POPUP_H__ -#define __EAB_POPUP_H__ - -#include <glib-object.h> - -#include "e-util/e-popup.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define ADAPTED_TO_E_NAME_SELECTOR 1 - -typedef struct _EABPopup EABPopup; -typedef struct _EABPopupClass EABPopupClass; - -/** - * enum _eab_popup_target_t - A list of mail popup target types. - * - * @EAB_POPUP_TARGET_SELECT: A selection of cards - * @EAB_POPUP_TARGET_SOURCE: A source selection. - * - * Defines the value of the targetid for all EABPopup target types. - **/ -enum _eab_popup_target_t { - EAB_POPUP_TARGET_SELECT, - EAB_POPUP_TARGET_URI, - EAB_POPUP_TARGET_SOURCE, - EAB_POPUP_TARGET_SELECT_NAMES, -}; - -/** - * enum _eab_popup_target_select_t - EABPopupTargetSelect qualifiers. - * - * @EAB_POPUP_SELECT_ONE: Only one item is selected. - * @EAB_POPUP_SELECT_MANY: Two or more items are selected. - * @EAB_POPUP_SELECT_ANY: One or 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<<0, - EAB_POPUP_SELECT_MANY = 1<<1, - EAB_POPUP_SELECT_ANY = 1<<2, - EAB_POPUP_SELECT_EDITABLE = 1<<3, - EAB_POPUP_SELECT_EMAIL = 1<<4, - EAB_POPUP_LIST = 1<<5, - EAB_POPUP_CONTACT = 1<<6, -}; - -enum _eab_popup_target_uri_t { - EAB_POPUP_URI_HTTP = 1<<0, - EAB_POPUP_URI_MAILTO = 1<<1, - EAB_POPUP_URI_NOT_MAILTO = 1<<2, -}; -/** - * enum _eab_popup_target_source_t - EABPopupTargetSource qualifiers. - * - * @EAB_POPUP_SOURCE_PRIMARY: Has a primary selection. - * @EAB_POPUP_SOURCE_SYSTEM: Is a 'system' folder. - * - **/ -enum _eab_popup_target_source_t { - EAB_POPUP_SOURCE_PRIMARY = 1<<0, - EAB_POPUP_SOURCE_SYSTEM = 1<<1, /* system folder */ - EAB_POPUP_SOURCE_USER = 1<<2, /* user folder (!system) */ -}; - -typedef struct _EABPopupTargetSelect EABPopupTargetSelect; -typedef struct _EABPopupTargetSource EABPopupTargetSource; -typedef struct _EABPopupTargetSelectNames EABPopupTargetSelectNames; -typedef struct _EABPopupTargetURI EABPopupTargetURI; -/** - * 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. - **/ -struct _EABPopupTargetSelect { - EPopupTarget target; - - struct _EBook *book; - GPtrArray *cards; -}; - - -struct _EABPopupTargetURI { - EPopupTarget target; - char *uri; -}; - -/** - * struct _EABPopupTargetSource - A source target. - * - * @target: Superclass. - * @selector: Selector holding the source selection. - * - * This target is used to represent a source selection. - **/ -struct _EABPopupTargetSource { - EPopupTarget target; - - struct _ESourceSelector *selector; -}; - -#ifdef ADAPTED_TO_E_NAME_SELECTOR - -/** - * struct _EABPopupTargetSelectNames - A select names target. - * - * @target: Superclass. - * @model: Select names model. - * @row: Row of item selected. - * - * This target is used to represent an item selected in an - * ESelectNames model. - **/ -struct _EABPopupTargetSelectNames { - EPopupTarget target; - - struct _ESelectNamesModel *model; - int row; -}; - -#endif - -typedef struct _EPopupItem EABPopupItem; - -/* The object */ -struct _EABPopup { - EPopup popup; - - struct _EABPopupPrivate *priv; -}; - -struct _EABPopupClass { - EPopupClass popup_class; -}; - -GType eab_popup_get_type(void); - -EABPopup *eab_popup_new(const char *menuid); - -EABPopupTargetSelect *eab_popup_target_new_select(EABPopup *eabp, struct _EBook *book, int readonly, GPtrArray *cards); -EABPopupTargetURI *eab_popup_target_new_uri(EABPopup *emp, const char *uri); -EABPopupTargetSource *eab_popup_target_new_source(EABPopup *eabp, struct _ESourceSelector *selector); - -#ifdef ADAPTED_TO_E_NAME_SELECTOR - -EABPopupTargetSelectNames *eab_popup_target_new_select_names(EABPopup *eabp, struct _ESelectNamesModel *model, int row); - -#endif - -/* ********************************************************************** */ - -typedef struct _EABPopupHook EABPopupHook; -typedef struct _EABPopupHookClass EABPopupHookClass; - -struct _EABPopupHook { - EPopupHook hook; -}; - -struct _EABPopupHookClass { - EPopupHookClass hook_class; -}; - -GType eab_popup_hook_get_type(void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __EAB_POPUP_H__ */ diff --git a/addressbook/gui/widgets/eab-vcard-control.c b/addressbook/gui/widgets/eab-vcard-control.c index 2379559e3d..431229498e 100644 --- a/addressbook/gui/widgets/eab-vcard-control.c +++ b/addressbook/gui/widgets/eab-vcard-control.c @@ -46,7 +46,7 @@ typedef struct { EABContactDisplay *display; GList *card_list; GtkWidget *label; - EABContactDisplayRenderMode render_mode; + EABContactDisplayMode mode; } EABVCardControl; #define VCARD_CONTROL_ID "OAFIID:GNOME_Evolution_Addressbook_VCard_Control:" BASE_VERSION @@ -134,8 +134,10 @@ pstream_load (BonoboPersistStream *ps, const Bonobo_Stream stream, g_free(vcard); vcard_control->card_list = list; if (list) { - eab_contact_display_render (vcard_control->display, E_CONTACT (list->data), - vcard_control->render_mode); + eab_contact_display_set_mode ( + vcard_control->display, vcard_control->mode); + eab_contact_display_set_contact ( + vcard_control->display, E_CONTACT (list->data)); } if (list && list->next) { char *message; @@ -218,23 +220,29 @@ static void toggle_full_vcard(GtkWidget *button, gpointer data) { EABVCardControl *vcard_control = data; + EContact *contact; char *label; if (!vcard_control->card_list) return; - if (vcard_control->render_mode == EAB_CONTACT_DISPLAY_RENDER_NORMAL) { - vcard_control->render_mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; + contact = E_CONTACT (vcard_control->card_list->data); + + if (vcard_control->mode == EAB_CONTACT_DISPLAY_RENDER_NORMAL) { + vcard_control->mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; label = _("Show Full vCard"); } else { - vcard_control->render_mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL; + vcard_control->mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL; label = _("Show Compact vCard"); } gtk_button_set_label (GTK_BUTTON (button), label); - eab_contact_display_render (vcard_control->display, E_CONTACT (vcard_control->card_list->data), - vcard_control->render_mode); + + eab_contact_display_set_mode ( + vcard_control->display, vcard_control->mode); + eab_contact_display_set_contact ( + vcard_control->display, contact); } static void @@ -265,7 +273,7 @@ eab_vcard_control_new (void) vcard_control->display = NULL; vcard_control->label = NULL; - vcard_control->render_mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; + vcard_control->mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; /* Create the control. */ diff --git a/shell/e-shell-sidebar.c b/shell/e-shell-sidebar.c index b67dc5b5e1..9d33024702 100644 --- a/shell/e-shell-sidebar.c +++ b/shell/e-shell-sidebar.c @@ -364,7 +364,6 @@ shell_sidebar_init (EShellSidebar *shell_sidebar) widget = gtk_event_box_new (); style = gtk_widget_get_style (widget); color = &style->bg[GTK_STATE_ACTIVE]; - gtk_container_set_border_width (GTK_CONTAINER (widget), 1); gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, color); gtk_widget_set_parent (widget, GTK_WIDGET (shell_sidebar)); shell_sidebar->priv->event_box = g_object_ref (widget); diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c index 96895908d8..7cb7defa33 100644 --- a/shell/e-shell-window.c +++ b/shell/e-shell-window.c @@ -648,6 +648,38 @@ e_shell_window_set_safe_mode (EShellWindow *shell_window, } /** + * e_shell_window_show_popup_menu: + * @shell_window: an #EShellWindow + * @widget_path: path in the UI definition + * @event: a #GdkEventButton + * + * Displays a context-sensitive (or "popup") menu that is described in + * the UI definition loaded into @shell_window<!-- -->'s user interface + * manager. The menu will be shown at the current mouse cursor position. + **/ +void +e_shell_window_show_popup_menu (EShellWindow *shell_window, + const gchar *widget_path, + GdkEventButton *event) +{ + GtkWidget *menu; + + g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); + + menu = e_shell_window_get_managed_widget (shell_window, widget_path); + g_return_if_fail (GTK_IS_MENU (menu)); + + if (event != NULL) + gtk_menu_popup ( + GTK_MENU (menu), NULL, NULL, NULL, NULL, + event->button, event->time); + else + gtk_menu_popup ( + GTK_MENU (menu), NULL, NULL, NULL, NULL, + 0, gtk_get_current_event_time ()); +} + +/** * e_shell_window_register_new_item_actions: * @shell_window: an #EShellWindow * @module_name: name of an #EShellModule diff --git a/shell/e-shell-window.h b/shell/e-shell-window.h index 002c37914e..bbc137dd07 100644 --- a/shell/e-shell-window.h +++ b/shell/e-shell-window.h @@ -80,6 +80,9 @@ void e_shell_window_set_active_view (EShellWindow *shell_window, gboolean e_shell_window_get_safe_mode (EShellWindow *shell_window); void e_shell_window_set_safe_mode (EShellWindow *shell_window, gboolean safe_mode); +void e_shell_window_show_popup_menu (EShellWindow *shell_window, + const gchar *widget_path, + GdkEventButton *event); /* These should be called from the shell module's window_created() handler. */ |