aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-input.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-10-31 11:43:26 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-10-31 11:43:26 +0800
commit0eb24eaa396b7f5f3ebe6fab21080cda7ba7d4bc (patch)
treed3a41d97055a1a92aa804201dacef5385c062c48 /filter/filter-input.c
parent7c3fad23b7c212cc96606a44e81d43e65b85acf8 (diff)
downloadgsoc2013-evolution-0eb24eaa396b7f5f3ebe6fab21080cda7ba7d4bc.tar
gsoc2013-evolution-0eb24eaa396b7f5f3ebe6fab21080cda7ba7d4bc.tar.gz
gsoc2013-evolution-0eb24eaa396b7f5f3ebe6fab21080cda7ba7d4bc.tar.bz2
gsoc2013-evolution-0eb24eaa396b7f5f3ebe6fab21080cda7ba7d4bc.tar.lz
gsoc2013-evolution-0eb24eaa396b7f5f3ebe6fab21080cda7ba7d4bc.tar.xz
gsoc2013-evolution-0eb24eaa396b7f5f3ebe6fab21080cda7ba7d4bc.tar.zst
gsoc2013-evolution-0eb24eaa396b7f5f3ebe6fab21080cda7ba7d4bc.zip
If a regex option is selected, change the FilterElement data to TRUE else
2000-10-30 Jeffrey Stedfast <fejj@helixcode.com> * filter-option.c (option_activate): If a regex option is selected, change the FilterElement data to TRUE else set to FALSE. * filter-rule.c (more_parts): Validate the previously entered FilterPart before allowing the user to add a new FilterPart. * filter-part.c (filter_part_validate): New convenience function to validate an entire FilterPart expression. * filter-input.c (validate): Validate the entry text if it contains a regular expression. * filter-element.[c,h]: New virtual function to validate the contents of the FilterElement (useful for regex and sexp). (filter_element_validate): You get the idea... svn path=/trunk/; revision=6285
Diffstat (limited to 'filter/filter-input.c')
-rw-r--r--filter/filter-input.c72
1 files changed, 61 insertions, 11 deletions
diff --git a/filter/filter-input.c b/filter/filter-input.c
index 2ef4327c33..fcee83a9eb 100644
--- a/filter/filter-input.c
+++ b/filter/filter-input.c
@@ -20,6 +20,7 @@
#include <gtk/gtk.h>
#include <gnome.h>
+#include <regex.h>
#include <gal/widgets/e-unicode.h>
@@ -28,6 +29,7 @@
#define d(x)
+static gboolean validate (FilterElement *fe, gpointer data);
static void xml_create(FilterElement *fe, xmlNodePtr node);
static xmlNodePtr xml_encode(FilterElement *fe);
static int xml_decode(FilterElement *fe, xmlNodePtr node);
@@ -86,6 +88,7 @@ filter_input_class_init (FilterInputClass *class)
object_class->finalize = filter_input_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;
@@ -101,16 +104,16 @@ filter_input_class_init (FilterInputClass *class)
static void
filter_input_init (FilterInput *o)
{
- o->priv = g_malloc0(sizeof(*o->priv));
+ o->priv = g_malloc0 (sizeof (*o->priv));
}
static void
-filter_input_finalise(GtkObject *obj)
+filter_input_finalise (GtkObject *obj)
{
FilterInput *o = (FilterInput *)obj;
-
+
o = o;
-
+
((GtkObjectClass *)(parent_class))->finalize(obj);
}
@@ -131,8 +134,8 @@ filter_input_new (void)
FilterInput *
filter_input_new_type_name (const char *type)
{
- FilterInput *o = filter_input_new();
- o->type = g_strdup(type);
+ FilterInput *o = filter_input_new ();
+ o->type = g_strdup (type);
d(printf("new type %s = %p\n", type, o));
return o;
@@ -142,15 +145,62 @@ void
filter_input_set_value (FilterInput *fi, const char *value)
{
GList *l;
-
+
l = fi->values;
while (l) {
- g_free(l->data);
- l = g_list_next(l);
+ g_free (l->data);
+ l = g_list_next (l);
}
- g_list_free(fi->values);
+ g_list_free (fi->values);
+
+ fi->values = g_list_append (NULL, g_strdup (value));
+}
- fi->values = g_list_append(NULL, g_strdup(value));
+static gboolean
+validate (FilterElement *fe, gpointer data)
+{
+ FilterInput *fi = (FilterInput *)fe;
+ gboolean is_regex = FALSE;
+ gboolean valid = TRUE;
+
+ if (data)
+ is_regex = GPOINTER_TO_INT (data);
+
+ if (is_regex) {
+ regex_t regexpat; /* regex patern */
+ gint regerr;
+ char *text;
+
+ text = fi->values->data;
+
+ regerr = regcomp (&regexpat, text, REG_EXTENDED | REG_NEWLINE | REG_ICASE);
+ if (regerr) {
+ GtkWidget *dialog;
+ gchar *regmsg, *errmsg;
+ size_t reglen;
+
+ /* regerror gets called twice to get the full error string
+ length to do proper posix error reporting */
+ reglen = regerror (regerr, &regexpat, 0, 0);
+ regmsg = g_malloc0 (reglen + 1);
+ regerror (regerr, &regexpat, regmsg, reglen);
+
+ errmsg = g_strdup_printf (_("Error in regular expression '%s':\n%s"),
+ text, regmsg);
+ g_free (regmsg);
+
+ dialog = gnome_ok_dialog (errmsg);
+
+ gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
+
+ g_free (errmsg);
+ valid = FALSE;
+ }
+
+ regfree (&regexpat);
+ }
+
+ return valid;
}
static void