aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-11-01 05:49:52 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-11-01 05:49:52 +0800
commit70ae377bb6e3897ae635b6ef3ad91c2e9fba817a (patch)
tree9f11936357723c4ac1db66667dfc52eea7bcdb42
parentf8fc698cde917a9fd8b0ec37279ce52cb9a09d3e (diff)
downloadgsoc2013-evolution-70ae377bb6e3897ae635b6ef3ad91c2e9fba817a.tar
gsoc2013-evolution-70ae377bb6e3897ae635b6ef3ad91c2e9fba817a.tar.gz
gsoc2013-evolution-70ae377bb6e3897ae635b6ef3ad91c2e9fba817a.tar.bz2
gsoc2013-evolution-70ae377bb6e3897ae635b6ef3ad91c2e9fba817a.tar.lz
gsoc2013-evolution-70ae377bb6e3897ae635b6ef3ad91c2e9fba817a.tar.xz
gsoc2013-evolution-70ae377bb6e3897ae635b6ef3ad91c2e9fba817a.tar.zst
gsoc2013-evolution-70ae377bb6e3897ae635b6ef3ad91c2e9fba817a.zip
Override the default validate function to only return TRUE if a folder has
2000-10-31 Jeffrey Stedfast <fejj@helixcode.com> * filter-folder.c (validate): Override the default validate function to only return TRUE if a folder has been selected. * filter-editor.c (rule_add): Validate that all the rule parts and action parts are correctly filled in. (rule_edit): Same. svn path=/trunk/; revision=6300
-rw-r--r--filter/ChangeLog9
-rw-r--r--filter/filter-editor.c122
-rw-r--r--filter/filter-folder.c144
3 files changed, 183 insertions, 92 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog
index d0c8f3043d..f4bb2470bc 100644
--- a/filter/ChangeLog
+++ b/filter/ChangeLog
@@ -1,5 +1,14 @@
2000-10-31 Jeffrey Stedfast <fejj@helixcode.com>
+ * filter-folder.c (validate): Override the default validate
+ function to only return TRUE if a folder has been selected.
+
+ * filter-editor.c (rule_add): Validate that all the rule parts and
+ action parts are correctly filled in.
+ (rule_edit): Same.
+
+2000-10-31 Jeffrey Stedfast <fejj@helixcode.com>
+
* filtertypes.xml: Updated to add an action to set message flags.
* filter-driver.c (do_flag): New callback to set message info
diff --git a/filter/filter-editor.c b/filter/filter-editor.c
index 83af757657..96e1b22b09 100644
--- a/filter/filter-editor.c
+++ b/filter/filter-editor.c
@@ -144,6 +144,7 @@ rule_add (GtkWidget *widget, struct _editor_data *data)
GtkWidget *gd;
GtkWidget *w;
FilterPart *part;
+ gboolean done = FALSE;
d(printf ("add rule\n"));
/* create a new rule with 1 match and 1 action */
@@ -165,30 +166,54 @@ rule_add (GtkWidget *widget, struct _editor_data *data)
gtk_widget_show (gd);
- result = gnome_dialog_run_and_close (GNOME_DIALOG (gd));
-
- if (result == 0) {
- GtkListItem *item;
- GList *l = NULL;
- gchar *s = e_utf8_to_gtk_string (GTK_WIDGET (data->list), ((FilterRule *)rule)->name);
-
- item = (GtkListItem *) gtk_list_item_new_with_label (s);
- g_free (s);
-
- gtk_object_set_data (GTK_OBJECT (item), "rule", rule);
- gtk_widget_show (GTK_WIDGET (item));
-
- l = g_list_append (l, item);
-
- gtk_list_append_items (data->list, l);
- gtk_list_select_child (data->list, GTK_WIDGET (item));
-
- data->current = (FilterRule *)rule;
- rule_context_add_rule (data->f, (FilterRule *)rule);
-
- set_sensitive (data);
- } else {
- gtk_object_unref (GTK_OBJECT (rule));
+ while (!done) {
+ result = gnome_dialog_run (GNOME_DIALOG (gd));
+
+ if (result == 0) {
+ GtkWidget *item;
+ GList *parts, *l = NULL;
+ gchar *s;
+
+ done = TRUE;
+
+ /* validate rule parts */
+ parts = ((FilterRule *)rule)->parts;
+ while (parts && done) {
+ done = filter_part_validate ((FilterPart *) parts->data);
+ parts = parts->next;
+ }
+
+ /* validate action parts */
+ parts = rule->actions;
+ while (parts && done) {
+ done = filter_part_validate ((FilterPart *) parts->data);
+ parts = parts->next;
+ }
+
+ if (done) {
+ s = e_utf8_to_gtk_string (GTK_WIDGET (data->list), ((FilterRule *)rule)->name);
+ item = gtk_list_item_new_with_label (s);
+ g_free (s);
+
+ gtk_object_set_data (GTK_OBJECT (item), "rule", rule);
+ gtk_widget_show (item);
+
+ l = g_list_append (l, GTK_LIST_ITEM (item));
+
+ gtk_list_append_items (data->list, l);
+ gtk_list_select_child (data->list, item);
+
+ data->current = (FilterRule *)rule;
+ rule_context_add_rule (data->f, (FilterRule *)rule);
+
+ set_sensitive (data);
+ gtk_widget_destroy (gd);
+ }
+ } else {
+ gtk_widget_destroy (gd);
+ gtk_object_unref (GTK_OBJECT (rule));
+ done = TRUE;
+ }
}
}
@@ -199,6 +224,7 @@ rule_edit (GtkWidget *widget, struct _editor_data *data)
int result;
GtkWidget *gd;
FilterRule *rule;
+ gboolean done = FALSE;
int pos;
d(printf ("edit rule\n"));
@@ -213,17 +239,43 @@ rule_edit (GtkWidget *widget, struct _editor_data *data)
gtk_widget_show (gd);
- result = gnome_dialog_run_and_close (GNOME_DIALOG (gd));
-
- if (result == 0) {
- pos = rule_context_get_rank_rule (data->f, data->current, data->current_source);
- if (pos != -1) {
- GtkListItem *item = g_list_nth_data (data->list->children, pos);
- gchar *s = e_utf8_to_gtk_string (GTK_WIDGET (item), data->current->name);
- gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), s);
- g_free (s);
+ while (!done) {
+ result = gnome_dialog_run (GNOME_DIALOG (gd));
+
+ if (result == 0) {
+ GList *parts;
+
+ done = TRUE;
+
+ /* validate rule parts */
+ parts = rule->parts;
+ while (parts && done) {
+ done = filter_part_validate ((FilterPart *) parts->data);
+ parts = parts->next;
+ }
+
+ /* validate action parts */
+ parts = ((FilterFilter *)rule)->actions;
+ while (parts && done) {
+ done = filter_part_validate ((FilterPart *) parts->data);
+ parts = parts->next;
+ }
+
+ if (done) {
+ pos = rule_context_get_rank_rule (data->f, data->current, data->current_source);
+ if (pos != -1) {
+ GtkListItem *item = g_list_nth_data (data->list->children, pos);
+ gchar *s = e_utf8_to_gtk_string (GTK_WIDGET (item), data->current->name);
+ gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), s);
+ g_free (s);
+ }
+ gtk_widget_destroy (gd);
+ }
+ } else {
+ gtk_widget_destroy (gd);
+ done = TRUE;
}
- }
+ }
}
static void
@@ -233,7 +285,7 @@ rule_delete (GtkWidget *widget, struct _editor_data *data)
GList *l;
GtkListItem *item;
- d(printf("ddelete rule\n"));
+ d(printf("delete rule\n"));
pos = rule_context_get_rank_rule(data->f, data->current, data->current_source);
if (pos != -1) {
rule_context_remove_rule (data->f, data->current);
diff --git a/filter/filter-folder.c b/filter/filter-folder.c
index 209bb2e295..0fc02a34a1 100644
--- a/filter/filter-folder.c
+++ b/filter/filter-folder.c
@@ -33,6 +33,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);
@@ -71,7 +72,7 @@ filter_folder_get_type (void)
(GtkArgGetFunc)NULL
};
- type = gtk_type_unique(filter_element_get_type (), &type_info);
+ type = gtk_type_unique (filter_element_get_type (), &type_info);
}
return type;
@@ -84,11 +85,12 @@ filter_folder_class_init (FilterFolderClass *class)
FilterElementClass *filter_element = (FilterElementClass *)class;
object_class = (GtkObjectClass *)class;
- parent_class = gtk_type_class(filter_element_get_type ());
+ parent_class = gtk_type_class (filter_element_get_type ());
object_class->finalize = filter_folder_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;
@@ -100,17 +102,17 @@ filter_folder_class_init (FilterFolderClass *class)
static void
filter_folder_init (FilterFolder *o)
{
- o->priv = g_malloc0(sizeof(*o->priv));
+ o->priv = g_malloc0 (sizeof (*o->priv));
}
static void
-filter_folder_finalise(GtkObject *obj)
+filter_folder_finalise (GtkObject *obj)
{
FilterFolder *o = (FilterFolder *)obj;
-
- g_free(o->uri);
- g_free(o->name);
-
+
+ g_free (o->uri);
+ g_free (o->name);
+
((GtkObjectClass *)(parent_class))->finalize(obj);
}
@@ -122,66 +124,90 @@ filter_folder_finalise(GtkObject *obj)
* Return value: A new #FilterFolder object.
**/
FilterFolder *
-filter_folder_new(void)
+filter_folder_new (void)
{
- FilterFolder *o = (FilterFolder *)gtk_type_new(filter_folder_get_type ());
+ FilterFolder *o = (FilterFolder *)gtk_type_new (filter_folder_get_type ());
return o;
}
-static void xml_create(FilterElement *fe, xmlNodePtr node)
+static gboolean
+validate (FilterElement *fe, gpointer data)
+{
+ FilterFolder *ff = (FilterFolder *) fe;
+
+ if (ff->uri && *ff->uri) {
+ return TRUE;
+ } else {
+ GtkWidget *dialog;
+
+ dialog = gnome_ok_dialog (_("Oops, you forgot to choose a folder.\n"
+ "Please go back and specify a valid folder to deliver mail to."));
+
+ gnome_dialog_run_and_close (GNOME_DIALOG (dialog));
+
+ return FALSE;
+ }
+}
+
+static void
+xml_create (FilterElement *fe, xmlNodePtr node)
{
/* parent implementation */
((FilterElementClass *)(parent_class))->xml_create(fe, node);
}
-static xmlNodePtr xml_encode(FilterElement *fe)
+static xmlNodePtr
+xml_encode (FilterElement *fe)
{
xmlNodePtr value, work;
FilterFolder *ff = (FilterFolder *)fe;
-
- d(printf("Encoding folder as xml\n"));
-
- value = xmlNewNode(NULL, "value");
- xmlSetProp(value, "name", fe->name);
- xmlSetProp(value, "type", "folder");
-
- work = xmlNewChild(value, NULL, "folder", NULL);
- xmlSetProp(work, "name", ff->name);
- xmlSetProp(work, "uri", ff->uri);
-
+
+ d(printf ("Encoding folder as xml\n"));
+
+ value = xmlNewNode (NULL, "value");
+ xmlSetProp (value, "name", fe->name);
+ xmlSetProp (value, "type", "folder");
+
+ work = xmlNewChild (value, NULL, "folder", NULL);
+ xmlSetProp (work, "name", ff->name);
+ xmlSetProp (work, "uri", ff->uri);
+
return value;
}
-static int xml_decode(FilterElement *fe, xmlNodePtr node)
+static int
+xml_decode (FilterElement *fe, xmlNodePtr node)
{
FilterFolder *ff = (FilterFolder *)fe;
xmlNodePtr n;
-
- d(printf("Decoding folder from xml %p\n", fe));
-
- fe->name = xmlGetProp(node, "name");
-
+
+ d(printf ("Decoding folder from xml %p\n", fe));
+
+ fe->name = xmlGetProp (node, "name");
+
n = node->childs;
while (n) {
- if (!strcmp(n->name, "folder")) {
- ff->name = xmlGetProp(n, "name");
- ff->uri = xmlGetProp(n, "uri");
+ if (!strcmp (n->name, "folder")) {
+ ff->name = xmlGetProp (n, "name");
+ ff->uri = xmlGetProp (n, "uri");
break;
}
n = n->next;
}
+
return 0;
}
-static void button_clicked(GtkButton *button, FilterFolder *ff)
+static void
+button_clicked (GtkButton *button, FilterFolder *ff)
{
#ifdef SHELL
const char *allowed_types[] = { "mail", NULL };
char *def, *physical_uri, *evolution_uri;
gchar *s;
-
+
def = ff->uri ? ff->uri : "";
-
+
evolution_shell_client_user_select_folder (global_shell_client,
_("Select Folder"),
def, allowed_types,
@@ -189,13 +215,13 @@ static void button_clicked(GtkButton *button, FilterFolder *ff)
&physical_uri);
if (physical_uri != NULL && physical_uri[0] != '\0') {
- g_free(ff->uri);
+ g_free (ff->uri);
ff->uri = physical_uri;
-
- g_free(ff->name);
+
+ g_free (ff->name);
ff->name = g_strdup (g_basename (evolution_uri));
- s = e_utf8_to_gtk_string((GtkWidget *) button, ff->name);
- gtk_label_set_text((GtkLabel *)GTK_BIN(button)->child, s);
+ s = e_utf8_to_gtk_string (GTK_WIDGET (button), ff->name);
+ gtk_label_set_text (GTK_LABEL (GTK_BIN (button)->child), s);
g_free (s);
} else {
g_free (physical_uri);
@@ -242,33 +268,37 @@ static void button_clicked(GtkButton *button, FilterFolder *ff)
#endif
}
-static GtkWidget *get_widget(FilterElement *fe)
+static GtkWidget *
+get_widget (FilterElement *fe)
{
FilterFolder *ff = (FilterFolder *)fe;
- GtkButton *button;
- GtkLabel *label;
-
+ GtkWidget *button;
+ GtkWidget *label;
+
if (ff->name && ff->name[0])
- label = (GtkLabel *)gtk_label_new(g_basename (ff->name));
+ label = gtk_label_new (g_basename (ff->name));
else
- label = (GtkLabel *)gtk_label_new(_("<click here to select a folder>"));
-
- button = (GtkButton *)gtk_button_new();
- gtk_container_add((GtkContainer *)button, (GtkWidget *)label);
- gtk_widget_show((GtkWidget *)button);
- gtk_widget_show((GtkWidget *)label);
- gtk_signal_connect((GtkObject *)button, "clicked", button_clicked, ff);
- return (GtkWidget *)button;
+ label = gtk_label_new (_("<click here to select a folder>"));
+
+ button = gtk_button_new ();
+ gtk_container_add (GTK_CONTAINER (button), label);
+ gtk_widget_show (button);
+ gtk_widget_show (label);
+ gtk_signal_connect (GTK_OBJECT (button), "clicked", button_clicked, ff);
+
+ return button;
}
-static void build_code(FilterElement *fe, GString *out, struct _FilterPart *ff)
+static void
+build_code (FilterElement *fe, GString *out, struct _FilterPart *ff)
{
return;
}
-static void format_sexp(FilterElement *fe, GString *out)
+static void
+format_sexp (FilterElement *fe, GString *out)
{
FilterFolder *ff = (FilterFolder *)fe;
-
- e_sexp_encode_string(out, ff->uri);
+
+ e_sexp_encode_string (out, ff->uri);
}