Updating branch refs/heads/aria2-xml-rpc
         to 54b27a5353ef5e3b3fc560aac6a272f65d687cfa (commit)
       from f8f788e3126e87724b539eb59d57c4ba8005f059 (commit)

commit 54b27a5353ef5e3b3fc560aac6a272f65d687cfa
Author: Mike Massonnet <[email protected]>
Date:   Fri Feb 12 18:22:36 2010 +0100

    New method to return a readable name for the download
    
    The download name is returned by going through the bittorrent array
    otherwise the files array from the tellStatus result. It fallback on
    aria2.getFiles for older versions of aria2.

 src/eatmanager.rb |   59 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/src/eatmanager.rb b/src/eatmanager.rb
index 87e6fa1..39d11b1 100644
--- a/src/eatmanager.rb
+++ b/src/eatmanager.rb
@@ -155,8 +155,8 @@ class Eat::Manager
                row_iter = nil
                gid_i = gid.to_i
 
-               result = @aria2.tell_status(gid)
-               return if result.empty?
+               status = @aria2.tell_status(gid)
+               return if status.empty?
 
                # Find gid in model
                @liststore.each do |model, path, iter|
@@ -168,7 +168,7 @@ class Eat::Manager
                # Add inexistent gid
                if !row_iter
                        # Avoid adding rows with incomplete information
-                       return if result["totalLength"] == "0" or 
result["status"] != "active"
+                       return if status["totalLength"] == "0" or 
status["status"] != "active"
 
                        # Add unknown active download to liststore
                        row_iter = @liststore.append
@@ -183,33 +183,27 @@ class Eat::Manager
                end
 
                # Update status of gid in the model
-               case result["status"]
+               case status["status"]
                when "active" then
-                       row_iter[1] = result["connections"].to_i
-                       row_iter[2] = result["completedLength"].to_i
-                       row_iter[3] = result["uploadLength"].to_i
-                       row_iter[4] = result["totalLength"].to_i
-                       row_iter[5] = result["downloadSpeed"].to_i
-                       row_iter[6] = result["uploadSpeed"].to_i
-                       row_iter[7] = result["infoHash"]
-
-                       completed = result["completedLength"].to_i
-                       total = result["totalLength"].to_i
+                       row_iter[1] = status["connections"].to_i
+                       row_iter[2] = status["completedLength"].to_i
+                       row_iter[3] = status["uploadLength"].to_i
+                       row_iter[4] = status["totalLength"].to_i
+                       row_iter[5] = status["downloadSpeed"].to_i
+                       row_iter[6] = status["uploadSpeed"].to_i
+                       row_iter[7] = status["infoHash"]
+
+                       completed = status["completedLength"].to_i
+                       total = status["totalLength"].to_i
                        percent = total > 0 ? 100 * completed / total : 0
                        row_iter[8] = percent
 
-                       result = @aria2.get_files(gid.to_s)
-                       if result != nil and !result[0]["path"].empty?
-                               row_iter[9] = File.basename(result[0]["path"])
-                       end
+                       row_iter[9] = get_download_name(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.
-                       result = @aria2.get_files(gid.to_s)
-                       if result != nil and !result[0]["path"].empty?
-                               row_iter[9] = File.basename(result[0]["path"])
-                       end
+                       row_iter[9] = get_download_name(status)
                when "removed" then
                        # TODO mark as stopped/inactive
                when "error" then
@@ -292,6 +286,27 @@ class Eat::Manager
 
        private
 
+       def get_download_name(status)
+               # TODO cache the return name
+               return nil if status == nil
+
+               # Use the bittorrent array
+               if status['bittorrent'] != nil
+                       return status['bittorrent']['info']['name']
+               # Use the files array
+               elsif status['files'] != nil and 
!status['files'][0]['path'].empty?
+                       return File.basename(status['files'][0]['path'])
+               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()
                settings = Eat::Settings.instance
                @file_max_download_speed.value = 
settings.aria2["max-download-limit"].to_i
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to