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

Improve file sending

Improve the Widget, properly handle finished/cancelled tranfers
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-06-26 01:35:30 +02:00
parent ec69308efc
commit c18d63553d
3 changed files with 60 additions and 11 deletions

View File

@ -180,7 +180,10 @@ void ChatForm::onSliderRangeChanged()
void ChatForm::startFileSend(ToxFile *file) void ChatForm::startFileSend(ToxFile *file)
{ {
QLabel *author = new QLabel(Widget::getInstance()->getUsername()), *date = new QLabel(); if (file->friendId != f->friendId)
return;
QLabel *author = new QLabel(Widget::getInstance()->getUsername());
QLabel *date = new QLabel(QTime::currentTime().toString("mm:ss"));
QScrollBar* scroll = chatArea->verticalScrollBar(); QScrollBar* scroll = chatArea->verticalScrollBar();
lockSliderToBottom = scroll && scroll->value() == scroll->maximum(); lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
author->setAlignment(Qt::AlignTop | Qt::AlignRight); author->setAlignment(Qt::AlignTop | Qt::AlignRight);
@ -207,4 +210,6 @@ void ChatForm::startFileSend(ToxFile *file)
curRow++; curRow++;
connect(Widget::getInstance()->getCore(), &Core::fileTransferInfo, fileTrans, &FileTransfertWidget::onFileTransferInfo); connect(Widget::getInstance()->getCore(), &Core::fileTransferInfo, fileTrans, &FileTransfertWidget::onFileTransferInfo);
connect(Widget::getInstance()->getCore(), &Core::fileTransferCancelled, fileTrans, &FileTransfertWidget::onFileTransferCancelled);
connect(Widget::getInstance()->getCore(), &Core::fileTransferFinished, fileTrans, &FileTransfertWidget::onFileTransferFinished);
} }

View File

@ -161,7 +161,9 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
if (chunkSize == -1) if (chunkSize == -1)
{ {
qWarning("Core::onFileControlCallback: Error getting preffered chunk size, aborting file send"); qWarning("Core::onFileControlCallback: Error getting preffered chunk size, aborting file send");
// TODO: Warn the Friend* that we're aborting (emit) file->status = ToxFile::STOPPED;
emit static_cast<Core*>(core)->fileTransferFinished(file);
tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
return; return;
} }
chunkSize = std::min(chunkSize, file->fileData.size()); chunkSize = std::min(chunkSize, file->fileData.size());
@ -169,7 +171,9 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
if (tox_file_send_data(tox, friendnumber, filenumber, (uint8_t*)toSend.data(), toSend.size()) == -1) if (tox_file_send_data(tox, friendnumber, filenumber, (uint8_t*)toSend.data(), toSend.size()) == -1)
{ {
qWarning("Core::onFileControlCallback: Error sending first data chunk, aborting"); qWarning("Core::onFileControlCallback: Error sending first data chunk, aborting");
// TODO: Warn the Friend* that we're aborting (emit) file->status = ToxFile::STOPPED;
emit static_cast<Core*>(core)->fileTransferFinished(file);
tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
return; return;
} }
else else
@ -264,7 +268,6 @@ void Core::sendFile(int32_t friendId, QString Filename, QByteArray data)
if (fileNum == -1) if (fileNum == -1)
{ {
qWarning() << "Core::sendFile: Can't create the Tox file sender"; qWarning() << "Core::sendFile: Can't create the Tox file sender";
// TODO: Notify Widget (with the friendId), Widget will notify the chatForm
return; return;
} }
@ -369,7 +372,8 @@ 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;
// TODO: Warn the Friend* and the peer that we're aborting (emit and tox_control_...) emit fileTransferFinished(&file);
tox_file_send_control(tox, file.friendId, 0, file.fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
return; return;
} }
chunkSize = std::min(chunkSize, file.fileData.size()); chunkSize = std::min(chunkSize, file.fileData.size());
@ -387,7 +391,7 @@ void Core::fileHeartbeat()
qDebug("Core::fileHeartbeat: Transfer finished"); qDebug("Core::fileHeartbeat: Transfer finished");
tox_file_send_control(tox, file.friendId, 0, file.fileNum, TOX_FILECONTROL_FINISHED, nullptr, 0); tox_file_send_control(tox, file.friendId, 0, file.fileNum, TOX_FILECONTROL_FINISHED, nullptr, 0);
file.status = ToxFile::STOPPED; // TODO: Remove it from the list and return; file.status = ToxFile::STOPPED; // TODO: Remove it from the list and return;
// TODO: Notify the Friend* that we're done sending (emit) emit fileTransferFinished(&file);
} }
else else
qDebug() << QString("Core::fileHeartbeat: sent %1/%2 bytes").arg(file.bytesSent).arg(file.fileData.size()); qDebug() << QString("Core::fileHeartbeat: sent %1/%2 bytes").arg(file.bytesSent).arg(file.fileData.size());

View File

@ -11,12 +11,14 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
QFont prettysmall; QFont prettysmall;
prettysmall.setPixelSize(10); prettysmall.setPixelSize(10);
QPalette greybg; QPalette greybg;
greybg.setColor(QPalette::Window, Qt::gray); greybg.setColor(QPalette::Window, QColor(209,209,209));
greybg.setColor(QPalette::Base, QColor(150,150,150));
setPalette(greybg); setPalette(greybg);
setAutoFillBackground(true); setAutoFillBackground(true);
setFixedSize(250,50); setFixedSize(250,50);
setLayout(mainLayout); setLayout(mainLayout);
mainLayout->setMargin(0);
filename->setText(file->fileName); filename->setText(file->fileName);
filename->setFont(prettysmall); filename->setFont(prettysmall);
@ -27,6 +29,8 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
eta->setText("00:00"); eta->setText("00:00");
eta->setFont(prettysmall); eta->setFont(prettysmall);
progress->setValue(0); progress->setValue(0);
progress->setMinimumHeight(11);
progress->setFont(prettysmall);
topright->setIcon(QIcon("img/button icons/no_2x.png")); topright->setIcon(QIcon("img/button icons/no_2x.png"));
if (file->direction == ToxFile::SENDING) if (file->direction == ToxFile::SENDING)
@ -34,8 +38,18 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
else else
bottomright->setIcon(QIcon("img/button icons/yes_2x.png")); bottomright->setIcon(QIcon("img/button icons/yes_2x.png"));
topright->setIconSize(QSize(25,25)); QPalette toxgreen;
bottomright->setIconSize(QSize(25,25)); toxgreen.setColor(QPalette::Button, QColor(107,194,96)); // Tox Green
topright->setIconSize(QSize(10,10));
topright->setFixedSize(24,24);
topright->setFlat(true);
topright->setAutoFillBackground(true);
topright->setPalette(toxgreen);
bottomright->setIconSize(QSize(10,10));
bottomright->setFixedSize(24,24);
bottomright->setFlat(true);
bottomright->setAutoFillBackground(true);
bottomright->setPalette(toxgreen);
mainLayout->addWidget(pic); mainLayout->addWidget(pic);
mainLayout->addLayout(infoLayout); mainLayout->addLayout(infoLayout);
@ -44,12 +58,18 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
infoLayout->addWidget(filename); infoLayout->addWidget(filename);
infoLayout->addLayout(textLayout); infoLayout->addLayout(textLayout);
infoLayout->addWidget(progress); infoLayout->addWidget(progress);
infoLayout->setMargin(5);
textLayout->addWidget(size); textLayout->addWidget(size);
textLayout->addWidget(speed); textLayout->addWidget(speed);
textLayout->addWidget(eta); textLayout->addWidget(eta);
textLayout->setMargin(0); textLayout->setMargin(0);
textLayout->setSpacing(5); textLayout->setSpacing(5);
buttonLayout->addWidget(topright);
buttonLayout->addWidget(bottomright);
buttonLayout->setMargin(0);
buttonLayout->setSpacing(2);
} }
QString FileTransfertWidget::getHumanReadableSize(int size) QString FileTransfertWidget::getHumanReadableSize(int size)
@ -86,10 +106,30 @@ void FileTransfertWidget::onFileTransferInfo(ToxFile* File)
void FileTransfertWidget::onFileTransferCancelled(ToxFile* File) void FileTransfertWidget::onFileTransferCancelled(ToxFile* File)
{ {
if (File != file)
return;
progress->hide();
speed->hide();
eta->hide();
topright->hide();
bottomright->hide();
QPalette toxred;
toxred.setColor(QPalette::Window, QColor(200,78,78)); // Tox Red
setPalette(toxred);
} }
void FileTransfertWidget::onFileTransferFinished(ToxFile* File) void FileTransfertWidget::onFileTransferFinished(ToxFile* File)
{ {
if (File != file)
return;
progress->hide();
speed->hide();
eta->hide();
topright->setIcon(QIcon("img/button icons/yes_2x.png"));
buttonLayout->addStretch();
buttonLayout->setSpacing(0);
bottomright->hide();
QPalette toxgreen;
toxgreen.setColor(QPalette::Window, QColor(107,194,96)); // Tox Green
setPalette(toxgreen);
} }