file transfers items bug fixes, translatable menu everywhere

This commit is contained in:
ingvar1995 2016-06-17 00:10:26 +03:00
parent 5fd5a9bd85
commit fd9bfa52f3
11 changed files with 118 additions and 92 deletions

View File

@ -226,11 +226,11 @@ def file_recv_control(tox, friend_number, file_number, file_control, user_data):
Friend cancelled, paused or resumed file transfer Friend cancelled, paused or resumed file transfer
""" """
if file_control == TOX_FILE_CONTROL['CANCEL']: 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']: 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']: 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 # Callbacks - custom packets

View File

@ -9,17 +9,28 @@ try:
except ImportError: except ImportError:
from PyQt4 import QtCore from PyQt4 import QtCore
# TODO: threads!
TOX_FILE_TRANSFER_STATE = { TOX_FILE_TRANSFER_STATE = {
'RUNNING': 0, 'RUNNING': 0,
'PAUSED': 1, 'PAUSED_BY_USER': 1,
'CANCELED': 2, 'CANCELLED': 2,
'FINISHED': 3, '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): class StateSignal(QtCore.QObject):
try: try:
@ -64,14 +75,14 @@ class FileTransfer(QtCore.QObject):
self.send_control(TOX_FILE_CONTROL['CANCEL']) self.send_control(TOX_FILE_CONTROL['CANCEL'])
if hasattr(self, '_file'): if hasattr(self, '_file'):
self._file.close() self._file.close()
self._state_changed.signal.emit(self.state, 1) self.signal()
def cancelled(self): def cancelled(self):
if hasattr(self, '_file'): if hasattr(self, '_file'):
sleep(0.1) sleep(0.1)
self._file.close() self._file.close()
self.state = TOX_FILE_TRANSFER_STATE['CANCELED'] self.state = TOX_FILE_TRANSFER_STATE['CANCELLED']
self._state_changed.signal.emit(self.state, 1) self.signal()
def pause(self, by_friend): def pause(self, by_friend):
if not by_friend: if not by_friend:
@ -102,6 +113,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._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 '')
@ -121,7 +133,7 @@ class SendTransfer(FileTransfer):
if hasattr(self, '_file'): if hasattr(self, '_file'):
self._file.close() self._file.close()
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 SendAvatar(SendTransfer): class SendAvatar(SendTransfer):
@ -145,6 +157,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._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)

View File

@ -136,8 +136,8 @@ class Friend(contact.Contact):
tr = filter(lambda x: x.get_type() == MESSAGE_TYPE['FILE_TRANSFER'] and x.is_active(file_number), tr = filter(lambda x: x.get_type() == MESSAGE_TYPE['FILE_TRANSFER'] and x.is_active(file_number),
self._corr)[0] self._corr)[0]
tr.set_status(status) tr.set_status(status)
if inline: # inline was loaded
i = self._corr.index(tr) i = self._corr.index(tr)
if inline: # inline was loaded
self._corr.insert(i, inline) self._corr.insert(i, inline)
return i - len(self._corr) return i - len(self._corr)
except: except:

View File

@ -4,9 +4,8 @@ try:
except ImportError: except ImportError:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
import profile 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 util import curr_directory, convert_time
from messages import FILE_TRANSFER_MESSAGE_STATUS
from widgets import DataLabel, create_menu from widgets import DataLabel, create_menu
import cgi import cgi
import smileys import smileys
@ -233,13 +232,12 @@ class FileTransferItem(QtGui.QListWidget):
QtGui.QListWidget.__init__(self, parent) QtGui.QListWidget.__init__(self, parent)
self.resize(QtCore.QSize(width, 34)) 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; }') 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; }') self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }')
else: else:
self.setStyleSheet('QListWidget { border: 1px solid green; }') self.setStyleSheet('QListWidget { border: 1px solid green; }')
self.state = state self.state = state
self.name = DataLabel(self) self.name = DataLabel(self)
@ -265,20 +263,23 @@ class FileTransferItem(QtGui.QListWidget):
icon = QtGui.QIcon(pixmap) icon = QtGui.QIcon(pixmap)
self.cancel.setIcon(icon) self.cancel.setIcon(icon)
self.cancel.setIconSize(QtCore.QSize(30, 30)) 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.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number))
self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; background-color: none;}') self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; background-color: none;}')
self.accept_or_pause = QtGui.QPushButton(self) self.accept_or_pause = QtGui.QPushButton(self)
self.accept_or_pause.setGeometry(QtCore.QRect(width - 170, 2, 30, 30)) 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.accept_or_pause.setVisible(True)
self.button_update('accept') self.button_update('accept')
elif state in (0, 1, 5): elif state in DO_NOT_SHOW_ACCEPT_BUTTON:
self.accept_or_pause.setVisible(False) 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.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')
@ -290,8 +291,7 @@ class FileTransferItem(QtGui.QListWidget):
self.pb.setGeometry(QtCore.QRect(100, 7, 100, 20)) self.pb.setGeometry(QtCore.QRect(100, 7, 100, 20))
self.pb.setValue(0) self.pb.setValue(0)
self.pb.setStyleSheet('QProgressBar { background-color: #302F2F; }') self.pb.setStyleSheet('QProgressBar { background-color: #302F2F; }')
if state < 2: self.pb.setVisible(state in SHOW_PROGRESS_BAR)
self.pb.setVisible(False)
self.file_name = DataLabel(self) self.file_name = DataLabel(self)
self.file_name.setGeometry(QtCore.QRect(210, 7, width - 400, 20)) 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_size = '{}KB'.format(file_size)
file_data = u'{} {}'.format(file_size, file_name) file_data = u'{} {}'.format(file_size, file_name)
self.file_name.setText(file_data) self.file_name.setText(file_data)
self.file_name.setToolTip(file_name)
self.saved_name = file_name self.saved_name = file_name
self.setFocusPolicy(QtCore.Qt.NoFocus) self.setFocusPolicy(QtCore.Qt.NoFocus)
self.paused = False self.paused = False
@ -319,23 +320,24 @@ class FileTransferItem(QtGui.QListWidget):
self.pb.setVisible(False) self.pb.setVisible(False)
def accept_or_pause_transfer(self, friend_number, file_number, size): 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, directory = QtGui.QFileDialog.getExistingDirectory(self,
QtGui.QApplication.translate("MainWindow", 'Choose folder', None, QtGui.QApplication.UnicodeUTF8), QtGui.QApplication.translate("MainWindow", 'Choose folder', None, QtGui.QApplication.UnicodeUTF8),
curr_directory(), curr_directory(),
QtGui.QFileDialog.ShowDirsOnly) QtGui.QFileDialog.ShowDirsOnly)
self.pb.setVisible(True)
if directory: if directory:
pr = profile.Profile.get_instance() pr = profile.Profile.get_instance()
pr.accept_transfer(self, directory + '/' + self.saved_name, friend_number, file_number, size) pr.accept_transfer(self, directory + '/' + self.saved_name, friend_number, file_number, size)
self.button_update('pause') 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 self.paused = False
profile.Profile.get_instance().resume_transfer(friend_number, file_number) profile.Profile.get_instance().resume_transfer(friend_number, file_number)
self.button_update('pause') self.button_update('pause')
self.state = FILE_TRANSFER_MESSAGE_STATUS['OUTGOING'] self.state = TOX_FILE_TRANSFER_STATE['RUNNING']
else: # pause else: # pause
self.paused = True 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) profile.Profile.get_instance().pause_transfer(friend_number, file_number)
self.button_update('resume') self.button_update('resume')
self.accept_or_pause.clearFocus() self.accept_or_pause.clearFocus()
@ -346,33 +348,27 @@ class FileTransferItem(QtGui.QListWidget):
self.accept_or_pause.setIcon(icon) self.accept_or_pause.setIcon(icon)
self.accept_or_pause.setIconSize(QtCore.QSize(30, 30)) 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) @QtCore.Slot(int, float)
def update(self, state, progress): def update(self, state, progress):
self.pb.setValue(int(progress * 100)) self.pb.setValue(int(progress * 100))
state = self.convert(state)
if self.state != 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.setStyleSheet('QListWidget { border: 1px solid #B40404; }')
self.cancel.setVisible(False) self.cancel.setVisible(False)
self.accept_or_pause.setVisible(False) self.accept_or_pause.setVisible(False)
self.pb.setVisible(False) self.pb.setVisible(False)
self.state = state self.state = state
elif state == FILE_TRANSFER_MESSAGE_STATUS['FINISHED']: elif state == TOX_FILE_TRANSFER_STATE['FINISHED']:
self.accept_or_pause.setVisible(False) self.accept_or_pause.setVisible(False)
self.pb.setVisible(False) self.pb.setVisible(False)
self.cancel.setVisible(False) self.cancel.setVisible(False)
self.setStyleSheet('QListWidget { border: 1px solid green; }') self.setStyleSheet('QListWidget { border: 1px solid green; }')
self.state = state 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.accept_or_pause.setVisible(False)
self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }') self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }')
self.state = state 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.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
@ -390,7 +386,7 @@ class UnsentFileItem(FileTransferItem):
def __init__(self, file_name, size, user, time, width, parent=None): def __init__(self, file_name, size, user, time, width, parent=None):
super(UnsentFileItem, self).__init__(file_name, size, time, user, -1, -1, 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._time = time
self.pb.setVisible(False) self.pb.setVisible(False)

View File

@ -7,7 +7,7 @@ except ImportError:
from widgets import * from widgets import *
class NickEdit(QtGui.QPlainTextEdit): class NickEdit(LineEdit):
def __init__(self, parent): def __init__(self, parent):
super(NickEdit, self).__init__(parent) super(NickEdit, self).__init__(parent)
@ -71,6 +71,7 @@ class LoginScreen(CenteredWidget):
QtCore.QMetaObject.connectSlotsByName(self) QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(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.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.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)) self.label.setText(QtGui.QApplication.translate("login", "Profile name:", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -3,7 +3,7 @@
from menu import * from menu import *
from profile import * from profile import *
from list_items import * from list_items import *
from widgets import MultilineEdit from widgets import MultilineEdit, LineEdit
import plugin_support import plugin_support
from mainscreen_widgets import * from mainscreen_widgets import *
@ -147,10 +147,11 @@ class MainWindow(QtGui.QMainWindow):
self.search_label.setScaledContents(False) self.search_label.setScaledContents(False)
self.search_label.setPixmap(pixmap) 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.setGeometry(QtCore.QRect(0, 0, 150, 25))
self.contact_name.setObjectName("contact_name") self.contact_name.setObjectName("contact_name")
self.contact_name.textChanged.connect(self.filtering) self.contact_name.textChanged.connect(self.filtering)
self.online_contacts = QtGui.QComboBox(Form) self.online_contacts = QtGui.QComboBox(Form)
self.online_contacts.setGeometry(QtCore.QRect(150, 0, 120, 25)) self.online_contacts.setGeometry(QtCore.QRect(150, 0, 120, 25))
self.online_contacts.activated[int].connect(lambda x: self.filtering()) self.online_contacts.activated[int].connect(lambda x: self.filtering())

View File

@ -5,7 +5,7 @@ except ImportError:
from settings import * from settings import *
from profile import Profile from profile import Profile
from util import curr_directory from util import curr_directory
from widgets import CenteredWidget, DataLabel from widgets import CenteredWidget, DataLabel, LineEdit
import pyaudio import pyaudio
import toxencryptsave import toxencryptsave
import plugin_support import plugin_support
@ -27,7 +27,7 @@ class AddContact(CenteredWidget):
self.sendRequestButton.setBaseSize(QtCore.QSize(0, 0)) self.sendRequestButton.setBaseSize(QtCore.QSize(0, 0))
self.sendRequestButton.setObjectName("sendRequestButton") self.sendRequestButton.setObjectName("sendRequestButton")
self.sendRequestButton.clicked.connect(self.add_friend) 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.setGeometry(QtCore.QRect(50, 40, 471, 27))
self.tox_id.setObjectName("lineEdit") self.tox_id.setObjectName("lineEdit")
self.tox_id.setText(tox_id) self.tox_id.setText(tox_id)
@ -85,12 +85,12 @@ class ProfileSettings(CenteredWidget):
self.setObjectName("ProfileSettingsForm") self.setObjectName("ProfileSettingsForm")
self.setMinimumSize(QtCore.QSize(650, 520)) self.setMinimumSize(QtCore.QSize(650, 520))
self.setMaximumSize(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.setGeometry(QtCore.QRect(30, 60, 350, 27))
self.nick.setObjectName("nick") self.nick.setObjectName("nick")
profile = Profile.get_instance() profile = Profile.get_instance()
self.nick.setText(profile.name) 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.setGeometry(QtCore.QRect(30, 130, 350, 27))
self.status.setObjectName("status") self.status.setObjectName("status")
self.status.setText(profile.status_message) self.status.setText(profile.status_message)
@ -138,12 +138,12 @@ class ProfileSettings(CenteredWidget):
self.profile_pass.setGeometry(QtCore.QRect(40, 300, 300, 50)) self.profile_pass.setGeometry(QtCore.QRect(40, 300, 300, 50))
font.setPointSize(18) font.setPointSize(18)
self.profile_pass.setFont(font) 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.setGeometry(QtCore.QRect(30, 350, 300, 30))
self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
self.leave_blank = QtGui.QLabel(self) self.leave_blank = QtGui.QLabel(self)
self.leave_blank.setGeometry(QtCore.QRect(340, 350, 300, 30)) 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.setGeometry(QtCore.QRect(30, 400, 300, 30))
self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
self.set_password = QtGui.QPushButton(self) self.set_password = QtGui.QPushButton(self)
@ -262,10 +262,10 @@ class NetworkSettings(CenteredWidget):
self.http = QtGui.QCheckBox(self) self.http = QtGui.QCheckBox(self)
self.http.setGeometry(QtCore.QRect(20, 70, 97, 22)) self.http.setGeometry(QtCore.QRect(20, 70, 97, 22))
self.proxy.setObjectName("proxy") self.proxy.setObjectName("proxy")
self.proxyip = QtGui.QLineEdit(self) self.proxyip = LineEdit(self)
self.proxyip.setGeometry(QtCore.QRect(40, 130, 231, 27)) self.proxyip.setGeometry(QtCore.QRect(40, 130, 231, 27))
self.proxyip.setObjectName("proxyip") self.proxyip.setObjectName("proxyip")
self.proxyport = QtGui.QLineEdit(self) self.proxyport = LineEdit(self)
self.proxyport.setGeometry(QtCore.QRect(40, 190, 231, 27)) self.proxyport.setGeometry(QtCore.QRect(40, 190, 231, 27))
self.proxyport.setObjectName("proxyport") self.proxyport.setObjectName("proxyport")
self.label = QtGui.QLabel(self) self.label = QtGui.QLabel(self)

View File

@ -8,16 +8,6 @@ MESSAGE_TYPE = {
'INFO_MESSAGE': 4 '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): class Message(object):
@ -62,7 +52,7 @@ class TransferMessage(Message):
self._friend_number, self._file_number = friend_number, file_number self._friend_number, self._file_number = friend_number, file_number
def is_active(self, 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): def get_friend_number(self):
return self._friend_number return self._friend_number

View File

@ -1,11 +1,11 @@
from widgets import CenteredWidget from widgets import CenteredWidget, LineEdit
try: try:
from PySide import QtCore, QtGui from PySide import QtCore, QtGui
except ImportError: except ImportError:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
class PasswordArea(QtGui.QLineEdit): class PasswordArea(LineEdit):
def __init__(self, parent): def __init__(self, parent):
super(PasswordArea, self).__init__(parent) super(PasswordArea, self).__init__(parent)

View File

@ -173,7 +173,7 @@ class Profile(contact.Contact, Singleton):
self.create_unsent_file_item(message) self.create_unsent_file_item(message)
continue continue
item = self.create_file_transfer_item(message) 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: try:
ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())] ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())]
ft.set_state_changed_handler(item.update) ft.set_state_changed_handler(item.update)
@ -453,7 +453,7 @@ class Profile(contact.Contact, Singleton):
self.create_unsent_file_item(message) self.create_unsent_file_item(message)
continue continue
item = self.create_file_transfer_item(message, False) 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 = self._file_transfers[(message.get_friend_number(), message.get_file_number())]
ft.set_state_changed_handler(item.update) ft.set_state_changed_handler(item.update)
elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
@ -757,12 +757,12 @@ class Profile(contact.Contact, Singleton):
settings = Settings.get_instance() settings = Settings.get_instance()
friend = self.get_friend_by_number(friend_number) friend = self.get_friend_by_number(friend_number)
auto = settings['allow_auto_accept'] and friend.tox_id in settings['auto_accept_from_friends'] 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: if inline and size < 1024 * 1024:
self.accept_transfer(None, '', friend_number, file_number, size, True) self.accept_transfer(None, '', friend_number, file_number, size, True)
tm = TransferMessage(MESSAGE_OWNER['FRIEND'], tm = TransferMessage(MESSAGE_OWNER['FRIEND'],
time.time(), time.time(),
FILE_TRANSFER_MESSAGE_STATUS['INCOMING_STARTED'], TOX_FILE_TRANSFER_STATE['RUNNING'],
size, size,
file_name, file_name,
friend_number, friend_number,
@ -783,7 +783,7 @@ class Profile(contact.Contact, Singleton):
self.accept_transfer(None, path + '/' + new_file_name, friend_number, file_number, size) self.accept_transfer(None, path + '/' + new_file_name, friend_number, file_number, size)
tm = TransferMessage(MESSAGE_OWNER['FRIEND'], tm = TransferMessage(MESSAGE_OWNER['FRIEND'],
time.time(), time.time(),
FILE_TRANSFER_MESSAGE_STATUS['INCOMING_STARTED'], TOX_FILE_TRANSFER_STATE['RUNNING'],
size, size,
new_file_name, new_file_name,
friend_number, friend_number,
@ -791,7 +791,7 @@ class Profile(contact.Contact, Singleton):
else: else:
tm = TransferMessage(MESSAGE_OWNER['FRIEND'], tm = TransferMessage(MESSAGE_OWNER['FRIEND'],
time.time(), time.time(),
FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED'], TOX_FILE_TRANSFER_STATE['INCOMING_NOT_STARTED'],
size, size,
file_name, file_name,
friend_number, friend_number,
@ -813,8 +813,8 @@ class Profile(contact.Contact, Singleton):
:param file_number: file number :param file_number: file number
:param already_cancelled: was cancelled by friend :param already_cancelled: was cancelled by friend
""" """
self.get_friend_by_number(friend_number).update_transfer_data(file_number, i = self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['CANCELLED']) TOX_FILE_TRANSFER_STATE['CANCELLED'])
if (friend_number, file_number) in self._file_transfers: if (friend_number, file_number) in self._file_transfers:
tr = self._file_transfers[(friend_number, file_number)] tr = self._file_transfers[(friend_number, file_number)]
if not already_cancelled: if not already_cancelled:
@ -825,7 +825,12 @@ class Profile(contact.Contact, Singleton):
del tr del tr
del self._file_transfers[(friend_number, file_number)] del self._file_transfers[(friend_number, file_number)]
else: else:
if not already_cancelled:
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 == 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): def cancel_not_started_transfer(self, time):
self._friends[self._active_friend].delete_one_unsent_file(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 = self._file_transfers[(friend_number, file_number)]
tr.pause(by_friend) 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) self.get_friend_by_number(friend_number).update_transfer_data(file_number, t)
def resume_transfer(self, friend_number, file_number, by_friend=False): 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 Resume transfer with specified data
""" """
self.get_friend_by_number(friend_number).update_transfer_data(file_number, 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)] tr = self._file_transfers[(friend_number, file_number)]
if by_friend: if by_friend:
tr.state = TOX_FILE_TRANSFER_STATE['RUNNING'] tr.state = TOX_FILE_TRANSFER_STATE['RUNNING']
@ -871,7 +876,7 @@ class Profile(contact.Contact, Singleton):
if item is not None: if item is not None:
rt.set_state_changed_handler(item.update) rt.set_state_changed_handler(item.update)
self.get_friend_by_number(friend_number).update_transfer_data(file_number, 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): def send_screenshot(self, data):
""" """
@ -899,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(),
FILE_TRANSFER_MESSAGE_STATUS['PAUSED_BY_FRIEND'], # OUTGOING NOT STARTED TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND'], # OUTGOING NOT STARTED
len(data), len(data),
file_name, file_name,
friend.number, friend.number,
@ -929,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(),
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.getsize(path),
os.path.basename(path), os.path.basename(path),
friend_number, friend_number,
@ -946,17 +951,18 @@ class Profile(contact.Contact, Singleton):
if (friend_number, file_number) in self._file_transfers: if (friend_number, file_number) in self._file_transfers:
transfer = self._file_transfers[(friend_number, file_number)] transfer = self._file_transfers[(friend_number, file_number)]
transfer.write_chunk(position, data) 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: if type(transfer) is ReceiveAvatar:
self.get_friend_by_number(friend_number).load_avatar() self.get_friend_by_number(friend_number).load_avatar()
self.set_active(None) self.set_active(None)
elif type(transfer) is ReceiveToBuffer: # inline image elif type(transfer) is ReceiveToBuffer: # inline image
inline = InlineImage(transfer.get_data()) inline = InlineImage(transfer.get_data())
i = self.get_friend_by_number(friend_number).update_transfer_data(file_number, i = self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['FINISHED'], TOX_FILE_TRANSFER_STATE['FINISHED'],
inline) inline)
if friend_number == self.get_active_number(): if friend_number == self.get_active_number():
count = self._messages.count() count = self._messages.count()
if count + i + 1 >= 0:
item = InlineImageItem(transfer.get_data(), self._messages.width()) item = InlineImageItem(transfer.get_data(), self._messages.width())
elem = QtGui.QListWidgetItem() elem = QtGui.QListWidgetItem()
elem.setSizeHint(QtCore.QSize(600, item.height())) elem.setSizeHint(QtCore.QSize(600, item.height()))
@ -964,7 +970,7 @@ class Profile(contact.Contact, Singleton):
self._messages.setItemWidget(elem, item) self._messages.setItemWidget(elem, item)
else: else:
self.get_friend_by_number(friend_number).update_transfer_data(file_number, 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)] del self._file_transfers[(friend_number, file_number)]
def outgoing_chunk(self, friend_number, file_number, position, size): 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: if (friend_number, file_number) in self._file_transfers:
transfer = self._file_transfers[(friend_number, file_number)] transfer = self._file_transfers[(friend_number, file_number)]
transfer.send_chunk(position, size) 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)] del self._file_transfers[(friend_number, file_number)]
if type(transfer) is not SendAvatar: if type(transfer) is not SendAvatar:
if type(transfer) is SendFromBuffer and Settings.get_instance()['allow_inline']: # inline if type(transfer) is SendFromBuffer and Settings.get_instance()['allow_inline']: # inline
inline = InlineImage(transfer.get_data()) inline = InlineImage(transfer.get_data())
self.get_friend_by_number(friend_number).update_transfer_data(file_number, i = self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['FINISHED'], TOX_FILE_TRANSFER_STATE[
'FINISHED'],
inline) inline)
self.update() # not load all messages? 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: else:
self.get_friend_by_number(friend_number).update_transfer_data(file_number, self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['FINISHED']) TOX_FILE_TRANSFER_STATE['FINISHED'])
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Avatars support # Avatars support
@ -1009,7 +1023,7 @@ class Profile(contact.Contact, Singleton):
:param size: size of avatar or 0 (default avatar) :param size: size of avatar or 0 (default avatar)
""" """
ra = ReceiveAvatar(self._tox, friend_number, size, file_number) 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 self._file_transfers[(friend_number, file_number)] = ra
else: else:
self.get_friend_by_number(friend_number).load_avatar() self.get_friend_by_number(friend_number).load_avatar()

View File

@ -29,6 +29,17 @@ class CenteredWidget(QtGui.QWidget):
self.move(qr.topLeft()) 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): class QRightClickButton(QtGui.QPushButton):
""" """
Button with right click support Button with right click support