[evolution/account-mgmt: 8/54] Adapt EContactEditor to the new ESource API.



commit dd16e2e75346e14d8d5e60bd9d6ba6f01110aeb4
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Dec 8 00:16:30 2010 -0500

    Adapt EContactEditor to the new ESource API.

 addressbook/gui/contact-editor/contact-editor.ui   |    1 +
 addressbook/gui/contact-editor/e-contact-editor.c  |   23 ++++---
 .../gui/contact-editor/e-contact-quick-add.c       |   65 +++++++++++---------
 .../gui/contact-editor/e-contact-quick-add.h       |   13 +++-
 4 files changed, 58 insertions(+), 44 deletions(-)
---
diff --git a/addressbook/gui/contact-editor/contact-editor.ui b/addressbook/gui/contact-editor/contact-editor.ui
index 2f133d4..985659d 100644
--- a/addressbook/gui/contact-editor/contact-editor.ui
+++ b/addressbook/gui/contact-editor/contact-editor.ui
@@ -232,6 +232,7 @@
                                 </child>
                                 <child>
                                   <object class="ESourceComboBox" type-func="e_source_combo_box_get_type" id="source-combo-box-source">
+                                    <property name="extension-name">Address Book</property>
                                     <property name="visible">True</property>
                                   </object>
                                   <packing>
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c
index 7676d62..f6a5e04 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/addressbook/gui/contact-editor/e-contact-editor.c
@@ -27,6 +27,7 @@
 #include "eab-editor.h"
 #include "e-contact-editor.h"
 
+#include <stdlib.h>
 #include <string.h>
 #include <time.h>
 #include <gtk/gtk.h>
@@ -3092,10 +3093,8 @@ source_changed (ESourceComboBox *source_combo_box,
 	ESource *target_source;
 	ESource *source_source;
 	ESource *source;
-	GtkWindow *parent;
 
 	source = e_source_combo_box_get_active (source_combo_box);
-	parent = eab_editor_get_window (EAB_EDITOR (editor));
 
 	if (editor->cancellable != NULL) {
 		g_cancellable_cancel (editor->cancellable);
@@ -3121,7 +3120,6 @@ source_changed (ESourceComboBox *source_combo_box,
 	e_client_utils_open_new (
 		source, E_CLIENT_SOURCE_TYPE_CONTACTS,
 		FALSE, editor->cancellable,
-		e_client_utils_authenticate_handler, parent,
 		contact_editor_book_loaded_cb, g_object_ref (editor));
 }
 
@@ -3574,7 +3572,12 @@ static void
 real_save_contact (EContactEditor *ce,
                    gboolean should_close)
 {
+	EShell *shell;
 	EditorCloseStruct *ecs;
+	ESourceRegistry *registry;
+
+	shell = eab_editor_get_shell (EAB_EDITOR (ce));
+	registry = e_shell_get_registry (shell);
 
 	ecs = g_new0 (EditorCloseStruct, 1);
 	ecs->ce = ce;
@@ -3588,17 +3591,17 @@ real_save_contact (EContactEditor *ce,
 	if (ce->source_client != ce->target_client) {
 		/* Two-step move; add to target, then remove from source */
 		eab_merging_book_add_contact (
-			ce->target_client, ce->contact,
-			contact_added_cb, ecs);
+			registry, ce->target_client,
+			ce->contact, contact_added_cb, ecs);
 	} else {
 		if (ce->is_new_contact)
 			eab_merging_book_add_contact (
-				ce->target_client, ce->contact,
-				contact_added_cb, ecs);
+				registry, ce->target_client,
+				ce->contact, contact_added_cb, ecs);
 		else if (ce->check_merge)
 			eab_merging_book_modify_contact (
-				ce->target_client, ce->contact,
-				contact_modified_cb, ecs);
+				registry, ce->target_client,
+				ce->contact, contact_modified_cb, ecs);
 		else
 			e_book_client_modify_contact (
 				ce->target_client, ce->contact, NULL,
@@ -4041,8 +4044,6 @@ e_contact_editor_init (EContactEditor *e_contact_editor)
 		G_CALLBACK (categories_clicked), e_contact_editor);
 	widget = e_builder_get_widget (
 		e_contact_editor->builder, "source-combo-box-source");
-	e_util_set_source_combo_box_list (
-		widget, "/apps/evolution/addressbook/sources");
 	g_signal_connect (
 		widget, "changed",
 		G_CALLBACK (source_changed), e_contact_editor);
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.c b/addressbook/gui/contact-editor/e-contact-quick-add.c
index 7c303e7..0e497e6 100644
--- a/addressbook/gui/contact-editor/e-contact-quick-add.c
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.c
@@ -32,6 +32,7 @@
 #include <libebook/e-contact.h>
 #include <libedataserverui/e-client-utils.h>
 #include <libedataserverui/e-source-combo-box.h>
+#include <libedataserver/e-source-address-book.h>
 #include <addressbook/util/eab-book-util.h>
 #include "e-contact-editor.h"
 #include "e-contact-quick-add.h"
@@ -45,7 +46,7 @@ struct _QuickAdd {
 	gchar *vcard;
 	EContact *contact;
 	GCancellable *cancellable;
-	ESourceList *source_list;
+	ESourceRegistry *registry;
 	ESource *source;
 
 	EContactQuickAddCallback cb;
@@ -61,10 +62,11 @@ struct _QuickAdd {
 };
 
 static QuickAdd *
-quick_add_new (void)
+quick_add_new (ESourceRegistry *registry)
 {
 	QuickAdd *qa = g_new0 (QuickAdd, 1);
 	qa->contact = e_contact_new ();
+	qa->registry = g_object_ref (registry);
 	qa->refs = 1;
 	return qa;
 }
@@ -79,12 +81,11 @@ quick_add_unref (QuickAdd *qa)
 				g_cancellable_cancel (qa->cancellable);
 				g_object_unref (qa->cancellable);
 			}
-			if (qa->source_list != NULL)
-				g_object_unref (qa->source_list);
 			g_free (qa->name);
 			g_free (qa->email);
 			g_free (qa->vcard);
 			g_object_unref (qa->contact);
+			g_object_unref (qa->registry);
 			g_free (qa);
 		}
 	}
@@ -156,12 +157,13 @@ merge_cb (GObject *source_object,
 
 	if (!e_client_is_readonly (client))
 		eab_merging_book_add_contact (
-			E_BOOK_CLIENT (client), qa->contact, NULL, NULL);
+			qa->registry, E_BOOK_CLIENT (client),
+			qa->contact, NULL, NULL);
 	else
 		e_alert_run_dialog_for_args (
 			e_shell_get_active_window (NULL),
 			"addressbook:error-read-only",
-			e_source_peek_name (source),
+			e_source_get_display_name (source),
 			NULL);
 
 	if (qa->cb)
@@ -184,9 +186,7 @@ quick_add_merge_contact (QuickAdd *qa)
 
 	e_client_utils_open_new (
 		qa->source, E_CLIENT_SOURCE_TYPE_CONTACTS,
-		FALSE, qa->cancellable,
-		e_client_utils_authenticate_handler, NULL,
-		merge_cb, qa);
+		FALSE, qa->cancellable, merge_cb, qa);
 }
 
 /* Raise a contact editor with all fields editable,
@@ -312,7 +312,8 @@ ce_have_book (GObject *source_object,
 	g_return_if_fail (E_IS_CLIENT (client));
 
 	eab_merging_book_find_contact (
-		E_BOOK_CLIENT (client), qa->contact, ce_have_contact, qa);
+		qa->registry, E_BOOK_CLIENT (client),
+		qa->contact, ce_have_contact, qa);
 }
 
 static void
@@ -327,9 +328,7 @@ edit_contact (QuickAdd *qa)
 
 	e_client_utils_open_new (
 		qa->source, E_CLIENT_SOURCE_TYPE_CONTACTS,
-		FALSE, qa->cancellable,
-		e_client_utils_authenticate_handler, NULL,
-		ce_have_book, qa);
+		FALSE, qa->cancellable, ce_have_book, qa);
 }
 
 #define QUICK_ADD_RESPONSE_EDIT_FULL 2
@@ -424,12 +423,12 @@ source_changed (ESourceComboBox *source_combo_box,
 static GtkWidget *
 build_quick_add_dialog (QuickAdd *qa)
 {
-	GConfClient *gconf_client;
 	GtkWidget *container;
 	GtkWidget *dialog;
 	GtkWidget *label;
 	GtkTable *table;
 	ESource *source;
+	const gchar *extension_name;
 	const gint xpad = 0, ypad = 0;
 
 	g_return_val_if_fail (qa != NULL, NULL);
@@ -470,13 +469,10 @@ build_quick_add_dialog (QuickAdd *qa)
 		gtk_widget_set_sensitive (qa->email_entry, FALSE);
 	}
 
-	gconf_client = gconf_client_get_default ();
-	qa->source_list = e_source_list_new_for_gconf (
-		gconf_client, "/apps/evolution/addressbook/sources");
-	source = e_source_list_peek_default_source (qa->source_list);
-	g_object_unref (gconf_client);
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	source = e_source_registry_get_default_address_book (qa->registry);
 
-	qa->combo_box = e_source_combo_box_new (qa->source_list);
+	qa->combo_box = e_source_combo_box_new (qa->registry, extension_name);
 	e_source_combo_box_set_active (
 		E_SOURCE_COMBO_BOX (qa->combo_box), source);
 
@@ -532,7 +528,8 @@ build_quick_add_dialog (QuickAdd *qa)
 }
 
 void
-e_contact_quick_add (const gchar *in_name,
+e_contact_quick_add (ESourceRegistry *registry,
+                     const gchar *in_name,
                      const gchar *email,
                      EContactQuickAddCallback cb,
                      gpointer closure)
@@ -542,6 +539,8 @@ e_contact_quick_add (const gchar *in_name,
 	gchar *name = NULL;
 	gint len;
 
+	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+
 	/* We need to have *something* to work with. */
 	if (in_name == NULL && email == NULL) {
 		if (cb)
@@ -563,7 +562,7 @@ e_contact_quick_add (const gchar *in_name,
 		g_strstrip (name);
 	}
 
-	qa = quick_add_new ();
+	qa = quick_add_new (registry);
 	qa->cb = cb;
 	qa->closure = closure;
 	if (name)
@@ -578,7 +577,8 @@ e_contact_quick_add (const gchar *in_name,
 }
 
 void
-e_contact_quick_add_free_form (const gchar *text,
+e_contact_quick_add_free_form (ESourceRegistry *registry,
+                               const gchar *text,
                                EContactQuickAddCallback cb,
                                gpointer closure)
 {
@@ -586,8 +586,10 @@ e_contact_quick_add_free_form (const gchar *text,
 	const gchar *last_at, *s;
 	gboolean in_quote;
 
+	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+
 	if (text == NULL) {
-		e_contact_quick_add (NULL, NULL, cb, closure);
+		e_contact_quick_add (registry, NULL, NULL, cb, closure);
 		return;
 	}
 
@@ -651,13 +653,15 @@ e_contact_quick_add_free_form (const gchar *text,
 			g_strstrip (email);
 	}
 
-	e_contact_quick_add (name, email, cb, closure);
+	e_contact_quick_add (registry, name, email, cb, closure);
+
 	g_free (name);
 	g_free (email);
 }
 
 void
-e_contact_quick_add_email (const gchar *email,
+e_contact_quick_add_email (ESourceRegistry *registry,
+                           const gchar *email,
                            EContactQuickAddCallback cb,
                            gpointer closure)
 {
@@ -679,14 +683,15 @@ e_contact_quick_add_email (const gchar *email,
 		addr = g_strdup (email);
 	}
 
-	e_contact_quick_add (name, addr, cb, closure);
+	e_contact_quick_add (registry, name, addr, cb, closure);
 
 	g_free (name);
 	g_free (addr);
 }
 
 void
-e_contact_quick_add_vcard (const gchar *vcard,
+e_contact_quick_add_vcard (ESourceRegistry *registry,
+                           const gchar *vcard,
                            EContactQuickAddCallback cb,
                            gpointer closure)
 {
@@ -694,6 +699,8 @@ e_contact_quick_add_vcard (const gchar *vcard,
 	GtkWidget *dialog;
 	EContact *contact;
 
+	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+
 	/* We need to have *something* to work with. */
 	if (vcard == NULL) {
 		if (cb)
@@ -701,7 +708,7 @@ e_contact_quick_add_vcard (const gchar *vcard,
 		return;
 	}
 
-	qa = quick_add_new ();
+	qa = quick_add_new (registry);
 	qa->cb = cb;
 	qa->closure = closure;
 	quick_add_set_vcard (qa, vcard);
diff --git a/addressbook/gui/contact-editor/e-contact-quick-add.h b/addressbook/gui/contact-editor/e-contact-quick-add.h
index 861ddba..91e6401 100644
--- a/addressbook/gui/contact-editor/e-contact-quick-add.h
+++ b/addressbook/gui/contact-editor/e-contact-quick-add.h
@@ -24,21 +24,26 @@
 #define __E_CONTACT_QUICK_ADD_H__
 
 #include <libebook/e-contact.h>
+#include <libedataserver/e-source-registry.h>
 
 typedef void	(*EContactQuickAddCallback)	(EContact *new_contact,
 						 gpointer closure);
 
-void		e_contact_quick_add		(const gchar *name,
+void		e_contact_quick_add		(ESourceRegistry *registry,
+						 const gchar *name,
 						 const gchar *email,
 						 EContactQuickAddCallback cb,
 						 gpointer closure);
-void		e_contact_quick_add_free_form	(const gchar *text,
+void		e_contact_quick_add_free_form	(ESourceRegistry *registry,
+						 const gchar *text,
 						 EContactQuickAddCallback cb,
 						 gpointer closure);
-void		e_contact_quick_add_email	(const gchar *email,
+void		e_contact_quick_add_email	(ESourceRegistry *registry,
+						 const gchar *email,
 						 EContactQuickAddCallback cb,
 						 gpointer closure);
-void		e_contact_quick_add_vcard	(const gchar *vcard,
+void		e_contact_quick_add_vcard	(ESourceRegistry *registry,
+						 const gchar *vcard,
 						 EContactQuickAddCallback cb,
 						 gpointer closure);
 



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