From e6be2a649baa6aa010cc7f779cb7c760a1d38828 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Thu, 28 Jul 2011 16:07:13 +0200 Subject: [PATCH] Added support for disconnect. --- bin/qasim-gui.rb | 65 ++++++++++++++++++++++++------------------------ qasim/map.rb | 19 +++++++++++++- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index f373f19..02b85dd 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -92,50 +92,49 @@ module Qasim # def action_trigger_map_item map, item puts "%s => %s" % [map.path, item.checked ] + @connect_error[map.path] = Set.new + @connect_running[map.path] = 0 if map.connected? then puts "disconnect !" - else + method = :disconnect + else puts "connect !" - begin - success = true + method = :connect + 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 - @connect_running[map.path] = 0 - map.connect 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 + dbus_notify "%s (%s)" % [APP_NAME, map.name], + ("Map %sed successfully" % method.to_s), + 'dialog-information' else - end - if @connect_running[map.path] == 0 then - # display someting - if @connect_error[map.path] == 0 then - - dbus_notify "%s (%s)" % [APP_NAME, map.name], - "Map connected successfully", - 'dialog-information' - else - erroneous = @connect_error[map.path].to_a.join(', ') - dbus_notify "%s (%s)" % [APP_NAME, map.name], - ("Unable to connect map
" + - "Broken link(s): %s" % erroneous), - 'dialog-error' - end + erroneous = @connect_error[map.path].to_a.join(', ') + dbus_notify "%s (%s)" % [APP_NAME, map.name], + ("Unable to %s map
" % method.to_s) + + ("Broken link(s): %s" % erroneous), + 'dialog-error' end end - @connect_running[map.path] += 1 - process.start cmd, cmd_args end - - rescue Map::ConnectError => e - puts e.inspect + @connect_running[map.path] += 1 + process.start cmd, cmd_args end - #FIXME: on error, setChecked false + rescue Map::ConnectError => e + puts e.inspect end + #FIXME: on error, setChecked false end # diff --git a/qasim/map.rb b/qasim/map.rb index 620cf8f..430662a 100644 --- a/qasim/map.rb +++ b/qasim/map.rb @@ -174,7 +174,24 @@ module Qasim def disconnect &block 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