2016-02-16 20:03:37 +00:00
|
|
|
from platform import system
|
2016-02-16 18:11:56 +00:00
|
|
|
import json
|
2016-02-16 19:57:45 +00:00
|
|
|
import os
|
2018-04-15 21:11:51 +00:00
|
|
|
from util.util import log, curr_directory, append_slash
|
2016-04-24 10:45:11 +00:00
|
|
|
import pyaudio
|
2018-01-26 20:21:46 +00:00
|
|
|
from user_data.toxes import ToxES
|
2018-04-17 12:14:05 +00:00
|
|
|
import smileys.smileys as smileys
|
2016-02-16 18:11:56 +00:00
|
|
|
|
|
|
|
|
2018-04-15 21:11:51 +00:00
|
|
|
class Settings(dict):
|
2016-05-14 10:35:31 +00:00
|
|
|
"""
|
|
|
|
Settings of current profile + global app settings
|
|
|
|
"""
|
2016-02-16 18:11:56 +00:00
|
|
|
|
2018-04-15 21:11:51 +00:00
|
|
|
def __init__(self, toxes, path):
|
|
|
|
self._path = path
|
2018-04-16 20:35:55 +00:00
|
|
|
self._profile_path = path.replace('.json', '.tox')
|
2018-04-15 21:11:51 +00:00
|
|
|
self._toxes = toxes
|
|
|
|
if os.path.isfile(path):
|
|
|
|
with open(path, 'rb') as fl:
|
2016-02-17 19:04:39 +00:00
|
|
|
data = fl.read()
|
2016-05-10 10:08:44 +00:00
|
|
|
try:
|
2018-04-15 21:11:51 +00:00
|
|
|
if toxes.is_data_encrypted(data):
|
|
|
|
data = toxes.pass_decrypt(data)
|
2016-06-21 11:58:11 +00:00
|
|
|
info = json.loads(str(data, 'utf-8'))
|
2016-05-13 09:08:45 +00:00
|
|
|
except Exception as ex:
|
2016-05-10 10:08:44 +00:00
|
|
|
info = Settings.get_default_settings()
|
2016-05-13 09:08:45 +00:00
|
|
|
log('Parsing settings error: ' + str(ex))
|
2018-04-16 20:35:55 +00:00
|
|
|
super().__init__(info)
|
2016-04-24 20:24:48 +00:00
|
|
|
self.upgrade()
|
2016-02-17 19:04:39 +00:00
|
|
|
else:
|
2018-04-16 20:35:55 +00:00
|
|
|
super().__init__(Settings.get_default_settings())
|
2016-02-17 20:47:43 +00:00
|
|
|
self.save()
|
2016-06-11 10:36:52 +00:00
|
|
|
smileys.SmileyLoader(self)
|
2016-07-02 12:40:06 +00:00
|
|
|
self.locked = False
|
2016-08-05 12:58:25 +00:00
|
|
|
self.closing = False
|
2017-03-26 21:04:32 +00:00
|
|
|
self.unlockScreen = False
|
2016-07-19 12:14:30 +00:00
|
|
|
p = pyaudio.PyAudio()
|
|
|
|
input_devices = output_devices = 0
|
|
|
|
for i in range(p.get_device_count()):
|
|
|
|
device = p.get_device_info_by_index(i)
|
|
|
|
if device["maxInputChannels"]:
|
|
|
|
input_devices += 1
|
|
|
|
if device["maxOutputChannels"]:
|
|
|
|
output_devices += 1
|
|
|
|
self.audio = {'input': p.get_default_input_device_info()['index'] if input_devices else -1,
|
|
|
|
'output': p.get_default_output_device_info()['index'] if output_devices else -1,
|
|
|
|
'enabled': input_devices and output_devices}
|
2017-07-12 18:18:21 +00:00
|
|
|
self.video = {'device': -1, 'width': 640, 'height': 480, 'x': 0, 'y': 0}
|
2016-02-17 19:04:39 +00:00
|
|
|
|
2016-03-02 16:05:03 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_auto_profile():
|
2017-02-20 18:33:04 +00:00
|
|
|
p = Settings.get_global_settings_path()
|
2016-09-21 18:14:53 +00:00
|
|
|
if os.path.isfile(p):
|
|
|
|
with open(p) as fl:
|
2016-03-02 16:05:03 +00:00
|
|
|
data = fl.read()
|
|
|
|
auto = json.loads(data)
|
2016-04-03 20:51:46 +00:00
|
|
|
if 'path' in auto and 'name' in auto:
|
2017-07-12 18:36:19 +00:00
|
|
|
path = str(auto['path'])
|
|
|
|
name = str(auto['name'])
|
|
|
|
if os.path.isfile(append_slash(path) + name + '.tox'):
|
|
|
|
return path, name
|
2016-06-18 19:32:14 +00:00
|
|
|
return '', ''
|
2016-03-02 16:05:03 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def set_auto_profile(path, name):
|
2017-02-20 18:33:04 +00:00
|
|
|
p = Settings.get_global_settings_path()
|
2016-09-21 18:14:53 +00:00
|
|
|
if os.path.isfile(p):
|
|
|
|
with open(p) as fl:
|
|
|
|
data = fl.read()
|
|
|
|
data = json.loads(data)
|
|
|
|
else:
|
|
|
|
data = {}
|
2016-06-21 11:58:11 +00:00
|
|
|
data['path'] = str(path)
|
|
|
|
data['name'] = str(name)
|
2016-03-02 16:05:03 +00:00
|
|
|
with open(p, 'w') as fl:
|
2016-06-18 19:32:14 +00:00
|
|
|
fl.write(json.dumps(data))
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def reset_auto_profile():
|
2017-02-20 18:33:04 +00:00
|
|
|
p = Settings.get_global_settings_path()
|
2016-09-21 18:14:53 +00:00
|
|
|
if os.path.isfile(p):
|
|
|
|
with open(p) as fl:
|
|
|
|
data = fl.read()
|
|
|
|
data = json.loads(data)
|
|
|
|
else:
|
|
|
|
data = {}
|
2016-06-18 19:32:14 +00:00
|
|
|
if 'path' in data:
|
|
|
|
del data['path']
|
|
|
|
del data['name']
|
|
|
|
with open(p, 'w') as fl:
|
|
|
|
fl.write(json.dumps(data))
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_active_profile(path, name):
|
2017-02-20 18:33:04 +00:00
|
|
|
path = path + name + '.lock'
|
|
|
|
return os.path.isfile(path)
|
2016-03-02 16:05:03 +00:00
|
|
|
|
2016-02-17 21:16:44 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_default_settings():
|
2016-05-14 10:35:31 +00:00
|
|
|
"""
|
|
|
|
Default profile settings
|
|
|
|
"""
|
2016-02-17 21:16:44 +00:00
|
|
|
return {
|
2017-05-01 23:59:24 +00:00
|
|
|
'theme': 'dark',
|
2016-02-18 16:15:38 +00:00
|
|
|
'ipv6_enabled': True,
|
|
|
|
'udp_enabled': True,
|
|
|
|
'proxy_type': 0,
|
2016-07-02 19:19:04 +00:00
|
|
|
'proxy_host': '127.0.0.1',
|
|
|
|
'proxy_port': 9050,
|
2016-02-18 16:15:38 +00:00
|
|
|
'start_port': 0,
|
|
|
|
'end_port': 0,
|
|
|
|
'tcp_port': 0,
|
|
|
|
'notifications': True,
|
|
|
|
'sound_notifications': False,
|
2016-04-04 09:20:32 +00:00
|
|
|
'language': 'English',
|
2016-02-18 16:15:38 +00:00
|
|
|
'save_history': False,
|
|
|
|
'allow_inline': True,
|
2016-05-13 09:08:45 +00:00
|
|
|
'allow_auto_accept': True,
|
2016-03-18 16:33:54 +00:00
|
|
|
'auto_accept_path': None,
|
2016-10-30 15:13:12 +00:00
|
|
|
'sorting': 0,
|
2016-02-18 16:15:38 +00:00
|
|
|
'auto_accept_from_friends': [],
|
2016-07-30 12:44:45 +00:00
|
|
|
'paused_file_transfers': {},
|
2016-07-30 18:43:28 +00:00
|
|
|
'resend_files': True,
|
2016-02-18 16:15:38 +00:00
|
|
|
'friends_aliases': [],
|
2016-07-13 20:09:34 +00:00
|
|
|
'show_avatars': False,
|
2016-04-27 18:10:53 +00:00
|
|
|
'typing_notifications': False,
|
2016-04-24 20:24:48 +00:00
|
|
|
'calls_sound': True,
|
2016-05-28 10:06:13 +00:00
|
|
|
'blocked': [],
|
2016-06-04 12:19:15 +00:00
|
|
|
'plugins': [],
|
2016-06-11 10:36:52 +00:00
|
|
|
'notes': {},
|
|
|
|
'smileys': True,
|
2016-06-11 12:37:52 +00:00
|
|
|
'smiley_pack': 'default',
|
2016-06-17 11:53:33 +00:00
|
|
|
'mirror_mode': False,
|
|
|
|
'width': 920,
|
|
|
|
'height': 500,
|
|
|
|
'x': 400,
|
2016-06-18 20:29:49 +00:00
|
|
|
'y': 400,
|
2016-06-21 14:17:52 +00:00
|
|
|
'message_font_size': 14,
|
2016-06-28 09:44:27 +00:00
|
|
|
'unread_color': 'red',
|
2016-07-01 13:25:46 +00:00
|
|
|
'save_unsent_only': False,
|
2016-07-04 20:30:45 +00:00
|
|
|
'compact_mode': False,
|
2016-08-05 12:58:25 +00:00
|
|
|
'show_welcome_screen': True,
|
|
|
|
'close_to_tray': False,
|
2016-09-23 17:37:32 +00:00
|
|
|
'font': 'Times New Roman',
|
2017-07-18 18:36:14 +00:00
|
|
|
'update': 1,
|
2018-01-24 19:45:58 +00:00
|
|
|
'group_notifications': True,
|
|
|
|
'download_nodes_list': False
|
2016-02-17 19:04:39 +00:00
|
|
|
}
|
2016-02-16 18:11:56 +00:00
|
|
|
|
2016-04-04 09:20:32 +00:00
|
|
|
@staticmethod
|
|
|
|
def supported_languages():
|
2016-06-18 20:50:12 +00:00
|
|
|
return {
|
|
|
|
'English': 'en_EN',
|
2017-04-30 21:44:55 +00:00
|
|
|
'French': 'fr_FR',
|
2016-06-18 20:50:12 +00:00
|
|
|
'Russian': 'ru_RU',
|
2017-04-30 21:44:55 +00:00
|
|
|
'Ukrainian': 'uk_UA'
|
2016-06-18 20:50:12 +00:00
|
|
|
}
|
2016-04-04 09:20:32 +00:00
|
|
|
|
2017-05-01 23:59:24 +00:00
|
|
|
@staticmethod
|
|
|
|
def built_in_themes():
|
|
|
|
return {
|
|
|
|
'dark': '/styles/dark_style.qss',
|
2017-05-03 16:42:37 +00:00
|
|
|
'default': '/styles/style.qss'
|
2017-05-01 23:59:24 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 20:24:48 +00:00
|
|
|
def upgrade(self):
|
|
|
|
default = Settings.get_default_settings()
|
|
|
|
for key in default:
|
|
|
|
if key not in self:
|
2016-06-21 11:58:11 +00:00
|
|
|
print(key)
|
2016-04-24 20:24:48 +00:00
|
|
|
self[key] = default[key]
|
|
|
|
self.save()
|
|
|
|
|
2016-02-16 19:57:45 +00:00
|
|
|
def save(self):
|
2016-02-17 21:16:44 +00:00
|
|
|
text = json.dumps(self)
|
2018-04-15 21:11:51 +00:00
|
|
|
if self._toxes.has_password():
|
|
|
|
text = bytes(self._toxes.pass_encrypt(bytes(text, 'utf-8')))
|
2016-06-21 20:43:43 +00:00
|
|
|
else:
|
|
|
|
text = bytes(text, 'utf-8')
|
2018-04-15 21:11:51 +00:00
|
|
|
with open(self._path, 'wb') as fl:
|
2016-02-16 19:57:45 +00:00
|
|
|
fl.write(text)
|
|
|
|
|
2016-04-03 20:51:46 +00:00
|
|
|
def close(self):
|
2018-04-16 20:35:55 +00:00
|
|
|
path = self._profile_path + '.lock'
|
2016-04-03 20:51:46 +00:00
|
|
|
if os.path.isfile(path):
|
2017-02-20 18:33:04 +00:00
|
|
|
os.remove(path)
|
2016-04-03 20:51:46 +00:00
|
|
|
|
|
|
|
def set_active_profile(self):
|
2016-05-14 10:35:31 +00:00
|
|
|
"""
|
|
|
|
Mark current profile as active
|
|
|
|
"""
|
2018-04-16 20:35:55 +00:00
|
|
|
path = self._profile_path + '.lock'
|
2016-04-03 20:51:46 +00:00
|
|
|
with open(path, 'w') as fl:
|
2017-02-20 18:33:04 +00:00
|
|
|
fl.write('active')
|
2016-04-03 20:51:46 +00:00
|
|
|
|
2016-03-13 12:06:06 +00:00
|
|
|
def export(self, path):
|
|
|
|
text = json.dumps(self)
|
|
|
|
with open(path + str(self.name) + '.json', 'w') as fl:
|
|
|
|
fl.write(text)
|
|
|
|
|
2016-07-27 14:13:57 +00:00
|
|
|
def update_path(self):
|
2018-01-26 20:21:46 +00:00
|
|
|
self.path = ProfileManager.get_path() + self.name + '.json'
|
2016-07-27 14:13:57 +00:00
|
|
|
|
2017-02-20 18:33:04 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_global_settings_path():
|
|
|
|
return curr_directory() + '/toxygen.json'
|
|
|
|
|
2016-02-16 18:11:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_default_path():
|
2016-07-26 16:09:57 +00:00
|
|
|
if system() == 'Windows':
|
2016-02-16 19:57:45 +00:00
|
|
|
return os.getenv('APPDATA') + '/Tox/'
|
2016-07-26 16:09:57 +00:00
|
|
|
elif system() == 'Darwin':
|
|
|
|
return os.getenv('HOME') + '/Library/Application Support/Tox/'
|
|
|
|
else:
|
|
|
|
return os.getenv('HOME') + '/.config/tox/'
|
2016-04-03 20:51:46 +00:00
|
|
|
|