[evolution-patches] groupwise filter class



Attached is the patch which has implementation for e-gw-filter class,
using which one can conveniently prepare and append groupwise filters to
soap message, to get items which match particular criteria like where
email contains the word smith etc.

Thanks,
Sivaiah
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/groupwise/ChangeLog,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 ChangeLog
--- ChangeLog	20 Feb 2004 14:57:57 -0000	1.4.2.1
+++ ChangeLog	9 Mar 2004 07:17:58 -0000
@@ -1,3 +1,8 @@
+2004-03-09 Sivaiah Nallagatla <snallagatla novell com>
+	
+	* e-gw-filter[.ch] : new class to handle gw filters used to query item which meet 
+	a set of criteria 
+
 2004-02-20 Sivaiah Nallagatla <snallagatla novell com>
 
 	* e-gw-container.[ch] (e_gw_container_get_is_writable)
--- e-gw-filter.h.orig	2004-03-09 12:39:46.000000000 +0530
+++ e-gw-filter.h	2004-03-08 18:41:22.000000000 +0530
@@ -0,0 +1,79 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* 
+ * Authors : 
+ * Sivaiah Nallagatla <snallagatla novell com> 
+ * 
+ *
+ * Copyright 2003, Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or 
+ * modify it under the terms of version 2 of the GNU General Public 
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef E_GW_FILTER_H
+#define E_GW_FILTER_H
+
+
+#include <libsoup/soup-soap-message.h>
+#include <libsoup/soup-soap-response.h>
+
+G_BEGIN_DECLS
+
+#define E_TYPE_GW_FILTER           (e_gw_filter_get_type ())
+#define E_GW_FILTER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_GW_FILTER, EGwFilter))
+#define E_GW_FILTER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_GW_FILTER, EGwFilterClass))
+#define E_IS_GW_FILTER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_GW_FILTER))
+#define E_IS_GW_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_GW_FILTER))
+
+typedef struct _EGwFilter        EGwFilter;
+typedef struct _EGwFilterClass   EGwFilterClass;
+typedef struct _EGwFilterPrivate EGwFilterPrivate;
+
+
+typedef enum {
+  E_GW_FILTER_OP_AND,
+  E_GW_FILTER_OP_OR,
+  E_GW_FILTER_OP_NOT,
+  E_GW_FILTER_OP_EQUAL,
+  E_GW_FILTER_OP_NOTEQUAL,
+  E_GW_FILTER_OP_GREATERTHAN,
+  E_GW_FILTER_OP_LESSTHAN,
+  E_GW_FILTER_OP_GREATERTHAN_OR_EQUAL,
+  E_GW_FILTER_OP_LESSTHAN_OR_EQUAL,
+  E_GW_FILTER_OP_CONTAINS,
+  E_GW_FILTER_OP_CONTAINSWORD,
+  E_GW_FILTER_OP_BEGINS,
+  E_GW_FILTER_OP_EXISTS,
+  E_GW_FILTER_OP_NOTEXISTS
+	
+} EGwFilterOpType;
+
+struct _EGwFilter {
+  GObject parent;
+  EGwFilterPrivate *priv;
+};
+
+struct _EGwFilterClass {
+  GObjectClass parent_class;
+};
+
+GType       e_gw_filter_get_type (void);
+EGwFilter*  e_gw_filter_new(void);
+void        e_gw_filter_group_type (EGwFilter *filter, int all_or_any);
+void        e_gw_filter_add_filter_element (EGwFilter *filter, EGwFilterOpType operation, const char *field_name, const char *field_value);
+void        e_gw_filter_append_to_soap_message (EGwFilter *filter, SoupSoapMessage *msg);
+
+G_END_DECLS
+
+#endif
--- e-gw-filter.c.orig	2004-03-09 12:39:49.000000000 +0530
+++ e-gw-filter.c	2004-03-09 12:25:24.000000000 +0530
@@ -0,0 +1,236 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* 
+ * Authors : 
+ * Sivaiah Nallagatla <snallagatla novell com> 
+ * 
+ *
+ * Copyright 2003, Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or 
+ * modify it under the terms of version 2 of the GNU General Public 
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "e-gw-filter.h"
+#include "e-gw-message.h"
+
+static GObjectClass *parent_class = NULL;
+
+struct _FilterElement {
+  int operation;
+  char *field_name;
+  char *field_value;
+};
+
+typedef struct _FilterElement  FilterElement;
+
+struct _EGwFilterPrivate {
+  GSList *element_list;
+  int  filter_group_type; /* stores, whether all condtions are to be met or any one of them*/
+  
+};
+
+
+
+void 
+e_gw_filter_group_type (EGwFilter *filter, int all_or_any)
+{
+  g_return_if_fail (E_IS_GW_FILTER (filter));
+  filter->priv->filter_group_type = all_or_any;
+}
+
+void
+e_gw_filter_add_filter_element (EGwFilter *filter, EGwFilterOpType operation, const char *field_name, const char *field_value)
+{
+  FilterElement *element;
+  
+  g_return_if_fail (E_IS_GW_FILTER (filter));
+  g_return_if_fail (field_name != NULL);
+  g_return_if_fail (field_value != NULL);
+  
+  element = g_new0 (FilterElement, 1);
+  element->operation = operation;
+  element->field_name = g_strdup (field_name);
+  element->field_value = g_strdup (field_value);
+  
+  filter->priv->element_list = g_slist_append (filter->priv->element_list, element);
+
+}
+
+void 
+e_gw_filter_append_to_soap_message (EGwFilter *filter, SoupSoapMessage *msg)
+{
+  g_return_if_fail (E_IS_GW_FILTER (filter));
+  g_return_if_fail (SOUP_IS_SOAP_MESSAGE (msg));
+  EGwFilterPrivate *priv;
+  GSList *element_list;
+  char *operation_name;
+  
+  FilterElement *filter_element;
+   
+  priv = filter->priv;
+  element_list = priv->element_list;
+   
+  soup_soap_message_start_element (msg, "filter", NULL, NULL);
+  
+  if (g_slist_length(element_list) > 1) {
+    soup_soap_message_start_element (msg, "element", NULL, NULL);
+    if (priv->filter_group_type == E_GW_FILTER_OP_AND)
+      e_gw_message_write_string_parameter (msg, "op", NULL, "and");
+    else 
+      e_gw_message_write_string_parameter (msg, "op", NULL, "or");
+  }
+   
+  for (; element_list != NULL; element_list = g_slist_next (element_list)) {
+    soup_soap_message_start_element (msg, "element", NULL, NULL);
+    filter_element = (FilterElement *)element_list->data;
+    operation_name = NULL;
+  
+    switch (filter_element->operation) {
+    
+    case E_GW_FILTER_OP_EQUAL :
+      operation_name = "eq";
+      break;
+    case E_GW_FILTER_OP_NOTEQUAL :
+      operation_name = "ne";
+      break;
+    case E_GW_FILTER_OP_GREATERTHAN :
+      operation_name = "gt";
+      break;
+    case E_GW_FILTER_OP_LESSTHAN :
+      operation_name = "lt";
+      break;
+    case E_GW_FILTER_OP_GREATERTHAN_OR_EQUAL :
+      operation_name = "gte";
+      break;
+    case E_GW_FILTER_OP_LESSTHAN_OR_EQUAL :
+      operation_name = "lte";
+      break;
+    case E_GW_FILTER_OP_CONTAINS :
+      operation_name = "contains";
+      break;
+    case E_GW_FILTER_OP_CONTAINSWORD :
+      operation_name = "containsWord";
+      break;
+    case E_GW_FILTER_OP_BEGINS :
+      operation_name = "begins";
+      break;
+    case E_GW_FILTER_OP_EXISTS :
+      operation_name = "exists";
+      break;
+    case E_GW_FILTER_OP_NOTEXISTS :
+      operation_name = "notExist";
+      break;
+       
+       
+    }
+   
+    if (operation_name != NULL) {
+      e_gw_message_write_string_parameter (msg, "op", NULL, operation_name);
+      e_gw_message_write_string_parameter (msg, "field", NULL, filter_element->field_name);
+      e_gw_message_write_string_parameter (msg, "value", NULL, filter_element->field_value);
+    }
+    soup_soap_message_end_element (msg);
+  }
+  if (g_slist_length (element_list) > 1) 
+    soup_soap_message_end_element (msg);
+
+  soup_soap_message_end_element (msg); //end filter
+    
+}
+
+static void
+e_gw_filter_finalize (GObject *object)
+{
+  EGwFilter *filter;
+  EGwFilterPrivate *priv;
+  GSList *filter_elements;
+  FilterElement *element;
+
+  filter = E_GW_FILTER (object);
+  priv = filter->priv;
+  filter_elements = priv->element_list;
+  for (; filter_elements != NULL; filter_elements = filter_elements = g_slist_next (filter_elements)) {
+    element = filter_elements->data;
+    g_free (element->field_name);
+    g_free (element->field_value);
+    g_free (filter_elements->data);
+  }
+
+  g_slist_free (priv->element_list);
+  g_free (priv);
+  filter->priv = NULL;
+  if (parent_class->finalize)
+    (* parent_class->finalize) (object);
+}
+
+static void 
+e_gw_filter_dispose (GObject *object)
+{
+  
+  if (parent_class->dispose)
+    (* parent_class->dispose) (object);
+
+}
+
+static void
+e_gw_filter_init (EGwFilter *filter, EGwFilterClass *klass)
+{
+  EGwFilterPrivate *priv;
+  priv = g_new0(EGwFilterPrivate, 1);
+  priv->filter_group_type = E_GW_FILTER_OP_AND; /*by default all condtions are to be met*/
+  priv->element_list = NULL;
+  filter->priv = priv;
+}
+
+
+static void
+e_gw_filter_class_init (EGwFilterClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  parent_class = g_type_class_peek_parent (klass);
+  object_class->dispose = e_gw_filter_dispose;
+  object_class->finalize = e_gw_filter_finalize;
+}
+
+GType
+e_gw_filter_get_type (void)
+{
+  static GType type = 0;
+  
+  if (!type) {
+    static GTypeInfo info = {
+      sizeof (EGwFilterClass),
+      (GBaseInitFunc) NULL,
+      (GBaseFinalizeFunc) NULL,
+      (GClassInitFunc) e_gw_filter_class_init,
+      NULL, NULL,
+      sizeof (EGwFilter),
+      0,
+      (GInstanceInitFunc) e_gw_filter_init
+    };
+    type = g_type_register_static (G_TYPE_OBJECT, "EGwFilter", &info, 0);
+  }
+
+  return type;
+}
+
+EGwFilter *
+e_gw_filter_new (void)
+{
+  return g_object_new (E_TYPE_GW_FILTER, NULL);
+}


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