LiteHTML pixbuf cache fixes
[claws.git] / src / plugins / litehtml_viewer / lh_viewer.c
index cf22959d5e24215b5da3afbc4832ee32fd15ae19..7fee13e4799dfcc9ca705090099abf30742dae20 100644 (file)
@@ -86,13 +86,32 @@ static void lh_show_mimepart(MimeViewer *_viewer, const gchar *infile,
 {
        debug_print("LH: show_mimepart\n");
        LHViewer *viewer = (LHViewer *)_viewer;
-       gchar *utf8 = procmime_get_part_as_string(partinfo, TRUE);
+       gchar *string = procmime_get_part_as_string(partinfo, TRUE);
+       gchar *utf8 = NULL;
+       const gchar *charset;
 
-       if (utf8 == NULL) {
+       if (string == NULL) {
                g_warning("LH: couldn't get MIME part file\n");
                return;
        }
 
+       charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
+       if (charset != NULL && g_ascii_strcasecmp("utf-8", charset) != 0) {
+               gsize length;
+               GError *error = NULL;
+               debug_print("LH: converting mimepart to UTF-8 from %s\n", charset);
+               utf8 = g_convert(string, -1, "utf-8", charset, NULL, &length, &error);
+               if (error) {
+                       g_warning("LH: failed mimepart conversion to UTF-8: %s", error->message);
+                       g_free(string);
+                       g_error_free(error);
+                       return;
+               }
+               debug_print("LH: successfully converted %" G_GSIZE_FORMAT " bytes\n", length);
+       } else {
+               utf8 = string;
+       }
+
        lh_widget_set_partinfo(viewer->widget, partinfo);
        lh_widget_open_html(viewer->widget, utf8);
        g_free(utf8);
@@ -107,13 +126,10 @@ static void lh_clear_viewer(MimeViewer *_viewer)
 
 static void lh_destroy_viewer(MimeViewer *_viewer)
 {
-       debug_print("LH: destroy_viewer\n");
-
-       /* Just in case. */
-       lh_clear_viewer(_viewer);
+       LHViewer *viewer = (LHViewer *)_viewer;
 
-//     LHViewer *viewer = (LHViewer *)_viewer;
-//     lh_widget_destroy(viewer->widget);
+       debug_print("LH: destroy_viewer\n");
+       g_free(viewer);
 }
 
 static void lh_print_viewer (MimeViewer *_viewer)
@@ -124,6 +140,31 @@ static void lh_print_viewer (MimeViewer *_viewer)
     lh_widget_print(viewer->widget);    
 }
 
+
+static gboolean lh_scroll_page(MimeViewer *_viewer, gboolean up)
+{
+       LHViewer *viewer = (LHViewer *)_viewer;
+       GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
+                                       GTK_SCROLLED_WINDOW(lh_widget_get_widget(viewer->widget)));
+
+       if (viewer->widget == NULL)
+               return FALSE;
+
+       return gtkutils_scroll_page(lh_widget_get_widget(viewer->widget), vadj, up);
+}
+
+static void lh_scroll_one_line(MimeViewer *_viewer, gboolean up)
+{
+       LHViewer *viewer = (LHViewer *)_viewer;
+       GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
+                                       GTK_SCROLLED_WINDOW(lh_widget_get_widget(viewer->widget)));
+
+       if (viewer->widget == NULL)
+               return;
+
+       gtkutils_scroll_one_line(lh_widget_get_widget(viewer->widget), vadj, up);
+}
+
 /***************************************************************/
 MimeViewer *lh_viewer_create()
 {
@@ -138,8 +179,9 @@ MimeViewer *lh_viewer_create()
 
        viewer->mimeviewer.clear_viewer = lh_clear_viewer;
        viewer->mimeviewer.destroy_viewer = lh_destroy_viewer;
-       
-       viewer->mimeviewer.print = lh_print_viewer;
+
+       viewer->mimeviewer.scroll_page = lh_scroll_page;
+       viewer->mimeviewer.scroll_one_line = lh_scroll_one_line;
 
        viewer->vbox = gtk_vbox_new(FALSE, 0);