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

IJHack / QtPass / 24836479615

23 Apr 2026 12:56PM UTC coverage: 27.381% (+0.3%) from 27.079%
24836479615

Pull #1140

github

web-flow
Merge 7bdaef2b5 into 6fc8c668f
Pull Request #1140: feat: Store git options per profile (#112)

44 of 93 new or added lines in 2 files covered. (47.31%)

21 existing lines in 2 files now uncovered.

1636 of 5975 relevant lines covered (27.38%)

29.67 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());
×
52

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

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

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

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

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

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

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

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

111
  useOtp(QtPassSettings::isUseOtp());
×
112
  useGrepSearch(QtPassSettings::isUseGrepSearch());
×
113
  useQrencode(QtPassSettings::isUseQrencode());
×
114

115
  usePwgen(QtPassSettings::isUsePwgen());
×
116
  useTemplate(QtPassSettings::isUseTemplate());
×
117

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

295
  QtPassSettings::setVersion(VERSION);
×
296

297
  // Initialize new profiles that need pass/git initialization
298
  initializeNewProfiles(existingProfiles);
×
299
}
×
300

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

333
/**
334
 * @brief ConfigDialog::on_radioButtonNative_clicked wrapper for
335
 * ConfigDialog::setGroupBoxState()
336
 */
337
void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
×
338

339
/**
340
 * @brief ConfigDialog::on_radioButtonPass_clicked wrapper for
341
 * ConfigDialog::setGroupBoxState()
342
 */
343
void ConfigDialog::on_radioButtonPass_clicked() { setGroupBoxState(); }
×
344

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

353
  if (keys.empty()) {
×
354
    return names;
355
  }
356

357
  foreach (const UserInfo &sec, keys)
×
358
    names << sec.name;
×
359

360
  return names;
×
361
}
362

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

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

401
  return {};
402
}
×
403

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

417
  return {};
418
}
×
419

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

433
  ui->checkBoxUseGit->setEnabled(state);
×
434
}
×
435

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

625
/**
626
 * @brief ConfigDialog::getProfiles return profile list.
627
 * @return
628
 */
629
auto ConfigDialog::getProfiles() -> QHash<QString, QHash<QString, QString>> {
×
630
  // Get currently selected profile name
NEW
631
  QList<QTableWidgetItem *> selected = ui->profileTable->selectedItems();
×
NEW
632
  QString selectedProfile;
×
NEW
633
  if (!selected.isEmpty()) {
×
634
    selectedProfile =
NEW
635
        ui->profileTable->item(selected.first()->row(), 0)->text();
×
636
  }
637

638
  // Fetch existing profiles to preserve git settings for non-selected profiles
639
  QHash<QString, QHash<QString, QString>> existingProfiles =
NEW
640
      QtPassSettings::getProfiles();
×
641

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

658
      // Only update git settings for the currently selected profile
659
      // Preserve existing git settings for other profiles
NEW
660
      if (item->text() == selectedProfile) {
×
NEW
661
        profile["useGit"] = ui->checkBoxUseGit->isChecked() ? "true" : "false";
×
NEW
662
        profile["autoPush"] =
×
NEW
663
            ui->checkBoxAutoPush->isChecked() ? "true" : "false";
×
NEW
664
        profile["autoPull"] =
×
NEW
665
            ui->checkBoxAutoPull->isChecked() ? "true" : "false";
×
NEW
666
      } else if (existingProfiles.contains(item->text())) {
×
667
        // Preserve existing git settings for non-selected profiles
668
        const QHash<QString, QString> &existing =
NEW
669
            existingProfiles.value(item->text());
×
NEW
670
        if (existing.contains("useGit")) {
×
NEW
671
          profile["useGit"] = existing.value("useGit");
×
672
        }
NEW
673
        if (existing.contains("autoPush")) {
×
NEW
674
          profile["autoPush"] = existing.value("autoPush");
×
675
        }
NEW
676
        if (existing.contains("autoPull")) {
×
NEW
677
          profile["autoPull"] = existing.value("autoPull");
×
678
        }
NEW
679
      }
×
UNCOV
680
      profiles.insert(item->text(), profile);
×
681
    }
682
  }
×
683
  return profiles;
×
684
}
×
685

686
/**
687
 * @brief Initialize new profiles that need pass/git initialization.
688
 * @param existingProfiles The profiles that existed before the dialog was
689
 * opened.
690
 */
691
void ConfigDialog::initializeNewProfiles(
×
692
    const QHash<QString, QHash<QString, QString>> &existingProfiles) {
693
  QHash<QString, QHash<QString, QString>> newProfiles = getProfiles();
×
694

695
  // Collect keys and sort for deterministic iteration
696
  QStringList keys = newProfiles.keys();
×
697
  keys.sort();
698

699
  for (const QString &name : keys) {
×
700
    const QString &path = newProfiles.value(name).value("path");
×
701

702
    // Skip if already existed before (check by name and path)
703
    if (existingProfiles.contains(name) &&
×
704
        existingProfiles.value(name).value("path") == path) {
×
705
      continue;
×
706
    }
707

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

729
    // Now check if initialization is needed (directory exists with no .gpg-id)
730
    if (!ProfileInit::needsInit(cleanPath)) {
×
731
      continue;
×
732
    }
733

734
    // Temporarily switch the active store so pass/git init operate on
735
    // the new profile's directory rather than the currently-saved one.
736
    const QString prevStore = QtPassSettings::getPassStore();
×
737
    QtPassSettings::setPassStore(cleanPath);
×
738

739
    // Show user selection dialog for GPG recipients
740
    // UsersDialog will run pass init when accepted
741
    UsersDialog usersDialog(cleanPath, this);
×
742
    usersDialog.setWindowTitle(tr("Select recipients for %1").arg(name));
×
743
    const int result = usersDialog.exec();
×
744

745
    if (result == QDialog::Accepted && ui->checkBoxUseGit->isChecked()) {
×
746
      QtPassSettings::getPass()->GitInit();
×
747
    }
748

749
    // Restore previous store setting
750
    QtPassSettings::setPassStore(prevStore);
×
751
  }
×
752
}
×
753

754
/**
755
 * @brief ConfigDialog::on_addButton_clicked add a profile row.
756
 */
757
void ConfigDialog::on_addButton_clicked() {
×
758
  bool sortingEnabled = ui->profileTable->isSortingEnabled();
×
759
  ui->profileTable->setSortingEnabled(false);
×
760

761
  int n = ui->profileTable->rowCount();
×
762
  ui->profileTable->insertRow(n);
×
763
  ui->profileTable->setItem(n, 0, new QTableWidgetItem(tr("New Profile")));
×
764
  ui->profileTable->setItem(n, 1, new QTableWidgetItem(ui->storePath->text()));
×
765
  ui->profileTable->setItem(n, 2, new QTableWidgetItem());
×
766

767
  ui->profileTable->setSortingEnabled(sortingEnabled);
×
768

769
  int currentRow = ui->profileTable->row(ui->profileTable->item(n, 0));
×
770
  ui->profileTable->selectRow(currentRow);
×
771
  ui->deleteButton->setEnabled(true);
×
772

773
  ui->profileTable->editItem(ui->profileTable->item(currentRow, 0));
×
774
  ui->profileTable->item(currentRow, 0)->setSelected(true);
×
775

776
  validate();
×
777
  updateProfileStatus(currentRow);
×
778
}
×
779

780
/**
781
 * @brief ConfigDialog::on_profileTable_cellDoubleClicked open folder browser
782
 * for path column (column 1).
783
 */
784
void ConfigDialog::on_profileTable_cellDoubleClicked(int row, int column) {
×
785
  if (column == 1) {
×
786
    QString dir = selectFolder();
×
787
    if (!dir.isEmpty()) {
×
788
      ui->profileTable->item(row, 1)->setText(dir);
×
789
    }
790
  }
791
}
×
792

793
/**
794
 * @brief ConfigDialog::on_deleteButton_clicked remove a profile row.
795
 */
796
void ConfigDialog::on_deleteButton_clicked() {
×
797
  QSet<int> selectedRows; //  we use a set to prevent doubles
798
  QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems();
×
799
  if (itemList.count() == 0) {
×
800
    QMessageBox::warning(this, tr("No profile selected"),
×
801
                         tr("No profile selected to delete"));
×
802
    return;
803
  }
804
  QTableWidgetItem *item;
805
  foreach (item, itemList)
×
806
    selectedRows.insert(item->row());
×
807
  // get a list, and sort it big to small
808
  QList<int> rows = selectedRows.values();
×
809
  std::sort(rows.begin(), rows.end());
×
810
  // now actually do the removing:
811
  foreach (int row, rows)
×
812
    ui->profileTable->removeRow(row);
×
813
  if (ui->profileTable->rowCount() < 1) {
×
814
    ui->deleteButton->setEnabled(false);
×
815
  }
816

817
  validate();
×
818
  updateProfileStatus(-1);
×
819
}
820

821
/**
822
 * @brief ConfigDialog::criticalMessage wrapper for showing critical messages
823
 * in a popup.
824
 * @param title
825
 * @param text
826
 */
827
void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
×
828
  QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
×
829
}
×
830

831
/**
832
 * @brief Checks whether the qrencode executable is available on the system.
833
 * @example
834
 * bool result = ConfigDialog::isQrencodeAvailable();
835
 * std::cout << result << std::endl; // Expected output: true if qrencode is
836
 * found, otherwise false
837
 *
838
 * @return bool - True if qrencode is available; otherwise false. On Windows,
839
 * always returns false.
840
 */
841
auto ConfigDialog::isQrencodeAvailable() -> bool {
×
842
#ifdef Q_OS_WIN
843
  return false;
844
#else
845
  QProcess which;
×
846
  which.start("which", QStringList() << "qrencode");
×
847
  which.waitForFinished();
×
848
  QtPassSettings::setQrencodeExecutable(
×
849
      which.readAllStandardOutput().trimmed());
×
850
  return which.exitCode() == 0;
×
851
#endif
852
}
×
853

854
auto ConfigDialog::isPassOtpAvailable() -> bool {
×
855
#ifdef Q_OS_WIN
856
  return false;
857
#else
858
  QProcess pass;
×
859
  pass.start(QtPassSettings::getPassExecutable(), QStringList() << "otp"
×
860
                                                                << "--help");
×
861
  pass.waitForFinished(2000);
×
862
  return pass.exitCode() == 0;
×
863
#endif
864
}
×
865

866
/**
867
 * @brief ConfigDialog::wizard first-time use wizard.
868
 */
869
void ConfigDialog::wizard() {
×
870
  (void)Util::configIsValid();
×
871
  on_autodetectButton_clicked();
×
872

873
  if (!checkGpgExistence()) {
×
874
    return;
875
  }
876
  if (!checkSecretKeys()) {
×
877
    return;
878
  }
879
  if (!checkPasswordStore()) {
×
880
    return;
881
  }
882
  handleGpgIdFile();
×
883

884
  ui->checkBoxHidePassword->setCheckState(Qt::Checked);
×
885
}
886

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

927
/**
928
 * @brief Checks whether secret keys are available and, if needed, prompts the
929
 * user to generate them.
930
 * @example
931
 * bool result = ConfigDialog.checkSecretKeys();
932
 * std::cout << result << std::endl; // Expected output: true if keys are
933
 * present or key generation dialog is accepted, false otherwise
934
 *
935
 * @return bool - Returns true when secret keys are already available or the key
936
 * generation dialog is accepted; false if the dialog is rejected.
937
 */
938
auto ConfigDialog::checkSecretKeys() -> bool {
×
939
  QString gpg = ui->gpgPath->text();
×
940
  QStringList names = getSecretKeys();
×
941

942
#ifdef QT_DEBUG
943
  dbg() << names;
944
#endif
945

946
  if ((gpg.startsWith("wsl ") || QFile(gpg).exists()) && names.empty()) {
×
947
    KeygenDialog d(this);
×
948
    return d.exec();
×
949
  }
×
950
  return true;
951
}
952

953
/**
954
 * @brief Checks whether the password-store path exists and prompts the user to
955
 * create it if it does not.
956
 * @example
957
 * bool result = ConfigDialog::checkPasswordStore();
958
 * std::cout << std::boolalpha << result << std::endl; // Expected output: true
959
 * if the store exists or is created successfully, false if creation fails
960
 *
961
 * @return bool - True if the password-store exists or is successfully created,
962
 * false if creation fails.
963
 */
964
auto ConfigDialog::checkPasswordStore() -> bool {
×
965
  QString passStore = ui->storePath->text();
×
966

967
  if (!QFile(passStore).exists()) {
×
968
    if (QMessageBox::question(
×
969
            this, tr("Create password-store?"),
×
970
            tr("Would you like to create a password-store at %1?")
×
971
                .arg(passStore),
×
972
            QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
973
      if (!QDir().mkdir(passStore)) {
×
974
        QMessageBox::warning(
×
975
            this, tr("Error"),
×
976
            tr("Failed to create password-store at: %1").arg(passStore));
×
977
        return false;
×
978
      }
979
#ifdef Q_OS_WIN
980
      SetFileAttributes(passStore.toStdWString().c_str(),
981
                        FILE_ATTRIBUTE_HIDDEN);
982
#endif
983
      if (ui->checkBoxUseGit->isChecked()) {
×
984
        emit mainWindow->passGitInitNeeded();
×
985
      }
986
      mainWindow->userDialog(passStore);
×
987
    }
988
  }
989
  return true;
990
}
991

992
/**
993
 * @brief Handles selection and validation of the password store's .gpg-id file.
994
 * @example
995
 * ConfigDialog dialog;
996
 * dialog.handleGpgIdFile();
997
 *
998
 * @return void - This method does not return a value; it updates the UI flow
999
 * and may prompt the user to choose a valid password store.
1000
 */
1001
void ConfigDialog::handleGpgIdFile() {
×
1002
  QString passStore = ui->storePath->text();
×
1003
  if (!QFile(QDir(passStore).filePath(".gpg-id")).exists()) {
×
1004
#ifdef QT_DEBUG
1005
    dbg() << ".gpg-id file does not exist";
1006
#endif
1007
    criticalMessage(tr("Password store not initialised"),
×
1008
                    tr("The folder %1 doesn't seem to be a password store or "
×
1009
                       "is not yet initialised.")
1010
                        .arg(passStore));
×
1011

1012
    while (!QFile(passStore).exists()) {
×
1013
      on_toolButtonStore_clicked();
×
1014
      if (passStore == ui->storePath->text()) {
×
1015
        return;
1016
      }
1017
      passStore = ui->storePath->text();
×
1018
    }
1019
    if (!QFile(passStore + ".gpg-id").exists()) {
×
1020
#ifdef QT_DEBUG
1021
      dbg() << ".gpg-id file still does not exist :/";
1022
#endif
1023
      mainWindow->userDialog(passStore);
×
1024
    }
1025
  }
1026
}
1027

1028
/**
1029
 * @brief ConfigDialog::useTrayIcon set preference for using trayicon.
1030
 * Enable or disable related checkboxes accordingly.
1031
 * @param useSystray
1032
 */
1033
void ConfigDialog::useTrayIcon(bool useSystray) {
×
1034
  if (QSystemTrayIcon::isSystemTrayAvailable()) {
×
1035
    ui->checkBoxUseTrayIcon->setChecked(useSystray);
×
1036
    ui->checkBoxHideOnClose->setEnabled(useSystray);
×
1037
    ui->checkBoxStartMinimized->setEnabled(useSystray);
×
1038

1039
    if (!useSystray) {
×
1040
      ui->checkBoxHideOnClose->setChecked(false);
×
1041
      ui->checkBoxStartMinimized->setChecked(false);
×
1042
    }
1043
  }
1044
}
×
1045

1046
/**
1047
 * @brief ConfigDialog::on_checkBoxUseTrayIcon_clicked enable and disable
1048
 * related checkboxes.
1049
 */
1050
void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
×
1051
  bool state = ui->checkBoxUseTrayIcon->isChecked();
×
1052
  ui->checkBoxHideOnClose->setEnabled(state);
×
1053
  ui->checkBoxStartMinimized->setEnabled(state);
×
1054
}
×
1055

1056
/**
1057
 * @brief ConfigDialog::closeEvent close this window.
1058
 * @param event
1059
 */
1060
void ConfigDialog::closeEvent(QCloseEvent *event) {
×
1061
  QtPassSettings::setDialogGeometry("configDialog", saveGeometry());
×
1062
  if (!isMaximized()) {
×
1063
    QtPassSettings::setDialogPos("configDialog", pos());
×
1064
    QtPassSettings::setDialogSize("configDialog", size());
×
1065
  }
1066
  QtPassSettings::setDialogMaximized("configDialog", isMaximized());
×
1067
  event->accept();
1068
}
×
1069

1070
/**
1071
 * @brief ConfigDialog::useGit set preference for using git.
1072
 * @param useGit
1073
 */
1074
void ConfigDialog::useGit(bool useGit) {
×
1075
  ui->checkBoxUseGit->setChecked(useGit);
×
1076
  on_checkBoxUseGit_clicked();
×
1077
}
×
1078

1079
/**
1080
 * @brief ConfigDialog::useOtp set preference for using otp plugin.
1081
 * @param useOtp
1082
 */
1083
void ConfigDialog::useOtp(bool useOtp) {
×
1084
  ui->checkBoxUseOtp->setChecked(useOtp);
×
1085
}
×
1086

1087
void ConfigDialog::useGrepSearch(bool useGrepSearch) {
×
1088
  ui->checkBoxUseGrepSearch->setChecked(useGrepSearch);
×
1089
}
×
1090

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

1099
/**
1100
 * @brief ConfigDialog::on_checkBoxUseGit_clicked enable or disable related
1101
 * checkboxes.
1102
 */
1103
void ConfigDialog::on_checkBoxUseGit_clicked() {
×
1104
  ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
×
1105
  ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
×
1106
  ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
×
1107
}
×
1108

1109
/**
1110
 * @brief ConfigDialog::on_toolButtonPwgen_clicked enable or disable related
1111
 * options in the interface.
1112
 */
1113
void ConfigDialog::on_toolButtonPwgen_clicked() {
×
1114
  QString pwgen = selectExecutable();
×
1115
  if (!pwgen.isEmpty()) {
×
1116
    ui->pwgenPath->setText(pwgen);
×
1117
    ui->checkBoxUsePwgen->setEnabled(true);
×
1118
  } else {
1119
    ui->checkBoxUsePwgen->setEnabled(false);
×
1120
    ui->checkBoxUsePwgen->setChecked(false);
×
1121
  }
1122
}
×
1123

1124
/**
1125
 * @brief ConfigDialog::setPwgenPath set pwgen executable path.
1126
 * Enable or disable related options in the interface.
1127
 * @param pwgen
1128
 */
1129
void ConfigDialog::setPwgenPath(const QString &pwgen) {
×
1130
  ui->pwgenPath->setText(pwgen);
×
1131
  if (pwgen.isEmpty()) {
×
1132
    ui->checkBoxUsePwgen->setChecked(false);
×
1133
    ui->checkBoxUsePwgen->setEnabled(false);
×
1134
  }
1135
  on_checkBoxUsePwgen_clicked();
×
1136
}
×
1137

1138
/**
1139
 * @brief ConfigDialog::on_checkBoxUsePwgen_clicked enable or disable related
1140
 * options in the interface.
1141
 */
1142
void ConfigDialog::on_checkBoxUsePwgen_clicked() {
×
1143
  if (ui->radioButtonPass->isChecked())
×
1144
    return;
1145
  bool usePwgen = ui->checkBoxUsePwgen->isChecked();
×
1146
  ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
×
1147
  ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
×
1148
  ui->checkBoxLessRandom->setEnabled(usePwgen);
×
1149
  ui->checkBoxUseSymbols->setEnabled(usePwgen);
×
1150
  ui->lineEditPasswordChars->setEnabled(!usePwgen);
×
1151
  ui->labelPasswordChars->setEnabled(!usePwgen);
×
1152
  ui->passwordCharTemplateSelector->setEnabled(!usePwgen);
×
1153
}
1154

1155
/**
1156
 * @brief ConfigDialog::usePwgen set preference for using pwgen (can be
1157
 * overruled by empty pwgenPath).
1158
 * enable or disable related options in the interface via
1159
 * ConfigDialog::on_checkBoxUsePwgen_clicked
1160
 * @param usePwgen
1161
 */
1162
void ConfigDialog::usePwgen(bool usePwgen) {
×
1163
  if (ui->pwgenPath->text().isEmpty()) {
×
1164
    usePwgen = false;
1165
  }
1166
  ui->checkBoxUsePwgen->setChecked(usePwgen);
×
1167
  on_checkBoxUsePwgen_clicked();
×
1168
}
×
1169

1170
void ConfigDialog::setPasswordConfiguration(
×
1171
    const PasswordConfiguration &config) {
1172
  ui->spinBoxPasswordLength->setValue(config.length);
×
1173
  ui->passwordCharTemplateSelector->setCurrentIndex(config.selected);
×
1174
  if (config.selected != PasswordConfiguration::CUSTOM) {
×
1175
    ui->lineEditPasswordChars->setEnabled(false);
×
1176
  }
1177
  ui->lineEditPasswordChars->setText(config.Characters[config.selected]);
×
1178
}
×
1179

1180
auto ConfigDialog::getPasswordConfiguration() -> PasswordConfiguration {
×
1181
  PasswordConfiguration config;
×
1182
  config.length = ui->spinBoxPasswordLength->value();
×
1183
  config.selected = static_cast<PasswordConfiguration::characterSet>(
×
1184
      ui->passwordCharTemplateSelector->currentIndex());
×
1185
  config.Characters[PasswordConfiguration::CUSTOM] =
1186
      ui->lineEditPasswordChars->text();
×
1187
  return config;
×
1188
}
×
1189

1190
/**
1191
 * @brief ConfigDialog::on_passwordCharTemplateSelector_activated sets the
1192
 * passwordChar Template
1193
 * combo box to the desired entry
1194
 * @param entry of
1195
 */
1196
void ConfigDialog::on_passwordCharTemplateSelector_activated(int index) {
×
1197
  ui->lineEditPasswordChars->setText(
×
1198
      QtPassSettings::getPasswordConfiguration().Characters[index]);
×
1199
  if (index == PasswordConfiguration::CUSTOM) {
×
1200
    ui->lineEditPasswordChars->setEnabled(true);
×
1201
  } else {
NEW
1202
    ui->lineEditPasswordChars->setEnabled(false);
×
1203
  }
NEW
1204
}
×
1205

1206
/**
1207
 * @brief ConfigDialog::on_checkBoxUseTemplate_clicked enable or disable the
1208
 * template field and options.
1209
 */
NEW
1210
void ConfigDialog::on_checkBoxUseTemplate_clicked() {
×
NEW
1211
  ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
×
NEW
1212
  ui->checkBoxTemplateAllFields->setEnabled(
×
NEW
1213
      ui->checkBoxUseTemplate->isChecked());
×
NEW
1214
}
×
1215

1216
void ConfigDialog::onProfileTableItemChanged(QTableWidgetItem *item) {
×
UNCOV
1217
  validate(item);
×
1218
  updateProfileStatus(item ? item->row() : -1);
×
UNCOV
1219
}
×
1220

UNCOV
1221
void ConfigDialog::onProfileTableSelectionChanged() {
×
UNCOV
1222
  QList<QTableWidgetItem *> selected = ui->profileTable->selectedItems();
×
UNCOV
1223
  if (selected.isEmpty()) {
×
1224
    return;
1225
  }
1226
  QTableWidgetItem *nameItem = ui->profileTable->item(selected.first()->row(), 0);
×
1227
  if (nameItem == nullptr) {
×
1228
    return;
1229
  }
1230
  QString profileName = nameItem->text();
×
1231
  QHash<QString, QHash<QString, QString>> profiles = QtPassSettings::getProfiles();
×
1232
  loadGitSettingsForProfile(profileName, profiles);
×
1233
}
×
1234

1235
/**
1236
 * @brief Update status bar with profile preview for given row.
1237
 * @param row The row index to preview, or -1 to clear.
1238
 */
1239
void ConfigDialog::updateProfileStatus(int row) {
×
1240
  if (row < 0 || row >= ui->profileTable->rowCount()) {
×
1241
    ui->statusLabel->setText(QString());
×
1242
    return;
×
1243
  }
1244

1245
  QTableWidgetItem *nameItem = ui->profileTable->item(row, 0);
×
1246
  QTableWidgetItem *pathItem = ui->profileTable->item(row, 1);
×
1247

1248
  QString statusMessage;
×
1249
  if (nameItem && !nameItem->text().isEmpty() && pathItem &&
×
1250
      !pathItem->text().isEmpty()) {
×
1251
    QDir dir(QDir::cleanPath(pathItem->text()));
×
1252
    if (!dir.exists()) {
×
1253
      statusMessage = tr("New profile: %1 at %2")
×
1254
                          .arg(nameItem->text())
×
1255
                          .arg(QDir::cleanPath(pathItem->text()));
×
1256
    } else {
1257
      statusMessage = tr("Profile: %1 at %2")
×
1258
                          .arg(nameItem->text())
×
1259
                          .arg(QDir::cleanPath(pathItem->text()));
×
1260
    }
1261
  } else {
×
1262
    statusMessage = tr("Fill in all required fields");
×
1263
  }
1264

1265
  ui->statusLabel->setText(statusMessage);
×
1266
}
1267

1268
/**
1269
 * @brief ConfigDialog::useTemplate set preference for using templates.
1270
 * @param useTemplate
1271
 */
1272
void ConfigDialog::useTemplate(bool useTemplate) {
×
1273
  ui->checkBoxUseTemplate->setChecked(useTemplate);
×
1274
  on_checkBoxUseTemplate_clicked();
×
1275
}
×
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