diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2007-11-15 06:04:21 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2007-11-15 06:04:21 +0800 |
commit | 9e4fcb29cf7f05c18f7fd34e318f9e795fa32e91 (patch) | |
tree | 2e1e96f33404781354c422a7e9beaf458ebeb655 /filter | |
parent | 7e8f8bb9e5167b0219b48ab3e8062080d3740b0a (diff) | |
download | gsoc2013-evolution-9e4fcb29cf7f05c18f7fd34e318f9e795fa32e91.tar.gz gsoc2013-evolution-9e4fcb29cf7f05c18f7fd34e318f9e795fa32e91.tar.zst gsoc2013-evolution-9e4fcb29cf7f05c18f7fd34e318f9e795fa32e91.zip |
** Remove trailing whitespace from source code.
2007-11-14 Matthew Barnes <mbarnes@redhat.com>
** Remove trailing whitespace from source code.
svn path=/trunk/; revision=34537
Diffstat (limited to 'filter')
-rw-r--r-- | filter/filter-code.c | 14 | ||||
-rw-r--r-- | filter/filter-code.h | 4 | ||||
-rw-r--r-- | filter/filter-colour.c | 16 | ||||
-rw-r--r-- | filter/filter-colour.h | 6 | ||||
-rw-r--r-- | filter/filter-datespec.c | 102 | ||||
-rw-r--r-- | filter/filter-datespec.h | 6 | ||||
-rw-r--r-- | filter/filter-element.c | 52 | ||||
-rw-r--r-- | filter/filter-element.h | 10 | ||||
-rw-r--r-- | filter/filter-file.c | 66 | ||||
-rw-r--r-- | filter/filter-file.h | 6 | ||||
-rw-r--r-- | filter/filter-input.c | 90 | ||||
-rw-r--r-- | filter/filter-input.h | 6 | ||||
-rw-r--r-- | filter/filter-int.c | 54 | ||||
-rw-r--r-- | filter/filter-int.h | 6 | ||||
-rw-r--r-- | filter/filter-label.c | 34 | ||||
-rw-r--r-- | filter/filter-label.h | 6 | ||||
-rw-r--r-- | filter/filter-option.c | 78 | ||||
-rw-r--r-- | filter/filter-option.h | 8 | ||||
-rw-r--r-- | filter/filter-part.c | 152 | ||||
-rw-r--r-- | filter/filter-part.h | 6 | ||||
-rw-r--r-- | filter/filter-rule.c | 230 | ||||
-rw-r--r-- | filter/filter-rule.h | 16 | ||||
-rw-r--r-- | filter/rule-context.c | 252 | ||||
-rw-r--r-- | filter/rule-context.h | 8 | ||||
-rw-r--r-- | filter/rule-editor.c | 198 | ||||
-rw-r--r-- | filter/rule-editor.h | 20 |
26 files changed, 723 insertions, 723 deletions
diff --git a/filter/filter-code.c b/filter/filter-code.c index 38c14010ec..9dc1927846 100644 --- a/filter/filter-code.c +++ b/filter/filter-code.c @@ -42,7 +42,7 @@ GType filter_code_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterCodeClass), @@ -55,10 +55,10 @@ filter_code_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_code_init, }; - + type = g_type_register_static (FILTER_TYPE_INPUT, "FilterCode", &info, 0); } - + return type; } @@ -67,11 +67,11 @@ filter_code_class_init (FilterCodeClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - + parent_class = g_type_class_ref (FILTER_TYPE_INPUT); - + object_class->finalize = filter_code_finalise; - + /* override methods */ fe_class->build_code = build_code; fe_class->format_sexp = format_sexp; @@ -94,7 +94,7 @@ filter_code_finalise (GObject *obj) * filter_code_new: * * Create a new FilterCode object. - * + * * Return value: A new #FilterCode object. **/ FilterCode * diff --git a/filter/filter-code.h b/filter/filter-code.h index bbf3954ac6..386ea72196 100644 --- a/filter/filter-code.h +++ b/filter/filter-code.h @@ -42,9 +42,9 @@ struct _FilterCode { struct _FilterCodeClass { FilterInputClass parent_class; - + /* virtual methods */ - + /* signals */ }; diff --git a/filter/filter-colour.c b/filter/filter-colour.c index 250d9f6594..1d3a670b1f 100644 --- a/filter/filter-colour.c +++ b/filter/filter-colour.c @@ -52,7 +52,7 @@ GType filter_colour_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterColourClass), @@ -65,10 +65,10 @@ filter_colour_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_colour_init, }; - + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterColour", &info, 0); } - + return type; } @@ -77,11 +77,11 @@ filter_colour_class_init (FilterColourClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); - + object_class->finalize = filter_colour_finalise; - + /* override methods */ fe_class->eq = colour_eq; fe_class->xml_create = xml_create; @@ -108,7 +108,7 @@ filter_colour_finalise (GObject *obj) * filter_colour_new: * * Create a new FilterColour object. - * + * * Return value: A new #FilterColour object. **/ FilterColour * @@ -199,7 +199,7 @@ get_widget (FilterElement *fe) g_signal_connect ( G_OBJECT (color_button), "color_set", G_CALLBACK (set_color), fe); - + return color_button; } diff --git a/filter/filter-colour.h b/filter/filter-colour.h index 70fb2952ec..8ebb7f0ec3 100644 --- a/filter/filter-colour.h +++ b/filter/filter-colour.h @@ -38,15 +38,15 @@ typedef struct _FilterColourClass FilterColourClass; struct _FilterColour { FilterElement parent_object; - + GdkColor color; }; struct _FilterColourClass { FilterElementClass parent_class; - + /* virtual methods */ - + /* signals */ }; diff --git a/filter/filter-datespec.c b/filter/filter-datespec.c index 328b7597dd..8bf1a914b7 100644 --- a/filter/filter-datespec.c +++ b/filter/filter-datespec.c @@ -105,7 +105,7 @@ GType filter_datespec_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterDatespecClass), @@ -118,10 +118,10 @@ filter_datespec_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_datespec_init, }; - + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterDatespec", &info, 0); } - + return type; } @@ -130,11 +130,11 @@ filter_datespec_class_init (FilterDatespecClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); - + object_class->finalize = filter_datespec_finalise; - + /* override methods */ fe_class->validate = validate; fe_class->eq = date_eq; @@ -157,9 +157,9 @@ static void filter_datespec_finalise (GObject *obj) { FilterDatespec *fd = (FilterDatespec *) obj; - + g_free (fd->priv); - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -167,7 +167,7 @@ filter_datespec_finalise (GObject *obj) * filter_datespec_new: * * Create a new FilterDatespec object. - * + * * Return value: A new #FilterDatespec object. **/ FilterDatespec * @@ -181,7 +181,7 @@ validate (FilterElement *fe) { FilterDatespec *fds = (FilterDatespec *) fe; gboolean valid; - + valid = fds->type != FDST_UNKNOWN; if (!valid) { /* FIXME: FilterElement should probably have a @@ -190,7 +190,7 @@ validate (FilterElement *fe) here. */ e_error_run(NULL, "filter:no-date", NULL); } - + return valid; } @@ -198,7 +198,7 @@ static int date_eq (FilterElement *fe, FilterElement *cm) { FilterDatespec *fd = (FilterDatespec *)fe, *cd = (FilterDatespec *)cm; - + return FILTER_ELEMENT_CLASS (parent_class)->eq(fe, cm) && (fd->type == cd->type) && (fd->value == cd->value); @@ -217,19 +217,19 @@ xml_encode (FilterElement *fe) xmlNodePtr value, work; FilterDatespec *fds = (FilterDatespec *)fe; char str[32]; - + d(printf ("Encoding datespec as xml\n")); - + value = xmlNewNode (NULL, (const unsigned char *)"value"); xmlSetProp (value, (const unsigned char *)"name", (unsigned char *)fe->name); xmlSetProp (value, (const unsigned char *)"type", (const unsigned char *)"datespec"); - + work = xmlNewChild (value, NULL, (const unsigned char *)"datespec", NULL); sprintf (str, "%d", fds->type); xmlSetProp (work, (const unsigned char *)"type", (unsigned char *)str); sprintf (str, "%d", (int)fds->value); xmlSetProp (work, (const unsigned char *)"value", (unsigned char *)str); - + return value; } @@ -239,12 +239,12 @@ xml_decode (FilterElement *fe, xmlNodePtr node) FilterDatespec *fds = (FilterDatespec *)fe; xmlNodePtr n; xmlChar *val; - + d(printf ("Decoding datespec from xml %p\n", fe)); - + xmlFree (fe->name); fe->name = (char *)xmlGetProp (node, (const unsigned char *)"name"); - + n = node->children; while (n) { if (!strcmp ((char *)n->name, "datespec")) { @@ -258,7 +258,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) } n = n->next; } - + return 0; } @@ -271,7 +271,7 @@ get_best_span (time_t val) if (val % timespans[i].seconds == 0) return i; } - + return 0; } @@ -281,7 +281,7 @@ set_button (FilterDatespec *fds) { char buf[128]; char *label = buf; - + switch (fds->type) { case FDST_UNKNOWN: label = _("<click here to select a date>"); @@ -291,7 +291,7 @@ set_button (FilterDatespec *fds) break; case FDST_SPECIFIED: { struct tm tm; - + localtime_r(&fds->value, &tm); /* strftime for date filter display, only needs to show a day date (i.e. no time) */ strftime(buf, sizeof(buf), _("%d-%b-%Y"), &tm); @@ -301,7 +301,7 @@ set_button (FilterDatespec *fds) label = _("now"); else { int span, count; - + span = get_best_span(fds->value); count = fds->value / timespans[span].seconds; sprintf(buf, ngettext(timespans[span].past_singular, timespans[span].past_plural, count), count); @@ -312,14 +312,14 @@ set_button (FilterDatespec *fds) label = _("now"); else { int span, count; - + span = get_best_span(fds->value); count = fds->value / timespans[span].seconds; sprintf(buf, ngettext(timespans[span].future_singular, timespans[span].future_plural, count), count); } break; } - + gtk_label_set_text((GtkLabel *)fds->priv->label_button, label); } @@ -327,12 +327,12 @@ static void get_values (FilterDatespec *fds) { struct _FilterDatespecPrivate *p = PRIV(fds); - + switch(fds->priv->type) { case FDST_SPECIFIED: { guint year, month, day; struct tm tm; - + gtk_calendar_get_date((GtkCalendar *)p->calendar_specify, &year, &month, &day); memset(&tm, 0, sizeof(tm)); tm.tm_mday = day; @@ -344,7 +344,7 @@ get_values (FilterDatespec *fds) case FDST_X_FUTURE: case FDST_X_AGO: { int val; - + val = gtk_spin_button_get_value_as_int((GtkSpinButton *)p->spin_relative); fds->value = timespans[p->span].seconds * val; break; } @@ -352,7 +352,7 @@ get_values (FilterDatespec *fds) default: break; } - + fds->type = p->type; } @@ -362,11 +362,11 @@ set_values (FilterDatespec *fds) int note_type; struct _FilterDatespecPrivate *p = PRIV(fds); - + p->type = fds->type==FDST_UNKNOWN ? FDST_NOW : fds->type; note_type = fds->type==FDST_X_FUTURE ? FDST_X_AGO : fds->type; // FUTURE and AGO use the same notebook pages/etc. - + switch (p->type) { case FDST_NOW: case FDST_UNKNOWN: @@ -375,7 +375,7 @@ set_values (FilterDatespec *fds) case FDST_SPECIFIED: { struct tm tm; - + localtime_r(&fds->value, &tm); gtk_calendar_select_month((GtkCalendar*)p->calendar_specify, tm.tm_mon, tm.tm_year + 1900); gtk_calendar_select_day((GtkCalendar*)p->calendar_specify, tm.tm_mday); @@ -394,7 +394,7 @@ set_values (FilterDatespec *fds) gtk_option_menu_set_history((GtkOptionMenu*)p->option_past_future, 1); break; } - + gtk_notebook_set_current_page ((GtkNotebook*) p->notebook_type, note_type); gtk_option_menu_set_history ((GtkOptionMenu*) p->option_type, note_type); } @@ -415,7 +415,7 @@ static void set_option_relative (GtkMenu *menu, FilterDatespec *fds) { GtkWidget *w; - + w = gtk_menu_get_active (menu); fds->priv->span = g_list_index (GTK_MENU_SHELL (menu)->children, w); } @@ -424,7 +424,7 @@ static void set_option_past_future (GtkMenu *menu, FilterDatespec *fds) { GtkWidget *w; - + w = gtk_menu_get_active (menu); if(g_list_index (GTK_MENU_SHELL (menu)->children, w) == 0) fds->type = fds->priv->type = FDST_X_AGO; @@ -442,11 +442,11 @@ button_clicked (GtkButton *button, FilterDatespec *fds) char *filter_glade = g_build_filename (EVOLUTION_GLADEDIR, "filter.glade", NULL); - + gui = glade_xml_new (filter_glade, "filter_datespec", NULL); g_free (filter_glade); toplevel = glade_xml_get_widget (gui, "filter_datespec"); - + dialog = (GtkDialog *) gtk_dialog_new (); gtk_window_set_title ((GtkWindow *) dialog, _("Select a time to compare against")); gtk_dialog_add_buttons (dialog, @@ -454,30 +454,30 @@ button_clicked (GtkButton *button, FilterDatespec *fds) GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_has_separator (dialog, FALSE); - + p->notebook_type = glade_xml_get_widget (gui, "notebook_type"); p->option_type = glade_xml_get_widget (gui, "option_type"); p->calendar_specify = glade_xml_get_widget (gui, "calendar_specify"); p->spin_relative = glade_xml_get_widget (gui, "spin_relative"); p->option_relative = glade_xml_get_widget (gui, "option_relative"); p->option_past_future = glade_xml_get_widget (gui, "option_past_future"); - + set_values (fds); - + g_signal_connect (GTK_OPTION_MENU (p->option_type)->menu, "deactivate", G_CALLBACK (set_option_type), fds); g_signal_connect (GTK_OPTION_MENU (p->option_relative)->menu, "deactivate", G_CALLBACK (set_option_relative), fds); g_signal_connect (GTK_OPTION_MENU (p->option_past_future)->menu, "deactivate", G_CALLBACK (set_option_past_future), fds); - + gtk_box_pack_start ((GtkBox *) dialog->vbox, toplevel, TRUE, TRUE, 3); - + if (gtk_dialog_run (dialog) == GTK_RESPONSE_OK) { get_values (fds); set_button (fds); } - + gtk_widget_destroy ((GtkWidget *)dialog); } @@ -486,32 +486,32 @@ get_widget (FilterElement *fe) { FilterDatespec *fds = (FilterDatespec *)fe; GtkWidget *button; - + fds->priv->label_button = gtk_label_new (""); gtk_misc_set_alignment (GTK_MISC (fds->priv->label_button), 0.5, 0.5); set_button(fds); - + button = gtk_button_new(); gtk_container_add (GTK_CONTAINER (button), fds->priv->label_button); g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), fds); - + gtk_widget_show (button); gtk_widget_show (fds->priv->label_button); - + return button; } -static void +static void build_code (FilterElement *fe, GString *out, struct _FilterPart *fp) { return; } -static void +static void format_sexp (FilterElement *fe, GString *out) { FilterDatespec *fds = (FilterDatespec *)fe; - + switch (fds->type) { case FDST_UNKNOWN: g_warning ("user hasn't selected a datespec yet!"); diff --git a/filter/filter-datespec.h b/filter/filter-datespec.h index 97676bfb5f..a243da9994 100644 --- a/filter/filter-datespec.h +++ b/filter/filter-datespec.h @@ -48,14 +48,14 @@ typedef enum _FilterDatespec_type { struct _FilterDatespec { FilterElement parent; struct _FilterDatespecPrivate *priv; - + FilterDatespec_type type; - + /* either a timespan, an absolute time, or 0 * depending on type -- the above mapping to * (X_FUTURE, X_AGO, SPECIFIED, NOW) */ - + time_t value; }; diff --git a/filter/filter-element.c b/filter/filter-element.c index 2c075f835d..74e55ba422 100644 --- a/filter/filter-element.c +++ b/filter/filter-element.c @@ -53,7 +53,7 @@ GType filter_element_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterElementClass), @@ -68,7 +68,7 @@ filter_element_get_type (void) }; type = g_type_register_static (G_TYPE_OBJECT, "FilterElement", &info, 0); } - + return type; } @@ -76,9 +76,9 @@ static void filter_element_class_init (FilterElementClass *klass) { parent_class = g_type_class_ref (G_TYPE_OBJECT); - + ((GObjectClass *)klass)->finalize = filter_element_finalise; - + /* override methods */ klass->validate = validate; klass->eq = element_eq; @@ -97,9 +97,9 @@ static void filter_element_finalise (GObject *obj) { FilterElement *o = (FilterElement *)obj; - + xmlFree (o->name); - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -107,7 +107,7 @@ filter_element_finalise (GObject *obj) * filter_element_new: * * Create a new FilterElement object. - * + * * Return value: A new #FilterElement object. **/ FilterElement * @@ -126,7 +126,7 @@ int filter_element_eq (FilterElement *fe, FilterElement *cm) { FilterElementClass *klass; - + klass = FILTER_ELEMENT_GET_CLASS (fe); return (klass == FILTER_ELEMENT_GET_CLASS (cm)) && klass->eq (fe, cm); } @@ -135,7 +135,7 @@ filter_element_eq (FilterElement *fe, FilterElement *cm) * filter_element_xml_create: * @fe: filter element * @node: xml node - * + * * Create a new filter element based on an xml definition of * that element. **/ @@ -148,10 +148,10 @@ filter_element_xml_create (FilterElement *fe, xmlNodePtr node) /** * filter_element_xml_encode: * @fe: filter element - * + * * Encode the values of a filter element into xml format. - * - * Return value: + * + * Return value: **/ xmlNodePtr filter_element_xml_encode (FilterElement *fe) @@ -163,10 +163,10 @@ filter_element_xml_encode (FilterElement *fe) * filter_element_xml_decode: * @fe: filter element * @node: xml node - * + * * Decode the values of a fitler element from xml format. - * - * Return value: + * + * Return value: **/ int filter_element_xml_decode (FilterElement *fe, xmlNodePtr node) @@ -177,10 +177,10 @@ filter_element_xml_decode (FilterElement *fe, xmlNodePtr node) /** * filter_element_clone: * @fe: filter element - * + * * Clones the FilterElement @fe. - * - * Return value: + * + * Return value: **/ FilterElement * filter_element_clone (FilterElement *fe) @@ -192,10 +192,10 @@ filter_element_clone (FilterElement *fe) * filter_element_get_widget: * @fe: filter element * @node: xml node - * + * * Create a widget to represent this element. - * - * Return value: + * + * Return value: **/ GtkWidget * filter_element_get_widget (FilterElement *fe) @@ -207,8 +207,8 @@ filter_element_get_widget (FilterElement *fe) * filter_element_build_code: * @fe: filter element * @out: output buffer - * @ff: - * + * @ff: + * * Add the code representing this element to the output string @out. **/ void @@ -221,7 +221,7 @@ filter_element_build_code (FilterElement *fe, GString *out, struct _FilterPart * * filter_element_format_sexp: * @fe: filter element * @out: output buffer - * + * * Format the value(s) of this element in a method suitable for the context of * sexp where it is used. Usually as space separated, double-quoted strings. **/ @@ -262,12 +262,12 @@ clone (FilterElement *fe) { xmlNodePtr node; FilterElement *new; - + new = (FilterElement *) g_object_new (G_OBJECT_TYPE (fe), NULL, NULL); node = filter_element_xml_encode (fe); filter_element_xml_decode (new, node); xmlFreeNodeList (node); - + return new; } diff --git a/filter/filter-element.h b/filter/filter-element.h index 6f2409de36..4ed4377aec 100644 --- a/filter/filter-element.h +++ b/filter/filter-element.h @@ -43,7 +43,7 @@ typedef FilterElement *(*FilterElementFunc)(void *data); struct _FilterElement { GObject parent_object; - + char *name; gpointer data; }; @@ -52,22 +52,22 @@ struct _FilterPart; struct _FilterElementClass { GObjectClass parent_class; - + /* virtual methods */ gboolean (*validate) (FilterElement *fe); int (*eq) (FilterElement *fe, FilterElement *cm); - + void (*xml_create) (FilterElement *, xmlNodePtr); xmlNodePtr (*xml_encode) (FilterElement *); int (*xml_decode) (FilterElement *, xmlNodePtr); - + FilterElement *(*clone) (FilterElement *fe); void (*copy_value)(FilterElement *fe, FilterElement *se); GtkWidget *(*get_widget) (FilterElement *); void (*build_code) (FilterElement *, GString *, struct _FilterPart *ff); void (*format_sexp) (FilterElement *, GString *); - + /* signals */ }; diff --git a/filter/filter-file.c b/filter/filter-file.c index 3fc797dff5..0418a36a2d 100644 --- a/filter/filter-file.c +++ b/filter/filter-file.c @@ -62,7 +62,7 @@ GType filter_file_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterFileClass), @@ -75,10 +75,10 @@ filter_file_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_file_init, }; - + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterFile", &info, 0); } - + return type; } @@ -87,11 +87,11 @@ filter_file_class_init (FilterFileClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); - + object_class->finalize = filter_file_finalise; - + /* override methods */ fe_class->validate = validate; fe_class->eq = file_eq; @@ -113,10 +113,10 @@ static void filter_file_finalise (GObject *obj) { FilterFile *ff = (FilterFile *) obj; - + xmlFree (ff->type); g_free (ff->path); - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -124,7 +124,7 @@ filter_file_finalise (GObject *obj) * filter_file_new: * * Create a new FilterFile object. - * + * * Return value: A new #FilterFile object. **/ FilterFile * @@ -138,10 +138,10 @@ FilterFile * filter_file_new_type_name (const char *type) { FilterFile *file; - + file = filter_file_new (); file->type = (char *)xmlStrdup ((xmlChar *)type); - + return file; } @@ -156,7 +156,7 @@ static gboolean validate (FilterElement *fe) { FilterFile *file = (FilterFile *) fe; - + if (!file->path) { /* FIXME: FilterElement should probably have a GtkWidget member pointing to the value gotten with @@ -166,9 +166,9 @@ validate (FilterElement *fe) return FALSE; } - + /* FIXME: do more to validate command-lines? */ - + if (strcmp (file->type, "file") == 0) { if (!g_file_test (file->path, G_FILE_TEST_IS_REGULAR)) { /* FIXME: FilterElement should probably have a @@ -176,7 +176,7 @@ validate (FilterElement *fe) ::get_widget() so that we can get the parent window here. */ e_error_run(NULL, "filter:bad-file", file->path, NULL); - + return FALSE; } } else if (strcmp (file->type, "command") == 0) { @@ -184,7 +184,7 @@ validate (FilterElement *fe) be an empty string */ return file->path[0] != '\0'; } - + return TRUE; } @@ -192,7 +192,7 @@ static int file_eq (FilterElement *fe, FilterElement *cm) { FilterFile *ff = (FilterFile *)fe, *cf = (FilterFile *)cm; - + return FILTER_ELEMENT_CLASS (parent_class)->eq (fe, cm) && ((ff->path && cf->path && strcmp (ff->path, cf->path) == 0) || (ff->path == NULL && cf->path == NULL)) @@ -213,18 +213,18 @@ xml_encode (FilterElement *fe) FilterFile *file = (FilterFile *) fe; xmlNodePtr cur, value; char *type; - + type = file->type ? file->type : "file"; - + d(printf ("Encoding %s as xml\n", type)); - + value = xmlNewNode (NULL, (const unsigned char *)"value"); xmlSetProp (value, (const unsigned char *)"name", (unsigned char *)fe->name); xmlSetProp (value, (const unsigned char *)"type", (unsigned char *)type); - + cur = xmlNewChild (value, NULL, (unsigned char *)type, NULL); xmlNodeSetContent (cur, (unsigned char *)file->path); - + return value; } @@ -234,37 +234,37 @@ xml_decode (FilterElement *fe, xmlNodePtr node) FilterFile *file = (FilterFile *)fe; char *name, *str, *type; xmlNodePtr n; - + name = (char *)xmlGetProp (node, (const unsigned char *)"name"); type = (char *)xmlGetProp (node, (const unsigned char *)"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; - + g_free (file->path); file->path = NULL; - + n = node->children; while (n != NULL) { if (!strcmp ((char *)n->name, type)) { str = (char *)xmlNodeGetContent (n); file->path = g_strdup (str ? str : ""); xmlFree (str); - + d(printf (" '%s'\n", file->path)); break; } else if (n->type == XML_ELEMENT_NODE) { g_warning ("Unknown node type '%s' encountered decoding a %s\n", n->name, type); } - + n = n->next; } - + return 0; } @@ -273,7 +273,7 @@ filename_changed (GtkWidget *widget, FilterElement *fe) { FilterFile *file = (FilterFile *) fe; const char *new; - + new = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)); g_free (file->path); file->path = g_strdup (new); @@ -287,7 +287,7 @@ get_widget (FilterElement *fe) filewidget = (GtkWidget *) gtk_file_chooser_button_new (_("Choose a file"), GTK_FILE_CHOOSER_ACTION_OPEN); gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (filewidget), file->path); - g_signal_connect (GTK_FILE_CHOOSER_BUTTON (filewidget), "selection-changed", + g_signal_connect (GTK_FILE_CHOOSER_BUTTON (filewidget), "selection-changed", G_CALLBACK (filename_changed), fe); return filewidget; } @@ -302,6 +302,6 @@ 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 index ced47eb56f..3b82a32ae0 100644 --- a/filter/filter-file.h +++ b/filter/filter-file.h @@ -43,16 +43,16 @@ typedef struct _FilterFileClass FilterFileClass; struct _FilterFile { FilterElement parent_object; - + char *type; char *path; }; struct _FilterFileClass { FilterElementClass parent_class; - + /* virtual methods */ - + /* signals */ }; diff --git a/filter/filter-input.c b/filter/filter-input.c index 59fa507945..8dd775673a 100644 --- a/filter/filter-input.c +++ b/filter/filter-input.c @@ -59,7 +59,7 @@ GType filter_input_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterInputClass), @@ -72,10 +72,10 @@ filter_input_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_input_init, }; - + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterInput", &info, 0); } - + return type; } @@ -84,11 +84,11 @@ filter_input_class_init (FilterInputClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); - + object_class->finalize = filter_input_finalise; - + /* override methods */ fe_class->validate = validate; fe_class->eq = input_eq; @@ -110,11 +110,11 @@ static void filter_input_finalise (GObject *obj) { FilterInput *fi = (FilterInput *) obj; - + xmlFree (fi->type); g_list_foreach (fi->values, (GFunc)g_free, NULL); g_list_free (fi->values); - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -122,7 +122,7 @@ filter_input_finalise (GObject *obj) * filter_input_new: * * Create a new FilterInput object. - * + * * Return value: A new #FilterInput object. **/ FilterInput * @@ -135,12 +135,12 @@ FilterInput * filter_input_new_type_name (const char *type) { FilterInput *fi; - + fi = filter_input_new (); fi->type = (char *)xmlStrdup ((xmlChar *)type); - + d(printf("new type %s = %p\n", type, fi)); - + return fi; } @@ -148,7 +148,7 @@ void filter_input_set_value (FilterInput *fi, const char *value) { GList *l; - + d(printf("set_value '%s'\n", value)); l = fi->values; @@ -157,7 +157,7 @@ filter_input_set_value (FilterInput *fi, const char *value) l = g_list_next (l); } g_list_free (fi->values); - + fi->values = g_list_append (NULL, g_strdup (value)); } @@ -166,37 +166,37 @@ validate (FilterElement *fe) { FilterInput *fi = (FilterInput *)fe; gboolean valid = TRUE; - + if (fi->values && !strcmp (fi->type, "regex")) { const char *pattern; regex_t regexpat; int regerr; - + pattern = fi->values->data; - + if ((regerr = regcomp (®expat, pattern, REG_EXTENDED | REG_NEWLINE | REG_ICASE))) { size_t reglen; char *regmsg; - - /* regerror gets called twice to get the full error string + + /* regerror gets called twice to get the full error string length to do proper posix error reporting */ reglen = regerror (regerr, ®expat, 0, 0); regmsg = g_malloc0 (reglen + 1); regerror (regerr, ®expat, regmsg, reglen); - + /* FIXME: FilterElement should probably have a GtkWidget member pointing to the value gotten with ::get_widget() so that we can get the parent window here. */ e_error_run(NULL, "filter:bad-regexp", pattern, regmsg, NULL); g_free (regmsg); - + valid = FALSE; } - + regfree (®expat); } - + return valid; } @@ -204,13 +204,13 @@ static int list_eq (GList *al, GList *bl) { int truth = TRUE; - + while (truth && al && bl) { truth = strcmp ((char *) al->data, (char *) bl->data) == 0; al = al->next; bl = bl->next; } - + return truth && al == NULL && bl == NULL; } @@ -218,7 +218,7 @@ static int input_eq (FilterElement *fe, FilterElement *cm) { FilterInput *fi = (FilterInput *)fe, *ci = (FilterInput *)cm; - + return FILTER_ELEMENT_CLASS (parent_class)->eq (fe, cm) && strcmp (fi->type, ci->type) == 0 && list_eq (fi->values, ci->values); @@ -238,11 +238,11 @@ xml_encode (FilterElement *fe) GList *l; FilterInput *fi = (FilterInput *)fe; char *type; - + type = fi->type ? fi->type : "string"; - + d(printf ("Encoding %s as xml\n", type)); - + value = xmlNewNode (NULL, (const unsigned char *)"value"); xmlSetProp (value, (const unsigned char *)"name", (unsigned char *)fe->name); xmlSetProp (value, (const unsigned char *)"type", (unsigned char *)type); @@ -250,16 +250,16 @@ xml_encode (FilterElement *fe) while (l) { xmlNodePtr cur; xmlChar *str = l->data; - + cur = xmlNewChild (value, NULL, (unsigned char *)type, NULL); - + str = xmlEncodeEntitiesReentrant (NULL, str); xmlNodeSetContent (cur, str); xmlFree (str); - + l = l->next; } - + return value; } @@ -270,7 +270,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) char *name, *str, *type; xmlNodePtr n; GList *l; - + l = fi->values; while (l) { g_free (l->data); @@ -281,7 +281,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) name = (char *)xmlGetProp (node, (const unsigned char *)"name"); type = (char *)xmlGetProp (node, (const unsigned char *)"type"); - + d(printf("Decoding %s from xml %p\n", type, fe)); d(printf ("Name = %s\n", name)); xmlFree (fe->name); @@ -293,7 +293,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) if (!strcmp ((char *)n->name, type)) { if (!(str = (char *)xmlNodeGetContent (n))) str = (char *)xmlStrdup ((const unsigned char *)""); - + d(printf (" '%s'\n", str)); fi->values = g_list_append (fi->values, g_strdup (str)); xmlFree (str); @@ -302,7 +302,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) } n = n->next; } - + return 0; } @@ -312,9 +312,9 @@ entry_changed (GtkEntry *entry, FilterElement *fe) FilterInput *fi = (FilterInput *) fe; const char *new; GList *l; - + new = gtk_entry_get_text (entry); - + d(printf("entry_changed '%s'\n", new)); /* NOTE: entry only supports a single value ... */ @@ -323,9 +323,9 @@ entry_changed (GtkEntry *entry, FilterElement *fe) g_free (l->data); l = l->next; } - + g_list_free (fi->values); - + fi->values = g_list_append (NULL, g_strdup (new)); } @@ -334,13 +334,13 @@ get_widget (FilterElement *fe) { GtkWidget *entry; FilterInput *fi = (FilterInput *)fe; - + entry = gtk_entry_new (); if (fi->values && fi->values->data) gtk_entry_set_text (GTK_ENTRY (entry), (const char *) fi->values->data); - + g_signal_connect (entry, "changed", G_CALLBACK (entry_changed), fe); - + return entry; } @@ -357,7 +357,7 @@ format_sexp (FilterElement *fe, GString *out) GList *l; d(printf("format_sexp, first elem=%p\n", fi->values)); - + l = fi->values; while (l) { e_sexp_encode_string (out, l->data); diff --git a/filter/filter-input.h b/filter/filter-input.h index d791a32eca..e958b9b9fa 100644 --- a/filter/filter-input.h +++ b/filter/filter-input.h @@ -38,16 +38,16 @@ typedef struct _FilterInputClass FilterInputClass; struct _FilterInput { FilterElement parent_object; - + char *type; /* name of type */ GList *values; /* strings */ }; struct _FilterInputClass { FilterElementClass parent_class; - + /* virtual methods */ - + /* signals */ }; diff --git a/filter/filter-int.c b/filter/filter-int.c index a6c4bbd9a5..ace5040747 100644 --- a/filter/filter-int.c +++ b/filter/filter-int.c @@ -54,7 +54,7 @@ GType filter_int_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterIntClass), @@ -67,10 +67,10 @@ filter_int_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_int_init, }; - + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterInt", &info, 0); } - + return type; } @@ -79,11 +79,11 @@ filter_int_class_init (FilterIntClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); - + object_class->finalize = filter_int_finalise; - + /* override methods */ fe_class->eq = int_eq; fe_class->clone = int_clone; @@ -106,9 +106,9 @@ static void filter_int_finalise (GObject *obj) { FilterInt *fi = (FilterInt *) obj; - + g_free (fi->type); - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -116,7 +116,7 @@ filter_int_finalise (GObject *obj) * filter_int_new: * * Create a new FilterInt object. - * + * * Return value: A new #FilterInt object. **/ FilterInt * @@ -129,13 +129,13 @@ FilterInt * filter_int_new_type (const char *type, int min, int max) { FilterInt *fi; - + fi = filter_int_new (); - + fi->type = g_strdup (type); fi->min = min; fi->max = max; - + return fi; } @@ -179,18 +179,18 @@ xml_encode (FilterElement *fe) FilterInt *fs = (FilterInt *)fe; char intval[32]; const char *type; - + type = fs->type?fs->type:"integer"; - + d(printf("Encoding %s as xml\n", type)); - + value = xmlNewNode (NULL, (const unsigned char *)"value"); xmlSetProp (value, (const unsigned char *)"name", (unsigned char *)fe->name); xmlSetProp (value, (const unsigned char *)"type", (unsigned char *)type); - + sprintf(intval, "%d", fs->val); xmlSetProp (value, (unsigned char *)type, (unsigned char *)intval); - + return value; } @@ -200,20 +200,20 @@ xml_decode (FilterElement *fe, xmlNodePtr node) FilterInt *fs = (FilterInt *)fe; char *name, *type; char *intval; - + d(printf("Decoding integer from xml %p\n", fe)); - + name = (char *)xmlGetProp (node, (const unsigned char *)"name"); d(printf ("Name = %s\n", name)); xmlFree (fe->name); fe->name = name; - + type = (char *)xmlGetProp(node, (const unsigned char *)"type"); d(printf ("Type = %s\n", type)); g_free(fs->type); fs->type = g_strdup(type); xmlFree(type); - + intval = (char *)xmlGetProp (node, (unsigned char *)(fs->type ? fs->type : "integer")); if (intval) { d(printf ("Value = %s\n", intval)); @@ -223,7 +223,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) d(printf ("Value = ?unknown?\n")); fs->val = 0; } - + return 0; } @@ -231,7 +231,7 @@ static void spin_changed (GtkWidget *spin, FilterElement *fe) { FilterInt *fs = (FilterInt *)fe; - + fs->val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin)); } @@ -241,16 +241,16 @@ get_widget (FilterElement *fe) GtkWidget *spin; GtkObject *adjustment; FilterInt *fs = (FilterInt *)fe; - + adjustment = gtk_adjustment_new (0.0, (gfloat)fs->min, (gfloat)fs->max, 1.0, 1.0, 1.0); spin = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), fs->max>fs->min+1000?5.0:1.0, 0); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin), TRUE); - + if (fs->val) gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), (gfloat) fs->val); - + g_signal_connect (spin, "value-changed", G_CALLBACK (spin_changed), fe); - + return spin; } diff --git a/filter/filter-int.h b/filter/filter-int.h index 501adc4114..375a8508f1 100644 --- a/filter/filter-int.h +++ b/filter/filter-int.h @@ -38,7 +38,7 @@ typedef struct _FilterIntClass FilterIntClass; struct _FilterInt { FilterElement parent_object; - + char *type; int val; int min; @@ -47,9 +47,9 @@ struct _FilterInt { struct _FilterIntClass { FilterElementClass parent_class; - + /* virtual methods */ - + /* signals */ }; diff --git a/filter/filter-label.c b/filter/filter-label.c index 4d997e7378..ca0ae005fe 100644 --- a/filter/filter-label.c +++ b/filter/filter-label.c @@ -39,7 +39,7 @@ #include <libedataserver/e-sexp.h> #include "e-util/e-util.h" -#define d(x) +#define d(x) static void xml_create (FilterElement *fe, xmlNodePtr node); @@ -55,7 +55,7 @@ GType filter_label_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterLabelClass), @@ -68,10 +68,10 @@ filter_label_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_label_init, }; - + type = g_type_register_static (FILTER_TYPE_OPTION, "FilterLabel", &info, 0); } - + return type; } @@ -80,11 +80,11 @@ filter_label_class_init (FilterLabelClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - + parent_class = g_type_class_ref (FILTER_TYPE_OPTION); - + object_class->finalize = filter_label_finalise; - + /* override methods */ fe_class->xml_create = xml_create; } @@ -105,7 +105,7 @@ filter_label_finalise (GObject *obj) * filter_label_new: * * Create a new FilterLabel object. - * + * * Return value: A new #FilterLabel object. **/ FilterLabel * @@ -143,12 +143,12 @@ int filter_label_index (const char *label) { int i; - + for (i = 0; i < sizeof (labels) / sizeof (labels[0]); i++) { if (strcmp (labels[i].value, label) == 0) return i; } - + return -1; } @@ -160,26 +160,26 @@ xml_create (FilterElement *fe, xmlNodePtr node) GSList *list, *l; char *title, *p, *nounderscores_title; int i = 0; - + FILTER_ELEMENT_CLASS (parent_class)->xml_create (fe, node); - + gconf = gconf_client_get_default (); - + l = list = gconf_client_get_list (gconf, "/apps/evolution/mail/labels", GCONF_VALUE_STRING, NULL); while (l != NULL) { title = (char *) l->data; if ((p = strrchr (title, ':'))) *p++ = '\0'; - + nounderscores_title = e_str_without_underscores (title); - + filter_option_add (fo, i < 5 ? labels[i++].value : (p ? p : "#ffffff"), nounderscores_title, NULL); g_free (title); g_free (nounderscores_title); - + l = l->next; } g_slist_free (list); - + g_object_unref (gconf); } diff --git a/filter/filter-label.h b/filter/filter-label.h index 6a60e6f760..cacd10bdb1 100644 --- a/filter/filter-label.h +++ b/filter/filter-label.h @@ -43,14 +43,14 @@ typedef struct _FilterLabelClass FilterLabelClass; struct _FilterLabel { FilterOption parent_object; - + }; struct _FilterLabelClass { FilterOptionClass parent_class; - + /* virtual methods */ - + /* signals */ }; diff --git a/filter/filter-option.c b/filter/filter-option.c index 7fc8e1602a..2aea362bbc 100644 --- a/filter/filter-option.c +++ b/filter/filter-option.c @@ -57,7 +57,7 @@ GType filter_option_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterOptionClass), @@ -70,10 +70,10 @@ filter_option_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_option_init, }; - + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterOption", &info, 0); } - + return type; } @@ -82,11 +82,11 @@ filter_option_class_init (FilterOptionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); - + object_class->finalize = filter_option_finalise; - + /* override methods */ fe_class->eq = option_eq; fe_class->xml_create = xml_create; @@ -117,10 +117,10 @@ static void filter_option_finalise (GObject *obj) { FilterOption *fo = (FilterOption *) obj; - + g_list_foreach (fo->options, (GFunc)free_option, NULL); g_list_free (fo->options); - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -128,7 +128,7 @@ filter_option_finalise (GObject *obj) * filter_option_new: * * Create a new FilterOption object. - * + * * Return value: A new #FilterOption object. **/ FilterOption * @@ -142,7 +142,7 @@ find_option (FilterOption *fo, const char *name) { GList *l = fo->options; struct _filter_option *op; - + while (l) { op = l->data; if (!strcmp (name, op->value)) { @@ -150,7 +150,7 @@ find_option (FilterOption *fo, const char *name) } l = g_list_next (l); } - + return NULL; } @@ -158,7 +158,7 @@ void filter_option_set_current (FilterOption *option, const char *name) { g_return_if_fail (IS_FILTER_OPTION(option)); - + option->current = find_option (option, name); } @@ -167,15 +167,15 @@ struct _filter_option * filter_option_add(FilterOption *fo, const char *value, const char *title, const char *code) { struct _filter_option *op; - + g_return_val_if_fail (IS_FILTER_OPTION(fo), NULL); g_return_val_if_fail(find_option(fo, value) == NULL, NULL); - + op = g_malloc(sizeof(*op)); op->title = g_strdup(title); op->value = g_strdup(value); op->code = g_strdup(code); - + fo->options = g_list_append(fo->options, op); if (fo->current == NULL) fo->current = op; @@ -187,7 +187,7 @@ static int option_eq(FilterElement *fe, FilterElement *cm) { FilterOption *fo = (FilterOption *)fe, *co = (FilterOption *)cm; - + return FILTER_ELEMENT_CLASS (parent_class)->eq (fe, cm) && ((fo->current && co->current && strcmp(fo->current->value, co->current->value) == 0) || (fo->current == NULL && co->current == NULL)); @@ -198,15 +198,15 @@ xml_create (FilterElement *fe, xmlNodePtr node) { FilterOption *fo = (FilterOption *)fe; xmlNodePtr n, work; - + /* parent implementation */ FILTER_ELEMENT_CLASS (parent_class)->xml_create (fe, node); - + n = node->children; while (n) { if (!strcmp ((char *)n->name, "option")) { char *tmp, *value, *title = NULL, *code = NULL; - + value = (char *)xmlGetProp (n, (const unsigned char *)"value"); work = n->children; while (work) { @@ -214,7 +214,7 @@ xml_create (FilterElement *fe, xmlNodePtr node) if (!title) { if (!(tmp = (char *)xmlNodeGetContent (work))) tmp = (char *)xmlStrdup ((const unsigned char *)""); - + title = g_strdup (tmp); xmlFree (tmp); } @@ -222,14 +222,14 @@ xml_create (FilterElement *fe, xmlNodePtr node) if (!code) { if (!(tmp = (char*)xmlNodeGetContent (work))) tmp = (char *)xmlStrdup ((const unsigned char *)""); - + code = g_strdup (tmp); xmlFree (tmp); } } work = work->next; } - + filter_option_add (fo, value, title, code); xmlFree (value); g_free (title); @@ -246,14 +246,14 @@ xml_encode (FilterElement *fe) { xmlNodePtr value; FilterOption *fo = (FilterOption *)fe; - + d(printf ("Encoding option as xml\n")); value = xmlNewNode (NULL, (const unsigned char *)"value"); xmlSetProp (value, (const unsigned char *)"name", (unsigned char *)fe->name); xmlSetProp (value, (const unsigned char *)"type", (unsigned char *)fo->type); if (fo->current) xmlSetProp (value, (const unsigned char *)"value", (unsigned char *)fo->current->value); - + return value; } @@ -262,7 +262,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) { FilterOption *fo = (FilterOption *)fe; char *value; - + d(printf ("Decoding option from xml\n")); xmlFree (fe->name); fe->name = (char *)xmlGetProp (node, (const unsigned char *)"name"); @@ -280,7 +280,7 @@ static void option_changed (GtkWidget *widget, FilterElement *fe) { FilterOption *fo = (FilterOption *)fe; - + fo->current = g_object_get_data ((GObject *) widget, "option"); } @@ -295,7 +295,7 @@ get_widget (FilterElement *fe) GList *l = fo->options; struct _filter_option *op; int index = 0, current = 0; - + menu = gtk_menu_new (); while (l) { op = l->data; @@ -310,19 +310,19 @@ get_widget (FilterElement *fe) } else if (!first) { first = item; } - + l = g_list_next (l); index++; } - + omenu = gtk_option_menu_new (); gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); - + if (first) g_signal_emit_by_name (first, "activate", fe); - + gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), current); - + return omenu; } @@ -330,9 +330,9 @@ static void build_code (FilterElement *fe, GString *out, struct _FilterPart *ff) { FilterOption *fo = (FilterOption *)fe; - + d(printf ("building option code %p, current = %p\n", fo, fo->current)); - + if (fo->current && fo->current->code) filter_part_expand_code (ff, fo->current->code, out); } @@ -341,7 +341,7 @@ static void format_sexp (FilterElement *fe, GString *out) { FilterOption *fo = (FilterOption *)fe; - + if (fo->current) e_sexp_encode_string (out, fo->current->value); } @@ -352,9 +352,9 @@ clone (FilterElement *fe) FilterOption *fo = (FilterOption *)fe, *new; GList *l; struct _filter_option *op, *newop; - + d(printf ("cloning option\n")); - + new = FILTER_OPTION (FILTER_ELEMENT_CLASS (parent_class)->clone (fe)); l = fo->options; while (l) { @@ -364,8 +364,8 @@ clone (FilterElement *fe) new->current = newop; l = l->next; } - + d(printf ("cloning option code %p, current = %p\n", new, new->current)); - + return (FilterElement *) new; } diff --git a/filter/filter-option.h b/filter/filter-option.h index 60f7eb2619..58f984d8e4 100644 --- a/filter/filter-option.h +++ b/filter/filter-option.h @@ -44,18 +44,18 @@ struct _filter_option { struct _FilterOption { FilterElement parent_object; - + const char *type; /* static memory, type name written to xml */ - + GList *options; struct _filter_option *current; }; struct _FilterOptionClass { FilterElementClass parent_class; - + /* virtual methods */ - + /* signals */ }; diff --git a/filter/filter-part.c b/filter/filter-part.c index 6ac8ddd842..91bd6655d6 100644 --- a/filter/filter-part.c +++ b/filter/filter-part.c @@ -50,7 +50,7 @@ GType filter_part_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterPartClass), @@ -63,10 +63,10 @@ filter_part_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_part_init, }; - + type = g_type_register_static (G_TYPE_OBJECT, "FilterPart", &info, 0); } - + return type; } @@ -74,9 +74,9 @@ static void filter_part_class_init (FilterPartClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - + parent_class = g_type_class_ref (G_TYPE_OBJECT); - + object_class->finalize = filter_part_finalise; } @@ -91,18 +91,18 @@ filter_part_finalise (GObject *obj) { FilterPart *fp = (FilterPart *) obj; GList *l; - + l = fp->elements; while (l) { g_object_unref (l->data); l = l->next; } - + g_list_free (fp->elements); g_free (fp->name); g_free (fp->title); g_free (fp->code); - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -110,7 +110,7 @@ filter_part_finalise (GObject *obj) * filter_part_new: * * Create a new FilterPart object. - * + * * Return value: A new #FilterPart object. **/ FilterPart * @@ -124,16 +124,16 @@ filter_part_validate (FilterPart *fp) { gboolean correct = TRUE; GList *l; - + l = fp->elements; while (l && correct) { FilterElement *fe = l->data; - + correct = filter_element_validate (fe); - + l = l->next; } - + return correct; } @@ -142,25 +142,25 @@ filter_part_eq (FilterPart *fp, FilterPart *fc) { int truth; GList *al, *bl; - + truth = ((fp->name && fc->name && strcmp(fp->name, fc->name) == 0) || (fp->name == NULL && fc->name == NULL)) && ((fp->title && fc->title && strcmp(fp->title, fc->title) == 0) || (fp->title == NULL && fc->title == NULL)) && ((fp->code && fc->code && strcmp(fp->code, fc->code) == 0) || (fp->code == NULL && fc->code == NULL)); - + al = fp->elements; bl = fc->elements; while (truth && al && bl) { FilterElement *a = al->data, *b = bl->data; - + truth = filter_element_eq(a, b); - + al = al->next; bl = bl->next; } - + return truth && al == NULL && bl == NULL; } @@ -170,12 +170,12 @@ filter_part_xml_create (FilterPart *ff, xmlNodePtr node, RuleContext *rc) xmlNodePtr n; char *type, *str; FilterElement *el; - + str = (char *)xmlGetProp (node, (const unsigned char *)"name"); ff->name = g_strdup (str); if (str) xmlFree (str); - + n = node->children; while (n) { if (!strcmp ((char *)n->name, "input")) { @@ -209,7 +209,7 @@ filter_part_xml_create (FilterPart *ff, xmlNodePtr node, RuleContext *rc) } n = n->next; } - + return 0; } @@ -219,9 +219,9 @@ filter_part_xml_encode (FilterPart *fp) GList *l; FilterElement *fe; xmlNodePtr part, value; - + g_return_val_if_fail (fp != NULL, NULL); - + part = xmlNewNode (NULL, (const unsigned char *)"part"); xmlSetProp (part, (const unsigned char *)"name", (unsigned char *)fp->name); l = fp->elements; @@ -231,7 +231,7 @@ filter_part_xml_encode (FilterPart *fp) xmlAddChild (part, value); l = g_list_next (l); } - + return part; } @@ -242,10 +242,10 @@ filter_part_xml_decode (FilterPart *fp, xmlNodePtr node) FilterElement *fe; xmlNodePtr n; char *name; - + g_return_val_if_fail (fp != NULL, -1); g_return_val_if_fail (node != NULL, -1); - + n = node->children; while (n) { if (!strcmp ((char *)n->name, "value")) { @@ -259,7 +259,7 @@ filter_part_xml_decode (FilterPart *fp, xmlNodePtr node) } n = n->next; } - + return 0; } @@ -269,7 +269,7 @@ filter_part_clone (FilterPart *fp) FilterPart *new; GList *l; FilterElement *fe, *ne; - + new = (FilterPart *) g_object_new (G_OBJECT_TYPE (fp), NULL, NULL); new->name = g_strdup (fp->name); new->title = g_strdup (fp->title); @@ -281,7 +281,7 @@ filter_part_clone (FilterPart *fp) new->elements = g_list_append (new->elements, ne); l = g_list_next (l); } - + return new; } @@ -291,9 +291,9 @@ filter_part_copy_values (FilterPart *dst, FilterPart *src) { GList *dstl, *srcl, *dstt; FilterElement *de, *se; - + /* NOTE: we go backwards, it just works better that way */ - + /* for each source type, search the dest type for a matching type in the same order */ srcl = g_list_last (src->elements); @@ -310,7 +310,7 @@ filter_part_copy_values (FilterPart *dst, FilterPart *src) } dstt = dstt->prev; } - + srcl = srcl->prev; } } @@ -320,17 +320,17 @@ filter_part_find_element (FilterPart *ff, const char *name) { GList *l = ff->elements; FilterElement *fe; - + if (name == NULL) return NULL; - + while (l) { fe = l->data; if (fe->name && !strcmp (fe->name, name)) return fe; l = g_list_next (l); } - + return NULL; } @@ -342,28 +342,28 @@ filter_part_get_widget (FilterPart *ff) GList *l = ff->elements; FilterElement *fe; GtkWidget *w; - + hbox = gtk_hbox_new (FALSE, 3); - + while (l) { fe = l->data; w = filter_element_get_widget (fe); if (w) gtk_box_pack_start (GTK_BOX (hbox), w, IS_FILTER_FILE (fe), IS_FILTER_FILE (fe), 3); - + l = g_list_next (l); } - + gtk_widget_show_all (hbox); - + return hbox; } /** * filter_part_build_code: - * @ff: - * @out: - * + * @ff: + * @out: + * * Outputs the code of a part. **/ void @@ -371,10 +371,10 @@ filter_part_build_code (FilterPart *ff, GString *out) { GList *l = ff->elements; FilterElement *fe; - + if (ff->code) filter_part_expand_code (ff, ff->code, out); - + while (l) { fe = l->data; filter_element_build_code (fe, out, ff); @@ -384,9 +384,9 @@ filter_part_build_code (FilterPart *ff, GString *out) /** * filter_part_build_code_list: - * @l: - * @out: - * + * @l: + * @out: + * * Construct a list of the filter parts code into * a single string. **/ @@ -394,7 +394,7 @@ void filter_part_build_code_list (GList *l, GString *out) { FilterPart *fp; - + while (l) { fp = l->data; filter_part_build_code (fp, out); @@ -405,20 +405,20 @@ filter_part_build_code_list (GList *l, GString *out) /** * filter_part_find_list: - * @l: - * @name: - * + * @l: + * @name: + * * Find a filter part stored in a list. - * - * Return value: + * + * Return value: **/ FilterPart * filter_part_find_list (GList *l, const char *name) { FilterPart *part; - + d(printf ("Find part named %s\n", name)); - + while (l) { part = l->data; if (!strcmp (part->name, name)) { @@ -427,18 +427,18 @@ filter_part_find_list (GList *l, const char *name) } l = l->next; } - + return NULL; } /** * filter_part_next_list: - * @l: + * @l: * @last: The last item retrieved, or NULL to start * from the beginning of the list. - * + * * Iterate through a filter part list. - * + * * Return value: The next value in the list, or NULL if the * list is expired. **/ @@ -446,7 +446,7 @@ FilterPart * filter_part_next_list (GList *l, FilterPart *last) { GList *node = l; - + if (last != NULL) { node = g_list_find (node, last); if (node == NULL) @@ -454,19 +454,19 @@ filter_part_next_list (GList *l, FilterPart *last) else node = node->next; } - + if (node) return node->data; - + return NULL; } /** * filter_part_expand_code: - * @ff: - * @str: - * @out: - * + * @ff: + * @str: + * @out: + * * Expands the variables in string @str based on the values of the part. **/ void @@ -476,7 +476,7 @@ filter_part_expand_code (FilterPart *ff, const char *source, GString *out) char *name = alloca (32); int len, namelen = 32; FilterElement *fe; - + start = source; while (start && (newstart = strstr (start, "${")) && (end = strstr (newstart+2, "}")) ) { @@ -513,34 +513,34 @@ int main(int argc, char **argv) xmlNodePtr node; FilterPart *ff; GString *code; - + gnome_init ("test", "0.0", argc, argv); - + system = xmlParseFile ("form.xml"); if (system == NULL) { printf("i/o error\n"); return 1; } - + ff = filter_part_new (); filter_part_xml_create (ff, system->root); - + w = filter_part_get_widget (ff); - + dialog = gtk_dialog_new (); gtk_dialog_add_buttons ((GtkDialog *) dialog, GTK_BUTTONS_OK, NULL); gtk_dialog_set_has_separator ((GtkDialog *) dialog, FALSE); gtk_window_set_title ((GtkWindow *) dialog, _("Test")); gtk_window_set_policy ((GtkWindow *) dialog, FALSE, TRUE, FALSE); gtk_box_pack_start ((GtkBox *) dialog->vbox, w, TRUE, TRUE, 0); - + gtk_dialog_run ((GtkDialog *) dialog); gtk_widget_destroy (dialog); - + code = g_string_new (""); filter_part_build_code (ff, code); printf("code is:\n%s\n", code->str); - + return 0; } #endif diff --git a/filter/filter-part.h b/filter/filter-part.h index 57de141d79..580cfaf29c 100644 --- a/filter/filter-part.h +++ b/filter/filter-part.h @@ -43,7 +43,7 @@ typedef struct _FilterPartClass FilterPartClass; struct _FilterPart { GObject parent_object; struct _FilterPartPrivate *priv; - + char *name; char *title; char *code; @@ -52,9 +52,9 @@ struct _FilterPart { struct _FilterPartClass { GObjectClass parent_class; - + /* virtual methods */ - + /* signals */ }; diff --git a/filter/filter-rule.c b/filter/filter-rule.c index b656ee9a1b..81fb3e8861 100644 --- a/filter/filter-rule.c +++ b/filter/filter-rule.c @@ -67,7 +67,7 @@ GType filter_rule_get_type (void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (FilterRuleClass), @@ -80,10 +80,10 @@ filter_rule_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) filter_rule_init, }; - + type = g_type_register_static (G_TYPE_OBJECT, "FilterRule", &info, 0); } - + return type; } @@ -91,11 +91,11 @@ static void filter_rule_class_init (FilterRuleClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - + parent_class = g_type_class_ref (G_TYPE_OBJECT); - + object_class->finalize = filter_rule_finalise; - + /* override methods */ klass->validate = validate; klass->eq = rule_eq; @@ -104,7 +104,7 @@ filter_rule_class_init (FilterRuleClass *klass) klass->build_code = build_code; klass->copy = rule_copy; klass->get_widget = get_widget; - + /* signals */ signals[CHANGED] = g_signal_new ("changed", @@ -127,14 +127,14 @@ static void filter_rule_finalise (GObject *obj) { FilterRule *fr = (FilterRule *) obj; - + g_free (fr->name); g_free (fr->source); g_list_foreach (fr->parts, (GFunc)g_object_unref, NULL); g_list_free (fr->parts); - + g_free (fr->priv); - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -142,7 +142,7 @@ filter_rule_finalise (GObject *obj) * filter_rule_new: * * Create a new FilterRule object. - * + * * Return value: A new #FilterRule object. **/ FilterRule * @@ -155,12 +155,12 @@ FilterRule * filter_rule_clone (FilterRule *base) { FilterRule *rule; - + g_return_val_if_fail (IS_FILTER_RULE (base), NULL); - + rule = g_object_new (G_OBJECT_TYPE (base), NULL, NULL); filter_rule_copy (rule, base); - + return rule; } @@ -168,14 +168,14 @@ void filter_rule_set_name (FilterRule *fr, const char *name) { g_return_if_fail (IS_FILTER_RULE (fr)); - + if ((fr->name && name && strcmp (fr->name, name) == 0) || (fr->name == NULL && name == NULL)) return; - + g_free (fr->name); fr->name = g_strdup (name); - + filter_rule_emit_changed (fr); } @@ -183,14 +183,14 @@ void filter_rule_set_source (FilterRule *fr, const char *source) { g_return_if_fail (IS_FILTER_RULE (fr)); - + if ((fr->source && source && strcmp (fr->source, source) == 0) || (fr->source == NULL && source == NULL)) return; - + g_free (fr->source); fr->source = g_strdup (source); - + filter_rule_emit_changed (fr); } @@ -207,17 +207,17 @@ validate (FilterRule *fr) { int valid = TRUE; GList *parts; - + if (!fr->name || !*fr->name) { /* FIXME: FilterElement should probably have a GtkWidget member pointing to the value gotten with ::get_widget() so that we can get the parent window here. */ e_error_run(NULL, "filter:no-name", NULL); - + return FALSE; } - + /* validate rule parts */ parts = fr->parts; valid = parts != NULL; @@ -225,7 +225,7 @@ validate (FilterRule *fr) valid = filter_part_validate ((FilterPart *) parts->data); parts = parts->next; } - + return valid; } @@ -234,7 +234,7 @@ filter_rule_eq (FilterRule *fr, FilterRule *cm) { g_return_val_if_fail (IS_FILTER_RULE (fr), 0); g_return_val_if_fail (IS_FILTER_RULE (cm), 0); - + return (FILTER_RULE_GET_CLASS (fr) == FILTER_RULE_GET_CLASS (cm)) && FILTER_RULE_GET_CLASS (fr)->eq (fr, cm); } @@ -243,15 +243,15 @@ static int list_eq(GList *al, GList *bl) { int truth = TRUE; - + while (truth && al && bl) { FilterPart *a = al->data, *b = bl->data; - + truth = filter_part_eq (a, b); al = al->next; bl = bl->next; } - + return truth && al == NULL && bl == NULL; } @@ -271,7 +271,7 @@ xmlNodePtr filter_rule_xml_encode (FilterRule *fr) { g_return_val_if_fail (IS_FILTER_RULE (fr), NULL); - + return FILTER_RULE_GET_CLASS (fr)->xml_encode (fr); } @@ -280,7 +280,7 @@ xml_encode (FilterRule *fr) { xmlNodePtr node, set, work; GList *l; - + node = xmlNewNode (NULL, (const unsigned char *)"rule"); switch (fr->grouping) { case FILTER_GROUP_ALL: @@ -314,13 +314,13 @@ xml_encode (FilterRule *fr) /* set to the default filter type */ xmlSetProp (node, (const unsigned char *)"source", (const unsigned char *)"incoming"); } - + if (fr->name) { work = xmlNewNode (NULL, (const unsigned char *)"title"); xmlNodeSetContent (work, (unsigned char *)fr->name); xmlAddChild (node, work); } - + set = xmlNewNode (NULL, (const unsigned char *)"partset"); xmlAddChild (node, set); l = fr->parts; @@ -329,7 +329,7 @@ xml_encode (FilterRule *fr) xmlAddChild (set, work); l = l->next; } - + return node; } @@ -339,7 +339,7 @@ load_set (xmlNodePtr node, FilterRule *fr, RuleContext *f) xmlNodePtr work; char *rulename; FilterPart *part; - + work = node->children; while (work) { if (!strcmp ((char *)work->name, "part")) { @@ -364,17 +364,17 @@ int filter_rule_xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) { int res; - + g_return_val_if_fail (IS_FILTER_RULE (fr), 0); g_return_val_if_fail (IS_RULE_CONTEXT (f), 0); g_return_val_if_fail (node != NULL, 0); - - fr->priv->frozen++; + + fr->priv->frozen++; res = FILTER_RULE_GET_CLASS (fr)->xml_decode (fr, node, f); fr->priv->frozen--; - + filter_rule_emit_changed (fr); - + return res; } @@ -384,12 +384,12 @@ xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) xmlNodePtr work; char *grouping; char *source; - + if (fr->name) { g_free (fr->name); fr->name = NULL; } - + grouping = (char *)xmlGetProp (node, (const unsigned char *)"grouping"); if (!strcmp (grouping, "any")) fr->grouping = FILTER_GROUP_ANY; @@ -410,7 +410,7 @@ xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) fr->threading = FILTER_THREAD_SINGLE; xmlFree (grouping); } - + g_free (fr->source); source = (char *)xmlGetProp (node, (const unsigned char *)"source"); if (source) { @@ -420,7 +420,7 @@ xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) /* default filter type */ fr->source = g_strdup ("incoming"); } - + work = node->children; while (work) { if (!strcmp ((char *)work->name, "partset")) { @@ -428,7 +428,7 @@ xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) } else if (!strcmp ((char *)work->name, "title") || !strcmp ((char *)work->name, "_title")) { if (!fr->name) { char *str, *decstr; - + str = (char *)xmlNodeGetContent (work); decstr = g_strdup (str); if (str) @@ -438,7 +438,7 @@ xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f) } work = work->next; } - + return 0; } @@ -446,13 +446,13 @@ static void rule_copy (FilterRule *dest, FilterRule *src) { GList *node; - + g_free (dest->name); dest->name = g_strdup (src->name); - + g_free (dest->source); dest->source = g_strdup (src->source); - + dest->grouping = src->grouping; dest->threading = src->threading; @@ -461,7 +461,7 @@ rule_copy (FilterRule *dest, FilterRule *src) g_list_free (dest->parts); dest->parts = NULL; } - + node = src->parts; while (node) { FilterPart *part; @@ -477,9 +477,9 @@ filter_rule_copy (FilterRule *dest, FilterRule *src) { g_return_if_fail (IS_FILTER_RULE (dest)); g_return_if_fail (IS_FILTER_RULE (src)); - + FILTER_RULE_GET_CLASS (dest)->copy (dest, src); - + filter_rule_emit_changed (dest); } @@ -488,9 +488,9 @@ filter_rule_add_part (FilterRule *fr, FilterPart *fp) { g_return_if_fail (IS_FILTER_RULE (fr)); g_return_if_fail (IS_FILTER_PART (fp)); - + fr->parts = g_list_append (fr->parts, fp); - + filter_rule_emit_changed (fr); } @@ -499,9 +499,9 @@ filter_rule_remove_part (FilterRule *fr, FilterPart *fp) { g_return_if_fail (IS_FILTER_RULE (fr)); g_return_if_fail (IS_FILTER_PART (fp)); - + fr->parts = g_list_remove (fr->parts, fp); - + filter_rule_emit_changed (fr); } @@ -509,18 +509,18 @@ void filter_rule_replace_part (FilterRule *fr, FilterPart *fp, FilterPart *new) { GList *l; - + g_return_if_fail (IS_FILTER_RULE (fr)); g_return_if_fail (IS_FILTER_PART (fp)); g_return_if_fail (IS_FILTER_PART (new)); - + l = g_list_find (fr->parts, fp); if (l) { l->data = new; } else { fr->parts = g_list_append (fr->parts, new); } - + filter_rule_emit_changed (fr); } @@ -529,9 +529,9 @@ filter_rule_build_code (FilterRule *fr, GString *out) { g_return_if_fail (IS_FILTER_RULE (fr)); g_return_if_fail (out != NULL); - + FILTER_RULE_GET_CLASS (fr)->build_code (fr, out); - + d(printf ("build_code: [%s](%d)", out->str, out->len)); } @@ -539,7 +539,7 @@ void filter_rule_emit_changed(FilterRule *fr) { g_return_if_fail (IS_FILTER_RULE (fr)); - + if (fr->priv->frozen == 0) g_signal_emit (fr, signals[CHANGED], 0); } @@ -574,7 +574,7 @@ build_code (FilterRule *fr, GString *out) default: g_warning ("Invalid grouping"); } - + filter_part_build_code_list (fr->parts, out); g_string_append (out, ")\n"); @@ -606,16 +606,16 @@ option_activate (GtkMenuItem *item, struct _part_data *data) { FilterPart *part = g_object_get_data ((GObject *) item, "part"); FilterPart *newpart; - + /* dont update if we haven't changed */ if (!strcmp (part->title, data->part->title)) return; - + /* here we do a widget shuffle, throw away the old widget/rulepart, and create another */ if (data->partwidget) gtk_container_remove (GTK_CONTAINER (data->container), data->partwidget); - + newpart = filter_part_clone (part); filter_part_copy_values (newpart, data->part); filter_rule_replace_part (data->fr, data->part, newpart); @@ -624,7 +624,7 @@ option_activate (GtkMenuItem *item, struct _part_data *data) data->partwidget = filter_part_get_widget (newpart); if (data->partwidget) gtk_box_pack_start (GTK_BOX (data->container), data->partwidget, TRUE, TRUE, 0); - + g_object_set_data ((GObject *) data->container, "part", newpart); } @@ -639,21 +639,21 @@ get_rule_part_widget (RuleContext *f, FilterPart *newpart, FilterRule *fr) GtkWidget *p; int index = 0, current = 0; struct _part_data *data; - + data = g_malloc0 (sizeof (*data)); data->fr = fr; data->f = f; data->part = newpart; - + hbox = gtk_hbox_new (FALSE, 0); /* only set to automatically clean up the memory */ g_object_set_data_full ((GObject *) hbox, "data", data, g_free); - + p = filter_part_get_widget (newpart); - + data->partwidget = p; data->container = hbox; - + menu = gtk_menu_new (); /* sigh, this is a little ugly */ while ((part = rule_context_next_part (f, part))) { @@ -664,21 +664,21 @@ get_rule_part_widget (RuleContext *f, FilterPart *newpart, FilterRule *fr) gtk_widget_show (item); if (!strcmp (newpart->title, part->title)) current = index; - + index++; } - + omenu = gtk_option_menu_new (); gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), current); gtk_widget_show (omenu); - + gtk_box_pack_start (GTK_BOX (hbox), omenu, FALSE, FALSE, 0); if (p) gtk_box_pack_start (GTK_BOX (hbox), p, TRUE, TRUE, 0); - + gtk_widget_show_all (hbox); - + return hbox; } @@ -693,17 +693,17 @@ less_parts (GtkWidget *button, struct _rule_data *data) { FilterPart *part; GtkWidget *rule; - + if (g_list_length (data->fr->parts) < 1) return; - + rule = g_object_get_data ((GObject *) button, "rule"); part = g_object_get_data ((GObject *) rule, "part"); - + /* remove the part from the list */ filter_rule_remove_part (data->fr, part); g_object_unref (part); - + /* and from the display */ gtk_container_remove (GTK_CONTAINER (data->parts), rule); gtk_container_remove (GTK_CONTAINER (data->parts), button); @@ -713,10 +713,10 @@ static void attach_rule (GtkWidget *rule, struct _rule_data *data, FilterPart *part, int row) { GtkWidget *remove; - + gtk_table_attach (GTK_TABLE (data->parts), rule, 0, 1, row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); - + remove = gtk_button_new_from_stock (GTK_STOCK_REMOVE); g_object_set_data ((GObject *) remove, "rule", rule); g_object_set_data ((GObject *) rule, "part", part); @@ -724,7 +724,7 @@ attach_rule (GtkWidget *rule, struct _rule_data *data, FilterPart *part, int row g_signal_connect (remove, "clicked", G_CALLBACK (less_parts), data); gtk_table_attach (GTK_TABLE (data->parts), remove, 1, 2, row, row + 1, 0, 0, 0, 0); - + gtk_widget_show (remove); } @@ -732,28 +732,28 @@ static void more_parts (GtkWidget *button, struct _rule_data *data) { FilterPart *new; - + /* first make sure that the last part is ok */ if (data->fr->parts) { FilterPart *part; GList *l; - + l = g_list_last (data->fr->parts); part = l->data; if (!filter_part_validate (part)) return; } - + /* create a new rule entry, use the first type of rule */ new = rule_context_next_part (data->f, NULL); if (new) { GtkWidget *w; int rows; - + new = filter_part_clone (new); filter_rule_add_part (data->fr, new); w = get_rule_part_widget (data->f, new, data->fr); - + rows = GTK_TABLE (data->parts)->nrows; gtk_table_resize (GTK_TABLE (data->parts), rows + 1, 2); attach_rule (w, data, new, rows); @@ -792,7 +792,7 @@ get_widget (FilterRule *fr, struct _RuleContext *f) FilterPart *part; struct _rule_data *data; int rows, i; - + /* this stuff should probably be a table, but the rule parts need to be a vbox */ vbox = gtk_vbox_new (FALSE, 6); @@ -809,10 +809,10 @@ get_widget (FilterRule *fr, struct _RuleContext *f) } else { gtk_entry_set_text (GTK_ENTRY (name), fr->name); } - + /* evil kludgy hack because gtk sucks */ g_signal_connect (name, "realize", G_CALLBACK (grab_focus), name); - + hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), name, TRUE, TRUE, 0); @@ -843,20 +843,20 @@ get_widget (FilterRule *fr, struct _RuleContext *f) inframe = gtk_vbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (hbox), inframe, TRUE, TRUE, 0); - + /* this is the parts table, it should probably be inside a scrolling list */ rows = g_list_length (fr->parts); parts = gtk_table_new (rows, 2, FALSE); - + /* data for the parts part of the display */ data = g_malloc0 (sizeof (*data)); data->f = f; data->fr = fr; data->parts = parts; - + /* only set to automatically clean up the memory */ g_object_set_data_full ((GObject *) vbox, "data", data, g_free); - + hbox = gtk_hbox_new (FALSE, 3); add = gtk_button_new_with_mnemonic (_("A_dd Filter Criteria")); @@ -869,19 +869,19 @@ get_widget (FilterRule *fr, struct _RuleContext *f) label = gtk_label_new_with_mnemonic (_("_Find items:")); menu = gtk_menu_new (); - + for (i=0;i<2;i++) { item = gtk_menu_item_new_with_label(_(thread_types[i])); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } - + omenu = gtk_option_menu_new (); gtk_label_set_mnemonic_widget ((GtkLabel *)label, omenu); gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), fr->grouping); gtk_widget_show (omenu); - + gtk_box_pack_end (GTK_BOX (hbox), omenu, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0); @@ -893,27 +893,27 @@ get_widget (FilterRule *fr, struct _RuleContext *f) label = gtk_label_new_with_mnemonic (_("I_nclude threads")); menu = gtk_menu_new (); - + for (i=0;i<5;i++) { item = gtk_menu_item_new_with_label(_(thread_types[i])); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } - + omenu = gtk_option_menu_new (); gtk_label_set_mnemonic_widget ((GtkLabel *)label, omenu); gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), fr->threading); gtk_widget_show (omenu); - + gtk_box_pack_end (GTK_BOX (hbox), omenu, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0); g_signal_connect(omenu, "changed", G_CALLBACK(fr_threading_changed), fr); } - + gtk_box_pack_start (GTK_BOX (inframe), hbox, FALSE, FALSE, 3); - + l = fr->parts; i = 0; while (l) { @@ -923,20 +923,20 @@ get_widget (FilterRule *fr, struct _RuleContext *f) attach_rule (w, data, part, i++); l = g_list_next (l); } - + hadj = gtk_adjustment_new (0.0, 0.0, 1.0, 1.0, 1.0, 1.0); vadj = gtk_adjustment_new (0.0, 0.0, 1.0, 1.0, 1.0, 1.0); scrolledwindow = gtk_scrolled_window_new (GTK_ADJUSTMENT (hadj), GTK_ADJUSTMENT (vadj)); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow), parts); - + gtk_box_pack_start (GTK_BOX (inframe), scrolledwindow, TRUE, TRUE, 3); - + gtk_widget_show_all (vbox); - + return vbox; } @@ -944,7 +944,7 @@ FilterRule * filter_rule_next_list (GList *l, FilterRule *last, const char *source) { GList *node = l; - + if (last != NULL) { node = g_list_find (node, last); if (node == NULL) @@ -952,20 +952,20 @@ filter_rule_next_list (GList *l, FilterRule *last, const char *source) else node = node->next; } - + if (source) { while (node) { FilterRule *rule = node->data; - + if (rule->source && strcmp (rule->source, source) == 0) break; node = node->next; } } - + if (node) return node->data; - + return NULL; } @@ -974,13 +974,13 @@ filter_rule_find_list (GList * l, const char *name, const char *source) { while (l) { FilterRule *rule = l->data; - + if (strcmp (rule->name, name) == 0) if (source == NULL || (rule->source != NULL && strcmp (rule->source, source) == 0)) return rule; l = l->next; } - + return NULL; } diff --git a/filter/filter-rule.h b/filter/filter-rule.h index 9e30b6e84b..19c3f0941a 100644 --- a/filter/filter-rule.h +++ b/filter/filter-rule.h @@ -63,10 +63,10 @@ enum _filter_threading_t { struct _FilterRule { GObject parent_object; struct _FilterRulePrivate *priv; - + char *name; char *source; - + enum _filter_grouping_t grouping; enum _filter_threading_t threading; @@ -76,20 +76,20 @@ struct _FilterRule { struct _FilterRuleClass { GObjectClass parent_class; - + /* virtual methods */ int (*validate) (FilterRule *); int (*eq) (FilterRule *fr, FilterRule *cm); - + xmlNodePtr (*xml_encode) (FilterRule *); int (*xml_decode) (FilterRule *, xmlNodePtr, struct _RuleContext *); - + void (*build_code) (FilterRule *, GString *out); - + void (*copy) (FilterRule *dest, FilterRule *src); - + GtkWidget *(*get_widget) (FilterRule *fr, struct _RuleContext *f); - + /* signals */ void (*changed) (FilterRule *fr); }; diff --git a/filter/rule-context.c b/filter/rule-context.c index 55d53bc078..3cf6bbe6d2 100644 --- a/filter/rule-context.c +++ b/filter/rule-context.c @@ -53,7 +53,7 @@ #include "filter-rule.h" #include "rule-context.h" -#define d(x) +#define d(x) static int load(RuleContext *rc, const char *system, const char *user); static int save(RuleContext *rc, const char *user); @@ -88,7 +88,7 @@ GType rule_context_get_type(void) { static GType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof(RuleContextClass), @@ -101,10 +101,10 @@ rule_context_get_type(void) 0, /* n_preallocs */ (GInstanceInitFunc) rule_context_init, }; - + type = g_type_register_static(G_TYPE_OBJECT, "RuleContext", &info, 0); } - + return type; } @@ -112,11 +112,11 @@ static void rule_context_class_init(RuleContextClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); - + parent_class = g_type_class_ref(G_TYPE_OBJECT); - + object_class->finalize = rule_context_finalise; - + /* override methods */ klass->load = load; klass->save = save; @@ -135,7 +135,7 @@ rule_context_class_init(RuleContextClass *klass) NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - + signals[RULE_REMOVED] = g_signal_new("rule_removed", RULE_TYPE_CONTEXT, @@ -145,7 +145,7 @@ rule_context_class_init(RuleContextClass *klass) NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); - + signals[CHANGED] = g_signal_new("changed", RULE_TYPE_CONTEXT, @@ -161,7 +161,7 @@ static void rule_context_init(RuleContext *rc) { rc->priv = g_malloc0(sizeof(*rc->priv)); - + rc->part_set_map = g_hash_table_new(g_str_hash, g_str_equal); rc->rule_set_map = g_hash_table_new(g_str_hash, g_str_equal); @@ -186,24 +186,24 @@ static void rule_context_finalise(GObject *obj) { RuleContext *rc =(RuleContext *) obj; - + g_list_foreach(rc->rule_set_list, (GFunc)free_rule_set, NULL); g_list_free(rc->rule_set_list); g_hash_table_destroy(rc->rule_set_map); - + g_list_foreach(rc->part_set_list, (GFunc)free_part_set, NULL); g_list_free(rc->part_set_list); g_hash_table_destroy(rc->part_set_map); - + g_free(rc->error); - + g_list_foreach(rc->parts, (GFunc)g_object_unref, NULL); g_list_free(rc->parts); g_list_foreach(rc->rules, (GFunc)g_object_unref, NULL); g_list_free(rc->rules); g_free(rc->priv); - + G_OBJECT_CLASS(parent_class)->finalize(obj); } @@ -211,7 +211,7 @@ rule_context_finalise(GObject *obj) * rule_context_new: * * Create a new RuleContext object. - * + * * Return value: A new #RuleContext object. **/ RuleContext * @@ -224,9 +224,9 @@ void rule_context_add_part_set(RuleContext *rc, const char *setname, GType part_type, RCPartFunc append, RCNextPartFunc next) { struct _part_set_map *map; - + g_return_if_fail (g_hash_table_lookup(rc->part_set_map, setname) == NULL); - + map = g_malloc0(sizeof(*map)); map->type = part_type; map->append = append; @@ -241,9 +241,9 @@ void rule_context_add_rule_set(RuleContext *rc, const char *setname, GType rule_type, RCRuleFunc append, RCNextRuleFunc next) { struct _rule_set_map *map; - + g_return_if_fail (g_hash_table_lookup(rc->rule_set_map, setname) == NULL); - + map = g_malloc0(sizeof(*map)); map->type = rule_type; map->append = append; @@ -256,43 +256,43 @@ rule_context_add_rule_set(RuleContext *rc, const char *setname, GType rule_type, /** * rule_context_set_error: - * @f: - * @error: - * + * @f: + * @error: + * * Set the text error for the context, or NULL to clear it. **/ static void rule_context_set_error(RuleContext *rc, char *error) { g_return_if_fail (rc); - + g_free(rc->error); rc->error = error; } /** * rule_context_load: - * @f: - * @system: - * @user: + * @f: + * @system: + * @user: * * Load a rule context from a system and user description file. - * - * Return value: + * + * Return value: **/ int rule_context_load(RuleContext *rc, const char *system, const char *user) { int res; - + g_return_val_if_fail (rc, -1); - + d(printf("rule_context: loading %s %s\n", system, user)); - + rc->priv->frozen++; res = RULE_CONTEXT_GET_CLASS(rc)->load(rc, system, user); rc->priv->frozen--; - + return res; } @@ -305,9 +305,9 @@ load(RuleContext *rc, const char *system, const char *user) struct _rule_set_map *rule_map; rule_context_set_error(rc, NULL); - + d(printf("loading rules %s %s\n", system, user)); - + systemdoc = e_xml_parse_file (system); if (systemdoc == NULL) { rule_context_set_error(rc, g_strdup_printf("Unable to load system rules '%s': %s", @@ -338,7 +338,7 @@ load(RuleContext *rc, const char *system, const char *user) while (rule) { if (!strcmp((char *)rule->name, "part")) { FilterPart *part = FILTER_PART(g_object_new(part_map->type, NULL, NULL)); - + if (filter_part_xml_create(part, rule, rc) == 0) { part_map->append(rc, part); } else { @@ -355,7 +355,7 @@ load(RuleContext *rc, const char *system, const char *user) d(printf("checking node: %s\n", rule->name)); if (!strcmp((char *)rule->name, "rule")) { FilterRule *part = FILTER_RULE(g_object_new(rule_map->type, NULL, NULL)); - + if (filter_rule_xml_decode(part, rule, rc) == 0) { part->system = TRUE; rule_map->append(rc, part); @@ -369,7 +369,7 @@ load(RuleContext *rc, const char *system, const char *user) } set = set->next; } - + /* now load actual rules */ if (userdoc) { root = xmlDocGetRootElement(userdoc); @@ -384,7 +384,7 @@ load(RuleContext *rc, const char *system, const char *user) d(printf("checking node: %s\n", rule->name)); if (!strcmp((char *)rule->name, "rule")) { FilterRule *part = FILTER_RULE(g_object_new(rule_map->type, NULL, NULL)); - + if (filter_rule_xml_decode(part, rule, rc) == 0) { rule_map->append(rc, part); } else { @@ -401,25 +401,25 @@ load(RuleContext *rc, const char *system, const char *user) xmlFreeDoc(userdoc); xmlFreeDoc(systemdoc); - + return 0; } /** * rule_context_save: - * @f: - * @user: - * + * @f: + * @user: + * * Save a rule context to disk. - * - * Return value: + * + * Return value: **/ int rule_context_save(RuleContext *rc, const char *user) { g_return_val_if_fail (rc, -1); g_return_val_if_fail (user, -1); - + return RULE_CONTEXT_GET_CLASS(rc)->save(rc, user); } @@ -432,7 +432,7 @@ save(RuleContext *rc, const char *user) FilterRule *rule; struct _rule_set_map *map; int ret; - + doc = xmlNewDoc((const unsigned char *)"1.0"); /* FIXME: set character encoding to UTF-8? */ root = xmlNewDocNode(doc, NULL, (const unsigned char *)"filteroptions", NULL); @@ -452,31 +452,31 @@ save(RuleContext *rc, const char *user) } l = g_list_next(l); } - + ret = e_xml_save_file(user, doc); - + xmlFreeDoc(doc); - + return ret; } /** * rule_context_revert: - * @f: - * @user: + * @f: + * @user: * * Reverts a rule context from a user description file. Assumes the * system description file is unchanged from when it was loaded. - * - * Return value: + * + * Return value: **/ int rule_context_revert(RuleContext *rc, const char *user) { g_return_val_if_fail (rc, 0); - + d(printf("rule_context: restoring %s\n", user)); - + return RULE_CONTEXT_GET_CLASS(rc)->revert(rc, user); } @@ -525,18 +525,18 @@ revert(RuleContext *rc, const char *user) GHashTable *source_hash; xmlDocPtr userdoc; FilterRule *frule; - + rule_context_set_error(rc, NULL); - + d(printf("restoring rules %s\n", user)); - + userdoc = e_xml_parse_file (user); if (userdoc == NULL) /* clear out anythign we have? */ return 0; - + source_hash = g_hash_table_new((GHashFunc)source_hashf, (GCompareFunc)source_eqf); - + /* setup stuff we have now */ /* Note that we assume there is only 1 set of rules in a given rule context, although other parts of the code dont assume this */ @@ -550,7 +550,7 @@ revert(RuleContext *rc, const char *user) } g_hash_table_insert(rest_data->rules, frule->name, frule); } - + /* make what we have, match what we load */ set = xmlDocGetRootElement(userdoc); set = set?set->children:NULL; @@ -564,7 +564,7 @@ revert(RuleContext *rc, const char *user) d(printf("checking node: %s\n", rule->name)); if (!strcmp((char *)rule->name, "rule")) { FilterRule *part = FILTER_RULE(g_object_new(rule_map->type, NULL, NULL)); - + if (filter_rule_xml_decode(part, rule, rc) == 0) { /* use the revert data to keep track of the right rank of this rule part */ rest_data = g_hash_table_lookup(source_hash, part->source); @@ -577,7 +577,7 @@ revert(RuleContext *rc, const char *user) if (frule) { if (rc->priv->frozen == 0 && !filter_rule_eq(frule, part)) filter_rule_copy(frule, part); - + g_object_unref(part); rule_context_rank_rule(rc, frule, frule->source, rest_data->rank); g_hash_table_remove(rest_data->rules, frule->name); @@ -596,13 +596,13 @@ revert(RuleContext *rc, const char *user) } set = set->next; } - + xmlFreeDoc(userdoc); - + /* remove any we still have that weren't in the file */ g_hash_table_foreach(source_hash, (GHFunc)revert_source_remove, rc); g_hash_table_destroy(source_hash); - + return 0; } @@ -611,7 +611,7 @@ rule_context_find_part(RuleContext *rc, const char *name) { g_return_val_if_fail (rc, NULL); g_return_val_if_fail (name, NULL); - + d(printf("find part : ")); return filter_part_find_list(rc->parts, name); } @@ -620,13 +620,13 @@ FilterPart * rule_context_create_part(RuleContext *rc, const char *name) { FilterPart *part; - + g_return_val_if_fail (rc, NULL); g_return_val_if_fail (name, NULL); - + if ((part = rule_context_find_part(rc, name))) return filter_part_clone(part); - + return NULL; } @@ -634,7 +634,7 @@ FilterPart * rule_context_next_part(RuleContext *rc, FilterPart *last) { g_return_val_if_fail (rc, NULL); - + return filter_part_next_list(rc->parts, last); } @@ -642,7 +642,7 @@ FilterRule * rule_context_next_rule(RuleContext *rc, FilterRule *last, const char *source) { g_return_val_if_fail (rc, NULL); - + return filter_rule_next_list(rc->rules, last, source); } @@ -651,7 +651,7 @@ rule_context_find_rule(RuleContext *rc, const char *name, const char *source) { g_return_val_if_fail (name, NULL); g_return_val_if_fail (rc, NULL); - + return filter_rule_find_list(rc->rules, name, source); } @@ -660,7 +660,7 @@ rule_context_add_part(RuleContext *rc, FilterPart *part) { g_return_if_fail (rc); g_return_if_fail (part); - + rc->parts = g_list_append(rc->parts, part); } @@ -669,11 +669,11 @@ rule_context_add_rule(RuleContext *rc, FilterRule *new) { g_return_if_fail (rc); g_return_if_fail (new); - + d(printf("add rule '%s'\n", new->name)); - + rc->rules = g_list_append(rc->rules, new); - + if (rc->priv->frozen == 0) { g_signal_emit(rc, signals[RULE_ADDED], 0, new); g_signal_emit(rc, signals[CHANGED], 0); @@ -686,7 +686,7 @@ new_rule_response(GtkWidget *dialog, int button, RuleContext *context) if (button == GTK_RESPONSE_OK) { FilterRule *rule = g_object_get_data((GObject *) dialog, "rule"); char *user = g_object_get_data((GObject *) dialog, "path"); - + if (!filter_rule_validate(rule)) { /* no need to popup a dialog because the validate code does that. */ return; @@ -697,13 +697,13 @@ new_rule_response(GtkWidget *dialog, int button, RuleContext *context) return; } - + g_object_ref(rule); rule_context_add_rule(context, rule); if (user) rule_context_save(context, user); } - + gtk_widget_destroy(dialog); } @@ -713,38 +713,38 @@ rule_context_add_rule_gui(RuleContext *rc, FilterRule *rule, const char *title, { GtkDialog *dialog; GtkWidget *widget; - + d(printf("add rule gui '%s'\n", rule->name)); - + g_return_if_fail (rc); g_return_if_fail (rule); - + widget = filter_rule_get_widget(rule, rc); gtk_widget_show(widget); - + dialog =(GtkDialog *) gtk_dialog_new(); gtk_dialog_add_buttons(dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_has_separator (dialog, FALSE); - + gtk_window_set_title((GtkWindow *) dialog, title); gtk_window_set_default_size((GtkWindow *) dialog, 600, 400); gtk_window_set_resizable((GtkWindow *) dialog, TRUE); - + gtk_box_pack_start((GtkBox *) dialog->vbox, widget, TRUE, TRUE, 0); - + g_object_set_data_full((GObject *) dialog, "rule", rule, g_object_unref); if (path) g_object_set_data_full((GObject *) dialog, "path", g_strdup(path), g_free); - + g_signal_connect(dialog, "response", G_CALLBACK(new_rule_response), rc); - + g_object_ref(rc); - + g_object_set_data_full((GObject *) dialog, "context", rc, g_object_unref); - + gtk_widget_show((GtkWidget *) dialog); } @@ -753,11 +753,11 @@ rule_context_remove_rule(RuleContext *rc, FilterRule *rule) { g_return_if_fail (rc); g_return_if_fail (rule); - + d(printf("remove rule '%s'\n", rule->name)); - + rc->rules = g_list_remove(rc->rules, rule); - + if (rc->priv->frozen == 0) { g_signal_emit(rc, signals[RULE_REMOVED], 0, rule); g_signal_emit(rc, signals[CHANGED], 0); @@ -769,33 +769,33 @@ rule_context_rank_rule(RuleContext *rc, FilterRule *rule, const char *source, in { GList *node; int i = 0, index = 0; - + g_return_if_fail (rc); g_return_if_fail (rule); - + if (rule_context_get_rank_rule (rc, rule, source) == rank) return; - + rc->rules = g_list_remove(rc->rules, rule); node = rc->rules; while (node) { FilterRule *r = node->data; - + if (i == rank) { rc->rules = g_list_insert(rc->rules, rule, index); if (rc->priv->frozen == 0) g_signal_emit(rc, signals[CHANGED], 0); - + return; } - - index++; + + index++; if (source == NULL || (r->source && strcmp(r->source, source) == 0)) i++; - + node = node->next; } - + rc->rules = g_list_append(rc->rules, rule); if (rc->priv->frozen == 0) g_signal_emit(rc, signals[CHANGED], 0); @@ -806,27 +806,27 @@ rule_context_get_rank_rule(RuleContext *rc, FilterRule *rule, const char *source { GList *node; int i = 0; - + g_return_val_if_fail (rc, -1); g_return_val_if_fail (rule, -1); - + d(printf("getting rank of rule '%s'\n", rule->name)); - + node = rc->rules; while (node) { FilterRule *r = node->data; - + d(printf(" checking against rule '%s' rank '%d'\n", r->name, i)); - + if (r == rule) return i; - + if (source == NULL || (r->source && strcmp(r->source, source) == 0)) i++; - + node = node->next; } - + return -1; } @@ -835,26 +835,26 @@ rule_context_find_rank_rule(RuleContext *rc, int rank, const char *source) { GList *node; int i = 0; - + g_return_val_if_fail (rc, NULL); - + d(printf("getting rule at rank %d source '%s'\n", rank, source?source:"<any>")); - + node = rc->rules; while (node) { FilterRule *r = node->data; - + d(printf(" checking against rule '%s' rank '%d'\n", r->name, i)); - + if (source == NULL || (r->source && strcmp(r->source, source) == 0)) { if (rank == i) return r; i++; } - + node = node->next; } - + return NULL; } @@ -886,9 +886,9 @@ void rule_context_free_uri_list(RuleContext *rc, GList *uris) { GList *l = uris, *n; - + /* TODO: should be virtual */ - + while (l) { n = l->next; g_free(l->data); @@ -934,12 +934,12 @@ new_element(RuleContext *rc, const char *type) /** * rule_context_new_element: - * @rc: - * @name: - * + * @rc: + * @name: + * * create a new filter element based on name. - * - * Return value: + * + * Return value: **/ FilterElement * rule_context_new_element(RuleContext *rc, const char *name) diff --git a/filter/rule-context.h b/filter/rule-context.h index c65990d97e..14da2806fd 100644 --- a/filter/rule-context.h +++ b/filter/rule-context.h @@ -50,14 +50,14 @@ enum { struct _RuleContext { GObject parent_object; struct _RuleContextPrivate *priv; - + char *error; /* string version of error */ guint32 flags; /* capability flags */ GList *parts; GList *rules; - + GHashTable *part_set_map; /* map set types to part types */ GList *part_set_list; GHashTable *rule_set_map; /* map set types to rule types */ @@ -73,12 +73,12 @@ struct _RuleContextClass { int (*load) (RuleContext *rc, const char *system, const char *user); int (*save) (RuleContext *rc, const char *user); int (*revert) (RuleContext *rc, const char *user); - + GList *(*delete_uri) (RuleContext *rc, const char *uri, GCompareFunc cmp); GList *(*rename_uri) (RuleContext *rc, const char *olduri, const char *newuri, GCompareFunc cmp); FilterElement *(*new_element)(RuleContext *rc, const char *name); - + /* signals */ void (*rule_added) (RuleContext *rc, FilterRule *rule); void (*rule_removed) (RuleContext *rc, FilterRule *rule); diff --git a/filter/rule-editor.c b/filter/rule-editor.c index 8320399618..fac0f6ba4c 100644 --- a/filter/rule-editor.c +++ b/filter/rule-editor.c @@ -76,7 +76,7 @@ GtkType rule_editor_get_type (void) { static GtkType type = 0; - + if (!type) { static const GTypeInfo info = { sizeof (RuleEditorClass), @@ -89,13 +89,13 @@ rule_editor_get_type (void) 0, /* n_preallocs */ (GInstanceInitFunc) rule_editor_init, }; - + /* TODO: Remove when it works (or never will) */ enable_undo = getenv ("EVOLUTION_RULE_UNDO") != NULL; - + type = g_type_register_static (gtk_dialog_get_type (), "RuleEditor", &info, 0); } - + return type; } @@ -104,12 +104,12 @@ rule_editor_class_init (RuleEditorClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkObjectClass *object_class = (GtkObjectClass *) klass; - + parent_class = g_type_class_ref(gtk_dialog_get_type ()); - + gobject_class->finalize = rule_editor_finalise; object_class->destroy = rule_editor_destroy; - + /* override methods */ klass->set_source = set_source; klass->set_sensitive = set_sensitive; @@ -127,10 +127,10 @@ rule_editor_finalise (GObject *obj) { RuleEditor *re = (RuleEditor *)obj; RuleEditorUndo *undo, *next; - + g_object_unref (re->context); g_free (re->priv); - + undo = re->undo_log; while (undo) { next = undo->next; @@ -138,7 +138,7 @@ rule_editor_finalise (GObject *obj) g_free (undo); undo = next; } - + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -146,12 +146,12 @@ static void rule_editor_destroy (GtkObject *obj) { RuleEditor *re = (RuleEditor *) obj; - + if (re->dialog) { gtk_widget_destroy (GTK_WIDGET (re->dialog)); re->dialog = NULL; } - + ((GtkObjectClass *)(parent_class))->destroy (obj); } @@ -159,7 +159,7 @@ rule_editor_destroy (GtkObject *obj) * rule_editor_new: * * Create a new RuleEditor object. - * + * * Return value: A new #RuleEditor object. **/ RuleEditor * @@ -170,13 +170,13 @@ rule_editor_new (RuleContext *rc, const char *source, const char *label) char *filter_glade = g_build_filename (EVOLUTION_GLADEDIR, "filter.glade", NULL); - + gui = glade_xml_new (filter_glade, "rule_editor", NULL); g_free (filter_glade); rule_editor_construct (re, rc, gui, source, label); - gtk_widget_hide(glade_xml_get_widget (gui, "filter_source")); + gtk_widget_hide(glade_xml_get_widget (gui, "filter_source")); g_object_unref (gui); - + return re; } @@ -206,11 +206,11 @@ create_rule (RuleEditor *re) { FilterRule *rule = filter_rule_new (); FilterPart *part; - + /* create a rule with 1 part in it */ part = rule_context_next_part (re->context, NULL); filter_rule_add_part (rule, filter_part_clone (part)); - + return rule; } @@ -221,9 +221,9 @@ editor_destroy (RuleEditor *re, GObject *deadbeef) g_object_unref (re->edit); re->edit = NULL; } - + re->dialog = NULL; - + gtk_widget_set_sensitive (GTK_WIDGET (re), TRUE); rule_editor_set_sensitive (re); } @@ -252,7 +252,7 @@ rule_editor_play_undo (RuleEditor *re) { RuleEditorUndo *undo, *next; FilterRule *rule; - + re->undo_active = TRUE; undo = re->undo_log; re->undo_log = NULL; @@ -288,7 +288,7 @@ rule_editor_play_undo (RuleEditor *re) rule_context_rank_rule (re->context, rule, re->source, undo->rank); break; } - + g_object_unref (undo->rule); g_free (undo); undo = next; @@ -304,7 +304,7 @@ editor_response (GtkWidget *dialog, int button, RuleEditor *re) rule_editor_play_undo (re); else { RuleEditorUndo *undo, *next; - + undo = re->undo_log; re->undo_log = NULL; while (undo) { @@ -323,38 +323,38 @@ add_editor_response (GtkWidget *dialog, int button, RuleEditor *re) GtkTreeSelection *selection; GtkTreePath *path; GtkTreeIter iter; - + if (button == GTK_RESPONSE_OK) { if (!filter_rule_validate (re->edit)) { /* no need to popup a dialog because the validate code does that. */ return; } - + if (rule_context_find_rule (re->context, re->edit->name, re->edit->source)) { e_error_run((GtkWindow *)dialog, "filter:bad-name-notunique", re->edit->name, NULL); return; } - + g_object_ref (re->edit); - + gtk_list_store_append (re->model, &iter); gtk_list_store_set (re->model, &iter, 0, re->edit->name, 1, re->edit, -1); selection = gtk_tree_view_get_selection (re->list); gtk_tree_selection_select_iter (selection, &iter); - + /* scroll to the newly added row */ path = gtk_tree_model_get_path ((GtkTreeModel *) re->model, &iter); gtk_tree_view_scroll_to_cell (re->list, path, NULL, TRUE, 1.0, 0.0); gtk_tree_path_free (path); - + re->current = re->edit; rule_context_add_rule (re->context, re->current); - + g_object_ref (re->current); rule_editor_add_undo (re, RULE_EDITOR_LOG_ADD, re->current, rule_context_get_rank_rule (re->context, re->current, re->current->source), 0); } - + gtk_widget_destroy (dialog); } @@ -362,29 +362,29 @@ static void rule_add (GtkWidget *widget, RuleEditor *re) { GtkWidget *rules; - + if (re->edit != NULL) return; - + re->edit = rule_editor_create_rule (re); filter_rule_set_source (re->edit, re->source); rules = filter_rule_get_widget (re->edit, re->context); - + re->dialog = gtk_dialog_new (); gtk_dialog_add_buttons ((GtkDialog *) re->dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_has_separator ((GtkDialog *) re->dialog, FALSE); - + gtk_window_set_title ((GtkWindow *) re->dialog, _("Add Rule")); gtk_window_set_default_size (GTK_WINDOW (re->dialog), 650, 400); gtk_window_set_resizable (GTK_WINDOW (re->dialog), TRUE); gtk_window_set_transient_for ((GtkWindow *) re->dialog, (GtkWindow *) re); gtk_container_set_border_width ((GtkContainer *) re->dialog, 6); - + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (re->dialog)->vbox), rules, TRUE, TRUE, 3); - + g_signal_connect (re->dialog, "response", G_CALLBACK (add_editor_response), re); g_object_weak_ref ((GObject *) re->dialog, (GWeakNotify) editor_destroy, re); @@ -392,7 +392,7 @@ rule_add (GtkWidget *widget, RuleEditor *re) dialog_rule_changed (re->edit, re->dialog); gtk_widget_set_sensitive (GTK_WIDGET (re), FALSE); - + gtk_widget_show (re->dialog); } @@ -403,37 +403,37 @@ edit_editor_response (GtkWidget *dialog, int button, RuleEditor *re) GtkTreePath *path; GtkTreeIter iter; int pos; - + if (button == GTK_RESPONSE_OK) { if (!filter_rule_validate (re->edit)) { /* no need to popup a dialog because the validate code does that. */ return; } - + rule = rule_context_find_rule (re->context, re->edit->name, re->edit->source); if (rule != NULL && rule != re->current) { e_error_run((GtkWindow *)dialog, "filter:bad-name-notunique", rule->name, NULL); - + return; } - + pos = rule_context_get_rank_rule (re->context, re->current, re->source); if (pos != -1) { path = gtk_tree_path_new (); gtk_tree_path_append_index (path, pos); gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path); gtk_tree_path_free (path); - + gtk_list_store_set (re->model, &iter, 0, re->edit->name, -1); - + rule_editor_add_undo (re, RULE_EDITOR_LOG_EDIT, filter_rule_clone (re->current), pos, 0); - + /* replace the old rule with the new rule */ filter_rule_copy (re->current, re->edit); } } - + gtk_widget_destroy (dialog); } @@ -441,29 +441,29 @@ static void rule_edit (GtkWidget *widget, RuleEditor *re) { GtkWidget *rules; - + if (re->current == NULL || re->edit != NULL) return; - + re->edit = filter_rule_clone (re->current); - + rules = filter_rule_get_widget (re->edit, re->context); - + re->dialog = gtk_dialog_new (); gtk_dialog_add_buttons ((GtkDialog *) re->dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_has_separator ((GtkDialog *) re->dialog, FALSE); - + gtk_window_set_title ((GtkWindow *) re->dialog, _("Edit Rule")); gtk_window_set_default_size (GTK_WINDOW (re->dialog), 650, 400); gtk_window_set_resizable (GTK_WINDOW (re->dialog), TRUE); gtk_widget_set_parent_window (GTK_WIDGET (re->dialog), GTK_WIDGET (re)->window); gtk_container_set_border_width ((GtkContainer *) re->dialog, 6); - + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (re->dialog)->vbox), rules, TRUE, TRUE, 3); - + g_signal_connect (re->dialog, "response", G_CALLBACK (edit_editor_response), re); g_object_weak_ref ((GObject *) re->dialog, (GWeakNotify) editor_destroy, re); @@ -471,7 +471,7 @@ rule_edit (GtkWidget *widget, RuleEditor *re) dialog_rule_changed (re->edit, re->dialog); gtk_widget_set_sensitive (GTK_WIDGET (re), FALSE); - + gtk_widget_show (re->dialog); } @@ -482,50 +482,50 @@ rule_delete (GtkWidget *widget, RuleEditor *re) GtkTreePath *path; GtkTreeIter iter; int pos, len; - + d(printf ("delete rule\n")); pos = rule_context_get_rank_rule (re->context, re->current, re->source); if (pos != -1) { rule_context_remove_rule (re->context, re->current); - + path = gtk_tree_path_new (); gtk_tree_path_append_index (path, pos); gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path); gtk_list_store_remove (re->model, &iter); gtk_tree_path_free (path); - + rule_editor_add_undo (re, RULE_EDITOR_LOG_REMOVE, re->current, rule_context_get_rank_rule (re->context, re->current, re->current->source), 0); -#if 0 +#if 0 g_object_unref (re->current); #endif re->current = NULL; - + /* now select the next rule */ len = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (re->model), NULL); pos = pos >= len ? len - 1 : pos; - + if (pos >= 0) { path = gtk_tree_path_new (); gtk_tree_path_append_index (path, pos); gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path); gtk_tree_path_free (path); - + /* select the new row */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (re->list)); gtk_tree_selection_select_iter (selection, &iter); - + /* scroll to the selected row */ path = gtk_tree_model_get_path ((GtkTreeModel *) re->model, &iter); gtk_tree_view_scroll_to_cell (re->list, path, NULL, FALSE, 0.0, 0.0); gtk_tree_path_free (path); - + /* update our selection state */ cursor_changed (re->list, re); return; } } - + rule_editor_set_sensitive (re); } @@ -536,38 +536,38 @@ rule_move (RuleEditor *re, int from, int to) GtkTreePath *path; GtkTreeIter iter; FilterRule *rule; - + g_object_ref (re->current); rule_editor_add_undo (re, RULE_EDITOR_LOG_RANK, re->current, rule_context_get_rank_rule (re->context, re->current, re->source), to); - + d(printf ("moving %d to %d\n", from, to)); rule_context_rank_rule (re->context, re->current, re->source, to); - + path = gtk_tree_path_new (); gtk_tree_path_append_index (path, from); gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path); gtk_tree_path_free (path); - + gtk_tree_model_get (GTK_TREE_MODEL (re->model), &iter, 1, &rule, -1); g_return_if_fail (rule != NULL); - + /* remove and then re-insert the row at the new location */ gtk_list_store_remove (re->model, &iter); gtk_list_store_insert (re->model, &iter, to); - + /* set the data on the row */ gtk_list_store_set (re->model, &iter, 0, rule->name, 1, rule, -1); - + /* select the row */ selection = gtk_tree_view_get_selection (re->list); gtk_tree_selection_select_iter (selection, &iter); - + /* scroll to the selected row */ path = gtk_tree_model_get_path ((GtkTreeModel *) re->model, &iter); gtk_tree_view_scroll_to_cell (re->list, path, NULL, FALSE, 0.0, 0.0); gtk_tree_path_free (path); - + rule_editor_set_sensitive (re); } @@ -586,7 +586,7 @@ static void rule_up (GtkWidget *widget, RuleEditor *re) { int pos; - + d(printf ("up rule\n")); pos = rule_context_get_rank_rule (re->context, re->current, re->source); if (pos > 0) @@ -597,7 +597,7 @@ static void rule_down (GtkWidget *widget, RuleEditor *re) { int pos; - + d(printf ("down rule\n")); pos = rule_context_get_rank_rule (re->context, re->current, re->source); if (pos >= 0) @@ -642,17 +642,17 @@ set_sensitive (RuleEditor *re) { FilterRule *rule = NULL; int index = -1, count = 0; - + while ((rule = rule_context_next_rule (re->context, rule, re->source))) { if (rule == re->current) index = count; count++; } - + d(printf("index = %d count=%d\n", index, count)); - + count--; - + gtk_widget_set_sensitive (GTK_WIDGET (re->priv->buttons[BUTTON_EDIT]), index != -1); gtk_widget_set_sensitive (GTK_WIDGET (re->priv->buttons[BUTTON_DELETE]), index != -1); gtk_widget_set_sensitive (GTK_WIDGET (re->priv->buttons[BUTTON_TOP]), index > 0); @@ -675,13 +675,13 @@ cursor_changed (GtkTreeView *treeview, RuleEditor *re) GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; - + selection = gtk_tree_view_get_selection (re->list); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_tree_model_get (GTK_TREE_MODEL (re->model), &iter, 1, &re->current, -1); - + g_return_if_fail (re->current); - + rule_editor_set_sensitive (re); } } @@ -692,9 +692,9 @@ double_click (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *colum GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; - + selection = gtk_tree_view_get_selection (re->list); - if (gtk_tree_selection_get_selected (selection, &model, &iter)) + if (gtk_tree_selection_get_selected (selection, &model, &iter)) gtk_tree_model_get (GTK_TREE_MODEL (re->model), &iter, 1, &re->current, -1); if (re->current) @@ -706,16 +706,16 @@ set_source (RuleEditor *re, const char *source) { FilterRule *rule = NULL; GtkTreeIter iter; - + gtk_list_store_clear (re->model); - + d(printf("Checking for rules that are of type %s\n", source ? source : "<nil>")); while ((rule = rule_context_next_rule (re->context, rule, source)) != NULL) { d(printf("Adding row '%s'\n", rule->name)); gtk_list_store_append (re->model, &iter); gtk_list_store_set (re->model, &iter, 0, rule->name, 1, rule, -1); } - + g_free (re->source); re->source = g_strdup (source); re->current = NULL; @@ -732,34 +732,34 @@ rule_editor_treeview_new (char *widget_name, char *string1, char *string2, int i GtkTreeSelection *selection; GtkCellRenderer *renderer; GtkListStore *model; - + scrolled = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - + model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); table = gtk_tree_view_new_with_model ((GtkTreeModel *) model); gtk_tree_view_set_headers_visible ((GtkTreeView *) table, FALSE); - + renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes ((GtkTreeView *) table, -1, _("Rule name"), renderer, "text", 0, NULL); - + selection = gtk_tree_view_get_selection ((GtkTreeView *) table); gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - + gtk_container_add (GTK_CONTAINER (scrolled), table); - + g_object_set_data ((GObject *) scrolled, "table", table); g_object_set_data ((GObject *) scrolled, "model", model); - + gtk_widget_show (scrolled); gtk_widget_show (table); g_object_unref (model); - + return scrolled; } @@ -769,10 +769,10 @@ rule_editor_construct (RuleEditor *re, RuleContext *context, GladeXML *gui, cons GtkWidget *w; int i; char *tmp; - + re->context = context; g_object_ref (context); - + gtk_window_set_resizable ((GtkWindow *) re, TRUE); gtk_window_set_default_size ((GtkWindow *) re, 350, 400); gtk_widget_realize ((GtkWidget *) re); @@ -785,11 +785,11 @@ rule_editor_construct (RuleEditor *re, RuleContext *context, GladeXML *gui, cons re->priv->buttons[i] = (GtkButton *) (w = glade_xml_get_widget (gui, edit_buttons[i].name)); g_signal_connect (w, "clicked", edit_buttons[i].func, re); } - + w = glade_xml_get_widget (gui, "rule_list"); re->list = (GtkTreeView *) g_object_get_data ((GObject *) w, "table"); re->model = (GtkListStore *) g_object_get_data ((GObject *) w, "model"); - + g_signal_connect (re->list, "cursor-changed", G_CALLBACK (cursor_changed), re); g_signal_connect (re->list, "row-activated", G_CALLBACK (double_click), re); diff --git a/filter/rule-editor.h b/filter/rule-editor.h index e7a21eb157..90a979205a 100644 --- a/filter/rule-editor.h +++ b/filter/rule-editor.h @@ -43,33 +43,33 @@ typedef struct _RuleEditorUndo RuleEditorUndo; struct _RuleEditor { GtkDialog parent_object; - + GtkListStore *model; GtkTreeView *list; - + RuleContext *context; FilterRule *current; FilterRule *edit; /* for editing/adding rules, so we only do 1 at a time */ - + GtkWidget *dialog; - + char *source; - + struct _RuleEditorUndo *undo_log; /* cancel/undo log */ unsigned int undo_active:1; /* we're performing undo */ - + struct _RuleEditorPrivate *priv; }; struct _RuleEditorClass { GtkDialogClass parent_class; - + /* virtual methods */ void (*set_sensitive) (RuleEditor *); void (*set_source) (RuleEditor *, const char *source); - + FilterRule *(*create_rule) (RuleEditor *); - + /* signals */ }; @@ -82,7 +82,7 @@ enum { struct _RuleEditorUndo { struct _RuleEditorUndo *next; - + unsigned int type; FilterRule *rule; int rank; |