ui update - signal added
This commit is contained in:
parent
52bfacb978
commit
42ca5d0597
@ -4,6 +4,7 @@ from os import remove
|
|||||||
from time import time
|
from time import time
|
||||||
from tox import Tox
|
from tox import Tox
|
||||||
import profile
|
import profile
|
||||||
|
from PySide import QtCore
|
||||||
|
|
||||||
|
|
||||||
TOX_FILE_TRANSFER_STATE = {
|
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):
|
def __init__(self, path, tox, friend_number, file_number=None):
|
||||||
|
QtCore.QObject.__init__(self)
|
||||||
self._path = path
|
self._path = path
|
||||||
self._tox = tox
|
self._tox = tox
|
||||||
self._friend_number = friend_number
|
self._friend_number = friend_number
|
||||||
@ -26,6 +30,9 @@ class FileTransfer(object):
|
|||||||
def set_tox(self, tox):
|
def set_tox(self, tox):
|
||||||
self._tox = tox
|
self._tox = tox
|
||||||
|
|
||||||
|
def set_event_handler(self, handler):
|
||||||
|
self.signal.connect(handler)
|
||||||
|
|
||||||
def get_file_number(self):
|
def get_file_number(self):
|
||||||
return self._file_number
|
return self._file_number
|
||||||
|
|
||||||
@ -51,7 +58,7 @@ class SendTransfer(FileTransfer):
|
|||||||
kind,
|
kind,
|
||||||
getsize(path) if path else 0,
|
getsize(path) if path else 0,
|
||||||
file_id,
|
file_id,
|
||||||
basename(path) if path else '')
|
basename(path).encode('utf-8') if path else '')
|
||||||
if path is not None:
|
if path is not None:
|
||||||
self._file = open(path, 'rb')
|
self._file = open(path, 'rb')
|
||||||
|
|
||||||
@ -63,6 +70,7 @@ class SendTransfer(FileTransfer):
|
|||||||
else:
|
else:
|
||||||
self._file.close()
|
self._file.close()
|
||||||
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
||||||
|
self.signal.emit()
|
||||||
|
|
||||||
|
|
||||||
class SendAvatar(SendTransfer):
|
class SendAvatar(SendTransfer):
|
||||||
@ -76,6 +84,7 @@ class SendAvatar(SendTransfer):
|
|||||||
|
|
||||||
|
|
||||||
class ReceiveTransfer(FileTransfer):
|
class ReceiveTransfer(FileTransfer):
|
||||||
|
# TODO: remove file on cancel and close file
|
||||||
def __init__(self, path, tox, friend_number, file_number):
|
def __init__(self, path, tox, friend_number, file_number):
|
||||||
super(ReceiveTransfer, self).__init__(path, tox, friend_number, file_number)
|
super(ReceiveTransfer, self).__init__(path, tox, friend_number, file_number)
|
||||||
self._file = open(self._path, 'wb')
|
self._file = open(self._path, 'wb')
|
||||||
|
@ -157,6 +157,7 @@ class StatusCircle(QtGui.QWidget):
|
|||||||
|
|
||||||
|
|
||||||
class FileTransferItem(QtGui.QListWidget):
|
class FileTransferItem(QtGui.QListWidget):
|
||||||
|
# TODO: accept button
|
||||||
def __init__(self, file_name, time, user, friend_number, file_number, parent=None):
|
def __init__(self, file_name, time, user, friend_number, file_number, parent=None):
|
||||||
QtGui.QListWidget.__init__(self, parent)
|
QtGui.QListWidget.__init__(self, parent)
|
||||||
self.name = QtGui.QLabel(self)
|
self.name = QtGui.QLabel(self)
|
||||||
@ -190,3 +191,6 @@ class FileTransferItem(QtGui.QListWidget):
|
|||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
profile.cancel_transfer(friend_number, file_number)
|
profile.cancel_transfer(friend_number, file_number)
|
||||||
self.name.setText('Cancelled')
|
self.name.setText('Cancelled')
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.name.setText('Finished')
|
||||||
|
@ -587,6 +587,7 @@ class Profile(Contact, Singleton):
|
|||||||
self._messages.addItem(elem)
|
self._messages.addItem(elem)
|
||||||
self._messages.setItemWidget(elem, item)
|
self._messages.setItemWidget(elem, item)
|
||||||
self._messages.repaint()
|
self._messages.repaint()
|
||||||
|
return item
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Work with friends (remove, set alias, get public key)
|
# 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)
|
friend = self.get_friend_by_number(friend_number)
|
||||||
if settings['allow_auto_accept'] and friend.tox_id in settings['auto_accept_from_friends']:
|
if settings['allow_auto_accept'] and friend.tox_id in settings['auto_accept_from_friends']:
|
||||||
path = settings['auto_accept_path'] or curr_directory()
|
path = settings['auto_accept_path'] or curr_directory()
|
||||||
rt = ReceiveTransfer(path + '/' + file_name, self._tox, friend_number, file_number)
|
self.accept_transfer(path + '/' + file_name, friend_number, file_number)
|
||||||
self._file_transfers[(friend_number, file_number)] = rt
|
|
||||||
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME'])
|
|
||||||
else:
|
else:
|
||||||
self.create_file_transfer_item(file_name + ' ' + str(size), friend_number, file_number)
|
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'])
|
#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):
|
def cancel_transfer(self, friend_number, file_number):
|
||||||
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL'])
|
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):
|
def incoming_avatar(self, friend_number, file_number, size):
|
||||||
"""
|
"""
|
||||||
@ -760,6 +767,9 @@ 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())
|
||||||
|
st.set_event_handler(item.update)
|
||||||
|
# bind st with widget
|
||||||
|
|
||||||
def outgoing_chunk(self, friend_number, file_number, position, size):
|
def outgoing_chunk(self, friend_number, file_number, position, size):
|
||||||
transfer = self._file_transfers[(friend_number, file_number)]
|
transfer = self._file_transfers[(friend_number, file_number)]
|
||||||
|
Loading…
Reference in New Issue
Block a user