[PATCH] : New Filter patch (against CVS)



	Hi all,
subject says all. This contains bugfixes and add an option menu to choose 
mailbox destination for a filter.
Bye
Manu
Common subdirectories: balsa/src/CVS and /home/manu/prog/test/balsa-cvs/balsa/src/CVS
Only in /home/manu/prog/test/balsa-cvs/balsa/src: Makefile.in
diff -u balsa/src/filter-edit-callbacks.c /home/manu/prog/test/balsa-cvs/balsa/src/filter-edit-callbacks.c
--- balsa/src/filter-edit-callbacks.c	Sun Dec 16 10:29:21 2001
+++ /home/manu/prog/test/balsa-cvs/balsa/src/filter-edit-callbacks.c	Thu Dec 20 12:26:44 2001
@@ -103,7 +103,9 @@
 
 /* action field */
 extern GtkWidget *fe_action_option_menu;
-extern GtkWidget *fe_action_entry;
+
+/* Mailboxes option menu */
+extern GtkWidget * fe_mailboxes;
 
 /* Different buttons that need to be greyed or ungreyed */
 extern GtkWidget * fe_delete_button;
@@ -1161,7 +1163,7 @@
 void
 fe_action_selected(GtkWidget * widget, gpointer data)
 {
-    gtk_widget_set_sensitive(GTK_WIDGET(fe_action_entry),
+    gtk_widget_set_sensitive(GTK_WIDGET(fe_mailboxes),
                              GPOINTER_TO_INT(data)!=FILTER_TRASH);
 }                       /* end fe_action_selected() */
 
@@ -1361,7 +1363,7 @@
         /* We clear all widgets */
         gtk_entry_set_text(GTK_ENTRY(fe_name_entry),"");
         gtk_entry_set_text(GTK_ENTRY(fe_popup_entry),"");
-        gtk_entry_set_text(GTK_ENTRY(fe_action_entry),"");
+	gtk_option_menu_set_history(GTK_OPTION_MENU(fe_mailboxes), 0);
         gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(fe_sound_entry))),"");
         gtk_clist_clear(fe_conditions_list);
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fe_sound_button),FALSE);
@@ -1382,7 +1384,7 @@
 fe_apply_pressed(GtkWidget * widget, gpointer data)
 {
     LibBalsaFilter *fil,*old;
-    gchar *temp,*action_str;
+    gchar *temp,*mailbox_name=NULL;
     GtkWidget * menu;
     gint row,i;
     FilterActionType action;
@@ -1399,19 +1401,17 @@
         return;
     }
     
-    action_str=gtk_entry_get_text(GTK_ENTRY(fe_action_entry));
 
     /* Retrieve the selected item in the action menu */
     menu=gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(fe_action_option_menu))));
     /* Set the type associated with the selected item */
     action=GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(menu),"value"));
     
-    if (action!=FILTER_RUN && action!=FILTER_TRASH) {
-        if (!action_str || action_str[0] == '\0' || !mblist_find_mbox_by_name(balsa_app.mblist,action_str)) {
-            balsa_information(LIBBALSA_INFORMATION_ERROR,
-                              _("Invalid mailbox name\n"));
-            return;
-        }
+    if (action!=FILTER_TRASH) {
+	/* Retrieve the selected malibox */
+	menu=gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(fe_mailboxes))));
+	/* FIXME : this could lead to something weird if user has removed the mailbox behind us */
+	mailbox_name=LIBBALSA_MAILBOX(gtk_object_get_data(GTK_OBJECT(menu),"mailbox"))->name;
     }
 
     if (!fe_conditions_list->rows) {
@@ -1469,7 +1469,7 @@
     fil->action=action;
 
     if (fil->action!=FILTER_TRASH)
-        fil->action_string=g_strdup(action_str);
+        fil->action_string=g_strdup(mailbox_name);
 
     if (GTK_TOGGLE_BUTTON(fe_popup_button)->active) {
         static gchar defstring[19] = N_("Filter has matched");
@@ -1571,8 +1571,21 @@
     gtk_option_menu_set_history(GTK_OPTION_MENU(fe_op_codes_option_menu), 
                                 fil->conditions_op-1);
 
-    if (fil->action!=FILTER_TRASH)
-        gtk_entry_set_text(GTK_ENTRY(fe_action_entry),fil->action_string==NULL ? "" : fil->action_string);
+    if (fil->action!=FILTER_TRASH && fil->action_string) {
+	gint i;
+	GList * items;
+	
+	items=
+	    gtk_container_children(GTK_CONTAINER(gtk_option_menu_get_menu(GTK_OPTION_MENU(fe_mailboxes))));
+	for (i=0;items;
+	     items=g_list_next(items)) {
+	    gchar * name=LIBBALSA_MAILBOX(gtk_object_get_data(GTK_OBJECT(items->data),"mailbox"))->name;
+	    if (name && !strcmp(name,fil->action_string))
+		break;
+	    else i++;
+	}
+	gtk_option_menu_set_history(GTK_OPTION_MENU(fe_mailboxes), i);
+    }
 
     /* We free the conditions */
     fe_free_associated_conditions();
diff -u balsa/src/filter-edit-dialog.c /home/manu/prog/test/balsa-cvs/balsa/src/filter-edit-dialog.c
--- balsa/src/filter-edit-dialog.c	Sun Dec 16 10:29:21 2001
+++ /home/manu/prog/test/balsa-cvs/balsa/src/filter-edit-dialog.c	Thu Dec 20 12:08:53 2001
@@ -19,10 +19,6 @@
  * 02111-1307, USA.
  */
 
-/*
- * FIXME : should have a combo box for mailbox name when selecting a move or copy action
- */
-
 #include "config.h"
 
 #include <gnome.h>
@@ -67,7 +63,9 @@
 
 /* action field */
 GtkWidget *fe_action_option_menu;
-GtkWidget *fe_action_entry;
+
+/* Mailboxes option menu */
+GtkWidget * fe_mailboxes;
 
 /* Different buttons that need to be greyed or ungreyed */
 GtkWidget * fe_delete_button,* fe_apply_button,* fe_revert_button;
@@ -256,6 +254,27 @@
     return vbox;
 }				/* end build_left_side() */
 
+/* Used to populate mailboxes option menu */
+
+static void
+add_mailbox_to_option_menu(GtkCTree * ctree,GtkCTreeNode *node,gpointer menu)
+{
+    GtkWidget * item;
+    BalsaMailboxNode *mbnode = gtk_ctree_node_get_row_data(ctree, node);
+
+    g_print("Nouveau noeud\n");
+    if (mbnode->mailbox) {
+	/* OK this node is a mailbox */
+	g_print("Mailbox\n");
+	item =
+	    gtk_menu_item_new_with_label(mbnode->mailbox->name);
+	gtk_object_set_data(GTK_OBJECT(item), "mailbox",
+			    mbnode->mailbox);
+	
+	gtk_menu_append(GTK_MENU(menu), item);
+	gtk_widget_show(item);
+    }
+}
 /*
  * build_match_page()
  *
@@ -360,8 +379,10 @@
 build_action_page()
 {
     GtkWidget *page, *frame, *table;
-
     GtkWidget *box = NULL;
+    GtkWidget *menu,* item;
+    GtkCTreeNode * node;
+    gint i;
 
     page = gtk_vbox_new(TRUE, 5);
 
@@ -413,8 +434,25 @@
 					      (fe_action_selected));
     gtk_box_pack_start(GTK_BOX(box), fe_action_option_menu, TRUE, FALSE,
 		       1);
-    fe_action_entry = gtk_entry_new_with_max_length(1023);
-    gtk_box_pack_start(GTK_BOX(box), fe_action_entry, TRUE, FALSE, 1);
+
+    /* We populate the option menu with mailboxes name
+     * FIXME : This is done once for all, but user could
+     * remove or add mailboxes behind us : we should connect
+     * ourselves to signals to refresh the options in these cases
+     */
+
+    menu = gtk_menu_new();
+    for(node=gtk_ctree_node_nth(GTK_CTREE(balsa_app.mblist), 0);
+	node; 
+	node=GTK_CTREE_NODE_NEXT(node))
+	gtk_ctree_pre_recursive(GTK_CTREE(balsa_app.mblist), 
+				node,
+				add_mailbox_to_option_menu,
+				menu);
+    fe_mailboxes = gtk_option_menu_new();
+    gtk_option_menu_set_menu(GTK_OPTION_MENU(fe_mailboxes), menu);
+    gtk_option_menu_set_history(GTK_OPTION_MENU(fe_mailboxes), 0);
+    gtk_box_pack_start(GTK_BOX(box), fe_mailboxes, TRUE, FALSE, 1);
 
     return page;
 }				/* end build_action_page() */
Common subdirectories: balsa/src/pixmaps and /home/manu/prog/test/balsa-cvs/balsa/src/pixmaps


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]