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 | |
parent | 9fd7dd8e0ca925b2aa738b1c495ff3b41f0f2487 (diff) | |
download | gsoc2013-evolution-236c15d106b4e740d4e3996e0649334ca8e13876.tar.gz 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
-rw-r--r-- | filter/ChangeLog | 2 | ||||
-rw-r--r-- | filter/filter-context.c | 224 | ||||
-rw-r--r-- | filter/filter-context.h | 35 | ||||
-rw-r--r-- | filter/rule-context.c | 10 | ||||
-rw-r--r-- | filter/rule-context.h | 71 |
5 files changed, 171 insertions, 171 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index c9d33d7c10..7b81ec9b20 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,5 +1,7 @@ 2002-11-02 Jeffrey Stedfast <fejj@ximian.com> + * filter-context.c: Ported this too. + * rule-context.c: Ported to glib2/GObject. 2002-11-01 Jeffrey Stedfast <fejj@ximian.com> 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; } - diff --git a/filter/filter-context.h b/filter/filter-context.h index 93feb3b8b2..157ee6f1de 100644 --- a/filter/filter-context.h +++ b/filter/filter-context.h @@ -26,36 +26,37 @@ #include "rule-context.h" -#define FILTER_CONTEXT(obj) GTK_CHECK_CAST (obj, filter_context_get_type (), FilterContext) -#define FILTER_CONTEXT_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_context_get_type (), FilterContextClass) -#define IS_FILTER_CONTEXT(obj) GTK_CHECK_TYPE (obj, filter_context_get_type ()) +#define FILTER_TYPE_CONTEXT (filter_context_get_type ()) +#define FILTER_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FILTER_TYPE_CONTEXT, FilterContext)) +#define FILTER_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FILTER_TYPE_CONTEXT, FilterContextClass)) +#define IS_FILTER_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FILTER_TYPE_CONTEXT)) +#define IS_FILTER_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FILTER_TYPE_CONTEXT)) +#define FILTER_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FILTER_TYPE_CONTEXT, FilterContextClass)) -typedef struct _FilterContext FilterContext; -typedef struct _FilterContextClass FilterContextClass; +typedef struct _FilterContext FilterContext; +typedef struct _FilterContextClass FilterContextClass; struct _FilterContext { - RuleContext parent; - struct _FilterContextPrivate *priv; - + RuleContext parent_object; + GList *actions; }; struct _FilterContextClass { RuleContextClass parent_class; - + /* virtual methods */ - + /* signals */ }; -guint filter_context_get_type (void); -FilterContext *filter_context_new (void); +GType filter_context_get_type (void); +FilterContext *filter_context_new (void); /* methods */ -void filter_context_add_action(FilterContext *f, FilterPart *action); -FilterPart *filter_context_find_action(FilterContext *f, const char *name); -FilterPart *filter_context_create_action(FilterContext *f, const char *name); -FilterPart *filter_context_next_action(FilterContext *f, FilterPart *last); +void filter_context_add_action (FilterContext *fc, FilterPart *action); +FilterPart *filter_context_find_action (FilterContext *fc, const char *name); +FilterPart *filter_context_create_action (FilterContext *fc, const char *name); +FilterPart *filter_context_next_action (FilterContext *fc, FilterPart *last); #endif /* ! _FILTER_CONTEXT_H */ - diff --git a/filter/rule-context.c b/filter/rule-context.c index 69de387100..4d0566943c 100644 --- a/filter/rule-context.c +++ b/filter/rule-context.c @@ -41,11 +41,11 @@ #define d(x) -static int load(RuleContext * f, const char *system, const char *user); -static int save(RuleContext * f, const char *user); -static int revert(RuleContext *f, const char *user); -static GList *rename_uri(RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp); -static GList *delete_uri(RuleContext *f, const char *uri, GCompareFunc cmp); +static int load (RuleContext *rc, const char *system, const char *user); +static int save (RuleContext *rc, const char *user); +static int revert (RuleContext *rc, const char *user); +static GList *rename_uri (RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp); +static GList *delete_uri (RuleContext *rc, const char *uri, GCompareFunc cmp); static void rule_context_class_init (RuleContextClass *klass); static void rule_context_init (RuleContext *rc); diff --git a/filter/rule-context.h b/filter/rule-context.h index 62e6f4ac19..96bc06b00d 100644 --- a/filter/rule-context.h +++ b/filter/rule-context.h @@ -20,6 +20,7 @@ * Boston, MA 02111-1307, USA. */ + #ifndef _RULE_CONTEXT_H #define _RULE_CONTEXT_H @@ -58,29 +59,29 @@ struct _RuleContext { GList *rule_set_list; }; -typedef void (*RCRegisterFunc) (RuleContext *f, FilterRule *rule, gpointer user_data); +typedef void (*RCRegisterFunc) (RuleContext *rc, FilterRule *rule, gpointer user_data); struct _RuleContextClass { GObjectClass parent_class; /* virtual methods */ - int (*load) (RuleContext *f, const char *system, const char *user); - int (*save) (RuleContext *f, const char *user); - int (*revert) (RuleContext *f, const char *user); + int (*load) (RuleContext *rc, const char *system, const char *user); + int (*save) (RuleContext *rc, const char *user); + int (*revert) (RuleContext *rc, const char *user); - GList *(*delete_uri) (RuleContext *f, const char *uri, GCompareFunc cmp); - GList *(*rename_uri) (RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp); + GList *(*delete_uri) (RuleContext *rc, const char *uri, GCompareFunc cmp); + GList *(*rename_uri) (RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp); /* signals */ - void (*rule_added) (RuleContext *f, FilterRule *rule); - void (*rule_removed) (RuleContext *f, FilterRule *rule); - void (*changed) (RuleContext *f); + void (*rule_added) (RuleContext *rc, FilterRule *rule); + void (*rule_removed) (RuleContext *rc, FilterRule *rule); + void (*changed) (RuleContext *rc); }; -typedef void (*RCPartFunc) (RuleContext *f, FilterPart *part); -typedef void (*RCRuleFunc) (RuleContext *f, FilterRule *part); -typedef FilterPart * (*RCNextPartFunc) (RuleContext *f, FilterPart *part); -typedef FilterRule * (*RCNextRuleFunc) (RuleContext *f, FilterRule *rule, const char *source); +typedef void (*RCPartFunc) (RuleContext *rc, FilterPart *part); +typedef void (*RCRuleFunc) (RuleContext *rc, FilterRule *part); +typedef FilterPart * (*RCNextPartFunc) (RuleContext *rc, FilterPart *part); +typedef FilterRule * (*RCNextRuleFunc) (RuleContext *rc, FilterRule *rule, const char *source); struct _part_set_map { char *name; @@ -100,36 +101,36 @@ GType rule_context_get_type (void); RuleContext *rule_context_new (void); /* methods */ -int rule_context_load (RuleContext *f, const char *system, const char *user); -int rule_context_save (RuleContext *f, const char *user); -int rule_context_revert (RuleContext *f, const char *user); - -void rule_context_add_part (RuleContext *f, FilterPart *new); -FilterPart *rule_context_find_part (RuleContext *f, const char *name); -FilterPart *rule_context_create_part (RuleContext *f, const char *name); -FilterPart *rule_context_next_part (RuleContext *f, FilterPart *last); - -FilterRule *rule_context_next_rule (RuleContext *f, FilterRule *last, const char *source); -FilterRule *rule_context_find_rule (RuleContext *f, const char *name, const char *source); -FilterRule *rule_context_find_rank_rule (RuleContext *f, int rank, const char *source); -void rule_context_add_rule (RuleContext *f, FilterRule *new); -void rule_context_add_rule_gui (RuleContext *f, FilterRule *rule, const char *title, const char *path); -void rule_context_remove_rule (RuleContext *f, FilterRule *rule); +int rule_context_load (RuleContext *rc, const char *system, const char *user); +int rule_context_save (RuleContext *rc, const char *user); +int rule_context_revert (RuleContext *rc, const char *user); + +void rule_context_add_part (RuleContext *rc, FilterPart *new); +FilterPart *rule_context_find_part (RuleContext *rc, const char *name); +FilterPart *rule_context_create_part (RuleContext *rc, const char *name); +FilterPart *rule_context_next_part (RuleContext *rc, FilterPart *last); + +FilterRule *rule_context_next_rule (RuleContext *rc, FilterRule *last, const char *source); +FilterRule *rule_context_find_rule (RuleContext *rc, const char *name, const char *source); +FilterRule *rule_context_find_rank_rule (RuleContext *rc, int rank, const char *source); +void rule_context_add_rule (RuleContext *rc, FilterRule *new); +void rule_context_add_rule_gui (RuleContext *rc, FilterRule *rule, const char *title, const char *path); +void rule_context_remove_rule (RuleContext *rc, FilterRule *rule); /* get/set the rank (position) of a rule */ -void rule_context_rank_rule (RuleContext *f, FilterRule *rule, int rank); -int rule_context_get_rank_rule (RuleContext *f, FilterRule *rule, const char *source); +void rule_context_rank_rule (RuleContext *rc, FilterRule *rule, int rank); +int rule_context_get_rank_rule (RuleContext *rc, FilterRule *rule, const char *source); /* setup type for set parts */ -void rule_context_add_part_set (RuleContext *f, const char *setname, int part_type, +void rule_context_add_part_set (RuleContext *rc, const char *setname, int part_type, RCPartFunc append, RCNextPartFunc next); -void rule_context_add_rule_set (RuleContext *f, const char *setname, int rule_type, +void rule_context_add_rule_set (RuleContext *rc, const char *setname, int rule_type, RCRuleFunc append, RCNextRuleFunc next); /* uri's disappear/renamed externally */ -GList *rule_context_delete_uri (RuleContext *f, const char *uri, GCompareFunc cmp); -GList *rule_context_rename_uri (RuleContext *f, const char *olduri, const char *newuri, GCompareFunc cmp); +GList *rule_context_delete_uri (RuleContext *rc, const char *uri, GCompareFunc cmp); +GList *rule_context_rename_uri (RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp); -void rule_context_free_uri_list (RuleContext *f, GList *uris); +void rule_context_free_uri_list (RuleContext *rc, GList *uris); #endif /* ! _RULE_CONTEXT_H */ |