diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-11-02 13:16:24 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-11-02 13:16:24 +0800 |
commit | 236c15d106b4e740d4e3996e0649334ca8e13876 (patch) | |
tree | f98b59632e0bf927288650393e49060950c7ad9e /filter/filter-context.c | |
parent | 9fd7dd8e0ca925b2aa738b1c495ff3b41f0f2487 (diff) | |
download | gsoc2013-evolution-236c15d106b4e740d4e3996e0649334ca8e13876.tar gsoc2013-evolution-236c15d106b4e740d4e3996e0649334ca8e13876.tar.gz gsoc2013-evolution-236c15d106b4e740d4e3996e0649334ca8e13876.tar.bz2 gsoc2013-evolution-236c15d106b4e740d4e3996e0649334ca8e13876.tar.lz gsoc2013-evolution-236c15d106b4e740d4e3996e0649334ca8e13876.tar.xz gsoc2013-evolution-236c15d106b4e740d4e3996e0649334ca8e13876.tar.zst gsoc2013-evolution-236c15d106b4e740d4e3996e0649334ca8e13876.zip |
Ported this too.
2002-11-02 Jeffrey Stedfast <fejj@ximian.com>
* filter-context.c: Ported this too.
* rule-context.c: Ported to glib2/GObject.
svn path=/trunk/; revision=18502
Diffstat (limited to 'filter/filter-context.c')
-rw-r--r-- | filter/filter-context.c | 224 |
1 files changed, 110 insertions, 114 deletions
diff --git a/filter/filter-context.c b/filter/filter-context.c index 6740af5b9e..c1dc6d8545 100644 --- a/filter/filter-context.c +++ b/filter/filter-context.c @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -18,15 +20,13 @@ * Boston, MA 02111-1307, USA. */ + #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <string.h> -#include <gtk/gtktypeutils.h> -#include <gtk/gtkobject.h> - #include "filter-context.h" #include "filter-filter.h" @@ -35,92 +35,80 @@ #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 GList *filter_rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp); -static GList *filter_delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp); - -#define _PRIVATE(x) (((FilterContext *)(x))->priv) +static void filter_context_class_init (FilterContextClass *klass); +static void filter_context_init (FilterContext *fc); +static void filter_context_finalise (GObject *obj); -struct _FilterContextPrivate { -}; +static GList *filter_rename_uri (RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp); +static GList *filter_delete_uri (RuleContext *rc, const char *uri, GCompareFunc cmp); -static RuleContextClass *parent_class; -enum { - LAST_SIGNAL -}; +static RuleContextClass *parent_class = NULL; -static guint signals[LAST_SIGNAL] = { 0 }; -guint +GType filter_context_get_type (void) { - static guint type = 0; + static GType type = 0; if (!type) { - GtkTypeInfo type_info = { - "FilterContext", - sizeof(FilterContext), - sizeof(FilterContextClass), - (GtkClassInitFunc)filter_context_class_init, - (GtkObjectInitFunc)filter_context_init, - (GtkArgSetFunc)NULL, - (GtkArgGetFunc)NULL + static const GTypeInfo info = { + sizeof (FilterContextClass), + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) filter_context_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FilterContext), + 0, /* n_preallocs */ + (GInstanceInitFunc) filter_context_init, }; - type = gtk_type_unique(rule_context_get_type (), &type_info); + type = g_type_register_static (RULE_TYPE_CONTEXT, "FilterContext", &info, 0); } return type; } static void -filter_context_class_init (FilterContextClass *class) +filter_context_class_init (FilterContextClass *klass) { - GtkObjectClass *object_class; - RuleContextClass *rule_class = (RuleContextClass *)class; - - object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class(rule_context_get_type ()); - + GObjectClass *object_class = G_OBJECT_CLASS (klass); + RuleContextClass *rc_class = RULE_CONTEXT_CLASS (klass); + + parent_class = g_type_class_ref (RULE_TYPE_CONTEXT); + object_class->finalize = filter_context_finalise; - + /* override methods */ - rule_class->rename_uri = filter_rename_uri; - rule_class->delete_uri = filter_delete_uri; - - /* signals */ - - gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL); + rc_class->rename_uri = filter_rename_uri; + rc_class->delete_uri = filter_delete_uri; } static void -filter_context_init (FilterContext *o) +filter_context_init (FilterContext *fc) { - o->priv = g_malloc0(sizeof(*o->priv)); - - rule_context_add_part_set((RuleContext *)o, "partset", filter_part_get_type(), - rule_context_add_part, rule_context_next_part); - rule_context_add_part_set((RuleContext *)o, "actionset", filter_part_get_type(), - (RCPartFunc)filter_context_add_action, - (RCNextPartFunc)filter_context_next_action); - - rule_context_add_rule_set((RuleContext *)o, "ruleset", filter_filter_get_type(), - (RCRuleFunc)rule_context_add_rule, rule_context_next_rule); + fc->priv = g_malloc0 (sizeof (*rc->priv)); + + rule_context_add_part_set ((RuleContext *) fc, "partset", filter_part_get_type (), + rule_context_add_part, rule_context_next_part); + rule_context_add_part_set ((RuleContext *) fc, "actionset", filter_part_get_type (), + (RCPartFunc) filter_context_add_action, + (RCNextPartFunc) filter_context_next_action); + + rule_context_add_rule_set ((RuleContext *) fc, "ruleset", filter_filter_get_type (), + (RCRuleFunc) rule_context_add_rule, rule_context_next_rule); } static void -filter_context_finalise(GtkObject *obj) +filter_context_finalise (GObject *obj) { - FilterContext *o = (FilterContext *)obj; - - g_list_foreach(o->actions, (GFunc)gtk_object_unref, NULL); - g_list_free(o->actions); - - ((GtkObjectClass *)(parent_class))->finalize(obj); + FilterContext *fc = (FilterContext *)obj; + + g_list_foreach (fc->actions, (GFunc)g_object_unref, NULL); + g_list_free (fc->actions); + + G_OBJECT_CLASS (parent_class)->finalize (obj); } /** @@ -131,41 +119,45 @@ filter_context_finalise(GtkObject *obj) * Return value: A new #FilterContext object. **/ FilterContext * -filter_context_new(void) +filter_context_new (void) { - FilterContext *o = (FilterContext *)gtk_type_new(filter_context_get_type ()); - return o; + return (FilterContext *) g_object_new (FILTER_TYPE_CONTEXT, NULL, NULL); } -void filter_context_add_action(FilterContext *f, FilterPart *action) +void +filter_context_add_action (FilterContext *fc, FilterPart *action) { d(printf("find action : ")); - f->actions = g_list_append(f->actions, action); + fc->actions = g_list_append (fc->actions, action); } -FilterPart *filter_context_find_action(FilterContext *f, const char *name) +FilterPart * +filter_context_find_action (FilterContext *fc, const char *name) { d(printf("find action : ")); - return filter_part_find_list(f->actions, name); + return filter_part_find_list (fc->actions, name); } -FilterPart *filter_context_create_action(FilterContext *f, const char *name) +FilterPart * +filter_context_create_action (FilterContext *fc, const char *name) { FilterPart *part; - - part = filter_context_find_action(f, name); - if (part) - part = filter_part_clone(part); - return part; + + if ((part = filter_context_find_action (fc, name))) + return filter_part_clone (part); + + return NULL; } -FilterPart *filter_context_next_action(FilterContext *f, FilterPart *last) +FilterPart * +filter_context_next_action (FilterContext *fc, FilterPart *last) { - return filter_part_next_list(f->actions, last); + return filter_part_next_list (fc->actions, last); } /* We search for any folders in our actions list that need updating, update them */ -static GList *filter_rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp) +static GList * +filter_rename_uri (RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp) { FilterRule *rule; GList *l, *el; @@ -173,32 +165,34 @@ static GList *filter_rename_uri(RuleContext *f, const char *olduri, const char * FilterElement *element; int count = 0; GList *changed = NULL; - + 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)) ) { + while ((rule = rule_context_next_rule (rc, rule, NULL))) { int rulecount = 0; - + d(printf("checking rule '%s'\n", rule->name)); - l = FILTER_FILTER(rule)->actions; + 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) + 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); @@ -208,66 +202,69 @@ static GList *filter_rename_uri(RuleContext *f, const char *olduri, const char * } l = l->next; } - + if (rulecount) { - changed = g_list_append(changed, g_strdup(rule->name)); - filter_rule_emit_changed(rule); + changed = g_list_append (changed, g_strdup (rule->name)); + filter_rule_emit_changed (rule); } - + count += rulecount; } - + /* might need to call parent class, if it did anything ... parent_class->rename_uri(f, olduri, newuri, cmp); */ - + return changed; } -static GList *filter_delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp) +static GList * +filter_delete_uri (RuleContext *rc, const char *uri, GCompareFunc cmp) { /* We basically do similar to above, but when we find it, Remove the action, and if thats the last action, this might create an empty rule? remove the rule? */ - + FilterRule *rule; GList *l, *el; FilterPart *action; FilterElement *element; int count = 0; GList *deleted = NULL; - + d(printf("uri '%s' deleted\n", uri)); - + /* For all rules, for all actions, for all elements, check deleted 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)) ) { + while ((rule = rule_context_next_rule (rc, rule, NULL))) { int recorded = 0; - + d(printf("checking rule '%s'\n", rule->name)); - l = FILTER_FILTER(rule)->actions; + 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) + 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, uri)) { d(printf(" Deleted!\n")); /* check if last action, if so, remove rule instead? */ l = l->next; - filter_filter_remove_action((FilterFilter *)rule, action); - gtk_object_unref((GtkObject *)action); + filter_filter_remove_action ((FilterFilter *)rule, action); + g_object_unref (action); count++; if (!recorded) - deleted = g_list_append(deleted, g_strdup(rule->name)); + deleted = g_list_append (deleted, g_strdup (rule->name)); goto next_action; } el = el->next; @@ -277,9 +274,8 @@ static GList *filter_delete_uri(RuleContext *f, const char *uri, GCompareFunc cm ; } } - + /* TODO: could call parent and merge lists */ - + return deleted; } - |