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

IJHack / QtPass / 44269343813

18 Nov 2026 08:42AM UTC coverage: 96.308% (+0.03%) from 96.28%
44269343813

Pull #2261

github

web-flow
Merge 977f9cff7 into ba6b598d3
Pull Request #2261: Git set-up refuses a FIFO and times out; a half-done pull stops re-encryption

60 of 64 new or added lines in 3 files covered. (93.75%)

17 existing lines in 2 files now uncovered.

9157 of 9508 relevant lines covered (96.31%)

1286.78 hits per line

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

97.54
/src/configdialog.cpp
1
// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
/**
4
 * @file
5
 * @brief Implements ConfigDialog: loading and reading the widgets
6
 * (applySettings(), readSettings()), the profile table with its validation
7
 * (validate(), problemsOf(), sharingTheKey()) and the initialisation of
8
 * stores for profiles added in the dialog (initializeNewProfiles()).
9
 */
10
#include "configdialog.h"
11
#include "appsettings.h"
12
#include "executor.h"
13
#include "gpgkeystate.h"
14
#include "keygendialog.h"
15
#include "plainmessagebox.h"
16
#include "profileinit.h"
17
#include "qtpasssettings.h"
18
#include "sshauthsock.h"
19
#include "ui_configdialog.h"
20
#include "usersdialog.h"
21
#include "util.h"
22
#include "windowstatestore.h"
23
#include <QClipboard>
24
#include <QDir>
25
#include <QEvent>
26
#include <QFileDialog>
27
#include <QFileInfo>
28
#include <QFormLayout>
29
#include <QGuiApplication>
30
#include <QHash>
31
#include <QLabel>
32
#include <QListWidgetItem>
33
#include <QMessageBox>
34
#include <QPushButton>
35
#include <QRegularExpression>
36
#include <QSet>
37
#include <QSystemTrayIcon>
38
#include <algorithm>
39
#include <utility>
40
#ifdef Q_OS_WIN
41
#include <windows.h>
42
#endif
43

44
#include "qtpasslogging.h"
45

46
ConfigDialog::ConfigDialog(QWidget *parent)
82 ✔
47
    : QDialog(parent), ui(new Ui::ConfigDialog) {
82 ✔
48
  ui->setupUi(this);
82 ✔
49

50
  WindowStateStore::attach(*this, QStringLiteral("configDialog"));
164 ✔
51

52
  // setSpecialValueText() in retranslateUi() drops the size hint without
53
  // telling the layout, which then sizes the box for "0" and shows "ver".
54
  ui->spinBoxAutoclearSeconds->updateGeometry();
82 ✔
55
  ui->spinBoxAutoclearPanelSeconds->updateGeometry();
82 ✔
56

57
  // The secret field names only mean something while passwords are hidden.
58
  connect(ui->checkBoxHidePassword, &QCheckBox::toggled, this,
82 ✔
59
          [this] { updateSecretFieldsEnabled(); });
109 ✔
60
  connect(ui->checkBoxHideSecretFields, &QCheckBox::toggled, this,
82 ✔
61
          [this] { updateSecretFieldsEnabled(); });
167 ✔
62
  connect(ui->checkBoxHideAllFields, &QCheckBox::toggled, this,
82 ✔
63
          [this] { updateSecretFieldsEnabled(); });
85 ✔
64
  connect(ui->buttonDefaultSecretFields, &QPushButton::clicked, this, [this] {
82 ✔
65
    ui->lineEditSecretFields->setText(
2 ✔
66
        AppSettings::defaultSecretFieldNames().join(QStringLiteral(", ")));
2 ✔
67
  });
1 ✔
68
  // "Seconds" says nothing next to "Never" (the spin box's 0).
69
  // Restoring is part of clearing: only there when the clipboard is cleared.
70
  connect(ui->spinBoxAutoclearSeconds, &QSpinBox::valueChanged, this,
82 ✔
71
          [this](int value) {
82 ✔
72
            ui->labelSeconds->setVisible(value > 0);
30 ✔
73
            ui->checkBoxRestoreClipboard->setVisible(value > 0);
30 ✔
74
          });
30 ✔
75
  connect(ui->spinBoxAutoclearPanelSeconds, &QSpinBox::valueChanged, this,
82 ✔
76
          [this](int value) { ui->labelPanelSeconds->setVisible(value > 0); });
113 ✔
77
  connect(
82 ✔
78
      ui->comboBoxFields, &QComboBox::currentIndexChanged, this,
82 ✔
79
      [this](int index) { ui->plainTextEditTemplate->setEnabled(index > 0); });
116 ✔
80

81
  const AppSettings s = QtPassSettings::load();
82 ✔
82
  applySettings(s);
82 ✔
83

84
  if (!QSystemTrayIcon::isSystemTrayAvailable()) {
82 ✔
85
    ui->checkBoxUseTrayIcon->setEnabled(false);
82 ✔
86
    ui->checkBoxUseTrayIcon->setToolTip(tr("System tray is not available"));
164 ✔
87
    ui->checkBoxHideOnClose->setEnabled(false);
82 ✔
88
    ui->checkBoxStartMinimized->setEnabled(false);
82 ✔
89
  }
90

91
  // Wayland has no client-side "keep above" — Qt::WindowStaysOnTopHint is
92
  // silently ignored there (stacking belongs to the compositor). Say so
93
  // instead of offering a checkbox that does nothing.
94
  if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"))) {
82 ✔
UNCOV
95
    ui->checkBoxAlwaysOnTop->setEnabled(false);
×
96
    ui->checkBoxAlwaysOnTop->setToolTip(
×
97
        tr("Not available on Wayland; use your compositor's "
×
98
           "\"keep above\" window rule instead"));
99
  }
100

101
#if defined(Q_OS_WIN)
102
  // checkBoxUseOtp stays visible: OTP is generated in-process, not by the
103
  // Unix-only pass-otp extension.
104
  ui->checkBoxUseQrencode->hide();
105
#endif
106

107
  if (!isQrencodeAvailable(s.qrencodeExecutable)) {
82 ✔
108
    ui->checkBoxUseQrencode->setEnabled(false);
80 ✔
109
    ui->checkBoxUseQrencode->setToolTip(tr("qrencode needs to be installed"));
160 ✔
110
  }
111

112
  connect(ui->profileList, &QListWidget::currentRowChanged, this,
82 ✔
113
          &ConfigDialog::onProfileSelected);
82 ✔
114
  connect(ui->profileName, &QLineEdit::textEdited, this,
82 ✔
115
          &ConfigDialog::onProfileNameEdited);
82 ✔
116
  connect(ui->profilePath, &QLineEdit::textEdited, this,
82 ✔
117
          &ConfigDialog::onProfilePathEdited);
82 ✔
118
  connect(ui->profileSigningKey, &QLineEdit::textEdited, this,
82 ✔
119
          &ConfigDialog::onProfileSigningKeyEdited);
164 ✔
120
  for (QCheckBox *box :
574 ✔
121
       {ui->profileUseGit, ui->profileAutoPush, ui->profileAutoPull}) {
328 ✔
122
    connect(box, &QCheckBox::clicked, this, &ConfigDialog::onProfileGitToggled);
246 ✔
123
  }
124
  m_nameTip = ui->profileName->toolTip();
164 ✔
125
  m_pathTip = ui->profilePath->toolTip();
164 ✔
126
  m_keyTip = ui->profileSigningKey->toolTip();
82 ✔
127
  // A warning, not a problem: shown under the signing key while another
128
  // profile, for another store, signs with the same key (#2050).
129
  m_sharedKeyWarning = new QLabel(this);
82 ✔
130
  m_sharedKeyWarning->setObjectName(QStringLiteral("profileSharedKeyWarning"));
164 ✔
131
  m_sharedKeyWarning->setTextFormat(Qt::PlainText);
82 ✔
132
  m_sharedKeyWarning->setWordWrap(true);
82 ✔
133
  m_sharedKeyWarning->hide();
82 ✔
134
  {
135
    int row = -1;
82 ✔
136
    QFormLayout::ItemRole role = QFormLayout::FieldRole;
82 ✔
137
    ui->profileFormLayout->getWidgetPosition(ui->profileSigningKey, &row,
82 ✔
138
                                             &role);
139
    ui->profileFormLayout->insertRow(row + 1, QString(), m_sharedKeyWarning);
82 ✔
140
  }
141
  // Under the pass settings: a store pass would commit outside of.
142
  m_passGitWarning = new QLabel(this);
82 ✔
143
  m_passGitWarning->setObjectName(QStringLiteral("passGitWarning"));
164 ✔
144
  m_passGitWarning->setTextFormat(Qt::PlainText);
82 ✔
145
  m_passGitWarning->setWordWrap(true);
82 ✔
146
  m_passGitWarning->hide();
82 ✔
147
  ui->groupBoxPass->layout()->addWidget(m_passGitWarning);
82 ✔
148
  connect(ui->storePath, &QLineEdit::textChanged, this,
82 ✔
149
          [this] { updatePassGitWarning(); });
174 ✔
150
  setProfiles(QtPassSettings::getProfiles(), QtPassSettings::getProfile());
246 ✔
151

152
  ui->label->setText(ui->label->text() + VERSION);
164 ✔
153
  ui->comboBoxClipboard->clear();
82 ✔
154

155
  ui->comboBoxClipboard->addItem(tr("No clipboard"));
164 ✔
156
  ui->comboBoxClipboard->addItem(tr("Always copy to clipboard"));
164 ✔
157
  ui->comboBoxClipboard->addItem(tr("On-demand copy to clipboard"));
164 ✔
158

159
  int currentIndex = static_cast<int>(s.clipBoardType);
82 ✔
160
  ui->comboBoxClipboard->setCurrentIndex(currentIndex);
82 ✔
161
  on_comboBoxClipboard_activated(currentIndex);
82 ✔
162

163
  QClipboard *clip = QApplication::clipboard();
82 ✔
164
  if (!clip->supportsSelection()) {
82 ✔
165
    useSelection(false);
82 ✔
166
    ui->checkBoxSelection->setVisible(false);
82 ✔
167
  } else {
UNCOV
168
    useSelection(s.useSelection);
×
169
  }
170

171
  connect(ui->pageList, &QListWidget::currentRowChanged, ui->pages,
82 ✔
172
          &QStackedWidget::setCurrentIndex);
164 ✔
173
  ui->pageList->setCurrentRow(
159 ✔
174
      Util::configIsValid(s)
82 ✔
175
          ? 0
176
          // Programs is what needs fixing when the configuration is not valid.
177
          : ui->pages->indexOf(ui->pagePrograms));
77 ✔
178

179
  connect(this, &ConfigDialog::accepted, this, &ConfigDialog::on_accepted);
82 ✔
180
}
82 ✔
181

182
void ConfigDialog::applySettings(const AppSettings &settings) {
82 ✔
183
  ui->passPath->setText(settings.passExecutable);
82 ✔
184
  setGitPath(settings.gitExecutable);
82 ✔
185
  ui->gpgPath->setText(settings.gpgExecutable);
82 ✔
186
  ui->storePath->setText(settings.passStore);
82 ✔
187
  ui->sshAuthSockOverride->setText(settings.sshAuthSockOverride);
82 ✔
188

189
  // One control each: 0 is "Never", so off and a delay are one setting.
190
  ui->spinBoxAutoclearSeconds->setValue(
82 ✔
191
      settings.useAutoclear ? settings.autoclearSeconds : 0);
82 ✔
192
  ui->labelSeconds->setVisible(ui->spinBoxAutoclearSeconds->value() > 0);
82 ✔
193
  ui->checkBoxRestoreClipboard->setChecked(settings.restoreClipboard);
82 ✔
194
  ui->checkBoxRestoreClipboard->setVisible(
82 ✔
195
      ui->spinBoxAutoclearSeconds->value() > 0);
82 ✔
196
  ui->spinBoxAutoclearPanelSeconds->setValue(
82 ✔
197
      settings.useAutoclearPanel ? settings.autoclearPanelSeconds : 0);
82 ✔
198
  ui->labelPanelSeconds->setVisible(ui->spinBoxAutoclearPanelSeconds->value() >
82 ✔
199
                                    0);
200
  ui->checkBoxHidePassword->setChecked(settings.hidePassword);
82 ✔
201
  ui->checkBoxHideSecretFields->setChecked(settings.hideSecretFields);
82 ✔
202
  ui->checkBoxHideAllFields->setChecked(settings.hideAllFields);
82 ✔
203
  ui->lineEditSecretFields->setText(
82 ✔
204
      settings.secretFieldNames.join(QStringLiteral(", ")));
164 ✔
205
  updateSecretFieldsEnabled();
82 ✔
206
  ui->checkBoxHideContent->setChecked(settings.hideContent);
82 ✔
207
  ui->checkBoxUseMonospace->setChecked(settings.useMonospace);
82 ✔
208
  ui->checkBoxDisplayAsIs->setChecked(settings.displayAsIs);
82 ✔
209
  ui->checkBoxNoLineWrapping->setChecked(settings.noLineWrapping);
82 ✔
210
  ui->checkBoxAddGPGId->setChecked(settings.addGPGId);
82 ✔
211
  ui->checkBoxHideOnClose->setChecked(settings.hideOnClose);
82 ✔
212
  ui->checkBoxStartMinimized->setChecked(settings.startMinimized);
82 ✔
213

214
  ui->checkBoxAvoidCapitals->setChecked(settings.avoidCapitals);
82 ✔
215
  ui->checkBoxAvoidNumbers->setChecked(settings.avoidNumbers);
82 ✔
216
  ui->checkBoxLessRandom->setChecked(settings.lessRandom);
82 ✔
217
  ui->checkBoxUseSymbols->setChecked(settings.useSymbols);
82 ✔
218
  ui->plainTextEditTemplate->setPlainText(settings.passTemplate);
82 ✔
219
  // All fields only applies while templating is on (#1766), so the two
220
  // switches are one choice of three.
221
  ui->comboBoxFields->setCurrentIndex(
82 ✔
222
      !settings.useTemplate ? 0 : (settings.templateAllFields ? 2 : 1));
82 ✔
223
  ui->plainTextEditTemplate->setEnabled(settings.useTemplate);
82 ✔
224
  ui->checkBoxAutoPull->setChecked(settings.autoPull);
82 ✔
225
  ui->checkBoxAutoPush->setChecked(settings.autoPush);
82 ✔
226
  ui->checkBoxGitUseParentRepository->setChecked(
82 ✔
227
      settings.gitUseParentRepository);
82 ✔
228
  ui->checkBoxAlwaysOnTop->setChecked(settings.alwaysOnTop);
82 ✔
229

230
  // Dependent helpers: set after the plain values above so the enable/disable
231
  // logic they trigger sees the final widget states.
232
  usePass(settings.usePass);
82 ✔
233
  useTrayIcon(settings.useTrayIcon);
82 ✔
234
  useGit(settings.useGit);
82 ✔
235
  useOtp(settings.useOtp);
82 ✔
236
  useGrepSearch(settings.useGrepSearch);
82 ✔
237
  useQrencode(settings.useQrencode);
82 ✔
238
  // Before usePwgen (gated on the pwgen path); otherwise readSettings() writes
239
  // the .ui defaults over the saved configuration on every OK.
240
  setPwgenPath(settings.pwgenExecutable);
82 ✔
241
  setPasswordConfiguration(settings.passwordConfiguration);
82 ✔
242
  usePwgen(settings.usePwgen);
82 ✔
243
}
82 ✔
244

245
auto ConfigDialog::readSettings() -> AppSettings {
27 ✔
246
  // Start from the persisted settings so keys this dialog does not own
247
  // (window geometry, profiles, etc.) survive the save.
248
  AppSettings settings = QtPassSettings::load();
27 ✔
249

250
  settings.passExecutable = ui->passPath->text();
54 ✔
251
  settings.gitExecutable = ui->gitPath->text();
54 ✔
252
  settings.gpgExecutable = ui->gpgPath->text();
54 ✔
253
  settings.sshAuthSockOverride = ui->sshAuthSockOverride->text().trimmed();
54 ✔
254
  settings.passStore = Util::normalizeFolderPath(ui->storePath->text());
54 ✔
255
  settings.usePass = ui->radioButtonPass->isChecked();
27 ✔
256
  settings.clipBoardType =
27 ✔
257
      static_cast<Enums::ClipBoardType>(ui->comboBoxClipboard->currentIndex());
27 ✔
258
  settings.useSelection = ui->checkBoxSelection->isChecked();
27 ✔
259
  settings.autoclearSeconds = ui->spinBoxAutoclearSeconds->value();
27 ✔
260
  settings.useAutoclear = settings.autoclearSeconds > 0;
27 ✔
261
  settings.restoreClipboard = ui->checkBoxRestoreClipboard->isChecked();
27 ✔
262
  settings.autoclearPanelSeconds = ui->spinBoxAutoclearPanelSeconds->value();
27 ✔
263
  settings.useAutoclearPanel = settings.autoclearPanelSeconds > 0;
27 ✔
264
  settings.hidePassword = ui->checkBoxHidePassword->isChecked();
27 ✔
265
  settings.hideSecretFields = ui->checkBoxHideSecretFields->isChecked();
27 ✔
266
  settings.hideAllFields = ui->checkBoxHideAllFields->isChecked();
27 ✔
267
  // As written, an empty list included ("Default" puts the set back).
268
  settings.secretFieldNames.clear();
27 ✔
269
  for (const QString &name :
270
       ui->lineEditSecretFields->text().split(QLatin1Char(','))) {
265 ✔
271
    if (!name.trimmed().isEmpty()) {
211 ✔
272
      settings.secretFieldNames << name.trimmed();
198 ✔
273
    }
274
  }
275
  settings.hideContent = ui->checkBoxHideContent->isChecked();
27 ✔
276
  settings.useMonospace = ui->checkBoxUseMonospace->isChecked();
27 ✔
277
  settings.displayAsIs = ui->checkBoxDisplayAsIs->isChecked();
27 ✔
278
  settings.noLineWrapping = ui->checkBoxNoLineWrapping->isChecked();
27 ✔
279
  settings.addGPGId = ui->checkBoxAddGPGId->isChecked();
27 ✔
280
  // A disabled control (e.g. no system tray) keeps the persisted value
281
  // instead of clobbering it to false.
282
  if (ui->checkBoxUseTrayIcon->isEnabled()) {
27 ✔
283
    settings.useTrayIcon = ui->checkBoxUseTrayIcon->isChecked();
1 ✔
284
    // Switched off here, hide-on-close and start-minimized go off with it.
285
    // Their boxes are disabled now and skipped below, so a stored "on"
286
    // would come back the next time anything turns the tray on (the
287
    // first-run wizard sets useTrayIcon only), and closing would hide.
288
    if (!settings.useTrayIcon) {
1 ✔
289
      settings.hideOnClose = false;
1 ✔
290
      settings.startMinimized = false;
1 ✔
291
    }
292
  }
293
  if (ui->checkBoxHideOnClose->isEnabled()) {
27 ✔
UNCOV
294
    settings.hideOnClose = ui->checkBoxHideOnClose->isChecked();
×
295
  }
296
  if (ui->checkBoxStartMinimized->isEnabled()) {
27 ✔
UNCOV
297
    settings.startMinimized = ui->checkBoxStartMinimized->isChecked();
×
298
  }
299
  settings.useGit = ui->checkBoxUseGit->isChecked();
27 ✔
300
  // The backends and the auto-pull-on-start read the global keys; #1140
301
  // started storing these per profile as well and stopped writing the
302
  // globals, which left both checkboxes without effect.
303
  settings.autoPush = ui->checkBoxAutoPush->isChecked();
27 ✔
304
  settings.autoPull = ui->checkBoxAutoPull->isChecked();
27 ✔
305
  settings.gitUseParentRepository =
27 ✔
306
      ui->checkBoxGitUseParentRepository->isChecked();
27 ✔
307
  settings.useOtp = ui->checkBoxUseOtp->isChecked();
27 ✔
308
  settings.useGrepSearch = ui->checkBoxUseGrepSearch->isChecked();
27 ✔
309
  settings.useQrencode = ui->checkBoxUseQrencode->isChecked();
27 ✔
310
  settings.pwgenExecutable = ui->pwgenPath->text();
54 ✔
311
  settings.usePwgen = ui->checkBoxUsePwgen->isChecked();
27 ✔
312
  settings.avoidCapitals = ui->checkBoxAvoidCapitals->isChecked();
27 ✔
313
  settings.avoidNumbers = ui->checkBoxAvoidNumbers->isChecked();
27 ✔
314
  settings.lessRandom = ui->checkBoxLessRandom->isChecked();
27 ✔
315
  settings.useSymbols = ui->checkBoxUseSymbols->isChecked();
27 ✔
316
  settings.passwordConfiguration = getPasswordConfiguration();
54 ✔
317
  settings.useTemplate = ui->comboBoxFields->currentIndex() > 0;
27 ✔
318
  settings.passTemplate = ui->plainTextEditTemplate->toPlainText();
54 ✔
319
  settings.templateAllFields = ui->comboBoxFields->currentIndex() == 2;
27 ✔
320
  settings.alwaysOnTop = ui->checkBoxAlwaysOnTop->isChecked();
27 ✔
321
  settings.version = VERSION;
27 ✔
322

323
  return settings;
27 ✔
UNCOV
324
}
×
325

326
ConfigDialog::~ConfigDialog() = default;
252 ✔
327

328
void ConfigDialog::setGitPath(const QString &path) {
82 ✔
329
  ui->gitPath->setText(path);
82 ✔
330
  ui->checkBoxUseGit->setEnabled(!path.isEmpty());
82 ✔
331
  if (path.isEmpty()) {
82 ✔
332
    useGit(false);
51 ✔
333
  }
334
}
82 ✔
335

336
void ConfigDialog::usePass(bool usePass) {
83 ✔
337
  ui->radioButtonNative->setChecked(!usePass);
83 ✔
338
  ui->radioButtonPass->setChecked(usePass);
83 ✔
339
  setGroupBoxState();
83 ✔
340
}
83 ✔
341

342
auto ConfigDialog::isFingerprintList(const QString &setting) -> bool {
178 ✔
343
  // 40 hex characters for OpenPGP v4 keys, 64 for v5/v6 (gpg 2.5+).
344
  static const QRegularExpression fingerprint(
345
      QStringLiteral("^(?:[0-9A-Fa-f]{40}|[0-9A-Fa-f]{64})$"));
180 ✔
346
  const QStringList keys = setting.split(QLatin1Char(' '), Qt::SkipEmptyParts);
178 ✔
347
  return std::all_of(keys.cbegin(), keys.cend(), [](const QString &key) {
178 ✔
348
    return fingerprint.match(key).hasMatch();
44 ✔
349
  });
178 ✔
350
}
351

352
// Profile names must be unique: the settings key profiles by name, so a
353
// duplicate would silently overwrite the other. Unique ignoring case:
354
// QSettings keys are case-insensitive on Windows (the registry, and INI
355
// files there), so "Work" and "work" were one profile, and a settings file
356
// can move between systems. For the same reason a name
357
// holds no slash: QSettings reads "/" as a group separator, and "\" as one on
358
// Windows, so "Work/Client" was stored a group too deep and read back as a
359
// profile "Work" without folder or signing key.
360
auto ConfigDialog::problemsOf(const ProfileEntry &entry,
175 ✔
361
                              const QHash<QString, int> &names) const
362
    -> ProfileProblems {
363
  ProfileProblems problems;
175 ✔
364
  if (entry.name.isEmpty()) {
175 ✔
365
    problems.name = tr("This field is required");
1 ✔
366
  } else if (entry.name.contains(QLatin1Char('/')) ||
174 ✔
367
             entry.name.contains(QLatin1Char('\\'))) {
170 ✔
368
    problems.name = tr("A profile name cannot contain / or \\");
5 ✔
369
  } else if (names.value(entry.name.toCaseFolded()) > 1) {
169 ✔
370
    problems.name = tr("Another profile already has this name");
4 ✔
371
  }
372
  if (entry.profile.path.isEmpty()) {
175 ✔
373
    problems.path = tr("This field is required");
3 ✔
374
  }
375
  // pass compares PASSWORD_STORE_SIGNING_KEY against the fingerprints in
376
  // gpg's VALIDSIG line, so anything shorter than a fingerprint would sign
377
  // and then never verify. Refuse it here instead of failing at first use.
378
  if (!isFingerprintList(entry.profile.signingKey)) {
175 ✔
379
    problems.key = tr("Full key fingerprints only (40 or 64 hexadecimal "
2 ✔
380
                      "characters), separated by spaces");
381
  }
382
  return problems;
175 ✔
UNCOV
383
}
×
384

385
void ConfigDialog::showProblems(int row, const ProfileProblems &problems) {
175 ✔
386
  if (QListWidgetItem *item = ui->profileList->item(row)) {
175 ✔
387
    item->setBackground(problems.none() ? QBrush() : QBrush(Qt::red));
175 ✔
388
    item->setToolTip(problems.none() ? problems.sharedKey : problems.first());
350 ✔
389
  }
390
  if (row != m_currentEntry) {
175 ✔
391
    return;
392
  }
393
  m_sharedKeyWarning->setText(problems.sharedKey);
100 ✔
394
  m_sharedKeyWarning->setVisible(!problems.sharedKey.isEmpty());
100 ✔
395
  const auto tipOr = [](const QString &problem, const QString &tip) {
396
    return problem.isEmpty() ? tip : problem;
300 ✔
397
  };
398
  ui->profileName->setToolTip(tipOr(problems.name, m_nameTip));
300 ✔
399
  ui->profilePath->setToolTip(tipOr(problems.path, m_pathTip));
300 ✔
400
  ui->profileSigningKey->setToolTip(tipOr(problems.key, m_keyTip));
300 ✔
401
}
402

403
auto ConfigDialog::signingStores() const -> SigningStores {
236 ✔
404
  // One folder spelled two ways (through a link, another case on a
405
  // case-insensitive file system) is one store: compared as the file system
406
  // resolves it where it exists. Resolved once per validate(), not once per
407
  // pair of profiles.
408
  SigningStores resolved;
236 ✔
409
  // Keys are looked up in the keyring that signs: the configured GPG home,
410
  // as profiles sign with it, not whatever GNUPGHOME QtPass inherited. The
411
  // dialog does not edit the home, so the settings are read once, not on
412
  // every keystroke; the environment is built each time, as the home may
413
  // only appear meanwhile (a key generated from this dialog).
414
  if (!m_gpgSettings) {
236 ✔
415
    m_gpgSettings = QtPassSettings::load();
82 ✔
416
  }
417
  const QProcessEnvironment env = ProfileInit::gpgEnvironment(*m_gpgSettings);
236 ✔
418
  for (const ProfileEntry &entry : std::as_const(m_entries)) {
411 ✔
419
    const QString real = QFileInfo(entry.profile.path).canonicalFilePath();
175 ✔
420
    resolved.stores << (real.isEmpty() ? QDir::cleanPath(entry.profile.path)
175 ✔
421
                                       : real);
175 ✔
422
    resolved.keys << signerKeys(entry.profile.signingKey, env);
350 ✔
423
  }
424
  return resolved;
236 ✔
425
}
236 ✔
426

427
auto ConfigDialog::signerKeys(const QString &signingKey,
175 ✔
428
                              const QProcessEnvironment &env) const
429
    -> QSet<QString> {
430
  // Verification takes the primary or the signing subkey's fingerprint
431
  // from VALIDSIG, and gpg signs for a primary key with its subkey: a key
432
  // written as the subkey in one profile and as the primary in another is
433
  // one signer (#2087). Only complete IDs are asked about, so typing a key
434
  // does not start gpg for every prefix.
435
  static const QRegularExpression complete(QStringLiteral(
1 ✔
436
      "^(?:0X)?(?:[0-9A-F]{8}|[0-9A-F]{16}|[0-9A-F]{40}|[0-9A-F]{64})$"));
177 ✔
437
  const QString gpg = ui->gpgPath->text();
175 ✔
438
  QSet<QString> keys;
439
  for (const QString &key :
440
       signingKey.toUpper().split(QLatin1Char(' '), Qt::SkipEmptyParts)) {
217 ✔
441
    keys.insert(key);
42 ✔
442
    if (gpg.isEmpty() || !complete.match(key).hasMatch()) {
57 ✔
443
      continue;
27 ✔
444
    }
445
    const QString cacheKey = gpg + QLatin1Char('\n') +
30 ✔
446
                             env.value(QStringLiteral("GNUPGHOME")) +
30 ✔
447
                             QLatin1Char('\n') + key;
30 ✔
448
    auto cached = m_primaryOf.constFind(cacheKey);
15 ✔
449
    if (cached == m_primaryOf.cend()) {
450
      QString out;
9 ✔
451
      // Blocking, once per key: no trustdb check, which a large keyring
452
      // would make slow.
453
      const int rc = Executor::executeBlocking(
99 ✔
454
          env, gpg,
455
          {QStringLiteral("--no-tty"), QStringLiteral("--batch"),
9 ✔
456
           QStringLiteral("--no-auto-check-trustdb"),
9 ✔
457
           QStringLiteral("--with-colons"),
9 ✔
458
           QStringLiteral("--with-fingerprint"),
9 ✔
459
           QStringLiteral("--with-subkey-fingerprint"),
9 ✔
460
           QStringLiteral("--list-keys"), QStringLiteral("--"), key},
9 ✔
461
          &out);
462
      cached = m_primaryOf.insert(
9 ✔
463
          cacheKey, rc == 0 ? primaryFingerprintOf(out, key) : QString());
18 ✔
464
    }
465
    if (!cached->isEmpty()) {
15 ✔
466
      keys.insert(*cached);
5 ✔
467
    }
468
  }
469
  return keys;
175 ✔
470
}
471

472
void ConfigDialog::changeEvent(QEvent *event) {
97 ✔
473
  QDialog::changeEvent(event);
97 ✔
474
  if (event->type() != QEvent::ActivationChange) {
97 ✔
475
    return;
476
  }
477
  // A key is imported somewhere else: a terminal, a key manager, or the
478
  // key generator this dialog opens. Whatever keyring gpg uses, the dialog
479
  // is in the background meanwhile, so a key gpg did not know is asked
480
  // about again on return.
481
  if (!isActiveWindow()) {
15 ✔
482
    const auto forgotten = m_primaryOf.removeIf(
6 ✔
483
        [](const std::pair<const QString &, QString &> &lookup) {
484
          return lookup.second.isEmpty();
485
        });
486
    m_recheckSigners = m_recheckSigners || forgotten > 0;
7 ✔
487
  } else if (m_recheckSigners) {
9 ✔
488
    m_recheckSigners = false;
1 ✔
489
    validate();
1 ✔
490
  }
491
}
492

493
auto ConfigDialog::sharingTheKey(int row, const SigningStores &resolved) const
175 ✔
494
    -> QStringList {
495
  // A list signed for one store verifies in the other when the stores share
496
  // a signing key; the folder line names a folder, not a store (#2050).
497
  QStringList others;
175 ✔
498
  const QSet<QString> &mine = resolved.keys.at(row);
499
  if (mine.isEmpty()) {
500
    return others;
501
  }
502
  for (int other = 0; other < m_entries.size(); ++other) {
136 ✔
503
    if (other == row || resolved.stores.at(other) == resolved.stores.at(row)) {
95 ✔
504
      continue;
55 ✔
505
    }
506
    if (resolved.keys.at(other).intersects(mine)) {
40 ✔
507
      others << m_entries.at(other).name;
16 ✔
508
    }
509
  }
510
  others.sort();
511
  return others;
512
}
513

514
void ConfigDialog::validate() {
236 ✔
515
  QHash<QString, int> names;
236 ✔
516
  for (const ProfileEntry &entry : std::as_const(m_entries)) {
411 ✔
517
    names[entry.name.toCaseFolded()]++;
350 ✔
518
  }
519
  bool status = true;
520
  const SigningStores resolved = signingStores();
236 ✔
521
  for (int row = 0; row < m_entries.size(); ++row) {
411 ✔
522
    ProfileProblems problems = problemsOf(m_entries.at(row), names);
175 ✔
523
    if (const QStringList others = sharingTheKey(row, resolved);
175 ✔
524
        !others.isEmpty()) {
525
      problems.sharedKey =
526
          tr("%1 signs with the same key for another store. A recipient "
13 ✔
527
             "list signed for one of these stores is accepted in the other: "
528
             "use a separate signing key for each store whose recipients "
529
             "differ.")
530
              .arg(others.join(QStringLiteral(", ")));
26 ✔
531
    }
532
    showProblems(row, problems);
175 ✔
533
    status = status && problems.none();
175 ✔
534
  }
175 ✔
535
  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
236 ✔
536
  updatePassGitWarning();
236 ✔
537
}
236 ✔
538

539
void ConfigDialog::updatePassGitWarning() {
343 ✔
540
  // Built after the first applySettings(); setProfiles() fills it then.
541
  if (m_passGitWarning == nullptr) {
343 ✔
542
    return;
82 ✔
543
  }
544
  QStringList warnings;
261 ✔
545
  if (ui->radioButtonPass->isChecked()) {
261 ✔
546
    QStringList stores{ui->storePath->text()};
22 ✔
547
    for (const ProfileEntry &entry : std::as_const(m_entries)) {
13 ✔
548
      stores << entry.profile.path;
2 ✔
549
    }
550
    stores.removeDuplicates();
551
    for (const QString &store : std::as_const(stores)) {
24 ✔
552
      const QString repository = Util::repositoryPassClimbsTo(store);
13 ✔
553
      if (!repository.isEmpty()) {
13 ✔
554
        warnings << tr("pass commits changes in %1 to the Git repository in "
5 ✔
555
                       "%2: with a colon in the store's path, pass cannot "
556
                       "keep Git to the store. Run \"git init\" in the store, "
557
                       "or use native Git/GPG.")
558
                        .arg(QDir::toNativeSeparators(store),
15 ✔
559
                             QDir::toNativeSeparators(repository));
10 ✔
560
      }
561
    }
562
  }
563
  m_passGitWarning->setText(warnings.join(QStringLiteral("\n\n")));
522 ✔
564
  m_passGitWarning->setVisible(!warnings.isEmpty());
261 ✔
565
}
11 ✔
566

567
void ConfigDialog::warnAboutSshAuthSockOverride() {
27 ✔
568
  const QString override = ui->sshAuthSockOverride->text().trimmed();
54 ✔
569
  if (override.isEmpty()) {
27 ✔
570
    return;
571
  }
572
  QString reason;
3 ✔
573
  switch (SshAuthSock::overrideStatus(override)) {
3 ✔
574
  case SshAuthSock::OverrideStatus::Valid:
575
    return;
576
  case SshAuthSock::OverrideStatus::DoesNotExist:
1 ✔
577
    reason = tr("The path does not exist.");
1 ✔
578
    break;
1 ✔
579
  case SshAuthSock::OverrideStatus::NotReadable:
1 ✔
580
    reason = tr("The path is not readable.");
1 ✔
581
    break;
1 ✔
582
  case SshAuthSock::OverrideStatus::NotUnixDomainSocket:
1 ✔
583
    reason = tr("The path is not a Unix domain socket.");
1 ✔
584
    break;
1 ✔
585
  }
586
  PlainMessageBox::warning(
3 ✔
587
      this, tr("Potentially invalid SSH_AUTH_SOCK override"),
3 ✔
588
      tr("The SSH_AUTH_SOCK override value may be invalid.\n\n%1\n\n"
3 ✔
589
         "The value will still be saved as entered.")
590
          .arg(reason));
6 ✔
591
}
592

593
void ConfigDialog::followActiveProfile(const Profiles &profiles) {
27 ✔
594
  // As MainWindow::on_profileBox_currentTextChanged does when switching.
595
  AppSettings s = QtPassSettings::load();
27 ✔
596
  const QString wasActive = s.activeProfile;
597
  QString nowActive;
27 ✔
598
  for (const ProfileEntry &entry : std::as_const(m_entries)) {
36 ✔
599
    if (!wasActive.isEmpty() && entry.originalName == wasActive) {
9 ✔
600
      nowActive = entry.name;
1 ✔
601
    }
602
  }
603
  s.activeProfile = nowActive;
27 ✔
604
  const auto active = profiles.constFind(nowActive);
605
  if (active != profiles.constEnd()) {
27 ✔
606
    s.useGit = active->useGit.value_or(s.useGit);
1 ✔
607
    s.autoPush = active->autoPush.value_or(s.autoPush);
1 ✔
608
    s.autoPull = active->autoPull.value_or(s.autoPull);
1 ✔
609
  }
610
  QtPassSettings::save(s);
27 ✔
611
}
27 ✔
612

613
void ConfigDialog::on_accepted() {
27 ✔
614
  warnAboutSshAuthSockOverride();
27 ✔
615
  const Profiles existingProfiles = QtPassSettings::getProfiles();
27 ✔
616
  // Persist via the facade, which also invalidates the cached Pass backend so
617
  // a changed "use pass" mode takes effect.
618
  QtPassSettings::save(readSettings());
27 ✔
619
  // Profiles are not part of AppSettings yet, so persist them separately.
620
  const Profiles profiles = getProfiles();
27 ✔
621
  QtPassSettings::setProfiles(profiles);
27 ✔
622
  followActiveProfile(profiles);
27 ✔
623
  initializeNewProfiles(existingProfiles);
27 ✔
624
}
27 ✔
625

626
void ConfigDialog::on_autodetectButton_clicked() {
1 ✔
627
  QString pass = Util::findBinaryInPath("pass");
2 ✔
628
  if (!pass.isEmpty()) {
1 ✔
629
    ui->passPath->setText(pass);
1 ✔
630
  }
631
  usePass(!pass.isEmpty());
1 ✔
632
  QString gpg = Util::findBinaryInPath("gpg2");
2 ✔
633
  if (gpg.isEmpty()) {
1 ✔
634
    gpg = Util::findBinaryInPath("gpg");
2 ✔
635
  }
636
  if (!gpg.isEmpty()) {
1 ✔
637
    ui->gpgPath->setText(gpg);
1 ✔
638
  }
639
  QString git = Util::findBinaryInPath("git");
2 ✔
640
  if (!git.isEmpty()) {
1 ✔
641
    ui->gitPath->setText(git);
1 ✔
642
  }
643
  QString pwgen = Util::findBinaryInPath("pwgen");
2 ✔
644
  if (!pwgen.isEmpty()) {
1 ✔
645
    ui->pwgenPath->setText(pwgen);
1 ✔
646
  }
647
}
1 ✔
648

649
void ConfigDialog::on_radioButtonNative_clicked() { setGroupBoxState(); }
9 ✔
650

651
void ConfigDialog::on_radioButtonPass_clicked() { setGroupBoxState(); }
5 ✔
652

653
void ConfigDialog::setGroupBoxState() {
97 ✔
654
  bool state = ui->radioButtonPass->isChecked();
97 ✔
655
  ui->groupBoxNative->setEnabled(!state);
97 ✔
656
  ui->groupBoxPass->setEnabled(state);
97 ✔
657
  updatePassGitWarning();
97 ✔
658
  on_checkBoxUseGit_clicked();
97 ✔
659
  if (state) {
97 ✔
660
    ui->spinBoxPasswordLength->setEnabled(false);
8 ✔
661
    ui->checkBoxUsePwgen->setEnabled(false);
8 ✔
662
    ui->checkBoxAvoidCapitals->setEnabled(false);
8 ✔
663
    ui->checkBoxUseSymbols->setEnabled(false);
8 ✔
664
    ui->checkBoxLessRandom->setEnabled(false);
8 ✔
665
    ui->checkBoxAvoidNumbers->setEnabled(false);
8 ✔
666
    ui->labelPasswordChars->setEnabled(false);
8 ✔
667
    ui->passwordCharTemplateSelector->setEnabled(false);
8 ✔
668
    ui->lineEditPasswordChars->setEnabled(false);
8 ✔
669
  } else {
670
    // native mode: restore pwgen/charset state from existing handlers
671
    ui->spinBoxPasswordLength->setEnabled(true);
89 ✔
672
    ui->checkBoxUsePwgen->setEnabled(!ui->pwgenPath->text().isEmpty());
89 ✔
673
    on_checkBoxUsePwgen_clicked();
89 ✔
674
  }
675
}
97 ✔
676

677
auto ConfigDialog::selectExecutable() -> QString {
8 ✔
678
  QFileDialog dialog(this);
16 ✔
679
  dialog.setFileMode(QFileDialog::ExistingFile);
8 ✔
680
  dialog.setOption(QFileDialog::ReadOnly);
8 ✔
681
  if (dialog.exec()) {
8 ✔
682
    return dialog.selectedFiles().constFirst();
8 ✔
683
  }
684

685
  return {};
4 ✔
686
}
8 ✔
687

688
auto ConfigDialog::selectFolder() -> QString {
3 ✔
689
  QFileDialog dialog(this);
6 ✔
690
  dialog.setFileMode(QFileDialog::Directory);
3 ✔
691
  dialog.setFilter(QDir::NoFilter);
3 ✔
692
  dialog.setOption(QFileDialog::ShowDirsOnly);
3 ✔
693
  if (dialog.exec()) {
3 ✔
694
    return dialog.selectedFiles().constFirst();
4 ✔
695
  }
696

697
  return {};
1 ✔
698
}
3 ✔
699

700
void ConfigDialog::on_toolButtonGit_clicked() {
2 ✔
701
  QString git = selectExecutable();
2 ✔
702
  bool state = !git.isEmpty();
2 ✔
703
  if (state) {
2 ✔
704
    ui->gitPath->setText(git);
1 ✔
705
  } else {
706
    useGit(false);
1 ✔
707
  }
708

709
  ui->checkBoxUseGit->setEnabled(state);
2 ✔
710
}
2 ✔
711

712
void ConfigDialog::on_toolButtonGpg_clicked() {
2 ✔
713
  QString gpg = selectExecutable();
2 ✔
714
  if (!gpg.isEmpty()) {
2 ✔
715
    ui->gpgPath->setText(gpg);
1 ✔
716
  }
717
}
2 ✔
718

719
void ConfigDialog::on_pushButtonGenerateKey_clicked() {
1 ✔
720
  KeygenDialog d(ui->gpgPath->text(), QtPassSettings::getPass(), this);
1 ✔
721
  d.exec();
1 ✔
722
}
1 ✔
723

724
void ConfigDialog::on_toolButtonPass_clicked() {
2 ✔
725
  QString pass = selectExecutable();
2 ✔
726
  if (!pass.isEmpty()) {
2 ✔
727
    ui->passPath->setText(pass);
1 ✔
728
  }
729
}
2 ✔
730

731
void ConfigDialog::on_toolButtonStore_clicked() {
2 ✔
732
  QString store = selectFolder();
2 ✔
733
  if (!store.isEmpty()) {
2 ✔
734
    ui->storePath->setText(store);
1 ✔
735
  }
736
}
2 ✔
737

738
// index 0 is "No clipboard".
739
void ConfigDialog::on_comboBoxClipboard_activated(int index) {
166 ✔
740
  bool state = index > 0;
166 ✔
741

742
  ui->checkBoxSelection->setEnabled(state);
166 ✔
743
  ui->checkBoxHidePassword->setEnabled(state);
166 ✔
744
  updateSecretFieldsEnabled();
166 ✔
745
  ui->checkBoxHideContent->setEnabled(state);
166 ✔
746
  ui->labelAutoclear->setEnabled(state);
166 ✔
747
  ui->spinBoxAutoclearSeconds->setEnabled(state);
166 ✔
748
  ui->labelSeconds->setEnabled(state);
166 ✔
749
  ui->checkBoxRestoreClipboard->setEnabled(state);
166 ✔
750
}
166 ✔
751

752
void ConfigDialog::updateSecretFieldsEnabled() {
363 ✔
753
  // Each control only while the one it depends on is on: other secrets and
754
  // every field only while passwords are hidden; the secret words only while
755
  // other secrets are, and not when every field is hidden anyway.
756
  const bool hiding = ui->checkBoxHidePassword->isEnabled() &&
615 ✔
757
                      ui->checkBoxHidePassword->isChecked();
252 ✔
758
  ui->checkBoxHideAllFields->setEnabled(hiding);
363 ✔
759
  const bool all = hiding && ui->checkBoxHideAllFields->isChecked();
363 ✔
760
  ui->checkBoxHideSecretFields->setEnabled(hiding && !all);
363 ✔
761
  const bool words =
762
      hiding && !all && ui->checkBoxHideSecretFields->isChecked();
363 ✔
763
  ui->lineEditSecretFields->setEnabled(words);
363 ✔
764
  ui->buttonDefaultSecretFields->setEnabled(words);
363 ✔
765
}
363 ✔
766

767
void ConfigDialog::useSelection(bool useSelection) {
84 ✔
768
  ui->checkBoxSelection->setChecked(useSelection);
84 ✔
769
  on_checkBoxSelection_clicked();
84 ✔
770
}
84 ✔
771

772
void ConfigDialog::on_checkBoxSelection_clicked() {
84 ✔
773
  on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
84 ✔
774
}
84 ✔
775

776
void ConfigDialog::setProfiles(Profiles profiles,
82 ✔
777
                               const QString &currentProfile) {
778
  // remove weird "" key value pairs
779
  profiles.remove(QString());
82 ✔
780

781
  m_entries.clear();
82 ✔
782
  ui->profileList->clear();
82 ✔
783
  int currentRow = -1;
784
  for (auto i = profiles.cbegin(); i != profiles.cend(); ++i) {
115 ✔
785
    if (i.key() == currentProfile) {
33 ✔
786
      currentRow = m_entries.size();
14 ✔
787
    }
788
    m_entries.append({i.key(), i.value(), i.key()});
33 ✔
789
    ui->profileList->addItem(i.key());
33 ✔
790
  }
791
  ui->profileList->setCurrentRow(currentRow);
82 ✔
792
  if (currentRow < 0) {
82 ✔
793
    loadProfileForm(-1);
68 ✔
794
  }
795
  validate();
82 ✔
796
}
115 ✔
797

798
auto ConfigDialog::currentEntry() -> ProfileEntry * {
279 ✔
799
  if (m_currentEntry < 0 || m_currentEntry >= m_entries.size()) {
279 ✔
800
    return nullptr;
801
  }
802
  return &m_entries[m_currentEntry];
143 ✔
803
}
804

805
// The Git boxes show the profile's own flags, else the global ones; only a
806
// click on a box makes the value the profile's own.
807
void ConfigDialog::loadProfileForm(int row) {
101 ✔
808
  m_currentEntry = (row >= 0 && row < m_entries.size()) ? row : -1;
101 ✔
809
  const ProfileEntry *entry = currentEntry();
101 ✔
810
  m_loadingForm = true;
101 ✔
811
  ui->profileForm->setEnabled(entry != nullptr);
101 ✔
812
  ui->deleteButton->setEnabled(entry != nullptr);
101 ✔
813
  ui->profileName->setText(entry ? entry->name : QString());
235 ✔
814
  ui->profilePath->setText(entry ? entry->profile.path : QString());
235 ✔
815
  ui->profileSigningKey->setText(entry ? entry->profile.signingKey : QString());
134 ✔
816
  const bool useGit =
817
      entry && entry->profile.useGit.value_or(ui->checkBoxUseGit->isChecked());
134 ✔
818
  ui->profileUseGit->setChecked(useGit);
101 ✔
819
  ui->profileAutoPush->setChecked(
101 ✔
820
      entry &&
134 ✔
821
      entry->profile.autoPush.value_or(ui->checkBoxAutoPush->isChecked()));
33 ✔
822
  ui->profileAutoPull->setChecked(
101 ✔
823
      entry &&
134 ✔
824
      entry->profile.autoPull.value_or(ui->checkBoxAutoPull->isChecked()));
33 ✔
825
  ui->profileAutoPush->setEnabled(useGit);
101 ✔
826
  ui->profileAutoPull->setEnabled(useGit);
101 ✔
827
  m_loadingForm = false;
101 ✔
828
  updateProfileStatus();
101 ✔
829
  validate();
101 ✔
830
}
101 ✔
831

832
auto ConfigDialog::getProfiles() -> Profiles {
64 ✔
833
  Profiles profiles;
64 ✔
834
  for (const ProfileEntry &entry : std::as_const(m_entries)) {
94 ✔
835
    profiles.insert(entry.name, entry.profile);
30 ✔
836
  }
837
  return profiles;
64 ✔
838
}
839

840
auto ConfigDialog::ensureProfileFolder(const QString &path) -> bool {
6 ✔
841
  if (QDir(path).exists()) {
6 ✔
842
    return true;
843
  }
844
  if (QMessageBox::question(
4 ✔
845
          this, tr("Create profile directory?"),
2 ✔
846
          tr("Would you like to create a password store at %1?").arg(path),
4 ✔
847
          QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
848
    return false;
849
  }
850
  if (!Util::mkpathForStore(path)) {
1 ✔
851
    PlainMessageBox::warning(
1 ✔
852
        this, tr("Error"),
1 ✔
853
        tr("Could not create profile directory: %1").arg(path));
2 ✔
854
    return false;
1 ✔
855
  }
856
  return true;
857
}
858

859
void ConfigDialog::initialiseProfileStore(const QString &name,
3 ✔
860
                                          const Profile &profile,
861
                                          const QString &path) {
862
  // Only the recipients come through the active backend. passStore is the
863
  // profile, or getGpgIdPath() would pre-tick the active store's recipients;
864
  // signing keys are per profile, exactly as the profile switch applies them
865
  // (MainWindow::on_profileBox_currentTextChanged).
866
  const AppSettings settings = QtPassSettings::load();
3 ✔
867
  AppSettings profileSettings = settings;
3 ✔
868
  profileSettings.passStore = Util::normalizeFolderPath(path);
3 ✔
869
  profileSettings.passSigningKey = profile.signingKey;
3 ✔
870
  // needsInit() found no .gpg-id: nothing to preselect, and none that
871
  // appears meanwhile is taken (it would be read under the active
872
  // profile's signing policy).
873
  UsersDialog usersDialog(QtPassSettings::getPass(), profileSettings,
874
                          profileSettings.passStore,
875
                          UsersDialog::Preselect::Nothing, this);
6 ✔
876
  usersDialog.setInitOnAccept(false);
877
  usersDialog.setWindowTitle(tr("Select recipients for %1").arg(name));
6 ✔
878
  if (usersDialog.exec() != QDialog::Accepted) {
3 ✔
879
    return;
880
  }
881
  QString note;
2 ✔
882
  const bool ok = ProfileInit::initialise(
2 ✔
883
      path, usersDialog.selectedUsers(), profileSettings,
2 ✔
884
      profile.useGit.value_or(settings.useGit), &note);
885
  if (!ok) {
2 ✔
886
    PlainMessageBox::warning(
1 ✔
887
        this, tr("Could not initialise profile %1").arg(name), note);
2 ✔
888
  } else if (!note.isEmpty()) {
1 ✔
889
    PlainMessageBox::show(this, QMessageBox::Information,
2 ✔
890
                          tr("Profile %1").arg(name), note);
2 ✔
891
  }
892
}
3 ✔
893

894
void ConfigDialog::initializeNewProfiles(const Profiles &existingProfiles) {
27 ✔
895
  const Profiles newProfiles = getProfiles();
27 ✔
896
  // QMap iterates in name order.
897
  for (auto it = newProfiles.cbegin(); it != newProfiles.cend(); ++it) {
63 ✔
898
    const QString path = QDir::cleanPath(it.value().path);
9 ✔
899
    // A store that was already a profile when the dialog opened, under this
900
    // or another name: a rename is not a new store.
901
    const bool known = std::any_of(
9 ✔
902
        existingProfiles.cbegin(), existingProfiles.cend(),
903
        [&it](const Profile &old) { return old.path == it.value().path; });
4 ✔
904
    // needsInit is false for a missing folder, so it is created first.
905
    if (!known && ensureProfileFolder(path) && ProfileInit::needsInit(path)) {
9 ✔
906
      initialiseProfileStore(it.key(), it.value(), path);
3 ✔
907
    }
908
  }
909
}
27 ✔
910

911
void ConfigDialog::on_addButton_clicked() {
7 ✔
912
  ProfileEntry entry;
7 ✔
913
  entry.name = tr("New profile");
7 ✔
914
  entry.profile.path = ui->storePath->text();
7 ✔
915
  m_entries.append(entry);
7 ✔
916
  ui->profileList->addItem(entry.name);
7 ✔
917
  ui->profileList->setCurrentRow(m_entries.size() - 1);
7 ✔
918
  ui->profileName->setFocus();
7 ✔
919
  ui->profileName->selectAll();
7 ✔
920
  validate();
7 ✔
921
}
7 ✔
922

923
void ConfigDialog::on_profilePathBrowse_clicked() {
1 ✔
924
  const QString dir = selectFolder();
1 ✔
925
  if (!dir.isEmpty()) {
1 ✔
926
    ui->profilePath->setText(dir);
1 ✔
927
    onProfilePathEdited(dir);
1 ✔
928
  }
929
}
1 ✔
930

931
void ConfigDialog::on_deleteButton_clicked() {
4 ✔
932
  const int row = ui->profileList->currentRow();
4 ✔
933
  if (row < 0 || row >= m_entries.size()) {
4 ✔
934
    QMessageBox::warning(this, tr("No profile selected"),
3 ✔
935
                         tr("No profile selected to delete"));
1 ✔
936
    return;
1 ✔
937
  }
938
  m_entries.removeAt(row);
3 ✔
939
  delete ui->profileList->takeItem(row);
3 ✔
940
  // The list moved its current row while the row was being removed, so
941
  // currentRowChanged carried the old numbering: the form named the profile
942
  // after the one now highlighted, and edits (a signing key) went there.
943
  // Load it from the row the list shows now.
944
  loadProfileForm(ui->profileList->currentRow());
3 ✔
945
}
946

UNCOV
947
void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
×
UNCOV
948
  QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
×
UNCOV
949
}
×
950

951
// Looks on Util's PATH (with the macOS and Windows additions) without a
952
// subprocess; a hit is stored for the QR display, a miss leaves the setting.
953
auto ConfigDialog::isQrencodeAvailable(const QString &configuredPath) -> bool {
82 ✔
954
#ifdef Q_OS_WIN
955
  Q_UNUSED(configuredPath);
956
  return false;
957
#else
958
  if (!configuredPath.isEmpty()) {
82 ✔
959
    const QFileInfo configured(configuredPath);
7 ✔
960
    if (configured.isFile() && configured.isExecutable()) {
7 ✔
961
      return true;
962
    }
963
  }
7 ✔
964
  const QString found = Util::findBinaryInPath(QStringLiteral("qrencode"));
162 ✔
965
  if (found.isEmpty()) {
81 ✔
966
    return false;
967
  }
968
  QtPassSettings::setQrencodeExecutable(found);
1 ✔
969
  return true;
970
#endif
971
}
972

973
void ConfigDialog::useTrayIcon(bool useSystray) {
82 ✔
974
  if (QSystemTrayIcon::isSystemTrayAvailable()) {
82 ✔
UNCOV
975
    ui->checkBoxUseTrayIcon->setChecked(useSystray);
×
UNCOV
976
    ui->checkBoxHideOnClose->setEnabled(useSystray);
×
UNCOV
977
    ui->checkBoxStartMinimized->setEnabled(useSystray);
×
978

UNCOV
979
    if (!useSystray) {
×
UNCOV
980
      ui->checkBoxHideOnClose->setChecked(false);
×
UNCOV
981
      ui->checkBoxStartMinimized->setChecked(false);
×
982
    }
983
  }
984
}
82 ✔
985

986
void ConfigDialog::on_checkBoxUseTrayIcon_clicked() {
3 ✔
987
  bool state = ui->checkBoxUseTrayIcon->isChecked();
3 ✔
988
  ui->checkBoxHideOnClose->setEnabled(state);
3 ✔
989
  ui->checkBoxStartMinimized->setEnabled(state);
3 ✔
990
}
3 ✔
991

992
void ConfigDialog::useGit(bool useGit) {
136 ✔
993
  ui->checkBoxUseGit->setChecked(useGit);
136 ✔
994
  on_checkBoxUseGit_clicked();
136 ✔
995
}
136 ✔
996

997
void ConfigDialog::useOtp(bool useOtp) {
84 ✔
998
  ui->checkBoxUseOtp->setChecked(useOtp);
84 ✔
999
}
84 ✔
1000

1001
void ConfigDialog::useGrepSearch(bool useGrepSearch) {
84 ✔
1002
  ui->checkBoxUseGrepSearch->setChecked(useGrepSearch);
84 ✔
1003
}
84 ✔
1004

1005
void ConfigDialog::useQrencode(bool useQrencode) {
84 ✔
1006
  ui->checkBoxUseQrencode->setChecked(useQrencode);
84 ✔
1007
}
84 ✔
1008

1009
void ConfigDialog::on_checkBoxUseGit_clicked() {
233 ✔
1010
  ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
233 ✔
1011
  ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
233 ✔
1012
  ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
233 ✔
1013
  // pass always stops git at the store's parent itself, so the choice only
1014
  // means something in native mode.
1015
  ui->checkBoxGitUseParentRepository->setEnabled(
233 ✔
1016
      ui->checkBoxUseGit->isChecked() && !ui->radioButtonPass->isChecked());
233 ✔
1017
}
233 ✔
1018

1019
void ConfigDialog::on_toolButtonPwgen_clicked() {
2 ✔
1020
  QString pwgen = selectExecutable();
2 ✔
1021
  if (!pwgen.isEmpty()) {
2 ✔
1022
    ui->pwgenPath->setText(pwgen);
1 ✔
1023
    ui->checkBoxUsePwgen->setEnabled(true);
1 ✔
1024
  } else {
1025
    ui->checkBoxUsePwgen->setEnabled(false);
1 ✔
1026
    ui->checkBoxUsePwgen->setChecked(false);
1 ✔
1027
  }
1028
}
2 ✔
1029

1030
void ConfigDialog::setPwgenPath(const QString &pwgen) {
84 ✔
1031
  ui->pwgenPath->setText(pwgen);
84 ✔
1032
  if (pwgen.isEmpty()) {
84 ✔
1033
    ui->checkBoxUsePwgen->setChecked(false);
57 ✔
1034
    ui->checkBoxUsePwgen->setEnabled(false);
57 ✔
1035
  }
1036
  on_checkBoxUsePwgen_clicked();
84 ✔
1037
}
84 ✔
1038

1039
void ConfigDialog::on_checkBoxUsePwgen_clicked() {
258 ✔
1040
  if (ui->radioButtonPass->isChecked())
258 ✔
1041
    return;
1042
  bool usePwgen = ui->checkBoxUsePwgen->isChecked();
254 ✔
1043
  ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
254 ✔
1044
  ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
254 ✔
1045
  ui->checkBoxLessRandom->setEnabled(usePwgen);
254 ✔
1046
  ui->checkBoxUseSymbols->setEnabled(usePwgen);
254 ✔
1047
  ui->lineEditPasswordChars->setEnabled(!usePwgen);
254 ✔
1048
  ui->labelPasswordChars->setEnabled(!usePwgen);
254 ✔
1049
  ui->passwordCharTemplateSelector->setEnabled(!usePwgen);
254 ✔
1050
}
1051

1052
void ConfigDialog::usePwgen(bool usePwgen) {
85 ✔
1053
  if (ui->pwgenPath->text().isEmpty()) {
170 ✔
1054
    usePwgen = false;
1055
  }
1056
  ui->checkBoxUsePwgen->setChecked(usePwgen);
85 ✔
1057
  on_checkBoxUsePwgen_clicked();
85 ✔
1058
}
85 ✔
1059

1060
void ConfigDialog::setPasswordConfiguration(
86 ✔
1061
    const PasswordConfiguration &config) {
1062
  // Retain the custom charset so it survives even when a builtin set is the
1063
  // active selection (the line edit then shows the builtin's characters).
1064
  m_customPasswordChars = config.Characters[PasswordConfiguration::CUSTOM];
86 ✔
1065
  ui->spinBoxPasswordLength->setValue(config.length);
86 ✔
1066
  ui->passwordCharTemplateSelector->setCurrentIndex(config.selected);
86 ✔
1067
  if (config.selected != PasswordConfiguration::CUSTOM) {
86 ✔
1068
    ui->lineEditPasswordChars->setEnabled(false);
84 ✔
1069
  }
1070
  ui->lineEditPasswordChars->setText(config.Characters[config.selected]);
86 ✔
1071
}
86 ✔
1072

1073
auto ConfigDialog::getPasswordConfiguration() -> PasswordConfiguration {
31 ✔
1074
  PasswordConfiguration config;
31 ✔
1075
  config.length = ui->spinBoxPasswordLength->value();
31 ✔
1076
  config.selected = static_cast<PasswordConfiguration::CharacterSet>(
31 ✔
1077
      ui->passwordCharTemplateSelector->currentIndex());
31 ✔
1078
  // For a builtin selection the line edit shows the builtin's characters;
1079
  // reading it would overwrite the saved custom charset.
1080
  if (config.selected == PasswordConfiguration::CUSTOM) {
31 ✔
1081
    config.Characters[PasswordConfiguration::CUSTOM] =
1082
        ui->lineEditPasswordChars->text();
4 ✔
1083
  } else {
1084
    config.Characters[PasswordConfiguration::CUSTOM] = m_customPasswordChars;
29 ✔
1085
  }
1086
  return config;
31 ✔
UNCOV
1087
}
×
1088

1089
void ConfigDialog::on_passwordCharTemplateSelector_activated(int index) {
2 ✔
1090
  ui->lineEditPasswordChars->setText(
4 ✔
1091
      QtPassSettings::getPasswordConfiguration().Characters[index]);
2 ✔
1092
  if (index == PasswordConfiguration::CUSTOM) {
2 ✔
1093
    ui->lineEditPasswordChars->setEnabled(true);
1 ✔
1094
  } else {
1095
    ui->lineEditPasswordChars->setEnabled(false);
1 ✔
1096
  }
1097
}
2 ✔
1098

1099
void ConfigDialog::onProfileSelected(int row) { loadProfileForm(row); }
30 ✔
1100

1101
void ConfigDialog::onProfileNameEdited(const QString &name) {
22 ✔
1102
  ProfileEntry *entry = currentEntry();
22 ✔
1103
  if (m_loadingForm || entry == nullptr) {
22 ✔
1104
    return;
1105
  }
1106
  entry->name = name;
22 ✔
1107
  if (QListWidgetItem *item = ui->profileList->item(m_currentEntry)) {
22 ✔
1108
    item->setText(name);
22 ✔
1109
  }
1110
  validate();
22 ✔
1111
  updateProfileStatus();
22 ✔
1112
}
1113

1114
void ConfigDialog::onProfilePathEdited(const QString &path) {
9 ✔
1115
  ProfileEntry *entry = currentEntry();
9 ✔
1116
  if (m_loadingForm || entry == nullptr) {
9 ✔
1117
    return;
1118
  }
1119
  entry->profile.path = path;
9 ✔
1120
  validate();
9 ✔
1121
  updateProfileStatus();
9 ✔
1122
}
1123

1124
void ConfigDialog::onProfileSigningKeyEdited(const QString &key) {
14 ✔
1125
  ProfileEntry *entry = currentEntry();
14 ✔
1126
  if (m_loadingForm || entry == nullptr) {
14 ✔
1127
    return;
1128
  }
1129
  entry->profile.signingKey = key;
14 ✔
1130
  validate();
14 ✔
1131
}
1132

1133
// A Git box was clicked: the profile now has its own flags.
1134
void ConfigDialog::onProfileGitToggled() {
1 ✔
1135
  ProfileEntry *entry = currentEntry();
1 ✔
1136
  if (m_loadingForm || entry == nullptr) {
1 ✔
1137
    return;
1138
  }
1139
  entry->profile.useGit = ui->profileUseGit->isChecked();
1 ✔
1140
  entry->profile.autoPush = ui->profileAutoPush->isChecked();
1 ✔
1141
  entry->profile.autoPull = ui->profileAutoPull->isChecked();
1 ✔
1142
  ui->profileAutoPush->setEnabled(ui->profileUseGit->isChecked());
1 ✔
1143
  ui->profileAutoPull->setEnabled(ui->profileUseGit->isChecked());
1 ✔
1144
}
1145

1146
void ConfigDialog::updateProfileStatus() {
132 ✔
1147
  const ProfileEntry *entry = currentEntry();
132 ✔
1148
  if (entry == nullptr) {
132 ✔
1149
    ui->statusLabel->setText(QString());
68 ✔
1150
    return;
68 ✔
1151
  }
1152

1153
  QString statusMessage;
64 ✔
1154
  if (!entry->name.isEmpty() && !entry->profile.path.isEmpty()) {
64 ✔
1155
    const QString path = QDir::cleanPath(entry->profile.path);
61 ✔
1156
    if (!QDir(path).exists()) {
61 ✔
1157
      statusMessage = tr("New profile: %1 at %2").arg(entry->name, path);
76 ✔
1158
    } else {
1159
      statusMessage = tr("Profile: %1 at %2").arg(entry->name, path);
46 ✔
1160
    }
1161
  } else {
1162
    statusMessage = tr("Fill in all required fields");
3 ✔
1163
  }
1164

1165
  ui->statusLabel->setText(statusMessage);
64 ✔
1166
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc