summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-03-21 10:47:37 -0300
committerkali <kali@leap.se>2013-03-21 23:01:51 +0900
commit344abd42c6b480a783ee05b6e92532a1113a86d2 (patch)
treec449846eec2c6bed61ebc1e24dd3c1ae180fe923 /src
parentbdc3e1b840c383f0d9236ad8d4df66633e87baf5 (diff)
Wrap bool setting casting in a method
Diffstat (limited to 'src')
-rw-r--r--src/leap/config/leapsettings.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/leap/config/leapsettings.py b/src/leap/config/leapsettings.py
index b728ce15..35c9fef6 100644
--- a/src/leap/config/leapsettings.py
+++ b/src/leap/config/leapsettings.py
@@ -29,6 +29,28 @@ from leap.config.prefixers import get_platform_prefixer
logger = logging.getLogger(__name__)
+def to_bool(val):
+ """
+ Returns the boolean value corresponding to val. Will return False
+ in case val is not a string or something that behaves like one.
+
+ @param val: value to cast
+ @type val: either bool already or str
+
+ @rtype: bool
+ """
+ if isinstance(val, bool):
+ return val
+
+ bool_val = False
+ try:
+ bool_val = val.lower() == "true"
+ except:
+ pass
+
+ return bool_val
+
+
class LeapSettings(object):
"""
Leap client QSettings wrapper
@@ -153,7 +175,7 @@ class LeapSettings(object):
@rtype: bool
"""
- return self._settings.value(self.AUTOLOGIN_KEY, "false") != "false"
+ return to_bool(self._settings.value(self.AUTOLOGIN_KEY, False))
def set_autologin(self, autologin):
"""
@@ -173,8 +195,7 @@ class LeapSettings(object):
@rtype: bool
"""
- return self._settings.value(self.PROPERPROVIDER_KEY,
- "false") != "false"
+ return to_bool(self._settings.value(self.PROPERPROVIDER_KEY, False))
def set_properprovider(self, properprovider):
"""