mirror of
https://github.com/QuasarApp/qTbot.git
synced 2025-05-07 10:49:38 +00:00
added FileWaiter class
This commit is contained in:
parent
78fa932640
commit
a8bd1f3b47
src/qTbot/src/public/qTbot
34
src/qTbot/src/public/qTbot/filewaiter.cpp
Normal file
34
src/qTbot/src/public/qTbot/filewaiter.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
//#
|
||||
//# Copyright (C) 2023-2023 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
#include "filewaiter.h"
|
||||
namespace qTbot {
|
||||
|
||||
FileWaiter::FileWaiter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FileWaiter::wait(const QSharedPointer<iFile> &file) {
|
||||
if (!file->isFinished()) {
|
||||
auto address = reinterpret_cast<size_t>(file.get());
|
||||
|
||||
_files[address] = file;
|
||||
|
||||
|
||||
connect(file.get(), &qTbot::iFile::finishedChanged, this, &FileWaiter::handleFileFinished,
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
void FileWaiter::handleFileFinished() {
|
||||
auto address = reinterpret_cast<size_t>(sender());
|
||||
|
||||
_files.remove(address);
|
||||
|
||||
}
|
||||
|
||||
}
|
43
src/qTbot/src/public/qTbot/filewaiter.h
Normal file
43
src/qTbot/src/public/qTbot/filewaiter.h
Normal file
@ -0,0 +1,43 @@
|
||||
//#
|
||||
//# Copyright (C) 2023-2023 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
|
||||
#ifndef FILEWAITER_H
|
||||
#define FILEWAITER_H
|
||||
|
||||
#include "ifile.h"
|
||||
|
||||
namespace qTbot {
|
||||
|
||||
/**
|
||||
* @brief The FileWaiter class. This is a simple storage for the shared pointer of files.
|
||||
* All added files will be removed (shared object) after finish donwload or upload.
|
||||
*/
|
||||
class FileWaiter: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileWaiter();
|
||||
|
||||
/**
|
||||
* @brief wait This method add shared pointer of file in to local storage, and remove it from this when @a file change state to finish.
|
||||
* @param file This is a processed file.
|
||||
* @note The file will not added if the file alredey finished.
|
||||
* @note This method not stop thread, it is just save a file until it is is progres
|
||||
*/
|
||||
void wait(const QSharedPointer<iFile>& file);
|
||||
|
||||
private slots:
|
||||
void handleFileFinished();
|
||||
|
||||
private:
|
||||
QHash<size_t, QSharedPointer<iFile>> _files;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
#endif // FILEWAITER_H
|
@ -364,6 +364,7 @@ private:
|
||||
QMap<QString, QSharedPointer<QJsonObject>>
|
||||
prepareKeyboard(bool autoResizeKeyboard, bool onTimeKeyboard, const QList<QList<QString> > &keyboard);
|
||||
|
||||
|
||||
unsigned long long _id = 0;
|
||||
QString _username;
|
||||
QSharedPointer<QNetworkReply> _loginReplay;
|
||||
|
Loading…
x
Reference in New Issue
Block a user