2007-09-28 [paul] 3.0.1cvs37
[claws.git] / src / prefs_folder_item.c
index 6bc9d8089b738bb297b6b1a4f22fe8156c5c4db7..400676d50eb2f2571eca1b90336fed3ccdad427d 100644 (file)
@@ -30,6 +30,7 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include "folder.h"
+#include "alertpanel.h"
 #include "prefs_folder_item.h"
 #include "folderview.h"
 #include "folder.h"
@@ -171,6 +172,7 @@ static gboolean templates_save_recurse_func(GNode *node, gpointer data);
 static gint prefs_folder_item_chmod_mode               (gchar *folder_chmod);
 
 static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
+static void clean_cache_cb(GtkWidget *widget, gpointer data);
 static void folder_regexp_test_cb(GtkWidget *widget, gpointer data);
 static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data);
 
@@ -192,7 +194,7 @@ static void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
        GtkListStore *folder_type_menu;
        GtkWidget *folder_type;
        GtkTreeIter iter;
-       GtkWidget *dummy_checkbtn;
+       GtkWidget *dummy_checkbtn, *clean_cache_btn;
        SpecialFolderItemType type;
        
        GtkWidget *no_save_warning = NULL;
@@ -228,7 +230,7 @@ static void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
        page->item         = item;
 
        /* Table */
-       table = gtk_table_new(9, 4, FALSE);
+       table = gtk_table_new(10, 4, FALSE);
        gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
        gtk_table_set_row_spacings(GTK_TABLE(table), 4);
        gtk_table_set_col_spacings(GTK_TABLE(table), 4);
@@ -501,6 +503,14 @@ static void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
        SET_TOGGLE_SENSITIVITY (checkbtn_offlinesync, hbox);
        SET_TOGGLE_SENSITIVITY (checkbtn_offlinesync, hbox2);
        
+       clean_cache_btn = gtk_button_new_with_label(_("Discard folder cache"));
+       gtk_widget_show (clean_cache_btn);
+       gtk_table_attach(GTK_TABLE(table), clean_cache_btn, 0, 1,
+                        rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+       g_signal_connect(G_OBJECT(clean_cache_btn), "clicked",
+                        G_CALLBACK(clean_cache_cb),
+                        page);
+
        gtk_widget_show_all(table);
 
        if (item->folder && (item->folder->klass->type != F_IMAP && 
@@ -517,6 +527,7 @@ static void prefs_folder_item_general_create_widget_func(PrefsPage * page_,
                gtk_widget_hide(GTK_WIDGET(hbox));
                gtk_widget_hide(GTK_WIDGET(hbox2));
                gtk_widget_hide(GTK_WIDGET(offlinesync_rec_checkbtn));
+               gtk_widget_hide(GTK_WIDGET(clean_cache_btn));
        
        }
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_offlinesync),
@@ -721,6 +732,7 @@ static void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
        GList *cur_ac;
        GList *account_list;
        PrefsAccount *ac_prefs;
+       gboolean default_account_set = FALSE;
 
        page->item         = item;
 
@@ -857,11 +869,20 @@ static void prefs_folder_item_compose_create_widget_func(PrefsPage * page_,
                                        ac_prefs->account_id);
 
                /* Set combobox to current default account id */
-               if (ac_prefs->account_id == item->prefs->default_account)
+               if (ac_prefs->account_id == item->prefs->default_account) {
                        combobox_select_by_data(GTK_COMBO_BOX(optmenu_default_account),
                                        ac_prefs->account_id);
+                       default_account_set = TRUE;
+               }
        }
 
+       /* If nothing has been set (folder doesn't have a default account set),
+        * pre-select global default account, since that's what actually used
+        * anyway. We don't want nothing selected in combobox. */
+       if( !default_account_set )
+               combobox_select_by_data(GTK_COMBO_BOX(optmenu_default_account),
+                               account_get_default()->account_id);
+
        SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_account, optmenu_default_account);
 
        default_account_rec_checkbtn = gtk_check_button_new();
@@ -1119,127 +1140,80 @@ static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
        FolderItemTemplatesPage *page = (FolderItemTemplatesPage *) page_;
        FolderItem *item = (FolderItem *) data;
 
-       GtkWidget *table;
-       GtkWidget *label;
-       guint rowcount;
+       GtkWidget *notebook;
        GtkWidget *vbox;
-       GtkWidget *alignment;
+       GtkWidget *page_vbox;
        GtkWidget *new_msg_format_rec_checkbtn;
        GtkWidget *reply_format_rec_checkbtn;
        GtkWidget *forward_format_rec_checkbtn;
 
-       page->item         = item;
-
-       /* Table */
-       table = gtk_table_new(5, 3, FALSE);
-       gtk_container_set_border_width (GTK_CONTAINER (table), VBOX_BORDER);
-       gtk_table_set_row_spacings(GTK_TABLE(table), 4);
-       gtk_table_set_col_spacings(GTK_TABLE(table), 4);
-       rowcount = 0;
+       page->item = item;
 
-       /* Apply to subfolders */
-       label = gtk_label_new(_("Apply to\nsubfolders"));
-       gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
-       gtk_table_attach(GTK_TABLE(table), label, 2, 3,
-                        rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
-       rowcount++;
+       page_vbox = gtk_vbox_new (FALSE, 0);
+       gtk_widget_show (page_vbox);
+       
+       /* Notebook */
+       notebook = gtk_notebook_new();
+       gtk_widget_show(notebook);
+       gtk_notebook_set_homogeneous_tabs(GTK_NOTEBOOK(notebook), TRUE);
+       gtk_box_pack_start(GTK_BOX(page_vbox), notebook, TRUE, TRUE, 0);
 
        /* compose format */
        vbox = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox);
-       gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
-       gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
-                        rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
 
        quotefmt_create_new_msg_fmt_widgets(
                                window,
                                vbox,
                                &page->checkbtn_compose_with_format,
-                               _("Use a specific format for new messages"),
                                &page->compose_subject_format,
                                &page->compose_body_format,
                                FALSE);
 
-       vbox = gtk_vbox_new (FALSE, VSPACING);
-       gtk_widget_show (vbox);
-       gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
-       gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
-                        rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
-
-       new_msg_format_rec_checkbtn = gtk_check_button_new();
-       gtk_box_pack_start (GTK_BOX(vbox), new_msg_format_rec_checkbtn, FALSE, FALSE, 0);
-       alignment = gtk_alignment_new(0, 1, 0, 0);      
-       gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
-
-       rowcount++;
+       new_msg_format_rec_checkbtn = gtk_check_button_new_with_label(
+                       _("Apply to subfolders"));
+       gtk_box_pack_end (GTK_BOX(vbox), new_msg_format_rec_checkbtn, FALSE, FALSE, 0);
+       gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Compose")));
 
        /* reply format */
        vbox = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox);
-       gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
-       gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
-                        rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
 
        quotefmt_create_reply_fmt_widgets(
                                window,
                                vbox,
                                &page->checkbtn_reply_with_format,
-                               _("Use a specific reply quote format"),
                                &page->reply_quotemark,
                                &page->reply_body_format,
                                FALSE);
 
-       vbox = gtk_vbox_new (FALSE, VSPACING);
-       gtk_widget_show (vbox);
-       gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
-       gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
-                        rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
-
-       reply_format_rec_checkbtn = gtk_check_button_new();
-       gtk_box_pack_start (GTK_BOX(vbox), reply_format_rec_checkbtn, FALSE, FALSE, 0);
-       alignment = gtk_alignment_new(0, 1, 0, 0);      
-       gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
-
-       rowcount++;
+       reply_format_rec_checkbtn = gtk_check_button_new_with_label(
+                       _("Apply to subfolders"));
+       gtk_box_pack_end (GTK_BOX(vbox), reply_format_rec_checkbtn, FALSE, FALSE, 0);
+       gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Reply")));
 
        /* forward format */
        vbox = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox);
-       gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
-       gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
-                        rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
 
        quotefmt_create_forward_fmt_widgets(
                                window,
                                vbox,
                                &page->checkbtn_forward_with_format,
-                               _("Use a specific forward quote format"),
                                &page->forward_quotemark,
                                &page->forward_body_format,
                                FALSE);
 
-       vbox = gtk_vbox_new (FALSE, VSPACING);
-       gtk_widget_show (vbox);
-       gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
-       gtk_table_attach(GTK_TABLE(table), vbox, 2, 3, 
-                        rowcount, rowcount + 1, GTK_SHRINK, GTK_FILL, 0, 0);
-
-       forward_format_rec_checkbtn = gtk_check_button_new();
-       gtk_box_pack_start (GTK_BOX(vbox), forward_format_rec_checkbtn, FALSE, FALSE, 0);
-       alignment = gtk_alignment_new(0, 1, 0, 0);      
-       gtk_box_pack_start (GTK_BOX(vbox), alignment, FALSE, FALSE, 0);
-
-       rowcount++;
+       forward_format_rec_checkbtn = gtk_check_button_new_with_label(
+                       _("Apply to subfolders"));
+       gtk_box_pack_end (GTK_BOX(vbox), forward_format_rec_checkbtn, FALSE, FALSE, 0);
+       gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(_("Forward")));
 
        /* information button */
-       vbox = gtk_vbox_new (FALSE, VSPACING);
-       gtk_widget_show (vbox);
-       gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
-       gtk_table_attach(GTK_TABLE(table), vbox, 1, 2, 
-                        rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
-       rowcount++;
-       quotefmt_add_info_button(window, vbox);
-
+       quotefmt_add_info_button(window, page_vbox);
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->checkbtn_compose_with_format),
                        item->prefs->compose_with_format);
@@ -1262,16 +1236,15 @@ static void prefs_folder_item_templates_create_widget_func(PrefsPage * page_,
        pref_set_textview_from_pref(GTK_TEXT_VIEW(page->forward_body_format),
                        item->prefs->forward_body_format);
 
-       gtk_widget_show_all(table);
+       gtk_widget_show_all(page_vbox);
 
        page->window = GTK_WIDGET(window);
-       page->table = table;
 
        page->new_msg_format_rec_checkbtn = new_msg_format_rec_checkbtn;
        page->reply_format_rec_checkbtn = reply_format_rec_checkbtn;
        page->forward_format_rec_checkbtn = forward_format_rec_checkbtn;
 
-       page->page.widget = table;
+       page->page.widget = page_vbox;
 }
 
 static void prefs_folder_item_templates_destroy_widget_func(PrefsPage *page_) 
@@ -1396,6 +1369,33 @@ static void folder_color_set_dialog(GtkWidget *widget, gpointer data)
        page->folder_color = rgbcolor;
 }
 
+static void clean_cache_cb(GtkWidget *widget, gpointer data)
+{
+       FolderItemGeneralPage *page = (FolderItemGeneralPage *) data;
+       FolderItem *item = page->item;
+       gboolean was_open = FALSE;
+       FolderView *folderview = NULL;
+
+       if (alertpanel_full(_("Discard cache"), 
+                           _("Do you really want to discard the local cached "
+                             "data for this folder?"),
+                                GTK_STOCK_CANCEL, _("+Discard"), NULL, FALSE,
+                                NULL, ALERT_WARNING, G_ALERTDEFAULT)
+               != G_ALERTALTERNATE)
+               return;
+       
+       if (mainwindow_get_mainwindow())
+               folderview = mainwindow_get_mainwindow()->folderview;
+
+       if (folderview && item->opened) {
+               folderview_close_opened(folderview);
+               was_open = TRUE;
+       }
+       folder_item_discard_cache(item);
+       if (was_open)
+               folderview_select(folderview,item);
+}
+
 static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
 {
        int err;
@@ -1495,11 +1495,12 @@ static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer dat
 
 static void register_general_page()
 {
-       static gchar *pfi_general_path[2];
+       static gchar *pfi_general_path[3];
        static FolderItemGeneralPage folder_item_general_page;
 
-       pfi_general_path[0] = _("General");
-       pfi_general_path[1] = NULL;
+       pfi_general_path[0] = _("Folder");
+       pfi_general_path[1] = _("General");
+       pfi_general_path[2] = NULL;
 
         folder_item_general_page.page.path = pfi_general_path;
         folder_item_general_page.page.create_widget = prefs_folder_item_general_create_widget_func;
@@ -1512,11 +1513,12 @@ static void register_general_page()
 
 static void register_compose_page(void)
 {
-       static gchar *pfi_compose_path[2];
+       static gchar *pfi_compose_path[3];
        static FolderItemComposePage folder_item_compose_page;
 
-       pfi_compose_path[0] = _("Compose");
-       pfi_compose_path[1] = NULL;
+       pfi_compose_path[0] = _("Folder");
+       pfi_compose_path[1] = _("Compose");
+       pfi_compose_path[2] = NULL;
 
         folder_item_compose_page.page.path = pfi_compose_path;
         folder_item_compose_page.page.create_widget = prefs_folder_item_compose_create_widget_func;
@@ -1528,11 +1530,12 @@ static void register_compose_page(void)
 
 static void register_templates_page(void)
 {
-       static gchar *pfi_templates_path[2];
+       static gchar *pfi_templates_path[3];
        static FolderItemTemplatesPage folder_item_templates_page;
 
-       pfi_templates_path[0] = _("Templates");
-       pfi_templates_path[1] = NULL;
+       pfi_templates_path[0] = _("Folder");
+       pfi_templates_path[1] = _("Templates");
+       pfi_templates_path[2] = NULL;
 
         folder_item_templates_page.page.path = pfi_templates_path;
         folder_item_templates_page.page.create_widget = prefs_folder_item_templates_create_widget_func;