unsent files fixes - part 1

This commit is contained in:
ingvar1995 2018-05-19 21:04:40 +03:00
parent 6495aa9920
commit 206c5c4905
4 changed files with 36 additions and 29 deletions

View file

@ -16,7 +16,7 @@ class FileTransfersMessagesService:
status = FILE_TRANSFER_STATE['RUNNING'] if accepted else FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']
tm = TransferMessage(author, util.get_unix_time(), status, size, file_name, friend.number, file_number)
if self._is_active(friend.number):
if self._is_friend_active(friend.number):
self._create_file_transfer_item(tm)
self._messages.scrollToBottom()
else:
@ -31,7 +31,7 @@ class FileTransfersMessagesService:
status = FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']
tm = TransferMessage(author, util.get_unix_time(), status, size, file_name, friend.number, file_number)
if self._is_active(friend.number):
if self._is_friend_active(friend.number):
self._create_file_transfer_item(tm)
self._messages.scrollToBottom()
@ -40,16 +40,18 @@ class FileTransfersMessagesService:
return tm
def add_inline_message(self, transfer, index):
if self._is_active(transfer.friend_number):
if self._is_friend_active(transfer.friend_number):
count = self._messages.count()
if count + index + 1 >= 0:
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())
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
size = os.path.getsize(file_path) if data is None else len(data)
tm = UnsentFileMessage(file_path, data, util.get_unix_time(), author, size, friend.number)
friend.append_message(tm)
if self._is_active(friend.number):
if self._is_friend_active(friend.number):
self._create_unsent_file_item(tm)
self._messages.scrollToBottom()
@ -59,7 +61,7 @@ class FileTransfersMessagesService:
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _is_active(self, friend_number):
def _is_friend_active(self, friend_number):
if not self._contacts_manager.is_active_a_friend():
return False

View file

@ -1,4 +1,5 @@
from history.database import MESSAGE_AUTHOR
import os.path
from ui.messages_widgets import *
@ -16,8 +17,18 @@ PAGE_SIZE = 42
class MessageAuthor:
def __init__(self, author_name, author_type):
self.name = author_name
self.type = author_type
self._name = author_name
self._type = author_type
def get_name(self):
return self._name
name = property(get_name)
def get_type(self):
return self._type
type = property(get_type)
class Message:
@ -139,7 +150,10 @@ class TransferMessage(Message):
self._friend_number, self._file_number = friend_number, file_number
def is_active(self, file_number):
return self._file_number == file_number and self._state not in (2, 3)
if self._file_number != file_number:
return False
return self._state not in (FILE_TRANSFER_STATE['FINISHED'], FILE_TRANSFER_STATE['CANCELLED'])
def get_friend_number(self):
return self._friend_number
@ -178,10 +192,11 @@ class TransferMessage(Message):
return FileTransferItem(self, *args)
class UnsentFileMessage(Message):
class UnsentFileMessage(TransferMessage):
def __init__(self, path, data, time):
super().__init__(MESSAGE_TYPE['FILE_TRANSFER'], 0, time)
def __init__(self, path, data, time, author, size, friend_number):
file_name = os.path.basename(path)
super().__init__(author, time, FILE_TRANSFER_STATE['UNSENT'], size, file_name, friend_number, -1)
self._data, self._path = data, path
def get_data(self):
@ -189,11 +204,6 @@ class UnsentFileMessage(Message):
data = property(get_data)
def get_state(self):
return FILE_TRANSFER_STATE['UNSENT']
state = property(get_state)
def get_path(self):
return self._path

View file

@ -316,8 +316,8 @@ class MainWindow(QtWidgets.QMainWindow):
def load(pos):
if not pos:
friend = self._contacts_manager.get_curr_friend()
self._history_loader.load_history(friend)
contact = self._contacts_manager.get_curr_contact()
self._history_loader.load_history(contact)
self.messages.verticalScrollBar().setValue(1)
self.messages.verticalScrollBar().valueChanged.connect(load)
self.messages.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)

View file

@ -253,7 +253,8 @@ class FileTransferItem(QtWidgets.QListWidget):
icon = QtGui.QIcon(pixmap)
self.cancel.setIcon(icon)
self.cancel.setIconSize(QtCore.QSize(30, 30))
self.cancel.setVisible(transfer_message.state in ACTIVE_FILE_TRANSFERS)
self.cancel.setVisible(transfer_message.state in ACTIVE_FILE_TRANSFERS or
transfer_message.state == FILE_TRANSFER_STATE['UNSENT'])
self.cancel.clicked.connect(
lambda: self.cancel_transfer(transfer_message.friend_number, transfer_message.file_number))
self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; background-color: none;}')
@ -268,6 +269,9 @@ class FileTransferItem(QtWidgets.QListWidget):
elif transfer_message.state == FILE_TRANSFER_STATE['PAUSED_BY_USER']: # setup for continue
self.accept_or_pause.setVisible(True)
self.button_update('resume')
elif transfer_message.state == FILE_TRANSFER_STATE['UNSENT']:
self.accept_or_pause.setVisible(False)
self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }')
else: # pause
self.accept_or_pause.setVisible(True)
self.button_update('pause')
@ -382,17 +386,12 @@ class FileTransferItem(QtWidgets.QListWidget):
self.state = state
self.time_left.setVisible(True)
@staticmethod
def mark_as_sent():
return False
class UnsentFileItem(FileTransferItem):
def __init__(self, transfer_message, file_transfer_handler, settings, width, parent=None):
super().__init__(transfer_message, file_transfer_handler, settings, width, parent)
self._time = time
self.pb.setVisible(False)
movie = QtGui.QMovie(util.join_path(util.get_images_directory(), 'spinner.gif'))
self.time.setMovie(movie)
movie.start()
@ -448,7 +447,3 @@ class InlineImageItem(QtWidgets.QScrollArea):
if directory:
fl = QtCore.QFile(directory + '/toxygen_inline_' + util.curr_time().replace(':', '_') + '.png')
self._pixmap.save(fl, 'PNG')
@staticmethod
def mark_as_sent():
return False