From 24ae91ad0ad438b07f8000cc18d08f03ccc16509 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Thu, 5 Sep 2019 18:31:16 +0300 Subject: [PATCH] Set dontconnect temporary, completely avoiding saving --- src/bitmessageqt/settings.py | 6 +++--- src/bmconfigparser.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 4273257e..513f285b 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -490,11 +490,11 @@ class SettingsDialog(QtGui.QDialog): if self.net_restart_needed: self.net_restart_needed = False - self.config.set('bitmessagesettings', 'dontconnect', 'true') + self.config.setTemp('bitmessagesettings', 'dontconnect', 'true') self.timer.singleShot( 5000, lambda: - self.config.remove_option( - 'bitmessagesettings', 'dontconnect') + self.config.setTemp( + 'bitmessagesettings', 'dontconnect', 'false') ) self.parent.updateStartOnLogon() diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 1ee64e94..726d32eb 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -46,6 +46,8 @@ class BMConfigParser(ConfigParser.SafeConfigParser): """Singleton class inherited from ConfigParser.SafeConfigParser with additional methods specific to bitmessage config.""" + _temp = {} + def set(self, section, option, value=None): if self._optcre is self.OPTCRE or value: if not isinstance(value, basestring): @@ -59,6 +61,10 @@ class BMConfigParser(ConfigParser.SafeConfigParser): if section == "bitmessagesettings" and option == "timeformat": return ConfigParser.ConfigParser.get( self, section, option, raw, variables) + try: + return self._temp[section][option] + except KeyError: + pass return ConfigParser.ConfigParser.get( self, section, option, True, variables) except ConfigParser.InterpolationError: @@ -70,6 +76,13 @@ class BMConfigParser(ConfigParser.SafeConfigParser): except (KeyError, ValueError, AttributeError): raise e + def setTemp(self, section, option, value=None): + """Temporary set option to value, not saving.""" + try: + self._temp[section][option] = value + except KeyError: + self._temp[section] = {option: value} + def safeGetBoolean(self, section, field): try: return self.getboolean(section, field)