diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2000-09-19 04:49:51 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2000-09-19 04:49:51 +0800 |
commit | 635f31e410676a42bd3f0cf3c1571dd2cf156f28 (patch) | |
tree | 4077b9a9200de9b121cec5a00f66d41f3752505b | |
parent | 69f189090877a8a60fd3a0fdbe0416f67346de26 (diff) | |
download | gsoc2013-evolution-635f31e410676a42bd3f0cf3c1571dd2cf156f28.tar.gz gsoc2013-evolution-635f31e410676a42bd3f0cf3c1571dd2cf156f28.tar.zst gsoc2013-evolution-635f31e410676a42bd3f0cf3c1571dd2cf156f28.zip |
Modified to use more intuitive naming
2000-09-18 Jeffrey Stedfast <fejj@helixcode.com>
* filtertypes.xml: Modified to use more intuitive naming
* score-rule.c (xml_decode): Make sure the score is within our
range
(get_widget): Changed range to -3 to +3
* filter-score.c (get_widget): Changed range to -3 to +3
(xml_decode): Make sure the score is within our range
* filter-rule.c (get_widget): Rearranged widgets.
* filter-filter.c (get_widget): Rearranged widgets.
* filter-editor.c (filter_editor_construct): Updated to allow for
double-clicking on a rule to edit it.
svn path=/trunk/; revision=5492
-rw-r--r-- | filter/ChangeLog | 18 | ||||
-rw-r--r-- | filter/filter-editor.c | 265 | ||||
-rw-r--r-- | filter/filter-filter.c | 345 | ||||
-rw-r--r-- | filter/filter-message-search.c | 1 | ||||
-rw-r--r-- | filter/filter-rule.c | 533 | ||||
-rw-r--r-- | filter/filter-score.c | 7 | ||||
-rw-r--r-- | filter/filtertypes.xml | 81 | ||||
-rw-r--r-- | filter/score-rule.c | 115 |
8 files changed, 760 insertions, 605 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index d04ceb7642..f1d4d0bf28 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,21 @@ +2000-09-18 Jeffrey Stedfast <fejj@helixcode.com> + + * filtertypes.xml: Modified to use more intuitive naming + + * score-rule.c (xml_decode): Make sure the score is within our + range + (get_widget): Changed range to -3 to +3 + + * filter-score.c (get_widget): Changed range to -3 to +3 + (xml_decode): Make sure the score is within our range + + * filter-rule.c (get_widget): Rearranged widgets. + + * filter-filter.c (get_widget): Rearranged widgets. + + * filter-editor.c (filter_editor_construct): Updated to allow for + double-clicking on a rule to edit it. + 2000-09-18 Christopher James Lahey <clahey@helixcode.com> * filter-editor.c, filter-filter.c, filter-folder.c, diff --git a/filter/filter-editor.c b/filter/filter-editor.c index c09160ee3f..cb3e879f04 100644 --- a/filter/filter-editor.c +++ b/filter/filter-editor.c @@ -30,9 +30,9 @@ #define d(x) #if 0 -static void filter_editor_class_init (FilterEditorClass *class); -static void filter_editor_init (FilterEditor *gspaper); -static void filter_editor_finalise (GtkObject *obj); +static void filter_editor_class_init (FilterEditorClass *class); +static void filter_editor_init (FilterEditor *gspaper); +static void filter_editor_finalise (GtkObject *obj); #define _PRIVATE(x) (((FilterEditor *)(x))->priv) @@ -92,7 +92,7 @@ filter_editor_init (FilterEditor *o) } static void -filter_editor_finalise(GtkObject *obj) +filter_editor_finalise (GtkObject *obj) { FilterEditor *o = (FilterEditor *)obj; @@ -107,7 +107,7 @@ filter_editor_finalise(GtkObject *obj) * Return value: A new #FilterEditor object. **/ FilterEditor * -filter_editor_new(void) +filter_editor_new (void) { FilterEditor *o = (FilterEditor *)gtk_type_new(filter_editor_get_type ()); return o; @@ -133,72 +133,80 @@ struct _editor_data { enum _filter_source_t current_source; }; -static void set_sensitive(struct _editor_data *data); +static void set_sensitive (struct _editor_data *data); -static void rule_add(GtkWidget *widget, struct _editor_data *data) +static void +rule_add (GtkWidget *widget, struct _editor_data *data) { FilterFilter *rule; int result; - GnomeDialog *gd; + GtkWidget *gd; GtkWidget *w; FilterPart *part; - - d(printf("add rule\n")); + + d(printf ("add rule\n")); /* create a new rule with 1 match and 1 action */ - rule = filter_filter_new(); + rule = filter_filter_new (); ((FilterRule *)rule)->source = data->current_source; - - part = rule_context_next_part(data->f, NULL); - filter_rule_add_part((FilterRule *)rule, filter_part_clone(part)); - part = filter_context_next_action((FilterContext *)data->f, NULL); - filter_filter_add_action(rule, filter_part_clone(part)); - - w = filter_rule_get_widget((FilterRule *)rule, data->f); - gd = (GnomeDialog *)gnome_dialog_new(_("Add Rule"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); - gtk_box_pack_start((GtkBox *)gd->vbox, w, FALSE, TRUE, 0); - gtk_widget_show((GtkWidget *)gd); - result = gnome_dialog_run_and_close(gd); + + part = rule_context_next_part (data->f, NULL); + filter_rule_add_part ((FilterRule *)rule, filter_part_clone (part)); + part = filter_context_next_action ((FilterContext *)data->f, NULL); + filter_filter_add_action (rule, filter_part_clone (part)); + + w = filter_rule_get_widget ((FilterRule *)rule, data->f); + gd = gnome_dialog_new (_("Add Rule"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); + gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (gd)->vbox), w, FALSE, TRUE, 0); + gtk_widget_show (gd); + + result = gnome_dialog_run_and_close (GNOME_DIALOG (gd)); + if (result == 0) { GtkListItem *item; GList *l = NULL; - gchar *s = e_utf8_to_gtk_string ((GtkWidget *) data->list, ((FilterRule *)rule)->name); - item = (GtkListItem *)gtk_list_item_new_with_label (s); + gchar *s = e_utf8_to_gtk_string (GTK_WIDGET (data->list), ((FilterRule *)rule)->name); + + item = (GtkListItem *) gtk_list_item_new_with_label (s); g_free (s); - gtk_object_set_data((GtkObject *)item, "rule", rule); - gtk_widget_show((GtkWidget *)item); - l = g_list_append(l, item); - gtk_list_append_items(data->list, l); - gtk_list_select_child(data->list, (GtkWidget *)item); + + gtk_object_set_data (GTK_OBJECT (item), "rule", rule); + gtk_widget_show (GTK_WIDGET (item)); + + l = g_list_append (l, item); + gtk_list_append_items (data->list, l); + gtk_list_select_child (data->list, GTK_WIDGET (item)); + data->current = (FilterRule *)rule; - rule_context_add_rule(data->f, (FilterRule *)rule); - set_sensitive(data); + rule_context_add_rule (data->f, (FilterRule *)rule); + set_sensitive (data); } else { - gtk_object_unref((GtkObject *)rule); + gtk_object_unref (GTK_OBJECT (rule)); } } -static void rule_edit(GtkWidget *widget, struct _editor_data *data) +static void +rule_edit (GtkWidget *widget, struct _editor_data *data) { GtkWidget *w; int result; - GnomeDialog *gd; + GtkWidget *gd; FilterRule *rule; int pos; - - d(printf("edit rule\n")); + + d(printf ("edit rule\n")); rule = data->current; - w = filter_rule_get_widget(rule, data->f); - gd = (GnomeDialog *)gnome_dialog_new(_("Edit Rule"), - GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, - NULL); - gtk_box_pack_start((GtkBox *)gd->vbox, w, FALSE, TRUE, 0); - gtk_widget_show((GtkWidget *)gd); - result = gnome_dialog_run_and_close(gd); - + w = filter_rule_get_widget (rule, data->f); + gd = gnome_dialog_new (_("Edit Rule"), + GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, + NULL); + gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (gd)->vbox), w, FALSE, TRUE, 0); + gtk_widget_show (gd); + result = gnome_dialog_run_and_close (GNOME_DIALOG (gd)); + if (result == 0) { pos = rule_context_get_rank_rule_with_source (data->f, data->current, data->current_source); if (pos != -1) { - GtkListItem *item = g_list_nth_data(data->list->children, pos); + GtkListItem *item = g_list_nth_data (data->list->children, pos); gchar *s = e_utf8_to_gtk_string ((GtkWidget *) item, data->current->name); gtk_label_set_text((GtkLabel *)(((GtkBin *)item)->child), s); g_free (s); @@ -206,7 +214,8 @@ static void rule_edit(GtkWidget *widget, struct _editor_data *data) } } -static void rule_delete(GtkWidget *widget, struct _editor_data *data) +static void +rule_delete (GtkWidget *widget, struct _editor_data *data) { int pos; GList *l; @@ -215,53 +224,56 @@ static void rule_delete(GtkWidget *widget, struct _editor_data *data) d(printf("ddelete rule\n")); pos = rule_context_get_rank_rule_with_source (data->f, data->current, data->current_source); if (pos != -1) { - rule_context_remove_rule(data->f, data->current); - - item = g_list_nth_data(data->list->children, pos); - l = g_list_append(NULL, item); - gtk_list_remove_items(data->list, l); - g_list_free(l); - - gtk_object_unref((GtkObject *)data->current); + rule_context_remove_rule (data->f, data->current); + + item = g_list_nth_data (data->list->children, pos); + l = g_list_append (NULL, item); + gtk_list_remove_items (data->list, l); + g_list_free (l); + + gtk_object_unref (GTK_OBJECT (data->current)); data->current = NULL; } - set_sensitive(data); + set_sensitive (data); } -static void rule_move(struct _editor_data *data, int from, int to) +static void +rule_move (struct _editor_data *data, int from, int to) { GList *l; GtkListItem *item; - + d(printf("moving %d to %d\n", from, to)); - rule_context_rank_rule(data->f, data->current, to); + rule_context_rank_rule (data->f, data->current, to); - item = g_list_nth_data(data->list->children, from); - l = g_list_append(NULL, item); - gtk_list_remove_items_no_unref(data->list, l); - gtk_list_insert_items(data->list, l, to); - gtk_list_select_child(data->list, (GtkWidget *)item); - set_sensitive(data); + item = g_list_nth_data (data->list->children, from); + l = g_list_append (NULL, item); + gtk_list_remove_items_no_unref (data->list, l); + gtk_list_insert_items (data->list, l, to); + gtk_list_select_child (data->list, GTK_WIDGET (item)); + set_sensitive (data); } -static void rule_up(GtkWidget *widget, struct _editor_data *data) +static void +rule_up (GtkWidget *widget, struct _editor_data *data) { int pos; - + d(printf("up rule\n")); - pos = rule_context_get_rank_rule_with_source(data->f, data->current, data->current_source); - if (pos>0) { - rule_move(data, pos, pos-1); + pos = rule_context_get_rank_rule_with_source (data->f, data->current, data->current_source); + if (pos > 0) { + rule_move (data, pos, pos-1); } } -static void rule_down(GtkWidget *widget, struct _editor_data *data) +static void +rule_down (GtkWidget *widget, struct _editor_data *data) { int pos; - - d(printf("down rule\n")); - pos = rule_context_get_rank_rule_with_source(data->f, data->current, data->current_source); - rule_move(data, pos, pos+1); + + d(printf ("down rule\n")); + pos = rule_context_get_rank_rule_with_source (data->f, data->current, data->current_source); + rule_move (data, pos, pos+1); } static struct { @@ -276,33 +288,42 @@ static struct { }; static void -set_sensitive(struct _editor_data *data) +set_sensitive (struct _editor_data *data) { FilterRule *rule = NULL; - int index=-1, count=0; - - while ((rule = rule_context_next_rule(data->f, rule))) { + int index = -1, count = 0; + + while ((rule = rule_context_next_rule (data->f, rule))) { if (rule == data->current) index=count; count++; } - d(printf("index = %d count=%d\n", index, count)); + d(printf ("index = %d count=%d\n", index, count)); count--; - gtk_widget_set_sensitive((GtkWidget *)data->buttons[BUTTON_EDIT], index != -1); - gtk_widget_set_sensitive((GtkWidget *)data->buttons[BUTTON_DELETE], index != -1); - gtk_widget_set_sensitive((GtkWidget *)data->buttons[BUTTON_UP], index > 0); - gtk_widget_set_sensitive((GtkWidget *)data->buttons[BUTTON_DOWN], index >=0 && index<count); + gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_EDIT]), index != -1); + gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_DELETE]), index != -1); + gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_UP]), index > 0); + gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_DOWN]), index >= 0 && index < count); } static void -select_rule(GtkWidget *w, GtkWidget *child, struct _editor_data *data) +select_rule (GtkWidget *w, GtkWidget *child, struct _editor_data *data) { - data->current = gtk_object_get_data((GtkObject *)child, "rule"); + data->current = gtk_object_get_data (GTK_OBJECT (child), "rule"); + if (data->current) - d(printf("seledct rule: %s\n", data->current->name)); + d(printf ("seledct rule: %s\n", data->current->name)); else - d(printf("bad data?\n")); - set_sensitive(data); + d(printf ("bad data?\n")); + + set_sensitive (data); +} + +static void +double_click (GtkWidget *widget, GdkEventButton *event, gpointer user_data) +{ + if (event->type == GDK_2BUTTON_PRESS) + rule_edit (widget, user_data); } /* FIXME: we need a way to change a rule from one source type @@ -315,83 +336,85 @@ select_source (GtkMenuItem *mi, struct _editor_data *data) FilterRule *rule = NULL; GList *newitems = NULL; enum _filter_source_t source; - + source = (enum _filter_source_t) GPOINTER_TO_INT ( gtk_object_get_data (GTK_OBJECT (mi), "number")); - + gtk_list_clear_items (GTK_LIST (data->list), 0, -1); - - d(printf("Checking for rules that are of type %d\n", source)); + + d(printf ("Checking for rules that are of type %d\n", source)); while ((rule = rule_context_next_rule (data->f, rule)) != NULL) { GtkWidget *item; gchar *s; - + if (rule->source != source) { - d(printf(" skipping %s: %d != %d\n", rule->name, rule->source, source)); + d(printf (" skipping %s: %d != %d\n", rule->name, rule->source, source)); continue; } - - d(printf(" hit %s (%d)\n", rule->name, source)); - s = e_utf8_to_gtk_string ((GtkWidget *) data->list, rule->name); + + d(printf (" hit %s (%d)\n", rule->name, source)); + s = e_utf8_to_gtk_string (GTK_WIDGET (data->list), rule->name); item = gtk_list_item_new_with_label (s); g_free (s); gtk_object_set_data (GTK_OBJECT (item), "rule", rule); gtk_widget_show (GTK_WIDGET (item)); newitems = g_list_append (newitems, item); } - + gtk_list_append_items (data->list, newitems); data->current_source = source; data->current = NULL; set_sensitive (data); } -GtkWidget *filter_editor_construct (struct _FilterContext *f) +GtkWidget * +filter_editor_construct (struct _FilterContext *f) { GladeXML *gui; GtkWidget *d, *w, *b, *firstitem = NULL; GList *l; struct _editor_data *data; int i; - - g_assert(IS_FILTER_CONTEXT(f)); - - data = g_malloc0(sizeof(*data)); + + g_assert (IS_FILTER_CONTEXT (f)); + + data = g_malloc0 (sizeof (*data)); data->f = (RuleContext *)f; - - gui = glade_xml_new(FILTER_GLADEDIR "/filter.glade", "edit_filter"); + + gui = glade_xml_new (FILTER_GLADEDIR "/filter.glade", "edit_filter"); d = glade_xml_get_widget (gui, "edit_filter"); - gtk_object_set_data_full((GtkObject *)d, "data", data, g_free); - - gtk_window_set_title((GtkWindow *)d, "Edit Filters"); - for (i=0;i<BUTTON_LAST;i++) { + gtk_object_set_data_full (GTK_OBJECT (d), "data", data, g_free); + + gtk_window_set_title (GTK_WINDOW (d), "Edit Filters"); + for (i = 0; i < BUTTON_LAST; i++) { data->buttons[i] = (GtkButton *)w = glade_xml_get_widget (gui, edit_buttons[i].name); - gtk_signal_connect((GtkObject *)w, "clicked", edit_buttons[i].func, data); + gtk_signal_connect (GTK_OBJECT (w), "clicked", edit_buttons[i].func, data); } - + w = glade_xml_get_widget (gui, "filter_source"); - l = GTK_MENU_SHELL(GTK_OPTION_MENU(w)->menu)->children; + l = GTK_MENU_SHELL (GTK_OPTION_MENU (w)->menu)->children; i = 0; while (l) { b = GTK_WIDGET (l->data); - + if (i == 0) firstitem = b; - + /* make sure that the glade is in sync with enum _filter_source_t! */ gtk_object_set_data (GTK_OBJECT (b), "number", GINT_TO_POINTER (i)); gtk_signal_connect (GTK_OBJECT (b), "activate", select_source, data); - + i++; l = l->next; } - + w = glade_xml_get_widget (gui, "rule_list"); - data->list = (GtkList *)w; - gtk_signal_connect((GtkObject *)w, "select_child", select_rule, data); + data->list = GTK_LIST (w); + gtk_signal_connect (GTK_OBJECT (w), "select_child", select_rule, data); + gtk_signal_connect (GTK_OBJECT (w), "button_press_event", double_click, data); select_source (GTK_MENU_ITEM (firstitem), data); - - gtk_object_unref((GtkObject *)gui); - + + gtk_object_unref (GTK_OBJECT (gui)); + return d; } diff --git a/filter/filter-filter.c b/filter/filter-filter.c index 8b021ef3a4..5268381e30 100644 --- a/filter/filter-filter.c +++ b/filter/filter-filter.c @@ -2,6 +2,7 @@ * Copyright (C) 2000 Helix Code Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfasr <fejj@helixcode.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -28,14 +29,14 @@ #define d(x) -static xmlNodePtr xml_encode(FilterRule *); -static int xml_decode(FilterRule *, xmlNodePtr, struct _RuleContext *f); +static xmlNodePtr xml_encode (FilterRule *); +static int xml_decode (FilterRule *, xmlNodePtr, struct _RuleContext *f); /*static void build_code(FilterRule *, GString *out);*/ -static GtkWidget *get_widget(FilterRule *fr, struct _RuleContext *f); +static GtkWidget *get_widget (FilterRule *fr, struct _RuleContext *f); -static void filter_filter_class_init (FilterFilterClass *class); -static void filter_filter_init (FilterFilter *gspaper); -static void filter_filter_finalise (GtkObject *obj); +static void filter_filter_class_init (FilterFilterClass *class); +static void filter_filter_init (FilterFilter *gspaper); +static void filter_filter_finalise (GtkObject *obj); #define _PRIVATE(x) (((FilterFilter *)(x))->priv) @@ -77,46 +78,46 @@ filter_filter_class_init (FilterFilterClass *class) { GtkObjectClass *object_class; FilterRuleClass *filter_rule = (FilterRuleClass *)class; - + object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class(filter_rule_get_type ()); - + parent_class = gtk_type_class (filter_rule_get_type ()); + object_class->finalize = filter_filter_finalise; - + /* override methods */ filter_rule->xml_encode = xml_encode; filter_rule->xml_decode = xml_decode; /*filter_rule->build_code = build_code;*/ filter_rule->get_widget = get_widget; - + /* signals */ - - gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL); + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); } static void filter_filter_init (FilterFilter *o) { - o->priv = g_malloc0(sizeof(*o->priv)); + o->priv = g_malloc0 (sizeof (*o->priv)); } static void -unref_list(GList *l) +unref_list (GList *l) { while (l) { - gtk_object_unref((GtkObject *)l->data); - l = g_list_next(l); + gtk_object_unref (GTK_OBJECT (l->data)); + l = g_list_next (l); } } static void -filter_filter_finalise(GtkObject *obj) +filter_filter_finalise (GtkObject *obj) { FilterFilter *o = (FilterFilter *)obj; - - unref_list(o->actions); - - ((GtkObjectClass *)(parent_class))->finalize(obj); + + unref_list (o->actions); + + ((GtkObjectClass *)(parent_class))->finalize (obj); } /** @@ -127,104 +128,113 @@ filter_filter_finalise(GtkObject *obj) * Return value: A new #FilterFilter object. **/ FilterFilter * -filter_filter_new(void) +filter_filter_new (void) { FilterFilter *o = (FilterFilter *)gtk_type_new(filter_filter_get_type ()); return o; } -void filter_filter_add_action (FilterFilter *fr, FilterPart *fp) +void +filter_filter_add_action (FilterFilter *fr, FilterPart *fp) { - fr->actions = g_list_append(fr->actions, fp); + fr->actions = g_list_append (fr->actions, fp); } -void filter_filter_remove_action (FilterFilter *fr, FilterPart *fp) +void +filter_filter_remove_action (FilterFilter *fr, FilterPart *fp) { - fr->actions = g_list_remove(fr->actions, fp); + fr->actions = g_list_remove (fr->actions, fp); } -void filter_filter_replace_action(FilterFilter *fr, FilterPart *fp, FilterPart *new) +void +filter_filter_replace_action (FilterFilter *fr, FilterPart *fp, FilterPart *new) { GList *l; - l = g_list_find(fr->actions, fp); + l = g_list_find (fr->actions, fp); if (l) { l->data = new; } else { - fr->actions = g_list_append(fr->actions, new); + fr->actions = g_list_append (fr->actions, new); } } -void filter_filter_build_action (FilterFilter *fr, GString *out) +void +filter_filter_build_action (FilterFilter *fr, GString *out) { - g_string_append(out, "(begin\n"); - filter_part_build_code_list(fr->actions, out); - g_string_append(out, ")\n"); + g_string_append (out, "(begin\n"); + filter_part_build_code_list (fr->actions, out); + g_string_append (out, ")\n"); } -static xmlNodePtr xml_encode(FilterRule *fr) +static xmlNodePtr +xml_encode (FilterRule *fr) { xmlNodePtr node, set, work; GList *l; FilterFilter *ff = (FilterFilter *)fr; - - node = ((FilterRuleClass *)(parent_class))->xml_encode(fr); - g_assert(node != NULL); - set = xmlNewNode(NULL, "actionset"); - xmlAddChild(node, set); + + node = ((FilterRuleClass *)(parent_class))->xml_encode (fr); + g_assert (node != NULL); + set = xmlNewNode (NULL, "actionset"); + xmlAddChild (node, set); l = ff->actions; while (l) { - work = filter_part_xml_encode((FilterPart *)l->data); - xmlAddChild(set, work); - l = g_list_next(l); + work = filter_part_xml_encode ((FilterPart *)l->data); + xmlAddChild (set, work); + l = g_list_next (l); } + return node; } -static void load_set(xmlNodePtr node, FilterFilter *ff, RuleContext *f) +static void +load_set (xmlNodePtr node, FilterFilter *ff, RuleContext *f) { xmlNodePtr work; char *rulename; FilterPart *part; - + work = node->childs; while (work) { - if (!strcmp(work->name, "part")) { - rulename = xmlGetProp(work, "name"); - part = filter_context_find_action((FilterContext *)f, rulename); + if (!strcmp (work->name, "part")) { + rulename = xmlGetProp (work, "name"); + part = filter_context_find_action ((FilterContext *)f, rulename); if (part) { - part = filter_part_clone(part); - filter_part_xml_decode(part, work); - filter_filter_add_action(ff, part); + part = filter_part_clone (part); + filter_part_xml_decode (part, work); + filter_filter_add_action (ff, part); } else { - g_warning("cannot find rule part '%s'\n", rulename); + g_warning ("cannot find rule part '%s'\n", rulename); } - xmlFree(rulename); + xmlFree (rulename); } else { - g_warning("Unknwon xml node in part: %s", work->name); + g_warning ("Unknwon xml node in part: %s", work->name); } work = work->next; } } -static int xml_decode(FilterRule *fr, xmlNodePtr node, struct _RuleContext *f) +static int +xml_decode (FilterRule *fr, xmlNodePtr node, struct _RuleContext *f) { xmlNodePtr work; FilterFilter *ff = (FilterFilter *)fr; int result; - result = ((FilterRuleClass *)(parent_class))->xml_decode(fr, node, f); + result = ((FilterRuleClass *)(parent_class))->xml_decode (fr, node, f); if (result != 0) return result; - + work = node->childs; while (work) { - if (!strcmp(work->name, "actionset")) { - load_set(work, ff, f); + if (!strcmp (work->name, "actionset")) { + load_set (work, ff, f); } work = work->next; } + return 0; } @@ -240,79 +250,83 @@ struct _part_data { GtkWidget *partwidget, *container; }; -static void option_activate(GtkMenuItem *item, struct _part_data *data) +static void +option_activate (GtkMenuItem *item, struct _part_data *data) { - FilterPart *part = gtk_object_get_data((GtkObject *)item, "part"); + FilterPart *part = gtk_object_get_data (GTK_OBJECT (item), "part"); FilterPart *newpart; - + /* dont update if we haven't changed */ - if (!strcmp(part->title, data->part->title)) + if (!strcmp (part->title, data->part->title)) return; - + /* here we do a widget shuffle, throw away the old widget/rulepart, and create another */ if (data->partwidget) - gtk_container_remove((GtkContainer *)data->container, data->partwidget); - newpart = filter_part_clone(part); - filter_filter_replace_action((FilterFilter *)data->fr, data->part, newpart); - gtk_object_unref((GtkObject *)data->part); + gtk_container_remove (GTK_CONTAINER (data->container), data->partwidget); + + newpart = filter_part_clone (part); + filter_filter_replace_action ((FilterFilter *)data->fr, data->part, newpart); + gtk_object_unref (GTK_OBJECT (data->part)); data->part = newpart; - data->partwidget = filter_part_get_widget(newpart); + data->partwidget = filter_part_get_widget (newpart); if (data->partwidget) - gtk_box_pack_start((GtkBox *)data->container, data->partwidget, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (data->container), data->partwidget, FALSE, FALSE, 0); } static GtkWidget * -get_rule_part_widget(FilterContext *f, FilterPart *newpart, FilterRule *fr) +get_rule_part_widget (FilterContext *f, FilterPart *newpart, FilterRule *fr) { FilterPart *part = NULL; - GtkMenu *menu; - GtkMenuItem *item; - GtkOptionMenu *omenu; - GtkHBox *hbox; + GtkWidget *menu; + GtkWidget *item; + GtkWidget *omenu; + GtkWidget *hbox; GtkWidget *p; - int index=0, current=0; + int index = 0, current = 0; struct _part_data *data; gchar *s; - - data = g_malloc0(sizeof(*data)); + + data = g_malloc0 (sizeof (*data)); data->fr = fr; data->f = f; data->part = newpart; - - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 0); - p = filter_part_get_widget(newpart); - + + hbox = gtk_hbox_new (FALSE, 0); + p = filter_part_get_widget (newpart); + data->partwidget = p; - data->container = (GtkWidget *)hbox; - - menu = (GtkMenu *)gtk_menu_new(); - while ((part=filter_context_next_action(f, part))) { - s = e_utf8_to_gtk_string ((GtkWidget *) menu, part->title); - item = (GtkMenuItem *)gtk_menu_item_new_with_label(s); + data->container = hbox; + + menu = gtk_menu_new (); + while ((part = filter_context_next_action (f, part))) { + s = e_utf8_to_gtk_string (menu, part->title); + item = gtk_menu_item_new_with_label (s); g_free (s); - gtk_object_set_data((GtkObject *)item, "part", part); - gtk_signal_connect((GtkObject *)item, "activate", option_activate, data); - gtk_menu_append(menu, (GtkWidget *)item); - gtk_widget_show((GtkWidget *)item); - if (!strcmp(newpart->title, part->title)) { + + gtk_object_set_data (GTK_OBJECT (item), "part", part); + gtk_signal_connect (GTK_OBJECT (item), "activate", option_activate, data); + gtk_menu_append (GTK_MENU (menu), item); + gtk_widget_show (item); + + if (!strcmp (newpart->title, part->title)) { current = index; } index++; } - - omenu = (GtkOptionMenu *)gtk_option_menu_new(); - gtk_option_menu_set_menu(omenu, (GtkWidget *)menu); - gtk_option_menu_set_history(omenu, current); - gtk_widget_show((GtkWidget *)omenu); - - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)omenu, FALSE, FALSE, 0); + + omenu = gtk_option_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); + gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), current); + gtk_widget_show (omenu); + + gtk_box_pack_start (GTK_BOX (hbox), omenu, FALSE, FALSE, 0); if (p) { - gtk_box_pack_start((GtkBox *)hbox, p, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), p, FALSE, FALSE, 0); } - gtk_widget_show_all((GtkWidget *)hbox); - - return (GtkWidget *)hbox; + gtk_widget_show_all (hbox); + + return hbox; } struct _rule_data { @@ -322,94 +336,113 @@ struct _rule_data { }; static void -less_parts(GtkWidget *button, struct _rule_data *data) +less_parts (GtkWidget *widget, struct _rule_data *data) { GList *l; FilterPart *part; GtkWidget *w; - + l = ((FilterFilter *)data->fr)->actions; - if (g_list_length(l) < 2) + if (g_list_length (l) < 2) return; - + /* remove the last one from the list */ - l = g_list_last(l); + l = g_list_last (l); part = l->data; - filter_filter_remove_action((FilterFilter *)data->fr, part); - gtk_object_unref((GtkObject *)part); - + filter_filter_remove_action ((FilterFilter *)data->fr, part); + gtk_object_unref (GTK_OBJECT (part)); + /* and from the display */ - l = g_list_last(GTK_BOX(data->parts)->children); - w = ((GtkBoxChild *)l->data)->widget; - gtk_container_remove((GtkContainer *)data->parts, w); + l = g_list_last (GTK_BOX (data->parts)->children); + w = ((GtkBoxChild *) l->data)->widget; + gtk_container_remove (GTK_CONTAINER (data->parts), w); } static void -more_parts(GtkWidget *button, struct _rule_data *data) +more_parts (GtkWidget *widget, struct _rule_data *data) { FilterPart *new; GtkWidget *w; - + /* create a new rule entry, use the first type of rule */ - new = filter_context_next_action((FilterContext *)data->f, NULL); + new = filter_context_next_action ((FilterContext *)data->f, NULL); if (new) { - new = filter_part_clone(new); - filter_filter_add_action((FilterFilter *)data->fr, new); - w = get_rule_part_widget(data->f, new, data->fr); - gtk_box_pack_start((GtkBox *)data->parts, w, FALSE, FALSE, 0); + new = filter_part_clone (new); + filter_filter_add_action ((FilterFilter *)data->fr, new); + w = get_rule_part_widget (data->f, new, data->fr); + gtk_box_pack_start (GTK_BOX (data->parts), w, FALSE, FALSE, 0); } } -static GtkWidget *get_widget(FilterRule *fr, struct _RuleContext *f) +static GtkWidget * +get_widget (FilterRule *fr, struct _RuleContext *f) { GtkWidget *widget; - GtkVBox *parts, *inframe; - GtkHBox *hbox; + GtkWidget *parts, *inframe; + GtkWidget *hbox; + GtkWidget *button, *pixmap; GtkWidget *w; - GtkFrame *frame; + GtkWidget *frame; + GtkWidget *scrolledwindow; + GtkObject *hadj, *vadj; GList *l; FilterPart *part; struct _rule_data *data; FilterFilter *ff = (FilterFilter *)fr; - - d(printf("filter filter.get widget\n")); - - widget = ((FilterRuleClass *)(parent_class))->get_widget(fr, f); - + + widget = ((FilterRuleClass *)(parent_class))->get_widget (fr, f); + /* and now for the action area */ - frame = (GtkFrame *)gtk_frame_new("Perform actions"); - inframe = (GtkVBox *)gtk_vbox_new(FALSE, 3); - gtk_container_add((GtkContainer *)frame, (GtkWidget *)inframe); + frame = gtk_frame_new (_("Then")); + inframe = gtk_vbox_new (FALSE, 3); + gtk_container_add (GTK_CONTAINER (frame), inframe); - parts = (GtkVBox *)gtk_vbox_new(FALSE, 3); - data = g_malloc0(sizeof(*data)); + parts = gtk_vbox_new (FALSE, 3); + data = g_malloc0 (sizeof (*data)); data->f = (FilterContext *)f; data->fr = fr; - data->parts = (GtkWidget *)parts; + data->parts = parts; + + hbox = gtk_hbox_new (FALSE, 3); + + pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_ADD); + button = gnome_pixmap_button (pixmap, _("Add action")); + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_signal_connect (GTK_OBJECT (button), "clicked", more_parts, data); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 3); + + pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_REMOVE); + button = gnome_pixmap_button (pixmap, _("Remove action")); + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_signal_connect (GTK_OBJECT (button), "clicked", less_parts, data); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 3); + + gtk_box_pack_start (GTK_BOX (inframe), hbox, FALSE, FALSE, 3); l = ff->actions; while (l) { part = l->data; - d(printf("adding action %s\n", part->title)); - w = get_rule_part_widget((FilterContext *)f, part, fr); - gtk_box_pack_start((GtkBox *)parts, (GtkWidget *)w, FALSE, FALSE, 3); - l = g_list_next(l); + d(printf ("adding action %s\n", part->title)); + w = get_rule_part_widget ((FilterContext *)f, part, fr); + gtk_box_pack_start (GTK_BOX (parts), w, FALSE, FALSE, 3); + l = g_list_next (l); } - gtk_box_pack_start((GtkBox *)inframe, (GtkWidget *)parts, FALSE, FALSE, 3); - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 3); - w = gtk_button_new_with_label(_("Less")); - gtk_signal_connect((GtkObject *)w, "clicked", less_parts, data); - gtk_box_pack_end((GtkBox *)hbox, (GtkWidget *)w, FALSE, FALSE, 3); - w = gtk_button_new_with_label(_("More")); - gtk_signal_connect((GtkObject *)w, "clicked", more_parts, data); - gtk_box_pack_end((GtkBox *)hbox, (GtkWidget *)w, FALSE, FALSE, 3); - gtk_box_pack_start((GtkBox *)inframe, (GtkWidget *)hbox, FALSE, FALSE, 3); - - gtk_widget_show_all((GtkWidget *)frame); - - gtk_box_pack_start((GtkBox *)widget, (GtkWidget *)frame, FALSE, FALSE, 3); - + hadj = gtk_adjustment_new (0.0, 0.0, 1.0, 1.0 ,1.0, 1.0); + vadj = gtk_adjustment_new (0.0, 0.0, 1.0, 1.0 ,1.0, 1.0); + scrolledwindow = gtk_scrolled_window_new (GTK_ADJUSTMENT (hadj), GTK_ADJUSTMENT (vadj)); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), parts); + + gtk_box_pack_start (GTK_BOX (inframe), scrolledwindow, FALSE, FALSE, 3); + + /*gtk_box_pack_start (GTK_BOX (inframe), parts, FALSE, FALSE, 3);*/ + + gtk_widget_show_all (frame); + + gtk_box_pack_start (GTK_BOX (widget), frame, FALSE, FALSE, 3); + return widget; } - diff --git a/filter/filter-message-search.c b/filter/filter-message-search.c index 9f87b9f97c..4f351b0829 100644 --- a/filter/filter-message-search.c +++ b/filter/filter-message-search.c @@ -22,7 +22,6 @@ #include "filter-message-search.h" #include <e-util/e-sexp.h> -#include <gal/util/e-util.h> #include <regex.h> typedef struct { diff --git a/filter/filter-rule.c b/filter/filter-rule.c index f403237ec7..33dc290c80 100644 --- a/filter/filter-rule.c +++ b/filter/filter-rule.c @@ -2,6 +2,7 @@ * Copyright (C) 2000 Helix Code Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@helixcode.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -29,14 +30,14 @@ #define d(x) -static xmlNodePtr xml_encode(FilterRule *); -static int xml_decode(FilterRule *, xmlNodePtr, RuleContext *); -static void build_code(FilterRule *, GString *out); -static GtkWidget *get_widget(FilterRule *fr, struct _RuleContext *f); +static xmlNodePtr xml_encode (FilterRule *); +static int xml_decode (FilterRule *, xmlNodePtr, RuleContext *); +static void build_code (FilterRule *, GString *out); +static GtkWidget *get_widget (FilterRule *fr, struct _RuleContext *f); -static void filter_rule_class_init (FilterRuleClass *class); -static void filter_rule_init (FilterRule *gspaper); -static void filter_rule_finalise (GtkObject *obj); +static void filter_rule_class_init (FilterRuleClass *class); +static void filter_rule_init (FilterRule *gspaper); +static void filter_rule_finalise (GtkObject *obj); #define _PRIVATE(x) (((FilterRule *)(x))->priv) @@ -68,7 +69,7 @@ filter_rule_get_type (void) (GtkArgGetFunc)NULL }; - type = gtk_type_unique(gtk_object_get_type (), &type_info); + type = gtk_type_unique (gtk_object_get_type (), &type_info); } return type; @@ -80,45 +81,45 @@ filter_rule_class_init (FilterRuleClass *class) GtkObjectClass *object_class; object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class(gtk_object_get_type ()); - + parent_class = gtk_type_class (gtk_object_get_type ()); + object_class->finalize = filter_rule_finalise; - + /* override methods */ class->xml_encode = xml_encode; class->xml_decode = xml_decode; class->build_code = build_code; class->get_widget = get_widget; - + /* signals */ - - gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL); + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); } static void filter_rule_init (FilterRule *o) { - o->priv = g_malloc0(sizeof(*o->priv)); + o->priv = g_malloc0 (sizeof (*o->priv)); } static void -unref_list(GList *l) +unref_list (GList *l) { while (l) { - gtk_object_unref((GtkObject *)l->data); - l = g_list_next(l); + gtk_object_unref (GTK_OBJECT (l->data)); + l = g_list_next (l); } } static void -filter_rule_finalise(GtkObject *obj) +filter_rule_finalise (GtkObject *obj) { FilterRule *o = (FilterRule *)obj; - - g_free(o->name); - unref_list(o->parts); - - ((GtkObjectClass *)(parent_class))->finalize(obj); + + g_free (o->name); + unref_list (o->parts); + + ((GtkObjectClass *)(parent_class))->finalize (obj); } /** @@ -129,114 +130,120 @@ filter_rule_finalise(GtkObject *obj) * Return value: A new #FilterRule object. **/ FilterRule * -filter_rule_new(void) +filter_rule_new (void) { - FilterRule *o = (FilterRule *)gtk_type_new(filter_rule_get_type ()); + FilterRule *o = (FilterRule *)gtk_type_new (filter_rule_get_type ()); return o; } -void filter_rule_set_name (FilterRule *fr, const char *name) +void +filter_rule_set_name (FilterRule *fr, const char *name) { - g_free(fr->name); - fr->name = g_strdup(name); + g_free (fr->name); + fr->name = g_strdup (name); } -xmlNodePtr filter_rule_xml_encode (FilterRule *fr) +xmlNodePtr +filter_rule_xml_encode (FilterRule *fr) { - return ((FilterRuleClass *)((GtkObject *)fr)->klass)->xml_encode(fr); + return ((FilterRuleClass *)((GtkObject *)fr)->klass)->xml_encode (fr); } -static xmlNodePtr xml_encode(FilterRule *fr) +static xmlNodePtr +xml_encode (FilterRule *fr) { xmlNodePtr node, set, work; GList *l; - - node = xmlNewNode(NULL, "rule"); + + node = xmlNewNode (NULL, "rule"); switch (fr->grouping) { case FILTER_GROUP_ALL: - xmlSetProp(node, "grouping", "all"); + xmlSetProp (node, "grouping", "all"); break; case FILTER_GROUP_ANY: - xmlSetProp(node, "grouping", "any"); + xmlSetProp (node, "grouping", "any"); break; } - + switch (fr->source) { case FILTER_SOURCE_INCOMING: - xmlSetProp(node, "source", "incoming"); + xmlSetProp (node, "source", "incoming"); break; case FILTER_SOURCE_DEMAND: - xmlSetProp(node, "source", "ondemand"); + xmlSetProp (node, "source", "ondemand"); break; case FILTER_SOURCE_OUTGOING: - xmlSetProp(node, "source", "outgoing"); + xmlSetProp (node, "source", "outgoing"); break; } - + if (fr->name) { - work = xmlNewNode(NULL, "title"); - xmlNodeSetContent(work, fr->name); - xmlAddChild(node, work); + work = xmlNewNode (NULL, "title"); + xmlNodeSetContent (work, fr->name); + xmlAddChild (node, work); } - set = xmlNewNode(NULL, "partset"); - xmlAddChild(node, set); + set = xmlNewNode (NULL, "partset"); + xmlAddChild (node, set); l = fr->parts; while (l) { - work = filter_part_xml_encode((FilterPart *)l->data); - xmlAddChild(set, work); - l = g_list_next(l); + work = filter_part_xml_encode ((FilterPart *)l->data); + xmlAddChild (set, work); + l = g_list_next (l); } return node; } -static void load_set(xmlNodePtr node, FilterRule *fr, RuleContext *f) +static void +load_set (xmlNodePtr node, FilterRule *fr, RuleContext *f) { xmlNodePtr work; char *rulename; FilterPart *part; - + work = node->childs; while (work) { - if (!strcmp(work->name, "part")) { - rulename = xmlGetProp(work, "name"); - part = rule_context_find_part(f, rulename); + if (!strcmp (work->name, "part")) { + rulename = xmlGetProp (work, "name"); + part = rule_context_find_part (f, rulename); if (part) { - part = filter_part_clone(part); - filter_part_xml_decode(part, work); - filter_rule_add_part(fr, part); + part = filter_part_clone (part); + filter_part_xml_decode (part, work); + filter_rule_add_part (fr, part); } else { - g_warning("cannot find rule part '%s'\n", rulename); + g_warning ("cannot find rule part '%s'\n", rulename); } - xmlFree(rulename); + xmlFree (rulename); } else { - g_warning("Unknwon xml node in part: %s", work->name); + g_warning ("Unknwon xml node in part: %s", work->name); } work = work->next; } } -int filter_rule_xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) +int +filter_rule_xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) { - return ((FilterRuleClass *)((GtkObject *)fr)->klass)->xml_decode(fr, node, f); + return ((FilterRuleClass *)((GtkObject *)fr)->klass)->xml_decode (fr, node, f); } -static int xml_decode(FilterRule *fr, xmlNodePtr node, RuleContext *f) +static int +xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) { xmlNodePtr work; char *grouping; char *source; - + if (fr->name) { - g_free(fr->name); + g_free (fr->name); fr->name = NULL; } - - grouping = xmlGetProp(node, "grouping"); - if (!strcmp(grouping, "any")) + + grouping = xmlGetProp (node, "grouping"); + if (!strcmp (grouping, "any")) fr->grouping = FILTER_GROUP_ANY; else fr->grouping = FILTER_GROUP_ALL; - + /* FIXME: free source and grouping? */ source = xmlGetProp (node, "source"); if (!source) /*default to incoming*/ @@ -251,77 +258,80 @@ static int xml_decode(FilterRule *fr, xmlNodePtr node, RuleContext *f) g_warning ("Unknown filter source type \"%s\"", source); fr->source = FILTER_SOURCE_INCOMING; } - + work = node->childs; while (work) { - if (!strcmp(work->name, "partset")) { - load_set(work, fr, f); - } else if (!strcmp(work->name, "title")) { + if (!strcmp (work->name, "partset")) { + load_set (work, fr, f); + } else if (!strcmp (work->name, "title")) { if (!fr->name) - fr->name = xmlNodeGetContent(work); + fr->name = xmlNodeGetContent (work); } work = work->next; } + return 0; } -void filter_rule_add_part (FilterRule *fr, FilterPart *fp) +void +filter_rule_add_part (FilterRule *fr, FilterPart *fp) { - fr->parts = g_list_append(fr->parts, fp); + fr->parts = g_list_append (fr->parts, fp); } -void filter_rule_remove_part (FilterRule *fr, FilterPart *fp) +void +filter_rule_remove_part (FilterRule *fr, FilterPart *fp) { - fr->parts = g_list_remove(fr->parts, fp); + fr->parts = g_list_remove (fr->parts, fp); } -void filter_rule_replace_part(FilterRule *fr, FilterPart *fp, FilterPart *new) +void +filter_rule_replace_part (FilterRule *fr, FilterPart *fp, FilterPart *new) { GList *l; - - l = g_list_find(fr->parts, fp); + + l = g_list_find (fr->parts, fp); if (l) { l->data = new; } else { - fr->parts = g_list_append(fr->parts, new); + fr->parts = g_list_append (fr->parts, new); } } -void filter_rule_build_code (FilterRule *fr, GString *out) +void +filter_rule_build_code (FilterRule *fr, GString *out) { - return ((FilterRuleClass *)((GtkObject *)fr)->klass)->build_code(fr, out); + return ((FilterRuleClass *)((GtkObject *)fr)->klass)->build_code (fr, out); } -static void build_code(FilterRule *fr, GString *out) +static void +build_code (FilterRule *fr, GString *out) { switch (fr->grouping) { case FILTER_GROUP_ALL: - g_string_append(out, " (and\n "); + g_string_append (out, " (and\n "); break; case FILTER_GROUP_ANY: - g_string_append(out, " (or\n "); + g_string_append (out, " (or\n "); break; default: - g_warning("Invalid grouping"); + g_warning ("Invalid grouping"); } - - filter_part_build_code_list(fr->parts, out); - g_string_append(out, ")\n"); + + filter_part_build_code_list (fr->parts, out); + g_string_append (out, ")\n"); } - static void -match_all(GtkRadioButton *w, FilterRule *fr) +match_all (GtkWidget *widget, FilterRule *fr) { - if (gtk_toggle_button_get_active((GtkToggleButton *)w)) - fr->grouping = FILTER_GROUP_ALL; + fr->grouping = FILTER_GROUP_ALL; } static void -match_any(GtkRadioButton *w, FilterRule *fr) +match_any (GtkWidget *widget, FilterRule *fr) { - if (gtk_toggle_button_get_active((GtkToggleButton *)w)) - fr->grouping = FILTER_GROUP_ANY; + fr->grouping = FILTER_GROUP_ANY; } struct _part_data { @@ -331,83 +341,84 @@ struct _part_data { GtkWidget *partwidget, *container; }; -static void option_activate(GtkMenuItem *item, struct _part_data *data) +static void +option_activate (GtkMenuItem *item, struct _part_data *data) { - FilterPart *part = gtk_object_get_data((GtkObject *)item, "part"); + FilterPart *part = gtk_object_get_data (GTK_OBJECT (item), "part"); FilterPart *newpart; - + /* dont update if we haven't changed */ - if (!strcmp(part->title, data->part->title)) + if (!strcmp (part->title, data->part->title)) return; - + /* here we do a widget shuffle, throw away the old widget/rulepart, and create another */ if (data->partwidget) - gtk_container_remove((GtkContainer *)data->container, data->partwidget); - newpart = filter_part_clone(part); - filter_rule_replace_part(data->fr, data->part, newpart); - gtk_object_unref((GtkObject *)data->part); + gtk_container_remove (GTK_CONTAINER (data->container), data->partwidget); + newpart = filter_part_clone (part); + filter_rule_replace_part (data->fr, data->part, newpart); + gtk_object_unref (GTK_OBJECT (data->part)); data->part = newpart; - data->partwidget = filter_part_get_widget(newpart); + data->partwidget = filter_part_get_widget (newpart); if (data->partwidget) - gtk_box_pack_start((GtkBox *)data->container, data->partwidget, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (data->container), data->partwidget, FALSE, FALSE, 0); } static GtkWidget * -get_rule_part_widget(RuleContext *f, FilterPart *newpart, FilterRule *fr) +get_rule_part_widget (RuleContext *f, FilterPart *newpart, FilterRule *fr) { FilterPart *part = NULL; - GtkMenu *menu; - GtkMenuItem *item; - GtkOptionMenu *omenu; - GtkHBox *hbox; + GtkWidget *menu; + GtkWidget *item; + GtkWidget *omenu; + GtkWidget *hbox; GtkWidget *p; - int index=0, current=0; + int index = 0, current = 0; struct _part_data *data; gchar *s; - - data = g_malloc0(sizeof(*data)); + + data = g_malloc0 (sizeof (*data)); data->fr = fr; data->f = f; data->part = newpart; - - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 0); + + hbox = gtk_hbox_new (FALSE, 0); /* only set to automatically clean up the memory */ - gtk_object_set_data_full((GtkObject *)hbox, "data", data, g_free); - - p = filter_part_get_widget(newpart); - + gtk_object_set_data_full (GTK_OBJECT (hbox), "data", data, g_free); + + p = filter_part_get_widget (newpart); + data->partwidget = p; - data->container = (GtkWidget *)hbox; - - menu = (GtkMenu *)gtk_menu_new(); + data->container = hbox; + + menu = gtk_menu_new (); /* sigh, this is a little ugly */ - while ((part=rule_context_next_part(f, part))) { - s = e_utf8_to_gtk_string ((GtkWidget *) menu, part->title); - item = (GtkMenuItem *)gtk_menu_item_new_with_label (s); + while ((part = rule_context_next_part (f, part))) { + s = e_utf8_to_gtk_string (menu, part->title); + item = gtk_menu_item_new_with_label (s); g_free (s); - gtk_object_set_data((GtkObject *)item, "part", part); - gtk_signal_connect((GtkObject *)item, "activate", option_activate, data); - gtk_menu_append(menu, (GtkWidget *)item); - gtk_widget_show((GtkWidget *)item); - if (!strcmp(newpart->title, part->title)) { + gtk_object_set_data (GTK_OBJECT (item), "part", part); + gtk_signal_connect (GTK_OBJECT (item), "activate", option_activate, data); + gtk_menu_append (GTK_MENU (menu), item); + gtk_widget_show (item); + if (!strcmp (newpart->title, part->title)) { current = index; } index++; } - - omenu = (GtkOptionMenu *)gtk_option_menu_new(); - gtk_option_menu_set_menu(omenu, (GtkWidget *)menu); - gtk_option_menu_set_history(omenu, current); - gtk_widget_show((GtkWidget *)omenu); - - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)omenu, FALSE, FALSE, 0); + + omenu = gtk_option_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); + gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), current); + gtk_widget_show (omenu); + + gtk_box_pack_start (GTK_BOX (hbox), omenu, FALSE, FALSE, 0); if (p) { - gtk_box_pack_start((GtkBox *)hbox, p, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), p, FALSE, FALSE, 0); } - gtk_widget_show_all((GtkWidget *)hbox); - - return (GtkWidget *)hbox; + gtk_widget_show_all (hbox); + + return hbox; } struct _rule_data { @@ -417,163 +428,207 @@ struct _rule_data { }; static void -less_parts(GtkWidget *button, struct _rule_data *data) +less_parts (GtkWidget *button, struct _rule_data *data) { GList *l; FilterPart *part; GtkWidget *w; - + l = data->fr->parts; - if (g_list_length(l) < 2) + if (g_list_length (l) < 2) return; - + /* remove the last one from the list */ - l = g_list_last(l); + l = g_list_last (l); part = l->data; - filter_rule_remove_part(data->fr, part); - gtk_object_unref((GtkObject *)part); - + filter_rule_remove_part (data->fr, part); + gtk_object_unref ((GtkObject *)part); + /* and from the display */ - l = g_list_last(GTK_BOX(data->parts)->children); + l = g_list_last (GTK_BOX(data->parts)->children); w = ((GtkBoxChild *)l->data)->widget; - gtk_container_remove((GtkContainer *)data->parts, w); + gtk_container_remove (GTK_CONTAINER (data->parts), w); } static void -more_parts(GtkWidget *button, struct _rule_data *data) +more_parts (GtkWidget *button, struct _rule_data *data) { FilterPart *new; GtkWidget *w; - + /* create a new rule entry, use the first type of rule */ - new = rule_context_next_part(data->f, NULL); + new = rule_context_next_part (data->f, NULL); if (new) { - new = filter_part_clone(new); - filter_rule_add_part(data->fr, new); - w = get_rule_part_widget(data->f, new, data->fr); - gtk_box_pack_start((GtkBox *)data->parts, w, FALSE, FALSE, 0); + new = filter_part_clone (new); + filter_rule_add_part (data->fr, new); + w = get_rule_part_widget (data->f, new, data->fr); + gtk_box_pack_start (GTK_BOX (data->parts), w, FALSE, FALSE, 0); } } static void -name_changed(GtkEntry *entry, FilterRule *fr) +name_changed (GtkEntry *entry, FilterRule *fr) { - g_free(fr->name); - fr->name = e_utf8_gtk_entry_get_text(entry); + g_free (fr->name); + fr->name = e_utf8_gtk_entry_get_text (entry); } -GtkWidget *filter_rule_get_widget (FilterRule *fr, struct _RuleContext *f) +GtkWidget * +filter_rule_get_widget (FilterRule *fr, struct _RuleContext *f) { - return ((FilterRuleClass *)((GtkObject *)fr)->klass)->get_widget(fr, f); + return ((FilterRuleClass *)((GtkObject *)fr)->klass)->get_widget (fr, f); } -static GtkWidget *get_widget(FilterRule *fr, struct _RuleContext *f) +static GtkWidget * +get_widget (FilterRule *fr, struct _RuleContext *f) { - GtkVBox *vbox, *parts, *inframe; - GtkHBox *hbox; + GtkWidget *vbox, *parts, *inframe; + GtkWidget *hbox; + GtkWidget *button, *pixmap; GtkWidget *w; - GtkRadioButton *g0, *g1; - GtkFrame *frame; - GtkEntry *name; - GtkLabel *label; + GtkWidget *menu, *item, *omenu; + GtkWidget *frame; + GtkWidget *name; + GtkWidget *label; + GtkWidget *scrolledwindow; + GtkObject *hadj, *vadj; GList *l; FilterPart *part; + char *string; struct _rule_data *data; - + /* this stuff should probably be a table, but the rule parts need to be a vbox */ - vbox = (GtkVBox *)gtk_vbox_new(FALSE, 3); - - label = (GtkLabel *)gtk_label_new("Name"); - name = (GtkEntry *)gtk_entry_new(); + vbox = gtk_vbox_new (FALSE, 3); + + label = gtk_label_new (_("Rule name: ")); + name = gtk_entry_new (); + + if (!fr->name) + fr->name = g_strdup (_("untitled")); + if (fr->name) - e_utf8_gtk_entry_set_text(name, fr->name); - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 3); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)label, FALSE, FALSE, 0); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)name, TRUE, TRUE, 0); - gtk_box_pack_start((GtkBox *)vbox, (GtkWidget *)hbox, FALSE, FALSE, 3); - gtk_signal_connect((GtkObject *)name, "changed", name_changed, fr); - - frame = (GtkFrame *)gtk_frame_new("Messages matching"); - inframe = (GtkVBox *)gtk_vbox_new(FALSE, 3); - gtk_container_add((GtkContainer *)frame, (GtkWidget *)inframe); - - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 3); - g0 = (GtkRadioButton *)gtk_radio_button_new_with_label(NULL, "Match all parts"); - g1 = (GtkRadioButton *)gtk_radio_button_new_with_label(g0->group, "Match any part"); - if (fr->grouping == FILTER_GROUP_ALL) { - gtk_toggle_button_set_active((GtkToggleButton *)g0, TRUE); - } else { - gtk_toggle_button_set_active((GtkToggleButton *)g1, TRUE); - } - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)g0, FALSE, FALSE, 0); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)g1, FALSE, FALSE, 0); - gtk_box_pack_start((GtkBox *)inframe, (GtkWidget *)hbox, FALSE, FALSE, 3); - - gtk_signal_connect((GtkObject *)g0, "toggled", match_all, fr); - gtk_signal_connect((GtkObject *)g1, "toggled", match_any, fr); - + e_utf8_gtk_entry_set_text (GTK_ENTRY (name), fr->name); + + hbox = gtk_hbox_new (FALSE, 3); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), name, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 3); + gtk_signal_connect (GTK_OBJECT (name), "changed", name_changed, fr); + + frame = gtk_frame_new (_("If")); + inframe = gtk_vbox_new (FALSE, 3); + gtk_container_add (GTK_CONTAINER (frame), inframe); + /* this is the parts list, it should probably be inside a scrolling list */ - parts = (GtkVBox *)gtk_vbox_new(FALSE, 3); - + parts = gtk_vbox_new (FALSE, 3); + /* data for the parts part of the display */ - data = g_malloc0(sizeof(*data)); + data = g_malloc0 (sizeof (*data)); data->f = f; data->fr = fr; - data->parts = (GtkWidget *)parts; - + data->parts = parts; + /* only set to automatically clean up the memory */ - gtk_object_set_data_full((GtkObject *)vbox, "data", data, g_free); - + gtk_object_set_data_full (GTK_OBJECT (vbox), "data", data, g_free); + + hbox = gtk_hbox_new (FALSE, 3); + label = gtk_label_new (_("Execute actions")); + + menu = gtk_menu_new (); + + string = e_utf8_to_gtk_string (menu, _("if all criteria are met")); + item = gtk_menu_item_new_with_label (string); + g_free (string); + gtk_signal_connect (GTK_OBJECT (item), "activate", match_all, fr); + gtk_menu_append (GTK_MENU (menu), item); + gtk_widget_show (item); + + string = e_utf8_to_gtk_string (menu, _("if any criteria are met")); + item = gtk_menu_item_new_with_label (string); + g_free (string); + gtk_signal_connect (GTK_OBJECT (item), "activate", match_any, fr); + gtk_menu_append (GTK_MENU (menu), item); + gtk_widget_show (item); + + omenu = gtk_option_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); + gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), + fr->grouping == FILTER_GROUP_ALL ? 0 : 1); + gtk_widget_show (omenu); + + pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_ADD); + button = gnome_pixmap_button (pixmap, _("Add criterion")); + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_signal_connect (GTK_OBJECT (button), "clicked", more_parts, data); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 3); + + pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_REMOVE); + button = gnome_pixmap_button (pixmap, _("Remove criterion")); + gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_signal_connect (GTK_OBJECT (button), "clicked", less_parts, data); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 3); + + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), omenu, FALSE, FALSE, 0); + + gtk_box_pack_start (GTK_BOX (inframe), hbox, FALSE, FALSE, 3); + l = fr->parts; while (l) { part = l->data; - w = get_rule_part_widget(f, part, fr); - gtk_box_pack_start((GtkBox *)parts, (GtkWidget *)w, FALSE, FALSE, 3); - l = g_list_next(l); + w = get_rule_part_widget (f, part, fr); + gtk_box_pack_start (GTK_BOX (parts), w, FALSE, FALSE, 3); + l = g_list_next (l); } - - gtk_box_pack_start((GtkBox *)inframe, (GtkWidget *)parts, FALSE, FALSE, 3); - - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 3); - w = gtk_button_new_with_label(_("Less")); - gtk_signal_connect((GtkObject *)w, "clicked", less_parts, data); - gtk_box_pack_end((GtkBox *)hbox, (GtkWidget *)w, FALSE, FALSE, 3); - w = gtk_button_new_with_label(_("More")); - gtk_signal_connect((GtkObject *)w, "clicked", more_parts, data); - gtk_box_pack_end((GtkBox *)hbox, (GtkWidget *)w, FALSE, FALSE, 3); - gtk_box_pack_start((GtkBox *)inframe, (GtkWidget *)hbox, FALSE, FALSE, 3); - - gtk_box_pack_start((GtkBox *)vbox, (GtkWidget *)frame, FALSE, FALSE, 3); - - gtk_widget_show_all((GtkWidget *)vbox); - return (GtkWidget *)vbox; + + hadj = gtk_adjustment_new (0.0, 0.0, 1.0, 1.0 ,1.0, 1.0); + vadj = gtk_adjustment_new (0.0, 0.0, 1.0, 1.0 ,1.0, 1.0); + scrolledwindow = gtk_scrolled_window_new (GTK_ADJUSTMENT (hadj), GTK_ADJUSTMENT (vadj)); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), parts); + + gtk_box_pack_start (GTK_BOX (inframe), scrolledwindow, FALSE, FALSE, 3); + + /*gtk_box_pack_start (GTK_BOX (inframe), parts, FALSE, FALSE, 3);*/ + + gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 3); + + gtk_widget_show_all (vbox); + + return vbox; } -FilterRule *filter_rule_next_list (GList *l, FilterRule *last) +FilterRule * +filter_rule_next_list (GList *l, FilterRule *last) { GList *node = l; - + if (last != NULL) { - node = g_list_find(node, last); + node = g_list_find (node, last); if (node == NULL) node = l; else - node = g_list_next(node); + node = g_list_next (node); } + if (node) return node->data; + return NULL; } -FilterRule *filter_rule_find_list (GList *l, const char *name) +FilterRule * +filter_rule_find_list (GList *l, const char *name) { while (l) { FilterRule *rule = l->data; - if (!strcmp(rule->name, name)) + if (!strcmp (rule->name, name)) return rule; - l = g_list_next(l); + l = g_list_next (l); } + return NULL; } - diff --git a/filter/filter-score.c b/filter/filter-score.c index 03e969aa6e..5053998444 100644 --- a/filter/filter-score.c +++ b/filter/filter-score.c @@ -176,6 +176,11 @@ xml_decode (FilterElement *fe, xmlNodePtr node) else fs->score = 0; + if (fs->score > 3) + fs->score = 3; + else if (fs->score < -3) + fs->score = -3; + return 0; } @@ -194,7 +199,7 @@ get_widget (FilterElement *fe) GtkObject *adjustment; FilterScore *fs = (FilterScore *)fe; - adjustment = gtk_adjustment_new (0.0, -100.0, 100.0, 1.0, 1.0, 1.0); + adjustment = gtk_adjustment_new (0.0, -3.0, 3.0, 1.0, 1.0, 1.0); spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1.0, 0); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin), TRUE); diff --git a/filter/filtertypes.xml b/filter/filtertypes.xml index 73b17f75d2..43a6043124 100644 --- a/filter/filtertypes.xml +++ b/filter/filtertypes.xml @@ -15,6 +15,7 @@ </input> <input type="string" name="sender"/> </part> + <part name="to"> <title>Recipients</title> <input type="optionlist" name="recipient-type"> @@ -36,6 +37,7 @@ </input> <input type="address" name="recipient"/> </part> + <part name="subject"> <title>Subject</title> <input type="optionlist" name="subject-type"> @@ -56,7 +58,7 @@ </part> <part name="header"> - <title>Message header</title> + <title>Specific header</title> <input type="string" name="header-field"/> <input type="optionlist" name="header-type"> <option value="contains"> @@ -93,36 +95,37 @@ </input> <input type="string" name="word"/> </part> + <part name="sexp"> <title>Expression</title> <input type="code" name="code"/> - </part> + </part> <part name="sent-date"> - <title>Message was sent</title> + <title>Date sent</title> <input type="optionlist" name="date-spec-type"> - <option value="before"> - <title>before</title> + <option value="is"> + <title>is</title> <code> - (match-all (< (get-sent-date) ${versus})) + (match-all (= (get-sent-date) ${versus})) </code> </option> - <option value="on-or-before"> - <title>on or before</title> + <option value="is-not"> + <title>is not</title> <code> - (match-all (not (> (get-sent-date) ${versus}))) + (match-all (not (= (get-sent-date) ${versus}))) </code> </option> - <option value="after"> - <title>after</title> + <option value="before"> + <title>was before</title> <code> - (match-all (> (get-sent-date) ${versus})) + (match-all (< (get-sent-date) ${versus})) </code> </option> - <option value="on-or-after"> - <title>on or after</title> + <option value="after"> + <title>was after</title> <code> - (match-all (not (< (get-sent-date) ${versus}))) + (match-all (> (get-sent-date) ${versus})) </code> </option> </input> @@ -131,30 +134,30 @@ </part> <part name="recv-date"> - <title>Message was received</title> + <title>Date received</title> <input type="optionlist" name="date-spec-type"> - <option value="before"> - <title>before</title> + <option value="is"> + <title>is</title> <code> - (match-all (< (get-received-date) ${versus})) + (match-all (= (get-received-date) ${versus})) </code> </option> - <option value="on-or-before"> - <title>on or before</title> + <option value="is-not"> + <title>is not</title> <code> - (match-all (not (> (get-received-date) ${versus}))) + (match-all (not (= (get-received-date) ${versus}))) </code> </option> - <option value="after"> - <title>after</title> + <option value="before"> + <title>was before</title> <code> - (match-all (> (get-received-date) ${versus})) + (match-all (< (get-received-date) ${versus})) </code> </option> - <option value="on-or-after"> - <title>on or after</title> + <option value="after"> + <title>was after</title> <code> - (match-all (not (< (get-received-date) ${versus}))) + (match-all (> (get-received-date) ${versus})) </code> </option> </input> @@ -163,33 +166,33 @@ </part> <part name="score"> - <title>Message score</title> + <title>Priority</title> <input type="optionlist" name="score-type"> <option value="less-than"> - <title>less than</title> + <title>is</title> <code> - (match-all (< (get-score) ${versus})) + (match-all (= (get-score) ${versus})) </code> </option> - <option value="less-than-or-equal"> - <title>less than or equal to</title> + <option value="is-not"> + <title>is not</title> <code> - (match-all (not (> (get-score) ${versus}))) + (match-all (not (= (get-score) ${versus}))) </code> </option> <option value="greater-than"> - <title>greater than</title> + <title>is greater than</title> <code> (match-all (> (get-score) ${versus})) </code> </option> - <option value="greater-than-or-equal"> - <title>greater than or equal to</title> + <option value="less-than"> + <title>is less than</title> <code> - (match-all (not (< (get-score) ${versus}))) + (match-all (< (get-score) ${versus})) </code> </option> - </input> + </input> <input type="score" name="versus"> </input> </part> diff --git a/filter/score-rule.c b/filter/score-rule.c index 8eb51b6821..7ad73a8df3 100644 --- a/filter/score-rule.c +++ b/filter/score-rule.c @@ -2,6 +2,7 @@ * Copyright (C) 2000 Helix Code Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@helixcode.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -61,7 +62,7 @@ score_rule_get_type (void) (GtkArgGetFunc)NULL }; - type = gtk_type_unique(filter_rule_get_type (), &type_info); + type = gtk_type_unique (filter_rule_get_type (), &type_info); } return type; @@ -72,37 +73,37 @@ score_rule_class_init (ScoreRuleClass *class) { GtkObjectClass *object_class; FilterRuleClass *rule_class = (FilterRuleClass *)class; - + object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class(filter_rule_get_type ()); - + parent_class = gtk_type_class (filter_rule_get_type ()); + object_class->finalize = score_rule_finalise; - + /* override methods */ rule_class->xml_encode = xml_encode; rule_class->xml_decode = xml_decode; /* rule_class->build_code = build_code;*/ rule_class->get_widget = get_widget; - + /* signals */ - - gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL); + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); } static void score_rule_init (ScoreRule *o) { - o->priv = g_malloc0(sizeof(*o->priv)); + o->priv = g_malloc0 (sizeof (*o->priv)); } static void -score_rule_finalise(GtkObject *obj) +score_rule_finalise (GtkObject *obj) { ScoreRule *o = (ScoreRule *)obj; - + o = o; - - ((GtkObjectClass *)(parent_class))->finalize(obj); + + ((GtkObjectClass *)(parent_class))->finalize (obj); } /** @@ -113,44 +114,55 @@ score_rule_finalise(GtkObject *obj) * Return value: A new #ScoreRule object. **/ ScoreRule * -score_rule_new(void) +score_rule_new (void) { - ScoreRule *o = (ScoreRule *)gtk_type_new(score_rule_get_type ()); + ScoreRule *o = (ScoreRule *)gtk_type_new (score_rule_get_type ()); return o; } -static xmlNodePtr xml_encode(FilterRule *fr) +static xmlNodePtr +xml_encode (FilterRule *fr) { ScoreRule *sr = (ScoreRule *)fr; xmlNodePtr node, value; char number[16]; - - node = ((FilterRuleClass *)(parent_class))->xml_encode(fr); - sprintf(number, "%d", sr->score); - value = xmlNewNode(NULL, "score"); - xmlSetProp(value, "value", number); - xmlAddChild(node, value); + + node = ((FilterRuleClass *)(parent_class))->xml_encode (fr); + sprintf (number, "%d", sr->score); + value = xmlNewNode (NULL, "score"); + xmlSetProp (value, "value", number); + xmlAddChild (node, value); + return node; } -static int xml_decode(FilterRule *fr, xmlNodePtr node, struct _RuleContext *f) +static int +xml_decode (FilterRule *fr, xmlNodePtr node, struct _RuleContext *f) { ScoreRule *sr = (ScoreRule *)fr; xmlNodePtr value; int result; char *str; - - result = ((FilterRuleClass *)(parent_class))->xml_decode(fr, node, f); + + result = ((FilterRuleClass *)(parent_class))->xml_decode (fr, node, f); if (result != 0) return result; + value = node->childs; while (value) { - if (!strcmp(value->name, "score")) { - str = xmlGetProp(value, "value"); - sscanf(str, "%d", &sr->score); + if (!strcmp (value->name, "score")) { + str = xmlGetProp (value, "value"); + sscanf (str, "%d", &sr->score); + + /* score range is -3 to +3 */ + if (sr->score > 3) + sr->score = 3; + else if (sr->score < -3) + sr->score = -3; } value = value->next; } + return 0; } @@ -158,33 +170,40 @@ static int xml_decode(FilterRule *fr, xmlNodePtr node, struct _RuleContext *f) { }*/ -static void spin_changed(GtkAdjustment *adj, ScoreRule *sr) +static void +spin_changed (GtkAdjustment *adj, ScoreRule *sr) { sr->score = adj->value; } -static GtkWidget *get_widget(FilterRule *fr, struct _RuleContext *f) +static GtkWidget * +get_widget (FilterRule *fr, struct _RuleContext *f) { GtkWidget *widget; - GtkFrame *frame; - GtkLabel *label; - GtkHBox *hbox; + GtkWidget *frame; + GtkWidget *label; + GtkWidget *hbox; GtkAdjustment *adj; ScoreRule *sr = (ScoreRule *)fr; - GtkSpinButton *spin; - - widget = ((FilterRuleClass *)(parent_class))->get_widget(fr, f); - frame = (GtkFrame *)gtk_frame_new("Score"); - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 3); - label = (GtkLabel *)gtk_label_new("Score"); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)label, FALSE, FALSE, 3); - adj = (GtkAdjustment *)gtk_adjustment_new((float)sr->score, -100, 100, 1, 10, 10); - gtk_signal_connect((GtkObject *)adj, "value_changed", spin_changed, sr); - spin = (GtkSpinButton *)gtk_spin_button_new(adj, 1.0, 0); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)spin, FALSE, FALSE, 3); - gtk_container_add((GtkContainer *)frame, (GtkWidget *)hbox); - gtk_widget_show_all((GtkWidget *)frame); - - gtk_box_pack_start((GtkBox *)widget, (GtkWidget *)frame, FALSE, FALSE, 3); + GtkWidget *spin; + + widget = ((FilterRuleClass *)(parent_class))->get_widget (fr, f); + + frame = gtk_frame_new (_("Score")); + hbox = gtk_hbox_new (FALSE, 3); + label = gtk_label_new (_("Score")); + + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3); + adj = (GtkAdjustment *)gtk_adjustment_new ((float) sr->score, -3.0, 3.0, 1.0, 1.0, 1.0); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", spin_changed, sr); + + spin = gtk_spin_button_new (adj, 1.0, 0); + gtk_box_pack_start (GTK_BOX (hbox), spin, FALSE, FALSE, 3); + gtk_container_add (GTK_CONTAINER (frame), hbox); + + gtk_widget_show_all (frame); + + gtk_box_pack_start (GTK_BOX (widget), frame, FALSE, FALSE, 3); + return widget; } |