aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNotZed <NotZed@HelixCode.com>2000-02-25 11:04:30 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-02-25 11:04:30 +0800
commit675d1c25dbedaccbb135dc8ccd784e6706aa4aaa (patch)
tree6b3aa7679bb798df06a97a8067202b6b10438328
parentd83721f8b79ba10df2d067d7d0384c1a0790574e (diff)
downloadgsoc2013-evolution-675d1c25dbedaccbb135dc8ccd784e6706aa4aaa.tar.gz
gsoc2013-evolution-675d1c25dbedaccbb135dc8ccd784e6706aa4aaa.tar.zst
gsoc2013-evolution-675d1c25dbedaccbb135dc8ccd784e6706aa4aaa.zip
Functions for memory management.
2000-02-24 NotZed <NotZed@HelixCode.com> * filter-xml.c (filter_description_free): (filter_load_ruleset_free): (filter_load_optionset_free): Functions for memory management. * filter-arg.c (filter_arg_copy): Copy the values of one arg into another. * filter-druid.c: (option_name_changed): Update the option's description as the user enters it in. svn path=/trunk/; revision=1929
-rw-r--r--filter/ChangeLog11
-rw-r--r--filter/filter-arg.c19
-rw-r--r--filter/filter-arg.h4
-rw-r--r--filter/filter-druid.c34
-rw-r--r--filter/filter-editor.c18
-rw-r--r--filter/filter-xml.c72
6 files changed, 155 insertions, 3 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog
index 5b48899b49..e7b9b025a6 100644
--- a/filter/ChangeLog
+++ b/filter/ChangeLog
@@ -1,10 +1,21 @@
2000-02-24 NotZed <NotZed@HelixCode.com>
+ * filter-xml.c (filter_description_free):
+ (filter_load_ruleset_free):
+ (filter_load_optionset_free): Functions for memory management.
+
+ * filter-arg.c (filter_arg_copy): Copy the values of one arg into
+ another.
+
* filter-editor.c: New widget, a dialogue which uses filter-druid
to present the various editing views.
+ (druid_dialogue_clicked): On finish, save the user's new filter
+ definition where it came from.
* filter-druid.c: Changed to just being a notebook with no tabs,
rather than a full druid (no next/prev/etc buttons).
+ (option_name_changed): Update the option's description as the user
+ enters it in.
2000-02-22 NotZed <NotZed@HelixCode.com>
diff --git a/filter/filter-arg.c b/filter/filter-arg.c
index 1d8affaadc..8adfb5576e 100644
--- a/filter/filter-arg.c
+++ b/filter/filter-arg.c
@@ -165,6 +165,24 @@ filter_arg_clone (FilterArg *arg)
}
void
+filter_arg_copy(FilterArg *dst, FilterArg *src)
+{
+ xmlNodePtr values;
+
+ g_return_if_fail( ((GtkObject *)src)->klass->type == ((GtkObject *)dst)->klass->type );
+
+ /* remove old values */
+ while (dst->values) {
+ filter_arg_remove(dst, dst->values->data);
+ }
+
+ /* clone values */
+ values = filter_arg_values_get_xml(src);
+ filter_arg_values_add_xml(dst, values);
+ xmlFreeNodeList(values);
+}
+
+void
filter_arg_add(FilterArg *arg, void *v)
{
g_return_if_fail(v != NULL);
@@ -181,6 +199,7 @@ filter_arg_remove(FilterArg *arg, void *v)
gtk_signal_emit(GTK_OBJECT(arg), signals[CHANGED]);
}
+
void
filter_arg_write_html(FilterArg *arg, GtkHTML *html, GtkHTMLStreamHandle *stream)
{
diff --git a/filter/filter-arg.h b/filter/filter-arg.h
index bf9448a17a..78ce067bbc 100644
--- a/filter/filter-arg.h
+++ b/filter/filter-arg.h
@@ -67,11 +67,15 @@ struct _FilterArgClass {
guint filter_arg_get_type (void);
FilterArg *filter_arg_new (char *name);
FilterArg *filter_arg_clone(FilterArg *arg);
+void filter_arg_copy (FilterArg *dst, FilterArg *src);
void filter_arg_value_add(FilterArg *a, void *v);
void filter_arg_edit_values(FilterArg *arg);
int filter_arg_edit_value(FilterArg *arg, int index);
+void filter_arg_remove(FilterArg *arg, void *v);
+void filter_arg_add(FilterArg *arg, void *v);
+
xmlNodePtr filter_arg_values_get_xml(FilterArg *arg);
void filter_arg_values_add_xml(FilterArg *arg, xmlNodePtr node);
int filter_arg_get_count(FilterArg *arg);
diff --git a/filter/filter-druid.c b/filter/filter-druid.c
index 0bcb893172..c502302270 100644
--- a/filter/filter-druid.c
+++ b/filter/filter-druid.c
@@ -102,6 +102,8 @@ object_finalize(FilterDruid *obj)
g_free(p->default_html);
+ printf("\n druid finalize!\n\n");
+
/* FIXME: free lists? */
GTK_OBJECT_CLASS(filter_druid_parent)->finalize(obj);
@@ -414,9 +416,19 @@ arg_link_clicked(GtkHTML *html, const char *url, FilterDruid *f)
void *dummy;
if (sscanf(url+4, "%p %p", &dummy, &arg)==2
- && arg) {
+ && arg) {
+ FilterArg *orig;
+
printf("arg = %p\n", arg);
filter_arg_edit_values(arg);
+
+ /* insert the new value into the existing one */
+ orig = gtk_object_get_data(arg, "origin");
+ if (orig) {
+ filter_arg_copy(orig, arg);
+ } else {
+ g_warning("unknown object loaded");
+ }
/* should have a changed signal which propagates the rewrite */
update_display(f, 0);
}
@@ -424,6 +436,24 @@ arg_link_clicked(GtkHTML *html, const char *url, FilterDruid *f)
}
static void
+option_name_changed(GtkEntry *entry, FilterDruid *f)
+{
+ struct filter_desc *desc;
+
+ printf("name chaned: %s\n", gtk_entry_get_text(entry));
+
+ if (f->option_current) {
+ /* FIXME: lots of memory leaks */
+ desc = g_malloc0(sizeof(*desc));
+ desc->data = g_strdup(gtk_entry_get_text(entry));
+ desc->type = FILTER_XML_TEXT;
+ desc->vartype = -1;
+ desc->varname = NULL;
+ f->option_current->description = g_list_append(NULL, desc);
+ }
+}
+
+static void
dialogue_clicked(FilterDruid *d, int button, void *data)
{
GString *s = g_string_new("");
@@ -636,6 +666,8 @@ build_druid(FilterDruid *d)
gtk_box_pack_start((GtkBox *)vbox1, p->activate1, TRUE, FALSE, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p->activate1), TRUE);
+ gtk_signal_connect(GTK_OBJECT(p->name1), "changed", option_name_changed, d);
+
gtk_box_pack_start((GtkBox *)vbox, frame, TRUE, TRUE, 0);
/* another copy of the filter thingy */
diff --git a/filter/filter-editor.c b/filter/filter-editor.c
index d37769359f..1d68276b73 100644
--- a/filter/filter-editor.c
+++ b/filter/filter-editor.c
@@ -35,6 +35,7 @@ struct _FilterEditorPrivate {
GtkWidget *edit, *add, *remove, *up, *down;
/* for sub-druid */
+ struct filter_option *druid_option;
GtkWidget *druid_dialogue;
FilterDruid *druid_druid;
};
@@ -125,7 +126,20 @@ druid_dialogue_clicked(GnomeDialog *d, int button, FilterEditor *e)
printf("Finish!\n");
if (p->druid_druid->option_current) {
/* FIXME: this should be copied? */
- e->useroptions = g_list_append(e->useroptions, p->druid_druid->option_current);
+ if (p->druid_option) {
+ GList *node;
+
+ node = g_list_find(e->useroptions, p->druid_option);
+ if (node) {
+ /* FIXME: memleak, should copy */
+ node->data = p->druid_druid->option_current;
+ } else {
+ g_warning("Cannot find node I edited, appending instead");
+ e->useroptions = g_list_append(e->useroptions, p->druid_druid->option_current);
+ }
+ } else {
+ e->useroptions = g_list_append(e->useroptions, p->druid_druid->option_current);
+ }
filter_druid_set_rules(p->druid, e->useroptions, e->rules, NULL);
}
case 3:
@@ -182,6 +196,8 @@ add_or_edit(FilterEditor *e, struct filter_option *option)
druid_dialogue_clicked(dialogue, 1, e);
}
+ p->druid_option = option;
+
gtk_signal_connect(druid, "option_selected", druid_dialogue_option_selected, e);
gtk_widget_show(druid);
diff --git a/filter/filter-xml.c b/filter/filter-xml.c
index 2371acc5a1..7615350acf 100644
--- a/filter/filter-xml.c
+++ b/filter/filter-xml.c
@@ -400,7 +400,9 @@ filter_clone_optionrule(struct filter_optionrule *or)
rule->rule = or->rule;
arg = or->args;
while (arg) {
- rule->args = g_list_append(rule->args, filter_arg_clone(FILTER_ARG(arg->data)));
+ FilterArg *new = filter_arg_clone(FILTER_ARG(arg->data));
+ gtk_object_set_data(new, "origin", arg->data);
+ rule->args = g_list_append(rule->args, new);
arg = g_list_next(arg);
}
return rule;
@@ -453,6 +455,74 @@ filter_optionrule_new_from_rule(struct filter_rule *rule)
return or;
}
+void
+filter_description_free(GList *descl)
+{
+ GList *node;
+
+ node = descl;
+ while (node) {
+ GList *next = g_list_next(node);
+ struct filter_desc *d = node->data;
+
+ g_free(d->data);
+ g_free(d->varname);
+ g_free(d);
+
+ node = next;
+ }
+ g_list_free(descl);
+}
+
+void
+filter_load_ruleset_free(GList *nodel)
+{
+ GList *node = nodel;
+
+ while (node) {
+ GList *next = g_list_next(node);
+ struct filter_rule *r = node->data;
+
+ filter_description_free(r->description);
+
+ /* g_free(r->name); */
+ /* g_free(r->code); */
+
+ g_free(r);
+ node = next;
+ }
+ g_list_free(nodel);
+}
+
+void
+filter_load_optionset_free(GList *optionl)
+{
+ GList *option = optionl;
+ while (option) {
+ GList *next = g_list_next(option);
+ struct filter_option *fo = option->data;
+ GList *optionrule = fo->options;
+
+ while (optionrule) {
+ GList *next = g_list_next(optionrule);
+ struct filter_optionrule *or = optionrule->data;
+ GList *arg = or->args;
+
+ while (arg) {
+ gtk_object_unref(arg->data);
+ arg = g_list_next(arg);
+ }
+
+ g_list_free(or->args);
+ g_free(or);
+ optionrule = next;
+ }
+ filter_description_free(fo->description);
+ g_list_free(fo->options);
+ g_free(fo);
+ option = next;
+ }
+}
#ifdef TESTER
int main(int argc, char **argv)