[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Make selecting torrent and metalink files work

Mike Massonnet noreply at xfce.org
Sun Feb 28 16:32:01 CET 2010


Updating branch refs/heads/aria2-xml-rpc
         to 517ee4991c800b827527f0c120ef5796ae4e7c06 (commit)
       from 7868c9fe8bdf4ba6396a8aba9d64edcf85c396b2 (commit)

commit 517ee4991c800b827527f0c120ef5796ae4e7c06
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Sun Feb 28 12:00:29 2010 +0100

    Make selecting torrent and metalink files work
    
    Adding from files finally works too. However the assumption that one
    could add .aria2 files was wrong.

 src/eataria2.rb   |    4 ++--
 src/eatmanager.rb |   35 ++++++++++++++++++++++++++++-------
 src/manager.ui    |    2 +-
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/src/eataria2.rb b/src/eataria2.rb
index 4074ac9..0fa1012 100755
--- a/src/eataria2.rb
+++ b/src/eataria2.rb
@@ -327,7 +327,7 @@ class Eat::Aria2 < GLib::Object
 
 	# Adds BitTorrent download by uploading .torrent file.
 	def add_torrent(torrent, uris = [], options = [], position = nil)
-		data = read(torrent)
+		data = File.read(torrent)
 		if position != nil
 			gid = call("aria2.addTorrent", XMLRPC::Base64.new(data), uris, options, position)
 		else
@@ -339,7 +339,7 @@ class Eat::Aria2 < GLib::Object
 
 	# Adds Metalink download by uploading .metalink file.
 	def add_metalink(metalink, options = [], position = nil)
-		data = read(metalink)
+		data = File.read(metalink)
 		if position != nil
 			gid = call("aria2.addMetalink", XMLRPC::Base64.new(data), options, position)
 		else
diff --git a/src/eatmanager.rb b/src/eatmanager.rb
index cf0f399..7b2139e 100755
--- a/src/eatmanager.rb
+++ b/src/eatmanager.rb
@@ -137,10 +137,9 @@ class Eat::Manager
 
 		# Setup new download dialog
 		file_filter = builder["filefilter-new-download"]
-		file_filter.name = "Torrents, Metalinks, aria2"
+		file_filter.name = "Torrents, Metalinks"
 		file_filter.add_pattern("*.torrent")
 		file_filter.add_pattern("*.metalink")
-		file_filter.add_pattern("*.aria2")
 		@file_select_file_dialog.filter = file_filter
 		@file_select_file.signal_connect('clicked') do
 			@file_select_file_dialog.unselect_all
@@ -224,6 +223,7 @@ class Eat::Manager
 		when "removed" then
 			# TODO mark as stopped/inactive
 		when "error" then
+			# TODO display an error message
 			row_iter[8] = -1
 		end
 	end
@@ -305,16 +305,21 @@ class Eat::Manager
 	end
 
 	def add_new_download(uri=nil)
+		# Update dialog
 		update_newdl_dialog
 		@file_uri.text = uri == nil ? "" : uri
 		@file_uri.grab_focus
+
+		# Run dialog
 		res = @newdl_dialog.run
 		@newdl_dialog.hide
+
+		# Read URI
 		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
+			# Prepare options
+			puts "download uri: %s" % uri
 			options = {
 				"max-download-limit" => @file_max_download_speed.value_as_int.to_s,
 				"split" => @file_split.value_as_int.to_s,
@@ -322,14 +327,30 @@ class Eat::Manager
 				"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)
+
+			# Add download to aria2
+			gid = nil
+			if File.readable? uri
+				if uri.end_with? "torrent"
+					gid = @aria2.add_torrent(uri, options)
+				elsif uri.end_with? "metalink"
+					gid = @aria2.add_metalink(uri, options)
+				end
+			else
+				gid = @aria2.add_uri(uri, options)
+			end
+			puts "gid: %s" % gid
+
+			# Update GUI
 			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
+			else
+				# Display an error message
+				# TODO
 			end
 		end
 	end
diff --git a/src/manager.ui b/src/manager.ui
index ed952d0..23a821e 100644
--- a/src/manager.ui
+++ b/src/manager.ui
@@ -1028,7 +1028,7 @@
   </object>
   <object class="GtkFileChooserDialog" id="filechooserdialog-new-download">
     <property name="border_width">5</property>
-    <property name="title" translatable="yes">Select a file - Torrents, Metalinks, or aria2 files</property>
+    <property name="title" translatable="yes">Select a file - Torrent or Metalink</property>
     <property name="window_position">center-on-parent</property>
     <property name="destroy_with_parent">True</property>
     <property name="icon_name">document-open</property>



More information about the Xfce4-commits mailing list