• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IJHack / QtPass / 24750126353

21 Apr 2026 10:39PM UTC coverage: 27.355%. First build
24750126353

Pull #1129

github

web-flow
Merge 909b2576b into ddeb57b55
Pull Request #1129: Fix: QProgressIndicator memory leak and dark mode support

1 of 12 new or added lines in 2 files covered. (8.33%)

1597 of 5838 relevant lines covered (27.36%)

30.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/keygendialog.cpp
1
// SPDX-FileCopyrightText: 2015 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "keygendialog.h"
4
#include "configdialog.h"
5
#include "pass.h"
6
#include "qprogressindicator.h"
7
#include "qtpasssettings.h"
8
#include "ui_keygendialog.h"
9
#include "util.h"
10
#include <QMessageBox>
11
#include <QRegularExpression>
12

13
#ifdef QT_DEBUG
14
#include "debughelper.h"
15
#endif
16

17
/**
18
 * @brief KeygenDialog::KeygenDialog basic constructor.
19
 * @param parent
20
 */
21
KeygenDialog::KeygenDialog(ConfigDialog *parent)
×
NEW
22
    : QDialog(parent), ui(new Ui::KeygenDialog), m_progressIndicator(nullptr) {
×
23
  ui->setupUi(this);
×
24
  dialog = parent;
×
25

26
  // Restore dialog state
27
  QByteArray savedGeometry = QtPassSettings::getDialogGeometry("keygenDialog");
×
28
  bool hasSavedGeometry = !savedGeometry.isEmpty();
29
  if (hasSavedGeometry) {
×
30
    restoreGeometry(savedGeometry);
×
31
  }
32
  if (QtPassSettings::isDialogMaximized("keygenDialog")) {
×
33
    showMaximized();
×
34
  } else if (hasSavedGeometry) {
×
35
    move(QtPassSettings::getDialogPos("keygenDialog"));
×
36
    resize(QtPassSettings::getDialogSize("keygenDialog"));
×
37
  } else {
38
    // Let window manager handle positioning for first launch
39
  }
40

41
  ui->plainTextEdit->setPlainText(Pass::getDefaultKeyTemplate());
×
42
}
×
43

44
/**
45
 * @brief KeygenDialog::~KeygenDialog even more basic destructor.
46
 */
NEW
47
KeygenDialog::~KeygenDialog() {
×
NEW
48
  delete ui;
×
NEW
49
  delete m_progressIndicator;
×
NEW
50
}
×
51

52
/**
53
 * @brief KeygenDialog::on_passphrase1_textChanged see if we want to have
54
 * protection.
55
 * @param arg1
56
 */
57
void KeygenDialog::on_passphrase1_textChanged(const QString &arg1) {
×
58
  bool state = ui->passphrase1->text() == ui->passphrase2->text();
×
59
  if (state) {
×
60
    replace("Passphrase", arg1);
×
61
    no_protection(arg1.isEmpty());
×
62
  }
63

64
  ui->buttonBox->setEnabled(state);
×
65
}
×
66

67
/**
68
 * @brief KeygenDialog::on_passphrase2_textChanged wrapper for
69
 * KeygenDialog::on_passphrase1_textChanged
70
 * @param arg1
71
 */
72
void KeygenDialog::on_passphrase2_textChanged(const QString &arg1) {
×
73
  on_passphrase1_textChanged(arg1);
×
74
}
×
75

76
/**
77
 * @brief KeygenDialog::on_checkBox_stateChanged expert mode enabled / disabled.
78
 * @param arg1
79
 */
80
void KeygenDialog::on_checkBox_stateChanged(int arg1) {
×
81
  ui->plainTextEdit->setReadOnly(!arg1);
×
82
  ui->plainTextEdit->setEnabled(arg1);
×
83
}
×
84

85
/**
86
 * @brief KeygenDialog::on_email_textChanged update the email in keypair
87
 * generation template.
88
 * @param arg1
89
 */
90
void KeygenDialog::on_email_textChanged(const QString &arg1) {
×
91
  replace("Name-Email", arg1);
×
92
}
×
93

94
/**
95
 * @brief KeygenDialog::on_name_textChanged update the name in keypair
96
 * generation template.
97
 * @param arg1
98
 */
99
void KeygenDialog::on_name_textChanged(const QString &arg1) {
×
100
  replace("Name-Real", arg1);
×
101
}
×
102

103
/**
104
 * @brief KeygenDialog::replace do some regex magic. fore replacing Passphrase
105
 * and protection in keypair generation template.
106
 * @param key
107
 * @param value
108
 */
109
void KeygenDialog::replace(const QString &key, const QString &value) {
×
110
  QStringList clear;
×
111
  QString expert = ui->plainTextEdit->toPlainText();
×
112
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
113
  const QStringList lines =
114
      expert.split(Util::newLinesRegex(), Qt::SkipEmptyParts);
×
115
#else
116
  const QStringList lines =
117
      expert.split(Util::newLinesRegex(), QString::SkipEmptyParts);
118
#endif
119
  for (QString line : lines) {
×
120
    line.replace(QRegularExpression(key + ":.*"), key + ": " + value);
×
121
    if (key == "Passphrase") {
×
122
      line.replace("%no-protection", "Passphrase: " + value);
×
123
    }
124
    clear.append(line);
125
  }
126
  ui->plainTextEdit->setPlainText(clear.join("\n"));
×
127
}
×
128

129
/**
130
 * @brief KeygenDialog::no_protection remove protection in keypair generation
131
 * template.
132
 * @param enable
133
 */
134
void KeygenDialog::no_protection(bool enable) {
×
135
  QStringList clear;
×
136
  QString expert = ui->plainTextEdit->toPlainText();
×
137
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
138
  const QStringList lines =
139
      expert.split(Util::newLinesRegex(), Qt::SkipEmptyParts);
×
140
#else
141
  const QStringList lines =
142
      expert.split(Util::newLinesRegex(), QString::SkipEmptyParts);
143
#endif
144
  for (QString line : lines) {
×
145
    bool remove = false;
146
    if (!enable) {
×
147
      if (line.indexOf("%no-protection") == 0) {
×
148
        remove = true;
149
      }
150
    } else {
151
      if (line.indexOf("Passphrase") == 0) {
×
152
        line = "%no-protection";
×
153
      }
154
    }
155
    if (!remove) {
156
      clear.append(line);
157
    }
158
  }
159
  ui->plainTextEdit->setPlainText(clear.join("\n"));
×
160
}
×
161

162
/**
163
 * @brief KeygenDialog::done we are going to create a key pair and show the
164
 * QProgressIndicator and some text since the generation will take some time.
165
 * @param r
166
 */
167
void KeygenDialog::done(int r) {
×
168
  if (QDialog::Accepted == r) { //  ok was pressed
×
169
                                // check name
170
    if (ui->name->text().length() < 5) {
×
171
      QMessageBox::critical(this, tr("Invalid name"),
×
172
                            tr("Name must be at least 5 characters long."));
×
173
      return;
×
174
    }
175

176
    // check email
177
    static const QRegularExpression mailre(
178
        QRegularExpression::anchoredPattern(
×
179
            R"(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b)"),
180
        QRegularExpression::CaseInsensitiveOption);
×
181
    if (!mailre.match(ui->email->text()).hasMatch()) {
×
182
      QMessageBox::critical(
×
183
          this, tr("Invalid email"),
×
184
          tr("The email address you typed is not a valid email address."));
×
185
      return;
×
186
    }
187

188
    ui->widget->setEnabled(false);
×
189
    ui->buttonBox->setEnabled(false);
×
190
    ui->checkBox->setEnabled(false);
×
191
    ui->plainTextEdit->setEnabled(false);
×
192

NEW
193
    m_progressIndicator = new QProgressIndicator();
×
NEW
194
    m_progressIndicator->startAnimation();
×
NEW
195
    m_progressIndicator->setSizePolicy(QSizePolicy::Expanding,
×
196
                                       QSizePolicy::Expanding);
197

198
    ui->frame->hide();
×
199
    ui->label->setText(
×
200
        tr("This operation can take some minutes.<br />"
×
201
           "We need to generate a lot of random bytes. It is a good idea to "
202
           "perform some other action (type on the keyboard, move the mouse, "
203
           "utilize the disks) during the prime generation; this gives the "
204
           "random number generator a better chance to gain enough entropy."));
205

NEW
206
    this->layout()->addWidget(m_progressIndicator);
×
207

208
    this->show();
×
209
    dialog->genKey(ui->plainTextEdit->toPlainText(), this);
×
210
  } else { //  cancel, close or exc was pressed
211
    QDialog::done(r);
×
212
    return;
×
213
  }
214
}
215

216
/**
217
 * @brief KeygenDialog::closeEvent we are done here.
218
 * @param event
219
 */
220
void KeygenDialog::closeEvent(QCloseEvent *event) {
×
221
  QtPassSettings::setDialogGeometry("keygenDialog", saveGeometry());
×
222
  if (!isMaximized()) {
×
223
    QtPassSettings::setDialogPos("keygenDialog", pos());
×
224
    QtPassSettings::setDialogSize("keygenDialog", size());
×
225
  }
226
  QtPassSettings::setDialogMaximized("keygenDialog", isMaximized());
×
227
  event->accept();
228
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc