aboutsummaryrefslogtreecommitdiffstats
path: root/filter
diff options
context:
space:
mode:
authorJonathon Jongsma <jonathon@quotidian.org>2009-11-25 06:34:24 +0800
committerJonathon Jongsma <jonathon@quotidian.org>2009-12-01 03:31:19 +0800
commit193625ae674a7dfd8a80c0ffeab390e6fcb65856 (patch)
tree625e56c715b4c8115cda20bbfdb7dfdcb18ffcd7 /filter
parentae8f6d681c0512089f9259de0fd1b270396991d5 (diff)
downloadgsoc2013-evolution-193625ae674a7dfd8a80c0ffeab390e6fcb65856.tar.gz
gsoc2013-evolution-193625ae674a7dfd8a80c0ffeab390e6fcb65856.tar.zst
gsoc2013-evolution-193625ae674a7dfd8a80c0ffeab390e6fcb65856.zip
port filter/ classes over to new EError API
https://bugzilla.gnome.org/show_bug.cgi?id=602963
Diffstat (limited to 'filter')
-rw-r--r--filter/e-filter-datespec.c7
-rw-r--r--filter/e-filter-element.c12
-rw-r--r--filter/e-filter-element.h5
-rw-r--r--filter/e-filter-file.c13
-rw-r--r--filter/e-filter-input.c29
-rw-r--r--filter/e-filter-part.c4
-rw-r--r--filter/e-filter-part.h2
-rw-r--r--filter/e-filter-rule.c17
-rw-r--r--filter/e-filter-rule.h4
-rw-r--r--filter/e-rule-context.c11
-rw-r--r--filter/e-rule-editor.c20
11 files changed, 73 insertions, 51 deletions
diff --git a/filter/e-filter-datespec.c b/filter/e-filter-datespec.c
index f395bf91d4..f85de14953 100644
--- a/filter/e-filter-datespec.c
+++ b/filter/e-filter-datespec.c
@@ -299,14 +299,17 @@ button_clicked (GtkButton *button, EFilterDatespec *fds)
static gboolean
filter_datespec_validate (EFilterElement *element,
- GtkWindow *error_parent)
+ EError **error)
{
EFilterDatespec *fds = E_FILTER_DATESPEC (element);
gboolean valid;
+ g_warn_if_fail (error == NULL || *error == NULL);
+
valid = fds->type != FDST_UNKNOWN;
if (!valid) {
- e_error_run (error_parent, "filter:no-date", NULL);
+ if (error)
+ *error = e_error_new ("filter:no-date", NULL);
}
return valid;
diff --git a/filter/e-filter-element.c b/filter/e-filter-element.c
index 707692ec3f..2165ea22c9 100644
--- a/filter/e-filter-element.c
+++ b/filter/e-filter-element.c
@@ -42,7 +42,7 @@ static gpointer parent_class;
static gboolean
filter_element_validate (EFilterElement *element,
- GtkWindow *error_parent)
+ EError **error)
{
return TRUE;
}
@@ -249,22 +249,16 @@ e_filter_element_new (void)
gboolean
e_filter_element_validate (EFilterElement *element,
- GtkWindow *error_parent)
+ EError **error)
{
EFilterElementClass *class;
g_return_val_if_fail (E_IS_FILTER_ELEMENT (element), FALSE);
- /* Warn but proceed if no parent window was given. */
- if (error_parent != NULL)
- g_return_val_if_fail (GTK_IS_WINDOW (error_parent), FALSE);
- else
- g_warning ("%s() called with no parent window", G_STRFUNC);
-
class = E_FILTER_ELEMENT_GET_CLASS (element);
g_return_val_if_fail (class->validate != NULL, FALSE);
- return class->validate (element, error_parent);
+ return class->validate (element, error);
}
gint
diff --git a/filter/e-filter-element.h b/filter/e-filter-element.h
index 589d3a48ca..e7abc77d6f 100644
--- a/filter/e-filter-element.h
+++ b/filter/e-filter-element.h
@@ -27,6 +27,7 @@
#include <gtk/gtk.h>
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
+#include <e-util/e-error.h>
#define E_TYPE_FILTER_ELEMENT \
(e_filter_element_get_type ())
@@ -68,7 +69,7 @@ struct _EFilterElementClass {
GObjectClass parent_class;
gboolean (*validate) (EFilterElement *element,
- GtkWindow *error_parent);
+ EError **error);
gint (*eq) (EFilterElement *element_a,
EFilterElement *element_b);
@@ -95,7 +96,7 @@ EFilterElement *e_filter_element_new (void);
void e_filter_element_set_data (EFilterElement *element,
gpointer data);
gboolean e_filter_element_validate (EFilterElement *element,
- GtkWindow *error_parent);
+ EError **error);
gint e_filter_element_eq (EFilterElement *element_a,
EFilterElement *element_b);
void e_filter_element_xml_create (EFilterElement *element,
diff --git a/filter/e-filter-file.c b/filter/e-filter-file.c
index 6364475a2e..b518f91f1b 100644
--- a/filter/e-filter-file.c
+++ b/filter/e-filter-file.c
@@ -65,12 +65,15 @@ filter_file_finalize (GObject *object)
static gboolean
filter_file_validate (EFilterElement *element,
- GtkWindow *error_parent)
+ EError **error)
{
EFilterFile *file = E_FILTER_FILE (element);
+ g_warn_if_fail (error == NULL || *error == NULL);
+
if (!file->path) {
- e_error_run (error_parent, "filter:no-file", NULL);
+ if (error)
+ *error = e_error_new ("filter:no-file", NULL);
return FALSE;
}
@@ -78,9 +81,9 @@ filter_file_validate (EFilterElement *element,
if (g_strcmp0 (file->type, "file") == 0) {
if (!g_file_test (file->path, G_FILE_TEST_IS_REGULAR)) {
- e_error_run (
- error_parent, "filter:bad-file",
- file->path, NULL);
+ if (error)
+ *error = e_error_new ( "filter:bad-file",
+ file->path, NULL);
return FALSE;
}
} else if (g_strcmp0 (file->type, "command") == 0) {
diff --git a/filter/e-filter-input.c b/filter/e-filter-input.c
index a8d6123905..9166d9272f 100644
--- a/filter/e-filter-input.c
+++ b/filter/e-filter-input.c
@@ -70,11 +70,13 @@ filter_input_finalize (GObject *object)
static gboolean
filter_input_validate (EFilterElement *element,
- GtkWindow *error_parent)
+ EError **error)
{
EFilterInput *input = E_FILTER_INPUT (element);
gboolean valid = TRUE;
+ g_warn_if_fail (error == NULL || *error == NULL);
+
if (input->values && !strcmp (input->type, "regex")) {
const gchar *pattern;
regex_t regexpat;
@@ -83,17 +85,20 @@ filter_input_validate (EFilterElement *element,
pattern = input->values->data;
if ((regerr = regcomp (&regexpat, pattern, REG_EXTENDED | REG_NEWLINE | REG_ICASE))) {
- gsize reglen;
- gchar *regmsg;
-
- /* 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);
-
- e_error_run (error_parent, "filter:bad-regexp", pattern, regmsg, NULL);
- g_free (regmsg);
+ if (error) {
+ gsize reglen;
+ gchar *regmsg;
+
+ /* 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);
+
+ *error = e_error_new ("filter:bad-regexp",
+ pattern, regmsg, NULL);
+ g_free (regmsg);
+ }
valid = FALSE;
}
diff --git a/filter/e-filter-part.c b/filter/e-filter-part.c
index 50d6d13ded..3128f58d31 100644
--- a/filter/e-filter-part.c
+++ b/filter/e-filter-part.c
@@ -105,7 +105,7 @@ e_filter_part_new (void)
gboolean
e_filter_part_validate (EFilterPart *part,
- GtkWindow *error_parent)
+ EError **error)
{
GList *link;
@@ -115,7 +115,7 @@ e_filter_part_validate (EFilterPart *part,
for (link = part->elements; link != NULL; link = g_list_next (link)) {
EFilterElement *element = link->data;
- if (!e_filter_element_validate (element, error_parent))
+ if (!e_filter_element_validate (element, error))
return FALSE;
}
diff --git a/filter/e-filter-part.h b/filter/e-filter-part.h
index 697cf8f787..fe1f3cc8cf 100644
--- a/filter/e-filter-part.h
+++ b/filter/e-filter-part.h
@@ -71,7 +71,7 @@ struct _EFilterPartClass {
GType e_filter_part_get_type (void);
EFilterPart * e_filter_part_new (void);
gboolean e_filter_part_validate (EFilterPart *part,
- GtkWindow *error_parent);
+ EError **error);
gint e_filter_part_eq (EFilterPart *part_a,
EFilterPart *part_b);
gint e_filter_part_xml_create (EFilterPart *part,
diff --git a/filter/e-filter-rule.c b/filter/e-filter-rule.c
index f60230dc31..fb496a5b87 100644
--- a/filter/e-filter-rule.c
+++ b/filter/e-filter-rule.c
@@ -239,11 +239,14 @@ more_parts (GtkWidget *button,
if (data->rule->parts) {
EFilterPart *part;
GList *l;
+ EError *error = NULL;
l = g_list_last (data->rule->parts);
part = l->data;
- if (!e_filter_part_validate (part, GTK_WINDOW (gtk_widget_get_toplevel (button))))
+ if (!e_filter_part_validate (part, &error)) {
+ e_error_run_dialog (GTK_WINDOW (gtk_widget_get_toplevel (button)), error);
return;
+ }
}
/* create a new rule entry, use the first type of rule */
@@ -353,13 +356,15 @@ filter_rule_finalize (GObject *object)
static gint
filter_rule_validate (EFilterRule *rule,
- GtkWindow *error_parent)
+ EError **error)
{
gint valid = TRUE;
GList *parts;
+ g_warn_if_fail (error == NULL || *error == NULL);
if (!rule->name || !*rule->name) {
- e_error_run (error_parent, "filter:no-name", NULL);
+ if (error)
+ *error = e_error_new ("filter:no-name", NULL);
return FALSE;
}
@@ -368,7 +373,7 @@ filter_rule_validate (EFilterRule *rule,
parts = rule->parts;
valid = parts != NULL;
while (parts && valid) {
- valid = e_filter_part_validate ((EFilterPart *) parts->data, error_parent);
+ valid = e_filter_part_validate ((EFilterPart *) parts->data, error);
parts = parts->next;
}
@@ -907,7 +912,7 @@ e_filter_rule_set_source (EFilterRule *rule,
gint
e_filter_rule_validate (EFilterRule *rule,
- GtkWindow *error_parent)
+ EError **error)
{
EFilterRuleClass *class;
@@ -916,7 +921,7 @@ e_filter_rule_validate (EFilterRule *rule,
class = E_FILTER_RULE_GET_CLASS (rule);
g_return_val_if_fail (class->validate != NULL, FALSE);
- return class->validate (rule, error_parent);
+ return class->validate (rule, error);
}
gint
diff --git a/filter/e-filter-rule.h b/filter/e-filter-rule.h
index c84cdefb0e..5f0c9a519f 100644
--- a/filter/e-filter-rule.h
+++ b/filter/e-filter-rule.h
@@ -96,7 +96,7 @@ struct _EFilterRuleClass {
/* virtual methods */
gint (*validate) (EFilterRule *rule,
- GtkWindow *error_parent);
+ EError **error);
gint (*eq) (EFilterRule *rule_a,
EFilterRule *rule_b);
@@ -126,7 +126,7 @@ void e_filter_rule_set_name (EFilterRule *rule,
void e_filter_rule_set_source (EFilterRule *rule,
const gchar *source);
gint e_filter_rule_validate (EFilterRule *rule,
- GtkWindow *error_parent);
+ EError **error);
gint e_filter_rule_eq (EFilterRule *rule_a,
EFilterRule *rule_b);
xmlNodePtr e_filter_rule_xml_encode (EFilterRule *rule);
diff --git a/filter/e-rule-context.c b/filter/e-rule-context.c
index 536685840c..67a1df2293 100644
--- a/filter/e-rule-context.c
+++ b/filter/e-rule-context.c
@@ -92,14 +92,17 @@ new_rule_response (GtkWidget *dialog,
if (button == GTK_RESPONSE_OK) {
EFilterRule *rule = g_object_get_data ((GObject *) dialog, "rule");
gchar *user = g_object_get_data ((GObject *) dialog, "path");
+ EError *error = NULL;
- if (!e_filter_rule_validate (rule, GTK_WINDOW (dialog))) {
- /* no need to popup a dialog because the validate code does that. */
- return;
+ if (!e_filter_rule_validate (rule, &error)) {
+ e_error_run_dialog (GTK_WINDOW (dialog), error);
+ e_error_free (error);
}
if (e_rule_context_find_rule (context, rule->name, rule->source)) {
- e_error_run ((GtkWindow *)dialog, "filter:bad-name-notunique", rule->name, NULL);
+ e_error_run_dialog_for_args ((GtkWindow *)dialog,
+ "filter:bad-name-notunique",
+ rule->name, NULL);
return;
}
diff --git a/filter/e-rule-editor.c b/filter/e-rule-editor.c
index fe4c1e1d52..a919fad7d0 100644
--- a/filter/e-rule-editor.c
+++ b/filter/e-rule-editor.c
@@ -143,13 +143,17 @@ add_editor_response (GtkWidget *dialog, gint button, ERuleEditor *editor)
GtkTreeIter iter;
if (button == GTK_RESPONSE_OK) {
- if (!e_filter_rule_validate (editor->edit, GTK_WINDOW (dialog))) {
- /* no need to popup a dialog because the validate code does that. */
+ EError *error = NULL;
+ if (!e_filter_rule_validate (editor->edit, &error)) {
+ e_error_run_dialog (GTK_WINDOW (dialog), error);
+ e_error_free (error);
return;
}
if (e_rule_context_find_rule (editor->context, editor->edit->name, editor->edit->source)) {
- e_error_run ((GtkWindow *)dialog, "filter:bad-name-notunique", editor->edit->name, NULL);
+ e_error_run_dialog_for_args ((GtkWindow *)dialog,
+ "filter:bad-name-notunique",
+ editor->edit->name, NULL);
return;
}
@@ -287,14 +291,18 @@ edit_editor_response (GtkWidget *dialog, gint button, ERuleEditor *editor)
gint pos;
if (button == GTK_RESPONSE_OK) {
- if (!e_filter_rule_validate (editor->edit, GTK_WINDOW (dialog))) {
- /* no need to popup a dialog because the validate code does that. */
+ EError *error = NULL;
+ if (!e_filter_rule_validate (editor->edit, &error)) {
+ e_error_run_dialog (GTK_WINDOW (dialog), error);
+ e_error_free (error);
return;
}
rule = e_rule_context_find_rule (editor->context, editor->edit->name, editor->edit->source);
if (rule != NULL && rule != editor->current) {
- e_error_run ((GtkWindow *)dialog, "filter:bad-name-notunique", rule->name, NULL);
+ e_error_run_dialog_for_args ((GtkWindow *)dialog,
+ "filter:bad-name-notunique",
+ rule->name, NULL);
return;
}