ui update - signal added

This commit is contained in:
ingvar1995 2016-03-19 14:41:01 +03:00
parent 52bfacb978
commit 42ca5d0597
3 changed files with 28 additions and 5 deletions

View file

@ -4,6 +4,7 @@ from os import remove
from time import time
from tox import Tox
import profile
from PySide import QtCore
TOX_FILE_TRANSFER_STATE = {
@ -14,8 +15,11 @@ TOX_FILE_TRANSFER_STATE = {
}
class FileTransfer(object):
class FileTransfer(QtCore.QObject):
signal = QtCore.Signal()
def __init__(self, path, tox, friend_number, file_number=None):
QtCore.QObject.__init__(self)
self._path = path
self._tox = tox
self._friend_number = friend_number
@ -26,6 +30,9 @@ class FileTransfer(object):
def set_tox(self, tox):
self._tox = tox
def set_event_handler(self, handler):
self.signal.connect(handler)
def get_file_number(self):
return self._file_number
@ -51,7 +58,7 @@ class SendTransfer(FileTransfer):
kind,
getsize(path) if path else 0,
file_id,
basename(path) if path else '')
basename(path).encode('utf-8') if path else '')
if path is not None:
self._file = open(path, 'rb')
@ -63,6 +70,7 @@ class SendTransfer(FileTransfer):
else:
self._file.close()
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
self.signal.emit()
class SendAvatar(SendTransfer):
@ -76,6 +84,7 @@ class SendAvatar(SendTransfer):
class ReceiveTransfer(FileTransfer):
# TODO: remove file on cancel and close file
def __init__(self, path, tox, friend_number, file_number):
super(ReceiveTransfer, self).__init__(path, tox, friend_number, file_number)
self._file = open(self._path, 'wb')

View file

@ -157,6 +157,7 @@ class StatusCircle(QtGui.QWidget):
class FileTransferItem(QtGui.QListWidget):
# TODO: accept button
def __init__(self, file_name, time, user, friend_number, file_number, parent=None):
QtGui.QListWidget.__init__(self, parent)
self.name = QtGui.QLabel(self)
@ -190,3 +191,6 @@ class FileTransferItem(QtGui.QListWidget):
profile = Profile.get_instance()
profile.cancel_transfer(friend_number, file_number)
self.name.setText('Cancelled')
def update(self):
self.name.setText('Finished')

View file

@ -587,6 +587,7 @@ class Profile(Contact, Singleton):
self._messages.addItem(elem)
self._messages.setItemWidget(elem, item)
self._messages.repaint()
return item
# -----------------------------------------------------------------------------------------------------------------
# Work with friends (remove, set alias, get public key)
@ -717,9 +718,7 @@ class Profile(Contact, Singleton):
friend = self.get_friend_by_number(friend_number)
if settings['allow_auto_accept'] and friend.tox_id in settings['auto_accept_from_friends']:
path = settings['auto_accept_path'] or curr_directory()
rt = ReceiveTransfer(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'])
self.accept_transfer(path + '/' + file_name, friend_number, file_number)
else:
self.create_file_transfer_item(file_name + ' ' + str(size), friend_number, file_number)
#self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL'])
@ -727,6 +726,14 @@ class Profile(Contact, Singleton):
def cancel_transfer(self, friend_number, file_number):
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL'])
if (friend_number, file_number) in self._file_transfers:
del self._file_transfers[(friend_number, file_number)]
def accept_transfer(self, path, friend_number, file_number):
rt = ReceiveTransfer(path + '/' + 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'])
# bind rt with widget
def incoming_avatar(self, friend_number, file_number, size):
"""
@ -760,6 +767,9 @@ 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())
st.set_event_handler(item.update)
# bind st with widget
def outgoing_chunk(self, friend_number, file_number, position, size):
transfer = self._file_transfers[(friend_number, file_number)]