evolution r36863 - in trunk: e-util filter mail



Author: mcrha
Date: Wed Dec 10 11:05:01 2008
New Revision: 36863
URL: http://svn.gnome.org/viewvc/evolution?rev=36863&view=rev

Log:
2008-12-10  Milan Crha  <mcrha redhat com>

	** Fix for bug #563870

	* e-util/e-util-labels.h: (e_util_labels_get_filter_options):
	* e-util/e-util-labels.c: (e_util_labels_get_filter_options):
	New helper function to be used in FilterOption.

	* filter/Makefile.am:
	* filter/filter-label.h:
	* filter/filter-label.c: Drop, not used anywhere.
	* filter/filter-element.c:
	* filter/rule-context.c: Remove dropped include and code.

	* filter/filter-option.c: (get_dynamic_options), (xml_create), (get_widget):
	Evaluate dynamic options even on create, to have them available for
	saved searches even before the widget itself is shown.

	* mail/vfoldertypes.xml:
	* mail/filtertypes.xml:
	* mail/searchtypes.xml: Use dynamic filter option.
	* mail/message-list.c: Drop unused header include.



Removed:
   trunk/filter/filter-label.c
   trunk/filter/filter-label.h
Modified:
   trunk/e-util/ChangeLog
   trunk/e-util/e-util-labels.c
   trunk/e-util/e-util-labels.h
   trunk/filter/ChangeLog
   trunk/filter/Makefile.am
   trunk/filter/filter-element.c
   trunk/filter/filter-option.c
   trunk/filter/rule-context.c
   trunk/mail/ChangeLog
   trunk/mail/em-filter-i18n.h
   trunk/mail/filtertypes.xml
   trunk/mail/message-list.c
   trunk/mail/searchtypes.xml
   trunk/mail/vfoldertypes.xml

Modified: trunk/e-util/e-util-labels.c
==============================================================================
--- trunk/e-util/e-util-labels.c	(original)
+++ trunk/e-util/e-util-labels.c	Wed Dec 10 11:05:01 2008
@@ -29,8 +29,10 @@
 
 #include <camel/camel-utf8.h>
 
+#include "e-util.h"
 #include "e-util-labels.h"
 #include "e-dialog-utils.h"
+#include "filter/filter-option.h"
 
 /* Note, the first element of each EUtilLabel must NOT be translated */
 EUtilLabel label_defaults[LABEL_DEFAULTS_NUM] = {
@@ -543,3 +545,38 @@
 
 	return label->colour;
 }
+
+/**
+ * e_util_labels_get_filter_options:
+ * Returns list of newly allocated struct _filter_option-s, to be used in filters.
+ **/
+GSList *
+e_util_labels_get_filter_options (void)
+{
+	GSList *known = e_util_labels_parse (NULL), *l;
+	GSList *res = NULL;
+
+	for (l = known; l; l = l->next) {
+		EUtilLabel *label = l->data;
+		const char *tag;
+		struct _filter_option *fo;
+
+		if (!label)
+			continue;
+
+		tag = label->tag;
+
+		if (tag && strncmp (tag, "$Label", 6) == 0)
+			tag += 6;
+
+		fo = g_new0 (struct _filter_option, 1);
+		fo->title = e_str_without_underscores (label->name);
+		fo->value = g_strdup (tag);
+
+		res = g_slist_prepend (res, fo);
+	}
+
+	e_util_labels_free (known);
+
+	return g_slist_reverse (res);
+}

Modified: trunk/e-util/e-util-labels.h
==============================================================================
--- trunk/e-util/e-util-labels.h	(original)
+++ trunk/e-util/e-util-labels.h	Wed Dec 10 11:05:01 2008
@@ -52,4 +52,6 @@
 gboolean    e_util_labels_get_color     (GSList *labels, const char *tag, GdkColor *color);
 const char *e_util_labels_get_color_str (GSList *labels, const char *tag);
 
+GSList *    e_util_labels_get_filter_options (void);
+
 #endif /* _E_UTIL_LABELS_H */

Modified: trunk/filter/Makefile.am
==============================================================================
--- trunk/filter/Makefile.am	(original)
+++ trunk/filter/Makefile.am	Wed Dec 10 11:05:01 2008
@@ -27,8 +27,6 @@
 	filter-input.h				\
 	filter-int.c				\
 	filter-int.h				\
-	filter-label.c				\
-	filter-label.h				\
 	filter-marshal.c			\
 	filter-marshal.h			\
 	filter-option.c				\

Modified: trunk/filter/filter-element.c
==============================================================================
--- trunk/filter/filter-element.c	(original)
+++ trunk/filter/filter-element.c	Wed Dec 10 11:05:01 2008
@@ -279,7 +279,6 @@
 #include "filter-datespec.h"
 #include "filter-int.h"
 #include "filter-file.h"
-#include "filter-label.h"
 
 static void
 copy_value(FilterElement *de, FilterElement *se)

Modified: trunk/filter/filter-option.c
==============================================================================
--- trunk/filter/filter-option.c	(original)
+++ trunk/filter/filter-option.c	Wed Dec 10 11:05:01 2008
@@ -45,6 +45,7 @@
 static GtkWidget *get_widget (FilterElement *fe);
 static void build_code (FilterElement *fe, GString *out, struct _FilterPart *ff);
 static void format_sexp (FilterElement *, GString *);
+static GSList *get_dynamic_options (FilterOption *fo);
 
 static void filter_option_class_init (FilterOptionClass *klass);
 static void filter_option_init (FilterOption *fo);
@@ -275,10 +276,23 @@
 
 				fn = xmlGetProp (n, (const unsigned char *)"func");
 				if (fn && *fn) {
+					GSList *items, *i;
+					struct _filter_option *op;
+
 					fo->dynamic_func = g_strdup ((const char *)fn);
 
-					/* to remember where to place them */
-					filter_option_add (fo, "fake_dynamic", "fake_dynamic", NULL, TRUE);
+					/* get options now, to have them available when reading saved rules */
+					items = get_dynamic_options (fo);
+					for (i = items; i; i = i->next) {
+						op = i->data;
+
+						if (op) {
+							filter_option_add (fo, op->value, op->title, op->code, TRUE);
+							free_option (op, NULL);
+						}
+					}
+
+					g_slist_free (items);
 				} else {
 					g_warning ("Missing 'func' attribute within '%s' node in optionlist '%s'", n->name, fe->name);
 				}
@@ -335,6 +349,30 @@
 	fo->current = g_object_get_data ((GObject *) widget, "option");
 }
 
+static GSList *
+get_dynamic_options (FilterOption *fo)
+{
+	void *module;
+	GSList *(*get_func)(void);
+	GSList *res = NULL;
+
+	if (!fo || !fo->dynamic_func)
+		return res;
+
+	module = dlopen (NULL, RTLD_LAZY);
+
+	get_func = dlsym (module, fo->dynamic_func);
+	if (get_func) {
+		res = get_func ();
+	} else {
+		g_warning ("optionlist dynamic fill function '%s' not found", fo->dynamic_func);
+	}
+
+	dlclose (module);
+
+	return res;
+}
+
 static GtkWidget *
 get_widget (FilterElement *fe)
 {
@@ -349,10 +387,9 @@
 
 	if (fo->dynamic_func) {
 		/* it is dynamically filled, thus remove all dynamics and put there the fresh ones */
+		GSList *items, *i;
 		GList *old_ops;
 		struct _filter_option *old_cur;
-		void *module;
-		GSList *(*get_func)(void);
 
 		old_ops = fo->options;
 		old_cur = fo->current;
@@ -372,27 +409,17 @@
 			}
 		}
 
-		module = dlopen (NULL, RTLD_LAZY);
-
-		get_func = dlsym (module, fo->dynamic_func);
-		if (get_func) {
-			GSList *items, *i;
-
-			items = get_func ();
-			for (i = items; i; i = i->next) {
-				op = i->data;
-
-				if (op) {
-					filter_option_add (fo, op->value, op->title, op->code, TRUE);
-					free_option (op, NULL);
-				}
+		items = get_dynamic_options (fo);
+		for (i = items; i; i = i->next) {
+			op = i->data;
+
+			if (op) {
+				filter_option_add (fo, op->value, op->title, op->code, TRUE);
+				free_option (op, NULL);
 			}
+		}
 
-			g_slist_free (items);
-		} else
-			g_warning ("optionlist dynamic fill function '%s' not found", fo->dynamic_func);
-
-		dlclose (module);
+		g_slist_free (items);
 
 		/* maybe some static left after those dynamic, add them too */
 		for (; l; l = l->next) {

Modified: trunk/filter/rule-context.c
==============================================================================
--- trunk/filter/rule-context.c	(original)
+++ trunk/filter/rule-context.c	Wed Dec 10 11:05:01 2008
@@ -48,7 +48,6 @@
 #include "filter-file.h"
 #include "filter-input.h"
 #include "filter-int.h"
-#include "filter-label.h"
 #include "filter-marshal.h"
 #include "filter-option.h"
 #include "filter-rule.h"
@@ -922,8 +921,6 @@
 		return (FilterElement *) filter_int_new ();
 	} else if (!strcmp (type, "regex")) {
 		return (FilterElement *) filter_input_new_type_name (type);
-	} else if (!strcmp (type, "label")) {
-		return (FilterElement *) filter_label_new ();
 	}else if (!strcmp(type, "completedpercent")) {
                  return (FilterElement *) filter_int_new_type("completedpercent", 0,100);
 

Modified: trunk/mail/em-filter-i18n.h
==============================================================================
--- trunk/mail/em-filter-i18n.h	(original)
+++ trunk/mail/em-filter-i18n.h	Wed Dec 10 11:05:01 2008
@@ -1,19 +1,3 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) version 3.
- *
- * 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with the program; if not, see <http://www.gnu.org/licenses/>  
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- */
 /* Automatically generated. Do not edit. */
 char *s = N_("Adjust Score");
 char *s = N_("Assign Color");
@@ -65,7 +49,6 @@
 char *s = N_("Move to Folder");
 char *s = N_("Pipe to Program");
 char *s = N_("Play Sound");
-/* Translators: "Read" as in "has been read" (em-filter-i18n.h) */
 char *s = N_("Read");
 char *s = N_("Recipients");
 char *s = N_("Regex Match");
@@ -76,6 +59,7 @@
 char *s = N_("Run Program");
 char *s = N_("Score");
 char *s = N_("Sender");
+char *s = N_("Sender or Recipients");
 char *s = N_("Set Label");
 char *s = N_("Set Status");
 char *s = N_("Size (kB)");

Modified: trunk/mail/filtertypes.xml
==============================================================================
--- trunk/mail/filtertypes.xml	(original)
+++ trunk/mail/filtertypes.xml	Wed Dec 10 11:05:01 2008
@@ -635,7 +635,9 @@
     </code>
    </option>
   </input>
-  <input type="label" name="versus"/>
+  <input type="optionlist" name="versus">
+     <dynamic func="e_util_labels_get_filter_options"/>
+  </input>
  </part>
 
  <part name="score">
@@ -920,7 +922,9 @@
  <part name="label">
   <title>Set Label</title>
   <code>(set-label ${label})</code>
-  <input type="label" name="label"/>
+  <input type="optionlist" name="label">
+     <dynamic func="e_util_labels_get_filter_options"/>
+  </input>
  </part>
  <part name="colour">
   <title>Assign Color</title>

Modified: trunk/mail/message-list.c
==============================================================================
--- trunk/mail/message-list.c	(original)
+++ trunk/mail/message-list.c	Wed Dec 10 11:05:01 2008
@@ -66,8 +66,6 @@
 #include "table/e-cell-vbox.h"
 #include "table/e-cell-hbox.h"
 
-#include "filter/filter-label.h"
-
 #include "em-popup.h"
 #include "em-utils.h"
 #include "mail-config.h"

Modified: trunk/mail/searchtypes.xml
==============================================================================
--- trunk/mail/searchtypes.xml	(original)
+++ trunk/mail/searchtypes.xml	Wed Dec 10 11:05:01 2008
@@ -270,7 +270,9 @@
     </code>
    </option>
   </input>
-  <input type="label" name="versus"/>
+  <input type="optionlist" name="versus">
+     <dynamic func="e_util_labels_get_filter_options"/>
+  </input>
  </part>
 
  <part name="score">

Modified: trunk/mail/vfoldertypes.xml
==============================================================================
--- trunk/mail/vfoldertypes.xml	(original)
+++ trunk/mail/vfoldertypes.xml	Wed Dec 10 11:05:01 2008
@@ -353,7 +353,9 @@
     </code>
    </option>
   </input>
-  <input type="label" name="versus"/>
+  <input type="optionlist" name="versus">
+     <dynamic func="e_util_labels_get_filter_options"/>
+  </input>
  </part>
 
  <part name="score">



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