toolbar reply refactoring: part 2
[claws.git] / src / toolbar.c
index 0937cca77b1eb1cadab212e5a3e485dfb7107d04..d0680477853eaf898ad1adba473f8a1efc5f3538 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001 Hiroyuki Yamamoto
+ * Copyright (C) 2001-2003 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
@@ -37,6 +37,7 @@
 
 #include "intl.h"
 #include "mainwindow.h"
+#include "summaryview.h"
 #include "compose.h"
 #include "utils.h"
 #include "xml.h"
@@ -87,6 +88,8 @@ static void activate_compose_button           (Toolbar        *toolbar,
                                                 ComposeButtonType type);
 
 /* toolbar callbacks */
+static void toolbar_reply                      (gpointer        data, 
+                                                guint           action);
 static void toolbar_delete_cb                  (GtkWidget      *widget,
                                                 gpointer        data);
 
@@ -166,7 +169,7 @@ struct {
        { "A_ADDRBOOK",      N_("Address book")                         },
 
        { "A_SYL_ACTIONS",   N_("Sylpheed Actions Feature")             }, 
-       { "A_SEPARATOR",     N_("Separator")                            }
+       { "A_SEPARATOR",     "Separator"                                }
 };
 
 /* struct holds configuration files and a list of
@@ -520,7 +523,7 @@ void toolbar_save_config_file(ToolbarType source)
 
                fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);      
        
-               if (prefs_write_close (pfile) < 0 ) 
+               if (prefs_file_close (pfile) < 0 ) 
                        g_warning("failed to write toolbar configuration to file\n");
        } else
                g_warning("failed to open toolbar configuration file for writing\n");
@@ -567,7 +570,7 @@ void toolbar_read_config_file(ToolbarType source)
                        } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
                                ToolbarItem *item = g_new0(ToolbarItem, 1);
                        
-                               item->file   = g_strdup(TOOLBAR_TAG_SEPARATOR);
+                               item->file   = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
                                item->index  = A_SEPARATOR;
                                toolbar_config[source].item_list = 
                                        g_slist_append(toolbar_config[source].item_list, item);
@@ -1069,9 +1072,7 @@ static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
        switch (toolbar_item->type) {
        case TOOLBAR_MSGVIEW:
                msgview = (MessageView*)toolbar_item->parent;
-               /* make sure the selected msg in summaryview is 
-                  the one we are asked to delete */
-               delete_msgview_cb(msgview, 0, widget);
+               messageview_delete(msgview);
                break;
         case TOOLBAR_MAIN:
                mainwin = (MainWindow*)toolbar_item->parent;
@@ -1115,10 +1116,7 @@ static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
 
 static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
 {
-       MainWindow *mainwin = get_mainwin(data);
-
-       g_return_if_fail(mainwin != NULL);
-       reply_cb(mainwin, action, widget);
+       toolbar_reply(data, action);
 }
 
 
@@ -1127,36 +1125,8 @@ static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
  */
 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
 {
-       ToolbarItem *toolbar_item = (ToolbarItem*)data;
-       MainWindow *mainwin;
-       MessageView *msgview;
-
-       g_return_if_fail(toolbar_item != NULL);
-
-       switch (toolbar_item->type) {
-       case TOOLBAR_MAIN:
-               mainwin = (MainWindow*)toolbar_item->parent;
-               if (prefs_common.default_reply_list)
-                       reply_cb(mainwin, 
-                                prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
-                                : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, 
-                                NULL);
-               else
-                       reply_cb(mainwin, 
-                                prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
-                                : COMPOSE_REPLY_WITHOUT_QUOTE,
-                                NULL);
-               break;
-       case TOOLBAR_MSGVIEW:
-               msgview = (MessageView*)toolbar_item->parent;
-               compose_reply(msgview->msginfo,
-                             prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
-                             : COMPOSE_REPLY_WITHOUT_QUOTE,
-                             FALSE, FALSE, FALSE, NULL);
-               break;
-       default:
-               debug_print("toolbar event not supported\n");
-       }
+       toolbar_reply(data, prefs_common.reply_with_quote ? 
+                     COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
 }
 
 
@@ -1165,30 +1135,9 @@ static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
  */
 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
 {
-       ToolbarItem *toolbar_item = (ToolbarItem*)data;
-       MainWindow *mainwin;
-       MessageView *msgview;
-
-       g_return_if_fail(toolbar_item != NULL);
-
-       switch (toolbar_item->type) {
-       case TOOLBAR_MAIN:
-               mainwin = (MainWindow*)toolbar_item->parent;
-               reply_cb(mainwin, 
-                        prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
-                        : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, 
-                        NULL);
-               break;
-       case TOOLBAR_MSGVIEW:
-               msgview = (MessageView*)toolbar_item->parent;
-               compose_reply(msgview->msginfo,
-                             prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
-                             : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
-                             TRUE, FALSE, FALSE, NULL);
-               break;
-       default:
-               debug_print("toolbar event not supported\n");
-       }
+       toolbar_reply(data,
+                     prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
+                     : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
 }
 
 
@@ -1197,30 +1146,9 @@ static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
  */
 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
 {
-       ToolbarItem *toolbar_item = (ToolbarItem*)data;
-       MainWindow *mainwin;
-       MessageView *msgview;
-
-       g_return_if_fail(toolbar_item != NULL);
-
-       switch (toolbar_item->type) {
-       case TOOLBAR_MAIN:
-               mainwin = (MainWindow*)toolbar_item->parent;
-               reply_cb(mainwin, 
-                        prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
-                        : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, 
-                        NULL);
-               break;
-       case TOOLBAR_MSGVIEW:
-               msgview = (MessageView*)toolbar_item->parent;
-               compose_reply(msgview->msginfo,
-                             prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
-                             : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
-                             FALSE, TRUE, FALSE, NULL);
-               break;
-       default:
-               debug_print("toolbar event not supported\n");
-       }
+       toolbar_reply(data, 
+                     prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
+                     : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
 }
 
 
@@ -1229,30 +1157,9 @@ static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
  */ 
 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
 {
-       ToolbarItem *toolbar_item = (ToolbarItem*)data;
-       MainWindow *mainwin;
-       MessageView *msgview;
-
-       g_return_if_fail(toolbar_item != NULL);
-
-       switch (toolbar_item->type) {
-       case TOOLBAR_MAIN:
-               mainwin = (MainWindow*)toolbar_item->parent;
-               reply_cb(mainwin, 
-                        prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
-                        : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, 
-                        NULL);
-               break;
-       case TOOLBAR_MSGVIEW:
-               msgview = (MessageView*)toolbar_item->parent;
-               compose_reply(msgview->msginfo,
-                             prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
-                             : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
-                             FALSE, FALSE, FALSE, NULL);
-               break;
-       default:
-               debug_print("toolbar event not supported\n\n");
-       }
+       toolbar_reply(data, 
+                     prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
+                     : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
 }
 
 /*
@@ -1285,23 +1192,7 @@ static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
  */
 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
 {
-       ToolbarItem *toolbar_item = (ToolbarItem*)data;
-       MainWindow *mainwin;
-
-       g_return_if_fail(toolbar_item != NULL);
-
-       switch (toolbar_item->type) {
-       case TOOLBAR_MAIN:
-               mainwin = (MainWindow*)toolbar_item->parent;
-               if (prefs_common.forward_as_attachment)
-                       reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
-               else
-                       reply_cb(mainwin, COMPOSE_FORWARD, NULL);
-               break;
-               
-       default:
-               debug_print("toolbar event not supported\n");
-       }
+       toolbar_reply(data, COMPOSE_FORWARD);
 }
 
 
@@ -1466,7 +1357,7 @@ static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
 }
 
 static void toolbar_buttons_cb(GtkWidget   *widget, 
-                                     ToolbarItem *item)
+                              ToolbarItem *item)
 {
        gint num_items;
        gint i;
@@ -2028,48 +1919,47 @@ void toolbar_init(Toolbar * toolbar) {
        toolbar_destroy(toolbar);
 }
 
-/* exported functions */
-
-void delete_msgview_cb(gpointer data, guint action, GtkWidget *widget)
+/*
+ */
+static void toolbar_reply(gpointer data, guint action)
 {
-       MessageView *msgview = (MessageView*)data;
+       ToolbarItem *toolbar_item = (ToolbarItem*)data;
+       MainWindow *mainwin;
+       MessageView *msgview;
+       GSList *msginfo_list = NULL;
+       gchar *body;
 
-       if (msgview->mainwin->summaryview->selected) {
-               SummaryView *summaryview = msgview->mainwin->summaryview;
-               GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
-               MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree, 
-                                                              summaryview->selected);  
-               if (msginfo->msgnum != msgview->msginfo->msgnum) {
-                       alertpanel_error(_("Message already removed from folder."));
-                       return;
-               }
+       g_return_if_fail(toolbar_item != NULL);
+
+       switch (toolbar_item->type) {
+       case TOOLBAR_MAIN:
+               mainwin = (MainWindow*)toolbar_item->parent;
+               msginfo_list = summary_get_selection(mainwin->summaryview);
+               msgview = (MessageView*)mainwin->messageview;
+               break;
+       case TOOLBAR_MSGVIEW:
+               msgview = (MessageView*)toolbar_item->parent;
+               msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
+               break;
+       default:
+               return;
        }
-       
-       summary_delete(msgview->mainwin->summaryview);  
-       
-       if (msgview->mainwin->summaryview->selected) {
-               SummaryView *summaryview = msgview->mainwin->summaryview;
-               GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
-               MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree, 
-                                                              summaryview->selected);
-               messageview_show(msgview, msginfo, 
-                                msgview->all_headers);
-       } else {
-               toolbar_clear_list(TOOLBAR_MSGVIEW);
-               toolbar_destroy(msgview->toolbar);
-               gtk_widget_destroy(msgview->window);
-       }       
-}
-
-void reply_cb(gpointer data, guint action, GtkWidget *widget)
-{
-       MainWindow *mainwin = (MainWindow*)data;
 
-       g_return_if_fail(mainwin != NULL);
+       g_return_if_fail(msgview != NULL);
+       body = messageview_get_selection(msgview);
+
+       g_return_if_fail(msginfo_list != NULL);
+       compose_reply_mode((ComposeMode)action, msginfo_list, body);
+
+       g_free(body);
+       g_slist_free(msginfo_list);
 
-       summary_reply(mainwin->summaryview, (ComposeMode)action);
+       /* TODO: update reply state ion summaryview */
 }
 
+
+/* exported functions */
+
 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
 {
        MainWindow *mainwin = (MainWindow*)data;
@@ -2102,7 +1992,6 @@ void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
                                (folder->queue, prefs_common.savemsg) < 0)
                                alertpanel_error(_("Some errors occurred while sending queued messages."));
                        folder_item_scan(folder->queue);
-                       folder_update_item(folder->queue, TRUE);
                }
        }
 }