diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2000-11-01 05:49:52 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2000-11-01 05:49:52 +0800 |
commit | 70ae377bb6e3897ae635b6ef3ad91c2e9fba817a (patch) | |
tree | 9f11936357723c4ac1db66667dfc52eea7bcdb42 /filter/filter-folder.c | |
parent | f8fc698cde917a9fd8b0ec37279ce52cb9a09d3e (diff) | |
download | gsoc2013-evolution-70ae377bb6e3897ae635b6ef3ad91c2e9fba817a.tar.gz 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
Diffstat (limited to 'filter/filter-folder.c')
-rw-r--r-- | filter/filter-folder.c | 144 |
1 files changed, 87 insertions, 57 deletions
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); } |