2 * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
3 * Copyright(C) 2019 the Claws Mail Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write tothe Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "claws-features.h"
24 #include "common/utils.h"
25 #include "mainwindow.h"
26 #include "statusbar.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) {
52 if (!g_utf8_validate(string, -1, NULL)) {
53 const gchar *cur_locale = conv_get_current_locale();
54 gchar* split = g_strstr_len(cur_locale, -1, ".");
58 locale = (gchar *) cur_locale;
60 debug_print("Try converting to UTF-8 from %s\n", locale);
61 if (g_ascii_strcasecmp("utf-8", locale) != 0) {
62 utf8 = g_convert(string, -1, "utf-8", locale, NULL, &length, &error);
64 debug_print("Failed convertion to current locale: %s\n", error->message);
65 g_clear_error(&error);
69 debug_print("Use iso-8859-1 as last resort\n");
70 utf8 = g_convert(string, -1, "utf-8", "iso-8859-1", NULL, &length, &error);
72 debug_print("Charset detection failed. Use text as is\n");
73 utf8 = g_strdup(string);
74 g_clear_error(&error);
78 utf8 = g_strdup(string);
84 static void lh_show_mimepart(MimeViewer *_viewer, const gchar *infile,
87 debug_print("LH: show_mimepart\n");
88 LHViewer *viewer = (LHViewer *)_viewer;
89 gchar *utf8 = procmime_get_part_as_string(partinfo, TRUE);
92 g_warning("LH: couldn't get MIME part file\n");
96 lh_widget_open_html(viewer->widget, utf8);
100 static void lh_clear_viewer(MimeViewer *_viewer)
102 debug_print("LH: clear_viewer\n");
103 LHViewer *viewer = (LHViewer *)_viewer;
104 lh_widget_clear(viewer->widget);
107 static void lh_destroy_viewer(MimeViewer *_viewer)
109 debug_print("LH: destroy_viewer\n");
112 lh_clear_viewer(_viewer);
114 // LHViewer *viewer = (LHViewer *)_viewer;
115 // lh_widget_destroy(viewer->widget);
118 static void lh_print_viewer (MimeViewer *_viewer)
120 debug_print("LH: print_viewer\n");
122 LHViewer* viewer = (LHViewer *) _viewer;
123 lh_widget_print(viewer->widget);
126 /***************************************************************/
127 MimeViewer *lh_viewer_create()
129 debug_print("LH: viewer_create\n");
131 LHViewer *viewer = g_new0(LHViewer, 1);
132 viewer->mimeviewer.factory = &lh_viewer_factory;
133 viewer->widget = lh_widget_new();
135 viewer->mimeviewer.get_widget = lh_get_widget;
136 viewer->mimeviewer.show_mimepart = lh_show_mimepart;
138 viewer->mimeviewer.clear_viewer = lh_clear_viewer;
139 viewer->mimeviewer.destroy_viewer = lh_destroy_viewer;
141 viewer->mimeviewer.print = lh_print_viewer;
143 viewer->vbox = gtk_vbox_new(FALSE, 0);
145 GtkWidget *w = lh_widget_get_widget(viewer->widget);
146 gtk_box_pack_start(GTK_BOX(viewer->vbox), w,
149 gtk_widget_show_all(viewer->vbox);
151 return (MimeViewer *)viewer;
154 void lh_widget_statusbar_push(const gchar* msg)
156 MainWindow *mainwin = mainwindow_get_mainwindow();
157 STATUSBAR_PUSH(mainwin, msg);
160 void lh_widget_statusbar_pop()
162 MainWindow *mainwin = mainwindow_get_mainwindow();
163 STATUSBAR_POP(mainwin);