1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Cleanly cancel broken file transfers

This commit is contained in:
tux3 2015-04-25 19:18:46 +02:00
parent cdb2bad7c3
commit e74e29e4fb
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
4 changed files with 22 additions and 0 deletions

View File

@ -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"};

View File

@ -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);

View File

@ -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())
{

View File

@ -80,6 +80,7 @@ struct ToxFile
FileDirection direction;
QTimer* sendTimer;
QByteArray avatarData;
QByteArray resumeFileId;
};
#endif // CORESTRUCTS_H