[evolution-data-server/openismus-work] EBookClientView: Added constructor for direct access



commit adab85a6322603b3fc3d387e47b106d37fa492d5
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Fri Nov 16 18:58:43 2012 +0900

    EBookClientView: Added constructor for direct access
    
    When the EBookClientView is created with direct ownership of an
    EDataBookView, the direct access apis are used to configure the
    view and the direct GSignals from that view are used instead of
    GDBus object signals for propagating notifications.

 addressbook/libebook/e-book-client-view-private.h |    2 +
 addressbook/libebook/e-book-client-view.c         |   96 +++++++++++++++++---
 2 files changed, 83 insertions(+), 15 deletions(-)
---
diff --git a/addressbook/libebook/e-book-client-view-private.h b/addressbook/libebook/e-book-client-view-private.h
index 668da47..3878251 100644
--- a/addressbook/libebook/e-book-client-view-private.h
+++ b/addressbook/libebook/e-book-client-view-private.h
@@ -23,10 +23,12 @@
 #define E_BOOK_CLIENT_VIEW_PRIVATE_H
 
 #include <libebook/libebook.h>
+#include <libedata-book/libedata-book.h>
 
 struct _EGdbusBookView;
 
 EBookClientView *_e_book_client_view_new (EBookClient *book_client, struct _EGdbusBookView *gdbus_bookview);
+EBookClientView *_e_book_client_view_new_direct (EBookClient *book_client, EDataBookView *direct_view);
 
 G_END_DECLS
 
diff --git a/addressbook/libebook/e-book-client-view.c b/addressbook/libebook/e-book-client-view.c
index eb5dea9..fb87c85 100644
--- a/addressbook/libebook/e-book-client-view.c
+++ b/addressbook/libebook/e-book-client-view.c
@@ -42,6 +42,7 @@ G_DEFINE_TYPE (EBookClientView, e_book_client_view, G_TYPE_OBJECT);
 
 struct _EBookClientViewPrivate {
 	GDBusProxy *gdbus_bookview;
+	EDataBookView *direct_view;
 	EBookClient *client;
 	gboolean running;
 };
@@ -58,7 +59,7 @@ enum {
 static guint signals[LAST_SIGNAL];
 
 static void
-objects_added_cb (EGdbusBookView *object,
+objects_added_cb (GObject *object,
                   const gchar * const *vcards,
                   EBookClientView *view)
 {
@@ -81,7 +82,7 @@ objects_added_cb (EGdbusBookView *object,
 }
 
 static void
-objects_modified_cb (EGdbusBookView *object,
+objects_modified_cb (GObject *object,
                      const gchar * const *vcards,
                      EBookClientView *view)
 {
@@ -103,7 +104,7 @@ objects_modified_cb (EGdbusBookView *object,
 }
 
 static void
-objects_removed_cb (EGdbusBookView *object,
+objects_removed_cb (GObject *object,
                     const gchar * const *ids,
                     EBookClientView *view)
 {
@@ -154,6 +155,17 @@ complete_cb (EGdbusBookView *object,
 		g_error_free (error);
 }
 
+static void
+complete_direct_cb (EDataBookView *object,
+		    GError *error,
+		    EBookClientView *view)
+{
+	if (!view->priv->running)
+		return;
+
+	g_signal_emit (view, signals[COMPLETE], 0, error);
+}
+
 /*
  * _e_book_client_view_new:
  * @book_client: an #EBookClient
@@ -190,6 +202,31 @@ _e_book_client_view_new (EBookClient *book_client,
 	return view;
 }
 
+EBookClientView *
+_e_book_client_view_new_direct (EBookClient *book_client,
+				EDataBookView *direct_view)
+{
+	EBookClientView *view;
+	EBookClientViewPrivate *priv;
+
+	view = g_object_new (E_TYPE_BOOK_CLIENT_VIEW, NULL);
+	priv = view->priv;
+
+	priv->client = g_object_ref (book_client);
+
+	/* Reference the EDataBookView (it's technically owned by it's backend) */
+	priv->direct_view = g_object_ref (direct_view);
+
+	g_signal_connect (priv->direct_view, "vcards-added", G_CALLBACK (objects_added_cb), view);
+	g_signal_connect (priv->direct_view, "vcards-modified", G_CALLBACK (objects_modified_cb), view);
+	g_signal_connect (priv->direct_view, "uids-removed", G_CALLBACK (objects_removed_cb), view);
+	g_signal_connect (priv->direct_view, "progress", G_CALLBACK (progress_cb), view);
+	g_signal_connect (priv->direct_view, "complete", G_CALLBACK (complete_direct_cb), view);
+
+	return view;
+}
+
+
 /**
  * e_book_client_view_get_client:
  * @view: an #EBookClientView
@@ -223,7 +260,12 @@ e_book_client_view_start (EBookClientView *view,
 
 	priv = view->priv;
 
-	if (priv->gdbus_bookview) {
+	if (priv->direct_view) {
+		
+		priv->running = TRUE;
+		e_data_book_view_start (priv->direct_view);
+
+	} else if (priv->gdbus_bookview) {
 		GError *local_error = NULL;
 
 		priv->running = TRUE;
@@ -233,7 +275,8 @@ e_book_client_view_start (EBookClientView *view,
 		e_client_unwrap_dbus_error (E_CLIENT (priv->client), local_error, error);
 	} else {
 		/* do not translate this string, it should ideally never happen */
-		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR, "Cannot start view, D-Bus proxy gone");
+		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR,
+				     "Cannot start view, Not a direct access view and no D-Bus proxy present");
 	}
 }
 
@@ -255,7 +298,11 @@ e_book_client_view_stop (EBookClientView *view,
 	priv = view->priv;
 	priv->running = FALSE;
 
-	if (priv->gdbus_bookview) {
+	if (priv->direct_view) {
+		
+		e_data_book_view_stop (priv->direct_view);
+
+	} else if (priv->gdbus_bookview) {
 		GError *local_error = NULL;
 
 		e_gdbus_book_view_call_stop_sync (priv->gdbus_bookview, NULL, &local_error);
@@ -263,7 +310,8 @@ e_book_client_view_stop (EBookClientView *view,
 		e_client_unwrap_dbus_error (E_CLIENT (priv->client), local_error, error);
 	} else {
 		/* do not translate this string, it should ideally never happen */
-		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR, "Cannot stop view, D-Bus proxy gone");
+		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR,
+				     "Cannot stop view, Not a direct access view and no D-Bus proxy present");
 	}
 }
 
@@ -288,7 +336,11 @@ e_book_client_view_set_flags (EBookClientView *view,
 
 	priv = view->priv;
 
-	if (priv->gdbus_bookview) {
+	if (priv->direct_view) {
+		
+		e_data_book_view_set_flags (priv->direct_view, flags);
+
+	} else if (priv->gdbus_bookview) {
 		GError *local_error = NULL;
 
 		e_gdbus_book_view_call_set_flags_sync (priv->gdbus_bookview, flags, NULL, &local_error);
@@ -297,7 +349,7 @@ e_book_client_view_set_flags (EBookClientView *view,
 	} else {
 		g_set_error_literal (
 			error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR,
-			"Cannot set flags on view, D-Bus proxy gone");
+			"Cannot set flags on view, Not a direct access view and no D-Bus proxy present");
 	}
 }
 
@@ -324,24 +376,29 @@ e_book_client_view_set_fields_of_interest (EBookClientView *view,
                                            GError **error)
 {
 	EBookClientViewPrivate *priv;
+	gchar **strv;
 
 	g_return_if_fail (E_IS_BOOK_CLIENT_VIEW (view));
 
 	priv = view->priv;
+	strv = e_client_util_slist_to_strv (fields_of_interest);
 
-	if (priv->gdbus_bookview) {
+	if (priv->direct_view) {
+		
+		e_data_book_view_set_fields_of_interest (priv->direct_view, (const gchar * const *) strv);
+
+	} else if (priv->gdbus_bookview) {
 		GError *local_error = NULL;
-		gchar **strv;
 
-		strv = e_client_util_slist_to_strv (fields_of_interest);
 		e_gdbus_book_view_call_set_fields_of_interest_sync (priv->gdbus_bookview, (const gchar * const *) strv, NULL, &local_error);
-		g_strfreev (strv);
-
 		e_client_unwrap_dbus_error (E_CLIENT (priv->client), local_error, error);
 	} else {
 		/* do not translate this string, it should ideally never happen */
-		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR, "Cannot set fields of interest, D-Bus proxy gone");
+		g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR,
+				     "Cannot set fields of interest, Not a direct access view and no D-Bus proxy present");
 	}
+
+	g_strfreev (strv);
 }
 
 static void
@@ -349,6 +406,7 @@ e_book_client_view_init (EBookClientView *view)
 {
 	view->priv = E_BOOK_CLIENT_VIEW_GET_PRIVATE (view);
 	view->priv->gdbus_bookview = NULL;
+	view->priv->direct_view = NULL;
 
 	view->priv->client = NULL;
 	view->priv->running = FALSE;
@@ -373,6 +431,14 @@ book_client_view_dispose (GObject *object)
 		}
 	}
 
+	if (view->priv->direct_view) {
+		g_signal_handlers_disconnect_matched (view->priv->direct_view, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, view);
+
+		e_data_book_view_delete (view->priv->direct_view);
+		g_object_unref (view->priv->direct_view);
+		view->priv->direct_view = NULL;
+	}
+
 	if (view->priv->client) {
 		g_object_unref (view->priv->client);
 		view->priv->client = NULL;



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