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
|
|
|
|
|
|
|
|
|
|
|
class Settings(object):
|
|
|
|
|
|
|
|
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
|
|
|
# TODO: create new if old not found
|
|
|
|
if os.path.exists(self.path):
|
|
|
|
with open(self.path) as fl:
|
|
|
|
data = fl.read()
|
|
|
|
self.data = json.loads(data)
|
|
|
|
else:
|
|
|
|
self.create_default_settings()
|
|
|
|
|
|
|
|
def create_default_settings(self):
|
|
|
|
self.data = {
|
|
|
|
"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-16 19:11:56 +01:00
|
|
|
|
|
|
|
def __get__(self, attr):
|
|
|
|
return self.data[attr]
|
|
|
|
|
2016-02-16 20:57:45 +01:00
|
|
|
def save(self):
|
|
|
|
text = json.dumps(self.data)
|
|
|
|
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/'
|
|
|
|
|