first commit
This commit is contained in:
parent
3936f652e9
commit
dd53c6a842
@ -75,13 +75,9 @@ def node_generator():
|
|||||||
"5625A62618CB4FCA70E147A71B29695F38CC65FF0CBD68AD46254585BE564802",
|
"5625A62618CB4FCA70E147A71B29695F38CC65FF0CBD68AD46254585BE564802",
|
||||||
"31910C0497D347FF160D6F3A6C0E317BAFA71E8E03BC4CBB2A185C9D4FB8B31E"
|
"31910C0497D347FF160D6F3A6C0E317BAFA71E8E03BC4CBB2A185C9D4FB8B31E"
|
||||||
]
|
]
|
||||||
for i in xrange(len(ips)):
|
for i in range(len(ips)):
|
||||||
nodes.append(Node(ips[i], ports[i], ids[i], random.randint(0, 1000000)))
|
nodes.append(Node(ips[i], ports[i], ids[i], random.randint(0, 1000000)))
|
||||||
arr = sorted(nodes, key=lambda x: x.rand)[:4]
|
arr = sorted(nodes, key=lambda x: x.rand)[:4]
|
||||||
for elem in arr:
|
for elem in arr:
|
||||||
yield elem.get_data()
|
yield elem.get_data()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
for elem in node_generator():
|
|
||||||
print str(elem)
|
|
||||||
|
@ -43,7 +43,7 @@ def self_connection_status(tox_link):
|
|||||||
Current user changed connection status (offline, UDP, TCP)
|
Current user changed connection status (offline, UDP, TCP)
|
||||||
"""
|
"""
|
||||||
def wrapped(tox, connection, user_data):
|
def wrapped(tox, connection, user_data):
|
||||||
print 'Connection status: ', str(connection)
|
print('Connection status: ', str(connection))
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
if profile.status is None:
|
if profile.status is None:
|
||||||
status = tox_link.self_get_status()
|
status = tox_link.self_get_status()
|
||||||
@ -62,7 +62,7 @@ def friend_status(tox, friend_num, new_status, user_data):
|
|||||||
"""
|
"""
|
||||||
Check friend's status (none, busy, away)
|
Check friend's status (none, busy, away)
|
||||||
"""
|
"""
|
||||||
print "Friend's #{} status changed! New status: {}".format(friend_num, new_status)
|
print("Friend's #{} status changed! New 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 friend.status is None and Settings.get_instance()['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
if friend.status is None and Settings.get_instance()['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
@ -76,7 +76,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 #{} connection 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']:
|
||||||
@ -94,7 +94,7 @@ def friend_name(tox, friend_num, name, size, user_data):
|
|||||||
Friend changed his name
|
Friend changed his name
|
||||||
"""
|
"""
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
print 'New name: ', friend_num, name
|
print('New name: ', friend_num, name)
|
||||||
invoke_in_main_thread(profile.new_name, friend_num, name)
|
invoke_in_main_thread(profile.new_name, friend_num, name)
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ def friend_status_message(tox, friend_num, status_message, size, user_data):
|
|||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
friend = profile.get_friend_by_number(friend_num)
|
friend = profile.get_friend_by_number(friend_num)
|
||||||
invoke_in_main_thread(friend.set_status_message, status_message)
|
invoke_in_main_thread(friend.set_status_message, status_message)
|
||||||
print 'User #{} has new status: {}'.format(friend_num, status_message)
|
print('User #{} has new status: {}'.format(friend_num, status_message))
|
||||||
invoke_in_main_thread(profile.send_messages, friend_num)
|
invoke_in_main_thread(profile.send_messages, friend_num)
|
||||||
if profile.get_active_number() == friend_num:
|
if profile.get_active_number() == friend_num:
|
||||||
invoke_in_main_thread(profile.set_active)
|
invoke_in_main_thread(profile.set_active)
|
||||||
@ -119,11 +119,12 @@ def friend_message(window, tray):
|
|||||||
def wrapped(tox, friend_number, message_type, message, size, user_data):
|
def wrapped(tox, friend_number, message_type, message, size, user_data):
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
|
message = str(message, 'utf-8')
|
||||||
invoke_in_main_thread(profile.new_message, friend_number, message_type, message)
|
invoke_in_main_thread(profile.new_message, friend_number, message_type, message)
|
||||||
if not window.isActiveWindow():
|
if not window.isActiveWindow():
|
||||||
friend = profile.get_friend_by_number(friend_number)
|
friend = profile.get_friend_by_number(friend_number)
|
||||||
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'), tray, window)
|
invoke_in_main_thread(tray_notification, friend.name, message, 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'])
|
||||||
invoke_in_main_thread(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'))
|
||||||
@ -134,12 +135,12 @@ def friend_request(tox, public_key, message, message_size, user_data):
|
|||||||
"""
|
"""
|
||||||
Called when user get new friend request
|
Called when user get new friend request
|
||||||
"""
|
"""
|
||||||
print 'Friend request'
|
print('Friend request')
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
key = ''.join(chr(x) for x in public_key[:TOX_PUBLIC_KEY_SIZE])
|
key = ''.join(chr(x) for x in public_key[:TOX_PUBLIC_KEY_SIZE])
|
||||||
tox_id = bin_to_string(key, TOX_PUBLIC_KEY_SIZE)
|
tox_id = bin_to_string(key, TOX_PUBLIC_KEY_SIZE)
|
||||||
if tox_id not in Settings.get_instance()['blocked']:
|
if tox_id not in Settings.get_instance()['blocked']:
|
||||||
invoke_in_main_thread(profile.process_friend_request, tox_id, message.decode('utf-8'))
|
invoke_in_main_thread(profile.process_friend_request, tox_id, message)
|
||||||
|
|
||||||
|
|
||||||
def friend_typing(tox, friend_number, typing, user_data):
|
def friend_typing(tox, friend_number, typing, user_data):
|
||||||
@ -165,11 +166,11 @@ def tox_file_recv(window, tray):
|
|||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
if file_type == TOX_FILE_KIND['DATA']:
|
if file_type == TOX_FILE_KIND['DATA']:
|
||||||
print 'file'
|
print('File')
|
||||||
try:
|
try:
|
||||||
file_name = unicode(file_name[:file_name_size].decode('utf-8'))
|
file_name = str(file_name[:file_name_size], 'utf-8')
|
||||||
except:
|
except:
|
||||||
file_name = u'toxygen_file'
|
file_name = 'toxygen_file'
|
||||||
invoke_in_main_thread(profile.incoming_file_transfer,
|
invoke_in_main_thread(profile.incoming_file_transfer,
|
||||||
friend_number,
|
friend_number,
|
||||||
file_number,
|
file_number,
|
||||||
@ -184,7 +185,7 @@ def tox_file_recv(window, tray):
|
|||||||
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
|
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
|
||||||
invoke_in_main_thread(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'))
|
||||||
else: # AVATAR
|
else: # AVATAR
|
||||||
print 'Avatar'
|
print ('Avatar')
|
||||||
invoke_in_main_thread(profile.incoming_avatar,
|
invoke_in_main_thread(profile.incoming_avatar,
|
||||||
friend_number,
|
friend_number,
|
||||||
file_number,
|
file_number,
|
||||||
@ -260,7 +261,7 @@ def call_state(toxav, friend_number, mask, user_data):
|
|||||||
"""
|
"""
|
||||||
New call state
|
New call state
|
||||||
"""
|
"""
|
||||||
print friend_number, mask
|
print(friend_number, mask)
|
||||||
if mask == TOXAV_FRIEND_CALL_STATE['FINISHED'] or mask == TOXAV_FRIEND_CALL_STATE['ERROR']:
|
if mask == TOXAV_FRIEND_CALL_STATE['FINISHED'] or mask == TOXAV_FRIEND_CALL_STATE['ERROR']:
|
||||||
invoke_in_main_thread(Profile.get_instance().stop_call, friend_number, True)
|
invoke_in_main_thread(Profile.get_instance().stop_call, friend_number, True)
|
||||||
else:
|
else:
|
||||||
@ -271,7 +272,7 @@ def call(toxav, friend_number, audio, video, user_data):
|
|||||||
"""
|
"""
|
||||||
Incoming call from friend
|
Incoming call from friend
|
||||||
"""
|
"""
|
||||||
print friend_number, audio, video
|
print(friend_number, audio, video)
|
||||||
invoke_in_main_thread(Profile.get_instance().incoming_call, audio, video, friend_number)
|
invoke_in_main_thread(Profile.get_instance().incoming_call, audio, video, friend_number)
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class Contact(object):
|
|||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
def set_name(self, value):
|
def set_name(self, value):
|
||||||
self._name = value.decode('utf-8')
|
self._name = str(value, 'utf-8')
|
||||||
self._widget.name.setText(self._name)
|
self._widget.name.setText(self._name)
|
||||||
self._widget.name.repaint()
|
self._widget.name.repaint()
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ class Contact(object):
|
|||||||
return self._status_message
|
return self._status_message
|
||||||
|
|
||||||
def set_status_message(self, value):
|
def set_status_message(self, value):
|
||||||
self._status_message = value.decode('utf-8')
|
self._status_message = str(value, 'utf-8')
|
||||||
self._widget.status_message.setText(self._status_message)
|
self._widget.status_message.setText(self._status_message)
|
||||||
self._widget.status_message.repaint()
|
self._widget.status_message.repaint()
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class SendTransfer(FileTransfer):
|
|||||||
super(SendTransfer, self).__init__(path, tox, friend_number, size)
|
super(SendTransfer, self).__init__(path, tox, friend_number, size)
|
||||||
self.state = TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']
|
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) if path else '')
|
||||||
|
|
||||||
def send_chunk(self, position, size):
|
def send_chunk(self, position, size):
|
||||||
"""
|
"""
|
||||||
@ -177,7 +177,7 @@ class SendFromBuffer(FileTransfer):
|
|||||||
self._creation_time = time()
|
self._creation_time = time()
|
||||||
if size:
|
if size:
|
||||||
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, bytes(data, 'utf-8'))
|
||||||
self._done += size
|
self._done += size
|
||||||
self.signal()
|
self.signal()
|
||||||
else:
|
else:
|
||||||
@ -290,7 +290,7 @@ class ReceiveAvatar(ReceiveTransfer):
|
|||||||
remove(path + '.tmp')
|
remove(path + '.tmp')
|
||||||
elif exists(path):
|
elif exists(path):
|
||||||
hash = self.get_file_id()
|
hash = self.get_file_id()
|
||||||
with open(path) as fl:
|
with open(path, 'rb') as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
existing_hash = Tox.hash(data)
|
existing_hash = Tox.hash(data)
|
||||||
if hash == existing_hash:
|
if hash == existing_hash:
|
||||||
|
@ -55,12 +55,12 @@ class Friend(contact.Contact):
|
|||||||
"""
|
"""
|
||||||
if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')):
|
if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')):
|
||||||
return
|
return
|
||||||
data = self._message_getter.get(PAGE_SIZE)
|
data = list(self._message_getter.get(PAGE_SIZE))
|
||||||
if data is not None and len(data):
|
if data is not None and len(data):
|
||||||
data.reverse()
|
data.reverse()
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
data = map(lambda tupl: TextMessage(*tupl), data)
|
data = list(map(lambda tupl: TextMessage(*tupl), data))
|
||||||
self._corr = data + self._corr
|
self._corr = data + self._corr
|
||||||
self._history_loaded = True
|
self._history_loaded = True
|
||||||
|
|
||||||
@ -71,11 +71,11 @@ class Friend(contact.Contact):
|
|||||||
"""
|
"""
|
||||||
if hasattr(self, '_message_getter'):
|
if hasattr(self, '_message_getter'):
|
||||||
del self._message_getter
|
del self._message_getter
|
||||||
messages = filter(lambda x: x.get_type() <= 1, self._corr)
|
messages = list(filter(lambda x: x.get_type() <= 1, self._corr))
|
||||||
return map(lambda x: x.get_data(), messages[-self._unsaved_messages:]) if self._unsaved_messages else []
|
return list(map(lambda x: x.get_data(), list(messages[-self._unsaved_messages:]))) if self._unsaved_messages else []
|
||||||
|
|
||||||
def get_corr(self):
|
def get_corr(self):
|
||||||
return self._corr[:]
|
return list(self._corr[:])
|
||||||
|
|
||||||
def append_message(self, message):
|
def append_message(self, message):
|
||||||
"""
|
"""
|
||||||
@ -86,7 +86,7 @@ class Friend(contact.Contact):
|
|||||||
self._unsaved_messages += 1
|
self._unsaved_messages += 1
|
||||||
|
|
||||||
def get_last_message_text(self):
|
def get_last_message_text(self):
|
||||||
messages = filter(lambda x: x.get_type() <= 1 and x.get_owner() != MESSAGE_OWNER['FRIEND'], self._corr)
|
messages = list(filter(lambda x: x.get_type() <= 1 and x.get_owner() != MESSAGE_OWNER['FRIEND'], self._corr))
|
||||||
if messages:
|
if messages:
|
||||||
return messages[-1].get_data()[0]
|
return messages[-1].get_data()[0]
|
||||||
else:
|
else:
|
||||||
@ -97,11 +97,11 @@ class Friend(contact.Contact):
|
|||||||
:return list of unsent messages
|
:return list of unsent messages
|
||||||
"""
|
"""
|
||||||
messages = filter(lambda x: x.get_owner() == MESSAGE_OWNER['NOT_SENT'], self._corr)
|
messages = filter(lambda x: x.get_owner() == MESSAGE_OWNER['NOT_SENT'], self._corr)
|
||||||
return messages
|
return list(messages)
|
||||||
|
|
||||||
def mark_as_sent(self):
|
def mark_as_sent(self):
|
||||||
try:
|
try:
|
||||||
message = filter(lambda x: x.get_owner() == MESSAGE_OWNER['NOT_SENT'], self._corr)[0]
|
message = list(filter(lambda x: x.get_owner() == MESSAGE_OWNER['NOT_SENT'], self._corr))[0]
|
||||||
message.mark_as_sent()
|
message.mark_as_sent()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
util.log('Mark as sent ex: ' + str(ex))
|
util.log('Mark as sent ex: ' + str(ex))
|
||||||
@ -113,7 +113,7 @@ class Friend(contact.Contact):
|
|||||||
if hasattr(self, '_message_getter'):
|
if hasattr(self, '_message_getter'):
|
||||||
del self._message_getter
|
del self._message_getter
|
||||||
# don't delete data about active file transfer
|
# don't delete data about active file transfer
|
||||||
self._corr = filter(lambda x: x.get_type() in (2, 3) and x.get_status() >= 2, self._corr)
|
self._corr = list(filter(lambda x: x.get_type() in (2, 3) and x.get_status() >= 2, self._corr))
|
||||||
self._unsaved_messages = 0
|
self._unsaved_messages = 0
|
||||||
|
|
||||||
def get_curr_text(self):
|
def get_curr_text(self):
|
||||||
@ -133,8 +133,8 @@ class Friend(contact.Contact):
|
|||||||
Update status of active transfer and load inline if needed
|
Update status of active transfer and load inline if needed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
tr = filter(lambda x: x.get_type() == MESSAGE_TYPE['FILE_TRANSFER'] and x.is_active(file_number),
|
tr = list(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)
|
||||||
i = self._corr.index(tr)
|
i = self._corr.index(tr)
|
||||||
if inline: # inline was loaded
|
if inline: # inline was loaded
|
||||||
@ -148,10 +148,10 @@ class Friend(contact.Contact):
|
|||||||
return messages
|
return messages
|
||||||
|
|
||||||
def clear_unsent_files(self):
|
def clear_unsent_files(self):
|
||||||
self._corr = filter(lambda x: type(x) is not UnsentFile, self._corr)
|
self._corr = list(filter(lambda x: type(x) is not UnsentFile, self._corr))
|
||||||
|
|
||||||
def delete_one_unsent_file(self, time):
|
def delete_one_unsent_file(self, time):
|
||||||
self._corr = filter(lambda x: not (type(x) is UnsentFile and x.get_data()[2] == time), self._corr)
|
self._corr = list(filter(lambda x: not (type(x) is UnsentFile and x.get_data()[2] == time), self._corr))
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Alias support
|
# Alias support
|
||||||
|
@ -70,6 +70,7 @@ class MessageEdit(QtGui.QTextBrowser):
|
|||||||
self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth())
|
self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth())
|
||||||
|
|
||||||
def decoratedText(self, text):
|
def decoratedText(self, text):
|
||||||
|
text = text.replace("&", "&")
|
||||||
text = cgi.escape(text) # replace < and >
|
text = cgi.escape(text) # replace < and >
|
||||||
exp = QtCore.QRegExp(
|
exp = QtCore.QRegExp(
|
||||||
'('
|
'('
|
||||||
@ -297,14 +298,14 @@ class FileTransferItem(QtGui.QListWidget):
|
|||||||
self.file_name.setGeometry(QtCore.QRect(210, 7, width - 420, 20))
|
self.file_name.setGeometry(QtCore.QRect(210, 7, width - 420, 20))
|
||||||
font.setPointSize(12)
|
font.setPointSize(12)
|
||||||
self.file_name.setFont(font)
|
self.file_name.setFont(font)
|
||||||
file_size = size / 1024
|
file_size = size // 1024
|
||||||
if not file_size:
|
if not file_size:
|
||||||
file_size = '{}B'.format(size)
|
file_size = '{}B'.format(size)
|
||||||
elif file_size >= 1024:
|
elif file_size >= 1024:
|
||||||
file_size = '{}MB'.format(file_size / 1024)
|
file_size = '{}MB'.format(file_size // 1024)
|
||||||
else:
|
else:
|
||||||
file_size = '{}KB'.format(file_size)
|
file_size = '{}KB'.format(file_size)
|
||||||
file_data = u'{} {}'.format(file_size, file_name)
|
file_data = '{} {}'.format(file_size, file_name)
|
||||||
self.file_name.setText(file_data)
|
self.file_name.setText(file_data)
|
||||||
self.file_name.setToolTip(file_name)
|
self.file_name.setToolTip(file_name)
|
||||||
self.saved_name = file_name
|
self.saved_name = file_name
|
||||||
|
@ -283,7 +283,7 @@ class Toxygen(object):
|
|||||||
self.tox.bootstrap(*data)
|
self.tox.bootstrap(*data)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
for _ in xrange(10):
|
for _ in range(10):
|
||||||
if self.stop:
|
if self.stop:
|
||||||
return
|
return
|
||||||
self.msleep(1000)
|
self.msleep(1000)
|
||||||
|
@ -499,7 +499,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
s = Settings.get_instance()
|
s = Settings.get_instance()
|
||||||
note = s['notes'][friend.tox_id] if friend.tox_id in s['notes'] else ''
|
note = s['notes'][friend.tox_id] if friend.tox_id in s['notes'] else ''
|
||||||
user = QtGui.QApplication.translate("MainWindow", 'Notes about user', None, QtGui.QApplication.UnicodeUTF8)
|
user = QtGui.QApplication.translate("MainWindow", 'Notes about user', None, QtGui.QApplication.UnicodeUTF8)
|
||||||
user = u'{} {}'.format(user, friend.name)
|
user = '{} {}'.format(user, friend.name)
|
||||||
|
|
||||||
def save_note(text):
|
def save_note(text):
|
||||||
if friend.tox_id in s['notes']:
|
if friend.tox_id in s['notes']:
|
||||||
|
@ -99,7 +99,6 @@ class ScreenShotWindow(QtGui.QWidget):
|
|||||||
if self.rubberband.isVisible():
|
if self.rubberband.isVisible():
|
||||||
self.rubberband.hide()
|
self.rubberband.hide()
|
||||||
rect = self.rubberband.geometry()
|
rect = self.rubberband.geometry()
|
||||||
print rect
|
|
||||||
if rect.width() and rect.height():
|
if rect.width() and rect.height():
|
||||||
p = QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop().winId(),
|
p = QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop().winId(),
|
||||||
rect.x() + 4,
|
rect.x() + 4,
|
||||||
|
@ -306,7 +306,7 @@ class NetworkSettings(CenteredWidget):
|
|||||||
self.udp.setChecked(settings['udp_enabled'])
|
self.udp.setChecked(settings['udp_enabled'])
|
||||||
self.proxy.setChecked(settings['proxy_type'])
|
self.proxy.setChecked(settings['proxy_type'])
|
||||||
self.proxyip.setText(settings['proxy_host'])
|
self.proxyip.setText(settings['proxy_host'])
|
||||||
self.proxyport.setText(unicode(settings['proxy_port']))
|
self.proxyport.setText(str(settings['proxy_port']))
|
||||||
self.http.setChecked(settings['proxy_type'] == 1)
|
self.http.setChecked(settings['proxy_type'] == 1)
|
||||||
self.warning = QtGui.QLabel(self)
|
self.warning = QtGui.QLabel(self)
|
||||||
self.warning.setGeometry(QtCore.QRect(5, 270, 290, 60))
|
self.warning.setGeometry(QtCore.QRect(5, 270, 290, 60))
|
||||||
@ -637,13 +637,13 @@ class AudioSettings(CenteredWidget):
|
|||||||
p = pyaudio.PyAudio()
|
p = pyaudio.PyAudio()
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
self.in_indexes, self.out_indexes = [], []
|
self.in_indexes, self.out_indexes = [], []
|
||||||
for i in xrange(p.get_device_count()):
|
for i in range(p.get_device_count()):
|
||||||
device = p.get_device_info_by_index(i)
|
device = p.get_device_info_by_index(i)
|
||||||
if device["maxInputChannels"]:
|
if device["maxInputChannels"]:
|
||||||
self.input.addItem(unicode(device["name"]))
|
self.input.addItem(str(device["name"]))
|
||||||
self.in_indexes.append(i)
|
self.in_indexes.append(i)
|
||||||
if device["maxOutputChannels"]:
|
if device["maxOutputChannels"]:
|
||||||
self.output.addItem(unicode(device["name"]))
|
self.output.addItem(str(device["name"]))
|
||||||
self.out_indexes.append(i)
|
self.out_indexes.append(i)
|
||||||
self.input.setCurrentIndex(self.in_indexes.index(settings.audio['input']))
|
self.input.setCurrentIndex(self.in_indexes.index(settings.audio['input']))
|
||||||
self.output.setCurrentIndex(self.out_indexes.index(settings.audio['output']))
|
self.output.setCurrentIndex(self.out_indexes.index(settings.audio['output']))
|
||||||
|
@ -57,8 +57,9 @@ class PasswordScreen(CenteredWidget):
|
|||||||
try:
|
try:
|
||||||
self._encrypt.set_password(self.password.text())
|
self._encrypt.set_password(self.password.text())
|
||||||
new_data = self._encrypt.pass_decrypt(self._data[0])
|
new_data = self._encrypt.pass_decrypt(self._data[0])
|
||||||
except Exception:
|
except Exception as ex:
|
||||||
self.warning.setVisible(True)
|
self.warning.setVisible(True)
|
||||||
|
print('Decryption error:', ex)
|
||||||
else:
|
else:
|
||||||
self._data[0] = new_data
|
self._data[0] = new_data
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -10,6 +10,7 @@ import toxencryptsave
|
|||||||
class PluginLoader(util.Singleton):
|
class PluginLoader(util.Singleton):
|
||||||
|
|
||||||
def __init__(self, tox, settings):
|
def __init__(self, tox, settings):
|
||||||
|
PluginLoader._instance = self
|
||||||
self._profile = profile.Profile.get_instance()
|
self._profile = profile.Profile.get_instance()
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._plugins = {} # dict. key - plugin unique short name, value - tuple (plugin instance, is active)
|
self._plugins = {} # dict. key - plugin unique short name, value - tuple (plugin instance, is active)
|
||||||
@ -48,7 +49,7 @@ class PluginLoader(util.Singleton):
|
|||||||
for elem in dir(module):
|
for elem in dir(module):
|
||||||
obj = getattr(module, elem)
|
obj = getattr(module, elem)
|
||||||
if inspect.isclass(obj) and issubclass(obj, pl.PluginSuperClass): # looking for plugin class in module
|
if inspect.isclass(obj) and issubclass(obj, pl.PluginSuperClass): # looking for plugin class in module
|
||||||
print 'Plugin', elem
|
print('Plugin', elem)
|
||||||
try: # create instance of plugin class
|
try: # create instance of plugin class
|
||||||
inst = obj(self._tox, self._profile, self._settings, self._encr)
|
inst = obj(self._tox, self._profile, self._settings, self._encr)
|
||||||
autostart = inst.get_short_name() in self._settings['plugins']
|
autostart = inst.get_short_name() in self._settings['plugins']
|
||||||
|
@ -125,11 +125,12 @@ class PluginSuperClass(object):
|
|||||||
New command. On 'help' this method should provide user list of available commands
|
New command. On 'help' this method should provide user list of available commands
|
||||||
:param command: string with command
|
:param command: string with command
|
||||||
"""
|
"""
|
||||||
msgbox = QtGui.QMessageBox()
|
if command == 'help':
|
||||||
title = QtGui.QApplication.translate("PluginWindow", "List of commands for plugin {}", None, QtGui.QApplication.UnicodeUTF8)
|
msgbox = QtGui.QMessageBox()
|
||||||
msgbox.setWindowTitle(title.format(self._name))
|
title = QtGui.QApplication.translate("PluginWindow", "List of commands for plugin {}", None, QtGui.QApplication.UnicodeUTF8)
|
||||||
msgbox.setText(QtGui.QApplication.translate("PluginWindow", "No commands available", None, QtGui.QApplication.UnicodeUTF8))
|
msgbox.setWindowTitle(title.format(self._name))
|
||||||
msgbox.exec_()
|
msgbox.setText(QtGui.QApplication.translate("PluginWindow", "No commands available", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
msgbox.exec_()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Translations support
|
# Translations support
|
||||||
@ -142,11 +143,11 @@ class PluginSuperClass(object):
|
|||||||
app = QtGui.QApplication.instance()
|
app = QtGui.QApplication.instance()
|
||||||
langs = self._settings.supported_languages()
|
langs = self._settings.supported_languages()
|
||||||
curr_lang = self._settings['language']
|
curr_lang = self._settings['language']
|
||||||
if curr_lang in map(lambda x: x[0], langs):
|
if curr_lang in langs:
|
||||||
if self._translator is not None:
|
if self._translator is not None:
|
||||||
app.removeTranslator(self._translator)
|
app.removeTranslator(self._translator)
|
||||||
self._translator = QtCore.QTranslator()
|
self._translator = QtCore.QTranslator()
|
||||||
lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1]
|
lang_path = langs[curr_lang]
|
||||||
self._translator.load(path_to_data(self._short_name) + lang_path)
|
self._translator.load(path_to_data(self._short_name) + lang_path)
|
||||||
app.installTranslator(self._translator)
|
app.installTranslator(self._translator)
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
tox.self_get_status_message(),
|
tox.self_get_status_message(),
|
||||||
screen.user_info,
|
screen.user_info,
|
||||||
tox.self_get_address())
|
tox.self_get_address())
|
||||||
|
Profile._instance = self
|
||||||
self._screen = screen
|
self._screen = screen
|
||||||
self._messages = screen.messages
|
self._messages = screen.messages
|
||||||
self._tox = tox
|
self._tox = tox
|
||||||
@ -131,7 +132,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
self.filtration(self._show_online, self._filter_string)
|
self.filtration(self._show_online, self._filter_string)
|
||||||
|
|
||||||
def get_friend_by_number(self, num):
|
def get_friend_by_number(self, num):
|
||||||
return filter(lambda x: x.number == num, self._friends)[0]
|
return list(filter(lambda x: x.number == num, self._friends))[0]
|
||||||
|
|
||||||
def get_friend(self, num):
|
def get_friend(self, num):
|
||||||
return self._friends[num]
|
return self._friends[num]
|
||||||
@ -192,7 +193,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
ft.set_state_changed_handler(item.update)
|
ft.set_state_changed_handler(item.update)
|
||||||
ft.signal()
|
ft.signal()
|
||||||
except:
|
except:
|
||||||
print 'Incoming not started transfer - no info found'
|
print('Incoming not started transfer - no info found')
|
||||||
elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
|
elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
|
||||||
self.create_inline_item(message.get_data())
|
self.create_inline_item(message.get_data())
|
||||||
else: # info message
|
else: # info message
|
||||||
@ -222,8 +223,9 @@ class Profile(contact.Contact, Singleton):
|
|||||||
self._screen.account_avatar.setScaledContents(False)
|
self._screen.account_avatar.setScaledContents(False)
|
||||||
self._screen.account_avatar.setPixmap(pixmap.scaled(64, 64, QtCore.Qt.KeepAspectRatio))
|
self._screen.account_avatar.setPixmap(pixmap.scaled(64, 64, QtCore.Qt.KeepAspectRatio))
|
||||||
self._screen.account_avatar.repaint() # comment?
|
self._screen.account_avatar.repaint() # comment?
|
||||||
except: # no friend found. ignore
|
except Exception as ex: # no friend found. ignore
|
||||||
log('Incorrect friend value: ' + str(value))
|
log('Incorrect friend value: ' + str(value))
|
||||||
|
log('Error: ' + str(ex))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
active_friend = property(get_active, set_active)
|
active_friend = property(get_active, set_active)
|
||||||
@ -244,7 +246,6 @@ class Profile(contact.Contact, Singleton):
|
|||||||
friend = self.get_friend_by_number(number)
|
friend = self.get_friend_by_number(number)
|
||||||
tmp = friend.name
|
tmp = friend.name
|
||||||
friend.set_name(name)
|
friend.set_name(name)
|
||||||
name = name.decode('utf-8')
|
|
||||||
if friend.name == name and tmp != name:
|
if friend.name == name and tmp != name:
|
||||||
message = QtGui.QApplication.translate("MainWindow", 'User {} is now known as {}', None, QtGui.QApplication.UnicodeUTF8)
|
message = QtGui.QApplication.translate("MainWindow", 'User {} is now known as {}', None, QtGui.QApplication.UnicodeUTF8)
|
||||||
message = message.format(tmp, name)
|
message = message.format(tmp, name)
|
||||||
@ -277,7 +278,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
if friend_number == self.get_active_number():
|
if friend_number == self.get_active_number():
|
||||||
self.update()
|
self.update()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print 'Exception in file sending: ' + str(ex)
|
print('Exception in file sending: ' + str(ex))
|
||||||
|
|
||||||
def friend_exit(self, friend_number):
|
def friend_exit(self, friend_number):
|
||||||
"""
|
"""
|
||||||
@ -362,15 +363,15 @@ class Profile(contact.Contact, Singleton):
|
|||||||
:param message: text of message
|
:param message: text of message
|
||||||
"""
|
"""
|
||||||
if friend_num == self.get_active_number(): # add message to list
|
if friend_num == self.get_active_number(): # add message to list
|
||||||
self.create_message_item(message.decode('utf-8'), curr_time(), MESSAGE_OWNER['FRIEND'], message_type)
|
self.create_message_item(message, curr_time(), MESSAGE_OWNER['FRIEND'], message_type)
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
self._friends[self._active_friend].append_message(
|
self._friends[self._active_friend].append_message(
|
||||||
TextMessage(message.decode('utf-8'), MESSAGE_OWNER['FRIEND'], time.time(), message_type))
|
TextMessage(message, MESSAGE_OWNER['FRIEND'], time.time(), message_type))
|
||||||
else:
|
else:
|
||||||
friend = self.get_friend_by_number(friend_num)
|
friend = self.get_friend_by_number(friend_num)
|
||||||
friend.inc_messages()
|
friend.inc_messages()
|
||||||
friend.append_message(
|
friend.append_message(
|
||||||
TextMessage(message.decode('utf-8'), MESSAGE_OWNER['FRIEND'], time.time(), message_type))
|
TextMessage(message, MESSAGE_OWNER['FRIEND'], time.time(), message_type))
|
||||||
if not friend.visibility:
|
if not friend.visibility:
|
||||||
self.update_filtration()
|
self.update_filtration()
|
||||||
|
|
||||||
@ -429,7 +430,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
self._history.delete_messages(friend.tox_id)
|
self._history.delete_messages(friend.tox_id)
|
||||||
self._history.delete_friend_from_db(friend.tox_id)
|
self._history.delete_friend_from_db(friend.tox_id)
|
||||||
else: # clear all history
|
else: # clear all history
|
||||||
for number in xrange(len(self._friends)):
|
for number in range(len(self._friends)):
|
||||||
self.clear_history(number)
|
self.clear_history(number)
|
||||||
if num is None or num == self.get_active_number():
|
if num is None or num == self.get_active_number():
|
||||||
self._messages.clear()
|
self._messages.clear()
|
||||||
@ -465,7 +466,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
ft.set_state_changed_handler(item.update)
|
ft.set_state_changed_handler(item.update)
|
||||||
ft.signal()
|
ft.signal()
|
||||||
except:
|
except:
|
||||||
print 'Incoming not started transfer - no info found'
|
print('Incoming not started transfer - no info found')
|
||||||
elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
|
elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
|
||||||
self.create_inline_item(message.get_data())
|
self.create_inline_item(message.get_data())
|
||||||
else: # info message
|
else: # info message
|
||||||
@ -562,7 +563,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
dialog = QtGui.QApplication.translate('MainWindow',
|
dialog = QtGui.QApplication.translate('MainWindow',
|
||||||
"Enter new alias for friend {} or leave empty to use friend's name:",
|
"Enter new alias for friend {} or leave empty to use friend's name:",
|
||||||
None, QtGui.QApplication.UnicodeUTF8)
|
None, QtGui.QApplication.UnicodeUTF8)
|
||||||
dialog = dialog.format(name.decode('utf-8'))
|
dialog = dialog.format(name)
|
||||||
title = QtGui.QApplication.translate('MainWindow',
|
title = QtGui.QApplication.translate('MainWindow',
|
||||||
'Set alias',
|
'Set alias',
|
||||||
None, QtGui.QApplication.UnicodeUTF8)
|
None, QtGui.QApplication.UnicodeUTF8)
|
||||||
@ -570,7 +571,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
title,
|
title,
|
||||||
dialog,
|
dialog,
|
||||||
QtGui.QLineEdit.Normal,
|
QtGui.QLineEdit.Normal,
|
||||||
name.decode('utf-8'))
|
name)
|
||||||
if ok:
|
if ok:
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
aliases = settings['friends_aliases']
|
aliases = settings['friends_aliases']
|
||||||
@ -905,7 +906,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
self.send_inline(data, 'toxygen_inline.png')
|
self.send_inline(data, 'toxygen_inline.png')
|
||||||
|
|
||||||
def send_sticker(self, path):
|
def send_sticker(self, path):
|
||||||
with open(path) as fl:
|
with open(path, 'rb') as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
self.send_inline(data, 'sticker.png')
|
self.send_inline(data, 'sticker.png')
|
||||||
|
|
||||||
@ -948,7 +949,7 @@ class Profile(contact.Contact, Singleton):
|
|||||||
self.update()
|
self.update()
|
||||||
return
|
return
|
||||||
elif friend.status is None and is_resend:
|
elif friend.status is None and is_resend:
|
||||||
print 'Error in sending'
|
print('Error in sending')
|
||||||
raise RuntimeError()
|
raise RuntimeError()
|
||||||
st = SendTransfer(path, self._tox, friend_number)
|
st = SendTransfer(path, self._tox, friend_number)
|
||||||
self._file_transfers[(friend_number, st.get_file_number())] = st
|
self._file_transfers[(friend_number, st.get_file_number())] = st
|
||||||
@ -1151,7 +1152,7 @@ def tox_factory(data=None, settings=None):
|
|||||||
tox_options = Tox.options_new()
|
tox_options = Tox.options_new()
|
||||||
tox_options.contents.udp_enabled = settings['udp_enabled']
|
tox_options.contents.udp_enabled = settings['udp_enabled']
|
||||||
tox_options.contents.proxy_type = settings['proxy_type']
|
tox_options.contents.proxy_type = settings['proxy_type']
|
||||||
tox_options.contents.proxy_host = settings['proxy_host']
|
tox_options.contents.proxy_host = bytes(settings['proxy_host'], 'UTF-8')
|
||||||
tox_options.contents.proxy_port = settings['proxy_port']
|
tox_options.contents.proxy_port = settings['proxy_port']
|
||||||
tox_options.contents.start_port = settings['start_port']
|
tox_options.contents.start_port = settings['start_port']
|
||||||
tox_options.contents.end_port = settings['end_port']
|
tox_options.contents.end_port = settings['end_port']
|
||||||
|
@ -8,13 +8,14 @@ from toxencryptsave import LibToxEncryptSave
|
|||||||
import smileys
|
import smileys
|
||||||
|
|
||||||
|
|
||||||
class Settings(Singleton, dict):
|
class Settings(dict, Singleton):
|
||||||
"""
|
"""
|
||||||
Settings of current profile + global app settings
|
Settings of current profile + global app settings
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.path = ProfileHelper.get_path() + unicode(name) + '.json'
|
Settings._instance = self
|
||||||
|
self.path = ProfileHelper.get_path() + str(name) + '.json'
|
||||||
self.name = name
|
self.name = name
|
||||||
if os.path.isfile(self.path):
|
if os.path.isfile(self.path):
|
||||||
with open(self.path, 'rb') as fl:
|
with open(self.path, 'rb') as fl:
|
||||||
@ -23,7 +24,7 @@ class Settings(Singleton, dict):
|
|||||||
try:
|
try:
|
||||||
if inst.is_data_encrypted(data):
|
if inst.is_data_encrypted(data):
|
||||||
data = inst.pass_decrypt(data)
|
data = inst.pass_decrypt(data)
|
||||||
info = json.loads(data)
|
info = json.loads(str(data, 'utf-8'))
|
||||||
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))
|
||||||
@ -45,7 +46,7 @@ class Settings(Singleton, dict):
|
|||||||
data = fl.read()
|
data = fl.read()
|
||||||
auto = json.loads(data)
|
auto = json.loads(data)
|
||||||
if 'path' in auto and 'name' in auto:
|
if 'path' in auto and 'name' in auto:
|
||||||
return unicode(auto['path']), unicode(auto['name'])
|
return str(auto['path']), str(auto['name'])
|
||||||
return '', ''
|
return '', ''
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -54,8 +55,8 @@ class Settings(Singleton, dict):
|
|||||||
with open(p) as fl:
|
with open(p) as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
data['path'] = unicode(path.decode(locale.getpreferredencoding()))
|
data['path'] = str(path)
|
||||||
data['name'] = unicode(name)
|
data['name'] = str(name)
|
||||||
with open(p, 'w') as fl:
|
with open(p, 'w') as fl:
|
||||||
fl.write(json.dumps(data))
|
fl.write(json.dumps(data))
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ class Settings(Singleton, dict):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_active_profile(path, name):
|
def is_active_profile(path, name):
|
||||||
path = path.decode(locale.getpreferredencoding()) + name + '.tox'
|
path = path + name + '.tox'
|
||||||
settings = Settings.get_default_path() + 'toxygen.json'
|
settings = Settings.get_default_path() + 'toxygen.json'
|
||||||
if os.path.isfile(settings):
|
if os.path.isfile(settings):
|
||||||
with open(settings) as fl:
|
with open(settings) as fl:
|
||||||
@ -135,7 +136,7 @@ class Settings(Singleton, dict):
|
|||||||
default = Settings.get_default_settings()
|
default = Settings.get_default_settings()
|
||||||
for key in default:
|
for key in default:
|
||||||
if key not in self:
|
if key not in self:
|
||||||
print key
|
print(key)
|
||||||
self[key] = default[key]
|
self[key] = default[key]
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ class Settings(Singleton, dict):
|
|||||||
if inst.has_password():
|
if inst.has_password():
|
||||||
text = inst.pass_encrypt(text)
|
text = inst.pass_encrypt(text)
|
||||||
with open(self.path, 'wb') as fl:
|
with open(self.path, 'wb') as fl:
|
||||||
fl.write(text)
|
fl.write(bytes(text, 'UTF-8'))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
path = Settings.get_default_path() + 'toxygen.json'
|
path = Settings.get_default_path() + 'toxygen.json'
|
||||||
@ -154,7 +155,7 @@ class Settings(Singleton, dict):
|
|||||||
data = fl.read()
|
data = fl.read()
|
||||||
app_settings = json.loads(data)
|
app_settings = json.loads(data)
|
||||||
try:
|
try:
|
||||||
app_settings['active_profile'].remove(unicode(ProfileHelper.get_path() + self.name + '.tox'))
|
app_settings['active_profile'].remove(str(ProfileHelper.get_path() + self.name + '.tox'))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
data = json.dumps(app_settings)
|
data = json.dumps(app_settings)
|
||||||
@ -175,7 +176,7 @@ class Settings(Singleton, dict):
|
|||||||
if 'active_profile' not in app_settings:
|
if 'active_profile' not in app_settings:
|
||||||
app_settings['active_profile'] = []
|
app_settings['active_profile'] = []
|
||||||
profile_path = ProfileHelper.get_path()
|
profile_path = ProfileHelper.get_path()
|
||||||
app_settings['active_profile'].append(unicode(profile_path + str(self.name) + '.tox'))
|
app_settings['active_profile'].append(str(profile_path + str(self.name) + '.tox'))
|
||||||
data = json.dumps(app_settings)
|
data = json.dumps(app_settings)
|
||||||
with open(path, 'w') as fl:
|
with open(path, 'w') as fl:
|
||||||
fl.write(data)
|
fl.write(data)
|
||||||
@ -198,7 +199,7 @@ class ProfileHelper(Singleton):
|
|||||||
Class with methods for search, load and save profiles
|
Class with methods for search, load and save profiles
|
||||||
"""
|
"""
|
||||||
def __init__(self, path, name):
|
def __init__(self, path, name):
|
||||||
path = path.decode(locale.getpreferredencoding())
|
ProfileHelper._instance = self
|
||||||
self._path = path + name + '.tox'
|
self._path = path + name + '.tox'
|
||||||
self._directory = path
|
self._directory = path
|
||||||
# create /avatars if not exists:
|
# create /avatars if not exists:
|
||||||
@ -223,7 +224,7 @@ class ProfileHelper(Singleton):
|
|||||||
data = inst.pass_encrypt(data)
|
data = inst.pass_encrypt(data)
|
||||||
with open(self._path, 'wb') as fl:
|
with open(self._path, 'wb') as fl:
|
||||||
fl.write(data)
|
fl.write(data)
|
||||||
print 'Profile saved successfully'
|
print('Profile saved successfully')
|
||||||
|
|
||||||
def export_profile(self, new_path):
|
def export_profile(self, new_path):
|
||||||
new_path += os.path.basename(self._path)
|
new_path += os.path.basename(self._path)
|
||||||
@ -231,7 +232,7 @@ class ProfileHelper(Singleton):
|
|||||||
data = fin.read()
|
data = fin.read()
|
||||||
with open(new_path, 'wb') as fout:
|
with open(new_path, 'wb') as fout:
|
||||||
fout.write(data)
|
fout.write(data)
|
||||||
print 'Profile exported successfully'
|
print('Profile exported successfully')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_profiles():
|
def find_profiles():
|
||||||
|
@ -14,6 +14,7 @@ class SmileyLoader(util.Singleton):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, settings):
|
def __init__(self, settings):
|
||||||
|
SmileyLoader._instance = self
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._curr_pack = None # current pack name
|
self._curr_pack = None # current pack name
|
||||||
self._smileys = {} # smileys dict. key - smiley (str), value - path to image (str)
|
self._smileys = {} # smileys dict. key - smiley (str), value - path to image (str)
|
||||||
@ -33,7 +34,7 @@ class SmileyLoader(util.Singleton):
|
|||||||
self._smileys = json.loads(fl.read())
|
self._smileys = json.loads(fl.read())
|
||||||
fl.seek(0)
|
fl.seek(0)
|
||||||
tmp = json.loads(fl.read(), object_pairs_hook=OrderedDict)
|
tmp = json.loads(fl.read(), object_pairs_hook=OrderedDict)
|
||||||
print 'Smiley pack {} loaded'.format(pack_name)
|
print('Smiley pack {} loaded'.format(pack_name))
|
||||||
keys, values, self._list = [], [], []
|
keys, values, self._list = [], [], []
|
||||||
for key, value in tmp.items():
|
for key, value in tmp.items():
|
||||||
value = self.get_smileys_path() + value
|
value = self.get_smileys_path() + value
|
||||||
@ -44,7 +45,7 @@ class SmileyLoader(util.Singleton):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
self._smileys = {}
|
self._smileys = {}
|
||||||
self._list = []
|
self._list = []
|
||||||
print 'Smiley pack {} was not loaded. Error: {}'.format(pack_name, ex)
|
print('Smiley pack {} was not loaded. Error: {}'.format(pack_name, ex))
|
||||||
|
|
||||||
def get_smileys_path(self):
|
def get_smileys_path(self):
|
||||||
return util.curr_directory() + '/smileys/' + self._curr_pack + '/'
|
return util.curr_directory() + '/smileys/' + self._curr_pack + '/'
|
||||||
@ -69,7 +70,7 @@ class SmileyLoader(util.Singleton):
|
|||||||
for i in range(len(arr)):
|
for i in range(len(arr)):
|
||||||
if arr[i] in self._smileys:
|
if arr[i] in self._smileys:
|
||||||
file_name = self._smileys[arr[i]] # image name
|
file_name = self._smileys[arr[i]] # image name
|
||||||
arr[i] = u'<img title=\"{}\" src=\"{}\" />'.format(arr[i], file_name)
|
arr[i] = '<img title=\"{}\" src=\"{}\" />'.format(arr[i], file_name)
|
||||||
if file_name.endswith('.gif'): # animated smiley
|
if file_name.endswith('.gif'): # animated smiley
|
||||||
edit.addAnimation(QtCore.QUrl(file_name), self.get_smileys_path() + file_name)
|
edit.addAnimation(QtCore.QUrl(file_name), self.get_smileys_path() + file_name)
|
||||||
return ' '.join(arr)
|
return ' '.join(arr)
|
||||||
@ -85,6 +86,6 @@ def sticker_loader():
|
|||||||
for key in keys:
|
for key in keys:
|
||||||
path = d + key + '/'
|
path = d + key + '/'
|
||||||
files = filter(lambda f: f.endswith('.png'), os.listdir(path))
|
files = filter(lambda f: f.endswith('.png'), os.listdir(path))
|
||||||
files = map(lambda f: unicode(path + f), files)
|
files = map(lambda f: str(path + f), files)
|
||||||
result.extend(files)
|
result.extend(files)
|
||||||
return result
|
return result
|
||||||
|
File diff suppressed because one or more lines are too long
16
src/tox.py
16
src/tox.py
@ -23,11 +23,11 @@ class ToxOptions(Structure):
|
|||||||
|
|
||||||
|
|
||||||
def string_to_bin(tox_id):
|
def string_to_bin(tox_id):
|
||||||
return c_char_p(tox_id.decode('hex')) if tox_id is not None else None
|
return c_char_p(bytes.fromhex(tox_id)) if tox_id is not None else None
|
||||||
|
|
||||||
|
|
||||||
def bin_to_string(raw_id, length):
|
def bin_to_string(raw_id, length):
|
||||||
res = ''.join('{:02x}'.format(ord(raw_id[i])) for i in xrange(length))
|
res = ''.join('{:02x}'.format(ord(raw_id[i])) for i in range(length))
|
||||||
return res.upper()
|
return res.upper()
|
||||||
|
|
||||||
|
|
||||||
@ -382,7 +382,7 @@ class Tox(object):
|
|||||||
if name is None:
|
if name is None:
|
||||||
name = create_string_buffer(self.self_get_name_size())
|
name = create_string_buffer(self.self_get_name_size())
|
||||||
Tox.libtoxcore.tox_self_get_name(self._tox_pointer, name)
|
Tox.libtoxcore.tox_self_get_name(self._tox_pointer, name)
|
||||||
return name.value.decode('utf8')
|
return str(name.value, 'utf-8')
|
||||||
|
|
||||||
def self_set_status_message(self, status_message):
|
def self_set_status_message(self, status_message):
|
||||||
"""
|
"""
|
||||||
@ -430,7 +430,7 @@ class Tox(object):
|
|||||||
if status_message is None:
|
if status_message is None:
|
||||||
status_message = create_string_buffer(self.self_get_status_message_size())
|
status_message = create_string_buffer(self.self_get_status_message_size())
|
||||||
Tox.libtoxcore.tox_self_get_status_message(self._tox_pointer, status_message)
|
Tox.libtoxcore.tox_self_get_status_message(self._tox_pointer, status_message)
|
||||||
return status_message.value.decode('utf8')
|
return str(status_message.value, 'utf-8')
|
||||||
|
|
||||||
def self_set_status(self, status):
|
def self_set_status(self, status):
|
||||||
"""
|
"""
|
||||||
@ -688,7 +688,7 @@ class Tox(object):
|
|||||||
byref(tox_err_friend_query))
|
byref(tox_err_friend_query))
|
||||||
tox_err_friend_query = tox_err_friend_query.value
|
tox_err_friend_query = tox_err_friend_query.value
|
||||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
|
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
|
||||||
return name.value.decode('utf8')
|
return str(name.value, 'utf-8')
|
||||||
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
||||||
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
|
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
|
||||||
' the `_self_` variants of these functions, which have no effect when a parameter is'
|
' the `_self_` variants of these functions, which have no effect when a parameter is'
|
||||||
@ -752,7 +752,7 @@ class Tox(object):
|
|||||||
byref(tox_err_friend_query))
|
byref(tox_err_friend_query))
|
||||||
tox_err_friend_query = tox_err_friend_query.value
|
tox_err_friend_query = tox_err_friend_query.value
|
||||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
|
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
|
||||||
return status_message.value.decode('utf8')
|
return str(status_message.value, 'utf-8')
|
||||||
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
||||||
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
|
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
|
||||||
' the `_self_` variants of these functions, which have no effect when a parameter is'
|
' the `_self_` variants of these functions, which have no effect when a parameter is'
|
||||||
@ -1200,7 +1200,9 @@ class Tox(object):
|
|||||||
"""
|
"""
|
||||||
tox_err_file_send = c_int()
|
tox_err_file_send = c_int()
|
||||||
result = self.libtoxcore.tox_file_send(self._tox_pointer, c_uint32(friend_number), c_uint32(kind),
|
result = self.libtoxcore.tox_file_send(self._tox_pointer, c_uint32(friend_number), c_uint32(kind),
|
||||||
c_uint64(file_size), string_to_bin(file_id), c_char_p(filename),
|
c_uint64(file_size),
|
||||||
|
string_to_bin(file_id),
|
||||||
|
c_char_p(bytes(filename, 'utf-8')),
|
||||||
c_size_t(len(filename)), byref(tox_err_file_send))
|
c_size_t(len(filename)), byref(tox_err_file_send))
|
||||||
tox_err_file_send = tox_err_file_send.value
|
tox_err_file_send = tox_err_file_send.value
|
||||||
if tox_err_file_send == TOX_ERR_FILE_SEND['OK']:
|
if tox_err_file_send == TOX_ERR_FILE_SEND['OK']:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import urllib2
|
import urllib.request
|
||||||
from util import log
|
from util import log
|
||||||
|
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ def tox_dns(email):
|
|||||||
|
|
||||||
|
|
||||||
def send_request(url, data):
|
def send_request(url, data):
|
||||||
req = urllib2.Request(url)
|
req = urllib.request.Request(url)
|
||||||
req.add_header('Content-Type', 'application/json')
|
req.add_header('Content-Type', 'application/json')
|
||||||
response = urllib2.urlopen(req, json.dumps(data))
|
response = urllib.request.urlopen(req, json.dumps(data))
|
||||||
res = json.loads(response.read())
|
res = json.loads(response.read())
|
||||||
if not res['c']:
|
if not res['c']:
|
||||||
return res['tox_id']
|
return res['tox_id']
|
||||||
|
@ -39,6 +39,7 @@ class LibToxEncryptSave(util.Singleton):
|
|||||||
libtoxencryptsave = libtox.LibToxEncryptSave()
|
libtoxencryptsave = libtox.LibToxEncryptSave()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
LibToxEncryptSave._instance = self
|
||||||
self._passphrase = None
|
self._passphrase = None
|
||||||
|
|
||||||
def set_password(self, passphrase):
|
def set_password(self, passphrase):
|
||||||
@ -50,7 +51,7 @@ class LibToxEncryptSave(util.Singleton):
|
|||||||
def is_data_encrypted(self, data):
|
def is_data_encrypted(self, data):
|
||||||
func = self.libtoxencryptsave.tox_is_data_encrypted
|
func = self.libtoxencryptsave.tox_is_data_encrypted
|
||||||
func.restype = c_bool
|
func.restype = c_bool
|
||||||
result = func(c_char_p(data))
|
result = func(c_char_p(bytes(data)))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def pass_encrypt(self, data):
|
def pass_encrypt(self, data):
|
||||||
@ -61,9 +62,9 @@ class LibToxEncryptSave(util.Singleton):
|
|||||||
"""
|
"""
|
||||||
out = create_string_buffer(len(data) + TOX_PASS_ENCRYPTION_EXTRA_LENGTH)
|
out = create_string_buffer(len(data) + TOX_PASS_ENCRYPTION_EXTRA_LENGTH)
|
||||||
tox_err_encryption = c_int()
|
tox_err_encryption = c_int()
|
||||||
self.libtoxencryptsave.tox_pass_encrypt(c_char_p(data),
|
self.libtoxencryptsave.tox_pass_encrypt(c_char_p(bytes(data)),
|
||||||
c_size_t(len(data)),
|
c_size_t(len(data)),
|
||||||
c_char_p(self._passphrase),
|
c_char_p(bytes(self._passphrase)),
|
||||||
c_size_t(len(self._passphrase)),
|
c_size_t(len(self._passphrase)),
|
||||||
out,
|
out,
|
||||||
byref(tox_err_encryption))
|
byref(tox_err_encryption))
|
||||||
@ -86,9 +87,9 @@ class LibToxEncryptSave(util.Singleton):
|
|||||||
"""
|
"""
|
||||||
out = create_string_buffer(len(data) - TOX_PASS_ENCRYPTION_EXTRA_LENGTH)
|
out = create_string_buffer(len(data) - TOX_PASS_ENCRYPTION_EXTRA_LENGTH)
|
||||||
tox_err_decryption = c_int()
|
tox_err_decryption = c_int()
|
||||||
self.libtoxencryptsave.tox_pass_decrypt(c_char_p(data),
|
self.libtoxencryptsave.tox_pass_decrypt(c_char_p(bytes(data)),
|
||||||
c_size_t(len(data)),
|
c_size_t(len(data)),
|
||||||
c_char_p(self._passphrase),
|
c_char_p(bytes(self._passphrase)),
|
||||||
c_size_t(len(self._passphrase)),
|
c_size_t(len(self._passphrase)),
|
||||||
out,
|
out,
|
||||||
byref(tox_err_decryption))
|
byref(tox_err_decryption))
|
||||||
|
@ -26,12 +26,8 @@ def convert_time(t):
|
|||||||
return '%02d:%02d' % (h, m)
|
return '%02d:%02d' % (h, m)
|
||||||
|
|
||||||
|
|
||||||
class Singleton(object):
|
class Singleton:
|
||||||
|
_instance = None
|
||||||
def __new__(cls, *args, **kwargs):
|
|
||||||
if not hasattr(cls, '_instance'):
|
|
||||||
cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
|
|
||||||
return cls._instance
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls):
|
def get_instance(cls):
|
||||||
|
Loading…
Reference in New Issue
Block a user