diff --git a/src/callbacks.py b/src/callbacks.py
index c2efe3d..e08d127 100644
--- a/src/callbacks.py
+++ b/src/callbacks.py
@@ -75,7 +75,7 @@ def friend_connection_status(tox, friend_num, new_status, user_data):
"""
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()
friend = profile.get_friend_by_number(friend_num)
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)
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
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
diff --git a/src/list_items.py b/src/list_items.py
index 1011e8c..7f9ef8c 100644
--- a/src/list_items.py
+++ b/src/list_items.py
@@ -13,8 +13,6 @@ import cgi
class MessageEdit(QtGui.QTextBrowser):
- # TODO: add anchor clicked with tox: support and unfocus links
-
def __init__(self, text, width, parent=None):
super(MessageEdit, self).__init__(parent)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
@@ -22,6 +20,7 @@ class MessageEdit(QtGui.QTextBrowser):
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
self.document().setTextWidth(width)
self.setOpenExternalLinks(True)
+ self.setOpenLinks(False)
self.setTextWithLinks(text)
font = QtGui.QFont()
font.setFamily("Times New Roman")
@@ -30,6 +29,7 @@ class MessageEdit(QtGui.QTextBrowser):
self.setFont(font)
self.setFixedHeight(self.document().size().height())
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
+ self.anchorClicked.connect(self.on_anchor_clicked)
def contextMenuEvent(self, event):
menu = create_menu(self.createStandardContextMenu(event.pos()))
@@ -37,6 +37,16 @@ class MessageEdit(QtGui.QTextBrowser):
menu.exec_(event.globalPos())
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):
text = cgi.escape(text)
exp = QtCore.QRegExp(
@@ -57,7 +67,11 @@ class MessageEdit(QtGui.QTextBrowser):
text = text[:offset] + html + text[offset + len(exp.cap()):]
offset += len(html)
offset = exp.indexIn(text, offset)
- self.setHtml(text)
+ arr = text.split('\n')
+ for i in range(len(arr)):
+ if arr[i].startswith('>'):
+ arr[i] = '' + arr[i] + ''
+ self.setHtml('
'.join(arr))
class MessageItem(QtGui.QWidget):
@@ -94,11 +108,6 @@ class MessageItem(QtGui.QWidget):
if message_type == TOX_MESSAGE_TYPE['ACTION']:
self.name.setStyleSheet("QLabel { 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):
diff --git a/src/menu.py b/src/menu.py
index 1fa5e68..7342289 100644
--- a/src/menu.py
+++ b/src/menu.py
@@ -14,11 +14,11 @@ import plugin_support
class AddContact(CenteredWidget):
"""Add contact form"""
- def __init__(self):
+ def __init__(self, tox_id=''):
super(AddContact, self).__init__()
- self.initUI()
+ self.initUI(tox_id)
- def initUI(self):
+ def initUI(self, tox_id):
self.setObjectName('AddContact')
self.resize(568, 306)
self.sendRequestButton = QtGui.QPushButton(self)
@@ -30,8 +30,9 @@ class AddContact(CenteredWidget):
self.tox_id = QtGui.QLineEdit(self)
self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27))
self.tox_id.setObjectName("lineEdit")
+ self.tox_id.setText(tox_id)
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.setGeometry(QtCore.QRect(120, 10, 420, 20))
font = QtGui.QFont()
@@ -44,7 +45,7 @@ class AddContact(CenteredWidget):
self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
self.message_edit.setObjectName("textEdit")
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.setObjectName("label_2")
self.retranslateUi()
@@ -70,6 +71,7 @@ class AddContact(CenteredWidget):
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.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):
diff --git a/src/settings.py b/src/settings.py
index f5be3a7..050f061 100644
--- a/src/settings.py
+++ b/src/settings.py
@@ -19,17 +19,17 @@ class Settings(Singleton, dict):
with open(self.path) as fl:
data = fl.read()
inst = LibToxEncryptSave.get_instance()
- if inst.has_password():
+ if inst.is_data_encrypted(data):
data = inst.pass_decrypt(data)
try:
info = json.loads(data)
except Exception as ex:
info = Settings.get_default_settings()
log('Parsing settings error: ' + str(ex))
- super(self.__class__, self).__init__(info)
+ super(Settings, self).__init__(info)
self.upgrade()
else:
- super(self.__class__, self).__init__(Settings.get_default_settings())
+ super(Settings, self).__init__(Settings.get_default_settings())
self.save()
p = pyaudio.PyAudio()
self.audio = {'input': p.get_default_input_device_info()['index'],