profile minor fixes

This commit is contained in:
ingvar1995 2018-05-18 00:06:14 +03:00
parent a3103f6fb9
commit 1b8241eee9
5 changed files with 18 additions and 25 deletions

View File

@ -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))

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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'])