Updating branch refs/heads/aria2-xml-rpc
         to 63958684896dac38fc0154265039dca17cf7405a (commit)
       from 58b19415898d4c76c2bce4b44d9749e6a09cb429 (commit)

commit 63958684896dac38fc0154265039dca17cf7405a
Author: Mike Massonnet <[email protected]>
Date:   Sat Feb 13 12:08:49 2010 +0100

    Add DND support on treeview
    
    The code from action_add has been moved into a new method called
    add_new_download. This way the method can be called by different
    meanings and setting directly the URI field.

 src/eatmanager.rb |   80 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/src/eatmanager.rb b/src/eatmanager.rb
index 2085632..077263b 100644
--- a/src/eatmanager.rb
+++ b/src/eatmanager.rb
@@ -108,6 +108,16 @@ class Eat::Manager
                column.pack_start(cell, true)
                column.add_attribute(cell, :text, 9)
 
+               # Setup DND on tree view
+               Drag.dest_set(@treeview, Drag::DEST_DEFAULT_ALL, nil, 
Gdk::DragContext::ACTION_COPY)
+               Drag.dest_add_uri_targets(@treeview)
+               @treeview.signal_connect("drag-data-received") { |this, 
context, x, y, selection_data, info, time|
+                       selection_data.uris.each do |uri|
+                               add_new_download(uri)
+                       end
+                       Drag.finish(context, true, false, time)
+               }
+
                # Setup statusbar
                @statuscontext = { "main" => @statusbar.get_context_id("main 
context"),
                                "menu" => @statusbar.get_context_id("menu 
context") }
@@ -176,7 +186,7 @@ class Eat::Manager
                        uris = @aria2.get_uris(gid)
                        p "uris:", uris
                        begin
-                               # TODO Torrent downloads don't have a URI
+                               # TODO Torrent downloads don't have a URI -- 
try to read from parent
                                row_iter[11] = uris[0]["uri"]
                        rescue
                        end
@@ -287,17 +297,49 @@ class Eat::Manager
                end
        end
 
+       def add_new_download(uri=nil)
+               update_newdl_dialog
+               @file_uri.text = uri == nil ? "" : uri
+               @file_uri.grab_focus
+               res = @newdl_dialog.run
+               @newdl_dialog.hide
+               uri = @file_uri.text
+               if res == Dialog::RESPONSE_OK and !uri.empty?
+                       # TODO check if it is a uri or a torrent/metalink file 
and use the right
+                       # method addUri/addTorrent/addMetalink
+                       puts "download file %s" % uri
+                       options = {
+                               "max-download-limit" => 
@file_max_download_speed.value_as_int.to_s,
+                               "split" => @file_split.value_as_int.to_s,
+                               "max-upload-limit" => 
@file_max_upload_speed.value_as_int.to_s,
+                               "seed-ratio" => @file_seed_ratio.value.to_s,
+                       }
+                       options["dir"] = @file_download_dir.current_folder if 
@aria2.use_local_server?
+                       gid = @aria2.add_uri(uri, options)
+                       if gid != nil
+                               puts "gid: %s" % gid
+                               # Add new row to liststore
+                               row_iter = @liststore.append
+                               row_iter[0] = gid.to_i
+                               row_iter[9] = File.basename(uri)
+                               row_iter[11] = uri
+                       end
+               end
+       end
+
        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
+               if name != nil
+                       iter[9] = name
+                       iter[10] = true
+               end
        end
 
        def get_download_name(status)
-               return nil if status == nil
+               return if status == nil
 
                # Use the bittorrent array
                if status['bittorrent'] != nil
@@ -305,8 +347,8 @@ class Eat::Manager
                # Use the files array
                elsif status['files'] != nil and 
!status['files'][0]['path'].empty?
                        return File.basename(status['files'][0]['path'])
+               # Fallback on the aria2.getFile XML-RPC method for older 
versions of aria2
                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"])
@@ -337,33 +379,7 @@ class Eat::Manager
        end
 
        def action_add()
-               update_newdl_dialog
-               @file_uri.text = ""
-               @file_uri.grab_focus
-               res = @newdl_dialog.run
-               @newdl_dialog.hide
-               uri = @file_uri.text
-               if res == Dialog::RESPONSE_OK and !uri.empty?
-                       # TODO check if it is a uri or a torrent/metalink file 
and use the right
-                       # method addUri/addTorrent/addMetalink
-                       puts "download file %s" % uri
-                       options = {
-                               "max-download-limit" => 
@file_max_download_speed.value_as_int.to_s,
-                               "split" => @file_split.value_as_int.to_s,
-                               "max-upload-limit" => 
@file_max_upload_speed.value_as_int.to_s,
-                               "seed-ratio" => @file_seed_ratio.value.to_s,
-                       }
-                       options["dir"] = @file_download_dir.current_folder if 
@aria2.use_local_server?
-                       gid = @aria2.add_uri(uri, options)
-                       if gid != nil
-                               puts "gid: %s" % gid
-                               # Add new row to liststore
-                               row_iter = @liststore.append
-                               row_iter[0] = gid.to_i
-                               row_iter[9] = File.basename(uri)
-                               row_iter[11] = uri
-                       end
-               end
+               add_new_download
        end
 
        def action_pause()
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to