qasim gui: Cleanup & moved constants in separate file.
git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1704 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
parent
061740d66c
commit
47e8f457a9
3 changed files with 92 additions and 87 deletions
|
@ -4,12 +4,12 @@ $DEBUG = true
|
||||||
$VERBOSE = true
|
$VERBOSE = true
|
||||||
|
|
||||||
require 'pp'
|
require 'pp'
|
||||||
require 'sshfs-mapper/config'
|
require 'qasim/config'
|
||||||
require 'sshfs-mapper/map'
|
require 'qasim/map'
|
||||||
|
|
||||||
module SshfsMapper
|
module Qasim
|
||||||
|
|
||||||
class SshfsMapper
|
class QasimCli
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
@ -69,7 +69,7 @@ module SshfsMapper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
app = SshfsMapper::SshfsMapper.new
|
app = Qasim::Qasim.new
|
||||||
app.run
|
app.run
|
||||||
|
|
||||||
|
|
||||||
|
|
165
bin/qasim-gui.rb
165
bin/qasim-gui.rb
|
@ -18,103 +18,106 @@ end
|
||||||
|
|
||||||
|
|
||||||
module Qasim
|
module Qasim
|
||||||
|
class QasimGui
|
||||||
|
|
||||||
NAME="Qasim"
|
|
||||||
VERSION="0.1"
|
|
||||||
|
|
||||||
def dbus_notify title, body, icon
|
def initialize
|
||||||
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
|
|
||||||
end
|
end
|
||||||
msg = Qt::DBusMessage.create_method_call( 'org.freedesktop.Notifications',
|
|
||||||
'/org/freedesktop/Notifications',
|
|
||||||
'org.freedesktop.Notifications',
|
|
||||||
'Notify' )
|
|
||||||
msg.arguments = [ NAME, Qt::Variant.from_value( 0, "unsigned int" ),
|
|
||||||
icon, title, body, [], {}, -1 ]
|
|
||||||
rep = bus.call( msg )
|
|
||||||
# if rep.type == Qt::DBusMessage
|
|
||||||
|
|
||||||
# si.showMessage("Qasim",
|
def dbus_notify title, body, icon
|
||||||
# "Sorry dude", 2, 5000 )
|
bus = Qt::DBusConnection.sessionBus
|
||||||
end
|
if !bus.connected?
|
||||||
|
$stderr.puts("Cannot connect to the D-BUS session bus.\n" \
|
||||||
def build_app
|
"To start it, run:\n" \
|
||||||
|
"\teval `dbus-launch --auto-syntax`\n")
|
||||||
app = Qt::Application.new(ARGV)
|
exit 1
|
||||||
si = Qt::SystemTrayIcon.new
|
|
||||||
|
|
||||||
std_icon = Qt::Icon.new( File.join ICON_PATH, "qasim.svg" )
|
|
||||||
alt_icon = Qt::Icon.new
|
|
||||||
blinking = false
|
|
||||||
|
|
||||||
si.icon = std_icon
|
|
||||||
si.show
|
|
||||||
dbus_notify "Hello", "World", 'dialog-information'
|
|
||||||
|
|
||||||
|
|
||||||
si.setToolTip("Qasim %s" % VERSION);
|
|
||||||
|
|
||||||
Qt::Timer.new(app) do |timer|
|
|
||||||
timer.connect(SIGNAL('timeout()')) do
|
|
||||||
si.icon = (si.icon.isNull ? std_icon : alt_icon) if blinking
|
|
||||||
end
|
end
|
||||||
timer.start(500)
|
msg = Qt::DBusMessage.create_method_call( 'org.freedesktop.Notifications',
|
||||||
|
'/org/freedesktop/Notifications',
|
||||||
|
'org.freedesktop.Notifications',
|
||||||
|
'Notify' )
|
||||||
|
msg.arguments = [ NAME, Qt::Variant.from_value( 0, "unsigned int" ),
|
||||||
|
icon, title, body, [], {}, -1 ]
|
||||||
|
rep = bus.call( msg )
|
||||||
|
# if rep.type == Qt::DBusMessage
|
||||||
|
|
||||||
|
# si.showMessage("Qasim",
|
||||||
|
# "Sorry dude", 2, 5000 )
|
||||||
end
|
end
|
||||||
|
|
||||||
menu = Qt::Menu.new
|
def self.build_app
|
||||||
|
|
||||||
['Diades', 'Daneel', 'Dolos'].each do |name|
|
app = Qt::Application.new(ARGV)
|
||||||
itemx = Qt::Action.new(name, menu)
|
si = Qt::SystemTrayIcon.new
|
||||||
itemx.setCheckable true;
|
|
||||||
itemx.connect(SIGNAL(:triggered)) do
|
std_icon = Qt::Icon.new( File.join APP_ICON_PATH, "qasim.svg" )
|
||||||
puts "%s => %s" % [name, itemx.checked ]
|
alt_icon = Qt::Icon.new
|
||||||
|
blinking = false
|
||||||
|
|
||||||
|
si.icon = std_icon
|
||||||
|
si.show
|
||||||
|
dbus_notify "Hello", "World", 'dialog-information'
|
||||||
|
|
||||||
|
|
||||||
|
si.setToolTip("Qasim %s" % VERSION);
|
||||||
|
|
||||||
|
Qt::Timer.new(app) do |timer|
|
||||||
|
timer.connect(SIGNAL('timeout()')) do
|
||||||
|
si.icon = (si.icon.isNull ? std_icon : alt_icon) if blinking
|
||||||
|
end
|
||||||
|
timer.start(500)
|
||||||
end
|
end
|
||||||
menu.addAction itemx;
|
|
||||||
end
|
|
||||||
|
|
||||||
menu.addSeparator
|
menu = Qt::Menu.new
|
||||||
|
|
||||||
act_pref = Qt::Action.new _('&Preferences'), menu
|
['Diades', 'Daneel', 'Dolos'].each do |name|
|
||||||
act_pref.setIcon( Qt::Icon::fromTheme("configure") )
|
itemx = Qt::Action.new(name, menu)
|
||||||
act_pref.setIconVisibleInMenu true
|
itemx.setCheckable true;
|
||||||
menu.addAction act_pref;
|
itemx.connect(SIGNAL(:triggered)) do
|
||||||
|
puts "%s => %s" % [name, itemx.checked ]
|
||||||
act_about = Qt::Action.new '&About', menu
|
end
|
||||||
act_about.setIcon( Qt::Icon::fromTheme("help-about") )
|
menu.addAction itemx;
|
||||||
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
|
|
||||||
act_quit.connect(SIGNAL(:triggered)) { app.quit }
|
|
||||||
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
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
act_quit.connect(SIGNAL(:triggered)) { app.quit }
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
app.exec
|
||||||
end
|
end
|
||||||
|
|
||||||
app.exec
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
include Qasim
|
Qasim::QasimGui::build_app
|
||||||
Qasim::build_app
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
module Qasim
|
module Qasim
|
||||||
ICON_PATH = "icons"
|
APP_ICON_PATH = "icons"
|
||||||
|
APP_NAME="Qasim"
|
||||||
|
APP_VERSION="0.1"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue