diff options
author | Not Zed <NotZed@Ximian.com> | 2003-03-10 16:15:01 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2003-03-10 16:15:01 +0800 |
commit | d51c9927e53206f889dba63274fd425efe65db5a (patch) | |
tree | 74b0a889cd150b67b8cf2eedf6b16a0b8252a83c /filter | |
parent | 286b4ee4849831ed3880ae19d74710f0f43753c8 (diff) | |
download | gsoc2013-evolution-d51c9927e53206f889dba63274fd425efe65db5a.tar.gz gsoc2013-evolution-d51c9927e53206f889dba63274fd425efe65db5a.tar.zst gsoc2013-evolution-d51c9927e53206f889dba63274fd425efe65db5a.zip |
go to the proper level of child node before looking for rule sets, fix for
2003-03-11 Not Zed <NotZed@Ximian.com>
* rule-context.c (revert): go to the proper level of child node
before looking for rule sets, fix for #39165 to make 'cancel' work.
svn path=/trunk/; revision=20230
Diffstat (limited to 'filter')
-rw-r--r-- | filter/ChangeLog | 5 | ||||
-rw-r--r-- | filter/rule-context.c | 433 |
2 files changed, 222 insertions, 216 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index 56748d7b10..9cb0eefc5c 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,8 @@ +2003-03-11 Not Zed <NotZed@Ximian.com> + + * rule-context.c (revert): go to the proper level of child node + before looking for rule sets, fix for #39165 to make 'cancel' work. + 2003-03-06 Jeffrey Stedfast <fejj@ximian.com> Fixes for bug #39170 diff --git a/filter/rule-context.c b/filter/rule-context.c index b376bb73d4..c7208dbd69 100644 --- a/filter/rule-context.c +++ b/filter/rule-context.c @@ -42,17 +42,17 @@ #define d(x) -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 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); -static void rule_context_finalise (GObject *obj); +static void rule_context_class_init(RuleContextClass *klass); +static void rule_context_init(RuleContext *rc); +static void rule_context_finalise(GObject *obj); -#define _PRIVATE(x) (((RuleContext *)(x))->priv) +#define _PRIVATE(x)(((RuleContext *)(x))->priv) struct _RuleContextPrivate { int frozen; @@ -71,35 +71,35 @@ static guint signals[LAST_SIGNAL] = { 0 }; GType -rule_context_get_type (void) +rule_context_get_type(void) { static GType type = 0; if (!type) { static const GTypeInfo info = { - sizeof (RuleContextClass), + sizeof(RuleContextClass), NULL, /* base_class_init */ NULL, /* base_class_finalize */ (GClassInitFunc) rule_context_class_init, NULL, /* class_finalize */ NULL, /* class_data */ - sizeof (RuleContext), + sizeof(RuleContext), 0, /* n_preallocs */ (GInstanceInitFunc) rule_context_init, }; - type = g_type_register_static (G_TYPE_OBJECT, "RuleContext", &info, 0); + type = g_type_register_static(G_TYPE_OBJECT, "RuleContext", &info, 0); } return type; } static void -rule_context_class_init (RuleContextClass *klass) +rule_context_class_init(RuleContextClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); - parent_class = g_type_class_ref (G_TYPE_OBJECT); + parent_class = g_type_class_ref(G_TYPE_OBJECT); object_class->finalize = rule_context_finalise; @@ -112,30 +112,30 @@ rule_context_class_init (RuleContextClass *klass) /* signals */ signals[RULE_ADDED] = - g_signal_new ("rule_added", + g_signal_new("rule_added", RULE_TYPE_CONTEXT, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (RuleContextClass, rule_added), + G_STRUCT_OFFSET(RuleContextClass, rule_added), NULL, NULL, filter_marshal_NONE__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); signals[RULE_REMOVED] = - g_signal_new ("rule_removed", + g_signal_new("rule_removed", RULE_TYPE_CONTEXT, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (RuleContextClass, rule_removed), + G_STRUCT_OFFSET(RuleContextClass, rule_removed), NULL, NULL, filter_marshal_NONE__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); signals[CHANGED] = - g_signal_new ("changed", + g_signal_new("changed", RULE_TYPE_CONTEXT, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (RuleContextClass, changed), + G_STRUCT_OFFSET(RuleContextClass, changed), NULL, NULL, filter_marshal_NONE__NONE, @@ -143,56 +143,56 @@ rule_context_class_init (RuleContextClass *klass) } static void -rule_context_init (RuleContext *rc) +rule_context_init(RuleContext *rc) { - rc->priv = g_malloc0 (sizeof (*rc->priv)); + rc->priv = g_malloc0(sizeof(*rc->priv)); - rc->part_set_map = g_hash_table_new (g_str_hash, g_str_equal); - rc->rule_set_map = g_hash_table_new (g_str_hash, g_str_equal); + rc->part_set_map = g_hash_table_new(g_str_hash, g_str_equal); + rc->rule_set_map = g_hash_table_new(g_str_hash, g_str_equal); } static void -free_part_set (struct _part_set_map *map, void *data) +free_part_set(struct _part_set_map *map, void *data) { - g_free (map->name); - g_free (map); + g_free(map->name); + g_free(map); } static void -free_rule_set (struct _rule_set_map *map, void *data) +free_rule_set(struct _rule_set_map *map, void *data) { - g_free (map->name); - g_free (map); + g_free(map->name); + g_free(map); } static void -rule_context_finalise (GObject *obj) +rule_context_finalise(GObject *obj) { - RuleContext *rc = (RuleContext *) obj; + RuleContext *rc =(RuleContext *) obj; - g_list_foreach (rc->rule_set_list, (GFunc)free_rule_set, NULL); - g_list_free (rc->rule_set_list); - g_hash_table_destroy (rc->rule_set_map); + g_list_foreach(rc->rule_set_list, (GFunc)free_rule_set, NULL); + g_list_free(rc->rule_set_list); + g_hash_table_destroy(rc->rule_set_map); - g_list_foreach (rc->part_set_list, (GFunc)free_part_set, NULL); - g_list_free (rc->part_set_list); - g_hash_table_destroy (rc->part_set_map); + g_list_foreach(rc->part_set_list, (GFunc)free_part_set, NULL); + g_list_free(rc->part_set_list); + g_hash_table_destroy(rc->part_set_map); - g_free (rc->error); + g_free(rc->error); - g_list_foreach (rc->parts, (GFunc)g_object_unref, NULL); - g_list_free (rc->parts); - g_list_foreach (rc->rules, (GFunc)g_object_unref, NULL); - g_list_free (rc->rules); + g_list_foreach(rc->parts, (GFunc)g_object_unref, NULL); + g_list_free(rc->parts); + g_list_foreach(rc->rules, (GFunc)g_object_unref, NULL); + g_list_free(rc->rules); if (rc->system) - xmlFreeDoc (rc->system); + xmlFreeDoc(rc->system); if (rc->user) - xmlFreeDoc (rc->user); + xmlFreeDoc(rc->user); - g_free (rc->priv); + g_free(rc->priv); - G_OBJECT_CLASS (parent_class)->finalize (obj); + G_OBJECT_CLASS(parent_class)->finalize(obj); } /** @@ -203,42 +203,42 @@ rule_context_finalise (GObject *obj) * Return value: A new #RuleContext object. **/ RuleContext * -rule_context_new (void) +rule_context_new(void) { - return (RuleContext *) g_object_new (RULE_TYPE_CONTEXT, NULL, NULL); + return(RuleContext *) g_object_new(RULE_TYPE_CONTEXT, NULL, NULL); } void -rule_context_add_part_set (RuleContext *rc, const char *setname, int part_type, RCPartFunc append, RCNextPartFunc next) +rule_context_add_part_set(RuleContext *rc, const char *setname, int part_type, RCPartFunc append, RCNextPartFunc next) { struct _part_set_map *map; - g_assert(g_hash_table_lookup (rc->part_set_map, setname) == NULL); + g_assert(g_hash_table_lookup(rc->part_set_map, setname) == NULL); - map = g_malloc0 (sizeof (*map)); + map = g_malloc0(sizeof(*map)); map->type = part_type; map->append = append; map->next = next; - map->name = g_strdup (setname); - g_hash_table_insert (rc->part_set_map, map->name, map); - rc->part_set_list = g_list_append (rc->part_set_list, map); + map->name = g_strdup(setname); + g_hash_table_insert(rc->part_set_map, map->name, map); + rc->part_set_list = g_list_append(rc->part_set_list, map); d(printf("adding part set '%s'\n", setname)); } void -rule_context_add_rule_set (RuleContext *rc, const char *setname, int rule_type, RCRuleFunc append, RCNextRuleFunc next) +rule_context_add_rule_set(RuleContext *rc, const char *setname, int rule_type, RCRuleFunc append, RCNextRuleFunc next) { struct _rule_set_map *map; - g_assert(g_hash_table_lookup (rc->rule_set_map, setname) == NULL); + g_assert(g_hash_table_lookup(rc->rule_set_map, setname) == NULL); - map = g_malloc0 (sizeof (*map)); + map = g_malloc0(sizeof(*map)); map->type = rule_type; map->append = append; map->next = next; - map->name = g_strdup (setname); - g_hash_table_insert (rc->rule_set_map, map->name, map); - rc->rule_set_list = g_list_append (rc->rule_set_list, map); + map->name = g_strdup(setname); + g_hash_table_insert(rc->rule_set_map, map->name, map); + rc->rule_set_list = g_list_append(rc->rule_set_list, map); d(printf("adding rule set '%s'\n", setname)); } @@ -250,11 +250,11 @@ rule_context_add_rule_set (RuleContext *rc, const char *setname, int rule_type, * Set the text error for the context, or NULL to clear it. **/ static void -rule_context_set_error (RuleContext *rc, char *error) +rule_context_set_error(RuleContext *rc, char *error) { g_assert(rc); - g_free (rc->error); + g_free(rc->error); rc->error = error; } @@ -269,7 +269,7 @@ rule_context_set_error (RuleContext *rc, char *error) * Return value: **/ int -rule_context_load (RuleContext *rc, const char *system, const char *user) +rule_context_load(RuleContext *rc, const char *system, const char *user) { int res; @@ -278,58 +278,58 @@ rule_context_load (RuleContext *rc, const char *system, const char *user) d(printf("rule_context: loading %s %s\n", system, user)); rc->priv->frozen++; - res = RULE_CONTEXT_GET_CLASS (rc)->load (rc, system, user); + res = RULE_CONTEXT_GET_CLASS(rc)->load(rc, system, user); rc->priv->frozen--; return res; } static int -load (RuleContext *rc, const char *system, const char *user) +load(RuleContext *rc, const char *system, const char *user) { xmlNodePtr set, rule, root; struct _part_set_map *part_map; struct _rule_set_map *rule_map; - rule_context_set_error (rc, NULL); + rule_context_set_error(rc, NULL); d(printf("loading rules %s %s\n", system, user)); - rc->system = xmlParseFile (system); + rc->system = xmlParseFile(system); if (rc->system == NULL) { - rule_context_set_error (rc, g_strdup_printf ("Unable to load system rules '%s': %s", - system, g_strerror (errno))); + rule_context_set_error(rc, g_strdup_printf("Unable to load system rules '%s': %s", + system, g_strerror(errno))); return -1; } root = xmlDocGetRootElement(rc->system); - if (root == NULL || strcmp (root->name, "filterdescription")) { - rule_context_set_error (rc, g_strdup_printf ("Unable to load system rules '%s': Invalid format", system)); - xmlFreeDoc (rc->system); + if (root == NULL || strcmp(root->name, "filterdescription")) { + rule_context_set_error(rc, g_strdup_printf("Unable to load system rules '%s': Invalid format", system)); + xmlFreeDoc(rc->system); rc->system = NULL; return -1; } /* doesn't matter if this doens't exist */ - rc->user = xmlParseFile (user); + rc->user = xmlParseFile(user); /* now parse structure */ /* get rule parts */ set = root->children; while (set) { d(printf("set name = %s\n", set->name)); - part_map = g_hash_table_lookup (rc->part_set_map, set->name); + part_map = g_hash_table_lookup(rc->part_set_map, set->name); if (part_map) { d(printf("loading parts ...\n")); rule = set->children; while (rule) { - if (!strcmp (rule->name, "part")) { - FilterPart *part = FILTER_PART (g_object_new (part_map->type, NULL, NULL)); + if (!strcmp(rule->name, "part")) { + FilterPart *part = FILTER_PART(g_object_new(part_map->type, NULL, NULL)); - if (filter_part_xml_create (part, rule) == 0) { - part_map->append (rc, part); + if (filter_part_xml_create(part, rule) == 0) { + part_map->append(rc, part); } else { - g_object_unref (part); - g_warning ("Cannot load filter part"); + g_object_unref(part); + g_warning("Cannot load filter part"); } } rule = rule->next; @@ -344,20 +344,20 @@ load (RuleContext *rc, const char *system, const char *user) set = root?root->children:NULL; while (set) { d(printf("set name = %s\n", set->name)); - rule_map = g_hash_table_lookup (rc->rule_set_map, set->name); + rule_map = g_hash_table_lookup(rc->rule_set_map, set->name); if (rule_map) { d(printf("loading rules ...\n")); rule = set->children; while (rule) { d(printf("checking node: %s\n", rule->name)); - if (!strcmp (rule->name, "rule")) { - FilterRule *part = FILTER_RULE (g_object_new (rule_map->type, NULL, NULL)); + if (!strcmp(rule->name, "rule")) { + FilterRule *part = FILTER_RULE(g_object_new(rule_map->type, NULL, NULL)); - if (filter_rule_xml_decode (part, rule, rc) == 0) { - rule_map->append (rc, part); + if (filter_rule_xml_decode(part, rule, rc) == 0) { + rule_map->append(rc, part); } else { - g_object_unref (part); - g_warning ("Cannot load filter part"); + g_object_unref(part); + g_warning("Cannot load filter part"); } } rule = rule->next; @@ -380,16 +380,16 @@ load (RuleContext *rc, const char *system, const char *user) * Return value: **/ int -rule_context_save (RuleContext *rc, const char *user) +rule_context_save(RuleContext *rc, const char *user) { g_assert(rc); g_assert(user); - return RULE_CONTEXT_GET_CLASS (rc)->save (rc, user); + return RULE_CONTEXT_GET_CLASS(rc)->save(rc, user); } static int -save (RuleContext *rc, const char *user) +save(RuleContext *rc, const char *user) { xmlDocPtr doc; xmlNodePtr root, rules, work; @@ -398,27 +398,27 @@ save (RuleContext *rc, const char *user) struct _rule_set_map *map; int ret; - doc = xmlNewDoc ("1.0"); + doc = xmlNewDoc("1.0"); /* FIXME: set character encoding to UTF-8? */ - root = xmlNewDocNode (doc, NULL, "filteroptions", NULL); - xmlDocSetRootElement (doc, root); + root = xmlNewDocNode(doc, NULL, "filteroptions", NULL); + xmlDocSetRootElement(doc, root); l = rc->rule_set_list; while (l) { map = l->data; - rules = xmlNewDocNode (doc, NULL, map->name, NULL); - xmlAddChild (root, rules); + rules = xmlNewDocNode(doc, NULL, map->name, NULL); + xmlAddChild(root, rules); rule = NULL; - while ((rule = map->next (rc, rule, NULL))) { + while ((rule = map->next(rc, rule, NULL))) { d(printf("processing rule %s\n", rule->name)); - work = filter_rule_xml_encode (rule); - xmlAddChild (rules, work); + work = filter_rule_xml_encode(rule); + xmlAddChild(rules, work); } - l = g_list_next (l); + l = g_list_next(l); } - ret = e_xml_save_file (user, doc); + ret = e_xml_save_file(user, doc); - xmlFreeDoc (doc); + xmlFreeDoc(doc); return ret; } @@ -440,7 +440,7 @@ rule_context_revert(RuleContext *rc, const char *user) d(printf("rule_context: restoring %s %s\n", user)); - return RULE_CONTEXT_GET_CLASS (rc)->revert (rc, user); + return RULE_CONTEXT_GET_CLASS(rc)->revert(rc, user); } struct _revert_data { @@ -449,37 +449,37 @@ struct _revert_data { }; static void -revert_rule_remove (void *key, FilterRule *frule, RuleContext *rc) +revert_rule_remove(void *key, FilterRule *frule, RuleContext *rc) { - rule_context_remove_rule (rc, frule); - g_object_unref (frule); + rule_context_remove_rule(rc, frule); + g_object_unref(frule); } static void revert_source_remove(void *key, struct _revert_data *rest_data, RuleContext *rc) { - g_hash_table_foreach (rest_data->rules, (GHFunc)revert_rule_remove, rc); - g_hash_table_destroy (rest_data->rules); - g_free (rest_data); + g_hash_table_foreach(rest_data->rules, (GHFunc)revert_rule_remove, rc); + g_hash_table_destroy(rest_data->rules); + g_free(rest_data); } static guint -source_hashf (const char *a) +source_hashf(const char *a) { if (a) - return g_str_hash (a); + return g_str_hash(a); return 0; } static int -source_eqf (const char *a, const char *b) +source_eqf(const char *a, const char *b) { - return (a && b && strcmp (a, b) == 0) + return((a && b && strcmp(a, b) == 0)) || (a == NULL && b == NULL); } static int -revert (RuleContext *rc, const char *user) +revert(RuleContext *rc, const char *user) { xmlNodePtr set, rule; /*struct _part_set_map *part_map;*/ @@ -489,68 +489,69 @@ revert (RuleContext *rc, const char *user) xmlDocPtr userdoc; FilterRule *frule; - rule_context_set_error (rc, NULL); + rule_context_set_error(rc, NULL); d(printf("restoring rules %s %s\n", user)); - userdoc = xmlParseFile (user); + userdoc = xmlParseFile(user); if (userdoc == NULL) /* clear out anythign we have? */ return 0; - source_hash = g_hash_table_new ((GHashFunc)source_hashf, (GCompareFunc)source_eqf); + source_hash = g_hash_table_new((GHashFunc)source_hashf, (GCompareFunc)source_eqf); /* setup stuff we have now */ /* Note that we assume there is only 1 set of rules in a given rule context, although other parts of the code dont assume this */ frule = NULL; - while ((frule = rule_context_next_rule (rc, frule, NULL))) { - rest_data = g_hash_table_lookup (source_hash, frule->source); + while ((frule = rule_context_next_rule(rc, frule, NULL))) { + rest_data = g_hash_table_lookup(source_hash, frule->source); if (rest_data == NULL) { - rest_data = g_malloc0 (sizeof (*rest_data)); - rest_data->rules = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_insert (source_hash, frule->source, rest_data); + rest_data = g_malloc0(sizeof(*rest_data)); + rest_data->rules = g_hash_table_new(g_str_hash, g_str_equal); + g_hash_table_insert(source_hash, frule->source, rest_data); } - g_hash_table_insert (rest_data->rules, frule->name, frule); + g_hash_table_insert(rest_data->rules, frule->name, frule); } /* make what we have, match what we load */ - set = userdoc->children; + set = xmlDocGetRootElement(rc->user); + set = set?set->children:NULL; while (set) { d(printf("set name = %s\n", set->name)); - rule_map = g_hash_table_lookup (rc->rule_set_map, set->name); + rule_map = g_hash_table_lookup(rc->rule_set_map, set->name); if (rule_map) { d(printf("loading rules ...\n")); rule = set->children; while (rule) { d(printf("checking node: %s\n", rule->name)); - if (!strcmp (rule->name, "rule")) { - FilterRule *part = FILTER_RULE (g_object_new (rule_map->type, NULL, NULL)); + if (!strcmp(rule->name, "rule")) { + FilterRule *part = FILTER_RULE(g_object_new(rule_map->type, NULL, NULL)); - if (filter_rule_xml_decode (part, rule, rc) == 0) { + if (filter_rule_xml_decode(part, rule, rc) == 0) { /* use the revert data to keep track of the right rank of this rule part */ - rest_data = g_hash_table_lookup (source_hash, part->source); + rest_data = g_hash_table_lookup(source_hash, part->source); if (rest_data == NULL) { - rest_data = g_malloc0 (sizeof (*rest_data)); - rest_data->rules = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_insert (source_hash, part->source, rest_data); + rest_data = g_malloc0(sizeof(*rest_data)); + rest_data->rules = g_hash_table_new(g_str_hash, g_str_equal); + g_hash_table_insert(source_hash, part->source, rest_data); } - frule = g_hash_table_lookup (rest_data->rules, part->name); + frule = g_hash_table_lookup(rest_data->rules, part->name); if (frule) { - if (rc->priv->frozen == 0 && !filter_rule_eq (frule, part)) - filter_rule_copy (frule, part); + if (rc->priv->frozen == 0 && !filter_rule_eq(frule, part)) + filter_rule_copy(frule, part); - g_object_unref (part); - rule_context_rank_rule (rc, frule, rest_data->rank); - g_hash_table_remove (rest_data->rules, frule->name); + g_object_unref(part); + rule_context_rank_rule(rc, frule, rest_data->rank); + g_hash_table_remove(rest_data->rules, frule->name); } else { - rule_context_add_rule (rc, part); - rule_context_rank_rule (rc, part, rest_data->rank); + rule_context_add_rule(rc, part); + rule_context_rank_rule(rc, part, rest_data->rank); } rest_data->rank++; } else { - g_object_unref (part); - g_warning ("Cannot load filter part"); + g_object_unref(part); + g_warning("Cannot load filter part"); } } rule = rule->next; @@ -559,168 +560,168 @@ revert (RuleContext *rc, const char *user) set = set->next; } - xmlFreeDoc (userdoc); + xmlFreeDoc(userdoc); /* remove any we still have that weren't in the file */ - g_hash_table_foreach (source_hash, (GHFunc)revert_source_remove, rc); - g_hash_table_destroy (source_hash); + g_hash_table_foreach(source_hash, (GHFunc)revert_source_remove, rc); + g_hash_table_destroy(source_hash); return 0; } FilterPart * -rule_context_find_part (RuleContext *rc, const char *name) +rule_context_find_part(RuleContext *rc, const char *name) { g_assert(rc); g_assert(name); d(printf("find part : ")); - return filter_part_find_list (rc->parts, name); + return filter_part_find_list(rc->parts, name); } FilterPart * -rule_context_create_part (RuleContext *rc, const char *name) +rule_context_create_part(RuleContext *rc, const char *name) { FilterPart *part; g_assert(rc); g_assert(name); - if ((part = rule_context_find_part (rc, name))) - return filter_part_clone (part); + if ((part = rule_context_find_part(rc, name))) + return filter_part_clone(part); return NULL; } FilterPart * -rule_context_next_part (RuleContext *rc, FilterPart *last) +rule_context_next_part(RuleContext *rc, FilterPart *last) { g_assert(rc); - return filter_part_next_list (rc->parts, last); + return filter_part_next_list(rc->parts, last); } FilterRule * -rule_context_next_rule (RuleContext *rc, FilterRule *last, const char *source) +rule_context_next_rule(RuleContext *rc, FilterRule *last, const char *source) { g_assert(rc); - return filter_rule_next_list (rc->rules, last, source); + return filter_rule_next_list(rc->rules, last, source); } FilterRule * -rule_context_find_rule (RuleContext *rc, const char *name, const char *source) +rule_context_find_rule(RuleContext *rc, const char *name, const char *source) { g_assert(name); g_assert(rc); - return filter_rule_find_list (rc->rules, name, source); + return filter_rule_find_list(rc->rules, name, source); } void -rule_context_add_part (RuleContext *rc, FilterPart *part) +rule_context_add_part(RuleContext *rc, FilterPart *part) { g_assert(rc); g_assert(part); - rc->parts = g_list_append (rc->parts, part); + rc->parts = g_list_append(rc->parts, part); } void -rule_context_add_rule (RuleContext *rc, FilterRule *new) +rule_context_add_rule(RuleContext *rc, FilterRule *new) { g_assert(rc); g_assert(new); d(printf("add rule '%s'\n", new->name)); - rc->rules = g_list_append (rc->rules, new); + rc->rules = g_list_append(rc->rules, new); if (rc->priv->frozen == 0) { - g_signal_emit (rc, signals[RULE_ADDED], 0, new); - g_signal_emit (rc, signals[CHANGED], 0); + g_signal_emit(rc, signals[RULE_ADDED], 0, new); + g_signal_emit(rc, signals[CHANGED], 0); } } static void -new_rule_response (GtkWidget *dialog, int button, RuleContext *context) +new_rule_response(GtkWidget *dialog, int button, RuleContext *context) { if (button == GTK_RESPONSE_ACCEPT) { - FilterRule *rule = g_object_get_data ((GObject *) dialog, "rule"); - char *user = g_object_get_data ((GObject *) dialog, "path"); + FilterRule *rule = g_object_get_data((GObject *) dialog, "rule"); + char *user = g_object_get_data((GObject *) dialog, "path"); - if (!filter_rule_validate (rule)) { + if (!filter_rule_validate(rule)) { /* no need to popup a dialog because the validate code does that. */ return; } - g_object_ref (rule); - rule_context_add_rule (context, rule); + g_object_ref(rule); + rule_context_add_rule(context, rule); if (user) - rule_context_save (context, user); + rule_context_save(context, user); } - gtk_widget_destroy (dialog); + gtk_widget_destroy(dialog); } /* add a rule, with a gui, asking for confirmation first ... optionally save to path */ void -rule_context_add_rule_gui (RuleContext *rc, FilterRule *rule, const char *title, const char *path) +rule_context_add_rule_gui(RuleContext *rc, FilterRule *rule, const char *title, const char *path) { GtkDialog *dialog; GtkWidget *widget; d(printf("add rule gui '%s'\n", rule->name)); - g_assert (rc); - g_assert (rule); + g_assert(rc); + g_assert(rule); - widget = filter_rule_get_widget (rule, rc); - gtk_widget_show (widget); + widget = filter_rule_get_widget(rule, rc); + gtk_widget_show(widget); - dialog = (GtkDialog *) gtk_dialog_new (); - gtk_dialog_add_buttons (dialog, + dialog =(GtkDialog *) gtk_dialog_new(); + gtk_dialog_add_buttons(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); - gtk_window_set_title ((GtkWindow *) dialog, title); - gtk_window_set_default_size ((GtkWindow *) dialog, 600, 400); - gtk_window_set_resizable ((GtkWindow *) dialog, TRUE); + gtk_window_set_title((GtkWindow *) dialog, title); + gtk_window_set_default_size((GtkWindow *) dialog, 600, 400); + gtk_window_set_resizable((GtkWindow *) dialog, TRUE); - gtk_box_pack_start ((GtkBox *) dialog->vbox, widget, TRUE, TRUE, 0); + gtk_box_pack_start((GtkBox *) dialog->vbox, widget, TRUE, TRUE, 0); - g_object_set_data_full ((GObject *) dialog, "rule", rule, g_object_unref); + g_object_set_data_full((GObject *) dialog, "rule", rule, g_object_unref); if (path) - g_object_set_data_full ((GObject *) dialog, "path", g_strdup (path), g_free); + g_object_set_data_full((GObject *) dialog, "path", g_strdup(path), g_free); - g_signal_connect (dialog, "response", G_CALLBACK (new_rule_response), rc); + g_signal_connect(dialog, "response", G_CALLBACK(new_rule_response), rc); - g_object_ref (rc); + g_object_ref(rc); - g_object_set_data_full ((GObject *) dialog, "context", rc, g_object_unref); + g_object_set_data_full((GObject *) dialog, "context", rc, g_object_unref); - gtk_widget_show ((GtkWidget *) dialog); + gtk_widget_show((GtkWidget *) dialog); } void -rule_context_remove_rule (RuleContext *rc, FilterRule *rule) +rule_context_remove_rule(RuleContext *rc, FilterRule *rule) { - g_assert (rc); - g_assert (rule); + g_assert(rc); + g_assert(rule); d(printf("remove rule '%s'\n", rule->name)); - rc->rules = g_list_remove (rc->rules, rule); + rc->rules = g_list_remove(rc->rules, rule); if (rc->priv->frozen == 0) { - g_signal_emit (rc, signals[RULE_REMOVED], 0, rule); - g_signal_emit (rc, signals[CHANGED], 0); + g_signal_emit(rc, signals[RULE_REMOVED], 0, rule); + g_signal_emit(rc, signals[CHANGED], 0); } } void -rule_context_rank_rule (RuleContext *rc, FilterRule *rule, int rank) +rule_context_rank_rule(RuleContext *rc, FilterRule *rule, int rank) { GList *node; int i = 0, index = 0; @@ -728,36 +729,36 @@ rule_context_rank_rule (RuleContext *rc, FilterRule *rule, int rank) g_assert(rc); g_assert(rule); - if (rule_context_get_rank_rule (rc, rule, rule->source) == rank) + if (rule_context_get_rank_rule(rc, rule, rule->source) == rank) return; - rc->rules = g_list_remove (rc->rules, rule); + rc->rules = g_list_remove(rc->rules, rule); node = rc->rules; while (node) { FilterRule *r = node->data; if (i == rank) { - rc->rules = g_list_insert (rc->rules, rule, index); + rc->rules = g_list_insert(rc->rules, rule, index); if (rc->priv->frozen == 0) - g_signal_emit (rc, signals[CHANGED], 0); + g_signal_emit(rc, signals[CHANGED], 0); return; } index++; - if (rule->source == NULL || (r->source && strcmp (r->source, rule->source) == 0)) + if (rule->source == NULL || (r->source && strcmp(r->source, rule->source) == 0)) i++; node = node->next; } - rc->rules = g_list_append (rc->rules, rule); + rc->rules = g_list_append(rc->rules, rule); if (rc->priv->frozen == 0) - g_signal_emit (rc, signals[CHANGED], 0); + g_signal_emit(rc, signals[CHANGED], 0); } int -rule_context_get_rank_rule (RuleContext *rc, FilterRule *rule, const char *source) +rule_context_get_rank_rule(RuleContext *rc, FilterRule *rule, const char *source) { GList *node; int i = 0; @@ -776,7 +777,7 @@ rule_context_get_rank_rule (RuleContext *rc, FilterRule *rule, const char *sourc if (r == rule) return i; - if (source == NULL || (r->source && strcmp (r->source, source) == 0)) + if (source == NULL || (r->source && strcmp(r->source, source) == 0)) i++; node = node->next; @@ -786,7 +787,7 @@ rule_context_get_rank_rule (RuleContext *rc, FilterRule *rule, const char *sourc } FilterRule * -rule_context_find_rank_rule (RuleContext *rc, int rank, const char *source) +rule_context_find_rank_rule(RuleContext *rc, int rank, const char *source) { GList *node; int i = 0; @@ -801,7 +802,7 @@ rule_context_find_rank_rule (RuleContext *rc, int rank, const char *source) d(printf(" checking against rule '%s' rank '%d'\n", r->name, i)); - if (source == NULL || (r->source && strcmp (r->source, source) == 0)) { + if (source == NULL || (r->source && strcmp(r->source, source) == 0)) { if (rank == i) return r; i++; @@ -814,31 +815,31 @@ rule_context_find_rank_rule (RuleContext *rc, int rank, const char *source) } static GList * -delete_uri (RuleContext *rc, const char *uri, GCompareFunc cmp) +delete_uri(RuleContext *rc, const char *uri, GCompareFunc cmp) { return NULL; } GList * -rule_context_delete_uri (RuleContext *rc, const char *uri, GCompareFunc cmp) +rule_context_delete_uri(RuleContext *rc, const char *uri, GCompareFunc cmp) { - return RULE_CONTEXT_GET_CLASS (rc)->delete_uri (rc, uri, cmp); + return RULE_CONTEXT_GET_CLASS(rc)->delete_uri(rc, uri, cmp); } static GList * -rename_uri (RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp) +rename_uri(RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp) { return NULL; } GList * -rule_context_rename_uri (RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp) +rule_context_rename_uri(RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp) { - return RULE_CONTEXT_GET_CLASS (rc)->rename_uri (rc, olduri, newuri, cmp); + return RULE_CONTEXT_GET_CLASS(rc)->rename_uri(rc, olduri, newuri, cmp); } void -rule_context_free_uri_list (RuleContext *rc, GList *uris) +rule_context_free_uri_list(RuleContext *rc, GList *uris) { GList *l = uris, *n; @@ -846,8 +847,8 @@ rule_context_free_uri_list (RuleContext *rc, GList *uris) while (l) { n = l->next; - g_free (l->data); - g_list_free_1 (l); + g_free(l->data); + g_list_free_1(l); l = n; } } |