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

IJHack / QtPass / 25588780598

09 May 2026 02:11AM UTC coverage: 28.31% (+0.3%) from 28.034%
25588780598

push

github

web-flow
feat: auto-probe + override for SSH_AUTH_SOCK (closes #543) (#1438)

* feat: auto-probe + override for SSH_AUTH_SOCK (closes #543)

Long-standing pain point: GUI-launched QtPass doesn't inherit shell-set
environment variables (SSH_AUTH_SOCK, GPG_TTY, etc.) from .bashrc/.zshrc.
Users with gpg-agent's SSH support — particularly YubiKey + GPG SSH auth —
hit "git push/pull" failures when they launch QtPass from the GNOME app
launcher / macOS Dock instead of a terminal. Issue #543 documents this
across multiple distros and the macOS side.

Resolution:

New Util::initialiseSshAuthSock(), called from main() before any
subprocess work happens. Resolution order:

1. If SSH_AUTH_SOCK is already set (terminal launch, .desktop Exec=
   override, parent process), do nothing.
2. If a sshAuthSockOverride setting is configured in QtPass, use it.
3. Probe `gpgconf --list-dirs agent-ssh-socket` (canonical for gpg-agent's
   SSH support).
4. On macOS, fall back to `launchctl getenv SSH_AUTH_SOCK`.

Sets via qputenv() so child processes (git, pass) inherit it.

Settings:

- New QtPassSettings::getSshAuthSockOverride() / setSshAuthSockOverride()
  with corresponding settingsconstants::sshAuthSockOverride key.
- New configdialog.ui field on the Programs tab — labelled
  "SSH_AUTH_SOCK override:" with placeholder text "(auto-probe via
  gpgconf)" and a tooltip referencing the issue. Empty value means
  "auto-probe is fine".

Tests (tests/auto/util/tst_util.cpp):

- sshAuthSockOverrideRoundtrip — getter/setter persistence
- sshAuthSockOverrideEmptyByDefault — default value behaviour
- initialiseSshAuthSockHonoursExistingEnv — env-already-set wins over
  override and over auto-probe (terminal-launch users keep their setup)
- initialiseSshAuthSockUsesOverride — override applied when env unset
- initialiseSshAuthSockOverrideWinsOverProbe — override beats gpgconf
  even on systems where gpgconf would have provided a value
- initialiseSshAuthSockNoOverrideNoEnvProbes — auto-probe... (continued)

31 of 33 new or added lines in 3 files covered. (93.94%)

193 existing lines in 2 files now uncovered.

1886 of 6662 relevant lines covered (28.31%)

27.18 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 "profileinit.h"
7
#include "qtpasssettings.h"
8
#include "ui_configdialog.h"
9
#include "usersdialog.h"
10
#include "util.h"
11
#include <QClipboard>
12
#include <QDir>
13
#include <QFileDialog>
14
#include <QMessageBox>
15
#include <QPushButton>
16
#include <QSystemTrayIcon>
17
#include <QTableWidgetItem>
18
#include <utility>
19
#ifdef Q_OS_WIN
20
#include <windows.h>
21
#endif
22

23
#ifdef QT_DEBUG
24
#include "debughelper.h"
25
#endif
26

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

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

48
  ui->passPath->setText(QtPassSettings::getPassExecutable());
×
49
  setGitPath(QtPassSettings::getGitExecutable());
×
50
  ui->gpgPath->setText(QtPassSettings::getGpgExecutable());
×
51
  ui->storePath->setText(QtPassSettings::getPassStore());
×
NEW
52
  ui->sshAuthSockOverride->setText(QtPassSettings::getSshAuthSockOverride());
×
53

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

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

74
  ui->checkBoxAvoidCapitals->setChecked(QtPassSettings::isAvoidCapitals());
×
75
  ui->checkBoxAvoidNumbers->setChecked(QtPassSettings::isAvoidNumbers());
×
76
  ui->checkBoxLessRandom->setChecked(QtPassSettings::isLessRandom());
×
77
  ui->checkBoxUseSymbols->setChecked(QtPassSettings::isUseSymbols());
×
78
  ui->plainTextEditTemplate->setPlainText(QtPassSettings::getPassTemplate());
×
79
  ui->checkBoxTemplateAllFields->setChecked(
×
80
      QtPassSettings::isTemplateAllFields());
×
81
  ui->checkBoxShowProcessOutput->setChecked(
×
82
      QtPassSettings::isShowProcessOutput());
×
83
  ui->checkBoxAutoPull->setChecked(QtPassSettings::isAutoPull());
×
84
  ui->checkBoxAutoPush->setChecked(QtPassSettings::isAutoPush());
×
85
  ui->checkBoxAlwaysOnTop->setChecked(QtPassSettings::isAlwaysOnTop());
×
86

87
#if defined(Q_OS_WIN)
88
  ui->checkBoxUseOtp->hide();
89
  ui->checkBoxUseQrencode->hide();
90
  ui->label_10->hide();
91
#endif
92

93
  if (!isPassOtpAvailable()) {
×
94
    ui->checkBoxUseOtp->setEnabled(false);
×
95
    ui->checkBoxUseOtp->setToolTip(
×
96
        tr("Pass OTP extension needs to be installed"));
×
97
  }
98

99
  if (!isQrencodeAvailable()) {
×
100
    ui->checkBoxUseQrencode->setEnabled(false);
×
101
    ui->checkBoxUseQrencode->setToolTip(tr("qrencode needs to be installed"));
×
102
  }
103

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

109
  setProfiles(QtPassSettings::getProfiles(), QtPassSettings::getProfile());
×
110

111
  useGit(QtPassSettings::isUseGit());
×
112

113
  useOtp(QtPassSettings::isUseOtp());
×
114
  useGrepSearch(QtPassSettings::isUseGrepSearch());
×
115
  useQrencode(QtPassSettings::isUseQrencode());
×
116

117
  usePwgen(QtPassSettings::isUsePwgen());
×
118
  useTemplate(QtPassSettings::isUseTemplate());
×
119

120
  ui->profileTable->verticalHeader()->hide();
×
121
  ui->profileTable->horizontalHeader()->setSectionResizeMode(
×
122
      1, QHeaderView::Stretch);
123
  ui->label->setText(ui->label->text() + VERSION);
×
124
  ui->comboBoxClipboard->clear();
×
125

126
  ui->comboBoxClipboard->addItem(tr("No Clipboard"));
×
127
  ui->comboBoxClipboard->addItem(tr("Always copy to clipboard"));
×
128
  ui->comboBoxClipboard->addItem(tr("On-demand copy to clipboard"));
×
129

130
  int currentIndex = QtPassSettings::getClipBoardTypeRaw();
×
131
  ui->comboBoxClipboard->setCurrentIndex(currentIndex);
×
132
  on_comboBoxClipboard_activated(currentIndex);
×
133

134
  QClipboard *clip = QApplication::clipboard();
×
135
  if (!clip->supportsSelection()) {
×
136
    useSelection(false);
×
137
    ui->checkBoxSelection->setVisible(false);
×
138
  } else {
139
    useSelection(QtPassSettings::isUseSelection());
×
140
  }
141

142
  if (!Util::configIsValid()) {
×
143
    // Show Programs tab, which is likely
144
    // what the user needs to fix now.
145
    ui->tabWidget->setCurrentIndex(1);
×
146
  }
147

148
  connect(ui->profileTable, &QTableWidget::itemChanged, this,
×
149
          &ConfigDialog::onProfileTableItemChanged);
×
150
  connect(ui->profileTable, &QTableWidget::itemSelectionChanged, this,
×
151
          &ConfigDialog::onProfileTableSelectionChanged);
×
152
  connect(this, &ConfigDialog::accepted, this, &ConfigDialog::on_accepted);
×
153
}
×
154

155
/**
156
 * @brief ConfigDialog::~ConfigDialog config destructor, makes sure the
157
 * mainWindow knows about git, gpg and pass executables.
158
 */
159
ConfigDialog::~ConfigDialog() {
×
160
  QtPassSettings::setGitExecutable(ui->gitPath->text());
×
161
  QtPassSettings::setGpgExecutable(ui->gpgPath->text());
×
162
  QtPassSettings::setPassExecutable(ui->passPath->text());
×
163
}
×
164

165
/**
166
 * @brief ConfigDialog::setGitPath set the git executable path.
167
 * Make sure the checkBoxUseGit is updated.
168
 * @param path
169
 */
170
void ConfigDialog::setGitPath(const QString &path) {
×
171
  ui->gitPath->setText(path);
×
172
  ui->checkBoxUseGit->setEnabled(!path.isEmpty());
×
173
  if (path.isEmpty()) {
×
174
    useGit(false);
×
175
  }
176
}
×
177

178
/**
179
 * @brief ConfigDialog::usePass set whether or not we want to use pass.
180
 * Update radio buttons accordingly.
181
 * @param usePass
182
 */
183
void ConfigDialog::usePass(bool usePass) {
×
184
  ui->radioButtonNative->setChecked(!usePass);
×
185
  ui->radioButtonPass->setChecked(usePass);
×
186
  setGroupBoxState();
×
187
}
×
188

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

204
  if (item == nullptr) {
×
205
    for (int i = 0; i < ui->profileTable->rowCount(); i++) {
×
206
      for (int j = 0; j < ui->profileTable->columnCount(); j++) {
×
207
        QTableWidgetItem *_item = ui->profileTable->item(i, j);
×
208

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

220
      if (!status) {
221
        break;
222
      }
223
    }
224
  } else {
225
    if (item->text().isEmpty() && item->column() != 2) {
×
226
      item->setBackground(Qt::red);
×
227
      item->setToolTip(tr("This field is required"));
×
228
      status = false;
229
    } else {
230
      item->setBackground(QBrush());
×
231
      item->setToolTip(QString());
×
232
    }
233
  }
234

235
  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
×
236
}
×
237

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

298
  QtPassSettings::setVersion(VERSION);
×
299

300
  // Initialize new profiles that need pass/git initialization
301
  initializeNewProfiles(existingProfiles);
×
302
}
×
303

304
/**
305
 * @brief Automatically detects required external binaries in the system PATH
306
 * and updates the dialog fields.
307
 * @example
308
 * ConfigDialog configDialog;
309
 * configDialog.on_autodetectButton_clicked();
310
 *
311
 * @return void - This function does not return a value.
312
 */
313
void ConfigDialog::on_autodetectButton_clicked() {
×
314
  QString pass = Util::findBinaryInPath("pass");
×
315
  if (!pass.isEmpty()) {
×
316
    ui->passPath->setText(pass);
×
317
  }
318
  usePass(!pass.isEmpty());
×
319
  QString gpg = Util::findBinaryInPath("gpg2");
×
320
  if (gpg.isEmpty()) {
×
321
    gpg = Util::findBinaryInPath("gpg");
×
322
  }
323
  if (!gpg.isEmpty()) {
×
324
    ui->gpgPath->setText(gpg);
×
325
  }
326
  QString git = Util::findBinaryInPath("git");
×
327
  if (!git.isEmpty()) {
×
328
    ui->gitPath->setText(git);
×
329
  }
330
  QString pwgen = Util::findBinaryInPath("pwgen");
×
331
  if (!pwgen.isEmpty()) {
×
332
    ui->pwgenPath->setText(pwgen);
×
333
  }
334
}
×
335

336
/**
337
 * @brief ConfigDialog::on_radioButtonNative_clicked wrapper for
338
 * ConfigDialog::setGroupBoxState()
339
 */
340
void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
×
341

342
/**
343
 * @brief ConfigDialog::on_radioButtonPass_clicked wrapper for
344
 * ConfigDialog::setGroupBoxState()
345
 */
346
void ConfigDialog::on_radioButtonPass_clicked() { setGroupBoxState(); }
×
347

348
/**
349
 * @brief ConfigDialog::getSecretKeys get list of secret/private keys
350
 * @return QStringList keys
351
 */
352
auto ConfigDialog::getSecretKeys() -> QStringList {
×
353
  QList<UserInfo> keys = QtPassSettings::getPass()->listKeys("", true);
×
354
  QStringList names;
×
355

356
  if (keys.empty()) {
×
357
    return names;
358
  }
359

360
  foreach (const UserInfo &sec, keys)
×
361
    names << sec.name;
×
362

363
  return names;
×
364
}
365

366
/**
367
 * @brief ConfigDialog::setGroupBoxState update checkboxes.
368
 */
369
void ConfigDialog::setGroupBoxState() {
×
370
  bool state = ui->radioButtonPass->isChecked();
×
371
  ui->groupBoxNative->setEnabled(!state);
×
372
  ui->groupBoxPass->setEnabled(state);
×
373
  if (state) {
×
374
    // pass mode: disable all password generation controls
375
    ui->spinBoxPasswordLength->setEnabled(false);
×
376
    ui->checkBoxUsePwgen->setEnabled(false);
×
377
    ui->checkBoxAvoidCapitals->setEnabled(false);
×
378
    ui->checkBoxUseSymbols->setEnabled(false);
×
379
    ui->checkBoxLessRandom->setEnabled(false);
×
380
    ui->checkBoxAvoidNumbers->setEnabled(false);
×
381
    ui->labelPasswordChars->setEnabled(false);
×
382
    ui->passwordCharTemplateSelector->setEnabled(false);
×
383
    ui->lineEditPasswordChars->setEnabled(false);
×
384
  } else {
385
    // native mode: restore pwgen/charset state from existing handlers
386
    ui->spinBoxPasswordLength->setEnabled(true);
×
387
    ui->checkBoxUsePwgen->setEnabled(!ui->pwgenPath->text().isEmpty());
×
388
    on_checkBoxUsePwgen_clicked();
×
389
  }
390
}
×
391

392
/**
393
 * @brief ConfigDialog::selectExecutable pop-up to choose an executable.
394
 * @return
395
 */
396
auto ConfigDialog::selectExecutable() -> QString {
×
397
  QFileDialog dialog(this);
×
398
  dialog.setFileMode(QFileDialog::ExistingFile);
×
399
  dialog.setOption(QFileDialog::ReadOnly);
×
400
  if (dialog.exec()) {
×
401
    return dialog.selectedFiles().constFirst();
×
402
  }
403

404
  return {};
405
}
×
406

407
/**
408
 * @brief ConfigDialog::selectFolder pop-up to choose a folder.
409
 * @return
410
 */
411
auto ConfigDialog::selectFolder() -> QString {
×
412
  QFileDialog dialog(this);
×
413
  dialog.setFileMode(QFileDialog::Directory);
×
414
  dialog.setFilter(QDir::NoFilter);
×
415
  dialog.setOption(QFileDialog::ShowDirsOnly);
×
416
  if (dialog.exec()) {
×
417
    return dialog.selectedFiles().constFirst();
×
418
  }
419

420
  return {};
421
}
×
422

423
/**
424
 * @brief ConfigDialog::on_toolButtonGit_clicked get git application.
425
 * Enable checkboxes if found.
426
 */
427
void ConfigDialog::on_toolButtonGit_clicked() {
×
428
  QString git = selectExecutable();
×
429
  bool state = !git.isEmpty();
×
430
  if (state) {
×
431
    ui->gitPath->setText(git);
×
432
  } else {
433
    useGit(false);
×
434
  }
435

436
  ui->checkBoxUseGit->setEnabled(state);
×
437
}
×
438

439
/**
440
 * @brief ConfigDialog::on_toolButtonGpg_clicked get gpg application.
441
 */
442
void ConfigDialog::on_toolButtonGpg_clicked() {
×
443
  QString gpg = selectExecutable();
×
444
  if (!gpg.isEmpty()) {
×
445
    ui->gpgPath->setText(gpg);
×
446
  }
447
}
×
448

449
/**
450
 * @brief ConfigDialog::on_pushButtonGenerateKey_clicked open keygen dialog.
451
 */
452
void ConfigDialog::on_pushButtonGenerateKey_clicked() {
×
453
  KeygenDialog d(this);
×
454
  d.exec();
×
455
}
×
456

457
/**
458
 * @brief ConfigDialog::on_toolButtonPass_clicked get pass application.
459
 */
460
void ConfigDialog::on_toolButtonPass_clicked() {
×
461
  QString pass = selectExecutable();
×
462
  if (!pass.isEmpty()) {
×
463
    ui->passPath->setText(pass);
×
464
  }
465
}
×
466

467
/**
468
 * @brief ConfigDialog::on_toolButtonStore_clicked get .password-store
469
 * location.
470
 */
471
void ConfigDialog::on_toolButtonStore_clicked() {
×
472
  QString store = selectFolder();
×
473
  if (!store.isEmpty()) {
×
474
    ui->storePath->setText(store);
×
475
  }
476
}
×
477

478
/**
479
 * @brief ConfigDialog::on_comboBoxClipboard_activated show and hide options.
480
 * @param index of selectbox (0 = no clipboard).
481
 */
482
void ConfigDialog::on_comboBoxClipboard_activated(int index) {
×
483
  bool state = index > 0;
×
484

485
  ui->checkBoxSelection->setEnabled(state);
×
486
  ui->checkBoxAutoclear->setEnabled(state);
×
487
  ui->checkBoxHidePassword->setEnabled(state);
×
488
  ui->checkBoxHideContent->setEnabled(state);
×
489
  if (state) {
×
490
    ui->spinBoxAutoclearSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
×
491
    ui->labelSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
×
492
  } else {
493
    ui->spinBoxAutoclearSeconds->setEnabled(false);
×
494
    ui->labelSeconds->setEnabled(false);
×
495
  }
496
}
×
497

498
/**
499
 * @brief ConfigDialog::on_checkBoxAutoclearPanel_clicked enable and disable
500
 * options based on autoclear use.
501
 */
502
void ConfigDialog::on_checkBoxAutoclearPanel_clicked() {
×
503
  bool state = ui->checkBoxAutoclearPanel->isChecked();
×
504
  ui->spinBoxAutoclearPanelSeconds->setEnabled(state);
×
505
  ui->labelPanelSeconds->setEnabled(state);
×
506
}
×
507

508
/**
509
 * @brief ConfigDialog::useSelection set the clipboard type use from
510
 * MainWindow.
511
 * @param useSelection
512
 */
513
void ConfigDialog::useSelection(bool useSelection) {
×
514
  ui->checkBoxSelection->setChecked(useSelection);
×
515
  on_checkBoxSelection_clicked();
×
516
}
×
517

518
/**
519
 * @brief ConfigDialog::useAutoclear set the clipboard autoclear use from
520
 * MainWindow.
521
 * @param useAutoclear
522
 */
523
void ConfigDialog::useAutoclear(bool useAutoclear) {
×
524
  ui->checkBoxAutoclear->setChecked(useAutoclear);
×
525
  on_checkBoxAutoclear_clicked();
×
526
}
×
527

528
/**
529
 * @brief ConfigDialog::useAutoclearPanel set the panel autoclear use from
530
 * MainWindow.
531
 * @param useAutoclearPanel
532
 */
533
void ConfigDialog::useAutoclearPanel(bool useAutoclearPanel) {
×
534
  ui->checkBoxAutoclearPanel->setChecked(useAutoclearPanel);
×
535
  on_checkBoxAutoclearPanel_clicked();
×
536
}
×
537

538
/**
539
 * @brief ConfigDialog::on_checkBoxSelection_clicked checkbox clicked, update
540
 * state via ConfigDialog::on_comboBoxClipboard_activated
541
 */
542
void ConfigDialog::on_checkBoxSelection_clicked() {
×
543
  on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
×
544
}
×
545

546
/**
547
 * @brief ConfigDialog::on_checkBoxAutoclear_clicked checkbox clicked, update
548
 * state via ConfigDialog::on_comboBoxClipboard_activated
549
 */
550
void ConfigDialog::on_checkBoxAutoclear_clicked() {
×
551
  on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
×
552
}
×
553

554
/**
555
 * @brief ConfigDialog::genKey tunnel function to make MainWindow generate a
556
 * gpg key pair.
557
 * @param batch
558
 * @param dialog
559
 */
560
void ConfigDialog::genKey(const QString &batch, QDialog *dialog) {
×
561
  mainWindow->generateKeyPair(batch, dialog);
×
562
}
×
563

564
/**
565
 * @brief ConfigDialog::setProfiles set the profiles and chosen profile from
566
 * MainWindow.
567
 * @param profiles
568
 * @param profile
569
 */
570
void ConfigDialog::setProfiles(QHash<QString, QHash<QString, QString>> profiles,
×
571
                               const QString &currentProfile) {
572
  if (profiles.contains("")) {
×
573
    profiles.remove("");
×
574
    // remove weird "" key value pairs
575
  }
576

577
  // Cache profiles for use in onProfileTableSelectionChanged
578
  m_profiles = profiles;
×
579

580
  ui->profileTable->setRowCount(static_cast<int>(profiles.count()));
×
581
  QHashIterator<QString, QHash<QString, QString>> i(profiles);
×
582
  int n = 0;
583
  while (i.hasNext()) {
×
584
    i.next();
585
    if (!i.value().isEmpty() && !i.key().isEmpty()) {
×
586
      ui->profileTable->setItem(n, 0, new QTableWidgetItem(i.key()));
×
587
      ui->profileTable->setItem(n, 1,
×
588
                                new QTableWidgetItem(i.value().value("path")));
×
589
      ui->profileTable->setItem(
×
590
          n, 2, new QTableWidgetItem(i.value().value("signingKey")));
×
591
      if (i.key() == currentProfile) {
×
592
        ui->profileTable->selectRow(n);
×
593
        // Load git settings for current profile
594
        loadGitSettingsForProfile(currentProfile, m_profiles);
×
595
      }
596
    }
597
    ++n;
×
598
  }
599
}
×
600

601
/**
602
 * @brief Load git settings for a specific profile.
603
 * @param profileName The profile name.
604
 * @param profiles The profiles hash containing git settings.
605
 */
606
void ConfigDialog::loadGitSettingsForProfile(
×
607
    const QString &profileName,
608
    const QHash<QString, QHash<QString, QString>> &profiles) {
609
  if (profiles.contains(profileName)) {
×
610
    const QHash<QString, QString> &profile = profiles.value(profileName);
×
611
    QString useGitStr = profile.value("useGit");
×
612
    QString autoPushStr = profile.value("autoPush");
×
613
    QString autoPullStr = profile.value("autoPull");
×
614

615
    // Load profile-specific git settings if set, otherwise use global settings
616
    if (!useGitStr.isEmpty()) {
×
617
      useGit(useGitStr == "true");
×
618
      ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
×
619
      ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
×
620
      if (autoPushStr == "true" || autoPushStr == "false") {
×
621
        ui->checkBoxAutoPush->setChecked(autoPushStr == "true");
×
622
      }
623
      if (autoPullStr == "true" || autoPullStr == "false") {
×
624
        ui->checkBoxAutoPull->setChecked(autoPullStr == "true");
×
625
      }
626
    }
627
    // If not set (empty), leave global settings as-is for migration
628
  }
×
629
}
×
630

631
/**
632
 * @brief ConfigDialog::getProfiles return profile list.
633
 * @return
634
 */
635
auto ConfigDialog::getProfiles() -> QHash<QString, QHash<QString, QString>> {
×
636
  // Get currently selected profile name
637
  QList<QTableWidgetItem *> selected = ui->profileTable->selectedItems();
×
638
  QString selectedProfile;
×
639
  if (!selected.isEmpty()) {
×
640
    selectedProfile =
641
        ui->profileTable->item(selected.first()->row(), 0)->text();
×
642
  }
643

644
  // Use cached m_profiles to preserve git settings for non-selected profiles
645
  QHash<QString, QHash<QString, QString>> existingProfiles = m_profiles;
646

647
  QHash<QString, QHash<QString, QString>> profiles;
×
648
  // Check?
649
  for (int i = 0; i < ui->profileTable->rowCount(); ++i) {
×
650
    QHash<QString, QString> profile;
×
651
    QTableWidgetItem *pathItem = ui->profileTable->item(i, 1);
×
652
    if (nullptr != pathItem) {
×
653
      QTableWidgetItem *item = ui->profileTable->item(i, 0);
×
654
      if (item == nullptr) {
×
655
        continue;
656
      }
657
      profile["path"] = pathItem->text();
×
658
      QTableWidgetItem *signingKeyItem = ui->profileTable->item(i, 2);
×
659
      if (nullptr != signingKeyItem) {
×
660
        profile["signingKey"] = signingKeyItem->text();
×
661
      }
662

663
      // Only update git settings for the currently selected profile
664
      // Preserve existing git settings for other profiles
665
      if (item->text() == selectedProfile) {
×
666
        profile["useGit"] = ui->checkBoxUseGit->isChecked() ? "true" : "false";
×
667
        profile["autoPush"] =
×
668
            ui->checkBoxAutoPush->isChecked() ? "true" : "false";
×
669
        profile["autoPull"] =
×
670
            ui->checkBoxAutoPull->isChecked() ? "true" : "false";
×
671
      } else if (existingProfiles.contains(item->text())) {
×
672
        // Preserve existing git settings for non-selected profiles
673
        const QHash<QString, QString> &existing =
674
            existingProfiles.value(item->text());
×
675
        if (existing.contains("useGit")) {
×
676
          profile["useGit"] = existing.value("useGit");
×
677
        }
678
        if (existing.contains("autoPush")) {
×
679
          profile["autoPush"] = existing.value("autoPush");
×
680
        }
681
        if (existing.contains("autoPull")) {
×
682
          profile["autoPull"] = existing.value("autoPull");
×
683
        }
684
      }
×
685
      profiles.insert(item->text(), profile);
×
686
    }
687
  }
×
688
  // Update cache with current in-dialog state
689
  m_profiles = profiles;
×
690
  return profiles;
×
691
}
×
692

693
/**
694
 * @brief Initialize new profiles that need pass/git initialization.
695
 * @param existingProfiles The profiles that existed before the dialog was
696
 * opened.
697
 */
698
void ConfigDialog::initializeNewProfiles(
×
699
    const QHash<QString, QHash<QString, QString>> &existingProfiles) {
700
  QHash<QString, QHash<QString, QString>> newProfiles = getProfiles();
×
701

702
  // Collect keys and sort for deterministic iteration
703
  QStringList keys = newProfiles.keys();
×
704
  keys.sort();
705

706
  for (const QString &name : keys) {
×
707
    const QString &path = newProfiles.value(name).value("path");
×
708

709
    // Skip if already existed before (check by name and path)
710
    if (existingProfiles.contains(name) &&
×
711
        existingProfiles.value(name).value("path") == path) {
×
712
      continue;
×
713
    }
714

715
    // This is a new profile - create directory if needed and initialize
716
    // Note: needsInit returns false for non-existent directories, so we
717
    // must create the directory first.
718
    QString cleanPath = QDir::cleanPath(path);
×
719
    QDir dir(cleanPath);
×
720
    if (!dir.exists()) {
×
721
      if (QMessageBox::question(
×
722
              this, tr("Create profile directory?"),
×
723
              tr("Would you like to create a password store at %1?")
×
724
                  .arg(cleanPath),
×
725
              QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
726
        continue;
×
727
      }
728
      if (!QDir().mkpath(cleanPath)) {
×
729
        QMessageBox::warning(
×
730
            this, tr("Error"),
×
731
            tr("Could not create profile directory: %1").arg(cleanPath));
×
732
        continue;
×
733
      }
734
    }
735

736
    // Now check if initialization is needed (directory exists with no .gpg-id)
737
    if (!ProfileInit::needsInit(cleanPath)) {
×
738
      continue;
×
739
    }
740

741
    // Temporarily switch the active store so pass/git init operate on
742
    // the new profile's directory rather than the currently-saved one.
743
    const QString prevStore = QtPassSettings::getPassStore();
×
744
    QtPassSettings::setPassStore(cleanPath);
×
745

746
    // Show user selection dialog for GPG recipients
747
    // UsersDialog will run pass init when accepted
748
    UsersDialog usersDialog(cleanPath, this);
×
749
    usersDialog.setWindowTitle(tr("Select recipients for %1").arg(name));
×
750
    const int result = usersDialog.exec();
×
751

752
    // Use per-profile useGit setting, falling back to global if not set
753
    QString useGitStr = newProfiles.value(name).value("useGit");
×
754
    bool useGit =
755
        useGitStr.isEmpty() ? QtPassSettings::isUseGit() : useGitStr == "true";
×
756

757
    if (result == QDialog::Accepted && useGit) {
×
758
      QtPassSettings::getPass()->GitInit();
×
759
    }
760

761
    // Restore previous store setting
762
    QtPassSettings::setPassStore(prevStore);
×
763
  }
×
764
}
×
765

766
/**
767
 * @brief ConfigDialog::on_addButton_clicked add a profile row.
768
 */
769
void ConfigDialog::on_addButton_clicked() {
×
770
  bool sortingEnabled = ui->profileTable->isSortingEnabled();
×
771
  ui->profileTable->setSortingEnabled(false);
×
772

773
  int n = ui->profileTable->rowCount();
×
774
  ui->profileTable->insertRow(n);
×
775
  ui->profileTable->setItem(n, 0, new QTableWidgetItem(tr("New Profile")));
×
776
  ui->profileTable->setItem(n, 1, new QTableWidgetItem(ui->storePath->text()));
×
777
  ui->profileTable->setItem(n, 2, new QTableWidgetItem());
×
778

779
  ui->profileTable->setSortingEnabled(sortingEnabled);
×
780

781
  int currentRow = ui->profileTable->row(ui->profileTable->item(n, 0));
×
782
  ui->profileTable->selectRow(currentRow);
×
783
  ui->deleteButton->setEnabled(true);
×
784

785
  ui->profileTable->editItem(ui->profileTable->item(currentRow, 0));
×
786
  ui->profileTable->item(currentRow, 0)->setSelected(true);
×
787

788
  validate();
×
789
  updateProfileStatus(currentRow);
×
790
}
×
791

792
/**
793
 * @brief ConfigDialog::on_profileTable_cellDoubleClicked open folder browser
794
 * for path column (column 1).
795
 */
796
void ConfigDialog::on_profileTable_cellDoubleClicked(int row, int column) {
×
797
  if (column == 1) {
×
798
    QString dir = selectFolder();
×
799
    if (!dir.isEmpty()) {
×
800
      ui->profileTable->item(row, 1)->setText(dir);
×
801
    }
802
  }
803
}
×
804

805
/**
806
 * @brief ConfigDialog::on_deleteButton_clicked remove a profile row.
807
 */
808
void ConfigDialog::on_deleteButton_clicked() {
×
809
  QSet<int> selectedRows; //  we use a set to prevent doubles
810
  QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems();
×
811
  if (itemList.count() == 0) {
×
812
    QMessageBox::warning(this, tr("No profile selected"),
×
813
                         tr("No profile selected to delete"));
×
814
    return;
815
  }
816
  QTableWidgetItem *item;
817
  foreach (item, itemList)
×
818
    selectedRows.insert(item->row());
×
819
  // get a list, and sort it big to small
820
  QList<int> rows = selectedRows.values();
×
821
  std::sort(rows.begin(), rows.end());
×
822
  // now actually do the removing:
823
  foreach (int row, rows)
×
824
    ui->profileTable->removeRow(row);
×
825
  if (ui->profileTable->rowCount() < 1) {
×
826
    ui->deleteButton->setEnabled(false);
×
827
  }
828

829
  validate();
×
830
  updateProfileStatus(-1);
×
831
}
832

833
/**
834
 * @brief ConfigDialog::criticalMessage wrapper for showing critical messages
835
 * in a popup.
836
 * @param title
837
 * @param text
838
 */
839
void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
×
840
  QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
×
841
}
×
842

843
/**
844
 * @brief Checks whether the qrencode executable is available on the system.
845
 * @example
846
 * bool result = ConfigDialog::isQrencodeAvailable();
847
 * std::cout << result << std::endl; // Expected output: true if qrencode is
848
 * found, otherwise false
849
 *
850
 * @return bool - True if qrencode is available; otherwise false. On Windows,
851
 * always returns false.
852
 */
853
auto ConfigDialog::isQrencodeAvailable() -> bool {
×
854
#ifdef Q_OS_WIN
855
  return false;
856
#else
857
  QProcess which;
×
858
  which.start("which", QStringList() << "qrencode");
×
859
  which.waitForFinished();
×
860
  QtPassSettings::setQrencodeExecutable(
×
861
      which.readAllStandardOutput().trimmed());
×
862
  return which.exitCode() == 0;
×
863
#endif
864
}
×
865

866
auto ConfigDialog::isPassOtpAvailable() -> bool {
×
867
#ifdef Q_OS_WIN
868
  return false;
869
#else
870
  QProcess pass;
×
871
  pass.start(QtPassSettings::getPassExecutable(), QStringList() << "otp"
×
872
                                                                << "--help");
×
873
  pass.waitForFinished(2000);
×
874
  return pass.exitCode() == 0;
×
875
#endif
876
}
×
877

878
/**
879
 * @brief ConfigDialog::wizard first-time use wizard.
880
 */
881
void ConfigDialog::wizard() {
×
882
  (void)Util::configIsValid();
×
883
  on_autodetectButton_clicked();
×
884

885
  if (!checkGpgExistence()) {
×
886
    return;
887
  }
888
  if (!checkSecretKeys()) {
×
889
    return;
890
  }
891
  if (!checkPasswordStore()) {
×
892
    return;
893
  }
894
  handleGpgIdFile();
×
895

896
  ui->checkBoxHidePassword->setCheckState(Qt::Checked);
×
897
}
898

899
/**
900
 * @brief Checks whether the configured GnuPG executable exists.
901
 * @example
902
 * bool result = ConfigDialog::checkGpgExistence();
903
 * std::cout << result << std::endl; // Expected output: true if GnuPG is found,
904
 * false otherwise
905
 *
906
 * @return bool - True if the GnuPG path is valid or uses a WSL command prefix;
907
 * false if the executable cannot be found and an error message is shown.
908
 */
909
auto ConfigDialog::checkGpgExistence() -> bool {
×
910
  QString gpg = ui->gpgPath->text();
×
911
  if (!gpg.startsWith("wsl ") && !QFile(gpg).exists()) {
×
912
    criticalMessage(
×
913
        tr("GnuPG not found"),
×
914
#ifdef Q_OS_WIN
915
#ifdef WINSTORE
916
        tr("Please install GnuPG on your system.<br>Install "
917
           "<strong>Ubuntu</strong> from the Microsoft Store to get it.<br>"
918
           "If you already did so, make sure you started it once and<br>"
919
           "click \"Autodetect\" in the next dialog.")
920
#else
921
        tr("Please install GnuPG on your system.<br>Install "
922
           "<strong>Ubuntu</strong> from the Microsoft Store<br>or <a "
923
           "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
924
           "from GnuPG.org")
925
#endif
926
#else
927
        tr("Please install GnuPG on your system.<br>Install "
×
928
           "<strong>gpg</strong> using your favorite package manager<br>or "
929
           "<a "
930
           "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
931
           "from GnuPG.org")
932
#endif
933
    );
934
    return false;
×
935
  }
936
  return true;
937
}
938

939
/**
940
 * @brief Checks whether secret keys are available and, if needed, prompts the
941
 * user to generate them.
942
 * @example
943
 * bool result = ConfigDialog.checkSecretKeys();
944
 * std::cout << result << std::endl; // Expected output: true if keys are
945
 * present or key generation dialog is accepted, false otherwise
946
 *
947
 * @return bool - Returns true when secret keys are already available or the key
948
 * generation dialog is accepted; false if the dialog is rejected.
949
 */
950
auto ConfigDialog::checkSecretKeys() -> bool {
×
951
  QString gpg = ui->gpgPath->text();
×
952
  QStringList names = getSecretKeys();
×
953

954
#ifdef QT_DEBUG
955
  dbg() << names;
956
#endif
957

958
  if ((gpg.startsWith("wsl ") || QFile(gpg).exists()) && names.empty()) {
×
959
    KeygenDialog d(this);
×
960
    return d.exec();
×
961
  }
×
962
  return true;
963
}
964

965
/**
966
 * @brief Checks whether the password-store path exists and prompts the user to
967
 * create it if it does not.
968
 * @example
969
 * bool result = ConfigDialog::checkPasswordStore();
970
 * std::cout << std::boolalpha << result << std::endl; // Expected output: true
971
 * if the store exists or is created successfully, false if creation fails
972
 *
973
 * @return bool - True if the password-store exists or is successfully created,
974
 * false if creation fails.
975
 */
976
auto ConfigDialog::checkPasswordStore() -> bool {
×
977
  QString passStore = ui->storePath->text();
×
978

979
  if (!QFile(passStore).exists()) {
×
980
    if (QMessageBox::question(
×
981
            this, tr("Create password-store?"),
×
982
            tr("Would you like to create a password-store at %1?")
×
983
                .arg(passStore),
×
984
            QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
985
      if (!QDir().mkdir(passStore)) {
×
986
        QMessageBox::warning(
×
987
            this, tr("Error"),
×
988
            tr("Failed to create password-store at: %1").arg(passStore));
×
989
        return false;
×
990
      }
991
#ifdef Q_OS_WIN
992
      SetFileAttributes(passStore.toStdWString().c_str(),
993
                        FILE_ATTRIBUTE_HIDDEN);
994
#endif
995
      if (ui->checkBoxUseGit->isChecked()) {
×
996
        emit mainWindow->passGitInitNeeded();
×
997
      }
998
      mainWindow->userDialog(passStore);
×
999
    }
1000
  }
1001
  return true;
1002
}
1003

1004
/**
1005
 * @brief Handles selection and validation of the password store's .gpg-id file.
1006
 * @example
1007
 * ConfigDialog dialog;
1008
 * dialog.handleGpgIdFile();
1009
 *
1010
 * @return void - This method does not return a value; it updates the UI flow
1011
 * and may prompt the user to choose a valid password store.
1012
 */
1013
void ConfigDialog::handleGpgIdFile() {
×
1014
  QString passStore = ui->storePath->text();
×
1015
  if (!QFile(QDir(passStore).filePath(".gpg-id")).exists()) {
×
1016
#ifdef QT_DEBUG
1017
    dbg() << ".gpg-id file does not exist";
1018
#endif
1019
    criticalMessage(tr("Password store not initialised"),
×
1020
                    tr("The folder %1 doesn't seem to be a password store or "
×
1021
                       "is not yet initialised.")
1022
                        .arg(passStore));
×
1023

1024
    while (!QFile(passStore).exists()) {
×
1025
      on_toolButtonStore_clicked();
×
1026
      if (passStore == ui->storePath->text()) {
×
1027
        return;
1028
      }
1029
      passStore = ui->storePath->text();
×
1030
    }
1031
    if (!QFile(passStore + ".gpg-id").exists()) {
×
1032
#ifdef QT_DEBUG
1033
      dbg() << ".gpg-id file still does not exist :/";
1034
#endif
1035
      mainWindow->userDialog(passStore);
×
1036
    }
1037
  }
1038
}
1039

1040
/**
1041
 * @brief ConfigDialog::useTrayIcon set preference for using trayicon.
1042
 * Enable or disable related checkboxes accordingly.
1043
 * @param useSystray
1044
 */
1045
void ConfigDialog::useTrayIcon(bool useSystray) {
×
1046
  if (QSystemTrayIcon::isSystemTrayAvailable()) {
×
1047
    ui->checkBoxUseTrayIcon->setChecked(useSystray);
×
1048
    ui->checkBoxHideOnClose->setEnabled(useSystray);
×
1049
    ui->checkBoxStartMinimized->setEnabled(useSystray);
×
1050

1051
    if (!useSystray) {
×
1052
      ui->checkBoxHideOnClose->setChecked(false);
×
1053
      ui->checkBoxStartMinimized->setChecked(false);
×
1054
    }
1055
  }
1056
}
×
1057

1058
/**
1059
 * @brief ConfigDialog::on_checkBoxUseTrayIcon_clicked enable and disable
1060
 * related checkboxes.
1061
 */
1062
void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
×
1063
  bool state = ui->checkBoxUseTrayIcon->isChecked();
×
1064
  ui->checkBoxHideOnClose->setEnabled(state);
×
1065
  ui->checkBoxStartMinimized->setEnabled(state);
×
1066
}
×
1067

1068
/**
1069
 * @brief ConfigDialog::closeEvent close this window.
1070
 * @param event
1071
 */
1072
void ConfigDialog::closeEvent(QCloseEvent *event) {
×
1073
  QtPassSettings::setDialogGeometry("configDialog", saveGeometry());
×
1074
  if (!isMaximized()) {
×
1075
    QtPassSettings::setDialogPos("configDialog", pos());
×
1076
    QtPassSettings::setDialogSize("configDialog", size());
×
1077
  }
1078
  QtPassSettings::setDialogMaximized("configDialog", isMaximized());
×
1079
  event->accept();
1080
}
×
1081

1082
/**
1083
 * @brief ConfigDialog::useGit set preference for using git.
1084
 * @param useGit
1085
 */
1086
void ConfigDialog::useGit(bool useGit) {
×
1087
  ui->checkBoxUseGit->setChecked(useGit);
×
1088
  on_checkBoxUseGit_clicked();
×
1089
}
×
1090

1091
/**
1092
 * @brief ConfigDialog::useOtp set preference for using otp plugin.
1093
 * @param useOtp
1094
 */
1095
void ConfigDialog::useOtp(bool useOtp) {
×
1096
  ui->checkBoxUseOtp->setChecked(useOtp);
×
1097
}
×
1098

1099
void ConfigDialog::useGrepSearch(bool useGrepSearch) {
×
1100
  ui->checkBoxUseGrepSearch->setChecked(useGrepSearch);
×
1101
}
×
1102

1103
/**
1104
 * @brief ConfigDialog::useQrencode set preference for using qrencode plugin.
1105
 * @param useQrencode
1106
 */
1107
void ConfigDialog::useQrencode(bool useQrencode) {
×
1108
  ui->checkBoxUseQrencode->setChecked(useQrencode);
×
1109
}
×
1110

1111
/**
1112
 * @brief ConfigDialog::on_checkBoxUseGit_clicked enable or disable related
1113
 * checkboxes.
1114
 */
1115
void ConfigDialog::on_checkBoxUseGit_clicked() {
×
1116
  ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
×
1117
  ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
×
1118
  ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
×
1119
}
×
1120

1121
/**
1122
 * @brief ConfigDialog::on_toolButtonPwgen_clicked enable or disable related
1123
 * options in the interface.
1124
 */
1125
void ConfigDialog::on_toolButtonPwgen_clicked() {
×
1126
  QString pwgen = selectExecutable();
×
1127
  if (!pwgen.isEmpty()) {
×
1128
    ui->pwgenPath->setText(pwgen);
×
1129
    ui->checkBoxUsePwgen->setEnabled(true);
×
1130
  } else {
1131
    ui->checkBoxUsePwgen->setEnabled(false);
×
1132
    ui->checkBoxUsePwgen->setChecked(false);
×
1133
  }
1134
}
×
1135

1136
/**
1137
 * @brief ConfigDialog::setPwgenPath set pwgen executable path.
1138
 * Enable or disable related options in the interface.
1139
 * @param pwgen
1140
 */
1141
void ConfigDialog::setPwgenPath(const QString &pwgen) {
×
1142
  ui->pwgenPath->setText(pwgen);
×
1143
  if (pwgen.isEmpty()) {
×
1144
    ui->checkBoxUsePwgen->setChecked(false);
×
1145
    ui->checkBoxUsePwgen->setEnabled(false);
×
1146
  }
1147
  on_checkBoxUsePwgen_clicked();
×
1148
}
×
1149

1150
/**
1151
 * @brief ConfigDialog::on_checkBoxUsePwgen_clicked enable or disable related
1152
 * options in the interface.
1153
 */
1154
void ConfigDialog::on_checkBoxUsePwgen_clicked() {
×
1155
  if (ui->radioButtonPass->isChecked())
×
1156
    return;
1157
  bool usePwgen = ui->checkBoxUsePwgen->isChecked();
×
1158
  ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
×
1159
  ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
×
1160
  ui->checkBoxLessRandom->setEnabled(usePwgen);
×
1161
  ui->checkBoxUseSymbols->setEnabled(usePwgen);
×
1162
  ui->lineEditPasswordChars->setEnabled(!usePwgen);
×
1163
  ui->labelPasswordChars->setEnabled(!usePwgen);
×
1164
  ui->passwordCharTemplateSelector->setEnabled(!usePwgen);
×
1165
}
1166

1167
/**
1168
 * @brief ConfigDialog::usePwgen set preference for using pwgen (can be
1169
 * overruled by empty pwgenPath).
1170
 * enable or disable related options in the interface via
1171
 * ConfigDialog::on_checkBoxUsePwgen_clicked
1172
 * @param usePwgen
1173
 */
1174
void ConfigDialog::usePwgen(bool usePwgen) {
×
1175
  if (ui->pwgenPath->text().isEmpty()) {
×
1176
    usePwgen = false;
1177
  }
1178
  ui->checkBoxUsePwgen->setChecked(usePwgen);
×
1179
  on_checkBoxUsePwgen_clicked();
×
1180
}
×
1181

1182
void ConfigDialog::setPasswordConfiguration(
×
1183
    const PasswordConfiguration &config) {
1184
  ui->spinBoxPasswordLength->setValue(config.length);
×
1185
  ui->passwordCharTemplateSelector->setCurrentIndex(config.selected);
×
1186
  if (config.selected != PasswordConfiguration::CUSTOM) {
×
1187
    ui->lineEditPasswordChars->setEnabled(false);
×
1188
  }
1189
  ui->lineEditPasswordChars->setText(config.Characters[config.selected]);
×
1190
}
×
1191

1192
auto ConfigDialog::getPasswordConfiguration() -> PasswordConfiguration {
×
1193
  PasswordConfiguration config;
×
1194
  config.length = ui->spinBoxPasswordLength->value();
×
1195
  config.selected = static_cast<PasswordConfiguration::characterSet>(
×
1196
      ui->passwordCharTemplateSelector->currentIndex());
×
1197
  config.Characters[PasswordConfiguration::CUSTOM] =
1198
      ui->lineEditPasswordChars->text();
×
1199
  return config;
×
1200
}
×
1201

1202
/**
1203
 * @brief ConfigDialog::on_passwordCharTemplateSelector_activated sets the
1204
 * passwordChar Template
1205
 * combo box to the desired entry
1206
 * @param entry of
1207
 */
1208
void ConfigDialog::on_passwordCharTemplateSelector_activated(int index) {
×
1209
  ui->lineEditPasswordChars->setText(
×
1210
      QtPassSettings::getPasswordConfiguration().Characters[index]);
×
1211
  if (index == PasswordConfiguration::CUSTOM) {
×
1212
    ui->lineEditPasswordChars->setEnabled(true);
×
1213
  } else {
1214
    ui->lineEditPasswordChars->setEnabled(false);
×
1215
  }
1216
}
×
1217

1218
/**
1219
 * @brief ConfigDialog::on_checkBoxUseTemplate_clicked enable or disable the
1220
 * template field and options.
1221
 */
1222
void ConfigDialog::on_checkBoxUseTemplate_clicked() {
×
1223
  ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
×
1224
  ui->checkBoxTemplateAllFields->setEnabled(
×
1225
      ui->checkBoxUseTemplate->isChecked());
×
1226
}
×
1227

1228
void ConfigDialog::onProfileTableItemChanged(QTableWidgetItem *item) {
×
1229
  validate(item);
×
1230
  updateProfileStatus(item ? item->row() : -1);
×
1231
}
×
1232

1233
void ConfigDialog::onProfileTableSelectionChanged() {
×
1234
  QList<QTableWidgetItem *> selected = ui->profileTable->selectedItems();
×
1235
  if (selected.isEmpty()) {
×
1236
    return;
1237
  }
1238
  QTableWidgetItem *nameItem =
1239
      ui->profileTable->item(selected.first()->row(), 0);
×
1240
  if (nameItem == nullptr) {
×
1241
    return;
1242
  }
1243
  QString profileName = nameItem->text();
×
1244
  loadGitSettingsForProfile(profileName, m_profiles);
×
1245
}
1246

1247
/**
1248
 * @brief Update status bar with profile preview for given row.
1249
 * @param row The row index to preview, or -1 to clear.
1250
 */
1251
void ConfigDialog::updateProfileStatus(int row) {
×
1252
  if (row < 0 || row >= ui->profileTable->rowCount()) {
×
1253
    ui->statusLabel->setText(QString());
×
1254
    return;
×
1255
  }
1256

1257
  QTableWidgetItem *nameItem = ui->profileTable->item(row, 0);
×
1258
  QTableWidgetItem *pathItem = ui->profileTable->item(row, 1);
×
1259

1260
  QString statusMessage;
×
1261
  if (nameItem && !nameItem->text().isEmpty() && pathItem &&
×
1262
      !pathItem->text().isEmpty()) {
×
1263
    QDir dir(QDir::cleanPath(pathItem->text()));
×
1264
    if (!dir.exists()) {
×
1265
      statusMessage = tr("New profile: %1 at %2")
×
1266
                          .arg(nameItem->text())
×
1267
                          .arg(QDir::cleanPath(pathItem->text()));
×
1268
    } else {
1269
      statusMessage = tr("Profile: %1 at %2")
×
1270
                          .arg(nameItem->text())
×
1271
                          .arg(QDir::cleanPath(pathItem->text()));
×
1272
    }
1273
  } else {
×
1274
    statusMessage = tr("Fill in all required fields");
×
1275
  }
1276

1277
  ui->statusLabel->setText(statusMessage);
×
1278
}
1279

1280
/**
1281
 * @brief ConfigDialog::useTemplate set preference for using templates.
1282
 * @param useTemplate
1283
 */
1284
void ConfigDialog::useTemplate(bool useTemplate) {
×
1285
  ui->checkBoxUseTemplate->setChecked(useTemplate);
×
1286
  on_checkBoxUseTemplate_clicked();
×
1287
}
×
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