diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd.cpp | 11 | ||||
-rw-r--r-- | src/core/GpgCoreInit.cpp | 19 | ||||
-rw-r--r-- | src/core/GpgCoreInit.h | 9 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.cpp | 14 | ||||
-rw-r--r-- | src/core/function/GlobalSettingStation.h | 9 | ||||
-rw-r--r-- | src/ui/dialog/controller/GnuPGControllerDialog.cpp | 8 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairOperaTab.cpp | 149 |
7 files changed, 129 insertions, 90 deletions
diff --git a/src/cmd.cpp b/src/cmd.cpp index 89a0be95..c9cdbc17 100644 --- a/src/cmd.cpp +++ b/src/cmd.cpp @@ -35,13 +35,13 @@ #include <qtextstream.h> #include "core/GpgCoreInit.h" +#include "core/function/GlobalSettingStation.h" #include "core/module/ModuleManager.h" #include "core/utils/BuildInfoUtils.h" // GpgFrontend #include "GpgFrontendContext.h" -#include "core/utils/GpgUtils.h" #include "test/GpgFrontendTest.h" namespace GpgFrontend { @@ -79,7 +79,14 @@ auto PrintEnvInfo() -> int { stream << Tr("OpenSSL Version: ") << GetProjectOpenSSLVersion() << '\n'; stream << Tr("Libarchive Version: ") << GetProjectLibarchiveVersion() << '\n'; + stream << '\n'; + + auto& setting_station = GlobalSettingStation::GetInstance(); + stream << Tr("App Data Path: ") << setting_station.GetAppDataPath() << '\n'; + stream << Tr("App Log Path: ") << setting_station.GetAppLogPath() << '\n'; + stream << Tr("Modules Path: ") << setting_station.GetModulesDir() << '\n'; + stream << Tr("App Binary Directory: ") << setting_station.GetAppDir() << '\n'; stream << '\n'; @@ -152,7 +159,7 @@ auto PrintEnvInfo() -> int { stream << '\n'; int index = 0; - auto key_dbs = GetGpgKeyDatabaseInfos(); + auto key_dbs = GetKeyDatabaseInfoBySettings(default_database_path); for (const auto& key_database : key_dbs) { stream << Tr("Key Database [") << index++ << "] " << Tr("Name: ") << key_database.name << " " << Tr("-> Path: ") << key_database.path diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 34ac866b..3ff293ae 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -435,7 +435,8 @@ auto InitBasicPath() -> bool { return true; } -auto GetKeyDatabases(QString& default_home_path) -> QList<KeyDatabaseItemSO> { +auto GetKeyDatabasesBySettings(QString& default_home_path) + -> QList<KeyDatabaseItemSO> { auto key_db_list_so = SettingsObject("key_database_list"); auto key_db_list = KeyDatabaseListSO(key_db_list_so); auto key_dbs = key_db_list.key_databases; @@ -448,6 +449,20 @@ auto GetKeyDatabases(QString& default_home_path) -> QList<KeyDatabaseItemSO> { return key_dbs; } +auto GetKeyDatabaseInfoBySettings(QString& default_home_path) + -> QList<KeyDatabaseInfo> { + auto key_dbs = GetKeyDatabasesBySettings(default_home_path); + QList<KeyDatabaseInfo> infos; + for (const auto& key_db : key_dbs) { + KeyDatabaseInfo info; + info.name = key_db.name; + info.path = key_db.path; + info.channel = -1; + infos.append(info); + } + return infos; +} + auto InitGpgFrontendCore(CoreInitArgs args) -> int { // initialize gpgme if (!InitGpgME()) { @@ -548,7 +563,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int { CoreSignalStation::GetInstance()->SignalGoodGnupgEnv(); LOG_I() << "Basic ENV Checking Finished"; - auto key_dbs = GetKeyDatabases(default_home_path); + auto key_dbs = GetKeyDatabasesBySettings(default_home_path); auto* task = new Thread::Task( [=](const DataObjectPtr&) -> int { diff --git a/src/core/GpgCoreInit.h b/src/core/GpgCoreInit.h index 888ca1a3..b23f5a9a 100644 --- a/src/core/GpgCoreInit.h +++ b/src/core/GpgCoreInit.h @@ -29,6 +29,7 @@ #pragma once #include "core/GpgFrontendCoreExport.h" +#include "core/model/KeyDatabaseInfo.h" namespace GpgFrontend { @@ -71,4 +72,12 @@ auto GPGFRONTEND_CORE_EXPORT InitGpgME() -> bool; */ auto GPGFRONTEND_CORE_EXPORT InitBasicPath() -> bool; +/** + * @brief Get the Key Databases By Settings object + * + * @return auto + */ +auto GPGFRONTEND_CORE_EXPORT GetKeyDatabaseInfoBySettings( + QString& default_home_path) -> QList<KeyDatabaseInfo>; + } // namespace GpgFrontend diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 367437da..26b5d8b8 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -119,6 +119,15 @@ class GlobalSettingStation::Impl { [[nodiscard]] auto GetLogDir() const -> QString { return app_log_path(); } /** + * @brief Get the Config Path object + * + * @return QString + */ + [[nodiscard]] auto GetConfigPath() const -> QString { + return app_config_file_path(); + } + + /** * @brief Get the Modules Dir object * * @return QString @@ -171,7 +180,7 @@ auto GlobalSettingStation::GetAppDataPath() const -> QString { return p_->GetAppDataPath(); } -[[nodiscard]] auto GlobalSettingStation::GetLogDir() const -> QString { +[[nodiscard]] auto GlobalSettingStation::GetAppLogPath() const -> QString { return p_->GetLogDir(); } @@ -193,4 +202,7 @@ void GlobalSettingStation::ClearAllDataObjects() const { p_->ClearAllDataObjects(); } +auto GlobalSettingStation::GetConfigPath() const -> QString { + return p_->GetConfigPath(); +} } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h index 7234ea2d..e7da0308 100644 --- a/src/core/function/GlobalSettingStation.h +++ b/src/core/function/GlobalSettingStation.h @@ -82,7 +82,14 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation * * @return QString */ - [[nodiscard]] auto GetLogDir() const -> QString; + [[nodiscard]] auto GetAppLogPath() const -> QString; + + /** + * @brief Get the Log Dir object + * + * @return QString + */ + [[nodiscard]] auto GetConfigPath() const -> QString; /** * @brief Get the Modules Dir object diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp index 72e9c276..9c43c08d 100644 --- a/src/ui/dialog/controller/GnuPGControllerDialog.cpp +++ b/src/ui/dialog/controller/GnuPGControllerDialog.cpp @@ -48,10 +48,6 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent) ui_(GpgFrontend::SecureCreateSharedObject<Ui_GnuPGControllerDialog>()) { ui_->setupUi(this); - ui_->tab->setWindowTitle(tr("General")); - ui_->tab_2->setWindowTitle(tr("Key Database")); - ui_->tab_3->setWindowTitle(tr("Advanced")); - ui_->asciiModeCheckBox->setText(tr("Use Binary Mode for File Operations")); ui_->usePinentryAsPasswordInputDialogCheckBox->setText( tr("Use Pinentry as Password Input Dialog")); @@ -70,6 +66,10 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent) tr("Tips: notice that modify any of these settings will cause an " "Application restart.")); + ui_->tabWidget->setTabText(0, tr("General")); + ui_->tabWidget->setTabText(1, tr("Key Database")); + ui_->tabWidget->setTabText(2, tr("Advanced")); + popup_menu_ = new QMenu(this); popup_menu_->addAction(ui_->actionMove_Key_Database_Up); popup_menu_->addAction(ui_->actionMove_Key_Database_Down); diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp index c849e43f..98f025a0 100644 --- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp @@ -362,86 +362,75 @@ void KeyPairOperaTab::slot_publish_key_to_server() { GpgKeyImportExporter::GetInstance(current_gpg_context_channel_) .ExportKey(m_key_, false, true, false); - Thread::TaskRunnerGetter::GetInstance() - .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network) - ->PostTask(new Thread::Task( - [this, fpr = m_key_.GetFingerprint(), - key_text = gf_buffer.ConvertToQByteArray()]( - const DataObjectPtr& data_obj) -> int { - Module::TriggerEvent( - "REQUEST_UPLOAD_PUBLIC_KEY", - { - {"key_text", QString::fromUtf8(key_text)}, - }, - [=](Module::EventIdentifier i, - Module::Event::ListenerIdentifier ei, - Module::Event::Params p) { - LOG_D() << "REQUEST_UPLOAD_PUBLIC_KEY " - "callback: " - << i << ei; - - if (p["ret"] != "0" || !p["error_msg"].isEmpty()) { - LOG_E() << "An error occurred trying to get data " - "from key:" - << fpr << "error message: " << p["error_msg"] - << "reply data: " << p["reply_data"]; - - // Notify user of the error - QString error_message = p["error_msg"]; - QMessageBox::critical( - this, tr("Key Upload Failed"), - tr("Failed to upload key to the server.\n" - "Fingerprint: %1\n" - "Error: %2") - .arg(fpr, error_message)); - } else if (p.contains("token") && p.contains("status") && - p.contains("fingerprint")) { - const auto token = p["token"]; - const auto status = p["status"]; - const auto reply_fpr = p["fingerprint"]; - LOG_D() << "got key data of key " << fpr - << "from key server, token: " << token - << "fpr: " << fpr << "status: " << status; - - // Handle successful response - QString status_message = - tr("The following email addresses have status:\n"); - QJsonDocument json_doc = - QJsonDocument::fromJson(status.toUtf8()); - QStringList email_list; - if (!json_doc.isNull() && json_doc.isObject()) { - QJsonObject json_obj = json_doc.object(); - for (auto it = json_obj.constBegin(); - it != json_obj.constEnd(); ++it) { - status_message += - QString("%1: %2\n") - .arg(it.key(), it.value().toString()); - email_list.append(it.key()); - } - } else { - status_message += - tr("Could not parse status information."); - } - - // Notify user of successful upload and status details - QMessageBox::information( - this, tr("Key Upload Successful"), - tr("The key was successfully uploaded to the key " - "server keys.openpgp.org.\n" - "Fingerprint: %1\n\n" - "%2\n" - "Please check your email (%3) for further " - "verification from keys.openpgp.org.\n\n" - "Note: For verification, you can find more " - "information here: " - "https://keys.openpgp.org/about") - .arg(fpr, status_message, email_list.join(", "))); - } - }); - - return 0; - }, - QString("key_%1_publish_task").arg(m_key_.GetId()))); + auto fpr = m_key_.GetFingerprint(); + auto key_text = gf_buffer.ConvertToQByteArray(); + + Module::TriggerEvent( + "REQUEST_UPLOAD_PUBLIC_KEY", + { + {"key_text", QString::fromUtf8(key_text)}, + }, + [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, + Module::Event::Params p) { + LOG_D() << "REQUEST_UPLOAD_PUBLIC_KEY " + "callback: " + << i << ei; + + if (p["ret"] != "0" || !p["error_msg"].isEmpty()) { + LOG_E() << "An error occurred trying to get data " + "from key:" + << fpr << "error message: " << p["error_msg"] + << "reply data: " << p["reply_data"]; + + // Notify user of the error + QString error_message = p["error_msg"]; + QMessageBox::critical( + this, tr("Key Upload Failed"), + tr("Failed to upload public key to the server.\n" + "Fingerprint: %1\n" + "Error: %2") + .arg(fpr, error_message)); + } else if (p.contains("token") && p.contains("status") && + p.contains("fingerprint")) { + const auto token = p["token"]; + const auto status = p["status"]; + const auto reply_fpr = p["fingerprint"]; + LOG_D() << "got key data of key " << fpr + << "from key server, token: " << token << "fpr: " << fpr + << "status: " << status; + + // Handle successful response + QString status_message = + tr("The following email addresses have status:\n"); + QJsonDocument json_doc = QJsonDocument::fromJson(status.toUtf8()); + QStringList email_list; + if (!json_doc.isNull() && json_doc.isObject()) { + QJsonObject json_obj = json_doc.object(); + for (auto it = json_obj.constBegin(); it != json_obj.constEnd(); + ++it) { + status_message += + QString("%1: %2\n").arg(it.key(), it.value().toString()); + email_list.append(it.key()); + } + } else { + status_message += tr("Could not parse status information."); + } + + // Notify user of successful upload and status details + QMessageBox::information( + this, tr("Public Key Upload Successful"), + tr("The public key was successfully uploaded to the " + "key server keys.openpgp.org.\n" + "Fingerprint: %1\n\n" + "%2\n" + "Please check your email (%3) for further " + "verification from keys.openpgp.org.\n\n" + "Note: For verification, you can find more " + "information here: " + "https://keys.openpgp.org/about") + .arg(fpr, status_message, email_list.join(", "))); + } + }); return; } |