aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/key_generate/KeygenDialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ui/key_generate/KeygenDialog.cpp (renamed from src/ui/keygen/KeygenDialog.cpp)249
1 files changed, 129 insertions, 120 deletions
diff --git a/src/ui/keygen/KeygenDialog.cpp b/src/ui/key_generate/KeygenDialog.cpp
index 2baa22f4..6df0bcf0 100644
--- a/src/ui/keygen/KeygenDialog.cpp
+++ b/src/ui/key_generate/KeygenDialog.cpp
@@ -1,4 +1,6 @@
/**
+ * Copyright (C) 2021 Saturneric
+ *
* This file is part of GpgFrontend.
*
* GpgFrontend is free software: you can redistribute it and/or modify
@@ -6,33 +8,35 @@
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * Foobar is distributed in the hope that it will be useful,
+ * 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 Foobar. If not, see <https://www.gnu.org/licenses/>.
+ * 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.
*
- * The initial version of the source code is inherited from gpg4usb-team.
- * Their source code version also complies with GNU General Public License.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric<[email protected]> starting on May 12, 2021.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]> starting on May 12, 2021.
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-#include "ui/keygen/KeygenDialog.h"
+#include "ui/key_generate/KeygenDialog.h"
-#include "gpg/function/GpgKeyOpera.h"
+#include "dialog/WaitingDialog.h"
+#include "core/function/gpg/GpgKeyOpera.h"
#include "ui/SignalStation.h"
-#include "ui/WaitingDialog.h"
-#include "ui/settings/GlobalSettingStation.h"
+#include "core/function/GlobalSettingStation.h"
namespace GpgFrontend::UI {
KeyGenDialog::KeyGenDialog(QWidget* parent) : QDialog(parent) {
- buttonBox =
+ button_box_ =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
@@ -54,26 +58,26 @@ KeyGenDialog::KeyGenDialog(QWidget* parent) : QDialog(parent) {
this->setWindowTitle(_("Generate Key"));
this->setModal(true);
- connect(this, SIGNAL(KeyGenerated()), SignalStation::GetInstance(),
- SIGNAL(KeyDatabaseRefresh()));
+ connect(this, &KeyGenDialog::SignalKeyGenerated, SignalStation::GetInstance(),
+ &SignalStation::SignalKeyDatabaseRefresh);
- generateKeyDialog();
+ generate_key_dialog();
}
-void KeyGenDialog::generateKeyDialog() {
- keyUsageGroupBox = create_key_usage_group_box();
+void KeyGenDialog::generate_key_dialog() {
+ key_usage_group_box_ = create_key_usage_group_box();
auto* groupGrid = new QGridLayout(this);
groupGrid->addWidget(create_basic_info_group_box(), 0, 0);
- groupGrid->addWidget(keyUsageGroupBox, 1, 0);
+ groupGrid->addWidget(key_usage_group_box_, 1, 0);
auto* nameList = new QWidget(this);
nameList->setLayout(groupGrid);
auto* vbox2 = new QVBoxLayout();
vbox2->addWidget(nameList);
- vbox2->addWidget(errorLabel);
- vbox2->addWidget(buttonBox);
+ vbox2->addWidget(error_label_);
+ vbox2->addWidget(button_box_);
this->setLayout(vbox2);
@@ -82,17 +86,18 @@ void KeyGenDialog::generateKeyDialog() {
refresh_widgets_state();
}
-void KeyGenDialog::slotKeyGenAccept() {
+void KeyGenDialog::slot_key_gen_accept() {
std::stringstream error_stream;
/**
* check for errors in keygen dialog input
*/
- if ((nameEdit->text()).size() < 5) {
+ if ((name_edit_->text()).size() < 5) {
error_stream << " " << _("Name must contain at least five characters.")
<< std::endl;
}
- if (emailEdit->text().isEmpty() || !check_email_address(emailEdit->text())) {
+ if (email_edit_->text().isEmpty() ||
+ !check_email_address(email_edit_->text())) {
error_stream << " " << _("Please give a email address.") << std::endl;
}
@@ -100,7 +105,7 @@ void KeyGenDialog::slotKeyGenAccept() {
* primary keys should have a reasonable expiration date (no more than 2 years
* in the future)
*/
- if (dateEdit->dateTime() > max_date_time_) {
+ if (date_edit_->dateTime() > max_date_time_) {
error_stream << " " << _("Expiration time too long.") << std::endl;
}
@@ -110,17 +115,17 @@ void KeyGenDialog::slotKeyGenAccept() {
/**
* create the string for key generation
*/
- gen_key_info_->setName(nameEdit->text().toStdString());
- gen_key_info_->setEmail(emailEdit->text().toStdString());
- gen_key_info_->setComment(commentEdit->text().toStdString());
+ gen_key_info_->SetName(name_edit_->text().toStdString());
+ gen_key_info_->SetEmail(email_edit_->text().toStdString());
+ gen_key_info_->SetComment(comment_edit_->text().toStdString());
- gen_key_info_->setKeySize(keySizeSpinBox->value());
+ gen_key_info_->SetKeyLength(key_size_spin_box_->value());
- if (expireCheckBox->checkState()) {
- gen_key_info_->setNonExpired(true);
+ if (expire_check_box_->checkState()) {
+ gen_key_info_->SetNonExpired(true);
} else {
- gen_key_info_->setExpired(
- boost::posix_time::from_time_t(dateEdit->dateTime().toTime_t()));
+ gen_key_info_->SetExpireTime(
+ boost::posix_time::from_time_t(date_edit_->dateTime().toTime_t()));
}
GpgGenKeyResult result;
@@ -148,7 +153,7 @@ void KeyGenDialog::slotKeyGenAccept() {
msg_box->setModal(false);
msg_box->open();
- emit KeyGenerated();
+ emit SignalKeyGenerated();
this->close();
} else {
QMessageBox::critical(this, _("Failure"), _(gpgme_strerror(error)));
@@ -158,21 +163,21 @@ void KeyGenDialog::slotKeyGenAccept() {
/**
* create error message
*/
- errorLabel->setAutoFillBackground(true);
- QPalette error = errorLabel->palette();
+ error_label_->setAutoFillBackground(true);
+ QPalette error = error_label_->palette();
error.setColor(QPalette::Window, "#ff8080");
- errorLabel->setPalette(error);
- errorLabel->setText(err_string.c_str());
+ error_label_->setPalette(error);
+ error_label_->setText(err_string.c_str());
this->show();
}
}
-void KeyGenDialog::slotExpireBoxChanged() {
- if (expireCheckBox->checkState()) {
- dateEdit->setEnabled(false);
+void KeyGenDialog::slot_expire_box_changed() {
+ if (expire_check_box_->checkState()) {
+ date_edit_->setEnabled(false);
} else {
- dateEdit->setEnabled(true);
+ date_edit_->setEnabled(true);
}
}
@@ -209,159 +214,163 @@ QGroupBox* KeyGenDialog::create_key_usage_group_box() {
return groupBox;
}
-void KeyGenDialog::slotEncryptionBoxChanged(int state) {
+void KeyGenDialog::slot_encryption_box_changed(int state) {
if (state == 0) {
- gen_key_info_->setAllowEncryption(false);
+ gen_key_info_->SetAllowEncryption(false);
} else {
- gen_key_info_->setAllowEncryption(true);
+ gen_key_info_->SetAllowEncryption(true);
}
}
-void KeyGenDialog::slotSigningBoxChanged(int state) {
+void KeyGenDialog::slot_signing_box_changed(int state) {
if (state == 0) {
- gen_key_info_->setAllowSigning(false);
+ gen_key_info_->SetAllowSigning(false);
} else {
- gen_key_info_->setAllowSigning(true);
+ gen_key_info_->SetAllowSigning(true);
}
}
-void KeyGenDialog::slotCertificationBoxChanged(int state) {
+void KeyGenDialog::slot_certification_box_changed(int state) {
if (state == 0) {
- gen_key_info_->setAllowCertification(false);
+ gen_key_info_->SetAllowCertification(false);
} else {
- gen_key_info_->setAllowCertification(true);
+ gen_key_info_->SetAllowCertification(true);
}
}
-void KeyGenDialog::slotAuthenticationBoxChanged(int state) {
+void KeyGenDialog::slot_authentication_box_changed(int state) {
if (state == 0) {
- gen_key_info_->setAllowAuthentication(false);
+ gen_key_info_->SetAllowAuthentication(false);
} else {
- gen_key_info_->setAllowAuthentication(true);
+ gen_key_info_->SetAllowAuthentication(true);
}
}
-void KeyGenDialog::slotActivatedKeyType(int index) {
+void KeyGenDialog::slot_activated_key_type(int index) {
qDebug() << "key type index changed " << index;
- gen_key_info_->setAlgo(this->keyTypeComboBox->itemText(index).toStdString());
+ gen_key_info_->SetAlgo(
+ this->key_type_combo_box_->itemText(index).toStdString());
refresh_widgets_state();
}
void KeyGenDialog::refresh_widgets_state() {
qDebug() << "refresh_widgets_state called";
- if (gen_key_info_->isAllowEncryption())
+ if (gen_key_info_->IsAllowEncryption())
key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Checked);
else
key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Unchecked);
- if (gen_key_info_->isAllowChangeEncryption())
+ if (gen_key_info_->IsAllowChangeEncryption())
key_usage_check_boxes_[0]->setDisabled(false);
else
key_usage_check_boxes_[0]->setDisabled(true);
- if (gen_key_info_->isAllowSigning())
+ if (gen_key_info_->IsAllowSigning())
key_usage_check_boxes_[1]->setCheckState(Qt::CheckState::Checked);
else
key_usage_check_boxes_[1]->setCheckState(Qt::CheckState::Unchecked);
- if (gen_key_info_->isAllowChangeSigning())
+ if (gen_key_info_->IsAllowChangeSigning())
key_usage_check_boxes_[1]->setDisabled(false);
else
key_usage_check_boxes_[1]->setDisabled(true);
- if (gen_key_info_->isAllowCertification())
+ if (gen_key_info_->IsAllowCertification())
key_usage_check_boxes_[2]->setCheckState(Qt::CheckState::Checked);
else
key_usage_check_boxes_[2]->setCheckState(Qt::CheckState::Unchecked);
- if (gen_key_info_->isAllowChangeCertification())
+ if (gen_key_info_->IsAllowChangeCertification())
key_usage_check_boxes_[2]->setDisabled(false);
else
key_usage_check_boxes_[2]->setDisabled(true);
- if (gen_key_info_->isAllowAuthentication())
+ if (gen_key_info_->IsAllowAuthentication())
key_usage_check_boxes_[3]->setCheckState(Qt::CheckState::Checked);
else
key_usage_check_boxes_[3]->setCheckState(Qt::CheckState::Unchecked);
- if (gen_key_info_->isAllowChangeAuthentication())
+ if (gen_key_info_->IsAllowChangeAuthentication())
key_usage_check_boxes_[3]->setDisabled(false);
else
key_usage_check_boxes_[3]->setDisabled(true);
- if (gen_key_info_->isAllowNoPassPhrase())
- noPassPhraseCheckBox->setDisabled(false);
+ if (gen_key_info_->IsAllowNoPassPhrase())
+ no_pass_phrase_check_box_->setDisabled(false);
else
- noPassPhraseCheckBox->setDisabled(true);
+ no_pass_phrase_check_box_->setDisabled(true);
- keySizeSpinBox->setRange(gen_key_info_->getSuggestMinKeySize(),
- gen_key_info_->getSuggestMaxKeySize());
- keySizeSpinBox->setValue(gen_key_info_->getKeySize());
- keySizeSpinBox->setSingleStep(gen_key_info_->getSizeChangeStep());
+ key_size_spin_box_->setRange(gen_key_info_->GetSuggestMinKeySize(),
+ gen_key_info_->GetSuggestMaxKeySize());
+ key_size_spin_box_->setValue(gen_key_info_->GetKeyLength());
+ key_size_spin_box_->setSingleStep(gen_key_info_->GetSizeChangeStep());
}
void KeyGenDialog::set_signal_slot() {
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotKeyGenAccept()));
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
-
- connect(expireCheckBox, SIGNAL(stateChanged(int)), this,
- SLOT(slotExpireBoxChanged()));
-
- connect(key_usage_check_boxes_[0], SIGNAL(stateChanged(int)), this,
- SLOT(slotEncryptionBoxChanged(int)));
- connect(key_usage_check_boxes_[1], SIGNAL(stateChanged(int)), this,
- SLOT(slotSigningBoxChanged(int)));
- connect(key_usage_check_boxes_[2], SIGNAL(stateChanged(int)), this,
- SLOT(slotCertificationBoxChanged(int)));
- connect(key_usage_check_boxes_[3], SIGNAL(stateChanged(int)), this,
- SLOT(slotAuthenticationBoxChanged(int)));
-
- connect(keyTypeComboBox, SIGNAL(currentIndexChanged(int)), this,
- SLOT(slotActivatedKeyType(int)));
-
- connect(noPassPhraseCheckBox, &QCheckBox::stateChanged, this,
+ connect(button_box_, &QDialogButtonBox::accepted, this,
+ &KeyGenDialog::slot_key_gen_accept);
+ connect(button_box_, &QDialogButtonBox::rejected, this,
+ &KeyGenDialog::reject);
+
+ connect(expire_check_box_, &QCheckBox::stateChanged, this,
+ &KeyGenDialog::slot_expire_box_changed);
+
+ connect(key_usage_check_boxes_[0], &QCheckBox::stateChanged, this,
+ &KeyGenDialog::slot_encryption_box_changed);
+ connect(key_usage_check_boxes_[1], &QCheckBox::stateChanged, this,
+ &KeyGenDialog::slot_signing_box_changed);
+ connect(key_usage_check_boxes_[2], &QCheckBox::stateChanged, this,
+ &KeyGenDialog::slot_certification_box_changed);
+ connect(key_usage_check_boxes_[3], &QCheckBox::stateChanged, this,
+ &KeyGenDialog::slot_authentication_box_changed);
+
+ connect(key_type_combo_box_, qOverload<int>(&QComboBox::currentIndexChanged),
+ this, &KeyGenDialog::slot_activated_key_type);
+
+ connect(no_pass_phrase_check_box_, &QCheckBox::stateChanged, this,
[this](int state) -> void {
if (state == 0) {
- gen_key_info_->setNonPassPhrase(false);
+ gen_key_info_->SetNonPassPhrase(false);
} else {
- gen_key_info_->setNonPassPhrase(true);
+ gen_key_info_->SetNonPassPhrase(true);
}
});
}
bool KeyGenDialog::check_email_address(const QString& str) {
- return re_email.match(str).hasMatch();
+ return re_email_.match(str).hasMatch();
}
QGroupBox* KeyGenDialog::create_basic_info_group_box() {
- errorLabel = new QLabel();
- nameEdit = new QLineEdit(this);
- emailEdit = new QLineEdit(this);
- commentEdit = new QLineEdit(this);
- keySizeSpinBox = new QSpinBox(this);
- keyTypeComboBox = new QComboBox(this);
-
- for (auto& algo : GenKeyInfo::getSupportedKeyAlgo()) {
- keyTypeComboBox->addItem(QString::fromStdString(algo));
+ error_label_ = new QLabel();
+ name_edit_ = new QLineEdit(this);
+ email_edit_ = new QLineEdit(this);
+ comment_edit_ = new QLineEdit(this);
+ key_size_spin_box_ = new QSpinBox(this);
+ key_type_combo_box_ = new QComboBox(this);
+
+ for (auto& algo : GenKeyInfo::GetSupportedKeyAlgo()) {
+ key_type_combo_box_->addItem(QString::fromStdString(algo));
}
- if (!GenKeyInfo::getSupportedKeyAlgo().empty()) {
- keyTypeComboBox->setCurrentIndex(0);
+ if (!GenKeyInfo::GetSupportedKeyAlgo().empty()) {
+ key_type_combo_box_->setCurrentIndex(0);
}
- dateEdit = new QDateTimeEdit(QDateTime::currentDateTime().addYears(2), this);
- dateEdit->setMinimumDateTime(QDateTime::currentDateTime());
- dateEdit->setMaximumDateTime(max_date_time_);
- dateEdit->setDisplayFormat("dd/MM/yyyy hh:mm:ss");
- dateEdit->setCalendarPopup(true);
- dateEdit->setEnabled(true);
+ date_edit_ =
+ new QDateTimeEdit(QDateTime::currentDateTime().addYears(2), this);
+ date_edit_->setMinimumDateTime(QDateTime::currentDateTime());
+ date_edit_->setMaximumDateTime(max_date_time_);
+ date_edit_->setDisplayFormat("dd/MM/yyyy hh:mm:ss");
+ date_edit_->setCalendarPopup(true);
+ date_edit_->setEnabled(true);
- expireCheckBox = new QCheckBox(this);
- expireCheckBox->setCheckState(Qt::Unchecked);
+ expire_check_box_ = new QCheckBox(this);
+ expire_check_box_->setCheckState(Qt::Unchecked);
- noPassPhraseCheckBox = new QCheckBox(this);
- noPassPhraseCheckBox->setCheckState(Qt::Unchecked);
+ no_pass_phrase_check_box_ = new QCheckBox(this);
+ no_pass_phrase_check_box_->setCheckState(Qt::Unchecked);
auto* vbox1 = new QGridLayout;
@@ -374,14 +383,14 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() {
vbox1->addWidget(new QLabel(QString(_("Key Type")) + ": "), 5, 0);
vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase")) + ": "), 6, 0);
- vbox1->addWidget(nameEdit, 0, 1, 1, 3);
- vbox1->addWidget(emailEdit, 1, 1, 1, 3);
- vbox1->addWidget(commentEdit, 2, 1, 1, 3);
- vbox1->addWidget(dateEdit, 3, 1);
- vbox1->addWidget(expireCheckBox, 3, 2);
- vbox1->addWidget(keySizeSpinBox, 4, 1);
- vbox1->addWidget(keyTypeComboBox, 5, 1);
- vbox1->addWidget(noPassPhraseCheckBox, 6, 1);
+ vbox1->addWidget(name_edit_, 0, 1, 1, 3);
+ vbox1->addWidget(email_edit_, 1, 1, 1, 3);
+ vbox1->addWidget(comment_edit_, 2, 1, 1, 3);
+ vbox1->addWidget(date_edit_, 3, 1);
+ vbox1->addWidget(expire_check_box_, 3, 2);
+ vbox1->addWidget(key_size_spin_box_, 4, 1);
+ vbox1->addWidget(key_type_combo_box_, 5, 1);
+ vbox1->addWidget(no_pass_phrase_check_box_, 6, 1);
auto basicInfoGroupBox = new QGroupBox();
basicInfoGroupBox->setLayout(vbox1);