Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(transfer): Accurately represent pause state in UI
Browse files Browse the repository at this point in the history
Toxcore has a 3 state pause, us, them, or both. Currently our UI
messes up if both parties pause. This changeset changes our UI behavior
to show whether we're paused, or if we are waiting on the remote to
unpause.
  • Loading branch information
sphaerophoria committed Dec 16, 2018
1 parent cbf2a18 commit 293a1d6
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 31 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions src/chatlog/content/filetransferwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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("");
Expand Down Expand Up @@ -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;
}

Expand All @@ -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");
Expand Down
45 changes: 20 additions & 25 deletions src/core/corefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,43 +152,36 @@ void CoreFile::pauseResumeFileSend(Core* core, uint32_t friendId, uint32_t fileI
qWarning("pauseResumeFileSend: No such file in queue");
return;
}
if (file->status == ToxFile::TRANSMITTING) {

if (file->status != ToxFile::TRANSMITTING && file->status != ToxFile::PAUSED) {
qWarning() << "pauseResumeFileSend: File is stopped";
return;
}

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,
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");
return;
}
if (file->status == ToxFile::TRANSMITTING) {
file->status = ToxFile::PAUSED;
emit core->fileTransferPaused(*file);
if (file->pauseStatus.localPaused()) {
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);
} else {
tox_file_control(core->tox.get(), file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME,
nullptr);
} else {
qWarning() << "pauseResumeFileRecv: File is stopped or broken";
}
}

void CoreFile::pauseResumeFileRecv(Core* core, uint32_t friendId, uint32_t fileId)
{
pauseResumeFileSend(core, friendId, fileId);
}

void CoreFile::cancelFileSend(Core* core, uint32_t friendId, uint32_t fileId)
{
ToxFile* file = findFile(friendId, fileId);
Expand Down Expand Up @@ -382,14 +375,16 @@ 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) {
if (file->direction == ToxFile::SENDING && file->fileKind == TOX_FILE_KIND_AVATAR)
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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/toxfile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef CORESTRUCTS_H
#define CORESTRUCTS_H

#include "src/core/toxfilepause.h"

#include <QString>
#include <memory>
#include <QCryptographicHash>
Expand Down Expand Up @@ -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 changes: 76 additions & 0 deletions src/core/toxfilepause.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 293a1d6

Please sign in to comment.