aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-option.c
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/filter-option.c
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/filter-option.c')
-rw-r--r--filter/filter-option.c71
1 files changed, 49 insertions, 22 deletions
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) {