From ae4eae92ae6ba6db699b27e266a652444c7f16f7 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 23 Sep 2018 13:04:27 +0300 Subject: [PATCH] minor bug fixes --- toxygen/app.py | 6 +++--- toxygen/contacts/basecontact.py | 2 +- toxygen/file_transfers/file_transfers_handler.py | 7 +++++-- toxygen/middleware/callbacks.py | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/toxygen/app.py b/toxygen/app.py index 4597d0a..a23816d 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -105,12 +105,12 @@ class App: def _stop_app(self): self._plugin_loader.stop() self._stop_threads() + self._file_transfer_handler.stop() self._tray.hide() self._save_profile() self._settings.close() self._kill_toxav() self._kill_tox() - del self._tox # ----------------------------------------------------------------------------------------------------------------- # App loading @@ -323,7 +323,6 @@ class App: self._save_profile(data) self._kill_toxav() self._kill_tox() - del self._tox # create new tox instance self._tox = self._create_tox(data) self._start_threads(False) @@ -398,7 +397,8 @@ class App: if updating: self._save_profile() self._settings.close() - del self._tox + self._kill_toxav() + self._kill_tox() return updating def _create_tox(self, data): diff --git a/toxygen/contacts/basecontact.py b/toxygen/contacts/basecontact.py index c64ffdb..2058890 100644 --- a/toxygen/contacts/basecontact.py +++ b/toxygen/contacts/basecontact.py @@ -126,7 +126,7 @@ class BaseContact: if os.path.isfile(avatar_path) and not avatar_path == self._get_default_avatar_path(): os.remove(avatar_path) if generate_new: - self.set_avatar(common.generate_avatar(self.tox_id)) + self.set_avatar(common.generate_avatar(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])) else: self.load_avatar() diff --git a/toxygen/file_transfers/file_transfers_handler.py b/toxygen/file_transfers/file_transfers_handler.py index cde1795..463152f 100644 --- a/toxygen/file_transfers/file_transfers_handler.py +++ b/toxygen/file_transfers/file_transfers_handler.py @@ -20,7 +20,7 @@ class FileTransfersHandler(ToxSave): profile.avatar_changed_event.add_callback(self._send_avatar_to_contacts) - def __del__(self): + def stop(self): self._settings['paused_file_transfers'] = self._paused_file_transfers if self._settings['resend_files'] else {} self._settings.save() @@ -259,13 +259,16 @@ class FileTransfersHandler(ToxSave): def _send_avatar_to_contacts(self, _): friends = self._get_all_friends() - for friend in friends: + for friend in filter(self._is_friend_online, friends): self.send_avatar(friend.number) # ----------------------------------------------------------------------------------------------------------------- # Private methods # ----------------------------------------------------------------------------------------------------------------- + def _is_friend_online(self, friend_number): + return self._get_friend_by_number(friend_number).status is not None + def _get_friend_by_number(self, friend_number): return self._contact_provider.get_friend_by_number(friend_number) diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index 77a029d..da94a7f 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -181,7 +181,7 @@ def tox_file_recv(window, tray, profile, file_transfer_handler, contacts_manager invoke_in_main_thread(tray_notification, file_from + ' ' + friend.name, file_name, tray, window) if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']: sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER']) - icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png') + icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png') invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon)) else: # AVATAR print('Avatar') @@ -371,7 +371,7 @@ def group_message(window, tray, tox, messenger, settings, profile): invoke_in_main_thread(tray_notification, name, message, tray, window) if settings['sound_notifications'] and bl and profile.status != TOX_USER_STATUS['BUSY']: sound_notification(SOUND_NOTIFICATION['MESSAGE']) - icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png') + icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png') invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon)) return wrapped @@ -392,7 +392,7 @@ def group_private_message(window, tray, tox, messenger, settings, profile): invoke_in_main_thread(tray_notification, name, message, tray, window) if settings['sound_notifications'] and bl and profile.status != TOX_USER_STATUS['BUSY']: sound_notification(SOUND_NOTIFICATION['MESSAGE']) - icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png') + icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png') invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon)) return wrapped @@ -411,7 +411,7 @@ def group_invite(window, settings, tray, profile, groups_service, contacts_provi title = util_ui.tr('New invite to group chat') text = util_ui.tr('{} invites you to group "{}"').format(friend.name, group_name) invoke_in_main_thread(tray_notification, title, text, tray, window) - icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png') + icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png') invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon)) return wrapped