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:
parent
cdb2bad7c3
commit
e74e29e4fb
|
@ -78,6 +78,7 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
|
||||||
connect(Core::getInstance(), &Core::fileTransferPaused, this, &FileTransferWidget::onFileTransferPaused);
|
connect(Core::getInstance(), &Core::fileTransferPaused, this, &FileTransferWidget::onFileTransferPaused);
|
||||||
connect(Core::getInstance(), &Core::fileTransferFinished, this, &FileTransferWidget::onFileTransferFinished);
|
connect(Core::getInstance(), &Core::fileTransferFinished, this, &FileTransferWidget::onFileTransferFinished);
|
||||||
connect(Core::getInstance(), &Core::fileTransferRemotePausedUnpaused, this, &FileTransferWidget::fileTransferRemotePausedUnpaused);
|
connect(Core::getInstance(), &Core::fileTransferRemotePausedUnpaused, this, &FileTransferWidget::fileTransferRemotePausedUnpaused);
|
||||||
|
connect(Core::getInstance(), &Core::fileTransferBrokenUnbroken, this, &FileTransferWidget::fileTransferBrokenUnbroken);
|
||||||
|
|
||||||
setupButtons();
|
setupButtons();
|
||||||
|
|
||||||
|
@ -370,6 +371,13 @@ void FileTransferWidget::fileTransferRemotePausedUnpaused(ToxFile file, bool pau
|
||||||
onFileTransferResumed(file);
|
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)
|
QString FileTransferWidget::getHumanReadableSize(qint64 size)
|
||||||
{
|
{
|
||||||
static const char* suffix[] = {"B","kiB","MiB","GiB","TiB"};
|
static const char* suffix[] = {"B","kiB","MiB","GiB","TiB"};
|
||||||
|
|
|
@ -48,6 +48,7 @@ protected slots:
|
||||||
void onFileTransferResumed(ToxFile file);
|
void onFileTransferResumed(ToxFile file);
|
||||||
void onFileTransferFinished(ToxFile file);
|
void onFileTransferFinished(ToxFile file);
|
||||||
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
|
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
|
||||||
|
void fileTransferBrokenUnbroken(ToxFile file, bool broken);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString getHumanReadableSize(qint64 size);
|
QString getHumanReadableSize(qint64 size);
|
||||||
|
|
|
@ -34,6 +34,8 @@ void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& d
|
||||||
file.fileName = QByteArray((char*)filename, TOX_HASH_LENGTH);
|
file.fileName = QByteArray((char*)filename, TOX_HASH_LENGTH);
|
||||||
file.fileKind = TOX_FILE_KIND_AVATAR;
|
file.fileKind = TOX_FILE_KIND_AVATAR;
|
||||||
file.avatarData = data;
|
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);
|
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};
|
ToxFile file{fileNum, friendId, fileName, FilePath, ToxFile::SENDING};
|
||||||
file.filesize = filesize;
|
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))
|
if (!file.open(false))
|
||||||
{
|
{
|
||||||
qWarning() << QString("CoreFile::sendFile: Can't open file, error: %1").arg(file.file->errorString());
|
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};
|
CString::toString(fname,fnameLen).toUtf8(), "", ToxFile::RECEIVING};
|
||||||
file.filesize = filesize;
|
file.filesize = filesize;
|
||||||
file.fileKind = kind;
|
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);
|
addFile(friendId, fileId, file);
|
||||||
if (kind != TOX_FILE_KIND_AVATAR)
|
if (kind != TOX_FILE_KIND_AVATAR)
|
||||||
emit core->fileReceiveRequested(file);
|
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)
|
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;
|
ToxFile::FileStatus status = online ? ToxFile::TRANSMITTING : ToxFile::BROKEN;
|
||||||
for (uint64_t key : fileMap.keys())
|
for (uint64_t key : fileMap.keys())
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,6 +80,7 @@ struct ToxFile
|
||||||
FileDirection direction;
|
FileDirection direction;
|
||||||
QTimer* sendTimer;
|
QTimer* sendTimer;
|
||||||
QByteArray avatarData;
|
QByteArray avatarData;
|
||||||
|
QByteArray resumeFileId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CORESTRUCTS_H
|
#endif // CORESTRUCTS_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user