From 23a682cbdfbf08b814ed1d2b73c306eaf7cefa73 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 14 Apr 2016 15:01:59 +0300 Subject: [PATCH] bug fixes and docs update --- src/file_transfers.py | 29 +++++++++++++++++++++++++++-- src/main.py | 9 ++++----- src/profile.py | 15 +++++++++++---- src/toxcore_enums_and_consts.py | 2 ++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/file_transfers.py b/src/file_transfers.py index ba98195..bc4c36a 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -20,6 +20,9 @@ class StateSignal(QtCore.QObject): class FileTransfer(QtCore.QObject): + """ + Superclass for file transfers + """ def __init__(self, path, tox, friend_number, size, file_number=None): QtCore.QObject.__init__(self) @@ -49,12 +52,12 @@ class FileTransfer(QtCore.QObject): self.send_control(TOX_FILE_CONTROL['CANCEL']) if hasattr(self, '_file'): self._file.close() - self._state_changed.signal.emit(self.state, self._done / self._size) + self._state_changed.signal.emit(self.state, 1) def cancelled(self): if hasattr(self, '_file'): self._file.close() - self._state_changed.signal.emit(TOX_FILE_CONTROL['CANCEL'], self._done / self._size if self._size else 0) + self._state_changed.signal.emit(TOX_FILE_CONTROL['CANCEL'], 1) def send_control(self, control): if self._tox.file_control(self._friend_number, self._file_number, control): @@ -82,6 +85,11 @@ class SendTransfer(FileTransfer): basename(path).encode('utf-8') if path else '') def send_chunk(self, position, size): + """ + Send chunk + :param position: start position in file + :param size: chunk max size + """ if size: self._file.seek(position) data = self._file.read(size) @@ -95,6 +103,9 @@ class SendTransfer(FileTransfer): class SendAvatar(SendTransfer): + """ + Send avatar to friend. Doesn't need file transfer item + """ def __init__(self, path, tox, friend_number): if path is None: @@ -106,6 +117,9 @@ class SendAvatar(SendTransfer): class SendFromBuffer(FileTransfer): + """ + Send inline image + """ def __init__(self, tox, friend_number, data, file_name): super(SendFromBuffer, self).__init__(None, tox, friend_number, len(data)) @@ -143,6 +157,11 @@ class ReceiveTransfer(FileTransfer): remove(self._path) def write_chunk(self, position, data): + """ + Incoming chunk + :param position: position in file to save data + :param data: raw data (string) + """ if data is None: self._file.close() self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] @@ -163,6 +182,9 @@ class ReceiveTransfer(FileTransfer): class ReceiveToBuffer(FileTransfer): + """ + Inline image - save in buffer not in file system + """ def __init__(self, tox, friend_number, size, file_number): super(ReceiveToBuffer, self).__init__(None, tox, friend_number, size, file_number) @@ -189,6 +211,9 @@ class ReceiveToBuffer(FileTransfer): class ReceiveAvatar(ReceiveTransfer): + """ + Get friend's avatar. Doesn't need file transfer item + """ MAX_AVATAR_SIZE = 512 * 1024 def __init__(self, tox, friend_number, size, file_number): diff --git a/src/main.py b/src/main.py index 2ce549a..1417114 100644 --- a/src/main.py +++ b/src/main.py @@ -38,7 +38,7 @@ class Toxygen(object): if curr_lang in map(lambda x: x[0], langs): lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1] translator = QtCore.QTranslator() - translator.load('translations/' + lang_path) + translator.load(curr_directory() + '/translations/' + lang_path) app.installTranslator(translator) app.translator = translator ls = LoginScreen() @@ -87,7 +87,7 @@ class Toxygen(object): lang = filter(lambda x: x[0] == settings['language'], Settings.supported_languages())[0] translator = QtCore.QTranslator() - translator.load('translations/' + lang[1]) + translator.load(curr_directory() + '/translations/' + lang[1]) app.installTranslator(translator) app.translator = translator @@ -217,11 +217,10 @@ class Toxygen(object): def login_screen_close(self, t, number=-1, default=False, name=None): """ Function which processes data from login screen :param t: 0 - window was closed, 1 - new profile was created, 2 - profile loaded - :param number: num of choosen profile in list (-1 by default) - :param default: was or not choosen profile marked as default + :param number: num of chosen profile in list (-1 by default) + :param default: was or not chosen profile marked as default :param name: name of new profile """ - print str(t), str(number), str(default), str(name) self.t = t self.num = number self.default = default diff --git a/src/profile.py b/src/profile.py index edd703c..3631b6c 100644 --- a/src/profile.py +++ b/src/profile.py @@ -181,13 +181,20 @@ class Friend(Contact): if message.get_type() <= 1: self._unsaved_messages += 1 - def get_last_message(self): + def get_last_message_text(self): messages = filter(lambda x: x.get_type() <= 1 and not x.get_owner(), self._corr) if messages: return messages[-1].get_data()[0] else: return '' + def last_message_owner(self): + messages = filter(lambda x: x.get_type() <= 1, self._corr) + if messages: + return messages[-1].get_owner() + else: + return -1 + def clear_corr(self): """ Clear messages list @@ -208,7 +215,7 @@ class Friend(Contact): i = self._corr.index(tr) self._corr.insert(i, inline) except Exception as ex: - log('Update transfer data failed:' + str(ex)) + log('Update transfer data failed: ' + str(ex)) # ----------------------------------------------------------------------------------------------------------------- # Alias support @@ -421,7 +428,7 @@ class Profile(Contact, Singleton): active_friend = property(get_active, set_active) def get_last_message(self): - return self._friends[self._active_friend].get_last_message() + return self._friends[self._active_friend].get_last_message_text() def get_active_number(self): return self._friends[self._active_friend].number if self._active_friend + 1 else -1 @@ -949,7 +956,7 @@ class Profile(Contact, Singleton): def tox_factory(data=None, settings=None): """ :param data: user data from .tox file. None = no saved data, create new profile - :param settings: current application settings. None = defaults settings will be used + :param settings: current profile settings. None = default settings will be used :return: new tox instance """ if settings is None: diff --git a/src/toxcore_enums_and_consts.py b/src/toxcore_enums_and_consts.py index 17c9e13..4d52837 100644 --- a/src/toxcore_enums_and_consts.py +++ b/src/toxcore_enums_and_consts.py @@ -205,3 +205,5 @@ TOX_SECRET_KEY_SIZE = 32 TOX_FILE_ID_LENGTH = 32 TOX_HASH_LENGTH = 32 + +TOX_MAX_CUSTOM_PACKET_SIZE = 1373