From 1b8241eee9ea628f45b25b89f4ec0af8c780cd64 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 18 May 2018 00:06:14 +0300 Subject: [PATCH] profile minor fixes --- toxygen/app.py | 4 ++-- toxygen/contacts/profile.py | 29 +++++++++--------------- toxygen/file_transfers/file_transfers.py | 2 +- toxygen/middleware/callbacks.py | 6 ++--- toxygen/ui/menu.py | 2 +- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/toxygen/app.py b/toxygen/app.py index a618cc2..3a3476e 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -298,11 +298,11 @@ class App: self._calls_manager = CallsManager(self._tox.AV, self._settings) db = Database(self._path.replace('.tox', '.db'), self._toxes) - profile = Profile(self._profile_manager, self._tox, self._ms) - self._plugin_loader = PluginLoader(self._tox, self._toxes, profile, self._settings) friend_items_factory = FriendItemsFactory(self._settings, self._ms) self._friend_factory = FriendFactory(self._profile_manager, self._settings, self._tox, db, friend_items_factory) self._contacts_provider = ContactProvider(self._tox, self._friend_factory) + profile = Profile(self._profile_manager, self._tox, self._ms, self._contacts_provider, self._reset) + self._plugin_loader = PluginLoader(self._tox, self._toxes, profile, self._settings) history = None messages_items_factory = MessagesItemsFactory(self._settings, self._plugin_loader, self._smiley_loader, self._ms, lambda m: history.delete_message(m)) diff --git a/toxygen/contacts/profile.py b/toxygen/contacts/profile.py index 4edae71..6393f7e 100644 --- a/toxygen/contacts/profile.py +++ b/toxygen/contacts/profile.py @@ -11,7 +11,7 @@ class Profile(basecontact.BaseContact): """ Profile of current toxygen user. Contains friends list, tox instance """ - def __init__(self, profile_manager, tox, screen): + def __init__(self, profile_manager, tox, screen, contacts_provider, reset_action): """ :param tox: tox instance :param screen: ref to main screen @@ -25,11 +25,10 @@ class Profile(basecontact.BaseContact): self._screen = screen self._messages = screen.messages self._tox = tox - self._file_transfers = {} # dict of file transfers. key - tuple (friend_number, file_number) - self._load_history = True + self._contacts_provider = contacts_provider + self._reset_action = reset_action self._waiting_for_reconnection = False - self._contacts_manager = None - self._timer = threading.Timer(50, self.reconnect) + self._timer = threading.Timer(50, self._reconnect) # ----------------------------------------------------------------------------------------------------------------- # Edit current user's data @@ -68,7 +67,7 @@ class Profile(basecontact.BaseContact): super().set_status_message(value) self._tox.self_set_status_message(self._status_message.encode('utf-8')) - def new_nospam(self): + def set_new_nospam(self): """Sets new nospam part of tox id""" self._tox.self_set_nospam(random.randint(0, 4294967295)) # no spam - uint32 self._tox_id = self._tox.self_get_address() @@ -88,23 +87,20 @@ class Profile(basecontact.BaseContact): # Reset # ----------------------------------------------------------------------------------------------------------------- - def reset(self, restart): + def _restart(self): """ Recreate tox instance - :param restart: method which calls restart and returns new tox instance """ - for friend in self._contacts: - self.friend_exit(friend.number) del self._tox - self._tox = restart() + self._tox = self._reset_action() self.status = None - self._contacts_manager.update_filtration() - def reconnect(self): + def _reconnect(self): self._waiting_for_reconnection = False - if self.status is None or all(list(map(lambda x: x.status is None, self._contacts))) and len(self._contacts): + contacts = self._contacts_provider.get_all() + if self.status is None or all(list(map(lambda x: x.status is None, contacts))) and len(contacts): self._waiting_for_reconnection = True - self.reset(self._screen.reset) + self._restart() self._timer.start() def close(self): @@ -112,6 +108,3 @@ class Profile(basecontact.BaseContact): self.friend_exit(friend.number) for i in range(len(self._contacts)): del self._contacts[0] - if hasattr(self, '_call'): - self._call.stop() - del self._call diff --git a/toxygen/file_transfers/file_transfers.py b/toxygen/file_transfers/file_transfers.py index e5c2bb4..710320c 100644 --- a/toxygen/file_transfers/file_transfers.py +++ b/toxygen/file_transfers/file_transfers.py @@ -161,12 +161,12 @@ class SendTransfer(FileTransfer): data = self._file.read(size) self._tox.file_send_chunk(self._friend_number, self._file_number, position, data) self._done += size + self._signal() else: if self._file is not None: self._file.close() self.state = FILE_TRANSFER_STATE['FINISHED'] self._finished() - self._signal() class SendAvatar(SendTransfer): diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index 9f4cdd8..83dcc64 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -1,4 +1,4 @@ -from PyQt5 import QtGui, QtCore +from PyQt5 import QtGui from user_data.settings import Settings from contacts.profile import Profile from wrapper.toxcore_enums_and_consts import * @@ -26,8 +26,8 @@ def self_connection_status(tox, profile): """ def wrapped(tox_link, connection, user_data): print('Connection status: ', str(connection)) - status = None if connection == TOX_CONNECTION['NONE'] else tox.self_get_status() - invoke_in_main_thread(profile.set_status, None) + status = tox.self_get_status() if connection != TOX_CONNECTION['NONE'] else None + invoke_in_main_thread(profile.set_status, status) return wrapped diff --git a/toxygen/ui/menu.py b/toxygen/ui/menu.py index 1a33bde..d912619 100644 --- a/toxygen/ui/menu.py +++ b/toxygen/ui/menu.py @@ -242,7 +242,7 @@ class ProfileSettings(CenteredWidget): self.copy_pk.setIconSize(QtCore.QSize(10, 10)) def new_no_spam(self): - self.tox_id.setText(self._profile.new_nospam()) + self.tox_id.setText(self._profile.set_new_nospam()) def reset_avatar(self): self._profile.reset_avatar(self._settings['identicons'])