From 47c115e6993e20a501cf711408e98a843fb1d25e Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 30 Jun 2018 14:56:41 +0300 Subject: [PATCH] avatars support fixed --- .gitignore | 2 ++ toxygen/app.py | 6 +++--- toxygen/contacts/basecontact.py | 5 ++--- toxygen/contacts/contact.py | 4 ++-- toxygen/contacts/friend.py | 4 ++-- toxygen/contacts/friend_factory.py | 5 ++--- toxygen/contacts/group_chat.py | 4 ++-- toxygen/contacts/group_factory.py | 5 ++--- toxygen/contacts/group_peer_contact.py | 4 ++-- toxygen/contacts/profile.py | 3 +-- toxygen/file_transfers/file_transfers.py | 8 ++------ 11 files changed, 22 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index f31ca4c..0a8182a 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ html Toxygen.egg-info *.tox .cache +*.db + diff --git a/toxygen/app.py b/toxygen/app.py index 60bb8bf..f3fd429 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -332,11 +332,11 @@ class App: db = Database(self._path.replace('.tox', '.db'), self._toxes) contact_items_factory = ContactItemsFactory(self._settings, self._ms) - self._friend_factory = FriendFactory(self._profile_manager, self._settings, + self._friend_factory = FriendFactory(self._settings, self._tox, db, contact_items_factory) - self._group_factory = GroupFactory(self._profile_manager, self._settings, self._tox, db, contact_items_factory) + self._group_factory = GroupFactory(self._settings, self._tox, db, contact_items_factory) self._contacts_provider = ContactProvider(self._tox, self._friend_factory, self._group_factory) - self._profile = Profile(self._profile_manager, self._tox, self._ms, self._contacts_provider, self._reset) + self._profile = Profile(self._tox, self._ms, self._contacts_provider, self._reset) self._plugin_loader = PluginLoader(self._tox, self._toxes, self._profile, self._settings) history = None messages_items_factory = MessagesItemsFactory(self._settings, self._plugin_loader, self._smiley_loader, diff --git a/toxygen/contacts/basecontact.py b/toxygen/contacts/basecontact.py index 0357809..0a7a456 100644 --- a/toxygen/contacts/basecontact.py +++ b/toxygen/contacts/basecontact.py @@ -14,14 +14,13 @@ class BaseContact: Base class for all contacts. """ - def __init__(self, profile_manager, name, status_message, widget, tox_id): + def __init__(self, name, status_message, widget, tox_id): """ :param name: name, example: 'Toxygen user' :param status_message: status message, example: 'Toxing on Toxygen' :param widget: ContactItem instance :param tox_id: tox id of contact """ - self._profile_manager = profile_manager self._name, self._status_message = name, status_message self._status, self._widget = None, widget self._tox_id = tox_id @@ -144,7 +143,7 @@ class BaseContact: return avatar_path def get_contact_avatar_path(self): - directory = util.join_path(self._profile_manager.get_dir(), 'avatars') + directory = util.join_path(Settings.get_default_path(), 'avatars') return util.join_path(directory, '{}.png'.format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])) diff --git a/toxygen/contacts/contact.py b/toxygen/contacts/contact.py index fb124dd..4969b73 100644 --- a/toxygen/contacts/contact.py +++ b/toxygen/contacts/contact.py @@ -12,12 +12,12 @@ class Contact(basecontact.BaseContact): Properties: number, message getter, history etc. Base class for friend and gc classes """ - def __init__(self, profile_manager, message_getter, number, name, status_message, widget, tox_id): + def __init__(self, message_getter, number, name, status_message, widget, tox_id): """ :param message_getter: gets messages from db :param number: number of friend. """ - super().__init__(profile_manager, name, status_message, widget, tox_id) + super().__init__(name, status_message, widget, tox_id) self._number = number self._new_messages = False self._visible = True diff --git a/toxygen/contacts/friend.py b/toxygen/contacts/friend.py index 5c8eabb..142185a 100644 --- a/toxygen/contacts/friend.py +++ b/toxygen/contacts/friend.py @@ -9,8 +9,8 @@ class Friend(contact.Contact): Friend in list of friends. """ - def __init__(self, profile_manager, message_getter, number, name, status_message, widget, tox_id): - super().__init__(profile_manager, message_getter, number, name, status_message, widget, tox_id) + def __init__(self, message_getter, number, name, status_message, widget, tox_id): + super().__init__(message_getter, number, name, status_message, widget, tox_id) self._receipts = 0 self._typing_notification_handler = common.FriendTypingNotificationHandler(number) diff --git a/toxygen/contacts/friend_factory.py b/toxygen/contacts/friend_factory.py index 8ebafd6..a85f4c9 100644 --- a/toxygen/contacts/friend_factory.py +++ b/toxygen/contacts/friend_factory.py @@ -4,9 +4,8 @@ from common.tox_save import ToxSave class FriendFactory(ToxSave): - def __init__(self, profile_manager, settings, tox, db, items_factory): + def __init__(self, settings, tox, db, items_factory): super().__init__(tox) - self._profile_manager = profile_manager self._settings = settings self._db = db self._items_factory = items_factory @@ -27,7 +26,7 @@ class FriendFactory(ToxSave): name = alias or self._tox.friend_get_name(friend_number) or tox_id status_message = self._tox.friend_get_status_message(friend_number) message_getter = self._db.messages_getter(tox_id) - friend = Friend(self._profile_manager, message_getter, friend_number, name, status_message, item, tox_id) + friend = Friend(message_getter, friend_number, name, status_message, item, tox_id) friend.set_alias(alias) return friend diff --git a/toxygen/contacts/group_chat.py b/toxygen/contacts/group_chat.py index b7429d4..0feed0f 100644 --- a/toxygen/contacts/group_chat.py +++ b/toxygen/contacts/group_chat.py @@ -8,8 +8,8 @@ from common.tox_save import ToxSave class GroupChat(contact.Contact, ToxSave): - def __init__(self, tox, profile_manager, message_getter, number, name, status_message, widget, tox_id): - super().__init__(profile_manager, message_getter, number, name, status_message, widget, tox_id) + def __init__(self, tox, message_getter, number, name, status_message, widget, tox_id): + super().__init__(message_getter, number, name, status_message, widget, tox_id) ToxSave.__init__(self, tox) self.set_status(constants.TOX_USER_STATUS['NONE']) self._peers = [] diff --git a/toxygen/contacts/group_factory.py b/toxygen/contacts/group_factory.py index 8db3e9a..0bd3285 100644 --- a/toxygen/contacts/group_factory.py +++ b/toxygen/contacts/group_factory.py @@ -4,9 +4,8 @@ from common.tox_save import ToxSave class GroupFactory(ToxSave): - def __init__(self, profile_manager, settings, tox, db, items_factory): + def __init__(self, settings, tox, db, items_factory): super().__init__(tox) - self._profile_manager = profile_manager self._settings = settings self._db = db self._items_factory = items_factory @@ -27,7 +26,7 @@ class GroupFactory(ToxSave): name = alias or self._tox.group_get_name(group_number) or tox_id status_message = self._tox.group_get_topic(group_number) message_getter = self._db.messages_getter(tox_id) - group = GroupChat(self._tox, self._profile_manager, message_getter, group_number, name, status_message, + group = GroupChat(self._tox, message_getter, group_number, name, status_message, item, tox_id) group.set_alias(alias) diff --git a/toxygen/contacts/group_peer_contact.py b/toxygen/contacts/group_peer_contact.py index 1c51f67..6480985 100644 --- a/toxygen/contacts/group_peer_contact.py +++ b/toxygen/contacts/group_peer_contact.py @@ -3,8 +3,8 @@ import contacts.contact class GroupPeerContact(contacts.contact.Contact): - def __init__(self, profile_manager, message_getter, peer_number, name, status_messsage, widget, tox_id, group_pk): - super().__init__(profile_manager, message_getter, peer_number, name, status_messsage, widget, tox_id) + def __init__(self, message_getter, peer_number, name, status_messsage, widget, tox_id, group_pk): + super().__init__(message_getter, peer_number, name, status_messsage, widget, tox_id) self._group_pk = group_pk def get_group_pk(self): diff --git a/toxygen/contacts/profile.py b/toxygen/contacts/profile.py index 3529be4..847039b 100644 --- a/toxygen/contacts/profile.py +++ b/toxygen/contacts/profile.py @@ -8,13 +8,12 @@ class Profile(basecontact.BaseContact, tox_save.ToxSave): """ Profile of current toxygen user. Contains friends list, tox instance """ - def __init__(self, profile_manager, tox, screen, contacts_provider, reset_action): + def __init__(self, tox, screen, contacts_provider, reset_action): """ :param tox: tox instance :param screen: ref to main screen """ basecontact.BaseContact.__init__(self, - profile_manager, tox.self_get_name(), tox.self_get_status_message(), screen.user_info, diff --git a/toxygen/file_transfers/file_transfers.py b/toxygen/file_transfers/file_transfers.py index 61a379f..46a777f 100644 --- a/toxygen/file_transfers/file_transfers.py +++ b/toxygen/file_transfers/file_transfers.py @@ -50,9 +50,6 @@ class FileTransfer: self._finished_event = Event() self._file_id = self._file = None - def set_tox(self, tox): - self._tox = tox - def set_state_changed_handler(self, handler): self._state_changed_event += handler @@ -344,11 +341,10 @@ class ReceiveAvatar(ReceiveTransfer): self.send_control(TOX_FILE_CONTROL['RESUME']) def write_chunk(self, position, data): - super().write_chunk(position, data) - if self.state: + if data is None: avatar_path = self._path[:-4] if exists(avatar_path): chdir(dirname(avatar_path)) remove(avatar_path) rename(self._path, avatar_path) - self._finished() + super().write_chunk(position, data)