[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Cache the download name
Mike Massonnet
noreply at xfce.org
Fri Feb 12 21:24:01 CET 2010
Updating branch refs/heads/aria2-xml-rpc
to 58b19415898d4c76c2bce4b44d9749e6a09cb429 (commit)
from 54b27a5353ef5e3b3fc560aac6a272f65d687cfa (commit)
commit 58b19415898d4c76c2bce4b44d9749e6a09cb429
Author: Mike Massonnet <mmassonnet at xfce.org>
Date: Fri Feb 12 21:18:38 2010 +0100
Cache the download name
There is a new column in the tree store "download-name-found" that can
be set to true or false. It is used to jump over repetitive requests.
Small bug fix: when applying new settings to the local server, a dialog
asks before restarting it when there are active downloads, if it isn't
restarted directly the GUI is reset sensitive.
src/eatmanager.rb | 39 +++++++++++++++++++++++----------------
src/manager.ui | 4 +++-
2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/src/eatmanager.rb b/src/eatmanager.rb
index 39d11b1..2085632 100644
--- a/src/eatmanager.rb
+++ b/src/eatmanager.rb
@@ -174,10 +174,10 @@ class Eat::Manager
row_iter = @liststore.append
row_iter[0] = gid_i
uris = @aria2.get_uris(gid)
- p uris
+ p "uris:", uris
begin
# TODO Torrent downloads don't have a URI
- row_iter[10] = uris[0]["uri"]
+ row_iter[11] = uris[0]["uri"]
rescue
end
end
@@ -198,12 +198,12 @@ class Eat::Manager
percent = total > 0 ? 100 * completed / total : 0
row_iter[8] = percent
- row_iter[9] = get_download_name(status)
+ set_download_name_for_iter(row_iter, status)
when "complete" then
row_iter[8] = 100
# Update the name, useful for very small files for which
# this callback didn't run with the "active" state.
- row_iter[9] = get_download_name(status)
+ set_download_name_for_iter(row_iter, status)
when "removed" then
# TODO mark as stopped/inactive
when "error" then
@@ -273,6 +273,9 @@ class Eat::Manager
debug("restart local server")
@aria2.shutdown
@aria2.connect(true)
+ else
+ # If the server is not restarted directly then reset the control buttons sensitive
+ set_sensitive(true)
end
else
debug("switch to local server")
@@ -286,8 +289,14 @@ class Eat::Manager
private
+ def set_download_name_for_iter(iter, status)
+ return if iter[10] == true
+ name = get_download_name(status)
+ iter[9] = name
+ iter[10] = true
+ end
+
def get_download_name(status)
- # TODO cache the return name
return nil if status == nil
# Use the bittorrent array
@@ -296,15 +305,13 @@ class Eat::Manager
# Use the files array
elsif status['files'] != nil and !status['files'][0]['path'].empty?
return File.basename(status['files'][0]['path'])
+ else
+ # Fallback on the aria2.getFile XML-RPC method for older versions of aria2
+ result = @aria2.get_files(status['gid'])
+ if result != nil and !result[0]["path"].empty?
+ return File.basename(result[0]["path"])
+ end
end
-
- # Fallback on the aria2.getFile XML-RPC method for older version of aria2
- result = @aria2.get_files(status['gid'])
- if result != nil and !result[0]["path"].empty?
- return File.basename(result[0]["path"])
- end
-
- return 'n/a'
end
def update_newdl_dialog()
@@ -354,7 +361,7 @@ class Eat::Manager
row_iter = @liststore.append
row_iter[0] = gid.to_i
row_iter[9] = File.basename(uri)
- row_iter[10] = uri
+ row_iter[11] = uri
end
end
end
@@ -376,7 +383,7 @@ class Eat::Manager
when "removed"
# Restart the download queued at position 0 and delete current row
# as new gid will be created
- uri = iter[10]
+ uri = iter[11]
if !uri.empty?
percent = iter[8]
@liststore.remove(iter)
@@ -389,7 +396,7 @@ class Eat::Manager
iter[0] = gid.to_i
iter[8] = percent
iter[9] = File.basename(uri)
- iter[10] = uri
+ iter[11] = uri
end
end
end
diff --git a/src/manager.ui b/src/manager.ui
index a98d9ef..a0f5e5f 100644
--- a/src/manager.ui
+++ b/src/manager.ui
@@ -22,8 +22,10 @@
<column type="gchararray"/>
<!-- column-name file_length -->
<column type="gint"/>
- <!-- column-name file_path -->
+ <!-- column-name download_name -->
<column type="gchararray"/>
+ <!-- column-name download_name_found -->
+ <column type="gboolean"/>
<!-- column-name uri -->
<column type="gchararray"/>
</columns>
More information about the Xfce4-commits
mailing list