Пример #1
0
GList *
balsa_print_objects_append_from_body(GList * list,
				     GtkPrintContext * context,
				     LibBalsaMessageBody * mime_body,
				     BalsaPrintSetup * psetup)
{
    static const struct {
        char * type;  /* MIME type */
        int use_len;  /* length for strncasecmp or -1 for strcasecmp */
        GList * (*handler)(GList *, GtkPrintContext *, LibBalsaMessageBody *,
                           BalsaPrintSetup *);
    } pr_handlers[] = {
        { "text/html",                     -1, balsa_print_object_default },
        { "text/enriched",                 -1, balsa_print_object_default },
        { "text/richtext",                 -1, balsa_print_object_default },
        { "text/x-vcard",                  -1, balsa_print_object_text_vcard },
        { "text/directory",                -1, balsa_print_object_text_vcard },
        { "text/calendar",                 -1, balsa_print_object_text_calendar },
        { "text/plain",                    -1, balsa_print_object_text_plain },
        { "text/rfc822-headers",	   -1, balsa_print_object_emb_headers },
        { "text/",                          5, balsa_print_object_text },
        { "image/",                         6, balsa_print_object_image },
        { "message/rfc822",                -1, balsa_print_object_emb_message },
#ifdef HAVE_GPGME
        { "application/pgp-signature",     -1, balsa_print_object_mp_crypto },
#ifdef HAVE_SMIME
        { "application/pkcs7-signature",   -1, balsa_print_object_mp_crypto },
        { "application/x-pkcs7-signature", -1, balsa_print_object_mp_crypto },
#endif				/* HAVE_SMIME */
#endif				/* HAVE_GPGME */
        { NULL,                            -1, balsa_print_object_default }
    };
    gchar *conttype;
    GList *result;
    int n;

    conttype = libbalsa_message_body_get_mime_type(mime_body);
    for (n = 0;
         pr_handlers[n].type &&
             ((pr_handlers[n].use_len == -1 &&
               g_ascii_strcasecmp(pr_handlers[n].type, conttype)) ||
              (pr_handlers[n].use_len > 0 &&
               g_ascii_strncasecmp(pr_handlers[n].type, conttype, pr_handlers[n].use_len)));
         n++);
    result = pr_handlers[n].handler(list, context, mime_body, psetup);
    g_free(conttype);
    return result;
}
Пример #2
0
BalsaMimeWidget *
balsa_mime_widget_new(BalsaMessage * bm, LibBalsaMessageBody * mime_body, gpointer data)
{
    BalsaMimeWidget *mw = NULL;
    gchar *content_type;
    mime_delegate_t *delegate;

    g_return_val_if_fail(bm != NULL, NULL);
    g_return_val_if_fail(mime_body != NULL, NULL);

    /* determine the content type of the passed MIME body */
    content_type = libbalsa_message_body_get_mime_type(mime_body);
    delegate = mime_delegate;
    while (delegate->handler &&
	   ((delegate->wildcard &&
	     g_ascii_strncasecmp(delegate->mime_type, content_type,
				 strlen(delegate->mime_type))) ||
	    (!delegate->wildcard &&
	     g_ascii_strcasecmp(delegate->mime_type, content_type))))
	delegate++;

    if (delegate->handler)
	mw = (delegate->handler) (bm, mime_body, content_type, data);
    /* fall back to default if no handler is present */
    if (!mw)
	mw = balsa_mime_widget_new_unknown(bm, mime_body, content_type);

    if (mw) {
	if (mw->widget) {
	    g_signal_connect(G_OBJECT(mw->widget), "focus_in_event",
			     G_CALLBACK(balsa_mime_widget_limit_focus),
			     (gpointer) bm);
	    g_signal_connect(G_OBJECT(mw->widget), "focus_out_event",
			     G_CALLBACK(balsa_mime_widget_unlimit_focus),
			     (gpointer) bm);
#ifdef HAVE_GPGME
	    if (mime_body->sig_info &&
		g_ascii_strcasecmp("application/pgp-signature", content_type) &&
		g_ascii_strcasecmp("application/pkcs7-signature", content_type) &&
		g_ascii_strcasecmp("application/x-pkcs7-signature", content_type)) {
		GtkWidget * signature =
		    balsa_mime_widget_signature_widget(mime_body, content_type);
		mw->widget = balsa_mime_widget_crypto_frame(mime_body, mw->widget,
							    mime_body->was_encrypted,
							    FALSE, signature);
	    } else if (mime_body->was_encrypted &&
		       g_ascii_strcasecmp("multipart/signed", content_type)) {
		mw->widget = balsa_mime_widget_crypto_frame(mime_body, mw->widget,
							    TRUE, TRUE, NULL);
	    }
#endif
            g_object_ref_sink(mw->widget);

	    if (GTK_IS_LAYOUT(mw->widget)) {
                GtkAdjustment *vadj;

                g_object_get(G_OBJECT(mw->widget), "vadjustment", &vadj,
                             NULL);
		g_signal_connect(vadj, "changed",
				 G_CALLBACK(vadj_change_cb), mw->widget);
            }

            gtk_widget_show_all(mw->widget);
	}
    }
    g_free(content_type);

    return mw;
}
Пример #3
0
GList *
balsa_print_object_default(GList * list,
			   GtkPrintContext * context,
			   LibBalsaMessageBody * body,
			   BalsaPrintSetup * psetup)
{
    BalsaPrintObjectDefault *pod;
    BalsaPrintObject *po;
    gchar *conttype;
    PangoFontDescription *header_font;
    PangoLayout *test_layout;
    PangoTabArray *tabs;
    GString *desc_buf;
    gdouble c_max_height;
    gchar *part_desc;

    pod = g_object_new(BALSA_TYPE_PRINT_OBJECT_DEFAULT, NULL);
    g_assert(pod != NULL);
    po = BALSA_PRINT_OBJECT(pod);

    /* create the part */
    po->depth = psetup->curr_depth;
    po->c_width =
	psetup->c_width - 2 * psetup->curr_depth * C_LABEL_SEP;

    /* get a pixbuf according to the mime type */
    conttype = libbalsa_message_body_get_mime_type(body);
    pod->pixbuf =
	libbalsa_icon_finder(NULL, conttype, NULL, NULL,
                             GTK_ICON_SIZE_DND);
    pod->c_image_width = gdk_pixbuf_get_width(pod->pixbuf);
    pod->c_image_height = gdk_pixbuf_get_height(pod->pixbuf);


    /* create a layout for calculating the maximum label width */
    header_font =
	pango_font_description_from_string(balsa_app.print_header_font);
    test_layout = gtk_print_context_create_pango_layout(context);
    pango_layout_set_font_description(test_layout, header_font);
    pango_font_description_free(header_font);
    desc_buf = g_string_new("");

    /* add type and filename (if available) */
    pod->p_label_width =
	p_string_width_from_layout(test_layout, _("Type:"));
    if ((part_desc = libbalsa_vfs_content_description(conttype)))
	g_string_append_printf(desc_buf, "%s\t%s (%s)", _("Type:"),
			       part_desc, conttype);
    else
	g_string_append_printf(desc_buf, "%s\t%s", _("Type:"), conttype);
    g_free(part_desc);
    g_free(conttype);
    if (body->filename) {
	gint p_fnwidth =
	    p_string_width_from_layout(test_layout, _("File name:"));

	if (p_fnwidth > pod->p_label_width)
	    pod->p_label_width = p_fnwidth;
	g_string_append_printf(desc_buf, "\n%s\t%s", _("File name:"),
			       body->filename);
    }

    /* add a small space between label and value */
    pod->p_label_width += C_TO_P(C_LABEL_SEP);

    /* configure the layout so we can calculate the text height */
    pango_layout_set_indent(test_layout, -pod->p_label_width);
    tabs =
	pango_tab_array_new_with_positions(1, FALSE, PANGO_TAB_LEFT,
					   pod->p_label_width);
    pango_layout_set_tabs(test_layout, tabs);
    pango_tab_array_free(tabs);
    pango_layout_set_width(test_layout,
			   C_TO_P(po->c_width -
				  4 * C_LABEL_SEP - pod->c_image_width));
    pango_layout_set_alignment(test_layout, PANGO_ALIGN_LEFT);
    pod->c_text_height =
	P_TO_C(p_string_height_from_layout(test_layout, desc_buf->str));
    pod->description = g_string_free(desc_buf, FALSE);

    /* check if we should move to the next page */
    c_max_height = MAX(pod->c_text_height, pod->c_image_height);
    if (psetup->c_y_pos + c_max_height > psetup->c_height) {
	psetup->c_y_pos = 0;
	psetup->page_count++;
    }

    /* remember the extent */
    po->on_page = psetup->page_count - 1;
    po->c_at_x = psetup->c_x0 + po->depth * C_LABEL_SEP;
    po->c_at_y = psetup->c_y0 + psetup->c_y_pos;
    po->c_width = psetup->c_width - 2 * po->depth * C_LABEL_SEP;
    po->c_height = c_max_height;

    /* adjust the y position */
    psetup->c_y_pos += c_max_height;

    return g_list_append(list, po);
}