From 53ab8e23bc75e717e5d809225263f07c7478b3fd Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 8 May 2012 20:11:35 -0400 Subject: [PATCH] set time between checks --- lib/unison/config.rb | 24 ++++++++++++++++++++---- lib/unison/ui/preferences.rb | 19 ++++++++++++++++++- lib/unison/watcher.rb | 15 ++++++++++----- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/lib/unison/config.rb b/lib/unison/config.rb index 0a29b35..a5192ed 100644 --- a/lib/unison/config.rb +++ b/lib/unison/config.rb @@ -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 diff --git a/lib/unison/ui/preferences.rb b/lib/unison/ui/preferences.rb index 785fecb..597fe40 100644 --- a/lib/unison/ui/preferences.rb +++ b/lib/unison/ui/preferences.rb @@ -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 diff --git a/lib/unison/watcher.rb b/lib/unison/watcher.rb index 34fa8bf..6ff2d63 100644 --- a/lib/unison/watcher.rb +++ b/lib/unison/watcher.rb @@ -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