bug fixes and docs update
This commit is contained in:
parent
100d83aea7
commit
23a682cbdf
@ -20,6 +20,9 @@ class StateSignal(QtCore.QObject):
|
|||||||
|
|
||||||
|
|
||||||
class FileTransfer(QtCore.QObject):
|
class FileTransfer(QtCore.QObject):
|
||||||
|
"""
|
||||||
|
Superclass for file transfers
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, path, tox, friend_number, size, file_number=None):
|
def __init__(self, path, tox, friend_number, size, file_number=None):
|
||||||
QtCore.QObject.__init__(self)
|
QtCore.QObject.__init__(self)
|
||||||
@ -49,12 +52,12 @@ class FileTransfer(QtCore.QObject):
|
|||||||
self.send_control(TOX_FILE_CONTROL['CANCEL'])
|
self.send_control(TOX_FILE_CONTROL['CANCEL'])
|
||||||
if hasattr(self, '_file'):
|
if hasattr(self, '_file'):
|
||||||
self._file.close()
|
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):
|
def cancelled(self):
|
||||||
if hasattr(self, '_file'):
|
if hasattr(self, '_file'):
|
||||||
self._file.close()
|
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):
|
def send_control(self, control):
|
||||||
if self._tox.file_control(self._friend_number, self._file_number, 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 '')
|
basename(path).encode('utf-8') if path else '')
|
||||||
|
|
||||||
def send_chunk(self, position, size):
|
def send_chunk(self, position, size):
|
||||||
|
"""
|
||||||
|
Send chunk
|
||||||
|
:param position: start position in file
|
||||||
|
:param size: chunk max size
|
||||||
|
"""
|
||||||
if size:
|
if size:
|
||||||
self._file.seek(position)
|
self._file.seek(position)
|
||||||
data = self._file.read(size)
|
data = self._file.read(size)
|
||||||
@ -95,6 +103,9 @@ class SendTransfer(FileTransfer):
|
|||||||
|
|
||||||
|
|
||||||
class SendAvatar(SendTransfer):
|
class SendAvatar(SendTransfer):
|
||||||
|
"""
|
||||||
|
Send avatar to friend. Doesn't need file transfer item
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, path, tox, friend_number):
|
def __init__(self, path, tox, friend_number):
|
||||||
if path is None:
|
if path is None:
|
||||||
@ -106,6 +117,9 @@ class SendAvatar(SendTransfer):
|
|||||||
|
|
||||||
|
|
||||||
class SendFromBuffer(FileTransfer):
|
class SendFromBuffer(FileTransfer):
|
||||||
|
"""
|
||||||
|
Send inline image
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, tox, friend_number, data, file_name):
|
def __init__(self, tox, friend_number, data, file_name):
|
||||||
super(SendFromBuffer, self).__init__(None, tox, friend_number, len(data))
|
super(SendFromBuffer, self).__init__(None, tox, friend_number, len(data))
|
||||||
@ -143,6 +157,11 @@ class ReceiveTransfer(FileTransfer):
|
|||||||
remove(self._path)
|
remove(self._path)
|
||||||
|
|
||||||
def write_chunk(self, position, data):
|
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:
|
if data is None:
|
||||||
self._file.close()
|
self._file.close()
|
||||||
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
||||||
@ -163,6 +182,9 @@ class ReceiveTransfer(FileTransfer):
|
|||||||
|
|
||||||
|
|
||||||
class ReceiveToBuffer(FileTransfer):
|
class ReceiveToBuffer(FileTransfer):
|
||||||
|
"""
|
||||||
|
Inline image - save in buffer not in file system
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, tox, friend_number, size, file_number):
|
def __init__(self, tox, friend_number, size, file_number):
|
||||||
super(ReceiveToBuffer, self).__init__(None, 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):
|
class ReceiveAvatar(ReceiveTransfer):
|
||||||
|
"""
|
||||||
|
Get friend's avatar. Doesn't need file transfer item
|
||||||
|
"""
|
||||||
MAX_AVATAR_SIZE = 512 * 1024
|
MAX_AVATAR_SIZE = 512 * 1024
|
||||||
|
|
||||||
def __init__(self, tox, friend_number, size, file_number):
|
def __init__(self, tox, friend_number, size, file_number):
|
||||||
|
@ -38,7 +38,7 @@ class Toxygen(object):
|
|||||||
if curr_lang in map(lambda x: x[0], langs):
|
if curr_lang in map(lambda x: x[0], langs):
|
||||||
lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1]
|
lang_path = filter(lambda x: x[0] == curr_lang, langs)[0][1]
|
||||||
translator = QtCore.QTranslator()
|
translator = QtCore.QTranslator()
|
||||||
translator.load('translations/' + lang_path)
|
translator.load(curr_directory() + '/translations/' + lang_path)
|
||||||
app.installTranslator(translator)
|
app.installTranslator(translator)
|
||||||
app.translator = translator
|
app.translator = translator
|
||||||
ls = LoginScreen()
|
ls = LoginScreen()
|
||||||
@ -87,7 +87,7 @@ class Toxygen(object):
|
|||||||
|
|
||||||
lang = filter(lambda x: x[0] == settings['language'], Settings.supported_languages())[0]
|
lang = filter(lambda x: x[0] == settings['language'], Settings.supported_languages())[0]
|
||||||
translator = QtCore.QTranslator()
|
translator = QtCore.QTranslator()
|
||||||
translator.load('translations/' + lang[1])
|
translator.load(curr_directory() + '/translations/' + lang[1])
|
||||||
app.installTranslator(translator)
|
app.installTranslator(translator)
|
||||||
app.translator = translator
|
app.translator = translator
|
||||||
|
|
||||||
@ -217,11 +217,10 @@ class Toxygen(object):
|
|||||||
def login_screen_close(self, t, number=-1, default=False, name=None):
|
def login_screen_close(self, t, number=-1, default=False, name=None):
|
||||||
""" Function which processes data from login screen
|
""" Function which processes data from login screen
|
||||||
:param t: 0 - window was closed, 1 - new profile was created, 2 - profile loaded
|
: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 number: num of chosen profile in list (-1 by default)
|
||||||
:param default: was or not choosen profile marked as default
|
:param default: was or not chosen profile marked as default
|
||||||
:param name: name of new profile
|
:param name: name of new profile
|
||||||
"""
|
"""
|
||||||
print str(t), str(number), str(default), str(name)
|
|
||||||
self.t = t
|
self.t = t
|
||||||
self.num = number
|
self.num = number
|
||||||
self.default = default
|
self.default = default
|
||||||
|
@ -181,13 +181,20 @@ class Friend(Contact):
|
|||||||
if message.get_type() <= 1:
|
if message.get_type() <= 1:
|
||||||
self._unsaved_messages += 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)
|
messages = filter(lambda x: x.get_type() <= 1 and not x.get_owner(), self._corr)
|
||||||
if messages:
|
if messages:
|
||||||
return messages[-1].get_data()[0]
|
return messages[-1].get_data()[0]
|
||||||
else:
|
else:
|
||||||
return ''
|
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):
|
def clear_corr(self):
|
||||||
"""
|
"""
|
||||||
Clear messages list
|
Clear messages list
|
||||||
@ -421,7 +428,7 @@ class Profile(Contact, Singleton):
|
|||||||
active_friend = property(get_active, set_active)
|
active_friend = property(get_active, set_active)
|
||||||
|
|
||||||
def get_last_message(self):
|
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):
|
def get_active_number(self):
|
||||||
return self._friends[self._active_friend].number if self._active_friend + 1 else -1
|
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):
|
def tox_factory(data=None, settings=None):
|
||||||
"""
|
"""
|
||||||
:param data: user data from .tox file. None = no saved data, create new profile
|
: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
|
:return: new tox instance
|
||||||
"""
|
"""
|
||||||
if settings is None:
|
if settings is None:
|
||||||
|
@ -205,3 +205,5 @@ TOX_SECRET_KEY_SIZE = 32
|
|||||||
TOX_FILE_ID_LENGTH = 32
|
TOX_FILE_ID_LENGTH = 32
|
||||||
|
|
||||||
TOX_HASH_LENGTH = 32
|
TOX_HASH_LENGTH = 32
|
||||||
|
|
||||||
|
TOX_MAX_CUSTOM_PACKET_SIZE = 1373
|
||||||
|
Loading…
Reference in New Issue
Block a user