diff options
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-model.c | 78 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-model.h | 7 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-selector.c | 4 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-table-adapter.c | 20 | ||||
-rw-r--r-- | addressbook/gui/widgets/e-addressbook-view.c | 36 |
5 files changed, 89 insertions, 56 deletions
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c index 948c74d432..cddbabf924 100644 --- a/addressbook/gui/widgets/e-addressbook-model.c +++ b/addressbook/gui/widgets/e-addressbook-model.c @@ -36,7 +36,7 @@ ((obj), E_TYPE_ADDRESSBOOK_MODEL, EAddressbookModelPrivate)) struct _EAddressbookModelPrivate { - ESourceRegistry *registry; + EClientCache *client_cache; EBookClient *book_client; gchar *query_str; EBookClientView *client_view; @@ -62,9 +62,9 @@ struct _EAddressbookModelPrivate { enum { PROP_0, PROP_CLIENT, + PROP_CLIENT_CACHE, PROP_EDITABLE, - PROP_QUERY, - PROP_REGISTRY + PROP_QUERY }; enum { @@ -454,13 +454,13 @@ remove_status_cb (gpointer data) } static void -addressbook_model_set_registry (EAddressbookModel *model, - ESourceRegistry *registry) +addressbook_model_set_client_cache (EAddressbookModel *model, + EClientCache *client_cache) { - g_return_if_fail (E_IS_SOURCE_REGISTRY (registry)); - g_return_if_fail (model->priv->registry == NULL); + g_return_if_fail (E_IS_CLIENT_CACHE (client_cache)); + g_return_if_fail (model->priv->client_cache == NULL); - model->priv->registry = g_object_ref (registry); + model->priv->client_cache = g_object_ref (client_cache); } static void @@ -476,6 +476,12 @@ addressbook_model_set_property (GObject *object, g_value_get_object (value)); return; + case PROP_CLIENT_CACHE: + addressbook_model_set_client_cache ( + E_ADDRESSBOOK_MODEL (object), + g_value_get_object (value)); + return; + case PROP_EDITABLE: e_addressbook_model_set_editable ( E_ADDRESSBOOK_MODEL (object), @@ -487,12 +493,6 @@ addressbook_model_set_property (GObject *object, E_ADDRESSBOOK_MODEL (object), g_value_get_string (value)); return; - - case PROP_REGISTRY: - addressbook_model_set_registry ( - E_ADDRESSBOOK_MODEL (object), - g_value_get_object (value)); - return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -512,6 +512,12 @@ addressbook_model_get_property (GObject *object, E_ADDRESSBOOK_MODEL (object))); return; + case PROP_CLIENT_CACHE: + g_value_set_object ( + value, e_addressbook_model_get_client_cache ( + E_ADDRESSBOOK_MODEL (object))); + return; + case PROP_EDITABLE: g_value_set_boolean ( value, e_addressbook_model_get_editable ( @@ -523,12 +529,6 @@ addressbook_model_get_property (GObject *object, value, e_addressbook_model_get_query ( E_ADDRESSBOOK_MODEL (object))); return; - - case PROP_REGISTRY: - g_value_set_object ( - value, e_addressbook_model_get_registry ( - E_ADDRESSBOOK_MODEL (object))); - return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -542,6 +542,8 @@ addressbook_model_dispose (GObject *object) remove_book_view (model); free_data (model); + g_clear_object (&model->priv->client_cache); + if (model->priv->book_client) { if (model->priv->writable_status_id) g_signal_handler_disconnect ( @@ -601,6 +603,18 @@ e_addressbook_model_class_init (EAddressbookModelClass *class) g_object_class_install_property ( object_class, + PROP_CLIENT_CACHE, + g_param_spec_object ( + "client-cache", + "Client Cache", + "Shared EClient instances", + E_TYPE_CLIENT_CACHE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property ( + object_class, PROP_EDITABLE, g_param_spec_boolean ( "editable", @@ -622,18 +636,6 @@ e_addressbook_model_class_init (EAddressbookModelClass *class) G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS)); - g_object_class_install_property ( - object_class, - PROP_REGISTRY, - g_param_spec_object ( - "registry", - "Registry", - "Data source registry", - E_TYPE_SOURCE_REGISTRY, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - signals[WRITABLE_STATUS] = g_signal_new ( "writable_status", G_OBJECT_CLASS_TYPE (object_class), @@ -743,21 +745,21 @@ e_addressbook_model_init (EAddressbookModel *model) } EAddressbookModel * -e_addressbook_model_new (ESourceRegistry *registry) +e_addressbook_model_new (EClientCache *client_cache) { - g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL); + g_return_val_if_fail (E_IS_CLIENT_CACHE (client_cache), NULL); return g_object_new ( E_TYPE_ADDRESSBOOK_MODEL, - "registry", registry, NULL); + "client-cache", client_cache, NULL); } -ESourceRegistry * -e_addressbook_model_get_registry (EAddressbookModel *model) +EClientCache * +e_addressbook_model_get_client_cache (EAddressbookModel *model) { g_return_val_if_fail (E_IS_ADDRESSBOOK_MODEL (model), NULL); - return model->priv->registry; + return model->priv->client_cache; } EContact * diff --git a/addressbook/gui/widgets/e-addressbook-model.h b/addressbook/gui/widgets/e-addressbook-model.h index 0fb7be340f..c08fdb4319 100644 --- a/addressbook/gui/widgets/e-addressbook-model.h +++ b/addressbook/gui/widgets/e-addressbook-model.h @@ -23,6 +23,8 @@ #include <libebook/libebook.h> +#include <e-util/e-util.h> + /* Standard GObject macros */ #define E_TYPE_ADDRESSBOOK_MODEL \ (e_addressbook_model_get_type ()) @@ -80,9 +82,8 @@ struct _EAddressbookModelClass { GType e_addressbook_model_get_type (void); EAddressbookModel * - e_addressbook_model_new (ESourceRegistry *registry); -ESourceRegistry * - e_addressbook_model_get_registry + e_addressbook_model_new (EClientCache *client_cache); +EClientCache * e_addressbook_model_get_client_cache (EAddressbookModel *model); /* Returns object with ref count of 1. */ diff --git a/addressbook/gui/widgets/e-addressbook-selector.c b/addressbook/gui/widgets/e-addressbook-selector.c index 0ae747f404..7ef9ccd047 100644 --- a/addressbook/gui/widgets/e-addressbook-selector.c +++ b/addressbook/gui/widgets/e-addressbook-selector.c @@ -311,8 +311,7 @@ addressbook_selector_data_dropped (ESourceSelector *selector, string = (const gchar *) gtk_selection_data_get_data (selection_data); remove_from_source = (action == GDK_ACTION_MOVE); - model = e_addressbook_view_get_model (priv->current_view); - registry = e_addressbook_model_get_registry (model); + registry = e_source_selector_get_registry (selector); eab_source_and_contact_list_from_string ( registry, string, NULL, &list); @@ -320,6 +319,7 @@ addressbook_selector_data_dropped (ESourceSelector *selector, if (list == NULL) return FALSE; + model = e_addressbook_view_get_model (priv->current_view); source_client = e_addressbook_model_get_client (model); g_return_val_if_fail (E_IS_BOOK_CLIENT (source_client), FALSE); diff --git a/addressbook/gui/widgets/e-addressbook-table-adapter.c b/addressbook/gui/widgets/e-addressbook-table-adapter.c index 12be6c821d..5bd188ccec 100644 --- a/addressbook/gui/widgets/e-addressbook-table-adapter.c +++ b/addressbook/gui/widgets/e-addressbook-table-adapter.c @@ -171,13 +171,11 @@ addressbook_set_value_at (ETableModel *etc, EAddressbookTableAdapterPrivate *priv = adapter->priv; if (e_addressbook_model_get_editable (priv->model)) { + EClientCache *client_cache; ESourceRegistry *registry; EBookClient *book_client; EContact *contact; - registry = e_addressbook_model_get_registry (priv->model); - book_client = e_addressbook_model_get_client (priv->model); - if (col >= COLS || row >= e_addressbook_model_contact_count (priv->model)) return; @@ -197,11 +195,19 @@ addressbook_set_value_at (ETableModel *etc, g_hash_table_remove (priv->emails, old_value); } + client_cache = + e_addressbook_model_get_client_cache (priv->model); + book_client = e_addressbook_model_get_client (priv->model); + + registry = e_client_cache_ref_registry (client_cache); + e_contact_set (contact, col, (gpointer) val); eab_merging_book_modify_contact ( registry, book_client, contact, contact_modified_cb, etc); + g_object_unref (registry); + g_object_unref (contact); /* XXX Do we need this? Shouldn't the commit_contact @@ -226,6 +232,7 @@ addressbook_append_row (ETableModel *etm, { EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER (etm); EAddressbookTableAdapterPrivate *priv = adapter->priv; + EClientCache *client_cache; ESourceRegistry *registry; EBookClient *book_client; EContact *contact; @@ -238,12 +245,17 @@ addressbook_append_row (ETableModel *etm, e_contact_set (contact, col, (gpointer) val); } - registry = e_addressbook_model_get_registry (priv->model); + client_cache = + e_addressbook_model_get_client_cache (priv->model); book_client = e_addressbook_model_get_client (priv->model); + registry = e_client_cache_ref_registry (client_cache); + eab_merging_book_add_contact ( registry, book_client, contact, NULL, NULL); + g_object_unref (registry); + g_object_unref (contact); } diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c index 3fb30fe0f9..5edbf0fe60 100644 --- a/addressbook/gui/widgets/e-addressbook-view.c +++ b/addressbook/gui/widgets/e-addressbook-view.c @@ -566,19 +566,19 @@ addressbook_view_constructed (GObject *object) EShell *shell; EShellView *shell_view; EShellBackend *shell_backend; - ESourceRegistry *registry; + EClientCache *client_cache; ESource *source; const gchar *uid; shell_view = e_addressbook_view_get_shell_view (view); shell_backend = e_shell_view_get_shell_backend (shell_view); shell = e_shell_backend_get_shell (shell_backend); - registry = e_shell_get_registry (shell); + client_cache = e_shell_get_client_cache (shell); source = e_addressbook_view_get_source (view); uid = e_source_get_uid (source); - view->priv->model = e_addressbook_model_new (registry); + view->priv->model = e_addressbook_model_new (client_cache); view_instance = e_shell_view_new_view_instance (shell_view, uid); g_signal_connect_swapped ( @@ -697,6 +697,7 @@ addressbook_view_paste_clipboard (ESelectable *selectable) EBookClient *book_client; EAddressbookView *view; EAddressbookModel *model; + EClientCache *client_cache; ESourceRegistry *registry; GtkClipboard *clipboard; GSList *contact_list, *iter; @@ -709,13 +710,15 @@ addressbook_view_paste_clipboard (ESelectable *selectable) return; model = e_addressbook_view_get_model (view); - registry = e_addressbook_model_get_registry (model); + client_cache = e_addressbook_model_get_client_cache (model); book_client = e_addressbook_model_get_client (model); string = e_clipboard_wait_for_directory (clipboard); contact_list = eab_contact_list_from_string (string); g_free (string); + registry = e_client_cache_ref_registry (client_cache); + for (iter = contact_list; iter != NULL; iter = iter->next) { EContact *contact = iter->data; @@ -723,6 +726,8 @@ addressbook_view_paste_clipboard (ESelectable *selectable) registry, book_client, contact, NULL, NULL); } + g_object_unref (registry); + g_slist_free_full (contact_list, (GDestroyNotify) g_object_unref); } @@ -1508,7 +1513,7 @@ all_contacts_ready_cb (GObject *source_object, EBookClient *book_client = E_BOOK_CLIENT (source_object); struct TransferContactsData *tcd = user_data; EAddressbookModel *model; - ESourceRegistry *registry; + EClientCache *client_cache; EShellView *shell_view; EShellContent *shell_content; EAlertSink *alert_sink; @@ -1526,7 +1531,7 @@ all_contacts_ready_cb (GObject *source_object, alert_sink = E_ALERT_SINK (shell_content); model = e_addressbook_view_get_model (tcd->view); - registry = e_addressbook_model_get_registry (model); + client_cache = e_addressbook_model_get_client_cache (model); if (error) { e_alert_submit ( @@ -1534,9 +1539,15 @@ all_contacts_ready_cb (GObject *source_object, error->message, NULL); g_error_free (error); } else if (contacts) { + ESourceRegistry *registry; + + registry = e_client_cache_ref_registry (client_cache); + eab_transfer_contacts ( registry, book_client, contacts, tcd->delete_from_source, alert_sink); + + g_object_unref (registry); } g_object_unref (tcd->view); @@ -1548,11 +1559,13 @@ view_transfer_contacts (EAddressbookView *view, gboolean delete_from_source, gboolean all) { + EAddressbookModel *model; EBookClient *book_client; - ESourceRegistry *registry; + EClientCache *client_cache; - registry = e_addressbook_model_get_registry (view->priv->model); - book_client = e_addressbook_model_get_client (view->priv->model); + model = e_addressbook_view_get_model (view); + book_client = e_addressbook_model_get_client (model); + client_cache = e_addressbook_model_get_client_cache (model); if (all) { EBookQuery *query; @@ -1575,6 +1588,7 @@ view_transfer_contacts (EAddressbookView *view, EShellView *shell_view; EShellContent *shell_content; EAlertSink *alert_sink; + ESourceRegistry *registry; shell_view = e_addressbook_view_get_shell_view (view); shell_content = e_shell_view_get_shell_content (shell_view); @@ -1582,9 +1596,13 @@ view_transfer_contacts (EAddressbookView *view, contacts = e_addressbook_view_get_selected (view); + registry = e_client_cache_ref_registry (client_cache); + eab_transfer_contacts ( registry, book_client, contacts, delete_from_source, alert_sink); + + g_object_unref (registry); } } |