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

IJHack / QtPass / 24124365613

08 Apr 2026 07:54AM UTC coverage: 21.044%. Remained the same
24124365613

push

github

web-flow
Merge pull request #929 from IJHack/fix/clang-format-docstrings

docs: add Doxygen docstrings to source files (clang-formatted)

1109 of 5270 relevant lines covered (21.04%)

7.8 hits per line

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

0.0
/src/configdialog.cpp
1
// SPDX-FileCopyrightText: 2016 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
  restoreGeometry(QtPassSettings::getDialogGeometry("configDialog"));
×
36
  if (QtPassSettings::isDialogMaximized("configDialog")) {
×
37
    showMaximized();
×
38
  } else {
39
    move(QtPassSettings::getDialogPos("configDialog"));
×
40
    resize(QtPassSettings::getDialogSize("configDialog"));
×
41
  }
42

43
  ui->passPath->setText(QtPassSettings::getPassExecutable());
×
44
  setGitPath(QtPassSettings::getGitExecutable());
×
45
  ui->gpgPath->setText(QtPassSettings::getGpgExecutable());
×
46
  ui->storePath->setText(QtPassSettings::getPassStore());
×
47

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

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

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

79
#if defined(Q_OS_WIN)
80
  ui->checkBoxUseOtp->hide();
81
  ui->checkBoxUseQrencode->hide();
82
  ui->label_10->hide();
83
#endif
84

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

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

96
  setProfiles(QtPassSettings::getProfiles(), QtPassSettings::getProfile());
×
97
  setPwgenPath(QtPassSettings::getPwgenExecutable());
×
98
  setPasswordConfiguration(QtPassSettings::getPasswordConfiguration());
×
99

100
  usePass(QtPassSettings::isUsePass());
×
101
  useAutoclear(QtPassSettings::isUseAutoclear());
×
102
  useAutoclearPanel(QtPassSettings::isUseAutoclearPanel());
×
103
  useTrayIcon(QtPassSettings::isUseTrayIcon());
×
104
  useGit(QtPassSettings::isUseGit());
×
105

106
  useOtp(QtPassSettings::isUseOtp());
×
107
  useQrencode(QtPassSettings::isUseQrencode());
×
108

109
  usePwgen(QtPassSettings::isUsePwgen());
×
110
  useTemplate(QtPassSettings::isUseTemplate());
×
111

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

118
  ui->comboBoxClipboard->addItem(tr("No Clipboard"));
×
119
  ui->comboBoxClipboard->addItem(tr("Always copy to clipboard"));
×
120
  ui->comboBoxClipboard->addItem(tr("On-demand copy to clipboard"));
×
121

122
  int currentIndex = QtPassSettings::getClipBoardTypeRaw();
×
123
  ui->comboBoxClipboard->setCurrentIndex(currentIndex);
×
124
  on_comboBoxClipboard_activated(currentIndex);
×
125

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

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

140
  connect(ui->profileTable, &QTableWidget::itemChanged, this,
×
141
          &ConfigDialog::onProfileTableItemChanged);
×
142
  connect(this, &ConfigDialog::accepted, this, &ConfigDialog::on_accepted);
×
143
}
×
144

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

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

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

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

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

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

209
      if (!status) {
210
        break;
211
      }
212
    }
213
  } else {
214
    if (item->text().isEmpty() && item->column() != 2) {
×
215
      item->setBackground(Qt::red);
×
216
      item->setToolTip(tr("This field is required"));
×
217
      status = false;
218
    } else {
219
      item->setToolTip(QString());
×
220
    }
221
  }
222

223
  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
×
224
}
×
225

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

282
  QtPassSettings::setVersion(VERSION);
×
283
}
×
284

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

317
/**
318
 * @brief ConfigDialog::on_radioButtonNative_clicked wrapper for
319
 * ConfigDialog::setGroupBoxState()
320
 */
321
void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
×
322

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

329
/**
330
 * @brief ConfigDialog::getSecretKeys get list of secret/private keys
331
 * @return QStringList keys
332
 */
333
auto ConfigDialog::getSecretKeys() -> QStringList {
×
334
  QList<UserInfo> keys = QtPassSettings::getPass()->listKeys("", true);
×
335
  QStringList names;
×
336

337
  if (keys.empty()) {
×
338
    return names;
339
  }
340

341
  foreach (const UserInfo &sec, keys)
×
342
    names << sec.name;
×
343

344
  return names;
×
345
}
346

347
/**
348
 * @brief ConfigDialog::setGroupBoxState update checkboxes.
349
 */
350
void ConfigDialog::setGroupBoxState() {
×
351
  bool state = ui->radioButtonPass->isChecked();
×
352
  ui->groupBoxNative->setEnabled(!state);
×
353
  ui->groupBoxPass->setEnabled(state);
×
354
}
×
355

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

368
  return {};
369
}
×
370

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

384
  return {};
385
}
×
386

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

400
  ui->checkBoxUseGit->setEnabled(state);
×
401
}
×
402

403
/**
404
 * @brief ConfigDialog::on_toolButtonGpg_clicked get gpg application.
405
 */
406
void ConfigDialog::on_toolButtonGpg_clicked() {
×
407
  QString gpg = selectExecutable();
×
408
  if (!gpg.isEmpty()) {
×
409
    ui->gpgPath->setText(gpg);
×
410
  }
411
}
×
412

413
/**
414
 * @brief ConfigDialog::on_pushButtonGenerateKey_clicked open keygen dialog.
415
 */
416
void ConfigDialog::on_pushButtonGenerateKey_clicked() {
×
417
  KeygenDialog d(this);
×
418
  d.exec();
×
419
}
×
420

421
/**
422
 * @brief ConfigDialog::on_toolButtonPass_clicked get pass application.
423
 */
424
void ConfigDialog::on_toolButtonPass_clicked() {
×
425
  QString pass = selectExecutable();
×
426
  if (!pass.isEmpty()) {
×
427
    ui->passPath->setText(pass);
×
428
  }
429
}
×
430

431
/**
432
 * @brief ConfigDialog::on_toolButtonStore_clicked get .password-store
433
 * location.s
434
 */
435
void ConfigDialog::on_toolButtonStore_clicked() {
×
436
  QString store = selectFolder();
×
437
  if (!store.isEmpty()) {
×
438
    ui->storePath->setText(store);
×
439
  }
440
}
×
441

442
/**
443
 * @brief ConfigDialog::on_comboBoxClipboard_activated show and hide options.
444
 * @param index of selectbox (0 = no clipboard).
445
 */
446
void ConfigDialog::on_comboBoxClipboard_activated(int index) {
×
447
  bool state = index > 0;
×
448

449
  ui->checkBoxSelection->setEnabled(state);
×
450
  ui->checkBoxAutoclear->setEnabled(state);
×
451
  ui->checkBoxHidePassword->setEnabled(state);
×
452
  ui->checkBoxHideContent->setEnabled(state);
×
453
  if (state) {
×
454
    ui->spinBoxAutoclearSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
×
455
    ui->labelSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
×
456
  } else {
457
    ui->spinBoxAutoclearSeconds->setEnabled(false);
×
458
    ui->labelSeconds->setEnabled(false);
×
459
  }
460
}
×
461

462
/**
463
 * @brief ConfigDialog::on_checkBoxAutoclearPanel_clicked enable and disable
464
 * options based on autoclear use.
465
 */
466
void ConfigDialog::on_checkBoxAutoclearPanel_clicked() {
×
467
  bool state = ui->checkBoxAutoclearPanel->isChecked();
×
468
  ui->spinBoxAutoclearPanelSeconds->setEnabled(state);
×
469
  ui->labelPanelSeconds->setEnabled(state);
×
470
}
×
471

472
/**
473
 * @brief ConfigDialog::useSelection set the clipboard type use from
474
 * MainWindow.
475
 * @param useSelection
476
 */
477
void ConfigDialog::useSelection(bool useSelection) {
×
478
  ui->checkBoxSelection->setChecked(useSelection);
×
479
  on_checkBoxSelection_clicked();
×
480
}
×
481

482
/**
483
 * @brief ConfigDialog::useAutoclear set the clipboard autoclear use from
484
 * MainWindow.
485
 * @param useAutoclear
486
 */
487
void ConfigDialog::useAutoclear(bool useAutoclear) {
×
488
  ui->checkBoxAutoclear->setChecked(useAutoclear);
×
489
  on_checkBoxAutoclear_clicked();
×
490
}
×
491

492
/**
493
 * @brief ConfigDialog::useAutoclearPanel set the panel autoclear use from
494
 * MainWindow.
495
 * @param useAutoclearPanel
496
 */
497
void ConfigDialog::useAutoclearPanel(bool useAutoclearPanel) {
×
498
  ui->checkBoxAutoclearPanel->setChecked(useAutoclearPanel);
×
499
  on_checkBoxAutoclearPanel_clicked();
×
500
}
×
501

502
/**
503
 * @brief ConfigDialog::on_checkBoxSelection_clicked checkbox clicked, update
504
 * state via ConfigDialog::on_comboBoxClipboard_activated
505
 */
506
void ConfigDialog::on_checkBoxSelection_clicked() {
×
507
  on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
×
508
}
×
509

510
/**
511
 * @brief ConfigDialog::on_checkBoxAutoclear_clicked checkbox clicked, update
512
 * state via ConfigDialog::on_comboBoxClipboard_activated
513
 */
514
void ConfigDialog::on_checkBoxAutoclear_clicked() {
×
515
  on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
×
516
}
×
517

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

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

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

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

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

601
  validate();
×
602
}
×
603

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

628
  validate();
×
629
}
630

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

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

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

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

684
  if (!checkGpgExistence()) {
×
685
    return;
686
  }
687
  if (!checkSecretKeys()) {
×
688
    return;
689
  }
690
  if (!checkPasswordStore()) {
×
691
    return;
692
  }
693
  handleGpgIdFile();
×
694

695
  ui->checkBoxHidePassword->setCheckState(Qt::Checked);
×
696
}
697

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

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

753
#ifdef QT_DEBUG
754
  dbg() << names;
755
#endif
756

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

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

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

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

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

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

850
    if (!useSystray) {
×
851
      ui->checkBoxHideOnClose->setChecked(false);
×
852
      ui->checkBoxStartMinimized->setChecked(false);
×
853
    }
854
  }
855
}
×
856

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

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

879
/**
880
 * @brief ConfigDialog::useGit set preference for using git.
881
 * @param useGit
882
 */
883
void ConfigDialog::useGit(bool useGit) {
×
884
  ui->checkBoxUseGit->setChecked(useGit);
×
885
  on_checkBoxUseGit_clicked();
×
886
}
×
887

888
/**
889
 * @brief ConfigDialog::useOtp set preference for using otp plugin.
890
 * @param useOtp
891
 */
892
void ConfigDialog::useOtp(bool useOtp) {
×
893
  ui->checkBoxUseOtp->setChecked(useOtp);
×
894
}
×
895

896
/**
897
 * @brief ConfigDialog::useOtp set preference for using otp plugin.
898
 * @param useOtp
899
 */
900
void ConfigDialog::useQrencode(bool useQrencode) {
×
901
  ui->checkBoxUseQrencode->setChecked(useQrencode);
×
902
}
×
903

904
/**
905
 * @brief ConfigDialog::on_checkBoxUseGit_clicked enable or disable related
906
 * checkboxes.
907
 */
908
void ConfigDialog::on_checkBoxUseGit_clicked() {
×
909
  ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
×
910
  ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
×
911
  ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
×
912
}
×
913

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

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

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

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

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

983
auto ConfigDialog::getPasswordConfiguration() -> PasswordConfiguration {
×
984
  PasswordConfiguration config;
×
985
  config.length = ui->spinBoxPasswordLength->value();
×
986
  config.selected = static_cast<PasswordConfiguration::characterSet>(
×
987
      ui->passwordCharTemplateSelector->currentIndex());
×
988
  config.Characters[PasswordConfiguration::CUSTOM] =
989
      ui->lineEditPasswordChars->text();
×
990
  return config;
×
991
}
×
992

993
/**
994
 * @brief ConfigDialog::on_passwordCharTemplateSelector_activated sets the
995
 * passwordChar Template
996
 * combo box to the desired entry
997
 * @param entry of
998
 */
999
void ConfigDialog::on_passwordCharTemplateSelector_activated(int index) {
×
1000
  ui->lineEditPasswordChars->setText(
×
1001
      QtPassSettings::getPasswordConfiguration().Characters[index]);
×
1002
  if (index == 3) {
×
1003
    ui->lineEditPasswordChars->setEnabled(true);
×
1004
  } else {
1005
    ui->lineEditPasswordChars->setEnabled(false);
×
1006
  }
1007
}
×
1008

1009
/**
1010
 * @brief ConfigDialog::on_checkBoxUseTemplate_clicked enable or disable the
1011
 * template field and options.
1012
 */
1013
void ConfigDialog::on_checkBoxUseTemplate_clicked() {
×
1014
  ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
×
1015
  ui->checkBoxTemplateAllFields->setEnabled(
×
1016
      ui->checkBoxUseTemplate->isChecked());
×
1017
}
×
1018

1019
void ConfigDialog::onProfileTableItemChanged(QTableWidgetItem *item) {
×
1020
  validate(item);
×
1021
}
×
1022

1023
/**
1024
 * @brief ConfigDialog::useTemplate set preference for using templates.
1025
 * @param useTemplate
1026
 */
1027
void ConfigDialog::useTemplate(bool useTemplate) {
×
1028
  ui->checkBoxUseTemplate->setChecked(useTemplate);
×
1029
  on_checkBoxUseTemplate_clicked();
×
1030
}
×
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