set time between checks
This commit is contained in:
parent
6e291cc583
commit
53ab8e23bc
|
@ -3,6 +3,8 @@ require 'atomic'
|
|||
|
||||
module Unison
|
||||
class Config
|
||||
DEFAULT_TIME_BETWEEN_CHECKS = 60
|
||||
|
||||
def self.ensure(file)
|
||||
if !File.file?(file)
|
||||
File.open(file, 'wb') { |fh| fh.print YAML.dump(skel_data) }
|
||||
|
@ -12,7 +14,7 @@ module Unison
|
|||
end
|
||||
|
||||
def self.skel_data
|
||||
{ 'profiles' => [] }
|
||||
{ 'profiles' => [], 'time_between_checks' => DEFAULT_TIME_BETWEEN_CHECKS }
|
||||
end
|
||||
|
||||
def set_profile(profile, is_set)
|
||||
|
@ -28,13 +30,12 @@ module Unison
|
|||
d
|
||||
end
|
||||
|
||||
@on_update.call if @on_update
|
||||
|
||||
save
|
||||
end
|
||||
|
||||
def on_update(&block)
|
||||
@on_update = block
|
||||
@on_update ||= []
|
||||
@on_update << block
|
||||
end
|
||||
|
||||
def initialize(file)
|
||||
|
@ -51,6 +52,17 @@ module Unison
|
|||
data['profiles']
|
||||
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
|
||||
@data.update { |d| d || YAML.load_file(@file) }
|
||||
@data.value
|
||||
|
@ -65,6 +77,10 @@ module Unison
|
|||
File.open(@file, 'wb') { |fh| fh.print YAML.dump(d) }
|
||||
d
|
||||
end
|
||||
|
||||
if @on_update
|
||||
@on_update.each(&:call)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,24 @@ module Unison
|
|||
profile_group_layout.addWidget(radio)
|
||||
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)
|
||||
end
|
||||
|
|
|
@ -3,7 +3,6 @@ require 'forwardable'
|
|||
module Unison
|
||||
class Watcher < Qt::Application
|
||||
TRANSFER_LOG = '~/unison.log'
|
||||
SYNC_CHECK_COUNT = 600
|
||||
SYNC_CHECK_TIME = 0.1
|
||||
|
||||
extend Forwardable
|
||||
|
@ -18,7 +17,13 @@ module Unison
|
|||
@sync_now = false
|
||||
@exiting = false
|
||||
@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)
|
||||
@queue.update { |q| q += [ dirs ].flatten ; q }
|
||||
|
@ -73,7 +78,7 @@ module Unison
|
|||
|
||||
@icons = {}
|
||||
|
||||
@remote_sync_check = SYNC_CHECK_COUNT
|
||||
@remote_sync_check = time_between_checks
|
||||
|
||||
while !@exiting
|
||||
check
|
||||
|
@ -128,7 +133,7 @@ module Unison
|
|||
|
||||
show_working
|
||||
|
||||
@remote_sync_check = SYNC_CHECK_COUNT
|
||||
@remote_sync_check = time_between_checks
|
||||
@sync_now = false
|
||||
@queue.update { [] }
|
||||
end
|
||||
|
@ -145,7 +150,7 @@ module Unison
|
|||
else
|
||||
@current_text = "Syncing paused."
|
||||
|
||||
@remote_sync_check = SYNC_CHECK_COUNT
|
||||
@remote_sync_check = time_between_checks
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue