From de2d358926885856d43a5f53aecb3739a9b5f3c8 Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 21 May 2000 22:40:15 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'gnomoku-0_3'. svn path=/tags/gnomoku-0_3/; revision=3161 --- filter/.cvsignore | 9 - filter/ChangeLog | 216 ------------- filter/Makefile.am | 35 --- filter/blank.xpm | 22 -- filter/check.xpm | 22 -- filter/filter-arg-types.c | 753 ---------------------------------------------- filter/filter-arg-types.h | 101 ------- filter/filter-arg.c | 563 ---------------------------------- filter/filter-arg.h | 88 ------ filter/filter-driver.c | 619 ------------------------------------- filter/filter-driver.h | 58 ---- filter/filter-druid.c | 736 -------------------------------------------- filter/filter-druid.h | 76 ----- filter/filter-editor.c | 386 ------------------------ filter/filter-editor.h | 58 ---- filter/filter-format.c | 237 --------------- filter/filter-format.h | 10 - filter/filter-xml.c | 580 ----------------------------------- filter/filter-xml.h | 77 ----- filter/filtertypes.xml | 94 ------ 20 files changed, 4740 deletions(-) delete mode 100644 filter/.cvsignore delete mode 100644 filter/ChangeLog delete mode 100644 filter/Makefile.am delete mode 100755 filter/blank.xpm delete mode 100755 filter/check.xpm delete mode 100644 filter/filter-arg-types.c delete mode 100644 filter/filter-arg-types.h delete mode 100644 filter/filter-arg.c delete mode 100644 filter/filter-arg.h delete mode 100644 filter/filter-driver.c delete mode 100644 filter/filter-driver.h delete mode 100644 filter/filter-druid.c delete mode 100644 filter/filter-druid.h delete mode 100644 filter/filter-editor.c delete mode 100644 filter/filter-editor.h delete mode 100644 filter/filter-format.c delete mode 100644 filter/filter-format.h delete mode 100644 filter/filter-xml.c delete mode 100644 filter/filter-xml.h delete mode 100644 filter/filtertypes.xml (limited to 'filter') diff --git a/filter/.cvsignore b/filter/.cvsignore deleted file mode 100644 index 7c13af9a14..0000000000 --- a/filter/.cvsignore +++ /dev/null @@ -1,9 +0,0 @@ -*.la -*.lo -.libs -.deps -.pure -Makefile -Makefile.in -filter-driver -filter-editor diff --git a/filter/ChangeLog b/filter/ChangeLog deleted file mode 100644 index 9387f72a4e..0000000000 --- a/filter/ChangeLog +++ /dev/null @@ -1,216 +0,0 @@ -2000-05-21 Ettore Perazzoli - - * filter-druid.c: Don't pass an empty URL to `gtk_html_begin()' - anymore. - - * filter-arg-types.c: Updated for the new GtkHTML API which uses - `GtkHTMLStream *' instead of `GtkHTMLStreamHandle'. - * filter-arg.c: Likewise. - * filter-arg.h: Likewise. - * filter-druid.c: Likewise. - - * filter-format.c: Likewise. - * filter-format.h: Likewise. - -2000-05-18 Dan Winship - - * filter-driver.c (filter_driver_run): update for - camel_folder_get_uids change - -2000-05-17 NotZed - - * filter-druid.c: Fix some html formatting. - -2000-05-16 NotZed - - * filter-driver.c (filter_driver_run): Delete all processed - messages. This is probably going to slow it down a bit. - (filter_driver_run): Close folders before destroying them *sigh*. - (open_folder): Actually open the folder. Doh. - - * filtertypes.xml: Initial filter rules. - - * filter-xml.c (filter_write_optionset): Save the description - also. - (write_description): Routine to save description - only saves 1 - node of description. - - * filter-arg.c (filter_arg_edit_clicked): Dont free edata here, - let the destroy do it(?) - - * filter-editor.c (main): Simple driver program for testing, so i - can fix all this really broken code *sigh* - -2000-05-15 NotZed - - * filter-editor.c (filter_editor_set_rule_files): filename based - interface. - (filter_editor_save_rules): Interface to save the options to a - filename. - - * filter-xml.[ch]: Bunch of cleanup. - - * filter-xml.c (filter_*_file): New interfaces to read/write files - directly, rather than messing with xmldoc crap. - - * Makefile.am: Removed filter-driver test program, now just part - of libfilter. - - * filter-driver.c: Made an object, with an api and everything, can - apply a filter to a given mailbox. - -2000-05-10 Christopher James Lahey - - * filter-arg.h: Changed tree.h to gnome-xml/tree.h. - - * Makefile.am: Added filter-arg-types.h, filter-arg.h, - filter-xml.h, filter-format.h, filter-druid.h, filter-editor.h. - -2000-05-02 Matt Loper - - * Makefile.am: set G_LOG_DOMAIN. - -2000-05-01 NotZed - - * filter-driver.c (main): Fix for api. - -2000-04-30 Dan Winship - - * filter-driver.c (start): Remove no-longer-necessary call to - camel_provider_register_as_module. - -2000-04-25 Ettore Perazzoli - - * Makefile.am (INCLUDES): Use `$(GTKHTML_CFLAGS)'. - -2000-04-20 NotZed - - * filter-driver.c: Removed a bunch of crappy unrequired headers. - - * Makefile.am (filter_driver_LDADD): Added libibex back again. - -2000-04-18 Dan Winship - - * filter-driver.c: remove unused camel-log.h include - -2000-04-12 Matt Loper - - * filter-arg.c (filter_arg_edit_value): Return a value. - -2000-03-27 NotZed - - * filter-xml.c (tokenise_xmlfreeprop): Free a prop after - tokenising it. - (find_node_attr): Free the prop after using it. - (load_desc): Ditto. I use free() because xmlFree() is nowhere to - be found. - (filter_load_optionset): Ditto. - - * filter-arg-types.c (arg_address_values_add_xml): free() xml - stuff, plugs a leak. - (arg_folder_values_add_xml): Ditto. - -2000-03-22 NotZed - - * filter-driver.c (main): Changed to use async search api. - -2000-03-04 NotZed - - * filter-druid.c (html_write_options): Output 'and' bits between - the rules. - - * filter-driver.c (main): Actually implement filtering, at least, - from Inbox. Copy messages to folder (in the same store only, so - far), delete, and stop processing are implemented, and the logic - to handle default processing. - - * filter-xml.c (load_optionvalue): Fix up a bug where we lost the - name of the arg (ouch). - * filter-xml.c: Wrapped printf's in debug macros. - -2000-03-02 NotZed - - * filter-druid.c (object_destroy): Disconnect the list signal, so - we dont get spurious emits during destroy. - (arg_changed): Callback to update filter arg asynchronously. - (arg_link_clicked): Edit the value non-modally. - - * filter-arg.c (filter_arg_edit_values_1): Changed to use - non-modal interface. - -2000-03-01 Ettore Perazzoli - - * Makefile.am: New file. - - * Makefile: Removed. I wonder why we are using plain Makefiles - instead of automake Makefiles at all. - -2000-02-29 NotZed - - * filter-driver.c (main): Remove gui code, this will be actual - filtering code. - - * Makefile: Added filter-editor to the library. - - * filter-editor.c (main): Comment out, make it a proper library. - -2000-02-28 NotZed - - * filter-druid.c: Removed unused header. - - * Makefile: Removed references to filter-sexp.[ch]. - - * filter-sexp.[ch]: Removed some unecessary includes. Moved to - e-util. Renamed callers. - -2000-02-24 NotZed - - * 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 - - * filter-xml.c (filter_clone_optionrule): - (filter_clone_optionrule_free): - (filter_optionrule_new_from_rule): New utility functions for - working with the internal rule format. - - * filter-arg.[ch]: Added new callbacks for editing a single value, - and a new editor which shows all items in a list, and allows you - to edit them via the single-edit method. This needs some cleanup - for some unused/unusable virtual methods (edit_values, - write_html?). - - * Makefile: Add the druid for build. - - * filter-druid.c: A 'druid' widget for editing a single filter - rule. - -2000-02-21 Matt Loper - - * .cvsignore: New file. - -2000-02-18 NotZed - - * blank/check.xpm: Added forgotten files. - - * Uh, more changes, lots, its still work in progress. - -2000-02-14 NotZed - - * Initial import. - diff --git a/filter/Makefile.am b/filter/Makefile.am deleted file mode 100644 index 32ef89f638..0000000000 --- a/filter/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -INCLUDES = \ - -I $(top_srcdir) \ - -I $(top_srcdir)/libibex \ - -I $(top_srcdir)/camel \ - -I $(top_srcdir)/e-util \ - -I $(top_srcdir)/camel/providers/mbox \ - -I $(GNOME_INCLUDEDIR) \ - $(GTKHTML_CFLAGS) \ - -DG_LOG_DOMAIN=\"filter\" -## - -noinst_LTLIBRARIES = \ - libfilter.la - -libfilter_la_SOURCES = \ - filter-arg-types.c \ - filter-arg-types.h \ - filter-arg.c \ - filter-arg.h \ - filter-xml.c \ - filter-xml.h \ - filter-format.c \ - filter-format.h \ - filter-druid.c \ - filter-druid.h \ - filter-editor.c \ - filter-editor.h \ - filter-driver.c \ - filter-driver.h - -EXTRA_DIST = blank.xpm check.xpm - -# basic rules. -filterdir = $(prefix)/share/evolution -filter_DATA = filtertypes.xml diff --git a/filter/blank.xpm b/filter/blank.xpm deleted file mode 100755 index 499f7a04fc..0000000000 --- a/filter/blank.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * blank_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" .............. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .............. ", -" "}; diff --git a/filter/check.xpm b/filter/check.xpm deleted file mode 100755 index 74f9b56122..0000000000 --- a/filter/check.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * check_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" .............. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .+++++++++.++. ", -" .++++++++..++. ", -" .+++++++...++. ", -" .++.+++...+++. ", -" .++..+...++++. ", -" .++.....+++++. ", -" .+++...++++++. ", -" .++++.+++++++. ", -" .++++++++++++. ", -" .++++++++++++. ", -" .............. ", -" "}; diff --git a/filter/filter-arg-types.c b/filter/filter-arg-types.c deleted file mode 100644 index fd0bb32248..0000000000 --- a/filter/filter-arg-types.c +++ /dev/null @@ -1,753 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * Implementations of the filter-arg types. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -#include "filter-arg-types.h" - - -/* ********************************************************************** */ -/* String */ -/* ********************************************************************** */ - -/* Use for a superclass of any items which are simple strings */ - -static void filter_arg_string_class_init (FilterArgStringClass *class); -static void filter_arg_string_init (FilterArgString *gspaper); - -static FilterArg *string_parent_class; - -guint -filter_arg_string_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "FilterArgString", - sizeof (FilterArgString), - sizeof (FilterArgStringClass), - (GtkClassInitFunc) filter_arg_string_class_init, - (GtkObjectInitFunc) filter_arg_string_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (filter_arg_get_type (), &type_info); - } - - return type; -} - -static void -arg_string_write_html(FilterArg *argin, GtkHTML *html, GtkHTMLStream *stream) -{ - FilterArgString *arg = (FilterArgString *)argin; - /* empty */ -} - -static void -arg_string_write_text(FilterArg *argin, GString *string) -{ - FilterArgString *arg = (FilterArgString *)argin; - GList *l; - char *a; - - l = argin->values; - if (l == NULL) { - g_string_append(string, "folder"); - } - while (l) { - a = l->data; - g_string_append(string, a); - if (l->next) { - g_string_append(string, ", "); - } - l = g_list_next(l); - } -} - -static void -arg_string_edit_values(FilterArg *arg) -{ - printf("edit string values!\n"); -} - -/* pop up a dialogue, asking for a new string value */ -static int -arg_string_edit_value(FilterArg *arg, int index) -{ - GnomeDialog *dialogue; - GtkHBox *hbox; - GtkLabel *label; - GtkEntry *entry; - char *text = NULL; - char *newtext; - - dialogue = (GnomeDialog *)gnome_dialog_new("Edit value", "Ok", "Cancel", 0); - - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 0); - label = (GtkLabel *)gtk_label_new("Folder name"); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)label, FALSE, FALSE, 0); - entry = (GtkEntry *)gtk_entry_new(); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)entry, TRUE, TRUE, 0); - if (index>=0) { - text = filter_arg_get_value(arg, index); - } - if (text) { - gtk_entry_set_text(entry, text); - } - gtk_box_pack_start((GtkBox *)dialogue->vbox, (GtkWidget *)hbox, TRUE, TRUE, 0); - gtk_widget_show_all((GtkWidget *)hbox); - gtk_object_ref((GtkObject *)entry); /* so we can get the text back afterwards */ - if (gnome_dialog_run_and_close(dialogue) == 0) { - GList *node; - - newtext = g_strdup(gtk_entry_get_text(entry)); - gtk_object_unref((GtkObject *)entry); - if (index>=0 - && (node = g_list_find(arg->values, text))) { - node->data = newtext; - } else { - arg->values = g_list_append(arg->values, newtext); - } - g_free(text); - return g_list_index(arg->values, newtext); - } - return -1; -} - -static xmlNodePtr -arg_string_values_get_xml(FilterArg *argin) -{ - xmlNodePtr value; - FilterArgString *arg = (FilterArgString *)argin; - GList *l; - char *a; - - value = xmlNewNode(NULL, "optionvalue"); - xmlSetProp(value, "name", argin->name); - - l = argin->values; - while (l) { - xmlNodePtr cur; - - a = l->data; - - cur = xmlNewChild(value, NULL, "folder", NULL); - if (a) - xmlSetProp(cur, "folder", a); - l = g_list_next(l); - } - - return value; -} - -static void -arg_string_values_add_xml(FilterArg *arg, xmlNodePtr node) -{ - xmlNodePtr n; - - n = node->childs; - while (n) { - if (!strcmp(n->name, "folder")) { - filter_arg_string_add(arg, xmlGetProp(n, "folder")); - } else { - g_warning("Loading folders from xml, wrong node encountered: %s\n", n->name); - } - n = n->next; - } -} - -static char * -arg_string_get_value_as_string(FilterArg *argin, void *data) -{ - FilterArgString *arg = (FilterArgString *)argin; - char *a = (char *)data; - - return a; -} - -static void -arg_string_free_value(FilterArg *arg, void *a) -{ - g_free(a); -} - -static void -filter_arg_string_class_init (FilterArgStringClass *class) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) class; - if (string_parent_class == NULL) - string_parent_class = gtk_type_class (gtk_object_get_type ()); - - class->parent_class.write_html = arg_string_write_html; - class->parent_class.write_text = arg_string_write_text; - class->parent_class.edit_values = arg_string_edit_values; - class->parent_class.edit_value = arg_string_edit_value; - class->parent_class.free_value = arg_string_free_value; - class->parent_class.get_value_as_string = arg_string_get_value_as_string; - - class->parent_class.values_get_xml = arg_string_values_get_xml; - class->parent_class.values_add_xml = arg_string_values_add_xml; -} - -static void -filter_arg_string_init (FilterArgString *arg) -{ - arg->arg.values = NULL; -} - -/** - * filter_arg_string_new: - * - * Create a new FilterArgString widget. - * - * Return value: A new FilterArgString widget. - **/ -FilterArg * -filter_arg_string_new (char *name) -{ - FilterArg *a = FILTER_ARG ( gtk_type_new (filter_arg_string_get_type ())); - a->name = g_strdup(name); - return a; -} - - -void -filter_arg_string_add(FilterArg *arg, char *name) -{ - filter_arg_add(arg, g_strdup(name)); -} - -void -filter_arg_string_remove(FilterArg *arg, char *name) -{ - /* do it */ -} - - -/* ********************************************************************** */ -/* Address */ -/* ********************************************************************** */ - -static void filter_arg_address_class_init (FilterArgAddressClass *class); -static void filter_arg_address_init (FilterArgAddress *gspaper); - -static FilterArg *parent_class; - -guint -filter_arg_address_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "FilterArgAddress", - sizeof (FilterArgAddress), - sizeof (FilterArgAddressClass), - (GtkClassInitFunc) filter_arg_address_class_init, - (GtkObjectInitFunc) filter_arg_address_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (filter_arg_get_type (), &type_info); - } - - return type; -} - -static void -arg_address_write_html(FilterArg *argin, GtkHTML *html, GtkHTMLStream *stream) -{ - FilterArgAddress *arg = (FilterArgAddress *)argin; - /* empty */ -} - -static void -arg_address_write_text(FilterArg *argin, GString *string) -{ - FilterArgAddress *arg = (FilterArgAddress *)argin; - GList *l; - struct filter_arg_address *a; - - l = argin->values; - if (l == NULL) { - g_string_append(string, "email address"); - } - while (l) { - a = l->data; - g_string_append(string, a->name); - if (l->next) { - g_string_append(string, ", "); - } - l = g_list_next(l); - } -} - -static void -arg_address_edit_values(FilterArg *arg) -{ - printf("edit it!\n"); -} - -static int -arg_address_edit_value(FilterArg *arg, int index) -{ - GnomeDialog *dialogue; - GtkHBox *hbox; - GtkLabel *label; - GtkEntry *entry; - char *text = NULL; - char *newtext; - struct filter_arg_address *ad; - - dialogue = (GnomeDialog *)gnome_dialog_new("Edit value", "Ok", "Cancel", 0); - - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 0); - label = (GtkLabel *)gtk_label_new("Folder name"); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)label, FALSE, FALSE, 0); - entry = (GtkEntry *)gtk_entry_new(); - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)entry, TRUE, TRUE, 0); - if (index>=0 - && (ad = filter_arg_get_value(arg, index))) { - text = ad->email; - } - if (text) { - gtk_entry_set_text(entry, text); - } - gtk_box_pack_start((GtkBox *)dialogue->vbox, (GtkWidget *)hbox, TRUE, TRUE, 0); - gtk_widget_show_all((GtkWidget *)hbox); - gtk_object_ref((GtkObject *)entry); /* so we can get the text back afterwards */ - if (gnome_dialog_run_and_close(dialogue) == 0) { - GList *node; - - newtext = g_strdup(gtk_entry_get_text(entry)); - gtk_object_unref((GtkObject *)entry); - if (index>=0 - && (node = g_list_find(arg->values, text))) { - ad = node->data; - ad->email = newtext; - } else { - ad = g_malloc0(sizeof(*ad)); - ad->email = newtext; - arg->values = g_list_append(arg->values, ad); - } - g_free(text); - return g_list_index(arg->values, ad); - } - return -1; -} - -static xmlNodePtr -arg_address_values_get_xml(FilterArg *argin) -{ - xmlNodePtr value; - FilterArgAddress *arg = (FilterArgAddress *)argin; - GList *l; - struct filter_arg_address *a; - - /* hmm, perhaps this overhead should be in FilterArg, and this function just returns the base node?? */ - value = xmlNewNode(NULL, "optionvalue"); - xmlSetProp(value, "name", argin->name); - - l = argin->values; - while (l) { - xmlNodePtr cur; - - a = l->data; - - cur = xmlNewChild(value, NULL, "address", NULL); - if (a->name) - xmlSetProp(cur, "name", a->name); - if (a->email) - xmlSetProp(cur, "email", a->email); - l = g_list_next(l); - } - - return value; -} - -static void -arg_address_values_add_xml(FilterArg *arg, xmlNodePtr node) -{ - xmlNodePtr n; - - n = node->childs; - while (n) { - if (!strcmp(n->name, "address")) { - char *nm, *e; - nm = xmlGetProp(n, "name"); - e = xmlGetProp(n, "email"); - filter_arg_address_add(arg, nm, e); - free(nm); - free(e); - } else { - g_warning("Loading address from xml, wrong node encountered: %s\n", n->name); - } - n = n->next; - } -} - -/* the search string is just the raw email address */ -static char * -arg_address_get_value_as_string(FilterArg *argin, void *data) -{ - FilterArgAddress *arg = (FilterArgAddress *)argin; - struct filter_arg_address *a = (struct filter_arg_address *)data; - - printf("geting address as string : %s %s\n", a->email, a->name); - - if (a->email == NULL - || a->email[0] == '\0') { - if (a->name == NULL - || a->name[0] == '\0') - return ""; - return a->name; - } else - return a->email; -} - -static void -arg_address_free_value(FilterArg *arg, struct filter_arg_address *a) -{ - g_free(a->name); - g_free(a->email); - g_free(a); -} - -static void -filter_arg_address_class_init (FilterArgAddressClass *class) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) class; - if (parent_class == NULL) - parent_class = gtk_type_class (gtk_object_get_type ()); - - class->parent_class.write_html = arg_address_write_html; - class->parent_class.write_text = arg_address_write_text; - class->parent_class.edit_values= arg_address_edit_values; - class->parent_class.edit_value= arg_address_edit_value; - class->parent_class.free_value = arg_address_free_value; - - class->parent_class.values_get_xml = arg_address_values_get_xml; - class->parent_class.values_add_xml = arg_address_values_add_xml; - - class->parent_class.get_value_as_string = arg_address_get_value_as_string; -} - -static void -filter_arg_address_init (FilterArgAddress *arg) -{ -} - -/** - * filter_arg_address_new: - * - * Create a new FilterArgAddress widget. - * - * Return value: A new FilterArgAddress widget. - **/ -FilterArg * -filter_arg_address_new (char *name) -{ - FilterArg *a = FILTER_ARG ( gtk_type_new (filter_arg_address_get_type ())); - a->name = g_strdup(name); - return a; -} - -void -filter_arg_address_add(FilterArg *arg, char *name, char *email) -{ - struct filter_arg_address *a; - - a = g_malloc0(sizeof(*a)); - - a->name = g_strdup(name); - a->email = g_strdup(email); - - filter_arg_add(arg, a); -} - -void -filter_arg_address_remove(FilterArg *arg, char *name, char *email) -{ - -} - -/* ********************************************************************** */ -/* Folder */ -/* ********************************************************************** */ - - -static void filter_arg_folder_class_init (FilterArgFolderClass *class); -static void filter_arg_folder_init (FilterArgFolder *gspaper); - -static FilterArg *folder_parent_class; - -guint -filter_arg_folder_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "FilterArgFolder", - sizeof (FilterArgFolder), - sizeof (FilterArgFolderClass), - (GtkClassInitFunc) filter_arg_folder_class_init, - (GtkObjectInitFunc) filter_arg_folder_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (filter_arg_string_get_type (), &type_info); - } - - return type; -} - -static void -arg_folder_write_html(FilterArg *argin, GtkHTML *html, GtkHTMLStream *stream) -{ - FilterArgFolder *arg = (FilterArgFolder *)argin; - /* empty */ -} - -static void -arg_folder_write_text(FilterArg *argin, GString *string) -{ - FilterArgFolder *arg = (FilterArgFolder *)argin; - GList *l; - char *a; - - l = argin->values; - if (l == NULL) { - g_string_append(string, "folder"); - } - while (l) { - a = l->data; - g_string_append(string, a); - if (l->next) { - g_string_append(string, ", "); - } - l = g_list_next(l); - } -} - -static void -arg_folder_edit_values(FilterArg *argin) -{ - FilterArgFolder *arg = (FilterArgFolder *)argin; - GList *l; - char *a, *start, *ptr, *ptrend, *ptrgap; - char outbuf[128], *outptr; /* FIXME: dont use a bounded buffer! */ - GString *string = g_string_new(""); - GtkWidget *dialogue; - GtkWidget *text; - - dialogue = gnome_dialog_new("Edit addresses", - "Ok", "Cancel", NULL); - text = gtk_text_new(NULL, NULL); - gtk_object_ref((GtkObject *)text); - - l = argin->values; - while (l) { - a = l->data; - gtk_text_insert(text, NULL, NULL, NULL, a, strlen(a)); - gtk_text_insert(text, NULL, NULL, NULL, "\n", 1); - l = g_list_next(l); - } - - gtk_box_pack_start(GNOME_DIALOG(dialogue)->vbox, text, TRUE, TRUE, 2); - gtk_widget_show(text); - gtk_text_set_editable(text, 1); - - gnome_dialog_run_and_close(dialogue); - - /* FIXME: free current values */ - argin->values = NULL; - ptr = GTK_TEXT(text)->text.ch; - ptrend = ptr+GTK_TEXT(text)->text_end; - ptrgap = ptr+GTK_TEXT(text)->gap_position; - - start = ptr; - outptr = outbuf; - while (ptr0) { - new = g_malloc(len+1); - new[len]=0; - memcpy(new, outbuf, len); - printf("(appending '%s')", new); - argin->values = g_list_append(argin->values, new); - } - outptr = outbuf; - } else { - *outptr++ = *ptr; - } - ptr++; - if (ptr==ptrgap) { - ptr += GTK_TEXT(text)->gap_size; - } - } - if (outptr>outbuf) { - int len = outptr-outbuf; - char *new; - - printf("(lastlen = %d)", len); - - new = g_malloc(len+1); - new[len]=0; - memcpy(new, start, len); - argin->values = g_list_append(argin->values, new); - } - printf("\n"); -} - -static xmlNodePtr -arg_folder_values_get_xml(FilterArg *argin) -{ - xmlNodePtr value; - FilterArgFolder *arg = (FilterArgFolder *)argin; - GList *l; - char *a; - - value = xmlNewNode(NULL, "optionvalue"); - xmlSetProp(value, "name", argin->name); - - l = argin->values; - while (l) { - xmlNodePtr cur; - - a = l->data; - - cur = xmlNewChild(value, NULL, "folder", NULL); - if (a) - xmlSetProp(cur, "name", a); - l = g_list_next(l); - } - - return value; -} - -static void -arg_folder_values_add_xml(FilterArg *arg, xmlNodePtr node) -{ - xmlNodePtr n; - - printf("adding folder values ...\n"); - - n = node->childs; - while (n) { - if (!strcmp(n->name, "folder")) { - char *name = xmlGetProp(n, "name"); - if (name) { - filter_arg_folder_add(arg, name); - free(name); - } else - g_warning("no xml prop 'name' on '%s'\n", n->name); - } else { - g_warning("Loading folders from xml, wrong node encountered: %s\n", n->name); - } - n = n->next; - } -} - -static char * -arg_folder_get_value_as_string(FilterArg *argin, void *data) -{ - FilterArgFolder *arg = (FilterArgFolder *)argin; - char *a = (char *)data; - - return a; -} - -static void -arg_folder_free_value(FilterArg *arg, void *a) -{ - g_free(a); -} - -static void -filter_arg_folder_class_init (FilterArgFolderClass *class) -{ - GtkObjectClass *object_class; - FilterArgClass *filter_class; - - object_class = (GtkObjectClass *) class; - filter_class = (FilterArgClass *) class; - if (folder_parent_class == NULL) - folder_parent_class = gtk_type_class (filter_arg_string_get_type ()); - - /* FIXME: only need to over-ride the edit values right? */ - filter_class->write_html = arg_folder_write_html; - filter_class->write_text = arg_folder_write_text; - filter_class->edit_values = arg_folder_edit_values; - filter_class->free_value = arg_folder_free_value; - - filter_class->values_get_xml = arg_folder_values_get_xml; - filter_class->values_add_xml = arg_folder_values_add_xml; -} - -static void -filter_arg_folder_init (FilterArgFolder *arg) -{ -} - -/** - * filter_arg_folder_new: - * - * Create a new FilterArgFolder widget. - * - * Return value: A new FilterArgFolder widget. - **/ -FilterArg * -filter_arg_folder_new (char *name) -{ - FilterArg *a = FILTER_ARG ( gtk_type_new (filter_arg_folder_get_type ())); - a->name = g_strdup(name); - return a; -} - - -void -filter_arg_folder_add(FilterArg *arg, char *name) -{ - filter_arg_add(arg, g_strdup(name)); -} - -void -filter_arg_folder_remove(FilterArg *arg, char *name) -{ - /* do it */ -} diff --git a/filter/filter-arg-types.h b/filter/filter-arg-types.h deleted file mode 100644 index 6a1d80bfae..0000000000 --- a/filter/filter-arg-types.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * Implementations of the filter-args. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef _FILTER_ARG_TYPES_H -#define _FILTER_ARG_TYPES_H - -#include "filter-arg.h" - -/* An Address */ -#define FILTER_ARG_ADDRESS(obj) GTK_CHECK_CAST (obj, filter_arg_address_get_type (), FilterArgAddress) -#define FILTER_ARG_ADDRESS_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_arg_address_get_type (), FilterArgAddressClass) -#define IS_FILTER_ARG_ADDRESS(obj) GTK_CHECK_TYPE (obj, filter_arg_address_get_type ()) - -typedef struct _FilterArgAddress FilterArgAddress; -typedef struct _FilterArgAddressClass FilterArgAddressClass; - -struct _FilterArgAddress { - FilterArg arg; -}; - -struct _FilterArgAddressClass { - FilterArgClass parent_class; -}; - -struct filter_arg_address { - char *name; - char *email; -}; - -guint filter_arg_address_get_type (void); -FilterArg *filter_arg_address_new (char *name); -void filter_arg_address_add(FilterArg *, char *name, char *email); -void filter_arg_address_remove(FilterArg *, char *name, char *email); - -/* A simple String */ -#define FILTER_ARG_STRING(obj) GTK_CHECK_CAST (obj, filter_arg_string_get_type (), FilterArgString) -#define FILTER_ARG_STRING_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_arg_string_get_type (), FilterArgStringClass) -#define IS_FILTER_ARG_STRING(obj) GTK_CHECK_TYPE (obj, filter_arg_string_get_type ()) - -typedef struct _FilterArgString FilterArgString; -typedef struct _FilterArgStringClass FilterArgStringClass; - -struct _FilterArgString { - FilterArg arg; - - /* Name/property to save/load to xml */ - /* char *xmlname; */ - /* char *xmlprop; */ -}; - -struct _FilterArgStringClass { - FilterArgClass parent_class; -}; - -guint filter_arg_string_get_type (void); -FilterArg *filter_arg_string_new (char *name); -void filter_arg_string_add(FilterArg *, char *name); -void filter_arg_string_remove(FilterArg *, char *name); - -/* A Folder, subclass of a string */ -#define FILTER_ARG_FOLDER(obj) GTK_CHECK_CAST (obj, filter_arg_folder_get_type (), FilterArgFolder) -#define FILTER_ARG_FOLDER_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_arg_folder_get_type (), FilterArgFolderClass) -#define IS_FILTER_ARG_FOLDER(obj) GTK_CHECK_TYPE (obj, filter_arg_folder_get_type ()) - -typedef struct _FilterArgFolder FilterArgFolder; -typedef struct _FilterArgFolderClass FilterArgFolderClass; - -struct _FilterArgFolder { - FilterArgString arg; -}; - -struct _FilterArgFolderClass { - FilterArgStringClass parent_class; -}; - -guint filter_arg_folder_get_type (void); -FilterArg *filter_arg_folder_new (char *name); -void filter_arg_folder_add(FilterArg *, char *name); -void filter_arg_folder_remove(FilterArg *, char *name); - -#endif /* ! _FILTER_ARG_TYPES_H */ - diff --git a/filter/filter-arg.c b/filter/filter-arg.c deleted file mode 100644 index ece10efbba..0000000000 --- a/filter/filter-arg.c +++ /dev/null @@ -1,563 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * Abstract filter argument class. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include - -#include "filter-arg.h" - - -static void filter_arg_class_init (FilterArgClass *class); -static void filter_arg_init (FilterArg *gspaper); - -#define _PRIVATE(x) (((FilterArg *)(x))->priv) - -struct _FilterArgPrivate { - GtkWidget *dialogue; /* editor widget */ - xmlNodePtr *oldargs; -}; - -static GtkObjectClass *parent_class; - -enum { - CHANGED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -guint -filter_arg_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "FilterArg", - sizeof (FilterArg), - sizeof (FilterArgClass), - (GtkClassInitFunc) filter_arg_class_init, - (GtkObjectInitFunc) filter_arg_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &type_info); - } - - return type; -} - -static FilterArg * -clone_default(FilterArg *a) -{ - xmlNodePtr values; - FilterArg *new = FILTER_ARG ( gtk_type_new (((GtkObject *)a)->klass->type) ); - - /* clone values */ - new->name = g_strdup(a->name); - values = filter_arg_values_get_xml(a); - filter_arg_values_add_xml(new, values); - xmlFreeNodeList(values); - - return new; -} - -static void -write_html_nothing(FilterArg *arg, GtkHTML *html, GtkHTMLStream *stream) -{ - /* empty */ -} - -static void -write_text_nothing(FilterArg *arg, GString *string) -{ - /* empty */ -} - -static void -edit_values_nothing(FilterArg *arg) -{ - /* empty */ -} - -static void * -edit_value_nothing(FilterArg *arg, void *v) -{ - return v; -} - -static void -free_value_nothing(FilterArg *arg, void *v) -{ - /* empty */ -} - -static gint -compare_pointers(gpointer a, gpointer b) -{ - return a==b; -} - -static void -filter_arg_class_init (FilterArgClass *class) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) class; - parent_class = gtk_type_class (gtk_object_get_type ()); - - class->write_html = write_html_nothing; - class->write_text = write_text_nothing; - class->edit_values = edit_values_nothing; - class->edit_value = edit_value_nothing; - class->free_value = free_value_nothing; - class->clone = clone_default; - - signals[CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (FilterArgClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -filter_arg_init (FilterArg *arg) -{ - arg->values = NULL; - arg->priv = g_malloc0(sizeof(*arg->priv)); -} - -/** - * filter_arg_new: - * - * Create a new FilterArg widget. - * - * Return value: A new FilterArg widget. - **/ -FilterArg * -filter_arg_new (char *name) -{ - FilterArg *a = FILTER_ARG ( gtk_type_new (filter_arg_get_type ())); - if (name) - a->name = g_strdup(name); - return a; -} - -FilterArg * -filter_arg_clone (FilterArg *arg) -{ - return ((FilterArgClass *)(arg->object.klass))->clone(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); - - arg->values = g_list_append(arg->values, v); - gtk_signal_emit(GTK_OBJECT(arg), signals[CHANGED]); -} - -void -filter_arg_remove(FilterArg *arg, void *v) -{ - arg->values = g_list_remove(arg->values, v); - ((FilterArgClass *)(arg->object.klass))->free_value(arg, v); - gtk_signal_emit(GTK_OBJECT(arg), signals[CHANGED]); -} - - -void -filter_arg_write_html(FilterArg *arg, GtkHTML *html, GtkHTMLStream *stream) -{ - ((FilterArgClass *)(arg->object.klass))->write_html(arg, html, stream); -} -void -filter_arg_write_text(FilterArg *arg, GString *string) -{ - int count, i; - - count = filter_arg_get_count(arg); - for (i=0;i1) { - g_string_append(string, "or "); - } - } - -#if 0 - ((FilterArgClass *)(arg->object.klass))->write_text(arg, string); -#endif -} -void -filter_arg_edit_values(FilterArg *arg) -{ - void filter_arg_edit_values_1(FilterArg *arg); - - g_return_if_fail(arg != NULL); - - -#if 1 - filter_arg_edit_values_1(arg); -#else - - if (((FilterArgClass *)(arg->object.klass))->edit_values) - ((FilterArgClass *)(arg->object.klass))->edit_values(arg); - else - g_warning("No implementation of virtual method edit_values"); -#endif -} - -int -filter_arg_edit_value(FilterArg *arg, int index) -{ - return ((FilterArgClass *)(arg->object.klass))->edit_value(arg, index); -} - -xmlNodePtr -filter_arg_values_get_xml(FilterArg *arg) -{ - return ((FilterArgClass *)(arg->object.klass))->values_get_xml(arg); -} -void -filter_arg_values_add_xml(FilterArg *arg, xmlNodePtr node) -{ - ((FilterArgClass *)(arg->object.klass))->values_add_xml(arg, node); -} - -/* returns the number of args in the arg list */ -int -filter_arg_get_count(FilterArg *arg) -{ - int count=0; - GList *l; - - for (l = arg->values;l;l=g_list_next(l)) - count++; - return count; -} - -void * -filter_arg_get_value(FilterArg *arg, int index) -{ - int count=0; - GList *l; - - for (l = arg->values;l && countdata; - return NULL; -} - -char * -filter_arg_get_value_as_string(FilterArg *arg, int index) -{ - int count=0; - GList *l; - void *data; - - data = filter_arg_get_value(arg, index); - if (data) { - return ((FilterArgClass *)(arg->object.klass))->get_value_as_string(arg, data); - } else { - return ""; - } -} - - -struct filter_arg_edit { - FilterArg *arg; - GtkList *list; - GList *items; - GnomeDialog *dialogue; - GtkWidget *add, *remove, *edit; - GtkWidget *item_current; -}; - -static void -filter_arg_edit_add(GtkWidget *w, struct filter_arg_edit *edata) -{ - GtkListItem *listitem; - GList *items = NULL; - int i; - - printf("adding new item\n"); - - printf("editing ...\n"); - - i = filter_arg_edit_value(edata->arg, -1); - if (i>=0) { - gtk_list_remove_items_no_unref(edata->list, edata->items); - listitem = (GtkListItem *)gtk_list_item_new_with_label(filter_arg_get_value_as_string(edata->arg, i)); - gtk_object_set_data((GtkObject *)listitem, "arg_i", filter_arg_get_value(edata->arg, i)); - edata->items = g_list_append(edata->items, listitem); - gtk_widget_show((GtkWidget *)listitem); - - /* this api is nonsense */ - gtk_list_append_items(edata->list, g_list_copy(edata->items)); - } -} - -void dump_list(GList *list) -{ - printf("dumping list:\n"); - for (;list;list = g_list_next(list)) { - printf(" %p %p\n", list, list->data); - } -} - -static void -fill_list(struct filter_arg_edit *edata) -{ - GList *items = NULL; - int i, count; - GtkListItem *listitem; - - gtk_list_remove_items(edata->list, edata->items); - g_list_free(edata->items); - - count = filter_arg_get_count(edata->arg); - for (i=0;iarg, i); - listitem = (GtkListItem *)gtk_list_item_new_with_label(labeltext); - gtk_object_set_data((GtkObject *)listitem, "arg_i", filter_arg_get_value(edata->arg, i)); - items = g_list_append(items, listitem); - gtk_widget_show(GTK_WIDGET(listitem)); - printf("adding item %d\n", i); - } - - printf("items re-added\n"); - - edata->item_current = NULL; - edata->items = items; - - gtk_list_append_items(edata->list, g_list_copy(edata->items)); -} - -static void -filter_arg_edit_edit(GtkWidget *w, struct filter_arg_edit *edata) -{ - char *name; - int i; - - /* yurck */ - if (edata->item_current - && (name = gtk_object_get_data((GtkObject *)edata->item_current, "arg_i")) - && (i = g_list_index(edata->arg->values, name)) >= 0 - && (i = filter_arg_edit_value(edata->arg, i)) >= 0) { - - fill_list(edata); - } -} - -static void -filter_arg_edit_delete(GtkWidget *w, struct filter_arg_edit *edata) -{ - GtkListItem *listitem; - char *name; - - /* yurck */ - if (edata->item_current - && (name = gtk_object_get_data((GtkObject *)edata->item_current, "arg_i"))) { - filter_arg_remove(edata->arg, name); - fill_list(edata); - } -} - -static void -edit_sensitise(struct filter_arg_edit *edata) -{ - int state = edata->item_current != NULL; - gtk_widget_set_sensitive(edata->remove, state); - gtk_widget_set_sensitive(edata->edit, state); -} - -static void -filter_arg_edit_select(GtkWidget *w, GtkListItem *list, struct filter_arg_edit *edata) -{ - edata->item_current = list; - edit_sensitise(edata); - - printf ("node = %p\n", g_list_find(edata->items, edata->item_current)); -} - -static void -filter_arg_edit_unselect(GtkWidget *w, GtkListItem *list, struct filter_arg_edit *edata) -{ - edata->item_current = NULL; - edit_sensitise(edata); -} - -static void -filter_arg_edit_clicked(GnomeDialog *d, int button, struct filter_arg_edit *edata) -{ - struct _FilterArgPrivate *p = _PRIVATE(edata->arg); - - printf("window finished\n"); - if (button==0) { - gtk_signal_emit(GTK_OBJECT(edata->arg), signals[CHANGED]); - } else { - /* cancel button, restore old values ... */ - printf("cancel button\n"); - while (edata->arg->values) { - filter_arg_remove(edata->arg, edata->arg->values->data); - } - filter_arg_values_add_xml(edata->arg, p->oldargs); - } - xmlFreeNodeList(p->oldargs); - p->oldargs = NULL; - p->dialogue = NULL; - gnome_dialog_close(d); -} - -static void -filter_arg_edit_destroy(GnomeDialog *d, struct filter_arg_edit *edata) -{ - struct _FilterArgPrivate *p = _PRIVATE(edata->arg); - - if (p->oldargs) { - while (edata->arg->values) { - filter_arg_remove(edata->arg, edata->arg->values->data); - } - filter_arg_values_add_xml(edata->arg, p->oldargs); - xmlFreeNodeList(p->oldargs); - p->oldargs = NULL; - } - - if (p->dialogue) { - p->dialogue = NULL; - gnome_dialog_close(d); - } - g_free(edata); -} - -void -filter_arg_edit_values_1(FilterArg *arg) -{ - GList *vales; - GtkList *list; - GtkListItem *listitem; - int count, i; - GnomeDialog *dialogue; - GtkHBox *hbox; - GtkVBox *vbox; - GtkWidget *button; - GtkWidget *scrolled_window, *frame; - struct filter_arg_edit * edata; - struct _FilterArgPrivate *p = _PRIVATE(arg); - - /* dont show more than 1 editor for each type */ - if (p->dialogue) { - gdk_window_raise(GTK_WIDGET(p->dialogue)->window); - return; - } - - /* copy the current state */ - p->oldargs= filter_arg_values_get_xml(arg); - - edata = g_malloc0(sizeof(*edata)); - edata->item_current = NULL; - edata->arg = arg; - - dialogue = (GnomeDialog *)gnome_dialog_new("Edit values", "Ok", "Cancel", 0); - edata->dialogue = dialogue; - - p->dialogue = dialogue; - - hbox = (GtkHBox *)gtk_hbox_new(FALSE, 0); - - list = (GtkList *)gtk_list_new(); - edata->list = list; - edata->items = NULL; - fill_list(edata); - - scrolled_window = gtk_scrolled_window_new(NULL, NULL); - frame = gtk_frame_new("Option values"); - - gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), (GtkWidget *)list); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_container_set_focus_vadjustment(GTK_CONTAINER (list), gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window))); - gtk_container_add(GTK_CONTAINER(frame), scrolled_window); - gtk_widget_set_usize(frame, 200, 300); - gtk_box_pack_start((GtkBox *)hbox, frame, TRUE, TRUE, 0); - - /* buttons */ - vbox = (GtkVBox *)gtk_vbox_new(FALSE, 0); - - button = gtk_button_new_with_label ("Add"); - gtk_box_pack_start((GtkBox *)vbox, button, FALSE, TRUE, 0); - edata->add = button; - button = gtk_button_new_with_label ("Remove"); - gtk_box_pack_start((GtkBox *)vbox, button, FALSE, TRUE, 0); - edata->remove = button; - button = gtk_button_new_with_label ("Edit"); - gtk_box_pack_start((GtkBox *)vbox, button, FALSE, TRUE, 0); - edata->edit = button; - - gtk_box_pack_start((GtkBox *)hbox, (GtkWidget *)vbox, FALSE, FALSE, 0); - - gtk_signal_connect((GtkObject *)edata->add, "clicked", filter_arg_edit_add, edata); - gtk_signal_connect((GtkObject *)edata->edit, "clicked", filter_arg_edit_edit, edata); - gtk_signal_connect((GtkObject *)edata->remove, "clicked", filter_arg_edit_delete, edata); - gtk_signal_connect((GtkObject *)edata->list, "select_child", filter_arg_edit_select, edata); - gtk_signal_connect((GtkObject *)edata->list, "unselect_child", filter_arg_edit_unselect, edata); - - gtk_widget_show(GTK_WIDGET(list)); - gtk_widget_show_all(GTK_WIDGET(hbox)); - gtk_box_pack_start((GtkBox *)dialogue->vbox, (GtkWidget *)hbox, TRUE, TRUE, 0); - - gtk_signal_connect((GtkObject *)dialogue, "clicked", filter_arg_edit_clicked, edata); - gtk_signal_connect((GtkObject *)dialogue, "destroy", filter_arg_edit_destroy, edata); - - edit_sensitise(edata); - - gtk_widget_show(dialogue); -} - - diff --git a/filter/filter-arg.h b/filter/filter-arg.h deleted file mode 100644 index 7790123569..0000000000 --- a/filter/filter-arg.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * Abstract class to hold filter arguments. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef _FILTER_ARG_H -#define _FILTER_ARG_H - -#include -#include -#include /* gnome-xml */ - -#define FILTER_ARG(obj) GTK_CHECK_CAST (obj, filter_arg_get_type (), FilterArg) -#define FILTER_ARG_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_arg_get_type (), FilterArgClass) -#define IS_FILTER_ARG(obj) GTK_CHECK_TYPE (obj, filter_arg_get_type ()) - -typedef struct _FilterArg FilterArg; -typedef struct _FilterArgClass FilterArgClass; - -struct _FilterArg { - GtkObject object; - - struct _FilterArgPrivate *priv; - - char *name; - GList *values; -}; - -struct _FilterArgClass { - GtkObjectClass parent_class; - - /* make a copy of yourself */ - struct _FilterArg * (*clone)(FilterArg *arg); - - /* virtual methods */ - void (*write_html)(FilterArg *arg, GtkHTML *html, GtkHTMLStream *stream); - void (*write_text)(FilterArg *arg, GString *string); - void (*free_value)(FilterArg *arg, void *v); - - void (*edit_values)(FilterArg *arg); - int (*edit_value)(FilterArg *arg, int index); - - void (*values_add_xml)(FilterArg *arg, xmlNodePtr node); - xmlNodePtr (*values_get_xml)(FilterArg *arg); - - char * (*get_value_as_string)(FilterArg *arg, void *data); - - /* signals */ - void (*changed)(FilterArg *arg); -}; - -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); -void *filter_arg_get_value(FilterArg *arg, int index); -char *filter_arg_get_value_as_string(FilterArg *arg, int index); - -#endif /* ! _FILTER_ARG_H */ - diff --git a/filter/filter-driver.c b/filter/filter-driver.c deleted file mode 100644 index 17ced7412d..0000000000 --- a/filter/filter-driver.c +++ /dev/null @@ -1,619 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "filter-driver.h" - -#include -#include -#include -#include - -#include -#include - -#include "filter-arg-types.h" -#include "filter-xml.h" -#include "e-sexp.h" -#include "filter-format.h" - -#include - -struct _FilterDriverPrivate { - GList *rules, *options; - GHashTable *globals; /* global variables */ - - /* run-time data */ - GHashTable *folders; /* currently open folders */ - GList *matches; /* all messages which match current rule */ - GHashTable *terminated; /* messages for which processing is terminated */ - GHashTable *processed; /* all messages that were processed in some way */ - - CamelFolder *source; /* temporary input folder */ - - CamelException *ex; - - /* evaluator */ - ESExp *eval; -}; - -#define _PRIVATE(o) (((FilterDriver *)(o))->priv) - -static void filter_driver_class_init (FilterDriverClass *klass); -static void filter_driver_init (FilterDriver *obj); -static void filter_driver_finalise (GtkObject *obj); - -static CamelFolder *open_folder(FilterDriver *d, const char *folder_url); -static int close_folders(FilterDriver *d); - -static ESExpResult *do_delete(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *); -static ESExpResult *do_forward(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *); -static ESExpResult *do_copy(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *); -static ESExpResult *do_stop(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *); - -static struct { - char *name; - ESExpFunc *func; - int type; /* set to 1 if a function can perform shortcut evaluation, or - doesn't execute everything, 0 otherwise */ -} symbols[] = { - { "delete", (ESExpFunc *)do_delete, 0 }, - { "forward-to", (ESExpFunc *)do_forward, 0 }, - { "copy-to", (ESExpFunc *)do_copy, 0 }, - { "stop", (ESExpFunc *)do_stop, 0 }, -}; - -static GtkObjectClass *filter_driver_parent; - -enum SIGNALS { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -guint -filter_driver_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "FilterDriver", - sizeof (FilterDriver), - sizeof (FilterDriverClass), - (GtkClassInitFunc) filter_driver_class_init, - (GtkObjectInitFunc) filter_driver_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &type_info); - } - - return type; -} - -static void -filter_driver_class_init (FilterDriverClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - filter_driver_parent = gtk_type_class (gtk_object_get_type ()); - - object_class->finalize = filter_driver_finalise; - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -filter_driver_init (FilterDriver *obj) -{ - struct _FilterDriverPrivate *p; - int i; - - p = _PRIVATE(obj) = g_malloc0(sizeof(*p)); - - p->eval = e_sexp_new(); - /* Load in builtin symbols */ - for(i=0;ieval, 0, symbols[i].name, (ESExpIFunc *)symbols[i].func, obj); - } else { - e_sexp_add_function(p->eval, 0, symbols[i].name, symbols[i].func, obj); - } - } - - p->globals = g_hash_table_new(g_str_hash, g_str_equal); - - p->ex = camel_exception_new (); -} - -static void -free_hash_strings(void *key, void *value, void *data) -{ - g_free(key); - g_free(value); -} - -static void -filter_driver_finalise (GtkObject *obj) -{ - FilterDriver *d = (FilterDriver *)obj; - struct _FilterDriverPrivate *p = _PRIVATE(d); - - g_hash_table_foreach(p->globals, free_hash_strings, d); - g_hash_table_destroy(p->globals); - - gtk_object_unref((GtkObject *)p->eval); - - ((GtkObjectClass *)(filter_driver_parent))->finalize((GtkObject *)obj); -} - -/** - * filter_driver_new: - * - * Create a new FilterDriver object. - * - * Return value: A new FilterDriver widget. - **/ -FilterDriver * -filter_driver_new (void) -{ - FilterDriver *new = FILTER_DRIVER ( gtk_type_new (filter_driver_get_type ())); - return new; -} - - -void filter_driver_set_session(FilterDriver *d, CamelSession *s) -{ - if (d->session) - gtk_object_unref((GtkObject *)s); - d->session = s; - if (s) - gtk_object_ref((GtkObject *)s); -} - -int filter_driver_set_rules(FilterDriver *d, const char *description, const char *filter) -{ - struct _FilterDriverPrivate *p = _PRIVATE(d); - xmlDocPtr desc, filt; - - printf("Loading system '%s'\nLoading user '%s'\n", description, filter); - -#warning "fix leaks, free xml docs here" - desc = xmlParseFile(description); - p->rules = filter_load_ruleset(desc); - - filt = xmlParseFile(filter); - p->options = filter_load_optionset(filt, p->rules); - - return 0; -} - -void filter_driver_set_global(FilterDriver *d, const char *name, const char *value) -{ - struct _FilterDriverPrivate *p = _PRIVATE(d); - char *oldkey, *oldvalue; - - if (g_hash_table_lookup_extended(p->globals, name, (void *)&oldkey, (void *)&oldvalue)) { - g_free(oldvalue); - g_hash_table_insert(p->globals, oldkey, g_strdup(value)); - } else { - g_hash_table_insert(p->globals, g_strdup(name), g_strdup(value)); - } -} - -extern int filter_find_arg(FilterArg *a, char *name); - -/* - - foreach rule - find matches - - foreach action - get all matches - - */ - -/* - splices ${cc} lines into a single string -*/ -static int -expand_variables(GString *out, char *source, GList *args, GHashTable *globals) -{ - GList *argl; - FilterArg *arg; - char *name= alloca(32); - char *start, *end, *newstart, *tmp, *val; - int namelen=32; - int len=0; - int ok = 0; - - printf("expanding %s\n", source); - - start = source; - while ( (newstart = strstr(start, "${")) - && (end = strstr(newstart+2, "}")) ) { - len = end-newstart-2; - if (len+1>namelen) { - namelen = (len+1)*2; - name = alloca(namelen); - } - memcpy(name, newstart+2, len); - name[len] = 0; - printf("looking for name '%s'\n", name); - argl = g_list_find_custom(args, name, (GCompareFunc) filter_find_arg); - if (argl) { - int i, count; - - tmp = g_strdup_printf("%.*s", newstart-start, start); - printf("appending: %s\n", tmp); - g_string_append(out, tmp); - g_free(tmp); - - arg = argl->data; - count = filter_arg_get_count(arg); - for (i=0;ioptions; - while (optionl) { - struct filter_optionrule *or = optionl->data; - if (or->rule->type == FILTER_XML_MATCH - || or->rule->type == FILTER_XML_EXCEPT) { - if (or->args) { - arg = or->args->data; - if (arg) { - printf("arg = %s\n", arg->name); - } - } - expand_variables(s, or->rule->code, or->args, p->globals); - } - optionl = g_list_next(optionl); - } - - g_string_append(s, ")"); - - g_string_append(action, "(begin "); - optionl = op->options; - while (optionl) { - struct filter_optionrule *or = optionl->data; - if (or->rule->type == FILTER_XML_ACTION) { - expand_variables(action, or->rule->code, or->args, p->globals); - g_string_append(action, " "); - } - optionl = g_list_next(optionl); - } - g_string_append(action, ")"); - - printf("combined rule '%s'\n", s->str); - printf("combined action '%s'\n", action->str); -} - -static ESExpResult * -do_delete(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d) -{ - struct _FilterDriverPrivate *p = _PRIVATE(d); - GList *m; - - printf("doing delete\n"); - m = p->matches; - while (m) { - CamelMimeMessage *mm; - - printf(" %s\n", (char *)m->data); - - mm = camel_folder_get_message_by_uid(p->source, m->data, p->ex); - if (mm) { - camel_mime_message_set_flags(mm, CAMEL_MESSAGE_DELETED, CAMEL_MESSAGE_DELETED); - gtk_object_unref((GtkObject *)mm); - } - - m = m->next; - } - return NULL; -} - -static ESExpResult * -do_forward(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d) -{ - struct _FilterDriverPrivate *p = _PRIVATE(d); - GList *m; - - printf("doing forward on the following messages:\n"); - m = p->matches; - while (m) { - printf(" %s\n", (char *)m->data); - m = m->next; - } - return NULL; -} - -static ESExpResult * -do_copy(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d) -{ - GList *m; - int i; - struct _FilterDriverPrivate *p = _PRIVATE(d); - - printf("doing copy\n"); - for (i=0;itype == ESEXP_RES_STRING) { - char *folder = argv[i]->value.string; - CamelFolder *outbox; - - /* FIXME: this might have to find another store, based on - the folder as a url??? */ - printf("opening outpbox %s\n", folder); - outbox = open_folder(d, folder); - if (outbox == NULL) { - g_warning("Cannot open folder: %s", folder); - continue; - } - - m = p->matches; - while (m) { - CamelMimeMessage *mm; - - printf("appending message %s\n", (char *)m->data); - - mm = camel_folder_get_message_by_uid(p->source, m->data, p->ex); - camel_folder_append_message(outbox, mm, p->ex); - gtk_object_unref((GtkObject *)mm); - - printf(" %s\n", (char *)m->data); - m = m->next; - } - } - } - - return NULL; -} - -static ESExpResult * -do_stop(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d) -{ - GList *m; - struct _FilterDriverPrivate *p = _PRIVATE(d); - - printf("doing stop on the following messages:\n"); - m = p->matches; - while (m) { - printf(" %s\n", (char *)m->data); - g_hash_table_insert(p->terminated, g_strdup(m->data), (void *)1); - m = m->next; - } - return NULL; -} - -static CamelFolder * -open_folder(FilterDriver *d, const char *folder_url) -{ - char *folder, *store; - CamelStore *camelstore; - CamelFolder *camelfolder; - struct _FilterDriverPrivate *p = _PRIVATE(d); - - /* we have a lookup table of currently open folders */ - camelfolder = g_hash_table_lookup(p->folders, folder_url); - if (camelfolder) - return camelfolder; - - store = g_strdup(folder_url); - folder = strrchr(store, '/'); - if (folder == NULL || folder == store || folder[1]==0) - goto fail; - - *folder++ = 0; - camelstore = camel_session_get_store (d->session, store, p->ex); - if (camel_exception_get_id (p->ex)) { - printf ("Could not open store: %s: %s", store, camel_exception_get_description (p->ex)); - goto fail; - } - - camelfolder = camel_store_get_folder (camelstore, folder, p->ex); - if (camel_exception_get_id (p->ex)) { - printf ("Could not open folder: %s: %s", folder, camel_exception_get_description (p->ex)); - goto fail; - } - - if (!camel_folder_exists(camelfolder, p->ex)) { - camel_folder_create(camelfolder, p->ex); - } - - camel_folder_open(camelfolder, FOLDER_OPEN_RW, p->ex); - - if (camel_exception_get_id (p->ex)) { - printf ("Could not open folder: %s: %s", folder, camel_exception_get_description (p->ex)); - goto fail; - } - - printf("opening folder: %s\n", folder_url); - - g_free(store); - - g_hash_table_insert(p->folders, g_strdup(folder_url), camelfolder); - - return camelfolder; - -fail: - g_free(store); - return NULL; -} - -static void -close_folder(void *key, void *value, void *data) -{ - CamelFolder *f = value; - FilterDriver *d = data; - struct _FilterDriverPrivate *p = _PRIVATE(d); - - printf("closing folder: %s\n", key); - - g_free(key); - camel_folder_close(f, TRUE, p->ex); - gtk_object_unref((GtkObject *)f); -} - -/* flush/close all folders */ -static int -close_folders(FilterDriver *d) -{ - struct _FilterDriverPrivate *p = _PRIVATE(d); - - g_hash_table_foreach(p->folders, close_folder, d); - g_hash_table_destroy(p->folders); - p->folders = g_hash_table_new(g_str_hash, g_str_equal); - - /* FIXME: status from d */ - return 0; -} - -int -filter_driver_run(FilterDriver *d, CamelFolder *source, CamelFolder *inbox) -{ - struct _FilterDriverPrivate *p = _PRIVATE(d); - ESExpResult *r; - GList *options; - GString *s, *a; - GPtrArray *all; - GList *m; - int i; - -#warning "This must be made mega-robust" - p->source = source; - - /* setup runtime data */ - p->folders = g_hash_table_new(g_str_hash, g_str_equal); - p->terminated = g_hash_table_new(g_str_hash, g_str_equal); - p->processed = g_hash_table_new(g_str_hash, g_str_equal); - - camel_exception_init(p->ex); - - options = p->options; - while (options) { - struct filter_option *fo = options->data; - - s = g_string_new(""); - a = g_string_new(""); - expand_filter_option(d, s, a, fo); - - printf("searching expression %s\n", s->str); - p->matches = camel_folder_search_by_expression (p->source, s->str, p->ex); - - /* remove uid's for which processing is complete ... */ - m = p->matches; - while (m) { - GList *n = m->next; - - printf("matched: %s\n", m->data); - - /* for all matching id's, so we can work out what to default */ - if (g_hash_table_lookup(p->processed, m->data) == NULL) { - g_hash_table_insert(p->processed, g_strdup(m->data), (void *)1); - } - - if (g_hash_table_lookup(p->terminated, m->data)) { - printf("removing terminated message %s\n", (char *)m->data); - p->matches = g_list_remove_link(p->matches, m); - } - m = n; - } - - printf("applying actions ... '%s'\n", a->str); - e_sexp_input_text(p->eval, a->str, strlen(a->str)); - e_sexp_parse(p->eval); - r = e_sexp_eval(p->eval); - e_sexp_result_free(r); - - g_string_free(s, TRUE); - g_string_free(a, TRUE); - - g_list_free(p->matches); - - options = g_list_next(options); - } - - /* apply the default of copying to an inbox, if we are given one, and make sure - we delete everything as well */ - all = camel_folder_get_uids(p->source, p->ex); - for (i = 0; i < all->len; i++) { - char *uid = all->pdata[i], *procuid; - CamelMimeMessage *mm; - - procuid = g_hash_table_lookup(p->processed, uid); - if (procuid == NULL) { - if (inbox) { - printf("Applying default rule to message %s\n", uid); - - mm = camel_folder_get_message_by_uid(p->source, all->pdata[i], p->ex); - camel_folder_append_message(inbox, mm, p->ex); - camel_mime_message_set_flags(mm, CAMEL_MESSAGE_DELETED, CAMEL_MESSAGE_DELETED); - gtk_object_unref((GtkObject *)mm); - } - } else { - camel_folder_delete_message_by_uid(p->source, uid, p->ex); - } - } - camel_folder_free_uids(p->source, all); - - g_hash_table_destroy(p->processed); - g_hash_table_destroy(p->terminated); - close_folders(d); - g_hash_table_destroy(p->folders); - - return 0; -} diff --git a/filter/filter-driver.h b/filter/filter-driver.h deleted file mode 100644 index dc670bc85e..0000000000 --- a/filter/filter-driver.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifndef _FILTER_DRIVER_H -#define _FILTER_DRIVER_H - -#include -#include -#include - -#define FILTER_DRIVER(obj) GTK_CHECK_CAST (obj, filter_driver_get_type (), FilterDriver) -#define FILTER_DRIVER_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_driver_get_type (), FilterDriverClass) -#define IS_FILTER_DRIVER(obj) GTK_CHECK_TYPE (obj, filter_driver_get_type ()) - -typedef struct _FilterDriver FilterDriver; -typedef struct _FilterDriverClass FilterDriverClass; - -struct _FilterDriver { - GtkObject parent; - - struct _FilterDriverPrivate *priv; - - CamelSession *session; -}; - -struct _FilterDriverClass { - GtkObjectClass parent_class; -}; - -guint filter_driver_get_type (void); -FilterDriver *filter_driver_new (void); - -void filter_driver_set_session(FilterDriver *, CamelSession *); -int filter_driver_set_rules(FilterDriver *, const char *system, const char *filter); -void filter_driver_set_global(FilterDriver *, const char *name, const char *value); - -/* apply rules to a folder, unmatched messages goto inbox, if not NULL */ -int filter_driver_run(FilterDriver *d, CamelFolder *source, CamelFolder *inbox); - -#endif /* ! _FILTER_DRIVER_H */ diff --git a/filter/filter-druid.c b/filter/filter-druid.c deleted file mode 100644 index 4a4595c5fb..0000000000 --- a/filter/filter-druid.c +++ /dev/null @@ -1,736 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include "filter-arg-types.h" -#include "filter-xml.h" -#include "filter-format.h" - - -#include "filter-druid.h" - -static void filter_druid_class_init (FilterDruidClass *klass); -static void filter_druid_init (FilterDruid *obj); - -#define _PRIVATE(x) (((FilterDruid *)(x))->priv) - -struct _FilterDruidPrivate { - GtkWidget *notebook; - int page; - - char *default_html; - - /* page 0 */ - GtkWidget *list0; - GtkWidget *html0; - GtkWidget *add0, *remove0, *up0, *down0; - GList *items0; - GtkFrame *listframe0; - - /* page 1 */ - GtkWidget *name1; - GtkWidget *activate1; - GtkHTML *html1; -}; - -/* forward ref's */ -static void build_druid(FilterDruid *d); -static void update_display(FilterDruid *f, int initial); - -/* globals */ -static GtkNotebookClass *filter_druid_parent; - -enum SIGNALS { - OPTION_SELECTED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -guint -filter_druid_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "FilterDruid", - sizeof (FilterDruid), - sizeof (FilterDruidClass), - (GtkClassInitFunc) filter_druid_class_init, - (GtkObjectInitFunc) filter_druid_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (gtk_notebook_get_type (), &type_info); - } - - return type; -} - -static void -object_destroy(FilterDruid *obj) -{ - struct _FilterDruidPrivate *p = _PRIVATE(obj); - - g_free(p->default_html); - - gtk_signal_disconnect_by_data((GtkObject *)p->list0, obj); - - /* FIXME: free lists? */ - - GTK_OBJECT_CLASS(filter_druid_parent)->destroy(obj); -} - -static void -filter_druid_class_init (FilterDruidClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - filter_druid_parent = gtk_type_class (gtk_notebook_get_type ()); - - object_class->destroy = object_destroy; - - signals[OPTION_SELECTED] = - gtk_signal_new ("option_selected", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (FilterDruidClass, option_selected), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -filter_druid_init (FilterDruid *obj) -{ - struct _FilterDruidPrivate *priv; - - obj->priv = g_malloc0(sizeof(*obj->priv)); - priv = _PRIVATE(obj); -} - -/** - * filter_druid_new: - * - * Create a new FilterDruid object. - * - * Return value: A new FilterDruid widget. - **/ -FilterDruid * -filter_druid_new (void) -{ - FilterDruid *new = FILTER_DRUID ( gtk_type_new (filter_druid_get_type ())); - - build_druid(new); - - return new; -} - - -extern int filter_find_arg(FilterArg *a, char *name); - -#include "check.xpm" -#include "blank.xpm" - - -struct filter_optionrule * -find_optionrule(struct filter_option *option, char *name) -{ - GList *optionrulel; - struct filter_optionrule *or; - - optionrulel = option->options; - while (optionrulel) { - or = optionrulel->data; - if (!strcmp(or->rule->name, name)) { - return or; - } - optionrulel = g_list_next(optionrulel); - } - return NULL; -} - -static int display_order[] = { - FILTER_XML_MATCH, - FILTER_XML_EXCEPT, - FILTER_XML_ACTION, -}; -static char *display_pretext[] = { - "For messages matching:
    ", - "Unless:
      ", - "Perform these actions:
        ", -}; -static char *display_posttext[] = { - "
      ", - "
    ", - "
", -}; - -void -html_write_options(GtkHTML *html, struct filter_option *option, char *def) -{ - GtkHTMLStream *stream; - GList *optionrulel; - int i; - - stream = gtk_html_begin(html); - - gtk_html_write(html, stream, "", strlen("")); - if (option) { - char *t; - - if (option->type == FILTER_XML_SEND) { - t = "

When a message is sent.

"; - } else { - t = "

When a message is received.

"; - } - gtk_html_write(html, stream, t, strlen(t)); - - for (i=0;ioptions; - while (optionrulel) { - struct filter_optionrule *or = optionrulel->data; - - if (or->rule->type == display_order[i]) { - if (!doneheader) { - gtk_html_write(html, stream, display_pretext[i], strlen(display_pretext[i])); - doneheader = TRUE; - } - - if (donefirst) { - gtk_html_write(html, stream, "   and ", strlen("   and ")); - } - filter_description_html_write(or->rule->description, or->args, html, stream); - donefirst = TRUE; - gtk_html_write(html, stream, "
", strlen("
")); - } - optionrulel = g_list_next(optionrulel); - } - if (doneheader) { - gtk_html_write(html, stream, display_posttext[i], strlen(display_posttext[i])); - } - } - } else { - if (def == NULL) - def = "Select options."; - gtk_html_write(html, stream, def, strlen(def)); - } - gtk_html_end(html, stream, GTK_HTML_STREAM_OK); -} - -GList * -fill_rules(GList *rules, struct filter_option *option, int type) -{ - GList *optionl, *rulel; - GtkWidget *listitem, *hbox, *checkbox, *label; - GList *items = NULL; - - rulel = rules; - while (rulel) { - struct filter_rule *fr = rulel->data; - char *labeltext; - - if (fr->type == type) { - int state; - - state = find_optionrule(option, fr->name) != NULL; - - labeltext = filter_description_text(fr->description, NULL); - - printf("adding rule %s\n", labeltext); - - hbox = gtk_hbox_new(FALSE, 3); - checkbox = gnome_pixmap_new_from_xpm_d(state?check_xpm:blank_xpm); - gtk_box_pack_start(GTK_BOX(hbox), checkbox, FALSE, FALSE, 0); - label = gtk_label_new(labeltext); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0); - listitem = gtk_list_item_new(); - gtk_container_add(GTK_CONTAINER(listitem), hbox); - gtk_widget_show_all(listitem); - - gtk_object_set_data(GTK_OBJECT(listitem), "checkbox", checkbox); - gtk_object_set_data(GTK_OBJECT(listitem), "checkstate", (void *)state); - gtk_object_set_data(GTK_OBJECT(listitem), "rule", fr); - - items = g_list_append(items, listitem); - } - rulel = g_list_next(rulel); - } - return items; -} - -GList * -fill_options(GList *options) -{ - GList *optionl, *rulel, *optionrulel; - GtkWidget *listitem, *hbox, *checkbox, *label; - GList *items = NULL; - - optionl = options; - while (optionl) { - struct filter_option *op = optionl->data; - char *labeltext; - - labeltext = filter_description_text(op->description, NULL); - listitem = gtk_list_item_new_with_label(labeltext); - g_free(labeltext); - gtk_widget_show_all(listitem); - - gtk_object_set_data(GTK_OBJECT(listitem), "option", op); - - items = g_list_append(items, listitem); - optionl = g_list_next(optionl); - } - return items; -} - -static void -select_rule_child(GtkList *list, GtkWidget *child, FilterDruid *f) -{ - GtkWidget *w; - struct filter_rule *fr = gtk_object_get_data(GTK_OBJECT(child), "rule"); - int state; - struct filter_optionrule *rule; - struct _FilterDruidPrivate *p = _PRIVATE(f); - - w = gtk_object_get_data(GTK_OBJECT(child), "checkbox"); - state = !(int) gtk_object_get_data(GTK_OBJECT(child), "checkstate"); - - gnome_pixmap_load_xpm_d(GNOME_PIXMAP(w), state?check_xpm:blank_xpm); - gtk_object_set_data(GTK_OBJECT(child), "checkstate", (void *)state); - - if (state) { - printf("adding rule %p\n", fr); - rule = filter_optionrule_new_from_rule(fr); - f->option_current->options = g_list_append(f->option_current->options, rule); - } else { - rule = find_optionrule(f->option_current, fr->name); - if (rule) { - f->option_current->options = g_list_remove(f->option_current->options, rule); - filter_clone_optionrule_free(rule); - } - } - - update_display(f, 0); -} - - - -static void -select_option_child(GtkList *list, GtkWidget *child, FilterDruid *f) -{ - struct filter_option *op; - struct filter_option *new; - GList *optionsl; - struct _FilterDruidPrivate *p = _PRIVATE(f); - - switch (p->page) { - case 1: - case 2: - case 3: - select_rule_child(list, child, f); - default: - return; - case 0: - break; - } - - if (f->option_current) { - printf("freeing current option\n"); - /* free option_current copy */ - optionsl = f->option_current->options; - while (optionsl) { - GList *op = optionsl; - optionsl = g_list_next(optionsl); - filter_clone_optionrule_free(op->data); - } - g_list_free(f->option_current->options); - g_free(f->option_current); - f->option_current = NULL; - } - - if (child) { - op = gtk_object_get_data(GTK_OBJECT(child), "option"); - - printf("option = %p\n", op); - - /* clone the option */ - new = g_malloc(sizeof(*new)); - new->type = op->type; - new->description = op->description; - new->options = NULL; - optionsl = op->options; - while (optionsl) { - struct filter_optionrule *ornew, - *or = optionsl->data; - ornew = filter_clone_optionrule(or); - new->options = g_list_append(new->options, ornew); - optionsl = g_list_next(optionsl); - } - f->option_current = new; - - gtk_signal_emit(GTK_OBJECT(f), signals[OPTION_SELECTED], op); - } - - update_display(f, 0); -} - -static void -unselect_option_child(GtkList *list, GtkWidget *child, FilterDruid *f) -{ - printf("unselect option child\n"); - select_option_child(list, NULL, f); -} - -static void -arg_changed(FilterArg *arg, FilterDruid *f) -{ - FilterArg *orig; - - printf("value changed!!!\n"); - - orig = gtk_object_get_data(arg, "origin"); - if (orig) { - filter_arg_copy(orig, arg); - update_display(f, 0); - } else { - /* FIXME: uh, what the fuck to do here? */ - update_display(f, 0); - } -} - -static void -arg_link_clicked(GtkHTML *html, const char *url, FilterDruid *f) -{ - printf("url clicked: %s\n", url); - if (!strncmp(url, "arg:", 4)) { - FilterArg *arg; - void *dummy; - - if (sscanf(url+4, "%p %p", &dummy, &arg)==2 - && arg) { - FilterArg *orig; - - printf("arg = %p\n", arg); - - gtk_signal_connect((GtkObject *)arg, "changed", arg_changed, f); - filter_arg_edit_values(arg); - } - } -} - -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(""); - struct _FilterDruidPrivate *p = _PRIVATE(d); - int initial=0; - - printf("button %d clicked ...\n", button); - - g_string_free(s, TRUE); - - switch(button) { - case 1: - if (p->page<4) { - p->page++; - initial =1; - } - break; - case 0: - if (p->page>0) { - p->page--; - initial = 1; - } - break; - } - update_display(d, initial); -} - -static int filter_types[] = { FILTER_XML_MATCH, FILTER_XML_EXCEPT, FILTER_XML_ACTION }; -static char *filter_titles[] = { - "Select rule(s), where messages match", - "Select rule(s), where messages do not match", - "Select action(s) to apply to messages" - -}; -static void -update_display(FilterDruid *f, int initial) -{ - struct _FilterDruidPrivate *p = _PRIVATE(f); - - printf("rending page %d options\n", p->page); - - switch (p->page) { - case 0: - printf("option_current = %p <###################\n", f->option_current); - - if (initial) { - printf("adding options\n"); - gtk_signal_handler_block_by_data((GtkObject *)p->list0, f); - gtk_list_remove_items((GtkList *)p->list0, p->items0); - p->items0 = fill_options(f->options); - gtk_list_append_items((GtkList *)p->list0, p->items0); - gtk_signal_handler_unblock_by_data((GtkObject *)p->list0, f); - gtk_frame_set_label(p->listframe0, "Select rule type"); - } - - html_write_options((GtkHTML *)p->html0, f->option_current, p->default_html); - break; - case 1: - case 2: - case 3: - if (initial) { - printf("adding rules\n"); - gtk_signal_handler_block_by_data((GtkObject *)p->list0, f); - gtk_list_remove_items((GtkList *)p->list0, p->items0); - p->items0 = fill_rules(f->rules, f->option_current, filter_types[p->page-1]); - gtk_list_append_items((GtkList *)p->list0, p->items0); - gtk_signal_handler_unblock_by_data((GtkObject *)p->list0, f); - gtk_frame_set_label(p->listframe0, filter_titles[p->page-1]); - gtk_notebook_set_page(GTK_NOTEBOOK(p->notebook), 0); - } - - html_write_options((GtkHTML *)p->html0, f->option_current, p->default_html); - break; - case 4: - if (initial) { - char *text; - text = filter_description_text(f->option_current->description, NULL); - if (text == NULL) { - /* maybe this could fudge something out of the first - bits of the rule */ - if (f->option_current->type == FILTER_XML_SEND) { - text = "Filter messages sent"; - } else { - text = "Filter messages received"; - } - gtk_entry_set_text(GTK_ENTRY(p->name1), text); - } else { - gtk_entry_set_text(GTK_ENTRY(p->name1), text); - g_free(text); - } - gtk_notebook_set_page(GTK_NOTEBOOK(p->notebook), 1); - } - - html_write_options((GtkHTML *)p->html1, f->option_current, p->default_html); - break; - - } -} - -void -filter_druid_set_rules(FilterDruid *f, GList *options, GList *rules, struct filter_option *current) -{ - struct filter_option *new; - GList *optionsl; - - f->options = options; - f->rules = rules; - f->user = NULL; - - if (current) { - /* FIXME: free this list if it isn't empty ... */ - /* clone the 'current' option */ - new = g_malloc(sizeof(*new)); - new->type = current->type; - new->description = current->description; - new->options = NULL; - optionsl = current->options; - while (optionsl) { - struct filter_optionrule *ornew, - *or = optionsl->data; - ornew = filter_clone_optionrule(or); - new->options = g_list_append(new->options, ornew); - optionsl = g_list_next(optionsl); - } - f->option_current = new; - } else { - f->option_current = NULL; - } - - update_display(f, 1); -} - -static void -build_druid(FilterDruid *d) -{ - GtkWidget *vbox, *frame, *scrolled_window, *list, *html, *hbox, *label, *vbox1; - struct _FilterDruidPrivate *p = _PRIVATE(d); - -#if 0 - gnome_dialog_append_buttons((GnomeDialog *)d, "Prev", "Next", "Finish", "Cancel", 0); - gnome_dialog_set_close((GnomeDialog *)d, FALSE); - gnome_dialog_set_sensitive((GnomeDialog *)d, 0, FALSE); - gnome_dialog_set_sensitive((GnomeDialog *)d, 1, FALSE); - gnome_dialog_set_sensitive((GnomeDialog *)d, 2, FALSE); - gnome_dialog_set_default((GnomeDialog *)d, 1); -#endif - - p->notebook = d; - gtk_notebook_set_show_tabs(GTK_NOTEBOOK(p->notebook), FALSE); - - /* page0, initial setup page */ - vbox = gtk_vbox_new(FALSE, 3); - frame = gtk_frame_new("Filters"); - p->listframe0 = (GtkFrame *)frame; - - list = gtk_list_new(); - scrolled_window = gtk_scrolled_window_new(NULL, NULL); - gtk_widget_set_usize(scrolled_window, 400, 150); - gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), list); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_container_set_focus_vadjustment - (GTK_CONTAINER (list), - gtk_scrolled_window_get_vadjustment - (GTK_SCROLLED_WINDOW (scrolled_window))); - gtk_container_add(GTK_CONTAINER(frame), scrolled_window); - gtk_box_pack_start((GtkBox *)vbox, frame, TRUE, TRUE, 0); - - frame = gtk_frame_new("Filter Description (click on values to edit)"); - html = gtk_html_new(); - scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_set_usize(scrolled_window, 400, 150); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(scrolled_window), html); - gtk_container_add(GTK_CONTAINER(frame), scrolled_window); - gtk_box_pack_start((GtkBox *)vbox, frame, TRUE, TRUE, 0); - - p->html0 = html; - p->list0 = list; - - gtk_signal_connect(GTK_OBJECT(list), "select_child", select_option_child, d); - gtk_signal_connect(GTK_OBJECT(list), "unselect_child", select_option_child, d); -/* gtk_signal_connect(GTK_OBJECT(list), "unselect_child", unselect_option_child, d); */ -/* gtk_signal_connect(GTK_OBJECT(d), "clicked", dialogue_clicked, d);*/ - - gtk_signal_connect(GTK_OBJECT(html), "link_clicked", arg_link_clicked, d); - - gtk_notebook_append_page(GTK_NOTEBOOK(p->notebook), vbox, NULL); - - - /* page1, used for the final page display */ - vbox = gtk_vbox_new(FALSE, 3); - - frame = gtk_frame_new("Rule options"); - vbox1 = gtk_vbox_new(FALSE, 3); - - hbox = gtk_hbox_new(FALSE, 3); - label = gtk_label_new("Name of rule"); - p->name1 = gtk_entry_new(); - gtk_box_pack_start((GtkBox *)hbox, label, FALSE, FALSE, 0); - gtk_box_pack_start((GtkBox *)hbox, p->name1, TRUE, TRUE, 0); - gtk_box_pack_start((GtkBox *)vbox1, hbox, TRUE, FALSE, 0); - - gtk_container_add(GTK_CONTAINER(frame), vbox1); - - p->activate1 = gtk_check_button_new_with_label("Activate rule?"); - 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 */ - frame = gtk_frame_new("Filter Description (click on values to edit)"); - html = gtk_html_new(); - p->html1 = (GtkHTML *)html; - scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_set_usize(scrolled_window, 400, 150); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_container_add(GTK_CONTAINER(scrolled_window), html); - gtk_container_add(GTK_CONTAINER(frame), scrolled_window); - gtk_box_pack_start((GtkBox *)vbox, frame, TRUE, TRUE, 0); - - /* finish off */ - gtk_notebook_append_page(GTK_NOTEBOOK(p->notebook), vbox, NULL); - - gtk_signal_connect(GTK_OBJECT(html), "link_clicked", arg_link_clicked, d); - - gtk_widget_show_all(p->notebook); -} - -void -filter_druid_set_page(FilterDruid *f, enum FilterDruidPage page) -{ - struct _FilterDruidPrivate *p = _PRIVATE(f); - int initial = p->page != page; - - p->page = page; - update_display(f, initial); -} - - -void -filter_druid_set_default_html(FilterDruid *f, const char *html) -{ - struct _FilterDruidPrivate *p = _PRIVATE(f); - - g_free(p->default_html); - p->default_html = g_strdup(html); -} - -enum FilterDruidPage -filter_druid_get_page(FilterDruid *f) -{ - struct _FilterDruidPrivate *p = _PRIVATE(f); - - return p->page; -} - diff --git a/filter/filter-druid.h b/filter/filter-druid.h deleted file mode 100644 index 7927dc70dd..0000000000 --- a/filter/filter-druid.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef _FILTER_DRUID_H -#define _FILTER_DRUID_H - -#include - -#include "filter-xml.h" - -#define FILTER_DRUID(obj) GTK_CHECK_CAST (obj, filter_druid_get_type (), FilterDruid) -#define FILTER_DRUID_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_druid_get_type (), FilterDruidClass) -#define IS_FILTER_DRUID(obj) GTK_CHECK_TYPE (obj, filter_druid_get_type ()) - -typedef struct _FilterDruid FilterDruid; -typedef struct _FilterDruidClass FilterDruidClass; - -enum FilterDruidPage { - FILTER_DRUID_SELECT_RULE, - FILTER_DRUID_SELECT_MATCH, - FILTER_DRUID_SELECT_NOMATCH, - FILTER_DRUID_SELECT_ACTION, - FILTER_DRUID_SELECT_FINISH -}; - -struct _FilterDruid { - GtkNotebook parent; - - GList *options; /* all options */ - GList *rules; /* all rules */ - GList *user; /* current user options */ - - struct filter_option *option_current; - - struct _FilterDruidPrivate *priv; -}; - -struct _FilterDruidClass { - GtkNotebookClass parent_class; - - /* signals */ - void (*option_selected)(FilterDruid *f, struct filter_option *option); -}; - -guint filter_druid_get_type (void); -FilterDruid *filter_druid_new (void); - -/* Hmm, glists suck, no typesafety */ -void filter_druid_set_rules(FilterDruid *f, GList *options, GList *rules, struct filter_option *userrule); -void filter_druid_set_default_html(FilterDruid *f, const char *text); - -/* set the page of display */ -void filter_druid_set_page(FilterDruid *f, enum FilterDruidPage page); -enum FilterDruidPage filter_druid_get_page(FilterDruid *f); - -/* check if the druid is allowed to finish at this point */ -gboolean filter_druid_can_finish(FilterDruid *f); - -#endif /* ! _FILTER_DRUID_H */ diff --git a/filter/filter-editor.c b/filter/filter-editor.c deleted file mode 100644 index ec6320b649..0000000000 --- a/filter/filter-editor.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "filter-druid.h" -#include "filter-editor.h" - - -static void filter_editor_class_init (FilterEditorClass *klass); -static void filter_editor_init (FilterEditor *obj); - -static GnomeDialogClass *filter_editor_parent; - -#define _PRIVATE(x) (((FilterEditor *)(x))->priv) - -struct _FilterEditorPrivate { - FilterDruid *druid; - - GtkWidget *edit, *add, *remove, *up, *down; - - /* for sub-druid */ - struct filter_option *druid_option; - GtkWidget *druid_dialogue; - FilterDruid *druid_druid; -}; - -enum SIGNALS { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -guint -filter_editor_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "FilterEditor", - sizeof (FilterEditor), - sizeof (FilterEditorClass), - (GtkClassInitFunc) filter_editor_class_init, - (GtkObjectInitFunc) filter_editor_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (gnome_dialog_get_type (), &type_info); - } - - return type; -} - -static void -object_destroy(FilterEditor *obj) -{ - struct _FilterEditorPrivate *p = _PRIVATE(obj); - - if (p->druid_druid) - gtk_object_unref((GtkObject *)p->druid_dialogue); - - GTK_OBJECT_CLASS(filter_editor_parent)->destroy(obj); -} - -static void -filter_editor_class_init (FilterEditorClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - filter_editor_parent = gtk_type_class (gnome_dialog_get_type ()); - - object_class->destroy = object_destroy; - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -filter_editor_init (FilterEditor *obj) -{ - obj->priv = g_malloc0(sizeof(*obj->priv)); -} - - -static void -sensitise(FilterEditor *e) -{ - struct _FilterEditorPrivate *p = _PRIVATE(e); - - gtk_widget_set_sensitive(p->add, TRUE); - gtk_widget_set_sensitive(p->edit, e->option_current != NULL); - gtk_widget_set_sensitive(p->remove, e->option_current != NULL); - gtk_widget_set_sensitive(p->up, g_list_index(e->useroptions, e->option_current)>0); - gtk_widget_set_sensitive(p->down, g_list_index(e->useroptions, e->option_current)!=g_list_length(e->useroptions)-1); -} - -static void -druid_option_selected(FilterDruid *f, struct filter_option *option, FilterEditor *e) -{ - printf("option selected: %p\n", option); - e->option_current = option; - sensitise(e); -} - -static void -druid_dialogue_clicked(GnomeDialog *d, int button, FilterEditor *e) -{ - struct _FilterEditorPrivate *p = _PRIVATE(e); - int page = filter_druid_get_page(p->druid_druid); - - switch(button) { - case 1: - if (page<4) { - page++; - } - break; - case 0: - if (page>0) { - page--; - } - break; - case 2: - printf("Finish!\n"); - if (p->druid_druid->option_current) { - struct filrt_optionrule *or; - - printf("refcount = %d\n", ((GtkObject *)p->druid_druid)->ref_count); - - or = p->druid_druid->option_current; - if (p->druid_option) { - GList *node; - - node = g_list_find(e->useroptions, p->druid_option); - if (node) { - /* fixme: free old one */ - node->data = or; - } else { - g_warning("Cannot find node I edited, appending instead"); - e->useroptions = g_list_append(e->useroptions, or); - } - } else { - e->useroptions = g_list_append(e->useroptions, or); - } - filter_druid_set_rules(p->druid, e->useroptions, e->rules, or); - } - case 3: - printf("cancel!\n"); - p->druid_dialogue = NULL; - gnome_dialog_close(d); - return; - } - filter_druid_set_page(p->druid_druid, page); - - gnome_dialog_set_sensitive(p->druid_dialogue, 0, page>0); - gnome_dialog_set_sensitive(p->druid_dialogue, 1, page<4); - gnome_dialog_set_sensitive(p->druid_dialogue, 2, page==4); /* FIXME: make this depenedant on when the rules are actually done */ -} - -static void -druid_dialogue_option_selected(FilterDruid *f, struct filter_option *option, FilterEditor *e) -{ - struct _FilterEditorPrivate *p = _PRIVATE(e); - - gnome_dialog_set_sensitive(p->druid_dialogue, 1, TRUE); -} - -static void -add_or_edit(FilterEditor *e, struct filter_option *option) -{ - GnomeDialog *dialogue; - FilterDruid *druid; - struct _FilterEditorPrivate *p = _PRIVATE(e); - - if (p->druid_dialogue) { - gdk_window_raise(GTK_WIDGET(p->druid_dialogue)->window); - return; - } - - dialogue = gnome_dialog_new(option?"Edit Filter":"Create filter", "Prev", "Next", "Finish", "Cancel", 0); - - p->druid_dialogue = dialogue; - - gnome_dialog_set_close(dialogue, FALSE); - gnome_dialog_set_sensitive(dialogue, 0, FALSE); - gnome_dialog_set_sensitive(dialogue, 1, FALSE); - gnome_dialog_set_sensitive(dialogue, 2, FALSE); - gnome_dialog_set_default(dialogue, 1); - - gtk_signal_connect(GTK_OBJECT(dialogue), "clicked", druid_dialogue_clicked, e); - - druid = filter_druid_new(); - - p->druid_druid = druid; - - filter_druid_set_default_html(p->druid_druid, "

Create Filtering Rule

" - "

Select one of the base rules above, then continue " - "forwards to customise it.

"); - - filter_druid_set_rules(druid, e->systemoptions, e->rules, option); - gtk_box_pack_start(dialogue->vbox, druid, TRUE, TRUE, 0); - - if (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); - gtk_widget_show(dialogue); -} - -static void -add_clicked(GtkWidget *w, FilterEditor *e) -{ - printf("add new ...\n"); - - add_or_edit(e, NULL); -} - -static void -edit_clicked(GtkWidget *w, FilterEditor *e) -{ - printf("add new ...\n"); - - add_or_edit(e, e->option_current); -} - -static void -remove_clicked(GtkWidget *w, FilterEditor *e) -{ - printf("remove current ...\n"); -} - -static void -up_clicked(GtkWidget *w, FilterEditor *e) -{ - printf("up ...\n"); -} - -static void -down_clicked(GtkWidget *w, FilterEditor *e) -{ - printf("down ...\n"); -} - -/* build the contents of the editor */ -static void -build_editor(FilterEditor *e) -{ - struct _FilterEditorPrivate *p = _PRIVATE(e); - GtkWidget *hbox; - GtkWidget *vbox; - - hbox = gtk_hbox_new(FALSE, 3); - - p->druid = (GtkWidget *)filter_druid_new(); - gtk_box_pack_start((GtkBox *)hbox, p->druid, TRUE, TRUE, 0); - - vbox = gtk_vbox_new(FALSE, 0); - - p->edit = gtk_button_new_with_label ("Edit"); - p->add = gtk_button_new_with_label ("Add"); - p->remove = gtk_button_new_with_label ("Remove"); - p->up = gtk_button_new_with_label ("Up"); - p->down = gtk_button_new_with_label ("Down"); - - gtk_box_pack_start((GtkBox *)vbox, p->edit, FALSE, TRUE, 0); - gtk_box_pack_start((GtkBox *)vbox, p->add, FALSE, TRUE, 3); - gtk_box_pack_start((GtkBox *)vbox, p->remove, FALSE, TRUE, 0); - gtk_box_pack_start((GtkBox *)vbox, p->up, FALSE, TRUE, 3); - gtk_box_pack_start((GtkBox *)vbox, p->down, FALSE, TRUE, 0); - - gtk_box_pack_start((GtkBox *)hbox, vbox, FALSE, FALSE, 0); - - gtk_box_pack_start((GtkBox *)e->parent.vbox, hbox, TRUE, TRUE, 0); - - gtk_signal_connect(p->druid, "option_selected", druid_option_selected, e); - - gtk_signal_connect(p->edit, "clicked", edit_clicked, e); - gtk_signal_connect(p->add, "clicked", add_clicked, e); - gtk_signal_connect(p->remove, "clicked", remove_clicked, e); - gtk_signal_connect(p->up, "clicked", up_clicked, e); - gtk_signal_connect(p->down, "clicked", down_clicked, e); - - filter_druid_set_default_html(p->druid, "

Filtering Rules

" - "

Select one of the rules above to view, and " - "edit. Or Add a new rule.

"); - - gtk_widget_show_all(hbox); - sensitise(e); -} - - -/** - * filter_editor_new: - * - * Create a new FilterEditor object. - * - * Return value: A new FilterEditor widget. - **/ -FilterEditor * -filter_editor_new (void) -{ - FilterEditor *new = FILTER_EDITOR ( gtk_type_new (filter_editor_get_type ())); - - build_editor(new); - - return new; -} - -void -filter_editor_set_rules(FilterEditor *e, GList *rules, GList *systemoptions, GList *useroptions) -{ - struct _FilterEditorPrivate *p = _PRIVATE(e); - - e->rules= rules; - e->systemoptions = systemoptions; - e->useroptions = useroptions; - - filter_druid_set_rules(p->druid, useroptions, rules, NULL); -} - -void -filter_editor_set_rule_files(FilterEditor *e, const char *systemrules, const char *userrules) -{ - GList *rules, *options = NULL, *options2; - xmlDocPtr doc, out, optionset, filteroptions; - - doc = xmlParseFile(systemrules); - rules = filter_load_ruleset(doc); - options2 = filter_load_optionset(doc, rules); - out = xmlParseFile(userrules); - if (out) - options = filter_load_optionset(out, rules); - - printf("Loading system rules: %s = %p = %p\n", systemrules, doc, rules); - printf("Loading user rules: %s = %p = %p\n", userrules, out, options); - - filter_editor_set_rules(e, rules, options2, options); -} - -int -filter_editor_save_rules(FilterEditor *e, const char *userrules) -{ - return filter_write_optionset_file(userrules, e->useroptions); -} - -#ifdef STANDALONE - -int main(int argc, char **argv) -{ - FilterEditor *fe; - - gnome_init("Test", "0.0", argc, argv); - gdk_rgb_init (); - gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); - gtk_widget_set_default_visual (gdk_rgb_get_visual ()); - - fe = filter_editor_new(); - filter_editor_set_rule_files(fe, "/home/notzed/gnome/evolution/filter/filterdescription.xml", "/home/notzed/filters.xml"); - gtk_widget_show(fe); - - gtk_main(); - - return 0; -} - -#endif diff --git a/filter/filter-editor.h b/filter/filter-editor.h deleted file mode 100644 index 66f7a81e11..0000000000 --- a/filter/filter-editor.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef _FILTER_EDITOR_H -#define _FILTER_EDITOR_H - -#include -#include -#include "filter-xml.h" - -#define FILTER_EDITOR(obj) GTK_CHECK_CAST (obj, filter_editor_get_type (), FilterEditor) -#define FILTER_EDITOR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_editor_get_type (), FilterEditorClass) -#define IS_FILTER_EDITOR(obj) GTK_CHECK_TYPE (obj, filter_editor_get_type ()) - -typedef struct _FilterEditor FilterEditor; -typedef struct _FilterEditorClass FilterEditorClass; - -struct _FilterEditor { - GnomeDialog parent; - - struct _FilterEditorPrivate *priv; - - GList *rules; - GList *systemoptions; - GList *useroptions; - - struct filter_option *option_current; -}; - -struct _FilterEditorClass { - GnomeDialogClass parent_class; -}; - -guint filter_editor_get_type (void); -FilterEditor *filter_editor_new (void); - -void filter_editor_set_rules(FilterEditor *e, GList *rules, GList *systemoptions, GList *useroptions); -void filter_editor_set_rule_files(FilterEditor *e, const char *systemrules, const char *userrules); -int filter_editor_save_rules(FilterEditor *e, const char *userrules); - -#endif /* ! _FILTER_EDITOR_H */ diff --git a/filter/filter-format.c b/filter/filter-format.c deleted file mode 100644 index b7a2a956be..0000000000 --- a/filter/filter-format.c +++ /dev/null @@ -1,237 +0,0 @@ -/* -*- Mode: C; c-file-style: "linux"; indent-tabs-mode: t; c-basic-offset: 8; -*- */ - -#include -#include -#include -#include - -#include -#include - -#include "filter-arg-types.h" -#include "filter-xml.h" - -#define d(x) - -/* FIXME: remove static, this is defined in filter-xml */ -static int -filter_find_rule(struct filter_rule *a, char *name) -{ - d(printf("finding, is %s = %s?\n", a->name, name)); - return strcmp(a->name, name); -} - -static int -filter_find_arg(FilterArg *a, char *name) -{ - d(printf("finding, is %s = %s?\n", a->name, name)); - return strcmp(a->name, name); -} - -static int display_order[] = { FILTER_XML_MATCH, FILTER_XML_ACTION, FILTER_XML_EXCEPT }; - -static struct filter_option * -option_clone(struct filter_option *source) -{ - struct filter_option *dest = g_malloc0(sizeof(*dest)); - GList *loptions; - struct filter_optionrule *old, *new; - - dest->type = source->type; - dest->description = source->description; - loptions = dest->options; - while (loptions) { - old = loptions->data; - new = g_malloc0(sizeof(*new)); - new->rule = old->rule; - /* FIXME: need to copy any args as well!!! */ - dest->options = g_list_append(dest->options, new); - loptions = g_list_next(loptions); - } - return dest; -} - - - -struct description_decode_lambda { - GString *str; - GList *args; - GtkHTML *html; - GtkHTMLStream *stream; -}; - -static char * -arg_text(FilterArg *arg) -{ - char *out = NULL; - GList *value, *next; - GString *str; - - value = arg->values; - - d(printf("getting text from arg %s\n", arg->name)); - - if (value == NULL) - return NULL; - - str = g_string_new(""); - filter_arg_write_text(arg, str); - out = str->str; - g_string_free(str, FALSE); - return out; -} - -static void -description_decode_text(struct filter_desc *d, struct description_decode_lambda *l) -{ - GList *list; - char *txt; - - switch (d->type) { - case FILTER_XML_TEXT: - case FILTER_XML_DESC: - dotext: - d(printf("appending '%s'\n", d->data)); - /* printf("vartype = %s\n", detokenise(d->vartype)); */ - d(printf("varname = %s\n", d->varname)); - if (d->vartype !=-1 && d->varname - && (list = g_list_find_custom(l->args, d->varname, (GCompareFunc) filter_find_arg)) - && (txt = arg_text(list->data))) { - } else { - txt = d->data; - } - g_string_append(l->str, txt); - break; - default: - printf("WARN: unknown desc text type '%d' = %s\n", d->type, d->data); - goto dotext; - } -} - -char * -filter_description_text(GList *description, GList *args) -{ - char *txt; - struct description_decode_lambda l; - - d(printf("\ndecoding ...\n")); - - l.str = g_string_new(""); - l.args = args; - g_list_foreach(description, (GFunc) description_decode_text, &l); - - d(printf("string is '%s'\n", l.str->str)); - - txt = l.str->str; - g_string_free(l.str, FALSE); - - return txt; -} - -static void -html_write(GtkHTML *html, GtkHTMLStream *stream, char *s) -{ - d(printf("appending html '%s'\n", s)); - gtk_html_write(html, stream, s, strlen(s)); -} - - -static void -description_decode_html(struct filter_desc *d, struct description_decode_lambda *l) -{ - GList *list; - char *txt, *end; - int free; - - switch (d->type) { - case FILTER_XML_TEXT: - case FILTER_XML_DESC: - dotext: - d(printf("appending '%s'\n", d->data)); - /*printf("vartype = %s\n", detokenise(d->vartype));*/ - d(printf("varname = %s\n", d->varname)); - free = FALSE; - if (d->vartype !=-1 && d->varname) { - char *link; - list = g_list_find_custom(l->args, d->varname, (GCompareFunc) filter_find_arg); - end = ""; - if (list) { - txt = arg_text(list->data); - if (txt == NULL) - txt = d->data; - else - free = TRUE; - link = g_strdup_printf("", d, list->data); - } else { - printf("cannot find arg '%s'\n", d->varname); - link = g_strdup_printf("", d, NULL); - txt = d->data; - } - html_write(l->html, l->stream, link); - g_free(link); - } else { - txt = d->data; - end = NULL; - } - html_write(l->html, l->stream, txt); - if (end) { - html_write(l->html, l->stream, end); - } - if (free) - g_free(txt); - break; - default: - /*printf("WARN: unknown desc text type '%s' = %s\n", detokenise(d->type), d->data);*/ - goto dotext; - } -} - -void -filter_description_html_write(GList *description, GList *args, GtkHTML *html, GtkHTMLStream *stream) -{ - char *txt; - struct description_decode_lambda l; - - d(printf("\ndecoding ...\n")); - - l.str = NULL; - l.args = args; - l.html = html; - l.stream = stream; - g_list_foreach(description, (GFunc) description_decode_html, &l); -} - -#ifdef TESTER -int main(int argc, char **argv) -{ - GList *rules, *options; - xmlDocPtr doc, out, optionset, filteroptions; - - gnome_init("Test", "0.0", argc, argv); - - doc = xmlParseFile("filterdescription.xml"); - - rules = load_ruleset(doc); - options = load_optionset(doc, rules); - - out = xmlParseFile("saveoptions.xml"); - options = load_optionset(doc, rules); - - while (options) { - printf("applying a rule ...\n"); - filterme(options->data); - options = g_list_next(options); - } - -#if 0 - out = xmlNewDoc("1.0"); - optionset = save_optionset(out, options); - filteroptions = xmlNewDocNode(out, NULL, "filteroptions", NULL); - xmlAddChild(filteroptions, optionset); - xmlDocSetRootElement(out, filteroptions); - xmlSaveFile("saveoptions.xml", out); -#endif - return 0; -} -#endif - diff --git a/filter/filter-format.h b/filter/filter-format.h deleted file mode 100644 index bdd047164e..0000000000 --- a/filter/filter-format.h +++ /dev/null @@ -1,10 +0,0 @@ - -#ifndef _FILTER_FORMAT_H -#define _FILTER_FORMAT_H - -#include - -char *filter_description_text(GList *description, GList *args); -void description_html_write(GList *description, GList *args, GtkHTML *html, GtkHTMLStream *stream); - -#endif /* _FILTER_FORMAT_H */ diff --git a/filter/filter-xml.c b/filter/filter-xml.c deleted file mode 100644 index 1979ab76f7..0000000000 --- a/filter/filter-xml.c +++ /dev/null @@ -1,580 +0,0 @@ -/* -*- Mode: C; c-file-style: "linux"; indent-tabs-mode: t; c-basic-offset: 8; -*- */ - -/* Load save filter descriptions/options from an xml file */ - -#include -#include -#include -#include - -#include -#include - -#include "filter-arg-types.h" -#include "filter-xml.h" - -#define d(x) - -struct token_tab { - char *name; - enum filter_xml_token token; -}; - -struct token_tab token_table[] = { - { "action", FILTER_XML_ACTION }, - { "address", FILTER_XML_ADDRESS }, - { "code", FILTER_XML_CODE }, - { "description", FILTER_XML_DESC }, - { "except", FILTER_XML_EXCEPT }, - { "folder", FILTER_XML_FOLDER }, - { "match", FILTER_XML_MATCH }, - { "name", FILTER_XML_NAME }, - { "option", FILTER_XML_OPTION }, - { "optionrule", FILTER_XML_OPTIONRULE }, - { "optionset", FILTER_XML_OPTIONSET }, - { "optionvalue", FILTER_XML_OPTIONVALUE }, - { "receive", FILTER_XML_RECEIVE }, - { "rule", FILTER_XML_RULE }, - { "ruleset", FILTER_XML_RULESET }, - { "send", FILTER_XML_SEND }, - { "source", FILTER_XML_SOURCE }, - { "text", FILTER_XML_TEXT }, -}; - -/* convert a name to a token value */ -static int -tokenise(const char *name) -{ - int i; - int len = sizeof(token_table)/sizeof(token_table[0]); - - if (name) { - for (i=0;i=0) { - for (i=0;i"; -} - - -static xmlNodePtr -find_node(xmlNodePtr start, char *name) -{ - d(printf("trying to find node '%s'\n", name)); - while (start && strcmp(start->name, name)) - start = start->next; - d(printf("node = %p\n", start)); - return start; -} - -static xmlNodePtr -find_node_attr(xmlNodePtr start, char *name, char *attrname, char *attrvalue) -{ - char *s; - - d(printf("looking for node named %s with attribute %s=%s\n", name, attrname, attrvalue)); - - while ( start && (start = find_node(start, name)) ) { - s = xmlGetProp(start, attrname); - d(printf(" comparing '%s' to '%s'\n", s, attrvalue)); - if (s && !strcmp(s, attrvalue)) { - free(s); - break; - } - free(s); - start = start->next; - } - return start; -} - -static GList * -load_desc(xmlNodePtr node, int type, int vartype, char *varname) -{ - struct filter_desc *desc; - xmlNodePtr n; - int newtype; - int newvartype; - char *newvarname; - GList *list = NULL; - - while (node) { - if (node->content) { - desc = g_malloc0(sizeof(*desc)); - desc->data = node->content; - desc->type = type; - desc->vartype = vartype; - desc->varname = varname?g_strdup(varname):0; - d(printf(" **** node name = %s var name = %s var type = %s\n", node->name, varname, detokenise(vartype))); - list = g_list_append(list, desc); - d(printf("appending '%s'\n", node->content)); - newtype = type; - newvartype = -1; - newvarname = NULL; - } else { - newtype = tokenise(node->name); - newvartype = tokenise_xmlfreeprop(xmlGetProp(node, "type")); - newvarname = xmlGetProp(node, "name"); - } - n = node->childs; - while (n) { - d(printf("adding child '%s'\n", n->name)); - list = g_list_concat(list, load_desc(n, newtype, newvartype, newvarname)); - n = n->next; - } - if (newvarname) - free(newvarname); - node = node->next; - } - return list; -} - -GList * -filter_load_ruleset(xmlDocPtr doc) -{ - xmlNodePtr ruleset, rule, n; - struct filter_rule *r; - int type; - int ruletype; - GList *rules = NULL; - - g_return_val_if_fail(doc!=NULL, NULL); - - ruleset = find_node(doc->root->childs, "ruleset"); - - while (ruleset) { - - rule = ruleset->childs; - - ruletype = tokenise_xmlfreeprop(xmlGetProp(ruleset, "type")); - - d(printf("ruleset, name = %s\n", ruleset->name)); - - while (rule) { - - n = rule->childs; - r = g_malloc0(sizeof(*r)); - r->type = ruletype; - r->name = xmlGetProp(rule, "name"); - - d(printf(" rule, name = %s\n", r->name)); - - while (n) { - type = tokenise(n->name); - d(printf(" n, name = %s\n", n->name)); - d(printf(" ncontent = %s\n", n->content)); - d(printf(" childs = %p\n", n->childs)); - if (n->childs) { - d(printf(" childs content = %s\n", n->childs->content)); - } - switch(type) { - case FILTER_XML_CODE: - r->code = xmlNodeGetContent(n); - break; - case FILTER_XML_DESC: - d(printf(" ** loading description\n")); - r->description = load_desc(n->childs, type, -1, NULL); - d(printf(" ** done loading description\n")); - break; - default: - printf("warning, unknown token encountered\n"); - break; - } - n = n->next; - } - if (r) - rules = g_list_append(rules, r); - rule = rule->next; - } - ruleset = find_node(ruleset->next, "ruleset"); - } - return rules; -} - -int -filter_find_rule(struct filter_rule *a, char *name) -{ - d(printf("finding, is %s = %s?\n", a->name, name)); - return strcmp(a->name, name); -} - -int -filter_find_arg(FilterArg *a, char *name) -{ - d(printf("finding, is %s = %s?\n", a->name, name)); - return strcmp(a->name, name); -} - -static FilterArg * -load_optionvalue(struct filter_desc *desc, xmlNodePtr node) -{ - FilterArg *arg = NULL; - - d(printf("creating arg entry for '%s'\n", desc->varname)); - - switch(desc->vartype) { - case FILTER_XML_ADDRESS: - arg = filter_arg_address_new(desc->varname); - break; - case FILTER_XML_FOLDER: - arg = filter_arg_folder_new(desc->varname); - break; - default: - d(printf("ok, maybe we're not\n")); - /* unknown arg type, drop it */ - return NULL; - } - - if (node == NULL) - return arg; - - filter_arg_values_add_xml(arg, node); - - return arg; -} - -GList * -filter_load_optionset(xmlDocPtr doc, GList *rules) -{ - xmlNodePtr optionset, option, o, or; - struct filter_option *op; - struct filter_optionrule *optionrule; - struct filter_rule *fr; - struct filter_desc *desc; - int type; - GList *l = NULL; - GList *lrule; - GList *ldesc; - - g_return_val_if_fail(doc!=NULL, NULL); - - optionset = find_node(doc->root->childs, "optionset"); - if (optionset == NULL) { - printf("optionset not found\n"); - return NULL; - } - option = find_node(optionset->childs, "option"); - while (option) { - o = option->childs; - op = g_malloc0(sizeof(*op)); - d(printf("option = %s\n", o->name)); - d(printf("option, type=%s\n", xmlGetProp(option, "type"))); - op->type = tokenise_xmlfreeprop(xmlGetProp(option, "type")); - while (o) { - char *rulestr; - - type = tokenise(o->name); - switch (type) { - case FILTER_XML_OPTIONRULE: - rulestr = xmlGetProp(o, "rule"); - lrule = g_list_find_custom(rules, rulestr, (GCompareFunc) filter_find_rule); - if (lrule) { - fr = lrule->data; - d(printf("found rule : %s\n", fr->name)); - optionrule = g_malloc0(sizeof(*optionrule)); - optionrule->rule = fr; - op->options = g_list_append(op->options, optionrule); - - /* scan through all variables required, setup blank variables if they do not exist */ - ldesc = fr->description; - while (ldesc) { - desc = ldesc->data; - if (desc->varname && desc->vartype!=-1) { - FilterArg *arg; - /* try and see if there is a setting for this value */ - or = find_node_attr(o->childs, "optionvalue", "name", desc->varname); - arg = load_optionvalue(desc, or); - if (arg) { - optionrule->args = g_list_append(optionrule->args, arg); - d(printf("Adding arg %s\n", arg->name)); - } - } - ldesc = g_list_next(ldesc); - } - } else { - /* FIXME: memleak */ - printf("Cannot find rule: %s\n", rulestr); - } - free(rulestr); - break; - case FILTER_XML_DESC: - d(printf("loading option descriptiong\n")); - op->description = load_desc(option->childs, type, -1, NULL); - break; - } - o = o->next; - } - l = g_list_append(l, op); - option = find_node(option->next, "option"); - } - return l; -} - -static xmlNodePtr -write_description(xmlDocPtr doc, GList *descl) -{ - xmlNodePtr d; - struct filter_desc *desc; - - desc = descl->data; - d = xmlNewDocNode(doc, NULL, "description", NULL); - xmlNodeSetContent(d, desc->data); - return d; -} - -xmlNodePtr -filter_write_optionset(xmlDocPtr doc, GList *optionl) -{ - xmlNodePtr root, option, optionrule, optionvalue; - GList *optionrulel, *argl; - struct filter_optionrule *or; - - root = xmlNewDocNode(doc, NULL, "optionset", NULL); - - /* for all options */ - while (optionl) { - struct filter_option *op = optionl->data; - - option = xmlNewDocNode(doc, NULL, "option", NULL); - xmlSetProp(option, "type", detokenise(op->type)); - - if (op->description) { - xmlNodePtr desc; - - desc = write_description(doc, op->description); - xmlAddChild(option, desc); - } - - optionrulel = op->options; - while (optionrulel) { - or = optionrulel->data; - - optionrule = xmlNewDocNode(doc, NULL, "optionrule", NULL); - xmlSetProp(optionrule, "type", detokenise(or->rule->type)); - xmlSetProp(optionrule, "rule", or->rule->name); - - argl = or->args; - while (argl) { - FilterArg *arg = argl->data; - - optionvalue = filter_arg_values_get_xml(arg); - if (optionvalue) - xmlAddChild(optionrule, optionvalue); - - argl = g_list_next(argl); - } - - xmlAddChild(option, optionrule); - - optionrulel = g_list_next(optionrulel); - } - - xmlAddChild(root, option); - optionl = g_list_next(optionl); - } - - return root; -} - -/* utility functions */ -struct filter_optionrule * -filter_clone_optionrule(struct filter_optionrule *or) -{ - GList *arg; - struct filter_optionrule *rule; - - rule = g_malloc0(sizeof(*rule)); - - rule->rule = or->rule; - arg = or->args; - while (arg) { - FilterArg *new = filter_arg_clone(FILTER_ARG(arg->data)); - gtk_object_set_data((GtkObject *)new, "origin", arg->data); - rule->args = g_list_append(rule->args, new); - arg = g_list_next(arg); - } - return rule; -} - -void -filter_clone_optionrule_free(struct filter_optionrule *or) -{ - GList *argl; - - d(printf("---- free optionrule\n")); - - argl = or->args; - while (argl) { - gtk_object_unref(GTK_OBJECT(argl->data)); - argl = g_list_next(argl); - } - g_list_free(or->args); - g_free(or); -} - -struct filter_optionrule * -filter_optionrule_new_from_rule(struct filter_rule *rule) -{ - struct filter_optionrule *or; - GList *descl; - - or = g_malloc0(sizeof(*or)); - - or->rule = rule; - - descl = rule->description; - while (descl) { - struct filter_desc *desc = descl->data; - if (desc->varname && desc->vartype != -1) { - FilterArg *arg = NULL; - switch (desc->vartype) { - case FILTER_XML_ADDRESS: - arg = filter_arg_address_new(desc->varname); - break; - case FILTER_XML_FOLDER: - arg = filter_arg_folder_new(desc->varname); - break; - } - if (arg) { - or->args = g_list_append(or->args, arg); - } - } - descl = g_list_next(descl); - } - 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; - } -} - -GList *filter_load_ruleset_file(const char *name) -{ - xmlDocPtr doc; - GList *rules; - - doc = xmlParseFile(name); - rules = filter_load_ruleset(doc); - xmlFreeDoc(doc); - - return rules; -} - -GList *filter_load_optionset_file(const char *name, GList *rules) -{ - xmlDocPtr doc; - GList *options; - - doc = xmlParseFile(name); - options = filter_load_optionset(doc, rules); - xmlFreeDoc(doc); - - return options; -} - -int filter_write_optionset_file(const char *name, GList *optionl) -{ - xmlDocPtr out; - xmlDocPtr optionset; - xmlNodePtr filteroptions; - int ret; - - out = xmlNewDoc("1.0"); - optionset = filter_write_optionset(out, optionl); - filteroptions = xmlNewDocNode(out, NULL, "filteroptions", NULL); - xmlAddChild(filteroptions, optionset); - xmlDocSetRootElement(out, filteroptions); - ret = xmlSaveFile(name, out); - xmlFreeDoc(out); - - return ret; -} diff --git a/filter/filter-xml.h b/filter/filter-xml.h deleted file mode 100644 index ce8a5ffc3a..0000000000 --- a/filter/filter-xml.h +++ /dev/null @@ -1,77 +0,0 @@ - -#ifndef _FILTER_XML_H -#define _FILTER_XML_H - -#include -#include - -#include "filter-arg.h" - -enum filter_xml_token { - FILTER_XML_TEXT=0, - FILTER_XML_RULE, - FILTER_XML_CODE, - FILTER_XML_DESC, - FILTER_XML_RULESET, - FILTER_XML_OPTION, - FILTER_XML_OPTIONRULE, - FILTER_XML_OPTIONSET, - FILTER_XML_OPTIONVALUE, - FILTER_XML_SOURCE, - FILTER_XML_SEND, - FILTER_XML_RECEIVE, - FILTER_XML_ADDRESS, - FILTER_XML_FOLDER, - FILTER_XML_NAME, - FILTER_XML_MATCH, - FILTER_XML_ACTION, - FILTER_XML_EXCEPT -}; - -struct filter_desc { - int type; - char *data; - char *varname; /* for named types */ - int vartype; -}; - -struct filter_rule { - int type; - char *name; - char *code; - GList *description; -}; - -struct filter_optionrule { - struct filter_rule *rule; - GList *args; /* FilterArg objects */ -}; - -struct filter_option { - int type; /* 'send' 'receive'? */ - GList *description; /* filter_desc */ - GList *options; /* option_rule */ -}; - -GList *filter_load_ruleset(xmlDocPtr doc); -GList *filter_load_optionset(xmlDocPtr doc, GList *rules); -xmlNodePtr filter_write_optionset(xmlDocPtr doc, GList *optionl); - -void filter_description_free(GList *descl); -void filter_load_ruleset_free(GList *nodel); -void filter_load_optionset_free(GList *optionl); - -GList *filter_load_ruleset_file(const char *name); -GList *filter_load_optionset_file(const char *name, GList *rules); -int filter_write_optionset_file(const char *name, GList *optionl); - -/* callbacks for searching GLists of various types */ -int filter_find_rule(struct filter_rule *a, char *name); -int filter_find_arg(FilterArg *a, char *name); - -/* utility functions */ -struct filter_optionrule *filter_clone_optionrule(struct filter_optionrule *or); -void filter_clone_optionrule_free(struct filter_optionrule *or); -struct filter_optionrule *filter_optionrule_new_from_rule(struct filter_rule *rule); - -#endif /* ! _FILTER_XML_H */ diff --git a/filter/filtertypes.xml b/filter/filtertypes.xml deleted file mode 100644 index f93a7b9c35..0000000000 --- a/filter/filtertypes.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - (match-all (header-contains "From" ${sender})) - - The From address matches sender(s). - - - - - (match-all (header-contains "To" ${receipient})) - - The To address matches receipients. - - - - - (match-all (header-contains "Subject" ${words})) - - The Subject contains words. - - - - - (match-all (header-contains "CC" ${self-email})) - - I am in the cc list. - - - - - (& (> message-size (size-lower size-range)) - (< message-size (size-uppwer size-range))) - - The message is a certain size. - - - - - - - (copy-to ${folder}) - - Send a copy to folder. - - - - (forward-to ${address}) - - Forward the message to people. - - - - (delete) - - Delete message. - - - - (stop) - - Stop processing further rules for this message. - - - - - - - (match-all (not (header-contains "To" ${self-email}))) - - When I am the receipient. - - - - - - - - - - -- cgit v1.2.3