[evolution-data-server/openismus-work-master: 67/76] EDataBook: Handle D-Bus calls for creating cursors and export new cursors on the bus.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master: 67/76] EDataBook: Handle D-Bus calls for creating cursors and export new cursors on the bus.
- Date: Tue, 30 Jul 2013 21:40:02 +0000 (UTC)
commit 8a615c4bfb84b33411a67756acbcec169b60fa21
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Tue Jul 2 17:44:51 2013 +0900
EDataBook: Handle D-Bus calls for creating cursors and export new cursors on the bus.
addressbook/libedata-book/e-data-book.c | 183 +++++++++++++++++++++++++++++++
1 files changed, 183 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/libedata-book/e-data-book.c b/addressbook/libedata-book/e-data-book.c
index 9384fe1..fb254de 100644
--- a/addressbook/libedata-book/e-data-book.c
+++ b/addressbook/libedata-book/e-data-book.c
@@ -210,6 +210,18 @@ construct_bookview_path (void)
getpid (), counter);
}
+static gchar *
+construct_bookcursor_path (void)
+{
+ static volatile gint counter = 1;
+
+ g_atomic_int_inc (&counter);
+
+ return g_strdup_printf (
+ "/org/gnome/evolution/dataserver/AddressBookCursor/%d/%d",
+ getpid (), counter);
+}
+
static void
data_book_convert_to_client_error (GError *error)
{
@@ -1031,6 +1043,173 @@ data_book_handle_get_view_cb (EDBusAddressBook *interface,
}
static gboolean
+data_book_interpret_sort_keys (const gchar * const *in_sort_keys,
+ const gchar * const *in_sort_types,
+ EContactField **out_sort_keys,
+ EBookSortType **out_sort_types,
+ gint *n_fields,
+ GError **error)
+{
+ gint i, key_count = 0, type_count = 0;
+ EContactField *sort_keys;
+ EBookSortType *sort_types;
+ gboolean success = TRUE;
+
+ if (!in_sort_keys || !in_sort_types) {
+ g_set_error (error,
+ E_CLIENT_ERROR,
+ E_CLIENT_ERROR_INVALID_ARG,
+ "Missing sort keys while trying to create a Cursor");
+ return FALSE;
+ }
+
+ for (i = 0; in_sort_keys[i] != NULL; i++)
+ key_count++;
+ for (i = 0; in_sort_types[i] != NULL; i++)
+ type_count++;
+
+ if (key_count != type_count) {
+ g_set_error (error,
+ E_CLIENT_ERROR,
+ E_CLIENT_ERROR_INVALID_ARG,
+ "Must specify the same amount of sort keys as sort types while creating a
Cursor");
+ return FALSE;
+ }
+
+ sort_keys = g_new0 (EContactField, key_count);
+ sort_types = g_new0 (EBookSortType, type_count);
+
+ for (i = 0; success && i < key_count; i++) {
+
+ sort_keys[i] = e_contact_field_id (in_sort_keys[i]);
+
+ if (sort_keys[i] == 0) {
+ g_set_error (error,
+ E_CLIENT_ERROR,
+ E_CLIENT_ERROR_INVALID_ARG,
+ "Invalid sort key '%s' specified when creating a Cursor",
+ in_sort_keys[i]);
+ success = FALSE;
+ }
+ }
+
+ for (i = 0; success && i < type_count; i++) {
+ gint enum_value = 0;
+
+ if (!e_enum_from_string (E_TYPE_BOOK_SORT_TYPE,
+ in_sort_types[i],
+ &enum_value)) {
+ g_set_error (error,
+ E_CLIENT_ERROR,
+ E_CLIENT_ERROR_INVALID_ARG,
+ "Invalid sort type '%s' specified when creating a Cursor",
+ in_sort_types[i]);
+ success = FALSE;
+ }
+
+ sort_types[i] = enum_value;
+ }
+
+ if (!success) {
+ g_free (sort_keys);
+ g_free (sort_types);
+ } else {
+ *out_sort_keys = sort_keys;
+ *out_sort_types = sort_types;
+ *n_fields = key_count;
+ }
+
+ return success;
+}
+
+static gboolean
+data_book_handle_get_cursor_cb (EDBusAddressBook *interface,
+ GDBusMethodInvocation *invocation,
+ const gchar *in_query,
+ const gchar * const *in_sort_keys,
+ const gchar * const *in_sort_types,
+ EDataBook *data_book)
+{
+ EBookBackend *backend;
+ EDataBookCursor *cursor;
+ GDBusConnection *connection;
+ EContactField *sort_keys = NULL;
+ EBookSortType *sort_types = NULL;
+ gint n_fields = 0;
+ gchar *object_path;
+ GError *error = NULL;
+
+ backend = e_data_book_ref_backend (data_book);
+ g_return_val_if_fail (backend != NULL, FALSE);
+
+ /*
+ * Interpret arguments
+ */
+ if (!data_book_interpret_sort_keys (in_sort_keys,
+ in_sort_types,
+ &sort_keys,
+ &sort_types,
+ &n_fields,
+ &error)) {
+ g_dbus_method_invocation_take_error (invocation, error);
+ g_object_unref (backend);
+ return TRUE;
+ }
+
+ /*
+ * Create cursor
+ */
+ cursor = e_book_backend_create_cursor (backend,
+ sort_keys,
+ sort_types,
+ n_fields,
+ &error);
+ g_free (sort_keys);
+ g_free (sort_types);
+
+ if (!cursor) {
+ g_dbus_method_invocation_take_error (invocation, error);
+ g_object_unref (backend);
+ return TRUE;
+ }
+
+ /*
+ * Set the query, if any (no query is allowed)
+ */
+ if (!e_data_book_cursor_set_sexp (cursor, in_query, &error)) {
+
+ e_book_backend_delete_cursor (backend, cursor);
+ g_dbus_method_invocation_take_error (invocation, error);
+ g_object_unref (backend);
+ return TRUE;
+ }
+
+ object_path = construct_bookcursor_path ();
+ connection = g_dbus_method_invocation_get_connection (invocation);
+
+ /*
+ * Now export the object on the connection
+ */
+ if (!e_data_book_cursor_register_gdbus_object (cursor, connection, object_path, &error)) {
+ e_book_backend_delete_cursor (backend, cursor);
+ g_dbus_method_invocation_take_error (invocation, error);
+ g_object_unref (backend);
+ g_free (object_path);
+ return TRUE;
+ }
+
+ /*
+ * All is good in the hood, complete the method call
+ */
+ e_dbus_address_book_complete_get_cursor (interface,
+ invocation,
+ object_path);
+ g_free (object_path);
+ g_object_unref (backend);
+ return TRUE;
+}
+
+static gboolean
data_book_handle_close_cb (EDBusAddressBook *interface,
GDBusMethodInvocation *invocation,
EDataBook *data_book)
@@ -2013,6 +2192,10 @@ e_data_book_init (EDataBook *data_book)
G_CALLBACK (data_book_handle_get_view_cb),
data_book);
g_signal_connect (
+ dbus_interface, "handle-get-cursor",
+ G_CALLBACK (data_book_handle_get_cursor_cb),
+ data_book);
+ g_signal_connect (
dbus_interface, "handle-close",
G_CALLBACK (data_book_handle_close_cb),
data_book);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]