From cd837f0d154e061bc26118f204d5f9a2a417be81 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 12 Jan 2022 08:36:36 +0800 Subject: (ui): Adjust src/ui/function to src/ui/thread --- src/ui/thread/FileReadThread.cpp | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/ui/thread/FileReadThread.cpp (limited to 'src/ui/thread/FileReadThread.cpp') diff --git a/src/ui/thread/FileReadThread.cpp b/src/ui/thread/FileReadThread.cpp new file mode 100644 index 00000000..270f50e7 --- /dev/null +++ b/src/ui/thread/FileReadThread.cpp @@ -0,0 +1,68 @@ +/** + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Foobar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see . + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric starting on May 12, 2021. + * + */ + +#include "FileReadThread.h" + +#include +#include + +namespace GpgFrontend::UI { + +FileReadThread::FileReadThread(std::string path) : path(std::move(path)) {} + +void FileReadThread::run() { + LOG(INFO) << "Started"; + boost::filesystem::path read_file_path(this->path); + if (is_regular_file(read_file_path)) { + LOG(INFO) << "Read Open"; + + auto fp = fopen(read_file_path.string().c_str(), "r"); + size_t read_size; + LOG(INFO) << "Thread Start Reading"; + + char buffer[8192]; + while ((read_size = fread(buffer, sizeof(char), sizeof buffer, fp)) > 0) { + // Check isInterruptionRequested + if (QThread::currentThread()->isInterruptionRequested()) { + LOG(INFO) << "Read Thread isInterruptionRequested "; + fclose(fp); + return; + } + LOG(INFO) << "Read Thread Read block size " << read_size; + std::string buffer_str(buffer, read_size); + + emit sendReadBlock(QString::fromStdString(buffer_str)); +#ifdef RELEASE + QThread::msleep(32); +#else + QThread::msleep(48); +#endif + } + fclose(fp); + emit readDone(); + LOG(INFO) << "Thread End Reading"; + } +} + +} // namespace GpgFrontend::UI -- cgit v1.2.3 From d24f0251e8c8964bf42f4bf028023f02f4e96933 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 12 Jan 2022 11:04:46 +0800 Subject: (ui): Text editor improvements. 1. Add binary display mode 2. Add information bar 3. Added character code recognition function. 4. Identify text encoding and line breaks 5. Count the number of characters 6. Code reconstruction --- src/ui/thread/FileReadThread.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/ui/thread/FileReadThread.cpp') diff --git a/src/ui/thread/FileReadThread.cpp b/src/ui/thread/FileReadThread.cpp index 270f50e7..04f713bd 100644 --- a/src/ui/thread/FileReadThread.cpp +++ b/src/ui/thread/FileReadThread.cpp @@ -29,39 +29,41 @@ namespace GpgFrontend::UI { -FileReadThread::FileReadThread(std::string path) : path(std::move(path)) {} +FileReadThread::FileReadThread(std::string path) : path(std::move(path)) { + qRegisterMetaType("std::string"); +} void FileReadThread::run() { - LOG(INFO) << "Started"; + LOG(INFO) << "started"; boost::filesystem::path read_file_path(this->path); if (is_regular_file(read_file_path)) { - LOG(INFO) << "Read Open"; + LOG(INFO) << "read open"; - auto fp = fopen(read_file_path.string().c_str(), "r"); + auto fp = fopen(read_file_path.string().c_str(), "rb"); size_t read_size; - LOG(INFO) << "Thread Start Reading"; + LOG(INFO) << "thread start reading"; - char buffer[8192]; + char buffer[4096]; while ((read_size = fread(buffer, sizeof(char), sizeof buffer, fp)) > 0) { // Check isInterruptionRequested if (QThread::currentThread()->isInterruptionRequested()) { - LOG(INFO) << "Read Thread isInterruptionRequested "; + LOG(INFO) << "thread is interruption requested "; fclose(fp); return; } - LOG(INFO) << "Read Thread Read block size " << read_size; + LOG(INFO) << "block size " << read_size; std::string buffer_str(buffer, read_size); - emit sendReadBlock(QString::fromStdString(buffer_str)); + emit sendReadBlock(buffer_str); #ifdef RELEASE QThread::msleep(32); #else - QThread::msleep(48); + QThread::msleep(128); #endif } fclose(fp); emit readDone(); - LOG(INFO) << "Thread End Reading"; + LOG(INFO) << "thread end reading"; } } -- cgit v1.2.3 From 036bbfbe8ed09a4f4d09a37a3a002bb8ec0aecf6 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 23 Jan 2022 04:11:32 +0800 Subject: (src, test): Fix some issues in license statement. --- src/ui/thread/FileReadThread.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/ui/thread/FileReadThread.cpp') diff --git a/src/ui/thread/FileReadThread.cpp b/src/ui/thread/FileReadThread.cpp index 04f713bd..1e991752 100644 --- a/src/ui/thread/FileReadThread.cpp +++ b/src/ui/thread/FileReadThread.cpp @@ -1,4 +1,6 @@ /** + * Copyright (C) 2021 Saturneric + * * This file is part of GpgFrontend. * * GpgFrontend is free software: you can redistribute it and/or modify @@ -6,16 +8,16 @@ * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * Foobar is distributed in the hope that it will be useful, + * GpgFrontend is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Foobar. If not, see . + * along with GpgFrontend. If not, see . * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. * * The source code version of this software was modified and released * by Saturneric starting on May 12, 2021. -- cgit v1.2.3 From 247b5b8f7ffb5cf7df5d4bc0e4fb786152934569 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 23 Jan 2022 15:36:55 +0800 Subject: (ui): tidy up codes and comments. 1. tidy up thread. --- src/ui/thread/FileReadThread.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ui/thread/FileReadThread.cpp') diff --git a/src/ui/thread/FileReadThread.cpp b/src/ui/thread/FileReadThread.cpp index 1e991752..1ed9ae60 100644 --- a/src/ui/thread/FileReadThread.cpp +++ b/src/ui/thread/FileReadThread.cpp @@ -31,13 +31,13 @@ namespace GpgFrontend::UI { -FileReadThread::FileReadThread(std::string path) : path(std::move(path)) { +FileReadThread::FileReadThread(std::string path) : path_(std::move(path)) { qRegisterMetaType("std::string"); } void FileReadThread::run() { LOG(INFO) << "started"; - boost::filesystem::path read_file_path(this->path); + boost::filesystem::path read_file_path(this->path_); if (is_regular_file(read_file_path)) { LOG(INFO) << "read open"; @@ -56,7 +56,7 @@ void FileReadThread::run() { LOG(INFO) << "block size " << read_size; std::string buffer_str(buffer, read_size); - emit sendReadBlock(buffer_str); + emit SignalSendReadBlock(buffer_str); #ifdef RELEASE QThread::msleep(32); #else @@ -64,7 +64,7 @@ void FileReadThread::run() { #endif } fclose(fp); - emit readDone(); + emit SignalReadDone(); LOG(INFO) << "thread end reading"; } } -- cgit v1.2.3 From 260bb5426b6621d409f4e68981e49c936cb313bb Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sat, 5 Feb 2022 17:35:55 +0800 Subject: (ui, core, project): Use std::filesystem instead of boost::filesystem --- src/ui/thread/FileReadThread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/thread/FileReadThread.cpp') diff --git a/src/ui/thread/FileReadThread.cpp b/src/ui/thread/FileReadThread.cpp index 1ed9ae60..b0eae355 100644 --- a/src/ui/thread/FileReadThread.cpp +++ b/src/ui/thread/FileReadThread.cpp @@ -26,7 +26,7 @@ #include "FileReadThread.h" -#include + #include namespace GpgFrontend::UI { @@ -37,7 +37,7 @@ FileReadThread::FileReadThread(std::string path) : path_(std::move(path)) { void FileReadThread::run() { LOG(INFO) << "started"; - boost::filesystem::path read_file_path(this->path_); + std::filesystem::path read_file_path(this->path_); if (is_regular_file(read_file_path)) { LOG(INFO) << "read open"; -- cgit v1.2.3 From dad03e9ccc57da0a04d058ec418ce0068ce3841d Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sat, 19 Mar 2022 14:09:55 +0800 Subject: (core, ui): Fix path double-byte encoding problem under Windows --- src/ui/thread/FileReadThread.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/ui/thread/FileReadThread.cpp') diff --git a/src/ui/thread/FileReadThread.cpp b/src/ui/thread/FileReadThread.cpp index b0eae355..258b9405 100644 --- a/src/ui/thread/FileReadThread.cpp +++ b/src/ui/thread/FileReadThread.cpp @@ -36,25 +36,33 @@ FileReadThread::FileReadThread(std::string path) : path_(std::move(path)) { } void FileReadThread::run() { - LOG(INFO) << "started"; - std::filesystem::path read_file_path(this->path_); + LOG(INFO) << "started reading" << path_; + +#ifdef WINDOWS + std::filesystem::path read_file_path(QString::fromStdString(path_).toStdU16String()); +#else + std::filesystem::path read_file_path(QString::fromStdString(path_).toStdString()); +#endif + if (is_regular_file(read_file_path)) { - LOG(INFO) << "read open"; + LOG(INFO) << "read open" << read_file_path; - auto fp = fopen(read_file_path.string().c_str(), "rb"); - size_t read_size; + QFile file; + file.setFileName(QString::fromStdString(read_file_path.u8string())); + file.open(QIODevice::ReadOnly); + QByteArray read_buffer; LOG(INFO) << "thread start reading"; - char buffer[4096]; - while ((read_size = fread(buffer, sizeof(char), sizeof buffer, fp)) > 0) { + const size_t buffer_size = 4096; + while ((read_buffer = file.read(buffer_size)).size() > 0) { // Check isInterruptionRequested if (QThread::currentThread()->isInterruptionRequested()) { LOG(INFO) << "thread is interruption requested "; - fclose(fp); + file.close(); return; } - LOG(INFO) << "block size " << read_size; - std::string buffer_str(buffer, read_size); + LOG(INFO) << "block size " << read_buffer.size(); + std::string buffer_str(read_buffer.toStdString()); emit SignalSendReadBlock(buffer_str); #ifdef RELEASE @@ -63,7 +71,7 @@ void FileReadThread::run() { QThread::msleep(128); #endif } - fclose(fp); + file.close(); emit SignalReadDone(); LOG(INFO) << "thread end reading"; } -- cgit v1.2.3