Browse Source

Implement file send cancel

pull/2/head
Tux3 / Mlkj / !Lev.uXFMLA 12 years ago
parent
commit
b62700e6f6
  1. 13
      core.cpp
  2. 1
      core.h
  3. 10
      filetransfertwidget.cpp
  4. 3
      filetransfertwidget.h
  5. 2
      widget.cpp
  6. 2
      widget.h

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"); qWarning("Core::onFileControlCallback: Error getting preffered chunk size, aborting file send");
file->status = ToxFile::STOPPED; 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); tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
return; 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"); qWarning("Core::onFileControlCallback: Error sending first data chunk, aborting");
file->status = ToxFile::STOPPED; 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); tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
return; return;
} }
@ -276,6 +276,13 @@ void Core::sendFile(int32_t friendId, QString Filename, QByteArray data)
emit fileSendStarted(&fileSendQueue.last()); 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) void Core::removeFriend(int friendId)
{ {
if (tox_del_friend(tox, friendId) == -1) { 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"); qWarning("Core::fileHeartbeat: Error getting preffered chunk size, aborting file send");
file.status = ToxFile::STOPPED; 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); tox_file_send_control(tox, file.friendId, 0, file.fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
return; return;
} }

1
core.h

@ -195,6 +195,7 @@ public slots:
void sendTyping(int friendId, bool typing); void sendTyping(int friendId, bool typing);
void sendFile(int32_t friendId, QString Filename, QByteArray data); void sendFile(int32_t friendId, QString Filename, QByteArray data);
void cancelFileSend(ToxFile* file);
void setUsername(const QString& username); void setUsername(const QString& username);
void setStatusMessage(const QString& message); void setStatusMessage(const QString& message);

10
filetransfertwidget.cpp

@ -1,4 +1,6 @@
#include "filetransfertwidget.h" #include "filetransfertwidget.h"
#include "widget.h"
#include "core.h"
FileTransfertWidget::FileTransfertWidget(ToxFile *File) FileTransfertWidget::FileTransfertWidget(ToxFile *File)
: file{File}, lastUpdate{QDateTime::currentDateTime()}, lastBytesSent{0} : file{File}, lastUpdate{QDateTime::currentDateTime()}, lastBytesSent{0}
@ -33,6 +35,7 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
progress->setFont(prettysmall); progress->setFont(prettysmall);
topright->setIcon(QIcon("img/button icons/no_2x.png")); topright->setIcon(QIcon("img/button icons/no_2x.png"));
connect(topright, SIGNAL(clicked()), this, SLOT(cancelTransfer()));
if (file->direction == ToxFile::SENDING) if (file->direction == ToxFile::SENDING)
bottomright->setIcon(QIcon("img/button icons/pause_2x.png")); bottomright->setIcon(QIcon("img/button icons/pause_2x.png"));
else else
@ -108,6 +111,7 @@ void FileTransfertWidget::onFileTransferCancelled(ToxFile* File)
{ {
if (File != file) if (File != file)
return; return;
disconnect(topright);
progress->hide(); progress->hide();
speed->hide(); speed->hide();
eta->hide(); eta->hide();
@ -122,6 +126,7 @@ void FileTransfertWidget::onFileTransferFinished(ToxFile* File)
{ {
if (File != file) if (File != file)
return; return;
disconnect(topright);
progress->hide(); progress->hide();
speed->hide(); speed->hide();
eta->hide(); eta->hide();
@ -133,3 +138,8 @@ void FileTransfertWidget::onFileTransferFinished(ToxFile* File)
toxgreen.setColor(QPalette::Window, QColor(107,194,96)); // Tox Green toxgreen.setColor(QPalette::Window, QColor(107,194,96)); // Tox Green
setPalette(toxgreen); setPalette(toxgreen);
} }
void FileTransfertWidget::cancelTransfer()
{
Widget::getInstance()->getCore()->cancelFileSend(file);
}

3
filetransfertwidget.h

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

2
widget.cpp

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

2
widget.h

@ -25,7 +25,7 @@ class Widget : public QWidget
public: public:
explicit Widget(QWidget *parent = 0); explicit Widget(QWidget *parent = 0);
QString getUsername(); QString getUsername();
const Core* getCore(); Core* getCore();
static Widget* getInstance(); static Widget* getInstance();
~Widget(); ~Widget();

Loading…
Cancel
Save