file resuming part 3

This commit is contained in:
ingvar1995 2016-07-30 22:51:25 +03:00
parent 59154d081f
commit d1437b3445
2 changed files with 13 additions and 11 deletions

View File

@ -218,6 +218,7 @@ class ReceiveTransfer(FileTransfer):
self._file.truncate(position) self._file.truncate(position)
self._missed = set() self._missed = set()
self._file_id = self.get_file_id() self._file_id = self.get_file_id()
self._done = position
def cancel(self): def cancel(self):
super(ReceiveTransfer, self).cancel() super(ReceiveTransfer, self).cancel()

View File

@ -43,7 +43,8 @@ class Profile(contact.Contact, Singleton):
self._show_online = settings['show_online_friends'] self._show_online = settings['show_online_friends']
self._show_avatars = settings['show_avatars'] self._show_avatars = settings['show_avatars']
self._friend_item_height = 40 if settings['compact_mode'] else 70 self._friend_item_height = 40 if settings['compact_mode'] else 70
self._paused_file_transfers = settings['paused_file_transfers'] self._paused_file_transfers = dict(settings['paused_file_transfers'])
# key - file id, value: [path, friend number, is incoming, start position]
screen.online_contacts.setCurrentIndex(int(self._show_online)) screen.online_contacts.setCurrentIndex(int(self._show_online))
aliases = settings['friends_aliases'] aliases = settings['friends_aliases']
data = tox.self_get_friend_list() data = tox.self_get_friend_list()
@ -841,14 +842,16 @@ class Profile(contact.Contact, Singleton):
QtCore.QTimer.singleShot(30000, self.reconnect) QtCore.QTimer.singleShot(30000, self.reconnect)
def close(self): def close(self):
for friend in self._friends:
self.friend_exit(friend.number)
for i in range(len(self._friends)):
del self._friends[0]
if hasattr(self, '_call'): if hasattr(self, '_call'):
self._call.stop() self._call.stop()
del self._call del self._call
for i in range(len(self._friends)): s = Settings.get_instance()
del self._friends[0] s['paused_file_transfers'] = dict(self._paused_file_transfers) if s['resend_files'] else {}
settings = Settings.get_instance() s.save()
settings['paused_file_transfers'] = self._paused_file_transfers if settings['resend_files'] else {}
settings.save()
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# File transfers support # File transfers support
@ -870,10 +873,8 @@ class Profile(contact.Contact, Singleton):
accepted = True accepted = True
if file_id in self._paused_file_transfers: if file_id in self._paused_file_transfers:
data = self._paused_file_transfers[file_id] data = self._paused_file_transfers[file_id]
if not os.path.exists(data[0]): pos = data[-1] if os.path.exists(data[0]) else 0
pos = 0 print(pos, os.path.getsize(data[0]))
else:
pos = data[-1]
self._tox.file_seek(friend_number, file_number, pos) self._tox.file_seek(friend_number, file_number, pos)
self.accept_transfer(None, data[0], friend_number, file_number, size, False, pos) self.accept_transfer(None, data[0], friend_number, file_number, size, False, pos)
tm = TransferMessage(MESSAGE_OWNER['FRIEND'], tm = TransferMessage(MESSAGE_OWNER['FRIEND'],
@ -1052,7 +1053,7 @@ class Profile(contact.Contact, Singleton):
:param is_resend: is 'offline' message :param is_resend: is 'offline' message
:param file_id: file id of transfer :param file_id: file id of transfer
""" """
friend_number = number or self.get_active_number() friend_number = self.get_active_number() if number is None else number
friend = self.get_friend_by_number(friend_number) friend = self.get_friend_by_number(friend_number)
if friend.status is None and not is_resend: if friend.status is None and not is_resend:
m = UnsentFile(path, None, time.time()) m = UnsentFile(path, None, time.time())