file resuming support
This commit is contained in:
parent
0e103749a2
commit
81660a9ad4
@ -12,6 +12,7 @@ TOX_FILE_TRANSFER_STATE = {
|
|||||||
'PAUSED': 1,
|
'PAUSED': 1,
|
||||||
'CANCELED': 2,
|
'CANCELED': 2,
|
||||||
'FINISHED': 3,
|
'FINISHED': 3,
|
||||||
|
'PAUSED_BY_FRIEND': 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,6 +68,8 @@ class FileTransfer(QtCore.QObject):
|
|||||||
def pause(self, by_friend):
|
def pause(self, by_friend):
|
||||||
if not by_friend:
|
if not by_friend:
|
||||||
self.send_control(TOX_FILE_CONTROL['PAUSE'])
|
self.send_control(TOX_FILE_CONTROL['PAUSE'])
|
||||||
|
else:
|
||||||
|
self.state = TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND']
|
||||||
self.signal()
|
self.signal()
|
||||||
|
|
||||||
def send_control(self, control):
|
def send_control(self, control):
|
||||||
|
@ -145,6 +145,8 @@ class FileTransferItem(QtGui.QListWidget):
|
|||||||
else:
|
else:
|
||||||
self.setStyleSheet('QWidget { background-color: #B40404; }')
|
self.setStyleSheet('QWidget { background-color: #B40404; }')
|
||||||
|
|
||||||
|
self.state = state
|
||||||
|
|
||||||
self.name = DataLabel(self)
|
self.name = DataLabel(self)
|
||||||
self.name.setGeometry(QtCore.QRect(1, 15, 95, 20))
|
self.name.setGeometry(QtCore.QRect(1, 15, 95, 20))
|
||||||
self.name.setTextFormat(QtCore.Qt.PlainText)
|
self.name.setTextFormat(QtCore.Qt.PlainText)
|
||||||
@ -174,15 +176,22 @@ class FileTransferItem(QtGui.QListWidget):
|
|||||||
self.cancel.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number))
|
self.cancel.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number))
|
||||||
self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; }')
|
self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; }')
|
||||||
|
|
||||||
self.accept = QtGui.QPushButton(self)
|
self.accept_or_pause = QtGui.QPushButton(self)
|
||||||
self.accept.setGeometry(QtCore.QRect(450, 2, 46, 46))
|
self.accept_or_pause.setGeometry(QtCore.QRect(450, 2, 46, 46))
|
||||||
pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png')
|
if state == FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED']:
|
||||||
icon = QtGui.QIcon(pixmap)
|
self.accept_or_pause.setVisible(True)
|
||||||
self.accept.setIcon(icon)
|
self.button_update('accept')
|
||||||
self.accept.setIconSize(QtCore.QSize(30, 30))
|
elif state in (0, 1, 5):
|
||||||
self.accept.clicked.connect(lambda: self.accept_transfer(friend_number, file_number, size))
|
self.accept_or_pause.setVisible(False)
|
||||||
self.accept.setVisible(state == FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED'])
|
elif state == FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_USER']: # setup for continue
|
||||||
self.accept.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; }')
|
self.accept_or_pause.setVisible(True)
|
||||||
|
self.button_update('resume')
|
||||||
|
else: # pause
|
||||||
|
self.accept_or_pause.setVisible(True)
|
||||||
|
self.button_update('pause')
|
||||||
|
self.accept_or_pause.clicked.connect(lambda: self.accept_or_pause_transfer(friend_number, file_number, size))
|
||||||
|
|
||||||
|
self.accept_or_pause.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; }')
|
||||||
|
|
||||||
self.pb = QtGui.QProgressBar(self)
|
self.pb = QtGui.QProgressBar(self)
|
||||||
self.pb.setGeometry(QtCore.QRect(100, 15, 100, 20))
|
self.pb.setGeometry(QtCore.QRect(100, 15, 100, 20))
|
||||||
@ -212,27 +221,56 @@ class FileTransferItem(QtGui.QListWidget):
|
|||||||
pr.cancel_transfer(friend_number, file_number)
|
pr.cancel_transfer(friend_number, file_number)
|
||||||
self.setStyleSheet('QListWidget { background-color: #B40404; }')
|
self.setStyleSheet('QListWidget { background-color: #B40404; }')
|
||||||
self.cancel.setVisible(False)
|
self.cancel.setVisible(False)
|
||||||
self.accept.setVisible(False)
|
self.accept_or_pause.setVisible(False)
|
||||||
self.pb.setVisible(False)
|
self.pb.setVisible(False)
|
||||||
|
|
||||||
def accept_transfer(self, friend_number, file_number, size):
|
def accept_or_pause_transfer(self, friend_number, file_number, size):
|
||||||
directory = QtGui.QFileDialog.getExistingDirectory()
|
if self.state == FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED']:
|
||||||
if directory:
|
directory = QtGui.QFileDialog.getExistingDirectory()
|
||||||
pr = profile.Profile.get_instance()
|
if directory:
|
||||||
pr.accept_transfer(self, directory + '/' + self.saved_name, friend_number, file_number, size)
|
pr = profile.Profile.get_instance()
|
||||||
self.accept.setVisible(False)
|
pr.accept_transfer(self, directory + '/' + self.saved_name, friend_number, file_number, size)
|
||||||
|
self.button_update('pause')
|
||||||
|
elif self.state == FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_USER']: # resume
|
||||||
|
profile.Profile.get_instance().resume_transfer(friend_number, file_number)
|
||||||
|
else: # pause
|
||||||
|
profile.Profile.get_instance().pause_transfer(friend_number, file_number)
|
||||||
|
self.state = FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_USER']
|
||||||
|
self.accept_or_pause.clearFocus()
|
||||||
|
|
||||||
|
def button_update(self, path):
|
||||||
|
pixmap = QtGui.QPixmap(curr_directory() + '/images/{}.png'.format(path))
|
||||||
|
icon = QtGui.QIcon(pixmap)
|
||||||
|
self.accept_or_pause.setIcon(icon)
|
||||||
|
self.accept_or_pause.setIconSize(QtCore.QSize(30, 30))
|
||||||
|
|
||||||
|
def convert(self, state):
|
||||||
|
# convert TOX_FILE_TRANSFER_STATE to FILE_TRANSFER_MESSAGE_STATUS
|
||||||
|
d = {0: 2, 1: 6, 2: 1, 3: 0, 4: 5}
|
||||||
|
return d[state]
|
||||||
|
|
||||||
@QtCore.Slot(int, float)
|
@QtCore.Slot(int, float)
|
||||||
def update(self, state, progress):
|
def update(self, state, progress):
|
||||||
self.pb.setValue(int(progress * 100))
|
self.pb.setValue(int(progress * 100))
|
||||||
if state == TOX_FILE_TRANSFER_STATE['CANCELED']:
|
state = self.convert(state)
|
||||||
self.setStyleSheet('QListWidget { background-color: #B40404; }')
|
if self.state != state:
|
||||||
self.cancel.setVisible(False)
|
if state == FILE_TRANSFER_MESSAGE_STATUS['CANCELLED']:
|
||||||
self.accept.setVisible(False)
|
self.setStyleSheet('QListWidget { background-color: #B40404; }')
|
||||||
self.pb.setVisible(False)
|
self.cancel.setVisible(False)
|
||||||
elif state == TOX_FILE_TRANSFER_STATE['FINISHED']:
|
self.accept_or_pause.setVisible(False)
|
||||||
self.pb.setVisible(False)
|
self.pb.setVisible(False)
|
||||||
self.cancel.setVisible(False)
|
elif state == FILE_TRANSFER_MESSAGE_STATUS['FINISHED']:
|
||||||
|
self.accept_or_pause.setVisible(False)
|
||||||
|
self.pb.setVisible(False)
|
||||||
|
self.cancel.setVisible(False)
|
||||||
|
elif state == FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_FRIEND']:
|
||||||
|
self.accept_or_pause.setVisible(False)
|
||||||
|
elif state == FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_USER']:
|
||||||
|
self.button_update('resume') # setup button continue
|
||||||
|
else: # active
|
||||||
|
self.accept_or_pause.setVisible(True) # setup to pause
|
||||||
|
self.button_update('pause')
|
||||||
|
self.state = state
|
||||||
|
|
||||||
|
|
||||||
class InlineImageItem(QtGui.QWidget):
|
class InlineImageItem(QtGui.QWidget):
|
||||||
|
@ -953,6 +953,12 @@ class Profile(Contact, Singleton):
|
|||||||
def resume_transfer(self, friend_number, file_number, by_friend=False):
|
def resume_transfer(self, friend_number, file_number, by_friend=False):
|
||||||
self.get_friend_by_number(friend_number).update_transfer_data(file_number,
|
self.get_friend_by_number(friend_number).update_transfer_data(file_number,
|
||||||
FILE_TRANSFER_MESSAGE_STATUS['OUTGOING'])
|
FILE_TRANSFER_MESSAGE_STATUS['OUTGOING'])
|
||||||
|
tr = self._file_transfers[(friend_number, file_number)]
|
||||||
|
if by_friend:
|
||||||
|
tr.state = TOX_FILE_TRANSFER_STATE['RUNNING']
|
||||||
|
tr.signal()
|
||||||
|
else:
|
||||||
|
tr.send_control(TOX_FILE_CONTROL['RESUME'])
|
||||||
|
|
||||||
def accept_transfer(self, item, path, friend_number, file_number, size, inline=False):
|
def accept_transfer(self, item, path, friend_number, file_number, size, inline=False):
|
||||||
"""
|
"""
|
||||||
@ -1018,7 +1024,7 @@ class Profile(Contact, Singleton):
|
|||||||
if (friend_number, file_number) in self._file_transfers:
|
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 in (2, 3): # finished or cancelled
|
||||||
if type(transfer) is ReceiveAvatar:
|
if type(transfer) is ReceiveAvatar:
|
||||||
self.get_friend_by_number(friend_number).load_avatar()
|
self.get_friend_by_number(friend_number).load_avatar()
|
||||||
self.set_active(None)
|
self.set_active(None)
|
||||||
@ -1043,7 +1049,7 @@ class Profile(Contact, Singleton):
|
|||||||
if (friend_number, file_number) in self._file_transfers:
|
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 in (2, 3): # finished or cancelled
|
||||||
del self._file_transfers[(friend_number, file_number)]
|
del self._file_transfers[(friend_number, file_number)]
|
||||||
if type(transfer) is not SendAvatar:
|
if type(transfer) is not SendAvatar:
|
||||||
if type(transfer) is SendFromBuffer and Settings.get_instance()['allow_inline']: # inline
|
if type(transfer) is SendFromBuffer and Settings.get_instance()['allow_inline']: # inline
|
||||||
|
Loading…
Reference in New Issue
Block a user