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 /addressbook/gui/component | |
parent | bb7cb1d677117a938ae18d9cae7acc7a56678b6f (diff) | |
download | gsoc2013-evolution-8d21ab98d99ca43ee7873adba8172b699d8a007f.tar.gz 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
Diffstat (limited to 'addressbook/gui/component')
-rw-r--r-- | addressbook/gui/component/e-book-shell-view-actions.c | 15 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view-private.c | 161 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view-private.h | 3 | ||||
-rw-r--r-- | addressbook/gui/component/e-book-shell-view.c | 10 |
4 files changed, 127 insertions, 62 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 |