avatars of friends support

This commit is contained in:
ingvar1995 2016-03-17 20:36:34 +03:00
parent 33290216df
commit 9768cfdd1e
2 changed files with 17 additions and 11 deletions

View File

@ -159,11 +159,11 @@ def tox_file_recv(window, tray):
def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, user_data): def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, user_data):
print 'Len:', type(length) invoke_in_main_thread(Profile.get_instance().incoming_chunk,
print 'Chunk', type(chunk) friend_number,
print 'Pos', type(position) file_number,
#chunk = cast(pointer(chunk), c_char_p)[0] position,
Profile.get_instance().incoming_chunk(friend_number, file_number, position, chunk[:length] if length else None) chunk[:length] if length else None)
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Callbacks - initialization # Callbacks - initialization
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------

View File

@ -313,7 +313,7 @@ class Profile(Contact, Singleton):
self._screen = screen self._screen = screen
self._messages = screen.messages self._messages = screen.messages
self._tox = tox self._tox = tox
self._file_transfers = [] # list of file transfers self._file_transfers = {} # dict of file transfers
settings = Settings.get_instance() settings = Settings.get_instance()
self._show_online = settings['show_online_friends'] self._show_online = settings['show_online_friends']
screen.online_contacts.setChecked(self._show_online) screen.online_contacts.setChecked(self._show_online)
@ -705,7 +705,7 @@ class Profile(Contact, Singleton):
def incoming_file_transfer(self, friend_number, file_number, size, file_name): def incoming_file_transfer(self, friend_number, file_number, size, file_name):
rt = ReceiveTransfer(Settings.get_default_path() + file_name, self._tox, friend_number) rt = ReceiveTransfer(Settings.get_default_path() + file_name, self._tox, friend_number)
self._file_transfers.append(rt) self._file_transfers[(friend_number, file_number)] = rt
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME']) self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME'])
def incoming_avatar(self, friend_number, file_number, size): def incoming_avatar(self, friend_number, file_number, size):
@ -724,13 +724,19 @@ class Profile(Contact, Singleton):
new_avatar_hash = self._tox.file_get_file_id(friend_number, file_number) new_avatar_hash = self._tox.file_get_file_id(friend_number, file_number)
if hash == new_avatar_hash: # avatar is the same if hash == new_avatar_hash: # avatar is the same
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) # ignore file self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) # ignore file
else: else: # get new avatar
pass path = ProfileHelper.get_path() + '/avatars/{}.png'.format(friend.tox_id)
rt = ReceiveTransfer(path, self._tox, friend_number)
self._file_transfers[(friend_number, file_number)] = rt
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME'])
def incoming_chunk(self, friend_number, file_number, position, data): def incoming_chunk(self, friend_number, file_number, position, data):
# TODO: better transfer filtering transfer = self._file_transfers[(friend_number, file_number)]
transfer = filter(lambda x: x._friend_number == friend_number, self._file_transfers)[0]
transfer.write_chunk(position, data) transfer.write_chunk(position, data)
if data is None:
del self._file_transfers[(friend_number, file_number)]
friend = self.get_friend_by_number(friend_number)
friend.load_avatar()
def send_avatar(self, friend_number): def send_avatar(self, friend_number):
pass pass