diff --git a/app/hub.py b/app/hub.py index fb54f6a..fa06016 100644 --- a/app/hub.py +++ b/app/hub.py @@ -678,6 +678,23 @@ def update_wallet_loading_height(self): if h > self.current_block_height: self.on_update_wallet_loading_height_event.emit(h, self.ui.target_height) self.current_block_height = h + + @Slot(bool) + def change_minimize_to_tray(self, status): + self.ui.close_to_system_tray = status + self.ui.app_settings.settings['application']['minimize_to_tray'] = status + self.ui.app_settings.save() + + @Slot(int) + def change_limit_rate_up(self, limit_rate_up): + self.ui.app_settings.settings['daemon']['limit_rate_up'] = limit_rate_up + self.ui.app_settings.save() + + + @Slot(int) + def change_limit_rate_down(self, limit_rate_down): + self.ui.app_settings.settings['daemon']['limit_rate_down'] = limit_rate_down + self.ui.app_settings.save() def update_daemon_status(self, status): diff --git a/classes/__init__.py b/classes/__init__.py index 443f493..1c7ad80 100644 --- a/classes/__init__.py +++ b/classes/__init__.py @@ -81,18 +81,36 @@ def reset(self): self.bc_height = -1 +def set_default_settings(default_settings, settings): + for k, v in default_settings.iteritems(): + settings.setdefault(k, v) + if type(v) is dict: set_default_settings(default_settings[k], settings[k]) + class AppSettings(): - settings = { + settings = {} + default_settings = { "daemon": { "log_level": 0, - "block_sync_size": 10 + "block_sync_size": 10, + "limit_rate_up": 2048, + "limit_rate_down": 8192, }, "blockchain": { "height": 0, + }, + + "application": { + "minimize_to_tray": False, } } + log_levels = [0,1,2,3,4] + block_sync_sizes = [10,20,50,100,200] + limit_rate_ups = [512,1024,2048,3072,4096,8192,16384] + limit_rate_downs = [512,1024,2048,4096,8192,12288,16384] + + def __init__(self): self.app_settings_filepath = os.path.join(config_path, 'app_settings.json') @@ -101,12 +119,36 @@ def load(self): if os.path.exists(self.app_settings_filepath): try: self.settings = json.loads(readFile(self.app_settings_filepath)) - return True except Exception, err: - log("[AppSettings]>>> Load error:" + str(err), LEVEL_ERROR) - return False - return False - + log("[AppSettings]>>> Load config file error:" + str(err), LEVEL_ERROR) + + # Set default values: + set_default_settings(self.default_settings, self.settings) + + # Validate values + if self.settings["daemon"]["log_level"] not in self.log_levels: + self.settings["daemon"]["log_level"] = self.default_settings["daemon"]["log_level"] + + if self.settings["daemon"]["block_sync_size"] not in self.block_sync_sizes: + self.settings["daemon"]["block_sync_size"] = self.default_settings["daemon"]["block_sync_size"] + + if self.settings["daemon"]["limit_rate_up"] not in self.limit_rate_ups: + self.settings["daemon"]["limit_rate_up"] = self.default_settings["daemon"]["limit_rate_up"] + + if self.settings["daemon"]["limit_rate_down"] not in self.limit_rate_downs: + self.settings["daemon"]["limit_rate_down"] = self.default_settings["daemon"]["limit_rate_down"] + + try: + self.settings["blockchain"]["height"] = abs(int(self.settings["blockchain"]["height"])) + except: + self.settings["blockchain"]["height"] = self.default_settings["blockchain"]["height"] + + try: + self.settings["application"]["minimize_to_tray"] = bool(self.settings["application"]["minimize_to_tray"]) + except: + self.settings["application"]["minimize_to_tray"] = self.default_settings["application"]["minimize_to_tray"] + + def save(self): try: writeFile(self.app_settings_filepath, \ diff --git a/html/index.py b/html/index.py index b9ec9c4..40cff45 100644 --- a/html/index.py +++ b/html/index.py @@ -89,7 +89,7 @@ #settings_tab h3{ margin-top: 20px; - margin-bottom: 30px; + margin-bottom: 20px; } .syncing{ @@ -374,6 +374,10 @@ text-align: center; } + #speed_limit_form select { + font-size: 14px; + } + @@ -391,6 +395,11 @@ $('#daemon_log_level_' + log_level).prop('checked', true); var block_sync_size = app_settings['daemon']['block_sync_size']; $('#block_sync_size_' + block_sync_size).prop('checked', true); + + $('#minimize_to_tray_chk').prop('checked', app_settings['application']['minimize_to_tray']); + + $('#up_speed_limit_select').val(app_settings['daemon']['limit_rate_up']); + $('#down_speed_limit_select').val(app_settings['daemon']['limit_rate_down']); }); app_hub.on_main_wallet_ui_reset_event.connect(function(){ @@ -754,7 +763,7 @@ var row_rendered = Mustache.render(new_subaddress_row_tmpl, { 'address_index': subaddress['address_index'], 'address' : subaddress['address'], - 'address_short' : subaddress['address'].substr(0, 70) + '...' + 'address_short' : subaddress['address'].substr(0, 60) + '...' }); @@ -772,7 +781,7 @@ var row_rendered = Mustache.render(used_subaddress_row_tmpl, { 'address_index': subaddress['address_index'], 'address' : subaddress['address'], - 'address_short' : subaddress['address'].substr(0, 40) + '...', + 'address_short' : subaddress['address'].substr(0, 30) + '...', 'balance': subaddress['balance'], 'unlocked_balance': subaddress['unlocked_balance'], 'row_font_weight': subaddress['address_index'] == 0 ? 'bold' : 'normal' @@ -1086,6 +1095,18 @@ }, 1); } }); + + $("#minimize_to_tray_chk").change(function() { + app_hub.change_minimize_to_tray(this.checked); + }); + + $('#up_speed_limit_select').on('change', function(e) { + app_hub.change_limit_rate_up(this.value); + }); + + $('#down_speed_limit_select').on('change', function(e) { + app_hub.change_limit_rate_down(this.value); + }); }); @@ -1326,15 +1347,15 @@ -