1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

hooked up filetransferwidget

This commit is contained in:
krepa098 2014-11-17 16:05:14 +01:00
parent 1cf9fe3474
commit 27cb075dbb
12 changed files with 396 additions and 152 deletions

View File

@ -94,7 +94,14 @@
<file>translations/fr.qm</file> <file>translations/fr.qm</file>
<file>translations/ru.qm</file> <file>translations/ru.qm</file>
<file>ui/fileTransferWidget/fileTransferWidget.css</file> <file>ui/fileTransferWidget/fileTransferWidget.css</file>
<file>ui/fileTransferInstance/red.css</file>
<file>ui/fileTransferInstance/green.css</file>
<file>ui/fileTransferInstance/grey.css</file>
<file>ui/fileTransferInstance/yellow.css</file>
<file>ui/fileTransferInstance/background_red.png</file> <file>ui/fileTransferInstance/background_red.png</file>
<file>ui/fileTransferInstance/background_yellow.png</file>
<file>ui/fileTransferInstance/background_green.png</file>
<file>ui/fileTransferInstance/background_grey.png</file>
<file>ui/fileTransferInstance/pause_2x.png</file> <file>ui/fileTransferInstance/pause_2x.png</file>
<file>ui/fileTransferInstance/no_2x.png</file> <file>ui/fileTransferInstance/no_2x.png</file>
<file>ui/fileTransferInstance/yes_2x.png</file> <file>ui/fileTransferInstance/yes_2x.png</file>

View File

@ -18,6 +18,7 @@
#include "ui_filetransferwidget.h" #include "ui_filetransferwidget.h"
#include "src/core.h" #include "src/core.h"
#include "src/misc/style.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug> #include <QDebug>
@ -26,15 +27,28 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::FileTransferWidget) , ui(new Ui::FileTransferWidget)
, fileInfo(file) , fileInfo(file)
, lastTick(QTime::currentTime())
{ {
ui->setupUi(this); ui->setupUi(this);
ui->filenameLabel->setText(file.fileName); ui->filenameLabel->setText(file.fileName);
ui->progressBar->setValue(0); ui->progressBar->setValue(0);
ui->fileSizeLabel->setText(getHumanReadableSize(file.filesize));
ui->progressLabel->setText("0%");
ui->etaLabel->setText("--:--");
setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/grey.css"));
Style::repolish(this);
connect(Core::getInstance(), &Core::fileTransferInfo, this, &FileTransferWidget::onFileTransferInfo); connect(Core::getInstance(), &Core::fileTransferInfo, this, &FileTransferWidget::onFileTransferInfo);
connect(Core::getInstance(), &Core::fileTransferAccepted, this, &FileTransferWidget::onFileTransferAccepted);
connect(Core::getInstance(), &Core::fileTransferCancelled, this, &FileTransferWidget::onFileTransferCancelled);
connect(Core::getInstance(), &Core::fileTransferPaused, this, &FileTransferWidget::onFileTransferPaused);
connect(Core::getInstance(), &Core::fileTransferFinished, this, &FileTransferWidget::onFileTransferFinished);
setFixedHeight(100); setupButtons();
setFixedHeight(85);
} }
FileTransferWidget::~FileTransferWidget() FileTransferWidget::~FileTransferWidget()
@ -42,12 +56,176 @@ FileTransferWidget::~FileTransferWidget()
delete ui; delete ui;
} }
void FileTransferWidget::onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction) void FileTransferWidget::onFileTransferInfo(ToxFile file)
{ {
if(FileNum != fileInfo.fileNum) if(fileInfo != file)
return; return;
fileInfo = file;
// update progress // update progress
qreal progress = static_cast<qreal>(Filesize)/static_cast<qreal>(BytesSent); qreal progress = static_cast<qreal>(file.bytesSent) / static_cast<qreal>(file.filesize);
ui->progressBar->setValue(static_cast<int>(progress * 100.0)); ui->progressBar->setValue(static_cast<int>(progress * 100.0));
// eta, speed
QTime now = QTime::currentTime();
qreal deltaSecs = lastTick.msecsTo(now) / 1000.0;
if(deltaSecs >= 1.0)
{
qint64 deltaBytes = file.bytesSent - lastBytesSent;
qint64 bytesPerSec = static_cast<int>(static_cast<qreal>(deltaBytes) / deltaSecs);
if(bytesPerSec > 0)
{
QTime toGo(0,0,file.filesize / bytesPerSec);
ui->etaLabel->setText(toGo.toString("mm:ss"));
}
else
{
ui->etaLabel->setText("--:--");
}
ui->progressLabel->setText(getHumanReadableSize(bytesPerSec) + "/s");
lastTick = now;
lastBytesSent = file.bytesSent;
}
setupButtons();
repaint();
}
void FileTransferWidget::onFileTransferAccepted(ToxFile file)
{
if(fileInfo != file)
return;
fileInfo = file;
setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/yellow.css"));
Style::repolish(this);
setupButtons();
}
void FileTransferWidget::onFileTransferCancelled(ToxFile file)
{
if(fileInfo != file)
return;
fileInfo = file;
setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/red.css"));
Style::repolish(this);
setupButtons();
hideWidgets();
disconnect(Core::getInstance());
}
void FileTransferWidget::onFileTransferPaused(ToxFile file)
{
if(fileInfo != file)
return;
fileInfo = file;
setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/grey.css"));
Style::repolish(this);
setupButtons();
}
void FileTransferWidget::onFileTransferFinished(ToxFile file)
{
if(fileInfo != file)
return;
fileInfo = file;
setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/green.css"));
Style::repolish(this);
setupButtons();
hideWidgets();
disconnect(Core::getInstance());
}
QString FileTransferWidget::getHumanReadableSize(qint64 size)
{
static const char* suffix[] = {"B","kiB","MiB","GiB","TiB"};
int exp = 0;
if (size > 0)
exp = std::min( (int) (log(size) / log(1024)), (int) (sizeof(suffix) / sizeof(suffix[0]) - 1));
return QString().setNum(size / pow(1024, exp),'f',2).append(suffix[exp]);
}
void FileTransferWidget::hideWidgets()
{
ui->buttonWidget->hide();
ui->progressBar->hide();
ui->progressLabel->hide();
ui->etaLabel->hide();
}
void FileTransferWidget::setupButtons()
{
switch(fileInfo.status)
{
case ToxFile::TRANSMITTING:
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/no_2x.png"));
ui->topButton->setObjectName("cancel");
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/pause_2x.png"));
ui->bottomButton->setObjectName("pause");
break;
case ToxFile::PAUSED:
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/no_2x.png"));
ui->topButton->setObjectName("cancel");
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/arrow_white_2x.png"));
ui->bottomButton->setObjectName("resume");
break;
case ToxFile::STOPPED:
case ToxFile::BROKEN: //TODO: ?
break;
}
}
void FileTransferWidget::handleButton(QPushButton *btn)
{
if(fileInfo.direction == ToxFile::SENDING)
{
if(btn->objectName() == "cancel")
Core::getInstance()->cancelFileSend(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "pause")
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
}
else
{
if(btn->objectName() == "cancel")
Core::getInstance()->cancelFileRecv(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "pause")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
}
}
void FileTransferWidget::on_topButton_clicked()
{
handleButton(ui->topButton);
}
void FileTransferWidget::on_bottomButton_clicked()
{
handleButton(ui->bottomButton);
} }

View File

@ -18,6 +18,7 @@
#define FILETRANSFERWIDGET_H #define FILETRANSFERWIDGET_H
#include <QWidget> #include <QWidget>
#include <QTime>
#include "../chatlinecontent.h" #include "../chatlinecontent.h"
#include "../../corestructs.h" #include "../../corestructs.h"
@ -25,6 +26,8 @@ namespace Ui {
class FileTransferWidget; class FileTransferWidget;
} }
class QPushButton;
class FileTransferWidget : public QWidget class FileTransferWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -34,11 +37,27 @@ public:
virtual ~FileTransferWidget(); virtual ~FileTransferWidget();
protected slots: protected slots:
void onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction); void onFileTransferInfo(ToxFile file);
void onFileTransferAccepted(ToxFile file);
void onFileTransferCancelled(ToxFile file);
void onFileTransferPaused(ToxFile file);
void onFileTransferFinished(ToxFile file);
protected:
QString getHumanReadableSize(qint64 size);
void hideWidgets();
void setupButtons();
void handleButton(QPushButton* btn);
private slots:
void on_topButton_clicked();
void on_bottomButton_clicked();
private: private:
Ui::FileTransferWidget *ui; Ui::FileTransferWidget *ui;
ToxFile fileInfo; ToxFile fileInfo;
QTime lastTick;
qint64 lastBytesSent = 0;
}; };

View File

@ -6,35 +6,29 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>619</width> <width>544</width>
<height>86</height> <height>207</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color:transparent;</string> <string notr="true">#FileTransferWidget {
background-color:transparent;
}</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QFrame" name="frame_3"> <widget class="QFrame" name="frame_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QFrame { <string notr="true"/>
border-image: url(:/ui/fileTransferInstance/background_red.png);
border-left:25;padding-top:-30;
border-top:28;
border-right:25; padding-right:-28;
border-bottom:28;padding-bottom:-30;
color:white;
}
QPushButton {
margin:0;
}</string>
</property> </property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
@ -45,70 +39,89 @@ QPushButton {
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="topMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item> <item>
<widget class="QLabel" name="filenameLabel"> <widget class="QLabel" name="filenameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Filename</string> <string>Filename</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QWidget" name="statusWidget" native="true">
<item> <layout class="QHBoxLayout" name="_2">
<widget class="QLabel" name="label"> <property name="spacing">
<property name="text"> <number>0</number>
<string>10Mb</string> </property>
</property> <property name="leftMargin">
<property name="alignment"> <number>0</number>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> </property>
</property> <property name="topMargin">
</widget> <number>0</number>
</item> </property>
<item> <property name="rightMargin">
<widget class="QLabel" name="label_2"> <number>0</number>
<property name="text"> </property>
<string>24%</string> <property name="bottomMargin">
</property> <number>0</number>
<property name="alignment"> </property>
<set>Qt::AlignCenter</set> <item>
</property> <widget class="QLabel" name="fileSizeLabel">
</widget> <property name="text">
</item> <string>10Mb</string>
<item> </property>
<widget class="QLabel" name="progressLabel"> <property name="alignment">
<property name="text"> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
<string>ETA:10:10</string> </property>
</property> </widget>
<property name="alignment"> </item>
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <item>
</property> <widget class="QLabel" name="progressLabel">
</widget> <property name="text">
</item> <string>24%</string>
</layout> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="etaLabel">
<property name="text">
<string>ETA:10:10</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item> </item>
<item> <item>
<widget class="QProgressBar" name="progressBar"> <widget class="QProgressBar" name="progressBar">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>16777215</width>
<height>14</height> <height>10</height>
</size> </size>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QProgressBar { <string notr="true"/>
border: 2px solid black;
border-radius: 0px;
color: white;
background-color:white;
}
QProgressBar::chunk {
background-color: black;
width: 20px;
}</string>
</property> </property>
<property name="value"> <property name="value">
<number>24</number> <number>24</number>
@ -140,64 +153,78 @@ QProgressBar::chunk {
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <widget class="QWidget" name="buttonWidget" native="true">
<property name="spacing"> <layout class="QVBoxLayout" name="verticalLayout">
<number>0</number> <property name="spacing">
</property> <number>0</number>
<item> </property>
<widget class="QPushButton" name="pushButton"> <property name="leftMargin">
<property name="text"> <number>0</number>
<string/> </property>
</property> <property name="topMargin">
<property name="icon"> <number>0</number>
<iconset resource="../../../res.qrc"> </property>
<normaloff>:/ui/fileTransferInstance/pause_2x.png</normaloff>:/ui/fileTransferInstance/pause_2x.png</iconset> <property name="rightMargin">
</property> <number>0</number>
<property name="iconSize"> </property>
<size> <property name="bottomMargin">
<width>25</width> <number>0</number>
<height>28</height> </property>
</size> <item>
</property> <widget class="QPushButton" name="topButton">
<property name="flat"> <property name="text">
<bool>true</bool> <string/>
</property> </property>
</widget> <property name="icon">
</item> <iconset resource="../../../res.qrc">
<item> <normaloff>:/ui/fileTransferInstance/pause_2x.png</normaloff>:/ui/fileTransferInstance/pause_2x.png</iconset>
<spacer name="verticalSpacer"> </property>
<property name="orientation"> <property name="iconSize">
<enum>Qt::Vertical</enum> <size>
</property> <width>25</width>
<property name="sizeHint" stdset="0"> <height>28</height>
<size> </size>
<width>20</width> </property>
<height>40</height> <property name="flat">
</size> <bool>true</bool>
</property> </property>
</spacer> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_2"> <spacer name="verticalSpacer">
<property name="text"> <property name="orientation">
<string/> <enum>Qt::Vertical</enum>
</property> </property>
<property name="icon"> <property name="sizeHint" stdset="0">
<iconset resource="../../../res.qrc"> <size>
<normaloff>:/ui/fileTransferInstance/arrow_white_2x.png</normaloff>:/ui/fileTransferInstance/arrow_white_2x.png</iconset> <width>20</width>
</property> <height>92</height>
<property name="iconSize"> </size>
<size> </property>
<width>25</width> </spacer>
<height>28</height> </item>
</size> <item>
</property> <widget class="QPushButton" name="bottomButton">
<property name="flat"> <property name="text">
<bool>true</bool> <string/>
</property> </property>
</widget> <property name="icon">
</item> <iconset resource="../../../res.qrc">
</layout> <normaloff>:/ui/fileTransferInstance/arrow_white_2x.png</normaloff>:/ui/fileTransferInstance/arrow_white_2x.png</iconset>
</property>
<property name="iconSize">
<size>
<width>25</width>
<height>28</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -567,7 +567,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
qDebug() << QString("Core::onFileControlCallback: Transfer of file %1 cancelled by friend %2") qDebug() << QString("Core::onFileControlCallback: Transfer of file %1 cancelled by friend %2")
.arg(file->fileNum).arg(file->friendId); .arg(file->fileNum).arg(file->friendId);
file->status = ToxFile::STOPPED; file->status = ToxFile::STOPPED;
emit static_cast<Core*>(core)->fileTransferCancelled(file->friendId, file->fileNum, ToxFile::SENDING); emit static_cast<Core*>(core)->fileTransferCancelled(*file);
// Wait for sendAllFileData to return before deleting the ToxFile, we MUST ensure this or we'll use after free // Wait for sendAllFileData to return before deleting the ToxFile, we MUST ensure this or we'll use after free
if (file->sendTimer) if (file->sendTimer)
{ {
@ -594,7 +594,7 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
qDebug() << QString("Core::onFileControlCallback: Transfer of file %1 cancelled by friend %2") qDebug() << QString("Core::onFileControlCallback: Transfer of file %1 cancelled by friend %2")
.arg(file->fileNum).arg(file->friendId); .arg(file->fileNum).arg(file->friendId);
file->status = ToxFile::STOPPED; file->status = ToxFile::STOPPED;
emit static_cast<Core*>(core)->fileTransferCancelled(file->friendId, file->fileNum, ToxFile::RECEIVING); emit static_cast<Core*>(core)->fileTransferCancelled(*file);
removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum); removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum);
} }
else if (receive_send == 0 && control_type == TOX_FILECONTROL_FINISHED) else if (receive_send == 0 && control_type == TOX_FILECONTROL_FINISHED)
@ -669,8 +669,7 @@ void Core::onFileDataCallback(Tox*, int32_t friendnumber, uint8_t filenumber, co
file->file->write((char*)data,length); file->file->write((char*)data,length);
file->bytesSent += length; file->bytesSent += length;
//qDebug() << QString("Core::onFileDataCallback: received %1/%2 bytes").arg(file->bytesSent).arg(file->filesize); //qDebug() << QString("Core::onFileDataCallback: received %1/%2 bytes").arg(file->bytesSent).arg(file->filesize);
emit static_cast<Core*>(core)->fileTransferInfo(file->friendId, file->fileNum, emit static_cast<Core*>(core)->fileTransferInfo(*file);
file->filesize, file->bytesSent, ToxFile::RECEIVING);
} }
void Core::onAvatarInfoCallback(Tox*, int32_t friendnumber, uint8_t format, void Core::onAvatarInfoCallback(Tox*, int32_t friendnumber, uint8_t format,
@ -852,7 +851,7 @@ void Core::pauseResumeFileSend(int friendId, int fileNum)
if (file->status == ToxFile::TRANSMITTING) if (file->status == ToxFile::TRANSMITTING)
{ {
file->status = ToxFile::PAUSED; file->status = ToxFile::PAUSED;
emit fileTransferPaused(file->friendId, file->fileNum, ToxFile::SENDING); emit fileTransferPaused(*file);
tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_PAUSE, nullptr, 0); tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_PAUSE, nullptr, 0);
} }
else if (file->status == ToxFile::PAUSED) else if (file->status == ToxFile::PAUSED)
@ -884,7 +883,7 @@ void Core::pauseResumeFileRecv(int friendId, int fileNum)
if (file->status == ToxFile::TRANSMITTING) if (file->status == ToxFile::TRANSMITTING)
{ {
file->status = ToxFile::PAUSED; file->status = ToxFile::PAUSED;
emit fileTransferPaused(file->friendId, file->fileNum, ToxFile::RECEIVING); emit fileTransferPaused(*file);
tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_PAUSE, nullptr, 0); tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_PAUSE, nullptr, 0);
} }
else if (file->status == ToxFile::PAUSED) else if (file->status == ToxFile::PAUSED)
@ -914,7 +913,7 @@ void Core::cancelFileSend(int friendId, int fileNum)
return; return;
} }
file->status = ToxFile::STOPPED; file->status = ToxFile::STOPPED;
emit fileTransferCancelled(file->friendId, file->fileNum, ToxFile::SENDING); 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);
while (file->sendTimer) QThread::msleep(1); // Wait until sendAllFileData returns before deleting while (file->sendTimer) QThread::msleep(1); // Wait until sendAllFileData returns before deleting
removeFileFromQueue(true, friendId, fileNum); removeFileFromQueue(true, friendId, fileNum);
@ -937,7 +936,7 @@ void Core::cancelFileRecv(int friendId, int fileNum)
return; return;
} }
file->status = ToxFile::STOPPED; file->status = ToxFile::STOPPED;
emit fileTransferCancelled(file->friendId, file->fileNum, ToxFile::RECEIVING); emit fileTransferCancelled(*file);
tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
removeFileFromQueue(true, friendId, fileNum); removeFileFromQueue(true, friendId, fileNum);
} }
@ -959,7 +958,7 @@ void Core::rejectFileRecvRequest(int friendId, int fileNum)
return; return;
} }
file->status = ToxFile::STOPPED; file->status = ToxFile::STOPPED;
emit fileTransferCancelled(file->friendId, file->fileNum, ToxFile::SENDING); emit fileTransferCancelled(*file);
tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
removeFileFromQueue(false, friendId, fileNum); removeFileFromQueue(false, friendId, fileNum);
} }
@ -1557,14 +1556,14 @@ void Core::sendAllFileData(Core *core, ToxFile* file)
file->sendTimer = nullptr; file->sendTimer = nullptr;
return; return;
} }
emit core->fileTransferInfo(file->friendId, file->fileNum, file->filesize, file->bytesSent, ToxFile::SENDING); emit core->fileTransferInfo(*file);
// qApp->processEvents(); // qApp->processEvents();
long long chunkSize = tox_file_data_size(core->tox, file->friendId); long long chunkSize = tox_file_data_size(core->tox, file->friendId);
if (chunkSize == -1) if (chunkSize == -1)
{ {
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 core->fileTransferCancelled(file->friendId, file->fileNum, ToxFile::SENDING); emit core->fileTransferCancelled(*file);
tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
removeFileFromQueue(true, file->friendId, file->fileNum); removeFileFromQueue(true, file->friendId, file->fileNum);
return; return;
@ -1579,7 +1578,7 @@ void Core::sendAllFileData(Core *core, ToxFile* file)
qWarning() << QString("Core::sendAllFileData: Error reading from file: %1").arg(file->file->errorString()); qWarning() << QString("Core::sendAllFileData: Error reading from file: %1").arg(file->file->errorString());
delete[] data; delete[] data;
file->status = ToxFile::STOPPED; file->status = ToxFile::STOPPED;
emit core->fileTransferCancelled(file->friendId, file->fileNum, ToxFile::SENDING); emit core->fileTransferCancelled(*file);
tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
removeFileFromQueue(true, file->friendId, file->fileNum); removeFileFromQueue(true, file->friendId, file->fileNum);
return; return;
@ -1589,7 +1588,7 @@ void Core::sendAllFileData(Core *core, ToxFile* file)
qWarning() << QString("Core::sendAllFileData: Nothing to read from file: %1").arg(file->file->errorString()); qWarning() << QString("Core::sendAllFileData: Nothing to read from file: %1").arg(file->file->errorString());
delete[] data; delete[] data;
file->status = ToxFile::STOPPED; file->status = ToxFile::STOPPED;
emit core->fileTransferCancelled(file->friendId, file->fileNum, ToxFile::SENDING); emit core->fileTransferCancelled(*file);
tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0); tox_file_send_control(core->tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
removeFileFromQueue(true, file->friendId, file->fileNum); removeFileFromQueue(true, file->friendId, file->fileNum);
return; return;

View File

@ -173,12 +173,12 @@ signals:
void fileSendStarted(ToxFile file); void fileSendStarted(ToxFile file);
void fileReceiveRequested(ToxFile file); void fileReceiveRequested(ToxFile file);
void fileTransferAccepted(ToxFile file); void fileTransferAccepted(ToxFile file);
void fileTransferCancelled(int FriendId, int FileNum, ToxFile::FileDirection direction); void fileTransferCancelled(ToxFile file);
void fileTransferFinished(ToxFile file); void fileTransferFinished(ToxFile file);
void fileUploadFinished(const QString& path); void fileUploadFinished(const QString& path);
void fileDownloadFinished(const QString& path); void fileDownloadFinished(const QString& path);
void fileTransferPaused(int FriendId, int FileNum, ToxFile::FileDirection direction); void fileTransferPaused(ToxFile file);
void fileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction); void fileTransferInfo(ToxFile file);
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused); void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
void fileTransferBrokenUnbroken(ToxFile file, bool broken); void fileTransferBrokenUnbroken(ToxFile file, bool broken);

View File

@ -12,6 +12,16 @@ ToxFile::ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePat
{ {
} }
bool ToxFile::operator==(const ToxFile &other) const
{
return fileNum == other.fileNum && friendId && other.friendId;
}
bool ToxFile::operator!=(const ToxFile &other) const
{
return !(*this == other);
}
void ToxFile::setFilePath(QString path) void ToxFile::setFilePath(QString path)
{ {
filePath=path; filePath=path;

View File

@ -57,6 +57,10 @@ struct ToxFile
ToxFile()=default; ToxFile()=default;
ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePath, FileDirection Direction); ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePath, FileDirection Direction);
~ToxFile(){} ~ToxFile(){}
bool operator==(const ToxFile& other) const;
bool operator!=(const ToxFile& other) const;
void setFilePath(QString path); void setFilePath(QString path);
bool open(bool write); bool open(bool write);
@ -65,8 +69,8 @@ struct ToxFile
QByteArray fileName; QByteArray fileName;
QString filePath; QString filePath;
QFile* file; QFile* file;
long long bytesSent; qint64 bytesSent;
long long filesize; qint64 filesize;
FileStatus status; FileStatus status;
FileDirection direction; FileDirection direction;
QTimer* sendTimer; QTimer* sendTimer;

View File

@ -197,13 +197,13 @@ void ChatForm::onFileRecvRequest(ToxFile file)
FileTransferInstance* fileTrans = new FileTransferInstance(file); FileTransferInstance* fileTrans = new FileTransferInstance(file);
ftransWidgets.insert(fileTrans->getId(), fileTrans); ftransWidgets.insert(fileTrans->getId(), fileTrans);
connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo); // connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled); // connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished); // connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile))); // connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile)));
connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection))); // connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection)));
connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool))); // connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool)));
connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool))); // connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool)));
Widget* w = Widget::getInstance(); Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow()) if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())

Binary file not shown.

After

Width:  |  Height:  |  Size: 495 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 495 B