[gnome-documents] epub: add support for saving pages



commit 73fe9f6f67478b1305013360fe0cb57a73b4b2b7
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Jun 26 10:17:43 2016 +0800

    epub: add support for saving pages
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768047

 src/epubview.js |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/src/epubview.js b/src/epubview.js
index 99f3227..2a637a7 100644
--- a/src/epubview.js
+++ b/src/epubview.js
@@ -19,6 +19,7 @@
  *
  */
 
+const GdPrivate = imports.gi.GdPrivate;
 const Gepub = imports.gi.Gepub;
 const Gio = imports.gi.Gio;
 const WebKit2 = imports.gi.WebKit2;
@@ -70,10 +71,35 @@ const EPUBView = new Lang.Class({
         let f = Gio.File.new_for_uri(doc.uri);
         this._epubdoc = new Gepub.Doc({ path: f.get_path() });
         this._epubdoc.init(null);
+
         this.view.doc = this._epubdoc;
+        this._epubdoc.connect('notify::page', Lang.bind(this, this._onPageChanged));
+
+        this._metadata = this._loadMetadata();
+
         this.set_visible_child_name('view');
     },
 
+    _loadMetadata: function() {
+        let file = Gio.File.new_for_path(this._epubdoc.path);
+        if (!GdPrivate.is_metadata_supported_for_file(file))
+            return null;
+
+        let metadata = new GdPrivate.Metadata({ file: file });
+
+        let [res, val] = metadata.get_int('page');
+        if (res)
+            this._epubdoc.page = val;
+
+        return metadata;
+    },
+
+    _onPageChanged: function() {
+        let pageNumber = this._epubdoc.page;
+        if (this._metadata)
+            this._metadata.set_int('page', pageNumber);
+    },
+
     goPrev: function() {
         this._epubdoc.go_prev();
     },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]