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

IJHack / QtPass / 24638606826

19 Apr 2026 08:38PM UTC coverage: 27.351% (+0.01%) from 27.338%
24638606826

push

github

web-flow
Merge pull request #1082 from IJHack/ai-findings-autofix/src-passworddialog.cpp

fix: modernise passworddialog — typo fix, isEmpty, range-for loop

1 of 2 new or added lines in 1 file covered. (50.0%)

7 existing lines in 1 file now uncovered.

1594 of 5828 relevant lines covered (27.35%)

16.45 hits per line

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

57.8
/src/passworddialog.cpp
1
// SPDX-FileCopyrightText: 2015 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "passworddialog.h"
4
#include "filecontent.h"
5
#include "helpers.h"
6
#include "pass.h"
7
#include "passwordconfiguration.h"
8
#include "qtpasssettings.h"
9
#include "ui_passworddialog.h"
10

11
#include <QLabel>
12
#include <QLineEdit>
13
#include <utility>
14

15
#ifdef QT_DEBUG
16
#include "debughelper.h"
17
#endif
18

19
/**
20
 * @brief PasswordDialog::PasswordDialog basic constructor.
21
 * @param passConfig configuration constant
22
 * @param parent
23
 */
24
PasswordDialog::PasswordDialog(PasswordConfiguration passConfig,
11✔
25
                               QWidget *parent)
11✔
26
    : QDialog(parent), ui(new Ui::PasswordDialog),
22✔
27
      m_passConfig(std::move(passConfig)) {
11✔
28
  m_templating = false;
29
  m_allFields = false;
30
  m_isNew = false;
11✔
31

32
  ui->setupUi(this);
11✔
33
  setLength(m_passConfig.length);
11✔
34
  setPasswordCharTemplate(m_passConfig.selected);
11✔
35

36
  connect(QtPassSettings::getPass(), &Pass::finishedShow, this,
11✔
37
          &PasswordDialog::setPass);
11✔
38
}
11✔
39

40
/**
41
 * @brief PasswordDialog::PasswordDialog complete constructor.
42
 * @param file
43
 * @param isNew
44
 * @param parent pointer
45
 */
46
PasswordDialog::PasswordDialog(QString file, const bool &isNew, QWidget *parent)
×
47
    : QDialog(parent), ui(new Ui::PasswordDialog), m_file(std::move(file)),
×
48
      m_isNew(isNew) {
×
49

50
  if (!isNew) {
×
51
    QtPassSettings::getPass()->Show(m_file);
×
52
  }
53

54
  ui->setupUi(this);
×
55

56
  setWindowTitle(this->windowTitle() + " " + m_file);
×
57
  m_passConfig = QtPassSettings::getPasswordConfiguration();
×
58
  usePwgen(QtPassSettings::isUsePwgen());
×
59
  setTemplate(QtPassSettings::getPassTemplate(),
×
60
              QtPassSettings::isUseTemplate());
×
61
  templateAll(QtPassSettings::isTemplateAllFields());
×
62

63
  setLength(m_passConfig.length);
×
64
  setPasswordCharTemplate(m_passConfig.selected);
×
65

66
  connect(QtPassSettings::getPass(), &Pass::finishedShow, this,
×
67
          &PasswordDialog::setPass);
×
68
  connect(QtPassSettings::getPass(), &Pass::processErrorExit, this,
×
69
          &PasswordDialog::close);
×
70
  connect(this, &PasswordDialog::accepted, this, &PasswordDialog::on_accepted);
×
71
  connect(this, &PasswordDialog::rejected, this, &PasswordDialog::on_rejected);
×
72
}
×
73

74
/**
75
 * @brief PasswordDialog::~PasswordDialog basic destructor.
76
 */
77
PasswordDialog::~PasswordDialog() { delete ui; }
33✔
78

79
/**
80
 * @brief PasswordDialog::on_checkBoxShow_stateChanged hide or show passwords.
81
 * @param arg1
82
 */
83
void PasswordDialog::on_checkBoxShow_stateChanged(int arg1) {
×
84
  if (arg1) {
×
85
    ui->lineEditPassword->setEchoMode(QLineEdit::Normal);
×
86
  } else {
87
    ui->lineEditPassword->setEchoMode(QLineEdit::Password);
×
88
  }
89
}
×
90

91
/**
92
 * @brief PasswordDialog::on_createPasswordButton_clicked generate a random
93
 * password.
94
 */
95
void PasswordDialog::on_createPasswordButton_clicked() {
×
96
  ui->widget->setEnabled(false);
×
97
  QString newPass = QtPassSettings::getPass()->generatePassword(
×
98
      static_cast<unsigned int>(ui->spinBox_pwdLength->value()),
×
99
      m_passConfig.Characters[static_cast<PasswordConfiguration::characterSet>(
100
          ui->passwordTemplateSwitch->currentIndex())]);
×
NEW
101
  if (!newPass.isEmpty()) {
×
102
    ui->lineEditPassword->setText(newPass);
×
103
  }
104
  ui->widget->setEnabled(true);
×
105
}
×
106

107
/**
108
 * @brief PasswordDialog::on_accepted handle Ok click for QDialog
109
 */
110
void PasswordDialog::on_accepted() {
×
111
  QString newValue = getPassword();
×
112
  if (newValue.isEmpty()) {
×
113
    return;
114
  }
115

116
  if (newValue.right(1) != "\n") {
×
117
    newValue += "\n";
×
118
  }
119

120
  QtPassSettings::getPass()->Insert(m_file, newValue, !m_isNew);
×
121
}
122

123
/**
124
 * @brief PasswordDialog::on_rejected handle Cancel click for QDialog
125
 */
126
void PasswordDialog::on_rejected() { setPassword(QString()); }
×
127

128
/**
129
 * @brief PasswordDialog::setPassword populate the (templated) fields.
130
 * @param password
131
 */
132
void PasswordDialog::setPassword(const QString &password) {
11✔
133
  FileContent fileContent = FileContent::parse(
134
      password, m_templating ? m_fields : QStringList(), m_allFields);
22✔
135
  ui->lineEditPassword->setText(fileContent.getPassword());
11✔
136

137
  QWidget *previous = ui->checkBoxShow;
11✔
138
  // first set templated values
139
  NamedValues namedValues = fileContent.getNamedValues();
11✔
140
  for (QLineEdit *line : AS_CONST(templateLines)) {
13✔
141
    line->setText(namedValues.takeValue(line->objectName()));
4✔
142
    previous = line;
143
  }
144
  // show remaining values (if there are)
145
  otherLines.clear();
11✔
146
  for (const NamedValue &nv : AS_CONST(namedValues)) {
13✔
147
    auto *line = new QLineEdit();
2✔
148
    line->setObjectName(nv.name);
2✔
149
    line->setText(nv.value);
2✔
150
    ui->formLayout->addRow(new QLabel(nv.name), line);
2✔
151
    setTabOrder(previous, line);
2✔
152
    otherLines.append(line);
2✔
153
    previous = line;
154
  }
155

156
  ui->plainTextEdit->insertPlainText(fileContent.getRemainingData());
22✔
157
}
11✔
158

159
/**
160
 * @brief PasswordDialog::getPassword  join the (templated) fields to a QString
161
 * for writing back.
162
 * @return collapsed password.
163
 */
164
auto PasswordDialog::getPassword() -> QString {
11✔
165
  QString passFile = ui->lineEditPassword->text() + "\n";
22✔
166
  QList<QLineEdit *> allLines(templateLines);
167
  allLines.append(otherLines);
11✔
168
  for (QLineEdit *line : allLines) {
26✔
169
    QString text = line->text();
4✔
170
    if (text.isEmpty()) {
4✔
171
      continue;
172
    }
173
    passFile += line->objectName() + ": " + text + "\n";
8✔
174
  }
175
  passFile += ui->plainTextEdit->toPlainText();
22✔
176
  return passFile;
11✔
177
}
178

179
/**
180
 * @brief PasswordDialog::setTemplate set the template and create the fields.
181
 * @param rawFields
182
 */
183
void PasswordDialog::setTemplate(const QString &rawFields, bool useTemplate) {
10✔
184
  m_fields = rawFields.split('\n');
10✔
185
  m_templating = useTemplate;
10✔
186
  templateLines.clear();
10✔
187

188
  if (m_templating) {
10✔
189
    QWidget *previous = ui->checkBoxShow;
3✔
190
    for (const QString &field : std::as_const(m_fields)) {
6✔
191
      if (field.isEmpty()) {
3✔
192
        continue;
1✔
193
      }
194
      auto *line = new QLineEdit();
2✔
195
      line->setObjectName(field);
2✔
196
      ui->formLayout->addRow(new QLabel(field), line);
2✔
197
      setTabOrder(previous, line);
2✔
198
      templateLines.append(line);
2✔
199
      previous = line;
200
    }
201
  }
202
}
10✔
203

204
/**
205
 * @brief PasswordDialog::templateAll basic setter for use in
206
 * PasswordDialog::setPassword templating all tokenisable lines.
207
 * @param templateAll
208
 */
209
void PasswordDialog::templateAll(bool templateAll) {
3✔
210
  m_allFields = templateAll;
3✔
211
}
3✔
212

213
/**
214
 * @brief PasswordDialog::setLength
215
 * PasswordDialog::setLength password length.
216
 * @param l
217
 */
218
void PasswordDialog::setLength(int l) { ui->spinBox_pwdLength->setValue(l); }
11✔
219

220
/**
221
 * @brief PasswordDialog::setPasswordCharTemplate
222
 * PasswordDialog::setPasswordCharTemplate chose the template style.
223
 * @param t
224
 */
225
void PasswordDialog::setPasswordCharTemplate(int t) {
11✔
226
  ui->passwordTemplateSwitch->setCurrentIndex(t);
11✔
227
}
11✔
228

229
/**
230
 * @brief PasswordDialog::usePwgen
231
 * PasswordDialog::usePwgen don't use own password generator.
232
 * @param usePwgen
233
 */
234
void PasswordDialog::usePwgen(bool usePwgen) {
×
235
  ui->passwordTemplateSwitch->setDisabled(usePwgen);
×
236
  ui->label_characterset->setDisabled(usePwgen);
×
237
}
×
238

239
/**
240
 * @brief Sets the password from pass show output.
241
 * @param output Output from pass show command
242
 */
243
void PasswordDialog::setPass(const QString &output) {
11✔
244
  setPassword(output);
11✔
245
  // UI is enabled by default when password is set - no additional action needed
246
}
11✔
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