Skip to content

Commit

Permalink
feat(filesform): Add in progress transfers to files form
Browse files Browse the repository at this point in the history
As part of qTox#1532 it was identified that long running file transfers
could get lost deep in the chatlog. This could result in unexpected use
of bandwidth over time if users lose track of old/large transfers. This
commit updates the files form to show in progress file transfers and
offer a way to control them.

* FilesForm now works on ToxFiles instead of finished file paths
* FilesForm widgets have been replaced with an MV tree view with depth
  1. The existing QListWidget did not provide us the controls to render
  more complex items. The use of delegates allows us to efficiently draw
  progress bars and controls
* getHumanReadableSize has been extracted from FileTransferWidget into a
  more general utils file
  • Loading branch information
sphaerophoria committed Dec 11, 2021
1 parent c7efe32 commit 257a19c
Show file tree
Hide file tree
Showing 20 changed files with 1,188 additions and 56 deletions.
1 change: 1 addition & 0 deletions cmake/Testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ auto_test(model messageprocessor "")
auto_test(model sessionchatlog "")
auto_test(model exiftransform "")
auto_test(model notificationgenerator "${MOCK_SOURCES}")
auto_test(widget filesform "")

if (UNIX)
auto_test(platform posixsignalnotifier "")
Expand Down
6 changes: 6 additions & 0 deletions res.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@
<file>themes/dark/chatArea/typing.svg</file>
<file>themes/dark/chatArea/error.svg</file>
<file>themes/dark/fileTransferInstance/no.svg</file>
<file>themes/dark/fileTransferInstance/no_dark.svg</file>
<file>themes/dark/fileTransferInstance/pause.svg</file>
<file>themes/dark/fileTransferInstance/pause_dark.svg</file>
<file>themes/dark/fileTransferInstance/yes.svg</file>
<file>themes/dark/fileTransferInstance/dir.svg</file>
<file>themes/dark/fileTransferInstance/arrow_white.svg</file>
<file>themes/dark/fileTransferInstance/arrow_black.svg</file>
<file>themes/dark/fileTransferInstance/browse.svg</file>
<file>themes/dark/fileTransferInstance/filetransferWidget.css</file>
<file>themes/dark/genericChatForm/genericChatForm.css</file>
Expand Down Expand Up @@ -164,10 +167,13 @@
<file>themes/default/chatArea/typing.svg</file>
<file>themes/default/chatArea/error.svg</file>
<file>themes/default/fileTransferInstance/no.svg</file>
<file>themes/default/fileTransferInstance/no_dark.svg</file>
<file>themes/default/fileTransferInstance/pause.svg</file>
<file>themes/default/fileTransferInstance/pause_dark.svg</file>
<file>themes/default/fileTransferInstance/yes.svg</file>
<file>themes/default/fileTransferInstance/dir.svg</file>
<file>themes/default/fileTransferInstance/arrow_white.svg</file>
<file>themes/default/fileTransferInstance/arrow_black.svg</file>
<file>themes/default/fileTransferInstance/browse.svg</file>
<file>themes/default/fileTransferInstance/filetransferWidget.css</file>
<file>themes/default/genericChatForm/genericChatForm.css</file>
Expand Down
13 changes: 1 addition & 12 deletions src/chatlog/content/filetransferwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "src/widget/style.h"
#include "src/widget/widget.h"
#include "src/model/exiftransform.h"
#include "util/display.h"

#include <QBuffer>
#include <QDebug>
Expand Down Expand Up @@ -234,18 +235,6 @@ void FileTransferWidget::reloadTheme()
updateBackgroundColor(lastStatus);
}

QString FileTransferWidget::getHumanReadableSize(qint64 size)
{
static const char* suffix[] = {"B", "KiB", "MiB", "GiB", "TiB"};
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));
}

return QString().setNum(size / pow(1024, exp), 'f', exp > 1 ? 2 : 0).append(suffix[exp]);
}

void FileTransferWidget::updateWidgetColor(ToxFile const& file)
{
if (lastStatus == file.status) {
Expand Down
2 changes: 0 additions & 2 deletions src/chatlog/content/filetransferwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class FileTransferWidget : public QWidget
explicit FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file);
virtual ~FileTransferWidget();
bool isActive() const;
static QString getHumanReadableSize(qint64 size);

void onFileTransferUpdate(ToxFile file);

protected:
Expand Down
2 changes: 0 additions & 2 deletions src/core/corefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ void CoreFile::onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId,
file->status = ToxFile::FINISHED;
if (file->fileKind != TOX_FILE_KIND_AVATAR) {
emit coreFile->fileTransferFinished(*file);
emit coreFile->fileUploadFinished(file->filePath);
}
coreFile->removeFile(friendId, fileId);
return;
Expand Down Expand Up @@ -519,7 +518,6 @@ void CoreFile::onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fil
}
} else {
emit coreFile->fileTransferFinished(*file);
emit coreFile->fileDownloadFinished(file->filePath);
}
coreFile->removeFile(friendId, fileId);
return;
Expand Down
2 changes: 0 additions & 2 deletions src/core/corefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class CoreFile : public QObject
void fileTransferAccepted(ToxFile file);
void fileTransferCancelled(ToxFile file);
void fileTransferFinished(ToxFile file);
void fileUploadFinished(const QString& path);
void fileDownloadFinished(const QString& path);
void fileTransferPaused(ToxFile file);
void fileTransferInfo(ToxFile file);
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
Expand Down
3 changes: 2 additions & 1 deletion src/model/notificationgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "notificationgenerator.h"
#include "src/chatlog/content/filetransferwidget.h"
#include "util/display.h"

#include <QCollator>

Expand Down Expand Up @@ -223,7 +224,7 @@ NotificationData NotificationGenerator::fileTransferNotification(const Friend* f
{
//: e.g. Bob - file transfer
ret.title = tr("%1 - file transfer").arg(f->getDisplayedName());
ret.message = filename + " (" + FileTransferWidget::getHumanReadableSize(fileSize) + ")";
ret.message = filename + " (" + getHumanReadableSize(fileSize) + ")";
}

ret.pixmap = getSenderAvatar(profile, f->getPublicKey());
Expand Down
Loading

0 comments on commit 257a19c

Please sign in to comment.