diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/GpgCoreInit.cpp | 32 | ||||
-rw-r--r-- | src/core/function/CacheManager.cpp | 57 | ||||
-rw-r--r-- | src/core/function/CacheManager.h | 4 | ||||
-rw-r--r-- | src/core/function/CharsetOperator.cpp | 4 | ||||
-rw-r--r-- | src/core/function/DataObjectOperator.cpp | 10 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.cpp | 9 | ||||
-rw-r--r-- | src/core/function/basic/ChannelObject.cpp | 10 | ||||
-rw-r--r-- | src/core/function/gpg/GpgCommandExecutor.cpp | 52 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyOpera.cpp | 1 | ||||
-rw-r--r-- | src/core/thread/FileReadTask.cpp | 8 | ||||
-rw-r--r-- | src/core/thread/FileReadTask.h | 1 | ||||
-rw-r--r-- | src/core/utils/GpgUtils.cpp | 17 | ||||
-rw-r--r-- | src/ui/GpgFrontendUIInit.cpp | 10 | ||||
-rw-r--r-- | src/ui/widgets/PlainTextEditorPage.cpp | 17 |
14 files changed, 110 insertions, 122 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 0aec196a..7ccb2438 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -184,7 +184,7 @@ auto InitGpgME() -> bool { case GPGME_PROTOCOL_OpenPGP: find_openpgp = true; - Module::UpsertRTValue("core", "gpgme.engine.openpgp", "1"); + Module::UpsertRTValue("core", "gpgme.engine.openpgp", 1); Module::UpsertRTValue("core", "gpgme.ctx.app_path", std::string(engine_info->file_name)); Module::UpsertRTValue("core", "gpgme.ctx.gnupg_version", @@ -196,7 +196,7 @@ auto InitGpgME() -> bool { break; case GPGME_PROTOCOL_CMS: find_cms = true; - Module::UpsertRTValue("core", "gpgme.engine.cms", "1"); + Module::UpsertRTValue("core", "gpgme.engine.cms", 1); Module::UpsertRTValue("core", "gpgme.ctx.cms_path", std::string(engine_info->file_name)); @@ -204,13 +204,13 @@ auto InitGpgME() -> bool { case GPGME_PROTOCOL_GPGCONF: find_gpgconf = true; - Module::UpsertRTValue("core", "gpgme.engine.gpgconf", "1"); + Module::UpsertRTValue("core", "gpgme.engine.gpgconf", 1); Module::UpsertRTValue("core", "gpgme.ctx.gpgconf_path", std::string(engine_info->file_name)); break; case GPGME_PROTOCOL_ASSUAN: - Module::UpsertRTValue("core", "gpgme.engine.assuan", "1"); + Module::UpsertRTValue("core", "gpgme.engine.assuan", 1); Module::UpsertRTValue("core", "gpgme.ctx.assuan_path", std::string(engine_info->file_name)); break; @@ -242,17 +242,17 @@ auto InitGpgME() -> bool { return false; } - Module::UpsertRTValue("core", "env.state.gpgme", std::string{"1"}); + Module::UpsertRTValue("core", "env.state.gpgme", 1); return true; } void InitGpgFrontendCore(CoreInitArgs args) { // initialize global register table - Module::UpsertRTValue("core", "env.state.gpgme", std::string{"0"}); - Module::UpsertRTValue("core", "env.state.ctx", std::string{"0"}); - Module::UpsertRTValue("core", "env.state.gnupg", std::string{"0"}); - Module::UpsertRTValue("core", "env.state.basic", std::string{"0"}); - Module::UpsertRTValue("core", "env.state.all", std::string{"0"}); + Module::UpsertRTValue("core", "env.state.gpgme", 0); + Module::UpsertRTValue("core", "env.state.ctx", 0); + Module::UpsertRTValue("core", "env.state.gnupg", 0); + Module::UpsertRTValue("core", "env.state.basic", 0); + Module::UpsertRTValue("core", "env.state.all", 0); // initialize locale environment SPDLOG_DEBUG("locale: {}", setlocale(LC_CTYPE, nullptr)); @@ -392,7 +392,7 @@ void InitGpgFrontendCore(CoreInitArgs args) { _("GpgME Context inilization failed")); return -1; } - Module::UpsertRTValue("core", "env.state.ctx", std::string{"1"}); + Module::UpsertRTValue("core", "env.state.ctx", 1); } // if gnupg-info-gathering module activated @@ -420,20 +420,18 @@ void InitGpgFrontendCore(CoreInitArgs args) { // try to restart all components GpgFrontend::GpgAdvancedOperator::RestartGpgComponents(); - Module::UpsertRTValue("core", "env.state.gnupg", - std::string{"1"}); + Module::UpsertRTValue("core", "env.state.gnupg", 1); // announce that all checkings were finished SPDLOG_INFO( "all env checking finished, including gpgme, " "ctx and gnupg"); - Module::UpsertRTValue("core", "env.state.all", - std::string{"1"}); + Module::UpsertRTValue("core", "env.state.all", 1); } }); } else { SPDLOG_DEBUG("gnupg-info-gathering is not activated"); - Module::UpsertRTValue("core", "env.state.all", std::string{"1"}); + Module::UpsertRTValue("core", "env.state.all", 1); } if (args.load_default_gpg_context) { @@ -445,7 +443,7 @@ void InitGpgFrontendCore(CoreInitArgs args) { SPDLOG_INFO( "basic env checking finished, including gpgme, ctx, and key " "infos"); - Module::UpsertRTValue("core", "env.state.basic", std::string{"1"}); + Module::UpsertRTValue("core", "env.state.basic", 1); CoreSignalStation::GetInstance()->SignalGoodGnupgEnv(); return 0; diff --git a/src/core/function/CacheManager.cpp b/src/core/function/CacheManager.cpp index 80d5aeb4..f9fa41ac 100644 --- a/src/core/function/CacheManager.cpp +++ b/src/core/function/CacheManager.cpp @@ -91,15 +91,13 @@ class ThreadSafeMap { mutable std::shared_mutex mutex_; }; -class CacheManager::Impl : public SingletonFunctionObject<CacheManager::Impl> { +class CacheManager::Impl : public QObject { + Q_OBJECT public: - Impl(CacheManager* parent, int channel) - : SingletonFunctionObject<CacheManager::Impl>(channel), - parent_(parent), - m_timer_(new QTimer(parent)) { - connect(m_timer_, &QTimer::timeout, parent_, - [this]() { flush_cache_storage(); }); - m_timer_->start(15000); + Impl() : flush_timer_(new QTimer(this)) { + connect(flush_timer_, &QTimer::timeout, this, + &Impl::slot_flush_cache_storage); + flush_timer_->start(15000); load_all_cache_storage(); } @@ -115,7 +113,7 @@ class CacheManager::Impl : public SingletonFunctionObject<CacheManager::Impl> { } if (flush) { - flush_cache_storage(); + slot_flush_cache_storage(); } } @@ -153,11 +151,28 @@ class CacheManager::Impl : public SingletonFunctionObject<CacheManager::Impl> { return cache_storage_.remove(key); } + private slots: + + /** + * @brief + * + */ + void slot_flush_cache_storage() { + for (const auto& cache : cache_storage_.mirror()) { + auto key = get_data_object_key(cache.first); + SPDLOG_TRACE("save cache into filesystem, key {}, value size: {}", key, + cache.second.size()); + GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(key, + cache.second); + } + GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(drk_key_, + key_storage_); + } + private: - CacheManager* parent_; ThreadSafeMap<std::string, nlohmann::json> cache_storage_; nlohmann::json key_storage_; - QTimer* m_timer_; + QTimer* flush_timer_; const std::string drk_key_ = "__cache_manage_data_register_key_list"; /** @@ -222,22 +237,6 @@ class CacheManager::Impl : public SingletonFunctionObject<CacheManager::Impl> { /** * @brief * - */ - void flush_cache_storage() { - for (const auto& cache : cache_storage_.mirror()) { - auto key = get_data_object_key(cache.first); - SPDLOG_TRACE("save cache into filesystem, key {}, value size: {}", key, - cache.second.size()); - GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(key, - cache.second); - } - GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(drk_key_, - key_storage_); - } - - /** - * @brief - * * @param key */ void register_cache_key(const std::string& key) {} @@ -245,7 +244,7 @@ class CacheManager::Impl : public SingletonFunctionObject<CacheManager::Impl> { CacheManager::CacheManager(int channel) : SingletonFunctionObject<CacheManager>(channel), - p_(SecureCreateUniqueObject<Impl>(this, channel)) {} + p_(SecureCreateUniqueObject<Impl>()) {} CacheManager::~CacheManager() = default; @@ -268,3 +267,5 @@ auto CacheManager::ResetCache(std::string key) -> bool { } } // namespace GpgFrontend + +#include "CacheManager.moc"
\ No newline at end of file diff --git a/src/core/function/CacheManager.h b/src/core/function/CacheManager.h index 062ff490..0cb893a2 100644 --- a/src/core/function/CacheManager.h +++ b/src/core/function/CacheManager.h @@ -35,9 +35,7 @@ namespace GpgFrontend { class GPGFRONTEND_CORE_EXPORT CacheManager - : public QObject, - public SingletonFunctionObject<CacheManager> { - Q_OBJECT + : public SingletonFunctionObject<CacheManager> { public: explicit CacheManager( int channel = SingletonFunctionObject::GetDefaultChannel()); diff --git a/src/core/function/CharsetOperator.cpp b/src/core/function/CharsetOperator.cpp index 8623428d..a5f96344 100644 --- a/src/core/function/CharsetOperator.cpp +++ b/src/core/function/CharsetOperator.cpp @@ -49,8 +49,6 @@ auto CharsetOperator::Detect(const std::string &buffer) return {"unknown", "unknown", 0}; } - SPDLOG_DEBUG("detecting charset buffer: {} bytes", buffer.size()); - status = U_ZERO_ERROR; ucsdet_setText(csd, buffer.data(), buffer.size(), &status); if (U_FAILURE(status) != 0) { @@ -76,7 +74,7 @@ auto CharsetOperator::Detect(const std::string &buffer) const char *language = ucsdet_getLanguage(ucm, &status); if (U_FAILURE(status) != 0) return {name, "unknown", confidence}; - SPDLOG_DEBUG("Detected charset: {} {} {}", name, language, confidence); + SPDLOG_DEBUG("detected charset: {} {} {}", name, language, confidence); return {name, language, confidence}; } diff --git a/src/core/function/DataObjectOperator.cpp b/src/core/function/DataObjectOperator.cpp index 0a68b394..9607de59 100644 --- a/src/core/function/DataObjectOperator.cpp +++ b/src/core/function/DataObjectOperator.cpp @@ -106,7 +106,7 @@ auto DataObjectOperator::SaveDataObj(const std::string& _key, auto DataObjectOperator::GetDataObject(const std::string& _key) -> std::optional<nlohmann::json> { try { - SPDLOG_TRACE("get data object {}", _key); + SPDLOG_TRACE("get data object from disk {}", _key); auto hash_obj_key = QCryptographicHash::hash(hash_key_ + QByteArray::fromStdString(_key), QCryptographicHash::Sha256) @@ -116,18 +116,16 @@ auto DataObjectOperator::GetDataObject(const std::string& _key) const auto obj_path = app_data_objs_path_ / hash_obj_key; if (!std::filesystem::exists(obj_path)) { - SPDLOG_ERROR("data object not found :{}", _key); + SPDLOG_WARN("data object not found, key: {}", _key); return {}; } std::string buffer; if (!ReadFileStd(obj_path.u8string(), buffer)) { - SPDLOG_ERROR("failed to read data object: {}", _key); + SPDLOG_ERROR("failed to read data object, key: {}", _key); return {}; } - SPDLOG_TRACE("data object found {}", _key); - auto encoded = QByteArray::fromStdString(buffer); QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB, QAESEncryption::Padding::ISO); @@ -142,7 +140,7 @@ auto DataObjectOperator::GetDataObject(const std::string& _key) return nlohmann::json::parse(decoded.toStdString()); } catch (...) { - SPDLOG_ERROR("failed to get data object: {}", _key); + SPDLOG_ERROR("failed to get data object, caught exception: {}", _key); return {}; } } diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index e3970a6a..6290e866 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -31,8 +31,8 @@ #include <boost/dll.hpp> #include <filesystem> +#include "core/module/ModuleManager.h" #include "core/utils/FilesystemUtils.h" -#include "core/utils/IOUtils.h" namespace GpgFrontend { @@ -44,10 +44,11 @@ class GlobalSettingStation::Impl { */ explicit Impl() noexcept { SPDLOG_INFO("app path: {}", app_path_.u8string()); - auto protable_file_path = app_path_ / "PORTABLE.txt"; - if (std::filesystem::exists(protable_file_path)) { + auto portable_file_path = app_path_ / "PORTABLE.txt"; + if (std::filesystem::exists(portable_file_path)) { SPDLOG_INFO( - "dectected protable mode, reconfiguring config and data path..."); + "dectected portable mode, reconfiguring config and data path..."); + Module::UpsertRTValue("core", "env.state.portable", 1); app_configure_path_ = app_path_.parent_path(); config_dir_path_ = app_configure_path_ / "conf"; diff --git a/src/core/function/basic/ChannelObject.cpp b/src/core/function/basic/ChannelObject.cpp index 451f9eeb..ddbfa603 100644 --- a/src/core/function/basic/ChannelObject.cpp +++ b/src/core/function/basic/ChannelObject.cpp @@ -28,7 +28,7 @@ #include "ChannelObject.h" -#include <utility> +#include <iostream> namespace GpgFrontend { @@ -37,7 +37,15 @@ ChannelObject::ChannelObject() noexcept = default; ChannelObject::ChannelObject(int channel, std::string type) : channel_(channel), type_(std::move(type)) {} +#ifdef DEBUG +ChannelObject::~ChannelObject() noexcept { + // using iostream instead of spdlog bacause at this time spdlog may have + // already been destroyed. + std::cout << "releasing channel object: " << this->type_ << std::endl; +} +#else ChannelObject::~ChannelObject() noexcept = default; +#endif void ChannelObject::SetChannel(int channel) { this->channel_ = channel; } diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp index 6718d62a..fbcb1e4d 100644 --- a/src/core/function/gpg/GpgCommandExecutor.cpp +++ b/src/core/function/gpg/GpgCommandExecutor.cpp @@ -54,29 +54,27 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) SPDLOG_DEBUG("building task: called cmd {} arguments size: {}", cmd, arguments.size()); - Thread::Task::TaskCallback result_callback = - [cmd, joined_argument](int /*rtn*/, const DataObjectPtr &data_object) { - SPDLOG_DEBUG( - "data object args count of cmd executor result callback: {}", - data_object->GetObjectSize()); - if (!data_object->Check<int, std::string, std::string, - GpgCommandExecutorCallback>()) { - throw std::runtime_error("invalid data object size"); - } - - auto exit_code = ExtractParams<int>(data_object, 0); - auto process_stdout = ExtractParams<std::string>(data_object, 1); - auto process_stderr = ExtractParams<std::string>(data_object, 2); - auto callback = - ExtractParams<GpgCommandExecutorCallback>(data_object, 3); - - // call callback - SPDLOG_DEBUG( - "calling custom callback from caller of cmd {} {}, " - "exit_code: {}", - cmd, joined_argument, exit_code); - callback(exit_code, process_stdout, process_stderr); - }; + Thread::Task::TaskCallback result_callback = [cmd, joined_argument]( + int /*rtn*/, + const DataObjectPtr + &data_object) { + SPDLOG_DEBUG("data object args count of cmd executor result callback: {}", + data_object->GetObjectSize()); + if (!data_object->Check<int, std::string, GpgCommandExecutorCallback>()) { + throw std::runtime_error("invalid data object size"); + } + + auto exit_code = ExtractParams<int>(data_object, 0); + auto process_stdout = ExtractParams<std::string>(data_object, 1); + auto callback = ExtractParams<GpgCommandExecutorCallback>(data_object, 2); + + // call callback + SPDLOG_DEBUG( + "calling custom callback from caller of cmd {} {}, " + "exit_code: {}", + cmd, joined_argument, exit_code); + callback(exit_code, process_stdout, {}); + }; Thread::Task::TaskRunnable runner = [joined_argument](const DataObjectPtr &data_object) -> int { @@ -140,8 +138,6 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) std::string process_stdout = cmd_process->readAllStandardOutput().toStdString(); - std::string process_stderr = - cmd_process->readAllStandardError().toStdString(); int exit_code = cmd_process->exitCode(); SPDLOG_DEBUG( @@ -151,15 +147,13 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) "Exit Code: {}\n" "---- Standard Output ----\n" "{}\n" - "---- Standard Error ----\n" - "{}\n" "===============================", - cmd, joined_argument, exit_code, process_stdout, process_stderr); + cmd, joined_argument, exit_code, process_stdout); cmd_process->close(); cmd_process->deleteLater(); - data_object->Swap({exit_code, process_stdout, process_stderr, callback}); + data_object->Swap({exit_code, process_stdout, callback}); return 0; }; diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index 378a946d..c48b75f3 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -40,7 +40,6 @@ #include "core/GpgModel.h" #include "core/function/gpg/GpgCommandExecutor.h" #include "core/function/gpg/GpgKeyGetter.h" -#include "core/function/result_analyse/GpgResultAnalyse.h" #include "core/model/DataObject.h" #include "core/model/GpgGenKeyInfo.h" #include "core/module/ModuleManager.h" diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index 52ec9db9..906ea188 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -30,6 +30,8 @@ namespace GpgFrontend::UI { +constexpr size_t kBufferSize = 8192; + FileReadTask::FileReadTask(std::string path) : Task("file_read_task") { HoldOnLifeCycle(true); connect(this, &FileReadTask::SignalFileBytesReadNext, this, @@ -68,11 +70,11 @@ void FileReadTask::Run() { void FileReadTask::read_bytes() { QByteArray read_buffer; if (!target_file_.atEnd() && - (read_buffer = target_file_.read(buffer_size_)).size() > 0) { - SPDLOG_DEBUG("read bytes: {}", read_buffer.size()); + (read_buffer = target_file_.read(kBufferSize)).size() > 0) { + SPDLOG_DEBUG("io thread read bytes: {}", read_buffer.size()); emit SignalFileBytesRead(std::move(read_buffer)); } else { - SPDLOG_DEBUG("read bytes end"); + SPDLOG_DEBUG("io read bytes end"); emit SignalFileBytesReadEnd(); // announce finish task emit SignalTaskShouldEnd(0); diff --git a/src/core/thread/FileReadTask.h b/src/core/thread/FileReadTask.h index 666cc6f3..e7eb1370 100644 --- a/src/core/thread/FileReadTask.h +++ b/src/core/thread/FileReadTask.h @@ -54,7 +54,6 @@ class GPGFRONTEND_CORE_EXPORT FileReadTask : public GpgFrontend::Thread::Task { private: std::filesystem::path read_file_path_; QFile target_file_; - const size_t buffer_size_ = 4096; QEventLoop looper; private slots: diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp index cd5a6772..98e4c749 100644 --- a/src/core/utils/GpgUtils.cpp +++ b/src/core/utils/GpgUtils.cpp @@ -32,20 +32,20 @@ namespace GpgFrontend { -static inline void Ltrim(std::string& s) { +inline void Ltrim(std::string& s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); } -static inline void Rtrim(std::string& s) { +inline void Rtrim(std::string& s) { s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }) .base(), s.end()); } -static inline auto Trim(std::string& s) -> std::string { +inline auto Trim(std::string& s) -> std::string { Ltrim(s); Rtrim(s); return s; @@ -54,12 +54,12 @@ static inline auto Trim(std::string& s) -> std::string { auto GetGpgmeErrorString(size_t buffer_size, gpgme_error_t err) -> std::string { std::vector<char> buffer(buffer_size); - gpgme_error_t ret = gpgme_strerror_r(err, buffer.data(), buffer.size()); + gpgme_error_t const ret = gpgme_strerror_r(err, buffer.data(), buffer.size()); if (ret == ERANGE && buffer_size < 1024) { return GetGpgmeErrorString(buffer_size * 2, err); } - return std::string(buffer.data()); + return {buffer.data()}; } auto GetGpgmeErrorString(gpgme_error_t err) -> std::string { @@ -161,9 +161,6 @@ auto SetExtensionOfOutputFileForArchive(std::filesystem::path path, case kENCRYPT_SIGN: extension += ".tar.asc"; return path.replace_extension(extension); - case kDECRYPT: - case kDECRYPT_VERIFY: - return path.parent_path(); default: break; } @@ -173,13 +170,11 @@ auto SetExtensionOfOutputFileForArchive(std::filesystem::path path, case kENCRYPT_SIGN: extension += ".tar.gpg"; return path.replace_extension(extension); - case kDECRYPT: - case kDECRYPT_VERIFY: - return path.parent_path(); default: break; } } + return path.parent_path(); } } // namespace GpgFrontend diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index 9849fab2..99a9541f 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -92,14 +92,14 @@ void WaitEnvCheckingProcess() { exit(0); }); - auto env_state = Module::RetrieveRTValueTypedOrDefault<>( - "core", "env.state.basic", std::string{"0"}); + auto env_state = + Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.basic", 0); SPDLOG_DEBUG("ui is ready to wating for env initialized, env_state: {}", env_state); // check twice to avoid some unlucky sitations - if (env_state == "1") { + if (env_state == 1) { SPDLOG_DEBUG("env state turned initialized before the looper start"); waiting_dialog->finished(0); waiting_dialog->deleteLater(); @@ -199,8 +199,8 @@ void InitGpgFrontendUI(QApplication* /*app*/) { QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); } - if (Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.basic", - std::string{"0"}) == "0") { + if (Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.basic", 0) == + 0) { WaitEnvCheckingProcess(); } } diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp index 1685e0e2..2037689e 100644 --- a/src/ui/widgets/PlainTextEditorPage.cpp +++ b/src/ui/widgets/PlainTextEditorPage.cpp @@ -95,10 +95,7 @@ bool PlainTextEditorPage::WillCharsetChange() const { if (is_crlf_) return true; // detect if the charset of the file will change - if (charset_name_ != "UTF-8" && charset_name_ != "ISO-8859-1") - return true; - else - return false; + return charset_name_ != "UTF-8" && charset_name_ != "ISO-8859-1"; } void PlainTextEditorPage::NotifyFileSaved() { @@ -170,7 +167,7 @@ void PlainTextEditorPage::ReadFile() { ui_->loadingLabel->setHidden(false); ui_->textPage->document()->blockSignals(true); - auto text_page = this->GetTextPage(); + auto *text_page = this->GetTextPage(); text_page->setReadOnly(true); const auto target_path = this->full_file_path_.toStdString(); @@ -202,7 +199,7 @@ void PlainTextEditorPage::ReadFile() { task_runner->PostTask(read_task); } -std::string binary_to_string(const std::string &source) { +auto BinaryToString(const std::string &source) -> std::string { static char syms[] = "0123456789ABCDEF"; std::stringstream ss; for (unsigned char c : source) @@ -212,7 +209,8 @@ std::string binary_to_string(const std::string &source) { void PlainTextEditorPage::slot_insert_text(QByteArray bytes_data) { std::string data = bytes_data.toStdString(); - SPDLOG_DEBUG("data size: {}", data.size()); + + SPDLOG_TRACE("inserting data read to editor, data size: {}", data.size()); read_bytes_ += data.size(); // If binary format is detected, the entire file is converted to binary // format for display. @@ -227,13 +225,12 @@ void PlainTextEditorPage::slot_insert_text(QByteArray bytes_data) { auto text_buffer = ui_->textPage->document()->toRawText().toLocal8Bit().toStdString(); ui_->textPage->clear(); - this->GetTextPage()->insertPlainText( - binary_to_string(text_buffer).c_str()); + this->GetTextPage()->insertPlainText(BinaryToString(text_buffer).c_str()); this->ui_->lfLabel->setText("None"); } // insert new data - this->GetTextPage()->insertPlainText(binary_to_string(data).c_str()); + this->GetTextPage()->insertPlainText(BinaryToString(data).c_str()); // update the size of the file auto str = boost::format(_("%1% byte(s)")) % read_bytes_; |