mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Implement file send cancel
This commit is contained in:
parent
c18d63553d
commit
b62700e6f6
13
core.cpp
13
core.cpp
|
@ -162,7 +162,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
|
|||
{
|
||||
qWarning("Core::onFileControlCallback: Error getting preffered chunk size, aborting file send");
|
||||
file->status = ToxFile::STOPPED;
|
||||
emit static_cast<Core*>(core)->fileTransferFinished(file);
|
||||
emit static_cast<Core*>(core)->fileTransferCancelled(file);
|
||||
tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
|
||||
return;
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
|
|||
{
|
||||
qWarning("Core::onFileControlCallback: Error sending first data chunk, aborting");
|
||||
file->status = ToxFile::STOPPED;
|
||||
emit static_cast<Core*>(core)->fileTransferFinished(file);
|
||||
emit static_cast<Core*>(core)->fileTransferCancelled(file);
|
||||
tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
|
||||
return;
|
||||
}
|
||||
|
@ -276,6 +276,13 @@ void Core::sendFile(int32_t friendId, QString Filename, QByteArray data)
|
|||
emit fileSendStarted(&fileSendQueue.last());
|
||||
}
|
||||
|
||||
void Core::cancelFileSend(ToxFile* file)
|
||||
{
|
||||
file->status = ToxFile::STOPPED;
|
||||
emit fileTransferCancelled(file);
|
||||
tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
|
||||
}
|
||||
|
||||
void Core::removeFriend(int friendId)
|
||||
{
|
||||
if (tox_del_friend(tox, friendId) == -1) {
|
||||
|
@ -372,7 +379,7 @@ void Core::fileHeartbeat()
|
|||
{
|
||||
qWarning("Core::fileHeartbeat: Error getting preffered chunk size, aborting file send");
|
||||
file.status = ToxFile::STOPPED;
|
||||
emit fileTransferFinished(&file);
|
||||
emit fileTransferCancelled(&file);
|
||||
tox_file_send_control(tox, file.friendId, 0, file.fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
|
||||
return;
|
||||
}
|
||||
|
|
1
core.h
1
core.h
|
@ -195,6 +195,7 @@ public slots:
|
|||
void sendTyping(int friendId, bool typing);
|
||||
|
||||
void sendFile(int32_t friendId, QString Filename, QByteArray data);
|
||||
void cancelFileSend(ToxFile* file);
|
||||
|
||||
void setUsername(const QString& username);
|
||||
void setStatusMessage(const QString& message);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "filetransfertwidget.h"
|
||||
#include "widget.h"
|
||||
#include "core.h"
|
||||
|
||||
FileTransfertWidget::FileTransfertWidget(ToxFile *File)
|
||||
: file{File}, lastUpdate{QDateTime::currentDateTime()}, lastBytesSent{0}
|
||||
|
@ -33,6 +35,7 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
|
|||
progress->setFont(prettysmall);
|
||||
|
||||
topright->setIcon(QIcon("img/button icons/no_2x.png"));
|
||||
connect(topright, SIGNAL(clicked()), this, SLOT(cancelTransfer()));
|
||||
if (file->direction == ToxFile::SENDING)
|
||||
bottomright->setIcon(QIcon("img/button icons/pause_2x.png"));
|
||||
else
|
||||
|
@ -108,6 +111,7 @@ void FileTransfertWidget::onFileTransferCancelled(ToxFile* File)
|
|||
{
|
||||
if (File != file)
|
||||
return;
|
||||
disconnect(topright);
|
||||
progress->hide();
|
||||
speed->hide();
|
||||
eta->hide();
|
||||
|
@ -122,6 +126,7 @@ void FileTransfertWidget::onFileTransferFinished(ToxFile* File)
|
|||
{
|
||||
if (File != file)
|
||||
return;
|
||||
disconnect(topright);
|
||||
progress->hide();
|
||||
speed->hide();
|
||||
eta->hide();
|
||||
|
@ -133,3 +138,8 @@ void FileTransfertWidget::onFileTransferFinished(ToxFile* File)
|
|||
toxgreen.setColor(QPalette::Window, QColor(107,194,96)); // Tox Green
|
||||
setPalette(toxgreen);
|
||||
}
|
||||
|
||||
void FileTransfertWidget::cancelTransfer()
|
||||
{
|
||||
Widget::getInstance()->getCore()->cancelFileSend(file);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@ public slots:
|
|||
void onFileTransferCancelled(ToxFile* File);
|
||||
void onFileTransferFinished(ToxFile* File);
|
||||
|
||||
private slots:
|
||||
void cancelTransfer();
|
||||
|
||||
private:
|
||||
QString getHumanReadableSize(int size);
|
||||
|
||||
|
|
|
@ -374,7 +374,7 @@ void Widget::removeGroup(int groupId)
|
|||
onAddClicked();
|
||||
}
|
||||
|
||||
const Core* Widget::getCore()
|
||||
Core *Widget::getCore()
|
||||
{
|
||||
return core;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user