From 42aa102d1d4444e8c2feafade4facb9b045addcd Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 21 Jun 2016 23:43:43 +0300 Subject: [PATCH] encrypt save support, smileys fix, bug fixes --- src/file_transfers.py | 2 +- src/history.py | 2 +- src/list_items.py | 2 +- src/mainscreen_widgets.py | 4 ++-- src/menu.py | 2 +- src/profile.py | 5 ++++- src/settings.py | 6 ++++-- src/smileys.py | 2 +- src/toxencryptsave.py | 6 +++--- 9 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/file_transfers.py b/src/file_transfers.py index ee86506..9f3be01 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -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: diff --git a/src/history.py b/src/history.py index bffec3e..4435d3f 100644 --- a/src/history.py +++ b/src/history.py @@ -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) diff --git a/src/list_items.py b/src/list_items.py index 87de7e5..c663780 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -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 diff --git a/src/mainscreen_widgets.py b/src/mainscreen_widgets.py index fc23670..ba8fcb9 100644 --- a/src/mainscreen_widgets.py +++ b/src/mainscreen_widgets.py @@ -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) diff --git a/src/menu.py b/src/menu.py index ae011b1..6d89db9 100644 --- a/src/menu.py +++ b/src/menu.py @@ -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): diff --git a/src/profile.py b/src/profile.py index 4eb6450..d922d03 100644 --- a/src/profile.py +++ b/src/profile.py @@ -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'], diff --git a/src/settings.py b/src/settings.py index 43a8cdb..45b2bc1 100644 --- a/src/settings.py +++ b/src/settings.py @@ -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' diff --git a/src/smileys.py b/src/smileys.py index 47e414b..bf1eb84 100644 --- a/src/smileys.py +++ b/src/smileys.py @@ -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): """ diff --git a/src/toxencryptsave.py b/src/toxencryptsave.py index e003500..633586f 100644 --- a/src/toxencryptsave.py +++ b/src/toxencryptsave.py @@ -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))