Added support for disconnect.

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

View file

@ -92,50 +92,49 @@ 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 ]
@connect_error[map.path] = Set.new
@connect_running[map.path] = 0
if map.connected? then if map.connected? then
puts "disconnect !" puts "disconnect !"
method = :disconnect
else else
puts "connect !" puts "connect !"
begin method = :connect
success = true end
begin
map.send(method) do |linkname,cmd,cmd_args|
process = Qt::Process.new
process.connect(SIGNAL('finished(int, QProcess::ExitStatus)')) do |exitcode,exitstatus|
puts "exitcode = %s, exitstatus = %s" % [exitcode, exitstatus]
@connect_running[map.path] -= 1
if exitcode != 0 then
@connect_error[map.path].add linkname
else
end
if @connect_running[map.path] == 0 then
# display someting
if @connect_error[map.path].empty? then
@connect_error[map.path] = Set.new dbus_notify "%s (%s)" % [APP_NAME, map.name],
@connect_running[map.path] = 0 ("<b>Map %sed successfully<b>" % method.to_s),
map.connect do |linkname,cmd,cmd_args| 'dialog-information'
process = Qt::Process.new
process.connect(SIGNAL('finished(int, QProcess::ExitStatus)')) do |exitcode,exitstatus|
puts "exitcode = %s, exitstatus = %s" % [exitcode, exitstatus]
@connect_running[map.path] -= 1
if exitcode != 0 then
@connect_error[map.path].add linkname
else else
end erroneous = @connect_error[map.path].to_a.join(', ')
if @connect_running[map.path] == 0 then dbus_notify "%s (%s)" % [APP_NAME, map.name],
# display someting ("<b>Unable to %s map</b><br>" % method.to_s) +
if @connect_error[map.path] == 0 then ("Broken link(s): %s" % erroneous),
'dialog-error'
dbus_notify "%s (%s)" % [APP_NAME, map.name],
"<b>Map connected successfully<b>",
'dialog-information'
else
erroneous = @connect_error[map.path].to_a.join(', ')
dbus_notify "%s (%s)" % [APP_NAME, map.name],
("<b>Unable to connect map</b><br>" +
"Broken link(s): %s" % erroneous),
'dialog-error'
end
end end
end end
@connect_running[map.path] += 1
process.start cmd, cmd_args
end end
@connect_running[map.path] += 1
rescue Map::ConnectError => e process.start cmd, cmd_args
puts e.inspect
end end
#FIXME: on error, setChecked false
rescue Map::ConnectError => e
puts e.inspect
end end
#FIXME: on error, setChecked false
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