file transfer item update #3. bug fixes
This commit is contained in:
parent
01803a6376
commit
6a2bc1f650
@ -177,6 +177,7 @@ def file_chunk_request(tox, friend_number, file_number, position, size, user_dat
|
||||
|
||||
|
||||
def file_recv_control(tox, friend_number, file_number, file_control, user_data):
|
||||
# TODO: process
|
||||
pass
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -16,7 +16,7 @@ TOX_FILE_TRANSFER_STATE = {
|
||||
|
||||
|
||||
class Signal(QtCore.QObject):
|
||||
signal = QtCore.Signal(int)
|
||||
signal = QtCore.Signal(str)
|
||||
|
||||
|
||||
class FileTransfer(QtCore.QObject):
|
||||
@ -46,7 +46,7 @@ class FileTransfer(QtCore.QObject):
|
||||
def cancel(self):
|
||||
self.send_control(TOX_FILE_CONTROL['CANCEL'])
|
||||
self._file.close()
|
||||
self._signal.signal.emit(1) # other signal params - status and %?
|
||||
self._signal.signal.emit('{} {}'.format(self.state, 0))
|
||||
|
||||
def send_control(self, control):
|
||||
if self._tox.file_control(self._friend_number, self._file_number, control):
|
||||
@ -76,11 +76,12 @@ class SendTransfer(FileTransfer):
|
||||
if size:
|
||||
self._file.seek(position)
|
||||
data = self._file.read(size)
|
||||
return self._tox.file_send_chunk(self._friend_number, self._file_number, position, data)
|
||||
self._tox.file_send_chunk(self._friend_number, self._file_number, position, data)
|
||||
self._signal.signal.emit('{} {}'.format(self.state, 0))
|
||||
else:
|
||||
self._file.close()
|
||||
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
||||
self._signal.signal.emit(position)
|
||||
self._signal.signal.emit('{} {}'.format(self.state, 100))
|
||||
|
||||
|
||||
class SendAvatar(SendTransfer):
|
||||
@ -117,10 +118,11 @@ class ReceiveTransfer(FileTransfer):
|
||||
self._file.flush()
|
||||
if position + len(data) > self._size:
|
||||
self._size = position + len(data)
|
||||
self._signal.signal.emit('{} {}'.format(self.state, 0))
|
||||
else:
|
||||
self._file.close()
|
||||
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
||||
self._signal.signal.emit(position)
|
||||
self._signal.signal.emit('{} {}'.format(self.state, 100))
|
||||
|
||||
|
||||
class ReceiveAvatar(ReceiveTransfer):
|
||||
|
@ -1,6 +1,7 @@
|
||||
from toxcore_enums_and_consts import *
|
||||
from PySide import QtGui, QtCore
|
||||
import profile
|
||||
from file_transfers import TOX_FILE_TRANSFER_STATE
|
||||
from util import curr_directory
|
||||
|
||||
|
||||
@ -215,10 +216,10 @@ class FileTransferItem(QtGui.QListWidget):
|
||||
def cancel_transfer(self, friend_number, file_number):
|
||||
pr = profile.Profile.get_instance()
|
||||
pr.cancel_transfer(friend_number, file_number)
|
||||
self.name.setText('Cancelled')
|
||||
self.setStyleSheet('QListWidget { background-color: red; }')
|
||||
self.cancel.setVisible(False)
|
||||
self.accept.setVisible(False)
|
||||
self.pb.setVisible(False)
|
||||
|
||||
def accept_transfer(self, friend_number, file_number):
|
||||
directory = QtGui.QFileDialog.getExistingDirectory()
|
||||
@ -229,6 +230,14 @@ class FileTransferItem(QtGui.QListWidget):
|
||||
|
||||
@QtCore.Slot(str)
|
||||
def update(self, data):
|
||||
# TODO: add params - status and %
|
||||
self.name.setText('Finished')
|
||||
arr = data.split()
|
||||
self.pb.setValue(int(arr[1]))
|
||||
if int(arr[0]) == TOX_FILE_TRANSFER_STATE['CANCELED']:
|
||||
self.setStyleSheet('QListWidget { background-color: red; }')
|
||||
self.cancel.setVisible(False)
|
||||
self.accept.setVisible(False)
|
||||
self.pb.setVisible(False)
|
||||
elif int(arr[0]) == TOX_FILE_TRANSFER_STATE['FINISHED']:
|
||||
self.pb.setVisible(False)
|
||||
self.cancel.setVisible(False)
|
||||
print data
|
||||
|
@ -749,12 +749,13 @@ class Profile(Contact, Singleton):
|
||||
self.get_friend_by_number(friend_number).load_avatar()
|
||||
|
||||
def incoming_chunk(self, friend_number, file_number, position, data):
|
||||
transfer = self._file_transfers[(friend_number, file_number)]
|
||||
transfer.write_chunk(position, data)
|
||||
if transfer.state:
|
||||
if type(transfer) is ReceiveAvatar:
|
||||
self.get_friend_by_number(friend_number).load_avatar()
|
||||
del self._file_transfers[(friend_number, file_number)]
|
||||
if (friend_number, file_number) in self._file_transfers:
|
||||
transfer = self._file_transfers[(friend_number, file_number)]
|
||||
transfer.write_chunk(position, data)
|
||||
if transfer.state:
|
||||
if type(transfer) is ReceiveAvatar:
|
||||
self.get_friend_by_number(friend_number).load_avatar()
|
||||
del self._file_transfers[(friend_number, file_number)]
|
||||
|
||||
def send_avatar(self, friend_number):
|
||||
avatar_path = (ProfileHelper.get_path() + 'avatars/{}.png').format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])
|
||||
@ -767,14 +768,15 @@ class Profile(Contact, Singleton):
|
||||
friend_number = self.get_active_number()
|
||||
st = SendTransfer(path, self._tox, friend_number)
|
||||
self._file_transfers[(friend_number, st.get_file_number())] = st
|
||||
item = self.create_file_transfer_item('Out file', friend_number, st.get_file_number(), False)
|
||||
item = self.create_file_transfer_item(os.path.basename(path), os.path.getsize(path), friend_number, st.get_file_number(), False)
|
||||
st.set_event_handler(item.update)
|
||||
|
||||
def outgoing_chunk(self, friend_number, file_number, position, size):
|
||||
transfer = self._file_transfers[(friend_number, file_number)]
|
||||
transfer.send_chunk(position, size)
|
||||
if transfer.state:
|
||||
del self._file_transfers[(friend_number, file_number)]
|
||||
if (friend_number, file_number) in self._file_transfers:
|
||||
transfer = self._file_transfers[(friend_number, file_number)]
|
||||
transfer.send_chunk(position, size)
|
||||
if transfer.state:
|
||||
del self._file_transfers[(friend_number, file_number)]
|
||||
|
||||
def reset_avatar(self):
|
||||
super(Profile, self).reset_avatar()
|
||||
|
Loading…
Reference in New Issue
Block a user