aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/thread/FileReadThread.h
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-05-13 17:43:56 +0000
committerSaturneric <[email protected]>2022-05-13 17:43:56 +0000
commit93ac14374580d6a173b83bef0dba0ff73ff77f5a (patch)
treedb4926fd694f660c48d2e18bb2bf6eaa4aaeae6d /src/ui/thread/FileReadThread.h
parentperf: improve core performance (diff)
downloadGpgFrontend-93ac14374580d6a173b83bef0dba0ff73ff77f5a.tar.gz
GpgFrontend-93ac14374580d6a173b83bef0dba0ff73ff77f5a.zip
feat: add a simple TaskRunner system
1. solve multiple threads problem.
Diffstat (limited to '')
-rw-r--r--src/core/thread/FileReadTask.h (renamed from src/ui/thread/FileReadThread.h)46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/ui/thread/FileReadThread.h b/src/core/thread/FileReadTask.h
index e7573af8..d4e61cbe 100644
--- a/src/ui/thread/FileReadThread.h
+++ b/src/core/thread/FileReadTask.h
@@ -27,7 +27,8 @@
#ifndef GPGFRONTEND_FILEREADTHREAD_H
#define GPGFRONTEND_FILEREADTHREAD_H
-#include "ui/GpgFrontendUI.h"
+#include "core/GpgFrontendCore.h"
+#include "core/thread/Task.h"
namespace GpgFrontend::UI {
@@ -35,41 +36,28 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class FileReadThread : public QThread {
+class GPGFRONTEND_CORE_EXPORT FileReadTask : public GpgFrontend::Thread::Task {
Q_OBJECT
-
public:
- /**
- * @brief Construct a new File Read Thread object
- *
- * @param path
- */
- explicit FileReadThread(std::string path);
-
- signals:
+ explicit FileReadTask(std::string path);
- /**
- * @brief
- *
- * @param block
- */
- void SignalSendReadBlock(const std::string& block);
+ virtual ~FileReadTask() override;
- /**
- * @brief
- *
- */
- void SignalReadDone();
+ void Run() override;
- protected:
- /**
- * @brief
- *
- */
- void run() override;
+ signals:
+ void SignalFileBytesRead(QByteArray bytes);
+ void SignalFileBytesReadEnd();
+ void SignalFileBytesReadNext();
private:
- std::string path_; ///<
+ std::filesystem::path read_file_path_;
+ QFile target_file_;
+ const size_t buffer_size_ = 4096;
+ QEventLoop looper;
+
+ private slots:
+ void read_bytes();
};
} // namespace GpgFrontend::UI