summaryrefslogtreecommitdiff
path: root/wikipedia
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2013-08-08 11:29:25 -0700
committerPhilip Chimento <philip@endlessm.com>2013-08-08 11:29:25 -0700
commit7123670cff775b331e726e93118ccde066af89b5 (patch)
tree40407d03fc425b8fce90d8bcc257534cc2e4ad74 /wikipedia
parent0a7043965f27677551ad11511f55110d61147289 (diff)
Custom image:// URI on WikipediaView
WikipediaView will now interpret all image:// URIs as files in the Wikipedia images directory (whose root is set with the 'application-base-path' property on the WikipediaApplication.) [endlessm/eos-sdk#253]
Diffstat (limited to 'wikipedia')
-rw-r--r--wikipedia/views/wikipedia_view.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/wikipedia/views/wikipedia_view.js b/wikipedia/views/wikipedia_view.js
index 261e879..da4f942 100644
--- a/wikipedia/views/wikipedia_view.js
+++ b/wikipedia/views/wikipedia_view.js
@@ -1,3 +1,4 @@
+const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Soup = imports.gi.Soup;
@@ -6,6 +7,16 @@ const Utils = imports.utils;
const getPageURL = "http://127.0.0.1:3000/getArticleByTitle?title=";
+// Interpret image:// URIs as wikipedia images
+WebKit.WebContext.get_default().register_uri_scheme('image', function(request) {
+ let filename = request.get_uri().slice('image://'.length);
+ let pictures_dir = request.get_web_view()._getArticleImagesPath();
+ let parent = Gio.File.new_for_path(pictures_dir);
+ let file = parent.get_child(filename);
+ let stream = file.read(null);
+ request.finish(stream, -1, 'image/png');
+});
+
const WikipediaView = new Lang.Class({
Name: 'EndlessWikipediaView',
Extends: WebKit.WebView,
@@ -78,8 +89,7 @@ const WikipediaView = new Lang.Class({
let title = article['title'];
let current_dir = Endless.getCurrentFileDir();
- let cur_exec = this.get_toplevel().get_application().application_base_path;
- let image_path = cur_exec + "/web_view/article_images/";
+ let image_path = this._getArticleImagesPath();
let documentHTML = this._get_meta_html() + this._get_body_html(articleHTML, human_title, image_path);
@@ -94,5 +104,10 @@ const WikipediaView = new Lang.Class({
// Right now, this doesn't work, regardless of what we put in for base_uri
this.load_uri(temp_uri);
}));
+ },
+
+ _getArticleImagesPath: function() {
+ let cur_exec = this.get_toplevel().get_application().application_base_path;
+ return cur_exec + "/web_view/article_images/";
}
});