aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-12-28 12:53:01 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-01-05 21:01:28 +0900
commite017dd42637071687f88f5a36e7e03f1536332be (patch)
tree88de440b83243b49181fa0a4a1cb3d74f2c98ad3 /lib
parent3b88c2b537b6cb98dcd0f2066d39e426b5cc52da (diff)
downloadlibquotient-e017dd42637071687f88f5a36e7e03f1536332be.tar.gz
libquotient-e017dd42637071687f88f5a36e7e03f1536332be.zip
FileTransferInfo: new properties: isUpload and started
Also: use constructors instead of list-based initialisation in FileTransferPrivateInfo to enable a case of "invalid/empty" FileTransferPrivateInfo with status == None.
Diffstat (limited to 'lib')
-rw-r--r--lib/room.cpp16
-rw-r--r--lib/room.h12
2 files changed, 19 insertions, 9 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 156b5b1f..d613fd77 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -126,15 +126,17 @@ class Room::Private
struct FileTransferPrivateInfo
{
-#ifdef WORKAROUND_EXTENDED_INITIALIZER_LIST
FileTransferPrivateInfo() = default;
- FileTransferPrivateInfo(BaseJob* j, QString fileName)
- : job(j), localFileInfo(fileName)
+ FileTransferPrivateInfo(BaseJob* j, const QString& fileName,
+ bool isUploading = false)
+ : status(FileTransferInfo::Started), job(j)
+ , localFileInfo(fileName), isUpload(isUploading)
{ }
-#endif
+
+ FileTransferInfo::Status status = FileTransferInfo::None;
QPointer<BaseJob> job = nullptr;
QFileInfo localFileInfo { };
- FileTransferInfo::Status status = FileTransferInfo::Started;
+ bool isUpload = false;
qint64 progress = 0;
qint64 total = -1;
@@ -969,7 +971,7 @@ FileTransferInfo Room::fileTransferInfo(const QString& id) const
fti.localPath = QUrl::fromLocalFile(infoIt->localFileInfo.absoluteFilePath());
return fti;
#else
- return { infoIt->status, int(progress), int(total),
+ return { infoIt->status, infoIt->isUpload, int(progress), int(total),
QUrl::fromLocalFile(infoIt->localFileInfo.absolutePath()),
QUrl::fromLocalFile(infoIt->localFileInfo.absoluteFilePath())
};
@@ -1532,7 +1534,7 @@ void Room::uploadFile(const QString& id, const QUrl& localFilename,
auto job = connection()->uploadFile(fileName, overrideContentType);
if (isJobRunning(job))
{
- d->fileTransfers.insert(id, { job, fileName });
+ d->fileTransfers.insert(id, { job, fileName, true });
connect(job, &BaseJob::uploadProgress, this,
[this,id] (qint64 sent, qint64 total) {
d->fileTransfers[id].update(sent, total);
diff --git a/lib/room.h b/lib/room.h
index 6384b706..b832977f 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -42,10 +42,17 @@ namespace QMatrixClient
class SetRoomStateWithKeyJob;
class RedactEventJob;
+ /** The data structure used to expose file transfer information to views
+ *
+ * This is specifically tuned to work with QML exposing all traits as
+ * Q_PROPERTY values.
+ */
class FileTransferInfo
{
Q_GADGET
+ Q_PROPERTY(bool isUpload MEMBER isUpload CONSTANT)
Q_PROPERTY(bool active READ active CONSTANT)
+ Q_PROPERTY(bool started READ started CONSTANT)
Q_PROPERTY(bool completed READ completed CONSTANT)
Q_PROPERTY(bool failed READ failed CONSTANT)
Q_PROPERTY(int progress MEMBER progress CONSTANT)
@@ -55,14 +62,15 @@ namespace QMatrixClient
public:
enum Status { None, Started, Completed, Failed };
Status status = None;
+ bool isUpload = false;
int progress = 0;
int total = -1;
QUrl localDir { };
QUrl localPath { };
- bool active() const
- { return status == Started || status == Completed; }
+ bool started() const { return status == Started; }
bool completed() const { return status == Completed; }
+ bool active() const { return started() || completed(); }
bool failed() const { return status == Failed; }
};