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

IJHack / QtPass / 23862950363

01 Apr 2026 05:54PM UTC coverage: 20.086% (+0.004%) from 20.082%
23862950363

push

github

web-flow
Merge pull request #890 from IJHack/fix/ai-findings-10-more

fix: address 10 more AI findings across 4 files

9 of 45 new or added lines in 7 files covered. (20.0%)

4 existing lines in 4 files now uncovered.

1030 of 5128 relevant lines covered (20.09%)

7.89 hits per line

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

57.41
/src/passworddialog.cpp
1
// SPDX-FileCopyrightText: 2016 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
 * passwords.
94
 * @todo refactor when process is untangled from MainWindow class.
95
 */
96
void PasswordDialog::on_createPasswordButton_clicked() {
×
97
  ui->widget->setEnabled(false);
×
NEW
98
  QString newPass = QtPassSettings::getPass()->generatePassword(
×
99
      static_cast<unsigned int>(ui->spinBox_pwdLength->value()),
×
100
      m_passConfig.Characters[static_cast<PasswordConfiguration::characterSet>(
101
          ui->passwordTemplateSwitch->currentIndex())]);
×
102
  if (newPass.length() > 0) {
×
103
    ui->lineEditPassword->setText(newPass);
×
104
  }
105
  ui->widget->setEnabled(true);
×
106
}
×
107

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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