1
0
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:
Tux3 / Mlkj / !Lev.uXFMLA 2014-06-26 01:48:20 +02:00
parent c18d63553d
commit b62700e6f6
6 changed files with 26 additions and 5 deletions

View File

@ -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
View File

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

View File

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

View File

@ -24,6 +24,9 @@ public slots:
void onFileTransferCancelled(ToxFile* File);
void onFileTransferFinished(ToxFile* File);
private slots:
void cancelTransfer();
private:
QString getHumanReadableSize(int size);

View File

@ -374,7 +374,7 @@ void Widget::removeGroup(int groupId)
onAddClicked();
}
const Core* Widget::getCore()
Core *Widget::getCore()
{
return core;
}

View File

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