aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author3 <NotZed@Ximian.com>2001-09-15 16:13:19 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-09-15 16:13:19 +0800
commit07a40707a39c663f06893a5cba36d49ed63ba5b6 (patch)
tree8e650e3f5508d50a8d10bd3a4b6804cd5cf61385
parent466e05c024510d8019989f8bf8f04541c3ca792d (diff)
downloadgsoc2013-evolution-07a40707a39c663f06893a5cba36d49ed63ba5b6.tar.gz
gsoc2013-evolution-07a40707a39c663f06893a5cba36d49ed63ba5b6.tar.zst
gsoc2013-evolution-07a40707a39c663f06893a5cba36d49ed63ba5b6.zip
Emit changed events.
2001-09-13 <NotZed@Ximian.com> * filter-filter.c (filter_filter_add_action): (filter_filter_remove_action): (filter_filter_replace_action): Emit changed events. * filter-rule.c (filter_rule_xml_decode): Emiot a rule changed event. (filter_rule_copy): Emit a changed event. (filter_rule_replace_part): " (filter_rule_add_part): " (filter_rule_remove_part): " (filter_rule_xml_decode): Freeze around decoding, so we only emit changed when done. (filter_rule_emit_changed): New function to emit changed events if not frozen. 2001-09-13 <NotZed@Ximian.com> * rule-context.c (rule_context_class_init): Added a 'rule_added' and 'rule_removed' signal. (rule_context_load): Set a (private) frozen flag while we're loading. (rule_context_add_rule): Emit a rule_added signal if we're not frozen. (rule_context_remove_rule): Emit a rule_removed signal if we're not frozen. svn path=/trunk/; revision=12855
-rw-r--r--filter/ChangeLog24
-rw-r--r--filter/filter-filter.c6
-rw-r--r--filter/filter-rule.c41
-rw-r--r--filter/filter-rule.h4
-rw-r--r--filter/rule-context.c38
-rw-r--r--filter/rule-context.h2
6 files changed, 108 insertions, 7 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog
index fcd6f22aed..cf3a975126 100644
--- a/filter/ChangeLog
+++ b/filter/ChangeLog
@@ -1,3 +1,27 @@
+2001-09-13 <NotZed@Ximian.com>
+
+ * filter-filter.c (filter_filter_add_action):
+ (filter_filter_remove_action):
+ (filter_filter_replace_action): Emit changed events.
+
+ * filter-rule.c (filter_rule_xml_decode): Emiot a rule changed event.
+ (filter_rule_copy): Emit a changed event.
+ (filter_rule_replace_part): "
+ (filter_rule_add_part): "
+ (filter_rule_remove_part): "
+ (filter_rule_xml_decode): Freeze around decoding, so we only emit changed when done.
+ (filter_rule_emit_changed): New function to emit changed events if not frozen.
+
+2001-09-13 <NotZed@Ximian.com>
+
+ * rule-context.c (rule_context_class_init): Added a 'rule_added'
+ and 'rule_removed' signal.
+ (rule_context_load): Set a (private) frozen flag while we're loading.
+ (rule_context_add_rule): Emit a rule_added signal if we're not
+ frozen.
+ (rule_context_remove_rule): Emit a rule_removed signal if we're
+ not frozen.
+
2001-09-12 Jeffrey Stedfast <fejj@ximian.com>
* rule-editor.c (rule_edit): Clone the current rule before editing
diff --git a/filter/filter-filter.c b/filter/filter-filter.c
index 50d29d2369..f8d369adcf 100644
--- a/filter/filter-filter.c
+++ b/filter/filter-filter.c
@@ -152,12 +152,16 @@ void
filter_filter_add_action (FilterFilter *fr, FilterPart *fp)
{
fr->actions = g_list_append (fr->actions, fp);
+
+ filter_rule_emit_changed((FilterRule *)fr);
}
void
filter_filter_remove_action (FilterFilter *fr, FilterPart *fp)
{
fr->actions = g_list_remove (fr->actions, fp);
+
+ filter_rule_emit_changed((FilterRule *)fr);
}
void
@@ -171,6 +175,8 @@ filter_filter_replace_action (FilterFilter *fr, FilterPart *fp, FilterPart *new)
} else {
fr->actions = g_list_append (fr->actions, new);
}
+
+ filter_rule_emit_changed((FilterRule *)fr);
}
void
diff --git a/filter/filter-rule.c b/filter/filter-rule.c
index bf948ba299..28703024a2 100644
--- a/filter/filter-rule.c
+++ b/filter/filter-rule.c
@@ -52,11 +52,13 @@ static void filter_rule_finalise (GtkObject * obj);
#define _PRIVATE(x) (((FilterRule *)(x))->priv)
struct _FilterRulePrivate {
+ int frozen;
};
static GtkObjectClass *parent_class;
enum {
+ CHANGED,
LAST_SIGNAL
};
@@ -103,6 +105,13 @@ filter_rule_class_init (FilterRuleClass * class)
class->get_widget = get_widget;
/* signals */
+ signals[CHANGED] =
+ gtk_signal_new("changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (FilterRuleClass, changed),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
}
@@ -281,11 +290,19 @@ load_set (xmlNodePtr node, FilterRule *fr, RuleContext *f)
int
filter_rule_xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f)
{
+ int res;
+
g_assert (IS_FILTER_RULE (fr));
g_assert (IS_RULE_CONTEXT (f));
g_assert (node != NULL);
-
- return ((FilterRuleClass *) ((GtkObject *) fr)->klass)->xml_decode (fr, node, f);
+
+ fr->priv->frozen++;
+ res = ((FilterRuleClass *) ((GtkObject *) fr)->klass)->xml_decode (fr, node, f);
+ fr->priv->frozen--;
+
+ filter_rule_emit_changed(fr);
+
+ return res;
}
static int
@@ -323,7 +340,8 @@ xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f)
load_set (work, fr, f);
} else if (!strcmp (work->name, "title") || !strcmp (work->name, "_title")) {
if (!fr->name) {
- gchar *str, *decstr;
+ char *str, *decstr;
+
str = xmlNodeGetContent (work);
decstr = e_utf8_xml1_decode (str);
if (str)
@@ -373,6 +391,8 @@ filter_rule_copy (FilterRule *dest, FilterRule *src)
g_assert (IS_FILTER_RULE (src));
((FilterRuleClass *) ((GtkObject *) dest)->klass)->copy (dest, src);
+
+ filter_rule_emit_changed(dest);
}
void
@@ -382,6 +402,8 @@ filter_rule_add_part (FilterRule *fr, FilterPart *fp)
g_assert (IS_FILTER_PART (fp));
fr->parts = g_list_append (fr->parts, fp);
+
+ filter_rule_emit_changed(fr);
}
void
@@ -391,6 +413,8 @@ filter_rule_remove_part (FilterRule *fr, FilterPart *fp)
g_assert (IS_FILTER_PART (fp));
fr->parts = g_list_remove (fr->parts, fp);
+
+ filter_rule_emit_changed(fr);
}
void
@@ -408,6 +432,8 @@ filter_rule_replace_part (FilterRule *fr, FilterPart *fp, FilterPart *new)
} else {
fr->parts = g_list_append (fr->parts, new);
}
+
+ filter_rule_emit_changed(fr);
}
void
@@ -421,6 +447,15 @@ filter_rule_build_code (FilterRule *fr, GString *out)
d(printf ("build_code: [%s](%d)", out->str, out->len));
}
+void
+filter_rule_emit_changed(FilterRule *fr)
+{
+ g_assert (IS_FILTER_RULE (fr));
+
+ if (fr->priv->frozen == 0)
+ gtk_signal_emit((GtkObject *)fr, signals[CHANGED]);
+}
+
static void
build_code (FilterRule *fr, GString *out)
{
diff --git a/filter/filter-rule.h b/filter/filter-rule.h
index 41a10ca326..37704214a9 100644
--- a/filter/filter-rule.h
+++ b/filter/filter-rule.h
@@ -71,6 +71,7 @@ struct _FilterRuleClass {
GtkWidget *(*get_widget)(FilterRule *fr, struct _RuleContext *f);
/* signals */
+ void (*changed)(FilterRule *fr);
};
guint filter_rule_get_type (void);
@@ -100,9 +101,12 @@ void filter_rule_build_code (FilterRule *fr, GString *out);
void filter_rule_build_action(FilterRule *fr, GString *out);
*/
+void filter_rule_emit_changed (FilterRule *fr);
+
/* static functions */
FilterRule *filter_rule_next_list (GList *l, FilterRule *last, const char *source);
FilterRule *filter_rule_find_list (GList *l, const char *name, const char *source);
+
#endif /* ! _FILTER_RULE_H */
diff --git a/filter/rule-context.c b/filter/rule-context.c
index 61e422eeb1..389ef7296a 100644
--- a/filter/rule-context.c
+++ b/filter/rule-context.c
@@ -42,11 +42,14 @@ static void rule_context_finalise(GtkObject * obj);
#define _PRIVATE(x) (((RuleContext *)(x))->priv)
struct _RuleContextPrivate {
+ int frozen;
};
static GtkObjectClass *parent_class;
enum {
+ RULE_ADDED,
+ RULE_REMOVED,
LAST_SIGNAL
};
@@ -89,6 +92,21 @@ rule_context_class_init (RuleContextClass * class)
class->save = save;
/* signals */
+ signals[RULE_ADDED] =
+ gtk_signal_new("rule_added",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (RuleContextClass, rule_added),
+ gtk_marshal_NONE__POINTER,
+ GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
+
+ signals[RULE_REMOVED] =
+ gtk_signal_new("rule_removed",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (RuleContextClass, rule_removed),
+ gtk_marshal_NONE__POINTER,
+ GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
}
@@ -222,9 +240,15 @@ rule_context_set_error (RuleContext * f, char *error)
int
rule_context_load (RuleContext *f, const char *system, const char *user)
{
+ int res;
+
d(printf("rule_context: loading %s %s\n", system, user));
-
- return ((RuleContextClass *) ((GtkObject *) f)->klass)->load (f, system, user);
+
+ f->priv->frozen++;
+ res= ((RuleContextClass *) ((GtkObject *) f)->klass)->load (f, system, user);
+ f->priv->frozen--;
+
+ return res;
}
static int
@@ -240,8 +264,8 @@ load (RuleContext *f, const char *system, const char *user)
f->system = xmlParseFile (system);
if (f->system == NULL) {
- rule_context_set_error (f, g_strdup_printf ("Unable to load system rules '%s': %s",
- system, g_strerror (errno)));
+ rule_context_set_error(f, g_strdup_printf ("Unable to load system rules '%s': %s",
+ system, strerror(errno)));
return -1;
}
if (strcmp (f->system->root->name, "filterdescription")) {
@@ -400,6 +424,9 @@ void
rule_context_add_rule (RuleContext *f, FilterRule *new)
{
f->rules = g_list_append (f->rules, new);
+
+ if (f->priv->frozen == 0)
+ gtk_signal_emit((GtkObject *)f, signals[RULE_ADDED], new);
}
static void
@@ -455,6 +482,9 @@ void
rule_context_remove_rule (RuleContext *f, FilterRule *rule)
{
f->rules = g_list_remove (f->rules, rule);
+
+ if (f->priv->frozen == 0)
+ gtk_signal_emit((GtkObject *)f, signals[RULE_REMOVED], rule);
}
void
diff --git a/filter/rule-context.h b/filter/rule-context.h
index a06bad9acd..6f6a72f270 100644
--- a/filter/rule-context.h
+++ b/filter/rule-context.h
@@ -62,6 +62,8 @@ struct _RuleContextClass {
int (*save)(RuleContext *f, const char *user);
/* signals */
+ void (*rule_added)(RuleContext *f, FilterRule *rule);
+ void (*rule_removed)(RuleContext *f, FilterRule *rule);
};
typedef void (*RCPartFunc)(RuleContext *f, FilterPart *part);