whoa it works better

This commit is contained in:
John Bintz 2012-05-03 23:16:51 -04:00
parent 773f5fdb1a
commit fa5585fec5
2 changed files with 96 additions and 74 deletions

View File

@ -11,5 +11,4 @@ when /linux/
end
gem 'atomic'
gem 'daemons'

View File

@ -5,11 +5,9 @@ require 'bundler/setup'
require 'Qt4'
require 'thread'
require 'atomic'
require 'daemons'
ENV['PROFILE'] ||= 'default'
class UnisonProfile
def initialize(which = ENV['PROFILE'])
@which = which
@ -108,92 +106,124 @@ class UnisonWatcher < Qt::Application
watcher[:app] = self
end
def menu
menu = Qt::Menu.new
def update_status(status)
new_status = Qt::Action.new(status, @menu)
new_status.enabled = false
@menu.insertAction(@active_status, new_status)
@menu.removeAction(@status)
@status = Qt::Action.new("Unison watch idle.", menu)
@status = new_status
end
def menu
@menu = Qt::Menu.new
@current_text = 'Unison watch idle.'
@status = Qt::Action.new(@status_text, @menu)
@status.enabled = false
sync_now = Qt::Action.new("Sync now", menu)
sync_now = Qt::Action.new("Sync now", @menu)
sync_now.connect(SIGNAL :triggered) { @sync_now = true }
@active_status = Qt::Action.new("Pause syncing", menu)
@active_status = Qt::Action.new("Pause syncing", @menu)
@active_status.connect(SIGNAL :triggered) { toggle_status }
@log = Qt::Action.new("View transfer log", menu)
@log = Qt::Action.new("View transfer log", @menu)
@log.connect(SIGNAL :triggered) { system %{open #{TRANSFER_LOG}} }
quit = Qt::Action.new("Quit", menu)
quit = Qt::Action.new("Quit", @menu)
quit.connect(SIGNAL :triggered) { @exiting = true }
menu.addAction @status
menu.addAction @active_status
menu.addAction sync_now
menu.addSeparator
menu.addAction @log
menu.addAction quit
@menu.addAction @active_status
@menu.addAction sync_now
@menu.addSeparator
@menu.addAction @log
@menu.addAction quit
menu
@current_text = 'Unison watch idle.'
update_status @current_text
@menu
end
def ui
icon = Qt::SystemTrayIcon.new
icon.contextMenu = menu
toggle_status true
@prior_icon = nil
while !@exiting
@log.enabled = File.file?(File.expand_path(TRANSFER_LOG))
def update_ui
if @current_icon != @prior_icon
icon.icon = Qt::Icon.new(File.expand_path("../../assets/#{@current_icon}.png", __FILE__))
if !@prior_icon
icon.show
if !@icons[@current_icon]
@icons[@current_icon] = Qt::Icon.new(File.expand_path("../../assets/#{@current_icon}.png", __FILE__))
end
@icon.icon = @icons[@current_icon]
@icon.show if !@prior_icon
@prior_icon = @current_icon
end
if @current_text!= @prior_text
update_status @current_text
@prior_text = @current_text
end
processEvents
sleep 0.1
end
def ui
@icon = Qt::SystemTrayIcon.new
@icon.contextMenu = menu
toggle_status true
@prior_icon = nil
@prior_text = nil
s = nil
@icons = {}
@remote_sync_check = SYNC_CHECK_COUNT
while !@exiting
check
update_ui
sleep SYNC_CHECK_TIME
end
end
def start
watch
check
ui
end
def check
remote_sync_check = SYNC_CHECK_COUNT
Thread.new do
while true do
begin
if @active && (@queue.value.length > 0 || remote_sync_check == 0 || @sync_now)
if @active && (@queue.value.length > 0 || @remote_sync_check == 0 || @sync_now)
dir = nil
@status.text = "Syncing..."
@current_text = "Syncing..."
animation = Thread.new do
while !Thread.current[:done] do
@done = false
runner = Thread.new do
system %{bash -c 'unison -log -logfile #{TRANSFER_LOG} -batch #{ENV['PROFILE']}'}
@done = true
end
while !@done
@current_icon = 'working-1'
update_ui
sleep 0.25
@current_icon = 'working-2'
sleep 0.25
update_ui
end
@current_icon = 'idle'
end
system %{bash -c 'unison -log -logfile #{TRANSFER_LOG} -batch #{ENV['PROFILE']}'}
animation[:done] = true
remote_sync_check = SYNC_CHECK_COUNT
@remote_sync_check = SYNC_CHECK_COUNT
@sync_now = false
@queue.update { [] }
end
@ -203,21 +233,14 @@ class UnisonWatcher < Qt::Application
exit
end
remote_sync_check -= 1
check_text = "Next check in #{sprintf("%.0d", SYNC_CHECK_TIME * remote_sync_check)} secs."
@status.text = check_text
@remote_sync_check -= 1
if @active
sleep SYNC_CHECK_TIME
@current_text = "Next check in #{sprintf("%.0d", SYNC_CHECK_TIME * @remote_sync_check)} secs."
else
while !@active do
@status.text = "Syncing paused."
sleep SYNC_CHECK_TIME
end
@current_text = "Syncing paused."
remote_sync_check = SYNC_CHECK_COUNT
end
end
@remote_sync_check = SYNC_CHECK_COUNT
end
end