aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2006-11-30 07:44:59 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2006-11-30 07:44:59 +0000
commita07a513dcca1b9a8a90499658a27a528660ade40 (patch)
tree405e2051422fd1b7a3e8a71a65d2e30ba56b5664
parent4cc3707180ec49e18d83fd72c4f3eea541eb40ea (diff)
implemented printing of MIME part. Code cleanups.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1386 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog8
-rw-r--r--ChangeLog.ja8
-rw-r--r--libsylph/procmsg.c100
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/messageview.c26
-rw-r--r--src/mimeview.c51
-rw-r--r--src/mimeview.h4
-rw-r--r--src/printing.c95
-rw-r--r--src/printing.h19
-rw-r--r--src/summaryview.c41
10 files changed, 253 insertions, 100 deletions
diff --git a/ChangeLog b/ChangeLog
index c3560ffd..e9a75ca5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-11-30
+
+ * libsylph/procmsg.c
+ src/printing.[ch]
+ src/messageview.c
+ src/mimeview.[ch]
+ src/summaryview.c: implemented printing of MIME part. Code cleanups.
+
2006-11-29
* libsylph/prefs_common.[ch]
diff --git a/ChangeLog.ja b/ChangeLog.ja
index 8aa015c2..84f79fcd 100644
--- a/ChangeLog.ja
+++ b/ChangeLog.ja
@@ -1,3 +1,11 @@
+2006-11-30
+
+ * libsylph/procmsg.c
+ src/printing.[ch]
+ src/messageview.c
+ src/mimeview.[ch]
+ src/summaryview.c: MIME パートの印刷を実装。コードの整理。
+
2006-11-29
* libsylph/prefs_common.[ch]
diff --git a/libsylph/procmsg.c b/libsylph/procmsg.c
index 3d69f015..03f31da5 100644
--- a/libsylph/procmsg.c
+++ b/libsylph/procmsg.c
@@ -1320,16 +1320,52 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file)
return 0;
}
+static guint print_id = 0;
+
+static gint print_command_exec(const gchar *file, const gchar *cmdline)
+{
+ static const gchar *def_cmd = "lpr %s";
+ gchar buf[1024];
+
+#ifdef G_OS_WIN32
+ if (canonicalize_file_replace(file) < 0)
+ return -1;
+#endif
+
+ if (cmdline && str_find_format_times(cmdline, 's') == 1)
+ g_snprintf(buf, sizeof(buf) - 1, cmdline, file);
+ else {
+ if (cmdline) {
+ g_warning(_("Print command line is invalid: `%s'\n"),
+ cmdline);
+ return -1;
+ }
+
+#ifdef G_OS_WIN32
+ execute_print_file(file);
+ return 0;
+#else
+ g_snprintf(buf, sizeof(buf) - 1, def_cmd, file);
+#endif
+ }
+
+ g_strchomp(buf);
+ if (buf[strlen(buf) - 1] != '&')
+ strcat(buf, "&");
+
+ system(buf);
+
+ return 0;
+}
+
void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline,
gboolean all_headers)
{
- static const gchar *def_cmd = "lpr %s";
- static guint id = 0;
gchar *prtmp;
FILE *msgfp, *tmpfp, *prfp;
GPtrArray *headers;
gint i;
- gchar buf[1024];
+ gchar buf[BUFFSIZE];
g_return_if_fail(msginfo != NULL);
@@ -1340,7 +1376,8 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline,
}
prtmp = g_strdup_printf("%s%cprinttmp-%08x.txt",
- get_mime_tmp_dir(), G_DIR_SEPARATOR, id++);
+ get_mime_tmp_dir(), G_DIR_SEPARATOR,
+ print_id++);
if ((prfp = g_fopen(prtmp, "wb")) == NULL) {
FILE_OP_ERROR(prtmp, "fopen");
@@ -1409,37 +1446,48 @@ void procmsg_print_message(MsgInfo *msginfo, const gchar *cmdline,
fclose(prfp);
fclose(tmpfp);
-#ifdef G_OS_WIN32
- if (canonicalize_file_replace(prtmp) < 0) {
- g_free(prtmp);
+ print_command_exec(prtmp, cmdline);
+
+ g_free(prtmp);
+}
+
+void procmsg_print_message_part(MsgInfo *msginfo, MimeInfo *partinfo,
+ const gchar *cmdline, gboolean all_headers)
+{
+ FILE *msgfp, *tmpfp, *prfp;
+ gchar *prtmp;
+ gchar buf[BUFFSIZE];
+
+ if ((msgfp = procmsg_open_message(msginfo)) == NULL) {
return;
}
-#endif
- if (cmdline && str_find_format_times(cmdline, 's') == 1)
- g_snprintf(buf, sizeof(buf) - 1, cmdline, prtmp);
- else {
- if (cmdline) {
- g_warning(_("Print command line is invalid: `%s'\n"),
- cmdline);
- g_free(prtmp);
- return;
- }
+ if ((tmpfp = procmime_get_text_content
+ (partinfo, msgfp, conv_get_locale_charset_str())) == NULL) {
+ fclose(msgfp);
+ return;
+ }
+ fclose(msgfp);
-#ifdef G_OS_WIN32
- execute_print_file(prtmp);
+ prtmp = g_strdup_printf("%s%cprinttmp-%08x.txt",
+ get_mime_tmp_dir(), G_DIR_SEPARATOR,
+ print_id++);
+ if ((prfp = g_fopen(prtmp, "wb")) == NULL) {
+ FILE_OP_ERROR(prtmp, "fopen");
g_free(prtmp);
+ fclose(tmpfp);
return;
-#else
- g_snprintf(buf, sizeof(buf) - 1, def_cmd, prtmp);
-#endif
}
- g_free(prtmp);
+ while (fgets(buf, sizeof(buf), tmpfp) != NULL)
+ fputs(buf, prfp);
- g_strchomp(buf);
- if (buf[strlen(buf) - 1] != '&') strcat(buf, "&");
- system(buf);
+ fclose(prfp);
+ fclose(tmpfp);
+
+ print_command_exec(prtmp, cmdline);
+
+ g_free(prtmp);
}
MsgInfo *procmsg_msginfo_copy(MsgInfo *msginfo)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 25dbbba3..7045d752 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -78,6 +78,7 @@ src/prefs_folder_item.c
src/prefs_search_folder.c
src/prefs_summary_column.c
src/prefs_template.c
+src/printing.c
src/progressdialog.c
src/query_search.c
src/rfc2015.c
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 <glib.h>
#include <glib/gi18n.h>
+#if GTK_CHECK_VERSION(2, 10, 0)
#include <gtk/gtkprintoperation.h>
+#endif
#include <stdio.h>
@@ -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 <gtk/gtkversion.h>
-#if GTK_CHECK_VERSION(2, 10, 0)
#include <glib.h>
-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);
}