aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog10
-rw-r--r--mail/em-folder-view.c97
-rw-r--r--mail/em-folder-view.h3
-rw-r--r--mail/em-format-html-print.c314
-rw-r--r--mail/em-format-html-print.h32
5 files changed, 174 insertions, 282 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 4d5e57fc59..833daa6384 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,13 @@
+2007-04-20 Matthew Barnes <mbarnes@redhat.com>
+
+ ** Fixes part of bug #426812
+
+ * em-format-html-print.c:
+ * em-format-html-print.h:
+ * em-folder-view.c:
+ * em-folder-view.h:
+ Refactor the printing infrastructure.
+
2007-04-20 Srinivasa Ragavan <sragavan@novell.com>
* em-composer-prefs.c: (signature_key_press): Fix for bug #353662
diff --git a/mail/em-folder-view.c b/mail/em-folder-view.c
index 78b5d00790..62568c8282 100644
--- a/mail/em-folder-view.c
+++ b/mail/em-folder-view.c
@@ -110,7 +110,6 @@
#include "mail-vfolder.h"
#include "mail-component.h"
#include "mail-tools.h"
-#include <gtk/gtkprintunixdialog.h>
#include "evolution-shell-component-utils.h" /* Pixmap stuff, sigh */
@@ -781,7 +780,7 @@ static void
emfv_popup_print(EPopup *ep, EPopupItem *pitem, void *data)
{
EMFolderView *emfv = data;
- em_folder_view_print(emfv, FALSE);
+ em_folder_view_print(emfv, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
}
static void
@@ -1549,7 +1548,7 @@ emfv_print_preview_message(BonoboUIComponent *uic, void *data, const char *path)
{
EMFolderView *emfv = data;
- em_folder_view_print(emfv, TRUE);
+ em_folder_view_print(emfv, GTK_PRINT_OPERATION_ACTION_PREVIEW);
}
static void
@@ -2114,86 +2113,30 @@ emfv_activate(EMFolderView *emfv, BonoboUIComponent *uic, int act)
}
}
-struct _print_data {
- EMFolderView *emfv;
-
- GtkPrintSettings *settings;
- int preview;
- CamelFolder *folder;
- char *uid;
-};
-
-static void
-emfv_print_response(GtkWidget *w, int resp, struct _print_data *data)
-{
- EMFormatHTMLPrint *print;
- gboolean preview = FALSE;
-
- switch (resp) {
- case GTK_RESPONSE_APPLY:
- preview = TRUE;
- case GTK_RESPONSE_OK:
- print = em_format_html_print_new ();
- print->preview = preview;
- em_format_set_session ((EMFormat *)print, ((EMFormat *)data->emfv->preview)->session);
- em_format_html_print_message (print,
- (EMFormatHTML *)data->emfv->preview,
- data->settings,
- data->folder,
- data->uid,
- data->preview);
- g_object_unref(print);
- break;
- }
-
- if (w)
- gtk_widget_destroy (w);
-
- g_object_unref (data->emfv);
- g_object_unref (data->settings);
- camel_object_unref (data->folder);
- g_free (data->uid);
- g_free (data);
-}
-
-
-
-int em_folder_view_print(EMFolderView *emfv, int preview)
+int
+em_folder_view_print (EMFolderView *emfv, GtkPrintOperationAction action)
{
- struct _print_data *data;
+ EMFormatHTMLPrint *efhp;
GPtrArray *uids;
if (emfv->folder == NULL)
return 0;
- uids = message_list_get_selected(emfv->list);
- if (uids->len != 1) {
- message_list_free_uids(emfv->list, uids);
- return 0;
- }
-
- data = g_malloc0(sizeof(*data));
- data->emfv = emfv;
- g_object_ref(emfv);
- data->settings = e_print_load_settings ();
- data->preview = preview;
- data->folder = emfv->folder;
- camel_object_ref(data->folder);
- data->uid = g_strdup(uids->pdata[0]);
- message_list_free_uids(emfv->list, uids);
-
- if (preview) {
- GtkDialog *dialog = (GtkDialog *)e_print_get_dialog_with_config (_("Print Message"),
- 0, data->settings);
- e_dialog_set_transient_for ((GtkWindow *) dialog, (GtkWidget *) emfv);
- emfv_print_response(dialog, GTK_RESPONSE_APPLY, data);
- } else {
- GtkDialog *dialog = (GtkDialog *)e_print_get_dialog_with_config (_("Print Message"),
- 0, data->settings);
- gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
- e_dialog_set_transient_for ((GtkWindow *) dialog, (GtkWidget *) emfv);
- emfv_print_response (dialog, GTK_RESPONSE_OK, data);
- }
+ uids = message_list_get_selected (emfv->list);
+ if (uids->len != 1)
+ goto exit;
+
+ efhp = em_format_html_print_new (
+ (EMFormatHTML *) emfv->preview, action);
+ em_format_set_session (
+ (EMFormat *) efhp,
+ ((EMFormat *) emfv->preview)->session);
+ em_format_html_print_message (
+ efhp, emfv->folder, uids->pdata[0]);
+ g_object_unref (efhp);
+
+exit:
+ message_list_free_uids (emfv->list, uids);
return 0;
}
diff --git a/mail/em-folder-view.h b/mail/em-folder-view.h
index 4c998dcc86..d2afb4d666 100644
--- a/mail/em-folder-view.h
+++ b/mail/em-folder-view.h
@@ -25,6 +25,7 @@
#define _EM_FOLDER_VIEW_H
#include <gtk/gtkvbox.h>
+#include <gtk/gtkprintoperation.h>
#include "mail/em-popup.h"
#ifdef __cplusplus
@@ -132,7 +133,7 @@ EMPopupTargetSelect *em_folder_view_get_popup_target(EMFolderView *emfv, EMPopup
int em_folder_view_mark_selected(EMFolderView *emfv, guint32 mask, guint32 set);
int em_folder_view_open_selected(EMFolderView *emfv);
-int em_folder_view_print(EMFolderView *emfv, int preview);
+int em_folder_view_print(EMFolderView *emfv, GtkPrintOperationAction action);
/* this could be on message-list */
guint32 em_folder_view_disable_mask(EMFolderView *emfv);
diff --git a/mail/em-format-html-print.c b/mail/em-format-html-print.c
index bc94f8aae5..ebda5aaf2a 100644
--- a/mail/em-format-html-print.c
+++ b/mail/em-format-html-print.c
@@ -26,274 +26,212 @@
#endif
#include <string.h>
-#include <libgnomeprint/gnome-print-job.h>
-#include <libgnomeprintui/gnome-print-job-preview.h>
+#include <gtk/gtk.h>
#include <gtkhtml/gtkhtml.h>
-#include <gtk/gtkwindow.h>
#include <camel/camel-i18n.h>
#include "mail-ops.h"
#include "mail-mt.h"
#include "em-format-html-print.h"
-#include <gtk/gtk.h>
#include <e-util/e-print.h>
-static void efhp_builtin_init(EMFormatHTMLPrintClass *efhc);
-
-static EMFormatHTMLClass *efhp_parent;
+static gpointer parent_class = NULL;
static void
-efhp_init(GObject *o)
+efhp_finalize (GObject *o)
{
EMFormatHTMLPrint *efhp = (EMFormatHTMLPrint *)o;
- GtkWidget *html = (GtkWidget *)efhp->formathtml.html;
- /* ?? */
- gtk_widget_set_name(html, "EvolutionMailPrintHTMLWidget");
+ gtk_widget_destroy (efhp->window);
+ if (efhp->source != NULL)
+ g_object_unref (efhp->source);
- /* gtk widgets don't like to be realized outside top level widget
- so we put new html widget into gtk window */
- efhp->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_container_add((GtkContainer *)efhp->window, html);
- gtk_widget_realize(html);
- efhp->formathtml.show_icon = FALSE;
+ ((GObjectClass *) parent_class)->finalize (o);
}
static void
-efhp_finalise(GObject *o)
+efhp_class_init (GObjectClass *class)
{
- EMFormatHTMLPrint *efhp = (EMFormatHTMLPrint *)o;
-
- gtk_widget_destroy(efhp->window);
- if (efhp->settings)
- g_object_unref(efhp->settings);
- if (efhp->source)
- g_object_unref(efhp->source);
-
- ((GObjectClass *)efhp_parent)->finalize(o);
+ parent_class = g_type_class_ref(EM_TYPE_FORMAT_HTML_PRINT);
+ class->finalize = efhp_finalize;
}
static void
-efhp_base_init(EMFormatHTMLPrintClass *efhpklass)
+efhp_init (GObject *o)
{
- efhp_builtin_init(efhpklass);
-}
+ EMFormatHTMLPrint *efhp = (EMFormatHTMLPrint *)o;
+ GtkWidget *html = (GtkWidget *)efhp->parent.html;
-static void
-efhp_class_init(GObjectClass *klass)
-{
- klass->finalize = efhp_finalise;
+ /* ?? */
+ gtk_widget_set_name(html, "EvolutionMailPrintHTMLWidget");
+
+ /* gtk widgets don't like to be realized outside top level widget
+ so we put new html widget into gtk window */
+ efhp->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_container_add (GTK_CONTAINER (efhp->window), html);
+ gtk_widget_realize (html);
+ efhp->parent.show_icon = FALSE;
}
GType
-em_format_html_print_get_type(void)
+em_format_html_print_get_type (void)
{
static GType type = 0;
- if (type == 0) {
- static const GTypeInfo info = {
- sizeof(EMFormatHTMLPrintClass),
- (GBaseInitFunc)efhp_base_init, NULL,
- (GClassInitFunc)efhp_class_init,
- NULL, NULL,
- sizeof(EMFormatHTMLPrint), 0,
- (GInstanceInitFunc)efhp_init
+ if (G_UNLIKELY (type == 0)) {
+ static const GTypeInfo type_info = {
+ sizeof (EMFormatHTMLPrintClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) efhp_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (EMFormatHTMLPrint),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) efhp_init
};
- efhp_parent = g_type_class_ref(em_format_html_get_type());
- type = g_type_register_static(em_format_html_get_type(), "EMFormatHTMLPrint", &info, 0);
+
+ type = g_type_register_static (
+ em_format_html_get_type (), "EMFormatHTMLPrint",
+ &type_info, 0);
}
return type;
}
-EMFormatHTMLPrint *em_format_html_print_new(void)
+EMFormatHTMLPrint *
+em_format_html_print_new (EMFormatHTML *source, GtkPrintOperationAction action)
{
EMFormatHTMLPrint *efhp;
- efhp = g_object_new(em_format_html_print_get_type(), 0);
+ efhp = g_object_new (EM_TYPE_FORMAT_HTML_PRINT, NULL);
+ if (source != NULL)
+ efhp->source = g_object_ref (source);
+ efhp->action = action;
return efhp;
}
struct footer_info {
- GnomeFont *local_font;
+ PangoLayout *layout;
gint page_num, pages;
};
-typedef struct MailDraw MailDraw;
-
-struct MailDraw {
- EMFormatHTMLPrint *efhp;
- struct footer_info info;
- void *data;
- gint res;
- gdouble line;
-};
-static void mail_draw_page(GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, MailDraw *mdi);
static void
-efhp_footer_cb(GtkHTML *html, GtkPrintContext *print_context, double x, double y, double width, double height, void *data)
+efhp_footer_cb (GtkHTML *html, GtkPrintContext *context, gdouble x, gdouble y,
+ gdouble width, gdouble height, gpointer data)
{
struct footer_info *info = data;
+ gchar *footer_text;
cairo_t *cr;
-
- /* do we want anything nicer here, like who its from, etc? */
- if (info->local_font) {
- char *text = g_strdup_printf (_("Page %d of %d"), info->page_num, info->pages);
- /*gdouble tw = gnome_font_get_width_string (info->local_font, text);*/
- /* FIXME: work out how to measure this */
- gdouble tw = strlen(text) * 8;
- cr = gtk_print_context_get_cairo_context (print_context);
- cairo_save (cr);
- cairo_set_source_rgb (cr, .0, .0, .0);
- cairo_move_to (cr, x + width - tw, y - gnome_font_get_ascender(info->local_font));
- cairo_set_font_face (cr, NULL);
- cairo_set_font_size (cr, 6);
- cairo_show_text (cr, text);
- cairo_restore(cr);
- g_free(text);
- info->page_num++;
- }
-}
-/* perform preview, or print */
-/* returns GNOME_PRINT_OK on success */
-static void
-emfhp_complete(EMFormatHTMLPrint *efhp, void *data)
-{
- GtkPaperSize *paper_size;
- GtkPrintOperation *print;
- GtkPrintSettings *settings;
- GtkPageSetup *page_setup;
- struct MailDraw *mdi;
- struct footer_info info;
+ footer_text = g_strdup_printf (_("Page %d of %d"),
+ info->page_num++, info->pages);
+
+ pango_layout_set_text (info->layout, footer_text, -1);
+ pango_layout_set_width (info->layout, pango_units_from_double (width));
- page_setup = gtk_page_setup_new ();
- paper_size = gtk_paper_size_new ("iso_a4");/*FIXME paper size hardcoded */
- print = gtk_print_operation_new ();
- gtk_page_setup_set_paper_size (page_setup, paper_size);
-
- settings = e_print_load_settings ();
- gtk_print_operation_set_print_settings (print, settings);
- /* running the dialog */
- gtk_print_operation_set_default_page_setup (print, page_setup);
- gtk_print_operation_set_n_pages (print, 1);
-
- /*initialise the struct */
- mdi = g_new0 (MailDraw, 1);
- mdi->efhp = efhp;
- mdi->line = 0.0;
- mdi->res = GNOME_PRINT_OK;
- mdi->info = info;
-
- /* connect */
- g_signal_connect (print,"draw_page", G_CALLBACK (mail_draw_page), mdi);
- if (!efhp->preview)
- gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
- else
- gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PREVIEW, NULL, NULL);
- settings = gtk_print_operation_get_print_settings (print);
- e_print_save_settings (settings);
- g_object_unref (print);
+ cr = gtk_print_context_get_cairo_context (context);
+
+ cairo_save (cr);
+ cairo_set_source_rgb (cr, .0, .0, .0);
+ cairo_move_to (cr, x, y);
+ pango_cairo_show_layout (cr, info->layout);
+ cairo_restore (cr);
+
+ g_free (footer_text);
}
static void
-mail_draw_page (GtkPrintOperation *print, GtkPrintContext *context, gint page_nr, MailDraw *mdi)
+mail_draw_page (GtkPrintOperation *print, GtkPrintContext *context,
+ gint page_nr, EMFormatHTMLPrint *efhp)
{
- mdi->info.local_font = gnome_font_find_closest("Sans Regular", 10.0);
- if (mdi->info.local_font) {
- mdi->line = gnome_font_get_ascender(mdi->info.local_font) - gnome_font_get_descender(mdi->info.local_font);
- mdi->info.page_num = 1;
- mdi->info.pages = gtk_html_print_page_get_pages_num(mdi->efhp->formathtml.html, context, 0.0, mdi->line );
- gtk_html_print_page_with_header_footer(mdi->efhp->formathtml.html,
- context,
- 0.0,
- mdi->line,
- NULL,
- efhp_footer_cb,
- &(mdi->info));
- } else {
- gtk_html_print_page (mdi->efhp->formathtml.html, context);
- }
-}
+ GtkHTML *html = efhp->parent.html;
+ PangoFontDescription *desc;
+ PangoFontMetrics *metrics;
+ struct footer_info info;
+ gdouble footer_height;
-int em_format_html_print_print(EMFormatHTMLPrint *efhp, EMFormatHTML *source, struct GtkPrintSettings *settings, int preview)
-{
- EMFormat *emfs = (EMFormat *)source;
+ desc = pango_font_description_from_string ("Sans Regular 10");
- efhp->settings = settings;
- if (settings)
- g_object_ref(settings);
+ info.layout = gtk_print_context_create_pango_layout (context);
+ pango_layout_set_alignment (info.layout, PANGO_ALIGN_CENTER);
+ pango_layout_set_font_description (info.layout, desc);
- efhp->preview = preview;
- ((EMFormatHTML *)efhp)->load_http = source->load_http_now;
+ metrics = pango_context_get_metrics (
+ pango_layout_get_context (info.layout),
+ desc, pango_language_get_default ());
+ footer_height = pango_units_to_double (
+ pango_font_metrics_get_ascent (metrics) +
+ pango_font_metrics_get_descent (metrics));
+ pango_font_metrics_unref (metrics);
- g_signal_connect(efhp, "complete", G_CALLBACK(emfhp_complete), efhp);
+ pango_font_description_free (desc);
- g_object_ref(efhp);
- em_format_format_clone((EMFormat *)efhp, emfs->folder, emfs->uid, emfs->message, (EMFormat *)source);
+ info.page_num = 1;
+ info.pages = gtk_html_print_page_get_pages_num (
+ html, context, 0.0, footer_height);
- return 0; /* damn async ... */
+ gtk_html_print_page_with_header_footer (
+ html, context, 0.0, footer_height,
+ NULL, efhp_footer_cb, &info);
}
static void
-emfhp_got_message(struct _CamelFolder *folder, const char *uid, struct _CamelMimeMessage *msg, void *data)
+emfhp_complete (EMFormatHTMLPrint *efhp)
{
- EMFormatHTMLPrint *efhp = data;
-
- if (msg) {
- if (efhp->source)
- ((EMFormatHTML *)efhp)->load_http = efhp->source->load_http_now;
- g_signal_connect(efhp, "complete", G_CALLBACK(emfhp_complete), efhp);
- em_format_format_clone((EMFormat *)efhp, folder, uid, msg, (EMFormat *)efhp->source);
- } else {
- g_object_unref(efhp);
- }
-}
+ GtkPrintOperation *operation;
-int em_format_html_print_message(EMFormatHTMLPrint *efhp, EMFormatHTML *source, struct GtkPrintSettings *settings, struct _CamelFolder *folder, const char *uid, int preview)
-{
- efhp->settings = settings;
+ operation = e_print_operation_new ();
+ gtk_print_operation_set_n_pages (operation, 1);
- if (settings)
- g_object_ref(settings);
- efhp->preview = preview;
- efhp->source = source;
- if (source)
- g_object_ref(source);
- g_object_ref(efhp);
+ g_signal_connect (
+ operation, "draw-page",
+ G_CALLBACK (mail_draw_page), efhp);
- mail_get_message(folder, uid, emfhp_got_message, efhp, mail_thread_new);
+ gtk_print_operation_run (operation, efhp->action, NULL, NULL);
- return 0; /* damn async ... */
+ g_object_unref (operation);
}
-int em_format_html_print_raw_message(EMFormatHTMLPrint *efhp, GtkPrintSettings *settings, struct _CamelMimeMessage *msg, int preview)
+static void
+emfhp_got_message (CamelFolder *folder, const char *uid,
+ CamelMimeMessage *msg, gpointer data)
{
- efhp->settings = settings;
+ EMFormatHTMLPrint *efhp = data;
- if (settings)
- g_object_ref(settings);
- efhp->source = NULL;
- efhp->preview = preview;
- g_object_ref(efhp);
+ if (msg == NULL) {
+ g_object_unref (efhp);
+ return;
+ }
- emfhp_got_message(NULL, NULL, msg, efhp);
+ if (efhp->source != NULL)
+ ((EMFormatHTML *)efhp)->load_http =
+ efhp->source->load_http_now;
- return 0;
+ g_signal_connect (
+ efhp, "complete", G_CALLBACK (emfhp_complete), efhp);
+ em_format_format_clone (
+ (EMFormat *) efhp, folder, uid, msg,
+ (EMFormat *) efhp->source);
}
-/* ********************************************************************** */
+void
+em_format_html_print_message (EMFormatHTMLPrint *efhp,
+ CamelFolder *folder,
+ const char *uid)
+{
+ g_object_ref (efhp);
-/* if only ... but i doubt this is possible with gnome print/gtkhtml */
-static EMFormatHandler type_builtin_table[] = {
- /*{ "application/postscript", (EMFormatFunc)efhp_application_postscript },*/
-};
+ mail_get_message (
+ folder, uid, emfhp_got_message, efhp, mail_thread_new);
+}
-static void
-efhp_builtin_init(EMFormatHTMLPrintClass *efhc)
+void
+em_format_html_print_raw_message (EMFormatHTMLPrint *efhp,
+ CamelMimeMessage *msg)
{
- int i;
+ g_object_ref (efhp);
- for (i=0;i<sizeof(type_builtin_table)/sizeof(type_builtin_table[0]);i++)
- em_format_class_add_handler((EMFormatClass *)efhc, &type_builtin_table[i]);
+ emfhp_got_message (NULL, NULL, msg, efhp);
}
diff --git a/mail/em-format-html-print.h b/mail/em-format-html-print.h
index 3cc605ba43..a013d57452 100644
--- a/mail/em-format-html-print.h
+++ b/mail/em-format-html-print.h
@@ -8,32 +8,32 @@
#include "mail/em-format-html.h"
-struct GtkPrintSettings;
+#define EM_TYPE_FORMAT_HTML_PRINT \
+ (em_format_html_print_get_type ())
+
typedef struct _EMFormatHTMLPrint EMFormatHTMLPrint;
typedef struct _EMFormatHTMLPrintClass EMFormatHTMLPrintClass;
-struct _CamelFolder;
-
struct _EMFormatHTMLPrint {
- EMFormatHTML formathtml;
+ EMFormatHTML parent;
- struct _GtkWidget *window; /* used to realise the gtkhtml in a toplevel, i dont know why */
- struct _GtkPrintSettings *settings;
- struct _EMFormatHTML *source; /* used for print_message */
+ GtkWidget *window; /* used to realise the gtkhtml in a toplevel, i dont know why */
+ EMFormatHTML *source; /* used for print_message */
- guint preview:1;
+ GtkPrintOperationAction action;
};
struct _EMFormatHTMLPrintClass {
- EMFormatHTMLClass formathtml_class;
+ EMFormatHTMLClass parent_class;
};
-GType em_format_html_print_get_type(void);
-
-EMFormatHTMLPrint *em_format_html_print_new(void);
-
-int em_format_html_print_print(EMFormatHTMLPrint *efhp, EMFormatHTML *source, struct GtkPrintSettings *settings, int preview);
-int em_format_html_print_message(EMFormatHTMLPrint *efhp, EMFormatHTML *source, struct GtkPrintSettings *settings, struct _CamelFolder *folder, const char *uid, int preview);
-int em_format_html_print_raw_message(EMFormatHTMLPrint *efhp, struct _GtkPrintSettings *settings, struct _CamelMimeMessage *msg, int preview);
+GType em_format_html_print_get_type (void);
+EMFormatHTMLPrint * em_format_html_print_new (EMFormatHTML *source,
+ GtkPrintOperationAction action);
+void em_format_html_print_message (EMFormatHTMLPrint *efhp,
+ CamelFolder *folder,
+ const char *uid);
+void em_format_html_print_raw_message (EMFormatHTMLPrint *efhp,
+ CamelMimeMessage *msg);
#endif /* ! _EM_FORMAT_HTML_PRINT_H */