Use statusbar for notification. Begin print implementation
authorMichael Rasmussen <mir@datanom.net>
Fri, 16 Nov 2018 16:18:45 +0000 (17:18 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Tue, 12 Feb 2019 18:38:09 +0000 (19:38 +0100)
Signed-off-by: Michael Rasmussen <mir@datanom.net>
src/plugins/litehtml_viewer/lh_viewer.c
src/plugins/litehtml_viewer/lh_widget.cpp
src/plugins/litehtml_viewer/lh_widget.h
src/plugins/litehtml_viewer/lh_widget_wrapped.h

index c8912e2219fa9f6a73c2b35a37e4f6cee3f29969..f1279173a777a2fe6b1fa1314887db5eb67e2a5d 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <codeconv.h>
 #include "common/utils.h"
+#include "mainwindow.h"
+#include "statusbar.h"
 #include "lh_viewer.h"
 
 static gchar *content_types[] = { "text/html", NULL };
@@ -44,20 +46,32 @@ static GtkWidget *lh_get_widget(MimeViewer *_viewer)
 }
 
 static gchar *get_utf8_string(const gchar *string) {
-        gchar *utf8;
+        gchar *utf8 = NULL;
         gsize length;
         GError *error = NULL;
+        gchar *locale = NULL;
 
        if (!g_utf8_validate(string, -1, NULL)) {
                const gchar *cur_locale = conv_get_current_locale();
-               utf8 = g_convert(string, -1, "utf-8", cur_locale, NULL, &length, &error);
-               if (error) {
-                       debug_print("Failed convertion to current locale: %s", error->message);
-                       g_error_free(error);
-                       error = NULL;
+               gchar* split = g_strstr_len(cur_locale, -1, ".");
+               if (split) {
+                   locale = ++split;
+               } else {
+                   locale = (gchar *) cur_locale;
+               }
+               debug_print("Try converting to UTF-8 from %s\n", locale);
+               if (g_ascii_strcasecmp("utf-8", locale) != 0) {
+                   utf8 = g_convert(string, -1, "utf-8", locale, NULL, &length, &error);
+                   if (error) {
+                           debug_print("Failed convertion to current locale: %s\n", error->message);
+                           g_clear_error(&error);
+                       }
+           }
+           if (!utf8) {
+               debug_print("Use iso-8859-1 as last resort\n");
                        utf8 = g_convert(string, -1, "utf-8", "iso-8859-1", NULL, &length, &error);
                        if (error) {
-                               debug_print("Charset detection failed");
+                               debug_print("Charset detection failed. Use text as is\n");
                                utf8 = g_strdup(string);
                                g_clear_error(&error);
                        }
@@ -121,6 +135,14 @@ static void lh_destroy_viewer(MimeViewer *_viewer)
 //     lh_widget_destroy(viewer->widget);
 }
 
+static void lh_print_viewer (MimeViewer *_viewer)
+{
+    debug_print("LH: print_viewer\n");
+    
+    LHViewer* viewer = (LHViewer *) _viewer;
+    lh_widget_print(viewer->widget);    
+}
+
 /***************************************************************/
 MimeViewer *lh_viewer_create()
 {
@@ -135,6 +157,8 @@ 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->vbox = gtk_vbox_new(FALSE, 0);
 
@@ -147,3 +171,15 @@ MimeViewer *lh_viewer_create()
        return (MimeViewer *)viewer;
 }
 
+void lh_widget_statusbar_push(gchar* msg)
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       STATUSBAR_PUSH(mainwin, msg);
+        g_free(msg);
+}
+
+void lh_widget_statusbar_pop()
+{
+        MainWindow *mainwin = mainwindow_get_mainwindow();
+        STATUSBAR_POP(mainwin);
+}
index ec96a16d7708e8b58448e11268802f9bfaee2173..a4528c07a3946970c5a3a918c1748b8c50ab8b72 100644 (file)
@@ -149,12 +149,19 @@ GdkPixbuf *lh_widget::get_image(const litehtml::tchar_t* url, bool redraw_on_rea
        GdkPixbuf *pixbuf = NULL;
 
        g_log(NULL, G_LOG_LEVEL_MESSAGE, "Loading... %s", url);
-
+        lh_widget_statusbar_push(g_strconcat("Loading ", url, " ...", NULL));
+       
        http http_loader;
        GInputStream *image = http_loader.load_url(url, &error);
     
-       if (!image) return NULL;
-       
+       if (error || !image) {
+           if (error) {
+               g_log(NULL, G_LOG_LEVEL_WARNING, "lh_widget::get_image: Could not create pixbuf %s", error->message);
+               g_clear_error(&error);
+           }
+           goto statusbar_pop;
+       }
+
        pixbuf = gdk_pixbuf_new_from_stream(image, NULL, &error);
        if (error) {
            g_log(NULL, G_LOG_LEVEL_WARNING, "lh_widget::get_image: Could not create pixbuf %s", error->message);
@@ -167,18 +174,23 @@ GdkPixbuf *lh_widget::get_image(const litehtml::tchar_t* url, bool redraw_on_rea
 /*     if (redraw_on_ready) {
                redraw();
        }*/
+
+statusbar_pop:
+       lh_widget_statusbar_pop();
        
        return pixbuf;
 }
 
 void lh_widget::open_html(const gchar *contents)
 {
+       lh_widget_statusbar_push(g_strconcat("Loading HTML part", " ...", NULL));
        m_html = litehtml::document::createFromString(contents, this, &m_context);
        m_rendered_width = 0;
        if (m_html != NULL) {
                g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget::open_html created document");
                redraw();
        }
+       lh_widget_statusbar_pop();
 }
 
 void lh_widget::draw(cairo_t *cr)
@@ -281,7 +293,7 @@ void lh_widget::clear()
 
 void lh_widget::set_cursor(const litehtml::tchar_t* cursor)
 {
-    g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget set_cursor %s:%s", m_cursor, cursor);
+    //g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget set_cursor %s:%s", m_cursor, cursor);
     if (cursor)
     {
        if (m_cursor != cursor)
@@ -294,7 +306,7 @@ void lh_widget::set_cursor(const litehtml::tchar_t* cursor)
 
 void lh_widget::update_cursor()
 {
-    g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget update_cursor %s", m_cursor);
+    //g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget update_cursor %s", m_cursor);
     GdkCursorType cursType = GDK_ARROW;
     if(m_cursor == _t("pointer"))
     {
@@ -309,6 +321,12 @@ void lh_widget::update_cursor()
     }
 }
 
+void lh_widget::print()
+{
+    g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget print");
+    gtk_widget_realize(GTK_WIDGET(m_drawing_area));
+}
+
 static gboolean expose_event_cb(GtkWidget *widget, GdkEvent *event,
                gpointer user_data)
 {
@@ -358,7 +376,7 @@ static gboolean motion_notify_event(GtkWidget *widget, GdkEventButton *event,
     litehtml::position::vector redraw_boxes;
     lh_widget *w = (lh_widget *)user_data;
     
-    g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget on_motion_notify_event");
+    //g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget on_motion_notify_event");
 
     if(w->m_html)
     {    
@@ -440,4 +458,8 @@ void lh_widget_destroy(lh_widget_wrapped *w)
        delete w;
 }
 
+void lh_widget_print(lh_widget_wrapped *w) {
+       w->print();
+}
+
 } /* extern "C" */
index 2f4eb11a23d02998ba7cec604c8e4ea5f0ca2cdc..ed56f7d6ba85f86112f743615c5fcb7b63770b5d 100644 (file)
@@ -29,6 +29,7 @@ class lh_widget : public container_linux
                void open_html(const gchar *contents);
                void clear();
                void update_cursor();
+               void print();
 
                litehtml::document::ptr m_html;
                litehtml::tstring m_clicked_url;
index 521c7f4f857075a135ff9fc9558c14e2ac27523e..64085faf12bdb616ac969a9876d62878ced1abc1 100644 (file)
@@ -12,6 +12,9 @@ GtkWidget *lh_widget_get_widget(lh_widget_wrapped *w);
 void lh_widget_open_html(lh_widget_wrapped *w, const gchar *path);
 void lh_widget_clear(lh_widget_wrapped *w);
 void lh_widget_destroy(lh_widget_wrapped *w);
+void lh_widget_statusbar_push(gchar* msg);
+void lh_widget_statusbar_pop();
+void lh_widget_print(lh_widget_wrapped *w);
 
 #ifdef __cplusplus
 } /* extern "C" */