From 8a63c3954d6745c5e323dcf3e518219ce6545cc0 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 1 Dec 2023 23:23:01 -0800 Subject: fix: add set owner struct action in keymanager menu --- src/ui/function/SetOwnerTrustLevel.cpp | 95 ++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/ui/function/SetOwnerTrustLevel.cpp (limited to 'src/ui/function/SetOwnerTrustLevel.cpp') diff --git a/src/ui/function/SetOwnerTrustLevel.cpp b/src/ui/function/SetOwnerTrustLevel.cpp new file mode 100644 index 00000000..4154b5ff --- /dev/null +++ b/src/ui/function/SetOwnerTrustLevel.cpp @@ -0,0 +1,95 @@ +/** + * Copyright (C) 2021 Saturneric + * + * 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. + * + * 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 GpgFrontend. If not, see . + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "SetOwnerTrustLevel.h" + +#include "core/GpgModel.h" +#include "core/function/gpg/GpgKeyGetter.h" +#include "core/function/gpg/GpgKeyManager.h" +#include "ui/UISignalStation.h" + +namespace GpgFrontend::UI { + +SetOwnerTrustLevel::SetOwnerTrustLevel(QWidget* parent) : QWidget(parent) {} + +auto SetOwnerTrustLevel::Exec(const std::string& key_id) -> bool { + if (key_id.empty()) { + return false; + } + + auto key = GpgKeyGetter::GetInstance().GetKey(key_id); + + QStringList items; + + items << _("Unknown") << _("Undefined") << _("Never") << _("Marginal") + << _("Full") << _("Ultimate"); + bool ok; + QString item = QInputDialog::getItem(this, _("Modify Owner Trust Level"), + _("Trust for the Key Pair:"), items, + key.GetOwnerTrustLevel(), false, &ok); + + if (ok && !item.isEmpty()) { + SPDLOG_DEBUG("selected owner trust policy: {}", item.toStdString()); + int trust_level = 0; // Unknown Level + if (item == _("Ultimate")) { + trust_level = 5; + } else if (item == _("Full")) { + trust_level = 4; + } else if (item == _("Marginal")) { + trust_level = 3; + } else if (item == _("Never")) { + trust_level = 2; + } else if (item == _("Undefined")) { + trust_level = 1; + } + + if (trust_level == 0) { + QMessageBox::warning( + this, _("Warning"), + QString(_("Owner Trust Level cannot set to Unknown level, automately " + "changing it into Undefined level."))); + trust_level = 1; + } + + bool status = + GpgKeyManager::GetInstance().SetOwnerTrustLevel(key, trust_level); + if (!status) { + QMessageBox::critical(this, _("Failed"), + QString(_("Modify Owner Trust Level failed."))); + return false; + } + + // update key database and refresh ui + emit UISignalStation::GetInstance()->SignalKeyDatabaseRefresh(); + return true; + } + + return false; +} + +} // namespace GpgFrontend::UI \ No newline at end of file -- cgit v1.2.3 From 644aa4397b03dbef73f8bfedc13925b51cad836b Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 5 Jan 2024 20:55:15 +0800 Subject: feat: integrate logging api to core --- src/ui/function/SetOwnerTrustLevel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/function/SetOwnerTrustLevel.cpp') diff --git a/src/ui/function/SetOwnerTrustLevel.cpp b/src/ui/function/SetOwnerTrustLevel.cpp index 4154b5ff..290b1436 100644 --- a/src/ui/function/SetOwnerTrustLevel.cpp +++ b/src/ui/function/SetOwnerTrustLevel.cpp @@ -54,7 +54,7 @@ auto SetOwnerTrustLevel::Exec(const std::string& key_id) -> bool { key.GetOwnerTrustLevel(), false, &ok); if (ok && !item.isEmpty()) { - SPDLOG_DEBUG("selected owner trust policy: {}", item.toStdString()); + GF_UI_LOG_DEBUG("selected owner trust policy: {}", item.toStdString()); int trust_level = 0; // Unknown Level if (item == _("Ultimate")) { trust_level = 5; -- cgit v1.2.3 From bf538056b24a68b8fd235b1c50991ee8eb46a776 Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 12 Jan 2024 14:02:37 +0800 Subject: refactor: use QString instead of std::string and improve threading system --- src/ui/function/SetOwnerTrustLevel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/function/SetOwnerTrustLevel.cpp') diff --git a/src/ui/function/SetOwnerTrustLevel.cpp b/src/ui/function/SetOwnerTrustLevel.cpp index 290b1436..91917961 100644 --- a/src/ui/function/SetOwnerTrustLevel.cpp +++ b/src/ui/function/SetOwnerTrustLevel.cpp @@ -37,8 +37,8 @@ namespace GpgFrontend::UI { SetOwnerTrustLevel::SetOwnerTrustLevel(QWidget* parent) : QWidget(parent) {} -auto SetOwnerTrustLevel::Exec(const std::string& key_id) -> bool { - if (key_id.empty()) { +auto SetOwnerTrustLevel::Exec(const QString& key_id) -> bool { + if (key_id.isEmpty()) { return false; } -- cgit v1.2.3 From 620ae9e7c1a8b2db2515c080416cb592066e5fec Mon Sep 17 00:00:00 2001 From: saturneric Date: Tue, 16 Jan 2024 21:35:59 +0800 Subject: refactor: remove libgettext from project --- src/ui/function/SetOwnerTrustLevel.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/ui/function/SetOwnerTrustLevel.cpp') diff --git a/src/ui/function/SetOwnerTrustLevel.cpp b/src/ui/function/SetOwnerTrustLevel.cpp index 91917961..360abfce 100644 --- a/src/ui/function/SetOwnerTrustLevel.cpp +++ b/src/ui/function/SetOwnerTrustLevel.cpp @@ -46,41 +46,42 @@ auto SetOwnerTrustLevel::Exec(const QString& key_id) -> bool { QStringList items; - items << _("Unknown") << _("Undefined") << _("Never") << _("Marginal") - << _("Full") << _("Ultimate"); + items << tr("Unknown") << tr("Undefined") << tr("Never") << tr("Marginal") + << tr("Full") << tr("Ultimate"); bool ok; - QString item = QInputDialog::getItem(this, _("Modify Owner Trust Level"), - _("Trust for the Key Pair:"), items, + QString item = QInputDialog::getItem(this, tr("Modify Owner Trust Level"), + tr("Trust for the Key Pair:"), items, key.GetOwnerTrustLevel(), false, &ok); if (ok && !item.isEmpty()) { GF_UI_LOG_DEBUG("selected owner trust policy: {}", item.toStdString()); int trust_level = 0; // Unknown Level - if (item == _("Ultimate")) { + if (item == tr("Ultimate")) { trust_level = 5; - } else if (item == _("Full")) { + } else if (item == tr("Full")) { trust_level = 4; - } else if (item == _("Marginal")) { + } else if (item == tr("Marginal")) { trust_level = 3; - } else if (item == _("Never")) { + } else if (item == tr("Never")) { trust_level = 2; - } else if (item == _("Undefined")) { + } else if (item == tr("Undefined")) { trust_level = 1; } if (trust_level == 0) { QMessageBox::warning( - this, _("Warning"), - QString(_("Owner Trust Level cannot set to Unknown level, automately " - "changing it into Undefined level."))); + this, tr("Warning"), + QString( + tr("Owner Trust Level cannot set to Unknown level, automately " + "changing it into Undefined level."))); trust_level = 1; } bool status = GpgKeyManager::GetInstance().SetOwnerTrustLevel(key, trust_level); if (!status) { - QMessageBox::critical(this, _("Failed"), - QString(_("Modify Owner Trust Level failed."))); + QMessageBox::critical(this, tr("Failed"), + tr("Modify Owner Trust Level failed.")); return false; } -- cgit v1.2.3