diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/GpgCoreInit.cpp | 5 | ||||
-rw-r--r-- | src/ui/dialog/KeyDatabaseEditDialog.cpp | 48 | ||||
-rw-r--r-- | src/ui/dialog/KeyDatabaseEditDialog.h | 8 |
3 files changed, 54 insertions, 7 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 3a5edff2..e796738e 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -99,9 +99,12 @@ auto InitGpgME(const QString& gpgconf_path, const QString& gnupg_path) -> bool { gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr)); #endif - if (!gnupg_path.isEmpty()) { + if (!gpgconf_path.isEmpty()) { CheckGpgError(gpgme_set_engine_info(GPGME_PROTOCOL_GPGCONF, gpgconf_path.toUtf8(), nullptr)); + } + + if (!gnupg_path.isEmpty()) { CheckGpgError(gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, gnupg_path.toUtf8(), nullptr)); } diff --git a/src/ui/dialog/KeyDatabaseEditDialog.cpp b/src/ui/dialog/KeyDatabaseEditDialog.cpp index 15604f39..a9c7af1c 100644 --- a/src/ui/dialog/KeyDatabaseEditDialog.cpp +++ b/src/ui/dialog/KeyDatabaseEditDialog.cpp @@ -28,15 +28,19 @@ #include "KeyDatabaseEditDialog.h" +#include "core/utils/GpgUtils.h" #include "core/utils/MemoryUtils.h" #include "ui_KeyDatabaseEditDialog.h" namespace GpgFrontend::UI { KeyDatabaseEditDialog::KeyDatabaseEditDialog(QWidget* parent) : GeneralDialog("KeyDatabaseEditDialog", parent), - ui_(GpgFrontend::SecureCreateSharedObject<Ui_KeyDatabaseEditDialog>()) { + ui_(GpgFrontend::SecureCreateSharedObject<Ui_KeyDatabaseEditDialog>()), + key_database_infos_(GetGpgKeyDatabaseInfos()) { ui_->setupUi(this); + ui_->keyDBPathShowLabel->setHidden(true); + ui_->keyDBNameLabel->setText(tr("Key Database Name")); ui_->keyDBPathLabel->setText(tr("Key Database Path")); ui_->selectKeyDBButton->setText(tr("Select A Key Database Path")); @@ -53,13 +57,15 @@ KeyDatabaseEditDialog::KeyDatabaseEditDialog(QWidget* parent) "exists readable directory.")); } - path_ = QFileInfo(path).absoluteFilePath(); - ui_->keyDBPathShowLabel->setText(path_); + if (!path.trimmed().isEmpty()) { + path_ = QFileInfo(path).absoluteFilePath(); + ui_->keyDBPathShowLabel->setText(path_); + ui_->keyDBPathShowLabel->setHidden(false); + } }); connect(ui_->buttonBox, &QDialogButtonBox::accepted, this, &KeyDatabaseEditDialog::slot_button_box_accepted); - connect(ui_->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(ui_->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); setAttribute(Qt::WA_DeleteOnClose); setModal(true); @@ -67,7 +73,29 @@ KeyDatabaseEditDialog::KeyDatabaseEditDialog(QWidget* parent) void KeyDatabaseEditDialog::slot_button_box_accepted() { name_ = ui_->keyDBNameLineEdit->text(); + + if (name_.isEmpty()) { + slot_show_err_msg(tr("The key database name cannot be empty.")); + return; + } + + if (path_.isEmpty()) { + slot_show_err_msg(tr("The key database path cannot be empty.")); + return; + } + + for (const auto& info : key_database_infos_) { + if (info.name == name_) { + slot_show_err_msg(tr("A key database with the name '%1' already exists. " + "Please choose a different name.") + .arg(name_)); + return; + } + } + + slot_clear_err_msg(); emit SignalKeyDatabaseInfoAccepted(name_, path_); + this->accept(); } auto KeyDatabaseEditDialog::check_custom_gnupg_key_database_path( @@ -82,8 +110,18 @@ void KeyDatabaseEditDialog::SetDefaultName(QString name) { name_ = std::move(name); } -void KeyDatabaseEditDialog::SetDefaultPath(QString path) { +void KeyDatabaseEditDialog::SetDefaultPath(const QString& path) { path_ = QFileInfo(path).absoluteFilePath(); ui_->keyDBPathShowLabel->setText(path_); } +void KeyDatabaseEditDialog::slot_show_err_msg(const QString& error_msg) { + ui_->errorLabel->setText(error_msg); + ui_->errorLabel->setStyleSheet("color: red;"); + ui_->errorLabel->setHidden(false); +} + +void KeyDatabaseEditDialog::slot_clear_err_msg() { + ui_->errorLabel->setText({}); + ui_->errorLabel->setHidden(true); +} }; // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/dialog/KeyDatabaseEditDialog.h b/src/ui/dialog/KeyDatabaseEditDialog.h index 287a97df..234bdc82 100644 --- a/src/ui/dialog/KeyDatabaseEditDialog.h +++ b/src/ui/dialog/KeyDatabaseEditDialog.h @@ -30,6 +30,7 @@ #include <utility> +#include "core/model/KeyDatabaseInfo.h" #include "ui/dialog/GeneralDialog.h" class Ui_KeyDatabaseEditDialog; @@ -42,7 +43,7 @@ class KeyDatabaseEditDialog : public GeneralDialog { void SetDefaultName(QString name); - void SetDefaultPath(QString path); + void SetDefaultPath(const QString& path); signals: void SignalKeyDatabaseInfoAccepted(QString name, QString path); @@ -51,9 +52,14 @@ class KeyDatabaseEditDialog : public GeneralDialog { std::shared_ptr<Ui_KeyDatabaseEditDialog> ui_; ///< QString name_; QString path_; + QList<KeyDatabaseInfo> key_database_infos_; void slot_button_box_accepted(); + void slot_show_err_msg(const QString& error_msg); + + void slot_clear_err_msg(); + auto check_custom_gnupg_key_database_path(const QString& path) -> bool; }; |