2011-07-19 15:27:24 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'Qt4'
|
|
|
|
|
2011-07-20 22:39:37 +00:00
|
|
|
$DEBUG = true
|
|
|
|
$VERBOSE = true
|
|
|
|
|
|
|
|
require 'pp'
|
|
|
|
require 'qasim/constants'
|
|
|
|
require 'qasim/config'
|
|
|
|
require 'qasim/map'
|
|
|
|
|
2011-07-19 15:27:24 +00:00
|
|
|
# QaSiM // Qt Sshfs Mapper
|
|
|
|
|
|
|
|
def _ str
|
|
|
|
Qt::Object.tr(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-07-19 16:22:56 +00:00
|
|
|
module Qasim
|
2011-07-20 22:49:07 +00:00
|
|
|
class QasimGui
|
2011-07-19 15:27:24 +00:00
|
|
|
|
|
|
|
|
2011-07-20 22:49:07 +00:00
|
|
|
def initialize
|
2011-07-21 14:36:33 +00:00
|
|
|
@config = Config.new
|
|
|
|
@config.parse_cmd_line ARGV
|
|
|
|
@config.parse_file
|
2011-07-20 13:38:55 +00:00
|
|
|
end
|
2011-07-19 15:27:24 +00:00
|
|
|
|
2011-07-20 22:49:07 +00:00
|
|
|
def dbus_notify title, body, icon
|
|
|
|
bus = Qt::DBusConnection.sessionBus
|
|
|
|
if !bus.connected?
|
|
|
|
$stderr.puts("Cannot connect to the D-BUS session bus.\n" \
|
|
|
|
"To start it, run:\n" \
|
|
|
|
"\teval `dbus-launch --auto-syntax`\n")
|
|
|
|
exit 1
|
2011-07-19 16:22:56 +00:00
|
|
|
end
|
2011-07-20 22:49:07 +00:00
|
|
|
msg = Qt::DBusMessage.create_method_call( 'org.freedesktop.Notifications',
|
|
|
|
'/org/freedesktop/Notifications',
|
|
|
|
'org.freedesktop.Notifications',
|
|
|
|
'Notify' )
|
2011-07-21 13:41:52 +00:00
|
|
|
msg.arguments = [ APP_NAME, Qt::Variant.from_value( 0, "unsigned int" ),
|
2011-07-20 22:49:07 +00:00
|
|
|
icon, title, body, [], {}, -1 ]
|
|
|
|
rep = bus.call( msg )
|
|
|
|
# if rep.type == Qt::DBusMessage
|
|
|
|
|
|
|
|
# si.showMessage("Qasim",
|
|
|
|
# "Sorry dude", 2, 5000 )
|
2011-07-19 16:22:56 +00:00
|
|
|
end
|
2011-07-19 15:27:24 +00:00
|
|
|
|
2011-07-21 13:41:52 +00:00
|
|
|
def build_interface
|
2011-07-19 15:27:24 +00:00
|
|
|
|
2011-07-21 13:41:52 +00:00
|
|
|
@app = Qt::Application.new(ARGV)
|
2011-07-20 22:49:07 +00:00
|
|
|
si = Qt::SystemTrayIcon.new
|
|
|
|
|
|
|
|
std_icon = Qt::Icon.new( File.join APP_ICON_PATH, "qasim.svg" )
|
|
|
|
alt_icon = Qt::Icon.new
|
|
|
|
blinking = false
|
2011-07-19 15:27:24 +00:00
|
|
|
|
2011-07-20 22:49:07 +00:00
|
|
|
si.icon = std_icon
|
|
|
|
si.show
|
|
|
|
dbus_notify "Hello", "World", 'dialog-information'
|
2011-07-19 16:22:56 +00:00
|
|
|
|
|
|
|
|
2011-07-20 22:49:07 +00:00
|
|
|
si.setToolTip("Qasim %s" % VERSION);
|
2011-07-19 16:22:56 +00:00
|
|
|
|
2011-07-21 13:41:52 +00:00
|
|
|
Qt::Timer.new(@app) do |timer|
|
2011-07-20 22:49:07 +00:00
|
|
|
timer.connect(SIGNAL('timeout()')) do
|
|
|
|
si.icon = (si.icon.isNull ? std_icon : alt_icon) if blinking
|
|
|
|
end
|
|
|
|
timer.start(500)
|
|
|
|
end
|
2011-07-19 16:22:56 +00:00
|
|
|
|
2011-07-20 22:49:07 +00:00
|
|
|
menu = Qt::Menu.new
|
2011-07-19 16:22:56 +00:00
|
|
|
|
2011-07-21 14:36:33 +00:00
|
|
|
@config.maps.each do |map|
|
|
|
|
name = (File.basename map.path).gsub(/\.map$/,'')
|
2011-07-20 22:49:07 +00:00
|
|
|
itemx = Qt::Action.new(name, menu)
|
|
|
|
itemx.setCheckable true;
|
|
|
|
itemx.connect(SIGNAL(:triggered)) do
|
|
|
|
puts "%s => %s" % [name, itemx.checked ]
|
|
|
|
end
|
|
|
|
menu.addAction itemx;
|
|
|
|
end
|
2011-07-19 16:22:56 +00:00
|
|
|
|
2011-07-20 22:49:07 +00:00
|
|
|
menu.addSeparator
|
|
|
|
|
|
|
|
act_pref = Qt::Action.new _('&Preferences'), menu
|
|
|
|
act_pref.setIcon( Qt::Icon::fromTheme("configure") )
|
|
|
|
act_pref.setIconVisibleInMenu true
|
|
|
|
menu.addAction act_pref;
|
|
|
|
|
|
|
|
act_about = Qt::Action.new '&About', menu
|
|
|
|
act_about.setIcon( Qt::Icon::fromTheme("help-about") )
|
|
|
|
act_about.setIconVisibleInMenu true
|
|
|
|
menu.addAction act_about;
|
|
|
|
|
|
|
|
menu.addSeparator
|
|
|
|
|
|
|
|
act_quit = Qt::Action.new _('Quit'), menu
|
|
|
|
act_quit.setIcon( Qt::Icon::fromTheme("application-exit") )
|
|
|
|
act_quit.setIconVisibleInMenu true
|
2011-07-21 13:41:52 +00:00
|
|
|
act_quit.connect(SIGNAL(:triggered)) { @app.quit }
|
2011-07-20 22:49:07 +00:00
|
|
|
menu.addAction act_quit
|
|
|
|
|
|
|
|
si.contextMenu = menu
|
|
|
|
|
|
|
|
si.connect(SIGNAL('activated(QSystemTrayIcon::ActivationReason)')) do |reason|
|
|
|
|
case reason
|
|
|
|
when Qt::SystemTrayIcon::Trigger
|
|
|
|
blinking = !blinking
|
|
|
|
si.icon = blinking ? alt_icon : std_icon
|
|
|
|
when Qt::SystemTrayIcon::MiddleClick: puts 'Middle Click'
|
|
|
|
when Qt::SystemTrayIcon::Context: puts 'Right Click'
|
|
|
|
when Qt::SystemTrayIcon::DoubleClick: puts 'Double Click'
|
|
|
|
end
|
2011-07-19 16:22:56 +00:00
|
|
|
end
|
2011-07-21 13:41:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
@app.exec
|
|
|
|
end
|
2011-07-20 22:49:07 +00:00
|
|
|
|
2011-07-21 13:41:52 +00:00
|
|
|
def self.main
|
|
|
|
qasim = QasimGui.new
|
|
|
|
qasim.build_interface
|
|
|
|
qasim.run
|
2011-07-19 15:27:24 +00:00
|
|
|
end
|
2011-07-19 16:22:56 +00:00
|
|
|
|
2011-07-19 15:27:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-07-21 13:41:52 +00:00
|
|
|
Qasim::QasimGui::main
|
2011-07-19 15:27:24 +00:00
|
|
|
|