From fd9bfa52f36571ef7ff2fe4e3fc9c5bc95449659 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 17 Jun 2016 00:10:26 +0300 Subject: [PATCH] file transfers items bug fixes, translatable menu everywhere --- src/callbacks.py | 6 ++-- src/file_transfers.py | 29 ++++++++++++----- src/friend.py | 4 +-- src/list_items.py | 48 +++++++++++++---------------- src/loginscreen.py | 3 +- src/mainscreen.py | 5 +-- src/menu.py | 16 +++++----- src/messages.py | 12 +------- src/passwordscreen.py | 4 +-- src/profile.py | 72 ++++++++++++++++++++++++++----------------- src/widgets.py | 11 +++++++ 11 files changed, 118 insertions(+), 92 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index b760ed6..6c094b8 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -226,11 +226,11 @@ def file_recv_control(tox, friend_number, file_number, file_control, user_data): Friend cancelled, paused or resumed file transfer """ if file_control == TOX_FILE_CONTROL['CANCEL']: - Profile.get_instance().cancel_transfer(friend_number, file_number, True) + invoke_in_main_thread(Profile.get_instance().cancel_transfer, friend_number, file_number, True) elif file_control == TOX_FILE_CONTROL['PAUSE']: - Profile.get_instance().pause_transfer(friend_number, file_number, True) + invoke_in_main_thread(Profile.get_instance().pause_transfer, friend_number, file_number, True) elif file_control == TOX_FILE_CONTROL['RESUME']: - Profile.get_instance().resume_transfer(friend_number, file_number, True) + invoke_in_main_thread(Profile.get_instance().resume_transfer, friend_number, file_number, True) # ----------------------------------------------------------------------------------------------------------------- # Callbacks - custom packets diff --git a/src/file_transfers.py b/src/file_transfers.py index 6060e9b..b8a930f 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -9,17 +9,28 @@ try: except ImportError: from PyQt4 import QtCore +# TODO: threads! + TOX_FILE_TRANSFER_STATE = { 'RUNNING': 0, - 'PAUSED': 1, - 'CANCELED': 2, + 'PAUSED_BY_USER': 1, + 'CANCELLED': 2, 'FINISHED': 3, - 'PAUSED_BY_FRIEND': 4 + 'PAUSED_BY_FRIEND': 4, + 'INCOMING_NOT_STARTED': 5 } +ACTIVE_FILE_TRANSFERS = (0, 1, 4, 5) + +PAUSED_FILE_TRANSFERS = (1, 4, 5) + +DO_NOT_SHOW_ACCEPT_BUTTON = (2, 3, 4) + +SHOW_PROGRESS_BAR = (0, 1, 4) + +ALLOWED_FILES = ('toxygen_inline.png', 'utox-inline.png', 'sticker.png') -# TODO: rewrite class StateSignal(QtCore.QObject): try: @@ -64,14 +75,14 @@ class FileTransfer(QtCore.QObject): self.send_control(TOX_FILE_CONTROL['CANCEL']) if hasattr(self, '_file'): self._file.close() - self._state_changed.signal.emit(self.state, 1) + self.signal() def cancelled(self): if hasattr(self, '_file'): sleep(0.1) self._file.close() - self.state = TOX_FILE_TRANSFER_STATE['CANCELED'] - self._state_changed.signal.emit(self.state, 1) + self.state = TOX_FILE_TRANSFER_STATE['CANCELLED'] + self.signal() def pause(self, by_friend): if not by_friend: @@ -102,6 +113,7 @@ class SendTransfer(FileTransfer): else: size = 0 super(SendTransfer, self).__init__(path, tox, friend_number, size) + self.state = TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'] self._file_number = tox.file_send(friend_number, kind, size, file_id, basename(path).encode('utf-8') if path else '') @@ -121,7 +133,7 @@ class SendTransfer(FileTransfer): if hasattr(self, '_file'): self._file.close() self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] - self._state_changed.signal.emit(self.state, 1) + self.signal() class SendAvatar(SendTransfer): @@ -145,6 +157,7 @@ class SendFromBuffer(FileTransfer): def __init__(self, tox, friend_number, data, file_name): super(SendFromBuffer, self).__init__(None, tox, friend_number, len(data)) + self.state = TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'] self._data = data self._file_number = tox.file_send(friend_number, TOX_FILE_KIND['DATA'], len(data), None, file_name) diff --git a/src/friend.py b/src/friend.py index 97d85ea..64135b3 100644 --- a/src/friend.py +++ b/src/friend.py @@ -136,10 +136,10 @@ class Friend(contact.Contact): tr = filter(lambda x: x.get_type() == MESSAGE_TYPE['FILE_TRANSFER'] and x.is_active(file_number), self._corr)[0] tr.set_status(status) + i = self._corr.index(tr) if inline: # inline was loaded - i = self._corr.index(tr) self._corr.insert(i, inline) - return i - len(self._corr) + return i - len(self._corr) except: pass diff --git a/src/list_items.py b/src/list_items.py index 2ad18ca..51fb002 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -4,9 +4,8 @@ try: except ImportError: from PyQt4 import QtCore, QtGui import profile -from file_transfers import TOX_FILE_TRANSFER_STATE +from file_transfers import TOX_FILE_TRANSFER_STATE, PAUSED_FILE_TRANSFERS, DO_NOT_SHOW_ACCEPT_BUTTON, ACTIVE_FILE_TRANSFERS, SHOW_PROGRESS_BAR from util import curr_directory, convert_time -from messages import FILE_TRANSFER_MESSAGE_STATUS from widgets import DataLabel, create_menu import cgi import smileys @@ -233,13 +232,12 @@ class FileTransferItem(QtGui.QListWidget): QtGui.QListWidget.__init__(self, parent) self.resize(QtCore.QSize(width, 34)) - if state == FILE_TRANSFER_MESSAGE_STATUS['CANCELLED']: + if state == TOX_FILE_TRANSFER_STATE['CANCELLED']: self.setStyleSheet('QListWidget { border: 1px solid #B40404; }') - elif state in (FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED'], FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_FRIEND']): + elif state in PAUSED_FILE_TRANSFERS: self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }') else: self.setStyleSheet('QListWidget { border: 1px solid green; }') - self.state = state self.name = DataLabel(self) @@ -265,20 +263,23 @@ class FileTransferItem(QtGui.QListWidget): icon = QtGui.QIcon(pixmap) self.cancel.setIcon(icon) self.cancel.setIconSize(QtCore.QSize(30, 30)) - self.cancel.setVisible(state > 1) + self.cancel.setVisible(state in ACTIVE_FILE_TRANSFERS) self.cancel.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number)) self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; background-color: none;}') self.accept_or_pause = QtGui.QPushButton(self) self.accept_or_pause.setGeometry(QtCore.QRect(width - 170, 2, 30, 30)) - if state == FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED']: + if state == TOX_FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']: self.accept_or_pause.setVisible(True) self.button_update('accept') - elif state in (0, 1, 5): + elif state in DO_NOT_SHOW_ACCEPT_BUTTON: self.accept_or_pause.setVisible(False) - elif state == FILE_TRANSFER_MESSAGE_STATUS['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.button_update('resume') + elif state not in ACTIVE_FILE_TRANSFERS: + self.accept_or_pause.setVisible(False) + self.cancel.setVisible(False) else: # pause self.accept_or_pause.setVisible(True) self.button_update('pause') @@ -290,8 +291,7 @@ class FileTransferItem(QtGui.QListWidget): self.pb.setGeometry(QtCore.QRect(100, 7, 100, 20)) self.pb.setValue(0) self.pb.setStyleSheet('QProgressBar { background-color: #302F2F; }') - if state < 2: - self.pb.setVisible(False) + self.pb.setVisible(state in SHOW_PROGRESS_BAR) self.file_name = DataLabel(self) self.file_name.setGeometry(QtCore.QRect(210, 7, width - 400, 20)) @@ -306,6 +306,7 @@ class FileTransferItem(QtGui.QListWidget): file_size = '{}KB'.format(file_size) file_data = u'{} {}'.format(file_size, file_name) self.file_name.setText(file_data) + self.file_name.setToolTip(file_name) self.saved_name = file_name self.setFocusPolicy(QtCore.Qt.NoFocus) self.paused = False @@ -319,23 +320,24 @@ class FileTransferItem(QtGui.QListWidget): self.pb.setVisible(False) def accept_or_pause_transfer(self, friend_number, file_number, size): - if self.state == FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED']: + if self.state == TOX_FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']: directory = QtGui.QFileDialog.getExistingDirectory(self, QtGui.QApplication.translate("MainWindow", 'Choose folder', None, QtGui.QApplication.UnicodeUTF8), curr_directory(), QtGui.QFileDialog.ShowDirsOnly) + self.pb.setVisible(True) if directory: pr = profile.Profile.get_instance() pr.accept_transfer(self, directory + '/' + self.saved_name, friend_number, file_number, size) self.button_update('pause') - elif self.state == FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_USER']: # resume + elif self.state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']: # resume self.paused = False profile.Profile.get_instance().resume_transfer(friend_number, file_number) self.button_update('pause') - self.state = FILE_TRANSFER_MESSAGE_STATUS['OUTGOING'] + self.state = TOX_FILE_TRANSFER_STATE['RUNNING'] else: # pause self.paused = True - self.state = FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_USER'] + self.state = TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER'] profile.Profile.get_instance().pause_transfer(friend_number, file_number) self.button_update('resume') self.accept_or_pause.clearFocus() @@ -346,33 +348,27 @@ class FileTransferItem(QtGui.QListWidget): self.accept_or_pause.setIcon(icon) self.accept_or_pause.setIconSize(QtCore.QSize(30, 30)) - def convert(self, state): - # convert TOX_FILE_TRANSFER_STATE to FILE_TRANSFER_MESSAGE_STATUS - d = {0: 2, 1: 6, 2: 1, 3: 0, 4: 5} - return d[state] - @QtCore.Slot(int, float) def update(self, state, progress): self.pb.setValue(int(progress * 100)) - state = self.convert(state) if self.state != state: - if state == FILE_TRANSFER_MESSAGE_STATUS['CANCELLED']: + if state == TOX_FILE_TRANSFER_STATE['CANCELLED']: self.setStyleSheet('QListWidget { border: 1px solid #B40404; }') self.cancel.setVisible(False) self.accept_or_pause.setVisible(False) self.pb.setVisible(False) self.state = state - elif state == FILE_TRANSFER_MESSAGE_STATUS['FINISHED']: + elif state == TOX_FILE_TRANSFER_STATE['FINISHED']: self.accept_or_pause.setVisible(False) self.pb.setVisible(False) self.cancel.setVisible(False) self.setStyleSheet('QListWidget { border: 1px solid green; }') self.state = state - elif state == FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_FRIEND']: + elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND']: self.accept_or_pause.setVisible(False) self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }') self.state = state - elif state == FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_USER']: + elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']: self.button_update('resume') # setup button continue self.setStyleSheet('QListWidget { border: 1px solid green; }') self.state = state @@ -390,7 +386,7 @@ class UnsentFileItem(FileTransferItem): def __init__(self, file_name, size, user, time, width, parent=None): super(UnsentFileItem, self).__init__(file_name, size, time, user, -1, -1, - FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_FRIEND'], width, parent) + TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'], width, parent) self._time = time self.pb.setVisible(False) diff --git a/src/loginscreen.py b/src/loginscreen.py index 9190243..ed0d22a 100644 --- a/src/loginscreen.py +++ b/src/loginscreen.py @@ -7,7 +7,7 @@ except ImportError: from widgets import * -class NickEdit(QtGui.QPlainTextEdit): +class NickEdit(LineEdit): def __init__(self, parent): super(NickEdit, self).__init__(parent) @@ -71,6 +71,7 @@ class LoginScreen(CenteredWidget): QtCore.QMetaObject.connectSlotsByName(self) def retranslateUi(self): + self.new_name.setPlaceholderText(QtGui.QApplication.translate("login", "Profile name", None, QtGui.QApplication.UnicodeUTF8)) self.setWindowTitle(QtGui.QApplication.translate("login", "Log in", None, QtGui.QApplication.UnicodeUTF8)) self.new_profile.setText(QtGui.QApplication.translate("login", "Create", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("login", "Profile name:", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/src/mainscreen.py b/src/mainscreen.py index dc62e8c..c13aafe 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -3,7 +3,7 @@ from menu import * from profile import * from list_items import * -from widgets import MultilineEdit +from widgets import MultilineEdit, LineEdit import plugin_support from mainscreen_widgets import * @@ -147,10 +147,11 @@ class MainWindow(QtGui.QMainWindow): self.search_label.setScaledContents(False) self.search_label.setPixmap(pixmap) - self.contact_name = QtGui.QLineEdit(Form) + self.contact_name = LineEdit(Form) self.contact_name.setGeometry(QtCore.QRect(0, 0, 150, 25)) self.contact_name.setObjectName("contact_name") self.contact_name.textChanged.connect(self.filtering) + self.online_contacts = QtGui.QComboBox(Form) self.online_contacts.setGeometry(QtCore.QRect(150, 0, 120, 25)) self.online_contacts.activated[int].connect(lambda x: self.filtering()) diff --git a/src/menu.py b/src/menu.py index a7ed8bd..1b9ca45 100644 --- a/src/menu.py +++ b/src/menu.py @@ -5,7 +5,7 @@ except ImportError: from settings import * from profile import Profile from util import curr_directory -from widgets import CenteredWidget, DataLabel +from widgets import CenteredWidget, DataLabel, LineEdit import pyaudio import toxencryptsave import plugin_support @@ -27,7 +27,7 @@ class AddContact(CenteredWidget): self.sendRequestButton.setBaseSize(QtCore.QSize(0, 0)) self.sendRequestButton.setObjectName("sendRequestButton") self.sendRequestButton.clicked.connect(self.add_friend) - self.tox_id = QtGui.QLineEdit(self) + self.tox_id = LineEdit(self) self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27)) self.tox_id.setObjectName("lineEdit") self.tox_id.setText(tox_id) @@ -85,12 +85,12 @@ class ProfileSettings(CenteredWidget): self.setObjectName("ProfileSettingsForm") self.setMinimumSize(QtCore.QSize(650, 520)) self.setMaximumSize(QtCore.QSize(650, 520)) - self.nick = QtGui.QLineEdit(self) + self.nick = LineEdit(self) self.nick.setGeometry(QtCore.QRect(30, 60, 350, 27)) self.nick.setObjectName("nick") profile = Profile.get_instance() self.nick.setText(profile.name) - self.status = QtGui.QLineEdit(self) + self.status = LineEdit(self) self.status.setGeometry(QtCore.QRect(30, 130, 350, 27)) self.status.setObjectName("status") self.status.setText(profile.status_message) @@ -138,12 +138,12 @@ class ProfileSettings(CenteredWidget): self.profile_pass.setGeometry(QtCore.QRect(40, 300, 300, 50)) font.setPointSize(18) self.profile_pass.setFont(font) - self.password = QtGui.QLineEdit(self) + self.password = LineEdit(self) self.password.setGeometry(QtCore.QRect(30, 350, 300, 30)) self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.leave_blank = QtGui.QLabel(self) self.leave_blank.setGeometry(QtCore.QRect(340, 350, 300, 30)) - self.confirm_password = QtGui.QLineEdit(self) + self.confirm_password = LineEdit(self) self.confirm_password.setGeometry(QtCore.QRect(30, 400, 300, 30)) self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.set_password = QtGui.QPushButton(self) @@ -262,10 +262,10 @@ class NetworkSettings(CenteredWidget): self.http = QtGui.QCheckBox(self) self.http.setGeometry(QtCore.QRect(20, 70, 97, 22)) self.proxy.setObjectName("proxy") - self.proxyip = QtGui.QLineEdit(self) + self.proxyip = LineEdit(self) self.proxyip.setGeometry(QtCore.QRect(40, 130, 231, 27)) self.proxyip.setObjectName("proxyip") - self.proxyport = QtGui.QLineEdit(self) + self.proxyport = LineEdit(self) self.proxyport.setGeometry(QtCore.QRect(40, 190, 231, 27)) self.proxyport.setObjectName("proxyport") self.label = QtGui.QLabel(self) diff --git a/src/messages.py b/src/messages.py index c8234d0..f04151d 100644 --- a/src/messages.py +++ b/src/messages.py @@ -8,16 +8,6 @@ MESSAGE_TYPE = { 'INFO_MESSAGE': 4 } -FILE_TRANSFER_MESSAGE_STATUS = { - 'FINISHED': 0, - 'CANCELLED': 1, - 'OUTGOING': 2, - 'INCOMING_NOT_STARTED': 3, - 'INCOMING_STARTED': 4, - 'PAUSED_BY_FRIEND': 5, - 'PAUSED_BY_USER': 6 -} - class Message(object): @@ -62,7 +52,7 @@ 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._status > 1 + return self._file_number == file_number and self._status not in (2, 3) def get_friend_number(self): return self._friend_number diff --git a/src/passwordscreen.py b/src/passwordscreen.py index ef4ad5f..615fdea 100644 --- a/src/passwordscreen.py +++ b/src/passwordscreen.py @@ -1,11 +1,11 @@ -from widgets import CenteredWidget +from widgets import CenteredWidget, LineEdit try: from PySide import QtCore, QtGui except ImportError: from PyQt4 import QtCore, QtGui -class PasswordArea(QtGui.QLineEdit): +class PasswordArea(LineEdit): def __init__(self, parent): super(PasswordArea, self).__init__(parent) diff --git a/src/profile.py b/src/profile.py index 027f57a..21dcad0 100644 --- a/src/profile.py +++ b/src/profile.py @@ -173,7 +173,7 @@ class Profile(contact.Contact, Singleton): self.create_unsent_file_item(message) continue item = self.create_file_transfer_item(message) - if message.get_status() >= 2: # active file transfer + if message.get_status() in ACTIVE_FILE_TRANSFERS: # active file transfer try: ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())] ft.set_state_changed_handler(item.update) @@ -453,7 +453,7 @@ class Profile(contact.Contact, Singleton): self.create_unsent_file_item(message) continue item = self.create_file_transfer_item(message, False) - if message.get_status() >= 2: # active file transfer + if message.get_status() in ACTIVE_FILE_TRANSFERS: # active file transfer ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())] ft.set_state_changed_handler(item.update) elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline @@ -757,12 +757,12 @@ class Profile(contact.Contact, Singleton): settings = Settings.get_instance() friend = self.get_friend_by_number(friend_number) auto = settings['allow_auto_accept'] and friend.tox_id in settings['auto_accept_from_friends'] - inline = (file_name in ('toxygen_inline.png', 'utox-inline.png', 'sticker.png')) and settings['allow_inline'] + inline = (file_name in ALLOWED_FILES) and settings['allow_inline'] if inline and size < 1024 * 1024: self.accept_transfer(None, '', friend_number, file_number, size, True) tm = TransferMessage(MESSAGE_OWNER['FRIEND'], time.time(), - FILE_TRANSFER_MESSAGE_STATUS['INCOMING_STARTED'], + TOX_FILE_TRANSFER_STATE['RUNNING'], size, file_name, friend_number, @@ -783,7 +783,7 @@ class Profile(contact.Contact, Singleton): self.accept_transfer(None, path + '/' + new_file_name, friend_number, file_number, size) tm = TransferMessage(MESSAGE_OWNER['FRIEND'], time.time(), - FILE_TRANSFER_MESSAGE_STATUS['INCOMING_STARTED'], + TOX_FILE_TRANSFER_STATE['RUNNING'], size, new_file_name, friend_number, @@ -791,7 +791,7 @@ class Profile(contact.Contact, Singleton): else: tm = TransferMessage(MESSAGE_OWNER['FRIEND'], time.time(), - FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED'], + TOX_FILE_TRANSFER_STATE['INCOMING_NOT_STARTED'], size, file_name, friend_number, @@ -813,8 +813,8 @@ class Profile(contact.Contact, Singleton): :param file_number: file number :param already_cancelled: was cancelled by friend """ - self.get_friend_by_number(friend_number).update_transfer_data(file_number, - FILE_TRANSFER_MESSAGE_STATUS['CANCELLED']) + i = self.get_friend_by_number(friend_number).update_transfer_data(file_number, + TOX_FILE_TRANSFER_STATE['CANCELLED']) if (friend_number, file_number) in self._file_transfers: tr = self._file_transfers[(friend_number, file_number)] if not already_cancelled: @@ -825,7 +825,12 @@ class Profile(contact.Contact, Singleton): del tr del self._file_transfers[(friend_number, file_number)] else: - self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) + if not already_cancelled: + self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) + if friend_number == self.get_active_number(): + tmp = self._messages.count() + i + if tmp >= 0: + self._messages.itemWidget(self._messages.item(tmp)).update(TOX_FILE_TRANSFER_STATE['CANCELLED'], 0) def cancel_not_started_transfer(self, time): self._friends[self._active_friend].delete_one_unsent_file(time) @@ -837,7 +842,7 @@ class Profile(contact.Contact, Singleton): """ tr = self._file_transfers[(friend_number, file_number)] tr.pause(by_friend) - t = FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_FRIEND'] if by_friend else FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_USER'] + t = TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'] if by_friend else TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER'] self.get_friend_by_number(friend_number).update_transfer_data(file_number, t) def resume_transfer(self, friend_number, file_number, by_friend=False): @@ -845,7 +850,7 @@ class Profile(contact.Contact, Singleton): Resume transfer with specified data """ self.get_friend_by_number(friend_number).update_transfer_data(file_number, - FILE_TRANSFER_MESSAGE_STATUS['OUTGOING']) + TOX_FILE_TRANSFER_STATE['RUNNING']) tr = self._file_transfers[(friend_number, file_number)] if by_friend: tr.state = TOX_FILE_TRANSFER_STATE['RUNNING'] @@ -871,7 +876,7 @@ class Profile(contact.Contact, Singleton): if item is not None: rt.set_state_changed_handler(item.update) self.get_friend_by_number(friend_number).update_transfer_data(file_number, - FILE_TRANSFER_MESSAGE_STATUS['INCOMING_STARTED']) + TOX_FILE_TRANSFER_STATE['RUNNING']) def send_screenshot(self, data): """ @@ -899,7 +904,7 @@ class Profile(contact.Contact, Singleton): self._file_transfers[(friend.number, st.get_file_number())] = st tm = TransferMessage(MESSAGE_OWNER['ME'], time.time(), - FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_FRIEND'], # OUTGOING NOT STARTED + TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'], # OUTGOING NOT STARTED len(data), file_name, friend.number, @@ -929,7 +934,7 @@ class Profile(contact.Contact, Singleton): self._file_transfers[(friend_number, st.get_file_number())] = st tm = TransferMessage(MESSAGE_OWNER['ME'], time.time(), - FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_FRIEND'], # OUTGOING NOT STARTED + TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'], # OUTGOING NOT STARTED os.path.getsize(path), os.path.basename(path), friend_number, @@ -946,25 +951,26 @@ class Profile(contact.Contact, Singleton): if (friend_number, file_number) in self._file_transfers: transfer = self._file_transfers[(friend_number, file_number)] transfer.write_chunk(position, data) - if transfer.state in (2, 3): # finished or cancelled + if transfer.state not in ACTIVE_FILE_TRANSFERS: # finished or cancelled if type(transfer) is ReceiveAvatar: self.get_friend_by_number(friend_number).load_avatar() self.set_active(None) elif type(transfer) is ReceiveToBuffer: # inline image inline = InlineImage(transfer.get_data()) i = self.get_friend_by_number(friend_number).update_transfer_data(file_number, - FILE_TRANSFER_MESSAGE_STATUS['FINISHED'], + TOX_FILE_TRANSFER_STATE['FINISHED'], inline) if friend_number == self.get_active_number(): count = self._messages.count() - item = InlineImageItem(transfer.get_data(), self._messages.width()) - elem = QtGui.QListWidgetItem() - elem.setSizeHint(QtCore.QSize(600, item.height())) - self._messages.insertItem(count + i + 1, elem) - self._messages.setItemWidget(elem, item) + if count + i + 1 >= 0: + item = InlineImageItem(transfer.get_data(), self._messages.width()) + elem = QtGui.QListWidgetItem() + elem.setSizeHint(QtCore.QSize(600, item.height())) + self._messages.insertItem(count + i + 1, elem) + self._messages.setItemWidget(elem, item) else: self.get_friend_by_number(friend_number).update_transfer_data(file_number, - FILE_TRANSFER_MESSAGE_STATUS['FINISHED']) + TOX_FILE_TRANSFER_STATE['FINISHED']) del self._file_transfers[(friend_number, file_number)] def outgoing_chunk(self, friend_number, file_number, position, size): @@ -974,18 +980,26 @@ class Profile(contact.Contact, Singleton): if (friend_number, file_number) in self._file_transfers: transfer = self._file_transfers[(friend_number, file_number)] transfer.send_chunk(position, size) - if transfer.state in (2, 3): # finished or cancelled + if transfer.state not in ACTIVE_FILE_TRANSFERS: # finished or cancelled del self._file_transfers[(friend_number, file_number)] if type(transfer) is not SendAvatar: if type(transfer) is SendFromBuffer and Settings.get_instance()['allow_inline']: # inline inline = InlineImage(transfer.get_data()) - self.get_friend_by_number(friend_number).update_transfer_data(file_number, - FILE_TRANSFER_MESSAGE_STATUS['FINISHED'], - inline) - self.update() # not load all messages? + i = self.get_friend_by_number(friend_number).update_transfer_data(file_number, + TOX_FILE_TRANSFER_STATE[ + 'FINISHED'], + inline) + if friend_number == self.get_active_number(): + count = self._messages.count() + if count + i + 1 >= 0: + item = InlineImageItem(transfer.get_data(), self._messages.width()) + elem = QtGui.QListWidgetItem() + elem.setSizeHint(QtCore.QSize(600, item.height())) + self._messages.insertItem(count + i + 1, elem) + self._messages.setItemWidget(elem, item) else: self.get_friend_by_number(friend_number).update_transfer_data(file_number, - FILE_TRANSFER_MESSAGE_STATUS['FINISHED']) + TOX_FILE_TRANSFER_STATE['FINISHED']) # ----------------------------------------------------------------------------------------------------------------- # Avatars support @@ -1009,7 +1023,7 @@ class Profile(contact.Contact, Singleton): :param size: size of avatar or 0 (default avatar) """ ra = ReceiveAvatar(self._tox, friend_number, size, file_number) - if ra.state != TOX_FILE_TRANSFER_STATE['CANCELED']: + if ra.state != TOX_FILE_TRANSFER_STATE['CANCELLED']: self._file_transfers[(friend_number, file_number)] = ra else: self.get_friend_by_number(friend_number).load_avatar() diff --git a/src/widgets.py b/src/widgets.py index 3fdccf3..30482c6 100644 --- a/src/widgets.py +++ b/src/widgets.py @@ -29,6 +29,17 @@ class CenteredWidget(QtGui.QWidget): self.move(qr.topLeft()) +class LineEdit(QtGui.QLineEdit): + + def __init__(self, parent=None): + super(LineEdit, self).__init__(parent) + + def contextMenuEvent(self, event): + menu = create_menu(self.createStandardContextMenu()) + menu.exec_(event.globalPos()) + del menu + + class QRightClickButton(QtGui.QPushButton): """ Button with right click support