From 976a6c139dddeea9c1f5d164a2d7102036d08afc Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 18 Mar 2016 16:50:32 +0300 Subject: [PATCH] sending bug fix --- src/file_transfers.py | 12 +++++++----- src/notifications.py | 4 +++- src/profile.py | 15 +++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/file_transfers.py b/src/file_transfers.py index 3cb0dce..ec00773 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -1,5 +1,3 @@ -# TODO: add support of file transfers -# TODO: add support of avatars from toxcore_enums_and_consts import TOX_FILE_KIND, TOX_FILE_CONTROL from os.path import basename, getsize, exists from os import remove @@ -58,9 +56,13 @@ class SendTransfer(FileTransfer): self._file = open(path, 'rb') def send_chunk(self, position, size): - self._file.seek(position) - data = self._file.read(size) - return self._tox.file_send_chunk(self._friend_number, self._file_number, position, data) + if size: + self._file.seek(position) + data = self._file.read(size) + return self._tox.file_send_chunk(self._friend_number, self._file_number, position, data) + else: + self._file.close() + self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] class SendAvatar(SendTransfer): diff --git a/src/notifications.py b/src/notifications.py index d090afd..b736f0e 100644 --- a/src/notifications.py +++ b/src/notifications.py @@ -2,6 +2,7 @@ from PySide import QtGui from PySide.phonon import Phonon from util import curr_directory # TODO: make app icon active +# TODO: add all sound notifications SOUND_NOTIFICATION = { @@ -19,9 +20,10 @@ def tray_notification(title, text, tray): def sound_notification(t): - # TODO: add other sound notifications if t == SOUND_NOTIFICATION['MESSAGE']: f = curr_directory() + '/sounds/message.wav' + elif t == SOUND_NOTIFICATION['FILE_TRANSFER']: + f = curr_directory() + '/sounds/file.wav' else: return m = Phonon.MediaSource(f) diff --git a/src/profile.py b/src/profile.py index 98d6a15..70f591e 100644 --- a/src/profile.py +++ b/src/profile.py @@ -313,7 +313,7 @@ class Profile(Contact, Singleton): self._screen = screen self._messages = screen.messages self._tox = tox - self._file_transfers = {} # dict of file transfers + self._file_transfers = {} # dict of file transfers. key - tuple (friend_number, file_number) settings = Settings.get_instance() self._show_online = settings['show_online_friends'] screen.online_contacts.setChecked(self._show_online) @@ -533,11 +533,12 @@ class Profile(Contact, Singleton): Save history to db """ print 'In save' - if Settings.get_instance()['save_history']: - for friend in self._friends: - messages = friend.get_corr_for_saving() - self._history.save_messages_to_db(friend.tox_id, messages) - del self._history + if hasattr(self, '_history'): + if Settings.get_instance()['save_history']: + for friend in self._friends: + messages = friend.get_corr_for_saving() + self._history.save_messages_to_db(friend.tox_id, messages) + del self._history def clear_history(self, num=None): if num is not None: @@ -744,6 +745,8 @@ class Profile(Contact, Singleton): def outgoing_chunk(self, friend_number, file_number, position, size): transfer = self._file_transfers[(friend_number, file_number)] transfer.send_chunk(position, size) + if transfer.state: + del self._file_transfers[(friend_number, file_number)] def tox_factory(data=None, settings=None):