talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 142d4793deaf8bcf402307e63af4594e2be7d48f
parent 3c7ffb7d3c342bb68db1946a6e18c1a63f9fbf56
Author: Michael Rasmussen <mir@datanom.net>
Date:   Fri, 16 Nov 2018 17:18:45 +0100

Use statusbar for notification. Begin print implementation

Signed-off-by: Michael Rasmussen <mir@datanom.net>

Diffstat:
Msrc/plugins/litehtml_viewer/lh_viewer.c | 50+++++++++++++++++++++++++++++++++++++++++++-------
Msrc/plugins/litehtml_viewer/lh_widget.cpp | 34++++++++++++++++++++++++++++------
Msrc/plugins/litehtml_viewer/lh_widget.h | 1+
Msrc/plugins/litehtml_viewer/lh_widget_wrapped.h | 3+++
4 files changed, 75 insertions(+), 13 deletions(-)

diff --git a/src/plugins/litehtml_viewer/lh_viewer.c b/src/plugins/litehtml_viewer/lh_viewer.c @@ -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); +} diff --git a/src/plugins/litehtml_viewer/lh_widget.cpp b/src/plugins/litehtml_viewer/lh_widget.cpp @@ -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" */ diff --git a/src/plugins/litehtml_viewer/lh_widget.h b/src/plugins/litehtml_viewer/lh_widget.h @@ -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; diff --git a/src/plugins/litehtml_viewer/lh_widget_wrapped.h b/src/plugins/litehtml_viewer/lh_widget_wrapped.h @@ -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" */