Exemple #1
0
static GMimeStream *
libbalsa_mailbox_mh_get_message_stream(LibBalsaMailbox * mailbox,
				       guint msgno, gboolean peek)
{
    GMimeStream *stream;
    struct message_info *msg_info;
    gchar *tmp;

    g_return_val_if_fail(MAILBOX_OPEN(mailbox), NULL);

    msg_info = lbm_mh_message_info_from_msgno(LIBBALSA_MAILBOX_MH(mailbox),
					      msgno);
    tmp = MH_BASENAME(msg_info);
    stream = libbalsa_mailbox_local_get_message_stream(mailbox, tmp, NULL);
    g_free(tmp);

    return stream;
}
Exemple #2
0
void
libbalsa_show_message_source(GtkApplication  * application,
                             LibBalsaMessage * msg,
                             const gchar     * font,
			     gboolean        * escape_specials,
                             gint            * width,
                             gint            * height)
{
    GtkWidget *text;
    gchar *css;
    GtkCssProvider *css_provider;
    GtkWidget *vbox, *interior;
    GtkWidget *window;
    gchar *ui_file;
    GtkWidget *menu_bar;
    GError *err = NULL;
    LibBalsaSourceViewerInfo *lsvi;
    GAction *escape_action;

    g_return_if_fail(msg);
    g_return_if_fail(MAILBOX_OPEN(msg->mailbox));

    text = gtk_text_view_new();

    gtk_widget_set_name(text, BALSA_SOURCE_VIEWER);
    css = libbalsa_font_string_to_css(font, BALSA_SOURCE_VIEWER);

    css_provider = gtk_css_provider_new();
    gtk_css_provider_load_from_data(css_provider, css, -1, NULL);
    g_free(css);

    gtk_style_context_add_provider(gtk_widget_get_style_context(text) ,
                                   GTK_STYLE_PROVIDER(css_provider),
                                   GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    g_object_unref(css_provider);

    gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);

    interior = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(interior),
                                   GTK_POLICY_AUTOMATIC,
                                   GTK_POLICY_ALWAYS);
    gtk_container_add(GTK_CONTAINER(interior), GTK_WIDGET(text));

    window = gtk_application_window_new(application);
    gtk_window_set_title(GTK_WINDOW(window), _("Message Source"));
    gtk_window_set_role(GTK_WINDOW(window), "message-source");
    gtk_window_set_default_size(GTK_WINDOW(window), *width, *height);

    ui_file = g_build_filename(BALSA_DATA_PREFIX, "ui", "source-viewer.ui",
                               NULL);
    menu_bar = libbalsa_window_get_menu_bar(GTK_APPLICATION_WINDOW(window),
                                            win_entries,
                                            G_N_ELEMENTS(win_entries),
                                            ui_file, &err, window);
    if (!menu_bar) {
        libbalsa_information(LIBBALSA_INFORMATION_WARNING,
                             _("Error adding from %s: %s\n"), ui_file,
                             err->message);
        g_free(ui_file);
        g_error_free(err);
        return;
    }
    g_free(ui_file);

    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
#if HAVE_MACOSX_DESKTOP
    libbalsa_macosx_menu(window, GTK_MENU_SHELL(menu_bar));
#else
    gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, TRUE, 1);
#endif

    gtk_box_pack_start(GTK_BOX(vbox), interior, TRUE, TRUE, 0);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    lsvi = g_new(LibBalsaSourceViewerInfo, 1);
    lsvi->msg = g_object_ref(msg);
    lsvi->text = text;
    lsvi->window = window;
    lsvi->escape_specials = escape_specials;
    lsvi->width = width;
    lsvi->height = height;
    g_object_set_data_full(G_OBJECT(window), "lsvi", lsvi,
                           (GDestroyNotify) lsv_window_destroy_notify);

    g_signal_connect(window, "size-allocate",
                     G_CALLBACK(lsv_size_allocate_cb), lsvi);

    gtk_widget_show_all(window);

    escape_action =
        g_action_map_lookup_action(G_ACTION_MAP(window), "lsv-escape");
    lsv_escape_change_state(G_SIMPLE_ACTION(escape_action),
                            g_variant_new_boolean(*escape_specials),
                            window);
}