[gnome-maps] utils: Use Libsoup directly for HTTP(s) downloads
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] utils: Use Libsoup directly for HTTP(s) downloads
- Date: Tue, 3 Sep 2013 16:36:20 +0000 (UTC)
commit 6fed9eacd2a8cd33957ae6948f6ecd0adb28c9e7
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Sep 3 19:15:56 2013 +0300
utils: Use Libsoup directly for HTTP(s) downloads
This currently applies to place icons from Nominatim.
src/utils.js | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index 6a8082c..c43e31a 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -31,6 +31,7 @@ const Geocode = imports.gi.GeocodeGlib;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Clutter = imports.gi.Clutter;
const Cogl = imports.gi.Cogl;
+const Soup = imports.gi.Soup;
const _ = imports.gettext.gettext;
@@ -149,6 +150,11 @@ function _load_file_icon(icon, loadCompleteCallback) {
return;
}
+ if (icon.file.has_uri_scheme ("http") || icon.file.has_uri_scheme ("https")) {
+ _load_http_icon(icon, loadCompleteCallback);
+ return;
+ }
+
icon.load_async(-1, null, function(icon, res) {
try {
let stream = icon.load_finish(res, null)[0];
@@ -164,6 +170,40 @@ function _load_file_icon(icon, loadCompleteCallback) {
});
}
+function _load_http_icon(icon, loadCompleteCallback) {
+ let msg = Soup.form_request_new_from_hash('GET', icon.file.get_uri(), {});
+ let soup_session = _get_soup_session();
+
+ soup_session.queue_message(msg, function(session, msg) {
+ if (msg.status_code != Soup.KnownStatusCode.OK) {
+ log("Failed to load pixbuf: " + msg.reason_phrase);
+ return;
+ }
+
+ let contents = msg.response_body.flatten().get_as_bytes();
+ let stream = Gio.MemoryInputStream.new_from_data
+ (contents.get_data (null));
+ try {
+ let pixbuf = GdkPixbuf.Pixbuf.new_from_stream(stream, null);
+
+ _iconStore[icon.file.get_uri()] = pixbuf;
+ loadCompleteCallback(pixbuf);
+ } catch(e) {
+ log("Failed to load pixbuf: " + e);
+ }
+ });
+}
+
+let soup_session = null;
+function _get_soup_session() {
+ if (soup_session === null) {
+ log ("creating soup");
+ soup_session = new Soup.Session ();
+ }
+
+ return soup_session;
+}
+
function _load_themed_icon(icon, size, loadCompleteCallback) {
let theme = Gtk.IconTheme.get_default();
let flags = Gtk.IconLookupFlags.GENERIC_FALLBACK;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]