Fix Reply from mainwindow menu and toolbar when mainwindow's
[claws.git] / src / mainwindow.c
index e01564220889e92bba957863985e2cb2ceb51e02..30376f0b6c17d2819f0b153bfd230fe9878c1671 100644 (file)
@@ -1,6 +1,6 @@
 /*
    Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
-   Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
+   Copyright (C) 1999-2018 the Claws Mail team and Hiroyuki Yamamoto
 
    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
@@ -30,6 +30,7 @@
 #include "folderview.h"
 #include "folder_item_prefs.h"
 #include "foldersel.h"
+#include "quicksearch.h"
 #include "summaryview.h"
 #include "summary_search.h"
 #include "messageview.h"
@@ -776,9 +777,7 @@ static GtkActionEntry mainwin_entries[] =
        {"Tools/SSLCertificates",                    NULL, N_("SSL/TLS cer_tificates"), NULL, NULL, G_CALLBACK(ssl_manager_open_cb) }, 
 #endif
        /* {"Tools/---",                             NULL, "---", NULL, NULL, NULL }, */
-#ifndef G_OS_WIN32
        {"Tools/FilteringLog",                       NULL, N_("Filtering Lo_g"), NULL, NULL, G_CALLBACK(filtering_debug_window_show_cb) }, 
-#endif
        {"Tools/NetworkLog",                         NULL, N_("Network _Log"), "<shift><control>L", NULL, G_CALLBACK(log_window_show_cb) }, 
        /* {"Tools/---",                             NULL, "---", NULL, NULL, NULL }, */
        {"Tools/ForgetSessionPasswords",             NULL, N_("_Forget all session passwords"), NULL, NULL, G_CALLBACK(forget_session_passwords_cb) }, 
@@ -923,27 +922,8 @@ static GtkRadioActionEntry mainwin_radio_dec_entries[] =
 };
 
 static gboolean offline_ask_sync = TRUE;
-static guint lastkey;
 static gboolean is_obscured = FALSE;
 
-static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
-                                            GObject *arg1,
-                                            guint value,
-                                            GdkModifierType mod,
-                                            gpointer user_data) 
-{
-       MainWindow *mainwin = (MainWindow *)user_data;
-
-       if (mainwin->summaryview &&
-           mainwin->summaryview->quicksearch &&
-           quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
-           (mod == 0 || mod == GDK_SHIFT_MASK)) {
-               quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
-               return TRUE;
-       }
-       return FALSE;
-}
-
 #define N_COLOR_LABELS colorlabel_get_color_count()
 
 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
@@ -1381,14 +1361,19 @@ static gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                                    gpointer data)
 {
        MainWindow *mainwin = (MainWindow*) data;
-       
+
        if (!mainwin || !event) 
                return FALSE;
 
        if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
        {
-               lastkey = event->keyval;
-               return FALSE;
+               GtkWidget *entry =
+                       quicksearch_get_entry(mainwin->summaryview->quicksearch);
+               gboolean handled;
+               g_signal_emit_by_name(entry, "key-press-event", event, &handled);
+               if (handled) {
+                       return TRUE;
+               }
        }
 
        switch (event->keyval) {
@@ -1462,7 +1447,7 @@ MainWindow *main_window_create()
 
        /* main window */
        window = GTK_WIDGET(gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow"));
-       gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION_FRIENDLY);
+       gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
 #ifdef GENERIC_UMPC
        prefs_common.layout_mode = SMALL_LAYOUT;
@@ -1854,9 +1839,7 @@ MainWindow *main_window_create()
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "SSLCertificates", "Tools/SSLCertificates", GTK_UI_MANAGER_MENUITEM)
 #endif
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator7", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
-#ifndef G_OS_WIN32
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "FilteringLog", "Tools/FilteringLog", GTK_UI_MANAGER_MENUITEM)
-#endif
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "NetworkLog", "Tools/NetworkLog", GTK_UI_MANAGER_MENUITEM)
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "Separator8", "Tools/---", GTK_UI_MANAGER_SEPARATOR)
        MENUITEM_ADDUI_MANAGER(mainwin->ui_manager, "/Menu/Tools", "ForgetSessionPasswords", "Tools/ForgetSessionPasswords", GTK_UI_MANAGER_MENUITEM)
@@ -1972,7 +1955,7 @@ MainWindow *main_window_create()
        online_pixmap = stock_pixmap_widget(STOCK_PIXMAP_ONLINE);
        offline_pixmap = stock_pixmap_widget(STOCK_PIXMAP_OFFLINE);
        online_switch = gtk_button_new ();
-       gtkut_widget_set_can_focus(online_switch, FALSE);
+       gtk_widget_set_can_focus(online_switch, FALSE);
        CLAWS_SET_TIP(online_switch, 
                             _("You are online. Click the icon to go offline"));
        offline_switch = gtk_button_new ();
@@ -1992,7 +1975,7 @@ MainWindow *main_window_create()
 
        ac_button = gtk_button_new();
        CLAWS_SET_TIP(ac_button, _("Select account"));
-       gtkut_widget_set_can_focus(ac_button, FALSE);
+       gtk_widget_set_can_focus(ac_button, FALSE);
        gtk_widget_set_size_request(ac_button, -1, 0);
        gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(ac_button), "button_press_event",
@@ -2099,16 +2082,12 @@ MainWindow *main_window_create()
        summaryview->color_dim.red = summaryview->color_dim.green =
                summaryview->color_dim.blue = COLOR_DIM;
 
-       gtkut_convert_int_to_gdk_color(prefs_common.color_new,
+       gtkut_convert_int_to_gdk_color(prefs_common.color[COL_NEW],
                                       &folderview->color_new);
 
-       gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
+       gtkut_convert_int_to_gdk_color(prefs_common.color[COL_TGT_FOLDER],
                                       &folderview->color_op);
 
-       summaryview->color_important.red = 0;
-       summaryview->color_important.green = 0;
-       summaryview->color_important.blue = (guint16)65535;
-
        color[0] = summaryview->color_marked;
        color[1] = summaryview->color_dim;
        color[2] = folderview->color_new;
@@ -2182,10 +2161,7 @@ MainWindow *main_window_create()
 #define        ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
        gtk_window_add_accel_group                                      \
                (GTK_WINDOW(win),                                       \
-                gtk_ui_manager_get_accel_group(gtkut_ui_manager()));   \
-       g_signal_connect(G_OBJECT(gtk_ui_manager_get_accel_group(gtkut_ui_manager())), \
-                       "accel_activate",                               \
-                       G_CALLBACK(main_window_accel_activate), mainwin);
+                gtk_ui_manager_get_accel_group(gtkut_ui_manager()));
 
        ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
        
@@ -2650,9 +2626,9 @@ static void main_window_show_cur_account(MainWindow *mainwin)
                           : _("none"));
 
        if (cur_account)
-               buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION_FRIENDLY);
+               buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
        else
-               buf = g_strdup(PROG_VERSION_FRIENDLY);
+               buf = g_strdup(PROG_VERSION);
        gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
        g_free(buf);
 
@@ -2905,11 +2881,13 @@ gboolean main_window_empty_trash(MainWindow *mainwin, gboolean confirm, gboolean
                if (for_quit)
                        val = alertpanel(_("Empty trash"),
                               _("Delete all messages in trash folders?"),
-                              GTK_STOCK_NO, "+" GTK_STOCK_YES, _("Don't quit"));
+                              GTK_STOCK_NO, GTK_STOCK_YES, _("Don't quit"),
+                                                ALERTFOCUS_SECOND);
                else
                        val = alertpanel(_("Empty trash"),
                               _("Delete all messages in trash folders?"),
-                              GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
+                              GTK_STOCK_NO, GTK_STOCK_YES, NULL,
+                                                ALERTFOCUS_SECOND);
                if (val == G_ALERTALTERNATE) {
                        debug_print("will empty trash\n");
                } else if (val == G_ALERTDEFAULT) {
@@ -3387,6 +3365,18 @@ do { \
        cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/Message/CheckSignature", 
                                   mimepart_selected && mainwin->messageview->mimeview->signed_part);
 
+       sensitive = TRUE;
+       if (mimepart_selected) {
+               MimeInfo *partinfo = messageview_get_selected_mime_part(mainwin->messageview);
+
+               if (partinfo && (partinfo->type == MIMETYPE_MESSAGE ||
+                                partinfo->type == MIMETYPE_IMAGE ||
+                                partinfo->type == MIMETYPE_MULTIPART)) {
+                       sensitive = FALSE;
+               }
+       }
+       cm_menu_set_sensitive_full(mainwin->ui_manager, "Menu/View/Part/AsText", sensitive);
+
        main_window_menu_callback_unblock(mainwin);
 }
 
@@ -3892,8 +3882,7 @@ void main_window_destroy_all(void)
 
                /* free toolbar stuff */
                toolbar_clear_list(TOOLBAR_MAIN);
-               TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
-               TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
+               toolbar_destroy(mainwin->toolbar);
 
                summaryview_destroy(mainwin->summaryview);
                mainwin->folderview->mainwin = NULL;
@@ -4063,7 +4052,7 @@ static void app_exit_cb(GtkAction *action, gpointer data)
 
        if (prefs_common.confirm_on_exit) {
                if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
-                              GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
+                              GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL, ALERTFOCUS_FIRST)
                    != G_ALERTALTERNATE)
                        return;
                manage_window_focus_in(mainwin->window, NULL, NULL);
@@ -4131,7 +4120,15 @@ static void main_window_reply_cb(GtkAction *gaction, gpointer data)
 
        msginfo_list = summary_get_selection(mainwin->summaryview);
        cm_return_if_fail(msginfo_list != NULL);
-       compose_reply_from_messageview(msgview, msginfo_list, action);
+
+       if (!summary_has_opened_message(mainwin->summaryview)) {
+               compose_reply_from_messageview(NULL, msginfo_list, action);
+       } else if (summary_is_opened_message_selected(mainwin->summaryview)) {
+               compose_reply_from_messageview(msgview, msginfo_list, action);
+       } else {
+               compose_reply_from_messageview(msgview, NULL, action);
+       }
+
        g_slist_free(msginfo_list);
 }
 
@@ -4223,6 +4220,8 @@ void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
                online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
        offline_ask_sync = TRUE;
 
+       inc_reset_offline_override_timers();
+
        switching = FALSE;
 }
 
@@ -4255,7 +4254,7 @@ static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
 
        if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
                        _("Do you want to synchronise your folders now?"),
-                       GTK_STOCK_CANCEL, g_strconcat("+", _("_Synchronise"), NULL), NULL) != G_ALERTALTERNATE)
+                       GTK_STOCK_CANCEL, _("_Synchronise"), NULL, ALERTFOCUS_SECOND) != G_ALERTALTERNATE)
                return;
        
        if (offline_ask_sync)
@@ -4663,29 +4662,26 @@ static void set_folder_display_item_cb(GtkAction *action, gpointer data)
 static void sort_summary_cb(GtkAction *action, GtkRadioAction *current, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
-       FolderItem *item = mainwin->summaryview->folder_item;
        gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
 
        if (mainwin->menu_lock_count) return;
 
-       if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)) && item) {
+       if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current))) {
                summary_sort(mainwin->summaryview, (FolderSortKey)value,
-                            item->sort_type);
-               item->sort_key = value;
+                            mainwin->summaryview->sort_type);
        }
 }
 
 static void sort_summary_type_cb(GtkAction *gaction, GtkRadioAction *current, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
-       FolderItem *item = mainwin->summaryview->folder_item;
        gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current));
 
        if (mainwin->menu_lock_count) return;
 
-       if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)) && item)
+       if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)))
                summary_sort(mainwin->summaryview,
-                            item->sort_key, (FolderSortType)value);
+                            mainwin->summaryview->sort_key, (FolderSortType)value);
 }
 
 static void attract_by_subject_cb(GtkAction *action, gpointer data)
@@ -4899,8 +4895,8 @@ static void prev_history_cb(GtkAction *action, gpointer data)
        if (info) {
                if (info->folder != mainwin->summaryview->folder_item)
                        folderview_select(mainwin->folderview, info->folder);
-               summary_display_by_msgnum(mainwin->summaryview, info->msgnum);
-               summary_display_msg_selected(mainwin->summaryview, FALSE);
+               summary_select_by_msgnum(mainwin->summaryview, info->msgnum,
+                               OPEN_SELECTED_ON_PREVNEXT);
                procmsg_msginfo_free(&info);
                main_window_set_menu_sensitive(mainwindow_get_mainwindow());
                toolbar_main_set_sensitive(mainwindow_get_mainwindow());
@@ -4914,7 +4910,8 @@ static void next_history_cb(GtkAction *action, gpointer data)
        if (info) {
                if (info->folder != mainwin->summaryview->folder_item)
                        folderview_select(mainwin->folderview, info->folder);
-               summary_display_by_msgnum(mainwin->summaryview, info->msgnum);
+               summary_select_by_msgnum(mainwin->summaryview, info->msgnum,
+                               OPEN_SELECTED_ON_PREVNEXT);
                procmsg_msginfo_free(&info);
                main_window_set_menu_sensitive(mainwindow_get_mainwindow());
                toolbar_main_set_sensitive(mainwindow_get_mainwindow());
@@ -5085,7 +5082,7 @@ static void prefs_account_open_cb(GtkAction *action, gpointer data)
        if (!cur_account) {
                new_account_cb(NULL, mainwin);
        } else {
-               account_open(cur_account);
+               account_open(cur_account, FALSE);
        }
 }
 
@@ -5454,8 +5451,7 @@ void mainwindow_jump_to(const gchar *target, gboolean popup)
                }
                if (item && msg && atoi(msg)) {
                        g_print("selecting message %d\n", atoi(msg));
-                       summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
-                       summary_display_msg_selected(mainwin->summaryview, FALSE);
+                       summary_select_by_msgnum(mainwin->summaryview, atoi(msg), TRUE);
                        if (popup)
                                main_window_popup(mainwin);
                        g_free(tmp);
@@ -5467,8 +5463,7 @@ void mainwindow_jump_to(const gchar *target, gboolean popup)
                        msginfo = folder_item_get_msginfo_by_msgid(item, msg);
                        if (msginfo) {
                                g_print("selecting message %s\n", msg);
-                               summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
-                               summary_display_msg_selected(mainwin->summaryview, FALSE);
+                               summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum, TRUE);
                                if (popup)
                                        main_window_popup(mainwin);
                                g_free(tmp);