summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrootavish <[email protected]>2014-07-19 10:47:43 +0530
committerrootavish <[email protected]>2014-07-19 10:47:43 +0530
commit46fce038996fa84784df775d0b2e941228388b66 (patch)
treecf8360de1cc5a97cf5fbb5b56e0451b44cb4898c
parent812a3c3d777a74b6e72fc402c17a5b861a712040 (diff)
downloadatril-46fce038996fa84784df775d0b2e941228388b66.tar.bz2
atril-46fce038996fa84784df775d0b2e941228388b66.tar.xz
Thumbnails for all documents
Now other problems with webkit. After much fidgeting I was able to resolve the previous problems of threads. However, now there is a different webkit error.
-rw-r--r--backend/epub/epub-document.c177
-rw-r--r--libdocument/ev-document-thumbnails.c10
-rw-r--r--libdocument/ev-document-thumbnails.h7
-rw-r--r--libview/ev-jobs.c133
-rw-r--r--libview/ev-jobs.h30
-rw-r--r--libview/ev-web-view.c14
-rw-r--r--libview/ev-web-view.h5
-rw-r--r--shell/ev-sidebar-thumbnails.c26
-rw-r--r--shell/ev-window.c3
9 files changed, 291 insertions, 114 deletions
diff --git a/backend/epub/epub-document.c b/backend/epub/epub-document.c
index e12204b7..bea41d98 100644
--- a/backend/epub/epub-document.c
+++ b/backend/epub/epub-document.c
@@ -71,8 +71,8 @@ struct _EpubDocument
GList* contentList ;
/* A variable to hold our epubDocument for unzipping*/
unzFile epubDocument ;
- /* A pointer to an offscreen WebKitWebView, for thumbnails*/
- WebKitWebView *webview;
+ /*The (sub)directory that actually houses the document*/
+ gchar* documentdir;
};
static void epub_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *iface);
@@ -83,54 +83,60 @@ EV_BACKEND_REGISTER_WITH_CODE (EpubDocument, epub_document,
epub_document_document_thumbnails_iface_init);
} );
-/* A cairo surface for the thumbnails, this probably dosen't need to be global, but I couldn't find a better solution.*/
-static cairo_surface_t* surface = NULL ;
-static gboolean completed = FALSE;
-static GdkPixbuf *thumbnail=NULL ;
-
static void
-epub_webkit_render(EpubDocument *document,const char* uri);
+epub_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
+ EvRenderContext *rc,
+ gint *width,
+ gint *height)
+{
+ gdouble page_width, page_height;
+
+ page_width = 800;
+ page_height = 1080;
+
+ *width = MAX ((gint)(page_width * rc->scale + 0.5), 1);
+ *height = MAX ((gint)(page_height * rc->scale + 0.5), 1);
+}
static GdkPixbuf *
epub_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
- EvRenderContext *rc,
- gboolean border)
+ EvRenderContext *rc,
+ gboolean border)
{
- gchar* uri = (gchar*) rc->page->backend_page;
- EpubDocument *epub_document = EPUB_DOCUMENT(document);
- completed = FALSE ;
- thumbnail=NULL;
- if (surface) {
- cairo_surface_destroy (surface);
- surface=NULL;
- }
- epub_webkit_render (epub_document,uri);
+ cairo_surface_t *webpage;
+ GdkPixbuf *thumbnailpix = NULL ;
+ gint width,height;
+ epub_document_thumbnails_get_dimensions(document,rc,&width,&height);
+ webpage = ev_document_misc_surface_rotate_and_scale(rc->page->backend_page,width,height,0);
+ thumbnailpix = ev_document_misc_pixbuf_from_surface(webpage);
+ return thumbnailpix;
+}
- while (completed != TRUE ) {
- /*Wait for the job to complete*/
- }
-
- if (thumbnail) {
- return thumbnail;
- }
- else {
- return NULL;
+static void
+load_finished_cb(WebKitWebView *webview,
+ GParamSpec *spec,
+ gboolean *completed)
+{
+ WebKitLoadStatus status = webkit_web_view_get_load_status (webview);
+
+ if (status == WEBKIT_LOAD_FINISHED) {
+ (*completed) = TRUE;
}
}
-static void
-epub_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
- EvRenderContext *rc,
- gint *width,
- gint *height)
+GtkWidget*
+epub_document_thumbnails_render_in_webview(gchar* webpage)
{
- gdouble page_width, page_height;
-
- page_width = 800;
- page_height = 600;
-
- *width = MAX ((gint)(page_width * rc->scale + 0.5), 1);
- *height = MAX ((gint)(page_height * rc->scale + 0.5), 1);
+ GtkWidget *webview = webkit_web_view_new();
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview),webpage);
+ gboolean completed = FALSE;
+ g_signal_connect(webview,"notify::load-status",G_CALLBACK(load_finished_cb),&completed);
+
+ while (completed == FALSE) {
+ /* Wait for the load to complete*/
+ }
+
+ return webview;
}
static void
@@ -138,12 +144,13 @@ epub_document_document_thumbnails_iface_init (EvDocumentThumbnailsInterface *ifa
{
iface->get_thumbnail = epub_document_thumbnails_get_thumbnail;
iface->get_dimensions = epub_document_thumbnails_get_dimensions;
+ iface->render_in_webview = epub_document_thumbnails_render_in_webview;
}
static gboolean
epub_document_save (EvDocument *document,
- const char *uri,
- GError **error)
+ const char *uri,
+ GError **error)
{
EpubDocument *epub_document = EPUB_DOCUMENT (document);
@@ -161,45 +168,6 @@ epub_document_get_n_pages (EvDocument *document)
return g_list_length(epub_document->contentList);
}
#if !GTK_CHECK_VERSION(3, 0, 0)
-static void
-webkit_render_cb(GtkWidget *web_view,
- GParamSpec *specification,
- gpointer data)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status (WEBKIT_WEB_VIEW(web_view));
-
- if ( status == WEBKIT_LOAD_FINISHED )
- {
- surface = webkit_web_view_get_snapshot (WEBKIT_WEB_VIEW(web_view));
- thumbnail = ev_document_misc_pixbuf_from_surface(surface);
- completed=TRUE;
- }
-}
-
-static void epub_webkit_render(EpubDocument *epub_document,const char* uri)
-{
- webkit_web_view_load_uri(WEBKIT_WEB_VIEW(epub_document->webview),uri);
-}
-
-static WebKitWebView*
-offscreen_webview_init()
-{
- GtkWidget *offscreen_window = gtk_offscreen_window_new();
- gtk_window_set_default_size(GTK_WINDOW(offscreen_window),800,600);
-
- GtkWidget* scroll_view = gtk_scrolled_window_new (NULL,NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scroll_view),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
- GtkWidget* web_view = webkit_web_view_new ();
- WebKitWebSettings *webviewsettings = webkit_web_settings_new ();
- g_object_set (G_OBJECT(webviewsettings), "enable-plugins", FALSE, NULL);
- webkit_web_view_set_settings (WEBKIT_WEB_VIEW(web_view),webviewsettings);
- g_signal_connect(WEBKIT_WEB_VIEW(web_view),"notify::load-status",G_CALLBACK(webkit_render_cb),NULL);
- gtk_container_add(GTK_CONTAINER(scroll_view),web_view);
- gtk_container_add(GTK_CONTAINER(offscreen_window),scroll_view);
- gtk_widget_show_all (offscreen_window);
- return WEBKIT_WEB_VIEW(web_view);
-}
-
#else /* The webkit2 code for GTK3 */
static void
@@ -690,16 +658,18 @@ extract_epub_from_container (const gchar* uri,
return TRUE ;
}
-
static gchar*
-get_uri_to_content(const gchar* uri,GError ** error,gchar* tmp_archive_dir)
+get_uri_to_content(const gchar* uri,GError ** error,EpubDocument *epub_document)
{
+ gchar* tmp_archive_dir = epub_document->tmp_archive_dir;
GError * err = NULL ;
gchar* containerpath = g_filename_from_uri(uri,NULL,&err);
GString* absolutepath ;
gchar* content_uri ;
xmlNodePtr rootfileNode ;
xmlChar* relativepath;
+ gchar* directorybuffer = g_malloc0(sizeof(gchar*)*100);
+
if ( !containerpath )
{
if (err) {
@@ -752,6 +722,27 @@ get_uri_to_content(const gchar* uri,GError ** error,gchar* tmp_archive_dir)
return NULL ;
}
absolutepath = g_string_new(tmp_archive_dir);
+ gchar* documentfolder = g_strrstr((gchar*)relativepath,"/");
+ if (documentfolder != NULL) {
+ gchar* copybuffer = (gchar*)relativepath ;
+ gchar* writer = directorybuffer;
+
+ while(copybuffer != documentfolder) {
+ (*writer) = (*copybuffer);
+ writer++;copybuffer++;
+ }
+ *writer = '\0';
+ GString *documentdir = g_string_new(tmp_archive_dir);
+ g_string_append_printf(documentdir,"/%s",directorybuffer);
+ epub_document->documentdir = g_strdup(documentdir->str);
+
+ g_string_free(documentdir,TRUE);
+ }
+ else
+ {
+ epub_document->documentdir = g_strdup(tmp_archive_dir);
+ }
+
g_string_append_printf(absolutepath,"/%s",relativepath);
content_uri = g_filename_to_uri(absolutepath->str,NULL,&err);
if ( !content_uri ) {
@@ -767,12 +758,12 @@ get_uri_to_content(const gchar* uri,GError ** error,gchar* tmp_archive_dir)
return NULL ;
}
g_string_free(absolutepath,TRUE);
-
+ g_free(directorybuffer);
return content_uri ;
}
static GList*
-setup_document_content_list(const gchar* content_uri, GError** error,gchar *tmp_archive_dir)
+setup_document_content_list(const gchar* content_uri, GError** error,gchar *documentdir)
{
GList* newlist = NULL ;
GError * err = NULL ;
@@ -860,7 +851,7 @@ setup_document_content_list(const gchar* content_uri, GError** error,gchar *tmp_
break;
}
relativepath = (gchar*)xml_get_data_from_node(itemptr,XML_ATTRIBUTE,(xmlChar*)"href");
- g_string_assign(absolutepath,tmp_archive_dir);
+ g_string_assign(absolutepath,documentdir);
g_string_append_printf(absolutepath,"/%s",relativepath);
newnode->value = g_filename_to_uri(absolutepath->str,NULL,&err);
if ( newnode->value == NULL )
@@ -916,7 +907,7 @@ epub_document_init (EpubDocument *epub_document)
epub_document->archivename = NULL ;
epub_document->tmp_archive_dir = NULL ;
epub_document->contentList = NULL ;
- epub_document->webview = offscreen_webview_init();
+ epub_document->documentdir = NULL;
}
static gboolean
@@ -953,8 +944,8 @@ epub_document_load (EvDocument* document,
g_propagate_error(error,err);
return FALSE;
}
- contentOpfUri = get_uri_to_content (containeruri,&err,epub_document->tmp_archive_dir);
-
+ contentOpfUri = get_uri_to_content (containeruri,&err,epub_document);
+
if ( contentOpfUri == NULL )
{
g_propagate_error(error,err);
@@ -963,7 +954,7 @@ epub_document_load (EvDocument* document,
xml_free_doc() ;
- epub_document->contentList = setup_document_content_list (contentOpfUri,&err,epub_document->tmp_archive_dir);
+ epub_document->contentList = setup_document_content_list (contentOpfUri,&err,epub_document->documentdir);
if ( xmldocument != NULL )
xml_free_doc ();
@@ -998,6 +989,9 @@ epub_document_finalize (GObject *object)
if ( epub_document->archivename) {
g_free (epub_document->archivename);
}
+ if ( epub_document->documentdir) {
+ g_free (epub_document->documentdir);
+ }
G_OBJECT_CLASS (epub_document_parent_class)->finalize (object);
}
@@ -1017,7 +1011,7 @@ epub_document_get_info(EvDocument *document)
{
return NULL ;
}
- gchar* uri = get_uri_to_content (containeruri,&error,archive_dir);
+ gchar* uri = get_uri_to_content (containeruri,&error,epub_document);
if ( error )
{
return NULL ;
@@ -1093,7 +1087,6 @@ epub_document_class_init (EpubDocumentClass *klass)
EvDocumentClass *ev_document_class = EV_DOCUMENT_CLASS (klass);
gobject_class->finalize = epub_document_finalize;
-
ev_document_class->load = epub_document_load;
ev_document_class->save = epub_document_save;
ev_document_class->get_n_pages = epub_document_get_n_pages;
diff --git a/libdocument/ev-document-thumbnails.c b/libdocument/ev-document-thumbnails.c
index 9482e09e..61eb2fe8 100644
--- a/libdocument/ev-document-thumbnails.c
+++ b/libdocument/ev-document-thumbnails.c
@@ -61,3 +61,13 @@ ev_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
iface->get_dimensions (document, rc, width, height);
}
+GtkWidget*
+ev_document_thumbnails_get_webview_with_rendered_document(EvDocumentThumbnails *document,
+ gchar *webpageuri)
+{
+ EvDocumentThumbnailsInterface *iface;
+ g_return_val_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document),NULL);
+
+ iface = EV_DOCUMENT_THUMBNAILS_GET_IFACE(document);
+ return iface->render_in_webview(webpageuri);
+} \ No newline at end of file
diff --git a/libdocument/ev-document-thumbnails.h b/libdocument/ev-document-thumbnails.h
index 1a7cb9fd..a94a810d 100644
--- a/libdocument/ev-document-thumbnails.h
+++ b/libdocument/ev-document-thumbnails.h
@@ -26,7 +26,7 @@
#define EV_DOCUMENT_THUMBNAILS_H
#include <gdk-pixbuf/gdk-pixbuf.h>
-
+#include <gtk/gtk.h>
#include "ev-render-context.h"
G_BEGIN_DECLS
@@ -52,6 +52,8 @@ struct _EvDocumentThumbnailsInterface {
EvRenderContext *rc,
gint *width,
gint *height);
+
+ GtkWidget *(*render_in_webview) (gchar* webpage);
};
GType ev_document_thumbnails_get_type (void) G_GNUC_CONST;
@@ -63,7 +65,8 @@ void ev_document_thumbnails_get_dimensions (EvDocumentThumbnails *document
EvRenderContext *rc,
gint *width,
gint *height);
-
+GtkWidget* ev_document_thumbnails_get_webview_with_rendered_document (EvDocumentThumbnails *document,
+ gchar* webpageuri);
G_END_DECLS
#endif /* EV_DOCUMENT_THUMBNAILS_H */
diff --git a/libview/ev-jobs.c b/libview/ev-jobs.c
index 7792fafa..4f938a89 100644
--- a/libview/ev-jobs.c
+++ b/libview/ev-jobs.c
@@ -24,6 +24,7 @@
#include "ev-document-thumbnails.h"
#include "ev-document-links.h"
#include "ev-document-images.h"
+#include "ev-job-scheduler.h"
#include "ev-document-forms.h"
#include "ev-file-exporter.h"
#include "ev-document-factory.h"
@@ -39,6 +40,14 @@
#include "ev-document-text.h"
#include "ev-debug.h"
+#include <gtk/gtk.h>
+#ifdef ENABLE_EPUB
+#if GTK_CHECK_VERSION(3, 0, 0)
+#include <webkit2/webkit2.h>
+#else
+#include <webkit/webkit.h>
+#endif
+#endif
#include <errno.h>
#include <glib/gstdio.h>
#include <glib/gi18n-lib.h>
@@ -58,6 +67,8 @@ static void ev_job_page_data_init (EvJobPageData *job);
static void ev_job_page_data_class_init (EvJobPageDataClass *class);
static void ev_job_thumbnail_init (EvJobThumbnail *job);
static void ev_job_thumbnail_class_init (EvJobThumbnailClass *class);
+static void ev_job_web_thumbnail_init (EvJobWebThumbnail *job);
+static void ev_job_web_thumbnail_class_init (EvJobWebThumbnailClass *class);
static void ev_job_load_init (EvJobLoad *job);
static void ev_job_load_class_init (EvJobLoadClass *class);
static void ev_job_save_init (EvJobSave *job);
@@ -87,6 +98,11 @@ enum {
FIND_LAST_SIGNAL
};
+typedef struct _WebKitScreenShot {
+ cairo_surface_t *surface;
+ gboolean completed;
+}WebKitScreenShot;
+
static guint job_signals[LAST_SIGNAL] = { 0 };
static guint job_fonts_signals[FONTS_LAST_SIGNAL] = { 0 };
static guint job_find_signals[FIND_LAST_SIGNAL] = { 0 };
@@ -98,6 +114,7 @@ G_DEFINE_TYPE (EvJobAnnots, ev_job_annots, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobRender, ev_job_render, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobPageData, ev_job_page_data, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobThumbnail, ev_job_thumbnail, EV_TYPE_JOB)
+G_DEFINE_TYPE (EvJobWebThumbnail, ev_job_web_thumbnail, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobFonts, ev_job_fonts, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobLoad, ev_job_load, EV_TYPE_JOB)
G_DEFINE_TYPE (EvJobSave, ev_job_save, EV_TYPE_JOB)
@@ -758,7 +775,7 @@ ev_job_page_data_new (EvDocument *document,
static void
ev_job_thumbnail_init (EvJobThumbnail *job)
{
- EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
+ EV_JOB (job)->run_mode = EV_JOB_RUN_THREAD;
}
static void
@@ -784,10 +801,10 @@ ev_job_thumbnail_run (EvJob *job)
EvJobThumbnail *job_thumb = EV_JOB_THUMBNAIL (job);
EvRenderContext *rc;
EvPage *page;
-
+ GtkWidget *webview;
ev_debug_message (DEBUG_JOBS, "%d (%p)", job_thumb->page, job);
ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
-
+
ev_document_doc_mutex_lock ();
page = ev_document_get_page (job->document, job_thumb->page);
@@ -799,13 +816,38 @@ ev_job_thumbnail_run (EvJob *job)
}
g_object_unref (page);
+ if (job->document->iswebdocument == TRUE) {
+ webview = ev_document_thumbnails_get_webview_with_rendered_document(EV_DOCUMENT_THUMBNAILS(job->document),(gchar*)rc->page->backend_page);
+ gboolean completed = FALSE;
+
+ EvJobWebThumbnail *web_thumb_job =
+ EV_JOB_WEB_THUMBNAIL(ev_job_web_thumbnail_new(job->document, webview, &completed));
+
+ ev_job_scheduler_push_job (EV_JOB (web_thumb_job), EV_JOB_PRIORITY_HIGH);
+
+ while (completed == FALSE) {
+ /*Let the job complete before we proceed.
+ *This fix SHOULD solve all problems.
+ */
+ }
+
+ /* For the purpose of thumbnails only, we make the page a cairo surface, instead of the uri's we are passing around*/
+ EvPage *screenshotpage;
+ screenshotpage = ev_page_new(rc->page->index);
+ screenshotpage->backend_page = (EvBackendPage)web_thumb_job->surface;
+ screenshotpage->backend_destroy_func = (EvBackendPageDestroyFunc)cairo_surface_destroy ;
+ ev_render_context_set_page(rc,screenshotpage);
+
+ g_object_unref(web_thumb_job);
+ }
+
job_thumb->thumbnail = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (job->document),
rc, TRUE);
g_object_unref (rc);
ev_document_doc_mutex_unlock ();
ev_job_succeeded (job);
-
+
return FALSE;
}
@@ -839,6 +881,89 @@ ev_job_thumbnail_new (EvDocument *document,
return EV_JOB (job);
}
+/* This job is a part of thumbnails, but will run as a thread and call the otherwise main loop job on a signal*/
+/* EvJobWebThumbnail */
+static void
+ev_job_web_thumbnail_init (EvJobWebThumbnail *job)
+{
+ EV_JOB (job)->run_mode = EV_JOB_RUN_MAIN_LOOP;
+}
+
+static void
+ev_job_web_thumbnail_dispose (GObject *object)
+{
+ EvJobWebThumbnail *job;
+
+ job = EV_JOB_WEB_THUMBNAIL (object);
+
+ ev_debug_message (DEBUG_JOBS, "%d (%p)", job->page, job);
+
+ if(job->webview) {
+ g_object_unref(job->webview);
+ job->webview = NULL;
+ }
+
+ if(job->offscreenwindow) {
+ gtk_widget_destroy(job->offscreenwindow);
+ job->offscreenwindow = NULL;
+ }
+
+ if(job->surface) {
+ cairo_surface_destroy (job->surface);
+ job->surface = NULL;
+ }
+ (* G_OBJECT_CLASS (ev_job_web_thumbnail_parent_class)->dispose) (object);
+}
+
+static gboolean
+ev_job_web_thumbnail_run (EvJob *job)
+{
+ EvJobWebThumbnail *web_thumb_job = EV_JOB_WEB_THUMBNAIL(job);
+ gtk_window_set_default_size (GTK_WINDOW(web_thumb_job->offscreenwindow),800,1080);
+ gtk_container_add(GTK_CONTAINER(web_thumb_job->offscreenwindow),GTK_WIDGET(web_thumb_job->webview));
+ gtk_widget_show_all(web_thumb_job->offscreenwindow);
+
+ web_thumb_job->surface = webkit_web_view_get_snapshot (WEBKIT_WEB_VIEW(web_thumb_job->webview));
+
+ while (!web_thumb_job->surface) {
+ /* Wait for a surface */
+ }
+ *(web_thumb_job->completed) = TRUE ;
+
+ ev_job_succeeded (job);
+
+ return FALSE;
+}
+
+static void
+ev_job_web_thumbnail_class_init (EvJobWebThumbnailClass *class)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ EvJobClass *job_class = EV_JOB_CLASS (class);
+
+ oclass->dispose = ev_job_web_thumbnail_dispose;
+ job_class->run = ev_job_web_thumbnail_run;
+}
+
+EvJob *
+ev_job_web_thumbnail_new (EvDocument *document,
+ GtkWidget *webview,
+ gboolean *completed)
+{
+ EvJobWebThumbnail *job;
+
+ ev_debug_message (DEBUG_JOBS, "%d", page);
+
+ job = g_object_new (EV_TYPE_JOB_WEB_THUMBNAIL, NULL);
+
+ EV_JOB (job)->document = g_object_ref (document);
+ job->webview = g_object_ref(webview);
+ job->completed = completed;
+ job->offscreenwindow = gtk_offscreen_window_new();
+ job->surface = NULL;
+ return EV_JOB (job);
+}
+
/* EvJobFonts */
static void
ev_job_fonts_init (EvJobFonts *job)
diff --git a/libview/ev-jobs.h b/libview/ev-jobs.h
index e6ae4552..8924a129 100644
--- a/libview/ev-jobs.h
+++ b/libview/ev-jobs.h
@@ -45,6 +45,9 @@ typedef struct _EvJobPageDataClass EvJobPageDataClass;
typedef struct _EvJobThumbnail EvJobThumbnail;
typedef struct _EvJobThumbnailClass EvJobThumbnailClass;
+typedef struct _EvJobWebThumbnail EvJobWebThumbnail;
+typedef struct _EvJobWebThumbnailClass EvJobWebThumbnailClass;
+
typedef struct _EvJobLinks EvJobLinks;
typedef struct _EvJobLinksClass EvJobLinksClass;
@@ -111,6 +114,11 @@ typedef struct _EvJobPrintClass EvJobPrintClass;
#define EV_JOB_THUMBNAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_THUMBNAIL, EvJobThumbnailClass))
#define EV_IS_JOB_THUMBNAIL(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_THUMBNAIL))
+#define EV_TYPE_JOB_WEB_THUMBNAIL (ev_job_web_thumbnail_get_type())
+#define EV_JOB_WEB_THUMBNAIL(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_WEB_THUMBNAIL, EvJobWebThumbnail))
+#define EV_JOB_WEB_THUMBNAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_WEB_THUMBNAIL, EvJobWebThumbnailClass))
+#define EV_IS_JOB_WEB_THUMBNAIL(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_JOB_WEB_THUMBNAIL))
+
#define EV_TYPE_JOB_FONTS (ev_job_fonts_get_type())
#define EV_JOB_FONTS(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_JOB_FONTS, EvJobFonts))
#define EV_JOB_FONTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_JOB_FONTS, EvJobFontsClass))
@@ -281,11 +289,9 @@ struct _EvJobPageDataClass
struct _EvJobThumbnail
{
EvJob parent;
-
gint page;
gint rotation;
gdouble scale;
-
GdkPixbuf *thumbnail;
};
@@ -294,6 +300,20 @@ struct _EvJobThumbnailClass
EvJobClass parent_class;
};
+struct _EvJobWebThumbnail
+{
+ EvJob parent;
+ GtkWidget *webview;
+ GtkWidget *offscreenwindow;
+ gboolean *completed;
+ cairo_surface_t *surface;
+};
+
+struct _EvJobWebThumbnailClass
+{
+ EvJobClass parent_class;
+};
+
struct _EvJobFonts
{
EvJob parent;
@@ -450,6 +470,12 @@ EvJob *ev_job_thumbnail_new (EvDocument *document,
gint page,
gint rotation,
gdouble scale);
+
+/* EvJobWebThumbnail */
+GType ev_job_web_thumbnail_get_type (void) G_GNUC_CONST;
+EvJob *ev_job_web_thumbnail_new (EvDocument *document,
+ GtkWidget *webview,
+ gboolean *completed);
/* EvJobFonts */
GType ev_job_fonts_get_type (void) G_GNUC_CONST;
EvJob *ev_job_fonts_new (EvDocument *document);
diff --git a/libview/ev-web-view.c b/libview/ev-web-view.c
index 96fb6c46..b88d09ff 100644
--- a/libview/ev-web-view.c
+++ b/libview/ev-web-view.c
@@ -99,8 +99,7 @@ ev_web_view_destroy (GtkObject *object)
if (webview->model) {
g_object_unref(webview->model);
webview->model = NULL;
- }
- WebKitWebViewClass *klass = WEBKIT_WEB_VIEW_GET_CLASS(webview);
+ };
#if GTK_CHECK_VERSION (3, 0, 0)
G_OBJECT_CLASS (ev_web_view_parent_class)->dispose (object);
@@ -193,7 +192,7 @@ ev_web_view_document_changed_cb (EvDocumentModel *model,
if (webview->current_page != current_page) {
ev_web_view_change_page (webview, current_page);
} else {
- webkit_web_view_reload (webview);
+ webkit_web_view_reload (WEBKIT_WEB_VIEW(webview));
}
}
@@ -227,7 +226,6 @@ ev_web_view_fullscreen_changed_cb (EvDocumentModel *model,
webkit_web_view_set_view_mode(WEBKIT_WEB_VIEW(webview), WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN);
#endif
}
-
void
ev_web_view_set_model (EvWebView *webview,
EvDocumentModel *model)
@@ -296,9 +294,13 @@ ev_web_view_next_page (EvWebView *webview)
if (page < n_pages) {
ev_document_model_set_page (webview->model, page);
+ EvPage *webpage = ev_document_get_page(webview->document,page);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview),(gchar*)webpage->backend_page);
return TRUE;
} else if (page == n_pages) {
ev_document_model_set_page (webview->model, page - 1);
+ EvPage *webpage = ev_document_get_page(webview->document,page);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview),(gchar*)webpage->backend_page);
return TRUE;
} else {
return FALSE;
@@ -321,9 +323,13 @@ ev_web_view_previous_page (EvWebView *webview)
if (page >= 0) {
ev_document_model_set_page (webview->model, page);
+ EvPage *webpage = ev_document_get_page(webview->document,page);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview),(gchar*)webpage->backend_page);
return TRUE;
} else if (page == -1) {
ev_document_model_set_page (webview->model, 0);
+ EvPage *webpage = ev_document_get_page(webview->document,page);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview),(gchar*)webpage->backend_page);
return TRUE;
} else {
return FALSE;
diff --git a/libview/ev-web-view.h b/libview/ev-web-view.h
index 6aaa17ff..55736871 100644
--- a/libview/ev-web-view.h
+++ b/libview/ev-web-view.h
@@ -47,7 +47,10 @@ GtkWidget* ev_web_view_new (void);
void ev_web_view_set_model (EvWebView *webview,
EvDocumentModel *model);
void ev_web_view_reload (EvWebView *webview);
-
+void
+ev_web_view_reload_page (EvWebView *webview,
+ gint page);
+
/* Navigation */
gboolean ev_web_view_next_page (EvWebView *webview);
gboolean ev_web_view_previous_page (EvWebView *webview);
diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c
index ec03d998..92f24c2a 100644
--- a/shell/ev-sidebar-thumbnails.c
+++ b/shell/ev-sidebar-thumbnails.c
@@ -68,7 +68,6 @@ struct _EvSidebarThumbnailsPrivate {
EvDocument *document;
EvDocumentModel *model;
EvThumbsSizeCache *size_cache;
-
gint n_pages, pages_done;
int rotation;
@@ -136,8 +135,14 @@ ev_thumbnails_size_cache_new (EvDocument *document)
page = ev_document_get_page (document, i);
- ev_document_get_page_size (document, i, &page_width, &page_height);
-
+ if (document->iswebdocument == FALSE ) {
+ ev_document_get_page_size (document, i, &page_width, &page_height);
+ }
+ else {
+ /* Hardcoding these values to a large enough dimesnsion so as to achieve max content without loss in visibility*/
+ page_width = 800;
+ page_height = 1080;
+ }
if (!rc) {
rc = ev_render_context_new (page, 0, (gdouble)THUMBNAIL_WIDTH / page_width);
} else {
@@ -368,6 +373,10 @@ clear_range (EvSidebarThumbnails *sidebar_thumbnails,
result && start_page <= end_page;
result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), start_page ++) {
EvJobThumbnail *job;
+
+ if (priv->document->iswebdocument == TRUE) {
+ EV_JOB(job)->run_mode = EV_JOB_RUN_MAIN_LOOP ;
+ }
GdkPixbuf *loading_icon = NULL;
gint width, height;
@@ -409,9 +418,12 @@ get_scale_for_page (EvSidebarThumbnails *sidebar_thumbnails,
{
EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
gdouble width;
-
- ev_document_get_page_size (priv->document, page, &width, NULL);
-
+ if (priv->document->iswebdocument == TRUE ) {
+ /* Hardcoded for epub documents*/
+ width = 800;
+ } else {
+ ev_document_get_page_size (priv->document, page, &width, NULL);
+ }
return (gdouble)THUMBNAIL_WIDTH / width;
}
@@ -433,6 +445,7 @@ add_range (EvSidebarThumbnails *sidebar_thumbnails,
result && page <= end_page;
result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), page ++) {
EvJob *job;
+
gboolean thumbnail_set;
gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &iter,
@@ -444,6 +457,7 @@ add_range (EvSidebarThumbnails *sidebar_thumbnails,
job = ev_job_thumbnail_new (priv->document,
page, priv->rotation,
get_scale_for_page (sidebar_thumbnails, page));
+
ev_job_scheduler_push_job (EV_JOB (job), EV_JOB_PRIORITY_HIGH);
g_object_set_data_full (G_OBJECT (job), "tree_iter",
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 7c5011dc..5c18b28c 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -2089,9 +2089,6 @@ ev_window_open_document (EvWindow *ev_window,
EvWindowRunMode mode,
const gchar *search_string)
{
- if (document == ev_window->priv->document)
- return;
-
ev_window_close_dialogs (ev_window);
ev_window_clear_load_job (ev_window);
ev_window_clear_local_uri (ev_window);