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

IJHack / QtPass / 24161541909

08 Apr 2026 10:16PM UTC coverage: 21.0% (+0.008%) from 20.992%
24161541909

push

github

web-flow
fix: remove redundant move/resize after restoreGeometry (#948)

restoreGeometry already restores position/size, so the separate move()/resize()
calls are unnecessary.

1109 of 5281 relevant lines covered (21.0%)

7.79 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 {
208
          _item->setToolTip(QString());
×
209
        }
210
      }
211

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

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

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

285
  QtPassSettings::setVersion(VERSION);
×
286
}
×
287

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

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

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

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

340
  if (keys.empty()) {
×
341
    return names;
342
  }
343

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

347
  return names;
×
348
}
349

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

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

371
  return {};
372
}
×
373

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

387
  return {};
388
}
×
389

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

403
  ui->checkBoxUseGit->setEnabled(state);
×
404
}
×
405

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

602
  validate();
×
603
}
×
604

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

629
  validate();
×
630
}
631

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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