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

IJHack / QtPass / 24841278407

23 Apr 2026 02:36PM UTC coverage: 27.145% (+0.07%) from 27.079%
24841278407

Pull #1140

github

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

44 of 151 new or added lines in 2 files covered. (29.14%)

38 existing lines in 2 files now uncovered.

1636 of 6027 relevant lines covered (27.14%)

29.44 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
  // Initialize dialogGitSettings from existing profiles
102
  QHash<QString, QHash<QString, QString>> existingProfiles =
NEW
103
      QtPassSettings::getProfiles();
×
NEW
104
  for (auto it = existingProfiles.constBegin(); it != existingProfiles.constEnd();
×
105
       ++it) {
NEW
106
    QHash<QString, QString> gitSettings;
×
NEW
107
    gitSettings["useGit"] = it.value().value("useGit");
×
NEW
108
    gitSettings["autoPush"] = it.value().value("autoPush");
×
NEW
109
    gitSettings["autoPull"] = it.value().value("autoPull");
×
NEW
110
    dialogGitSettings[it.key()] = gitSettings;
×
NEW
111
  }
×
112

NEW
113
  setProfiles(existingProfiles, QtPassSettings::getProfile());
×
114
  setPwgenPath(QtPassSettings::getPwgenExecutable());
×
115
  setPasswordConfiguration(QtPassSettings::getPasswordConfiguration());
×
116

117
  usePass(QtPassSettings::isUsePass());
×
118
  useAutoclear(QtPassSettings::isUseAutoclear());
×
119
  useAutoclearPanel(QtPassSettings::isUseAutoclearPanel());
×
120
  useTrayIcon(QtPassSettings::isUseTrayIcon());
×
121
  useGit(QtPassSettings::isUseGit());
×
122

123
  useOtp(QtPassSettings::isUseOtp());
×
124
  useGrepSearch(QtPassSettings::isUseGrepSearch());
×
125
  useQrencode(QtPassSettings::isUseQrencode());
×
126

127
  usePwgen(QtPassSettings::isUsePwgen());
×
128
  useTemplate(QtPassSettings::isUseTemplate());
×
129

130
  ui->profileTable->verticalHeader()->hide();
×
131
  ui->profileTable->horizontalHeader()->setSectionResizeMode(
×
132
      1, QHeaderView::Stretch);
133
  ui->label->setText(ui->label->text() + VERSION);
×
134
  ui->comboBoxClipboard->clear();
×
135

136
  ui->comboBoxClipboard->addItem(tr("No Clipboard"));
×
137
  ui->comboBoxClipboard->addItem(tr("Always copy to clipboard"));
×
138
  ui->comboBoxClipboard->addItem(tr("On-demand copy to clipboard"));
×
139

140
  int currentIndex = QtPassSettings::getClipBoardTypeRaw();
×
141
  ui->comboBoxClipboard->setCurrentIndex(currentIndex);
×
142
  on_comboBoxClipboard_activated(currentIndex);
×
143

144
  QClipboard *clip = QApplication::clipboard();
×
145
  if (!clip->supportsSelection()) {
×
146
    useSelection(false);
×
147
    ui->checkBoxSelection->setVisible(false);
×
148
  } else {
149
    useSelection(QtPassSettings::isUseSelection());
×
150
  }
151

152
  if (!Util::configIsValid()) {
×
153
    // Show Programs tab, which is likely
154
    // what the user needs to fix now.
155
    ui->tabWidget->setCurrentIndex(1);
×
156
  }
157

158
  connect(ui->profileTable, &QTableWidget::itemChanged, this,
×
159
          &ConfigDialog::onProfileTableItemChanged);
×
NEW
160
  connect(ui->profileTable, &QTableWidget::itemSelectionChanged, this,
×
NEW
161
          &ConfigDialog::onProfileTableSelectionChanged);
×
162
  connect(this, &ConfigDialog::accepted, this, &ConfigDialog::on_accepted);
×
163
}
×
164

165
/**
166
 * @brief ConfigDialog::~ConfigDialog config destructor, makes sure the
167
 * mainWindow knows about git, gpg and pass executables.
168
 */
169
ConfigDialog::~ConfigDialog() {
×
170
  QtPassSettings::setGitExecutable(ui->gitPath->text());
×
171
  QtPassSettings::setGpgExecutable(ui->gpgPath->text());
×
172
  QtPassSettings::setPassExecutable(ui->passPath->text());
×
173
}
×
174

175
/**
176
 * @brief ConfigDialog::setGitPath set the git executable path.
177
 * Make sure the checkBoxUseGit is updated.
178
 * @param path
179
 */
180
void ConfigDialog::setGitPath(const QString &path) {
×
181
  ui->gitPath->setText(path);
×
182
  ui->checkBoxUseGit->setEnabled(!path.isEmpty());
×
183
  if (path.isEmpty()) {
×
184
    useGit(false);
×
185
  }
186
}
×
187

188
/**
189
 * @brief ConfigDialog::usePass set wether or not we want to use pass.
190
 * Update radio buttons accordingly.
191
 * @param usePass
192
 */
193
void ConfigDialog::usePass(bool usePass) {
×
194
  ui->radioButtonNative->setChecked(!usePass);
×
195
  ui->radioButtonPass->setChecked(usePass);
×
196
  setGroupBoxState();
×
197
}
×
198

199
/**
200
 * @brief Validates the configuration table fields and enables or disables the
201
 * OK button accordingly.
202
 * @example
203
 * ConfigDialog dialog;
204
 * QTableWidgetItem *item = dialog.findChild<QTableWidgetItem*>();
205
 * dialog.validate(item);
206
 *
207
 * @param QTableWidgetItem *item - The table item to validate; if null,
208
 * validates all relevant items in the profile table.
209
 * @return void - This function does not return a value.
210
 */
211
void ConfigDialog::validate(QTableWidgetItem *item) {
×
212
  bool status = true;
213

214
  if (item == nullptr) {
×
215
    for (int i = 0; i < ui->profileTable->rowCount(); i++) {
×
216
      for (int j = 0; j < ui->profileTable->columnCount(); j++) {
×
217
        QTableWidgetItem *_item = ui->profileTable->item(i, j);
×
218

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

230
      if (!status) {
231
        break;
232
      }
233
    }
234
  } else {
235
    if (item->text().isEmpty() && item->column() != 2) {
×
236
      item->setBackground(Qt::red);
×
237
      item->setToolTip(tr("This field is required"));
×
238
      status = false;
239
    } else {
240
      item->setBackground(QBrush());
×
241
      item->setToolTip(QString());
×
242
    }
243
  }
244

245
  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
×
246
}
×
247

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

307
  QtPassSettings::setVersion(VERSION);
×
308

309
  // Initialize new profiles that need pass/git initialization
310
  initializeNewProfiles(existingProfiles);
×
311
}
×
312

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

345
/**
346
 * @brief ConfigDialog::on_radioButtonNative_clicked wrapper for
347
 * ConfigDialog::setGroupBoxState()
348
 */
349
void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
×
350

351
/**
352
 * @brief ConfigDialog::on_radioButtonPass_clicked wrapper for
353
 * ConfigDialog::setGroupBoxState()
354
 */
355
void ConfigDialog::on_radioButtonPass_clicked() { setGroupBoxState(); }
×
356

357
/**
358
 * @brief ConfigDialog::getSecretKeys get list of secret/private keys
359
 * @return QStringList keys
360
 */
361
auto ConfigDialog::getSecretKeys() -> QStringList {
×
362
  QList<UserInfo> keys = QtPassSettings::getPass()->listKeys("", true);
×
363
  QStringList names;
×
364

365
  if (keys.empty()) {
×
366
    return names;
367
  }
368

369
  foreach (const UserInfo &sec, keys)
×
370
    names << sec.name;
×
371

372
  return names;
×
373
}
374

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

401
/**
402
 * @brief ConfigDialog::selectExecutable pop-up to choose an executable.
403
 * @return
404
 */
405
auto ConfigDialog::selectExecutable() -> QString {
×
406
  QFileDialog dialog(this);
×
407
  dialog.setFileMode(QFileDialog::ExistingFile);
×
408
  dialog.setOption(QFileDialog::ReadOnly);
×
409
  if (dialog.exec()) {
×
410
    return dialog.selectedFiles().constFirst();
×
411
  }
412

413
  return {};
414
}
×
415

416
/**
417
 * @brief ConfigDialog::selectFolder pop-up to choose a folder.
418
 * @return
419
 */
420
auto ConfigDialog::selectFolder() -> QString {
×
421
  QFileDialog dialog(this);
×
422
  dialog.setFileMode(QFileDialog::Directory);
×
423
  dialog.setFilter(QDir::NoFilter);
×
424
  dialog.setOption(QFileDialog::ShowDirsOnly);
×
425
  if (dialog.exec()) {
×
426
    return dialog.selectedFiles().constFirst();
×
427
  }
428

429
  return {};
430
}
×
431

432
/**
433
 * @brief ConfigDialog::on_toolButtonGit_clicked get git application.
434
 * Enable checkboxes if found.
435
 */
436
void ConfigDialog::on_toolButtonGit_clicked() {
×
437
  QString git = selectExecutable();
×
438
  bool state = !git.isEmpty();
×
439
  if (state) {
×
440
    ui->gitPath->setText(git);
×
441
  } else {
442
    useGit(false);
×
443
  }
444

445
  ui->checkBoxUseGit->setEnabled(state);
×
446
}
×
447

448
/**
449
 * @brief ConfigDialog::on_toolButtonGpg_clicked get gpg application.
450
 */
451
void ConfigDialog::on_toolButtonGpg_clicked() {
×
452
  QString gpg = selectExecutable();
×
453
  if (!gpg.isEmpty()) {
×
454
    ui->gpgPath->setText(gpg);
×
455
  }
456
}
×
457

458
/**
459
 * @brief ConfigDialog::on_pushButtonGenerateKey_clicked open keygen dialog.
460
 */
461
void ConfigDialog::on_pushButtonGenerateKey_clicked() {
×
462
  KeygenDialog d(this);
×
463
  d.exec();
×
464
}
×
465

466
/**
467
 * @brief ConfigDialog::on_toolButtonPass_clicked get pass application.
468
 */
469
void ConfigDialog::on_toolButtonPass_clicked() {
×
470
  QString pass = selectExecutable();
×
471
  if (!pass.isEmpty()) {
×
472
    ui->passPath->setText(pass);
×
473
  }
474
}
×
475

476
/**
477
 * @brief ConfigDialog::on_toolButtonStore_clicked get .password-store
478
 * location.
479
 */
480
void ConfigDialog::on_toolButtonStore_clicked() {
×
481
  QString store = selectFolder();
×
482
  if (!store.isEmpty()) {
×
483
    ui->storePath->setText(store);
×
484
  }
485
}
×
486

487
/**
488
 * @brief ConfigDialog::on_comboBoxClipboard_activated show and hide options.
489
 * @param index of selectbox (0 = no clipboard).
490
 */
491
void ConfigDialog::on_comboBoxClipboard_activated(int index) {
×
492
  bool state = index > 0;
×
493

494
  ui->checkBoxSelection->setEnabled(state);
×
495
  ui->checkBoxAutoclear->setEnabled(state);
×
496
  ui->checkBoxHidePassword->setEnabled(state);
×
497
  ui->checkBoxHideContent->setEnabled(state);
×
498
  if (state) {
×
499
    ui->spinBoxAutoclearSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
×
500
    ui->labelSeconds->setEnabled(ui->checkBoxAutoclear->isChecked());
×
501
  } else {
502
    ui->spinBoxAutoclearSeconds->setEnabled(false);
×
503
    ui->labelSeconds->setEnabled(false);
×
504
  }
505
}
×
506

507
/**
508
 * @brief ConfigDialog::on_checkBoxAutoclearPanel_clicked enable and disable
509
 * options based on autoclear use.
510
 */
511
void ConfigDialog::on_checkBoxAutoclearPanel_clicked() {
×
512
  bool state = ui->checkBoxAutoclearPanel->isChecked();
×
513
  ui->spinBoxAutoclearPanelSeconds->setEnabled(state);
×
514
  ui->labelPanelSeconds->setEnabled(state);
×
515
}
×
516

517
/**
518
 * @brief ConfigDialog::useSelection set the clipboard type use from
519
 * MainWindow.
520
 * @param useSelection
521
 */
522
void ConfigDialog::useSelection(bool useSelection) {
×
523
  ui->checkBoxSelection->setChecked(useSelection);
×
524
  on_checkBoxSelection_clicked();
×
525
}
×
526

527
/**
528
 * @brief ConfigDialog::useAutoclear set the clipboard autoclear use from
529
 * MainWindow.
530
 * @param useAutoclear
531
 */
532
void ConfigDialog::useAutoclear(bool useAutoclear) {
×
533
  ui->checkBoxAutoclear->setChecked(useAutoclear);
×
534
  on_checkBoxAutoclear_clicked();
×
535
}
×
536

537
/**
538
 * @brief ConfigDialog::useAutoclearPanel set the panel autoclear use from
539
 * MainWindow.
540
 * @param useAutoclearPanel
541
 */
542
void ConfigDialog::useAutoclearPanel(bool useAutoclearPanel) {
×
543
  ui->checkBoxAutoclearPanel->setChecked(useAutoclearPanel);
×
544
  on_checkBoxAutoclearPanel_clicked();
×
545
}
×
546

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

555
/**
556
 * @brief ConfigDialog::on_checkBoxAutoclear_clicked checkbox clicked, update
557
 * state via ConfigDialog::on_comboBoxClipboard_activated
558
 */
559
void ConfigDialog::on_checkBoxAutoclear_clicked() {
×
560
  on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
×
561
}
×
562

563
/**
564
 * @brief ConfigDialog::genKey tunnel function to make MainWindow generate a
565
 * gpg key pair.
566
 * @param batch
567
 * @param dialog
568
 */
569
void ConfigDialog::genKey(const QString &batch, QDialog *dialog) {
×
570
  mainWindow->generateKeyPair(batch, dialog);
×
571
}
×
572

573
/**
574
 * @brief ConfigDialog::setProfiles set the profiles and chosen profile from
575
 * MainWindow.
576
 * @param profiles
577
 * @param profile
578
 */
579
void ConfigDialog::setProfiles(QHash<QString, QHash<QString, QString>> profiles,
×
580
                               const QString &currentProfile) {
581
  if (profiles.contains("")) {
×
582
    profiles.remove("");
×
583
    // remove weird "" key value pairs
584
  }
585

586
  ui->profileTable->setRowCount(profiles.count());
×
587
  QHashIterator<QString, QHash<QString, QString>> i(profiles);
×
588
  int n = 0;
589
  while (i.hasNext()) {
×
590
    i.next();
591
    if (!i.value().isEmpty() && !i.key().isEmpty()) {
×
592
      ui->profileTable->setItem(n, 0, new QTableWidgetItem(i.key()));
×
593
      ui->profileTable->setItem(n, 1,
×
594
                                new QTableWidgetItem(i.value().value("path")));
×
595
      ui->profileTable->setItem(
×
596
          n, 2, new QTableWidgetItem(i.value().value("signingKey")));
×
597
      if (i.key() == currentProfile) {
×
598
        ui->profileTable->selectRow(n);
×
599
        // Load git settings for current profile
NEW
600
        currentProfileName = currentProfile;
×
NEW
601
        loadGitSettingsForProfile(currentProfile, profiles);
×
602
      }
603
    }
604
    ++n;
×
605
  }
606
}
×
607

608
/**
609
 * @brief Load git settings for a specific profile.
610
 * @param profileName The profile name.
611
 * @param profiles The profiles hash containing git settings.
612
 */
NEW
613
void ConfigDialog::loadGitSettingsForProfile(
×
614
    const QString &profileName,
615
    const QHash<QString, QHash<QString, QString>> &profiles) {
616
  // Load from dialogGitSettings first, fall back to profiles if not present
NEW
617
  QString useGitStr;
×
NEW
618
  QString autoPushStr;
×
NEW
619
  QString autoPullStr;
×
620

NEW
621
  if (dialogGitSettings.contains(profileName)) {
×
622
    const QHash<QString, QString> &gitSettings =
NEW
623
        dialogGitSettings.value(profileName);
×
NEW
624
    useGitStr = gitSettings.value("useGit");
×
NEW
625
    autoPushStr = gitSettings.value("autoPush");
×
NEW
626
    autoPullStr = gitSettings.value("autoPull");
×
NEW
627
  } else if (profiles.contains(profileName)) {
×
NEW
628
    const QHash<QString, QString> &profile = profiles.value(profileName);
×
NEW
629
    useGitStr = profile.value("useGit");
×
NEW
630
    autoPushStr = profile.value("autoPush");
×
NEW
631
    autoPullStr = profile.value("autoPull");
×
NEW
632
  }
×
633

634
  // Load profile-specific git settings if set, otherwise use global settings
NEW
635
  if (!useGitStr.isEmpty()) {
×
NEW
636
    useGit(useGitStr == "true");
×
NEW
637
    ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
×
NEW
638
    ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
×
NEW
639
    if (autoPushStr == "true" || autoPushStr == "false") {
×
NEW
640
      ui->checkBoxAutoPush->setChecked(autoPushStr == "true");
×
641
    }
NEW
642
    if (autoPullStr == "true" || autoPullStr == "false") {
×
NEW
643
      ui->checkBoxAutoPull->setChecked(autoPullStr == "true");
×
644
    }
645
  }
646
  // If not set (empty), leave global settings as-is for migration
NEW
647
}
×
648

649
/**
650
 * @brief ConfigDialog::getProfiles return profile list.
651
 * @return
652
 */
653
auto ConfigDialog::getProfiles() -> QHash<QString, QHash<QString, QString>> {
×
654
  // Save current profile's Git settings before serializing
NEW
655
  saveCurrentGitSettings();
×
656

657
  // Fetch existing profiles to fall back to if not in dialogGitSettings
658
  QHash<QString, QHash<QString, QString>> existingProfiles =
NEW
659
      QtPassSettings::getProfiles();
×
660

UNCOV
661
  QHash<QString, QHash<QString, QString>> profiles;
×
662
  // Check?
663
  for (int i = 0; i < ui->profileTable->rowCount(); ++i) {
×
664
    QHash<QString, QString> profile;
×
665
    QTableWidgetItem *pathItem = ui->profileTable->item(i, 1);
×
666
    if (nullptr != pathItem) {
×
667
      QTableWidgetItem *item = ui->profileTable->item(i, 0);
×
668
      if (item == nullptr) {
×
UNCOV
669
        continue;
×
670
      }
671
      profile["path"] = pathItem->text();
×
672
      QTableWidgetItem *signingKeyItem = ui->profileTable->item(i, 2);
×
673
      if (nullptr != signingKeyItem) {
×
674
        profile["signingKey"] = signingKeyItem->text();
×
675
      }
676

NEW
677
      QString profileName = item->text();
×
678

679
      // Serialize Git settings from dialogGitSettings for all profiles
NEW
680
      if (dialogGitSettings.contains(profileName)) {
×
681
        const QHash<QString, QString> &gitSettings =
NEW
682
            dialogGitSettings.value(profileName);
×
NEW
683
        if (gitSettings.contains("useGit")) {
×
NEW
684
          profile["useGit"] = gitSettings.value("useGit");
×
685
        }
NEW
686
        if (gitSettings.contains("autoPush")) {
×
NEW
687
          profile["autoPush"] = gitSettings.value("autoPush");
×
688
        }
NEW
689
        if (gitSettings.contains("autoPull")) {
×
NEW
690
          profile["autoPull"] = gitSettings.value("autoPull");
×
691
        }
NEW
692
      } else if (existingProfiles.contains(profileName)) {
×
693
        // Fall back to existing git settings if not in dialogGitSettings
694
        const QHash<QString, QString> &existing =
NEW
695
            existingProfiles.value(profileName);
×
NEW
696
        if (existing.contains("useGit")) {
×
NEW
697
          profile["useGit"] = existing.value("useGit");
×
698
        }
NEW
699
        if (existing.contains("autoPush")) {
×
NEW
700
          profile["autoPush"] = existing.value("autoPush");
×
701
        }
NEW
702
        if (existing.contains("autoPull")) {
×
NEW
703
          profile["autoPull"] = existing.value("autoPull");
×
704
        }
NEW
705
      }
×
706
      profiles.insert(profileName, profile);
707
    }
708
  }
×
709
  return profiles;
×
710
}
×
711

712
/**
713
 * @brief Initialize new profiles that need pass/git initialization.
714
 * @param existingProfiles The profiles that existed before the dialog was
715
 * opened.
716
 */
717
void ConfigDialog::initializeNewProfiles(
×
718
    const QHash<QString, QHash<QString, QString>> &existingProfiles) {
719
  QHash<QString, QHash<QString, QString>> newProfiles = getProfiles();
×
720

721
  // Collect keys and sort for deterministic iteration
722
  QStringList keys = newProfiles.keys();
×
723
  keys.sort();
724

725
  for (const QString &name : keys) {
×
726
    const QString &path = newProfiles.value(name).value("path");
×
727

728
    // Skip if already existed before (check by name and path)
729
    if (existingProfiles.contains(name) &&
×
730
        existingProfiles.value(name).value("path") == path) {
×
731
      continue;
×
732
    }
733

734
    // This is a new profile - create directory if needed and initialize
735
    // Note: needsInit returns false for non-existent directories, so we
736
    // must create the directory first.
737
    QString cleanPath = QDir::cleanPath(path);
×
738
    QDir dir(cleanPath);
×
739
    if (!dir.exists()) {
×
740
      if (QMessageBox::question(
×
741
              this, tr("Create profile directory?"),
×
742
              tr("Would you like to create a password store at %1?")
×
743
                  .arg(cleanPath),
×
744
              QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
745
        continue;
×
746
      }
747
      if (!QDir().mkpath(cleanPath)) {
×
748
        QMessageBox::warning(
×
749
            this, tr("Error"),
×
750
            tr("Could not create profile directory: %1").arg(cleanPath));
×
751
        continue;
×
752
      }
753
    }
754

755
    // Now check if initialization is needed (directory exists with no .gpg-id)
756
    if (!ProfileInit::needsInit(cleanPath)) {
×
757
      continue;
×
758
    }
759

760
    // Temporarily switch the active store so pass/git init operate on
761
    // the new profile's directory rather than the currently-saved one.
762
    const QString prevStore = QtPassSettings::getPassStore();
×
763
    QtPassSettings::setPassStore(cleanPath);
×
764

765
    // Show user selection dialog for GPG recipients
766
    // UsersDialog will run pass init when accepted
UNCOV
767
    UsersDialog usersDialog(cleanPath, this);
×
UNCOV
768
    usersDialog.setWindowTitle(tr("Select recipients for %1").arg(name));
×
UNCOV
769
    const int result = usersDialog.exec();
×
770

771
    if (result == QDialog::Accepted && ui->checkBoxUseGit->isChecked()) {
×
772
      QtPassSettings::getPass()->GitInit();
×
773
    }
774

775
    // Restore previous store setting
UNCOV
776
    QtPassSettings::setPassStore(prevStore);
×
UNCOV
777
  }
×
UNCOV
778
}
×
779

780
/**
781
 * @brief ConfigDialog::on_addButton_clicked add a profile row.
782
 */
NEW
783
void ConfigDialog::on_addButton_clicked() {
×
784
  // Save current profile's Git settings before switching
NEW
785
  saveCurrentGitSettings();
×
786

NEW
787
  bool sortingEnabled = ui->profileTable->isSortingEnabled();
×
NEW
788
  ui->profileTable->setSortingEnabled(false);
×
789

NEW
790
  int n = ui->profileTable->rowCount();
×
NEW
791
  ui->profileTable->insertRow(n);
×
NEW
792
  ui->profileTable->setItem(n, 0, new QTableWidgetItem(tr("New Profile")));
×
UNCOV
793
  ui->profileTable->setItem(n, 1, new QTableWidgetItem(ui->storePath->text()));
×
UNCOV
794
  ui->profileTable->setItem(n, 2, new QTableWidgetItem());
×
795

UNCOV
796
  ui->profileTable->setSortingEnabled(sortingEnabled);
×
797

798
  int currentRow = ui->profileTable->row(ui->profileTable->item(n, 0));
×
799
  ui->profileTable->selectRow(currentRow);
×
UNCOV
800
  ui->deleteButton->setEnabled(true);
×
801

802
  // Initialize git settings for the new profile with current UI state
803
  QString newProfileName = tr("New Profile");
804
  QHash<QString, QString> gitSettings;
×
805
  gitSettings["useGit"] = ui->checkBoxUseGit->isChecked() ? "true" : "false";
×
UNCOV
806
  gitSettings["autoPush"] =
×
807
      ui->checkBoxAutoPush->isChecked() ? "true" : "false";
×
UNCOV
808
  gitSettings["autoPull"] =
×
809
      ui->checkBoxAutoPull->isChecked() ? "true" : "false";
×
810
  dialogGitSettings[newProfileName] = gitSettings;
×
811
  currentProfileName = newProfileName;
×
812

813
  ui->profileTable->editItem(ui->profileTable->item(currentRow, 0));
×
814
  ui->profileTable->item(currentRow, 0)->setSelected(true);
×
815

816
  validate();
×
817
  updateProfileStatus(currentRow);
×
818
}
×
819

820
/**
821
 * @brief ConfigDialog::on_profileTable_cellDoubleClicked open folder browser
822
 * for path column (column 1).
823
 */
NEW
824
void ConfigDialog::on_profileTable_cellDoubleClicked(int row, int column) {
×
NEW
825
  if (column == 1) {
×
NEW
826
    QString dir = selectFolder();
×
827
    if (!dir.isEmpty()) {
×
NEW
828
      ui->profileTable->item(row, 1)->setText(dir);
×
829
    }
830
  }
NEW
831
}
×
832

833
/**
834
 * @brief ConfigDialog::on_deleteButton_clicked remove a profile row.
835
 */
836
void ConfigDialog::on_deleteButton_clicked() {
×
837
  QSet<int> selectedRows; //  we use a set to prevent doubles
UNCOV
838
  QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems();
×
UNCOV
839
  if (itemList.count() == 0) {
×
840
    QMessageBox::warning(this, tr("No profile selected"),
×
UNCOV
841
                         tr("No profile selected to delete"));
×
842
    return;
843
  }
844

845
  // Collect profile names to delete from dialogGitSettings
NEW
846
  QStringList profilesToDelete;
×
847
  QTableWidgetItem *item;
NEW
848
  foreach (item, itemList) {
×
NEW
849
    selectedRows.insert(item->row());
×
NEW
850
    QTableWidgetItem *nameItem = ui->profileTable->item(item->row(), 0);
×
NEW
851
    if (nameItem != nullptr) {
×
NEW
852
      profilesToDelete.append(nameItem->text());
×
853
    }
854
  }
855

856
  // get a list, and sort it big to small
UNCOV
857
  QList<int> rows = selectedRows.values();
×
858
  std::sort(rows.begin(), rows.end());
×
859
  // now actually do the removing:
860
  foreach (int row, rows)
×
861
    ui->profileTable->removeRow(row);
×
862

863
  // Remove deleted profiles from dialogGitSettings
UNCOV
864
  foreach (const QString &profileName, profilesToDelete) {
×
865
    dialogGitSettings.remove(profileName);
×
866
  }
867

868
  // Clear currentProfileName if it was deleted
869
  if (profilesToDelete.contains(currentProfileName)) {
×
UNCOV
870
    currentProfileName.clear();
×
871
  }
872

873
  if (ui->profileTable->rowCount() < 1) {
×
874
    ui->deleteButton->setEnabled(false);
×
875
  }
876

877
  validate();
×
878
  updateProfileStatus(-1);
×
879
}
880

881
/**
882
 * @brief ConfigDialog::criticalMessage wrapper for showing critical messages
883
 * in a popup.
884
 * @param title
885
 * @param text
886
 */
887
void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
×
888
  QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
×
889
}
×
890

891
/**
892
 * @brief Checks whether the qrencode executable is available on the system.
893
 * @example
894
 * bool result = ConfigDialog::isQrencodeAvailable();
895
 * std::cout << result << std::endl; // Expected output: true if qrencode is
896
 * found, otherwise false
897
 *
898
 * @return bool - True if qrencode is available; otherwise false. On Windows,
899
 * always returns false.
900
 */
901
auto ConfigDialog::isQrencodeAvailable() -> bool {
×
902
#ifdef Q_OS_WIN
903
  return false;
904
#else
905
  QProcess which;
×
906
  which.start("which", QStringList() << "qrencode");
×
907
  which.waitForFinished();
×
908
  QtPassSettings::setQrencodeExecutable(
×
909
      which.readAllStandardOutput().trimmed());
×
910
  return which.exitCode() == 0;
×
911
#endif
912
}
×
913

914
auto ConfigDialog::isPassOtpAvailable() -> bool {
×
915
#ifdef Q_OS_WIN
916
  return false;
917
#else
918
  QProcess pass;
×
919
  pass.start(QtPassSettings::getPassExecutable(), QStringList() << "otp"
×
920
                                                                << "--help");
×
921
  pass.waitForFinished(2000);
×
922
  return pass.exitCode() == 0;
×
923
#endif
924
}
×
925

926
/**
927
 * @brief ConfigDialog::wizard first-time use wizard.
928
 */
929
void ConfigDialog::wizard() {
×
930
  (void)Util::configIsValid();
×
931
  on_autodetectButton_clicked();
×
932

933
  if (!checkGpgExistence()) {
×
934
    return;
935
  }
936
  if (!checkSecretKeys()) {
×
937
    return;
938
  }
939
  if (!checkPasswordStore()) {
×
940
    return;
941
  }
942
  handleGpgIdFile();
×
943

944
  ui->checkBoxHidePassword->setCheckState(Qt::Checked);
×
945
}
946

947
/**
948
 * @brief Checks whether the configured GnuPG executable exists.
949
 * @example
950
 * bool result = ConfigDialog::checkGpgExistence();
951
 * std::cout << result << std::endl; // Expected output: true if GnuPG is found,
952
 * false otherwise
953
 *
954
 * @return bool - True if the GnuPG path is valid or uses a WSL command prefix;
955
 * false if the executable cannot be found and an error message is shown.
956
 */
957
auto ConfigDialog::checkGpgExistence() -> bool {
×
958
  QString gpg = ui->gpgPath->text();
×
959
  if (!gpg.startsWith("wsl ") && !QFile(gpg).exists()) {
×
960
    criticalMessage(
×
961
        tr("GnuPG not found"),
×
962
#ifdef Q_OS_WIN
963
#ifdef WINSTORE
964
        tr("Please install GnuPG on your system.<br>Install "
965
           "<strong>Ubuntu</strong> from the Microsoft Store to get it.<br>"
966
           "If you already did so, make sure you started it once and<br>"
967
           "click \"Autodetect\" in the next dialog.")
968
#else
969
        tr("Please install GnuPG on your system.<br>Install "
970
           "<strong>Ubuntu</strong> from the Microsoft Store<br>or <a "
971
           "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
972
           "from GnuPG.org")
973
#endif
974
#else
975
        tr("Please install GnuPG on your system.<br>Install "
×
976
           "<strong>gpg</strong> using your favorite package manager<br>or "
977
           "<a "
978
           "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
979
           "from GnuPG.org")
980
#endif
981
    );
982
    return false;
×
983
  }
984
  return true;
985
}
986

987
/**
988
 * @brief Checks whether secret keys are available and, if needed, prompts the
989
 * user to generate them.
990
 * @example
991
 * bool result = ConfigDialog.checkSecretKeys();
992
 * std::cout << result << std::endl; // Expected output: true if keys are
993
 * present or key generation dialog is accepted, false otherwise
994
 *
995
 * @return bool - Returns true when secret keys are already available or the key
996
 * generation dialog is accepted; false if the dialog is rejected.
997
 */
998
auto ConfigDialog::checkSecretKeys() -> bool {
×
999
  QString gpg = ui->gpgPath->text();
×
1000
  QStringList names = getSecretKeys();
×
1001

1002
#ifdef QT_DEBUG
1003
  dbg() << names;
1004
#endif
1005

1006
  if ((gpg.startsWith("wsl ") || QFile(gpg).exists()) && names.empty()) {
×
1007
    KeygenDialog d(this);
×
1008
    return d.exec();
×
1009
  }
×
1010
  return true;
1011
}
1012

1013
/**
1014
 * @brief Checks whether the password-store path exists and prompts the user to
1015
 * create it if it does not.
1016
 * @example
1017
 * bool result = ConfigDialog::checkPasswordStore();
1018
 * std::cout << std::boolalpha << result << std::endl; // Expected output: true
1019
 * if the store exists or is created successfully, false if creation fails
1020
 *
1021
 * @return bool - True if the password-store exists or is successfully created,
1022
 * false if creation fails.
1023
 */
1024
auto ConfigDialog::checkPasswordStore() -> bool {
×
1025
  QString passStore = ui->storePath->text();
×
1026

1027
  if (!QFile(passStore).exists()) {
×
1028
    if (QMessageBox::question(
×
1029
            this, tr("Create password-store?"),
×
1030
            tr("Would you like to create a password-store at %1?")
×
1031
                .arg(passStore),
×
1032
            QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
1033
      if (!QDir().mkdir(passStore)) {
×
1034
        QMessageBox::warning(
×
1035
            this, tr("Error"),
×
1036
            tr("Failed to create password-store at: %1").arg(passStore));
×
1037
        return false;
×
1038
      }
1039
#ifdef Q_OS_WIN
1040
      SetFileAttributes(passStore.toStdWString().c_str(),
1041
                        FILE_ATTRIBUTE_HIDDEN);
1042
#endif
1043
      if (ui->checkBoxUseGit->isChecked()) {
×
1044
        emit mainWindow->passGitInitNeeded();
×
1045
      }
1046
      mainWindow->userDialog(passStore);
×
1047
    }
1048
  }
1049
  return true;
1050
}
1051

1052
/**
1053
 * @brief Handles selection and validation of the password store's .gpg-id file.
1054
 * @example
1055
 * ConfigDialog dialog;
1056
 * dialog.handleGpgIdFile();
1057
 *
1058
 * @return void - This method does not return a value; it updates the UI flow
1059
 * and may prompt the user to choose a valid password store.
1060
 */
1061
void ConfigDialog::handleGpgIdFile() {
×
1062
  QString passStore = ui->storePath->text();
×
1063
  if (!QFile(QDir(passStore).filePath(".gpg-id")).exists()) {
×
1064
#ifdef QT_DEBUG
1065
    dbg() << ".gpg-id file does not exist";
1066
#endif
1067
    criticalMessage(tr("Password store not initialised"),
×
1068
                    tr("The folder %1 doesn't seem to be a password store or "
×
1069
                       "is not yet initialised.")
1070
                        .arg(passStore));
×
1071

1072
    while (!QFile(passStore).exists()) {
×
1073
      on_toolButtonStore_clicked();
×
1074
      if (passStore == ui->storePath->text()) {
×
1075
        return;
1076
      }
1077
      passStore = ui->storePath->text();
×
1078
    }
1079
    if (!QFile(passStore + ".gpg-id").exists()) {
×
1080
#ifdef QT_DEBUG
1081
      dbg() << ".gpg-id file still does not exist :/";
1082
#endif
1083
      mainWindow->userDialog(passStore);
×
1084
    }
1085
  }
1086
}
1087

1088
/**
1089
 * @brief ConfigDialog::useTrayIcon set preference for using trayicon.
1090
 * Enable or disable related checkboxes accordingly.
1091
 * @param useSystray
1092
 */
1093
void ConfigDialog::useTrayIcon(bool useSystray) {
×
1094
  if (QSystemTrayIcon::isSystemTrayAvailable()) {
×
1095
    ui->checkBoxUseTrayIcon->setChecked(useSystray);
×
1096
    ui->checkBoxHideOnClose->setEnabled(useSystray);
×
1097
    ui->checkBoxStartMinimized->setEnabled(useSystray);
×
1098

1099
    if (!useSystray) {
×
1100
      ui->checkBoxHideOnClose->setChecked(false);
×
1101
      ui->checkBoxStartMinimized->setChecked(false);
×
1102
    }
1103
  }
1104
}
×
1105

1106
/**
1107
 * @brief ConfigDialog::on_checkBoxUseTrayIcon_clicked enable and disable
1108
 * related checkboxes.
1109
 */
1110
void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
×
1111
  bool state = ui->checkBoxUseTrayIcon->isChecked();
×
1112
  ui->checkBoxHideOnClose->setEnabled(state);
×
1113
  ui->checkBoxStartMinimized->setEnabled(state);
×
1114
}
×
1115

1116
/**
1117
 * @brief ConfigDialog::closeEvent close this window.
1118
 * @param event
1119
 */
1120
void ConfigDialog::closeEvent(QCloseEvent *event) {
×
1121
  QtPassSettings::setDialogGeometry("configDialog", saveGeometry());
×
1122
  if (!isMaximized()) {
×
1123
    QtPassSettings::setDialogPos("configDialog", pos());
×
1124
    QtPassSettings::setDialogSize("configDialog", size());
×
1125
  }
1126
  QtPassSettings::setDialogMaximized("configDialog", isMaximized());
×
1127
  event->accept();
1128
}
×
1129

1130
/**
1131
 * @brief ConfigDialog::useGit set preference for using git.
1132
 * @param useGit
1133
 */
1134
void ConfigDialog::useGit(bool useGit) {
×
1135
  ui->checkBoxUseGit->setChecked(useGit);
×
1136
  on_checkBoxUseGit_clicked();
×
1137
}
×
1138

1139
/**
1140
 * @brief ConfigDialog::useOtp set preference for using otp plugin.
1141
 * @param useOtp
1142
 */
1143
void ConfigDialog::useOtp(bool useOtp) {
×
1144
  ui->checkBoxUseOtp->setChecked(useOtp);
×
1145
}
×
1146

1147
void ConfigDialog::useGrepSearch(bool useGrepSearch) {
×
1148
  ui->checkBoxUseGrepSearch->setChecked(useGrepSearch);
×
1149
}
×
1150

1151
/**
1152
 * @brief ConfigDialog::useQrencode set preference for using qrencode plugin.
1153
 * @param useQrencode
1154
 */
1155
void ConfigDialog::useQrencode(bool useQrencode) {
×
1156
  ui->checkBoxUseQrencode->setChecked(useQrencode);
×
1157
}
×
1158

1159
/**
1160
 * @brief ConfigDialog::on_checkBoxUseGit_clicked enable or disable related
1161
 * checkboxes.
1162
 */
1163
void ConfigDialog::on_checkBoxUseGit_clicked() {
×
1164
  ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
×
1165
  ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
×
1166
  ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
×
1167
}
×
1168

1169
/**
1170
 * @brief ConfigDialog::on_toolButtonPwgen_clicked enable or disable related
1171
 * options in the interface.
1172
 */
1173
void ConfigDialog::on_toolButtonPwgen_clicked() {
×
1174
  QString pwgen = selectExecutable();
×
1175
  if (!pwgen.isEmpty()) {
×
1176
    ui->pwgenPath->setText(pwgen);
×
1177
    ui->checkBoxUsePwgen->setEnabled(true);
×
1178
  } else {
1179
    ui->checkBoxUsePwgen->setEnabled(false);
×
1180
    ui->checkBoxUsePwgen->setChecked(false);
×
1181
  }
1182
}
×
1183

1184
/**
1185
 * @brief ConfigDialog::setPwgenPath set pwgen executable path.
1186
 * Enable or disable related options in the interface.
1187
 * @param pwgen
1188
 */
1189
void ConfigDialog::setPwgenPath(const QString &pwgen) {
×
1190
  ui->pwgenPath->setText(pwgen);
×
1191
  if (pwgen.isEmpty()) {
×
1192
    ui->checkBoxUsePwgen->setChecked(false);
×
1193
    ui->checkBoxUsePwgen->setEnabled(false);
×
1194
  }
1195
  on_checkBoxUsePwgen_clicked();
×
1196
}
×
1197

1198
/**
1199
 * @brief ConfigDialog::on_checkBoxUsePwgen_clicked enable or disable related
1200
 * options in the interface.
1201
 */
1202
void ConfigDialog::on_checkBoxUsePwgen_clicked() {
×
1203
  if (ui->radioButtonPass->isChecked())
×
1204
    return;
1205
  bool usePwgen = ui->checkBoxUsePwgen->isChecked();
×
1206
  ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
×
1207
  ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
×
1208
  ui->checkBoxLessRandom->setEnabled(usePwgen);
×
1209
  ui->checkBoxUseSymbols->setEnabled(usePwgen);
×
1210
  ui->lineEditPasswordChars->setEnabled(!usePwgen);
×
1211
  ui->labelPasswordChars->setEnabled(!usePwgen);
×
1212
  ui->passwordCharTemplateSelector->setEnabled(!usePwgen);
×
1213
}
1214

1215
/**
1216
 * @brief ConfigDialog::usePwgen set preference for using pwgen (can be
1217
 * overruled by empty pwgenPath).
1218
 * enable or disable related options in the interface via
1219
 * ConfigDialog::on_checkBoxUsePwgen_clicked
1220
 * @param usePwgen
1221
 */
1222
void ConfigDialog::usePwgen(bool usePwgen) {
×
1223
  if (ui->pwgenPath->text().isEmpty()) {
×
1224
    usePwgen = false;
1225
  }
1226
  ui->checkBoxUsePwgen->setChecked(usePwgen);
×
1227
  on_checkBoxUsePwgen_clicked();
×
1228
}
×
1229

1230
void ConfigDialog::setPasswordConfiguration(
×
1231
    const PasswordConfiguration &config) {
1232
  ui->spinBoxPasswordLength->setValue(config.length);
×
1233
  ui->passwordCharTemplateSelector->setCurrentIndex(config.selected);
×
1234
  if (config.selected != PasswordConfiguration::CUSTOM) {
×
1235
    ui->lineEditPasswordChars->setEnabled(false);
×
1236
  }
1237
  ui->lineEditPasswordChars->setText(config.Characters[config.selected]);
×
1238
}
×
1239

1240
auto ConfigDialog::getPasswordConfiguration() -> PasswordConfiguration {
×
1241
  PasswordConfiguration config;
×
1242
  config.length = ui->spinBoxPasswordLength->value();
×
1243
  config.selected = static_cast<PasswordConfiguration::characterSet>(
×
1244
      ui->passwordCharTemplateSelector->currentIndex());
×
1245
  config.Characters[PasswordConfiguration::CUSTOM] =
1246
      ui->lineEditPasswordChars->text();
×
1247
  return config;
×
1248
}
×
1249

1250
/**
1251
 * @brief ConfigDialog::on_passwordCharTemplateSelector_activated sets the
1252
 * passwordChar Template
1253
 * combo box to the desired entry
1254
 * @param entry of
1255
 */
1256
void ConfigDialog::on_passwordCharTemplateSelector_activated(int index) {
×
NEW
1257
  ui->lineEditPasswordChars->setText(
×
NEW
1258
      QtPassSettings::getPasswordConfiguration().Characters[index]);
×
NEW
1259
  if (index == PasswordConfiguration::CUSTOM) {
×
NEW
1260
    ui->lineEditPasswordChars->setEnabled(true);
×
1261
  } else {
NEW
1262
    ui->lineEditPasswordChars->setEnabled(false);
×
1263
  }
NEW
1264
}
×
1265

1266
/**
1267
 * @brief ConfigDialog::on_checkBoxUseTemplate_clicked enable or disable the
1268
 * template field and options.
1269
 */
NEW
1270
void ConfigDialog::on_checkBoxUseTemplate_clicked() {
×
NEW
1271
  ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
×
1272
  ui->checkBoxTemplateAllFields->setEnabled(
×
1273
      ui->checkBoxUseTemplate->isChecked());
×
1274
}
×
1275

NEW
1276
void ConfigDialog::onProfileTableItemChanged(QTableWidgetItem *item) {
×
1277
  // If profile name changed (column 0), update dialogGitSettings key
NEW
1278
  if (item != nullptr && item->column() == 0) {
×
NEW
1279
    QString newName = item->text();
×
1280
    // If currentProfileName was set and is different, rename in
1281
    // dialogGitSettings
NEW
1282
    if (!currentProfileName.isEmpty() && currentProfileName != newName) {
×
NEW
1283
      if (dialogGitSettings.contains(currentProfileName)) {
×
1284
        QHash<QString, QString> settings =
1285
            dialogGitSettings.take(currentProfileName);
NEW
1286
        dialogGitSettings[newName] = settings;
×
NEW
1287
      }
×
NEW
1288
      currentProfileName = newName;
×
1289
    }
1290
  }
1291

NEW
1292
  validate(item);
×
NEW
1293
  updateProfileStatus(item ? item->row() : -1);
×
NEW
1294
}
×
1295

1296
/**
1297
 * @brief Save the current profile's Git checkbox states to dialogGitSettings.
1298
 */
NEW
1299
void ConfigDialog::saveCurrentGitSettings() {
×
NEW
1300
  if (currentProfileName.isEmpty()) {
×
NEW
1301
    return;
×
1302
  }
1303

NEW
1304
  QHash<QString, QString> gitSettings;
×
NEW
1305
  gitSettings["useGit"] = ui->checkBoxUseGit->isChecked() ? "true" : "false";
×
NEW
1306
  gitSettings["autoPush"] =
×
NEW
1307
      ui->checkBoxAutoPush->isChecked() ? "true" : "false";
×
NEW
1308
  gitSettings["autoPull"] =
×
NEW
1309
      ui->checkBoxAutoPull->isChecked() ? "true" : "false";
×
NEW
1310
  dialogGitSettings[currentProfileName] = gitSettings;
×
1311
}
×
1312

UNCOV
1313
void ConfigDialog::onProfileTableSelectionChanged() {
×
1314
  // Save current profile's Git settings before switching
UNCOV
1315
  saveCurrentGitSettings();
×
1316

UNCOV
1317
  QList<QTableWidgetItem *> selected = ui->profileTable->selectedItems();
×
UNCOV
1318
  if (selected.isEmpty()) {
×
1319
    return;
1320
  }
1321
  QTableWidgetItem *nameItem =
1322
      ui->profileTable->item(selected.first()->row(), 0);
×
1323
  if (nameItem == nullptr) {
×
1324
    return;
1325
  }
1326
  QString profileName = nameItem->text();
×
1327
  currentProfileName = profileName;
×
1328
  loadGitSettingsForProfile(profileName);
×
1329
}
1330

1331
/**
1332
 * @brief Update status bar with profile preview for given row.
1333
 * @param row The row index to preview, or -1 to clear.
1334
 */
1335
void ConfigDialog::updateProfileStatus(int row) {
×
1336
  if (row < 0 || row >= ui->profileTable->rowCount()) {
×
1337
    ui->statusLabel->setText(QString());
×
1338
    return;
×
1339
  }
1340

1341
  QTableWidgetItem *nameItem = ui->profileTable->item(row, 0);
×
1342
  QTableWidgetItem *pathItem = ui->profileTable->item(row, 1);
×
1343

1344
  QString statusMessage;
×
1345
  if (nameItem && !nameItem->text().isEmpty() && pathItem &&
×
1346
      !pathItem->text().isEmpty()) {
×
1347
    QDir dir(QDir::cleanPath(pathItem->text()));
×
1348
    if (!dir.exists()) {
×
1349
      statusMessage = tr("New profile: %1 at %2")
×
1350
                          .arg(nameItem->text())
×
1351
                          .arg(QDir::cleanPath(pathItem->text()));
×
1352
    } else {
1353
      statusMessage = tr("Profile: %1 at %2")
×
1354
                          .arg(nameItem->text())
×
1355
                          .arg(QDir::cleanPath(pathItem->text()));
×
1356
    }
1357
  } else {
×
1358
    statusMessage = tr("Fill in all required fields");
×
1359
  }
1360

1361
  ui->statusLabel->setText(statusMessage);
×
1362
}
1363

1364
/**
1365
 * @brief ConfigDialog::useTemplate set preference for using templates.
1366
 * @param useTemplate
1367
 */
1368
void ConfigDialog::useTemplate(bool useTemplate) {
×
1369
  ui->checkBoxUseTemplate->setChecked(useTemplate);
×
1370
  on_checkBoxUseTemplate_clicked();
×
1371
}
×
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