diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-05-10 03:49:10 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-05-10 03:49:10 +0800 |
commit | 61ad53bfa902a1d48346457bb59461684f904e5e (patch) | |
tree | c9540fc22d97b4504eec56950e04933273362815 | |
parent | aedd47862d6d5268cd61bd4f7da7c4e5cc1a2f3b (diff) | |
download | gsoc2013-evolution-61ad53bfa902a1d48346457bb59461684f904e5e.tar.gz gsoc2013-evolution-61ad53bfa902a1d48346457bb59461684f904e5e.tar.zst gsoc2013-evolution-61ad53bfa902a1d48346457bb59461684f904e5e.zip |
New filter widgets for choosing files and/or command-line's (?). Not yet
2002-05-09 Jeffrey Stedfast <fejj@ximian.com>
* filter-file.[c,h]: New filter widgets for choosing files and/or
command-line's (?). Not yet hooked up or anything, just for future
use.
svn path=/trunk/; revision=16735
-rw-r--r-- | filter/ChangeLog | 6 | ||||
-rw-r--r-- | filter/filter-file.c | 308 | ||||
-rw-r--r-- | filter/filter-file.h | 61 |
3 files changed, 375 insertions, 0 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index beaecec429..358ffbdfb1 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,9 @@ +2002-05-09 Jeffrey Stedfast <fejj@ximian.com> + + * filter-file.[c,h]: New filter widgets for choosing files and/or + command-line's (?). Not yet hooked up or anything, just for future + use. + 2002-05-08 Not Zed <NotZed@Ximian.com> * rule-context.c (rule_context_delete_uri): Changed to return a diff --git a/filter/filter-file.c b/filter/filter-file.c new file mode 100644 index 0000000000..6884fcb1a9 --- /dev/null +++ b/filter/filter-file.c @@ -0,0 +1,308 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@ximian.com> + * + * Copyright 2002 Ximian, Inc. (www.ximian.com) + * + * 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 Street #330, Boston, MA 02111-1307, USA. + * + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <sys/types.h> +#include <regex.h> +#include <gtk/gtkobject.h> +#include <gtk/gtkwidget.h> + +#include <libgnome/gnome-defs.h> +#include <libgnome/gnome-i18n.h> +#include <libgnomeui/gnome-dialog.h> +#include <libgnomeui/gnome-dialog-util.h> +#include <libgnomeui/gnome-file-entry.h> +#include <gal/widgets/e-unicode.h> + +#include "filter-file.h" +#include "e-util/e-sexp.h" + +#define d(x) + +static gboolean validate (FilterElement *fe); +static void xml_create(FilterElement *fe, xmlNodePtr node); +static xmlNodePtr xml_encode(FilterElement *fe); +static int xml_decode(FilterElement *fe, xmlNodePtr node); +static GtkWidget *get_widget(FilterElement *fe); +static void build_code(FilterElement *fe, GString *out, struct _FilterPart *ff); +static void format_sexp(FilterElement *, GString *); + +static void filter_file_class_init (FilterFileClass *class); +static void filter_file_init (FilterFile *gspaper); +static void filter_file_finalise (GtkObject *obj); + +#define _PRIVATE(x) (((FilterFile *)(x))->priv) + +struct _FilterFilePrivate { +}; + +static FilterElementClass *parent_class; + +enum { + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +GtkType +filter_file_get_type (void) +{ + static GtkType type = 0; + + if (!type) { + GtkTypeInfo type_info = { + "FilterFile", + sizeof (FilterFile), + sizeof (FilterFileClass), + (GtkClassInitFunc) filter_file_class_init, + (GtkObjectInitFunc) filter_file_init, + (GtkArgSetFunc) NULL, + (GtkArgGetFunc) NULL + }; + + type = gtk_type_unique (filter_element_get_type (), &type_info); + } + + return type; +} + +static void +filter_file_class_init (FilterFileClass *klass) +{ + GtkObjectClass *object_class = (GtkObjectClass *) klass; + FilterElementClass *filter_element = (FilterElementClass *) klass; + + parent_class = gtk_type_class (filter_element_get_type ()); + + object_class->finalize = filter_file_finalise; + + /* override methods */ + filter_element->validate = validate; + filter_element->xml_create = xml_create; + filter_element->xml_encode = xml_encode; + filter_element->xml_decode = xml_decode; + filter_element->get_widget = get_widget; + filter_element->build_code = build_code; + filter_element->format_sexp = format_sexp; + + /* signals */ + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); +} + +static void +filter_file_init (FilterFile *o) +{ + o->priv = g_malloc0 (sizeof (*o->priv)); +} + +static void +filter_file_finalise (GtkObject *obj) +{ + FilterFile *o = (FilterFile *) obj; + + xmlFree (o->type); + g_free (o->path); + + g_free (o->priv); + + ((GtkObjectClass *)(parent_class))->finalize (obj); +} + +/** + * filter_file_new: + * + * Create a new FilterFile object. + * + * Return value: A new #FilterFile object. + **/ +FilterFile * +filter_file_new (void) +{ + return (FilterFile *) gtk_type_new (filter_file_get_type ()); +} + + +FilterFile * +filter_file_new_type (const char *type) +{ + FilterFile *file; + + file = filter_file_new (); + file->type = xmlStrdup (type); + + return file; +} + +void +filter_file_set_path (FilterFile *file, const char *path) +{ + g_free (file->path); + file->path = g_strdup (path); +} + +static gboolean +validate (FilterElement *fe) +{ + FilterFile *file = (FilterFile *) fe; + GtkWidget *dialog; + struct stat st; + + if (!file->path) { + dialog = gnome_ok_dialog (_("You must specify a file name")); + + gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); + return FALSE; + } + + if (strcmp (file->type, "command") != 0) { + if (stat (file->path, &st) == -1 || !S_ISREG (st.st_mode)) { + char *errmsg; + + errmsg = g_strdup_printf (_("File '%s' does not exist or is not a regular file."), file->path); + dialog = gnome_ok_dialog (errmsg); + g_free (errmsg); + + gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); + return FALSE; + } + } + + return TRUE; +} + +static void +xml_create (FilterElement *fe, xmlNodePtr node) +{ + /* parent implementation */ + ((FilterElementClass *)(parent_class))->xml_create (fe, node); + +} + +static xmlNodePtr +xml_encode (FilterElement *fe) +{ + FilterFile *file = (FilterFile *) fe; + xmlNodePtr cur, value; + char *encstr, *type; + + type = file->type ? file->type : "file"; + + d(printf ("Encoding %s as xml\n", type)); + + value = xmlNewNode (NULL, "value"); + xmlSetProp (value, "name", fe->name); + xmlSetProp (value, "type", type); + + cur = xmlNewChild (value, NULL, type, NULL); + encstr = e_utf8_xml1_encode (file->path); + xmlNodeSetContent (cur, encstr); + g_free (encstr); + + return value; +} + +static int +xml_decode (FilterElement *fe, xmlNodePtr node) +{ + FilterFile *file = (FilterFile *)fe; + char *name, *str, *type; + xmlNodePtr n; + + name = xmlGetProp (node, "name"); + type = xmlGetProp (node, "type"); + + d(printf("Decoding %s from xml %p\n", type, fe)); + d(printf ("Name = %s\n", name)); + + xmlFree (fe->name); + fe->name = name; + xmlFree (file->type); + file->type = type; + + n = node->childs; + if (!strcmp (n->name, type)) { + char *decstr; + + str = xmlNodeGetContent (n); + if (str) { + decstr = e_utf8_xml1_decode (str); + xmlFree (str); + } else + decstr = g_strdup (""); + + d(printf (" '%s'\n", decstr)); + + file->path = decstr; + } else { + g_warning ("Unknown node type '%s' encountered decoding a %s\n", n->name, type); + } + + return 0; +} + +static void +entry_changed (GtkEntry *entry, FilterElement *fe) +{ + FilterFile *file = (FilterFile *) fe; + char *new; + + new = e_utf8_gtk_entry_get_text (entry); + + g_free (file->path); + fi->path = new; +} + +static GtkWidget * +get_widget (FilterElement *fe) +{ + FilterFile *file = (FilterFile *) fe; + GtkWidget *fileentry, *entry; + + fileentry = gnome_file_entry_new (NULL, _("Choose a file")); + gnome_file_entry_set_default_path (GNOME_FILE_ENTRY (fileentry), file->path); + gnome_file_entry_set_modal (GNOME_FILE_ENTRY (fileentry), TRUE); + + entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (fileentry)); + gtk_signal_connect (GTK_OBJECT (entry), "changed", entry_changed, fe); + + return fileentry; +} + +static void +build_code (FilterElement *fe, GString *out, struct _FilterPart *ff) +{ + return; +} + +static void +format_sexp (FilterElement *fe, GString *out) +{ + FilterFile *file = (FilterFile *) fe; + + e_sexp_encode_string (out, file->path); +} diff --git a/filter/filter-file.h b/filter/filter-file.h new file mode 100644 index 0000000000..fa772f7bd2 --- /dev/null +++ b/filter/filter-file.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@ximian.com> + * + * Copyright 2002 Ximian, Inc. (www.ximian.com) + * + * 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 Street #330, Boston, MA 02111-1307, USA. + * + */ + + +#ifndef _FILTER_FILE_H +#define _FILTER_FILE_H + +#include "filter-element.h" + +#define FILTER_FILE(obj) GTK_CHECK_CAST (obj, filter_file_get_type (), FilterFile) +#define FILTER_FILE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_file_get_type (), FilterFileClass) +#define IS_FILTER_FILE(obj) GTK_CHECK_TYPE (obj, filter_file_get_type ()) + +typedef struct _FilterFile FilterFile; +typedef struct _FilterFileClass FilterFileClass; + +struct _FilterFile { + FilterElement parent; + struct _FilterFilePrivate *priv; + + char *type; + char *path; +}; + +struct _FilterFileClass { + FilterElementClass parent_class; + + /* virtual methods */ + + /* signals */ +}; + +GtkType filter_file_get_type (void); + +FilterFile *filter_file_new (void); + +FilterFile *filter_file_new_type_name (const char *type); + +/* methods */ +void filter_file_set_path (FilterFile *file, const char *path); + +#endif /* ! _FILTER_FILE_H */ |