settings fix

This commit is contained in:
ingvar1995 2016-03-02 19:05:03 +03:00
parent 0c590b01d7
commit 26fcc260df
4 changed files with 38 additions and 11 deletions

View file

@ -6,8 +6,8 @@ from util import Singleton
class Settings(dict, Singleton):
def __init__(self):
self.path = Settings.get_default_path() + 'toxygen.json'
def __init__(self, name=''):
self.path = Settings.get_default_path() + str(name) + '.json'
if os.path.isfile(self.path):
with open(self.path) as fl:
data = fl.read()
@ -16,6 +16,24 @@ class Settings(dict, Singleton):
super(self.__class__, self).__init__(Settings.get_default_settings())
self.save()
@staticmethod
def get_auto_profile():
path = Settings.get_default_path() + 'toxygen.json'
if os.path.isfile(path):
with open(path) as fl:
data = fl.read()
auto = json.loads(data)
return auto['path'], auto['name']
else:
return None
@staticmethod
def set_auto_profile(path, name):
p = Settings.get_default_path() + 'toxygen.json'
data = json.dumps({'path': path, 'name': name})
with open(p, 'w') as fl:
fl.write(data)
@staticmethod
def get_default_settings():
return {
@ -38,7 +56,6 @@ class Settings(dict, Singleton):
'auto_accept_from_friends': [],
'friends_aliases': [],
'typing_notifications': True,
'auto_profile': None,
'calls_sound': True
}