[ease] Async downloading of media, with progress dialog.
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease] Async downloading of media, with progress dialog.
- Date: Mon, 23 Aug 2010 04:04:05 +0000 (UTC)
commit bf4a2ed417635ab4a086d789e8b5a2010161473e
Author: Nate Stedman <natesm gmail com>
Date: Mon Aug 23 00:03:45 2010 -0400
Async downloading of media, with progress dialog.
ease/ease-import-dialog.vala | 55 ++++++++++++++++++++++++++++++-----------
ease/ease-import-widget.vala | 6 +++-
2 files changed, 44 insertions(+), 17 deletions(-)
---
diff --git a/ease/ease-import-dialog.vala b/ease/ease-import-dialog.vala
index 5d8683d..b7d5400 100644
--- a/ease/ease-import-dialog.vala
+++ b/ease/ease-import-dialog.vala
@@ -53,21 +53,11 @@ internal class Ease.ImportDialog : Gtk.Window
var item = new Source.SpinnerItem.from_stock_icon(title, stock_id,
widget);
- widget.add_media.connect((media) => {
- var temp = Temp.request();
-
- var file = File.new_for_uri(media.file_link);
- var copy = File.new_for_path(Path.build_filename(temp, "media"));
- try
- {
- file.copy(copy, FileCopyFlags.OVERWRITE, null, null);
- add_image(copy.get_path());
- }
- catch (Error e)
- {
- critical("Couldn't read file: %s", e.message);
- return;
- }
+ widget.add_media.connect((media_list) => {
+ var progress = new Dialog.Progress(_("Downloading Media Files"),
+ false, media_list.size, this);
+ progress.show();
+ add_media_recursive(progress, media_list, Temp.request(), 0);
});
service.started.connect(() => item.start());
@@ -76,4 +66,39 @@ internal class Ease.ImportDialog : Gtk.Window
return item;
}
+
+ private void add_media_recursive(Dialog.Progress progress,
+ Gee.Queue<Plugin.ImportMedia> media_list,
+ string temp, int i)
+ {
+ if (media_list.size == 0)
+ {
+ progress.destroy();
+ return;
+ }
+
+ var file = File.new_for_uri(media_list.poll().file_link);
+ var copy = File.new_for_path(Path.build_filename(temp,
+ "media" +
+ (i++).to_string()));
+ try
+ {
+ double previous = 0;
+ file.copy_async(copy, FileCopyFlags.OVERWRITE,
+ Priority.DEFAULT, null,
+ (current, total) => {
+ progress.add(((double)current - previous) / (double)total);
+ previous += current - previous;
+ },
+ (sender, result) => {
+ add_image(copy.get_path());
+ add_media_recursive(progress, media_list, temp, i);
+ });
+ }
+ catch (Error e)
+ {
+ critical("Couldn't read file: %s", e.message);
+ return;
+ }
+ }
}
diff --git a/ease/ease-import-widget.vala b/ease/ease-import-widget.vala
index 9ea3785..1bfa355 100644
--- a/ease/ease-import-widget.vala
+++ b/ease/ease-import-widget.vala
@@ -56,7 +56,7 @@ internal class Ease.ImportWidget : Gtk.Alignment
/**
* Triggers a media add.
*/
- internal signal void add_media(Plugin.ImportMedia media);
+ internal signal void add_media(Gee.Queue<Plugin.ImportMedia> media_list);
/**
* Size of the spinner
@@ -102,12 +102,14 @@ internal class Ease.ImportWidget : Gtk.Alignment
var model = icons.model;
Gtk.TreeIter iter = Gtk.TreeIter();
Plugin.ImportMedia media = null;
+ var list = new Gee.LinkedList<Plugin.ImportMedia>();
icons.selected_foreach((view, path) => {
model.get_iter(out iter, path);
model.get(iter, Plugin.ImportService.Column.IMPORT_MEDIA,
out media);
- add_media(media);
+ list.add(media);
});
+ add_media(list);
});
insert.expose_event.connect(set_bg);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]