file transfer item update #3. bug fixes

This commit is contained in:
ingvar1995 2016-03-19 23:36:54 +03:00
parent 01803a6376
commit 6a2bc1f650
4 changed files with 33 additions and 19 deletions

View file

@ -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): def file_recv_control(tox, friend_number, file_number, file_control, user_data):
# TODO: process
pass pass
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------

View file

@ -16,7 +16,7 @@ TOX_FILE_TRANSFER_STATE = {
class Signal(QtCore.QObject): class Signal(QtCore.QObject):
signal = QtCore.Signal(int) signal = QtCore.Signal(str)
class FileTransfer(QtCore.QObject): class FileTransfer(QtCore.QObject):
@ -46,7 +46,7 @@ class FileTransfer(QtCore.QObject):
def cancel(self): def cancel(self):
self.send_control(TOX_FILE_CONTROL['CANCEL']) self.send_control(TOX_FILE_CONTROL['CANCEL'])
self._file.close() 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): def send_control(self, control):
if self._tox.file_control(self._friend_number, self._file_number, control): if self._tox.file_control(self._friend_number, self._file_number, control):
@ -76,11 +76,12 @@ class SendTransfer(FileTransfer):
if size: if size:
self._file.seek(position) self._file.seek(position)
data = self._file.read(size) 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: else:
self._file.close() self._file.close()
self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
self._signal.signal.emit(position) self._signal.signal.emit('{} {}'.format(self.state, 100))
class SendAvatar(SendTransfer): class SendAvatar(SendTransfer):
@ -117,10 +118,11 @@ class ReceiveTransfer(FileTransfer):
self._file.flush() self._file.flush()
if position + len(data) > self._size: if position + len(data) > self._size:
self._size = position + len(data) self._size = position + len(data)
self._signal.signal.emit('{} {}'.format(self.state, 0))
else: else:
self._file.close() self._file.close()
self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
self._signal.signal.emit(position) self._signal.signal.emit('{} {}'.format(self.state, 100))
class ReceiveAvatar(ReceiveTransfer): class ReceiveAvatar(ReceiveTransfer):

View file

@ -1,6 +1,7 @@
from toxcore_enums_and_consts import * from toxcore_enums_and_consts import *
from PySide import QtGui, QtCore from PySide import QtGui, QtCore
import profile import profile
from file_transfers import TOX_FILE_TRANSFER_STATE
from util import curr_directory from util import curr_directory
@ -215,10 +216,10 @@ class FileTransferItem(QtGui.QListWidget):
def cancel_transfer(self, friend_number, file_number): def cancel_transfer(self, friend_number, file_number):
pr = profile.Profile.get_instance() pr = profile.Profile.get_instance()
pr.cancel_transfer(friend_number, file_number) pr.cancel_transfer(friend_number, file_number)
self.name.setText('Cancelled')
self.setStyleSheet('QListWidget { background-color: red; }') self.setStyleSheet('QListWidget { background-color: red; }')
self.cancel.setVisible(False) self.cancel.setVisible(False)
self.accept.setVisible(False) self.accept.setVisible(False)
self.pb.setVisible(False)
def accept_transfer(self, friend_number, file_number): def accept_transfer(self, friend_number, file_number):
directory = QtGui.QFileDialog.getExistingDirectory() directory = QtGui.QFileDialog.getExistingDirectory()
@ -229,6 +230,14 @@ class FileTransferItem(QtGui.QListWidget):
@QtCore.Slot(str) @QtCore.Slot(str)
def update(self, data): def update(self, data):
# TODO: add params - status and % arr = data.split()
self.name.setText('Finished') 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 print data

View file

@ -749,6 +749,7 @@ class Profile(Contact, Singleton):
self.get_friend_by_number(friend_number).load_avatar() self.get_friend_by_number(friend_number).load_avatar()
def incoming_chunk(self, friend_number, file_number, position, data): def incoming_chunk(self, friend_number, file_number, position, data):
if (friend_number, file_number) in self._file_transfers:
transfer = self._file_transfers[(friend_number, file_number)] transfer = self._file_transfers[(friend_number, file_number)]
transfer.write_chunk(position, data) transfer.write_chunk(position, data)
if transfer.state: if transfer.state:
@ -767,10 +768,11 @@ class Profile(Contact, Singleton):
friend_number = self.get_active_number() friend_number = self.get_active_number()
st = SendTransfer(path, self._tox, friend_number) st = SendTransfer(path, self._tox, friend_number)
self._file_transfers[(friend_number, st.get_file_number())] = st 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) st.set_event_handler(item.update)
def outgoing_chunk(self, friend_number, file_number, position, size): def outgoing_chunk(self, friend_number, file_number, position, size):
if (friend_number, file_number) in self._file_transfers:
transfer = self._file_transfers[(friend_number, file_number)] transfer = self._file_transfers[(friend_number, file_number)]
transfer.send_chunk(position, size) transfer.send_chunk(position, size)
if transfer.state: if transfer.state: