aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-10-24 10:10:20 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-10-24 10:10:20 +0800
commitbdb308067c223640c2c14ebd92205e0ae1d20326 (patch)
tree8bbfe199baa3ffaeb33eac81176e6ac11ad9ebbf
parent067991f6b4eae28762f76637e37be092d1232f2e (diff)
downloadgsoc2013-evolution-bdb308067c223640c2c14ebd92205e0ae1d20326.tar.gz
gsoc2013-evolution-bdb308067c223640c2c14ebd92205e0ae1d20326.tar.zst
gsoc2013-evolution-bdb308067c223640c2c14ebd92205e0ae1d20326.zip
Set the remove button insensitive if there is only 1 action left.
2000-10-23 Jeffrey Stedfast <fejj@helixcode.com> * filter-filter.c (less_parts): Set the remove button insensitive if there is only 1 action left. (more_parts): Set the remove button sensitive (since we now have 2 or more actions). (get_widget): If there is only 1 action, disable the remove button. * filter-rule.c (xml_encode): If there is a defined source, don't set it to "incoming", set it to whatever the source is! (less_parts): Set the remove button insensitive if there is only 1 criterion left. (more_parts): Set the remove button sensitive (since we now have 2 or more criterion). (get_widget): If there is no name for the filter then set it to "Untitled", highlight it, and grab the focus. If there is only 1 criterion, disable the remove button. * filter-editor.c, vfolder-editor.c: GUI fixes here and there as well as some consistancy fixes between them. * filter-driver.c (filter_driver_filter_mbox): Updated to send the source url to filter_driver_filter_message() (filter_driver_filter_folder): Updated to send the source url of the folder to filter_driver_filter_message() (filter_driver_filter_message): Now takes a source_url argument that represents the url of the folder the message is coming from (so that we may filter based upon that information). svn path=/trunk/; revision=6138
-rw-r--r--filter/ChangeLog30
-rw-r--r--filter/filter-driver.c20
-rw-r--r--filter/filter-driver.h3
-rw-r--r--filter/filter-editor.c62
-rw-r--r--filter/filter-filter.c39
-rw-r--r--filter/filter-rule.c569
-rw-r--r--filter/vfolder-editor.c302
7 files changed, 583 insertions, 442 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog
index 0695f97cfd..a5568df3ff 100644
--- a/filter/ChangeLog
+++ b/filter/ChangeLog
@@ -1,3 +1,33 @@
+2000-10-23 Jeffrey Stedfast <fejj@helixcode.com>
+
+ * filter-filter.c (less_parts): Set the remove button insensitive
+ if there is only 1 action left.
+ (more_parts): Set the remove button sensitive (since we now have 2
+ or more actions).
+ (get_widget): If there is only 1 action, disable the remove
+ button.
+
+ * filter-rule.c (xml_encode): If there is a defined source, don't
+ set it to "incoming", set it to whatever the source is!
+ (less_parts): Set the remove button insensitive if there is only 1
+ criterion left.
+ (more_parts): Set the remove button sensitive (since we now have 2
+ or more criterion).
+ (get_widget): If there is no name for the filter then set it to
+ "Untitled", highlight it, and grab the focus. If there is only 1
+ criterion, disable the remove button.
+
+ * filter-editor.c, vfolder-editor.c: GUI fixes here and there as
+ well as some consistancy fixes between them.
+
+ * filter-driver.c (filter_driver_filter_mbox): Updated to send the
+ source url to filter_driver_filter_message()
+ (filter_driver_filter_folder): Updated to send the source url of
+ the folder to filter_driver_filter_message()
+ (filter_driver_filter_message): Now takes a source_url argument
+ that represents the url of the folder the message is coming from
+ (so that we may filter based upon that information).
+
2000-10-23 Christopher James Lahey <clahey@helixcode.com>
* filter.glade: Fixed these widgets to resize properly.
diff --git a/filter/filter-driver.c b/filter/filter-driver.c
index d1f132e428..9bff98fac4 100644
--- a/filter/filter-driver.c
+++ b/filter/filter-driver.c
@@ -510,6 +510,7 @@ void
filter_driver_filter_mbox (FilterDriver *driver, const char *mbox, const char *source, CamelException *ex)
{
CamelMimeParser *mp = NULL;
+ char *source_url = NULL;
int fd = -1;
int i = 0;
struct stat st;
@@ -529,6 +530,9 @@ filter_driver_filter_mbox (FilterDriver *driver, const char *mbox, const char *s
goto fail;
}
fd = -1;
+
+ source_url = g_strdup_printf ("file://%s", mbox);
+
while (camel_mime_parser_step (mp, 0, 0) == HSCAN_FROM) {
CamelMimeMessage *msg;
int pc;
@@ -544,7 +548,7 @@ filter_driver_filter_mbox (FilterDriver *driver, const char *mbox, const char *s
goto fail;
}
- filter_driver_filter_message (driver, msg, NULL, source, ex);
+ filter_driver_filter_message (driver, msg, NULL, source_url, source, ex);
camel_object_unref (CAMEL_OBJECT (msg));
if (camel_exception_is_set (ex)) {
report_status (driver, FILTER_STATUS_END, "Failed message %d", i);
@@ -558,6 +562,7 @@ filter_driver_filter_mbox (FilterDriver *driver, const char *mbox, const char *s
camel_mime_parser_step (mp, 0, 0);
}
fail:
+ g_free (source_url);
if (fd != -1)
close (fd);
if (mp)
@@ -573,6 +578,11 @@ filter_driver_filter_folder (FilterDriver *driver, CamelFolder *folder, const ch
int freeuids = FALSE;
CamelMimeMessage *message;
const CamelMessageInfo *info;
+ char *source_url, *service_url;
+
+ service_url = camel_service_get_url (CAMEL_SERVICE (camel_folder_get_parent_store (folder)));
+ source_url = g_strdup_printf ("%s%s", service_url, camel_folder_get_full_name (folder));
+ g_free (service_url);
if (uids == NULL) {
uids = camel_folder_get_uids (folder);
@@ -593,7 +603,7 @@ filter_driver_filter_folder (FilterDriver *driver, CamelFolder *folder, const ch
else
info = NULL;
- filter_driver_filter_message (driver, message, (CamelMessageInfo *)info, source, ex);
+ filter_driver_filter_message (driver, message, (CamelMessageInfo *)info, source_url, source, ex);
if (camel_exception_is_set (ex)) {
report_status (driver, FILTER_STATUS_END, "Failed at message %d of %d", i+1, uids->len);
break;
@@ -608,11 +618,13 @@ filter_driver_filter_folder (FilterDriver *driver, CamelFolder *folder, const ch
if (freeuids)
camel_folder_free_uids (folder, uids);
+
+ g_free (source_url);
}
void
filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, CamelMessageInfo *info,
- const char *source, CamelException *ex)
+ const char *source_url, const char *source, CamelException *ex)
{
struct _FilterDriverPrivate *p = _PRIVATE (driver);
ESExpResult *r;
@@ -657,7 +669,7 @@ filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, C
d(fprintf (stderr, "applying rule %s\n action %s\n", fsearch->str, faction->str));
mail_tool_camel_lock_up ();
- matched = filter_message_search (p->message, p->info, source, fsearch->str, p->ex);
+ matched = filter_message_search (p->message, p->info, source_url, fsearch->str, p->ex);
mail_tool_camel_lock_down ();
if (matched) {
diff --git a/filter/filter-driver.h b/filter/filter-driver.h
index 1da1fc37ff..471118631e 100644
--- a/filter/filter-driver.h
+++ b/filter/filter-driver.h
@@ -2,6 +2,7 @@
* Copyright (C) 2000 Helix Code Inc.
*
* Authors: Michael Zucchi <notzed@helixcode.com>
+ * Jeffrey Stedfast <fejj@helixcode.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -70,7 +71,7 @@ void filter_driver_set_default_folder (FilterDriver *d, CamelFolder *def);
/* filter a message - returns TRUE if the message was filtered into some location other than inbox */
void filter_driver_filter_message (FilterDriver *driver, CamelMimeMessage *message, CamelMessageInfo *info,
- const char *source, CamelException *ex);
+ const char *source_url, const char *source, CamelException *ex);
void filter_driver_filter_mbox (FilterDriver *driver, const char *mbox, const char *source, CamelException *ex);
void filter_driver_filter_folder (FilterDriver *driver, CamelFolder *folder, const char *source,
GPtrArray *uids, gboolean remove, CamelException *ex);
diff --git a/filter/filter-editor.c b/filter/filter-editor.c
index 4b86317141..776fd740ac 100644
--- a/filter/filter-editor.c
+++ b/filter/filter-editor.c
@@ -2,6 +2,7 @@
* Copyright (C) 2000 Helix Code Inc.
*
* Authors: Not Zed <notzed@lostzed.mmc.com.au>
+ * Jeffrey Stedfast <fejj@helixcode.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
@@ -63,7 +64,7 @@ filter_editor_get_type (void)
(GtkArgGetFunc)NULL
};
- type = gtk_type_unique(gnome_dialog_get_type (), &type_info);
+ type = gtk_type_unique (gnome_dialog_get_type (), &type_info);
}
return type;
@@ -75,20 +76,20 @@ filter_editor_class_init (FilterEditorClass *class)
GtkObjectClass *object_class;
object_class = (GtkObjectClass *)class;
- parent_class = gtk_type_class(gnome_dialog_get_type ());
-
+ parent_class = gtk_type_class (gnome_dialog_get_type ());
+
object_class->finalize = filter_editor_finalise;
/* override methods */
-
+
/* signals */
-
- gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
}
static void
filter_editor_init (FilterEditor *o)
{
- o->priv = g_malloc0(sizeof(*o->priv));
+ o->priv = g_malloc0 (sizeof (*o->priv));
}
static void
@@ -109,7 +110,7 @@ filter_editor_finalise (GtkObject *obj)
FilterEditor *
filter_editor_new (void)
{
- FilterEditor *o = (FilterEditor *)gtk_type_new(filter_editor_get_type ());
+ FilterEditor *o = (FilterEditor *)gtk_type_new (filter_editor_get_type ());
return o;
}
@@ -155,9 +156,13 @@ rule_add (GtkWidget *widget, struct _editor_data *data)
filter_filter_add_action (rule, filter_part_clone (part));
w = filter_rule_get_widget ((FilterRule *)rule, data->f);
- gd = gnome_dialog_new (_("Add Rule"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL);
- gtk_window_set_policy(GTK_WINDOW(gd), FALSE, TRUE, FALSE);
+ gd = gnome_dialog_new (_("Add Filter Rule"),
+ GNOME_STOCK_BUTTON_OK,
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
+ gtk_window_set_policy (GTK_WINDOW (gd), FALSE, TRUE, FALSE);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (gd)->vbox), w, TRUE, TRUE, 0);
+
gtk_widget_show (gd);
result = gnome_dialog_run_and_close (GNOME_DIALOG (gd));
@@ -174,11 +179,13 @@ rule_add (GtkWidget *widget, struct _editor_data *data)
gtk_widget_show (GTK_WIDGET (item));
l = g_list_append (l, item);
+
gtk_list_append_items (data->list, l);
gtk_list_select_child (data->list, GTK_WIDGET (item));
data->current = (FilterRule *)rule;
rule_context_add_rule (data->f, (FilterRule *)rule);
+
set_sensitive (data);
} else {
gtk_object_unref (GTK_OBJECT (rule));
@@ -197,18 +204,23 @@ rule_edit (GtkWidget *widget, struct _editor_data *data)
d(printf ("edit rule\n"));
rule = data->current;
w = filter_rule_get_widget (rule, data->f);
- gd = gnome_dialog_new(_("Edit Rule"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL);
- gtk_window_set_policy(GTK_WINDOW(gd), FALSE, TRUE, FALSE);
+ gd = gnome_dialog_new (_("Edit Filter Rule"),
+ GNOME_STOCK_BUTTON_OK,
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
+ gtk_window_set_policy (GTK_WINDOW (gd), FALSE, TRUE, FALSE);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (gd)->vbox), w, TRUE, TRUE, 0);
+
gtk_widget_show (gd);
+
result = gnome_dialog_run_and_close (GNOME_DIALOG (gd));
if (result == 0) {
- pos = rule_context_get_rank_rule(data->f, data->current, data->current_source);
+ pos = rule_context_get_rank_rule (data->f, data->current, data->current_source);
if (pos != -1) {
GtkListItem *item = g_list_nth_data (data->list->children, pos);
- gchar *s = e_utf8_to_gtk_string ((GtkWidget *) item, data->current->name);
- gtk_label_set_text((GtkLabel *)(((GtkBin *)item)->child), s);
+ gchar *s = e_utf8_to_gtk_string (GTK_WIDGET (item), data->current->name);
+ gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), s);
g_free (s);
}
}
@@ -220,7 +232,7 @@ rule_delete (GtkWidget *widget, struct _editor_data *data)
int pos;
GList *l;
GtkListItem *item;
-
+
d(printf("ddelete rule\n"));
pos = rule_context_get_rank_rule(data->f, data->current, data->current_source);
if (pos != -1) {
@@ -234,6 +246,7 @@ rule_delete (GtkWidget *widget, struct _editor_data *data)
gtk_object_unref (GTK_OBJECT (data->current));
data->current = NULL;
}
+
set_sensitive (data);
}
@@ -260,9 +273,9 @@ rule_up (GtkWidget *widget, struct _editor_data *data)
int pos;
d(printf("up rule\n"));
- pos = rule_context_get_rank_rule(data->f, data->current, data->current_source);
+ pos = rule_context_get_rank_rule (data->f, data->current, data->current_source);
if (pos > 0) {
- rule_move (data, pos, pos-1);
+ rule_move (data, pos, pos - 1);
}
}
@@ -272,8 +285,8 @@ rule_down (GtkWidget *widget, struct _editor_data *data)
int pos;
d(printf ("down rule\n"));
- pos = rule_context_get_rank_rule(data->f, data->current, data->current_source);
- rule_move (data, pos, pos+1);
+ pos = rule_context_get_rank_rule (data->f, data->current, data->current_source);
+ rule_move (data, pos, pos + 1);
}
static struct {
@@ -295,11 +308,14 @@ set_sensitive (struct _editor_data *data)
while ((rule = rule_context_next_rule (data->f, rule, data->current_source))) {
if (rule == data->current)
- index=count;
+ index = count;
count++;
}
+
d(printf ("index = %d count=%d\n", index, count));
+
count--;
+
gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_EDIT]), index != -1);
gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_DELETE]), index != -1);
gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_UP]), index > 0);
@@ -312,7 +328,7 @@ select_rule (GtkWidget *w, GtkWidget *child, struct _editor_data *data)
data->current = gtk_object_get_data (GTK_OBJECT (child), "rule");
if (data->current)
- d(printf ("seledct rule: %s\n", data->current->name));
+ d(printf ("selected rule: %s\n", data->current->name));
else
d(printf ("bad data?\n"));
@@ -418,6 +434,8 @@ filter_editor_construct (struct _FilterContext *f)
gtk_signal_connect (GTK_OBJECT (w), "button_press_event", double_click, data);
select_source (GTK_MENU_ITEM (firstitem), data);
+ set_sensitive (data);
+
gtk_object_unref (GTK_OBJECT (gui));
return d;
diff --git a/filter/filter-filter.c b/filter/filter-filter.c
index 12d7af2f19..145f5f6d92 100644
--- a/filter/filter-filter.c
+++ b/filter/filter-filter.c
@@ -2,7 +2,7 @@
* Copyright (C) 2000 Helix Code Inc.
*
* Authors: Not Zed <notzed@lostzed.mmc.com.au>
- * Jeffrey Stedfasr <fejj@helixcode.com>
+ * Jeffrey Stedfast <fejj@helixcode.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
@@ -150,7 +150,7 @@ void
filter_filter_replace_action (FilterFilter *fr, FilterPart *fp, FilterPart *new)
{
GList *l;
-
+
l = g_list_find (fr->actions, fp);
if (l) {
l->data = new;
@@ -336,7 +336,7 @@ struct _rule_data {
};
static void
-less_parts (GtkWidget *widget, struct _rule_data *data)
+less_parts (GtkWidget *button, struct _rule_data *data)
{
GList *l;
FilterPart *part;
@@ -356,10 +356,14 @@ less_parts (GtkWidget *widget, struct _rule_data *data)
l = g_list_last (GTK_BOX (data->parts)->children);
w = ((GtkBoxChild *) l->data)->widget;
gtk_container_remove (GTK_CONTAINER (data->parts), w);
+
+ /* if there's only 1 action, we can't remove anymore so set insensitive */
+ if (g_list_length (((FilterFilter *)data->fr)->actions) == 1)
+ gtk_widget_set_sensitive (button, FALSE);
}
static void
-more_parts (GtkWidget *widget, struct _rule_data *data)
+more_parts (GtkWidget *button, struct _rule_data *data)
{
FilterPart *new;
GtkWidget *w;
@@ -372,6 +376,10 @@ more_parts (GtkWidget *widget, struct _rule_data *data)
w = get_rule_part_widget (data->f, new, data->fr);
gtk_box_pack_start (GTK_BOX (data->parts), w, FALSE, FALSE, 0);
}
+
+ /* set the "Remove action" button sensitive */
+ w = gtk_object_get_data (GTK_OBJECT (button), "remove");
+ gtk_widget_set_sensitive (w, TRUE);
}
static GtkWidget *
@@ -380,7 +388,7 @@ get_widget (FilterRule *fr, struct _RuleContext *f)
GtkWidget *widget;
GtkWidget *parts, *inframe;
GtkWidget *hbox;
- GtkWidget *button, *pixmap;
+ GtkWidget *add, *remove, *pixmap;
GtkWidget *w;
GtkWidget *frame;
GtkWidget *scrolledwindow;
@@ -406,16 +414,21 @@ get_widget (FilterRule *fr, struct _RuleContext *f)
hbox = gtk_hbox_new (FALSE, 3);
pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_ADD);
- button = gnome_pixmap_button (pixmap, _("Add action"));
- gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
- gtk_signal_connect (GTK_OBJECT (button), "clicked", more_parts, data);
- gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 3);
+ add = gnome_pixmap_button (pixmap, _("Add action"));
+ gtk_button_set_relief (GTK_BUTTON (add), GTK_RELIEF_NONE);
+ gtk_signal_connect (GTK_OBJECT (add), "clicked", more_parts, data);
+ gtk_box_pack_start (GTK_BOX (hbox), add, FALSE, FALSE, 3);
pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_REMOVE);
- button = gnome_pixmap_button (pixmap, _("Remove action"));
- gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
- gtk_signal_connect (GTK_OBJECT (button), "clicked", less_parts, data);
- gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 3);
+ remove = gnome_pixmap_button (pixmap, _("Remove action"));
+ gtk_object_set_data (GTK_OBJECT (add), "remove", remove);
+ gtk_button_set_relief (GTK_BUTTON (remove), GTK_RELIEF_NONE);
+ gtk_signal_connect (GTK_OBJECT (remove), "clicked", less_parts, data);
+ gtk_box_pack_start (GTK_BOX (hbox), remove, FALSE, FALSE, 3);
+
+ /* if we only have 1 action, then we can't remove any more so disable this */
+ if (g_list_length (ff->actions) == 1)
+ gtk_widget_set_sensitive (remove, FALSE);
gtk_box_pack_start (GTK_BOX (inframe), hbox, FALSE, FALSE, 3);
diff --git a/filter/filter-rule.c b/filter/filter-rule.c
index c42f169f3e..4a1573e4c9 100644
--- a/filter/filter-rule.c
+++ b/filter/filter-rule.c
@@ -30,14 +30,14 @@
#define d(x)
-static xmlNodePtr xml_encode(FilterRule *);
-static int xml_decode(FilterRule *, xmlNodePtr, RuleContext *);
-static void build_code(FilterRule *, GString * out);
-static GtkWidget *get_widget(FilterRule * fr, struct _RuleContext *f);
+static xmlNodePtr xml_encode (FilterRule *);
+static int xml_decode (FilterRule *, xmlNodePtr, RuleContext *);
+static void build_code (FilterRule *, GString * out);
+static GtkWidget *get_widget (FilterRule * fr, struct _RuleContext *f);
-static void filter_rule_class_init(FilterRuleClass * class);
-static void filter_rule_init(FilterRule * gspaper);
-static void filter_rule_finalise(GtkObject * obj);
+static void filter_rule_class_init (FilterRuleClass * class);
+static void filter_rule_init (FilterRule * gspaper);
+static void filter_rule_finalise (GtkObject * obj);
#define _PRIVATE(x) (((FilterRule *)(x))->priv)
@@ -53,72 +53,73 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-guint filter_rule_get_type(void)
+guint
+filter_rule_get_type ()
{
static guint type = 0;
-
+
if (!type) {
GtkTypeInfo type_info = {
"FilterRule",
- sizeof(FilterRule),
- sizeof(FilterRuleClass),
+ sizeof (FilterRule),
+ sizeof (FilterRuleClass),
(GtkClassInitFunc) filter_rule_class_init,
(GtkObjectInitFunc) filter_rule_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL
};
-
- type = gtk_type_unique(gtk_object_get_type(), &type_info);
+
+ type = gtk_type_unique (gtk_object_get_type(), &type_info);
}
-
+
return type;
}
static void
-filter_rule_class_init(FilterRuleClass * class)
+filter_rule_class_init (FilterRuleClass * class)
{
GtkObjectClass *object_class;
-
+
object_class = (GtkObjectClass *) class;
- parent_class = gtk_type_class(gtk_object_get_type());
-
+ parent_class = gtk_type_class (gtk_object_get_type());
+
object_class->finalize = filter_rule_finalise;
-
+
/* override methods */
class->xml_encode = xml_encode;
class->xml_decode = xml_decode;
class->build_code = build_code;
class->get_widget = get_widget;
-
+
/* signals */
-
- gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
}
static void
-filter_rule_init(FilterRule * o)
+filter_rule_init (FilterRule * o)
{
- o->priv = g_malloc0(sizeof(*o->priv));
+ o->priv = g_malloc0 (sizeof (*o->priv));
}
static void
-unref_list(GList * l)
+unref_list (GList * l)
{
while (l) {
- gtk_object_unref(GTK_OBJECT(l->data));
- l = g_list_next(l);
+ gtk_object_unref (GTK_OBJECT (l->data));
+ l = g_list_next (l);
}
}
static void
-filter_rule_finalise(GtkObject * obj)
+filter_rule_finalise (GtkObject * obj)
{
FilterRule *o = (FilterRule *) obj;
- g_free(o->name);
- g_free(o->source);
- unref_list(o->parts);
-
+ g_free (o->name);
+ g_free (o->source);
+ unref_list (o->parts);
+
((GtkObjectClass *) (parent_class))->finalize(obj);
}
@@ -130,196 +131,205 @@ filter_rule_finalise(GtkObject * obj)
* Return value: A new #FilterRule object.
**/
FilterRule *
-filter_rule_new(void)
+filter_rule_new ()
{
- FilterRule *o = (FilterRule *) gtk_type_new(filter_rule_get_type());
-
+ FilterRule *o = (FilterRule *) gtk_type_new (filter_rule_get_type());
+
return o;
}
void
-filter_rule_set_name(FilterRule * fr, const char *name)
+filter_rule_set_name (FilterRule *fr, const char *name)
{
- g_free(fr->name);
- fr->name = g_strdup(name);
+ g_free (fr->name);
+ fr->name = g_strdup (name);
}
void
-filter_rule_set_source(FilterRule * fr, const char *source)
+filter_rule_set_source (FilterRule *fr, const char *source)
{
- g_free(fr->source);
- fr->source = g_strdup(source);
+ g_free (fr->source);
+ fr->source = g_strdup (source);
}
-xmlNodePtr filter_rule_xml_encode(FilterRule * fr)
+xmlNodePtr
+filter_rule_xml_encode (FilterRule *fr)
{
return ((FilterRuleClass *) ((GtkObject *) fr)->klass)->xml_encode(fr);
}
static xmlNodePtr
-xml_encode(FilterRule * fr)
+xml_encode (FilterRule *fr)
{
xmlNodePtr node, set, work;
GList *l;
-
- node = xmlNewNode(NULL, "rule");
+
+ node = xmlNewNode (NULL, "rule");
switch (fr->grouping) {
case FILTER_GROUP_ALL:
- xmlSetProp(node, "grouping", "all");
+ xmlSetProp (node, "grouping", "all");
break;
case FILTER_GROUP_ANY:
- xmlSetProp(node, "grouping", "any");
+ xmlSetProp (node, "grouping", "any");
break;
}
-
+
if (fr->source) {
- xmlSetProp(node, "source", "incoming");
+ xmlSetProp (node, "source", fr->source);
+ } else {
+ /* set to the default filter type */
+ xmlSetProp (node, "source", "incoming");
}
-
+
if (fr->name) {
- work = xmlNewNode(NULL, "title");
- xmlNodeSetContent(work, fr->name);
- xmlAddChild(node, work);
+ work = xmlNewNode (NULL, "title");
+ xmlNodeSetContent (work, fr->name);
+ xmlAddChild (node, work);
}
- set = xmlNewNode(NULL, "partset");
- xmlAddChild(node, set);
+
+ set = xmlNewNode (NULL, "partset");
+ xmlAddChild (node, set);
l = fr->parts;
while (l) {
- work = filter_part_xml_encode((FilterPart *) l->data);
- xmlAddChild(set, work);
- l = g_list_next(l);
+ work = filter_part_xml_encode ((FilterPart *) l->data);
+ xmlAddChild (set, work);
+ l = g_list_next (l);
}
+
return node;
}
static void
-load_set(xmlNodePtr node, FilterRule * fr, RuleContext * f)
+load_set (xmlNodePtr node, FilterRule *fr, RuleContext *f)
{
xmlNodePtr work;
char *rulename;
FilterPart *part;
-
+
work = node->childs;
while (work) {
- if (!strcmp(work->name, "part")) {
- rulename = xmlGetProp(work, "name");
- part = rule_context_find_part(f, rulename);
+ if (!strcmp (work->name, "part")) {
+ rulename = xmlGetProp (work, "name");
+ part = rule_context_find_part (f, rulename);
if (part) {
- part = filter_part_clone(part);
- filter_part_xml_decode(part, work);
- filter_rule_add_part(fr, part);
+ part = filter_part_clone (part);
+ filter_part_xml_decode (part, work);
+ filter_rule_add_part (fr, part);
} else {
- g_warning("cannot find rule part '%s'\n", rulename);
+ g_warning ("cannot find rule part '%s'\n", rulename);
}
- xmlFree(rulename);
+ xmlFree (rulename);
} else {
- g_warning("Unknwon xml node in part: %s", work->name);
+ g_warning ("Unknwon xml node in part: %s", work->name);
}
work = work->next;
}
}
int
-filter_rule_xml_decode(FilterRule * fr, xmlNodePtr node, RuleContext * f)
+filter_rule_xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f)
{
return ((FilterRuleClass *) ((GtkObject *) fr)->klass)->xml_decode(fr, node, f);
}
static int
-xml_decode(FilterRule * fr, xmlNodePtr node, RuleContext * f)
+xml_decode (FilterRule *fr, xmlNodePtr node, RuleContext *f)
{
xmlNodePtr work;
char *grouping;
char *source;
-
+
if (fr->name) {
- g_free(fr->name);
+ g_free (fr->name);
fr->name = NULL;
}
-
- grouping = xmlGetProp(node, "grouping");
- if (!strcmp(grouping, "any"))
+
+ grouping = xmlGetProp (node, "grouping");
+ if (!strcmp (grouping, "any"))
fr->grouping = FILTER_GROUP_ANY;
else
fr->grouping = FILTER_GROUP_ALL;
- xmlFree(grouping);
-
- source = xmlGetProp(node, "source");
+ xmlFree (grouping);
+
+ source = xmlGetProp (node, "source");
if (source) {
fr->source = source;
+ } else {
+ /* default filter type */
+ fr->source = g_strdup ("incoming");
}
-
+
work = node->childs;
while (work) {
- if (!strcmp(work->name, "partset")) {
- load_set(work, fr, f);
- } else if (!strcmp(work->name, "title")) {
+ if (!strcmp (work->name, "partset")) {
+ load_set (work, fr, f);
+ } else if (!strcmp (work->name, "title")) {
if (!fr->name)
- fr->name = xmlNodeGetContent(work);
+ fr->name = xmlNodeGetContent (work);
}
work = work->next;
}
-
+
return 0;
}
void
-filter_rule_add_part(FilterRule * fr, FilterPart * fp)
+filter_rule_add_part (FilterRule *fr, FilterPart *fp)
{
- fr->parts = g_list_append(fr->parts, fp);
+ fr->parts = g_list_append (fr->parts, fp);
}
void
-filter_rule_remove_part(FilterRule * fr, FilterPart * fp)
+filter_rule_remove_part (FilterRule *fr, FilterPart *fp)
{
- fr->parts = g_list_remove(fr->parts, fp);
+ fr->parts = g_list_remove (fr->parts, fp);
}
void
-filter_rule_replace_part(FilterRule * fr, FilterPart * fp, FilterPart * new)
+filter_rule_replace_part (FilterRule *fr, FilterPart *fp, FilterPart *new)
{
GList *l;
-
- l = g_list_find(fr->parts, fp);
+
+ l = g_list_find (fr->parts, fp);
if (l) {
l->data = new;
} else {
- fr->parts = g_list_append(fr->parts, new);
+ fr->parts = g_list_append (fr->parts, new);
}
}
void
-filter_rule_build_code(FilterRule * fr, GString * out)
+filter_rule_build_code (FilterRule *fr, GString *out)
{
return ((FilterRuleClass *) ((GtkObject *) fr)->klass)->build_code(fr, out);
}
static void
-build_code(FilterRule * fr, GString * out)
+build_code (FilterRule *fr, GString *out)
{
switch (fr->grouping) {
case FILTER_GROUP_ALL:
- g_string_append(out, " (and\n ");
+ g_string_append (out, " (and\n ");
break;
case FILTER_GROUP_ANY:
- g_string_append(out, " (or\n ");
+ g_string_append (out, " (or\n ");
break;
default:
- g_warning("Invalid grouping");
+ g_warning ("Invalid grouping");
}
-
- filter_part_build_code_list(fr->parts, out);
- g_string_append(out, ")\n");
+
+ filter_part_build_code_list (fr->parts, out);
+ g_string_append (out, ")\n");
}
static void
-match_all(GtkWidget * widget, FilterRule * fr)
+match_all (GtkWidget *widget, FilterRule *fr)
{
fr->grouping = FILTER_GROUP_ALL;
}
static void
-match_any(GtkWidget * widget, FilterRule * fr)
+match_any (GtkWidget *widget, FilterRule *fr)
{
fr->grouping = FILTER_GROUP_ANY;
}
@@ -332,30 +342,31 @@ struct _part_data {
};
static void
-option_activate(GtkMenuItem * item, struct _part_data *data)
+option_activate (GtkMenuItem *item, struct _part_data *data)
{
- FilterPart *part = gtk_object_get_data(GTK_OBJECT(item), "part");
+ FilterPart *part = gtk_object_get_data (GTK_OBJECT (item), "part");
FilterPart *newpart;
-
+
/* dont update if we haven't changed */
- if (!strcmp(part->title, data->part->title))
+ 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_rule_replace_part(data->fr, data->part, newpart);
- gtk_object_unref(GTK_OBJECT(data->part));
+ gtk_container_remove (GTK_CONTAINER (data->container), data->partwidget);
+
+ newpart = filter_part_clone (part);
+ filter_rule_replace_part (data->fr, data->part, newpart);
+ gtk_object_unref (GTK_OBJECT (data->part));
data->part = newpart;
- data->partwidget = filter_part_get_widget(newpart);
+ data->partwidget = filter_part_get_widget (newpart);
if (data->partwidget)
- gtk_box_pack_start(GTK_BOX(data->container), data->partwidget, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (data->container), data->partwidget, FALSE, FALSE, 0);
}
static GtkWidget *
-get_rule_part_widget(RuleContext * f, FilterPart * newpart, FilterRule * fr)
+get_rule_part_widget (RuleContext *f, FilterPart *newpart, FilterRule *fr)
{
FilterPart *part = NULL;
GtkWidget *menu;
@@ -366,48 +377,48 @@ get_rule_part_widget(RuleContext * f, FilterPart * newpart, FilterRule * fr)
int index = 0, current = 0;
struct _part_data *data;
gchar *s;
-
- data = g_malloc0(sizeof(*data));
+
+ data = g_malloc0 (sizeof (*data));
data->fr = fr;
data->f = f;
data->part = newpart;
-
- hbox = gtk_hbox_new(FALSE, 0);
+
+ hbox = gtk_hbox_new (FALSE, 0);
/* only set to automatically clean up the memory */
- gtk_object_set_data_full(GTK_OBJECT(hbox), "data", data, g_free);
-
- p = filter_part_get_widget(newpart);
-
+ gtk_object_set_data_full (GTK_OBJECT (hbox), "data", data, g_free);
+
+ p = filter_part_get_widget (newpart);
+
data->partwidget = p;
data->container = hbox;
-
- menu = gtk_menu_new();
+
+ menu = gtk_menu_new ();
/* sigh, this is a little ugly */
- while ((part = rule_context_next_part(f, part))) {
- s = e_utf8_to_gtk_string(menu, part->title);
- item = gtk_menu_item_new_with_label(s);
- g_free(s);
- gtk_object_set_data(GTK_OBJECT(item), "part", part);
- gtk_signal_connect(GTK_OBJECT(item), "activate", option_activate, data);
- gtk_menu_append(GTK_MENU(menu), item);
- gtk_widget_show(item);
- if (!strcmp(newpart->title, part->title)) {
+ while ((part = rule_context_next_part (f, part))) {
+ s = e_utf8_to_gtk_string (menu, part->title);
+ item = gtk_menu_item_new_with_label (s);
+ g_free (s);
+ gtk_object_set_data (GTK_OBJECT (item), "part", part);
+ gtk_signal_connect (GTK_OBJECT (item), "activate", option_activate, data);
+ gtk_menu_append (GTK_MENU (menu), item);
+ 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);
+
+ 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, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), p, FALSE, FALSE, 0);
}
- gtk_widget_show_all(hbox);
-
+ gtk_widget_show_all (hbox);
+
return hbox;
}
@@ -418,63 +429,71 @@ struct _rule_data {
};
static void
-less_parts(GtkWidget * button, struct _rule_data *data)
+less_parts (GtkWidget *button, struct _rule_data *data)
{
GList *l;
FilterPart *part;
GtkWidget *w;
-
+
l = data->fr->parts;
- if (g_list_length(l) < 2)
+ if (g_list_length (l) < 2)
return;
-
+
/* remove the last one from the list */
- l = g_list_last(l);
+ l = g_list_last (l);
part = l->data;
- filter_rule_remove_part(data->fr, part);
- gtk_object_unref((GtkObject *) part);
-
+ filter_rule_remove_part (data->fr, part);
+ gtk_object_unref (GTK_OBJECT (part));
+
/* and from the display */
- l = g_list_last(GTK_BOX(data->parts)->children);
+ l = g_list_last (GTK_BOX (data->parts)->children);
w = ((GtkBoxChild *) l->data)->widget;
- gtk_container_remove(GTK_CONTAINER(data->parts), w);
+ gtk_container_remove (GTK_CONTAINER (data->parts), w);
+
+ /* if there's only 1 criterion, we can't remove anymore so set insensitive */
+ if (g_list_length (data->fr->parts) == 1)
+ gtk_widget_set_sensitive (button, FALSE);
}
static void
-more_parts(GtkWidget * button, struct _rule_data *data)
+more_parts (GtkWidget *button, struct _rule_data *data)
{
FilterPart *new;
GtkWidget *w;
-
+
/* create a new rule entry, use the first type of rule */
- new = rule_context_next_part(data->f, NULL);
+ new = rule_context_next_part (data->f, NULL);
if (new) {
- new = filter_part_clone(new);
- filter_rule_add_part(data->fr, new);
- w = get_rule_part_widget(data->f, new, data->fr);
- gtk_box_pack_start(GTK_BOX(data->parts), w, FALSE, FALSE, 0);
+ new = filter_part_clone (new);
+ filter_rule_add_part (data->fr, new);
+ w = get_rule_part_widget (data->f, new, data->fr);
+ gtk_box_pack_start (GTK_BOX (data->parts), w, FALSE, FALSE, 0);
}
+
+ /* set the "Remove criterion" button sensitive */
+ w = gtk_object_get_data (GTK_OBJECT (button), "remove");
+ gtk_widget_set_sensitive (w, TRUE);
}
static void
-name_changed(GtkEntry * entry, FilterRule * fr)
+name_changed (GtkEntry *entry, FilterRule *fr)
{
- g_free(fr->name);
- fr->name = e_utf8_gtk_entry_get_text(entry);
+ g_free (fr->name);
+ fr->name = e_utf8_gtk_entry_get_text (entry);
}
GtkWidget *
-filter_rule_get_widget(FilterRule * fr, struct _RuleContext *f)
+filter_rule_get_widget (FilterRule *fr, struct _RuleContext *f)
{
return ((FilterRuleClass *) ((GtkObject *) fr)->klass)->get_widget(fr, f);
}
static GtkWidget *
-get_widget(FilterRule * fr, struct _RuleContext *f)
+get_widget (FilterRule *fr, struct _RuleContext *f)
{
GtkWidget *vbox, *parts, *inframe;
GtkWidget *hbox;
- GtkWidget *button, *pixmap;
+ GtkWidget *add, *remove, *pixmap;
GtkWidget *w;
GtkWidget *menu, *item, *omenu;
GtkWidget *frame;
@@ -486,149 +505,159 @@ get_widget(FilterRule * fr, struct _RuleContext *f)
FilterPart *part;
char *string;
struct _rule_data *data;
-
+
/* this stuff should probably be a table, but the
rule parts need to be a vbox */
- vbox = gtk_vbox_new(FALSE, 3);
-
- label = gtk_label_new(_("Rule name: "));
- name = gtk_entry_new();
-
- if (!fr->name)
- fr->name = g_strdup(_("untitled"));
-
- if (fr->name)
- e_utf8_gtk_entry_set_text(GTK_ENTRY(name), fr->name);
-
- hbox = gtk_hbox_new(FALSE, 3);
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), name, TRUE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
- gtk_signal_connect(GTK_OBJECT(name), "changed", name_changed, fr);
-
- frame = gtk_frame_new(_("If"));
- inframe = gtk_vbox_new(FALSE, 3);
- gtk_container_add(GTK_CONTAINER(frame), inframe);
-
+ vbox = gtk_vbox_new (FALSE, 3);
+
+ label = gtk_label_new (_("Rule name: "));
+ name = gtk_entry_new ();
+
+ if (!fr->name) {
+ fr->name = g_strdup (_("Untitled"));
+ e_utf8_gtk_entry_set_text (GTK_ENTRY (name), fr->name);
+ gtk_editable_select_region (GTK_EDITABLE (name), 0, -1);
+ gtk_widget_grab_focus (GTK_WIDGET (name));
+ } else {
+ e_utf8_gtk_entry_set_text (GTK_ENTRY (name), fr->name);
+ }
+
+ hbox = gtk_hbox_new (FALSE, 3);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), name, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 3);
+ gtk_signal_connect (GTK_OBJECT (name), "changed", name_changed, fr);
+
+ frame = gtk_frame_new (_("If"));
+ inframe = gtk_vbox_new (FALSE, 3);
+ gtk_container_add (GTK_CONTAINER (frame), inframe);
+
/* this is the parts list, it should probably be inside a scrolling list */
- parts = gtk_vbox_new(FALSE, 3);
-
+ parts = gtk_vbox_new (FALSE, 3);
+
/* data for the parts part of the display */
- data = g_malloc0(sizeof(*data));
+ data = g_malloc0 (sizeof (*data));
data->f = f;
data->fr = fr;
data->parts = parts;
-
+
/* only set to automatically clean up the memory */
- gtk_object_set_data_full(GTK_OBJECT(vbox), "data", data, g_free);
-
- hbox = gtk_hbox_new(FALSE, 3);
- label = gtk_label_new(_("Execute actions"));
-
- menu = gtk_menu_new();
-
- string = e_utf8_to_gtk_string(menu, _("if all criteria are met"));
- item = gtk_menu_item_new_with_label(string);
- g_free(string);
- gtk_signal_connect(GTK_OBJECT(item), "activate", match_all, fr);
- gtk_menu_append(GTK_MENU(menu), item);
- gtk_widget_show(item);
-
- string = e_utf8_to_gtk_string(menu, _("if any criteria are met"));
- item = gtk_menu_item_new_with_label(string);
- g_free(string);
- gtk_signal_connect(GTK_OBJECT(item), "activate", match_any, fr);
- gtk_menu_append(GTK_MENU(menu), item);
- gtk_widget_show(item);
-
- omenu = gtk_option_menu_new();
- gtk_option_menu_set_menu(GTK_OPTION_MENU(omenu), menu);
- gtk_option_menu_set_history(GTK_OPTION_MENU(omenu), fr->grouping == FILTER_GROUP_ALL ? 0 : 1);
- gtk_widget_show(omenu);
-
- pixmap = gnome_stock_new_with_icon(GNOME_STOCK_PIXMAP_ADD);
- button = gnome_pixmap_button(pixmap, _("More criteria"));
- gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
- gtk_signal_connect(GTK_OBJECT(button), "clicked", more_parts, data);
- gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 3);
-
- pixmap = gnome_stock_new_with_icon(GNOME_STOCK_PIXMAP_REMOVE);
- button = gnome_pixmap_button(pixmap, _("Fewer criteria"));
- gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
- gtk_signal_connect(GTK_OBJECT(button), "clicked", less_parts, data);
- gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 3);
-
- gtk_box_pack_end(GTK_BOX(hbox), omenu, FALSE, FALSE, 0);
- gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
-
- gtk_box_pack_start(GTK_BOX(inframe), hbox, FALSE, FALSE, 3);
-
+ gtk_object_set_data_full (GTK_OBJECT (vbox), "data", data, g_free);
+
+ hbox = gtk_hbox_new (FALSE, 3);
+ label = gtk_label_new (_("Execute actions"));
+
+ menu = gtk_menu_new ();
+
+ string = e_utf8_to_gtk_string (menu, _("if all criteria are met"));
+ item = gtk_menu_item_new_with_label (string);
+ g_free (string);
+ gtk_signal_connect (GTK_OBJECT (item), "activate", match_all, fr);
+ gtk_menu_append (GTK_MENU (menu), item);
+ gtk_widget_show (item);
+
+ string = e_utf8_to_gtk_string (menu, _("if any criteria are met"));
+ item = gtk_menu_item_new_with_label (string);
+ g_free (string);
+ gtk_signal_connect (GTK_OBJECT (item), "activate", match_any, fr);
+ gtk_menu_append (GTK_MENU (menu), item);
+ gtk_widget_show (item);
+
+ omenu = gtk_option_menu_new ();
+ gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
+ gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), fr->grouping == FILTER_GROUP_ALL ? 0 : 1);
+ gtk_widget_show (omenu);
+
+ pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_ADD);
+ add = gnome_pixmap_button (pixmap, _("Add criterion"));
+ gtk_button_set_relief (GTK_BUTTON (add), GTK_RELIEF_NONE);
+ gtk_signal_connect (GTK_OBJECT (add), "clicked", more_parts, data);
+ gtk_box_pack_start (GTK_BOX (hbox), add, FALSE, FALSE, 3);
+
+ pixmap = gnome_stock_new_with_icon (GNOME_STOCK_PIXMAP_REMOVE);
+ remove = gnome_pixmap_button (pixmap, _("Remove criterion"));
+ gtk_object_set_data (GTK_OBJECT (add), "remove", remove);
+ gtk_button_set_relief (GTK_BUTTON (remove), GTK_RELIEF_NONE);
+ gtk_signal_connect (GTK_OBJECT (remove), "clicked", less_parts, data);
+ gtk_box_pack_start (GTK_BOX (hbox), remove, FALSE, FALSE, 3);
+
+ /* if we only have 1 criterion, then we can't remove any more so disable this */
+ if (g_list_length (fr->parts) == 1)
+ gtk_widget_set_sensitive (remove, FALSE);
+
+ gtk_box_pack_end (GTK_BOX (hbox), omenu, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (inframe), hbox, FALSE, FALSE, 3);
+
l = fr->parts;
while (l) {
part = l->data;
- w = get_rule_part_widget(f, part, fr);
- gtk_box_pack_start(GTK_BOX(parts), w, FALSE, FALSE, 3);
- l = g_list_next(l);
+ w = get_rule_part_widget (f, part, fr);
+ gtk_box_pack_start (GTK_BOX (parts), w, FALSE, FALSE, 3);
+ 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);
-
+
+ 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_box_pack_start (GTK_BOX (inframe), parts, FALSE, FALSE, 3); */
-
- gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 3);
-
- gtk_widget_show_all(vbox);
-
+
+ gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 3);
+
+ gtk_widget_show_all (vbox);
+
return vbox;
}
FilterRule *
-filter_rule_next_list(GList * l, FilterRule * last, const char *source)
+filter_rule_next_list (GList * l, FilterRule * last, const char *source)
{
GList *node = l;
-
+
if (last != NULL) {
- node = g_list_find(node, last);
+ node = g_list_find (node, last);
if (node == NULL)
node = l;
else
- node = g_list_next(node);
+ node = g_list_next (node);
}
-
+
if (source) {
while (node) {
FilterRule *rule = node->data;
-
- if (rule->source && strcmp(rule->source, source) == 0)
+
+ if (rule->source && strcmp (rule->source, source) == 0)
break;
- node = g_list_next(node);
+ node = g_list_next (node);
}
}
-
+
if (node)
return node->data;
-
+
return NULL;
}
FilterRule *
-filter_rule_find_list(GList * l, const char *name, const char *source)
+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))
+
+ if (strcmp (rule->name, name) == 0)
+ if (source == NULL || (rule->source != NULL && strcmp (rule->source, source) == 0))
return rule;
- l = g_list_next(l);
+ l = g_list_next (l);
}
-
+
return NULL;
}
diff --git a/filter/vfolder-editor.c b/filter/vfolder-editor.c
index 32be9bce3b..33f292bd18 100644
--- a/filter/vfolder-editor.c
+++ b/filter/vfolder-editor.c
@@ -2,6 +2,7 @@
* Copyright (C) 2000 Helix Code Inc.
*
* Authors: Not Zed <notzed@lostzed.mmc.com.au>
+ * Jeffrey Stedfast <fejj@helixcode.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
@@ -30,9 +31,9 @@
#define d(x)
#if 0
-static void vfolder_editor_class_init (VfolderEditorClass *class);
+static void vfolder_editor_class_init (VfolderEditorClass *class);
static void vfolder_editor_init (VfolderEditor *gspaper);
-static void vfolder_editor_finalise (GtkObject *obj);
+static void vfolder_editor_finalise (GtkObject *obj);
#define _PRIVATE(x) (((VfolderEditor *)(x))->priv)
@@ -63,7 +64,7 @@ vfolder_editor_get_type (void)
(GtkArgGetFunc)NULL
};
- type = gtk_type_unique(gnome_dialog_get_type (), &type_info);
+ type = gtk_type_unique (gnome_dialog_get_type (), &type_info);
}
return type;
@@ -75,20 +76,20 @@ vfolder_editor_class_init (VfolderEditorClass *class)
GtkObjectClass *object_class;
object_class = (GtkObjectClass *)class;
- parent_class = gtk_type_class(gnome_dialog_get_type ());
-
+ parent_class = gtk_type_class (gnome_dialog_get_type ());
+
object_class->finalize = vfolder_editor_finalise;
/* override methods */
-
+
/* signals */
-
- gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
}
static void
vfolder_editor_init (VfolderEditor *o)
{
- o->priv = g_malloc0(sizeof(*o->priv));
+ o->priv = g_malloc0 (sizeof (*o->priv));
}
static void
@@ -109,7 +110,7 @@ vfolder_editor_finalise(GtkObject *obj)
VfolderEditor *
vfolder_editor_new(void)
{
- VfolderEditor *o = (VfolderEditor *)gtk_type_new(vfolder_editor_get_type ());
+ VfolderEditor *o = (VfolderEditor *)gtk_type_new (vfolder_editor_get_type ());
return o;
}
#endif
@@ -132,137 +133,157 @@ struct _editor_data {
GtkButton *buttons[BUTTON_LAST];
};
-static void set_sensitive(struct _editor_data *data);
+static void set_sensitive (struct _editor_data *data);
-static void rule_add(GtkWidget *widget, struct _editor_data *data)
+static void
+rule_add (GtkWidget *widget, struct _editor_data *data)
{
FilterRule *rule;
int result;
- GnomeDialog *gd;
+ GtkWidget *gd;
GtkWidget *w;
FilterPart *part;
- d(printf("add rule\n"));
+ d(printf ("add rule\n"));
/* create a new rule with 1 match and 1 action */
- rule = (FilterRule *) vfolder_rule_new();
-
- part = rule_context_next_part(data->f, NULL);
- filter_rule_add_part(rule, filter_part_clone(part));
-
- w = filter_rule_get_widget(rule, data->f);
- gd = (GnomeDialog *)gnome_dialog_new(_("Add Rule"),
- GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL,
- NULL);
- gtk_window_set_policy(GTK_WINDOW(gd), FALSE, TRUE, FALSE);
- gtk_box_pack_start((GtkBox *)gd->vbox, w, TRUE, TRUE, 0);
- gtk_widget_show((GtkWidget *)gd);
- result = gnome_dialog_run_and_close(gd);
+ rule = (FilterRule *) vfolder_rule_new ();
+
+ part = rule_context_next_part (data->f, NULL);
+ filter_rule_add_part (rule, filter_part_clone (part));
+
+ w = filter_rule_get_widget (rule, data->f);
+ gd = gnome_dialog_new (_("Add VFolder Rule"),
+ GNOME_STOCK_BUTTON_OK,
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
+ gtk_window_set_policy (GTK_WINDOW (gd), FALSE, TRUE, FALSE);
+ gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (gd)->vbox), w, TRUE, TRUE, 0);
+
+ gtk_widget_show (gd);
+
+ result = gnome_dialog_run_and_close (GNOME_DIALOG (gd));
+
if (result == 0) {
- GtkListItem *item;
+ GtkWidget *item;
GList *l = NULL;
gchar *s;
-
- s = e_utf8_to_gtk_string ((GtkWidget *) data->list, rule->name);
- item = (GtkListItem *)gtk_list_item_new_with_label(rule->name);
+
+ s = e_utf8_to_gtk_string (GTK_WIDGET (data->list), rule->name);
+ item = gtk_list_item_new_with_label (rule->name);
g_free (s);
-
- gtk_object_set_data((GtkObject *)item, "rule", rule);
- gtk_widget_show((GtkWidget *)item);
- l = g_list_append(l, item);
- gtk_list_append_items(data->list, l);
- gtk_list_select_child(data->list, (GtkWidget *)item);
+
+ gtk_object_set_data (GTK_OBJECT (item), "rule", rule);
+ gtk_widget_show (item);
+
+ l = g_list_append (l, GTK_LIST_ITEM (item));
+
+ gtk_list_append_items (data->list, l);
+ gtk_list_select_child (data->list, item);
+
data->current = rule;
- rule_context_add_rule(data->f, rule);
- set_sensitive(data);
+ rule_context_add_rule (data->f, rule);
+
+ set_sensitive (data);
} else {
- gtk_object_unref((GtkObject *)rule);
+ gtk_object_unref (GTK_OBJECT (rule));
}
}
-static void rule_edit(GtkWidget *widget, struct _editor_data *data)
+static void
+rule_edit (GtkWidget *widget, struct _editor_data *data)
{
GtkWidget *w;
int result;
- GnomeDialog *gd;
+ GtkWidget *gd;
FilterRule *rule;
int pos;
-
- d(printf("edit rule\n"));
+
+ d(printf ("edit rule\n"));
rule = data->current;
- w = filter_rule_get_widget(rule, data->f);
- gd = (GnomeDialog *)gnome_dialog_new(_("Edit VFolder Rule"), GNOME_STOCK_BUTTON_OK, NULL);
- gtk_window_set_policy(GTK_WINDOW(gd), FALSE, TRUE, FALSE);
- gtk_box_pack_start((GtkBox *)gd->vbox, w, TRUE, TRUE, 0);
- gtk_widget_show((GtkWidget *)gd);
- result = gnome_dialog_run_and_close(gd);
-
+ w = filter_rule_get_widget (rule, data->f);
+ gd = gnome_dialog_new (_("Edit VFolder Rule"),
+ GNOME_STOCK_BUTTON_OK,
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
+ gtk_window_set_policy (GTK_WINDOW (gd), FALSE, TRUE, FALSE);
+ gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (gd)->vbox), w, TRUE, TRUE, 0);
+
+ gtk_widget_show (gd);
+
+ result = gnome_dialog_run_and_close (GNOME_DIALOG (gd));
+
if (result == 0) {
- pos = rule_context_get_rank_rule(data->f, data->current, NULL);
+ pos = rule_context_get_rank_rule (data->f, data->current, NULL);
if (pos != -1) {
- GtkListItem *item = g_list_nth_data(data->list->children, pos);
- gchar *s = e_utf8_to_gtk_string ((GtkWidget *) item, data->current->name);
- gtk_label_set_text((GtkLabel *)(((GtkBin *)item)->child), s);
+ GtkListItem *item = g_list_nth_data (data->list->children, pos);
+ gchar *s = e_utf8_to_gtk_string (GTK_WIDGET (item), data->current->name);
+ gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), s);
g_free (s);
}
}
}
-static void rule_delete(GtkWidget *widget, struct _editor_data *data)
+static void
+rule_delete (GtkWidget *widget, struct _editor_data *data)
{
int pos;
GList *l;
GtkListItem *item;
-
- d(printf("ddelete rule\n"));
- pos = rule_context_get_rank_rule(data->f, data->current, NULL);
+
+ d(printf ("delete rule\n"));
+ pos = rule_context_get_rank_rule (data->f, data->current, NULL);
if (pos != -1) {
- rule_context_remove_rule(data->f, data->current);
-
- item = g_list_nth_data(data->list->children, pos);
- l = g_list_append(NULL, item);
- gtk_list_remove_items(data->list, l);
- g_list_free(l);
-
- gtk_object_unref((GtkObject *)data->current);
+ rule_context_remove_rule (data->f, data->current);
+
+ item = g_list_nth_data (data->list->children, pos);
+ l = g_list_append (NULL, item);
+ gtk_list_remove_items (data->list, l);
+ g_list_free (l);
+
+ gtk_object_unref (GTK_OBJECT (data->current));
data->current = NULL;
}
- set_sensitive(data);
+
+ set_sensitive (data);
}
-static void rule_move(struct _editor_data *data, int from, int to)
+static void
+rule_move (struct _editor_data *data, int from, int to)
{
GList *l;
GtkListItem *item;
-
- d(printf("moving %d to %d\n", from, to));
- rule_context_rank_rule(data->f, data->current, to);
-
- item = g_list_nth_data(data->list->children, from);
- l = g_list_append(NULL, item);
- gtk_list_remove_items_no_unref(data->list, l);
- gtk_list_insert_items(data->list, l, to);
- gtk_list_select_child(data->list, (GtkWidget *)item);
- set_sensitive(data);
+
+ d(printf ("moving %d to %d\n", from, to));
+ rule_context_rank_rule (data->f, data->current, to);
+
+ item = g_list_nth_data (data->list->children, from);
+ l = g_list_append (NULL, item);
+ gtk_list_remove_items_no_unref (data->list, l);
+ gtk_list_insert_items (data->list, l, to);
+ gtk_list_select_child (data->list, GTK_WIDGET (item));
+ set_sensitive (data);
}
-static void rule_up(GtkWidget *widget, struct _editor_data *data)
+static void
+rule_up (GtkWidget *widget, struct _editor_data *data)
{
int pos;
-
- d(printf("up rule\n"));
- pos = rule_context_get_rank_rule(data->f, data->current, NULL);
- if (pos>0) {
- rule_move(data, pos, pos-1);
+
+ d(printf ("up rule\n"));
+ pos = rule_context_get_rank_rule (data->f, data->current, NULL);
+ if (pos > 0) {
+ rule_move (data, pos, pos - 1);
}
}
-static void rule_down(GtkWidget *widget, struct _editor_data *data)
+static void
+rule_down (GtkWidget *widget, struct _editor_data *data)
{
int pos;
-
- d(printf("down rule\n"));
- pos = rule_context_get_rank_rule(data->f, data->current, NULL);
- rule_move(data, pos, pos+1);
+
+ d(printf ("down rule\n"));
+ pos = rule_context_get_rank_rule (data->f, data->current, NULL);
+ rule_move (data, pos, pos + 1);
}
static struct {
@@ -277,36 +298,49 @@ static struct {
};
static void
-set_sensitive(struct _editor_data *data)
+set_sensitive (struct _editor_data *data)
{
FilterRule *rule = NULL;
- int index=-1, count=0;
-
- while ((rule = rule_context_next_rule(data->f, rule, NULL))) {
+ int index = -1, count = 0;
+
+ while ((rule = rule_context_next_rule (data->f, rule, NULL))) {
if (rule == data->current)
- index=count;
+ index = count;
count++;
}
- d(printf("index = %d count=%d\n", index, count));
+
+ d(printf ("index = %d count=%d\n", index, count));
+
count--;
- gtk_widget_set_sensitive((GtkWidget *)data->buttons[BUTTON_EDIT], index != -1);
- gtk_widget_set_sensitive((GtkWidget *)data->buttons[BUTTON_DELETE], index != -1);
- gtk_widget_set_sensitive((GtkWidget *)data->buttons[BUTTON_UP], index > 0);
- gtk_widget_set_sensitive((GtkWidget *)data->buttons[BUTTON_DOWN], index >=0 && index<count);
+
+ gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_EDIT]), index != -1);
+ gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_DELETE]), index != -1);
+ gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_UP]), index > 0);
+ gtk_widget_set_sensitive (GTK_WIDGET (data->buttons[BUTTON_DOWN]), index >= 0 && index < count);
}
static void
-select_rule(GtkWidget *w, GtkWidget *child, struct _editor_data *data)
+select_rule (GtkWidget *w, GtkWidget *child, struct _editor_data *data)
{
- data->current = gtk_object_get_data((GtkObject *)child, "rule");
+ data->current = gtk_object_get_data (GTK_OBJECT (child), "rule");
+
if (data->current)
- d(printf("seledct rule: %s\n", data->current->name));
+ d(printf ("selected rule: %s\n", data->current->name));
else
- d(printf("bad data?\n"));
- set_sensitive(data);
+ d(printf ("bad data?\n"));
+
+ set_sensitive (data);
}
-GtkWidget *vfolder_editor_construct (struct _VfolderContext *f)
+static void
+double_click (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
+{
+ if (event->type == GDK_2BUTTON_PRESS)
+ rule_edit (widget, user_data);
+}
+
+GtkWidget *
+vfolder_editor_construct (struct _VfolderContext *f)
{
GladeXML *gui;
GtkWidget *d, *w;
@@ -314,39 +348,43 @@ GtkWidget *vfolder_editor_construct (struct _VfolderContext *f)
FilterRule *rule = NULL;
struct _editor_data *data;
int i;
-
- g_assert(IS_VFOLDER_CONTEXT(f));
-
- data = g_malloc0(sizeof(*data));
+
+ g_assert (IS_VFOLDER_CONTEXT (f));
+
+ data = g_malloc0 (sizeof (*data));
data->f = (RuleContext *)f;
-
- gui = glade_xml_new(FILTER_GLADEDIR "/filter.glade", "edit_vfolder");
+
+ gui = glade_xml_new (FILTER_GLADEDIR "/filter.glade", "edit_vfolder");
d = glade_xml_get_widget (gui, "edit_vfolder");
- gtk_object_set_data_full((GtkObject *)d, "data", data, g_free);
-
- gtk_window_set_title((GtkWindow *)d, "Edit VFolders");
- for (i=0;i<BUTTON_LAST;i++) {
+ gtk_object_set_data_full (GTK_OBJECT (d), "data", data, g_free);
+
+ gtk_window_set_title (GTK_WINDOW (d), "Edit VFolders");
+ for (i = 0; i < BUTTON_LAST; i++) {
data->buttons[i] = (GtkButton *)w = glade_xml_get_widget (gui, edit_buttons[i].name);
- gtk_signal_connect((GtkObject *)w, "clicked", edit_buttons[i].func, data);
+ gtk_signal_connect (GTK_OBJECT (w), "clicked", edit_buttons[i].func, data);
}
-
+
w = glade_xml_get_widget (gui, "rule_list");
- data->list = (GtkList *)w;
+ data->list = GTK_LIST (w);
l = NULL;
- while ((rule = rule_context_next_rule((RuleContext *)f, rule, NULL))) {
- GtkListItem *item;
- gchar *s = e_utf8_to_gtk_string ((GtkWidget *) data->list, rule->name);
- item = (GtkListItem *)gtk_list_item_new_with_label(s);
+ while ((rule = rule_context_next_rule ((RuleContext *)f, rule, NULL))) {
+ GtkWidget *item;
+
+ gchar *s = e_utf8_to_gtk_string (GTK_WIDGET (data->list), rule->name);
+ item = gtk_list_item_new_with_label (s);
g_free (s);
- gtk_object_set_data((GtkObject *)item, "rule", rule);
- gtk_widget_show((GtkWidget *)item);
- l = g_list_append(l, item);
+ gtk_object_set_data (GTK_OBJECT (item), "rule", rule);
+ gtk_widget_show (GTK_WIDGET (item));
+ l = g_list_append (l, GTK_LIST_ITEM (item));
}
- gtk_list_append_items(data->list, l);
- gtk_signal_connect((GtkObject *)w, "select_child", select_rule, data);
-
- set_sensitive(data);
- gtk_object_unref((GtkObject *)gui);
-
+
+ gtk_list_append_items (data->list, l);
+ gtk_signal_connect (GTK_OBJECT (w), "select_child", select_rule, data);
+ gtk_signal_connect (GTK_OBJECT (w), "button_press_event", double_click, data);
+
+ set_sensitive (data);
+
+ gtk_object_unref (GTK_OBJECT (gui));
+
return d;
}