2007-08-19 [paul] 2.10.0cvs132
[claws.git] / src / folderview.c
index f53d945acb253299f96b28512597cefe267f134f..6d6dd2b0c37c79c19952ce5773b7537f8e66cd23 100644 (file)
@@ -4,7 +4,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #include "defs.h"
@@ -237,6 +237,9 @@ static void folderview_send_queue_cb        (FolderView     *folderview,
 static void folderview_search_cb       (FolderView     *folderview,
                                         guint           action,
                                         GtkWidget      *widget);
+static void folderview_run_processing_cb(FolderView    *folderview,
+                                        guint           action,
+                                        GtkWidget      *widget);
 
 static void folderview_property_cb     (FolderView     *folderview,
                                         guint           action,
@@ -289,6 +292,7 @@ static GtkItemFactoryEntry folderview_common_popup_entries[] =
 {
        {N_("/Mark all re_ad"),         NULL, mark_all_read_cb, 0, NULL},
        {"/---",                        NULL, NULL, 0, "<Separator>"},
+       {N_("/Run processing rules"),   NULL, folderview_run_processing_cb, 0, NULL},
        {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
        {N_("/_Properties..."),         NULL, folderview_property_cb, 0, NULL},
        {N_("/Process_ing..."),         NULL, folderview_processing_cb, 0, NULL},
@@ -373,9 +377,11 @@ static void create_ifactories(gpointer key, gpointer value, gpointer data)
 static void folderview_column_set_titles(FolderView *folderview)
 {
        GtkWidget *ctree = folderview->ctree;
+       GtkWidget *label_folder;
        GtkWidget *label_new;
        GtkWidget *label_unread;
        GtkWidget *label_total;
+       GtkWidget *hbox_folder;
        GtkWidget *hbox_new;
        GtkWidget *hbox_unread;
        GtkWidget *hbox_total;
@@ -393,18 +399,22 @@ static void folderview_column_set_titles(FolderView *folderview)
                         &unreadxpm, &unreadxpmmask);
        stock_pixmap_gdk(ctree, STOCK_PIXMAP_READ,
                         &readxpm, &readxpmmask);
-               
+       
+       label_folder = gtk_label_new(_("Folder"));
        label_new = gtk_image_new_from_pixmap(newxpm, newxpmmask);
        label_unread = gtk_image_new_from_pixmap(unreadxpm, unreadxpmmask);
        label_total = gtk_image_new_from_pixmap(readxpm, readxpmmask);
        
        gtk_clist_column_titles_active(GTK_CLIST(ctree));
         
+       hbox_folder = gtk_hbox_new(FALSE, 4);
        hbox_new = gtk_hbox_new(FALSE, 4);
        hbox_unread = gtk_hbox_new(FALSE, 4);
        hbox_total = gtk_hbox_new(FALSE, 4);
 
        /* left justified */
+       gtk_box_pack_start(GTK_BOX(hbox_folder), label_folder, TRUE, TRUE, 0);
+       gtk_misc_set_alignment (GTK_MISC (label_folder), 0, 0.5);
        gtk_box_pack_start(GTK_BOX(hbox_new), label_new, TRUE, TRUE, 0);
        gtk_misc_set_alignment (GTK_MISC (label_new), 1, 0.5);
        gtk_box_pack_start(GTK_BOX(hbox_unread), label_unread, TRUE, TRUE, 0);
@@ -412,14 +422,26 @@ static void folderview_column_set_titles(FolderView *folderview)
        gtk_box_pack_start(GTK_BOX(hbox_total), label_total, TRUE, TRUE, 0);
        gtk_misc_set_alignment (GTK_MISC (label_total), 1, 0.5);
 
+       gtk_widget_show_all(hbox_folder);
        gtk_widget_show_all(hbox_new);
        gtk_widget_show_all(hbox_unread);
        gtk_widget_show_all(hbox_total);
 
+#ifdef MAEMO
+       gtk_widget_set_size_request(hbox_new, -1, 20);
+       gtk_widget_set_size_request(hbox_unread, -1, 20);
+       gtk_widget_set_size_request(hbox_total, -1, 20);
+#endif
+
+       gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_FOLDER],hbox_folder);
        gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_NEW],hbox_new);
        gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_UNREAD],hbox_unread);
        gtk_clist_set_column_widget(GTK_CLIST(ctree),col_pos[F_COL_TOTAL],hbox_total);
 
+#ifdef MAEMO
+       GTK_EVENTS_FLUSH();
+#endif
+
        gtk_sctree_set_column_tooltip(GTK_SCTREE(ctree), col_pos[F_COL_NEW], _("New"));
        gtk_sctree_set_column_tooltip(GTK_SCTREE(ctree), col_pos[F_COL_UNREAD], _("Unread"));
        gtk_sctree_set_column_tooltip(GTK_SCTREE(ctree), col_pos[F_COL_TOTAL], _("Total"));
@@ -475,6 +497,10 @@ static GtkWidget *folderview_ctree_create(FolderView *folderview)
        ctree = gtk_sctree_new_with_titles(N_FOLDER_COLS, col_pos[F_COL_FOLDER],
                                           titles);
 
+       if (prefs_common.show_col_headers == FALSE)
+               gtk_clist_column_titles_hide(GTK_CLIST(ctree));
+
+
        gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
        gtk_clist_set_column_justification(GTK_CLIST(ctree), col_pos[F_COL_NEW],
                                           GTK_JUSTIFY_RIGHT);
@@ -530,8 +556,12 @@ static GtkWidget *folderview_ctree_create(FolderView *folderview)
                         folderview);
        g_signal_connect(G_OBJECT(ctree), "tree_select_row",
                         G_CALLBACK(folderview_selected), folderview);
+#ifndef MAEMO
+       /* drag-n-dropping folders on maemo is impractical as this 
+        * opens the folder almost everytime */
        g_signal_connect(G_OBJECT(ctree), "start_drag",
                         G_CALLBACK(folderview_start_drag), folderview);
+#endif
        g_signal_connect(G_OBJECT(ctree), "drag_data_get",
                         G_CALLBACK(folderview_drag_data_get),
                         folderview);
@@ -1895,11 +1925,14 @@ static void folderview_set_sens_and_popup_menu(FolderView *folderview, gint row,
 #define SET_SENS(name, sens) \
        menu_set_sensitive(fpopup_factory, name, sens)
 
+       SET_SENS("/Download messages", !item->no_select);
        SET_SENS("/Mark all read", item->unread_msgs >= 1);
        SET_SENS("/Search folder...", item->total_msgs >= 1 && 
                 folderview->selected == folderview->opened);
-       SET_SENS("/Properties...", TRUE);
-       SET_SENS("/Processing...", item->node->parent != NULL);
+       SET_SENS("/Run processing rules", item->prefs->processing &&
+                item->total_msgs >= 1);
+       SET_SENS("/Properties...", !item->no_select);
+       SET_SENS("/Processing...", item->node->parent != NULL && !item->no_select);
        if (item == folder->trash || item == special_trash
            || folder_has_parent_of_type(item, F_TRASH)) {
                GSList *msglist = folder_item_get_msg_list(item);
@@ -2008,6 +2041,7 @@ static gboolean folderview_key_pressed(GtkWidget *widget, GdkEventKey *event,
        case GDK_Right:
 #ifndef MAEMO
        case GDK_Return:
+       case GDK_KP_Enter:
 #endif
                if (folderview->selected) {
                        folderview_select_node(folderview,
@@ -2067,7 +2101,8 @@ void folderview_close_opened(FolderView *folderview)
        if (folderview->opened) {
                FolderItem *olditem;
                
-               olditem = gtk_ctree_node_get_row_data(folderview->ctree, folderview->opened);
+               olditem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree), 
+                                                     folderview->opened);
                if (olditem) {
                        gchar *buf = g_strdup_printf(_("Closing Folder %s..."), 
                                olditem->path ? olditem->path:olditem->name);
@@ -2085,7 +2120,7 @@ void folderview_close_opened(FolderView *folderview)
 
        if (folderview->opened &&
            !GTK_CTREE_ROW(folderview->opened)->children)
-               gtk_ctree_collapse(folderview->ctree, folderview->opened);
+               gtk_ctree_collapse(GTK_CTREE(folderview->ctree), folderview->opened);
 
        folderview->opened = NULL;
 }
@@ -2124,7 +2159,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
                return;
        }
        item = gtk_ctree_node_get_row_data(ctree, row);
-       if (!item || item->no_select) {
+       if (!item) {
                END_TIMING();
                folderview->open_folder = FALSE;
                return;
@@ -2159,6 +2194,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
        }
 
        /* Open Folder */
+       /* TODO: wwp: avoid displaying (null) in the status bar */
        buf = g_strdup_printf(_("Opening Folder %s..."), item->path ? 
                                        item->path : "(null)");
        debug_print("%s\n", buf);
@@ -2168,7 +2204,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
        main_window_cursor_wait(folderview->mainwin);
 
        res = folder_item_open(item);
-       if (res == -1) {
+       if (res == -1 && item->no_select == FALSE) {
                main_window_cursor_normal(folderview->mainwin);
                STATUSBAR_POP(folderview->mainwin);
 
@@ -2178,7 +2214,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
                can_select = TRUE;
                END_TIMING();
                return;
-        } else if (res == -2) {
+        } else if (res == -2 && item->no_select == FALSE) {
                PostponedSelectData *data = g_new0(PostponedSelectData, 1);
                data->ctree = ctree;
                data->row = row;
@@ -2420,6 +2456,21 @@ static void folderview_search_cb(FolderView *folderview, guint action,
        summary_search(folderview->summaryview);
 }
 
+static void folderview_run_processing_cb(FolderView *folderview, guint action,
+                                GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+
+       if (!folderview->selected) return;
+
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+
+       folder_item_apply_processing(item);
+}
+
 static void folderview_property_cb(FolderView *folderview, guint action,
                                   GtkWidget *widget)
 {
@@ -2473,7 +2524,7 @@ void folderview_move_folder(FolderView *folderview, FolderItem *from_folder,
        
        if (prefs_common.warn_dnd) {
                buf = g_strdup_printf(copy ? _("Do you really want to copy folder '%s' in '%s' ?"):
-                                            _("Do you really want to make folder '%s' a sub-folder of '%s' ?"), 
+                                            _("Do you really want to make folder '%s' a subfolder of '%s' ?"), 
                                        from_folder->name, to_folder->name);
                status = alertpanel_full(copy ? _("Copy folder"):_("Move folder"), buf,
                                         GTK_STOCK_NO, GTK_STOCK_YES, NULL, TRUE,
@@ -2948,6 +2999,11 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                        item = gtk_ctree_node_get_row_data(GTK_CTREE(widget), node);
                        src_item = folderview->summaryview->folder_item;
 
+                       if (item->no_select) {
+                               alertpanel_error(_("The destination folder can only be used to "
+                                                  "store subfolders."));
+                               return;
+                       }
                        /* re-check (due to acceptable possibly set for folder moves */
                        if (!(item && item->folder && item->path && !item->no_select && 
                              src_item && src_item != item && FOLDER_CLASS(item->folder)->copy_msg != NULL)) {
@@ -2994,8 +3050,7 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                                !folder_has_parent_of_type(src_item, F_DRAFT) &&
                                !folder_has_parent_of_type(src_item, F_QUEUE) &&
                                !folder_has_parent_of_type(src_item, F_TRASH);
-                       if (!item || item->no_select || !src_item 
-                       ||  !folder_is_normal) {
+                       if (!item || !src_item || !folder_is_normal) {
                                gtk_drag_finish(drag_context, FALSE, FALSE, time);                      
                                return;
                        }