diff options
author | 8 <NotZed@Ximian.com> | 2001-10-28 17:39:04 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2001-10-28 17:39:04 +0800 |
commit | 15ada734a7008b42c2ca2c21aece9336c2b9e075 (patch) | |
tree | 49036be5a3eac64ecac70f22d35ab38493bd00eb /filter/filter-context.c | |
parent | c0cf9754b8c5ec7e13f6ee035040d792bc254ee2 (diff) | |
download | gsoc2013-evolution-15ada734a7008b42c2ca2c21aece9336c2b9e075.tar.gz gsoc2013-evolution-15ada734a7008b42c2ca2c21aece9336c2b9e075.tar.zst gsoc2013-evolution-15ada734a7008b42c2ca2c21aece9336c2b9e075.zip |
Implement, change any folder uri's that have been renamed, to the new one.
2001-10-28 <NotZed@Ximian.com>
* filter-context.c (filter_rename_uri): Implement, change any
folder uri's that have been renamed, to the new one.
(filter_delete_uri): Dont actually do any work (yet).
We could probably put rename_uri on every rule context/filter
part/filter element, and let their methods handle it, but for now
its easy enough just to handle the few cases that we have to
handle manually.
* rule-context.c (rule_context_delete_uri): Update a filter
context for a deleted uri, e.g. folder removed.
(rule_context_rename_uri): Update a filter context for a renamed
uri, e.g.
* filter-folder.c (filter_folder_set_value): New function to set
the uri of a folder filter.
* rule-editor.c (rule_move): Add undo for move.
(rule_editor_add_undo): Add extra rank item.
(rule_editor_play_undo): handle rank case.
(rule_editor_finalise): Clean up any hanging over undo log.
(editor_clicked): Only enable 'undo' if we have
EVOLUTION_RULE_UNDO enabled. Code still a bit flakey.
(rule_editor_construct): Only enable a cancel button if
EVOLUTION_RULE_UNDO is set.
(rule_editor_add_undo): Only add if undo enabled.
* filter-rule.c (filter_rule_set_name): Emit a changed event if it
changes.
(filter_rule_set_source): Same.
svn path=/trunk/; revision=14289
Diffstat (limited to 'filter/filter-context.c')
-rw-r--r-- | filter/filter-context.c | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/filter/filter-context.c b/filter/filter-context.c index 3ec682fc07..aa3b36a5ee 100644 --- a/filter/filter-context.c +++ b/filter/filter-context.c @@ -22,18 +22,26 @@ #include <config.h> #endif +#include <string.h> + #include <gtk/gtktypeutils.h> #include <gtk/gtkobject.h> #include "filter-context.h" #include "filter-filter.h" +/* For poking into filter-folder guts */ +#include "filter-folder.h" + #define d(x) static void filter_context_class_init (FilterContextClass *class); static void filter_context_init (FilterContext *gspaper); static void filter_context_finalise (GtkObject *obj); +static int filter_rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp); +static int filter_delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp); + #define _PRIVATE(x) (((FilterContext *)(x))->priv) struct _FilterContextPrivate { @@ -73,12 +81,16 @@ static void filter_context_class_init (FilterContextClass *class) { GtkObjectClass *object_class; - + RuleContextClass *rule_class = (RuleContextClass *)class; + object_class = (GtkObjectClass *)class; parent_class = gtk_type_class(rule_context_get_type ()); object_class->finalize = filter_context_finalise; + /* override methods */ + rule_class->rename_uri = filter_rename_uri; + rule_class->delete_uri = filter_delete_uri; /* signals */ @@ -151,3 +163,75 @@ FilterPart *filter_context_next_action(FilterContext *f, FilterPart *last) { return filter_part_next_list(f->actions, last); } + +/* We search for any folders in our actions list that need updating, update them */ +static int filter_rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp) +{ + FilterRule *rule; + GList *l, *el; + FilterPart *action; + FilterElement *element; + const char *name; + int count = 0; + + name = strrchr(newuri, '/'); + if (name) + name++; + else + name = newuri; + + d(printf("uri '%s' renamed to '%s'\n", olduri, newuri)); + + /* For all rules, for all actions, for all elements, rename any folder elements */ + /* Yes we could do this inside each part itself, but not today */ + rule = NULL; + while ( (rule = rule_context_next_rule(f, rule, NULL)) ) { + int rulecount = 0; + + d(printf("checking rule '%s'\n", rule->name)); + + l = FILTER_FILTER(rule)->actions; + while (l) { + action = l->data; + + d(printf("checking action '%s'\n", action->name)); + + el = action->elements; + while (el) { + element = el->data; + + d(printf("checking element '%s'\n", element->name)); + if (IS_FILTER_FOLDER(element)) + d(printf(" is folder, existing uri = '%s'\n", FILTER_FOLDER(element)->uri)); + + if (IS_FILTER_FOLDER(element) + && cmp(((FilterFolder *)element)->uri, olduri)) { + d(printf(" Changed!\n")); + filter_folder_set_value((FilterFolder *)element, newuri, name); + rulecount++; + } + el = el->next; + } + l = l->next; + } + + if (rulecount) + filter_rule_emit_changed(rule); + + count += rulecount; + } + + return count + parent_class->rename_uri(f, olduri, newuri, cmp); +} + +static int filter_delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp) +{ + /* We basically should do similar to above, but when we find it, + Remove the action, and if thats the last action, remove the rule? */ + + /* But i'm not confident the rest of the mailer wont accidentlly delete + something which was just temporarily not available. */ + + return parent_class->delete_uri(f, uri, cmp); +} + |