aboutsummaryrefslogtreecommitdiffstats
path: root/filter
diff options
context:
space:
mode:
author8 <NotZed@Ximian.com>2001-10-28 17:39:04 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-10-28 17:39:04 +0800
commit15ada734a7008b42c2ca2c21aece9336c2b9e075 (patch)
tree49036be5a3eac64ecac70f22d35ab38493bd00eb /filter
parentc0cf9754b8c5ec7e13f6ee035040d792bc254ee2 (diff)
downloadgsoc2013-evolution-15ada734a7008b42c2ca2c21aece9336c2b9e075.tar
gsoc2013-evolution-15ada734a7008b42c2ca2c21aece9336c2b9e075.tar.gz
gsoc2013-evolution-15ada734a7008b42c2ca2c21aece9336c2b9e075.tar.bz2
gsoc2013-evolution-15ada734a7008b42c2ca2c21aece9336c2b9e075.tar.lz
gsoc2013-evolution-15ada734a7008b42c2ca2c21aece9336c2b9e075.tar.xz
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')
-rw-r--r--filter/ChangeLog18
-rw-r--r--filter/filter-context.c86
-rw-r--r--filter/filter-folder.c9
-rw-r--r--filter/filter-folder.h1
-rw-r--r--filter/rule-context.c32
-rw-r--r--filter/rule-context.h7
-rw-r--r--filter/rule-editor.c15
7 files changed, 160 insertions, 8 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog
index 1e94dae79d..f0b4698be3 100644
--- a/filter/ChangeLog
+++ b/filter/ChangeLog
@@ -1,5 +1,22 @@
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.
@@ -8,6 +25,7 @@
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.
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);
+}
+
diff --git a/filter/filter-folder.c b/filter/filter-folder.c
index 5caac7fb62..177e0996e4 100644
--- a/filter/filter-folder.c
+++ b/filter/filter-folder.c
@@ -134,6 +134,15 @@ filter_folder_new (void)
return o;
}
+void
+filter_folder_set_value(FilterFolder *ff, const char *uri, const char *name)
+{
+ g_free(ff->uri);
+ ff->uri = g_strdup(uri);
+ g_free(ff->name);
+ ff->name = g_strdup(name);
+}
+
static gboolean
validate (FilterElement *fe)
{
diff --git a/filter/filter-folder.h b/filter/filter-folder.h
index 4e77d96fc5..e58444fb14 100644
--- a/filter/filter-folder.h
+++ b/filter/filter-folder.h
@@ -50,6 +50,7 @@ guint filter_folder_get_type (void);
FilterFolder *filter_folder_new (void);
/* methods */
+void filter_folder_set_value(FilterFolder *ff, const char *uri, const char *name);
#endif /* ! _FILTER_FOLDER_H */
diff --git a/filter/rule-context.c b/filter/rule-context.c
index ce83abc662..d11e4ec722 100644
--- a/filter/rule-context.c
+++ b/filter/rule-context.c
@@ -38,6 +38,8 @@
static int load(RuleContext * f, const char *system, const char *user);
static int save(RuleContext * f, const char *user);
+static int rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp);
+static int delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp);
static void rule_context_class_init(RuleContextClass * class);
static void rule_context_init(RuleContext * gspaper);
@@ -95,7 +97,9 @@ rule_context_class_init (RuleContextClass * class)
/* override methods */
class->load = load;
class->save = save;
-
+ class->rename_uri = rename_uri;
+ class->delete_uri = delete_uri;
+
/* signals */
signals[RULE_ADDED] =
gtk_signal_new("rule_added",
@@ -647,3 +651,29 @@ rule_context_find_rank_rule (RuleContext *f, int rank, const char *source)
return NULL;
}
+
+static int
+delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp)
+{
+ return 0;
+}
+
+int
+rule_context_delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp)
+{
+ return ((RuleContextClass *) ((GtkObject *) f)->klass)->delete_uri(f, uri, cmp);
+}
+
+static int
+rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp)
+{
+ return 0;
+}
+
+int
+rule_context_rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp)
+{
+ return ((RuleContextClass *) ((GtkObject *) f)->klass)->rename_uri (f, olduri, newuri, cmp);
+}
+
+
diff --git a/filter/rule-context.h b/filter/rule-context.h
index 05c6ccfcf4..982129b216 100644
--- a/filter/rule-context.h
+++ b/filter/rule-context.h
@@ -61,6 +61,9 @@ struct _RuleContextClass {
int (*load)(RuleContext *f, const char *system, const char *user);
int (*save)(RuleContext *f, const char *user);
+ int (*delete_uri)(RuleContext *f, const char *uri, GCompareFunc cmp);
+ int (*rename_uri)(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp);
+
/* signals */
void (*rule_added)(RuleContext *f, FilterRule *rule);
void (*rule_removed)(RuleContext *f, FilterRule *rule);
@@ -113,5 +116,9 @@ int rule_context_get_rank_rule(RuleContext *f, FilterRule *rule, const char *so
void rule_context_add_part_set(RuleContext *f, const char *setname, int part_type, RCPartFunc append, RCNextPartFunc next);
void rule_context_add_rule_set(RuleContext *f, const char *setname, int rule_type, RCRuleFunc append, RCNextRuleFunc next);
+/* uri's disappear/renamed externally */
+int rule_context_delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp);
+int rule_context_rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp);
+
#endif /* ! _RULE_CONTEXT_H */
diff --git a/filter/rule-editor.c b/filter/rule-editor.c
index 0fdd845dd9..63986e6f2d 100644
--- a/filter/rule-editor.c
+++ b/filter/rule-editor.c
@@ -36,6 +36,8 @@
/* for getenv only, remove when getenv need removed */
#include <stdlib.h>
+static int enable_undo;
+
void rule_editor_add_undo(RuleEditor *re, int type, FilterRule *rule, int rank, int newrank);
void rule_editor_play_undo(RuleEditor *re);
@@ -88,7 +90,10 @@ rule_editor_get_type(void)
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL
};
-
+
+ /* TODO: Remove when it works (or never will) */
+ enable_undo = getenv("EVOLUTION_RULE_UNDO") != NULL;
+
type = gtk_type_unique (gnome_dialog_get_type (), &type_info);
}
@@ -514,9 +519,7 @@ rule_editor_add_undo(RuleEditor *re, int type, FilterRule *rule, int rank, int n
{
RuleEditorUndo *undo;
- printf("Adding udno record: %d object %p '%s'\n", type, rule, rule->name);
-
- if (!re->undo_active) {
+ if (!re->undo_active && !enable_undo) {
undo = g_malloc0(sizeof(*undo));
undo->rule = rule;
undo->type = type;
@@ -581,7 +584,7 @@ static void
editor_clicked (GtkWidget *dialog, int button, RuleEditor *re)
{
if (button != 0) {
- if (getenv("EVOLUTION_RULE_UNDO"))
+ if (enable_undo)
rule_editor_play_undo(re);
else {
RuleEditorUndo *undo, *next;
@@ -624,7 +627,7 @@ rule_editor_construct (RuleEditor *re, RuleContext *context, GladeXML *gui, cons
gtk_signal_connect (GTK_OBJECT (re), "clicked", editor_clicked, re);
rule_editor_set_source (re, source);
- if (getenv("EVOLUTION_RULE_UNDO")) {
+ if (enable_undo) {
gnome_dialog_append_buttons (GNOME_DIALOG (re), GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL, NULL);
} else