file transfers - spacing, ui fixes. menu fixes

This commit is contained in:
ingvar1995 2016-06-17 13:31:48 +03:00
parent fd9bfa52f3
commit e375dca9cc
4 changed files with 43 additions and 36 deletions

View File

@ -18,14 +18,15 @@ TOX_FILE_TRANSFER_STATE = {
'CANCELLED': 2, 'CANCELLED': 2,
'FINISHED': 3, 'FINISHED': 3,
'PAUSED_BY_FRIEND': 4, 'PAUSED_BY_FRIEND': 4,
'INCOMING_NOT_STARTED': 5 'INCOMING_NOT_STARTED': 5,
'OUTGOING_NOT_STARTED': 6
} }
ACTIVE_FILE_TRANSFERS = (0, 1, 4, 5) ACTIVE_FILE_TRANSFERS = (0, 1, 4, 5, 6)
PAUSED_FILE_TRANSFERS = (1, 4, 5) PAUSED_FILE_TRANSFERS = (1, 4, 5, 6)
DO_NOT_SHOW_ACCEPT_BUTTON = (2, 3, 4) DO_NOT_SHOW_ACCEPT_BUTTON = (2, 3, 4, 6)
SHOW_PROGRESS_BAR = (0, 1, 4) SHOW_PROGRESS_BAR = (0, 1, 4)
@ -51,7 +52,7 @@ class FileTransfer(QtCore.QObject):
self._friend_number = friend_number self._friend_number = friend_number
self.state = TOX_FILE_TRANSFER_STATE['RUNNING'] self.state = TOX_FILE_TRANSFER_STATE['RUNNING']
self._file_number = file_number self._file_number = file_number
self._creation_time = time() self._creation_time = None
self._size = float(size) self._size = float(size)
self._done = 0 self._done = 0
self._state_changed = StateSignal() self._state_changed = StateSignal()
@ -113,7 +114,7 @@ class SendTransfer(FileTransfer):
else: else:
size = 0 size = 0
super(SendTransfer, self).__init__(path, tox, friend_number, size) super(SendTransfer, self).__init__(path, tox, friend_number, size)
self.state = TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'] self.state = TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']
self._file_number = tox.file_send(friend_number, kind, size, file_id, self._file_number = tox.file_send(friend_number, kind, size, file_id,
basename(path).encode('utf-8') if path else '') basename(path).encode('utf-8') if path else '')
@ -157,7 +158,7 @@ class SendFromBuffer(FileTransfer):
def __init__(self, tox, friend_number, data, file_name): def __init__(self, tox, friend_number, data, file_name):
super(SendFromBuffer, self).__init__(None, tox, friend_number, len(data)) super(SendFromBuffer, self).__init__(None, tox, friend_number, len(data))
self.state = TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'] self.state = TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']
self._data = data self._data = data
self._file_number = tox.file_send(friend_number, TOX_FILE_KIND['DATA'], len(data), None, file_name) self._file_number = tox.file_send(friend_number, TOX_FILE_KIND['DATA'], len(data), None, file_name)
@ -169,10 +170,10 @@ class SendFromBuffer(FileTransfer):
data = self._data[position:position + size] data = self._data[position:position + size]
self._tox.file_send_chunk(self._friend_number, self._file_number, position, data) self._tox.file_send_chunk(self._friend_number, self._file_number, position, data)
self._done += size self._done += size
self._state_changed.signal.emit(self.state, self._done / self._size) self.signal()
else: else:
self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
self._state_changed.signal.emit(self.state, 1) self.signal()
class SendFromFileBuffer(SendTransfer): class SendFromFileBuffer(SendTransfer):

View File

@ -110,7 +110,7 @@ class MessageItem(QtGui.QWidget):
self.name.setText(user) self.name.setText(user)
self.time = QtGui.QLabel(self) self.time = QtGui.QLabel(self)
self.time.setGeometry(QtCore.QRect(parent.width() - 50, 0, 50, 25)) self.time.setGeometry(QtCore.QRect(parent.width() - 50, 0, 50, 20))
font = QtGui.QFont() font = QtGui.QFont()
font.setFamily("Times New Roman") font.setFamily("Times New Roman")
font.setPointSize(10) font.setPointSize(10)
@ -277,9 +277,6 @@ class FileTransferItem(QtGui.QListWidget):
elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']: # setup for continue elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']: # setup for continue
self.accept_or_pause.setVisible(True) self.accept_or_pause.setVisible(True)
self.button_update('resume') self.button_update('resume')
elif state not in ACTIVE_FILE_TRANSFERS:
self.accept_or_pause.setVisible(False)
self.cancel.setVisible(False)
else: # pause else: # pause
self.accept_or_pause.setVisible(True) self.accept_or_pause.setVisible(True)
self.button_update('pause') self.button_update('pause')
@ -372,6 +369,10 @@ class FileTransferItem(QtGui.QListWidget):
self.button_update('resume') # setup button continue self.button_update('resume') # setup button continue
self.setStyleSheet('QListWidget { border: 1px solid green; }') self.setStyleSheet('QListWidget { border: 1px solid green; }')
self.state = state self.state = state
elif state == TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']:
self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }')
self.accept_or_pause.setVisible(False)
self.pb.setVisible(False)
elif not self.paused: # active elif not self.paused: # active
self.accept_or_pause.setVisible(True) # setup to pause self.accept_or_pause.setVisible(True) # setup to pause
self.button_update('pause') self.button_update('pause')

View File

@ -242,6 +242,7 @@ class MainWindow(QtGui.QMainWindow):
self.messages = QtGui.QListWidget(widget) self.messages = QtGui.QListWidget(widget)
self.messages.setGeometry(0, 0, 620, 310) self.messages.setGeometry(0, 0, 620, 310)
self.messages.setObjectName("messages") self.messages.setObjectName("messages")
self.messages.setSpacing(1)
self.messages.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.messages.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.messages.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.messages.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.messages.setFocusPolicy(QtCore.Qt.NoFocus) self.messages.setFocusPolicy(QtCore.Qt.NoFocus)
@ -398,35 +399,39 @@ class MainWindow(QtGui.QMainWindow):
def send_file(self): def send_file(self):
self.menu.hide() self.menu.hide()
choose_file = QtGui.QApplication.translate("MainWindow", 'Choose file', None, QtGui.QApplication.UnicodeUTF8) if self.profile.active_friend + 1:
choose = QtGui.QApplication.translate("MainWindow", choose_file, None, QtGui.QApplication.UnicodeUTF8) choose = QtGui.QApplication.translate("MainWindow", 'Choose file', None, QtGui.QApplication.UnicodeUTF8)
name = QtGui.QFileDialog.getOpenFileName(self, choose) name = QtGui.QFileDialog.getOpenFileName(self, choose)
if name[0]: if name[0]:
self.profile.send_file(name[0]) self.profile.send_file(name[0])
def send_screenshot(self, hide=False): def send_screenshot(self, hide=False):
self.menu.hide() self.menu.hide()
self.sw = ScreenShotWindow(self) if self.profile.active_friend + 1:
self.sw.show() self.sw = ScreenShotWindow(self)
if hide: self.sw.show()
self.hide() if hide:
self.hide()
def send_smiley(self): def send_smiley(self):
self.menu.hide() self.menu.hide()
self.smiley = SmileyWindow(self) if self.profile.active_friend + 1:
self.smiley.setGeometry(QtCore.QRect(self.x() if Settings.get_instance()['mirror_mode'] else 270 + self.x(), self.smiley = SmileyWindow(self)
self.y() + self.height() - 200, self.smiley.setGeometry(QtCore.QRect(self.x() if Settings.get_instance()['mirror_mode'] else 270 + self.x(),
self.smiley.width(), self.y() + self.height() - 200,
self.smiley.height())) self.smiley.width(),
self.smiley.show() self.smiley.height()))
self.smiley.show()
def send_sticker(self): def send_sticker(self):
self.sticker = StickerWindow(self) self.menu.hide()
self.sticker.setGeometry(QtCore.QRect(self.x() if Settings.get_instance()['mirror_mode'] else 270 + self.x(), if self.profile.active_friend + 1:
self.y() + self.height() - 200, self.sticker = StickerWindow(self)
self.sticker.width(), self.sticker.setGeometry(QtCore.QRect(self.x() if Settings.get_instance()['mirror_mode'] else 270 + self.x(),
self.sticker.height())) self.y() + self.height() - 200,
self.sticker.show() self.sticker.width(),
self.sticker.height()))
self.sticker.show()
def active_call(self): def active_call(self):
self.update_call_state('finish_call') self.update_call_state('finish_call')

View File

@ -904,7 +904,7 @@ class Profile(contact.Contact, Singleton):
self._file_transfers[(friend.number, st.get_file_number())] = st self._file_transfers[(friend.number, st.get_file_number())] = st
tm = TransferMessage(MESSAGE_OWNER['ME'], tm = TransferMessage(MESSAGE_OWNER['ME'],
time.time(), time.time(),
TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'], # OUTGOING NOT STARTED TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED'],
len(data), len(data),
file_name, file_name,
friend.number, friend.number,
@ -934,7 +934,7 @@ class Profile(contact.Contact, Singleton):
self._file_transfers[(friend_number, st.get_file_number())] = st self._file_transfers[(friend_number, st.get_file_number())] = st
tm = TransferMessage(MESSAGE_OWNER['ME'], tm = TransferMessage(MESSAGE_OWNER['ME'],
time.time(), time.time(),
TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'], # OUTGOING NOT STARTED TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED'],
os.path.getsize(path), os.path.getsize(path),
os.path.basename(path), os.path.basename(path),
friend_number, friend_number,