sshfs-mapper qasim: check mounted maps in menu.

git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1711 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
Glenn Y. Rolland 2011-07-24 16:49:07 +00:00
parent 9b1eb727d6
commit f455b89ec2
3 changed files with 36 additions and 6 deletions

View file

@ -72,6 +72,9 @@ module Qasim
end end
itemx = Qt::Action.new(map.name, @map_menu) itemx = Qt::Action.new(map.name, @map_menu)
itemx.setCheckable true; itemx.setCheckable true;
if map.connected? then
itemx.setChecked true
end
itemx.connect(SIGNAL(:triggered)) do itemx.connect(SIGNAL(:triggered)) do
action_trigger_map_item map, itemx action_trigger_map_item map, itemx
end end

View file

@ -8,6 +8,7 @@ require 'find'
require 'rubygems' require 'rubygems'
require 'rdebug/base' require 'rdebug/base'
require 'qasim/map'
module Qasim module Qasim
class Config class Config
@ -36,7 +37,7 @@ module Qasim
home_dir + '/.config' home_dir + '/.config'
end end
mnt_dir = File.join home_dir, "mnt" @mnt_dir = File.join home_dir, "mnt"
@config_dir = xdg_dir + '/sshfs-mapper' @config_dir = xdg_dir + '/sshfs-mapper'
@config_file = nil @config_file = nil
@ -56,7 +57,7 @@ module Qasim
if File.file? path if File.file? path
if File.basename( path ) =~ /.map$/ if File.basename( path ) =~ /.map$/
begin begin
map = Map.new path map = Map.new self, path
yield map if block_given? yield map if block_given?
maps.push map maps.push map
rescue rescue

View file

@ -1,6 +1,7 @@
require 'rubygems' require 'rubygems'
require 'rdebug/base' require 'rdebug/base'
require 'qasim/config'
module Qasim module Qasim
@ -20,7 +21,8 @@ module Qasim
CYPHER_AES256CBC = "aes-256-cbc".to_sym CYPHER_AES256CBC = "aes-256-cbc".to_sym
CYPHERS = [ CYPHER_ARCFOUR, CYPHER_AES256CBC ] CYPHERS = [ CYPHER_ARCFOUR, CYPHER_AES256CBC ]
def initialize map_path def initialize config, map_path
@config = config
@path = map_path @path = map_path
@host = nil @host = nil
@port = 22 @port = 22
@ -44,15 +46,18 @@ module Qasim
line = line.strip line = line.strip
linect += 1 linect += 1
while line =~ /\$(.*)/ do while line =~ /\$(\w+)/ do
puts "FOUND PATTERN %s => %s" % [$1, local_env[$1]] puts "FOUND PATTERN %s => %s" % [$1, local_env[$1]]
case line case line
when /\$\{(.+?)\}/ then when /\$\{(.+)\}/ then
pattern = $1 pattern = $1
line.gsub!(/\$\{#{attern}\}/,local_env[pattern]) puts pattern
line.gsub!(/\$\{#{pattern}\}/,local_env[pattern])
when /\$(\w+)/ then when /\$(\w+)/ then
pattern = $1 pattern = $1
line.gsub!(/\$#{pattern}/,local_env[pattern]) line.gsub!(/\$#{pattern}/,local_env[pattern])
else
puts "unknown pattern: %s" % line
end end
end end
@ -100,6 +105,27 @@ module Qasim
def connected? def connected?
#FIXME test if connected / mounted #FIXME test if connected / mounted
f = File.open("/proc/mounts")
sshfs_mounted = (f.readlines.select do |line|
line =~ /\s+fuse.sshfs\s+/
end).map do |line|
line.split(/\s+/)[1]
end
f.close
score = 0
@maps.each do |name, remotepath|
score += 1
local_path = File.join @config.mnt_dir, name
if sshfs_mounted.include? local_path then
score -= 1
end
end
if score == 0 then return true
else return false
# FIXME: explain why ?
end
end end
def connect &block def connect &block