aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/key_generate
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/dialog/key_generate')
-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
5 files changed, 171 insertions, 21 deletions
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_) {