qTox/src/chatlog/content/filetransferwidget.cpp

560 lines
18 KiB
C++
Raw Normal View History

2014-11-16 19:58:43 +08:00
/*
Copyright © 2014-2019 by The qTox Project Contributors
2014-11-16 19:58:43 +08:00
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
2014-11-16 19:58:43 +08:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
2014-11-16 19:58:43 +08:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2014-11-16 19:58:43 +08:00
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
2014-11-16 19:58:43 +08:00
*/
2014-11-12 21:11:25 +08:00
#include "filetransferwidget.h"
#include "ui_filetransferwidget.h"
#include "src/core/corefile.h"
#include "src/persistence/settings.h"
#include "src/widget/gui.h"
#include "src/widget/style.h"
#include "src/widget/widget.h"
#include "src/model/exiftransform.h"
#include <QBuffer>
#include <QDebug>
#include <QDesktopServices>
2015-03-01 00:14:58 +08:00
#include <QDesktopWidget>
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
#include <QVariantAnimation>
2014-11-12 21:11:25 +08:00
#include <cassert>
2015-02-18 14:02:09 +08:00
#include <math.h>
// The leftButton is used to accept, pause, or resume a file transfer, as well as to open a
// received file.
// The rightButton is used to cancel a file transfer, or to open the directory a file was
// downloaded to.
FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file)
: QWidget(parent)
, coreFile{_coreFile}
2014-11-17 03:01:37 +08:00
, ui(new Ui::FileTransferWidget)
, fileInfo(file)
2019-03-23 20:58:44 +08:00
, backgroundColor(Style::getColor(Style::TransferMiddle))
, buttonColor(Style::getColor(Style::TransferWait))
2019-02-23 00:01:43 +08:00
, buttonBackgroundColor(Style::getColor(Style::GroundBase))
, active(true)
2014-11-12 21:11:25 +08:00
{
ui->setupUi(this);
2014-11-18 03:08:55 +08:00
// hide the QWidget background (background-color: transparent doesn't seem to work)
setAttribute(Qt::WA_TranslucentBackground, true);
ui->previewButton->hide();
2014-11-17 03:01:37 +08:00
ui->filenameLabel->setText(file.fileName);
ui->progressBar->setValue(0);
ui->fileSizeLabel->setText(getHumanReadableSize(file.progress.getFileSize()));
2015-01-18 01:17:40 +08:00
ui->etaLabel->setText("");
2014-11-17 23:05:14 +08:00
2015-02-13 23:46:59 +08:00
backgroundColorAnimation = new QVariantAnimation(this);
backgroundColorAnimation->setDuration(500);
backgroundColorAnimation->setEasingCurve(QEasingCurve::OutCubic);
connect(backgroundColorAnimation, &QVariantAnimation::valueChanged, this,
[this](const QVariant& val) {
backgroundColor = val.value<QColor>();
update();
});
2015-02-05 00:21:56 +08:00
2015-02-14 19:14:09 +08:00
buttonColorAnimation = new QVariantAnimation(this);
buttonColorAnimation->setDuration(500);
buttonColorAnimation->setEasingCurve(QEasingCurve::OutCubic);
connect(buttonColorAnimation, &QVariantAnimation::valueChanged, this, [this](const QVariant& val) {
buttonColor = val.value<QColor>();
update();
});
2017-06-01 15:50:59 +08:00
connect(ui->leftButton, &QPushButton::clicked, this, &FileTransferWidget::onLeftButtonClicked);
connect(ui->rightButton, &QPushButton::clicked, this, &FileTransferWidget::onRightButtonClicked);
connect(ui->previewButton, &QPushButton::clicked, this,
&FileTransferWidget::onPreviewButtonClicked);
2014-11-17 23:05:14 +08:00
connect(&GUI::getInstance(), &GUI::themeReload, this, &FileTransferWidget::reloadTheme);
// Set lastStatus to anything but the file's current value, this forces an update
lastStatus = file.status == ToxFile::FINISHED ? ToxFile::INITIALIZING : ToxFile::FINISHED;
updateWidget(file);
2014-11-17 03:01:37 +08:00
setFixedHeight(64);
2014-11-12 21:11:25 +08:00
}
FileTransferWidget::~FileTransferWidget()
{
delete ui;
}
// TODO(sudden6): remove file IO from the UI
/**
* @brief Dangerous way to find out if a path is writable.
* @param filepath Path to file which should be deleted.
* @return True, if file writeable, false otherwise.
*/
bool FileTransferWidget::tryRemoveFile(const QString& filepath)
{
QFile tmp(filepath);
bool writable = tmp.open(QIODevice::WriteOnly);
tmp.remove();
return writable;
}
refactor(chatform): Remove message handling logic from gui path Functional changes * Offline messages are still sent when the chat log is cleared * Spinner now does not wait for history to be complete, just a receipt from our friend * Export chat and load chat history are now available in group chats * Merged save chat log and export chat log * Note that we lost the info messages in the process NonFunctional Changes * FileTransferWidget slots only called for correct file * Settings::getEnableGroupChatsColor now embedded in GenericChatForm::colorizeNames * Settings::setEnableGroupChatscolor now emits signal connected to GenericChatForm::setColorizedNames to keep state in sync * Chatlog history not reloaded on setPassword() * I am pretty sure this had no purpose * Removed a lot of responsibility from ChatForm * History moved to ChatHistory implementation of IChatLog * OfflineMsgEngine moved to FriendMessageDispatcher * Export chat and load chat history moved to GenericChatLog * Backed by IChatLog so can be used generically * Message processing moved to FriendMessageDispatcher * The action of sending files to coreFile is still handled by ChatForm, but displaying of the sent messages is done through IChatLog -> GenericChatForm * Search moved to ChatHistory/SessionChatLog * All insertion of chat log elements should be handled by GenericChatForm now * Removed overlapping responsibilities from GroupChatForm * Search and message sending goes through ichatlog/messagedispatcher too * Lots of search functionality pushed down into IChatLog * Some of the file logic was moved into Widget. This is mostly to avoid scope increase of this PR even further. * History APIs removed that were no longer used
2019-05-26 08:11:44 +08:00
void FileTransferWidget::onFileTransferUpdate(ToxFile file)
2014-12-14 04:11:03 +08:00
{
refactor(chatform): Remove message handling logic from gui path Functional changes * Offline messages are still sent when the chat log is cleared * Spinner now does not wait for history to be complete, just a receipt from our friend * Export chat and load chat history are now available in group chats * Merged save chat log and export chat log * Note that we lost the info messages in the process NonFunctional Changes * FileTransferWidget slots only called for correct file * Settings::getEnableGroupChatsColor now embedded in GenericChatForm::colorizeNames * Settings::setEnableGroupChatscolor now emits signal connected to GenericChatForm::setColorizedNames to keep state in sync * Chatlog history not reloaded on setPassword() * I am pretty sure this had no purpose * Removed a lot of responsibility from ChatForm * History moved to ChatHistory implementation of IChatLog * OfflineMsgEngine moved to FriendMessageDispatcher * Export chat and load chat history moved to GenericChatLog * Backed by IChatLog so can be used generically * Message processing moved to FriendMessageDispatcher * The action of sending files to coreFile is still handled by ChatForm, but displaying of the sent messages is done through IChatLog -> GenericChatForm * Search moved to ChatHistory/SessionChatLog * All insertion of chat log elements should be handled by GenericChatForm now * Removed overlapping responsibilities from GroupChatForm * Search and message sending goes through ichatlog/messagedispatcher too * Lots of search functionality pushed down into IChatLog * Some of the file logic was moved into Widget. This is mostly to avoid scope increase of this PR even further. * History APIs removed that were no longer used
2019-05-26 08:11:44 +08:00
updateWidget(file);
2015-01-11 18:57:33 +08:00
}
2014-12-14 04:11:03 +08:00
bool FileTransferWidget::isActive() const
{
return active;
}
void FileTransferWidget::acceptTransfer(const QString& filepath)
2015-01-11 18:57:33 +08:00
{
if (filepath.isEmpty()) {
return;
}
// test if writable
if (!tryRemoveFile(filepath)) {
2016-01-04 19:02:37 +08:00
GUI::showWarning(tr("Location not writable", "Title of permissions popup"),
tr("You do not have permission to write that location. Choose another, or "
"cancel the save dialog.",
"text of permissions popup"));
2014-12-14 04:11:03 +08:00
return;
}
// everything ok!
coreFile.acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, filepath);
2015-01-11 18:57:33 +08:00
}
void FileTransferWidget::setBackgroundColor(const QColor& c, bool whiteFont)
{
if (c != backgroundColor) {
2015-02-13 23:46:59 +08:00
backgroundColorAnimation->setStartValue(backgroundColor);
backgroundColorAnimation->setEndValue(c);
backgroundColorAnimation->start();
}
2015-02-05 00:21:56 +08:00
setProperty("fontColor", whiteFont ? "white" : "black");
setStyleSheet(Style::getStylesheet("fileTransferInstance/filetransferWidget.css"));
Style::repolish(this);
update();
}
void FileTransferWidget::setButtonColor(const QColor& c)
2015-02-14 19:14:09 +08:00
{
if (c != buttonColor) {
2015-02-14 19:14:09 +08:00
buttonColorAnimation->setStartValue(buttonColor);
buttonColorAnimation->setEndValue(c);
buttonColorAnimation->start();
}
}
bool FileTransferWidget::drawButtonAreaNeeded() const
{
return (ui->rightButton->isVisible() || ui->leftButton->isVisible())
&& !(ui->leftButton->isVisible() && ui->leftButton->objectName() == "ok");
2015-02-14 19:14:09 +08:00
}
void FileTransferWidget::paintEvent(QPaintEvent*)
{
// required by Hi-DPI support as border-image doesn't work.
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
2015-02-13 23:46:59 +08:00
qreal ratio = static_cast<qreal>(geometry().height()) / static_cast<qreal>(geometry().width());
2015-02-14 19:14:09 +08:00
const int r = 24;
const int buttonFieldWidth = 32;
2015-02-14 19:21:03 +08:00
const int lineWidth = 1;
2015-02-13 23:46:59 +08:00
// Draw the widget background:
painter.setClipRect(QRect(0, 0, width(), height()));
painter.setBrush(QBrush(backgroundColor));
painter.drawRoundedRect(geometry(), r * ratio, r, Qt::RelativeSize);
2015-02-13 23:46:59 +08:00
if (drawButtonAreaNeeded()) {
// Draw the button background:
QPainterPath buttonBackground;
buttonBackground.addRoundedRect(width() - 2 * buttonFieldWidth - lineWidth * 2, 0,
buttonFieldWidth, buttonFieldWidth + lineWidth, 50, 50,
Qt::RelativeSize);
2017-06-01 15:50:59 +08:00
buttonBackground.addRect(width() - 2 * buttonFieldWidth - lineWidth * 2, 0,
buttonFieldWidth * 2, buttonFieldWidth / 2);
buttonBackground.addRect(width() - 1.5 * buttonFieldWidth - lineWidth * 2, 0,
buttonFieldWidth * 2, buttonFieldWidth + 1);
buttonBackground.setFillRule(Qt::WindingFill);
painter.setBrush(QBrush(buttonBackgroundColor));
painter.drawPath(buttonBackground);
// Draw the left button:
QPainterPath leftButton;
leftButton.addRoundedRect(QRect(width() - 2 * buttonFieldWidth - lineWidth, 0,
2017-06-01 15:50:59 +08:00
buttonFieldWidth, buttonFieldWidth),
50, 50, Qt::RelativeSize);
2017-06-01 15:50:59 +08:00
leftButton.addRect(QRect(width() - 2 * buttonFieldWidth - lineWidth, 0,
buttonFieldWidth / 2, buttonFieldWidth / 2));
leftButton.addRect(QRect(width() - 1.5 * buttonFieldWidth - lineWidth, 0,
buttonFieldWidth / 2, buttonFieldWidth));
leftButton.setFillRule(Qt::WindingFill);
2015-02-14 19:14:09 +08:00
painter.setBrush(QBrush(buttonColor));
painter.drawPath(leftButton);
2015-02-14 19:14:09 +08:00
// Draw the right button:
2015-02-14 19:14:09 +08:00
painter.setBrush(QBrush(buttonColor));
2017-06-01 15:50:59 +08:00
painter.setClipRect(QRect(width() - buttonFieldWidth, 0, buttonFieldWidth, buttonFieldWidth));
painter.drawRoundedRect(geometry(), r * ratio, r, Qt::RelativeSize);
2015-02-14 19:14:09 +08:00
}
}
void FileTransferWidget::reloadTheme()
{
updateBackgroundColor(lastStatus);
}
2014-11-17 23:05:14 +08:00
QString FileTransferWidget::getHumanReadableSize(qint64 size)
{
static const char* suffix[] = {"B", "KiB", "MiB", "GiB", "TiB"};
2014-11-17 23:05:14 +08:00
int exp = 0;
if (size > 0) {
exp = std::min(static_cast<int>(log(size) / log(1024)), static_cast<int>(sizeof(suffix) / sizeof(suffix[0]) - 1));
}
2014-11-17 23:05:14 +08:00
return QString().setNum(size / pow(1024, exp), 'f', exp > 1 ? 2 : 0).append(suffix[exp]);
2014-11-17 23:05:14 +08:00
}
void FileTransferWidget::updateWidgetColor(ToxFile const& file)
{
if (lastStatus == file.status) {
return;
}
updateBackgroundColor(file.status);
}
void FileTransferWidget::updateWidgetText(ToxFile const& file)
{
if (lastStatus == file.status && file.status != ToxFile::PAUSED) {
return;
}
switch (file.status) {
case ToxFile::INITIALIZING:
if (file.direction == ToxFile::SENDING) {
ui->progressLabel->setText(tr("Waiting to send...", "file transfer widget"));
} else {
ui->progressLabel->setText(tr("Accept to receive this file", "file transfer widget"));
}
break;
case ToxFile::PAUSED:
ui->etaLabel->setText("");
if (file.pauseStatus.localPaused()) {
ui->progressLabel->setText(tr("Paused", "file transfer widget"));
} else {
ui->progressLabel->setText(tr("Remote paused", "file transfer widget"));
}
break;
case ToxFile::TRANSMITTING:
ui->etaLabel->setText("");
ui->progressLabel->setText(tr("Resuming...", "file transfer widget"));
break;
case ToxFile::BROKEN:
case ToxFile::CANCELED:
break;
case ToxFile::FINISHED:
break;
default:
qCritical() << "Invalid file status";
assert(false);
}
}
void FileTransferWidget::updatePreview(ToxFile const& file)
{
if (lastStatus == file.status) {
return;
}
switch (file.status) {
case ToxFile::INITIALIZING:
case ToxFile::PAUSED:
case ToxFile::TRANSMITTING:
case ToxFile::BROKEN:
case ToxFile::CANCELED:
if (file.direction == ToxFile::SENDING) {
showPreview(file.filePath);
}
break;
case ToxFile::FINISHED:
showPreview(file.filePath);
break;
default:
qCritical() << "Invalid file status";
assert(false);
}
}
void FileTransferWidget::updateFileProgress(ToxFile const& file)
{
switch (file.status) {
case ToxFile::INITIALIZING:
case ToxFile::PAUSED:
break;
case ToxFile::TRANSMITTING: {
auto speed = file.progress.getSpeed();
auto progress = file.progress.getProgress();
auto remainingTime = file.progress.getTimeLeftSeconds();
ui->progressBar->setValue(static_cast<int>(progress * 100.0));
// update UI
if (speed > 0) {
// ETA
QTime toGo = QTime(0, 0).addSecs(remainingTime);
QString format = toGo.hour() > 0 ? "hh:mm:ss" : "mm:ss";
ui->etaLabel->setText(toGo.toString(format));
} else {
ui->etaLabel->setText("");
}
ui->progressLabel->setText(getHumanReadableSize(speed) + "/s");
break;
}
case ToxFile::BROKEN:
case ToxFile::CANCELED:
case ToxFile::FINISHED: {
ui->progressBar->hide();
ui->progressLabel->hide();
ui->etaLabel->hide();
break;
}
default:
qCritical() << "Invalid file status";
assert(false);
}
}
void FileTransferWidget::updateSignals(ToxFile const& file)
2014-11-17 23:05:14 +08:00
{
if (lastStatus == file.status) {
return;
}
switch (file.status) {
case ToxFile::CANCELED:
case ToxFile::BROKEN:
case ToxFile::FINISHED:
active = false;
disconnect(&coreFile, nullptr, this, nullptr);
break;
case ToxFile::INITIALIZING:
case ToxFile::PAUSED:
case ToxFile::TRANSMITTING:
break;
default:
qCritical() << "Invalid file status";
assert(false);
}
2014-11-17 23:05:14 +08:00
}
void FileTransferWidget::setupButtons(ToxFile const& file)
2014-11-17 23:05:14 +08:00
{
if (lastStatus == file.status && file.status != ToxFile::PAUSED) {
return;
}
switch (file.status) {
2014-11-17 23:05:14 +08:00
case ToxFile::TRANSMITTING:
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg")));
ui->leftButton->setObjectName("pause");
ui->leftButton->setToolTip(tr("Pause transfer"));
2015-02-14 19:14:09 +08:00
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg")));
ui->rightButton->setObjectName("cancel");
ui->rightButton->setToolTip(tr("Cancel transfer"));
2014-11-17 23:05:14 +08:00
2019-03-23 20:58:44 +08:00
setButtonColor(Style::getColor(Style::TransferGood));
break;
case ToxFile::PAUSED:
if (file.pauseStatus.localPaused()) {
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/arrow_white.svg")));
ui->leftButton->setObjectName("resume");
ui->leftButton->setToolTip(tr("Resume transfer"));
} else {
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg")));
ui->leftButton->setObjectName("pause");
ui->leftButton->setToolTip(tr("Pause transfer"));
}
2015-02-14 19:14:09 +08:00
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg")));
ui->rightButton->setObjectName("cancel");
ui->rightButton->setToolTip(tr("Cancel transfer"));
2015-02-14 19:14:09 +08:00
2019-03-23 20:58:44 +08:00
setButtonColor(Style::getColor(Style::TransferMiddle));
2014-11-17 23:05:14 +08:00
break;
case ToxFile::INITIALIZING:
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg")));
ui->rightButton->setObjectName("cancel");
ui->rightButton->setToolTip(tr("Cancel transfer"));
2014-11-18 03:08:55 +08:00
if (file.direction == ToxFile::SENDING) {
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg")));
ui->leftButton->setObjectName("pause");
ui->leftButton->setToolTip(tr("Pause transfer"));
} else {
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/yes.svg")));
ui->leftButton->setObjectName("accept");
ui->leftButton->setToolTip(tr("Accept transfer"));
2014-11-18 03:08:55 +08:00
}
break;
case ToxFile::CANCELED:
case ToxFile::BROKEN:
ui->leftButton->hide();
ui->rightButton->hide();
break;
case ToxFile::FINISHED:
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/yes.svg")));
ui->leftButton->setObjectName("ok");
ui->leftButton->setToolTip(tr("Open file"));
ui->leftButton->show();
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/dir.svg")));
ui->rightButton->setObjectName("dir");
ui->rightButton->setToolTip(tr("Open file directory"));
ui->rightButton->show();
2014-11-17 23:05:14 +08:00
break;
default:
qCritical() << "Invalid file status";
assert(false);
2014-11-17 23:05:14 +08:00
}
}
void FileTransferWidget::handleButton(QPushButton* btn)
2014-11-17 23:05:14 +08:00
{
if (fileInfo.direction == ToxFile::SENDING) {
if (btn->objectName() == "cancel") {
coreFile.cancelFileSend(fileInfo.friendId, fileInfo.fileNum);
} else if (btn->objectName() == "pause") {
coreFile.pauseResumeFile(fileInfo.friendId, fileInfo.fileNum);
} else if (btn->objectName() == "resume") {
coreFile.pauseResumeFile(fileInfo.friendId, fileInfo.fileNum);
}
} else // receiving or paused
2014-11-17 23:05:14 +08:00
{
if (btn->objectName() == "cancel") {
coreFile.cancelFileRecv(fileInfo.friendId, fileInfo.fileNum);
} else if (btn->objectName() == "pause") {
coreFile.pauseResumeFile(fileInfo.friendId, fileInfo.fileNum);
} else if (btn->objectName() == "resume") {
coreFile.pauseResumeFile(fileInfo.friendId, fileInfo.fileNum);
} else if (btn->objectName() == "accept") {
QString path =
QFileDialog::getSaveFileName(Q_NULLPTR,
tr("Save a file", "Title of the file saving dialog"),
Settings::getInstance().getGlobalAutoAcceptDir() + "/"
+ fileInfo.fileName);
2014-12-14 04:11:03 +08:00
acceptTransfer(path);
2014-11-18 03:08:55 +08:00
}
2014-11-17 23:05:14 +08:00
}
if (btn->objectName() == "ok" || btn->objectName() == "previewButton") {
Widget::confirmExecutableOpen(QFileInfo(fileInfo.filePath));
} else if (btn->objectName() == "dir") {
QString dirPath = QFileInfo(fileInfo.filePath).dir().path();
2015-03-01 17:43:43 +08:00
QDesktopServices::openUrl(QUrl::fromLocalFile(dirPath));
}
2014-11-17 23:05:14 +08:00
}
void FileTransferWidget::showPreview(const QString& filename)
2014-11-18 03:08:55 +08:00
{
ui->previewButton->setIconFromFile(filename);
ui->previewButton->show();
2014-11-18 03:08:55 +08:00
}
void FileTransferWidget::onLeftButtonClicked()
2014-11-17 23:05:14 +08:00
{
handleButton(ui->leftButton);
2014-11-17 23:05:14 +08:00
}
void FileTransferWidget::onRightButtonClicked()
2014-11-17 23:05:14 +08:00
{
handleButton(ui->rightButton);
2014-11-12 21:11:25 +08:00
}
void FileTransferWidget::onPreviewButtonClicked()
{
handleButton(ui->previewButton);
}
void FileTransferWidget::updateWidget(ToxFile const& file)
{
refactor(chatform): Remove message handling logic from gui path Functional changes * Offline messages are still sent when the chat log is cleared * Spinner now does not wait for history to be complete, just a receipt from our friend * Export chat and load chat history are now available in group chats * Merged save chat log and export chat log * Note that we lost the info messages in the process NonFunctional Changes * FileTransferWidget slots only called for correct file * Settings::getEnableGroupChatsColor now embedded in GenericChatForm::colorizeNames * Settings::setEnableGroupChatscolor now emits signal connected to GenericChatForm::setColorizedNames to keep state in sync * Chatlog history not reloaded on setPassword() * I am pretty sure this had no purpose * Removed a lot of responsibility from ChatForm * History moved to ChatHistory implementation of IChatLog * OfflineMsgEngine moved to FriendMessageDispatcher * Export chat and load chat history moved to GenericChatLog * Backed by IChatLog so can be used generically * Message processing moved to FriendMessageDispatcher * The action of sending files to coreFile is still handled by ChatForm, but displaying of the sent messages is done through IChatLog -> GenericChatForm * Search moved to ChatHistory/SessionChatLog * All insertion of chat log elements should be handled by GenericChatForm now * Removed overlapping responsibilities from GroupChatForm * Search and message sending goes through ichatlog/messagedispatcher too * Lots of search functionality pushed down into IChatLog * Some of the file logic was moved into Widget. This is mostly to avoid scope increase of this PR even further. * History APIs removed that were no longer used
2019-05-26 08:11:44 +08:00
assert(file == fileInfo);
fileInfo = file;
bool shouldUpdateFileProgress = file.status != ToxFile::TRANSMITTING || lastTransmissionUpdate ==
QTime() || lastTransmissionUpdate.msecsTo(file.progress.lastSampleTime()) > 1000;
updatePreview(file);
if (shouldUpdateFileProgress)
updateFileProgress(file);
updateWidgetText(file);
updateWidgetColor(file);
setupButtons(file);
updateSignals(file);
lastStatus = file.status;
if (shouldUpdateFileProgress) {
lastTransmissionUpdate = QTime::currentTime();
update();
}
}
void FileTransferWidget::updateBackgroundColor(const ToxFile::FileStatus status)
{
switch (status) {
case ToxFile::INITIALIZING:
case ToxFile::PAUSED:
case ToxFile::TRANSMITTING:
setBackgroundColor(Style::getColor(Style::TransferMiddle), false);
break;
case ToxFile::BROKEN:
case ToxFile::CANCELED:
setBackgroundColor(Style::getColor(Style::TransferBad), true);
break;
case ToxFile::FINISHED:
setBackgroundColor(Style::getColor(Style::TransferGood), true);
break;
default:
qCritical() << "Invalid file status";
assert(false);
}
}