[evolution/account-mgmt: 15/54] Adapt addressbook/gui/widgets to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/account-mgmt: 15/54] Adapt addressbook/gui/widgets to the new ESource API.
- Date: Tue, 24 Apr 2012 23:46:09 +0000 (UTC)
commit 3331cba8a77cf8b7cdfbea156036890a225271c1
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Dec 8 00:16:09 2010 -0500
Adapt addressbook/gui/widgets to the new ESource API.
addressbook/gui/widgets/e-addressbook-model.c | 54 ++++++++++++-
addressbook/gui/widgets/e-addressbook-model.h | 6 +-
addressbook/gui/widgets/e-addressbook-selector.c | 84 +++++++++-----------
addressbook/gui/widgets/e-addressbook-selector.h | 3 +-
.../gui/widgets/e-addressbook-table-adapter.c | 10 ++-
addressbook/gui/widgets/e-addressbook-view.c | 39 +++++++---
addressbook/gui/widgets/e-book-source-config.c | 12 ++-
addressbook/gui/widgets/eab-gui-util.c | 66 ++++++++--------
addressbook/gui/widgets/eab-gui-util.h | 7 +-
9 files changed, 179 insertions(+), 102 deletions(-)
---
diff --git a/addressbook/gui/widgets/e-addressbook-model.c b/addressbook/gui/widgets/e-addressbook-model.c
index 1888248..3cc02df 100644
--- a/addressbook/gui/widgets/e-addressbook-model.c
+++ b/addressbook/gui/widgets/e-addressbook-model.c
@@ -36,6 +36,7 @@
((obj), E_TYPE_ADDRESSBOOK_MODEL, EAddressbookModelPrivate))
struct _EAddressbookModelPrivate {
+ ESourceRegistry *registry;
EBookClient *book_client;
gchar *query_str;
EBookClientView *client_view;
@@ -63,7 +64,8 @@ enum {
PROP_0,
PROP_CLIENT,
PROP_EDITABLE,
- PROP_QUERY
+ PROP_QUERY,
+ PROP_REGISTRY
};
enum {
@@ -462,6 +464,16 @@ remove_status_cb (gpointer data)
}
static void
+addressbook_model_set_registry (EAddressbookModel *model,
+ ESourceRegistry *registry)
+{
+ g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+ g_return_if_fail (model->priv->registry == NULL);
+
+ model->priv->registry = g_object_ref (registry);
+}
+
+static void
addressbook_model_set_property (GObject *object,
guint property_id,
const GValue *value,
@@ -485,6 +497,12 @@ 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);
@@ -515,6 +533,12 @@ 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);
@@ -615,6 +639,18 @@ 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),
@@ -726,9 +762,21 @@ e_addressbook_model_init (EAddressbookModel *model)
}
EAddressbookModel *
-e_addressbook_model_new (void)
+e_addressbook_model_new (ESourceRegistry *registry)
{
- return g_object_new (E_TYPE_ADDRESSBOOK_MODEL, NULL);
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
+
+ return g_object_new (
+ E_TYPE_ADDRESSBOOK_MODEL,
+ "registry", registry, NULL);
+}
+
+ESourceRegistry *
+e_addressbook_model_get_registry (EAddressbookModel *model)
+{
+ g_return_val_if_fail (E_IS_ADDRESSBOOK_MODEL (model), NULL);
+
+ return model->priv->registry;
}
EContact *
diff --git a/addressbook/gui/widgets/e-addressbook-model.h b/addressbook/gui/widgets/e-addressbook-model.h
index 680352c..24c4302 100644
--- a/addressbook/gui/widgets/e-addressbook-model.h
+++ b/addressbook/gui/widgets/e-addressbook-model.h
@@ -24,6 +24,7 @@
#include <libebook/e-book-client.h>
#include <libebook/e-book-client-view.h>
#include <libebook/e-book-query.h>
+#include <libedataserver/e-source-registry.h>
/* Standard GObject macros */
#define E_TYPE_ADDRESSBOOK_MODEL \
@@ -83,7 +84,10 @@ struct _EAddressbookModelClass {
GType e_addressbook_model_get_type (void);
EAddressbookModel *
- e_addressbook_model_new (void);
+ e_addressbook_model_new (ESourceRegistry *registry);
+ESourceRegistry *
+ e_addressbook_model_get_registry
+ (EAddressbookModel *model);
/* Returns object with ref count of 1. */
EContact * e_addressbook_model_get_contact (EAddressbookModel *model,
diff --git a/addressbook/gui/widgets/e-addressbook-selector.c b/addressbook/gui/widgets/e-addressbook-selector.c
index 6fc1df3..1fbed5a 100644
--- a/addressbook/gui/widgets/e-addressbook-selector.c
+++ b/addressbook/gui/widgets/e-addressbook-selector.c
@@ -24,8 +24,10 @@
#include "e-addressbook-selector.h"
-#include <e-util/e-selection.h>
#include <libedataserverui/e-client-utils.h>
+#include <libedataserver/e-source-address-book.h>
+
+#include <e-util/e-selection.h>
#include <eab-book-util.h>
#include <eab-contact-merging.h>
@@ -41,6 +43,7 @@ struct _EAddressbookSelectorPrivate {
};
struct _MergeContext {
+ ESourceRegistry *registry;
EBookClient *source_client;
EBookClient *target_client;
@@ -62,8 +65,6 @@ static GtkTargetEntry drag_types[] = {
{ (gchar *) "text/x-source-vcard", 0, 0 }
};
-static gpointer parent_class;
-
G_DEFINE_TYPE (
EAddressbookSelector,
e_addressbook_selector,
@@ -85,13 +86,15 @@ merge_context_next (MergeContext *merge_context)
}
static MergeContext *
-merge_context_new (EBookClient *source_client,
+merge_context_new (ESourceRegistry *registry,
+ EBookClient *source_client,
EBookClient *target_client,
GSList *contact_list)
{
MergeContext *merge_context;
merge_context = g_slice_new0 (MergeContext);
+ merge_context->registry = g_object_ref (registry);
merge_context->source_client = source_client;
merge_context->target_client = target_client;
merge_context->remaining_contacts = contact_list;
@@ -103,6 +106,9 @@ merge_context_new (EBookClient *source_client,
static void
merge_context_free (MergeContext *merge_context)
{
+ if (merge_context->registry != NULL)
+ g_object_unref (merge_context->registry);
+
if (merge_context->source_client != NULL)
g_object_unref (merge_context->source_client);
@@ -163,6 +169,7 @@ addressbook_selector_merge_next_cb (EBookClient *book_client,
if (merge_context->remaining_contacts != NULL) {
merge_context_next (merge_context);
eab_merging_book_add_contact (
+ merge_context->registry,
merge_context->target_client,
merge_context->current_contact,
addressbook_selector_merge_next_cb, merge_context);
@@ -174,35 +181,6 @@ addressbook_selector_merge_next_cb (EBookClient *book_client,
}
static void
-addressbook_selector_load_primary_source (ESourceSelector *selector)
-{
- ESourceList *source_list;
- ESource *source = NULL;
- GSList *groups;
-
- source_list = e_source_selector_get_source_list (selector);
-
- /* Dig up the first source in the source list.
- * XXX libedataserver should provide API for this. */
- groups = e_source_list_peek_groups (source_list);
- while (groups != NULL) {
- ESourceGroup *source_group = groups->data;
- GSList *sources;
-
- sources = e_source_group_peek_sources (source_group);
- if (sources != NULL) {
- source = sources->data;
- break;
- }
-
- groups = g_slist_next (groups);
- }
-
- if (source != NULL)
- e_source_selector_set_primary_selection (selector, source);
-}
-
-static void
addressbook_selector_set_property (GObject *object,
guint property_id,
const GValue *value,
@@ -250,19 +228,25 @@ addressbook_selector_dispose (GObject *object)
}
/* Chain up to parent's dispose() method. */
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ G_OBJECT_CLASS (e_addressbook_selector_parent_class)->dispose (object);
}
static void
addressbook_selector_constructed (GObject *object)
{
ESourceSelector *selector;
+ ESourceRegistry *registry;
+ ESource *source;
selector = E_SOURCE_SELECTOR (object);
- addressbook_selector_load_primary_source (selector);
+ registry = e_source_selector_get_registry (selector);
+ source = e_source_registry_ref_default_address_book (registry);
+ e_source_selector_set_primary_selection (selector, source);
+ g_object_unref (source);
/* Chain up to parent's constructed() method. */
- G_OBJECT_CLASS (parent_class)->constructed (object);
+ G_OBJECT_CLASS (e_addressbook_selector_parent_class)->
+ constructed (object);
}
static void
@@ -302,7 +286,7 @@ target_client_open_ready_cb (GObject *source_object,
}
eab_merging_book_add_contact (
- merge_context->target_client,
+ merge_context->registry, merge_context->target_client,
merge_context->current_contact,
addressbook_selector_merge_next_cb, merge_context);
}
@@ -318,6 +302,7 @@ addressbook_selector_data_dropped (ESourceSelector *selector,
MergeContext *merge_context;
EAddressbookModel *model;
EBookClient *source_client = NULL;
+ ESourceRegistry *registry;
GSList *list;
const gchar *string;
gboolean remove_from_source;
@@ -328,26 +313,29 @@ 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);
+
/* XXX Function assumes both out arguments are provided. All we
* care about is the contact list; source_client will be NULL. */
- eab_book_and_contact_list_from_string (string, &source_client, &list);
+ eab_book_and_contact_list_from_string (
+ registry, string, &source_client, &list);
if (source_client)
g_object_unref (source_client);
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);
- merge_context = merge_context_new (g_object_ref (source_client), NULL, list);
+ merge_context = merge_context_new (
+ registry, g_object_ref (source_client), NULL, list);
merge_context->remove_from_source = remove_from_source;
merge_context->pending_adds = TRUE;
e_client_utils_open_new (
destination, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
- e_client_utils_authenticate_handler, NULL,
target_client_open_ready_cb, merge_context);
return TRUE;
@@ -359,7 +347,6 @@ e_addressbook_selector_class_init (EAddressbookSelectorClass *class)
GObjectClass *object_class;
ESourceSelectorClass *selector_class;
- parent_class = g_type_class_peek_parent (class);
g_type_class_add_private (class, sizeof (EAddressbookSelectorPrivate));
object_class = G_OBJECT_CLASS (class);
@@ -387,6 +374,12 @@ e_addressbook_selector_init (EAddressbookSelector *selector)
{
selector->priv = E_ADDRESSBOOK_SELECTOR_GET_PRIVATE (selector);
+ e_source_selector_set_show_colors (
+ E_SOURCE_SELECTOR (selector), FALSE);
+
+ e_source_selector_set_show_toggles (
+ E_SOURCE_SELECTOR (selector), FALSE);
+
gtk_drag_dest_set (
GTK_WIDGET (selector), GTK_DEST_DEFAULT_ALL,
drag_types, G_N_ELEMENTS (drag_types),
@@ -396,13 +389,14 @@ e_addressbook_selector_init (EAddressbookSelector *selector)
}
GtkWidget *
-e_addressbook_selector_new (ESourceList *source_list)
+e_addressbook_selector_new (ESourceRegistry *registry)
{
- g_return_val_if_fail (E_IS_SOURCE_LIST (source_list), NULL);
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
return g_object_new (
E_TYPE_ADDRESSBOOK_SELECTOR,
- "source-list", source_list, NULL);
+ "extension-name", E_SOURCE_EXTENSION_ADDRESS_BOOK,
+ "registry", registry, NULL);
}
EAddressbookView *
diff --git a/addressbook/gui/widgets/e-addressbook-selector.h b/addressbook/gui/widgets/e-addressbook-selector.h
index c0102cb..d4d6ad8 100644
--- a/addressbook/gui/widgets/e-addressbook-selector.h
+++ b/addressbook/gui/widgets/e-addressbook-selector.h
@@ -21,7 +21,6 @@
#ifndef E_ADDRESSBOOK_SELECTOR_H
#define E_ADDRESSBOOK_SELECTOR_H
-#include <libedataserver/e-source-list.h>
#include <libedataserverui/e-source-selector.h>
#include "e-addressbook-view.h"
@@ -60,7 +59,7 @@ struct _EAddressbookSelectorClass {
};
GType e_addressbook_selector_get_type (void);
-GtkWidget * e_addressbook_selector_new (ESourceList *source_list);
+GtkWidget * e_addressbook_selector_new (ESourceRegistry *registry);
EAddressbookView *
e_addressbook_selector_get_current_view
(EAddressbookSelector *selector);
diff --git a/addressbook/gui/widgets/e-addressbook-table-adapter.c b/addressbook/gui/widgets/e-addressbook-table-adapter.c
index 5a2a9b4..165f1d7 100644
--- a/addressbook/gui/widgets/e-addressbook-table-adapter.c
+++ b/addressbook/gui/widgets/e-addressbook-table-adapter.c
@@ -170,9 +170,11 @@ addressbook_set_value_at (ETableModel *etc,
EAddressbookTableAdapterPrivate *priv = adapter->priv;
if (e_addressbook_model_get_editable (priv->model)) {
+ 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))
@@ -196,7 +198,7 @@ addressbook_set_value_at (ETableModel *etc,
e_contact_set (contact, col, (gpointer) val);
eab_merging_book_modify_contact (
- book_client,
+ registry, book_client,
contact, contact_modified_cb, etc);
g_object_unref (contact);
@@ -223,6 +225,7 @@ addressbook_append_row (ETableModel *etm,
{
EAddressbookTableAdapter *adapter = E_ADDRESSBOOK_TABLE_ADAPTER (etm);
EAddressbookTableAdapterPrivate *priv = adapter->priv;
+ ESourceRegistry *registry;
EBookClient *book_client;
EContact *contact;
gint col;
@@ -234,8 +237,11 @@ addressbook_append_row (ETableModel *etm,
e_contact_set (contact, col, (gpointer) val);
}
+ registry = e_addressbook_model_get_registry (priv->model);
book_client = e_addressbook_model_get_client (priv->model);
- eab_merging_book_add_contact (book_client, contact, NULL, NULL);
+
+ eab_merging_book_add_contact (
+ registry, book_client, contact, NULL, NULL);
g_object_unref (contact);
}
diff --git a/addressbook/gui/widgets/e-addressbook-view.c b/addressbook/gui/widgets/e-addressbook-view.c
index 5dce1e2..8dc7208 100644
--- a/addressbook/gui/widgets/e-addressbook-view.c
+++ b/addressbook/gui/widgets/e-addressbook-view.c
@@ -576,15 +576,24 @@ addressbook_view_constructed (GObject *object)
{
EAddressbookView *view = E_ADDRESSBOOK_VIEW (object);
GalViewInstance *view_instance;
+ EShell *shell;
EShellView *shell_view;
+ EShellBackend *shell_backend;
+ ESourceRegistry *registry;
ESource *source;
- gchar *uri;
+ 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);
+
source = e_addressbook_view_get_source (view);
- uri = e_source_get_uri (source);
+ uid = e_source_get_uid (source);
- view_instance = e_shell_view_new_view_instance (shell_view, uri);
+ view->priv->model = e_addressbook_model_new (registry);
+
+ view_instance = e_shell_view_new_view_instance (shell_view, uid);
g_signal_connect_swapped (
view_instance, "display-view",
G_CALLBACK (addressbook_view_display_view_cb), view);
@@ -595,8 +604,6 @@ addressbook_view_constructed (GObject *object)
* e_book_shell_content_get_current_view() returns the correct
* view in GalViewInstance::loaded signal handlers. */
- g_free (uri);
-
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (parent_class)->constructed (object);
}
@@ -703,6 +710,7 @@ addressbook_view_paste_clipboard (ESelectable *selectable)
EBookClient *book_client;
EAddressbookView *view;
EAddressbookModel *model;
+ ESourceRegistry *registry;
GtkClipboard *clipboard;
GSList *contact_list, *iter;
gchar *string;
@@ -714,6 +722,7 @@ addressbook_view_paste_clipboard (ESelectable *selectable)
return;
model = e_addressbook_view_get_model (view);
+ registry = e_addressbook_model_get_registry (model);
book_client = e_addressbook_model_get_client (model);
string = e_clipboard_wait_for_directory (clipboard);
@@ -723,7 +732,8 @@ addressbook_view_paste_clipboard (ESelectable *selectable)
for (iter = contact_list; iter != NULL; iter = iter->next) {
EContact *contact = iter->data;
- eab_merging_book_add_contact (book_client, contact, NULL, NULL);
+ eab_merging_book_add_contact (
+ registry, book_client, contact, NULL, NULL);
}
e_client_util_free_object_slist (contact_list);
@@ -860,8 +870,6 @@ e_addressbook_view_init (EAddressbookView *view)
view->priv = E_ADDRESSBOOK_VIEW_GET_PRIVATE (view);
- view->priv->model = e_addressbook_model_new ();
-
target_list = gtk_target_list_new (NULL, 0);
e_target_list_add_directory_targets (target_list, 0);
view->priv->copy_target_list = target_list;
@@ -1124,16 +1132,18 @@ backend_died (EAddressbookView *view)
EAlertSink *alert_sink;
EAddressbookModel *model;
EBookClient *book_client;
+ ESource *source;
shell_view = e_addressbook_view_get_shell_view (view);
alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
model = e_addressbook_view_get_model (view);
book_client = e_addressbook_model_get_client (model);
+ source = e_client_get_source (E_CLIENT (book_client));
e_alert_submit (alert_sink,
"addressbook:backend-died",
- e_client_get_uri (E_CLIENT (book_client)), NULL);
+ e_source_get_display_name (source), NULL);
}
static void
@@ -1533,6 +1543,8 @@ all_contacts_ready_cb (GObject *source_object,
{
EBookClient *book_client = E_BOOK_CLIENT (source_object);
struct TransferContactsData *tcd = user_data;
+ EAddressbookModel *model;
+ ESourceRegistry *registry;
EShellView *shell_view;
EShellContent *shell_content;
EAlertSink *alert_sink;
@@ -1549,6 +1561,9 @@ all_contacts_ready_cb (GObject *source_object,
shell_content = e_shell_view_get_shell_content (shell_view);
alert_sink = E_ALERT_SINK (shell_content);
+ model = e_addressbook_view_get_model (tcd->view);
+ registry = e_addressbook_model_get_registry (model);
+
if (error) {
e_alert_submit (
alert_sink, "addressbook:search-error",
@@ -1556,7 +1571,7 @@ all_contacts_ready_cb (GObject *source_object,
g_error_free (error);
} else if (contacts) {
eab_transfer_contacts (
- book_client, contacts,
+ registry, book_client, contacts,
tcd->delete_from_source, alert_sink);
}
@@ -1570,7 +1585,9 @@ view_transfer_contacts (EAddressbookView *view,
gboolean all)
{
EBookClient *book_client;
+ ESourceRegistry *registry;
+ registry = e_addressbook_model_get_registry (view->priv->model);
book_client = e_addressbook_model_get_client (view->priv->model);
if (all) {
@@ -1602,7 +1619,7 @@ view_transfer_contacts (EAddressbookView *view,
contacts = e_addressbook_view_get_selected (view);
eab_transfer_contacts (
- book_client, contacts,
+ registry, book_client, contacts,
delete_from_source, alert_sink);
}
}
diff --git a/addressbook/gui/widgets/e-book-source-config.c b/addressbook/gui/widgets/e-book-source-config.c
index 8b9ed62..7c75103 100644
--- a/addressbook/gui/widgets/e-book-source-config.c
+++ b/addressbook/gui/widgets/e-book-source-config.c
@@ -40,13 +40,13 @@ G_DEFINE_TYPE (
E_TYPE_SOURCE_CONFIG)
static ESource *
-book_source_config_get_default (ESourceConfig *config)
+book_source_config_ref_default (ESourceConfig *config)
{
ESourceRegistry *registry;
registry = e_source_config_get_registry (config);
- return e_source_registry_get_default_address_book (registry);
+ return e_source_registry_ref_default_address_book (registry);
}
static void
@@ -109,7 +109,7 @@ book_source_config_constructed (GObject *object)
priv->autocomplete_button = g_object_ref_sink (widget);
gtk_widget_show (widget);
- default_source = book_source_config_get_default (config);
+ default_source = book_source_config_ref_default (config);
original_source = e_source_config_get_original_source (config);
if (original_source != NULL) {
@@ -119,6 +119,8 @@ book_source_config_constructed (GObject *object)
g_object_set (priv->default_button, "active", active, NULL);
}
+ g_object_unref (default_source);
+
e_source_config_insert_widget (
config, NULL, NULL, priv->default_button);
@@ -173,7 +175,7 @@ book_source_config_commit_changes (ESourceConfig *config,
class = E_SOURCE_CONFIG_CLASS (e_book_source_config_parent_class);
class->commit_changes (config, scratch_source);
- default_source = book_source_config_get_default (config);
+ default_source = book_source_config_ref_default (config);
/* The default setting is a little tricky to get right. If
* the toggle button is active, this ESource is now the default.
@@ -185,6 +187,8 @@ book_source_config_commit_changes (ESourceConfig *config,
book_source_config_set_default (config, scratch_source);
else if (e_source_equal (scratch_source, default_source))
book_source_config_set_default (config, NULL);
+
+ g_object_unref (default_source);
}
static void
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c
index 3d9d819..95b49a3 100644
--- a/addressbook/gui/widgets/eab-gui-util.c
+++ b/addressbook/gui/widgets/eab-gui-util.c
@@ -36,6 +36,7 @@
#include <glib/gi18n.h>
#include <libebook/e-destination.h>
#include <libedataserver/e-data-server-util.h>
+#include <libedataserver/e-source-address-book.h>
#include <libedataserverui/e-client-utils.h>
#include <libedataserverui/e-source-selector.h>
#include <e-util/e-util.h>
@@ -107,12 +108,17 @@ eab_load_error_dialog (GtkWidget *parent,
ESource *source,
const GError *error)
{
- gchar *label_string, *label = NULL, *uri;
+ ESourceBackend *extension;
+ gchar *label_string, *label = NULL;
gboolean can_detail_error = TRUE;
+ const gchar *backend_name;
+ const gchar *extension_name;
g_return_if_fail (source != NULL);
- uri = e_source_get_uri (source);
+ extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+ extension = e_source_get_extension (source, extension_name);
+ backend_name = e_source_backend_get_backend_name (extension);
if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_OFFLINE_UNAVAILABLE)) {
can_detail_error = FALSE;
@@ -124,25 +130,16 @@ eab_load_error_dialog (GtkWidget *parent,
"download its contents.");
}
- else if (uri && g_str_has_prefix (uri, "local:")) {
+ else if (g_strcmp0 (backend_name, "local") == 0) {
const gchar *user_data_dir;
- const gchar *source_dir;
- gchar *mangled_source_dir;
+ const gchar *uid;
gchar *path;
+ uid = e_source_get_uid (source);
user_data_dir = e_get_user_data_dir ();
- source_dir = e_source_peek_relative_uri (source);
-
- if (!source_dir || !g_str_equal (source_dir, "system"))
- source_dir = e_source_get_uid (source);
-
- /* Mangle the URI to not contain invalid characters. */
- mangled_source_dir = g_strdelimit (g_strdup (source_dir), ":/", '_');
path = g_build_filename (
- user_data_dir, "addressbook", mangled_source_dir, NULL);
-
- g_free (mangled_source_dir);
+ user_data_dir, "addressbook", uid, NULL);
label = g_strdup_printf (
_("This address book cannot be opened. Please check that the "
@@ -153,7 +150,7 @@ eab_load_error_dialog (GtkWidget *parent,
}
#ifndef HAVE_LDAP
- else if (uri && !strncmp (uri, "ldap:", 5)) {
+ else if (g_strcmp0 (backend_name, "ldap") == 0) {
/* special case for ldap: contact folders so we can tell the user about openldap */
can_detail_error = FALSE;
@@ -198,7 +195,6 @@ eab_load_error_dialog (GtkWidget *parent,
}
g_free (label);
- g_free (uri);
}
void
@@ -298,24 +294,24 @@ source_selection_changed_cb (ESourceSelector *selector,
}
ESource *
-eab_select_source (ESource *except_source,
+eab_select_source (ESourceRegistry *registry,
+ ESource *except_source,
const gchar *title,
const gchar *message,
const gchar *select_uid,
GtkWindow *parent)
{
ESource *source;
- ESourceList *source_list;
GtkWidget *content_area;
GtkWidget *dialog;
GtkWidget *ok_button;
/* GtkWidget *label; */
GtkWidget *selector;
GtkWidget *scrolled_window;
+ const gchar *extension_name;
gint response;
- if (!e_book_client_get_sources (&source_list, NULL))
- return NULL;
+ g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
dialog = gtk_dialog_new_with_buttons (
_("Select Address Book"), parent,
@@ -330,27 +326,29 @@ eab_select_source (ESource *except_source,
/* label = gtk_label_new (message); */
- selector = e_source_selector_new (source_list);
- e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE);
+ extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+ selector = e_source_selector_new (registry, extension_name);
+ e_source_selector_set_show_toggles (
+ E_SOURCE_SELECTOR (selector), FALSE);
ok_button = gtk_dialog_get_widget_for_response (
GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
if (except_source)
g_object_set_data (
- G_OBJECT (ok_button), "except-source",
- e_source_list_peek_source_by_uid (
- source_list, e_source_get_uid (except_source)));
+ G_OBJECT (ok_button), "except-source", except_source);
g_signal_connect (
selector, "primary_selection_changed",
G_CALLBACK (source_selection_changed_cb), ok_button);
if (select_uid) {
- source = e_source_list_peek_source_by_uid (source_list, select_uid);
- if (source != NULL)
+ source = e_source_registry_ref_source (registry, select_uid);
+ if (source != NULL) {
e_source_selector_set_primary_selection (
E_SOURCE_SELECTOR (selector), source);
+ g_object_unref (source);
+ }
}
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
@@ -411,6 +409,7 @@ struct ContactCopyProcess_ {
GSList *contacts;
EBookClient *source;
EBookClient *destination;
+ ESourceRegistry *registry;
gboolean delete_from_source;
EAlertSink *alert_sink;
};
@@ -481,6 +480,7 @@ process_unref (ContactCopyProcess *process)
e_client_util_free_object_slist (process->contacts);
g_object_unref (process->source);
g_object_unref (process->destination);
+ g_object_unref (process->registry);
g_free (process);
}
}
@@ -525,7 +525,7 @@ do_copy (gpointer data,
process->count++;
eab_merging_book_add_contact (
- book_client,
+ process->registry, book_client,
contact, contact_added_cb, process);
}
@@ -561,7 +561,8 @@ exit:
}
void
-eab_transfer_contacts (EBookClient *source_client,
+eab_transfer_contacts (ESourceRegistry *registry,
+ EBookClient *source_client,
GSList *contacts /* adopted */,
gboolean delete_from_source,
EAlertSink *alert_sink)
@@ -573,6 +574,7 @@ eab_transfer_contacts (EBookClient *source_client,
gchar *desc;
GtkWindow *window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (alert_sink)));
+ g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
g_return_if_fail (E_IS_BOOK_CLIENT (source_client));
if (contacts == NULL)
@@ -596,7 +598,7 @@ eab_transfer_contacts (EBookClient *source_client,
source = e_client_get_source (E_CLIENT (source_client));
destination = eab_select_source (
- source, desc, NULL, last_uid, window);
+ registry, source, desc, NULL, last_uid, window);
if (!destination)
return;
@@ -612,12 +614,12 @@ eab_transfer_contacts (EBookClient *source_client,
process->source = g_object_ref (source_client);
process->contacts = contacts;
process->destination = NULL;
+ process->registry = g_object_ref (registry);
process->alert_sink = alert_sink;
process->delete_from_source = delete_from_source;
e_client_utils_open_new (
destination, E_CLIENT_SOURCE_TYPE_CONTACTS, FALSE, NULL,
- e_client_utils_authenticate_handler, window,
book_loaded_cb, process);
}
diff --git a/addressbook/gui/widgets/eab-gui-util.h b/addressbook/gui/widgets/eab-gui-util.h
index 7844094..3f6f319 100644
--- a/addressbook/gui/widgets/eab-gui-util.h
+++ b/addressbook/gui/widgets/eab-gui-util.h
@@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include <libebook/e-book-client.h>
+#include <libedataserver/e-source-registry.h>
#include "libevolution-utils/e-alert-sink.h"
G_BEGIN_DECLS
@@ -40,12 +41,14 @@ void eab_load_error_dialog (GtkWidget *parent,
void eab_search_result_dialog (EAlertSink *alert_sink,
const GError *error);
gint eab_prompt_save_dialog (GtkWindow *parent);
-void eab_transfer_contacts (EBookClient *source_client,
+void eab_transfer_contacts (ESourceRegistry *registry,
+ EBookClient *source_client,
GSList *contacts, /* adopted */
gboolean delete_from_source,
EAlertSink *alert_sink);
gchar * eab_suggest_filename (const GSList *contact_list);
-ESource * eab_select_source (ESource *except_source,
+ESource * eab_select_source (ESourceRegistry *registry,
+ ESource *except_source,
const gchar *title,
const gchar *message,
const gchar *select_uid,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]