[gnome-boxes] downloader: Add fetch_media()



commit 468cb951d16f2c163d178a954d110977e8674055
Author: Lasse Schuirmann <lasse schuirmann gmail com>
Date:   Thu Jun 26 15:15:28 2014 +0200

    downloader: Add fetch_media()
    
    This allows easy downloading of media to the users Download folder. If
    the user already downloaded the media (via Boxes or externally) and left
    it with the same name as the initial one in the Download folder it will
    be taken from there.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=729026

 src/downloader.vala |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/src/downloader.vala b/src/downloader.vala
index 3953228..614f6f9 100644
--- a/src/downloader.vala
+++ b/src/downloader.vala
@@ -195,6 +195,25 @@ private class Boxes.Downloader : GLib.Object {
         }
     }
 
+    public static async string fetch_media (string           uri,
+                                            ActivityProgress progress = new ActivityProgress (),
+                                            Cancellable?     cancellable = null) throws GLib.Error {
+        var file = File.new_for_uri (uri);
+        var basename = file.get_basename ();
+        return_val_if_fail (basename != null && basename != "" && basename != "/", null);
+
+        var downloader = Downloader.get_instance ();
+        var cache = Path.build_filename (GLib.Environment.get_user_special_dir (GLib.UserDirectory.DOWNLOAD),
+                                         basename);
+
+        progress.progress = 0;
+        debug ("Downloading media from '%s' to '%s'.", uri, cache);
+        yield downloader.download (file, {cache}, progress, cancellable);
+        progress.progress = 1;
+
+        return cache;
+    }
+
     private async File? await_download (Download         download,
                                         string           cached_path,
                                         ActivityProgress progress) throws GLib.Error {


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