2016-02-16 21:03:37 +01:00
|
|
|
from platform import system
|
2016-02-16 19:11:56 +01:00
|
|
|
import json
|
2016-02-16 20:57:45 +01:00
|
|
|
import os
|
2016-02-16 19:11:56 +01:00
|
|
|
|
|
|
|
|
2016-02-17 22:16:44 +01:00
|
|
|
class Settings(dict):
|
2016-02-16 19:11:56 +01:00
|
|
|
|
|
|
|
def __init__(self):
|
2016-02-16 20:57:45 +01:00
|
|
|
self.path = Settings.get_default_path() + 'toxygen.json'
|
2016-02-17 20:04:39 +01:00
|
|
|
if os.path.exists(self.path):
|
|
|
|
with open(self.path) as fl:
|
|
|
|
data = fl.read()
|
2016-02-17 22:16:44 +01:00
|
|
|
super(self.__class__, self).__init__(json.loads(data))
|
2016-02-17 20:04:39 +01:00
|
|
|
else:
|
2016-02-17 22:16:44 +01:00
|
|
|
super(self.__class__, self).__init__(Settings.get_default_settings())
|
2016-02-17 21:47:43 +01:00
|
|
|
self.save()
|
2016-02-17 20:04:39 +01:00
|
|
|
|
2016-02-17 22:16:44 +01:00
|
|
|
@staticmethod
|
|
|
|
def get_default_settings():
|
|
|
|
return {
|
2016-02-18 17:15:38 +01:00
|
|
|
'theme': 'default',
|
|
|
|
'ipv6_enabled': True,
|
|
|
|
'udp_enabled': True,
|
|
|
|
'proxy_type': 0,
|
|
|
|
'proxy_host': '0',
|
|
|
|
'proxy_port': 0,
|
|
|
|
'start_port': 0,
|
|
|
|
'end_port': 0,
|
|
|
|
'tcp_port': 0,
|
|
|
|
'notifications': True,
|
|
|
|
'sound_notifications': False,
|
|
|
|
'language': 'en-en',
|
|
|
|
'save_history': False,
|
|
|
|
'allow_inline': True,
|
|
|
|
'allow_auto_accept': False,
|
|
|
|
'auto_accept_from_friends': [],
|
|
|
|
'friends_aliases': [],
|
|
|
|
'typing_notifications': True,
|
2016-02-18 18:13:55 +01:00
|
|
|
'auto_profile': None
|
2016-02-17 20:04:39 +01:00
|
|
|
}
|
2016-02-16 19:11:56 +01:00
|
|
|
|
2016-02-16 20:57:45 +01:00
|
|
|
def save(self):
|
2016-02-17 22:16:44 +01:00
|
|
|
text = json.dumps(self)
|
2016-02-16 20:57:45 +01:00
|
|
|
with open(self.path, 'w') as fl:
|
|
|
|
fl.write(text)
|
|
|
|
|
2016-02-16 19:11:56 +01:00
|
|
|
@staticmethod
|
|
|
|
def get_default_path():
|
2016-02-16 21:03:37 +01:00
|
|
|
if system() == 'Linux':
|
2016-02-16 20:57:45 +01:00
|
|
|
return os.getenv('HOME') + '/.config/tox/'
|
2016-02-16 21:03:37 +01:00
|
|
|
elif system() == 'Windows':
|
2016-02-16 20:57:45 +01:00
|
|
|
return os.getenv('APPDATA') + '/Tox/'
|
|
|
|
|