diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-09-13 06:06:46 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-09-13 06:06:46 +0800 |
commit | e01b1d7c259f148847e97d4c3e609933e26a73cf (patch) | |
tree | ec8f29ab4a07dd9bb64ec8e4c3b2223c2fbe9346 /filter | |
parent | 8be7f276a292ba85e6bec20fd7d5a351f094296e (diff) | |
download | gsoc2013-evolution-e01b1d7c259f148847e97d4c3e609933e26a73cf.tar gsoc2013-evolution-e01b1d7c259f148847e97d4c3e609933e26a73cf.tar.gz gsoc2013-evolution-e01b1d7c259f148847e97d4c3e609933e26a73cf.tar.bz2 gsoc2013-evolution-e01b1d7c259f148847e97d4c3e609933e26a73cf.tar.lz gsoc2013-evolution-e01b1d7c259f148847e97d4c3e609933e26a73cf.tar.xz gsoc2013-evolution-e01b1d7c259f148847e97d4c3e609933e26a73cf.tar.zst gsoc2013-evolution-e01b1d7c259f148847e97d4c3e609933e26a73cf.zip |
Clone the current rule before editing it so that changes can be undone.
2001-09-12 Jeffrey Stedfast <fejj@ximian.com>
* rule-editor.c (rule_edit): Clone the current rule before editing
it so that changes can be undone.
(edit_editor_clicked): If the user hit OK, replace the original
rule with the new one.
* vfolder-rule.c (vfolder_rule_finalise): Free the sources list.
(rule_copy): Implemented.
* filter-filter.c (rule_copy): Implemented.
* filter-rule.c (filter_rule_copy): New convenience function to
copy one rule "into" another.
(rule_copy): Default implementation.
(filter_rule_clone): Use filter_rule_copy() internally to get rid
of the nastiness/slowness of xml encoding and then decoding.
svn path=/trunk/; revision=12787
Diffstat (limited to 'filter')
-rw-r--r-- | filter/ChangeLog | 18 | ||||
-rw-r--r-- | filter/filter-filter.c | 29 | ||||
-rw-r--r-- | filter/filter-rule.c | 49 | ||||
-rw-r--r-- | filter/filter-rule.h | 6 | ||||
-rw-r--r-- | filter/libfilter-i18n.h | 36 | ||||
-rw-r--r-- | filter/rule-editor.c | 8 | ||||
-rw-r--r-- | filter/vfolder-rule.c | 34 |
7 files changed, 150 insertions, 30 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index 827efa6f0b..fcd6f22aed 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,21 @@ +2001-09-12 Jeffrey Stedfast <fejj@ximian.com> + + * rule-editor.c (rule_edit): Clone the current rule before editing + it so that changes can be undone. + (edit_editor_clicked): If the user hit OK, replace the original + rule with the new one. + + * vfolder-rule.c (vfolder_rule_finalise): Free the sources list. + (rule_copy): Implemented. + + * filter-filter.c (rule_copy): Implemented. + + * filter-rule.c (filter_rule_copy): New convenience function to + copy one rule "into" another. + (rule_copy): Default implementation. + (filter_rule_clone): Use filter_rule_copy() internally to get rid + of the nastiness/slowness of xml encoding and then decoding. + 2001-09-12 <NotZed@Ximian.com> * vfoldertypes.xml: Remove the match-all from the not diff --git a/filter/filter-filter.c b/filter/filter-filter.c index 145be391dd..50d29d2369 100644 --- a/filter/filter-filter.c +++ b/filter/filter-filter.c @@ -42,6 +42,7 @@ static int validate(FilterRule *); static xmlNodePtr xml_encode (FilterRule *); static int xml_decode (FilterRule *, xmlNodePtr, struct _RuleContext *f); +static void rule_copy (FilterRule *dest, FilterRule *src); /*static void build_code(FilterRule *, GString *out);*/ static GtkWidget *get_widget (FilterRule *fr, struct _RuleContext *f); @@ -100,6 +101,7 @@ filter_filter_class_init (FilterFilterClass *class) filter_rule->xml_encode = xml_encode; filter_rule->xml_decode = xml_decode; /*filter_rule->build_code = build_code;*/ + filter_rule->copy = rule_copy; filter_rule->get_widget = get_widget; /* signals */ @@ -269,6 +271,33 @@ xml_decode (FilterRule *fr, xmlNodePtr node, struct _RuleContext *f) return 0; } +static void +rule_copy (FilterRule *dest, FilterRule *src) +{ + FilterFilter *fdest, *fsrc; + GList *node; + + fdest = (FilterFilter *) dest; + fsrc = (FilterFilter *) src; + + if (fdest->actions) { + g_list_foreach (fdest->actions, (GFunc) gtk_object_unref, NULL); + g_list_free (fdest->actions); + fdest->actions = NULL; + } + + node = fsrc->actions; + while (node) { + FilterPart *part = node->data; + + gtk_object_ref (GTK_OBJECT (part)); + fdest->actions = g_list_append (fdest->actions, part); + node = node->next; + } + + ((FilterRuleClass *)(parent_class))->copy (dest, src); +} + /*static void build_code(FilterRule *fr, GString *out) { return ((FilterRuleClass *)(parent_class))->build_code(fr, out); diff --git a/filter/filter-rule.c b/filter/filter-rule.c index aff01a0f25..bf948ba299 100644 --- a/filter/filter-rule.c +++ b/filter/filter-rule.c @@ -42,6 +42,7 @@ static int validate(FilterRule *); static xmlNodePtr xml_encode (FilterRule *); static int xml_decode (FilterRule *, xmlNodePtr, RuleContext *); static void build_code (FilterRule *, GString * out); +static void rule_copy (FilterRule *dest, FilterRule *src); static GtkWidget *get_widget (FilterRule * fr, struct _RuleContext *f); static void filter_rule_class_init (FilterRuleClass * class); @@ -98,6 +99,7 @@ filter_rule_class_init (FilterRuleClass * class) class->xml_encode = xml_encode; class->xml_decode = xml_decode; class->build_code = build_code; + class->copy = rule_copy; class->get_widget = get_widget; /* signals */ @@ -142,19 +144,14 @@ filter_rule_new () } FilterRule * -filter_rule_clone(FilterRule *base, RuleContext *f) +filter_rule_clone (FilterRule *base) { - xmlNodePtr xml; FilterRule *rule; g_assert (IS_FILTER_RULE (base)); - g_assert (IS_RULE_CONTEXT (f)); - /* TODO: do this more directly/efficiently */ - xml = filter_rule_xml_encode (base); rule = gtk_type_new (GTK_OBJECT (base)->klass->type); - filter_rule_xml_decode (rule, xml, f); - xmlFreeNodeList (xml); + filter_rule_copy (rule, base); return rule; } @@ -340,6 +337,44 @@ xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) return 0; } +static void +rule_copy (FilterRule *dest, FilterRule *src) +{ + GList *node; + + g_free (dest->name); + dest->name = g_strdup (src->name); + + g_free (dest->source); + dest->source = g_strdup (src->source); + + dest->grouping = src->grouping; + + if (dest->parts) { + g_list_foreach (dest->parts, (GFunc) gtk_object_unref, NULL); + g_list_free (dest->parts); + dest->parts = NULL; + } + + node = src->parts; + while (node) { + FilterPart *part = node->data; + + gtk_object_ref (GTK_OBJECT (part)); + dest->parts = g_list_append (dest->parts, part); + node = node->next; + } +} + +void +filter_rule_copy (FilterRule *dest, FilterRule *src) +{ + g_assert (IS_FILTER_RULE (dest)); + g_assert (IS_FILTER_RULE (src)); + + ((FilterRuleClass *) ((GtkObject *) dest)->klass)->copy (dest, src); +} + void filter_rule_add_part (FilterRule *fr, FilterPart *fp) { diff --git a/filter/filter-rule.h b/filter/filter-rule.h index ffad99e627..41a10ca326 100644 --- a/filter/filter-rule.h +++ b/filter/filter-rule.h @@ -65,6 +65,8 @@ struct _FilterRuleClass { int (*xml_decode)(FilterRule *, xmlNodePtr, struct _RuleContext *); void (*build_code)(FilterRule *, GString *out); + + void (*copy)(FilterRule *dest, FilterRule *src); GtkWidget *(*get_widget)(FilterRule *fr, struct _RuleContext *f); @@ -74,7 +76,7 @@ struct _FilterRuleClass { guint filter_rule_get_type (void); FilterRule *filter_rule_new (void); -FilterRule *filter_rule_clone (FilterRule *base, struct _RuleContext *f); +FilterRule *filter_rule_clone (FilterRule *base); /* methods */ void filter_rule_set_name (FilterRule *fr, const char *name); @@ -85,6 +87,8 @@ int filter_rule_validate (FilterRule *fr); xmlNodePtr filter_rule_xml_encode (FilterRule *fr); int filter_rule_xml_decode (FilterRule *fr, xmlNodePtr node, struct _RuleContext *f); +void filter_rule_copy (FilterRule *dest, FilterRule *src); + void filter_rule_add_part (FilterRule *fr, FilterPart *fp); void filter_rule_remove_part (FilterRule *fr, FilterPart *fp); void filter_rule_replace_part(FilterRule *fr, FilterPart *fp, FilterPart *new); diff --git a/filter/libfilter-i18n.h b/filter/libfilter-i18n.h index 175eac2dc6..d3cc5cbb36 100644 --- a/filter/libfilter-i18n.h +++ b/filter/libfilter-i18n.h @@ -1,23 +1,39 @@ /* Automatically generated. Do not edit. */ +char *s = N_("after"); char *s = N_("Assign Color"); char *s = N_("Assign Score"); char *s = N_("Attachments"); +char *s = N_("before"); +char *s = N_("contains"); char *s = N_("Copy to Folder"); char *s = N_("Date received"); char *s = N_("Date sent"); char *s = N_("Delete"); char *s = N_("Deleted"); +char *s = N_("does not contain"); +char *s = N_("does not end with"); +char *s = N_("does not exist"); +char *s = N_("does not sound like"); +char *s = N_("does not start with"); char *s = N_("Do Not Exist"); char *s = N_("Draft"); +char *s = N_("ends with"); char *s = N_("Exist"); +char *s = N_("exists"); char *s = N_("Expression"); char *s = N_("Important"); +char *s = N_("is"); +char *s = N_("is greater than"); +char *s = N_("is less than"); +char *s = N_("is not"); char *s = N_("Mailing list"); char *s = N_("Message Body"); char *s = N_("Message Header"); char *s = N_("Message was received"); char *s = N_("Message was sent"); char *s = N_("Move to Folder"); +char *s = N_("on or after"); +char *s = N_("on or before"); char *s = N_("Read"); char *s = N_("Recipients"); char *s = N_("Regex Match"); @@ -26,28 +42,12 @@ char *s = N_("Score"); char *s = N_("Sender"); char *s = N_("Set Status"); char *s = N_("Size (kB)"); +char *s = N_("sounds like"); char *s = N_("Source Account"); char *s = N_("Specific header"); +char *s = N_("starts with"); char *s = N_("Status"); char *s = N_("Stop Processing"); char *s = N_("Subject"); -char *s = N_("after"); -char *s = N_("before"); -char *s = N_("contains"); -char *s = N_("does not contain"); -char *s = N_("does not end with"); -char *s = N_("does not exist"); -char *s = N_("does not sound like"); -char *s = N_("does not start with"); -char *s = N_("ends with"); -char *s = N_("exists"); -char *s = N_("is greater than"); -char *s = N_("is less than"); -char *s = N_("is not"); -char *s = N_("is"); -char *s = N_("on or after"); -char *s = N_("on or before"); -char *s = N_("sounds like"); -char *s = N_("starts with"); char *s = N_("was after"); char *s = N_("was before"); diff --git a/filter/rule-editor.c b/filter/rule-editor.c index 5a6718660d..e966ef89ad 100644 --- a/filter/rule-editor.c +++ b/filter/rule-editor.c @@ -271,6 +271,9 @@ edit_editor_clicked (GtkWidget *dialog, int button, RuleEditor *re) string = e_utf8_to_gtk_string (GTK_WIDGET (item), re->current->name); gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), string); g_free (string); + + /* replace the old rule with the new rule */ + filter_rule_copy (re->current, re->edit); } case 1: default: @@ -292,10 +295,9 @@ rule_edit (GtkWidget *widget, RuleEditor *re) if (re->current == NULL) return; - re->edit = re->current; - gtk_object_ref (GTK_OBJECT (re->edit)); + re->edit = filter_rule_clone (re->current); - rules = filter_rule_get_widget (re->current, re->context); + rules = filter_rule_get_widget (re->edit, re->context); dialog = gnome_dialog_new (_("Edit Rule"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, diff --git a/filter/vfolder-rule.c b/filter/vfolder-rule.c index 13e5337a18..5f122b5f1a 100644 --- a/filter/vfolder-rule.c +++ b/filter/vfolder-rule.c @@ -42,6 +42,7 @@ static gint validate(FilterRule *); static xmlNodePtr xml_encode(FilterRule *); static int xml_decode(FilterRule *, xmlNodePtr, struct _RuleContext *f); +static void rule_copy (FilterRule *dest, FilterRule *src); /*static void build_code(FilterRule *, GString *out);*/ static GtkWidget *get_widget(FilterRule *fr, struct _RuleContext *f); @@ -95,6 +96,7 @@ vfolder_rule_class_init (VfolderRuleClass *class) filter_rule->validate = validate; filter_rule->xml_encode = xml_encode; filter_rule->xml_decode = xml_decode; + filter_rule->copy = rule_copy; /*filter_rule->build_code = build_code;*/ filter_rule->get_widget = get_widget; } @@ -109,7 +111,10 @@ static void vfolder_rule_finalise(GtkObject *obj) { VfolderRule *o = (VfolderRule *)obj; - o = o; + + g_list_foreach (o->sources, (GFunc) g_free, NULL); + g_list_free (o->sources); + ((GtkObjectClass *)(parent_class))->finalize(obj); } @@ -258,6 +263,33 @@ xml_decode (FilterRule *fr, xmlNodePtr node, struct _RuleContext *f) return 0; } +static void +rule_copy (FilterRule *dest, FilterRule *src) +{ + VfolderRule *vdest, *vsrc; + GList *node; + + vdest = (VfolderRule *) dest; + vsrc = (VfolderRule *) src; + + if (vdest->sources) { + g_list_foreach (vdest->sources, (GFunc) g_free, NULL); + g_list_free (vdest->sources); + vdest->sources = NULL; + } + + node = vsrc->sources; + while (node) { + char *uri = node->data; + + vdest->sources = g_list_append (vdest->sources, g_strdup (uri)); + node = node->next; + } + + ((FilterRuleClass *)(parent_class))->copy (dest, src); +} + + enum { BUTTON_ADD, BUTTON_REMOVE, |