From a07a513dcca1b9a8a90499658a27a528660ade40 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 30 Nov 2006 07:44:59 +0000 Subject: implemented printing of MIME part. Code cleanups. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1386 ee746299-78ed-0310-b773-934348b2243d --- src/messageview.c | 26 ++------------- src/mimeview.c | 51 +++++++++++++++++++++++++++-- src/mimeview.h | 4 ++- src/printing.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++---- src/printing.h | 19 +++++++++-- src/summaryview.c | 41 ++---------------------- 6 files changed, 162 insertions(+), 74 deletions(-) (limited to 'src') diff --git a/src/messageview.c b/src/messageview.c index 872a72ab..1b436a71 100644 --- a/src/messageview.c +++ b/src/messageview.c @@ -50,6 +50,7 @@ #include "alertpanel.h" #include "inputdialog.h" #include "manage_window.h" +#include "printing.h" #include "procmsg.h" #include "procheader.h" #include "procmime.h" @@ -753,32 +754,11 @@ static void save_as_cb(gpointer data, guint action, GtkWidget *widget) static void print_cb(gpointer data, guint action, GtkWidget *widget) { MessageView *messageview = (MessageView *)data; - const gchar *cmdline; - gchar *msg; if (!messageview->msginfo) return; - cmdline = prefs_common.print_cmd; - - msg = g_strconcat - (_("The message will be printed with the following command:"), - "\n\n", cmdline ? cmdline : _("(Default print command)"), - NULL); - if (alertpanel(_("Print"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL) - != G_ALERTDEFAULT) { - g_free(msg); - return; - } - g_free(msg); - - if (cmdline && str_find_format_times(cmdline, 's') != 1) { - alertpanel_error(_("Print command line is invalid:\n`%s'"), - cmdline); - return; - } - - procmsg_print_message(messageview->msginfo, cmdline, - messageview->textview->show_all_headers); + printing_print_message(messageview->msginfo, + messageview->textview->show_all_headers); } static void close_cb(gpointer data, guint action, GtkWidget *widget) diff --git a/src/mimeview.c b/src/mimeview.c index b117d6a9..9ce62a15 100644 --- a/src/mimeview.c +++ b/src/mimeview.c @@ -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 * * 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 @@ -51,6 +51,7 @@ #include "textview.h" #include "imageview.h" #include "procmime.h" +#include "procheader.h" #include "summaryview.h" #include "menu.h" #include "filesel.h" @@ -129,7 +130,8 @@ static GtkItemFactoryEntry mimeview_popup_entries[] = {N_("/Open _with..."), NULL, mimeview_open_with, 0, NULL}, {N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL}, {N_("/_Save as..."), NULL, mimeview_save_as, 0, NULL}, - {N_("/Save _all..."), NULL, mimeview_save_all, 0, NULL} + {N_("/Save _all..."), NULL, mimeview_save_all, 0, NULL}, + {N_("/_Print..."), NULL, mimeview_print, 0, NULL} #if USE_GPGME , {N_("/_Check signature"), NULL, mimeview_check_signature, 0, NULL} @@ -843,6 +845,15 @@ static gint mimeview_button_pressed(GtkWidget *widget, GdkEventButton *event, else menu_set_sensitive(mimeview->popupfactory, "/Open", TRUE); + + if (partinfo && (partinfo->mime_type == MIME_TEXT || + partinfo->mime_type == MIME_TEXT_HTML || + partinfo->mime_type == MIME_MESSAGE_RFC822)) + menu_set_sensitive(mimeview->popupfactory, + "/Print...", TRUE); + else + menu_set_sensitive(mimeview->popupfactory, + "/Print...", FALSE); #if USE_GPGME menu_set_sensitive(mimeview->popupfactory, "/Check signature", @@ -1048,6 +1059,42 @@ void mimeview_save_all(MimeView *mimeview) g_free(dir); } +void mimeview_print(MimeView *mimeview) +{ + MimeInfo *partinfo; + + if (!mimeview->opened) return; + if (!mimeview->file) return; + + partinfo = mimeview_get_selected_part(mimeview); + g_return_if_fail(partinfo != NULL); + + if (partinfo->mime_type == MIME_MESSAGE_RFC822) { + gchar *filename; + MsgInfo *msginfo; + MsgFlags flags = {0, 0}; + + filename = procmime_get_tmp_file_name(partinfo); + if (procmime_get_part(filename, mimeview->file, partinfo) < 0) { + alertpanel_error + (_("Can't save the part of multipart message.")); + g_free(filename); + return; + } + + msginfo = procheader_parse_file(filename, flags, TRUE); + msginfo->file_path = filename; + filename = NULL; + printing_print_message + (msginfo, mimeview->textview->show_all_headers); + procmsg_msginfo_free(msginfo); + } else if (partinfo->mime_type == MIME_TEXT || + partinfo->mime_type == MIME_TEXT_HTML) { + printing_print_message_part(mimeview->messageview->msginfo, + partinfo); + } +} + static void mimeview_launch(MimeView *mimeview) { MimeInfo *partinfo; diff --git a/src/mimeview.h b/src/mimeview.h index 6e11f9fe..a9a3df40 100644 --- a/src/mimeview.h +++ b/src/mimeview.h @@ -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 * * 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 @@ -90,4 +90,6 @@ void mimeview_pass_key_press_event (MimeView *mimeview, void mimeview_save_as (MimeView *mimeview); void mimeview_save_all (MimeView *mimeview); +void mimeview_print (MimeView *mimeview); + #endif /* __MIMEVIEW_H__ */ diff --git a/src/printing.c b/src/printing.c index 591055a6..b83d10a3 100644 --- a/src/printing.c +++ b/src/printing.c @@ -24,10 +24,11 @@ #include "defs.h" #include "printing.h" -#if GTK_CHECK_VERSION(2, 10, 0) #include #include +#if GTK_CHECK_VERSION(2, 10, 0) #include +#endif #include @@ -35,10 +36,13 @@ #include "procmsg.h" #include "procheader.h" #include "prefs_common.h" +#include "alertpanel.h" +#if GTK_CHECK_VERSION(2, 10, 0) typedef struct { GSList *mlist; + GSList *cur; gboolean all_headers; } PrintData; @@ -71,8 +75,7 @@ static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context, debug_print("draw_page: %d\n", page_nr); - msginfo = (MsgInfo *)print_data->mlist->data; - g_return_if_fail(msginfo != NULL); + msginfo = (MsgInfo *)print_data->cur->data; if ((fp = procmsg_open_message(msginfo)) == NULL) return; @@ -167,35 +170,113 @@ static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context, g_object_unref(layout); } -gint printing_print_messages(GSList *mlist, gboolean all_headers) +gint printing_print_messages_gtk(GSList *mlist, gboolean all_headers) { + static GtkPrintSettings *settings = NULL; GtkPrintOperation *op; GtkPrintOperationResult res; PrintData *print_data; + GSList *cur; + + g_return_val_if_fail(mlist != NULL, -1); debug_print("printing start\n"); print_data = g_new0(PrintData, 1); print_data->mlist = mlist; + print_data->cur = mlist; print_data->all_headers = all_headers; op = gtk_print_operation_new(); + gtk_print_operation_set_unit(op, GTK_UNIT_POINTS); + g_signal_connect(op, "begin-print", G_CALLBACK(begin_print), print_data); g_signal_connect(op, "draw-page", G_CALLBACK(draw_page), print_data); - gtk_print_operation_set_unit(op, GTK_UNIT_POINTS); + if (settings) + gtk_print_operation_set_print_settings(op, settings); res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(main_window_get()->window), NULL); - g_object_unref(op); + if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { + g_print("save settings\n"); + if (settings) + g_object_unref(settings); + settings = g_object_ref + (gtk_print_operation_get_print_settings(op)); + } + g_object_unref(op); g_free(print_data); debug_print("printing finished\n"); + + return 0; } -#endif +#endif /* GTK_CHECK_VERSION(2, 10, 0) */ + +gint printing_print_messages_with_command(GSList *mlist, gboolean all_headers, + const gchar *cmdline) +{ + MsgInfo *msginfo; + GSList *cur; + gchar *msg; + + g_return_val_if_fail(mlist != NULL, -1); + + msg = g_strconcat + (_("The message will be printed with the following command:"), + "\n\n", cmdline ? cmdline : _("(Default print command)"), + NULL); + if (alertpanel(_("Print"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL) + != G_ALERTDEFAULT) { + g_free(msg); + return 0; + } + g_free(msg); + + if (cmdline && str_find_format_times(cmdline, 's') != 1) { + alertpanel_error(_("Print command line is invalid:\n`%s'"), + cmdline); + return -1; + } + + for (cur = mlist; cur != NULL; cur = cur->next) { + msginfo = (MsgInfo *)cur->data; + if (msginfo) + procmsg_print_message(msginfo, cmdline, all_headers); + } + + return 0; +} + +gint printing_print_messages(GSList *mlist, gboolean all_headers) +{ +#if GTK_CHECK_VERSION(2, 10, 0) + if (!prefs_common.use_print_cmd) + return printing_print_messages_gtk(mlist, all_headers); + else +#endif /* GTK_CHECK_VERSION(2, 10, 0) */ + return printing_print_messages_with_command + (mlist, all_headers, prefs_common.print_cmd); +} + +gint printing_print_message(MsgInfo *msginfo, gboolean all_headers) +{ + GSList mlist; + + mlist.data = msginfo; + mlist.next = NULL; + return printing_print_messages(&mlist, all_headers); +} + +gint printing_print_message_part(MsgInfo *msginfo, MimeInfo *partinfo) +{ + procmsg_print_message_part(msginfo, partinfo, prefs_common.print_cmd, + FALSE); +} diff --git a/src/printing.h b/src/printing.h index bd6ce832..7e9e8a58 100644 --- a/src/printing.h +++ b/src/printing.h @@ -22,12 +22,25 @@ #include -#if GTK_CHECK_VERSION(2, 10, 0) #include -gint printing_print_messages (GSList *mlist, - gboolean all_headers); +#include "procmsg.h" +#include "procmime.h" +#if GTK_CHECK_VERSION(2, 10, 0) +gint printing_print_messages_gtk (GSList *mlist, + gboolean all_headers); #endif +gint printing_print_messages_with_command (GSList *mlist, + gboolean all_headers, + const gchar *cmdline); + +gint printing_print_messages (GSList *mlist, + gboolean all_headers); +gint printing_print_message (MsgInfo *msginfo, + gboolean all_headers); +gint printing_print_message_part (MsgInfo *msginfo, + MimeInfo *partinfo); + #endif /* __PRINTING_H__ */ diff --git a/src/summaryview.c b/src/summaryview.c index 15829edd..02f9343a 100644 --- a/src/summaryview.c +++ b/src/summaryview.c @@ -3575,49 +3575,14 @@ void summary_print(SummaryView *summaryview) { MsgInfo *msginfo; GSList *mlist, *cur; - const gchar *cmdline; gchar *msg; gboolean all_headers; - if (gtk_tree_selection_count_selected_rows(summaryview->selection) == 0) - return; - all_headers = summaryview->messageview->textview->show_all_headers; - -#if GTK_CHECK_VERSION(2, 10, 0) - if (!prefs_common.use_print_cmd) { - mlist = summary_get_selected_msg_list(summaryview); - printing_print_messages(mlist, all_headers); - g_slist_free(mlist); - return; - } -#endif - - cmdline = prefs_common.print_cmd; - - msg = g_strconcat - (_("The message will be printed with the following command:"), - "\n\n", cmdline ? cmdline : _("(Default print command)"), - NULL); - if (alertpanel(_("Print"), msg, GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL) - != G_ALERTDEFAULT) { - g_free(msg); - return; - } - g_free(msg); - - if (cmdline && str_find_format_times(cmdline, 's') != 1) { - alertpanel_error(_("Print command line is invalid:\n`%s'"), - cmdline); - return; - } - mlist = summary_get_selected_msg_list(summaryview); - for (cur = mlist; cur != NULL; cur = cur->next) { - msginfo = (MsgInfo *)cur->data; - if (msginfo) - procmsg_print_message(msginfo, cmdline, all_headers); - } + if (!mlist) + return; + printing_print_messages(mlist, all_headers); g_slist_free(mlist); } -- cgit v1.2.3