encrypt save support, smileys fix, bug fixes

This commit is contained in:
ingvar1995 2016-06-21 23:43:43 +03:00
parent dd53c6a842
commit 42aa102d1d
9 changed files with 18 additions and 13 deletions

View File

@ -177,7 +177,7 @@ class SendFromBuffer(FileTransfer):
self._creation_time = time()
if size:
data = self._data[position:position + size]
self._tox.file_send_chunk(self._friend_number, self._file_number, position, bytes(data, 'utf-8'))
self._tox.file_send_chunk(self._friend_number, self._file_number, position, data)
self._done += size
self.signal()
else:

View File

@ -45,7 +45,7 @@ class History(object):
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
with open(path, 'rb') as fin:
data = fin.read()
data = encr.pass_encrypt(data)
data = encr.pass_encrypt(bytes(data))
with open(path, 'wb') as fout:
fout.write(data)

View File

@ -430,7 +430,7 @@ class InlineImageItem(QtGui.QScrollArea):
self.setWidget(self._image_label)
self._image_label.setScaledContents(False)
self._pixmap = QtGui.QPixmap()
self._pixmap.loadFromData(QtCore.QByteArray(data), "PNG")
self._pixmap.loadFromData(QtCore.QByteArray(str(data)), "PNG")
self._max_size = width - 30
self._resize_needed = not (self._pixmap.width() <= self._max_size)
self._full_size = not self._resize_needed

View File

@ -144,13 +144,13 @@ class SmileyWindow(QtGui.QWidget):
elem.setGeometry(QtCore.QRect(i * 20 + 5, 180, 20, 20))
elem.clicked.connect(lambda i=i: self.checked(i))
self.radio.append(elem)
width = max(self.page_count * 20 + 30, (self.page_size + 5) * 8 / 10)
width = max(self.page_count * 20 + 30, (self.page_size + 5) * 8 // 10)
self.setMaximumSize(width, 200)
self.setMinimumSize(width, 200)
self.buttons = []
for i in range(self.page_size): # pages - radio buttons
b = QtGui.QPushButton(self)
b.setGeometry(QtCore.QRect((i / 8) * 20 + 5, (i % 8) * 20, 20, 20))
b.setGeometry(QtCore.QRect((i // 8) * 20 + 5, (i % 8) * 20, 20, 20))
b.clicked.connect(lambda i=i: self.clicked(i))
self.buttons.append(b)
self.checked(0)

View File

@ -715,7 +715,7 @@ class PluginsSettings(CenteredWidget):
def update_list(self):
self.comboBox.clear()
data = self.pl_loader.get_plugins_list()
self.comboBox.addItems(map(lambda x: x[0], data))
self.comboBox.addItems(list(map(lambda x: x[0], data)))
self.data = data
def show_data(self):

View File

@ -84,7 +84,7 @@ class Profile(contact.Contact, Singleton):
if tmp != value:
message = QtGui.QApplication.translate("MainWindow", 'User {} is now known as {}', None,
QtGui.QApplication.UnicodeUTF8)
message = message.format(tmp, value)
message = message.format(tmp, str(value, 'utf-8'))
for friend in self._friends:
friend.append_message(InfoMessage(message, time.time()))
if self._active_friend + 1:
@ -246,6 +246,7 @@ class Profile(contact.Contact, Singleton):
friend = self.get_friend_by_number(number)
tmp = friend.name
friend.set_name(name)
name = str(name, 'utf-8')
if friend.name == name and tmp != name:
message = QtGui.QApplication.translate("MainWindow", 'User {} is now known as {}', None, QtGui.QApplication.UnicodeUTF8)
message = message.format(tmp, name)
@ -977,6 +978,7 @@ class Profile(contact.Contact, Singleton):
self.get_friend_by_number(friend_number).load_avatar()
self.set_active(None)
elif type(transfer) is ReceiveToBuffer: # inline image
print('inline')
inline = InlineImage(transfer.get_data())
i = self.get_friend_by_number(friend_number).update_transfer_data(file_number,
TOX_FILE_TRANSFER_STATE['FINISHED'],
@ -1006,6 +1008,7 @@ class Profile(contact.Contact, Singleton):
if type(transfer) is not SendAvatar:
if type(transfer) is SendFromBuffer and Settings.get_instance()['allow_inline']: # inline
inline = InlineImage(transfer.get_data())
print('inline')
i = self.get_friend_by_number(friend_number).update_transfer_data(file_number,
TOX_FILE_TRANSFER_STATE[
'FINISHED'],

View File

@ -144,9 +144,11 @@ class Settings(dict, Singleton):
text = json.dumps(self)
inst = LibToxEncryptSave.get_instance()
if inst.has_password():
text = inst.pass_encrypt(text)
text = bytes(inst.pass_encrypt(bytes(text, 'utf-8')))
else:
text = bytes(text, 'utf-8')
with open(self.path, 'wb') as fl:
fl.write(bytes(text, 'UTF-8'))
fl.write(text)
def close(self):
path = Settings.get_default_path() + 'toxygen.json'

View File

@ -55,7 +55,7 @@ class SmileyLoader(util.Singleton):
return [x[1] for x in os.walk(d)][0]
def get_smileys(self):
return self._list[:]
return list(self._list)[:]
def add_smileys_to_text(self, text, edit):
"""

View File

@ -62,9 +62,9 @@ class LibToxEncryptSave(util.Singleton):
"""
out = create_string_buffer(len(data) + TOX_PASS_ENCRYPTION_EXTRA_LENGTH)
tox_err_encryption = c_int()
self.libtoxencryptsave.tox_pass_encrypt(c_char_p(bytes(data)),
self.libtoxencryptsave.tox_pass_encrypt(c_char_p(data),
c_size_t(len(data)),
c_char_p(bytes(self._passphrase)),
c_char_p(bytes(self._passphrase, 'utf-8')),
c_size_t(len(self._passphrase)),
out,
byref(tox_err_encryption))
@ -89,7 +89,7 @@ class LibToxEncryptSave(util.Singleton):
tox_err_decryption = c_int()
self.libtoxencryptsave.tox_pass_decrypt(c_char_p(bytes(data)),
c_size_t(len(data)),
c_char_p(bytes(self._passphrase)),
c_char_p(bytes(self._passphrase, 'utf-8')),
c_size_t(len(self._passphrase)),
out,
byref(tox_err_decryption))