aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/thread/FileReadTask.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-12 06:02:37 +0000
committersaturneric <[email protected]>2024-01-12 06:02:37 +0000
commitbf538056b24a68b8fd235b1c50991ee8eb46a776 (patch)
treee1bab54095b80df62b321fb5bd69453f9f951b05 /src/core/thread/FileReadTask.cpp
parentfeat: improve api and ui of keys import and export (diff)
downloadGpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.tar.gz
GpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.zip
refactor: use QString instead of std::string and improve threading system
Diffstat (limited to 'src/core/thread/FileReadTask.cpp')
-rw-r--r--src/core/thread/FileReadTask.cpp23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp
index 98dbf718..38a0ab37 100644
--- a/src/core/thread/FileReadTask.cpp
+++ b/src/core/thread/FileReadTask.cpp
@@ -32,27 +32,18 @@ namespace GpgFrontend::UI {
constexpr size_t kBufferSize = 8192;
-FileReadTask::FileReadTask(std::string path) : Task("file_read_task") {
+FileReadTask::FileReadTask(QString path) : Task("file_read_task") {
HoldOnLifeCycle(true);
connect(this, &FileReadTask::SignalFileBytesReadNext, this,
&FileReadTask::read_bytes);
-
-#ifdef WINDOWS
- std::filesystem::path read_file_path(
- QString::fromStdString(path).toStdU16String());
-#else
- std::filesystem::path read_file_path(
- QString::fromStdString(path).toStdString());
-#endif
- read_file_path_ = read_file_path;
+ read_file_path_ = path;
}
void FileReadTask::Run() {
- if (is_regular_file(read_file_path_)) {
- GF_CORE_LOG_DEBUG("read open file: {}", read_file_path_.u8string());
+ if (QFileInfo(read_file_path_).isFile()) {
+ GF_CORE_LOG_DEBUG("read open file: {}", read_file_path_);
- target_file_.setFileName(
- QString::fromStdString(read_file_path_.u8string()));
+ target_file_.setFileName(read_file_path_);
target_file_.open(QIODevice::ReadOnly);
if (!(target_file_.isOpen() && target_file_.isReadable())) {
@@ -60,7 +51,7 @@ void FileReadTask::Run() {
if (target_file_.isOpen()) target_file_.close();
return;
}
- GF_CORE_LOG_DEBUG("started reading: {}", read_file_path_.u8string());
+ GF_CORE_LOG_DEBUG("started reading: {}", read_file_path_);
read_bytes();
} else {
emit SignalFileBytesReadEnd();
@@ -82,7 +73,7 @@ void FileReadTask::read_bytes() {
}
FileReadTask::~FileReadTask() {
- GF_CORE_LOG_DEBUG("close file: {}", read_file_path_.u8string());
+ GF_CORE_LOG_DEBUG("close file: {}", read_file_path_);
if (target_file_.isOpen()) target_file_.close();
}