Added support for disconnect.

This commit is contained in:
Glenn Y. Rolland 2011-07-28 16:07:13 +02:00
parent b143509fce
commit 033a1be046
2 changed files with 50 additions and 34 deletions

View file

@ -92,16 +92,17 @@ module Qasim
# #
def action_trigger_map_item map, item def action_trigger_map_item map, item
puts "%s => %s" % [map.path, item.checked ] puts "%s => %s" % [map.path, item.checked ]
if map.connected? then
puts "disconnect !"
else
puts "connect !"
begin
success = true
@connect_error[map.path] = Set.new @connect_error[map.path] = Set.new
@connect_running[map.path] = 0 @connect_running[map.path] = 0
map.connect do |linkname,cmd,cmd_args| if map.connected? then
puts "disconnect !"
method = :disconnect
else
puts "connect !"
method = :connect
end
begin
map.send(method) do |linkname,cmd,cmd_args|
process = Qt::Process.new process = Qt::Process.new
process.connect(SIGNAL('finished(int, QProcess::ExitStatus)')) do |exitcode,exitstatus| process.connect(SIGNAL('finished(int, QProcess::ExitStatus)')) do |exitcode,exitstatus|
puts "exitcode = %s, exitstatus = %s" % [exitcode, exitstatus] puts "exitcode = %s, exitstatus = %s" % [exitcode, exitstatus]
@ -112,16 +113,16 @@ module Qasim
end end
if @connect_running[map.path] == 0 then if @connect_running[map.path] == 0 then
# display someting # display someting
if @connect_error[map.path] == 0 then if @connect_error[map.path].empty? then
dbus_notify "%s (%s)" % [APP_NAME, map.name], dbus_notify "%s (%s)" % [APP_NAME, map.name],
"<b>Map connected successfully<b>", ("<b>Map %sed successfully<b>" % method.to_s),
'dialog-information' 'dialog-information'
else else
erroneous = @connect_error[map.path].to_a.join(', ') erroneous = @connect_error[map.path].to_a.join(', ')
dbus_notify "%s (%s)" % [APP_NAME, map.name], dbus_notify "%s (%s)" % [APP_NAME, map.name],
("<b>Unable to connect map</b><br>" + ("<b>Unable to %s map</b><br>" % method.to_s) +
"Broken link(s): %s" % erroneous), ("Broken link(s): %s" % erroneous),
'dialog-error' 'dialog-error'
end end
end end
@ -134,8 +135,6 @@ module Qasim
puts e.inspect puts e.inspect
end end
#FIXME: on error, setChecked false #FIXME: on error, setChecked false
end
end end
# #

View file

@ -174,7 +174,24 @@ module Qasim
def disconnect &block def disconnect &block
puts "Disconnecting map #{@path}" puts "Disconnecting map #{@path}"
# umount @links.each do |name, remotepath|
pp map
localpath = File.join ENV['HOME'], "mnt", name
cmd = "fusermount"
cmd_args = [
"-u", #umount
"-z" ,#lazy
localpath ]
rdebug "command: %s" % [ cmd, cmd_args ].flatten.join(' ')
if block_given? then
yield name, cmd, cmd_args
else
system cmd, cmd_args
if $?.exitstatus != 0 then
raise ConnectError, self
end
end
end
end end
end end
end end