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

IJHack / QtPass / 24190241587

09 Apr 2026 12:30PM UTC coverage: 21.06% (+0.004%) from 21.056%
24190241587

push

github

web-flow
fix: address AI findings - SLOT macro, dead code, magic numbers (#953)

* fix: address AI findings - SLOT macro, dead code, magic numbers

- qpushbuttonwithclipboard: use new-style connect instead of SLOT macro
- qpushbuttonasqrcode: remove unused changeIconDefault method and slot
- configdialog: reset background color in else branches, use PasswordConfiguration::CUSTOM

* svgo icons

---------

Co-authored-by: Anne Jan Brouwer <brouwer@annejan.com>

1 of 4 new or added lines in 2 files covered. (25.0%)

36 existing lines in 4 files now uncovered.

1113 of 5285 relevant lines covered (21.06%)

7.78 hits per line

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

0.0
/src/configdialog.cpp
1
// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "configdialog.h"
4
#include "keygendialog.h"
5
#include "mainwindow.h"
6
#include "qtpasssettings.h"
7
#include "ui_configdialog.h"
8
#include "util.h"
9
#include <QClipboard>
10
#include <QDir>
11
#include <QFileDialog>
12
#include <QMessageBox>
13
#include <QPushButton>
14
#include <QSystemTrayIcon>
15
#include <QTableWidgetItem>
16
#include <utility>
17
#ifdef Q_OS_WIN
18
#include <windows.h>
19
#endif
20

21
#ifdef QT_DEBUG
22
#include "debughelper.h"
23
#endif
24

25
/**
26
 * @brief ConfigDialog::ConfigDialog this sets up the configuration screen.
27
 * @param parent
28
 */
29
ConfigDialog::ConfigDialog(MainWindow *parent)
×
30
    : QDialog(parent), ui(new Ui::ConfigDialog) {
×
31
  mainWindow = parent;
×
32
  ui->setupUi(this);
×
33

34
  // Restore dialog state
35
  QByteArray savedGeometry = QtPassSettings::getDialogGeometry("configDialog");
×
36
  bool hasSavedGeometry = !savedGeometry.isEmpty();
37
  if (hasSavedGeometry) {
×
38
    restoreGeometry(savedGeometry);
×
39
  }
40
  if (QtPassSettings::isDialogMaximized("configDialog")) {
×
41
    showMaximized();
×
42
  } else if (!hasSavedGeometry) {
43
    // Let window manager handle positioning for first launch
44
  }
45

46
  ui->passPath->setText(QtPassSettings::getPassExecutable());
×
47
  setGitPath(QtPassSettings::getGitExecutable());
×
48
  ui->gpgPath->setText(QtPassSettings::getGpgExecutable());
×
49
  ui->storePath->setText(QtPassSettings::getPassStore());
×
50

51
  ui->spinBoxAutoclearSeconds->setValue(QtPassSettings::getAutoclearSeconds());
×
52
  ui->spinBoxAutoclearPanelSeconds->setValue(
×
53
      QtPassSettings::getAutoclearPanelSeconds());
×
54
  ui->checkBoxHidePassword->setChecked(QtPassSettings::isHidePassword());
×
55
  ui->checkBoxHideContent->setChecked(QtPassSettings::isHideContent());
×
56
  ui->checkBoxUseMonospace->setChecked(QtPassSettings::isUseMonospace());
×
57
  ui->checkBoxDisplayAsIs->setChecked(QtPassSettings::isDisplayAsIs());
×
58
  ui->checkBoxNoLineWrapping->setChecked(QtPassSettings::isNoLineWrapping());
×
59
  ui->checkBoxAddGPGId->setChecked(QtPassSettings::isAddGPGId(true));
×
60

61
  if (QSystemTrayIcon::isSystemTrayAvailable()) {
×
62
    ui->checkBoxHideOnClose->setChecked(QtPassSettings::isHideOnClose());
×
63
    ui->checkBoxStartMinimized->setChecked(QtPassSettings::isStartMinimized());
×
64
  } else {
65
    ui->checkBoxUseTrayIcon->setEnabled(false);
×
66
    ui->checkBoxUseTrayIcon->setToolTip(tr("System tray is not available"));
×
67
    ui->checkBoxHideOnClose->setEnabled(false);
×
68
    ui->checkBoxStartMinimized->setEnabled(false);
×
69
  }
70

71
  ui->checkBoxAvoidCapitals->setChecked(QtPassSettings::isAvoidCapitals());
×
72
  ui->checkBoxAvoidNumbers->setChecked(QtPassSettings::isAvoidNumbers());
×
73
  ui->checkBoxLessRandom->setChecked(QtPassSettings::isLessRandom());
×
74
  ui->checkBoxUseSymbols->setChecked(QtPassSettings::isUseSymbols());
×
75
  ui->plainTextEditTemplate->setPlainText(QtPassSettings::getPassTemplate());
×
76
  ui->checkBoxTemplateAllFields->setChecked(
×
77
      QtPassSettings::isTemplateAllFields());
×
78
  ui->checkBoxAutoPull->setChecked(QtPassSettings::isAutoPull());
×
79
  ui->checkBoxAutoPush->setChecked(QtPassSettings::isAutoPush());
×
80
  ui->checkBoxAlwaysOnTop->setChecked(QtPassSettings::isAlwaysOnTop());
×
81

82
#if defined(Q_OS_WIN)
83
  ui->checkBoxUseOtp->hide();
84
  ui->checkBoxUseQrencode->hide();
85
  ui->label_10->hide();
86
#endif
87

88
  if (!isPassOtpAvailable()) {
×
89
    ui->checkBoxUseOtp->setEnabled(false);
×
90
    ui->checkBoxUseOtp->setToolTip(
×
91
        tr("Pass OTP extension needs to be installed"));
×
92
  }
93

94
  if (!isQrencodeAvailable()) {
×
95
    ui->checkBoxUseQrencode->setEnabled(false);
×
96
    ui->checkBoxUseQrencode->setToolTip(tr("qrencode needs to be installed"));
×
97
  }
98

99
  setProfiles(QtPassSettings::getProfiles(), QtPassSettings::getProfile());
×
100
  setPwgenPath(QtPassSettings::getPwgenExecutable());
×
101
  setPasswordConfiguration(QtPassSettings::getPasswordConfiguration());
×
102

103
  usePass(QtPassSettings::isUsePass());
×
104
  useAutoclear(QtPassSettings::isUseAutoclear());
×
105
  useAutoclearPanel(QtPassSettings::isUseAutoclearPanel());
×
106
  useTrayIcon(QtPassSettings::isUseTrayIcon());
×
107
  useGit(QtPassSettings::isUseGit());
×
108

109
  useOtp(QtPassSettings::isUseOtp());
×
110
  useQrencode(QtPassSettings::isUseQrencode());
×
111

112
  usePwgen(QtPassSettings::isUsePwgen());
×
113
  useTemplate(QtPassSettings::isUseTemplate());
×
114

115
  ui->profileTable->verticalHeader()->hide();
×
116
  ui->profileTable->horizontalHeader()->setSectionResizeMode(
×
117
      1, QHeaderView::Stretch);
118
  ui->label->setText(ui->label->text() + VERSION);
×
119
  ui->comboBoxClipboard->clear();
×
120

121
  ui->comboBoxClipboard->addItem(tr("No Clipboard"));
×
122
  ui->comboBoxClipboard->addItem(tr("Always copy to clipboard"));
×
123
  ui->comboBoxClipboard->addItem(tr("On-demand copy to clipboard"));
×
124

125
  int currentIndex = QtPassSettings::getClipBoardTypeRaw();
×
126
  ui->comboBoxClipboard->setCurrentIndex(currentIndex);
×
127
  on_comboBoxClipboard_activated(currentIndex);
×
128

129
  QClipboard *clip = QApplication::clipboard();
×
130
  if (!clip->supportsSelection()) {
×
131
    useSelection(false);
×
132
    ui->checkBoxSelection->setVisible(false);
×
133
  } else {
134
    useSelection(QtPassSettings::isUseSelection());
×
135
  }
136

137
  if (!Util::configIsValid()) {
×
138
    // Show Programs tab, which is likely
139
    // what the user needs to fix now.
140
    ui->tabWidget->setCurrentIndex(1);
×
141
  }
142

143
  connect(ui->profileTable, &QTableWidget::itemChanged, this,
×
144
          &ConfigDialog::onProfileTableItemChanged);
×
145
  connect(this, &ConfigDialog::accepted, this, &ConfigDialog::on_accepted);
×
146
}
×
147

148
/**
149
 * @brief ConfigDialog::~ConfigDialog config destructor, makes sure the
150
 * mainWindow knows about git, gpg and pass executables.
151
 */
152
ConfigDialog::~ConfigDialog() {
×
153
  QtPassSettings::setGitExecutable(ui->gitPath->text());
×
154
  QtPassSettings::setGpgExecutable(ui->gpgPath->text());
×
155
  QtPassSettings::setPassExecutable(ui->passPath->text());
×
156
}
×
157

158
/**
159
 * @brief ConfigDialog::setGitPath set the git executable path.
160
 * Make sure the checkBoxUseGit is updated.
161
 * @param path
162
 */
163
void ConfigDialog::setGitPath(const QString &path) {
×
164
  ui->gitPath->setText(path);
×
165
  ui->checkBoxUseGit->setEnabled(!path.isEmpty());
×
166
  if (path.isEmpty()) {
×
167
    useGit(false);
×
168
  }
169
}
×
170

171
/**
172
 * @brief ConfigDialog::usePass set wether or not we want to use pass.
173
 * Update radio buttons accordingly.
174
 * @param usePass
175
 */
176
void ConfigDialog::usePass(bool usePass) {
×
177
  ui->radioButtonNative->setChecked(!usePass);
×
178
  ui->radioButtonPass->setChecked(usePass);
×
179
  setGroupBoxState();
×
180
}
×
181

182
/**
183
 * @brief Validates the configuration table fields and enables or disables the
184
 * OK button accordingly.
185
 * @example
186
 * ConfigDialog dialog;
187
 * QTableWidgetItem *item = dialog.findChild<QTableWidgetItem*>();
188
 * dialog.validate(item);
189
 *
190
 * @param QTableWidgetItem *item - The table item to validate; if null,
191
 * validates all relevant items in the profile table.
192
 * @return void - This function does not return a value.
193
 */
194
void ConfigDialog::validate(QTableWidgetItem *item) {
×
195
  bool status = true;
196

197
  if (item == nullptr) {
×
198
    for (int i = 0; i < ui->profileTable->rowCount(); i++) {
×
199
      for (int j = 0; j < ui->profileTable->columnCount(); j++) {
×
200
        QTableWidgetItem *_item = ui->profileTable->item(i, j);
×
201

202
        if (_item->text().isEmpty() && j != 2) {
×
203
          _item->setBackground(Qt::red);
×
204
          _item->setToolTip(tr("This field is required"));
×
205
          status = false;
206
          break;
207
        } else {
NEW
208
          _item->setBackground(QBrush());
×
UNCOV
209
          _item->setToolTip(QString());
×
210
        }
211
      }
212

213
      if (!status) {
214
        break;
215
      }
216
    }
217
  } else {
218
    if (item->text().isEmpty() && item->column() != 2) {
×
219
      item->setBackground(Qt::red);
×
220
      item->setToolTip(tr("This field is required"));
×
221
      status = false;
222
    } else {
NEW
223
      item->setBackground(QBrush());
×
UNCOV
224
      item->setToolTip(QString());
×
225
    }
226
  }
227

228
  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
×
229
}
×
230

231
/**
232
 * @brief Saves the configuration dialog settings to persistent application
233
 * settings.
234
 * @example
235
 * ConfigDialog dialog;
236
 * dialog.on_accepted();
237
 * // Expected output: All UI-selected configuration values are stored via
238
 * QtPassSettings.
239
 *
240
 * @return void - This method does not return a value.
241
 */
242
void ConfigDialog::on_accepted() {
×
243
  QtPassSettings::setPassExecutable(ui->passPath->text());
×
244
  QtPassSettings::setGitExecutable(ui->gitPath->text());
×
245
  QtPassSettings::setGpgExecutable(ui->gpgPath->text());
×
246
  QtPassSettings::setPassStore(
×
247
      Util::normalizeFolderPath(ui->storePath->text()));
×
248
  QtPassSettings::setUsePass(ui->radioButtonPass->isChecked());
×
249
  QtPassSettings::setClipBoardType(ui->comboBoxClipboard->currentIndex());
×
250
  QtPassSettings::setUseSelection(ui->checkBoxSelection->isChecked());
×
251
  QtPassSettings::setUseAutoclear(ui->checkBoxAutoclear->isChecked());
×
252
  QtPassSettings::setAutoclearSeconds(ui->spinBoxAutoclearSeconds->value());
×
253
  QtPassSettings::setUseAutoclearPanel(ui->checkBoxAutoclearPanel->isChecked());
×
254
  QtPassSettings::setAutoclearPanelSeconds(
×
255
      ui->spinBoxAutoclearPanelSeconds->value());
×
256
  QtPassSettings::setHidePassword(ui->checkBoxHidePassword->isChecked());
×
257
  QtPassSettings::setHideContent(ui->checkBoxHideContent->isChecked());
×
258
  QtPassSettings::setUseMonospace(ui->checkBoxUseMonospace->isChecked());
×
259
  QtPassSettings::setDisplayAsIs(ui->checkBoxDisplayAsIs->isChecked());
×
260
  QtPassSettings::setNoLineWrapping(ui->checkBoxNoLineWrapping->isChecked());
×
261
  QtPassSettings::setAddGPGId(ui->checkBoxAddGPGId->isChecked());
×
262
  QtPassSettings::setUseTrayIcon(ui->checkBoxUseTrayIcon->isEnabled() &&
×
263
                                 ui->checkBoxUseTrayIcon->isChecked());
×
264
  QtPassSettings::setHideOnClose(ui->checkBoxHideOnClose->isEnabled() &&
×
265
                                 ui->checkBoxHideOnClose->isChecked());
×
266
  QtPassSettings::setStartMinimized(ui->checkBoxStartMinimized->isEnabled() &&
×
267
                                    ui->checkBoxStartMinimized->isChecked());
×
268
  QtPassSettings::setProfiles(getProfiles());
×
269
  QtPassSettings::setUseGit(ui->checkBoxUseGit->isChecked());
×
270
  QtPassSettings::setUseOtp(ui->checkBoxUseOtp->isChecked());
×
271
  QtPassSettings::setUseQrencode(ui->checkBoxUseQrencode->isChecked());
×
272
  QtPassSettings::setPwgenExecutable(ui->pwgenPath->text());
×
273
  QtPassSettings::setUsePwgen(ui->checkBoxUsePwgen->isChecked());
×
274
  QtPassSettings::setAvoidCapitals(ui->checkBoxAvoidCapitals->isChecked());
×
275
  QtPassSettings::setAvoidNumbers(ui->checkBoxAvoidNumbers->isChecked());
×
276
  QtPassSettings::setLessRandom(ui->checkBoxLessRandom->isChecked());
×
277
  QtPassSettings::setUseSymbols(ui->checkBoxUseSymbols->isChecked());
×
278
  QtPassSettings::setPasswordConfiguration(getPasswordConfiguration());
×
279
  QtPassSettings::setUseTemplate(ui->checkBoxUseTemplate->isChecked());
×
280
  QtPassSettings::setPassTemplate(ui->plainTextEditTemplate->toPlainText());
×
281
  QtPassSettings::setTemplateAllFields(
×
282
      ui->checkBoxTemplateAllFields->isChecked());
×
283
  QtPassSettings::setAutoPush(ui->checkBoxAutoPush->isChecked());
×
284
  QtPassSettings::setAutoPull(ui->checkBoxAutoPull->isChecked());
×
285
  QtPassSettings::setAlwaysOnTop(ui->checkBoxAlwaysOnTop->isChecked());
×
286

287
  QtPassSettings::setVersion(VERSION);
×
288
}
×
289

290
/**
291
 * @brief Automatically detects required external binaries in the system PATH
292
 * and updates the dialog fields.
293
 * @example
294
 * ConfigDialog configDialog;
295
 * configDialog.on_autodetectButton_clicked();
296
 *
297
 * @return void - This function does not return a value.
298
 */
299
void ConfigDialog::on_autodetectButton_clicked() {
×
300
  QString pass = Util::findBinaryInPath("pass");
×
301
  if (!pass.isEmpty()) {
×
302
    ui->passPath->setText(pass);
×
303
  }
304
  usePass(!pass.isEmpty());
×
305
  QString gpg = Util::findBinaryInPath("gpg2");
×
306
  if (gpg.isEmpty()) {
×
307
    gpg = Util::findBinaryInPath("gpg");
×
308
  }
309
  if (!gpg.isEmpty()) {
×
310
    ui->gpgPath->setText(gpg);
×
311
  }
312
  QString git = Util::findBinaryInPath("git");
×
313
  if (!git.isEmpty()) {
×
314
    ui->gitPath->setText(git);
×
315
  }
316
  QString pwgen = Util::findBinaryInPath("pwgen");
×
317
  if (!pwgen.isEmpty()) {
×
318
    ui->pwgenPath->setText(pwgen);
×
319
  }
320
}
×
321

322
/**
323
 * @brief ConfigDialog::on_radioButtonNative_clicked wrapper for
324
 * ConfigDialog::setGroupBoxState()
325
 */
326
void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
×
327

328
/**
329
 * @brief ConfigDialog::on_radioButtonPass_clicked wrapper for
330
 * ConfigDialog::setGroupBoxState()
331
 */
332
void ConfigDialog::on_radioButtonPass_clicked() { setGroupBoxState(); }
×
333

334
/**
335
 * @brief ConfigDialog::getSecretKeys get list of secret/private keys
336
 * @return QStringList keys
337
 */
338
auto ConfigDialog::getSecretKeys() -> QStringList {
×
339
  QList<UserInfo> keys = QtPassSettings::getPass()->listKeys("", true);
×
340
  QStringList names;
×
341

342
  if (keys.empty()) {
×
343
    return names;
344
  }
345

346
  foreach (const UserInfo &sec, keys)
×
347
    names << sec.name;
×
348

349
  return names;
×
350
}
351

352
/**
353
 * @brief ConfigDialog::setGroupBoxState update checkboxes.
354
 */
355
void ConfigDialog::setGroupBoxState() {
×
356
  bool state = ui->radioButtonPass->isChecked();
×
357
  ui->groupBoxNative->setEnabled(!state);
×
358
  ui->groupBoxPass->setEnabled(state);
×
359
}
×
360

361
/**
362
 * @brief ConfigDialog::selectExecutable pop-up to choose an executable.
363
 * @return
364
 */
365
auto ConfigDialog::selectExecutable() -> QString {
×
366
  QFileDialog dialog(this);
×
367
  dialog.setFileMode(QFileDialog::ExistingFile);
×
368
  dialog.setOption(QFileDialog::ReadOnly);
×
369
  if (dialog.exec()) {
×
370
    return dialog.selectedFiles().constFirst();
×
371
  }
372

373
  return {};
374
}
×
375

376
/**
377
 * @brief ConfigDialog::selectFolder pop-up to choose a folder.
378
 * @return
379
 */
380
auto ConfigDialog::selectFolder() -> QString {
×
381
  QFileDialog dialog(this);
×
382
  dialog.setFileMode(QFileDialog::Directory);
×
383
  dialog.setFilter(QDir::NoFilter);
×
384
  dialog.setOption(QFileDialog::ShowDirsOnly);
×
385
  if (dialog.exec()) {
×
386
    return dialog.selectedFiles().constFirst();
×
387
  }
388

389
  return {};
390
}
×
391

392
/**
393
 * @brief ConfigDialog::on_toolButtonGit_clicked get git application.
394
 * Enable checkboxes if found.
395
 */
396
void ConfigDialog::on_toolButtonGit_clicked() {
×
397
  QString git = selectExecutable();
×
398
  bool state = !git.isEmpty();
×
399
  if (state) {
×
400
    ui->gitPath->setText(git);
×
401
  } else {
402
    useGit(false);
×
403
  }
404

405
  ui->checkBoxUseGit->setEnabled(state);
×
406
}
×
407

408
/**
409
 * @brief ConfigDialog::on_toolButtonGpg_clicked get gpg application.
410
 */
411
void ConfigDialog::on_toolButtonGpg_clicked() {
×
412
  QString gpg = selectExecutable();
×
413
  if (!gpg.isEmpty()) {
×
414
    ui->gpgPath->setText(gpg);
×
415
  }
416
}
×
417

418
/**
419
 * @brief ConfigDialog::on_pushButtonGenerateKey_clicked open keygen dialog.
420
 */
421
void ConfigDialog::on_pushButtonGenerateKey_clicked() {
×
422
  KeygenDialog d(this);
×
423
  d.exec();
×
424
}
×
425

426
/**
427
 * @brief ConfigDialog::on_toolButtonPass_clicked get pass application.
428
 */
429
void ConfigDialog::on_toolButtonPass_clicked() {
×
430
  QString pass = selectExecutable();
×
431
  if (!pass.isEmpty()) {
×
432
    ui->passPath->setText(pass);
×
433
  }
434
}
×
435

436
/**
437
 * @brief ConfigDialog::on_toolButtonStore_clicked get .password-store
438
 * location.s
439
 */
440
void ConfigDialog::on_toolButtonStore_clicked() {
×
441
  QString store = selectFolder();
×
442
  if (!store.isEmpty()) {
×
443
    ui->storePath->setText(store);
×
444
  }
445
}
×
446

447
/**
448
 * @brief ConfigDialog::on_comboBoxClipboard_activated show and hide options.
449
 * @param index of selectbox (0 = no clipboard).
450
 */
451
void ConfigDialog::on_comboBoxClipboard_activated(int index) {
×
452
  bool state = index > 0;
×
453

454
  ui->checkBoxSelection->setEnabled(state);
×
455
  ui->checkBoxAutoclear->setEnabled(state);
×
456
  ui->checkBoxHidePassword->setEnabled(state);
×
457
  ui->checkBoxHideContent->setEnabled(state);
×
458
  if (state) {
×
459
    ui->spinBoxAutoclearSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
×
460
    ui->labelSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
×
461
  } else {
462
    ui->spinBoxAutoclearSeconds->setEnabled(false);
×
463
    ui->labelSeconds->setEnabled(false);
×
464
  }
465
}
×
466

467
/**
468
 * @brief ConfigDialog::on_checkBoxAutoclearPanel_clicked enable and disable
469
 * options based on autoclear use.
470
 */
471
void ConfigDialog::on_checkBoxAutoclearPanel_clicked() {
×
472
  bool state = ui->checkBoxAutoclearPanel->isChecked();
×
473
  ui->spinBoxAutoclearPanelSeconds->setEnabled(state);
×
474
  ui->labelPanelSeconds->setEnabled(state);
×
475
}
×
476

477
/**
478
 * @brief ConfigDialog::useSelection set the clipboard type use from
479
 * MainWindow.
480
 * @param useSelection
481
 */
482
void ConfigDialog::useSelection(bool useSelection) {
×
483
  ui->checkBoxSelection->setChecked(useSelection);
×
484
  on_checkBoxSelection_clicked();
×
485
}
×
486

487
/**
488
 * @brief ConfigDialog::useAutoclear set the clipboard autoclear use from
489
 * MainWindow.
490
 * @param useAutoclear
491
 */
492
void ConfigDialog::useAutoclear(bool useAutoclear) {
×
493
  ui->checkBoxAutoclear->setChecked(useAutoclear);
×
494
  on_checkBoxAutoclear_clicked();
×
495
}
×
496

497
/**
498
 * @brief ConfigDialog::useAutoclearPanel set the panel autoclear use from
499
 * MainWindow.
500
 * @param useAutoclearPanel
501
 */
502
void ConfigDialog::useAutoclearPanel(bool useAutoclearPanel) {
×
503
  ui->checkBoxAutoclearPanel->setChecked(useAutoclearPanel);
×
504
  on_checkBoxAutoclearPanel_clicked();
×
505
}
×
506

507
/**
508
 * @brief ConfigDialog::on_checkBoxSelection_clicked checkbox clicked, update
509
 * state via ConfigDialog::on_comboBoxClipboard_activated
510
 */
511
void ConfigDialog::on_checkBoxSelection_clicked() {
×
512
  on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
×
513
}
×
514

515
/**
516
 * @brief ConfigDialog::on_checkBoxAutoclear_clicked checkbox clicked, update
517
 * state via ConfigDialog::on_comboBoxClipboard_activated
518
 */
519
void ConfigDialog::on_checkBoxAutoclear_clicked() {
×
520
  on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
×
521
}
×
522

523
/**
524
 * @brief ConfigDialog::genKey tunnel function to make MainWindow generate a
525
 * gpg key pair.
526
 * @todo refactor the process to not be entangled so much.
527
 * @param batch
528
 * @param dialog
529
 */
530
void ConfigDialog::genKey(const QString &batch, QDialog *dialog) {
×
531
  mainWindow->generateKeyPair(batch, dialog);
×
532
}
×
533

534
/**
535
 * @brief ConfigDialog::setProfiles set the profiles and chosen profile from
536
 * MainWindow.
537
 * @param profiles
538
 * @param profile
539
 */
540
void ConfigDialog::setProfiles(QHash<QString, QHash<QString, QString>> profiles,
×
541
                               const QString &currentProfile) {
542
  if (profiles.contains("")) {
×
543
    profiles.remove("");
×
544
    // remove weird "" key value pairs
545
  }
546

547
  ui->profileTable->setRowCount(profiles.count());
×
548
  QHashIterator<QString, QHash<QString, QString>> i(profiles);
×
549
  int n = 0;
550
  while (i.hasNext()) {
×
551
    i.next();
552
    if (!i.value().isEmpty() && !i.key().isEmpty()) {
×
553
      ui->profileTable->setItem(n, 0, new QTableWidgetItem(i.key()));
×
554
      ui->profileTable->setItem(n, 1,
×
555
                                new QTableWidgetItem(i.value().value("path")));
×
556
      ui->profileTable->setItem(
×
557
          n, 2, new QTableWidgetItem(i.value().value("signingKey")));
×
558
      if (i.key() == currentProfile) {
×
559
        ui->profileTable->selectRow(n);
×
560
      }
561
    }
562
    ++n;
×
563
  }
564
}
×
565

566
/**
567
 * @brief ConfigDialog::getProfiles return profile list.
568
 * @return
569
 */
570
auto ConfigDialog::getProfiles() -> QHash<QString, QHash<QString, QString>> {
×
571
  QHash<QString, QHash<QString, QString>> profiles;
×
572
  // Check?
573
  for (int i = 0; i < ui->profileTable->rowCount(); ++i) {
×
574
    QHash<QString, QString> profile;
×
575
    QTableWidgetItem *pathItem = ui->profileTable->item(i, 1);
×
576
    if (nullptr != pathItem) {
×
577
      QTableWidgetItem *item = ui->profileTable->item(i, 0);
×
578
      if (item == nullptr) {
×
579
        continue;
580
      }
581
      profile["path"] = pathItem->text();
×
582
      QTableWidgetItem *signingKeyItem = ui->profileTable->item(i, 2);
×
583
      if (nullptr != signingKeyItem) {
×
584
        profile["signingKey"] = signingKeyItem->text();
×
585
      }
586
      profiles.insert(item->text(), profile);
×
587
    }
588
  }
×
589
  return profiles;
×
590
}
×
591

592
/**
593
 * @brief ConfigDialog::on_addButton_clicked add a profile row.
594
 */
595
void ConfigDialog::on_addButton_clicked() {
×
596
  int n = ui->profileTable->rowCount();
×
597
  ui->profileTable->insertRow(n);
×
598
  ui->profileTable->setItem(n, 0, new QTableWidgetItem());
×
599
  ui->profileTable->setItem(n, 1, new QTableWidgetItem(ui->storePath->text()));
×
600
  ui->profileTable->setItem(n, 2, new QTableWidgetItem());
×
601
  ui->profileTable->selectRow(n);
×
602
  ui->deleteButton->setEnabled(true);
×
603

604
  validate();
×
605
}
×
606

607
/**
608
 * @brief ConfigDialog::on_deleteButton_clicked remove a profile row.
609
 */
610
void ConfigDialog::on_deleteButton_clicked() {
×
611
  QSet<int> selectedRows; //  we use a set to prevent doubles
612
  QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems();
×
613
  if (itemList.count() == 0) {
×
614
    QMessageBox::warning(this, tr("No profile selected"),
×
615
                         tr("No profile selected to delete"));
×
616
    return;
617
  }
618
  QTableWidgetItem *item;
619
  foreach (item, itemList)
×
620
    selectedRows.insert(item->row());
×
621
  // get a list, and sort it big to small
622
  QList<int> rows = selectedRows.values();
×
623
  std::sort(rows.begin(), rows.end());
×
624
  // now actually do the removing:
625
  foreach (int row, rows)
×
626
    ui->profileTable->removeRow(row);
×
627
  if (ui->profileTable->rowCount() < 1) {
×
628
    ui->deleteButton->setEnabled(false);
×
629
  }
630

631
  validate();
×
632
}
633

634
/**
635
 * @brief ConfigDialog::criticalMessage weapper for showing critical messages
636
 * in a popup.
637
 * @param title
638
 * @param text
639
 */
640
void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
×
641
  QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
×
642
}
×
643

644
/**
645
 * @brief Checks whether the qrencode executable is available on the system.
646
 * @example
647
 * bool result = ConfigDialog::isQrencodeAvailable();
648
 * std::cout << result << std::endl; // Expected output: true if qrencode is
649
 * found, otherwise false
650
 *
651
 * @return bool - True if qrencode is available; otherwise false. On Windows,
652
 * always returns false.
653
 */
654
auto ConfigDialog::isQrencodeAvailable() -> bool {
×
655
#ifdef Q_OS_WIN
656
  return false;
657
#else
658
  QProcess which;
×
659
  which.start("which", QStringList() << "qrencode");
×
660
  which.waitForFinished();
×
661
  QtPassSettings::setQrencodeExecutable(
×
662
      which.readAllStandardOutput().trimmed());
×
663
  return which.exitCode() == 0;
×
664
#endif
665
}
×
666

667
auto ConfigDialog::isPassOtpAvailable() -> bool {
×
668
#ifdef Q_OS_WIN
669
  return false;
670
#else
671
  QProcess pass;
×
672
  pass.start(QtPassSettings::getPassExecutable(), QStringList() << "otp"
×
673
                                                                << "--help");
×
674
  pass.waitForFinished(2000);
×
675
  return pass.exitCode() == 0;
×
676
#endif
677
}
×
678

679
/**
680
 * @brief ConfigDialog::wizard first-time use wizard.
681
 * @todo make this thing more reliable.
682
 */
683
void ConfigDialog::wizard() {
×
684
  (void)Util::configIsValid();
×
685
  on_autodetectButton_clicked();
×
686

687
  if (!checkGpgExistence()) {
×
688
    return;
689
  }
690
  if (!checkSecretKeys()) {
×
691
    return;
692
  }
693
  if (!checkPasswordStore()) {
×
694
    return;
695
  }
696
  handleGpgIdFile();
×
697

698
  ui->checkBoxHidePassword->setCheckState(Qt::Checked);
×
699
}
700

701
/**
702
 * @brief Checks whether the configured GnuPG executable exists.
703
 * @example
704
 * bool result = ConfigDialog::checkGpgExistence();
705
 * std::cout << result << std::endl; // Expected output: true if GnuPG is found,
706
 * false otherwise
707
 *
708
 * @return bool - True if the GnuPG path is valid or uses a WSL command prefix;
709
 * false if the executable cannot be found and an error message is shown.
710
 */
711
auto ConfigDialog::checkGpgExistence() -> bool {
×
712
  QString gpg = ui->gpgPath->text();
×
713
  if (!gpg.startsWith("wsl ") && !QFile(gpg).exists()) {
×
714
    criticalMessage(
×
715
        tr("GnuPG not found"),
×
716
#ifdef Q_OS_WIN
717
#ifdef WINSTORE
718
        tr("Please install GnuPG on your system.<br>Install "
719
           "<strong>Ubuntu</strong> from the Microsoft Store to get it.<br>"
720
           "If you already did so, make sure you started it once and<br>"
721
           "click \"Autodetect\" in the next dialog.")
722
#else
723
        tr("Please install GnuPG on your system.<br>Install "
724
           "<strong>Ubuntu</strong> from the Microsoft Store<br>or <a "
725
           "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
726
           "from GnuPG.org")
727
#endif
728
#else
729
        tr("Please install GnuPG on your system.<br>Install "
×
730
           "<strong>gpg</strong> using your favorite package manager<br>or "
731
           "<a "
732
           "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
733
           "from GnuPG.org")
734
#endif
735
    );
736
    return false;
×
737
  }
738
  return true;
739
}
740

741
/**
742
 * @brief Checks whether secret keys are available and, if needed, prompts the
743
 * user to generate them.
744
 * @example
745
 * bool result = ConfigDialog.checkSecretKeys();
746
 * std::cout << result << std::endl; // Expected output: true if keys are
747
 * present or key generation dialog is accepted, false otherwise
748
 *
749
 * @return bool - Returns true when secret keys are already available or the key
750
 * generation dialog is accepted; false if the dialog is rejected.
751
 */
752
auto ConfigDialog::checkSecretKeys() -> bool {
×
753
  QString gpg = ui->gpgPath->text();
×
754
  QStringList names = getSecretKeys();
×
755

756
#ifdef QT_DEBUG
757
  dbg() << names;
758
#endif
759

760
  if ((gpg.startsWith("wsl ") || QFile(gpg).exists()) && names.empty()) {
×
761
    KeygenDialog d(this);
×
762
    return d.exec();
×
763
  }
×
764
  return true;
765
}
766

767
/**
768
 * @brief Checks whether the password-store path exists and prompts the user to
769
 * create it if it does not.
770
 * @example
771
 * bool result = ConfigDialog::checkPasswordStore();
772
 * std::cout << std::boolalpha << result << std::endl; // Expected output: true
773
 * if the store exists or is created successfully, false if creation fails
774
 *
775
 * @return bool - True if the password-store exists or is successfully created,
776
 * false if creation fails.
777
 */
778
auto ConfigDialog::checkPasswordStore() -> bool {
×
779
  QString passStore = ui->storePath->text();
×
780

781
  if (!QFile(passStore).exists()) {
×
782
    if (QMessageBox::question(
×
783
            this, tr("Create password-store?"),
×
784
            tr("Would you like to create a password-store at %1?")
×
785
                .arg(passStore),
×
786
            QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
787
      if (!QDir().mkdir(passStore)) {
×
788
        QMessageBox::warning(
×
789
            this, tr("Error"),
×
790
            tr("Failed to create password-store at: %1").arg(passStore));
×
791
        return false;
×
792
      }
793
#ifdef Q_OS_WIN
794
      SetFileAttributes(passStore.toStdWString().c_str(),
795
                        FILE_ATTRIBUTE_HIDDEN);
796
#endif
797
      if (ui->checkBoxUseGit->isChecked()) {
×
798
        emit mainWindow->passGitInitNeeded();
×
799
      }
800
      mainWindow->userDialog(passStore);
×
801
    }
802
  }
803
  return true;
804
}
805

806
/**
807
 * @brief Handles selection and validation of the password store's .gpg-id file.
808
 * @example
809
 * ConfigDialog dialog;
810
 * dialog.handleGpgIdFile();
811
 *
812
 * @return void - This method does not return a value; it updates the UI flow
813
 * and may prompt the user to choose a valid password store.
814
 */
815
void ConfigDialog::handleGpgIdFile() {
×
816
  QString passStore = ui->storePath->text();
×
817
  if (!QFile(QDir(passStore).filePath(".gpg-id")).exists()) {
×
818
#ifdef QT_DEBUG
819
    dbg() << ".gpg-id file does not exist";
820
#endif
821
    criticalMessage(tr("Password store not initialised"),
×
822
                    tr("The folder %1 doesn't seem to be a password store or "
×
823
                       "is not yet initialised.")
824
                        .arg(passStore));
×
825

826
    while (!QFile(passStore).exists()) {
×
827
      on_toolButtonStore_clicked();
×
828
      if (passStore == ui->storePath->text()) {
×
829
        return;
830
      }
831
      passStore = ui->storePath->text();
×
832
    }
833
    if (!QFile(passStore + ".gpg-id").exists()) {
×
834
#ifdef QT_DEBUG
835
      dbg() << ".gpg-id file still does not exist :/";
836
#endif
837
      mainWindow->userDialog(passStore);
×
838
    }
839
  }
840
}
841

842
/**
843
 * @brief ConfigDialog::useTrayIcon set preference for using trayicon.
844
 * Enable or disable related checkboxes accordingly.
845
 * @param useSystray
846
 */
847
void ConfigDialog::useTrayIcon(bool useSystray) {
×
848
  if (QSystemTrayIcon::isSystemTrayAvailable()) {
×
849
    ui->checkBoxUseTrayIcon->setChecked(useSystray);
×
850
    ui->checkBoxHideOnClose->setEnabled(useSystray);
×
851
    ui->checkBoxStartMinimized->setEnabled(useSystray);
×
852

853
    if (!useSystray) {
×
854
      ui->checkBoxHideOnClose->setChecked(false);
×
855
      ui->checkBoxStartMinimized->setChecked(false);
×
856
    }
857
  }
858
}
×
859

860
/**
861
 * @brief ConfigDialog::on_checkBoxUseTrayIcon_clicked enable and disable
862
 * related checkboxes.
863
 */
864
void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
×
865
  bool state = ui->checkBoxUseTrayIcon->isChecked();
×
866
  ui->checkBoxHideOnClose->setEnabled(state);
×
867
  ui->checkBoxStartMinimized->setEnabled(state);
×
868
}
×
869

870
/**
871
 * @brief ConfigDialog::closeEvent close this window.
872
 * @param event
873
 */
874
void ConfigDialog::closeEvent(QCloseEvent *event) {
×
875
  QtPassSettings::setDialogGeometry("configDialog", saveGeometry());
×
876
  if (!isMaximized()) {
×
877
    QtPassSettings::setDialogPos("configDialog", pos());
×
878
    QtPassSettings::setDialogSize("configDialog", size());
×
879
  }
880
  QtPassSettings::setDialogMaximized("configDialog", isMaximized());
×
881
  event->accept();
882
}
×
883

884
/**
885
 * @brief ConfigDialog::useGit set preference for using git.
886
 * @param useGit
887
 */
888
void ConfigDialog::useGit(bool useGit) {
×
889
  ui->checkBoxUseGit->setChecked(useGit);
×
890
  on_checkBoxUseGit_clicked();
×
891
}
×
892

893
/**
894
 * @brief ConfigDialog::useOtp set preference for using otp plugin.
895
 * @param useOtp
896
 */
897
void ConfigDialog::useOtp(bool useOtp) {
×
898
  ui->checkBoxUseOtp->setChecked(useOtp);
×
899
}
×
900

901
/**
902
 * @brief ConfigDialog::useOtp set preference for using otp plugin.
903
 * @param useOtp
904
 */
905
void ConfigDialog::useQrencode(bool useQrencode) {
×
906
  ui->checkBoxUseQrencode->setChecked(useQrencode);
×
907
}
×
908

909
/**
910
 * @brief ConfigDialog::on_checkBoxUseGit_clicked enable or disable related
911
 * checkboxes.
912
 */
913
void ConfigDialog::on_checkBoxUseGit_clicked() {
×
914
  ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
×
915
  ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
×
916
  ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
×
917
}
×
918

919
/**
920
 * @brief ConfigDialog::on_toolButtonPwgen_clicked enable or disable related
921
 * options in the interface.
922
 */
923
void ConfigDialog::on_toolButtonPwgen_clicked() {
×
924
  QString pwgen = selectExecutable();
×
925
  if (!pwgen.isEmpty()) {
×
926
    ui->pwgenPath->setText(pwgen);
×
927
    ui->checkBoxUsePwgen->setEnabled(true);
×
928
  } else {
929
    ui->checkBoxUsePwgen->setEnabled(false);
×
930
    ui->checkBoxUsePwgen->setChecked(false);
×
931
  }
932
}
×
933

934
/**
935
 * @brief ConfigDialog::setPwgenPath set pwgen executable path.
936
 * Enable or disable related options in the interface.
937
 * @param pwgen
938
 */
939
void ConfigDialog::setPwgenPath(const QString &pwgen) {
×
940
  ui->pwgenPath->setText(pwgen);
×
941
  if (pwgen.isEmpty()) {
×
942
    ui->checkBoxUsePwgen->setChecked(false);
×
943
    ui->checkBoxUsePwgen->setEnabled(false);
×
944
  }
945
  on_checkBoxUsePwgen_clicked();
×
946
}
×
947

948
/**
949
 * @brief ConfigDialog::on_checkBoxUsPwgen_clicked enable or disable related
950
 * options in the interface.
951
 */
952
void ConfigDialog::on_checkBoxUsePwgen_clicked() {
×
953
  bool usePwgen = ui->checkBoxUsePwgen->isChecked();
×
954
  ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
×
955
  ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
×
956
  ui->checkBoxLessRandom->setEnabled(usePwgen);
×
957
  ui->checkBoxUseSymbols->setEnabled(usePwgen);
×
958
  ui->lineEditPasswordChars->setEnabled(!usePwgen);
×
959
  ui->labelPasswordChars->setEnabled(!usePwgen);
×
960
  ui->passwordCharTemplateSelector->setEnabled(!usePwgen);
×
961
}
×
962

963
/**
964
 * @brief ConfigDialog::usePwgen set preference for using pwgen (can be
965
 * overruled buy empty pwgenPath).
966
 * enable or disable related options in the interface via
967
 * ConfigDialog::on_checkBoxUsePwgen_clicked
968
 * @param usePwgen
969
 */
970
void ConfigDialog::usePwgen(bool usePwgen) {
×
971
  if (ui->pwgenPath->text().isEmpty()) {
×
972
    usePwgen = false;
973
  }
974
  ui->checkBoxUsePwgen->setChecked(usePwgen);
×
975
  on_checkBoxUsePwgen_clicked();
×
976
}
×
977

978
void ConfigDialog::setPasswordConfiguration(
×
979
    const PasswordConfiguration &config) {
980
  ui->spinBoxPasswordLength->setValue(config.length);
×
981
  ui->passwordCharTemplateSelector->setCurrentIndex(config.selected);
×
982
  if (config.selected != PasswordConfiguration::CUSTOM) {
×
983
    ui->lineEditPasswordChars->setEnabled(false);
×
984
  }
985
  ui->lineEditPasswordChars->setText(config.Characters[config.selected]);
×
986
}
×
987

988
auto ConfigDialog::getPasswordConfiguration() -> PasswordConfiguration {
×
989
  PasswordConfiguration config;
×
990
  config.length = ui->spinBoxPasswordLength->value();
×
991
  config.selected = static_cast<PasswordConfiguration::characterSet>(
×
992
      ui->passwordCharTemplateSelector->currentIndex());
×
993
  config.Characters[PasswordConfiguration::CUSTOM] =
994
      ui->lineEditPasswordChars->text();
×
995
  return config;
×
996
}
×
997

998
/**
999
 * @brief ConfigDialog::on_passwordCharTemplateSelector_activated sets the
1000
 * passwordChar Template
1001
 * combo box to the desired entry
1002
 * @param entry of
1003
 */
1004
void ConfigDialog::on_passwordCharTemplateSelector_activated(int index) {
×
1005
  ui->lineEditPasswordChars->setText(
×
1006
      QtPassSettings::getPasswordConfiguration().Characters[index]);
×
NEW
1007
  if (index == PasswordConfiguration::CUSTOM) {
×
1008
    ui->lineEditPasswordChars->setEnabled(true);
×
1009
  } else {
1010
    ui->lineEditPasswordChars->setEnabled(false);
×
1011
  }
1012
}
×
1013

1014
/**
1015
 * @brief ConfigDialog::on_checkBoxUseTemplate_clicked enable or disable the
1016
 * template field and options.
1017
 */
1018
void ConfigDialog::on_checkBoxUseTemplate_clicked() {
×
1019
  ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
×
1020
  ui->checkBoxTemplateAllFields->setEnabled(
×
1021
      ui->checkBoxUseTemplate->isChecked());
×
1022
}
×
1023

1024
void ConfigDialog::onProfileTableItemChanged(QTableWidgetItem *item) {
×
1025
  validate(item);
×
1026
}
×
1027

1028
/**
1029
 * @brief ConfigDialog::useTemplate set preference for using templates.
1030
 * @param useTemplate
1031
 */
1032
void ConfigDialog::useTemplate(bool useTemplate) {
×
1033
  ui->checkBoxUseTemplate->setChecked(useTemplate);
×
1034
  on_checkBoxUseTemplate_clicked();
×
1035
}
×
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