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 void lh_show_mimepart(MimeViewer
*_viewer
, const gchar
*infile
,
49 debug_print("LH: show_mimepart\n");
50 LHViewer
*viewer
= (LHViewer
*)_viewer
;
51 gchar
*string
= procmime_get_part_as_string(partinfo
, TRUE
);
56 g_warning("LH: couldn't get MIME part file");
60 charset
= procmime_mimeinfo_get_parameter(partinfo
, "charset");
61 if (charset
!= NULL
&& g_ascii_strcasecmp("utf-8", charset
) != 0) {
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
);
67 g_warning("LH: failed mimepart conversion to UTF-8: %s", error
->message
);
72 debug_print("LH: successfully converted %" G_GSIZE_FORMAT
" bytes\n", length
);
77 lh_widget_set_partinfo(viewer
->widget
, partinfo
);
78 lh_widget_open_html(viewer
->widget
, 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");
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
))
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
))
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
,
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
);