[evolution-data-server/email-factory] Add API to Search & Sort UIDS.
- From: Srinivasa Ragavan <sragavan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/email-factory] Add API to Search & Sort UIDS.
- Date: Wed, 11 May 2011 10:26:59 +0000 (UTC)
commit 3c6b9db2d9e441ca8fee2115a763e027c2270e3e
Author: Srinivasa Ragavan <sragavan gnome org>
Date: Wed May 11 15:53:58 2011 +0530
Add API to Search & Sort UIDS.
mail/daemon/e-mail-data-folder.c | 115 +++++++++++++++++++++++-
mail/daemon/e-mail-data-folder.xml | 6 ++
mail/libegdbus/e-gdbus-emailfolder.c | 166 ++++++++++++++++++++++++++++++++++
mail/libegdbus/e-gdbus-emailfolder.h | 36 ++++++++
4 files changed, 322 insertions(+), 1 deletions(-)
---
diff --git a/mail/daemon/e-mail-data-folder.c b/mail/daemon/e-mail-data-folder.c
index 39f30ae..b99079a 100644
--- a/mail/daemon/e-mail-data-folder.c
+++ b/mail/daemon/e-mail-data-folder.c
@@ -5,6 +5,7 @@
#include "e-mail-data-folder.h"
#include "e-mail-data-session.h"
#include "e-gdbus-emailfolder.h"
+#include "mail-send-recv.h"
#include <camel/camel.h>
#include "mail-ops.h"
#include "utils.h"
@@ -883,7 +884,7 @@ info_from_variant (CamelFolder *folder, GVariant *vinfo)
g_variant_iter_init (&aiter, item);
while ((aitem = g_variant_iter_next_value (&aiter))) {
- char *str = g_variant_get_string (aitem, NULL);
+ const char *str = g_variant_get_string (aitem, NULL);
if (str && *str)
camel_flag_set (&info->user_flags, str, TRUE);
}
@@ -1086,6 +1087,8 @@ typedef struct _email_folder_search_data {
EGdbusFolderCF *object;
GDBusMethodInvocation *invocation;
char *query;
+ char *sort;
+ gboolean ascending;
GPtrArray *query_uids;
GPtrArray *result_uids;
}EMailFolderSearchData;
@@ -1146,6 +1149,115 @@ impl_Mail_searchByExpression (EGdbusFolderCF *object, GDBusMethodInvocation *inv
return TRUE;
}
+struct _sort_data {
+ CamelFolder *folder;
+ char sort; /* u- subject, e- sender, r-datereceived */
+ gboolean ascending;
+};
+
+static gint
+compare_uids (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
+{
+ const gchar *uid1 = *(const gchar **) a;
+ const gchar *uid2 = *(const gchar **) b;
+ struct _sort_data *data = (struct _sort_data *) user_data;
+ CamelFolder *folder = data->folder;
+ CamelMessageInfoBase *info1, *info2;
+ gint ret=0;
+
+ info1 = (CamelMessageInfoBase *)camel_folder_get_message_info (folder, uid1);
+ info2 = (CamelMessageInfoBase *)camel_folder_get_message_info (folder, uid2);
+
+ if (data->sort == 'u') {
+ ret = g_strcmp0 (info1->subject, info2->subject);
+ } else if (data->sort == 'e') {
+ ret = g_strcmp0 (info1->from, info2->from);
+ } else if (data->sort == 'r') {
+ ret = info1->date_received - info2->date_received;
+ }
+
+ if (!data->ascending)
+ ret = -ret;
+
+ camel_message_info_free (info1);
+ camel_message_info_free (info2);
+
+ return ret;
+}
+
+static gboolean
+search_sort_expr_operate (CamelFolder *folder, gpointer sdata, GError **error)
+{
+ EMailFolderSearchData *data = (EMailFolderSearchData *)sdata;
+ struct _sort_data *sort = g_new0(struct _sort_data, 1);
+
+ sort->folder = folder;
+ if (g_strcmp0 (data->sort, "subject") == 0)
+ sort->sort = 'u';
+ else if (g_strcmp0 (data->sort, "sender") == 0)
+ sort->sort = 'e';
+ else /* Date received*/
+ sort->sort = 'r';
+
+ sort->ascending = data->ascending;
+
+ data->result_uids = camel_folder_search_by_expression (folder, data->query, error);
+ g_qsort_with_data (data->result_uids->pdata, data->result_uids->len, sizeof (gpointer), compare_uids, sort);
+ g_free (sort);
+
+ return TRUE;
+}
+
+static void
+search_sort_expr_done (gboolean success, gpointer sdata, GError *error)
+{
+ EMailFolderSearchData *data = (EMailFolderSearchData *)sdata;
+ EMailDataFolderPrivate *priv = DATA_FOLDER_PRIVATE(data->mfolder);
+
+ g_ptr_array_add (data->result_uids, NULL);
+
+ if (error && error->message) {
+ g_warning ("Search Sort by expr failed: %s: %s\n", priv->path, error->message);
+ g_dbus_method_invocation_return_gerror (data->invocation, error);
+ ipc(printf("Search Sort by expr : %s failed: %s\n", priv->path, error->message));
+ return;
+ }
+
+ egdbus_folder_cf_complete_search_sort_by_expression (data->object, data->invocation, (const gchar *const *)data->result_uids->pdata);
+
+ g_ptr_array_remove_index_fast (data->result_uids, data->result_uids->len-1);
+ ipc(printf("Search Sort messages by expr: %s success: %d results\n", priv->path, data->result_uids->len));
+
+ camel_folder_search_free (priv->folder, data->result_uids);
+ g_free (data->query);
+ g_free (data->sort);
+ g_free (data);
+}
+
+static gboolean
+impl_Mail_searchSortByExpression (EGdbusFolderCF *object, GDBusMethodInvocation *invocation, const char *expression, const char *sort, gboolean ascending, EMailDataFolder *mfolder)
+{
+ EMailDataFolderPrivate *priv = DATA_FOLDER_PRIVATE(mfolder);
+ EMailFolderSearchData *data;
+
+
+ data = g_new0 (EMailFolderSearchData, 1);
+ data->object = object;
+ data->mfolder = mfolder;
+ data->invocation = invocation;
+ data->query = g_strdup (expression);
+ data->sort = g_strdup (sort);
+ data->ascending = ascending;
+ ipc(printf("Search Sort by expr : %s : %s: %s: %d\n", priv->path, expression, sort, ascending));
+
+ mail_operate_on_folder (priv->folder, search_sort_expr_operate, search_sort_expr_done, data);
+
+
+ return TRUE;
+}
+
/* Search by UIDs */
static gboolean
search_uids_operate (CamelFolder *folder, gpointer sdata, GError **error)
@@ -1540,6 +1652,7 @@ e_mail_data_folder_init (EMailDataFolder *self)
g_signal_connect (priv->gdbus_object, "handle-get-uids", G_CALLBACK (impl_Mail_getUids), self);
g_signal_connect (priv->gdbus_object, "handle-get-message", G_CALLBACK (impl_Mail_getMessage), self);
g_signal_connect (priv->gdbus_object, "handle-search-by-expression", G_CALLBACK (impl_Mail_searchByExpression), self);
+ g_signal_connect (priv->gdbus_object, "handle-search-sort-by-expression", G_CALLBACK (impl_Mail_searchSortByExpression), self);
g_signal_connect (priv->gdbus_object, "handle-search-by-uids", G_CALLBACK (impl_Mail_searchByUids), self);
g_signal_connect (priv->gdbus_object, "handle-get-message-info", G_CALLBACK (impl_Mail_getMessageInfo), self);
g_signal_connect (priv->gdbus_object, "handle-transfer-messages-to", G_CALLBACK (impl_Mail_transferMessagesTo), self);
diff --git a/mail/daemon/e-mail-data-folder.xml b/mail/daemon/e-mail-data-folder.xml
index 93d30f6..1161eaf 100644
--- a/mail/daemon/e-mail-data-folder.xml
+++ b/mail/daemon/e-mail-data-folder.xml
@@ -134,6 +134,12 @@
<arg name="expression" type="s" direction="in"/>
<arg name="uids" type="as" direction="out"/>
</method>
+ <method name="searchSortByExpression">
+ <arg name="expression" type="s" direction="in"/>
+ <arg name="sort" type="s" direction="in"/>
+ <arg name="ascending" type="b" direction="in"/>
+ <arg name="uids" type="as" direction="out"/>
+ </method>
<method name="searchByUids">
<arg name="expression" type="s" direction="in"/>
<arg name="searchuids" type="as" direction="in"/>
diff --git a/mail/libegdbus/e-gdbus-emailfolder.c b/mail/libegdbus/e-gdbus-emailfolder.c
index 8672290..4bf8c55 100644
--- a/mail/libegdbus/e-gdbus-emailfolder.c
+++ b/mail/libegdbus/e-gdbus-emailfolder.c
@@ -1331,6 +1331,76 @@ static const _ExtendedGDBusMethodInfo _egdbus_folder_cf_method_info_search_by_ex
"handle-search-by-expression"
};
+static const _ExtendedGDBusArgInfo _egdbus_folder_cf_method_info_search_sort_by_expression_IN_ARG_expression =
+{
+ {
+ -1,
+ "expression",
+ "s",
+ NULL
+ },
+ FALSE
+};
+
+static const _ExtendedGDBusArgInfo _egdbus_folder_cf_method_info_search_sort_by_expression_IN_ARG_sort =
+{
+ {
+ -1,
+ "sort",
+ "s",
+ NULL
+ },
+ FALSE
+};
+
+static const _ExtendedGDBusArgInfo _egdbus_folder_cf_method_info_search_sort_by_expression_IN_ARG_ascending =
+{
+ {
+ -1,
+ "ascending",
+ "b",
+ NULL
+ },
+ FALSE
+};
+
+static const _ExtendedGDBusArgInfo * const _egdbus_folder_cf_method_info_search_sort_by_expression_IN_ARG_pointers[] =
+{
+ &_egdbus_folder_cf_method_info_search_sort_by_expression_IN_ARG_expression,
+ &_egdbus_folder_cf_method_info_search_sort_by_expression_IN_ARG_sort,
+ &_egdbus_folder_cf_method_info_search_sort_by_expression_IN_ARG_ascending,
+ NULL
+};
+
+static const _ExtendedGDBusArgInfo _egdbus_folder_cf_method_info_search_sort_by_expression_OUT_ARG_uids =
+{
+ {
+ -1,
+ "uids",
+ "as",
+ NULL
+ },
+ FALSE
+};
+
+static const _ExtendedGDBusArgInfo * const _egdbus_folder_cf_method_info_search_sort_by_expression_OUT_ARG_pointers[] =
+{
+ &_egdbus_folder_cf_method_info_search_sort_by_expression_OUT_ARG_uids,
+ NULL
+};
+
+static const _ExtendedGDBusMethodInfo _egdbus_folder_cf_method_info_search_sort_by_expression =
+{
+ {
+ -1,
+ "searchSortByExpression",
+ (GDBusArgInfo **) &_egdbus_folder_cf_method_info_search_sort_by_expression_IN_ARG_pointers,
+ (GDBusArgInfo **) &_egdbus_folder_cf_method_info_search_sort_by_expression_OUT_ARG_pointers,
+ NULL
+ },
+ "handle-search-sort-by-expression"
+};
+
static const _ExtendedGDBusArgInfo _egdbus_folder_cf_method_info_search_by_uids_IN_ARG_expression =
{
{
@@ -1559,6 +1629,7 @@ static const _ExtendedGDBusMethodInfo * const _egdbus_folder_cf_method_info_poin
&_egdbus_folder_cf_method_info_get_uids,
&_egdbus_folder_cf_method_info_get_message,
&_egdbus_folder_cf_method_info_search_by_expression,
+ &_egdbus_folder_cf_method_info_search_sort_by_expression,
&_egdbus_folder_cf_method_info_search_by_uids,
&_egdbus_folder_cf_method_info_get_message_info,
&_egdbus_folder_cf_method_info_transfer_messages_to,
@@ -1959,6 +2030,17 @@ egdbus_folder_cf_default_init (EGdbusFolderCFIface *iface)
2,
G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING);
+ g_signal_new ("handle-search-sort-by-expression",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EGdbusFolderCFIface, handle_search_sort_by_expression),
+ g_signal_accumulator_true_handled,
+ NULL,
+ _cclosure_marshal_generic,
+ G_TYPE_BOOLEAN,
+ 4,
+ G_TYPE_DBUS_METHOD_INVOCATION, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
+
g_signal_new ("handle-search-by-uids",
G_TYPE_FROM_INTERFACE (iface),
G_SIGNAL_RUN_LAST,
@@ -3691,6 +3773,79 @@ _out:
}
void
+egdbus_folder_cf_call_search_sort_by_expression (
+ EGdbusFolderCF *proxy,
+ const gchar *expression,
+ const gchar *sort,
+ gboolean ascending,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_dbus_proxy_call (G_DBUS_PROXY (proxy),
+ "searchSortByExpression",
+ g_variant_new ("(ssb)",
+ expression,
+ sort,
+ ascending),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
+}
+
+gboolean
+egdbus_folder_cf_call_search_sort_by_expression_finish (
+ EGdbusFolderCF *proxy,
+ gchar ***out_uids,
+ GAsyncResult *res,
+ GError **error)
+{
+ GVariant *_ret;
+ _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);
+ if (_ret == NULL)
+ goto _out;
+ g_variant_get (_ret,
+ "(^as)",
+ out_uids);
+ g_variant_unref (_ret);
+_out:
+ return _ret != NULL;
+}
+
+gboolean
+egdbus_folder_cf_call_search_sort_by_expression_sync (
+ EGdbusFolderCF *proxy,
+ const gchar *expression,
+ const gchar *sort,
+ gboolean ascending,
+ gchar ***out_uids,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GVariant *_ret;
+ _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),
+ "searchSortByExpression",
+ g_variant_new ("(ssb)",
+ expression,
+ sort,
+ ascending),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ error);
+ if (_ret == NULL)
+ goto _out;
+ g_variant_get (_ret,
+ "(^as)",
+ out_uids);
+ g_variant_unref (_ret);
+_out:
+ return _ret != NULL;
+}
+
+void
egdbus_folder_cf_call_search_by_uids (
EGdbusFolderCF *proxy,
const gchar *expression,
@@ -4233,6 +4388,17 @@ egdbus_folder_cf_complete_search_by_expression (
}
void
+egdbus_folder_cf_complete_search_sort_by_expression (
+ EGdbusFolderCF *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *const *uids)
+{
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(^as)",
+ uids));
+}
+
+void
egdbus_folder_cf_complete_search_by_uids (
EGdbusFolderCF *object,
GDBusMethodInvocation *invocation,
diff --git a/mail/libegdbus/e-gdbus-emailfolder.h b/mail/libegdbus/e-gdbus-emailfolder.h
index a573654..fe9548d 100644
--- a/mail/libegdbus/e-gdbus-emailfolder.h
+++ b/mail/libegdbus/e-gdbus-emailfolder.h
@@ -159,6 +159,13 @@ struct _EGdbusFolderCFIface
GDBusMethodInvocation *invocation,
const gchar *expression);
+ gboolean (*handle_search_sort_by_expression) (
+ EGdbusFolderCF *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *expression,
+ const gchar *sort,
+ gboolean ascending);
+
gboolean (*handle_search_by_uids) (
EGdbusFolderCF *object,
GDBusMethodInvocation *invocation,
@@ -324,6 +331,11 @@ void egdbus_folder_cf_complete_search_by_expression (
GDBusMethodInvocation *invocation,
const gchar *const *uids);
+void egdbus_folder_cf_complete_search_sort_by_expression (
+ EGdbusFolderCF *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *const *uids);
+
void egdbus_folder_cf_complete_search_by_uids (
EGdbusFolderCF *object,
GDBusMethodInvocation *invocation,
@@ -860,6 +872,30 @@ gboolean egdbus_folder_cf_call_search_by_expression_sync (
GCancellable *cancellable,
GError **error);
+void egdbus_folder_cf_call_search_sort_by_expression (
+ EGdbusFolderCF *proxy,
+ const gchar *expression,
+ const gchar *sort,
+ gboolean ascending,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean egdbus_folder_cf_call_search_sort_by_expression_finish (
+ EGdbusFolderCF *proxy,
+ gchar ***out_uids,
+ GAsyncResult *res,
+ GError **error);
+
+gboolean egdbus_folder_cf_call_search_sort_by_expression_sync (
+ EGdbusFolderCF *proxy,
+ const gchar *expression,
+ const gchar *sort,
+ gboolean ascending,
+ gchar ***out_uids,
+ GCancellable *cancellable,
+ GError **error);
+
void egdbus_folder_cf_call_search_by_uids (
EGdbusFolderCF *proxy,
const gchar *expression,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]