2004-11-18 [paul] 0.9.12cvs158.1
[claws.git] / src / mainwindow.c
index 63a21438e9ea9e7b4b32d70f1483c29428edb32e..7fda8ebc3b84a0df49265990a131249322feffce 100644 (file)
@@ -119,7 +119,7 @@ static void toolbar_child_detached          (GtkWidget      *widget,
                                                 GtkWidget      *child,
                                                 gpointer        data);
 
-static void ac_label_button_pressed            (GtkWidget      *widget,
+static gboolean ac_label_button_pressed                (GtkWidget      *widget,
                                                 GdkEventButton *event,
                                                 gpointer        data);
 static void ac_menu_popup_closed               (GtkMenuShell   *menu_shell,
@@ -260,6 +260,10 @@ static void set_charset_cb         (MainWindow     *mainwin,
                                         guint           action,
                                         GtkWidget      *widget);
 
+static void set_decode_cb              (MainWindow     *mainwin,
+                                        guint           action,
+                                        GtkWidget      *widget);
+
 static void hide_read_messages   (MainWindow   *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
@@ -435,10 +439,13 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
        {N_("/_File/_Add mailbox"),             NULL, NULL, 0, "<Branch>"},
        {N_("/_File/_Add mailbox/MH..."),       NULL, add_mailbox_cb, 0, NULL},
+       {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/Change folder order"),      NULL, foldersort_cb,  0, NULL},
+       {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
        {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
-       {N_("/_File/Empty _trash"),             "<shift>D", empty_trash_cb, 0, NULL},
+       {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
+       {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
        {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
        {N_("/_File/_Print..."),                NULL, print_cb, 0, NULL},
@@ -614,6 +621,22 @@ static GtkItemFactoryEntry mainwin_entries[] =
 #undef CODESET_SEPARATOR
 #undef CODESET_ACTION
 
+#define DECODE_SEPARATOR \
+       {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"}
+#define DECODE_ACTION(action) \
+        NULL, set_decode_cb, action, "/View/Decode/Auto detect"
+       {N_("/_View/Decode"),           NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/Decode/_Auto detect"),
+        NULL, set_decode_cb, 0, "<RadioItem>"},
+       {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"},
+       {N_("/_View/Decode/_8bit"),             DECODE_ACTION(ENC_8BIT)},
+       {N_("/_View/Decode/_Quoted printable"), DECODE_ACTION(ENC_QUOTED_PRINTABLE)},
+       {N_("/_View/Decode/_Base64"),           DECODE_ACTION(ENC_BASE64)},
+       {N_("/_View/Decode/_Uuencode"),         DECODE_ACTION(ENC_X_UUENCODE)},
+
+#undef DECODE_SEPARATOR
+#undef DECODE_ACTION
+
        {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
        {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
@@ -724,8 +747,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Configuration/_Edit accounts..."),
                                                NULL, account_edit_open, 0, NULL},
        {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
-       {N_("/_Configuration/_Common preferences..."),
-                                               NULL, prefs_common_open_cb, 0, NULL},
+       {N_("/_Configuration/_Preferences..."),
+                                               NULL, prefs_open_cb, 0, NULL},
        {N_("/_Configuration/Pre-processing..."),
                                                NULL, prefs_pre_processing_open_cb, 0, NULL},
        {N_("/_Configuration/Post-processing..."),
@@ -734,7 +757,6 @@ static GtkItemFactoryEntry mainwin_entries[] =
                                                NULL, prefs_filtering_open_cb, 0, NULL},
        {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
        {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
-       {N_("/_Configuration/_Other Preferences..."),  NULL, prefs_open_cb, 0, NULL},
        {N_("/_Configuration/Plugins..."),      NULL, plugins_open_cb, 0, NULL},
 
        {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
@@ -750,6 +772,24 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
 };
 
+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, value, mod);
+               return TRUE;
+       }
+       return FALSE;
+}
+
 MainWindow *main_window_create(SeparateType type)
 {
        MainWindow *mainwin;
@@ -783,6 +823,7 @@ MainWindow *main_window_create(SeparateType type)
        GtkWidget *menuitem;
        gint i;
        guint n_menu_entries;
+       gboolean hide_messageview = FALSE;
 
        static GdkGeometry geometry;
 
@@ -792,8 +833,7 @@ MainWindow *main_window_create(SeparateType type)
        /* main window */
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
-       gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
-       gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
+       gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
 
        if (!geometry.min_height) {
                geometry.min_width = 320;
@@ -893,7 +933,7 @@ MainWindow *main_window_create(SeparateType type)
                             ac_button, _("Select account"), NULL);
        gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
        GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
-       gtk_widget_set_size_request(ac_button, -1, 1);
+       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",
                         G_CALLBACK(ac_label_button_pressed), mainwin);
@@ -979,7 +1019,8 @@ 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",
@@ -1029,10 +1070,14 @@ MainWindow *main_window_create(SeparateType type)
        main_window_update_actions_menu(mainwin);
 
        /* attach accel groups to main window */
-#define        ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)        \
-       gtk_window_add_accel_group                      \
-               (GTK_WINDOW(win),                       \
-                gtk_item_factory_from_widget(menu)->accel_group)                
+#define        ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
+       gtk_window_add_accel_group                                      \
+               (GTK_WINDOW(win),                                       \
+                gtk_item_factory_from_widget(menu)->accel_group);      \
+       g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
+                       "accel_activate",                               \
+                       G_CALLBACK(main_window_accel_activate), mainwin);
+                        
        
        ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
        
@@ -1071,6 +1116,9 @@ 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;
 }
 
@@ -1479,7 +1527,7 @@ void main_window_get_size(MainWindow *mainwin)
                prefs_common.msgview_height = allocation->height;
        }
 
-       debug_print("summaryview size: %d x %d\n",
+/*     debug_print("summaryview size: %d x %d\n",
                    prefs_common.summaryview_width,
                    prefs_common.summaryview_height);
        debug_print("folderview size: %d x %d\n",
@@ -1487,7 +1535,7 @@ void main_window_get_size(MainWindow *mainwin)
                    prefs_common.folderview_height);
        debug_print("messageview size: %d x %d\n",
                    prefs_common.msgview_width,
-                   prefs_common.msgview_height);
+                   prefs_common.msgview_height); */
 }
 
 void main_window_get_position(MainWindow *mainwin)
@@ -1522,15 +1570,13 @@ void main_window_get_position(MainWindow *mainwin)
 
 void main_window_progress_on(MainWindow *mainwin)
 {
-       gtk_progress_set_show_text(GTK_PROGRESS(mainwin->progressbar), TRUE);
-       gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), "");
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
 }
 
 void main_window_progress_off(MainWindow *mainwin)
 {
-       gtk_progress_set_show_text(GTK_PROGRESS(mainwin->progressbar), FALSE);
-       gtk_progress_bar_update(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
-       gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), "");
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
 }
 
 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
@@ -1538,8 +1584,8 @@ void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
        gchar buf[32];
 
        g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
-       gtk_progress_set_format_string(GTK_PROGRESS(mainwin->progressbar), buf);
-       gtk_progress_bar_update(GTK_PROGRESS_BAR(mainwin->progressbar),
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
                                (cur == 0 && total == 0) ? 0 :
                                (gfloat)cur / (gfloat)total);
 }
@@ -1566,7 +1612,7 @@ void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
                manage_window_focus_in(mainwin->window, NULL, NULL);
        }
 
-       procmsg_empty_trash();
+       procmsg_empty_all_trash();
 
        if (mainwin->summaryview->folder_item &&
            mainwin->summaryview->folder_item->stype == F_TRASH)
@@ -1590,8 +1636,8 @@ void main_window_add_mailbox(MainWindow *mainwin)
                return;
        }
        folder = folder_new(folder_get_class_from_string("mh"), 
-                           !strcmp(path, "Mail") ? _("Mailbox") : g_basename(path),
-                           path);
+                           !strcmp(path, "Mail") ? _("Mailbox") : 
+                           g_path_get_basename(path), path);
        g_free(path);
 
        if (folder->klass->create_tree(folder) < 0) {
@@ -1691,7 +1737,7 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                 {"/File/Add mailbox/MH..."                   , M_UNLOCKED},
                {"/File/Change folder order"                  , M_UNLOCKED},
                {"/File/Export to mbox file..."               , M_UNLOCKED},
-               {"/File/Empty trash"                          , M_UNLOCKED},
+               {"/File/Empty all Trash folders"              , M_UNLOCKED},
                {"/File/Work offline"                         , M_UNLOCKED},
 
                {"/File/Save as...", M_TARGET_EXIST|M_UNLOCKED},
@@ -1936,10 +1982,7 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
                gtk_window_set_title(GTK_WINDOW(folderwin),
                                     _("Sylpheed - Folder View"));
-               gtk_window_set_wmclass(GTK_WINDOW(folderwin),
-                                      "folder_view", "Sylpheed");
-               gtk_window_set_policy(GTK_WINDOW(folderwin),
-                                     TRUE, TRUE, FALSE);
+               gtk_window_set_resizable(GTK_WINDOW(folderwin), TRUE);
                gtk_window_move(GTK_WINDOW(folderwin), prefs_common.folderwin_x,
                                prefs_common.folderwin_y);
                gtk_container_set_border_width(GTK_CONTAINER(folderwin),
@@ -1957,12 +2000,13 @@ static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
                messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
                gtk_window_set_title(GTK_WINDOW(messagewin),
                                     _("Sylpheed - Message View"));
-               gtk_window_set_wmclass(GTK_WINDOW(messagewin),
-                                      "message_view", "Sylpheed");
-               gtk_window_set_policy(GTK_WINDOW(messagewin),
-                                     TRUE, TRUE, FALSE);
-               gtk_window_move(GTK_WINDOW(messagewin), prefs_common.main_msgwin_x,
+               gtk_window_set_resizable(GTK_WINDOW(messagewin), TRUE);
+               gtk_window_move(GTK_WINDOW(messagewin), 
+                               prefs_common.main_msgwin_x,
                                prefs_common.main_msgwin_y);
+               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",
@@ -2196,7 +2240,7 @@ static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
        gtk_widget_set_usize(child, -1, -1);
 }
 
-static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
+static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
                                    gpointer data)
 {
        MainWindow *mainwin = (MainWindow *)data;
@@ -2602,20 +2646,34 @@ static void set_charset_cb(MainWindow *mainwin, guint action,
 
        if (GTK_CHECK_MENU_ITEM(widget)->active) {
                str = conv_get_charset_str((CharSet)action);
-               g_free(prefs_common.force_charset);
-               prefs_common.force_charset = str ? g_strdup(str) : NULL;
-
+               
+               g_free(mainwin->messageview->forced_charset);
+               mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
+               procmime_force_charset(str);
+               
                summary_redisplay_msg(mainwin->summaryview);
                
                debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
        }
 }
 
+static void set_decode_cb(MainWindow *mainwin, guint action,
+                          GtkWidget *widget)
+{
+       if (GTK_CHECK_MENU_ITEM(widget)->active) {
+               mainwin->messageview->forced_encoding = (EncodingType)action;
+               
+               summary_redisplay_msg(mainwin->summaryview);
+               
+               debug_print("forced encoding: %d\n", action);
+       }
+}
+
 static void hide_read_messages (MainWindow *mainwin, guint action,
                                GtkWidget *widget)
 {
        if (!mainwin->summaryview->folder_item
-           || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
+           || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
                return;
        summary_toggle_show_read_messages(mainwin->summaryview);
 }
@@ -2666,6 +2724,7 @@ static void sort_summary_cb(MainWindow *mainwin, guint action,
                summary_sort(mainwin->summaryview, (FolderSortKey)action,
                             GTK_CHECK_MENU_ITEM(menuitem)->active
                             ? SORT_ASCENDING : SORT_DESCENDING);
+               item->sort_key = action;
        }
 }
 
@@ -2692,7 +2751,7 @@ static void delete_duplicated_cb(MainWindow *mainwin, guint action,
 {
        FolderItem *item;
 
-       item = folderview_get_selected(mainwin->folderview);
+       item = folderview_get_selected_item(mainwin->folderview);
        if (item) {
                main_window_cursor_wait(mainwin);
                STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
@@ -2867,7 +2926,7 @@ static void create_processing_cb(MainWindow *mainwin, guint action,
 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
                                 GtkWidget *widget)
 {
-       prefs_common_open();
+       /* prefs_common_open(); */
 }
 
 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
@@ -3004,14 +3063,18 @@ gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
 {
        MainWindow *mainwin = (MainWindow*) data;
        
-       if (!mainwin || !event) return;
-               
+       if (!mainwin || !event) 
+               return FALSE;
+
+       if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
+               return FALSE;
+
        switch (event->keyval) {
        case GDK_Q:             /* Quit */
                BREAK_ON_MODIFIER_KEY();
 
                app_exit_cb(mainwin, 0, NULL);
-               return;
+               return FALSE;
        case GDK_space:
                if (mainwin->folderview && mainwin->summaryview
                    && !mainwin->summaryview->displayed) {
@@ -3069,10 +3132,12 @@ gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
        switch (data->cmd) {
        case PROGRESS_COMMAND_START:
        case PROGRESS_COMMAND_STOP:
-               gtk_progress_set_percentage(GTK_PROGRESS(mainwin->progressbar), 0.0);
+               gtk_progress_bar_set_fraction
+                       (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
                break;
        case PROGRESS_COMMAND_SET_PERCENTAGE:
-               gtk_progress_set_percentage(GTK_PROGRESS(mainwin->progressbar), data->value);
+               gtk_progress_bar_set_fraction
+                       (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
                break;          
        }
        while (gtk_events_pending()) gtk_main_iteration ();