[evolution] Contacts view: Add 'Refresh' into books context menu



commit be217ae4c574b82a8ecbc7dbb506aca36f6e56fa
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jul 1 15:53:06 2013 +0200

    Contacts view: Add 'Refresh' into books context menu
    
    Done as part of bug #700894

 modules/addressbook/e-book-shell-sidebar.c      |   13 +++++
 modules/addressbook/e-book-shell-sidebar.h      |    3 +-
 modules/addressbook/e-book-shell-view-actions.c |   67 +++++++++++++++++++++++
 modules/addressbook/e-book-shell-view-actions.h |    2 +
 modules/addressbook/e-book-shell-view.c         |    7 +++
 ui/evolution-contacts.ui                        |    1 +
 6 files changed, 92 insertions(+), 1 deletions(-)
---
diff --git a/modules/addressbook/e-book-shell-sidebar.c b/modules/addressbook/e-book-shell-sidebar.c
index 9c655e7..b29bd9a 100644
--- a/modules/addressbook/e-book-shell-sidebar.c
+++ b/modules/addressbook/e-book-shell-sidebar.c
@@ -194,6 +194,7 @@ book_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
        gboolean is_remote_deletable = FALSE;
        gboolean in_collection = FALSE;
        gboolean has_primary_source = FALSE;
+       gboolean refresh_supported = FALSE;
        guint32 state = 0;
 
        book_shell_sidebar = E_BOOK_SHELL_SIDEBAR (shell_sidebar);
@@ -202,6 +203,7 @@ book_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
        registry = e_source_selector_get_registry (selector);
 
        if (source != NULL) {
+               EClient *client;
                ESource *collection;
 
                has_primary_source = TRUE;
@@ -217,6 +219,15 @@ book_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
                        g_object_unref (collection);
                }
 
+               client = e_client_selector_ref_cached_client (
+                       E_CLIENT_SELECTOR (selector), source);
+
+               if (client != NULL) {
+                       refresh_supported =
+                               e_client_check_refresh_supported (client);
+                       g_object_unref (client);
+               }
+
                g_object_unref (source);
        }
 
@@ -232,6 +243,8 @@ book_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
                state |= E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOTE_DELETABLE;
        if (in_collection)
                state |= E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IN_COLLECTION;
+       if (refresh_supported)
+               state |= E_BOOK_SHELL_SIDEBAR_SOURCE_SUPPORTS_REFRESH;
 
        return state;
 }
diff --git a/modules/addressbook/e-book-shell-sidebar.h b/modules/addressbook/e-book-shell-sidebar.h
index 703d67c..d79fb27 100644
--- a/modules/addressbook/e-book-shell-sidebar.h
+++ b/modules/addressbook/e-book-shell-sidebar.h
@@ -56,7 +56,8 @@ enum {
        E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOVABLE        = 1 << 2,
        E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOTE_CREATABLE = 1 << 3,
        E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOTE_DELETABLE = 1 << 4,
-       E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IN_COLLECTION       = 1 << 5
+       E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IN_COLLECTION       = 1 << 5,
+       E_BOOK_SHELL_SIDEBAR_SOURCE_SUPPORTS_REFRESH            = 1 << 6
 };
 
 struct _EBookShellSidebar {
diff --git a/modules/addressbook/e-book-shell-view-actions.c b/modules/addressbook/e-book-shell-view-actions.c
index 78ea77d..9d72ef3 100644
--- a/modules/addressbook/e-book-shell-view-actions.c
+++ b/modules/addressbook/e-book-shell-view-actions.c
@@ -200,6 +200,62 @@ action_address_book_properties_cb (GtkAction *action,
        gtk_widget_show (dialog);
 }
 
+static void
+address_book_refresh_done_cb (GObject *source_object,
+                             GAsyncResult *result,
+                             gpointer user_data)
+{
+       EClient *client;
+       GError *error = NULL;
+
+       g_return_if_fail (E_IS_CLIENT (source_object));
+
+       client = E_CLIENT (source_object);
+
+       if (!e_client_refresh_finish (client, result, &error)) {
+               ESource *source = e_client_get_source (client);
+
+               if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
+                   !g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED))
+                       g_warning (
+                               "%s: Failed to refresh '%s', %s",
+                               G_STRFUNC, e_source_get_display_name (source),
+                               error ? error->message : "Unknown error");
+
+               g_clear_error (&error);
+       }
+}
+
+static void
+action_address_book_refresh_cb (GtkAction *action,
+                               EBookShellView *book_shell_view)
+{
+       EBookShellSidebar *book_shell_sidebar;
+       ESourceSelector *selector;
+       EClient *client = NULL;
+       ESource *source;
+
+       book_shell_sidebar = book_shell_view->priv->book_shell_sidebar;
+       selector = e_book_shell_sidebar_get_selector (book_shell_sidebar);
+
+       source = e_source_selector_ref_primary_selection (selector);
+
+       if (source != NULL) {
+               client = e_client_selector_ref_cached_client (
+                       E_CLIENT_SELECTOR (selector), source);
+               g_object_unref (source);
+       }
+
+       if (client == NULL)
+               return;
+
+       g_return_if_fail (e_client_check_refresh_supported (client));
+
+       e_client_refresh (client, NULL, address_book_refresh_done_cb, book_shell_view);
+
+       g_object_unref (client);
+}
+
 #ifdef WITH_CONTACT_MAPS
 static void
 contact_editor_contact_modified_cb (EABEditor *editor,
@@ -873,6 +929,13 @@ static GtkActionEntry contact_entries[] = {
          N_("Show properties of the selected address book"),
          G_CALLBACK (action_address_book_properties_cb) },
 
+       { "address-book-refresh",
+         GTK_STOCK_REFRESH,
+         N_("Re_fresh"),
+         NULL,
+         N_("Refresh the selected address book"),
+         G_CALLBACK (action_address_book_refresh_cb) },
+
        { "address-book-map",
          NULL,
          N_("Address Book _Map"),
@@ -984,6 +1047,10 @@ static EPopupActionEntry contact_popup_entries[] = {
          N_("_Properties"),
          "address-book-properties" },
 
+       { "address-book-popup-refresh",
+         NULL,
+         "address-book-refresh" },
+
        { "address-book-popup-map",
          N_("Address Book Map"),
          "address-book-map" },
diff --git a/modules/addressbook/e-book-shell-view-actions.h b/modules/addressbook/e-book-shell-view-actions.h
index 87eeaa8..32bf261 100644
--- a/modules/addressbook/e-book-shell-view-actions.h
+++ b/modules/addressbook/e-book-shell-view-actions.h
@@ -37,6 +37,8 @@
        E_SHELL_WINDOW_ACTION ((window), "address-book-print-preview")
 #define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_PROPERTIES(window) \
        E_SHELL_WINDOW_ACTION ((window), "address-book-properties")
+#define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_REFRESH(window) \
+       E_SHELL_WINDOW_ACTION ((window), "address-book-refresh")
 #define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_RENAME(window) \
        E_SHELL_WINDOW_ACTION ((window), "address-book-rename")
 #define E_SHELL_WINDOW_ACTION_ADDRESS_BOOK_SAVE_AS(window) \
diff --git a/modules/addressbook/e-book-shell-view.c b/modules/addressbook/e-book-shell-view.c
index f2c06bb..1f76cad 100644
--- a/modules/addressbook/e-book-shell-view.c
+++ b/modules/addressbook/e-book-shell-view.c
@@ -205,6 +205,7 @@ book_shell_view_update_actions (EShellView *shell_view)
        gboolean primary_source_is_removable;
        gboolean primary_source_is_remote_deletable;
        gboolean primary_source_in_collection;
+       gboolean refresh_supported;
        gboolean single_contact_selected;
        gboolean selection_is_contact_list;
        gboolean selection_has_email;
@@ -245,6 +246,8 @@ book_shell_view_update_actions (EShellView *shell_view)
                (state & E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IS_REMOTE_DELETABLE);
        primary_source_in_collection =
                (state & E_BOOK_SHELL_SIDEBAR_PRIMARY_SOURCE_IN_COLLECTION);
+       refresh_supported =
+               (state & E_BOOK_SHELL_SIDEBAR_SOURCE_SUPPORTS_REFRESH);
 
        any_contacts_selected =
                (single_contact_selected || multiple_contacts_selected);
@@ -271,6 +274,10 @@ book_shell_view_update_actions (EShellView *shell_view)
        sensitive = primary_source_is_writable;
        gtk_action_set_sensitive (action, sensitive);
 
+       action = ACTION (ADDRESS_BOOK_REFRESH);
+       sensitive = refresh_supported;
+       gtk_action_set_sensitive (action, sensitive);
+
        action = ACTION (ADDRESS_BOOK_RENAME);
        sensitive =
                primary_source_is_writable &&
diff --git a/ui/evolution-contacts.ui b/ui/evolution-contacts.ui
index 45f1a4d..36d640f 100644
--- a/ui/evolution-contacts.ui
+++ b/ui/evolution-contacts.ui
@@ -59,6 +59,7 @@
   <popup name='address-book-popup'>
     <menuitem action='address-book-new'/>
     <menuitem action='address-book-popup-rename'/>
+    <menuitem action='address-book-popup-refresh'/>
     <menuitem action='address-book-popup-save-as'/>
     <separator/>
     <menuitem action='address-book-popup-delete'/>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]