file transfers fixes - part 8 (unsent files minor fixes)
This commit is contained in:
parent
bde69bd417
commit
e8a0a3f5be
7 changed files with 55 additions and 29 deletions
|
@ -32,15 +32,15 @@ class Friend(contact.Contact):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_unsent_files(self):
|
def get_unsent_files(self):
|
||||||
messages = filter(lambda x: type(x) is UnsentFile, self._corr)
|
messages = filter(lambda x: type(x) is UnsentFileMessage, self._corr)
|
||||||
return messages
|
return list(messages)
|
||||||
|
|
||||||
def clear_unsent_files(self):
|
def clear_unsent_files(self):
|
||||||
self._corr = list(filter(lambda x: type(x) is not UnsentFile, self._corr))
|
self._corr = list(filter(lambda x: type(x) is not UnsentFileMessage, self._corr))
|
||||||
|
|
||||||
def remove_invalid_unsent_files(self):
|
def remove_invalid_unsent_files(self): # TODO: fix
|
||||||
def is_valid(message):
|
def is_valid(message):
|
||||||
if type(message) is not UnsentFile:
|
if type(message) is not UnsentFileMessage:
|
||||||
return True
|
return True
|
||||||
if message.get_data()[1] is not None:
|
if message.get_data()[1] is not None:
|
||||||
return True
|
return True
|
||||||
|
@ -49,7 +49,8 @@ class Friend(contact.Contact):
|
||||||
self._corr = list(filter(is_valid, self._corr))
|
self._corr = list(filter(is_valid, self._corr))
|
||||||
|
|
||||||
def delete_one_unsent_file(self, message_id):
|
def delete_one_unsent_file(self, message_id):
|
||||||
self._corr = list(filter(lambda m: not (type(m) is UnsentFile and m.message_id == message_id), self._corr))
|
self._corr = list(filter(lambda m: not (type(m) is UnsentFileMessage and m.message_id == message_id),
|
||||||
|
self._corr))
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# History support
|
# History support
|
||||||
|
|
|
@ -145,8 +145,7 @@ class FileTransfersHandler:
|
||||||
def send_inline(self, data, file_name, friend_number, is_resend=False):
|
def send_inline(self, data, file_name, friend_number, is_resend=False):
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if friend.status is None and not is_resend:
|
if friend.status is None and not is_resend:
|
||||||
m = UnsentFile(file_name, data, time.time())
|
self._file_transfers_message_service.add_unsent_file_message(friend, file_name, data)
|
||||||
friend.append_message(m)
|
|
||||||
return
|
return
|
||||||
elif friend.status is None and is_resend:
|
elif friend.status is None and is_resend:
|
||||||
raise RuntimeError()
|
raise RuntimeError()
|
||||||
|
@ -163,8 +162,7 @@ class FileTransfersHandler:
|
||||||
"""
|
"""
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if friend.status is None and not is_resend:
|
if friend.status is None and not is_resend:
|
||||||
m = UnsentFile(path, None, util.get_unix_time())
|
self._file_transfers_message_service.add_unsent_file_message(friend, path, None)
|
||||||
friend.append_message(m)
|
|
||||||
return
|
return
|
||||||
elif friend.status is None and is_resend:
|
elif friend.status is None and is_resend:
|
||||||
print('Error in sending')
|
print('Error in sending')
|
||||||
|
@ -192,7 +190,7 @@ class FileTransfersHandler:
|
||||||
self._get_friend_by_number(friend_number).load_avatar()
|
self._get_friend_by_number(friend_number).load_avatar()
|
||||||
elif t is ReceiveToBuffer or (t is SendFromBuffer and self._settings['allow_inline']): # inline image
|
elif t is ReceiveToBuffer or (t is SendFromBuffer and self._settings['allow_inline']): # inline image
|
||||||
print('inline')
|
print('inline')
|
||||||
inline = InlineImage(transfer.data)
|
inline = InlineImageMessage(transfer.data)
|
||||||
message_id = self._insert_inline_before[(friend_number, file_number)]
|
message_id = self._insert_inline_before[(friend_number, file_number)]
|
||||||
del self._insert_inline_before[(friend_number, file_number)]
|
del self._insert_inline_before[(friend_number, file_number)]
|
||||||
index = self._get_friend_by_number(friend_number).insert_inline(message_id, inline)
|
index = self._get_friend_by_number(friend_number).insert_inline(message_id, inline)
|
||||||
|
@ -203,20 +201,20 @@ class FileTransfersHandler:
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
friend.remove_invalid_unsent_files()
|
friend.remove_invalid_unsent_files()
|
||||||
files = friend.get_unsent_files()
|
files = friend.get_unsent_files()
|
||||||
try: # TODO: fix
|
try:
|
||||||
for fl in files:
|
for fl in files:
|
||||||
data = fl.get_data()
|
data, path = fl.data, fl.path
|
||||||
if data[1] is not None:
|
if data is not None:
|
||||||
self.send_inline(data[1], data[0], friend_number, True)
|
self.send_inline(data, path, friend_number, True)
|
||||||
else:
|
else:
|
||||||
self.send_file(data[0], friend_number, True)
|
self.send_file(path, friend_number, True)
|
||||||
friend.clear_unsent_files()
|
friend.clear_unsent_files()
|
||||||
for key in list(self._paused_file_transfers.keys()):
|
for key in list(self._paused_file_transfers.keys()):
|
||||||
data = self._paused_file_transfers[key]
|
(path, ft_friend_number, is_incoming, start_position) = self._paused_file_transfers[key]
|
||||||
if not os.path.exists(data[0]):
|
if not os.path.exists(path):
|
||||||
del self._paused_file_transfers[key]
|
del self._paused_file_transfers[key]
|
||||||
elif data[1] == friend_number and not data[2]:
|
elif ft_friend_number == friend_number and not is_incoming:
|
||||||
self.send_file(data[0], friend_number, True, key)
|
self.send_file(path, friend_number, True, key)
|
||||||
del self._paused_file_transfers[key]
|
del self._paused_file_transfers[key]
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print('Exception in file sending: ' + str(ex))
|
print('Exception in file sending: ' + str(ex))
|
||||||
|
|
|
@ -45,6 +45,16 @@ class FileTransfersMessagesService:
|
||||||
if count + index + 1 >= 0:
|
if count + index + 1 >= 0:
|
||||||
self._create_inline_item(transfer.data, count + index + 1)
|
self._create_inline_item(transfer.data, count + index + 1)
|
||||||
|
|
||||||
|
def add_unsent_file_message(self, friend, file_path, data):
|
||||||
|
tm = UnsentFileMessage(file_path, data, util.get_unix_time())
|
||||||
|
friend.append_message(tm)
|
||||||
|
|
||||||
|
if self._is_active(friend.number):
|
||||||
|
self._create_unsent_file_item(tm)
|
||||||
|
self._messages.scrollToBottom()
|
||||||
|
|
||||||
|
return tm
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Private methods
|
# Private methods
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -60,3 +70,6 @@ class FileTransfersMessagesService:
|
||||||
|
|
||||||
def _create_inline_item(self, data, position):
|
def _create_inline_item(self, data, position):
|
||||||
return self._messages_items_factory.create_inline_item(data, False, position)
|
return self._messages_items_factory.create_inline_item(data, False, position)
|
||||||
|
|
||||||
|
def _create_unsent_file_item(self, tm):
|
||||||
|
return self._messages_items_factory.create_unsent_file_item(tm)
|
||||||
|
|
|
@ -173,17 +173,30 @@ class TransferMessage(Message):
|
||||||
return FileTransferItem(self, *args)
|
return FileTransferItem(self, *args)
|
||||||
|
|
||||||
|
|
||||||
class UnsentFile(Message):
|
class UnsentFileMessage(Message):
|
||||||
|
|
||||||
def __init__(self, path, data, time):
|
def __init__(self, path, data, time):
|
||||||
super().__init__(MESSAGE_TYPE['FILE_TRANSFER'], 0, time)
|
super().__init__(MESSAGE_TYPE['FILE_TRANSFER'], 0, time)
|
||||||
self._data, self._path = data, path
|
self._data, self._path = data, path
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
return self._data
|
||||||
|
|
||||||
|
data = property(get_data)
|
||||||
|
|
||||||
|
def get_path(self):
|
||||||
|
return self._path
|
||||||
|
|
||||||
|
path = property(get_path)
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _create_widget(self, *args):
|
||||||
|
return UnsentFileItem(self, *args)
|
||||||
|
|
||||||
class InlineImage(Message):
|
|
||||||
|
class InlineImageMessage(Message):
|
||||||
"""
|
"""
|
||||||
Inline image
|
Inline image
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -57,8 +57,8 @@ class MessagesItemsFactory:
|
||||||
|
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def create_unsent_file_item(self, tm, append=True):
|
def create_unsent_file_item(self, message, append=True):
|
||||||
item = UnsentFileItem(self._file_transfers_handler, self._settings, tm, self._messages.width())
|
item = message.get_widget(self._file_transfers_handler, self._settings, self._messages.width(), self._messages)
|
||||||
elem = QtWidgets.QListWidgetItem()
|
elem = QtWidgets.QListWidgetItem()
|
||||||
elem.setSizeHint(QtCore.QSize(self._messages.width() - 30, 34))
|
elem.setSizeHint(QtCore.QSize(self._messages.width() - 30, 34))
|
||||||
if append:
|
if append:
|
||||||
|
@ -69,8 +69,8 @@ class MessagesItemsFactory:
|
||||||
|
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def create_file_transfer_item(self, tm, append=True):
|
def create_file_transfer_item(self, message, append=True):
|
||||||
item = tm.get_widget(self._file_transfers_handler, self._settings, self._messages.width(), self._messages)
|
item = message.get_widget(self._file_transfers_handler, self._settings, self._messages.width(), self._messages)
|
||||||
elem = QtWidgets.QListWidgetItem()
|
elem = QtWidgets.QListWidgetItem()
|
||||||
elem.setSizeHint(QtCore.QSize(self._messages.width() - 30, 34))
|
elem.setSizeHint(QtCore.QSize(self._messages.width() - 30, 34))
|
||||||
if append:
|
if append:
|
||||||
|
|
|
@ -308,7 +308,8 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
def load(pos):
|
def load(pos):
|
||||||
if not pos:
|
if not pos:
|
||||||
self._history_loader.load_history()
|
friend = self._contacts_manager.get_curr_friend()
|
||||||
|
self._history_loader.load_history(friend)
|
||||||
self.messages.verticalScrollBar().setValue(1)
|
self.messages.verticalScrollBar().setValue(1)
|
||||||
self.messages.verticalScrollBar().valueChanged.connect(load)
|
self.messages.verticalScrollBar().valueChanged.connect(load)
|
||||||
self.messages.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
|
self.messages.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
|
||||||
|
|
|
@ -390,8 +390,8 @@ class FileTransferItem(QtWidgets.QListWidget):
|
||||||
|
|
||||||
class UnsentFileItem(FileTransferItem):
|
class UnsentFileItem(FileTransferItem):
|
||||||
|
|
||||||
def __init__(self, file_transfer_handler, settings, transfer_message, width, parent=None):
|
def __init__(self, transfer_message, file_transfer_handler, settings, width, parent=None):
|
||||||
super().__init__(file_transfer_handler, settings, transfer_message, width, parent)
|
super().__init__(transfer_message, file_transfer_handler, settings, width, parent)
|
||||||
self._time = time
|
self._time = time
|
||||||
self.pb.setVisible(False)
|
self.pb.setVisible(False)
|
||||||
movie = QtGui.QMovie(util.join_path(util.get_images_directory(), 'spinner.gif'))
|
movie = QtGui.QMovie(util.join_path(util.get_images_directory(), 'spinner.gif'))
|
||||||
|
|
Loading…
Reference in a new issue