aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2025-04-17 15:28:04 +0000
committersaturneric <[email protected]>2025-04-17 15:28:04 +0000
commite276f9e86b161362d6f379ab790476936a0e6208 (patch)
tree65c27e3efcbf113a052bc053e1c2739f4a351217 /src/ui
parentfix: compiler issues on CI (diff)
downloadGpgFrontend-e276f9e86b161362d6f379ab790476936a0e6208.tar.gz
GpgFrontend-e276f9e86b161362d6f379ab790476936a0e6208.zip
feat: generate cark keys
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/UserInterfaceUtils.cpp2
-rw-r--r--src/ui/UserInterfaceUtils.h2
-rw-r--r--src/ui/dialog/KeyDatabaseEditDialog.cpp1
-rw-r--r--src/ui/dialog/KeyDatabaseEditDialog.h2
-rw-r--r--src/ui/dialog/KeyGroupCreationDialog.cpp10
-rw-r--r--src/ui/dialog/KeyGroupCreationDialog.h18
-rw-r--r--src/ui/dialog/KeyGroupManageDialog.cpp2
-rw-r--r--src/ui/dialog/RevocationOptionsDialog.h2
-rw-r--r--src/ui/dialog/controller/GnuPGControllerDialog.h2
-rw-r--r--src/ui/dialog/controller/ModuleControllerDialog.cpp2
-rw-r--r--src/ui/dialog/controller/ModuleControllerDialog.h2
-rw-r--r--src/ui/dialog/controller/SmartCardControllerDialog.cpp18
-rw-r--r--src/ui/dialog/import_export/ExportKeyPackageDialog.h2
-rw-r--r--src/ui/dialog/import_export/KeyImportDetailDialog.cpp4
-rw-r--r--src/ui/dialog/import_export/KeyImportDetailDialog.h4
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.cpp2
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.h2
-rw-r--r--src/ui/dialog/key_generate/GenerateCardKeyDialog.cpp110
-rw-r--r--src/ui/dialog/key_generate/GenerateCardKeyDialog.h58
-rw-r--r--src/ui/dialog/key_generate/KeyGenerateDialog.cpp6
-rw-r--r--src/ui/dialog/key_generate/KeyGenerateDialog.h16
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp9
-rw-r--r--src/ui/dialog/keypair_details/KeyNewUIDDialog.h12
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.h8
-rw-r--r--src/ui/dialog/settings/SettingsAppearance.h2
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.h8
-rw-r--r--src/ui/dialog/settings/SettingsKeyServer.h2
-rw-r--r--src/ui/dialog/settings/SettingsNetwork.h2
-rw-r--r--src/ui/model/GpgKeyTreeProxyModel.cpp5
-rw-r--r--src/ui/thread/KeyServerImportTask.h2
-rw-r--r--src/ui/widgets/FilePage.h2
-rw-r--r--src/ui/widgets/InfoBoardWidget.h2
-rw-r--r--src/ui/widgets/KeyList.h2
-rw-r--r--src/ui/widgets/KeyTreeView.cpp9
-rw-r--r--src/ui/widgets/KeyTreeView.h8
-rw-r--r--src/ui/widgets/PlainTextEditorPage.h2
37 files changed, 239 insertions, 105 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 7cae0648..8d277ab4 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -479,7 +479,7 @@ void CommonUtils::slot_update_key_status() {
void CommonUtils::slot_update_key_from_server_finished(
int channel, bool success, QString err_msg, QByteArray buffer,
- std::shared_ptr<GpgImportInformation> info) {
+ QSharedPointer<GpgImportInformation> info) {
if (!success) {
LOG_W() << "get err from reply: " << buffer;
QMessageBox::critical(nullptr, tr("Error"), err_msg);
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index 9f79cec2..fe912fcf 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -278,7 +278,7 @@ class CommonUtils : public QWidget {
*/
void slot_update_key_from_server_finished(
int channel, bool, QString, QByteArray,
- std::shared_ptr<GpgImportInformation>);
+ QSharedPointer<GpgImportInformation>);
private:
static QScopedPointer<CommonUtils> instance; ///<
diff --git a/src/ui/dialog/KeyDatabaseEditDialog.cpp b/src/ui/dialog/KeyDatabaseEditDialog.cpp
index a4744c85..a9516754 100644
--- a/src/ui/dialog/KeyDatabaseEditDialog.cpp
+++ b/src/ui/dialog/KeyDatabaseEditDialog.cpp
@@ -29,7 +29,6 @@
#include "KeyDatabaseEditDialog.h"
#include "core/function/GlobalSettingStation.h"
-#include "core/struct/settings_object/KeyDatabaseItemSO.h"
#include "core/utils/MemoryUtils.h"
#include "ui_KeyDatabaseEditDialog.h"
diff --git a/src/ui/dialog/KeyDatabaseEditDialog.h b/src/ui/dialog/KeyDatabaseEditDialog.h
index c2e9f435..7e9cdb60 100644
--- a/src/ui/dialog/KeyDatabaseEditDialog.h
+++ b/src/ui/dialog/KeyDatabaseEditDialog.h
@@ -49,7 +49,7 @@ class KeyDatabaseEditDialog : public GeneralDialog {
void SignalKeyDatabaseInfoAccepted(QString name, QString path);
private:
- std::shared_ptr<Ui_KeyDatabaseEditDialog> ui_; ///<
+ QSharedPointer<Ui_KeyDatabaseEditDialog> ui_; ///<
QString default_name_;
QString default_path_;
diff --git a/src/ui/dialog/KeyGroupCreationDialog.cpp b/src/ui/dialog/KeyGroupCreationDialog.cpp
index 16e34536..02642482 100644
--- a/src/ui/dialog/KeyGroupCreationDialog.cpp
+++ b/src/ui/dialog/KeyGroupCreationDialog.cpp
@@ -30,6 +30,7 @@
#include "core/function/gpg/GpgKeyGroupGetter.h"
#include "core/model/GpgKeyGroup.h"
+#include "core/utils/CommonUtils.h"
#include "ui/UISignalStation.h"
namespace GpgFrontend::UI {
@@ -96,9 +97,10 @@ void KeyGroupCreationDialog::slot_create_new_uid() {
error_stream << " " << tr("Name must contain at least five characters.")
<< Qt::endl;
}
- if (email_->text().isEmpty() || !check_email_address(email_->text())) {
+ if (email_->text().isEmpty() || !IsEmailAddress(email_->text())) {
error_stream << " " << tr("Please give a email address.") << Qt::endl;
}
+
auto error_string = error_stream.readAll();
if (error_string.isEmpty()) {
auto p_kg =
@@ -109,9 +111,6 @@ void KeyGroupCreationDialog::slot_create_new_uid() {
emit SignalCreated();
this->close();
} else {
- /**
- * create error message
- */
error_label_->setAutoFillBackground(true);
QPalette error = error_label_->palette();
error.setColor(QPalette::Window, "#ff8080");
@@ -124,7 +123,4 @@ void KeyGroupCreationDialog::slot_create_new_uid() {
}
}
-auto KeyGroupCreationDialog::check_email_address(const QString& str) -> bool {
- return re_email_.match(str).hasMatch();
-}
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/KeyGroupCreationDialog.h b/src/ui/dialog/KeyGroupCreationDialog.h
index 634c9148..d03c2cbc 100644
--- a/src/ui/dialog/KeyGroupCreationDialog.h
+++ b/src/ui/dialog/KeyGroupCreationDialog.h
@@ -28,11 +28,7 @@
#pragma once
-#include "core/function/gpg/GpgContext.h"
-#include "core/model/GpgKey.h"
-#include "core/typedef/GpgTypedef.h"
#include "ui/dialog/GeneralDialog.h"
-
namespace GpgFrontend::UI {
class KeyGroupCreationDialog : public GeneralDialog {
Q_OBJECT
@@ -45,7 +41,7 @@ class KeyGroupCreationDialog : public GeneralDialog {
* @param parent
*/
KeyGroupCreationDialog(int channel, QStringList key_ids,
- QWidget* parent = nullptr);
+ QWidget* parent = nullptr);
signals:
/**
@@ -74,17 +70,5 @@ class KeyGroupCreationDialog : public GeneralDialog {
QStringList error_messages_; ///<
QLabel* error_label_{}; ///<
-
- QRegularExpression re_email_{
- R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"};
-
- /**
- * @brief
- *
- * @param str
- * @return true
- * @return false
- */
- auto check_email_address(const QString& str) -> bool;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/KeyGroupManageDialog.cpp b/src/ui/dialog/KeyGroupManageDialog.cpp
index d7b9b3d3..59d54f20 100644
--- a/src/ui/dialog/KeyGroupManageDialog.cpp
+++ b/src/ui/dialog/KeyGroupManageDialog.cpp
@@ -88,7 +88,7 @@ KeyGroupManageDialog::KeyGroupManageDialog(
ui_->removeButton->setDisabled(true);
ui_->keyGroupTipLabel->setText(tr("Key(s) in Key Group: "));
- ui_->keyDBTipLabel->setText(tr("Key(s) in Key Dayabase: "));
+ ui_->keyDBTipLabel->setText(tr("Key(s) in Key Database: "));
QTimer::singleShot(200, [=]() { slot_notify_invalid_key_ids(); });
diff --git a/src/ui/dialog/RevocationOptionsDialog.h b/src/ui/dialog/RevocationOptionsDialog.h
index 1ccdaac3..c9b18b35 100644
--- a/src/ui/dialog/RevocationOptionsDialog.h
+++ b/src/ui/dialog/RevocationOptionsDialog.h
@@ -46,7 +46,7 @@ class RevocationOptionsDialog : public GeneralDialog {
void SignalRevokeOptionAccepted(int code, QString text);
private:
- std::shared_ptr<Ui_RevocationOptionsDialog> ui_; ///<
+ QSharedPointer<Ui_RevocationOptionsDialog> ui_; ///<
int code_;
QString text_;
diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.h b/src/ui/dialog/controller/GnuPGControllerDialog.h
index 3ee129b9..0337b141 100644
--- a/src/ui/dialog/controller/GnuPGControllerDialog.h
+++ b/src/ui/dialog/controller/GnuPGControllerDialog.h
@@ -126,7 +126,7 @@ class GnuPGControllerDialog : public GeneralDialog {
void slot_edit_key_database();
private:
- std::shared_ptr<Ui_GnuPGControllerDialog> ui_; ///<
+ QSharedPointer<Ui_GnuPGControllerDialog> ui_; ///<
const QString app_path_;
int restart_mode_{0}; ///<
QString custom_key_database_path_;
diff --git a/src/ui/dialog/controller/ModuleControllerDialog.cpp b/src/ui/dialog/controller/ModuleControllerDialog.cpp
index 2ad13151..f9b8e58f 100644
--- a/src/ui/dialog/controller/ModuleControllerDialog.cpp
+++ b/src/ui/dialog/controller/ModuleControllerDialog.cpp
@@ -41,7 +41,7 @@ namespace GpgFrontend::UI {
ModuleControllerDialog::ModuleControllerDialog(QWidget* parent)
: GeneralDialog("ModuleControllerDialog", parent),
- ui_(std::make_shared<Ui_ModuleControllerDialog>()),
+ ui_(QSharedPointer<Ui_ModuleControllerDialog>::create()),
module_manager_(&Module::ModuleManager::GetInstance()) {
ui_->setupUi(this);
ui_->actionsGroupBox->hide();
diff --git a/src/ui/dialog/controller/ModuleControllerDialog.h b/src/ui/dialog/controller/ModuleControllerDialog.h
index 94520a76..455a39c8 100644
--- a/src/ui/dialog/controller/ModuleControllerDialog.h
+++ b/src/ui/dialog/controller/ModuleControllerDialog.h
@@ -55,7 +55,7 @@ class ModuleControllerDialog : public GeneralDialog {
void slot_load_module_details(Module::ModuleIdentifier);
private:
- std::shared_ptr<Ui_ModuleControllerDialog> ui_; ///<
+ QSharedPointer<Ui_ModuleControllerDialog> ui_; ///<
Module::ModuleManager* module_manager_;
};
diff --git a/src/ui/dialog/controller/SmartCardControllerDialog.cpp b/src/ui/dialog/controller/SmartCardControllerDialog.cpp
index b48d49af..fb812ad6 100644
--- a/src/ui/dialog/controller/SmartCardControllerDialog.cpp
+++ b/src/ui/dialog/controller/SmartCardControllerDialog.cpp
@@ -29,12 +29,11 @@
#include "SmartCardControllerDialog.h"
#include "core/function/gpg/GpgAdvancedOperator.h"
-#include "core/function/gpg/GpgAssuanHelper.h"
#include "core/function/gpg/GpgCommandExecutor.h"
#include "core/function/gpg/GpgSmartCardManager.h"
-#include "core/module/ModuleManager.h"
#include "core/utils/GpgUtils.h"
#include "ui/UISignalStation.h"
+#include "ui/dialog/key_generate/GenerateCardKeyDialog.h"
//
#include "ui_SmartCardControllerDialog.h"
@@ -59,6 +58,7 @@ SmartCardControllerDialog::SmartCardControllerDialog(QWidget* parent)
ui_->cResetCodeButton->setText(tr("Change Reset Code"));
ui_->fetchButton->setText(tr("Fetch"));
ui_->restartGpgAgentButton->setText(tr("Restart All Gpg-Agents"));
+ ui_->generateKeysButton->setText(tr("Generate Card Keys"));
ui_->refreshButton->setText(tr("Refresh"));
ui_->operationGroupBox->setTitle(tr("Operations"));
@@ -122,6 +122,16 @@ SmartCardControllerDialog::SmartCardControllerDialog(QWidget* parent)
});
});
+ connect(ui_->generateKeysButton, &QPushButton::clicked, this, [=](bool) {
+ auto serial_number = ui_->currentCardComboBox->currentText();
+ auto* d = new GenerateCardKeyDialog(channel_, serial_number, this);
+ connect(d, &GenerateCardKeyDialog::finished, this, [=](int ret) {
+ if (ret == 1) {
+ fetch_smart_card_info(serial_number);
+ }
+ });
+ });
+
connect(UISignalStation::GetInstance(),
&UISignalStation::SignalKeyDatabaseRefreshDone, this, [=]() {
refresh_key_tree_view(ui_->keyDBIndexComboBox->currentIndex());
@@ -325,17 +335,19 @@ void SmartCardControllerDialog::slot_refresh() {
void SmartCardControllerDialog::refresh_key_tree_view(int channel) {
if (!has_card_) return;
+ ui_->cardKeysTreeView->SetChannel(channel);
+
QStringList card_fprs;
for (const auto& key_info : card_info_.card_keys_info.values()) {
card_fprs.append(key_info.fingerprint);
}
+ LOG_D() << "card key fingerprints:" << card_fprs;
if (card_fprs.isEmpty()) {
ui_->cardKeysTreeView->SetKeyFilter([](auto) { return false; });
return;
}
- ui_->cardKeysTreeView->SetChannel(channel);
ui_->cardKeysTreeView->SetKeyFilter([=](const GpgAbstractKey* k) {
return card_fprs.contains(k->Fingerprint());
});
diff --git a/src/ui/dialog/import_export/ExportKeyPackageDialog.h b/src/ui/dialog/import_export/ExportKeyPackageDialog.h
index f457e405..6698ecac 100644
--- a/src/ui/dialog/import_export/ExportKeyPackageDialog.h
+++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.h
@@ -54,7 +54,7 @@ class ExportKeyPackageDialog : public GeneralDialog {
QWidget* parent);
private:
- std::shared_ptr<Ui_exportKeyPackageDialog> ui_; ///<
+ QSharedPointer<Ui_exportKeyPackageDialog> ui_; ///<
int current_gpg_context_channel_;
GpgAbstractKeyPtrList keys_; ///<
QString passphrase_; ///<
diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
index 92e45eb6..ea1cd478 100644
--- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
+++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
@@ -33,7 +33,7 @@
namespace GpgFrontend::UI {
KeyImportDetailDialog::KeyImportDetailDialog(
- int channel, std::shared_ptr<GpgImportInformation> result, QWidget* parent)
+ int channel, QSharedPointer<GpgImportInformation> result, QWidget* parent)
: GeneralDialog(typeid(KeyImportDetailDialog).name(), parent),
current_gpg_context_channel_(channel),
m_result_(std::move(result)) {
@@ -147,7 +147,7 @@ void KeyImportDetailDialog::create_keys_table() {
int row = 0;
for (const auto& imp_key : m_result_->imported_keys) {
keys_table_->setRowCount(row + 1);
-
+
auto key = GpgAbstractKeyGetter::GetInstance(current_gpg_context_channel_)
.GetKey(imp_key.fpr);
if (key == nullptr) continue;
diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.h b/src/ui/dialog/import_export/KeyImportDetailDialog.h
index 3058f6a3..f0bf815a 100644
--- a/src/ui/dialog/import_export/KeyImportDetailDialog.h
+++ b/src/ui/dialog/import_export/KeyImportDetailDialog.h
@@ -53,7 +53,7 @@ class KeyImportDetailDialog : public GeneralDialog {
* @param parent
*/
explicit KeyImportDetailDialog(int channel,
- std::shared_ptr<GpgImportInformation> result,
+ QSharedPointer<GpgImportInformation> result,
QWidget* parent = nullptr);
private:
@@ -89,6 +89,6 @@ class KeyImportDetailDialog : public GeneralDialog {
QDialogButtonBox* button_box_{}; ///<
int current_gpg_context_channel_;
- std::shared_ptr<GpgImportInformation> m_result_; ///<
+ QSharedPointer<GpgImportInformation> m_result_; ///<
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
index ad80f1a1..37ca5a3d 100644
--- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
@@ -408,7 +408,7 @@ void KeyServerImportDialog::SlotImport(QStringList key_ids,
void KeyServerImportDialog::slot_import_finished(
int channel, bool success, QString err_msg, QByteArray buffer,
- std::shared_ptr<GpgImportInformation> info) {
+ QSharedPointer<GpgImportInformation> info) {
set_loading(false);
if (!success) {
diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.h b/src/ui/dialog/import_export/KeyServerImportDialog.h
index 25c55c3e..529cd9fc 100644
--- a/src/ui/dialog/import_export/KeyServerImportDialog.h
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.h
@@ -99,7 +99,7 @@ class KeyServerImportDialog : public GeneralDialog {
*/
void slot_import_finished(int channel, bool success, QString err_msg,
QByteArray buffer,
- std::shared_ptr<GpgImportInformation> info);
+ QSharedPointer<GpgImportInformation> info);
/**
* @brief
diff --git a/src/ui/dialog/key_generate/GenerateCardKeyDialog.cpp b/src/ui/dialog/key_generate/GenerateCardKeyDialog.cpp
new file mode 100644
index 00000000..91498d43
--- /dev/null
+++ b/src/ui/dialog/key_generate/GenerateCardKeyDialog.cpp
@@ -0,0 +1,110 @@
+/**
+ * Copyright (C) 2021-2024 Saturneric <[email protected]>
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ *
+ * 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 <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "GenerateCardKeyDialog.h"
+
+#include "core/function/gpg/GpgSmartCardManager.h"
+#include "core/utils/CommonUtils.h"
+#include "ui/UISignalStation.h"
+#include "ui/function/GpgOperaHelper.h"
+
+//
+#include "ui_GenerateCardKeyDialog.h"
+
+namespace GpgFrontend::UI {
+
+GenerateCardKeyDialog::GenerateCardKeyDialog(int channel,
+ const QString& serial_number,
+ QWidget* parent)
+ : GeneralDialog("GenerateCardKeyDialog", parent),
+ channel_(channel),
+ serial_number_(serial_number),
+ ui_(QSharedPointer<Ui_GenerateCardKeyDialog>::create()) {
+ ui_->setupUi(this);
+
+ const auto min_date_time = QDateTime::currentDateTime().addDays(3);
+ ui_->dateEdit->setMinimumDateTime(min_date_time);
+
+ connect(ui_->generateButton, &QPushButton::clicked, this,
+ &GenerateCardKeyDialog::slot_generate_card_key);
+
+ movePosition2CenterOfParent();
+
+ this->show();
+ this->raise();
+ this->activateWindow();
+}
+
+void GenerateCardKeyDialog::slot_generate_card_key() {
+ QString buffer;
+ QTextStream error_stream(&buffer);
+
+ if ((ui_->nameEdit->text()).size() < 5) {
+ error_stream << " " << tr("Name must contain at least five characters.")
+ << Qt::endl;
+ }
+
+ if (ui_->nameEdit->text().isEmpty() ||
+ !IsEmailAddress(ui_->emailEdit->text())) {
+ error_stream << " " << tr("Please give a email address.") << Qt::endl;
+ }
+
+ auto error_string = error_stream.readAll();
+ if (!error_string.isEmpty()) {
+ ui_->errLabel->setAutoFillBackground(true);
+ QPalette error = ui_->errLabel->palette();
+ error.setColor(QPalette::Window, "#ff8080");
+ ui_->errLabel->setPalette(error);
+ ui_->errLabel->setText(error_string);
+
+ this->show();
+ this->raise();
+ this->activateWindow();
+ return;
+ }
+
+ auto f = [=](const OperaWaitingHd& hd) {
+ auto [ret, err] = GpgSmartCardManager::GetInstance(channel_).GenerateKey(
+ serial_number_, ui_->nameEdit->text(), ui_->emailEdit->text(),
+ ui_->commentEdit->text(), ui_->dateEdit->dateTime(),
+ ui_->nonExpireCheckBox->isChecked());
+
+ hd();
+
+ UISignalStation::GetInstance()->SignalKeyDatabaseRefresh();
+
+ connect(UISignalStation::GetInstance(),
+ &UISignalStation::SignalKeyDatabaseRefreshDone, this,
+ [=, ret = ret]() {
+ emit finished(ret ? 1 : -1);
+ this->close();
+ });
+ };
+ GpgOperaHelper::WaitForOpera(this, tr("Generating"), f);
+}
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/dialog/key_generate/GenerateCardKeyDialog.h b/src/ui/dialog/key_generate/GenerateCardKeyDialog.h
new file mode 100644
index 00000000..93df5aaa
--- /dev/null
+++ b/src/ui/dialog/key_generate/GenerateCardKeyDialog.h
@@ -0,0 +1,58 @@
+/**
+ * Copyright (C) 2021-2024 Saturneric <[email protected]>
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ *
+ * 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 <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+#include "ui/dialog/GeneralDialog.h"
+
+class Ui_GenerateCardKeyDialog;
+
+namespace GpgFrontend::UI {
+class GenerateCardKeyDialog : public GeneralDialog {
+ public:
+ /**
+ * @brief Construct a new Generate Card Key Dialog object
+ *
+ * @param parent
+ */
+ explicit GenerateCardKeyDialog(int channel_, const QString& serial_number,
+ QWidget* parent);
+
+ private:
+ /**
+ * @brief
+ *
+ */
+ void slot_generate_card_key();
+
+ private:
+ int channel_;
+ const QString& serial_number_;
+ QSharedPointer<Ui_GenerateCardKeyDialog> ui_; ///<
+};
+}; // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp
index 0a2dbe1a..d738029d 100644
--- a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp
@@ -157,7 +157,7 @@ void KeyGenerateDialog::slot_key_gen_accept() {
<< Qt::endl;
}
if (ui_->emailEdit->text().isEmpty() ||
- !check_email_address(ui_->emailEdit->text())) {
+ !IsEmailAddress(ui_->emailEdit->text())) {
err_stream << " -> " << tr("Please give a valid email address.")
<< Qt::endl;
}
@@ -454,10 +454,6 @@ void KeyGenerateDialog::set_signal_slot_config() {
&UISignalStation::SignalKeyDatabaseRefresh);
}
-auto KeyGenerateDialog::check_email_address(const QString& str) -> bool {
- return re_email_.match(str).hasMatch();
-}
-
void KeyGenerateDialog::sync_gen_key_algo_info() {
auto [found, algo] = GetAlgoByName(ui_->pAlgoComboBox->currentText(),
diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.h b/src/ui/dialog/key_generate/KeyGenerateDialog.h
index ad927446..6217d520 100644
--- a/src/ui/dialog/key_generate/KeyGenerateDialog.h
+++ b/src/ui/dialog/key_generate/KeyGenerateDialog.h
@@ -105,13 +105,6 @@ class KeyGenerateDialog : public GeneralDialog {
* @brief
*
*/
- QRegularExpression re_email_{
- R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"};
-
- /**
- * @brief
- *
- */
QStringList error_messages_; ///< List of errors occurring when checking
///< entries of line edits
@@ -138,15 +131,6 @@ class KeyGenerateDialog : public GeneralDialog {
/**
* @brief
*
- * @param str
- * @return true
- * @return false
- */
- auto check_email_address(const QString& str) -> bool;
-
- /**
- * @brief
- *
*/
void sync_gen_key_algo_info();
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index b182e017..fd592733 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -66,6 +66,8 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, GpgKeyPtr key,
const auto min_date_time = QDateTime::currentDateTime().addDays(3);
ui_->expireDateTimeEdit->setMinimumDateTime(min_date_time);
+ ui_->expireDateTimeEdit->setDateTime(
+ QDateTime::currentDateTime().addYears(2));
QSet<QString> algo_set;
for (const auto& algo : supported_subkey_algos_) {
diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
index 6a6745da..37688b44 100644
--- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
@@ -29,6 +29,7 @@
#include "KeyNewUIDDialog.h"
#include "core/function/gpg/GpgUIDOperator.h"
+#include "core/utils/CommonUtils.h"
#include "ui/UISignalStation.h"
namespace GpgFrontend::UI {
@@ -81,14 +82,11 @@ void KeyNewUIDDialog::slot_create_new_uid() {
QString buffer;
QTextStream error_stream(&buffer);
- /**
- * check for errors in keygen dialog input
- */
if ((name_->text()).size() < 5) {
error_stream << " " << tr("Name must contain at least five characters.")
<< Qt::endl;
}
- if (email_->text().isEmpty() || !check_email_address(email_->text())) {
+ if (email_->text().isEmpty() || !IsEmailAddress(email_->text())) {
error_stream << " " << tr("Please give a email address.") << Qt::endl;
}
auto error_string = error_stream.readAll();
@@ -117,7 +115,4 @@ void KeyNewUIDDialog::slot_create_new_uid() {
}
}
-auto KeyNewUIDDialog::check_email_address(const QString& str) -> bool {
- return re_email_.match(str).hasMatch();
-}
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.h b/src/ui/dialog/keypair_details/KeyNewUIDDialog.h
index f298a46b..f6ab93e5 100644
--- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.h
+++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.h
@@ -74,17 +74,5 @@ class KeyNewUIDDialog : public GeneralDialog {
QStringList error_messages_; ///<
QLabel* error_label_{}; ///<
-
- QRegularExpression re_email_{
- R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"};
-
- /**
- * @brief
- *
- * @param str
- * @return true
- * @return false
- */
- auto check_email_address(const QString& str) -> bool;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h
index b75339a0..55d09b4b 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h
@@ -75,10 +75,10 @@ class KeySetExpireDateDialog : public GeneralDialog {
*/
void init();
- std::shared_ptr<Ui_ModifiedExpirationDateTime> ui_; ///<
- int current_gpg_context_channel_; ///<
- const GpgKeyPtr m_key_; ///<
- const SubkeyId m_subkey_; ///<
+ QSharedPointer<Ui_ModifiedExpirationDateTime> ui_; ///<
+ int current_gpg_context_channel_; ///<
+ const GpgKeyPtr m_key_; ///<
+ const SubkeyId m_subkey_; ///<
private slots:
/**
diff --git a/src/ui/dialog/settings/SettingsAppearance.h b/src/ui/dialog/settings/SettingsAppearance.h
index 388234f7..fb50522c 100644
--- a/src/ui/dialog/settings/SettingsAppearance.h
+++ b/src/ui/dialog/settings/SettingsAppearance.h
@@ -58,7 +58,7 @@ class AppearanceTab : public QWidget {
void ApplySettings();
private:
- std::shared_ptr<Ui_AppearanceSettings> ui_; ///<
+ QSharedPointer<Ui_AppearanceSettings> ui_; ///<
QButtonGroup* icon_style_group_; ///<
QButtonGroup* icon_size_group_;
diff --git a/src/ui/dialog/settings/SettingsGeneral.h b/src/ui/dialog/settings/SettingsGeneral.h
index 2bd717d0..25cf7e41 100644
--- a/src/ui/dialog/settings/SettingsGeneral.h
+++ b/src/ui/dialog/settings/SettingsGeneral.h
@@ -80,9 +80,9 @@ class GeneralTab : public QWidget {
void SignalDeepRestartNeeded();
private:
- std::shared_ptr<Ui_GeneralSettings> ui_; ///<
- QHash<QString, QString> lang_; ///<
- QStringList key_ids_list_; ///<
- KeyList* m_key_list_{}; ///<
+ QSharedPointer<Ui_GeneralSettings> ui_; ///<
+ QHash<QString, QString> lang_; ///<
+ QStringList key_ids_list_; ///<
+ KeyList* m_key_list_{}; ///<
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/settings/SettingsKeyServer.h b/src/ui/dialog/settings/SettingsKeyServer.h
index b280cf9d..133f69d2 100644
--- a/src/ui/dialog/settings/SettingsKeyServer.h
+++ b/src/ui/dialog/settings/SettingsKeyServer.h
@@ -61,7 +61,7 @@ class KeyserverTab : public QWidget {
void ApplySettings();
private:
- std::shared_ptr<Ui_KeyServerSettings> ui_;
+ QSharedPointer<Ui_KeyServerSettings> ui_;
QString default_key_server_;
QStringList key_server_str_list_;
QMenu* popup_menu_{};
diff --git a/src/ui/dialog/settings/SettingsNetwork.h b/src/ui/dialog/settings/SettingsNetwork.h
index 5d598a6c..a6dd613d 100644
--- a/src/ui/dialog/settings/SettingsNetwork.h
+++ b/src/ui/dialog/settings/SettingsNetwork.h
@@ -67,7 +67,7 @@ class NetworkTab : public QWidget {
void slot_test_proxy_connection_result();
private:
- std::shared_ptr<Ui_NetworkSettings> ui_; ///<
+ QSharedPointer<Ui_NetworkSettings> ui_; ///<
QNetworkProxy::ProxyType proxy_type_ = QNetworkProxy::HttpProxy; ///<
/**
diff --git a/src/ui/model/GpgKeyTreeProxyModel.cpp b/src/ui/model/GpgKeyTreeProxyModel.cpp
index bff18dd6..4dd645e9 100644
--- a/src/ui/model/GpgKeyTreeProxyModel.cpp
+++ b/src/ui/model/GpgKeyTreeProxyModel.cpp
@@ -59,9 +59,10 @@ auto GpgKeyTreeProxyModel::filterAcceptsRow(
: nullptr;
const auto *key = i->Key();
+ assert(key != nullptr && key->IsGood());
LOG_D() << "get key: " << key->ID()
- << "from channel: " << model_->GetGpgContextChannel();
- assert(key->IsGood());
+ << "from channel: " << model_->GetGpgContextChannel()
+ << "fingerprint: " << key->Fingerprint();
if (!(display_mode_ & GpgKeyTreeDisplayMode::kPRIVATE_KEY) &&
key->IsPrivateKey()) {
diff --git a/src/ui/thread/KeyServerImportTask.h b/src/ui/thread/KeyServerImportTask.h
index 4e98a43a..84501ff1 100644
--- a/src/ui/thread/KeyServerImportTask.h
+++ b/src/ui/thread/KeyServerImportTask.h
@@ -65,7 +65,7 @@ class KeyServerImportTask : public Thread::Task {
* @param result
*/
void SignalKeyServerImportResult(int, bool, QString, QByteArray,
- std::shared_ptr<GpgImportInformation>);
+ QSharedPointer<GpgImportInformation>);
private slots:
diff --git a/src/ui/widgets/FilePage.h b/src/ui/widgets/FilePage.h
index 7c90b62f..fbf99ae9 100644
--- a/src/ui/widgets/FilePage.h
+++ b/src/ui/widgets/FilePage.h
@@ -119,7 +119,7 @@ class FilePage : public QWidget {
void keyPressEvent(QKeyEvent* event) override;
private:
- std::shared_ptr<Ui_FilePage> ui_; ///<
+ QSharedPointer<Ui_FilePage> ui_; ///<
QCompleter* path_edit_completer_; ///<
QStringListModel* path_complete_model_; ///<
diff --git a/src/ui/widgets/InfoBoardWidget.h b/src/ui/widgets/InfoBoardWidget.h
index c0416e2d..8fbd836a 100644
--- a/src/ui/widgets/InfoBoardWidget.h
+++ b/src/ui/widgets/InfoBoardWidget.h
@@ -122,7 +122,7 @@ class InfoBoardWidget : public QWidget {
void slot_save();
private:
- std::shared_ptr<Ui_InfoBoard> ui_; ///<
+ QSharedPointer<Ui_InfoBoard> ui_; ///<
QTextEdit* m_text_page_{
nullptr}; ///< TextEdit associated to the notification
diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h
index bb48c63b..b2bd8928 100644
--- a/src/ui/widgets/KeyList.h
+++ b/src/ui/widgets/KeyList.h
@@ -318,7 +318,7 @@ class KeyList : public QWidget {
void slot_new_key_group();
private:
- std::shared_ptr<Ui_KeyList> ui_; ///<
+ QSharedPointer<Ui_KeyList> ui_; ///<
std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr; ///<
int current_gpg_context_channel_;
KeyMenuAbility menu_ability_ = KeyMenuAbility::kALL; ///<
diff --git a/src/ui/widgets/KeyTreeView.cpp b/src/ui/widgets/KeyTreeView.cpp
index a6fb23bf..2d4d8d8c 100644
--- a/src/ui/widgets/KeyTreeView.cpp
+++ b/src/ui/widgets/KeyTreeView.cpp
@@ -116,7 +116,7 @@ void KeyTreeView::init() {
});
connect(UISignalStation::GetInstance(),
- &UISignalStation::SignalKeyDatabaseRefresh, this, [=] {
+ &UISignalStation::SignalKeyDatabaseRefreshDone, this, [=] {
model_ = QSharedPointer<GpgKeyTreeModel>::create(
channel_, GpgAbstractKeyGetter::GetInstance(channel_).Fetch(),
[](auto) { return false; }, this);
@@ -143,11 +143,14 @@ void KeyTreeView::SetChannel(int channel) {
}
auto KeyTreeView::GetKeyByIndex(QModelIndex index) -> GpgAbstractKeyPtr {
- auto* i = index.isValid()
- ? static_cast<GpgKeyTreeItem*>(index.internalPointer())
+ auto s_index = proxy_model_.mapToSource(index);
+ auto* i = s_index.isValid()
+ ? static_cast<GpgKeyTreeItem*>(s_index.internalPointer())
: nullptr;
assert(i != nullptr);
return i->SharedKey();
}
+
+void KeyTreeView::Refresh() { SetChannel(channel_); }
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/KeyTreeView.h b/src/ui/widgets/KeyTreeView.h
index af903273..b5a07f29 100644
--- a/src/ui/widgets/KeyTreeView.h
+++ b/src/ui/widgets/KeyTreeView.h
@@ -69,7 +69,7 @@ class KeyTreeView : public QTreeView {
* @param index
* @return GpgAbstractKeyPtr
*/
- static auto GetKeyByIndex(QModelIndex index) -> GpgAbstractKeyPtr;
+ auto GetKeyByIndex(QModelIndex index) -> GpgAbstractKeyPtr;
/**
* @brief Get the All Checked Key Ids object
@@ -99,6 +99,12 @@ class KeyTreeView : public QTreeView {
*/
void SetChannel(int channel);
+ /**
+ * @brief
+ *
+ */
+ void Refresh();
+
protected:
/**
* @brief
diff --git a/src/ui/widgets/PlainTextEditorPage.h b/src/ui/widgets/PlainTextEditorPage.h
index 86ec0a56..8c4f9b12 100644
--- a/src/ui/widgets/PlainTextEditorPage.h
+++ b/src/ui/widgets/PlainTextEditorPage.h
@@ -116,7 +116,7 @@ class PlainTextEditorPage : public QWidget {
void SignalUIBytesDisplayed();
protected:
- std::shared_ptr<Ui_PlainTextEditor> ui_; ///<
+ QSharedPointer<Ui_PlainTextEditor> ui_; ///<
private:
QString full_file_path_; ///< The path to the file handled in the tab