summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorrootavish <[email protected]>2014-07-07 18:36:55 +0530
committerrootavish <[email protected]>2014-07-07 18:36:55 +0530
commitdf43418e209ae9c98844185f789c63769ae9b3a2 (patch)
tree40b713aaa4b1596c1d6ccddbe89486983d093881 /backend
parent6f41c201422edd6b4dbf9f9f41b5dc29530d21c6 (diff)
downloadatril-df43418e209ae9c98844185f789c63769ae9b3a2.tar.bz2
atril-df43418e209ae9c98844185f789c63769ae9b3a2.tar.xz
Refactored code, created a new EvWebView type
Earlier my approach was to replace the atril view directly with a webview. However as it turned out it was extremely difficult to accomplish much tasks without the document-model. So I created an Extension of the WebKitWebView class, EvWebView so that now we can manipulate the webview as desired. Also having a separate file really helps in terms of clarity. Please note that there are many empty functions and TODO tags right now, I shall aim to fill these up once the display part is done, probably in this week. I also added some code on the backend to draw thumbnails when with GTK+-3.0, although I have never tested a GTK+-3.0 build.With GTK+-2.0 you won't get any build errors, however epub backend won't work right now. That being said, this commit is mostly because there was a lot of code that was lying in the local repository, and it was best to back it up as a failsafe. I modified ev-window to accomodate this new data structure, and having an equivalent ev_web_view function for every ev_view function, I can achieve most functionality by filling those functions with Webkit modules. Other than that on the backend Other than that there were some minor changes to the code. Although I did the above, currently I am not able to instantiate the EvWebView because of some class and object type definition errors, due to which I can't display the document.
Diffstat (limited to 'backend')
-rw-r--r--backend/epub/epub-document.c98
1 files changed, 84 insertions, 14 deletions
diff --git a/backend/epub/epub-document.c b/backend/epub/epub-document.c
index 7539fef8..bf1dc00b 100644
--- a/backend/epub/epub-document.c
+++ b/backend/epub/epub-document.c
@@ -1,3 +1,25 @@
+/* this file is part of atril, a mate document viewer
+ *
+ * Copyright (C) 2014 Avishkar Gupta
+ *
+ * Author:
+ * Avishkar Gupta <[email protected]>
+ *
+ * Atril is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Atril is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
#include "ev-file-helpers.h"
#include "epub-document.h"
#include "unzip.h"
@@ -11,7 +33,12 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
-#include <webkit/webkit.h>
+#if GTK_CHECK_VERSION(3, 0, 0)
+ #include <webkit2/webkit2.h>
+#else
+ #include <webkit/webkit.h>
+#endif
+
#include <gtk/gtk.h>
typedef enum _xmlParseReturnType
@@ -42,8 +69,6 @@ struct _EpubDocument
gchar* tmp_archive_dir ;
/*Stores the contentlist in a sorted manner*/
GList* contentList ;
- /*uri of the current page being displayed in the webview*/
- gchar* currentpageuri ;
/* A variable to hold our epubDocument for unzipping*/
unzFile epubDocument ;
};
@@ -68,10 +93,10 @@ epub_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
cairo_surface_t* surface=NULL;
gchar* uri = (gchar*) rc->page->backend_page;
epub_webkit_render (&surface,uri);
- while ( !surface )
- ;
- gint width = cairo_image_surface_get_width (surface);
- gint height = cairo_image_surface_get_height (surface);
+ if ( !surface ) {
+ return NULL ;
+ }
+
if (surface) {
thumbnail = ev_document_misc_pixbuf_from_surface (surface);
cairo_surface_destroy (surface);
@@ -118,7 +143,7 @@ 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,
@@ -148,6 +173,51 @@ epub_webkit_render(cairo_surface_t **surface,
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view),uri);
}
+#else /* The webkit2 code for GTK3 */
+
+static void
+snapshot_chain_cb(WebKitWebView *web_view,
+ GAsyncResult* res,
+ cairo_surface_t **surface)
+{
+ GError * err = NULL ;
+ *surface = webkit_web_view_get_snapshot_finish(WEBKIT_WEB_VIEW(web_view),res,&err);
+ if ( err ) {
+ surface = NULL ;
+ }
+}
+
+static void
+webkit_render_cb(WebKitWebView *webview,
+ WebKitLoadEvent load_status,
+ cairo_surface_t **surface)
+{
+ if ( load_status != WEBKIT_LOAD_FINISHED )
+ return ;
+
+ webkit_web_view_get_snapshot(webview,
+ WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT,
+ WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING,
+ NULL,
+ (GAsyncReadyCallback)snapshot_chain_cb,
+ surface);
+}
+
+static void epub_webkit_render(cairo_surface_t **surface,
+ const char* uri)
+{
+ 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 ();
+ gtk_container_add(GTK_CONTAINER(offscreen_window),scroll_view);
+ gtk_container_add(GTK_CONTAINER(scroll_view),web_view);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view),uri);
+ gtk_widget_show_all(offscreen_window);
+ g_signal_connect(web_view,"load-changed",G_CALLBACK(webkit_render_cb),surface);
+}
+#endif
/**
* epub_remove_temporary_dir : Removes a directory recursively.
* This function is same as comics_remove_temporary_dir
@@ -793,7 +863,6 @@ epub_document_init (EpubDocument *epub_document)
epub_document->archivename = NULL ;
epub_document->tmp_archive_dir = NULL ;
epub_document->contentList = NULL ;
- epub_document->currentpageuri = NULL;
}
static gboolean
@@ -869,11 +938,12 @@ epub_document_finalize (GObject *object)
if ( epub_document->contentList ) {
g_list_free_full(epub_document->contentList,(GDestroyNotify)free_tree_nodes);
}
-
- g_free (epub_document->tmp_archive_dir);
- g_free (epub_document->currentpageuri);
- g_free (epub_document->archivename);
-
+ if ( epub_document->tmp_archive_dir) {
+ g_free (epub_document->tmp_archive_dir);
+ }
+ if ( epub_document->archivename) {
+ g_free (epub_document->archivename);
+ }
G_OBJECT_CLASS (epub_document_parent_class)->finalize (object);
}