8#include "ui_keygendialog.h"
11#include <QRegularExpression>
28 bool hasSavedGeometry = !savedGeometry.isEmpty();
29 if (hasSavedGeometry) {
30 restoreGeometry(savedGeometry);
34 }
else if (hasSavedGeometry) {
54void KeygenDialog::on_passphrase1_textChanged(
const QString &arg1) {
55 bool state = ui->passphrase1->text() == ui->passphrase2->text();
57 replace(
"Passphrase", arg1);
58 no_protection(arg1.isEmpty());
61 ui->buttonBox->setEnabled(state);
69void KeygenDialog::on_passphrase2_textChanged(
const QString &arg1) {
70 on_passphrase1_textChanged(arg1);
77void KeygenDialog::on_checkBox_stateChanged(
int arg1) {
78 ui->plainTextEdit->setReadOnly(!arg1);
79 ui->plainTextEdit->setEnabled(arg1);
87void KeygenDialog::on_email_textChanged(
const QString &arg1) {
88 replace(
"Name-Email", arg1);
96void KeygenDialog::on_name_textChanged(
const QString &arg1) {
97 replace(
"Name-Real", arg1);
106void KeygenDialog::replace(
const QString &key,
const QString &value) {
108 QString expert = ui->plainTextEdit->toPlainText();
109#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
110 const QStringList lines =
113 const QStringList lines =
116 for (QString line : lines) {
117 line.replace(QRegularExpression(key +
":.*"), key +
": " + value);
118 if (key ==
"Passphrase") {
119 line.replace(
"%no-protection",
"Passphrase: " + value);
123 ui->plainTextEdit->setPlainText(clear.join(
"\n"));
131void KeygenDialog::no_protection(
bool enable) {
133 QString expert = ui->plainTextEdit->toPlainText();
134#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
135 const QStringList lines =
138 const QStringList lines =
141 for (QString line : lines) {
144 if (line.indexOf(
"%no-protection") == 0) {
148 if (line.indexOf(
"Passphrase") == 0) {
149 line =
"%no-protection";
156 ui->plainTextEdit->setPlainText(clear.join(
"\n"));
164void KeygenDialog::done(
int r) {
165 if (QDialog::Accepted == r) {
167 if (ui->name->text().length() < 5) {
168 QMessageBox::critical(
this, tr(
"Invalid name"),
169 tr(
"Name must be at least 5 characters long."));
174 static const QRegularExpression mailre(
175 QRegularExpression::anchoredPattern(
176 R
"(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b)"),
177 QRegularExpression::CaseInsensitiveOption);
178 if (!mailre.match(ui->email->text()).hasMatch()) {
179 QMessageBox::critical(
180 this, tr(
"Invalid email"),
181 tr(
"The email address you typed is not a valid email address."));
185 ui->widget->setEnabled(
false);
186 ui->buttonBox->setEnabled(
false);
187 ui->checkBox->setEnabled(
false);
188 ui->plainTextEdit->setEnabled(
false);
190 auto *pi =
new QProgressIndicator();
191 pi->startAnimation();
192 pi->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
196 tr(
"This operation can take some minutes.<br />"
197 "We need to generate a lot of random bytes. It is a good idea to "
198 "perform some other action (type on the keyboard, move the mouse, "
199 "utilize the disks) during the prime generation; this gives the "
200 "random number generator a better chance to gain enough entropy."));
202 this->layout()->addWidget(pi);
205 dialog->genKey(ui->plainTextEdit->toPlainText(),
this);
218 if (!isMaximized()) {
The ConfigDialog handles the configuration interface.
void closeEvent(QCloseEvent *event) override
KeygenDialog::closeEvent we are done here.
KeygenDialog(ConfigDialog *parent=nullptr)
KeygenDialog::KeygenDialog basic constructor.
~KeygenDialog() override
KeygenDialog::~KeygenDialog even more basic destructor.
static QString getDefaultKeyTemplate()
Get default key template for new GPG keys.
static auto getDialogPos(const QString &key, const QPoint &defaultValue=QVariant().toPoint()) -> QPoint
Get saved dialog position.
static void setDialogPos(const QString &key, const QPoint &pos)
Save dialog position.
static auto getDialogSize(const QString &key, const QSize &defaultValue=QVariant().toSize()) -> QSize
Get saved dialog size.
static void setDialogSize(const QString &key, const QSize &size)
Save dialog size.
static void setDialogMaximized(const QString &key, const bool &maximized)
Save dialog maximized state.
static auto isDialogMaximized(const QString &key, const bool &defaultValue=QVariant().toBool()) -> bool
Get dialog maximized state.
static void setDialogGeometry(const QString &key, const QByteArray &geometry)
Save dialog geometry.
static auto getDialogGeometry(const QString &key, const QByteArray &defaultValue=QVariant().toByteArray()) -> QByteArray
Get saved dialog geometry.
static auto newLinesRegex() -> const QRegularExpression &
Returns a regex to match newline characters.
Debug utilities for QtPass.