[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Add comments and switch Gtk.TreeIter#get/set_value against Gtk.TreeIter#[]
Mike Massonnet
noreply at xfce.org
Thu Feb 11 22:58:02 CET 2010
Updating branch refs/heads/aria2-xml-rpc
to fd103e266cf3e8b0f8aba5dd5fd0594a8bbd6cf5 (commit)
from 32127e76efd4aa52c4fd4969a5f33e205197176a (commit)
commit fd103e266cf3e8b0f8aba5dd5fd0594a8bbd6cf5
Author: Mike Massonnet <mmassonnet at xfce.org>
Date: Wed Feb 10 01:25:57 2010 +0100
Add comments and switch Gtk.TreeIter#get/set_value against Gtk.TreeIter#[]
src/eataria2.rb | 8 ++++++++
src/eatmanager.rb | 42 +++++++++++++++++++++++++-----------------
2 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/src/eataria2.rb b/src/eataria2.rb
index 468978f..e07b88a 100644
--- a/src/eataria2.rb
+++ b/src/eataria2.rb
@@ -164,6 +164,10 @@ class Eat::Aria2 < GLib::Object
end
end
+=begin
+ spawn_server:
+ Execute an aria2c process in background and wait for a positive response.
+=end
def spawn_server(command)
pid = Process.spawn(command, :pgroup=>true, :chdir=>ENV['HOME'],
STDOUT=>"/dev/null", STDIN=>"/dev/null")
@@ -183,6 +187,10 @@ class Eat::Aria2 < GLib::Object
pid
end
+=begin
+ call:
+ Make an XML-RPC call to the server. Try to connect if the connection is broken.
+=end
def call(method, *args)
begin
result = @@client.call(method, *args)
diff --git a/src/eatmanager.rb b/src/eatmanager.rb
index fea43f2..fecb8d4 100644
--- a/src/eatmanager.rb
+++ b/src/eatmanager.rb
@@ -119,6 +119,7 @@ class Eat::Manager
end
def set_sensitive(sensitive)
+ # Set/Unset sensitivity of widgets that need aria2
@treeview.set_sensitive(sensitive)
@action_add.set_sensitive(sensitive)
@action_pause.set_sensitive(sensitive)
@@ -134,59 +135,62 @@ class Eat::Manager
result = @aria2.tell_status(gid)
return if result.empty?
+ # Find gid in model
@liststore.each do |model, path, iter|
- next unless iter.get_value(0) == gid_i
+ next unless iter[0] == gid_i
row_iter = iter
break
end
+ # Add inexistent gid
if !row_iter
# Avoid adding rows with incomplete information
return if result["totalLength"] == "0" or result["status"] != "active"
# Add unknown active download to liststore
row_iter = @liststore.append
- @liststore.set_value(row_iter, 0, gid_i)
+ row_iter[0] = gid_i
uris = @aria2.get_uris(gid)
p uris
begin
# TODO Torrent downloads don't have a URI
- @liststore.set_value(row_iter, 10, uris[0]["uri"])
+ row_iter[10] = uris[0]["uri"]
rescue
end
end
+ # Update status of gid in the model
case result["status"]
when "active" then
- @liststore.set_value(row_iter, 1, result["connections"].to_i)
- @liststore.set_value(row_iter, 2, result["completedLength"].to_i)
- @liststore.set_value(row_iter, 3, result["uploadLength"].to_i)
- @liststore.set_value(row_iter, 4, result["totalLength"].to_i)
- @liststore.set_value(row_iter, 5, result["downloadSpeed"].to_i)
- @liststore.set_value(row_iter, 6, result["uploadSpeed"].to_i)
- @liststore.set_value(row_iter, 7, result["infoHash"])
+ 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
percent = total > 0 ? 100 * completed / total : 0
- @liststore.set_value(row_iter, 8, percent)
+ row_iter[8] = percent
result = @aria2.get_files(gid.to_s)
if result != nil and !result[0]["path"].empty?
- @liststore.set_value(row_iter, 9, File.basename(result[0]["path"]))
+ row_iter[9] = File.basename(result[0]["path"])
end
when "complete" then
- @liststore.set_value(row_iter, 8, 100)
+ 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?
- @liststore.set_value(row_iter, 9, File.basename(result[0]["path"]))
+ row_iter[9] = File.basename(result[0]["path"])
end
when "removed" then
# TODO mark as stopped/inactive
when "error" then
- @liststore.set_value(row_iter, 8, -1)
+ row_iter[8] = -1
end
end
@@ -295,13 +299,15 @@ class Eat::Manager
end
def action_pause()
+ # Remove gid from aria2 but keep them in model
@treeview.selection.selected_each do |model, path, iter|
- gid = iter.get_value(0)
+ gid = iter[0]
@aria2.remove(gid.to_s)
end
end
def action_resume()
+ # Resume gid that have been removed
@treeview.selection.selected_each do |model, path, iter|
gid = iter[0].to_s
status = @aria2.tell_status(gid)
@@ -331,7 +337,9 @@ class Eat::Manager
def action_remove()
@treeview.selection.selected_each do |model, path, iter|
- gid = iter.get_value(0)
+ # TODO aria2 may respond to the remove request after the callback
+ # and thus re-add a new iter
+ gid = iter[0]
@aria2.remove(gid.to_s)
@liststore.remove(iter)
end
More information about the Xfce4-commits
mailing list