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