tox: links in messages support and bug fixes
This commit is contained in:
parent
4b4075606e
commit
8fb263dadc
@ -75,7 +75,7 @@ def friend_connection_status(tox, friend_num, new_status, user_data):
|
|||||||
"""
|
"""
|
||||||
Check friend's connection status (offline, udp, tcp)
|
Check friend's connection status (offline, udp, tcp)
|
||||||
"""
|
"""
|
||||||
print "Friend #{} connected! Friend's status: {}".format(friend_num, new_status)
|
print "Friend #{} connection status: {}".format(friend_num, new_status)
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
friend = profile.get_friend_by_number(friend_num)
|
friend = profile.get_friend_by_number(friend_num)
|
||||||
if new_status == TOX_CONNECTION['NONE']:
|
if new_status == TOX_CONNECTION['NONE']:
|
||||||
@ -127,7 +127,7 @@ def friend_message(window, tray):
|
|||||||
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'), tray, window)
|
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'), tray, window)
|
||||||
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
||||||
tray.setIcon(QtGui.QIcon(curr_directory() + '/images/icon_new_messages.png'))
|
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(curr_directory() + '/images/icon_new_messages.png'))
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,8 +13,6 @@ import cgi
|
|||||||
|
|
||||||
class MessageEdit(QtGui.QTextBrowser):
|
class MessageEdit(QtGui.QTextBrowser):
|
||||||
|
|
||||||
# TODO: add anchor clicked with tox: support and unfocus links
|
|
||||||
|
|
||||||
def __init__(self, text, width, parent=None):
|
def __init__(self, text, width, parent=None):
|
||||||
super(MessageEdit, self).__init__(parent)
|
super(MessageEdit, self).__init__(parent)
|
||||||
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
@ -22,6 +20,7 @@ class MessageEdit(QtGui.QTextBrowser):
|
|||||||
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
|
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
|
||||||
self.document().setTextWidth(width)
|
self.document().setTextWidth(width)
|
||||||
self.setOpenExternalLinks(True)
|
self.setOpenExternalLinks(True)
|
||||||
|
self.setOpenLinks(False)
|
||||||
self.setTextWithLinks(text)
|
self.setTextWithLinks(text)
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setFamily("Times New Roman")
|
font.setFamily("Times New Roman")
|
||||||
@ -30,6 +29,7 @@ class MessageEdit(QtGui.QTextBrowser):
|
|||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
self.setFixedHeight(self.document().size().height())
|
self.setFixedHeight(self.document().size().height())
|
||||||
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
||||||
|
self.anchorClicked.connect(self.on_anchor_clicked)
|
||||||
|
|
||||||
def contextMenuEvent(self, event):
|
def contextMenuEvent(self, event):
|
||||||
menu = create_menu(self.createStandardContextMenu(event.pos()))
|
menu = create_menu(self.createStandardContextMenu(event.pos()))
|
||||||
@ -37,6 +37,16 @@ class MessageEdit(QtGui.QTextBrowser):
|
|||||||
menu.exec_(event.globalPos())
|
menu.exec_(event.globalPos())
|
||||||
del menu
|
del menu
|
||||||
|
|
||||||
|
def on_anchor_clicked(self, url):
|
||||||
|
text = str(url.toString())
|
||||||
|
if text.startswith('tox:'):
|
||||||
|
import menu
|
||||||
|
self.add_contact = menu.AddContact(text[4:])
|
||||||
|
self.add_contact.show()
|
||||||
|
else:
|
||||||
|
QtGui.QDesktopServices.openUrl(url)
|
||||||
|
self.clearFocus()
|
||||||
|
|
||||||
def setTextWithLinks(self, text):
|
def setTextWithLinks(self, text):
|
||||||
text = cgi.escape(text)
|
text = cgi.escape(text)
|
||||||
exp = QtCore.QRegExp(
|
exp = QtCore.QRegExp(
|
||||||
@ -57,7 +67,11 @@ class MessageEdit(QtGui.QTextBrowser):
|
|||||||
text = text[:offset] + html + text[offset + len(exp.cap()):]
|
text = text[:offset] + html + text[offset + len(exp.cap()):]
|
||||||
offset += len(html)
|
offset += len(html)
|
||||||
offset = exp.indexIn(text, offset)
|
offset = exp.indexIn(text, offset)
|
||||||
self.setHtml(text)
|
arr = text.split('\n')
|
||||||
|
for i in range(len(arr)):
|
||||||
|
if arr[i].startswith('>'):
|
||||||
|
arr[i] = '<font color="green">' + arr[i] + '</font>'
|
||||||
|
self.setHtml('<br>'.join(arr))
|
||||||
|
|
||||||
|
|
||||||
class MessageItem(QtGui.QWidget):
|
class MessageItem(QtGui.QWidget):
|
||||||
@ -94,11 +108,6 @@ class MessageItem(QtGui.QWidget):
|
|||||||
if message_type == TOX_MESSAGE_TYPE['ACTION']:
|
if message_type == TOX_MESSAGE_TYPE['ACTION']:
|
||||||
self.name.setStyleSheet("QLabel { color: #4169E1; }")
|
self.name.setStyleSheet("QLabel { color: #4169E1; }")
|
||||||
self.message.setStyleSheet("QTextEdit { color: #4169E1; }")
|
self.message.setStyleSheet("QTextEdit { color: #4169E1; }")
|
||||||
else: # TODO: replace with regex
|
|
||||||
if text[0] == '>':
|
|
||||||
self.message.setStyleSheet("QTextEdit { color: green; }")
|
|
||||||
if text[-1] == '<':
|
|
||||||
self.message.setStyleSheet("QTextEdit { color: red; }")
|
|
||||||
|
|
||||||
|
|
||||||
class ContactItem(QtGui.QWidget):
|
class ContactItem(QtGui.QWidget):
|
||||||
|
12
src/menu.py
12
src/menu.py
@ -14,11 +14,11 @@ import plugin_support
|
|||||||
class AddContact(CenteredWidget):
|
class AddContact(CenteredWidget):
|
||||||
"""Add contact form"""
|
"""Add contact form"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, tox_id=''):
|
||||||
super(AddContact, self).__init__()
|
super(AddContact, self).__init__()
|
||||||
self.initUI()
|
self.initUI(tox_id)
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self, tox_id):
|
||||||
self.setObjectName('AddContact')
|
self.setObjectName('AddContact')
|
||||||
self.resize(568, 306)
|
self.resize(568, 306)
|
||||||
self.sendRequestButton = QtGui.QPushButton(self)
|
self.sendRequestButton = QtGui.QPushButton(self)
|
||||||
@ -30,8 +30,9 @@ class AddContact(CenteredWidget):
|
|||||||
self.tox_id = QtGui.QLineEdit(self)
|
self.tox_id = QtGui.QLineEdit(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.label = QtGui.QLabel(self)
|
self.label = QtGui.QLabel(self)
|
||||||
self.label.setGeometry(QtCore.QRect(60, 10, 80, 20))
|
self.label.setGeometry(QtCore.QRect(50, 10, 80, 20))
|
||||||
self.error_label = DataLabel(self)
|
self.error_label = DataLabel(self)
|
||||||
self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20))
|
self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20))
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
@ -44,7 +45,7 @@ class AddContact(CenteredWidget):
|
|||||||
self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
|
self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
|
||||||
self.message_edit.setObjectName("textEdit")
|
self.message_edit.setObjectName("textEdit")
|
||||||
self.message = QtGui.QLabel(self)
|
self.message = QtGui.QLabel(self)
|
||||||
self.message.setGeometry(QtCore.QRect(60, 70, 101, 31))
|
self.message.setGeometry(QtCore.QRect(50, 70, 101, 31))
|
||||||
self.message.setFont(font)
|
self.message.setFont(font)
|
||||||
self.message.setObjectName("label_2")
|
self.message.setObjectName("label_2")
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
@ -70,6 +71,7 @@ class AddContact(CenteredWidget):
|
|||||||
self.sendRequestButton.setText(QtGui.QApplication.translate("Form", "Send request", None, QtGui.QApplication.UnicodeUTF8))
|
self.sendRequestButton.setText(QtGui.QApplication.translate("Form", "Send request", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.label.setText(QtGui.QApplication.translate('AddContact', "TOX ID:", None, QtGui.QApplication.UnicodeUTF8))
|
self.label.setText(QtGui.QApplication.translate('AddContact', "TOX ID:", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.message.setText(QtGui.QApplication.translate('AddContact', "Message:", None, QtGui.QApplication.UnicodeUTF8))
|
self.message.setText(QtGui.QApplication.translate('AddContact', "Message:", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.tox_id.setPlaceholderText(QtGui.QApplication.translate('AddContact', "TOX ID or public key of contact", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
|
|
||||||
class ProfileSettings(CenteredWidget):
|
class ProfileSettings(CenteredWidget):
|
||||||
|
@ -19,17 +19,17 @@ class Settings(Singleton, dict):
|
|||||||
with open(self.path) as fl:
|
with open(self.path) as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
inst = LibToxEncryptSave.get_instance()
|
inst = LibToxEncryptSave.get_instance()
|
||||||
if inst.has_password():
|
if inst.is_data_encrypted(data):
|
||||||
data = inst.pass_decrypt(data)
|
data = inst.pass_decrypt(data)
|
||||||
try:
|
try:
|
||||||
info = json.loads(data)
|
info = json.loads(data)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
info = Settings.get_default_settings()
|
info = Settings.get_default_settings()
|
||||||
log('Parsing settings error: ' + str(ex))
|
log('Parsing settings error: ' + str(ex))
|
||||||
super(self.__class__, self).__init__(info)
|
super(Settings, self).__init__(info)
|
||||||
self.upgrade()
|
self.upgrade()
|
||||||
else:
|
else:
|
||||||
super(self.__class__, self).__init__(Settings.get_default_settings())
|
super(Settings, self).__init__(Settings.get_default_settings())
|
||||||
self.save()
|
self.save()
|
||||||
p = pyaudio.PyAudio()
|
p = pyaudio.PyAudio()
|
||||||
self.audio = {'input': p.get_default_input_device_info()['index'],
|
self.audio = {'input': p.get_default_input_device_info()['index'],
|
||||||
|
Loading…
Reference in New Issue
Block a user