2 * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
3 * Copyright(C) 1999-2015 the Claws Mail Team
5 * This file Copyright (C) 2009-2015 Salvatore De Paolis
6 * <iwkse@claws-mail.org> and the Claws Mail Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write tothe Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "claws-features.h"
26 #include "common/utils.h"
27 #include "lh_viewer.h"
29 static gchar *content_types[] = { "text/html", NULL };
31 MimeViewer *lh_viewer_create();
33 MimeViewerFactory lh_viewer_factory = {
39 static GtkWidget *lh_get_widget(MimeViewer *_viewer)
41 debug_print("LH: get_widget\n");
42 LHViewer *viewer = (LHViewer *)_viewer;
46 static gchar *get_utf8_string(const gchar *string) {
51 if (!g_utf8_validate(string, -1, NULL)) {
52 const gchar *cur_locale = conv_get_current_locale();
53 utf8 = g_convert(string, -1, "utf-8", cur_locale, NULL, &length, &error);
55 debug_print("Failed convertion to current locale: %s", error->message);
58 utf8 = g_convert(string, -1, "utf-8", "iso-8859-1", NULL, &length, &error);
60 debug_print("Charset detection failed");
61 utf8 = g_strdup(string);
62 g_clear_error(&error);
66 utf8 = g_strdup(string);
72 static void lh_show_mimepart(MimeViewer *_viewer, const gchar *infole,
75 debug_print("LH: show_mimepart\n");
76 LHViewer *viewer = (LHViewer *)_viewer;
78 gchar *msgfile = procmime_get_tmp_file_name(partinfo);
79 debug_print("LH: msgfile '%s'\n", msgfile);
81 if (procmime_get_part(msgfile, partinfo) < 0) {
82 debug_print("LH: couldn't get MIME part file\n");
87 gchar *contents, *utf8;
90 if (!g_file_get_contents(msgfile, &contents, &length, &error)) {
91 g_warning("LiteHTML viewer: couldn't read contents of file '%s': %s",
92 msgfile, error->message);
93 g_clear_error(&error);
96 utf8 = get_utf8_string(contents);
102 lh_widget_open_html(viewer->widget, utf8);
106 static void lh_clear_viewer(MimeViewer *_viewer)
108 debug_print("LH: clear_viewer\n");
109 LHViewer *viewer = (LHViewer *)_viewer;
110 lh_widget_clear(viewer->widget);
113 static void lh_destroy_viewer(MimeViewer *_viewer)
115 debug_print("LH: destroy_viewer\n");
118 lh_clear_viewer(_viewer);
120 // LHViewer *viewer = (LHViewer *)_viewer;
121 // lh_widget_destroy(viewer->widget);
124 /***************************************************************/
125 MimeViewer *lh_viewer_create()
127 debug_print("LH: viewer_create\n");
129 LHViewer *viewer = g_new0(LHViewer, 1);
130 viewer->mimeviewer.factory = &lh_viewer_factory;
131 viewer->widget = lh_widget_new();
133 viewer->mimeviewer.get_widget = lh_get_widget;
134 viewer->mimeviewer.show_mimepart = lh_show_mimepart;
136 viewer->mimeviewer.clear_viewer = lh_clear_viewer;
137 viewer->mimeviewer.destroy_viewer = lh_destroy_viewer;
139 viewer->vbox = gtk_vbox_new(FALSE, 0);
141 GtkWidget *w = lh_widget_get_widget(viewer->widget);
142 gtk_box_pack_start(GTK_BOX(viewer->vbox), w,
145 gtk_widget_show_all(viewer->vbox);
147 return (MimeViewer *)viewer;