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

IJHack / QtPass / 24845934157

23 Apr 2026 04:12PM UTC coverage: 27.39% (+0.3%) from 27.079%
24845934157

Pull #1140

github

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

44 of 99 new or added lines in 2 files covered. (44.44%)

18 existing lines in 2 files now uncovered.

1636 of 5973 relevant lines covered (27.39%)

29.68 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
  usePass(QtPassSettings::isUsePass());
×
102
  useAutoclear(QtPassSettings::isUseAutoclear());
×
103
  useAutoclearPanel(QtPassSettings::isUseAutoclearPanel());
×
104
  useTrayIcon(QtPassSettings::isUseTrayIcon());
×
105

NEW
106
  setProfiles(QtPassSettings::getProfiles(), QtPassSettings::getProfile());
×
107

UNCOV
108
  useGit(QtPassSettings::isUseGit());
×
109

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

292
  QtPassSettings::setVersion(VERSION);
×
293

294
  // Initialize new profiles that need pass/git initialization
295
  initializeNewProfiles(existingProfiles);
×
296
}
×
297

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

330
/**
331
 * @brief ConfigDialog::on_radioButtonNative_clicked wrapper for
332
 * ConfigDialog::setGroupBoxState()
333
 */
334
void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
×
335

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

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

350
  if (keys.empty()) {
×
351
    return names;
352
  }
353

354
  foreach (const UserInfo &sec, keys)
×
355
    names << sec.name;
×
356

357
  return names;
×
358
}
359

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

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

398
  return {};
399
}
×
400

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

414
  return {};
415
}
×
416

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

430
  ui->checkBoxUseGit->setEnabled(state);
×
431
}
×
432

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

692
  // Collect keys and sort for deterministic iteration
693
  QStringList keys = newProfiles.keys();
×
694
  keys.sort();
695

696
  for (const QString &name : keys) {
×
697
    const QString &path = newProfiles.value(name).value("path");
×
698

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

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

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

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

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

742
    // Use per-profile useGit setting, falling back to global if not set
NEW
743
    QString useGitStr = newProfiles.value(name).value("useGit");
×
744
    bool useGit =
NEW
745
        useGitStr.isEmpty() ? QtPassSettings::isUseGit() : useGitStr == "true";
×
746

NEW
747
    if (result == QDialog::Accepted && useGit) {
×
UNCOV
748
      QtPassSettings::getPass()->GitInit();
×
749
    }
750

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

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

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

769
  ui->profileTable->setSortingEnabled(sortingEnabled);
×
770

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

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

778
  validate();
×
779
  updateProfileStatus(currentRow);
×
780
}
×
781

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

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

819
  validate();
×
820
  updateProfileStatus(-1);
×
821
}
822

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

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

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

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

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

886
  ui->checkBoxHidePassword->setCheckState(Qt::Checked);
×
887
}
888

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

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

944
#ifdef QT_DEBUG
945
  dbg() << names;
946
#endif
947

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1249
  QTableWidgetItem *nameItem = ui->profileTable->item(row, 0);
×
1250
  QTableWidgetItem *pathItem = ui->profileTable->item(row, 1);
×
1251

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

1269
  ui->statusLabel->setText(statusMessage);
×
1270
}
1271

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