2006-01-27 [cleroy] 1.9.100cvs192
[claws.git] / src / summaryview.c
index bfb812cf63d5201713e3bdb5aaca3e8512e366a4..9956843184dfae799d841e939178ad5b57740c7b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
  *
  * 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
@@ -176,7 +176,8 @@ static void summary_set_ctree_from_list     (SummaryView            *summaryview,
                                         GSList                 *mlist);
 static void summary_set_header         (SummaryView            *summaryview,
                                         gchar                  *text[],
-                                        MsgInfo                *msginfo);
+                                        MsgInfo                *msginfo,
+                                        gboolean               *free_from_to);
 static void summary_display_msg                (SummaryView            *summaryview,
                                         GtkCTreeNode           *row);
 static void summary_display_msg_full   (SummaryView            *summaryview,
@@ -847,14 +848,14 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item)
                gboolean changed = FALSE;
 
                val = alertpanel(_("Process mark"),
-                                _("Some marks are left. Process it?"),
-                                GTK_STOCK_YES, GTK_STOCK_NO, GTK_STOCK_CANCEL);
-               if (G_ALERTDEFAULT == val) {
+                                _("Some marks are left. Process them?"),
+                                GTK_STOCK_NO, GTK_STOCK_YES, GTK_STOCK_CANCEL);
+               if (G_ALERTALTERNATE == val) {
                        summary_unlock(summaryview);
                        summary_execute(summaryview);
                        summary_lock(summaryview);
                        changed = TRUE;
-               } else if (G_ALERTALTERNATE == val) {
+               } else if (G_ALERTDEFAULT == val) {
                        /* DO NOTHING */
                } else {
                        summary_unlock(summaryview);
@@ -1265,9 +1266,12 @@ static void summary_set_menu_sensitive(SummaryView *summaryview)
 
        summary_lock(summaryview);
        menuitem = gtk_item_factory_get_widget(ifactory, "/View/All header");
-       gtk_check_menu_item_set_active
-               (GTK_CHECK_MENU_ITEM(menuitem),
-                summaryview->messageview->mimeview->textview->show_all_headers);
+       if (summaryview->messageview 
+       &&  summaryview->messageview->mimeview
+       &&  summaryview->messageview->mimeview->textview)
+               gtk_check_menu_item_set_active
+                       (GTK_CHECK_MENU_ITEM(menuitem),
+                        summaryview->messageview->mimeview->textview->show_all_headers);
        summary_unlock(summaryview);
 }
 
@@ -1293,19 +1297,19 @@ void summary_select_prev_unread(SummaryView *summaryview)
                                val = alertpanel(_("No more unread messages"),
                                                 _("No unread message found. "
                                                   "Search from the end?"),
-                                                GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+                                                GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
                                break;
                        case NEXTUNREADMSGDIALOG_ASSUME_YES:
-                               val = G_ALERTDEFAULT;
+                               val = G_ALERTALTERNATE;
                                break;
                        case NEXTUNREADMSGDIALOG_ASSUME_NO:
-                               val = !G_ALERTDEFAULT;
+                               val = !G_ALERTALTERNATE;
                                break;
                        default:
                                debug_print(
                                        _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
                }
-               if (val != G_ALERTDEFAULT) return;
+               if (val != G_ALERTALTERNATE) return;
                node = summary_find_prev_flagged_msg(summaryview, NULL,
                                                     MSG_UNREAD, FALSE);
        }
@@ -1345,10 +1349,10 @@ void summary_select_next_unread(SummaryView *summaryview)
                                        val = alertpanel(_("No more unread messages"),
                                                         _("No unread message found. "
                                                           "Go to next folder?"),
-                                                        GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+                                                        GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
                                        break;
                                case NEXTUNREADMSGDIALOG_ASSUME_YES:
-                                       val = G_ALERTDEFAULT;
+                                       val = G_ALERTALTERNATE;
                                        break;
                                case NEXTUNREADMSGDIALOG_ASSUME_NO:
                                        val = G_ALERTOTHER;
@@ -1358,7 +1362,7 @@ void summary_select_next_unread(SummaryView *summaryview)
                                                _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
                        }
 
-                       if (val == G_ALERTDEFAULT) {
+                       if (val == G_ALERTALTERNATE) {
                                folderview_select_next_unread(summaryview->folderview);
                                return;
                        } 
@@ -1392,19 +1396,19 @@ void summary_select_prev_new(SummaryView *summaryview)
                                val = alertpanel(_("No more new messages"),
                                                 _("No new message found. "
                                                   "Search from the end?"),
-                                                GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+                                                GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
                                break;
                        case NEXTUNREADMSGDIALOG_ASSUME_YES:
-                               val = G_ALERTDEFAULT;
+                               val = G_ALERTALTERNATE;
                                break;
                        case NEXTUNREADMSGDIALOG_ASSUME_NO:
-                               val = !G_ALERTDEFAULT;
+                               val = !G_ALERTALTERNATE;
                                break;
                        default:
                                debug_print(
                                        _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
                }
-               if (val != G_ALERTDEFAULT) return;
+               if (val != G_ALERTALTERNATE) return;
                node = summary_find_prev_flagged_msg(summaryview, NULL,
                                                     MSG_NEW, FALSE);
        }
@@ -1444,10 +1448,10 @@ void summary_select_next_new(SummaryView *summaryview)
                                        val = alertpanel(_("No more new messages"),
                                                         _("No new message found. "
                                                           "Go to next folder?"),
-                                                        GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+                                                        GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
                                        break;
                                case NEXTUNREADMSGDIALOG_ASSUME_YES:
-                                       val = G_ALERTDEFAULT;
+                                       val = G_ALERTALTERNATE;
                                        break;
                                case NEXTUNREADMSGDIALOG_ASSUME_NO:
                                        val = G_ALERTOTHER;
@@ -1457,7 +1461,7 @@ void summary_select_next_new(SummaryView *summaryview)
                                                _("Internal error: unexpected value for prefs_common.next_unread_msg_dialog\n"));
                        }
 
-                       if (val == G_ALERTDEFAULT) {
+                       if (val == G_ALERTALTERNATE) {
                                folderview_select_next_new(summaryview->folderview);
                                return;
                        } 
@@ -1482,8 +1486,8 @@ void summary_select_prev_marked(SummaryView *summaryview)
                val = alertpanel(_("No more marked messages"),
                                 _("No marked message found. "
                                   "Search from the end?"),
-                                GTK_STOCK_YES, GTK_STOCK_NO, NULL);
-               if (val != G_ALERTDEFAULT) return;
+                                GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
+               if (val != G_ALERTALTERNATE) return;
                node = summary_find_prev_flagged_msg(summaryview, NULL,
                                                     MSG_MARKED, TRUE);
        }
@@ -1507,8 +1511,8 @@ void summary_select_next_marked(SummaryView *summaryview)
                val = alertpanel(_("No more marked messages"),
                                 _("No marked message found. "
                                   "Search from the beginning?"),
-                                GTK_STOCK_YES, GTK_STOCK_NO, NULL);
-               if (val != G_ALERTDEFAULT) return;
+                                GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
+               if (val != G_ALERTALTERNATE) return;
                node = summary_find_next_flagged_msg(summaryview, NULL,
                                                     MSG_MARKED, TRUE);
        }
@@ -1532,8 +1536,8 @@ void summary_select_prev_labeled(SummaryView *summaryview)
                val = alertpanel(_("No more labeled messages"),
                                 _("No labeled message found. "
                                   "Search from the end?"),
-                                GTK_STOCK_YES, GTK_STOCK_NO, NULL);
-               if (val != G_ALERTDEFAULT) return;
+                                GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
+               if (val != G_ALERTALTERNATE) return;
                node = summary_find_prev_flagged_msg(summaryview, NULL,
                                                     MSG_CLABEL_FLAG_MASK, TRUE);
        }
@@ -1557,8 +1561,8 @@ void summary_select_next_labeled(SummaryView *summaryview)
                val = alertpanel(_("No more labeled messages"),
                                 _("No labeled message found. "
                                   "Search from the beginning?"),
-                                GTK_STOCK_YES, GTK_STOCK_NO, NULL);
-               if (val != G_ALERTDEFAULT) return;
+                                GTK_STOCK_NO, "+"GTK_STOCK_YES, NULL);
+               if (val != G_ALERTALTERNATE) return;
                node = summary_find_next_flagged_msg(summaryview, NULL,
                                                     MSG_CLABEL_FLAG_MASK, TRUE);
        }
@@ -2226,8 +2230,9 @@ gboolean summary_insert_gnode_func(GtkCTree *ctree, guint depth, GNode *gnode,
        gint *col_pos = summaryview->col_pos;
        const gchar *msgid = msginfo->msgid;
        GHashTable *msgid_table = summaryview->msgid_table;
-
-       summary_set_header(summaryview, text, msginfo);
+       gboolean free_from_to = FALSE;
+       
+       summary_set_header(summaryview, text, msginfo, &free_from_to);
 
        gtk_sctree_set_node_info(ctree, cnode, text[col_pos[S_COL_SUBJECT]], 2,
                                NULL, NULL, NULL, NULL, FALSE,
@@ -2244,6 +2249,13 @@ gboolean summary_insert_gnode_func(GtkCTree *ctree, guint depth, GNode *gnode,
        SET_TEXT(S_COL_TO);
        /* SET_TEXT(S_COL_SUBJECT);  already set by node info */
 
+       if (free_from_to) {
+               g_free(text[col_pos[S_COL_FROM]]);
+               g_free(text[col_pos[S_COL_TO]]);
+               text[col_pos[S_COL_FROM]] = NULL;
+               text[col_pos[S_COL_TO]] = NULL;
+       }
+
 #undef SET_TEXT
 
        GTKUT_CTREE_NODE_SET_ROW_DATA(cnode, msginfo);
@@ -2301,16 +2313,25 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
                summary_thread_init(summaryview);
        } else {
                gchar *text[N_SUMMARY_COLS];
+               gboolean free_from_to = FALSE;
+               gint *col_pos = summaryview->col_pos;
+
                cur = mlist;
                for (; mlist != NULL; mlist = mlist->next) {
                        msginfo = (MsgInfo *)mlist->data;
 
-                       summary_set_header(summaryview, text, msginfo);
+                       summary_set_header(summaryview, text, msginfo, &free_from_to);
 
                        node = gtk_sctree_insert_node
                                (ctree, NULL, node, text, 2,
                                 NULL, NULL, NULL, NULL,
                                 FALSE, FALSE);
+                       if (free_from_to) {
+                               g_free(text[col_pos[S_COL_FROM]]);
+                               g_free(text[col_pos[S_COL_TO]]);
+                               text[col_pos[S_COL_FROM]] = NULL;
+                               text[col_pos[S_COL_TO]] = NULL;
+                       }
                        GTKUT_CTREE_NODE_SET_ROW_DATA(node, msginfo);
                        summary_set_marks_func(ctree, node, summaryview);
 
@@ -2392,7 +2413,7 @@ static gchar *summary_complete_address(const gchar *addr)
 }
 
 static void summary_set_header(SummaryView *summaryview, gchar *text[],
-                              MsgInfo *msginfo)
+                              MsgInfo *msginfo, gboolean *free_from_to)
 {
        static gchar date_modified[80];
        static gchar col_score[11];
@@ -2457,12 +2478,14 @@ static void summary_set_header(SummaryView *summaryview, gchar *text[],
        if (!should_swap) {
                text[col_pos[S_COL_FROM]] = from_text;
                text[col_pos[S_COL_TO]] = to_text;
+               *free_from_to = FALSE;
        } else {
                gchar *tmp = NULL;
                tmp = g_strconcat("-->", to_text, NULL);
                text[col_pos[S_COL_FROM]] = tmp;
                tmp = g_strconcat("<--", from_text, NULL);
                text[col_pos[S_COL_TO]] = tmp;
+               *free_from_to = TRUE;
        }
        
        if (summaryview->simplify_subject_preg != NULL)
@@ -3254,8 +3277,8 @@ void summary_delete(SummaryView *summaryview)
 
        aval = alertpanel(_("Delete message(s)"),
                          _("Do you really want to delete selected message(s)?"),
-                         GTK_STOCK_YES, GTK_STOCK_NO, NULL);
-       if (aval != G_ALERTDEFAULT) return;
+                         GTK_STOCK_CANCEL, "+"GTK_STOCK_DELETE, NULL);
+       if (aval != G_ALERTALTERNATE) return;
 
        for (cur = GTK_CLIST(ctree)->selection; cur != NULL && cur->data != NULL; 
             cur = cur->next) {
@@ -3411,6 +3434,8 @@ void summary_move_selected_to(SummaryView *summaryview, FolderItem *to_folder)
 
        END_LONG_OPERATION(summaryview);
 
+       summaryview->display_msg = prefs_common.always_show_msg;
+       
        if (prefs_common.immediate_exec) {
                summary_execute(summaryview);
        } else {
@@ -3646,8 +3671,10 @@ static void print_mimeview(MimeView *mimeview)
        ||  !mimeview->textview->text)
                alertpanel_warning(_("Cannot print: the message doesn't "
                                     "contain text."));
-       else
+       else {
+               gtk_widget_realize(mimeview->textview->text);
                gedit_print(GTK_TEXT_VIEW(mimeview->textview->text));
+       }
 }
 #endif