6#include "ui_keygendialog.h"
9#include <QRegularExpression>
35void KeygenDialog::on_passphrase1_textChanged(
const QString &arg1) {
36 bool state = ui->passphrase1->text() == ui->passphrase2->text();
38 replace(
"Passphrase", arg1);
39 no_protection(arg1.isEmpty());
42 ui->buttonBox->setEnabled(state);
50void KeygenDialog::on_passphrase2_textChanged(
const QString &arg1) {
51 on_passphrase1_textChanged(arg1);
58void KeygenDialog::on_checkBox_stateChanged(
int arg1) {
59 ui->plainTextEdit->setReadOnly(!arg1);
60 ui->plainTextEdit->setEnabled(arg1);
68void KeygenDialog::on_email_textChanged(
const QString &arg1) {
69 replace(
"Name-Email", arg1);
77void KeygenDialog::on_name_textChanged(
const QString &arg1) {
78 replace(
"Name-Real", arg1);
87void KeygenDialog::replace(
const QString &key,
const QString &value) {
89 QString expert = ui->plainTextEdit->toPlainText();
90#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
91 const QStringList lines =
94 const QStringList lines =
97 for (QString line : lines) {
98 line.replace(QRegularExpression(key +
":.*"), key +
": " + value);
99 if (key ==
"Passphrase") {
100 line.replace(
"%no-protection",
"Passphrase: " + value);
104 ui->plainTextEdit->setPlainText(clear.join(
"\n"));
112void KeygenDialog::no_protection(
bool enable) {
114 QString expert = ui->plainTextEdit->toPlainText();
115#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
116 const QStringList lines =
119 const QStringList lines =
122 for (QString line : lines) {
125 if (line.indexOf(
"%no-protection") == 0) {
129 if (line.indexOf(
"Passphrase") == 0) {
130 line =
"%no-protection";
137 ui->plainTextEdit->setPlainText(clear.join(
"\n"));
145void KeygenDialog::done(
int r) {
146 if (QDialog::Accepted == r) {
148 if (ui->name->text().length() < 5) {
149 QMessageBox::critical(
this, tr(
"Invalid name"),
150 tr(
"Name must be at least 5 characters long."));
155 static const QRegularExpression mailre(
156 QRegularExpression::anchoredPattern(
157 R
"(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b)"),
158 QRegularExpression::CaseInsensitiveOption);
159 if (!mailre.match(ui->email->text()).hasMatch()) {
160 QMessageBox::critical(
161 this, tr(
"Invalid email"),
162 tr(
"The email address you typed is not a valid email address."));
166 ui->widget->setEnabled(
false);
167 ui->buttonBox->setEnabled(
false);
168 ui->checkBox->setEnabled(
false);
169 ui->plainTextEdit->setEnabled(
false);
172 pi->startAnimation();
173 pi->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
177 tr(
"This operation can take some minutes.<br />"
178 "We need to generate a lot of random bytes. It is a good idea to "
179 "perform some other action (type on the keyboard, move the mouse, "
180 "utilize the disks) during the prime generation; this gives the "
181 "random number generator a better chance to gain enough entropy."));
183 this->layout()->addWidget(pi);
186 dialog->
genKey(ui->plainTextEdit->toPlainText(),
this);
The ConfigDialog handles the configuration interface.
void genKey(const QString &, QDialog *)
ConfigDialog::genKey tunnel function to make MainWindow generate a gpg key pair.
Handles GPG keypair generation.
KeygenDialog(ConfigDialog *parent=0)
KeygenDialog::KeygenDialog basic constructor.
void closeEvent(QCloseEvent *event)
KeygenDialog::closeEvent we are done here.
~KeygenDialog()
KeygenDialog::~KeygenDialog even more basic destructor.
The QProgressIndicator class lets an application display a progress indicator to show that a lengthy ...
static auto newLinesRegex() -> const QRegularExpression &