set time between checks

This commit is contained in:
John Bintz 2012-05-08 20:11:35 -04:00
parent 6e291cc583
commit 53ab8e23bc
3 changed files with 48 additions and 10 deletions

View File

@ -3,6 +3,8 @@ require 'atomic'
module Unison module Unison
class Config class Config
DEFAULT_TIME_BETWEEN_CHECKS = 60
def self.ensure(file) def self.ensure(file)
if !File.file?(file) if !File.file?(file)
File.open(file, 'wb') { |fh| fh.print YAML.dump(skel_data) } File.open(file, 'wb') { |fh| fh.print YAML.dump(skel_data) }
@ -12,7 +14,7 @@ module Unison
end end
def self.skel_data def self.skel_data
{ 'profiles' => [] } { 'profiles' => [], 'time_between_checks' => DEFAULT_TIME_BETWEEN_CHECKS }
end end
def set_profile(profile, is_set) def set_profile(profile, is_set)
@ -28,13 +30,12 @@ module Unison
d d
end end
@on_update.call if @on_update
save save
end end
def on_update(&block) def on_update(&block)
@on_update = block @on_update ||= []
@on_update << block
end end
def initialize(file) def initialize(file)
@ -51,6 +52,17 @@ module Unison
data['profiles'] data['profiles']
end end
def time_between_checks
data['time_between_checks']
end
def time_between_checks=(time)
time = DEFAULT_TIME_BETWEEN_CHECKS if time <= 10
data['time_between_checks'] = time
save
end
def data def data
@data.update { |d| d || YAML.load_file(@file) } @data.update { |d| d || YAML.load_file(@file) }
@data.value @data.value
@ -65,6 +77,10 @@ module Unison
File.open(@file, 'wb') { |fh| fh.print YAML.dump(d) } File.open(@file, 'wb') { |fh| fh.print YAML.dump(d) }
d d
end end
if @on_update
@on_update.each(&:call)
end
end end
end end
end end

View File

@ -23,7 +23,24 @@ module Unison
profile_group_layout.addWidget(radio) profile_group_layout.addWidget(radio)
end end
layout.addWidget(profile_group) performance_group = Qt::GroupBox.new("Performance")
performance_group_layout = Qt::VBoxLayout.new
performance_group.setLayout(performance_group_layout)
fields = Qt::Widget.new
fields_layout = Qt::GridLayout.new
fields.setLayout(fields_layout)
count_label = Qt::Label.new("Seconds between checks (min 10s):")
count_field = Qt::LineEdit.new(@config.time_between_checks.to_s)
count_field.connect(SIGNAL "textChanged(QString)") { |string| @config.time_between_checks = string.to_i }
fields_layout.addWidget(count_label, 0, 0)
fields_layout.addWidget(count_field, 0, 1)
performance_group_layout.addWidget(fields)
layout.addWidget(profile_group, 0, 0)
layout.addWidget(performance_group, 0, 1)
setLayout(layout) setLayout(layout)
end end

View File

@ -3,7 +3,6 @@ require 'forwardable'
module Unison module Unison
class Watcher < Qt::Application class Watcher < Qt::Application
TRANSFER_LOG = '~/unison.log' TRANSFER_LOG = '~/unison.log'
SYNC_CHECK_COUNT = 600
SYNC_CHECK_TIME = 0.1 SYNC_CHECK_TIME = 0.1
extend Forwardable extend Forwardable
@ -18,7 +17,13 @@ module Unison
@sync_now = false @sync_now = false
@exiting = false @exiting = false
@active = true @active = true
end
@config.on_update { @remote_sync_check = time_between_checks }
end
def time_between_checks
@config.time_between_checks * 10
end
def <<(dirs) def <<(dirs)
@queue.update { |q| q += [ dirs ].flatten ; q } @queue.update { |q| q += [ dirs ].flatten ; q }
@ -73,7 +78,7 @@ module Unison
@icons = {} @icons = {}
@remote_sync_check = SYNC_CHECK_COUNT @remote_sync_check = time_between_checks
while !@exiting while !@exiting
check check
@ -128,7 +133,7 @@ module Unison
show_working show_working
@remote_sync_check = SYNC_CHECK_COUNT @remote_sync_check = time_between_checks
@sync_now = false @sync_now = false
@queue.update { [] } @queue.update { [] }
end end
@ -145,7 +150,7 @@ module Unison
else else
@current_text = "Syncing paused." @current_text = "Syncing paused."
@remote_sync_check = SYNC_CHECK_COUNT @remote_sync_check = time_between_checks
end end
end end