various fixes - file transfers, friend exit callback
This commit is contained in:
parent
bcefe9bc79
commit
0b1e899931
5 changed files with 32 additions and 33 deletions
|
@ -1,7 +1,7 @@
|
||||||
import threading
|
import threading
|
||||||
import cv2
|
import cv2
|
||||||
import av.calls
|
import av.calls
|
||||||
from PyQt5 import QtWidgets
|
import utils.ui as util_ui
|
||||||
from messenger.messages import *
|
from messenger.messages import *
|
||||||
import time
|
import time
|
||||||
from ui import av_widgets
|
from ui import av_widgets
|
||||||
|
@ -35,9 +35,9 @@ class CallsManager:
|
||||||
self._call(num, audio, video)
|
self._call(num, audio, video)
|
||||||
self._screen.active_call()
|
self._screen.active_call()
|
||||||
if video:
|
if video:
|
||||||
text = QtWidgets.QApplication.translate("incoming_call", "Outgoing video call")
|
text = util_ui.tr("Outgoing video call")
|
||||||
else:
|
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.get_curr_friend().append_message(InfoMessage(text, time.time()))
|
||||||
self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
|
@ -52,9 +52,9 @@ class CallsManager:
|
||||||
return
|
return
|
||||||
friend = self.get_friend_by_number(friend_number)
|
friend = self.get_friend_by_number(friend_number)
|
||||||
if video:
|
if video:
|
||||||
text = QtWidgets.QApplication.translate("incoming_call", "Incoming video call")
|
text = util_ui.tr("Incoming video call")
|
||||||
else:
|
else:
|
||||||
text = QtWidgets.QApplication.translate("incoming_call", "Incoming audio call")
|
text = util_ui.tr("Incoming audio call")
|
||||||
friend.append_message(InfoMessage(text, time.time()))
|
friend.append_message(InfoMessage(text, time.time()))
|
||||||
self._incoming_calls.add(friend_number)
|
self._incoming_calls.add(friend_number)
|
||||||
if friend_number == self.get_active_number():
|
if friend_number == self.get_active_number():
|
||||||
|
@ -83,9 +83,9 @@ class CallsManager:
|
||||||
"""
|
"""
|
||||||
if friend_number in self._incoming_calls:
|
if friend_number in self._incoming_calls:
|
||||||
self._incoming_calls.remove(friend_number)
|
self._incoming_calls.remove(friend_number)
|
||||||
text = QtWidgets.QApplication.translate("incoming_call", "Call declined")
|
text = util_ui.tr("Call declined")
|
||||||
else:
|
else:
|
||||||
text = QtWidgets.QApplication.translate("incoming_call", "Call finished")
|
text = util_ui.tr("Call finished")
|
||||||
self._screen.call_finished()
|
self._screen.call_finished()
|
||||||
is_video = self._call.is_video_call(friend_number)
|
is_video = self._call.is_video_call(friend_number)
|
||||||
self._call.finish_call(friend_number, by_friend) # finish or decline call
|
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():
|
if friend_number == self.get_active_number():
|
||||||
self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
self.create_message_item(text, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
|
|
||||||
|
def friend_exit(self, friend_number):
|
||||||
|
if friend_number in self._call:
|
||||||
|
self._call.finish_call(friend_number, True)
|
||||||
|
|
|
@ -32,7 +32,8 @@ class ContactMenuBuilder:
|
||||||
|
|
||||||
def with_actions(self, actions):
|
def with_actions(self, actions):
|
||||||
for action in actions:
|
for action in actions:
|
||||||
self._add_action(*action)
|
(text, handler) = action
|
||||||
|
self._add_action(text, handler)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
@ -75,27 +75,6 @@ class Profile(basecontact.BaseContact):
|
||||||
|
|
||||||
return self._tox_id
|
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
|
# Private messages
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -118,7 +118,8 @@ class FileTransfersHandler:
|
||||||
rt = ReceiveToBuffer(self._tox, friend_number, size, file_number)
|
rt = ReceiveToBuffer(self._tox, friend_number, size, file_number)
|
||||||
rt.set_transfer_finished_handler(self.transfer_finished)
|
rt.set_transfer_finished_handler(self.transfer_finished)
|
||||||
message = friend.get_message(lambda m: m.type == MESSAGE_TYPE['FILE_TRANSFER']
|
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)
|
and m.file_number == file_number)
|
||||||
rt.set_state_changed_handler(message.transfer_updated)
|
rt.set_state_changed_handler(message.transfer_updated)
|
||||||
self._file_transfers[(friend_number, file_number)] = rt
|
self._file_transfers[(friend_number, file_number)] = rt
|
||||||
|
@ -214,6 +215,16 @@ class FileTransfersHandler:
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print('Exception in file sending: ' + str(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
|
# Avatars support
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -60,7 +60,8 @@ def friend_status(contacts_manager, file_transfer_handler, profile, settings):
|
||||||
return wrapped
|
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):
|
def wrapped(tox, friend_number, new_status, user_data):
|
||||||
"""
|
"""
|
||||||
Check friend's connection status (offline, udp, tcp)
|
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))
|
print("Friend #{} connection status: {}".format(friend_number, new_status))
|
||||||
friend = contacts_manager.get_friend_by_number(friend_number)
|
friend = contacts_manager.get_friend_by_number(friend_number)
|
||||||
if new_status == TOX_CONNECTION['NONE']:
|
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(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']:
|
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
sound_notification(SOUND_NOTIFICATION['FRIEND_CONNECTION_STATUS'])
|
sound_notification(SOUND_NOTIFICATION['FRIEND_CONNECTION_STATUS'])
|
||||||
elif friend.status is None:
|
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_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_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,
|
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_name(friend_name(contacts_manager), 0)
|
||||||
tox.callback_friend_status_message(friend_status_message(contacts_manager, messenger), 0)
|
tox.callback_friend_status_message(friend_status_message(contacts_manager, messenger), 0)
|
||||||
tox.callback_friend_request(friend_request(contacts_manager), 0)
|
tox.callback_friend_request(friend_request(contacts_manager), 0)
|
||||||
|
|
Loading…
Reference in a new issue