diff --git a/core.cpp b/core.cpp index ff2c16638..1b46832c3 100644 --- a/core.cpp +++ b/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)->fileTransferFinished(file); + emit static_cast(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)->fileTransferFinished(file); + emit static_cast(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; } diff --git a/core.h b/core.h index 84ab624d7..c43497250 100644 --- a/core.h +++ b/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); diff --git a/filetransfertwidget.cpp b/filetransfertwidget.cpp index 85ff62d9d..08fafe824 100644 --- a/filetransfertwidget.cpp +++ b/filetransfertwidget.cpp @@ -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); +} diff --git a/filetransfertwidget.h b/filetransfertwidget.h index b1d0ce1bf..868af6d6b 100644 --- a/filetransfertwidget.h +++ b/filetransfertwidget.h @@ -24,6 +24,9 @@ public slots: void onFileTransferCancelled(ToxFile* File); void onFileTransferFinished(ToxFile* File); +private slots: + void cancelTransfer(); + private: QString getHumanReadableSize(int size); diff --git a/widget.cpp b/widget.cpp index db88aa04f..0d13e2675 100644 --- a/widget.cpp +++ b/widget.cpp @@ -374,7 +374,7 @@ void Widget::removeGroup(int groupId) onAddClicked(); } -const Core* Widget::getCore() +Core *Widget::getCore() { return core; } diff --git a/widget.h b/widget.h index 2d6cd8b04..fe721a251 100644 --- a/widget.h +++ b/widget.h @@ -25,7 +25,7 @@ class Widget : public QWidget public: explicit Widget(QWidget *parent = 0); QString getUsername(); - const Core* getCore(); + Core* getCore(); static Widget* getInstance(); ~Widget();