From 9145974c7f2b81be79fa05a7c8896c5772084dca Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 24 Feb 2016 00:03:50 +0300 Subject: [PATCH] profile creation added --- src/main.py | 17 +++++++++-------- src/profile.py | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main.py b/src/main.py index afb705d..b6448bf 100644 --- a/src/main.py +++ b/src/main.py @@ -52,23 +52,24 @@ def main(): if not _login.t: return elif _login.t == 1: # create new profile - # TODO: add possibility to create new profile - path = Settings.get_default_path() + # TODO: test 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 path, name = _login.get_data() if _login.default: settings['auto_profile'] = (path, name) settings.save() + data = Profile.open_profile(path, name) + tox = tox_factory(data, settings) else: path, name = settings['auto_profile'] - # loading profile - print str(path), str(name) - data = Profile.open_profile(path, name) + data = Profile.open_profile(path, name) + tox = tox_factory(data, settings) + ms = MainWindow() - # creating tox instance - tox = tox_factory(data, settings) ms.show() # bootstrap for data in node_generator(): diff --git a/src/profile.py b/src/profile.py index 5bca1b7..adb6fba 100644 --- a/src/profile.py +++ b/src/profile.py @@ -37,12 +37,16 @@ class Profile(object): @staticmethod def save_profile(data): + if not hasattr(Profile, '_path'): + Profile._path = Settings.get_default_path() with open(Profile._path, 'wb') as fl: fl.write(data) 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.contents.udp_enabled = settings['udp_enabled'] 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.end_port = settings['end_port'] tox_options.contents.tcp_port = settings['tcp_port'] - tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['TOX_SAVE'] - tox_options.contents.savedata_data = c_char_p(data) - tox_options.contents.savedata_length = len(data) + if data: # load existing profile + tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['TOX_SAVE'] + 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)