Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / lh_viewer.c
blobb6109fd478c79f41d94ac9920017e22291d58414
1 /*
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.
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #include "claws-features.h"
21 #endif
23 #include <codeconv.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 = {
34 content_types,
36 lh_viewer_create
39 static GtkWidget *lh_get_widget(MimeViewer *_viewer)
41 debug_print("LH: get_widget\n");
42 LHViewer *viewer = (LHViewer *)_viewer;
43 return viewer->vbox;
46 static void lh_show_mimepart(MimeViewer *_viewer, const gchar *infile,
47 MimeInfo *partinfo)
49 debug_print("LH: show_mimepart\n");
50 LHViewer *viewer = (LHViewer *)_viewer;
51 gchar *string = procmime_get_part_as_string(partinfo, TRUE);
52 gchar *utf8 = NULL;
53 const gchar *charset;
55 if (string == NULL) {
56 g_warning("LH: couldn't get MIME part file");
57 return;
60 charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
61 if (charset != NULL && g_ascii_strcasecmp("utf-8", charset) != 0) {
62 gsize length;
63 GError *error = NULL;
64 debug_print("LH: converting mimepart to UTF-8 from %s\n", charset);
65 utf8 = g_convert(string, -1, "utf-8", charset, NULL, &length, &error);
66 if (error) {
67 g_warning("LH: failed mimepart conversion to UTF-8: %s", error->message);
68 g_free(string);
69 g_error_free(error);
70 return;
72 debug_print("LH: successfully converted %" G_GSIZE_FORMAT " bytes\n", length);
73 } else {
74 utf8 = string;
77 lh_widget_set_partinfo(viewer->widget, partinfo);
78 lh_widget_open_html(viewer->widget, utf8);
79 g_free(utf8);
82 static void lh_clear_viewer(MimeViewer *_viewer)
84 debug_print("LH: clear_viewer\n");
85 LHViewer *viewer = (LHViewer *)_viewer;
86 lh_widget_clear(viewer->widget);
89 static void lh_destroy_viewer(MimeViewer *_viewer)
91 LHViewer *viewer = (LHViewer *)_viewer;
93 debug_print("LH: destroy_viewer\n");
94 g_free(viewer);
98 static void lh_print_viewer (MimeViewer *_viewer)
100 debug_print("LH: print_viewer\n");
102 LHViewer* viewer = (LHViewer *) _viewer;
103 lh_widget_print(viewer->widget);
108 static gboolean lh_scroll_page(MimeViewer *_viewer, gboolean up)
110 LHViewer *viewer = (LHViewer *)_viewer;
111 GtkAdjustment *vadj = NULL;
113 if (!viewer || (viewer->widget == NULL))
114 return FALSE;
116 vadj = gtk_scrolled_window_get_vadjustment(
117 GTK_SCROLLED_WINDOW(lh_widget_get_widget(viewer->widget)));
118 return gtkutils_scroll_page(lh_widget_get_widget(viewer->widget), vadj, up);
121 static void lh_scroll_one_line(MimeViewer *_viewer, gboolean up)
123 LHViewer *viewer = (LHViewer *)_viewer;
124 GtkAdjustment *vadj = NULL;
126 if (!viewer || (viewer->widget == NULL))
127 return;
129 vadj = gtk_scrolled_window_get_vadjustment(
130 GTK_SCROLLED_WINDOW(lh_widget_get_widget(viewer->widget)));
131 gtkutils_scroll_one_line(lh_widget_get_widget(viewer->widget), vadj, up);
134 /***************************************************************/
135 MimeViewer *lh_viewer_create()
137 debug_print("LH: viewer_create\n");
139 LHViewer *viewer = g_new0(LHViewer, 1);
140 viewer->mimeviewer.factory = &lh_viewer_factory;
141 viewer->widget = lh_widget_new();
143 viewer->mimeviewer.get_widget = lh_get_widget;
144 viewer->mimeviewer.show_mimepart = lh_show_mimepart;
146 viewer->mimeviewer.clear_viewer = lh_clear_viewer;
147 viewer->mimeviewer.destroy_viewer = lh_destroy_viewer;
149 viewer->mimeviewer.scroll_page = lh_scroll_page;
150 viewer->mimeviewer.scroll_one_line = lh_scroll_one_line;
152 viewer->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
153 gtk_widget_set_name(GTK_WIDGET(viewer->vbox), "litehtml_viewer");
155 GtkWidget *w = lh_widget_get_widget(viewer->widget);
156 gtk_box_pack_start(GTK_BOX(viewer->vbox), w,
157 TRUE, TRUE, 1);
159 gtk_widget_show_all(viewer->vbox);
161 return (MimeViewer *)viewer;
164 void lh_widget_statusbar_push(const gchar* msg)
166 MainWindow *mainwin = mainwindow_get_mainwindow();
167 STATUSBAR_PUSH(mainwin, msg);
170 void lh_widget_statusbar_pop()
172 MainWindow *mainwin = mainwindow_get_mainwindow();
173 STATUSBAR_POP(mainwin);