From 09a5b6b00a5ace026bf019e3a6eba905e4312d2d Mon Sep 17 00:00:00 2001 From: Not Zed Date: Tue, 16 Jul 2002 02:36:20 +0000 Subject: cvs remove. 2002-07-15 Not Zed * filter-score.[ch]: cvs remove. * filter-element.c: Remove reference to filter-score.h * vfoldertypes.xml: Fix label vfolder rule as below, also add score and size rules from filtertypes.xml. * filtertypes.xml (score): Use (cast-int (user-tag "score")) to get the value directly, rather than (get-score). (label): Use (user-tag "label") to get the value directly, rather than (get-label). The label is now a string too. * filter-label.c (filter_label_get_type): Make filter-label inherit from filter-option. Which makes more sense doesn't it ... surely. (validate): Removed, optionlists are self-validating. (xml_create): Initialise the list of options from our configuration database. If it isn't working, ignore it and set it up anyway. (filter_label_init): Override the xml type. (filter_label_count): (filter_label_label): (filter_label_index): Some helper functions for external interfaces. All of the mail config/etc should use this. * filter-option.c (free_option): (xml_create): (clone): Made the "value" type in glib memory rather than xml memory space. (filter_option_add): Utility function to add a new option to the list. (clone): Use above function to simplify code. (xml_create): Same here. (xml_encode): Allow subclasses to override the type. svn path=/trunk/; revision=17472 --- filter/filter-option.c | 87 ++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 41 deletions(-) (limited to 'filter/filter-option.c') diff --git a/filter/filter-option.c b/filter/filter-option.c index 4102cd5eaf..495682cbe2 100644 --- a/filter/filter-option.c +++ b/filter/filter-option.c @@ -111,6 +111,8 @@ filter_option_class_init (FilterOptionClass *class) static void filter_option_init (FilterOption *o) { + o->type = "option"; + o->priv = g_malloc0 (sizeof (*o->priv)); } @@ -118,7 +120,7 @@ static void free_option(struct _filter_option *o, void *data) { g_free(o->title); - xmlFree (o->value); + g_free(o->value); g_free(o->code); g_free(o); } @@ -173,6 +175,25 @@ filter_option_set_current (FilterOption *option, const char *name) option->current = find_option (option, name); } +/* used by implementers to add additional options */ +void +filter_option_add(FilterOption *fo, const char *value, const char *title, const char *code) +{ + struct _filter_option *op; + + g_assert(IS_FILTER_OPTION(fo)); + g_return_if_fail(find_option(fo, value) == NULL); + + op = g_malloc(sizeof(*op)); + op->title = g_strdup(title); + op->value = g_strdup(value); + op->code = g_strdup(code); + + fo->options = g_list_append(fo->options, op); + if (fo->current == NULL) + fo->current = op; +} + static int option_eq(FilterElement *fe, FilterElement *cm) { @@ -189,41 +210,39 @@ xml_create (FilterElement *fe, xmlNodePtr node) FilterOption *fo = (FilterOption *)fe; xmlNodePtr n, work; struct _filter_option *op; - + /* parent implementation */ ((FilterElementClass *)(parent_class))->xml_create(fe, node); n = node->childs; while (n) { if (!strcmp (n->name, "option")) { - op = g_malloc0 (sizeof (*op)); - op->value = xmlGetProp (n, "value"); + char *tmp, *value, *title = NULL, *code = NULL; + + value = xmlGetProp (n, "value"); work = n->childs; while (work) { if (!strcmp (work->name, "title")) { - if (!op->title) { - gchar *str, *decstr; - str = xmlNodeGetContent (work); - decstr = e_utf8_xml1_decode (str); - if (str) xmlFree (str); - op->title = decstr; + if (!title) { + tmp = xmlNodeGetContent(work); + title = e_utf8_xml1_decode(tmp); + if (tmp) + xmlFree(tmp); } } else if (!strcmp (work->name, "code")) { - if (!op->code) { - gchar *str, *decstr; - str = xmlNodeGetContent (work); - decstr = e_utf8_xml1_decode (str); - if (str) xmlFree (str); - op->code = decstr; + if (!code) { + tmp = xmlNodeGetContent(work); + code = e_utf8_xml1_decode(tmp); + if (tmp) + xmlFree(tmp); } } work = work->next; } - d(printf ("creating new option:\n title %s\n value %s\n code %s\n", - op->title, op->value, op->code ? op->code : "none")); - fo->options = g_list_append (fo->options, op); - if (fo->current == NULL) - fo->current = op; + filter_option_add(fo, value, title, code); + xmlFree(value); + g_free(title); + g_free(code); } else { g_warning ("Unknown xml node within optionlist: %s\n", n->name); } @@ -240,10 +259,9 @@ xml_encode (FilterElement *fe) d(printf ("Encoding option as xml\n")); value = xmlNewNode (NULL, "value"); xmlSetProp (value, "name", fe->name); - xmlSetProp (value, "type", "option"); - if (fo->current) { + xmlSetProp (value, "type", fo->type); + if (fo->current) xmlSetProp (value, "value", fo->current->value); - } return value; } @@ -324,9 +342,8 @@ build_code (FilterElement *fe, GString *out, struct _FilterPart *ff) d(printf ("building option code %p, current = %p\n", fo, fo->current)); - if (fo->current && fo->current->code) { + if (fo->current && fo->current->code) filter_part_expand_code (ff, fo->current->code, out); - } } static void @@ -334,9 +351,8 @@ format_sexp (FilterElement *fe, GString *out) { FilterOption *fo = (FilterOption *)fe; - if (fo->current) { + if (fo->current) e_sexp_encode_string (out, fo->current->value); - } } static FilterElement * @@ -344,7 +360,7 @@ clone (FilterElement *fe) { FilterOption *fo = (FilterOption *)fe, *new; GList *l; - struct _filter_option *fn, *op; + struct _filter_option *op; d(printf ("cloning option\n")); @@ -352,19 +368,8 @@ clone (FilterElement *fe) l = fo->options; while (l) { op = l->data; - fn = g_malloc (sizeof (*fn)); - d(printf (" option %s\n", op->title)); - fn->title = g_strdup (op->title); - fn->value = xmlStrdup (op->value); - if (op->code) - fn->code = g_strdup (op->code); - else - fn->code = NULL; - new->options = g_list_append (new->options, fn); + filter_option_add(new, op->value, op->title, op->code); l = g_list_next (l); - - if (new->current == NULL) - new->current = fn; } d(printf ("cloning option code %p, current = %p\n", new, new->current)); -- cgit v1.2.3