From e74e29e4fb172002567e6e759405aeb7f5906aad Mon Sep 17 00:00:00 2001 From: tux3 Date: Sat, 25 Apr 2015 19:18:46 +0200 Subject: [PATCH] Cleanly cancel broken file transfers --- src/chatlog/content/filetransferwidget.cpp | 8 ++++++++ src/chatlog/content/filetransferwidget.h | 1 + src/core/corefile.cpp | 12 ++++++++++++ src/core/corestructs.h | 1 + 4 files changed, 22 insertions(+) diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index 636874fd3..1888a229c 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -78,6 +78,7 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file) connect(Core::getInstance(), &Core::fileTransferPaused, this, &FileTransferWidget::onFileTransferPaused); connect(Core::getInstance(), &Core::fileTransferFinished, this, &FileTransferWidget::onFileTransferFinished); connect(Core::getInstance(), &Core::fileTransferRemotePausedUnpaused, this, &FileTransferWidget::fileTransferRemotePausedUnpaused); + connect(Core::getInstance(), &Core::fileTransferBrokenUnbroken, this, &FileTransferWidget::fileTransferBrokenUnbroken); setupButtons(); @@ -370,6 +371,13 @@ void FileTransferWidget::fileTransferRemotePausedUnpaused(ToxFile file, bool pau onFileTransferResumed(file); } +void FileTransferWidget::fileTransferBrokenUnbroken(ToxFile file, bool broken) +{ + /// TODO: Handle broken transfer differently once we have resuming code + if (broken) + onFileTransferCancelled(file); +} + QString FileTransferWidget::getHumanReadableSize(qint64 size) { static const char* suffix[] = {"B","kiB","MiB","GiB","TiB"}; diff --git a/src/chatlog/content/filetransferwidget.h b/src/chatlog/content/filetransferwidget.h index 491477345..b05a3aee5 100644 --- a/src/chatlog/content/filetransferwidget.h +++ b/src/chatlog/content/filetransferwidget.h @@ -48,6 +48,7 @@ protected slots: void onFileTransferResumed(ToxFile file); void onFileTransferFinished(ToxFile file); void fileTransferRemotePausedUnpaused(ToxFile file, bool paused); + void fileTransferBrokenUnbroken(ToxFile file, bool broken); protected: QString getHumanReadableSize(qint64 size); diff --git a/src/core/corefile.cpp b/src/core/corefile.cpp index 299df352a..4b5f355ea 100644 --- a/src/core/corefile.cpp +++ b/src/core/corefile.cpp @@ -34,6 +34,8 @@ void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& d file.fileName = QByteArray((char*)filename, TOX_HASH_LENGTH); file.fileKind = TOX_FILE_KIND_AVATAR; file.avatarData = data; + file.resumeFileId.resize(TOX_FILE_ID_LENGTH); + tox_file_get_file_id(core->tox, friendId, fileNum, (uint8_t*)file.resumeFileId.data(), nullptr); addFile(friendId, fileNum, file); } @@ -54,6 +56,8 @@ void CoreFile::sendFile(Core* core, uint32_t friendId, QString Filename, QString ToxFile file{fileNum, friendId, fileName, FilePath, ToxFile::SENDING}; file.filesize = filesize; + file.resumeFileId.resize(TOX_FILE_ID_LENGTH); + tox_file_get_file_id(core->tox, friendId, fileNum, (uint8_t*)file.resumeFileId.data(), nullptr); if (!file.open(false)) { qWarning() << QString("CoreFile::sendFile: Can't open file, error: %1").arg(file.file->errorString()); @@ -240,6 +244,8 @@ void CoreFile::onFileReceiveCallback(Tox*, uint32_t friendId, uint32_t fileId, u CString::toString(fname,fnameLen).toUtf8(), "", ToxFile::RECEIVING}; file.filesize = filesize; file.fileKind = kind; + file.resumeFileId.resize(TOX_FILE_ID_LENGTH); + tox_file_get_file_id(core->tox, friendId, fileId, (uint8_t*)file.resumeFileId.data(), nullptr); addFile(friendId, fileId, file); if (kind != TOX_FILE_KIND_AVATAR) emit core->fileReceiveRequested(file); @@ -392,6 +398,12 @@ void CoreFile::onFileRecvChunkCallback(Tox *tox, uint32_t friendId, uint32_t fil void CoreFile::onConnectionStatusChanged(Core* core, uint32_t friendId, bool online) { + /// TODO: Actually resume broken file transfers + /// We need to: + /// - Start a new file transfer with the same 32byte file ID with toxcore + /// - Seek to the correct position again + /// - Update the fileNum in our ToxFile + /// - Update the users of our signals to check the 32byte tox file ID, not the uint32_t file_num (fileId) ToxFile::FileStatus status = online ? ToxFile::TRANSMITTING : ToxFile::BROKEN; for (uint64_t key : fileMap.keys()) { diff --git a/src/core/corestructs.h b/src/core/corestructs.h index 388b94366..0edbfdc9c 100644 --- a/src/core/corestructs.h +++ b/src/core/corestructs.h @@ -80,6 +80,7 @@ struct ToxFile FileDirection direction; QTimer* sendTimer; QByteArray avatarData; + QByteArray resumeFileId; }; #endif // CORESTRUCTS_H