diff options
-rw-r--r-- | e-util/ChangeLog | 8 | ||||
-rw-r--r-- | e-util/e-util-labels.c | 37 | ||||
-rw-r--r-- | e-util/e-util-labels.h | 2 | ||||
-rw-r--r-- | filter/ChangeLog | 14 | ||||
-rw-r--r-- | filter/Makefile.am | 2 | ||||
-rw-r--r-- | filter/filter-element.c | 1 | ||||
-rw-r--r-- | filter/filter-label.c | 311 | ||||
-rw-r--r-- | filter/filter-label.h | 70 | ||||
-rw-r--r-- | filter/filter-option.c | 71 | ||||
-rw-r--r-- | filter/rule-context.c | 3 | ||||
-rw-r--r-- | mail/ChangeLog | 9 | ||||
-rw-r--r-- | mail/em-filter-i18n.h | 18 | ||||
-rw-r--r-- | mail/filtertypes.xml | 8 | ||||
-rw-r--r-- | mail/message-list.c | 2 | ||||
-rw-r--r-- | mail/searchtypes.xml | 4 | ||||
-rw-r--r-- | mail/vfoldertypes.xml | 4 |
16 files changed, 132 insertions, 432 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 0fe2400300..b06be75c5b 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,11 @@ +2008-12-10 Milan Crha <mcrha@redhat.com> + + ** Part of fix for bug #563870 + + * e-util-labels.h: (e_util_labels_get_filter_options): + * e-util-labels.c: (e_util_labels_get_filter_options): + New helper function to be used in FilterOption. + 2008-12-09 Milan Crha <mcrha@redhat.com> ** Fix for bug #555663 diff --git a/e-util/e-util-labels.c b/e-util/e-util-labels.c index da32f233c5..88fff080b7 100644 --- a/e-util/e-util-labels.c +++ b/e-util/e-util-labels.c @@ -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 @@ e_util_labels_get_color_str (GSList *labels, const char *tag) 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); +} diff --git a/e-util/e-util-labels.h b/e-util/e-util-labels.h index a9dd5613bc..26520ff226 100644 --- a/e-util/e-util-labels.h +++ b/e-util/e-util-labels.h @@ -52,4 +52,6 @@ const char *e_util_labels_get_name (GSList *labels, const char *tag); 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 */ 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); diff --git a/mail/ChangeLog b/mail/ChangeLog index 6856858007..98aeccdef7 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,12 @@ +2008-12-10 Milan Crha <mcrha@redhat.com> + + ** Part of fix for bug #563870 + + * vfoldertypes.xml: + * filtertypes.xml: + * searchtypes.xml: Use dynamic filter option. + * message-list.c: Drop unused header include. + 2008-12-09 Milan Crha <mcrha@redhat.com> ** Part of fix for bug #552583 diff --git a/mail/em-filter-i18n.h b/mail/em-filter-i18n.h index 6c85661766..8b8d0c3323 100644 --- a/mail/em-filter-i18n.h +++ b/mail/em-filter-i18n.h @@ -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_("Message is not Junk"); 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_("returns less than"); 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)"); diff --git a/mail/filtertypes.xml b/mail/filtertypes.xml index 60702f2b08..69c1ddbaae 100644 --- a/mail/filtertypes.xml +++ b/mail/filtertypes.xml @@ -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> diff --git a/mail/message-list.c b/mail/message-list.c index 7333467fd1..70795478bf 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -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" diff --git a/mail/searchtypes.xml b/mail/searchtypes.xml index d48fc251af..ded2e2eabd 100644 --- a/mail/searchtypes.xml +++ b/mail/searchtypes.xml @@ -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"> diff --git a/mail/vfoldertypes.xml b/mail/vfoldertypes.xml index f7b4b7d8cd..b87af3280a 100644 --- a/mail/vfoldertypes.xml +++ b/mail/vfoldertypes.xml @@ -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"> |