remove all gtk3 conditionals
[claws.git] / src / mainwindow.c
index 73b009725d8ed70e7db486d9649aa0c27294d1b7..5fa621d1502c875550c96cc0d082448168a9e3e8 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"
@@ -921,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,
@@ -1379,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) {
@@ -1445,10 +1432,8 @@ MainWindow *main_window_create()
        FolderView *folderview;
        SummaryView *summaryview;
        MessageView *messageview;
-#if !GTK_CHECK_VERSION(3, 0, 0)
        GdkColormap *colormap;
        gboolean success[4];
-#endif
        GdkColor color[4];
        GtkWidget *ac_menu;
        gint i;
@@ -1460,7 +1445,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;
@@ -1968,7 +1953,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 ();
@@ -1988,7 +1973,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",
@@ -2101,23 +2086,17 @@ MainWindow *main_window_create()
        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;
        color[3] = folderview->color_op;
 
-#if !GTK_CHECK_VERSION(3, 0, 0)
        colormap = gdk_drawable_get_colormap(gtk_widget_get_window(window));
        gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
        for (i = 0; i < 4; i++) {
                if (success[i] == FALSE)
                        g_warning("MainWindow: color allocation %d failed", i);
        }
-#endif
 
        debug_print("done.\n");
 
@@ -2178,10 +2157,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);
        
@@ -2646,9 +2622,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);
 
@@ -2901,11 +2877,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) {
@@ -3383,6 +3361,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);
 }
 
@@ -3888,8 +3878,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;
@@ -4059,7 +4048,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);
@@ -4127,7 +4116,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);
 }
 
@@ -4219,6 +4216,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;
 }
 
@@ -4251,7 +4250,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)
@@ -4659,29 +4658,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)
@@ -5082,7 +5078,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);
        }
 }