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

IJHack / QtPass / 24836053081

23 Apr 2026 12:47PM UTC coverage: 27.5% (+0.4%) from 27.079%
24836053081

Pull #1140

github

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

44 of 70 new or added lines in 2 files covered. (62.86%)

2 existing lines in 1 file now uncovered.

1636 of 5949 relevant lines covered (27.5%)

29.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/configdialog.cpp
1
// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "configdialog.h"
4
#include "keygendialog.h"
5
#include "mainwindow.h"
6
#include "profileinit.h"
7
#include "qtpasssettings.h"
8
#include "ui_configdialog.h"
9
#include "usersdialog.h"
10
#include "util.h"
11
#include <QClipboard>
12
#include <QDir>
13
#include <QFileDialog>
14
#include <QMessageBox>
15
#include <QPushButton>
16
#include <QSystemTrayIcon>
17
#include <QTableWidgetItem>
18
#include <utility>
19
#ifdef Q_OS_WIN
20
#include <windows.h>
21
#endif
22

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

293
  QtPassSettings::setVersion(VERSION);
×
294

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

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

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

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

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

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

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

358
  return names;
×
359
}
360

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

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

399
  return {};
400
}
×
401

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

415
  return {};
416
}
×
417

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
630
  QHash<QString, QHash<QString, QString>> profiles;
×
631
  // Check?
632
  for (int i = 0; i < ui->profileTable->rowCount(); ++i) {
×
633
    QHash<QString, QString> profile;
×
634
    QTableWidgetItem *pathItem = ui->profileTable->item(i, 1);
×
635
    if (nullptr != pathItem) {
×
636
      QTableWidgetItem *item = ui->profileTable->item(i, 0);
×
637
      if (item == nullptr) {
×
638
        continue;
639
      }
640
      profile["path"] = pathItem->text();
×
641
      QTableWidgetItem *signingKeyItem = ui->profileTable->item(i, 2);
×
642
      if (nullptr != signingKeyItem) {
×
643
        profile["signingKey"] = signingKeyItem->text();
×
644
      }
645

646
      // Only update git settings for the currently selected profile
647
      // Preserve existing git settings for other profiles
NEW
648
      if (item->text() == selectedProfile) {
×
NEW
649
        profile["useGit"] = ui->checkBoxUseGit->isChecked() ? "true" : "false";
×
NEW
650
        profile["autoPush"] =
×
NEW
651
            ui->checkBoxAutoPush->isChecked() ? "true" : "false";
×
NEW
652
        profile["autoPull"] =
×
NEW
653
            ui->checkBoxAutoPull->isChecked() ? "true" : "false";
×
654
      }
UNCOV
655
      profiles.insert(item->text(), profile);
×
656
    }
657
  }
×
658
  return profiles;
×
659
}
×
660

661
/**
662
 * @brief Initialize new profiles that need pass/git initialization.
663
 * @param existingProfiles The profiles that existed before the dialog was
664
 * opened.
665
 */
666
void ConfigDialog::initializeNewProfiles(
×
667
    const QHash<QString, QHash<QString, QString>> &existingProfiles) {
668
  QHash<QString, QHash<QString, QString>> newProfiles = getProfiles();
×
669

670
  // Collect keys and sort for deterministic iteration
671
  QStringList keys = newProfiles.keys();
×
672
  keys.sort();
673

674
  for (const QString &name : keys) {
×
675
    const QString &path = newProfiles.value(name).value("path");
×
676

677
    // Skip if already existed before (check by name and path)
678
    if (existingProfiles.contains(name) &&
×
679
        existingProfiles.value(name).value("path") == path) {
×
680
      continue;
×
681
    }
682

683
    // This is a new profile - create directory if needed and initialize
684
    // Note: needsInit returns false for non-existent directories, so we
685
    // must create the directory first.
686
    QString cleanPath = QDir::cleanPath(path);
×
687
    QDir dir(cleanPath);
×
688
    if (!dir.exists()) {
×
689
      if (QMessageBox::question(
×
690
              this, tr("Create profile directory?"),
×
691
              tr("Would you like to create a password store at %1?")
×
692
                  .arg(cleanPath),
×
693
              QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
694
        continue;
×
695
      }
696
      if (!QDir().mkpath(cleanPath)) {
×
697
        QMessageBox::warning(
×
698
            this, tr("Error"),
×
699
            tr("Could not create profile directory: %1").arg(cleanPath));
×
700
        continue;
×
701
      }
702
    }
703

704
    // Now check if initialization is needed (directory exists with no .gpg-id)
705
    if (!ProfileInit::needsInit(cleanPath)) {
×
706
      continue;
×
707
    }
708

709
    // Temporarily switch the active store so pass/git init operate on
710
    // the new profile's directory rather than the currently-saved one.
711
    const QString prevStore = QtPassSettings::getPassStore();
×
712
    QtPassSettings::setPassStore(cleanPath);
×
713

714
    // Show user selection dialog for GPG recipients
715
    // UsersDialog will run pass init when accepted
716
    UsersDialog usersDialog(cleanPath, this);
×
717
    usersDialog.setWindowTitle(tr("Select recipients for %1").arg(name));
×
718
    const int result = usersDialog.exec();
×
719

720
    if (result == QDialog::Accepted && ui->checkBoxUseGit->isChecked()) {
×
721
      QtPassSettings::getPass()->GitInit();
×
722
    }
723

724
    // Restore previous store setting
725
    QtPassSettings::setPassStore(prevStore);
×
726
  }
×
727
}
×
728

729
/**
730
 * @brief ConfigDialog::on_addButton_clicked add a profile row.
731
 */
732
void ConfigDialog::on_addButton_clicked() {
×
733
  bool sortingEnabled = ui->profileTable->isSortingEnabled();
×
734
  ui->profileTable->setSortingEnabled(false);
×
735

736
  int n = ui->profileTable->rowCount();
×
737
  ui->profileTable->insertRow(n);
×
738
  ui->profileTable->setItem(n, 0, new QTableWidgetItem(tr("New Profile")));
×
739
  ui->profileTable->setItem(n, 1, new QTableWidgetItem(ui->storePath->text()));
×
740
  ui->profileTable->setItem(n, 2, new QTableWidgetItem());
×
741

742
  ui->profileTable->setSortingEnabled(sortingEnabled);
×
743

744
  int currentRow = ui->profileTable->row(ui->profileTable->item(n, 0));
×
745
  ui->profileTable->selectRow(currentRow);
×
746
  ui->deleteButton->setEnabled(true);
×
747

748
  ui->profileTable->editItem(ui->profileTable->item(currentRow, 0));
×
749
  ui->profileTable->item(currentRow, 0)->setSelected(true);
×
750

751
  validate();
×
752
  updateProfileStatus(currentRow);
×
753
}
×
754

755
/**
756
 * @brief ConfigDialog::on_profileTable_cellDoubleClicked open folder browser
757
 * for path column (column 1).
758
 */
759
void ConfigDialog::on_profileTable_cellDoubleClicked(int row, int column) {
×
760
  if (column == 1) {
×
761
    QString dir = selectFolder();
×
762
    if (!dir.isEmpty()) {
×
763
      ui->profileTable->item(row, 1)->setText(dir);
×
764
    }
765
  }
766
}
×
767

768
/**
769
 * @brief ConfigDialog::on_deleteButton_clicked remove a profile row.
770
 */
771
void ConfigDialog::on_deleteButton_clicked() {
×
772
  QSet<int> selectedRows; //  we use a set to prevent doubles
773
  QList<QTableWidgetItem *> itemList = ui->profileTable->selectedItems();
×
774
  if (itemList.count() == 0) {
×
775
    QMessageBox::warning(this, tr("No profile selected"),
×
776
                         tr("No profile selected to delete"));
×
777
    return;
778
  }
779
  QTableWidgetItem *item;
780
  foreach (item, itemList)
×
781
    selectedRows.insert(item->row());
×
782
  // get a list, and sort it big to small
783
  QList<int> rows = selectedRows.values();
×
784
  std::sort(rows.begin(), rows.end());
×
785
  // now actually do the removing:
786
  foreach (int row, rows)
×
787
    ui->profileTable->removeRow(row);
×
788
  if (ui->profileTable->rowCount() < 1) {
×
789
    ui->deleteButton->setEnabled(false);
×
790
  }
791

792
  validate();
×
793
  updateProfileStatus(-1);
×
794
}
795

796
/**
797
 * @brief ConfigDialog::criticalMessage wrapper for showing critical messages
798
 * in a popup.
799
 * @param title
800
 * @param text
801
 */
802
void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
×
803
  QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
×
804
}
×
805

806
/**
807
 * @brief Checks whether the qrencode executable is available on the system.
808
 * @example
809
 * bool result = ConfigDialog::isQrencodeAvailable();
810
 * std::cout << result << std::endl; // Expected output: true if qrencode is
811
 * found, otherwise false
812
 *
813
 * @return bool - True if qrencode is available; otherwise false. On Windows,
814
 * always returns false.
815
 */
816
auto ConfigDialog::isQrencodeAvailable() -> bool {
×
817
#ifdef Q_OS_WIN
818
  return false;
819
#else
820
  QProcess which;
×
821
  which.start("which", QStringList() << "qrencode");
×
822
  which.waitForFinished();
×
823
  QtPassSettings::setQrencodeExecutable(
×
824
      which.readAllStandardOutput().trimmed());
×
825
  return which.exitCode() == 0;
×
826
#endif
827
}
×
828

829
auto ConfigDialog::isPassOtpAvailable() -> bool {
×
830
#ifdef Q_OS_WIN
831
  return false;
832
#else
833
  QProcess pass;
×
834
  pass.start(QtPassSettings::getPassExecutable(), QStringList() << "otp"
×
835
                                                                << "--help");
×
836
  pass.waitForFinished(2000);
×
837
  return pass.exitCode() == 0;
×
838
#endif
839
}
×
840

841
/**
842
 * @brief ConfigDialog::wizard first-time use wizard.
843
 */
844
void ConfigDialog::wizard() {
×
845
  (void)Util::configIsValid();
×
846
  on_autodetectButton_clicked();
×
847

848
  if (!checkGpgExistence()) {
×
849
    return;
850
  }
851
  if (!checkSecretKeys()) {
×
852
    return;
853
  }
854
  if (!checkPasswordStore()) {
×
855
    return;
856
  }
857
  handleGpgIdFile();
×
858

859
  ui->checkBoxHidePassword->setCheckState(Qt::Checked);
×
860
}
861

862
/**
863
 * @brief Checks whether the configured GnuPG executable exists.
864
 * @example
865
 * bool result = ConfigDialog::checkGpgExistence();
866
 * std::cout << result << std::endl; // Expected output: true if GnuPG is found,
867
 * false otherwise
868
 *
869
 * @return bool - True if the GnuPG path is valid or uses a WSL command prefix;
870
 * false if the executable cannot be found and an error message is shown.
871
 */
872
auto ConfigDialog::checkGpgExistence() -> bool {
×
873
  QString gpg = ui->gpgPath->text();
×
874
  if (!gpg.startsWith("wsl ") && !QFile(gpg).exists()) {
×
875
    criticalMessage(
×
876
        tr("GnuPG not found"),
×
877
#ifdef Q_OS_WIN
878
#ifdef WINSTORE
879
        tr("Please install GnuPG on your system.<br>Install "
880
           "<strong>Ubuntu</strong> from the Microsoft Store to get it.<br>"
881
           "If you already did so, make sure you started it once and<br>"
882
           "click \"Autodetect\" in the next dialog.")
883
#else
884
        tr("Please install GnuPG on your system.<br>Install "
885
           "<strong>Ubuntu</strong> from the Microsoft Store<br>or <a "
886
           "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
887
           "from GnuPG.org")
888
#endif
889
#else
890
        tr("Please install GnuPG on your system.<br>Install "
×
891
           "<strong>gpg</strong> using your favorite package manager<br>or "
892
           "<a "
893
           "href=\"https://www.gnupg.org/download/#sec-1-2\">download</a> it "
894
           "from GnuPG.org")
895
#endif
896
    );
897
    return false;
×
898
  }
899
  return true;
900
}
901

902
/**
903
 * @brief Checks whether secret keys are available and, if needed, prompts the
904
 * user to generate them.
905
 * @example
906
 * bool result = ConfigDialog.checkSecretKeys();
907
 * std::cout << result << std::endl; // Expected output: true if keys are
908
 * present or key generation dialog is accepted, false otherwise
909
 *
910
 * @return bool - Returns true when secret keys are already available or the key
911
 * generation dialog is accepted; false if the dialog is rejected.
912
 */
913
auto ConfigDialog::checkSecretKeys() -> bool {
×
914
  QString gpg = ui->gpgPath->text();
×
915
  QStringList names = getSecretKeys();
×
916

917
#ifdef QT_DEBUG
918
  dbg() << names;
919
#endif
920

921
  if ((gpg.startsWith("wsl ") || QFile(gpg).exists()) && names.empty()) {
×
922
    KeygenDialog d(this);
×
923
    return d.exec();
×
924
  }
×
925
  return true;
926
}
927

928
/**
929
 * @brief Checks whether the password-store path exists and prompts the user to
930
 * create it if it does not.
931
 * @example
932
 * bool result = ConfigDialog::checkPasswordStore();
933
 * std::cout << std::boolalpha << result << std::endl; // Expected output: true
934
 * if the store exists or is created successfully, false if creation fails
935
 *
936
 * @return bool - True if the password-store exists or is successfully created,
937
 * false if creation fails.
938
 */
939
auto ConfigDialog::checkPasswordStore() -> bool {
×
940
  QString passStore = ui->storePath->text();
×
941

942
  if (!QFile(passStore).exists()) {
×
943
    if (QMessageBox::question(
×
944
            this, tr("Create password-store?"),
×
945
            tr("Would you like to create a password-store at %1?")
×
946
                .arg(passStore),
×
947
            QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
948
      if (!QDir().mkdir(passStore)) {
×
949
        QMessageBox::warning(
×
950
            this, tr("Error"),
×
951
            tr("Failed to create password-store at: %1").arg(passStore));
×
952
        return false;
×
953
      }
954
#ifdef Q_OS_WIN
955
      SetFileAttributes(passStore.toStdWString().c_str(),
956
                        FILE_ATTRIBUTE_HIDDEN);
957
#endif
958
      if (ui->checkBoxUseGit->isChecked()) {
×
959
        emit mainWindow->passGitInitNeeded();
×
960
      }
961
      mainWindow->userDialog(passStore);
×
962
    }
963
  }
964
  return true;
965
}
966

967
/**
968
 * @brief Handles selection and validation of the password store's .gpg-id file.
969
 * @example
970
 * ConfigDialog dialog;
971
 * dialog.handleGpgIdFile();
972
 *
973
 * @return void - This method does not return a value; it updates the UI flow
974
 * and may prompt the user to choose a valid password store.
975
 */
976
void ConfigDialog::handleGpgIdFile() {
×
977
  QString passStore = ui->storePath->text();
×
978
  if (!QFile(QDir(passStore).filePath(".gpg-id")).exists()) {
×
979
#ifdef QT_DEBUG
980
    dbg() << ".gpg-id file does not exist";
981
#endif
982
    criticalMessage(tr("Password store not initialised"),
×
983
                    tr("The folder %1 doesn't seem to be a password store or "
×
984
                       "is not yet initialised.")
985
                        .arg(passStore));
×
986

987
    while (!QFile(passStore).exists()) {
×
988
      on_toolButtonStore_clicked();
×
989
      if (passStore == ui->storePath->text()) {
×
990
        return;
991
      }
992
      passStore = ui->storePath->text();
×
993
    }
994
    if (!QFile(passStore + ".gpg-id").exists()) {
×
995
#ifdef QT_DEBUG
996
      dbg() << ".gpg-id file still does not exist :/";
997
#endif
998
      mainWindow->userDialog(passStore);
×
999
    }
1000
  }
1001
}
1002

1003
/**
1004
 * @brief ConfigDialog::useTrayIcon set preference for using trayicon.
1005
 * Enable or disable related checkboxes accordingly.
1006
 * @param useSystray
1007
 */
1008
void ConfigDialog::useTrayIcon(bool useSystray) {
×
1009
  if (QSystemTrayIcon::isSystemTrayAvailable()) {
×
1010
    ui->checkBoxUseTrayIcon->setChecked(useSystray);
×
1011
    ui->checkBoxHideOnClose->setEnabled(useSystray);
×
1012
    ui->checkBoxStartMinimized->setEnabled(useSystray);
×
1013

1014
    if (!useSystray) {
×
1015
      ui->checkBoxHideOnClose->setChecked(false);
×
1016
      ui->checkBoxStartMinimized->setChecked(false);
×
1017
    }
1018
  }
1019
}
×
1020

1021
/**
1022
 * @brief ConfigDialog::on_checkBoxUseTrayIcon_clicked enable and disable
1023
 * related checkboxes.
1024
 */
1025
void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
×
1026
  bool state = ui->checkBoxUseTrayIcon->isChecked();
×
1027
  ui->checkBoxHideOnClose->setEnabled(state);
×
1028
  ui->checkBoxStartMinimized->setEnabled(state);
×
1029
}
×
1030

1031
/**
1032
 * @brief ConfigDialog::closeEvent close this window.
1033
 * @param event
1034
 */
1035
void ConfigDialog::closeEvent(QCloseEvent *event) {
×
1036
  QtPassSettings::setDialogGeometry("configDialog", saveGeometry());
×
1037
  if (!isMaximized()) {
×
1038
    QtPassSettings::setDialogPos("configDialog", pos());
×
1039
    QtPassSettings::setDialogSize("configDialog", size());
×
1040
  }
1041
  QtPassSettings::setDialogMaximized("configDialog", isMaximized());
×
1042
  event->accept();
1043
}
×
1044

1045
/**
1046
 * @brief ConfigDialog::useGit set preference for using git.
1047
 * @param useGit
1048
 */
1049
void ConfigDialog::useGit(bool useGit) {
×
1050
  ui->checkBoxUseGit->setChecked(useGit);
×
1051
  on_checkBoxUseGit_clicked();
×
1052
}
×
1053

1054
/**
1055
 * @brief ConfigDialog::useOtp set preference for using otp plugin.
1056
 * @param useOtp
1057
 */
1058
void ConfigDialog::useOtp(bool useOtp) {
×
1059
  ui->checkBoxUseOtp->setChecked(useOtp);
×
1060
}
×
1061

1062
void ConfigDialog::useGrepSearch(bool useGrepSearch) {
×
1063
  ui->checkBoxUseGrepSearch->setChecked(useGrepSearch);
×
1064
}
×
1065

1066
/**
1067
 * @brief ConfigDialog::useQrencode set preference for using qrencode plugin.
1068
 * @param useQrencode
1069
 */
1070
void ConfigDialog::useQrencode(bool useQrencode) {
×
1071
  ui->checkBoxUseQrencode->setChecked(useQrencode);
×
1072
}
×
1073

1074
/**
1075
 * @brief ConfigDialog::on_checkBoxUseGit_clicked enable or disable related
1076
 * checkboxes.
1077
 */
1078
void ConfigDialog::on_checkBoxUseGit_clicked() {
×
1079
  ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
×
1080
  ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
×
1081
  ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
×
1082
}
×
1083

1084
/**
1085
 * @brief ConfigDialog::on_toolButtonPwgen_clicked enable or disable related
1086
 * options in the interface.
1087
 */
1088
void ConfigDialog::on_toolButtonPwgen_clicked() {
×
1089
  QString pwgen = selectExecutable();
×
1090
  if (!pwgen.isEmpty()) {
×
1091
    ui->pwgenPath->setText(pwgen);
×
1092
    ui->checkBoxUsePwgen->setEnabled(true);
×
1093
  } else {
1094
    ui->checkBoxUsePwgen->setEnabled(false);
×
1095
    ui->checkBoxUsePwgen->setChecked(false);
×
1096
  }
1097
}
×
1098

1099
/**
1100
 * @brief ConfigDialog::setPwgenPath set pwgen executable path.
1101
 * Enable or disable related options in the interface.
1102
 * @param pwgen
1103
 */
1104
void ConfigDialog::setPwgenPath(const QString &pwgen) {
×
1105
  ui->pwgenPath->setText(pwgen);
×
1106
  if (pwgen.isEmpty()) {
×
1107
    ui->checkBoxUsePwgen->setChecked(false);
×
1108
    ui->checkBoxUsePwgen->setEnabled(false);
×
1109
  }
1110
  on_checkBoxUsePwgen_clicked();
×
1111
}
×
1112

1113
/**
1114
 * @brief ConfigDialog::on_checkBoxUsePwgen_clicked enable or disable related
1115
 * options in the interface.
1116
 */
1117
void ConfigDialog::on_checkBoxUsePwgen_clicked() {
×
1118
  if (ui->radioButtonPass->isChecked())
×
1119
    return;
1120
  bool usePwgen = ui->checkBoxUsePwgen->isChecked();
×
1121
  ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
×
1122
  ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
×
1123
  ui->checkBoxLessRandom->setEnabled(usePwgen);
×
1124
  ui->checkBoxUseSymbols->setEnabled(usePwgen);
×
1125
  ui->lineEditPasswordChars->setEnabled(!usePwgen);
×
1126
  ui->labelPasswordChars->setEnabled(!usePwgen);
×
1127
  ui->passwordCharTemplateSelector->setEnabled(!usePwgen);
×
1128
}
1129

1130
/**
1131
 * @brief ConfigDialog::usePwgen set preference for using pwgen (can be
1132
 * overruled by empty pwgenPath).
1133
 * enable or disable related options in the interface via
1134
 * ConfigDialog::on_checkBoxUsePwgen_clicked
1135
 * @param usePwgen
1136
 */
1137
void ConfigDialog::usePwgen(bool usePwgen) {
×
1138
  if (ui->pwgenPath->text().isEmpty()) {
×
1139
    usePwgen = false;
1140
  }
1141
  ui->checkBoxUsePwgen->setChecked(usePwgen);
×
1142
  on_checkBoxUsePwgen_clicked();
×
1143
}
×
1144

1145
void ConfigDialog::setPasswordConfiguration(
×
1146
    const PasswordConfiguration &config) {
1147
  ui->spinBoxPasswordLength->setValue(config.length);
×
1148
  ui->passwordCharTemplateSelector->setCurrentIndex(config.selected);
×
1149
  if (config.selected != PasswordConfiguration::CUSTOM) {
×
1150
    ui->lineEditPasswordChars->setEnabled(false);
×
1151
  }
1152
  ui->lineEditPasswordChars->setText(config.Characters[config.selected]);
×
1153
}
×
1154

1155
auto ConfigDialog::getPasswordConfiguration() -> PasswordConfiguration {
×
1156
  PasswordConfiguration config;
×
1157
  config.length = ui->spinBoxPasswordLength->value();
×
1158
  config.selected = static_cast<PasswordConfiguration::characterSet>(
×
1159
      ui->passwordCharTemplateSelector->currentIndex());
×
1160
  config.Characters[PasswordConfiguration::CUSTOM] =
1161
      ui->lineEditPasswordChars->text();
×
1162
  return config;
×
1163
}
×
1164

1165
/**
1166
 * @brief ConfigDialog::on_passwordCharTemplateSelector_activated sets the
1167
 * passwordChar Template
1168
 * combo box to the desired entry
1169
 * @param entry of
1170
 */
1171
void ConfigDialog::on_passwordCharTemplateSelector_activated(int index) {
×
1172
  ui->lineEditPasswordChars->setText(
×
1173
      QtPassSettings::getPasswordConfiguration().Characters[index]);
×
1174
  if (index == PasswordConfiguration::CUSTOM) {
×
1175
    ui->lineEditPasswordChars->setEnabled(true);
×
1176
  } else {
1177
    ui->lineEditPasswordChars->setEnabled(false);
×
1178
  }
1179
}
×
1180

1181
/**
1182
 * @brief ConfigDialog::on_checkBoxUseTemplate_clicked enable or disable the
1183
 * template field and options.
1184
 */
1185
void ConfigDialog::on_checkBoxUseTemplate_clicked() {
×
1186
  ui->plainTextEditTemplate->setEnabled(ui->checkBoxUseTemplate->isChecked());
×
1187
  ui->checkBoxTemplateAllFields->setEnabled(
×
1188
      ui->checkBoxUseTemplate->isChecked());
×
1189
}
×
1190

1191
void ConfigDialog::onProfileTableItemChanged(QTableWidgetItem *item) {
×
1192
  validate(item);
×
1193
  updateProfileStatus(item ? item->row() : -1);
×
1194
}
×
1195

1196
/**
1197
 * @brief Update status bar with profile preview for given row.
1198
 * @param row The row index to preview, or -1 to clear.
1199
 */
1200
void ConfigDialog::updateProfileStatus(int row) {
×
1201
  if (row < 0 || row >= ui->profileTable->rowCount()) {
×
1202
    ui->statusLabel->setText(QString());
×
1203
    return;
×
1204
  }
1205

1206
  QTableWidgetItem *nameItem = ui->profileTable->item(row, 0);
×
1207
  QTableWidgetItem *pathItem = ui->profileTable->item(row, 1);
×
1208

1209
  QString statusMessage;
×
1210
  if (nameItem && !nameItem->text().isEmpty() && pathItem &&
×
1211
      !pathItem->text().isEmpty()) {
×
1212
    QDir dir(QDir::cleanPath(pathItem->text()));
×
1213
    if (!dir.exists()) {
×
1214
      statusMessage = tr("New profile: %1 at %2")
×
1215
                          .arg(nameItem->text())
×
1216
                          .arg(QDir::cleanPath(pathItem->text()));
×
1217
    } else {
1218
      statusMessage = tr("Profile: %1 at %2")
×
1219
                          .arg(nameItem->text())
×
1220
                          .arg(QDir::cleanPath(pathItem->text()));
×
1221
    }
1222
  } else {
×
1223
    statusMessage = tr("Fill in all required fields");
×
1224
  }
1225

1226
  ui->statusLabel->setText(statusMessage);
×
1227
}
1228

1229
/**
1230
 * @brief ConfigDialog::useTemplate set preference for using templates.
1231
 * @param useTemplate
1232
 */
1233
void ConfigDialog::useTemplate(bool useTemplate) {
×
1234
  ui->checkBoxUseTemplate->setChecked(useTemplate);
×
1235
  on_checkBoxUseTemplate_clicked();
×
1236
}
×
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