From 1bb145728f1167c5c7d0f28c5488b19d2b481d51 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 17 Mar 2016 23:49:27 +0300 Subject: [PATCH] sending updates --- src/callbacks.py | 15 +++++++++++++++ src/mainscreen.py | 2 +- src/profile.py | 12 +++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index 548a5b4..df63bde 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -164,6 +164,19 @@ def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, us file_number, position, chunk[:length] if length else None) + + +def file_chunk_request(tox, friend_number, file_number, position, size, user_data): + invoke_in_main_thread(Profile.get_instance().outgoing_chunck, + friend_number, + file_number, + position, + size) + + +def file_recv_control(tox, friend_number, file_number, file_control, user_data): + pass + # ----------------------------------------------------------------------------------------------------------------- # Callbacks - initialization # ----------------------------------------------------------------------------------------------------------------- @@ -187,3 +200,5 @@ def init_callbacks(tox, window, tray): tox.callback_file_recv(tox_file_recv(window, tray), 0) tox.callback_file_recv_chunk(file_recv_chunk, 0) + tox.callback_file_chunk_request(file_chunk_request, 0) + tox.callback_file_recv_control(file_recv_control, 0) diff --git a/src/mainscreen.py b/src/mainscreen.py index 93a1c43..be1f550 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -280,7 +280,7 @@ class MainWindow(QtGui.QMainWindow): if self.profile.is_active_online(): # active friend exists and online name = QtGui.QFileDialog.getOpenFileName(self, 'Choose file') if name: - self.profile.send_file(name) + self.profile.send_file(name[0]) # ----------------------------------------------------------------------------------------------------------------- # Functions which called when user open context menu in friends list diff --git a/src/profile.py b/src/profile.py index 9fc3720..cc6966b 100644 --- a/src/profile.py +++ b/src/profile.py @@ -704,7 +704,7 @@ class Profile(Contact, Singleton): # ----------------------------------------------------------------------------------------------------------------- def incoming_file_transfer(self, friend_number, file_number, size, file_name): - rt = ReceiveTransfer(Settings.get_default_path() + file_name, self._tox, friend_number) + rt = ReceiveTransfer(Settings.get_default_path() + file_name, self._tox, friend_number, file_number) self._file_transfers[(friend_number, file_number)] = rt self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME']) @@ -726,7 +726,7 @@ class Profile(Contact, Singleton): self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) # ignore file else: # get new avatar path = ProfileHelper.get_path() + '/avatars/{}.png'.format(friend.tox_id) - rt = ReceiveTransfer(path, self._tox, friend_number) + rt = ReceiveTransfer(path, self._tox, friend_number, file_number) self._file_transfers[(friend_number, file_number)] = rt self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME']) @@ -742,7 +742,13 @@ class Profile(Contact, Singleton): pass def send_file(self, path): - pass + friend_number = self.get_active_number() + st = SendTransfer(path, self._tox, friend_number) + self._file_transfers[(friend_number, st.get_file_number())] = st + + def outgoing_chunk(self, friend_number, file_number, position, size): + transfer = self._file_transfers[(friend_number, file_number)] + transfer.send_chunk(position, size) def tox_factory(data=None, settings=None):