2007-03-30 [paul] 2.8.1cvs68
[claws.git] / src / mainwindow.c
index 824fc3f96cac80e837c8f8c0edd2b941e798fedb..9150dbdaf52ac04ac1780212d7e752d50e20c646 100644 (file)
@@ -106,6 +106,8 @@ static GList *mainwin_list = NULL;
 static GdkCursor *watch_cursor = NULL;
 static GdkCursor *hand_cursor = NULL;
 
+static gint iconified_count = 0;
+
 static void main_window_menu_callback_block    (MainWindow     *mainwin);
 static void main_window_menu_callback_unblock  (MainWindow     *mainwin);
 
@@ -197,6 +199,9 @@ static void addressbook_open_cb     (MainWindow     *mainwin,
 static void log_window_show_cb (MainWindow     *mainwin,
                                 guint           action,
                                 GtkWidget      *widget);
+static void filtering_debug_window_show_cb     (MainWindow     *mainwin,
+                                guint           action,
+                                GtkWidget      *widget);
 
 static void inc_cancel_cb              (MainWindow     *mainwin,
                                         guint           action,
@@ -394,6 +399,9 @@ static void create_filter_cb         (MainWindow    *mainwin,
 static void create_processing_cb (MainWindow   *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
+static void open_urls_cb        (MainWindow    *mainwin,
+                                 guint          action,
+                                 GtkWidget     *widget);
 
 static void prefs_template_open_cb     (MainWindow     *mainwin,
                                         guint           action,
@@ -467,10 +475,16 @@ static void sync_cb                ( MainWindow *mainwin,
 static gboolean mainwindow_focus_in_event      (GtkWidget      *widget, 
                                                 GdkEventFocus  *focus,
                                                 gpointer        data);
-void main_window_reply_cb                      (MainWindow     *mainwin, 
+static gboolean mainwindow_visibility_event_cb (GtkWidget      *widget, 
+                                                GdkEventVisibility     *state,
+                                                gpointer        data);
+static gboolean mainwindow_state_event_cb      (GtkWidget      *widget, 
+                                                GdkEventWindowState    *state,
+                                                gpointer        data);
+static void main_window_reply_cb                       (MainWindow     *mainwin, 
                                                 guint           action,
                                                 GtkWidget      *widget);
-gboolean mainwindow_progressindicator_hook     (gpointer        source,
+static gboolean mainwindow_progressindicator_hook      (gpointer        source,
                                                 gpointer        userdata);
 
 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
@@ -547,9 +561,11 @@ static GtkItemFactoryEntry mainwin_entries[] =
 
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/La_yout"),                  NULL, NULL, 0, "<Branch>"},
-       {N_("/_View/Layout/_Normal"),           NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
-       {N_("/_View/Layout/_Vertical"),         NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Normal"},
-       {N_("/_View/Layout/_Wide"),             NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Normal"},
+       {N_("/_View/Layout/_Standard"),         NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
+       {N_("/_View/Layout/_Three columns"),    NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
+       {N_("/_View/Layout/_Wide message"),     NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
+       {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
+       {N_("/_View/Layout/S_mall screen"),     NULL, set_layout_cb, SMALL_LAYOUT, "/View/Layout/Standard"},
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
        {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
@@ -828,6 +844,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Tools/C_reate processing rule/by _Subject"),
                                                NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
+       {N_("/_Tools/List _URLs..."),           "<shift><control>U", open_urls_cb, 0, NULL},
+       {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/Ch_eck for new messages in all folders"),
@@ -846,6 +864,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                NULL, ssl_manager_open_cb, 0, NULL},
 #endif
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
+       {N_("/_Tools/Filtering debug window"),  NULL, filtering_debug_window_show_cb, 0, NULL},
        {N_("/_Tools/_Log window"),             "<shift><control>L", log_window_show_cb, 0, NULL},
 
        {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
@@ -881,6 +900,7 @@ static GtkItemFactoryEntry mainwin_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,
@@ -1027,12 +1047,12 @@ static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refr
                g_object_set_data(G_OBJECT(item), "mainwin",
                                  mainwin);
                gtk_widget_show(item);
-               gtk_widget_add_accelerator(item, "activate", 
+               if (i < 9)
+                       gtk_widget_add_accelerator(item, "activate", 
                                   mainwin->menu_factory->accel_group, 
                                   GDK_1+i, GDK_CONTROL_MASK,
                                   GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
        }
-
        gtk_widget_show(menu);
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
        mainwin->colorlabel_menu = menu;
@@ -1123,7 +1143,7 @@ MainWindow *main_window_create()
        mainwin = g_new0(MainWindow, 1);
 
        /* main window */
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow");
        gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
 
@@ -1270,16 +1290,40 @@ MainWindow *main_window_create()
 
        gtk_widget_hide(offline_switch);
        gtk_widget_hide(warning_btn);
+
        /* create views */
        mainwin->folderview  = folderview  = folderview_create();
        mainwin->summaryview = summaryview = summary_create();
        mainwin->messageview = messageview = messageview_create(mainwin);
-       mainwin->logwin      = log_window_create();
 
+       /* init log instances data before creating log views */
+       set_log_title(LOG_PROTOCOL, _("Protocol log"));
+       set_log_prefs(LOG_PROTOCOL,
+                       &prefs_common.logwin_width,
+                       &prefs_common.logwin_height);
+       set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
+       set_log_prefs(LOG_DEBUG_FILTERING,
+                       &prefs_common.filtering_debugwin_width,
+                       &prefs_common.filtering_debugwin_height);
+
+       /* setup log windows */
+       mainwin->logwin = log_window_create(LOG_PROTOCOL);
        log_window_init(mainwin->logwin);
-       log_window_set_clipping(mainwin->logwin, prefs_common.cliplog,
+
+       mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
+       log_window_set_clipping(mainwin->logwin,
+                               prefs_common.cliplog,
                                prefs_common.loglength);
 
+       log_window_init(mainwin->filtering_debugwin);
+       log_window_set_clipping(mainwin->filtering_debugwin,
+                               prefs_common.filtering_debug_cliplog,
+                               prefs_common.filtering_debug_loglength);
+       if (prefs_common.enable_filtering_debug)
+               log_message(LOG_DEBUG_FILTERING, _("filtering debug enabled\n"));
+       else
+               log_message(LOG_DEBUG_FILTERING, _("filtering debug disabled\n"));
+
        folderview->mainwin      = mainwin;
        folderview->summaryview  = summaryview;
 
@@ -1419,12 +1463,20 @@ MainWindow *main_window_create()
           menu items in different menus             */
        menu_connect_identical_items();
 
-
        gtk_window_iconify(GTK_WINDOW(mainwin->window));
 
-       if (prefs_common.layout_mode == VERTICAL_LAYOUT)
-               summary_relayout(mainwin->summaryview); 
+       g_signal_connect(G_OBJECT(window), "window_state_event",
+                        G_CALLBACK(mainwindow_state_event_cb), mainwin);
+       g_signal_connect(G_OBJECT(window), "visibility_notify_event",
+                        G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
+       gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
 
+       if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
+           prefs_common.layout_mode == SMALL_LAYOUT) {
+               summary_relayout(mainwin->summaryview); 
+       }
+       summary_update_unread(mainwin->summaryview, NULL);
+       
        gtk_widget_show(mainwin->window);
 
        /* initialize views */
@@ -1864,9 +1916,16 @@ static void main_window_separation_change(MainWindow *mainwin, LayoutType layout
        gtk_widget_unref(message_wid);
 }
 
-static void mainwin_reset_paned(GtkPaned *paned)
+void mainwindow_reset_paned(GtkPaned *paned)
 {
                gint min, max, mid;
+
+               if (gtk_paned_get_child1(GTK_PANED(paned)))
+                       gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
+               if (gtk_paned_get_child2(GTK_PANED(paned)))
+                       gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
+
+GTK_EVENTS_FLUSH();
                g_object_get (G_OBJECT(paned),
                                "min-position",
                                &min, NULL);
@@ -1874,17 +1933,47 @@ static void mainwin_reset_paned(GtkPaned *paned)
                                "max-position",
                                &max, NULL);
                mid = (min+max)/2;
-
                gtk_paned_set_position(GTK_PANED(paned), mid);
 }
 
+static void mainwin_paned_show_first(GtkPaned *paned)
+{
+               gint max;
+               g_object_get (G_OBJECT(paned),
+                               "max-position",
+                               &max, NULL);
+
+               if (gtk_paned_get_child1(GTK_PANED(paned)))
+                       gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
+               if (gtk_paned_get_child2(GTK_PANED(paned)))
+                       gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
+               gtk_paned_set_position(GTK_PANED(paned), max);
+}
+
+static void mainwin_paned_show_last(GtkPaned *paned)
+{
+               gint min;
+               g_object_get (G_OBJECT(paned),
+                               "min-position",
+                               &min, NULL);
+
+               if (gtk_paned_get_child1(GTK_PANED(paned)))
+                       gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
+               if (gtk_paned_get_child2(GTK_PANED(paned)))
+                       gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
+               gtk_paned_set_position(GTK_PANED(paned), min);
+}
+
 void main_window_toggle_message_view(MainWindow *mainwin)
 {
        SummaryView *summaryview = mainwin->summaryview;
        GtkWidget *ppaned = NULL;
        GtkWidget *container = NULL;
        
-       if (prefs_common.layout_mode != WIDE_LAYOUT) {
+       switch (prefs_common.layout_mode) {
+       case NORMAL_LAYOUT:
+       case VERTICAL_LAYOUT:
+       case SMALL_LAYOUT:
                ppaned = mainwin->vpaned;
                container = mainwin->hpaned;
                if (ppaned->parent != NULL) {
@@ -1899,7 +1988,8 @@ void main_window_toggle_message_view(MainWindow *mainwin)
                        gtk_container_add(GTK_CONTAINER(container), ppaned);
                        gtk_widget_unref(ppaned);
                }
-       } else {
+               break;
+       case WIDE_LAYOUT:
                ppaned = mainwin->hpaned;
                container = mainwin->vpaned;
                if (mainwin->messageview->vbox->parent != NULL) {
@@ -1912,6 +2002,10 @@ void main_window_toggle_message_view(MainWindow *mainwin)
                        gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
                        gtk_widget_unref(mainwin->messageview->vbox);
                }
+               break;
+       case WIDE_MSGLIST_LAYOUT:
+               g_warning("can't hide messageview in this wide msglist layout");
+               break;
        }
 
        if (messageview_is_visible(mainwin->messageview))
@@ -2023,10 +2117,10 @@ void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
 
 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
 {
-       if (confirm) {
+       if (confirm && procmsg_have_trashed_mails_fast()) {
                if (alertpanel(_("Empty trash"),
                               _("Delete all messages in trash folders?"),
-                              GTK_STOCK_CANCEL, _("+_Empty trash"), NULL)
+                              GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
                    != G_ALERTALTERNATE)
                        return;
                manage_window_focus_in(mainwin->window, NULL, NULL);
@@ -2241,11 +2335,15 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
                {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
                {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
+               {"/Tools/List URLs..."                 , M_TARGET_EXIST},
                {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
                {"/Tools/Execute"                      , M_DELAY_EXEC},
                {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
 
                {"/Configuration", M_UNLOCKED},
+               {"/Configuration/Preferences for current account...", M_UNLOCKED},
+               {"/Configuration/Create new account...", M_UNLOCKED},
+               {"/Configuration/Edit accounts...", M_UNLOCKED},
 
                {NULL, 0}
        };
@@ -2479,7 +2577,8 @@ static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
        const gchar *buf;
        gint i = 0;
        buf = *buffer;
-       
+       gboolean with_plus = TRUE;
+
        if (buf == 0x00) {
                *url_decoded = '\0';
                *buffer = NULL;
@@ -2493,6 +2592,8 @@ static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
        /* First non space and non comment must be a < */
        if (*buf =='<' ) {
                buf++;
+               if (!strncmp(buf, "mailto:", strlen("mailto:")))
+                       with_plus = FALSE;
                for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
                buf++;
        }
@@ -2509,7 +2610,7 @@ static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
        if (i == maxlen) {
                return;
        }
-       decode_uri (url_decoded, (const gchar *)tmp);
+       decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
 
        /* Prepare the work for the next url in the list */
        /* after the closing bracket >, ignore space, comments and tabs */
@@ -2553,6 +2654,13 @@ void main_window_popup(MainWindow *mainwin)
                main_window_show(mainwin);
 
        gtkut_window_popup(mainwin->window);
+       if (prefs_common.layout_mode == SMALL_LAYOUT) {
+               if (mainwin->in_folder) {
+                       mainwindow_enter_folder(mainwin);
+               } else {
+                       mainwindow_exit_folder(mainwin);
+               }
+       }
 }
 
 void main_window_show(MainWindow *mainwin)
@@ -2593,18 +2701,28 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
        GtkWidget *vbox_body = mainwin->vbox_body;
        GtkItemFactory *ifactory = mainwin->menu_factory;
        GtkWidget *menuitem;
-
+       gboolean first_set = (mainwin->hpaned == NULL);
        debug_print("Setting widgets... ");
 
-       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
+       if (layout_mode == SMALL_LAYOUT && first_set) {
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
                                    prefs_common.folderview_width,
                                    prefs_common.folderview_height);
-       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
+                                   0,0);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
+                                   0,0);
+       } else {
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
+                                   prefs_common.folderview_width,
+                                   prefs_common.folderview_height);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
                                    prefs_common.summaryview_width,
                                    prefs_common.summaryview_height);
-       gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
                                    prefs_common.msgview_width,
                                    prefs_common.msgview_height);
+       }
 
        mainwin->messageview->statusbar = mainwin->statusbar;
        mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
@@ -2616,7 +2734,13 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
                else
                        gtk_widget_destroy(mainwin->hpaned);
        }
-       if (layout_mode != WIDE_LAYOUT) {
+
+       menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
+               (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
+       switch (layout_mode) {
+       case VERTICAL_LAYOUT:
+       case NORMAL_LAYOUT:
+       case SMALL_LAYOUT:
                hpaned = gtk_hpaned_new();
                if (layout_mode == VERTICAL_LAYOUT)
                        vpaned = gtk_hpaned_new();
@@ -2640,8 +2764,12 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
                gtk_paned_add2(GTK_PANED(vpaned),
                               GTK_WIDGET_PTR(mainwin->messageview));
                gtk_widget_show(vpaned);
+               if (layout_mode == SMALL_LAYOUT && first_set) {
+                       mainwin_paned_show_first(GTK_PANED(hpaned));
+               }
                gtk_widget_queue_resize(vpaned);
-       } else {
+               break;
+       case WIDE_LAYOUT:
                vpaned = gtk_vpaned_new();
                hpaned = gtk_hpaned_new();
                gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
@@ -2663,11 +2791,61 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
                }
                gtk_widget_show(vpaned);
                gtk_widget_queue_resize(vpaned);
+               break;
+       case WIDE_MSGLIST_LAYOUT:
+               vpaned = gtk_vpaned_new();
+               hpaned = gtk_hpaned_new();
+               gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
+
+               gtk_paned_add1(GTK_PANED(vpaned),
+                              GTK_WIDGET_PTR(mainwin->summaryview));
+               gtk_paned_add1(GTK_PANED(hpaned),
+                              GTK_WIDGET_PTR(mainwin->folderview));
+
+               gtk_widget_show(hpaned);
+               gtk_widget_queue_resize(hpaned);
+
+               if (messageview_is_visible(mainwin->messageview)) {
+                       gtk_paned_add2(GTK_PANED(hpaned),
+                              GTK_WIDGET_PTR(mainwin->messageview));   
+               } else {
+                       gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
+               }
+               gtk_paned_add2(GTK_PANED(vpaned), hpaned);
+
+               gtk_widget_show(vpaned);
+               gtk_widget_queue_resize(vpaned);
+               break;
+       default:
+               g_warning("Unknown layout");
+               return;
        }
 
        mainwin->hpaned = hpaned;
        mainwin->vpaned = vpaned;
 
+       if (layout_mode == SMALL_LAYOUT) {
+               if (mainwin->messageview->visible)
+                       main_window_toggle_message_view(mainwin);
+       } 
+
+       if (layout_mode == SMALL_LAYOUT && first_set) {
+               gtk_widget_realize(mainwin->window);
+               gtk_widget_realize(mainwin->folderview->ctree);
+               gtk_widget_realize(mainwin->summaryview->hbox);
+               gtk_widget_realize(mainwin->summaryview->hbox_l);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
+                                   prefs_common.folderview_width,
+                                   prefs_common.folderview_height);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
+                                   0,0);
+               gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
+                                   0,0);
+               gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
+                               prefs_common.mainwin_width,
+                               prefs_common.mainwin_height);
+               gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
+       } 
        /* remove headerview if not in prefs */
        headerview_set_visibility(mainwin->messageview->headerview,
                                  prefs_common.display_header_pane);
@@ -2711,12 +2889,22 @@ static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
 }
 
-       if (prefs_common.layout_mode == NORMAL_LAYOUT) {
-               SET_CHECK_MENU_ACTIVE("/View/Layout/Normal", TRUE);
-       } else if (prefs_common.layout_mode == VERTICAL_LAYOUT) {
-               SET_CHECK_MENU_ACTIVE("/View/Layout/Vertical", TRUE);
-       } else if (prefs_common.layout_mode == WIDE_LAYOUT) {
-               SET_CHECK_MENU_ACTIVE("/View/Layout/Wide", TRUE);
+       switch (prefs_common.layout_mode) {
+       case NORMAL_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
+               break;
+       case VERTICAL_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
+               break;
+       case WIDE_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
+               break;
+       case WIDE_MSGLIST_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
+               break;
+       case SMALL_LAYOUT:
+               SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
+               break;
        }
 #undef SET_CHECK_MENU_ACTIVE
 
@@ -2793,8 +2981,11 @@ static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
                                 gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
+       gboolean close_allowed = TRUE;
 
-       if (mainwin->lock_count == 0)
+       hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
+
+       if (close_allowed && mainwin->lock_count == 0)
                app_exit_cb(data, 0, widget);
 
        return TRUE;
@@ -2805,7 +2996,6 @@ static void main_window_size_allocate_cb(GtkWidget *widget,
                                         gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
-
        main_window_get_size(mainwin);
 }
 
@@ -2932,7 +3122,7 @@ static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
        toolbar_toggle(action, mainwin);
 }
 
-void main_window_reply_cb(MainWindow *mainwin, guint action,
+static void main_window_reply_cb(MainWindow *mainwin, guint action,
                          GtkWidget *widget)
 {
        MessageView *msgview = (MessageView*)mainwin->messageview;
@@ -2963,7 +3153,7 @@ static void set_layout_cb(MainWindow *mainwin, guint action,
                               GtkWidget *widget)
 {
        LayoutType layout_mode = action;
-
+       LayoutType old_layout_mode = prefs_common.layout_mode;
        if (mainwin->menu_lock_count) {
                return;
        }
@@ -2975,13 +3165,22 @@ static void set_layout_cb(MainWindow *mainwin, guint action,
                return;
        }
        
-       if (!mainwin->messageview->visible)
+       if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
+               main_window_toggle_message_view(mainwin);
+       else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
                main_window_toggle_message_view(mainwin);
 
        main_window_separation_change(mainwin, layout_mode);
-
-       mainwin_reset_paned(GTK_PANED(mainwin->vpaned));
+       mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
+       if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
+               mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
+       }
+       if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
+               mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
+               mainwindow_exit_folder(mainwin);
+       }
        summary_relayout(mainwin->summaryview); 
+       summary_update_unread(mainwin->summaryview, NULL);
 }
 
 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
@@ -3082,6 +3281,12 @@ static void log_window_show_cb(MainWindow *mainwin, guint action,
        log_window_show(mainwin->logwin);
 }
 
+static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
+                              GtkWidget *widget)
+{
+       log_window_show(mainwin->filtering_debugwin);
+}
+
 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
 {
        inc_cancel_all();
@@ -3225,6 +3430,15 @@ static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
        summary_reedit(mainwin->summaryview);
 }
 
+static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
+{
+       if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
+               summary_display_msg_selected(mainwin->summaryview, 
+                       mainwin->messageview->mimeview->textview->show_all_headers);
+       }
+       messageview_list_urls(mainwin->messageview);
+}
+
 static void add_address_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
@@ -3710,6 +3924,34 @@ static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focu
        return FALSE;
 }
 
+static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
+                                         gpointer data)
+{
+       is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
+       return FALSE;
+}
+
+static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
+                                         gpointer data)
+{
+       if (!claws_is_starting()
+               && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
+               && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
+
+               if (iconified_count > 0)
+                       hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
+               iconified_count++;
+       }
+       if (state->new_window_state == 0)
+               gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
+       return FALSE;
+}
+
+gboolean mainwindow_is_obscured(void)
+{
+       return is_obscured;
+}
+
 #define BREAK_ON_MODIFIER_KEY() \
        if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
 
@@ -3744,6 +3986,15 @@ gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
                        folderview_select_next_unread(mainwin->folderview, TRUE);
                }
                break;
+#ifdef MAEMO
+       case GDK_F6:
+               if (maemo_mainwindow_is_fullscreen(widget)) {
+                       gtk_window_unfullscreen(GTK_WINDOW(widget));
+                } else {
+                       gtk_window_fullscreen(GTK_WINDOW(widget));
+                }
+               break;
+#endif
        default:
                break;
        }
@@ -3785,7 +4036,7 @@ MainWindow *mainwindow_get_mainwindow(void)
                return NULL;
 }
 
-gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
+static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
 {
        ProgressData *data = (ProgressData *) source;
        MainWindow *mainwin = (MainWindow *) userdata;
@@ -3888,3 +4139,40 @@ void mainwindow_jump_to(const gchar *target)
        
        g_free(tmp);
 }
+
+void mainwindow_exit_folder(MainWindow *mainwin) {
+       if (prefs_common.layout_mode == SMALL_LAYOUT) {
+               folderview_close_opened(mainwin->folderview);
+               mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
+               mainwin->in_folder = FALSE;
+       }
+}
+
+void mainwindow_enter_folder(MainWindow *mainwin) {
+       if (prefs_common.layout_mode == SMALL_LAYOUT) {
+               mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
+               mainwin->in_folder = TRUE;
+       }
+}
+
+#ifdef MAEMO
+gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
+{
+       gint w, h;
+       gtk_window_get_size(GTK_WINDOW(widget), &w, &h); 
+       return (w == 800);
+}
+
+void maemo_window_full_screen_if_needed (GtkWindow *window)
+{
+       if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
+               gtk_window_fullscreen(GTK_WINDOW(window));
+       }
+}
+
+void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
+{
+       g_signal_connect(G_OBJECT(window), "key_press_event",
+                        G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());
+}
+#endif