2005-08-10 [colin] 1.9.13cvs30
[claws.git] / src / mainwindow.c
index 893cc6264d128322c20a22d028b63b9ee79fc27a..bdad4c82382e54a650123ee4fbc2f5b02f89b909 100644 (file)
@@ -65,6 +65,7 @@
 #include "prefs_filtering.h"
 #include "prefs_account.h"
 #include "prefs_summary_column.h"
+#include "prefs_folder_column.h"
 #include "prefs_template.h"
 #include "action.h"
 #include "account.h"
@@ -229,6 +230,9 @@ static void copy_to_cb                      (MainWindow     *mainwin,
 static void delete_cb                  (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
+static void delete_trash_cb                    (MainWindow     *mainwin,
+                                        guint           action,
+                                        GtkWidget      *widget);
 
 static void cancel_cb                   (MainWindow     *mainwin,
                                         guint           action,
@@ -281,7 +285,10 @@ static void collapse_threads_cb     (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
 
-static void set_display_item_cb         (MainWindow    *mainwin,
+static void set_summary_display_item_cb         (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
+static void set_folder_display_item_cb  (MainWindow    *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
 static void sort_summary_cb     (MainWindow    *mainwin,
@@ -363,9 +370,6 @@ static void create_processing_cb (MainWindow        *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
 
-static void prefs_common_open_cb       (MainWindow     *mainwin,
-                                        guint           action,
-                                        GtkWidget      *widget);
 static void prefs_template_open_cb     (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -436,6 +440,9 @@ void main_window_reply_cb                   (MainWindow     *mainwin,
 gboolean mainwindow_progressindicator_hook     (gpointer        source,
                                                 gpointer        userdata);
 #define  SEPARATE_ACTION 500 
+static void mainwindow_quicksearch             (MainWindow     *mainwin, 
+                                                guint           action, 
+                                                GtkWidget      *widget);
 
 static GtkItemFactoryEntry mainwin_entries[] =
 {
@@ -468,6 +475,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Edit/_Find in current message..."),
                                                "<control>F", search_cb, 0, NULL},
        {N_("/_Edit/_Search folder..."),        "<shift><control>F", search_cb, 1, NULL},
+       {N_("/_Edit/_Quick search"),            "slash", mainwindow_quicksearch, 0, NULL},
        {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
        {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
        {N_("/_View/Show or hi_de/_Folder tree"),
@@ -516,7 +524,9 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
        {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
        {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
-       {N_("/_View/Set displayed _items..."),  NULL, set_display_item_cb, 0, NULL},
+       {N_("/_View/Set displayed _columns"),   NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Set displayed _columns/in _Folder list..."),        NULL, set_folder_display_item_cb, 0, NULL},
+       {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
 
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
@@ -579,6 +589,12 @@ static GtkItemFactoryEntry mainwin_entries[] =
         ENC_ACTION(C_ISO_8859_7)},
        ENC_SEPARATOR,
 
+       {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
+        ENC_ACTION(C_ISO_8859_8)},
+       {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
+        ENC_ACTION(C_CP1255)},
+       ENC_SEPARATOR,
+
        {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
         ENC_ACTION(C_ISO_8859_9)},
        ENC_SEPARATOR,
@@ -605,6 +621,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
 
        {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
         ENC_ACTION(C_GB2312)},
+       {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
+        ENC_ACTION(C_GBK)},
        {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
         ENC_ACTION(C_BIG5)},
        {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
@@ -676,7 +694,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
        {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
-       {N_("/_Message/_Delete"),               "<control>D", delete_cb,  0, NULL},
+       {N_("/_Message/Move to _trash"),        "<control>D", delete_trash_cb,  0, NULL},
+       {N_("/_Message/_Delete..."),            NULL, delete_cb,  0, NULL},
        {N_("/_Message/Cancel a news message"), "", cancel_cb,  0, NULL},
        {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
@@ -829,7 +848,6 @@ MainWindow *main_window_create(SeparateType type)
        GtkWidget *menuitem;
        gint i;
        guint n_menu_entries;
-       gboolean hide_messageview = FALSE;
 
        static GdkGeometry geometry;
 
@@ -878,14 +896,19 @@ MainWindow *main_window_create(SeparateType type)
        menu_set_sensitive(ifactory, "/Help/Manual (Local)", manual_available(MANUAL_MANUAL_LOCAL));
        menu_set_sensitive(ifactory, "/Help/FAQ (Local)", manual_available(MANUAL_FAQ_LOCAL));
 
-       handlebox = gtk_handle_box_new();
-       gtk_widget_show(handlebox);
-       gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
-       g_signal_connect(G_OBJECT(handlebox), "child_attached",
-                        G_CALLBACK(toolbar_child_attached), mainwin);
-       g_signal_connect(G_OBJECT(handlebox), "child_detached",
-                        G_CALLBACK(toolbar_child_detached), mainwin);
-
+       if (prefs_common.toolbar_detachable) {
+               handlebox = gtk_handle_box_new();
+               gtk_widget_show(handlebox);
+               gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
+               g_signal_connect(G_OBJECT(handlebox), "child_attached",
+                                G_CALLBACK(toolbar_child_attached), mainwin);
+               g_signal_connect(G_OBJECT(handlebox), "child_detached",
+                                G_CALLBACK(toolbar_child_detached), mainwin);
+       } else {
+               handlebox = gtk_hbox_new(FALSE, 0);
+               gtk_widget_show(handlebox);
+               gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
+       }
        /* link window to mainwin->window to avoid gdk warnings */
        mainwin->window       = window;
        
@@ -1025,8 +1048,7 @@ MainWindow *main_window_create(SeparateType type)
        debug_print("done.\n");
 
        messageview->visible = prefs_common.msgview_visible;
-       hide_messageview = !messageview->visible;
-       
+
        main_window_set_widgets(mainwin, type);
 
        g_signal_connect(G_OBJECT(window), "size_allocate",
@@ -1122,9 +1144,6 @@ MainWindow *main_window_create(SeparateType type)
        if (prefs_common.work_offline)
                online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
 
-       if (mainwin->type == SEPARATE_NONE && hide_messageview)
-               main_window_toggle_message_view(mainwin);
-
        return mainwin;
 }
 
@@ -1200,13 +1219,16 @@ static void main_window_menu_callback_unblock(MainWindow *mainwin)
                mainwin->menu_lock_count--;
 }
 
+static guint prefs_tag = 0;
+
 void main_window_reflect_prefs_all(void)
 {
        main_window_reflect_prefs_all_real(FALSE);
 }
 
-void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
+static gboolean reflect_prefs_timeout_cb(gpointer data) 
 {
+       gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
        GList *cur;
        MainWindow *mainwin;
        GtkWidget *pixmap;
@@ -1240,9 +1262,23 @@ void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
                        mainwin->offline_pixmap = pixmap;
                }
                
-               summary_redisplay_msg(mainwin->summaryview);
                headerview_set_visibility(mainwin->messageview->headerview,
                                          prefs_common.display_header_pane);
+
+               textview_reflect_prefs(mainwin->messageview->mimeview->textview);
+               folderview_reflect_prefs();
+               summary_reflect_prefs();
+               summary_redisplay_msg(mainwin->summaryview);
+       }
+       prefs_tag = 0;
+       return FALSE;
+}
+
+void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
+{
+       if (prefs_tag == 0 || pixmap_theme_changed) {
+               prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
+                                               GINT_TO_POINTER(pixmap_theme_changed));
        }
 }
 
@@ -1257,6 +1293,17 @@ void main_window_set_summary_column(void)
        }
 }
 
+void main_window_set_folder_column(void)
+{
+       GList *cur;
+       MainWindow *mainwin;
+
+       for (cur = mainwin_list; cur != NULL; cur = cur->next) {
+               mainwin = (MainWindow *)cur->data;
+               folderview_set_column_order(mainwin->folderview);
+       }
+}
+
 static void main_window_set_account_selector_menu(MainWindow *mainwin,
                                                  GList *account_list)
 {
@@ -1616,13 +1663,16 @@ void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
                folder = FOLDER(list->data);
                if (folder && folder->trash && folder->trash->total_msgs > 0)
                        has_trash++;
+               if (folder->account && folder->account->set_trash_folder && 
+                   folder_find_item_from_identifier(folder->account->trash_folder))
+                       has_trash++;
        }
 
        if (!has_trash) return;
        
        if (confirm) {
                if (alertpanel(_("Empty trash"),
-                              _("Empty all messages in trash?"),
+                              _("Delete all messages in trash folders?"),
                               GTK_STOCK_YES, GTK_STOCK_NO, NULL)
                    != G_ALERTDEFAULT)
                        return;
@@ -1648,7 +1698,7 @@ void main_window_add_mailbox(MainWindow *mainwin)
                            "Mail");
        if (!path) return;
        if (folder_find_from_path(path)) {
-               alertpanel_error(_("The mailbox `%s' already exists."), path);
+               alertpanel_error(_("The mailbox '%s' already exists."), path);
                g_free(path);
                return;
        }
@@ -1712,8 +1762,9 @@ SensitiveCond main_window_get_current_state(MainWindow *mainwin)
                state |= M_NOT_NEWS;
        if (selection == SUMMARY_SELECTED_SINGLE &&
            (item &&
-            (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
-             item->stype == F_QUEUE)))
+            (folder_has_parent_of_type(item, F_DRAFT) ||
+             folder_has_parent_of_type(item, F_OUTBOX) ||
+             folder_has_parent_of_type(item, F_QUEUE))))
                state |= M_ALLOW_REEDIT;
        if (cur_account)
                state |= M_HAVE_ACCOUNT;
@@ -1790,19 +1841,25 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
 
                {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
                {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
-               {"/Message/Reply to"             , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
+               {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
                {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
                {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
                {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
                {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
                {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
-               {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NOT_NEWS},
+               {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NOT_NEWS},
+               {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NOT_NEWS},
                {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NEWS},
                {"/Message/Mark"                  , M_TARGET_EXIST},
-               {"/Message/Re-edit"              , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
+               {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
 
                {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
                {"/Tools/Harvest addresses"            , M_UNLOCKED},
+               {"/Tools/Harvest addresses/from Folder..."       
+                                                      , M_UNLOCKED|M_MSG_EXIST},
+               {"/Tools/Harvest addresses/from Messages..."
+                                                      , M_UNLOCKED|M_MSG_EXIST|M_TARGET_EXIST},
+               {"/Tools/Harvest addresses"            , M_UNLOCKED},
                {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC|M_UNLOCKED},
                {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
                {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
@@ -1935,13 +1992,13 @@ void main_window_show(MainWindow *mainwin)
                                  prefs_common.mainwin_x,
                                  prefs_common.mainwin_y);
 
-       gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->folderview),
+       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
                             prefs_common.folderview_width,
                             prefs_common.folderview_height);
-       gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
+       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
                             prefs_common.summaryview_width,
                             prefs_common.summaryview_height);
-       gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
+       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
                             prefs_common.msgview_width,
                             prefs_common.msgview_height);
 
@@ -2006,35 +2063,63 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
 
        /* create separated window(s) if needed */
        if (type & SEPARATE_FOLDER) {
+               static GdkGeometry folderwin_geometry;
+               
                folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
                gtk_window_set_title(GTK_WINDOW(folderwin),
                                     _("Sylpheed - Folder View"));
-               gtk_window_set_resizable(GTK_WINDOW(folderwin), TRUE);
-               gtk_window_move(GTK_WINDOW(folderwin), prefs_common.folderwin_x,
+
+               gtk_window_move(GTK_WINDOW(folderwin),
+                               prefs_common.folderwin_x,
                                prefs_common.folderwin_y);
+
+               if (!folderwin_geometry.min_height) {
+                       folderwin_geometry.min_width = 320;
+                       folderwin_geometry.min_height = 200;
+               }
+               gtk_window_set_geometry_hints(GTK_WINDOW(folderwin), NULL,
+                                             &folderwin_geometry, GDK_HINT_MIN_SIZE);
+                               
+               gtk_widget_set_size_request(folderwin,
+                                           prefs_common.folderview_width,
+                                           prefs_common.folderview_height);
+
                gtk_container_set_border_width(GTK_CONTAINER(folderwin),
                                               BORDER_WIDTH);
+
                g_signal_connect(G_OBJECT(folderwin), "delete_event",
                                 G_CALLBACK(folder_window_close_cb),
                                   mainwin);
                gtk_container_add(GTK_CONTAINER(folderwin),
                                  GTK_WIDGET_PTR(mainwin->folderview));
                gtk_widget_realize(folderwin);
+
                if (prefs_common.folderview_visible)
                        gtk_widget_show(folderwin);
        }
 
        if (type & SEPARATE_MESSAGE) {
+               static GdkGeometry msgwin_geometry;
+               
                messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
                gtk_window_set_title(GTK_WINDOW(messagewin),
                                     _("Sylpheed - Message View"));
-               gtk_window_set_resizable(GTK_WINDOW(messagewin), TRUE);
+                                    
                gtk_window_move(GTK_WINDOW(messagewin), 
                                prefs_common.main_msgwin_x,
                                prefs_common.main_msgwin_y);
+
+               if (!msgwin_geometry.min_height) {
+                       msgwin_geometry.min_width = 320;
+                       msgwin_geometry.min_height = 200;
+               }
+               gtk_window_set_geometry_hints(GTK_WINDOW(messagewin), NULL,
+                                             &msgwin_geometry, GDK_HINT_MIN_SIZE);
+               
                gtk_widget_set_size_request(messagewin, 
                                            prefs_common.msgwin_width,
                                            prefs_common.msgwin_height);
+
                gtk_container_set_border_width(GTK_CONTAINER(messagewin),
                                               BORDER_WIDTH);
                g_signal_connect(G_OBJECT(messagewin), "delete_event",
@@ -2259,13 +2344,13 @@ static gboolean toolbar_account_button_pressed(GtkWidget *widget,
 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
                                   gpointer data)
 {
-       gtk_widget_set_usize(child, 1, -1);
+       gtk_widget_set_size_request(child, 1, -1);
 }
 
 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
                                   gpointer data)
 {
-       gtk_widget_set_usize(child, -1, -1);
+       gtk_widget_set_size_request(child, -1, -1);
 }
 
 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
@@ -2439,6 +2524,12 @@ static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
                message_search(mainwin->messageview);
 }
 
+static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
+{
+       prefs_common.show_searchbar = TRUE;
+       quicksearch_show(mainwin->summaryview->quicksearch);
+}
+
 static void toggle_folder_cb(MainWindow *mainwin, guint action,
                             GtkWidget *widget)
 {
@@ -2610,6 +2701,11 @@ static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
        summary_delete(mainwin->summaryview);
 }
 
+static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
+{
+       summary_delete_trash(mainwin->summaryview);
+}
+
 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        summary_cancel(mainwin->summaryview);
@@ -2630,6 +2726,8 @@ static void show_all_header_cb(MainWindow *mainwin, guint action,
                               GtkWidget *widget)
 {
        if (mainwin->menu_lock_count) return;
+       mainwin->summaryview->messageview->all_headers = 
+                       GTK_CHECK_MENU_ITEM(widget)->active;
        summary_display_msg_selected(mainwin->summaryview,
                                     GTK_CHECK_MENU_ITEM(widget)->active);
 }
@@ -2738,12 +2836,18 @@ static void collapse_threads_cb(MainWindow *mainwin, guint action,
        summary_collapse_threads(mainwin->summaryview);
 }
 
-static void set_display_item_cb(MainWindow *mainwin, guint action,
+static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
                                GtkWidget *widget)
 {
        prefs_summary_column_open();
 }
 
+static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
+                               GtkWidget *widget)
+{
+       prefs_folder_column_open();
+}
+
 static void sort_summary_cb(MainWindow *mainwin, guint action,
                            GtkWidget *widget)
 {
@@ -2822,7 +2926,9 @@ static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
        struct DelDupsData data = {0, 0};
 
        folder_func_to_all_folders(deldup_all, &data);
-       alertpanel_notice(_("Deleted %d duplicate message(s) in %d folders.\n"),
+       alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
+                                  "Deleted %d duplicate messages in %d folders.\n",
+                                  data.dups),
                          data.dups, data.folders);
 }
 
@@ -2957,12 +3063,6 @@ static void create_processing_cb(MainWindow *mainwin, guint action,
        summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
 }
 
-static void prefs_common_open_cb(MainWindow *mainwin, guint action,
-                                GtkWidget *widget)
-{
-       /* prefs_common_open(); */
-}
-
 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
                                         GtkWidget *widget)
 {
@@ -3025,7 +3125,23 @@ static void new_account_cb(MainWindow *mainwin, guint action,
 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
 {
        cur_account = (PrefsAccount *)data;
-       main_window_reflect_prefs_all();
+       FolderItem *item = NULL;
+       
+       if (!mainwindow_get_mainwindow())
+               return;
+       main_window_show_cur_account(mainwindow_get_mainwindow());
+       toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
+       main_window_set_menu_sensitive(mainwindow_get_mainwindow());
+       toolbar_main_set_sensitive(mainwindow_get_mainwindow());
+       
+       item = folderview_get_selected_item(
+                       mainwindow_get_mainwindow()->folderview);
+       if (item) {
+               toolbar_set_compose_button
+                       (mainwindow_get_mainwindow()->toolbar,
+                        FOLDER_TYPE(item->folder) == F_NEWS ? 
+                        COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
+       }
 }
 
 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)