2004-09-28 [colin] 0.9.12cvs110.1
[claws.git] / src / folderview.c
index 0266e550ca4d46df97aea845c21b665b5c2842d5..7c8e9f90b83309013cfb87d09af85135a1bf018a 100644 (file)
@@ -178,6 +178,10 @@ static void mark_all_read_cb            (FolderView    *folderview,
                                          guint           action,
                                          GtkWidget      *widget);
 
+static void folderview_empty_trash_cb  (FolderView     *folderview,
+                                        guint           action,
+                                        GtkWidget      *widget);
+
 static void folderview_search_cb       (FolderView     *folderview,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -232,9 +236,15 @@ static GtkItemFactoryEntry folderview_common_popup_entries[] =
        {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
        {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
        {N_("/_Properties..."),         NULL, folderview_property_cb, 0, NULL},
-       {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
+       {N_("/Pr_ocessing..."),         NULL, folderview_processing_cb, 0, NULL},
 };
 
+static GtkItemFactoryEntry folder_view_trash_popup_entries[] = {
+       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
+       {N_("/Empty trash..."),         NULL, folderview_empty_trash_cb, 0, NULL},
+};
+
+
 GtkTargetEntry folderview_drag_types[] =
 {
        {"text/plain", GTK_TARGET_SAME_APP, TARGET_DUMMY}
@@ -328,12 +338,10 @@ FolderView *folderview_create(void)
        
        gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
        gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_BROWSE);
-#ifndef CLAWS /* text instead of pixmaps */
        gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_NEW,
                                           GTK_JUSTIFY_RIGHT);
        gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_UNREAD,
                                           GTK_JUSTIFY_RIGHT);
-#endif                                    
        gtk_clist_set_column_justification(GTK_CLIST(ctree), COL_TOTAL,
                                           GTK_JUSTIFY_RIGHT);
        gtk_clist_set_column_width(GTK_CLIST(ctree), COL_FOLDER,
@@ -423,8 +431,6 @@ FolderView *folderview_create(void)
 
 void folderview_init(FolderView *folderview)
 {
-       static GdkFont *boldfont = NULL;
-       static GdkFont *normalfont = NULL;
        GtkWidget *ctree = folderview->ctree;
        GtkWidget *label_new;
        GtkWidget *label_unread;
@@ -469,8 +475,10 @@ void folderview_init(FolderView *folderview)
        hbox_unread = gtk_hbox_new(FALSE, 4);
 
        /* left justified */
-       gtk_box_pack_start(GTK_BOX(hbox_new),label_new,FALSE,FALSE,0);
-       gtk_box_pack_start(GTK_BOX(hbox_unread),label_unread,FALSE,FALSE,0);
+       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);
+       gtk_misc_set_alignment (GTK_MISC (label_unread), 1, 0.5);
 
        gtk_widget_show_all(hbox_new);
        gtk_widget_show_all(hbox_unread);
@@ -1385,6 +1393,15 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
        if (fpopup->set_sensitivity != NULL)
                fpopup->set_sensitivity(fpopup_factory, item);
 
+       if (item == folder->trash &&
+           gtk_item_factory_get_item(fpopup_factory, "/Empty trash...") == NULL) {
+               gtk_item_factory_create_item(fpopup_factory, &folder_view_trash_popup_entries[0], folderview, 1);
+               gtk_item_factory_create_item(fpopup_factory, &folder_view_trash_popup_entries[1], folderview, 1);
+       } else {
+               gtk_item_factory_delete_entry(fpopup_factory, &folder_view_trash_popup_entries[0]);
+               gtk_item_factory_delete_entry(fpopup_factory, &folder_view_trash_popup_entries[1]);
+       }
+       
 #define SET_SENS(name, sens) \
        menu_set_sensitive(fpopup_factory, name, sens)
 
@@ -1393,7 +1410,8 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
                 folderview->selected == folderview->opened);
        SET_SENS("/Properties...", TRUE);
        SET_SENS("/Processing...", item->node->parent != NULL);
-
+       if (item == folder->trash)
+               SET_SENS("/Empty trash...", folder_item_get_msg_list(item) != NULL);
 #undef SET_SENS
 
        popup = gtk_item_factory_get_widget(fpopup_factory, fpopup->path);
@@ -1659,6 +1677,38 @@ void folderview_create_folder_node(FolderView *folderview, FolderItem *item)
        gtk_clist_thaw(GTK_CLIST(ctree));
 }
 
+static void folderview_empty_trash_cb(FolderView *folderview, guint action,
+                                     GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+       GSList *mlist = NULL;
+       GSList *cur = NULL;
+       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);
+       if (item != item->folder->trash) return;
+       
+       if (prefs_common.ask_on_clean) {
+               if (alertpanel(_("Empty trash"),
+                              _("Empty all messages in trash?"),
+                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+                       return;
+       }
+       
+       mlist = folder_item_get_msg_list(item);
+       
+       for (cur = mlist ; cur != NULL ; cur = cur->next) {
+               MsgInfo * msginfo = (MsgInfo *) cur->data;
+               partial_mark_for_delete(msginfo);
+               procmsg_msginfo_free(msginfo);
+       }
+
+       folder_item_remove_all_msg(item);
+}
+
 static void folderview_search_cb(FolderView *folderview, guint action,
                                 GtkWidget *widget)
 {
@@ -1680,7 +1730,6 @@ static void folderview_property_cb(FolderView *folderview, guint action,
        if (folder_item_parent(item) == NULL && item->folder->account)
                account_open(item->folder->account);
        else {
-               printf("open prefs...\n");
                prefs_folder_item_open(item);
        }
 }