From 0b1e899931f97ee559a16b8e809fedcf7f889439 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 17 May 2018 19:03:58 +0300 Subject: [PATCH] various fixes - file transfers, friend exit callback --- toxygen/av/calls_manager.py | 18 +++++++++------- toxygen/contacts/contact_menu.py | 3 ++- toxygen/contacts/profile.py | 21 ------------------- .../file_transfers/file_transfers_handler.py | 13 +++++++++++- toxygen/middleware/callbacks.py | 10 ++++++--- 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/toxygen/av/calls_manager.py b/toxygen/av/calls_manager.py index 03d5c53..6e290e2 100644 --- a/toxygen/av/calls_manager.py +++ b/toxygen/av/calls_manager.py @@ -1,7 +1,7 @@ import threading import cv2 import av.calls -from PyQt5 import QtWidgets +import utils.ui as util_ui from messenger.messages import * import time from ui import av_widgets @@ -35,9 +35,9 @@ class CallsManager: self._call(num, audio, video) self._screen.active_call() if video: - text = QtWidgets.QApplication.translate("incoming_call", "Outgoing video call") + text = util_ui.tr("Outgoing video call") else: - text = QtWidgets.QApplication.translate("incoming_call", "Outgoing audio call") + text = util_ui.tr("Outgoing audio call") self.get_curr_friend().append_message(InfoMessage(text, time.time())) self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE']) self._messages.scrollToBottom() @@ -52,9 +52,9 @@ class CallsManager: return friend = self.get_friend_by_number(friend_number) if video: - text = QtWidgets.QApplication.translate("incoming_call", "Incoming video call") + text = util_ui.tr("Incoming video call") else: - text = QtWidgets.QApplication.translate("incoming_call", "Incoming audio call") + text = util_ui.tr("Incoming audio call") friend.append_message(InfoMessage(text, time.time())) self._incoming_calls.add(friend_number) if friend_number == self.get_active_number(): @@ -83,9 +83,9 @@ class CallsManager: """ if friend_number in self._incoming_calls: self._incoming_calls.remove(friend_number) - text = QtWidgets.QApplication.translate("incoming_call", "Call declined") + text = util_ui.tr("Call declined") else: - text = QtWidgets.QApplication.translate("incoming_call", "Call finished") + text = util_ui.tr("Call finished") self._screen.call_finished() is_video = self._call.is_video_call(friend_number) self._call.finish_call(friend_number, by_friend) # finish or decline call @@ -103,3 +103,7 @@ class CallsManager: if friend_number == self.get_active_number(): self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE']) self._messages.scrollToBottom() + + def friend_exit(self, friend_number): + if friend_number in self._call: + self._call.finish_call(friend_number, True) diff --git a/toxygen/contacts/contact_menu.py b/toxygen/contacts/contact_menu.py index 8047392..c580a3f 100644 --- a/toxygen/contacts/contact_menu.py +++ b/toxygen/contacts/contact_menu.py @@ -32,7 +32,8 @@ class ContactMenuBuilder: def with_actions(self, actions): for action in actions: - self._add_action(*action) + (text, handler) = action + self._add_action(text, handler) return self diff --git a/toxygen/contacts/profile.py b/toxygen/contacts/profile.py index 63775ff..4edae71 100644 --- a/toxygen/contacts/profile.py +++ b/toxygen/contacts/profile.py @@ -75,27 +75,6 @@ class Profile(basecontact.BaseContact): return self._tox_id - # ----------------------------------------------------------------------------------------------------------------- - # Friend connection status callbacks - # ----------------------------------------------------------------------------------------------------------------- - - def friend_exit(self, friend_number): - """ - Friend with specified number quit - """ - self.get_friend_by_number(friend_number).status = None - self.friend_typing(friend_number, False) - if friend_number in self._call: - self._call.finish_call(friend_number, True) - for friend_num, file_num in list(self._file_transfers.keys()): - if friend_num == friend_number: - ft = self._file_transfers[(friend_num, file_num)] - if type(ft) is SendTransfer: - self._paused_file_transfers[ft.get_id()] = [ft.get_path(), friend_num, False, -1] - elif type(ft) is ReceiveTransfer and ft.state != FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']: - self._paused_file_transfers[ft.get_id()] = [ft.get_path(), friend_num, True, ft.total_size()] - self.cancel_transfer(friend_num, file_num, True) - # ----------------------------------------------------------------------------------------------------------------- # Private messages # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/file_transfers/file_transfers_handler.py b/toxygen/file_transfers/file_transfers_handler.py index bb4041f..d060ae7 100644 --- a/toxygen/file_transfers/file_transfers_handler.py +++ b/toxygen/file_transfers/file_transfers_handler.py @@ -118,7 +118,8 @@ class FileTransfersHandler: rt = ReceiveToBuffer(self._tox, friend_number, size, file_number) rt.set_transfer_finished_handler(self.transfer_finished) message = friend.get_message(lambda m: m.type == MESSAGE_TYPE['FILE_TRANSFER'] - and m.state == FILE_TRANSFER_STATE['INCOMING_NOT_STARTED'] + and m.state in (FILE_TRANSFER_STATE['INCOMING_NOT_STARTED'], + FILE_TRANSFER_STATE['RUNNING']) and m.file_number == file_number) rt.set_state_changed_handler(message.transfer_updated) self._file_transfers[(friend_number, file_number)] = rt @@ -214,6 +215,16 @@ class FileTransfersHandler: except Exception as ex: print('Exception in file sending: ' + str(ex)) + def friend_exit(self, friend_number): + for friend_num, file_num in list(self._file_transfers.keys()): + if friend_num == friend_number: + ft = self._file_transfers[(friend_num, file_num)] + if type(ft) is SendTransfer: + self._paused_file_transfers[ft.get_id()] = [ft.get_path(), friend_num, False, -1] + elif type(ft) is ReceiveTransfer and ft.state != FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']: + self._paused_file_transfers[ft.get_id()] = [ft.get_path(), friend_num, True, ft.total_size()] + self.cancel_transfer(friend_num, file_num, True) + # ----------------------------------------------------------------------------------------------------------------- # Avatars support # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index d4fc7c4..860070f 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -60,7 +60,8 @@ def friend_status(contacts_manager, file_transfer_handler, profile, settings): return wrapped -def friend_connection_status(contacts_manager, profile, settings, plugin_loader, file_transfer_handler): +def friend_connection_status(contacts_manager, profile, settings, plugin_loader, file_transfer_handler, + messenger, calls_manager): def wrapped(tox, friend_number, new_status, user_data): """ Check friend's connection status (offline, udp, tcp) @@ -68,8 +69,11 @@ def friend_connection_status(contacts_manager, profile, settings, plugin_loader, print("Friend #{} connection status: {}".format(friend_number, new_status)) friend = contacts_manager.get_friend_by_number(friend_number) if new_status == TOX_CONNECTION['NONE']: - invoke_in_main_thread(profile.friend_exit, friend_number) + invoke_in_main_thread(friend.set_status, None) + invoke_in_main_thread(file_transfer_handler.friend_exit, friend_number) invoke_in_main_thread(contacts_manager.update_filtration) + invoke_in_main_thread(messenger.friend_typing, friend_number, False) + invoke_in_main_thread(calls_manager.friend_exit, friend_number) if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']: sound_notification(SOUND_NOTIFICATION['FRIEND_CONNECTION_STATUS']) elif friend.status is None: @@ -394,7 +398,7 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager, tox.callback_friend_status(friend_status(contacts_manager, file_transfer_handler, profile, settings), 0) tox.callback_friend_message(friend_message(messenger, contacts_manager, profile, settings, main_window, tray), 0) tox.callback_friend_connection_status(friend_connection_status(contacts_manager, profile, settings, plugin_loader, - file_transfer_handler), 0) + file_transfer_handler, messenger, calls_manager), 0) tox.callback_friend_name(friend_name(contacts_manager), 0) tox.callback_friend_status_message(friend_status_message(contacts_manager, messenger), 0) tox.callback_friend_request(friend_request(contacts_manager), 0)