4#include "ui_keygendialog.h"
6#include <QRegularExpression>
32void KeygenDialog::on_passphrase1_textChanged(
const QString &arg1) {
33 bool state = ui->passphrase1->text() == ui->passphrase2->text();
35 replace(
"Passphrase", arg1);
36 no_protection(arg1.isEmpty());
39 ui->buttonBox->setEnabled(state);
47void KeygenDialog::on_passphrase2_textChanged(
const QString &arg1) {
48 on_passphrase1_textChanged(arg1);
55void KeygenDialog::on_checkBox_stateChanged(
int arg1) {
56 ui->plainTextEdit->setReadOnly(!arg1);
57 ui->plainTextEdit->setEnabled(arg1);
65void KeygenDialog::on_email_textChanged(
const QString &arg1) {
66 replace(
"Name-Email", arg1);
74void KeygenDialog::on_name_textChanged(
const QString &arg1) {
75 replace(
"Name-Real", arg1);
84void KeygenDialog::replace(
const QString &key,
const QString &value) {
86 QString expert = ui->plainTextEdit->toPlainText();
87 static const QRegularExpression newLines{
"[\r\n]"};
88#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
89 const QStringList lines = expert.split(newLines, Qt::SkipEmptyParts);
91 const QStringList lines = expert.split(newLines, QString::SkipEmptyParts);
93 for (QString line : lines) {
94 line.replace(QRegularExpression(key +
":.*"), key +
": " + value);
95 if (key ==
"Passphrase")
96 line.replace(
"%no-protection",
"Passphrase: " + value);
99 ui->plainTextEdit->setPlainText(clear.join(
"\n"));
107void KeygenDialog::no_protection(
bool enable) {
109 QString expert = ui->plainTextEdit->toPlainText();
110 static const QRegularExpression newLines{
"[\r\n]"};
111#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
112 const QStringList lines = expert.split(newLines, Qt::SkipEmptyParts);
114 const QStringList lines = expert.split(newLines, QString::SkipEmptyParts);
116 for (QString line : lines) {
119 if (line.indexOf(
"%no-protection") == 0)
122 if (line.indexOf(
"Passphrase") == 0)
123 line =
"%no-protection";
128 ui->plainTextEdit->setPlainText(clear.join(
"\n"));
136void KeygenDialog::done(
int r) {
137 if (QDialog::Accepted == r) {
139 if (ui->name->text().length() < 5) {
140 QMessageBox::critical(
this, tr(
"Invalid name"),
141 tr(
"Name must be at least 5 characters long."));
146 static const QRegularExpression mailre(
147 QRegularExpression::anchoredPattern(
148 R
"(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)"),
149 QRegularExpression::CaseInsensitiveOption);
150 if (!mailre.match(ui->email->text()).hasMatch()) {
151 QMessageBox::critical(
152 this, tr(
"Invalid email"),
153 tr(
"The email address you typed is not a valid email address."));
157 ui->widget->setEnabled(
false);
158 ui->buttonBox->setEnabled(
false);
159 ui->checkBox->setEnabled(
false);
160 ui->plainTextEdit->setEnabled(
false);
163 pi->startAnimation();
164 pi->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
168 tr(
"This operation can take some minutes.<br />"
169 "We need to generate a lot of random bytes. It is a good idea to "
170 "perform some other action (type on the keyboard, move the mouse, "
171 "utilize the disks) during the prime generation; this gives the "
172 "random number generator a better chance to gain enough entropy."));
174 this->layout()->addWidget(pi);
177 dialog->
genKey(ui->plainTextEdit->toPlainText(),
this);
The ConfigDialog handles the configuration interface.
void genKey(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 ...