aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-03-02 03:30:14 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-03-02 07:16:07 +0800
commit4ff90f2bfd95337040616cae4b3bdddff033b5d6 (patch)
tree37d3acd7835e4366cc367dc904e43915c7c11f9b /e-util
parent977be20ced747224c0e08d565f961f0fa8d0baf8 (diff)
downloadgsoc2013-evolution-4ff90f2bfd95337040616cae4b3bdddff033b5d6.tar.gz
gsoc2013-evolution-4ff90f2bfd95337040616cae4b3bdddff033b5d6.tar.zst
gsoc2013-evolution-4ff90f2bfd95337040616cae4b3bdddff033b5d6.zip
Use EClientComboBox where appropriate.
Basically any place where we use both EClient and ESourceComboBox.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-name-selector-dialog.c125
-rw-r--r--e-util/e-name-selector-dialog.h7
-rw-r--r--e-util/e-name-selector-entry.c120
-rw-r--r--e-util/e-name-selector-entry.h11
-rw-r--r--e-util/e-name-selector-list.c8
-rw-r--r--e-util/e-name-selector-list.h4
-rw-r--r--e-util/e-name-selector.c120
-rw-r--r--e-util/e-name-selector.h9
-rw-r--r--e-util/test-name-selector.c33
9 files changed, 251 insertions, 186 deletions
diff --git a/e-util/e-name-selector-dialog.c b/e-util/e-name-selector-dialog.c
index fd72818612..e40c673284 100644
--- a/e-util/e-name-selector-dialog.c
+++ b/e-util/e-name-selector-dialog.c
@@ -33,7 +33,7 @@
#include <libebook/libebook.h>
#include <libebackend/libebackend.h>
-#include "e-source-combo-box.h"
+#include "e-client-combo-box.h"
#include "e-destination-store.h"
#include "e-contact-store.h"
#include "e-name-selector-dialog.h"
@@ -61,7 +61,7 @@ typedef struct {
} SelData;
struct _ENameSelectorDialogPrivate {
- ESourceRegistry *registry;
+ EClientCache *client_cache;
ENameSelectorModel *name_selector_model;
GtkTreeModelSort *contact_sort;
GCancellable *cancellable;
@@ -83,11 +83,12 @@ struct _ENameSelectorDialogPrivate {
enum {
PROP_0,
- PROP_REGISTRY
+ PROP_CLIENT_CACHE
};
static void search_changed (ENameSelectorDialog *name_selector_dialog);
-static void source_changed (ENameSelectorDialog *name_selector_dialog, ESourceComboBox *source_combo_box);
+static void source_changed (ENameSelectorDialog *name_selector_dialog,
+ EClientComboBox *combo_box);
static void transfer_button_clicked (ENameSelectorDialog *name_selector_dialog, GtkButton *transfer_button);
static void contact_selection_changed (ENameSelectorDialog *name_selector_dialog);
static void setup_name_selector_model (ENameSelectorDialog *name_selector_dialog);
@@ -146,13 +147,13 @@ name_selector_dialog_populate_categories (ENameSelectorDialog *name_selector_dia
}
static void
-name_selector_dialog_set_registry (ENameSelectorDialog *name_selector_dialog,
- ESourceRegistry *registry)
+name_selector_dialog_set_client_cache (ENameSelectorDialog *name_selector_dialog,
+ EClientCache *client_cache)
{
- g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
- g_return_if_fail (name_selector_dialog->priv->registry == NULL);
+ g_return_if_fail (E_IS_CLIENT_CACHE (client_cache));
+ g_return_if_fail (name_selector_dialog->priv->client_cache == NULL);
- name_selector_dialog->priv->registry = g_object_ref (registry);
+ name_selector_dialog->priv->client_cache = g_object_ref (client_cache);
}
static void
@@ -162,8 +163,8 @@ name_selector_dialog_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_REGISTRY:
- name_selector_dialog_set_registry (
+ case PROP_CLIENT_CACHE:
+ name_selector_dialog_set_client_cache (
E_NAME_SELECTOR_DIALOG (object),
g_value_get_object (value));
return;
@@ -179,10 +180,10 @@ name_selector_dialog_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_REGISTRY:
- g_value_set_object (
+ case PROP_CLIENT_CACHE:
+ g_value_take_object (
value,
- e_name_selector_dialog_get_registry (
+ e_name_selector_dialog_ref_client_cache (
E_NAME_SELECTOR_DIALOG (object)));
return;
}
@@ -200,10 +201,7 @@ name_selector_dialog_dispose (GObject *object)
remove_books (E_NAME_SELECTOR_DIALOG (object));
shutdown_name_selector_model (E_NAME_SELECTOR_DIALOG (object));
- if (priv->registry != NULL) {
- g_object_unref (priv->registry);
- priv->registry = NULL;
- }
+ g_clear_object (&priv->client_cache);
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_name_selector_dialog_parent_class)->dispose (object);
@@ -235,6 +233,7 @@ name_selector_dialog_constructed (GObject *object)
GtkTreeViewColumn *column;
GtkCellRenderer *cell_renderer;
GtkTreeSelection *selection;
+ ESourceRegistry *registry;
ESource *source;
gchar *tmp_str;
GtkWidget *name_selector_grid;
@@ -259,7 +258,7 @@ name_selector_dialog_constructed (GObject *object)
GtkWidget *source_tree_view;
GtkWidget *destination_vgrid;
GtkWidget *status_message;
- GtkWidget *source_combo;
+ GtkWidget *client_combo;
const gchar *extension_name;
priv = E_NAME_SELECTOR_DIALOG_GET_PRIVATE (object);
@@ -514,18 +513,22 @@ name_selector_dialog_constructed (GObject *object)
/* Create source menu */
extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
- source_combo = e_source_combo_box_new (priv->registry, extension_name);
+ client_combo = e_client_combo_box_new (
+ priv->client_cache, extension_name);
g_signal_connect_swapped (
- source_combo, "changed",
+ client_combo, "changed",
G_CALLBACK (source_changed), object);
- source_changed (E_NAME_SELECTOR_DIALOG (object), E_SOURCE_COMBO_BOX (source_combo));
+ source_changed (
+ E_NAME_SELECTOR_DIALOG (object),
+ E_CLIENT_COMBO_BOX (client_combo));
- gtk_label_set_mnemonic_widget (GTK_LABEL (AddressBookLabel), source_combo);
- gtk_widget_show (source_combo);
- gtk_widget_set_hexpand (source_combo, TRUE);
- gtk_widget_set_halign (source_combo, GTK_ALIGN_FILL);
- gtk_container_add (GTK_CONTAINER (source_menu_hgrid), source_combo);
+ gtk_label_set_mnemonic_widget (
+ GTK_LABEL (AddressBookLabel), client_combo);
+ gtk_widget_show (client_combo);
+ gtk_widget_set_hexpand (client_combo, TRUE);
+ gtk_widget_set_halign (client_combo, GTK_ALIGN_FILL);
+ gtk_container_add (GTK_CONTAINER (source_menu_hgrid), client_combo);
name_selector_dialog_populate_categories (
E_NAME_SELECTOR_DIALOG (object));
@@ -538,10 +541,12 @@ name_selector_dialog_constructed (GObject *object)
/* Display initial source */
- source = e_source_registry_ref_default_address_book (priv->registry);
+ registry = e_client_cache_ref_registry (priv->client_cache);
+ source = e_source_registry_ref_default_address_book (registry);
e_source_combo_box_set_active (
- E_SOURCE_COMBO_BOX (source_combo), source);
+ E_SOURCE_COMBO_BOX (client_combo), source);
g_object_unref (source);
+ g_object_unref (registry);
/* Set up dialog defaults */
@@ -592,14 +597,19 @@ e_name_selector_dialog_class_init (ENameSelectorDialogClass *class)
object_class->finalize = name_selector_dialog_finalize;
object_class->constructed = name_selector_dialog_constructed;
+ /**
+ * ENameSelectorDialog:client-cache:
+ *
+ * Cache of shared #EClient instances.
+ **/
g_object_class_install_property (
object_class,
- PROP_REGISTRY,
+ PROP_CLIENT_CACHE,
g_param_spec_object (
- "registry",
- "Registry",
- "Data source registry",
- E_TYPE_SOURCE_REGISTRY,
+ "client-cache",
+ "Client Cache",
+ "Cache of shared EClient instances",
+ E_TYPE_CLIENT_CACHE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
@@ -614,40 +624,42 @@ e_name_selector_dialog_init (ENameSelectorDialog *name_selector_dialog)
/**
* e_name_selector_dialog_new:
- * @registry: an #ESourceRegistry
+ * @client_cache: an #EClientCache
*
* Creates a new #ENameSelectorDialog.
*
* Returns: A new #ENameSelectorDialog.
**/
ENameSelectorDialog *
-e_name_selector_dialog_new (ESourceRegistry *registry)
+e_name_selector_dialog_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_NAME_SELECTOR_DIALOG,
- "registry", registry, NULL);
+ "client-cache", client_cache, NULL);
}
/**
- * e_name_selector_dialog_get_registry:
+ * e_name_selector_dialog_ref_client_cache:
* @name_selector_dialog: an #ENameSelectorDialog
*
- * Returns the #ESourceRegistry that was passed to
- * e_name_selector_dialog_new().
+ * Returns the #EClientCache passed to e_name_selector_dialog_new().
+ *
+ * The returned #EClientCache is referenced for thread-safety and must be
+ * unreferenced with g_object_unref() when finished with it.
*
- * Returns: the #ESourceRegistry
+ * Returns: an #EClientCache
*
- * Since: 3.6
+ * Since: 3.8
**/
-ESourceRegistry *
-e_name_selector_dialog_get_registry (ENameSelectorDialog *name_selector_dialog)
+EClientCache *
+e_name_selector_dialog_ref_client_cache (ENameSelectorDialog *name_selector_dialog)
{
g_return_val_if_fail (
E_IS_NAME_SELECTOR_DIALOG (name_selector_dialog), NULL);
- return name_selector_dialog->priv->registry;
+ return g_object_ref (name_selector_dialog->priv->client_cache);
}
/* --------- *
@@ -1133,9 +1145,9 @@ stop_client_view_cb (EContactStore *store,
}
static void
-book_client_connect_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+name_selector_dialog_get_client_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
ENameSelectorDialog *name_selector_dialog = user_data;
EClient *client;
@@ -1144,7 +1156,8 @@ book_client_connect_cb (GObject *source_object,
ENameSelectorModel *model;
GError *error = NULL;
- client = e_book_client_connect_finish (result, &error);
+ client = e_client_combo_box_get_client_finish (
+ E_CLIENT_COMBO_BOX (source_object), result, &error);
/* Sanity check. */
g_return_if_fail (
@@ -1181,13 +1194,13 @@ book_client_connect_cb (GObject *source_object,
static void
source_changed (ENameSelectorDialog *name_selector_dialog,
- ESourceComboBox *source_combo_box)
+ EClientComboBox *combo_box)
{
GCancellable *cancellable;
ESource *source;
gpointer parent;
- source = e_source_combo_box_ref_active (source_combo_box);
+ source = e_source_combo_box_ref_active (E_SOURCE_COMBO_BOX (combo_box));
parent = gtk_widget_get_toplevel (GTK_WIDGET (name_selector_dialog));
parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
@@ -1201,10 +1214,10 @@ source_changed (ENameSelectorDialog *name_selector_dialog,
cancellable = g_cancellable_new ();
name_selector_dialog->priv->cancellable = cancellable;
- /* Connect to the selected book. */
- e_book_client_connect (
- source, cancellable,
- book_client_connect_cb,
+ /* Connect to the selected source. */
+ e_client_combo_box_get_client (
+ combo_box, source, cancellable,
+ name_selector_dialog_get_client_cb,
g_object_ref (name_selector_dialog));
g_object_unref (source);
diff --git a/e-util/e-name-selector-dialog.h b/e-util/e-name-selector-dialog.h
index 69bd969704..c5e8d65b34 100644
--- a/e-util/e-name-selector-dialog.h
+++ b/e-util/e-name-selector-dialog.h
@@ -29,8 +29,8 @@
#define E_NAME_SELECTOR_DIALOG_H
#include <gtk/gtk.h>
-#include <libedataserver/libedataserver.h>
+#include <e-util/e-client-cache.h>
#include <e-util/e-contact-store.h>
#include <e-util/e-name-selector-model.h>
@@ -70,9 +70,8 @@ struct _ENameSelectorDialogClass {
GType e_name_selector_dialog_get_type (void) G_GNUC_CONST;
ENameSelectorDialog *
- e_name_selector_dialog_new (ESourceRegistry *registry);
-ESourceRegistry *
- e_name_selector_dialog_get_registry
+ e_name_selector_dialog_new (EClientCache *client_cache);
+EClientCache * e_name_selector_dialog_ref_client_cache
(ENameSelectorDialog *name_selector_dialog);
ENameSelectorModel *
e_name_selector_dialog_peek_model
diff --git a/e-util/e-name-selector-entry.c b/e-util/e-name-selector-entry.c
index a8a1b23cdb..78b82f2cdb 100644
--- a/e-util/e-name-selector-entry.c
+++ b/e-util/e-name-selector-entry.c
@@ -35,8 +35,7 @@
((obj), E_TYPE_NAME_SELECTOR_ENTRY, ENameSelectorEntryPrivate))
struct _ENameSelectorEntryPrivate {
-
- ESourceRegistry *registry;
+ EClientCache *client_cache;
gint minimum_query_length;
gboolean show_address;
@@ -70,7 +69,7 @@ struct _ENameSelectorEntryPrivate {
enum {
PROP_0,
- PROP_REGISTRY,
+ PROP_CLIENT_CACHE,
PROP_MINIMUM_QUERY_LENGTH,
PROP_SHOW_ADDRESS
};
@@ -119,8 +118,8 @@ name_selector_entry_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_REGISTRY:
- e_name_selector_entry_set_registry (
+ case PROP_CLIENT_CACHE:
+ e_name_selector_entry_set_client_cache (
E_NAME_SELECTOR_ENTRY (object),
g_value_get_object (value));
return;
@@ -148,10 +147,10 @@ name_selector_entry_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_REGISTRY:
- g_value_set_object (
+ case PROP_CLIENT_CACHE:
+ g_value_take_object (
value,
- e_name_selector_entry_get_registry (
+ e_name_selector_entry_ref_client_cache (
E_NAME_SELECTOR_ENTRY (object)));
return;
@@ -180,9 +179,9 @@ name_selector_entry_dispose (GObject *object)
priv = E_NAME_SELECTOR_ENTRY_GET_PRIVATE (object);
- if (priv->registry != NULL) {
- g_object_unref (priv->registry);
- priv->registry = NULL;
+ if (priv->client_cache != NULL) {
+ g_object_unref (priv->client_cache);
+ priv->client_cache = NULL;
}
if (priv->attr_list != NULL) {
@@ -327,14 +326,19 @@ e_name_selector_entry_class_init (ENameSelectorEntryClass *class)
widget_class->realize = name_selector_entry_realize;
widget_class->drag_data_received = name_selector_entry_drag_data_received;
+ /**
+ * ENameSelectorEntry:client-cache:
+ *
+ * Cache of shared #EClient instances.
+ **/
g_object_class_install_property (
object_class,
- PROP_REGISTRY,
+ PROP_CLIENT_CACHE,
g_param_spec_object (
- "registry",
- "Registry",
- "Data source registry",
- E_TYPE_SOURCE_REGISTRY,
+ "client-cache",
+ "Client Cache",
+ "Cache of shared EClient instances",
+ E_TYPE_CLIENT_CACHE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
@@ -2219,16 +2223,17 @@ setup_contact_store (ENameSelectorEntry *name_selector_entry)
}
static void
-book_client_connect_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+name_selector_entry_get_client_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
EContactStore *contact_store = user_data;
EBookClient *book_client;
EClient *client;
GError *error = NULL;
- client = e_book_client_connect_finish (result, &error);
+ client = e_client_cache_get_client_finish (
+ E_CLIENT_CACHE (source_object), result, &error);
/* Sanity check. */
g_return_if_fail (
@@ -2259,6 +2264,7 @@ book_client_connect_cb (GObject *source_object,
static void
setup_default_contact_store (ENameSelectorEntry *name_selector_entry)
{
+ EClientCache *client_cache;
ESourceRegistry *registry;
EContactStore *contact_store;
GList *list, *iter;
@@ -2272,10 +2278,8 @@ setup_default_contact_store (ENameSelectorEntry *name_selector_entry)
name_selector_entry->priv->contact_store = contact_store;
extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
- registry = e_name_selector_entry_get_registry (name_selector_entry);
-
- /* An ESourceRegistry should have been set by now. */
- g_return_if_fail (registry != NULL);
+ client_cache = e_name_selector_entry_ref_client_cache (name_selector_entry);
+ registry = e_client_cache_ref_registry (client_cache);
list = e_source_registry_list_sources (registry, extension_name);
@@ -2302,14 +2306,19 @@ setup_default_contact_store (ENameSelectorEntry *name_selector_entry)
&name_selector_entry->priv->cancellables,
cancellable);
- e_book_client_connect (
- source, cancellable,
- book_client_connect_cb,
+ e_client_cache_get_client (
+ client_cache, source,
+ E_SOURCE_EXTENSION_ADDRESS_BOOK,
+ cancellable,
+ name_selector_entry_get_client_cb,
g_object_ref (contact_store));
}
g_list_free_full (list, (GDestroyNotify) g_object_unref);
+ g_object_unref (registry);
+ g_object_unref (client_cache);
+
setup_contact_store (name_selector_entry);
}
@@ -3308,73 +3317,80 @@ e_name_selector_entry_init (ENameSelectorEntry *name_selector_entry)
/**
* e_name_selector_entry_new:
+ * @client_cache: an #EClientCache
*
* Creates a new #ENameSelectorEntry.
*
* Returns: A new #ENameSelectorEntry.
**/
-ENameSelectorEntry *
-e_name_selector_entry_new (ESourceRegistry *registry)
+GtkWidget *
+e_name_selector_entry_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_NAME_SELECTOR_ENTRY,
- "registry", registry, NULL);
+ "client-cache", client_cache, NULL);
}
/**
- * e_name_selector_entry_get_registry:
+ * e_name_selector_entry_ref_client_cache:
* @name_selector_entry: an #ENameSelectorEntry
*
- * Returns the #ESourceRegistry used to query address books.
+ * Returns the #EClientCache passed to e_name_selector_entry_new().
*
- * Returns: the #ESourceRegistry, or %NULL
+ * The returned #EClientCache is referenced for thread-safety and must be
+ * unreferenced with g_object_unref() when finished with it.
*
- * Since: 3.6
+ * Returns: an #EClientCache
+ *
+ * Since: 3.8
**/
-ESourceRegistry *
-e_name_selector_entry_get_registry (ENameSelectorEntry *name_selector_entry)
+EClientCache *
+e_name_selector_entry_ref_client_cache (ENameSelectorEntry *name_selector_entry)
{
g_return_val_if_fail (
E_IS_NAME_SELECTOR_ENTRY (name_selector_entry), NULL);
- return name_selector_entry->priv->registry;
+ if (name_selector_entry->priv->client_cache == NULL)
+ return NULL;
+
+ return g_object_ref (name_selector_entry->priv->client_cache);
}
/**
- * e_name_selector_entry_set_registry:
+ * e_name_selector_entry_set_client_cache:
* @name_selector_entry: an #ENameSelectorEntry
- * @registry: an #ESourceRegistry
+ * @client_cache: an #EClientCache
*
- * Sets the #ESourceRegistry used to query address books.
+ * Sets the #EClientCache used to query address books.
*
* This function is intended for cases where @name_selector_entry is
- * instantiated by a #GtkBuilder and has to be given an #EsourceRegistry
+ * instantiated by a #GtkBuilder and has to be given an #EClientCache
* after it is fully constructed.
*
* Since: 3.6
**/
void
-e_name_selector_entry_set_registry (ENameSelectorEntry *name_selector_entry,
- ESourceRegistry *registry)
+e_name_selector_entry_set_client_cache (ENameSelectorEntry *name_selector_entry,
+ EClientCache *client_cache)
{
g_return_if_fail (E_IS_NAME_SELECTOR_ENTRY (name_selector_entry));
- if (name_selector_entry->priv->registry == registry)
+ if (client_cache == name_selector_entry->priv->client_cache)
return;
- if (registry != NULL) {
- g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
- g_object_ref (registry);
+ if (client_cache != NULL) {
+ g_return_if_fail (E_IS_CLIENT_CACHE (client_cache));
+ g_object_ref (client_cache);
}
- if (name_selector_entry->priv->registry != NULL)
- g_object_unref (name_selector_entry->priv->registry);
+ if (name_selector_entry->priv->client_cache != NULL)
+ g_object_unref (name_selector_entry->priv->client_cache);
- name_selector_entry->priv->registry = registry;
+ name_selector_entry->priv->client_cache = client_cache;
- g_object_notify (G_OBJECT (name_selector_entry), "registry");
+ g_object_notify (G_OBJECT (name_selector_entry), "client-cache");
}
/**
diff --git a/e-util/e-name-selector-entry.h b/e-util/e-name-selector-entry.h
index 6aa0943e56..ce48aa6b64 100644
--- a/e-util/e-name-selector-entry.h
+++ b/e-util/e-name-selector-entry.h
@@ -31,6 +31,7 @@
#include <gtk/gtk.h>
#include <libebook/libebook.h>
+#include <e-util/e-client-cache.h>
#include <e-util/e-contact-store.h>
#include <e-util/e-destination-store.h>
#include <e-util/e-tree-model-generator.h>
@@ -75,14 +76,12 @@ struct _ENameSelectorEntryClass {
};
GType e_name_selector_entry_get_type (void) G_GNUC_CONST;
-ENameSelectorEntry *
- e_name_selector_entry_new (ESourceRegistry *registry);
-ESourceRegistry *
- e_name_selector_entry_get_registry
+GtkWidget * e_name_selector_entry_new (EClientCache *client_cache);
+EClientCache * e_name_selector_entry_ref_client_cache
(ENameSelectorEntry *name_selector_entry);
-void e_name_selector_entry_set_registry
+void e_name_selector_entry_set_client_cache
(ENameSelectorEntry *name_selector_entry,
- ESourceRegistry *registry);
+ EClientCache *client_cache);
gint e_name_selector_entry_get_minimum_query_length
(ENameSelectorEntry *name_selector_entry);
void e_name_selector_entry_set_minimum_query_length
diff --git a/e-util/e-name-selector-list.c b/e-util/e-name-selector-list.c
index 180dfbf986..52516a5621 100644
--- a/e-util/e-name-selector-list.c
+++ b/e-util/e-name-selector-list.c
@@ -780,12 +780,12 @@ e_name_selector_list_init (ENameSelectorList *list)
}
-ENameSelectorList *
-e_name_selector_list_new (ESourceRegistry *registry)
+GtkWidget *
+e_name_selector_list_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_NAME_SELECTOR_LIST,
- "registry", registry, NULL);
+ "client-cache", client_cache, NULL);
}
diff --git a/e-util/e-name-selector-list.h b/e-util/e-name-selector-list.h
index 28f7451592..008f991001 100644
--- a/e-util/e-name-selector-list.h
+++ b/e-util/e-name-selector-list.h
@@ -32,6 +32,7 @@
#include <gtk/gtk.h>
#include <libebook/libebook.h>
+#include <e-util/e-client-cache.h>
#include <e-util/e-contact-store.h>
#include <e-util/e-destination-store.h>
#include <e-util/e-tree-model-generator.h>
@@ -72,8 +73,7 @@ struct _ENameSelectorListClass {
};
GType e_name_selector_list_get_type (void) G_GNUC_CONST;
-ENameSelectorList *
- e_name_selector_list_new (ESourceRegistry *registry);
+GtkWidget * e_name_selector_list_new (EClientCache *client_cache);
void e_name_selector_list_expand_clicked
(ENameSelectorList *list);
diff --git a/e-util/e-name-selector.c b/e-util/e-name-selector.c
index 38ade81fb3..f6e6658731 100644
--- a/e-util/e-name-selector.c
+++ b/e-util/e-name-selector.c
@@ -50,7 +50,7 @@ typedef struct {
} SourceBook;
struct _ENameSelectorPrivate {
- ESourceRegistry *registry;
+ EClientCache *client_cache;
ENameSelectorModel *model;
ENameSelectorDialog *dialog;
@@ -63,7 +63,7 @@ struct _ENameSelectorPrivate {
enum {
PROP_0,
- PROP_REGISTRY
+ PROP_CLIENT_CACHE
};
G_DEFINE_TYPE (ENameSelector, e_name_selector, G_TYPE_OBJECT)
@@ -90,9 +90,9 @@ reset_pointer_cb (gpointer data,
}
static void
-name_selector_book_client_connect_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+name_selector_get_client_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
ENameSelector *name_selector = user_data;
EBookClient *book_client;
@@ -102,7 +102,8 @@ name_selector_book_client_connect_cb (GObject *source_object,
guint ii;
GError *error = NULL;
- client = e_book_client_connect_finish (result, &error);
+ client = e_client_cache_get_client_finish (
+ E_CLIENT_CACHE (source_object), result, &error);
/* Sanity check. */
g_return_if_fail (
@@ -160,6 +161,7 @@ name_selector_book_client_connect_cb (GObject *source_object,
void
e_name_selector_load_books (ENameSelector *name_selector)
{
+ EClientCache *client_cache;
ESourceRegistry *registry;
GList *list, *iter;
const gchar *extension_name;
@@ -167,7 +169,9 @@ e_name_selector_load_books (ENameSelector *name_selector)
g_return_if_fail (E_IS_NAME_SELECTOR (name_selector));
extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
- registry = e_name_selector_get_registry (name_selector);
+ client_cache = e_name_selector_ref_client_cache (name_selector);
+ registry = e_client_cache_ref_registry (client_cache);
+
list = e_source_registry_list_sources (registry, extension_name);
for (iter = list; iter != NULL; iter = g_list_next (iter)) {
@@ -187,13 +191,21 @@ e_name_selector_load_books (ENameSelector *name_selector)
if (!e_source_autocomplete_get_include_me (extension))
continue;
- e_book_client_connect (
- source, name_selector->priv->cancellable,
- name_selector_book_client_connect_cb,
+ /* FIXME GCancellable is only to be used for one
+ * operation at a time, not for multiple
+ * concurrent operations like this. */
+ e_client_cache_get_client (
+ client_cache, source,
+ E_SOURCE_EXTENSION_ADDRESS_BOOK,
+ name_selector->priv->cancellable,
+ name_selector_get_client_cb,
g_object_ref (name_selector));
}
g_list_free_full (list, (GDestroyNotify) g_object_unref);
+
+ g_object_unref (registry);
+ g_object_unref (client_cache);
}
/**
@@ -215,13 +227,13 @@ e_name_selector_cancel_loading (ENameSelector *name_selector)
}
static void
-name_selector_set_registry (ENameSelector *name_selector,
- ESourceRegistry *registry)
+name_selector_set_client_cache (ENameSelector *name_selector,
+ EClientCache *client_cache)
{
- g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
- g_return_if_fail (name_selector->priv->registry == NULL);
+ g_return_if_fail (E_IS_CLIENT_CACHE (client_cache));
+ g_return_if_fail (name_selector->priv->client_cache == NULL);
- name_selector->priv->registry = g_object_ref (registry);
+ name_selector->priv->client_cache = g_object_ref (client_cache);
}
static void
@@ -231,8 +243,8 @@ name_selector_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_REGISTRY:
- name_selector_set_registry (
+ case PROP_CLIENT_CACHE:
+ name_selector_set_client_cache (
E_NAME_SELECTOR (object),
g_value_get_object (value));
return;
@@ -248,10 +260,10 @@ name_selector_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_REGISTRY:
- g_value_set_object (
+ case PROP_CLIENT_CACHE:
+ g_value_take_object (
value,
- e_name_selector_get_registry (
+ e_name_selector_ref_client_cache (
E_NAME_SELECTOR (object)));
return;
}
@@ -337,14 +349,19 @@ e_name_selector_class_init (ENameSelectorClass *class)
object_class->dispose = name_selector_dispose;
object_class->finalize = name_selector_finalize;
+ /**
+ * ENameSelector:client-cache:
+ *
+ * Cache of shared #EClient instances.
+ **/
g_object_class_install_property (
object_class,
- PROP_REGISTRY,
+ PROP_CLIENT_CACHE,
g_param_spec_object (
- "registry",
- "Registry",
- "Data source registry",
- E_TYPE_SOURCE_REGISTRY,
+ "client-cache",
+ "Client Cache",
+ "Cache of shared EClient instances",
+ E_TYPE_CLIENT_CACHE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
@@ -369,38 +386,41 @@ e_name_selector_init (ENameSelector *name_selector)
/**
* e_name_selector_new:
- * @registry: an #ESourceRegistry
+ * @client_cache: an #EClientCache
*
* Creates a new #ENameSelector.
*
* Returns: A new #ENameSelector.
**/
ENameSelector *
-e_name_selector_new (ESourceRegistry *registry)
+e_name_selector_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_NAME_SELECTOR,
- "registry", registry, NULL);
+ "client-cache", client_cache, NULL);
}
/**
- * e_name_selector_get_registry:
+ * e_name_selector_ref_client_cache:
* @name_selector: an #ENameSelector
*
- * Returns the #ESourceRegistry passed to e_name_selector_new().
+ * Returns the #EClientCache passed to e_name_selector_new().
*
- * Returns: the #ESourceRegistry
+ * The returned #EClientCache is referenced for thread-safety and must be
+ * unreferenced with g_object_unref() when finished with it.
*
- * Since: 3.6
+ * Returns: an #EClientCache
+ *
+ * Since: 3.8
**/
-ESourceRegistry *
-e_name_selector_get_registry (ENameSelector *name_selector)
+EClientCache *
+e_name_selector_ref_client_cache (ENameSelector *name_selector)
{
g_return_val_if_fail (E_IS_NAME_SELECTOR (name_selector), NULL);
- return name_selector->priv->registry;
+ return g_object_ref (name_selector->priv->client_cache);
}
/* ------- *
@@ -479,13 +499,14 @@ e_name_selector_peek_dialog (ENameSelector *name_selector)
g_return_val_if_fail (E_IS_NAME_SELECTOR (name_selector), NULL);
if (name_selector->priv->dialog == NULL) {
- ESourceRegistry *registry;
+ EClientCache *client_cache;
ENameSelectorDialog *dialog;
ENameSelectorModel *model;
- registry = e_name_selector_get_registry (name_selector);
- dialog = e_name_selector_dialog_new (registry);
+ client_cache = e_name_selector_ref_client_cache (name_selector);
+ dialog = e_name_selector_dialog_new (client_cache);
name_selector->priv->dialog = dialog;
+ g_object_unref (client_cache);
model = e_name_selector_peek_model (name_selector);
e_name_selector_dialog_set_model (dialog, model);
@@ -563,13 +584,17 @@ e_name_selector_peek_section_entry (ENameSelector *name_selector,
section = &g_array_index (name_selector->priv->sections, Section, n);
if (!section->entry) {
- ESourceRegistry *registry;
+ EClientCache *client_cache;
EContactStore *contact_store;
+ GtkWidget *widget;
gchar *text;
gint i;
- registry = e_name_selector_get_registry (name_selector);
- section->entry = e_name_selector_entry_new (registry);
+ client_cache = e_name_selector_ref_client_cache (name_selector);
+ widget = e_name_selector_entry_new (client_cache);
+ section->entry = E_NAME_SELECTOR_ENTRY (widget);
+ g_object_unref (client_cache);
+
g_object_weak_ref (G_OBJECT (section->entry), reset_pointer_cb, name_selector);
if (pango_parse_markup (name, -1, '_', NULL,
&text, NULL, NULL)) {
@@ -635,13 +660,16 @@ e_name_selector_peek_section_list (ENameSelector *name_selector,
if (!section->entry) {
EContactStore *contact_store;
- ESourceRegistry *registry;
+ EClientCache *client_cache;
+ GtkWidget *widget;
gchar *text;
gint i;
- registry = name_selector->priv->registry;
- section->entry = (ENameSelectorEntry *)
- e_name_selector_list_new (registry);
+ client_cache = e_name_selector_ref_client_cache (name_selector);
+ widget = e_name_selector_list_new (client_cache);
+ section->entry = E_NAME_SELECTOR_ENTRY (widget);
+ g_object_unref (client_cache);
+
g_object_weak_ref (G_OBJECT (section->entry), reset_pointer_cb, name_selector);
if (pango_parse_markup (name, -1, '_', NULL,
&text, NULL, NULL)) {
diff --git a/e-util/e-name-selector.h b/e-util/e-name-selector.h
index c6949c5417..eb4dc79145 100644
--- a/e-util/e-name-selector.h
+++ b/e-util/e-name-selector.h
@@ -27,8 +27,7 @@
#ifndef E_NAME_SELECTOR_H
#define E_NAME_SELECTOR_H
-#include <libedataserver/libedataserver.h>
-
+#include <e-util/e-client-cache.h>
#include <e-util/e-name-selector-model.h>
#include <e-util/e-name-selector-dialog.h>
#include <e-util/e-name-selector-entry.h>
@@ -69,9 +68,9 @@ struct _ENameSelectorClass {
};
GType e_name_selector_get_type (void) G_GNUC_CONST;
-ENameSelector * e_name_selector_new (ESourceRegistry *registry);
-ESourceRegistry *
- e_name_selector_get_registry (ENameSelector *name_selector);
+ENameSelector * e_name_selector_new (EClientCache *client_cache);
+EClientCache * e_name_selector_ref_client_cache
+ (ENameSelector *name_selector);
ENameSelectorModel *
e_name_selector_peek_model (ENameSelector *name_selector);
ENameSelectorDialog *
diff --git a/e-util/test-name-selector.c b/e-util/test-name-selector.c
index 3744ad9f1a..b8cbee807f 100644
--- a/e-util/test-name-selector.c
+++ b/e-util/test-name-selector.c
@@ -39,12 +39,12 @@ close_dialog (GtkWidget *widget,
}
static gboolean
-start_test (ESourceRegistry *registry)
+start_test (EClientCache *client_cache)
{
- ENameSelectorModel *name_selector_model;
- ENameSelectorEntry *name_selector_entry;
- EDestinationStore *destination_store;
- GtkWidget *container;
+ ENameSelectorModel *name_selector_model;
+ EDestinationStore *destination_store;
+ GtkWidget *name_selector_entry;
+ GtkWidget *container;
destination_store = e_destination_store_new ();
name_selector_model = e_name_selector_model_new ();
@@ -53,18 +53,23 @@ start_test (ESourceRegistry *registry)
e_name_selector_model_add_section (name_selector_model, "cc", "Cc", NULL);
e_name_selector_model_add_section (name_selector_model, "bcc", "Bcc", NULL);
- name_selector_dialog = e_name_selector_dialog_new (registry);
+ name_selector_dialog = e_name_selector_dialog_new (client_cache);
e_name_selector_dialog_set_model (name_selector_dialog, name_selector_model);
gtk_window_set_modal (GTK_WINDOW (name_selector_dialog), FALSE);
- name_selector_entry = e_name_selector_entry_new (registry);
- e_name_selector_entry_set_destination_store (name_selector_entry, destination_store);
+ name_selector_entry = e_name_selector_entry_new (client_cache);
+ e_name_selector_entry_set_destination_store (
+ E_NAME_SELECTOR_ENTRY (name_selector_entry),
+ destination_store);
+
+ g_signal_connect (
+ name_selector_dialog, "response",
+ G_CALLBACK (close_dialog), name_selector_dialog);
- g_signal_connect (name_selector_dialog, "response", G_CALLBACK (close_dialog), name_selector_dialog);
gtk_widget_show (GTK_WIDGET (name_selector_dialog));
container = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_container_add (GTK_CONTAINER (container), GTK_WIDGET (name_selector_entry));
+ gtk_container_add (GTK_CONTAINER (container), name_selector_entry);
gtk_widget_show_all (container);
name_selector_entry_window = container;
@@ -79,6 +84,7 @@ main (gint argc,
gchar **argv)
{
ESourceRegistry *registry;
+ EClientCache *client_cache;
GError *error = NULL;
gtk_init (&argc, &argv);
@@ -94,9 +100,14 @@ main (gint argc,
g_assert_not_reached ();
}
- g_idle_add ((GSourceFunc) start_test, registry);
+ client_cache = e_client_cache_new (registry);
+
+ g_idle_add ((GSourceFunc) start_test, client_cache);
gtk_main ();
+ g_object_unref (registry);
+ g_object_unref (client_cache);
+
return 0;
}