diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2008-12-11 02:30:29 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2008-12-11 02:30:29 +0800 |
commit | d158af8cdfa6e4bf85c1e74769e8d61bc469494c (patch) | |
tree | ba55b970ae3a23e5ade4edbddc4eb8dcaf3033bd /filter | |
parent | dc0d0ee010319425b19d8d8d493f0bc489d5fd07 (diff) | |
download | gsoc2013-evolution-d158af8cdfa6e4bf85c1e74769e8d61bc469494c.tar gsoc2013-evolution-d158af8cdfa6e4bf85c1e74769e8d61bc469494c.tar.gz gsoc2013-evolution-d158af8cdfa6e4bf85c1e74769e8d61bc469494c.tar.bz2 gsoc2013-evolution-d158af8cdfa6e4bf85c1e74769e8d61bc469494c.tar.lz gsoc2013-evolution-d158af8cdfa6e4bf85c1e74769e8d61bc469494c.tar.xz gsoc2013-evolution-d158af8cdfa6e4bf85c1e74769e8d61bc469494c.tar.zst gsoc2013-evolution-d158af8cdfa6e4bf85c1e74769e8d61bc469494c.zip |
Merge revisions 36811:36865 from trunk.
svn path=/branches/kill-bonobo/; revision=36867
Diffstat (limited to 'filter')
-rw-r--r-- | filter/ChangeLog | 33 | ||||
-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 | 129 | ||||
-rw-r--r-- | filter/filter-option.h | 5 | ||||
-rw-r--r-- | filter/filter.glade | 2 | ||||
-rw-r--r-- | filter/rule-context.c | 3 |
9 files changed, 163 insertions, 393 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index 3534320543..367645ea18 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,36 @@ +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 + + * filter.glade: + Use zero GtkSpinButton's PageSize, as Gtk+ requires. + +2008-12-05 Milan Crha <mcrha@redhat.com> + + ** Fix for bug #332629 + + * filter-option.h: (struct _filter_option), + (struct _FilterOption), (filter_option_add): + * filter-option.c: (filter_option_init), (filter_option_finalise), + (filter_option_add), (xml_create), (get_widget), (clone): + Be able to define optionlist with dynamically created list of options. + + * filter-label.c: (fill_options): Adapt. + 2008-10-17 Matthew Barnes <mbarnes@redhat.com> ** Fix for bug #503898 diff --git a/filter/Makefile.am b/filter/Makefile.am index 2b6f473db9..ed11b06a67 100644 --- a/filter/Makefile.am +++ b/filter/Makefile.am @@ -26,8 +26,6 @@ libfilter_la_SOURCES = \ filter-input.h \ filter-int.c \ filter-int.h \ - filter-label.c \ - filter-label.h \ filter-option.c \ filter-option.h \ filter-part.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 1d76300339..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); - - 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 1685fe06ce..2d79b609c9 100644 --- a/filter/filter-option.c +++ b/filter/filter-option.c @@ -29,6 +29,7 @@ #include <gtk/gtk.h> #include <glib/gi18n.h> +#include <dlfcn.h> #include "filter-option.h" #include "filter-part.h" @@ -44,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); @@ -102,6 +104,7 @@ static void filter_option_init (FilterOption *fo) { fo->type = "option"; + fo->dynamic_func = NULL; } static void @@ -120,6 +123,7 @@ filter_option_finalise (GObject *obj) g_list_foreach (fo->options, (GFunc)free_option, NULL); g_list_free (fo->options); + g_free (fo->dynamic_func); G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -164,7 +168,7 @@ filter_option_set_current (FilterOption *option, const char *name) /* used by implementers to add additional options */ struct _filter_option * -filter_option_add(FilterOption *fo, const char *value, const char *title, const char *code) +filter_option_add(FilterOption *fo, const char *value, const char *title, const char *code, gboolean is_dynamic) { struct _filter_option *op; @@ -175,6 +179,7 @@ filter_option_add(FilterOption *fo, const char *value, const char *title, const op->title = g_strdup(title); op->value = g_strdup(value); op->code = g_strdup(code); + op->is_dynamic = is_dynamic; fo->options = g_list_append(fo->options, op); if (fo->current == NULL) @@ -253,10 +258,47 @@ xml_create (FilterElement *fe, xmlNodePtr node) work = work->next; } - filter_option_add (fo, value, title, code); + filter_option_add (fo, value, title, code, FALSE); xmlFree (value); g_free (title); g_free (code); + } else if (g_str_equal ((char *)n->name, "dynamic")) { + if (fo->dynamic_func) { + g_warning ("Only one 'dynamic' node is acceptable in the optionlist '%s'", fe->name); + } else { + /* Expecting only one <dynamic func="cb" /> in the option list, + The 'cb' should be of this prototype: + GSList *cb (void); + returning GSList of struct _filter_option, all newly allocated, because it'll + be freed with g_free and g_slist_free. 'is_dynamic' member is ignored here. + */ + xmlChar *fn; + + 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); + + /* 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); + } + + xmlFree (fn); + } } else if (n->type == XML_ELEMENT_NODE) { g_warning ("Unknown xml node within optionlist: %s\n", n->name); } @@ -307,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) { @@ -315,11 +381,64 @@ get_widget (FilterElement *fe) GtkWidget *omenu; GtkWidget *item; GtkWidget *first = NULL; - GList *l = fo->options; + GList *l; struct _filter_option *op; int index = 0, current = 0; + 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; + + old_ops = fo->options; + old_cur = fo->current; + l = old_ops; + + /* start with an empty list */ + fo->current = NULL; + fo->options = NULL; + + for (l = fo->options; l; l = l->next) { + op = l->data; + + if (op->is_dynamic) { + break; + } else { + filter_option_add (fo, op->value, op->title, op->code, FALSE); + } + } + + 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); + + /* maybe some static left after those dynamic, add them too */ + for (; l; l = l->next) { + op = l->data; + + if (!op->is_dynamic) + filter_option_add (fo, op->value, op->title, op->code, FALSE); + } + + if (old_cur) + filter_option_set_current (fo, old_cur->value); + + /* free old list */ + g_list_foreach (old_ops, (GFunc)free_option, NULL); + g_list_free (old_ops); + } + menu = gtk_menu_new (); + l = fo->options; while (l) { op = l->data; item = gtk_menu_item_new_with_label (_(op->title)); @@ -382,12 +501,14 @@ clone (FilterElement *fe) l = fo->options; while (l) { op = l->data; - newop = filter_option_add (new, op->value, op->title, op->code); + newop = filter_option_add (new, op->value, op->title, op->code, op->is_dynamic); if (fo->current == op) new->current = newop; l = l->next; } + new->dynamic_func = g_strdup (fo->dynamic_func); + d(printf ("cloning option code %p, current = %p\n", new, new->current)); return (FilterElement *) new; diff --git a/filter/filter-option.h b/filter/filter-option.h index 8cc6c052d4..6cf56645b8 100644 --- a/filter/filter-option.h +++ b/filter/filter-option.h @@ -40,6 +40,8 @@ struct _filter_option { char *title; /* button title */ char *value; /* value, if it has one */ char *code; /* used to string code segments together */ + + gboolean is_dynamic; /* whether is the option dynamic, FALSE if static */ }; struct _FilterOption { @@ -49,6 +51,7 @@ struct _FilterOption { GList *options; struct _filter_option *current; + char *dynamic_func; /* name of the dynamic fill func, called in get_widget */ }; struct _FilterOptionClass { @@ -66,7 +69,7 @@ FilterOption *filter_option_new (void); void filter_option_set_current (FilterOption *option, const char *name); const char *filter_option_get_current (FilterOption *option); -struct _filter_option *filter_option_add (FilterOption *fo, const char *name, const char *title, const char *code); +struct _filter_option *filter_option_add (FilterOption *fo, const char *name, const char *title, const char *code, gboolean is_dynamic); void filter_option_remove_all (FilterOption *fo); #endif /* ! _FILTER_OPTION_H */ diff --git a/filter/filter.glade b/filter/filter.glade index 8dd6197f0c..3b43c26249 100644 --- a/filter/filter.glade +++ b/filter/filter.glade @@ -615,7 +615,7 @@ a time relative to when filtering occurs.</property> <property name="update_policy">GTK_UPDATE_ALWAYS</property> <property name="snap_to_ticks">False</property> <property name="wrap">False</property> - <property name="adjustment">1 0 1000 1 10 10</property> + <property name="adjustment">1 0 1000 1 10 0</property> </widget> <packing> <property name="padding">0</property> diff --git a/filter/rule-context.c b/filter/rule-context.c index ecbdafefdd..a7f739615b 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-option.h" #include "filter-rule.h" #include "rule-context.h" @@ -921,8 +920,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); |