From e7694f9a0729cb88064eda6623c99070f5a46dc0 Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 2 Jun 2024 22:03:59 +0200 Subject: feat: rewrite key list structure and logic --- src/ui/UserInterfaceUtils.cpp | 46 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'src/ui/UserInterfaceUtils.cpp') diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 806ceb9e..06b784cc 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -529,34 +529,44 @@ auto CommonUtils::KeyExistsinFavouriteList(const GpgKey &key) -> bool { auto json_data = CacheObject("favourite_key_pair"); if (!json_data.isArray()) json_data.setArray(QJsonArray()); - auto key_array = json_data.array(); - return std::find(key_array.begin(), key_array.end(), key.GetFingerprint()) != - key_array.end(); + auto key_fpr_array = json_data.array(); + return std::find(key_fpr_array.begin(), key_fpr_array.end(), + key.GetFingerprint()) != key_fpr_array.end(); } void CommonUtils::AddKey2Favourtie(const GpgKey &key) { - auto json_data = CacheObject("favourite_key_pair"); - QJsonArray key_array; - if (json_data.isArray()) key_array = json_data.array(); + { + auto json_data = CacheObject("favourite_key_pair"); + QJsonArray key_array; + if (json_data.isArray()) key_array = json_data.array(); + + GF_UI_LOG_DEBUG("add key to favorites, key fpr: {}", key.GetFingerprint()); + key_array.push_back(key.GetFingerprint()); + json_data.setArray(key_array); + } - key_array.push_back(key.GetFingerprint()); - json_data.setArray(key_array); + emit SignalFavoritesChanged(); } void CommonUtils::RemoveKeyFromFavourite(const GpgKey &key) { - auto json_data = CacheObject("favourite_key_pair"); - QJsonArray key_array; - if (json_data.isArray()) key_array = json_data.array(); - - QString fingerprint = key.GetFingerprint(); - QJsonArray new_key_array; - for (auto &&item : key_array) { - if (item.isString() && item.toString() != fingerprint) { - new_key_array.append(item); + { + auto json_data = CacheObject("favourite_key_pair"); + QJsonArray key_array; + if (json_data.isArray()) key_array = json_data.array(); + + GF_UI_LOG_DEBUG("remove key from favorites, key fpr: {}", + key.GetFingerprint()); + auto fingerprint = key.GetFingerprint(); + QJsonArray new_key_array; + for (auto &&item : key_array) { + if (item.isString() && item.toString() != fingerprint) { + new_key_array.append(item); + } } + json_data.setArray(new_key_array); } - json_data.setArray(new_key_array); + emit SignalFavoritesChanged(); } /** -- cgit v1.2.3 From 37a62a8d0b590710b902376ca3320cc05e954b63 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 26 Jul 2024 18:24:34 +0200 Subject: feat: remove spdlog and clean up log --- src/ui/UserInterfaceUtils.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'src/ui/UserInterfaceUtils.cpp') diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 06b784cc..1d54c3cd 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -80,7 +80,6 @@ void ImportUnknownKeyFromKeyserver( auto key_ids = std::make_unique(); auto *signature = verify_result.GetSignatures(); while (signature != nullptr) { - GF_UI_LOG_DEBUG("signature fpr: {}", signature->fpr); key_ids->push_back(signature->fpr); signature = signature->next; } @@ -232,8 +231,6 @@ void CommonUtils::WaitForOpera(QWidget *parent, QTimer::singleShot(64, parent, [=]() { opera([dialog]() { if (dialog != nullptr) { - GF_UI_LOG_DEBUG("called operating waiting cb, dialog: {}", - static_cast(dialog)); dialog->close(); dialog->accept(); } @@ -328,18 +325,17 @@ void CommonUtils::SlotExecuteCommand( &QEventLoop::quit); connect(cmd_process, &QProcess::errorOccurred, &looper, &QEventLoop::quit); connect(cmd_process, &QProcess::started, - []() -> void { GF_UI_LOG_DEBUG("process started"); }); + []() -> void { qCDebug(ui, "process started"); }); connect(cmd_process, &QProcess::readyReadStandardOutput, [interact_func, cmd_process]() { interact_func(cmd_process); }); connect(cmd_process, &QProcess::errorOccurred, this, - [=]() -> void { GF_UI_LOG_ERROR("error in process"); }); + [=]() -> void { qCWarning(ui, "error in process"); }); connect(cmd_process, qOverload(&QProcess::finished), this, [=](int, QProcess::ExitStatus status) { - if (status == QProcess::NormalExit) - GF_UI_LOG_DEBUG("succeed in executing command: {}", cmd); - else - GF_UI_LOG_WARN("error in executing command: {}", cmd); + if (status != QProcess::NormalExit) { + qCWarning(ui) << "error in executing command: " << cmd; + } }); cmd_process->setProgram(cmd); @@ -365,11 +361,11 @@ void CommonUtils::SlotExecuteGpgCommand( &WaitingDialog::deleteLater); connect(gpg_process, &QProcess::errorOccurred, &looper, &QEventLoop::quit); connect(gpg_process, &QProcess::started, - []() -> void { GF_UI_LOG_DEBUG("gpg process started"); }); + []() -> void { qCDebug(ui, "gpg process started"); }); connect(gpg_process, &QProcess::readyReadStandardOutput, [interact_func, gpg_process]() { interact_func(gpg_process); }); connect(gpg_process, &QProcess::errorOccurred, this, [=]() -> void { - GF_UI_LOG_ERROR("Error in Process"); + qCWarning(ui, "Error in Process"); dialog->close(); QMessageBox::critical(nullptr, tr("Failure"), tr("Failed to execute command.")); @@ -388,7 +384,6 @@ void CommonUtils::SlotExecuteGpgCommand( const auto app_path = Module::RetrieveRTValueTypedOrDefault<>( "core", "gpgme.ctx.app_path", QString{}); - GF_UI_LOG_DEBUG("got gnupg app path from rt: {}", app_path); gpg_process->setProgram(app_path); gpg_process->setArguments(arguments); @@ -409,8 +404,6 @@ void CommonUtils::SlotImportKeyFromKeyServer( "please set a default keyserver first")); return; } - GF_UI_LOG_DEBUG("set target key server to default Key Server: {}", - target_keyserver); auto *thread = QThread::create([target_keyserver, key_ids, callback]() { QUrl target_keyserver_url(target_keyserver); @@ -426,8 +419,6 @@ void CommonUtils::SlotImportKeyFromKeyServer( target_keyserver_url.host() + "/pks/lookup?op=get&search=0x" + key_id + "&options=mr"); - GF_UI_LOG_DEBUG("request url: {}", req_url.toString()); - // Waiting for reply auto request = QNetworkRequest(req_url); request.setHeader(QNetworkRequest::UserAgentHeader, @@ -498,21 +489,19 @@ void CommonUtils::slot_update_key_from_server_finished( bool success, QString err_msg, QByteArray buffer, std::shared_ptr info) { if (!success) { - GF_UI_LOG_ERROR("get err from reply: {}", buffer); + qCWarning(ui) << "get err from reply: " << buffer; QMessageBox::critical(nullptr, tr("Error"), err_msg); return; } // refresh the key database - emit UISignalStation::GetInstance()->SignalKeyDatabaseRefresh(); + emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh(); // show details (new KeyImportDetailDialog(std::move(info), this))->exec(); } void CommonUtils::SlotRestartApplication(int code) { - GF_UI_LOG_DEBUG("application need restart, code: {}", code); - if (code == 0) { std::exit(0); } else { @@ -540,7 +529,6 @@ void CommonUtils::AddKey2Favourtie(const GpgKey &key) { QJsonArray key_array; if (json_data.isArray()) key_array = json_data.array(); - GF_UI_LOG_DEBUG("add key to favorites, key fpr: {}", key.GetFingerprint()); key_array.push_back(key.GetFingerprint()); json_data.setArray(key_array); } @@ -554,8 +542,6 @@ void CommonUtils::RemoveKeyFromFavourite(const GpgKey &key) { QJsonArray key_array; if (json_data.isArray()) key_array = json_data.array(); - GF_UI_LOG_DEBUG("remove key from favorites, key fpr: {}", - key.GetFingerprint()); auto fingerprint = key.GetFingerprint(); QJsonArray new_key_array; for (auto &&item : key_array) { -- cgit v1.2.3 From c1d0552cb33f80c4c8b7331e699ee867db2a2319 Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 28 Jul 2024 15:28:14 +0200 Subject: fix: can not import binary key data --- src/ui/UserInterfaceUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/UserInterfaceUtils.cpp') diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 1d54c3cd..8f50636b 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -264,7 +264,7 @@ void CommonUtils::RaiseFailureMessageBox(QWidget *parent, GpgError err) { .arg(desc.second)); } -void CommonUtils::SlotImportKeys(QWidget *parent, const QString &in_buffer) { +void CommonUtils::SlotImportKeys(QWidget *parent, const QByteArray &in_buffer) { auto info = GpgKeyImportExporter::GetInstance().ImportKey(GFBuffer(in_buffer)); emit SignalKeyStatusUpdated(); @@ -310,7 +310,7 @@ void CommonUtils::SlotImportKeyFromKeyServer(QWidget *parent) { void CommonUtils::SlotImportKeyFromClipboard(QWidget *parent) { QClipboard *cb = QApplication::clipboard(); - SlotImportKeys(parent, cb->text(QClipboard::Clipboard)); + SlotImportKeys(parent, cb->text(QClipboard::Clipboard).toLatin1()); } void CommonUtils::SlotExecuteCommand( -- cgit v1.2.3