aboutsummaryrefslogtreecommitdiffstats
path: root/filter
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2008-12-10 19:05:01 +0800
committerMilan Crha <mcrha@src.gnome.org>2008-12-10 19:05:01 +0800
commit65145381a69be1ac144c6e6dc7c2ab3fdb05d3b7 (patch)
tree6464b3307de194cd3326f3402a597cf09ccb4646 /filter
parent8977778ec47a4c415884fe210e258716aa011879 (diff)
downloadgsoc2013-evolution-65145381a69be1ac144c6e6dc7c2ab3fdb05d3b7.tar.gz
gsoc2013-evolution-65145381a69be1ac144c6e6dc7c2ab3fdb05d3b7.tar.zst
gsoc2013-evolution-65145381a69be1ac144c6e6dc7c2ab3fdb05d3b7.zip
** Fix for bug #563870
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. svn path=/trunk/; revision=36863
Diffstat (limited to 'filter')
-rw-r--r--filter/ChangeLog14
-rw-r--r--filter/Makefile.am2
-rw-r--r--filter/filter-element.c1
-rw-r--r--filter/filter-label.c311
-rw-r--r--filter/filter-label.h70
-rw-r--r--filter/filter-option.c71
-rw-r--r--filter/rule-context.c3
7 files changed, 63 insertions, 409 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog
index 8c8ec1336b..367645ea18 100644
--- a/filter/ChangeLog
+++ b/filter/ChangeLog
@@ -1,3 +1,17 @@
+2008-12-10 Milan Crha <mcrha@redhat.com>
+
+ ** Part of fix for bug #563870
+
+ * Makefile.am:
+ * filter-label.h:
+ * filter-label.c: Drop, not used anywhere.
+ * filter-element.c:
+ * rule-context.c: Remove dropped include and code.
+
+ * 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.
+
2008-12-09 Milan Crha <mcrha@redhat.com>
** Part of fix for bug #563669
diff --git a/filter/Makefile.am b/filter/Makefile.am
index 72cebb002a..7d4e72daeb 100644
--- a/filter/Makefile.am
+++ b/filter/Makefile.am
@@ -27,8 +27,6 @@ libfilter_la_SOURCES = \
filter-input.h \
filter-int.c \
filter-int.h \
- filter-label.c \
- filter-label.h \
filter-marshal.c \
filter-marshal.h \
filter-option.c \
diff --git a/filter/filter-element.c b/filter/filter-element.c
index 4369c65050..c14365cc8a 100644
--- a/filter/filter-element.c
+++ b/filter/filter-element.c
@@ -279,7 +279,6 @@ clone (FilterElement *fe)
#include "filter-datespec.h"
#include "filter-int.h"
#include "filter-file.h"
-#include "filter-label.h"
static void
copy_value(FilterElement *de, FilterElement *se)
diff --git a/filter/filter-label.c b/filter/filter-label.c
deleted file mode 100644
index 006d4822e8..0000000000
--- a/filter/filter-label.c
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- *
- * 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/>
- *
- *
- * Authors:
- * Jeffrey Stedfast <fejj@ximian.com>
- * Michael Zucchi <notzed@ximian.com>
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string.h>
-
-#include <gtk/gtk.h>
-#include <gconf/gconf.h>
-#include <gconf/gconf-client.h>
-#include <glib/gi18n.h>
-#include <libgnomeui/gnome-dialog.h>
-#include <libgnomeui/gnome-dialog-util.h>
-
-#include "filter-label.h"
-#include <libedataserver/e-sexp.h>
-#include "e-util/e-util.h"
-#include "e-util/e-util-labels.h"
-
-#define d(x)
-
-static void xml_create (FilterElement *fe, xmlNodePtr node);
-
-static void filter_label_class_init (FilterLabelClass *klass);
-static void filter_label_init (FilterLabel *label);
-static void filter_label_finalise (GObject *obj);
-
-static FilterElementClass *parent_class;
-
-GType
-filter_label_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo info = {
- sizeof (FilterLabelClass),
- NULL, /* base_class_init */
- NULL, /* base_class_finalize */
- (GClassInitFunc) filter_label_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (FilterLabel),
- 0, /* n_preallocs */
- (GInstanceInitFunc) filter_label_init,
- };
-
- type = g_type_register_static (FILTER_TYPE_OPTION, "FilterLabel", &info, 0);
- }
-
- return type;
-}
-
-static GStaticRecMutex cache_lock = G_STATIC_REC_MUTEX_INIT;
-static guint cache_notifier_id = 0;
-static GSList *tracked_filters = NULL;
-static GSList *labels_cache = NULL;
-static GConfClient *gconf_client = NULL;
-
-static void fill_cache (void);
-static void clear_cache (void);
-static void gconf_labels_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data);
-
-static void
-filter_label_class_init (FilterLabelClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass);
-
- parent_class = g_type_class_ref (FILTER_TYPE_OPTION);
-
- object_class->finalize = filter_label_finalise;
-
- /* override methods */
- fe_class->xml_create = xml_create;
-}
-
-static void
-filter_label_init (FilterLabel *fl)
-{
- ((FilterOption *) fl)->type = "label";
-
- g_static_rec_mutex_lock (&cache_lock);
-
- if (!tracked_filters) {
- fill_cache ();
-
- gconf_client = gconf_client_get_default ();
- gconf_client_add_dir (gconf_client, E_UTIL_LABELS_GCONF_KEY, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
- cache_notifier_id = gconf_client_notify_add (gconf_client, E_UTIL_LABELS_GCONF_KEY, gconf_labels_changed, NULL, NULL, NULL);
- }
-
- tracked_filters = g_slist_prepend (tracked_filters, fl);
-
- g_static_rec_mutex_unlock (&cache_lock);
-}
-
-static void
-filter_label_finalise (GObject *obj)
-{
- G_OBJECT_CLASS (parent_class)->finalize (obj);
-
- g_static_rec_mutex_lock (&cache_lock);
-
- tracked_filters = g_slist_remove (tracked_filters, obj);
-
- if (!tracked_filters) {
- clear_cache ();
-
- if (cache_notifier_id)
- gconf_client_notify_remove (gconf_client, cache_notifier_id);
-
- cache_notifier_id = 0;
- g_object_unref (gconf_client);
- gconf_client = NULL;
- }
-
- g_static_rec_mutex_unlock (&cache_lock);
-}
-
-/**
- * filter_label_new:
- *
- * Create a new FilterLabel object.
- *
- * Return value: A new #FilterLabel object.
- **/
-FilterLabel *
-filter_label_new (void)
-{
- return (FilterLabel *) g_object_new (FILTER_TYPE_LABEL, NULL, NULL);
-}
-
-/* ************************************************************************* */
-
-/* should already hold the lock when calling this function */
-static void
-fill_cache (void)
-{
- labels_cache = e_util_labels_parse (NULL);
-}
-
-/* should already hold the lock when calling this function */
-static void
-clear_cache (void)
-{
- e_util_labels_free (labels_cache);
- labels_cache = NULL;
-}
-
-static void
-fill_options (FilterOption *fo)
-{
- GSList *l;
-
- g_static_rec_mutex_lock (&cache_lock);
-
- for (l = labels_cache; l; l = l->next) {
- EUtilLabel *label = l->data;
- const char *tag;
- char *title;
-
- if (!label)
- continue;
-
- title = e_str_without_underscores (label->name);
- tag = label->tag;
-
- if (tag && strncmp (tag, "$Label", 6) == 0)
- tag += 6;
-
- filter_option_add (fo, tag, title, NULL, FALSE);
-
- g_free (title);
- }
-
- g_static_rec_mutex_unlock (&cache_lock);
-}
-
-static void
-regen_label_options (FilterOption *fo)
-{
- char *current;
-
- if (!fo)
- return;
-
- current = g_strdup (filter_option_get_current (fo));
-
- filter_option_remove_all (fo);
- fill_options (fo);
-
- if (current)
- filter_option_set_current (fo, current);
-
- g_free (current);
-}
-
-static void
-gconf_labels_changed (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data)
-{
- g_static_rec_mutex_lock (&cache_lock);
-
- clear_cache ();
- fill_cache ();
- g_slist_foreach (tracked_filters, (GFunc)regen_label_options, NULL);
-
- g_static_rec_mutex_unlock (&cache_lock);
-}
-
-/* ************************************************************************* */
-
-int
-filter_label_count (void)
-{
- int res;
-
- g_static_rec_mutex_lock (&cache_lock);
-
- res = g_slist_length (labels_cache);
-
- g_static_rec_mutex_unlock (&cache_lock);
-
- return res;
-}
-
-const char *
-filter_label_label (int i)
-{
- const char *res = NULL;
- GSList *l;
- EUtilLabel *label;
-
- g_static_rec_mutex_lock (&cache_lock);
-
- l = g_slist_nth (labels_cache, i);
-
- if (l)
- label = l->data;
- else
- label = NULL;
-
- if (label && label->tag) {
- if (strncmp (label->tag, "$Label", 6) == 0)
- res = label->tag + 6;
- else
- res = label->tag;
- }
-
- g_static_rec_mutex_unlock (&cache_lock);
-
- return res;
-}
-
-int
-filter_label_index (const char *label)
-{
- int i;
- GSList *l;
-
- g_static_rec_mutex_lock (&cache_lock);
-
- for (i = 0, l = labels_cache; l; i++, l = l->next) {
- EUtilLabel *lbl = l->data;
- const char *tag = lbl->tag;
-
- if (tag && strncmp (tag, "$Label", 6) == 0)
- tag += 6;
-
- if (tag && strcmp (tag, label) == 0)
- break;
- }
-
- g_static_rec_mutex_unlock (&cache_lock);
-
- if (l)
- return i;
-
- return -1;
-}
-
-static void
-xml_create (FilterElement *fe, xmlNodePtr node)
-{
- FILTER_ELEMENT_CLASS (parent_class)->xml_create (fe, node);
-
- fill_options ((FilterOption *) fe);
-}
diff --git a/filter/filter-label.h b/filter/filter-label.h
deleted file mode 100644
index 5df24b8b0d..0000000000
--- a/filter/filter-label.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- *
- * 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/>
- *
- *
- * Authors:
- * Jeffrey Stedfast <fejj@ximian.com>
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
- */
-
-#ifndef __FILTER_LABEL__
-#define __FILTER_LABEL__
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus */
-
-#include "filter-option.h"
-
-#define FILTER_TYPE_LABEL (filter_label_get_type ())
-#define FILTER_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FILTER_TYPE_LABEL, FilterLabel))
-#define FILTER_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FILTER_TYPE_LABEL, FilterLabelClass))
-#define IS_FILTER_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FILTER_TYPE_LABEL))
-#define IS_FILTER_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FILTER_TYPE_LABEL))
-#define FILTER_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FILTER_TYPE_LABEL, FilterLabelClass))
-
-typedef struct _FilterLabel FilterLabel;
-typedef struct _FilterLabelClass FilterLabelClass;
-
-struct _FilterLabel {
- FilterOption parent_object;
-
-};
-
-struct _FilterLabelClass {
- FilterOptionClass parent_class;
-
- /* virtual methods */
-
- /* signals */
-};
-
-GType filter_label_get_type (void);
-
-FilterLabel *filter_label_new (void);
-
-/* Sigh, this is a mess, but its cleaner than the original mess */
-int filter_label_count(void);
-const char *filter_label_label(int i);
-int filter_label_index(const char *label);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __FILTER_LABEL__ */
diff --git a/filter/filter-option.c b/filter/filter-option.c
index e0827d4475..2d79b609c9 100644
--- a/filter/filter-option.c
+++ b/filter/filter-option.c
@@ -45,6 +45,7 @@ static FilterElement *clone (FilterElement *fe);
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 @@ xml_create (FilterElement *fe, xmlNodePtr node)
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 @@ option_changed (GtkWidget *widget, FilterElement *fe)
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 @@ get_widget (FilterElement *fe)
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 @@ get_widget (FilterElement *fe)
}
}
- module = dlopen (NULL, RTLD_LAZY);
-
- get_func = dlsym (module, fo->dynamic_func);
- if (get_func) {
- GSList *items, *i;
+ items = get_dynamic_options (fo);
+ for (i = items; i; i = i->next) {
+ op = i->data;
- 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);
- }
+ 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) {
diff --git a/filter/rule-context.c b/filter/rule-context.c
index 2a370fd2af..304d230568 100644
--- a/filter/rule-context.c
+++ b/filter/rule-context.c
@@ -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 @@ new_element(RuleContext *rc, const char *type)
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);