mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #5366
Mick Sayson (2): fix(transfer): Accurately represent pause state in UI refactor(transfer): Remove unnecessary split for pause send/recv
This commit is contained in:
commit
f2e8567b21
|
@ -268,6 +268,7 @@ set(${PROJECT_NAME}_SOURCES
|
|||
src/core/toxencrypt.h
|
||||
src/core/toxfile.cpp
|
||||
src/core/toxfile.h
|
||||
src/core/toxfilepause.h
|
||||
src/core/toxid.cpp
|
||||
src/core/toxid.h
|
||||
src/core/toxlogger.cpp
|
||||
|
|
|
@ -346,7 +346,7 @@ void FileTransferWidget::updateWidgetColor(ToxFile const& file)
|
|||
|
||||
void FileTransferWidget::updateWidgetText(ToxFile const& file)
|
||||
{
|
||||
if (lastStatus == file.status) {
|
||||
if (lastStatus == file.status && file.status != ToxFile::PAUSED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,11 @@ void FileTransferWidget::updateWidgetText(ToxFile const& file)
|
|||
break;
|
||||
case ToxFile::PAUSED:
|
||||
ui->etaLabel->setText("");
|
||||
ui->progressLabel->setText(tr("Paused", "file transfer widget"));
|
||||
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("");
|
||||
|
@ -474,7 +478,7 @@ void FileTransferWidget::updateSignals(ToxFile const& file)
|
|||
|
||||
void FileTransferWidget::setupButtons(ToxFile const& file)
|
||||
{
|
||||
if (lastStatus == file.status) {
|
||||
if (lastStatus == file.status && file.status != ToxFile::PAUSED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -492,9 +496,15 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
|
|||
break;
|
||||
|
||||
case ToxFile::PAUSED:
|
||||
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/arrow_white.svg")));
|
||||
ui->leftButton->setObjectName("resume");
|
||||
ui->leftButton->setToolTip(tr("Resume transfer"));
|
||||
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"));
|
||||
}
|
||||
|
||||
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg")));
|
||||
ui->rightButton->setObjectName("cancel");
|
||||
|
@ -547,18 +557,18 @@ void FileTransferWidget::handleButton(QPushButton* btn)
|
|||
if (btn->objectName() == "cancel") {
|
||||
Core::getInstance()->cancelFileSend(fileInfo.friendId, fileInfo.fileNum);
|
||||
} else if (btn->objectName() == "pause") {
|
||||
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
|
||||
Core::getInstance()->pauseResumeFile(fileInfo.friendId, fileInfo.fileNum);
|
||||
} else if (btn->objectName() == "resume") {
|
||||
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
|
||||
Core::getInstance()->pauseResumeFile(fileInfo.friendId, fileInfo.fileNum);
|
||||
}
|
||||
} else // receiving or paused
|
||||
{
|
||||
if (btn->objectName() == "cancel") {
|
||||
Core::getInstance()->cancelFileRecv(fileInfo.friendId, fileInfo.fileNum);
|
||||
} else if (btn->objectName() == "pause") {
|
||||
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
|
||||
Core::getInstance()->pauseResumeFile(fileInfo.friendId, fileInfo.fileNum);
|
||||
} else if (btn->objectName() == "resume") {
|
||||
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
|
||||
Core::getInstance()->pauseResumeFile(fileInfo.friendId, fileInfo.fileNum);
|
||||
} else if (btn->objectName() == "accept") {
|
||||
QString path =
|
||||
QFileDialog::getSaveFileName(Q_NULLPTR,
|
||||
|
|
|
@ -734,18 +734,11 @@ void Core::sendAvatarFile(uint32_t friendId, const QByteArray& data)
|
|||
CoreFile::sendAvatarFile(this, friendId, data);
|
||||
}
|
||||
|
||||
void Core::pauseResumeFileSend(uint32_t friendId, uint32_t fileNum)
|
||||
void Core::pauseResumeFile(uint32_t friendId, uint32_t fileNum)
|
||||
{
|
||||
QMutexLocker ml{coreLoopLock.get()};
|
||||
|
||||
CoreFile::pauseResumeFileSend(this, friendId, fileNum);
|
||||
}
|
||||
|
||||
void Core::pauseResumeFileRecv(uint32_t friendId, uint32_t fileNum)
|
||||
{
|
||||
QMutexLocker ml{coreLoopLock.get()};
|
||||
|
||||
CoreFile::pauseResumeFileRecv(this, friendId, fileNum);
|
||||
CoreFile::pauseResumeFile(this, friendId, fileNum);
|
||||
}
|
||||
|
||||
void Core::cancelFileSend(uint32_t friendId, uint32_t fileNum)
|
||||
|
|
|
@ -130,8 +130,7 @@ public slots:
|
|||
void cancelFileRecv(uint32_t friendId, uint32_t fileNum);
|
||||
void rejectFileRecvRequest(uint32_t friendId, uint32_t fileNum);
|
||||
void acceptFileRecvRequest(uint32_t friendId, uint32_t fileNum, QString path);
|
||||
void pauseResumeFileSend(uint32_t friendId, uint32_t fileNum);
|
||||
void pauseResumeFileRecv(uint32_t friendId, uint32_t fileNum);
|
||||
void pauseResumeFile(uint32_t friendId, uint32_t fileNum);
|
||||
|
||||
void setNospam(uint32_t nospam);
|
||||
|
||||
|
|
|
@ -145,47 +145,35 @@ void CoreFile::sendFile(Core* core, uint32_t friendId, QString filename, QString
|
|||
emit core->fileSendStarted(file);
|
||||
}
|
||||
|
||||
void CoreFile::pauseResumeFileSend(Core* core, uint32_t friendId, uint32_t fileId)
|
||||
void CoreFile::pauseResumeFile(Core* core, uint32_t friendId, uint32_t fileId)
|
||||
{
|
||||
ToxFile* file = findFile(friendId, fileId);
|
||||
if (!file) {
|
||||
qWarning("pauseResumeFileSend: No such file in queue");
|
||||
return;
|
||||
}
|
||||
if (file->status == ToxFile::TRANSMITTING) {
|
||||
file->status = ToxFile::PAUSED;
|
||||
emit core->fileTransferPaused(*file);
|
||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE,
|
||||
nullptr);
|
||||
} else if (file->status == ToxFile::PAUSED) {
|
||||
file->status = ToxFile::TRANSMITTING;
|
||||
emit core->fileTransferAccepted(*file);
|
||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME,
|
||||
nullptr);
|
||||
} else {
|
||||
qWarning() << "pauseResumeFileSend: File is stopped";
|
||||
}
|
||||
}
|
||||
|
||||
void CoreFile::pauseResumeFileRecv(Core* core, uint32_t friendId, uint32_t fileId)
|
||||
{
|
||||
ToxFile* file = findFile(friendId, fileId);
|
||||
if (!file) {
|
||||
qWarning("cancelFileRecv: No such file in queue");
|
||||
if (file->status != ToxFile::TRANSMITTING && file->status != ToxFile::PAUSED) {
|
||||
qWarning() << "pauseResumeFileSend: File is stopped";
|
||||
return;
|
||||
}
|
||||
if (file->status == ToxFile::TRANSMITTING) {
|
||||
|
||||
file->pauseStatus.localPauseToggle();
|
||||
|
||||
if (file->pauseStatus.paused()) {
|
||||
file->status = ToxFile::PAUSED;
|
||||
emit core->fileTransferPaused(*file);
|
||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE,
|
||||
nullptr);
|
||||
} else if (file->status == ToxFile::PAUSED) {
|
||||
} else {
|
||||
file->status = ToxFile::TRANSMITTING;
|
||||
emit core->fileTransferAccepted(*file);
|
||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME,
|
||||
}
|
||||
|
||||
if (file->pauseStatus.localPaused()) {
|
||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE,
|
||||
nullptr);
|
||||
} else {
|
||||
qWarning() << "pauseResumeFileRecv: File is stopped or broken";
|
||||
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME,
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -382,6 +370,7 @@ void CoreFile::onFileControlCallback(Tox*, uint32_t friendId, uint32_t fileId,
|
|||
removeFile(friendId, fileId);
|
||||
} else if (control == TOX_FILE_CONTROL_PAUSE) {
|
||||
qDebug() << "onFileControlCallback: Received pause for file " << friendId << ":" << fileId;
|
||||
file->pauseStatus.remotePause();
|
||||
file->status = ToxFile::PAUSED;
|
||||
emit static_cast<Core*>(core)->fileTransferRemotePausedUnpaused(*file, true);
|
||||
} else if (control == TOX_FILE_CONTROL_RESUME) {
|
||||
|
@ -389,7 +378,8 @@ void CoreFile::onFileControlCallback(Tox*, uint32_t friendId, uint32_t fileId,
|
|||
qDebug() << "Avatar transfer" << fileId << "to friend" << friendId << "accepted";
|
||||
else
|
||||
qDebug() << "onFileControlCallback: Received resume for file " << friendId << ":" << fileId;
|
||||
file->status = ToxFile::TRANSMITTING;
|
||||
file->pauseStatus.remoteResume();
|
||||
file->status = file->pauseStatus.paused() ? ToxFile::PAUSED : ToxFile::TRANSMITTING;
|
||||
emit static_cast<Core*>(core)->fileTransferRemotePausedUnpaused(*file, false);
|
||||
} else {
|
||||
qWarning() << "Unhandled file control " << control << " for file " << friendId << ':' << fileId;
|
||||
|
|
|
@ -51,8 +51,7 @@ private:
|
|||
static void sendFile(Core* core, uint32_t friendId, QString filename, QString filePath,
|
||||
long long filesize);
|
||||
static void sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& data);
|
||||
static void pauseResumeFileSend(Core* core, uint32_t friendId, uint32_t fileId);
|
||||
static void pauseResumeFileRecv(Core* core, uint32_t friendId, uint32_t fileId);
|
||||
static void pauseResumeFile(Core* core, uint32_t friendId, uint32_t fileId);
|
||||
static void cancelFileSend(Core* core, uint32_t friendId, uint32_t fileId);
|
||||
static void cancelFileRecv(Core* core, uint32_t friendId, uint32_t fileId);
|
||||
static void rejectFileRecvRequest(Core* core, uint32_t friendId, uint32_t fileId);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef CORESTRUCTS_H
|
||||
#define CORESTRUCTS_H
|
||||
|
||||
#include "src/core/toxfilepause.h"
|
||||
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
#include <QCryptographicHash>
|
||||
|
@ -53,6 +55,7 @@ struct ToxFile
|
|||
QByteArray avatarData;
|
||||
QByteArray resumeFileId;
|
||||
std::shared_ptr<QCryptographicHash> hashGenerator = std::make_shared<QCryptographicHash>(QCryptographicHash::Sha256);
|
||||
ToxFilePause pauseStatus;
|
||||
};
|
||||
|
||||
#endif // CORESTRUCTS_H
|
||||
|
|
76
src/core/toxfilepause.h
Normal file
76
src/core/toxfilepause.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
Copyright © 2018 by The qTox Project Contributors
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
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,
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TOX_FILE_PAUSE_H
|
||||
#define TOX_FILE_PAUSE_H
|
||||
|
||||
class ToxFilePause
|
||||
{
|
||||
public:
|
||||
void localPause()
|
||||
{
|
||||
localPauseState = true;
|
||||
}
|
||||
|
||||
void localResume()
|
||||
{
|
||||
localPauseState = false;
|
||||
}
|
||||
|
||||
void localPauseToggle()
|
||||
{
|
||||
localPauseState = !localPauseState;
|
||||
}
|
||||
|
||||
void remotePause()
|
||||
{
|
||||
remotePauseState = true;
|
||||
}
|
||||
|
||||
void remoteResume()
|
||||
{
|
||||
remotePauseState = false;
|
||||
}
|
||||
|
||||
void remotePauseToggle()
|
||||
{
|
||||
remotePauseState = !remotePauseState;
|
||||
}
|
||||
|
||||
bool localPaused() const
|
||||
{
|
||||
return localPauseState;
|
||||
}
|
||||
|
||||
bool remotePaused() const
|
||||
{
|
||||
return remotePauseState;
|
||||
}
|
||||
|
||||
bool paused() const
|
||||
{
|
||||
return localPauseState || remotePauseState;
|
||||
}
|
||||
|
||||
private:
|
||||
bool localPauseState = false;
|
||||
bool remotePauseState = false;
|
||||
};
|
||||
|
||||
#endif // TOX_FILE_PAUSE_H
|
Loading…
Reference in New Issue
Block a user