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
itemx = Qt::Action.new(map.name, @map_menu)
itemx.setCheckable true;
if map.connected? then
itemx.setChecked true
end
itemx.connect(SIGNAL(:triggered)) do
action_trigger_map_item map, itemx
end

View file

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

View file

@ -1,6 +1,7 @@
require 'rubygems'
require 'rdebug/base'
require 'qasim/config'
module Qasim
@ -20,7 +21,8 @@ module Qasim
CYPHER_AES256CBC = "aes-256-cbc".to_sym
CYPHERS = [ CYPHER_ARCFOUR, CYPHER_AES256CBC ]
def initialize map_path
def initialize config, map_path
@config = config
@path = map_path
@host = nil
@port = 22
@ -44,15 +46,18 @@ module Qasim
line = line.strip
linect += 1
while line =~ /\$(.*)/ do
while line =~ /\$(\w+)/ do
puts "FOUND PATTERN %s => %s" % [$1, local_env[$1]]
case line
when /\$\{(.+?)\}/ then
when /\$\{(.+)\}/ then
pattern = $1
line.gsub!(/\$\{#{attern}\}/,local_env[pattern])
puts pattern
line.gsub!(/\$\{#{pattern}\}/,local_env[pattern])
when /\$(\w+)/ then
pattern = $1
line.gsub!(/\$#{pattern}/,local_env[pattern])
else
puts "unknown pattern: %s" % line
end
end
@ -100,6 +105,27 @@ module Qasim
def connected?
#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
def connect &block