profile creation added
This commit is contained in:
parent
6819698596
commit
9145974c7f
2 changed files with 22 additions and 12 deletions
17
src/main.py
17
src/main.py
|
@ -52,23 +52,24 @@ def main():
|
||||||
if not _login.t:
|
if not _login.t:
|
||||||
return
|
return
|
||||||
elif _login.t == 1: # create new profile
|
elif _login.t == 1: # create new profile
|
||||||
# TODO: add possibility to create new profile
|
# TODO: test
|
||||||
path = Settings.get_default_path()
|
|
||||||
name = _login.name if _login.name else 'Toxygen User'
|
name = _login.name if _login.name else 'Toxygen User'
|
||||||
return
|
tox = tox_factory()
|
||||||
|
tox.self_set_name(name)
|
||||||
|
Profile.save_profile(tox.get_savedata())
|
||||||
else: # load existing profile
|
else: # load existing profile
|
||||||
path, name = _login.get_data()
|
path, name = _login.get_data()
|
||||||
if _login.default:
|
if _login.default:
|
||||||
settings['auto_profile'] = (path, name)
|
settings['auto_profile'] = (path, name)
|
||||||
settings.save()
|
settings.save()
|
||||||
|
data = Profile.open_profile(path, name)
|
||||||
|
tox = tox_factory(data, settings)
|
||||||
else:
|
else:
|
||||||
path, name = settings['auto_profile']
|
path, name = settings['auto_profile']
|
||||||
# loading profile
|
data = Profile.open_profile(path, name)
|
||||||
print str(path), str(name)
|
tox = tox_factory(data, settings)
|
||||||
data = Profile.open_profile(path, name)
|
|
||||||
ms = MainWindow()
|
ms = MainWindow()
|
||||||
# creating tox instance
|
|
||||||
tox = tox_factory(data, settings)
|
|
||||||
ms.show()
|
ms.show()
|
||||||
# bootstrap
|
# bootstrap
|
||||||
for data in node_generator():
|
for data in node_generator():
|
||||||
|
|
|
@ -37,12 +37,16 @@ class Profile(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def save_profile(data):
|
def save_profile(data):
|
||||||
|
if not hasattr(Profile, '_path'):
|
||||||
|
Profile._path = Settings.get_default_path()
|
||||||
with open(Profile._path, 'wb') as fl:
|
with open(Profile._path, 'wb') as fl:
|
||||||
fl.write(data)
|
fl.write(data)
|
||||||
print 'Data saved to: {}'.format(Profile._path)
|
print 'Data saved to: {}'.format(Profile._path)
|
||||||
|
|
||||||
|
|
||||||
def tox_factory(data, settings):
|
def tox_factory(data=None, settings=None):
|
||||||
|
if settings is None:
|
||||||
|
settings = Settings.get_default_settings()
|
||||||
tox_options = Tox.options_new()
|
tox_options = Tox.options_new()
|
||||||
tox_options.contents.udp_enabled = settings['udp_enabled']
|
tox_options.contents.udp_enabled = settings['udp_enabled']
|
||||||
tox_options.contents.proxy_type = settings['proxy_type']
|
tox_options.contents.proxy_type = settings['proxy_type']
|
||||||
|
@ -51,7 +55,12 @@ def tox_factory(data, settings):
|
||||||
tox_options.contents.start_port = settings['start_port']
|
tox_options.contents.start_port = settings['start_port']
|
||||||
tox_options.contents.end_port = settings['end_port']
|
tox_options.contents.end_port = settings['end_port']
|
||||||
tox_options.contents.tcp_port = settings['tcp_port']
|
tox_options.contents.tcp_port = settings['tcp_port']
|
||||||
tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['TOX_SAVE']
|
if data: # load existing profile
|
||||||
tox_options.contents.savedata_data = c_char_p(data)
|
tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['TOX_SAVE']
|
||||||
tox_options.contents.savedata_length = len(data)
|
tox_options.contents.savedata_data = c_char_p(data)
|
||||||
|
tox_options.contents.savedata_length = len(data)
|
||||||
|
else: # create new profile
|
||||||
|
tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['NONE']
|
||||||
|
tox_options.contents.savedata_data = None
|
||||||
|
tox_options.contents.savedata_length = 0
|
||||||
return Tox(tox_options)
|
return Tox(tox_options)
|
||||||
|
|
Loading…
Reference in a new issue