#include <codeconv.h>
#include "common/utils.h"
+#include "mainwindow.h"
+#include "statusbar.h"
#include "lh_viewer.h"
static gchar *content_types[] = { "text/html", NULL };
}
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);
}
// 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()
{
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);
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);
+}
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);
/* 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)
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)
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"))
{
}
}
+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)
{
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)
{
delete w;
}
+void lh_widget_print(lh_widget_wrapped *w) {
+ w->print();
+}
+
} /* extern "C" */
void open_html(const gchar *contents);
void clear();
void update_cursor();
+ void print();
litehtml::document::ptr m_html;
litehtml::tstring m_clicked_url;
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" */