QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
configdialog.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
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 <QFile>
27#include <QFileDialog>
28#include <QFileInfo>
29#include <QFormLayout>
30#include <QGuiApplication>
31#include <QHash>
32#include <QLabel>
33#include <QListWidgetItem>
34#include <QMessageBox>
35#include <QPushButton>
36#include <QRegularExpression>
37#include <QSet>
38#include <QSystemTrayIcon>
39#include <algorithm>
40#include <utility>
41#ifdef Q_OS_WIN
42#include <windows.h>
43#endif
44
45#include "qtpasslogging.h"
46
48 : QDialog(parent), ui(new Ui::ConfigDialog) {
49 ui->setupUi(this);
50
51 WindowStateStore::attach(*this, QStringLiteral("configDialog"));
52
53 // setSpecialValueText() in retranslateUi() drops the size hint without
54 // telling the layout, which then sizes the box for "0" and shows "ver".
55 ui->spinBoxAutoclearSeconds->updateGeometry();
56 ui->spinBoxAutoclearPanelSeconds->updateGeometry();
57
58 // The secret field names only mean something while passwords are hidden.
59 connect(ui->checkBoxHidePassword, &QCheckBox::toggled, this,
60 [this] { updateSecretFieldsEnabled(); });
61 connect(ui->checkBoxHideSecretFields, &QCheckBox::toggled, this,
62 [this] { updateSecretFieldsEnabled(); });
63 connect(ui->checkBoxHideAllFields, &QCheckBox::toggled, this,
64 [this] { updateSecretFieldsEnabled(); });
65 connect(ui->buttonDefaultSecretFields, &QPushButton::clicked, this, [this] {
66 ui->lineEditSecretFields->setText(
67 AppSettings::defaultSecretFieldNames().join(QStringLiteral(", ")));
68 });
69 // "Seconds" says nothing next to "Never" (the spin box's 0).
70 // Restoring is part of clearing: only there when the clipboard is cleared.
71 connect(ui->spinBoxAutoclearSeconds, &QSpinBox::valueChanged, this,
72 [this](int value) {
73 ui->labelSeconds->setVisible(value > 0);
74 ui->checkBoxRestoreClipboard->setVisible(value > 0);
75 });
76 connect(ui->spinBoxAutoclearPanelSeconds, &QSpinBox::valueChanged, this,
77 [this](int value) { ui->labelPanelSeconds->setVisible(value > 0); });
78 connect(
79 ui->comboBoxFields, &QComboBox::currentIndexChanged, this,
80 [this](int index) { ui->plainTextEditTemplate->setEnabled(index > 0); });
81
84
85 if (!QSystemTrayIcon::isSystemTrayAvailable()) {
86 ui->checkBoxUseTrayIcon->setEnabled(false);
87 ui->checkBoxUseTrayIcon->setToolTip(tr("System tray is not available"));
88 ui->checkBoxHideOnClose->setEnabled(false);
89 ui->checkBoxStartMinimized->setEnabled(false);
90 }
91
92 // Wayland has no client-side "keep above" — Qt::WindowStaysOnTopHint is
93 // silently ignored there (stacking belongs to the compositor). Say so
94 // instead of offering a checkbox that does nothing.
95 if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"))) {
96 ui->checkBoxAlwaysOnTop->setEnabled(false);
97 ui->checkBoxAlwaysOnTop->setToolTip(
98 tr("Not available on Wayland; use your compositor's "
99 "\"keep above\" window rule instead"));
100 }
101
102#if defined(Q_OS_WIN)
103 // checkBoxUseOtp stays visible: OTP is generated in-process, not by the
104 // Unix-only pass-otp extension.
105 ui->checkBoxUseQrencode->hide();
106#endif
107
109 ui->checkBoxUseQrencode->setEnabled(false);
110 ui->checkBoxUseQrencode->setToolTip(tr("qrencode needs to be installed"));
111 }
112
113 connect(ui->profileList, &QListWidget::currentRowChanged, this,
115 connect(ui->profileName, &QLineEdit::textEdited, this,
117 connect(ui->profilePath, &QLineEdit::textEdited, this,
119 connect(ui->profileSigningKey, &QLineEdit::textEdited, this,
121 for (QCheckBox *box :
122 {ui->profileUseGit, ui->profileAutoPush, ui->profileAutoPull}) {
123 connect(box, &QCheckBox::clicked, this, &ConfigDialog::onProfileGitToggled);
124 }
125 m_nameTip = ui->profileName->toolTip();
126 m_pathTip = ui->profilePath->toolTip();
127 m_keyTip = ui->profileSigningKey->toolTip();
128 // A warning, not a problem: shown under the signing key while another
129 // profile, for another store, signs with the same key (#2050).
130 m_sharedKeyWarning = new QLabel(this);
131 m_sharedKeyWarning->setObjectName(QStringLiteral("profileSharedKeyWarning"));
132 m_sharedKeyWarning->setTextFormat(Qt::PlainText);
133 m_sharedKeyWarning->setWordWrap(true);
134 m_sharedKeyWarning->hide();
135 {
136 int row = -1;
137 QFormLayout::ItemRole role = QFormLayout::FieldRole;
138 ui->profileFormLayout->getWidgetPosition(ui->profileSigningKey, &row,
139 &role);
140 ui->profileFormLayout->insertRow(row + 1, QString(), m_sharedKeyWarning);
141 }
142 // Under the pass settings: a store pass would commit outside of.
143 m_passGitWarning = new QLabel(this);
144 m_passGitWarning->setObjectName(QStringLiteral("passGitWarning"));
145 m_passGitWarning->setTextFormat(Qt::PlainText);
146 m_passGitWarning->setWordWrap(true);
147 m_passGitWarning->hide();
148 ui->groupBoxPass->layout()->addWidget(m_passGitWarning);
149 connect(ui->storePath, &QLineEdit::textChanged, this,
150 [this] { updatePassGitWarning(); });
151 connect(ui->pwgenPath, &QLineEdit::textChanged, this,
153 connect(ui->gitPath, &QLineEdit::textChanged, this,
156
157 ui->label->setText(ui->label->text() + VERSION);
158 ui->comboBoxClipboard->clear();
159
160 ui->comboBoxClipboard->addItem(tr("No clipboard"));
161 ui->comboBoxClipboard->addItem(tr("Always copy to clipboard"));
162 ui->comboBoxClipboard->addItem(tr("On-demand copy to clipboard"));
163
164 int currentIndex = static_cast<int>(s.clipBoardType);
165 ui->comboBoxClipboard->setCurrentIndex(currentIndex);
166 on_comboBoxClipboard_activated(currentIndex);
167
168 QClipboard *clip = QApplication::clipboard();
169 if (!clip->supportsSelection()) {
170 useSelection(false);
171 ui->checkBoxSelection->setVisible(false);
172 } else {
174 }
175
176 connect(ui->pageList, &QListWidget::currentRowChanged, ui->pages,
177 &QStackedWidget::setCurrentIndex);
178 ui->pageList->setCurrentRow(
180 ? 0
181 // Programs is what needs fixing when the configuration is not valid.
182 : ui->pages->indexOf(ui->pagePrograms));
183
184 connect(this, &ConfigDialog::accepted, this, &ConfigDialog::on_accepted);
185}
186
188 ui->passPath->setText(settings.passExecutable);
189 setGitPath(settings.gitExecutable);
190 ui->gpgPath->setText(settings.gpgExecutable);
191 ui->storePath->setText(settings.passStore);
192 ui->sshAuthSockOverride->setText(settings.sshAuthSockOverride);
193
194 // One control each: 0 is "Never", so off and a delay are one setting.
195 ui->spinBoxAutoclearSeconds->setValue(
196 settings.useAutoclear ? settings.autoclearSeconds : 0);
197 ui->labelSeconds->setVisible(ui->spinBoxAutoclearSeconds->value() > 0);
198 ui->checkBoxRestoreClipboard->setChecked(settings.restoreClipboard);
199 ui->checkBoxRestoreClipboard->setVisible(
200 ui->spinBoxAutoclearSeconds->value() > 0);
201 ui->spinBoxAutoclearPanelSeconds->setValue(
202 settings.useAutoclearPanel ? settings.autoclearPanelSeconds : 0);
203 ui->labelPanelSeconds->setVisible(ui->spinBoxAutoclearPanelSeconds->value() >
204 0);
205 ui->checkBoxHidePassword->setChecked(settings.hidePassword);
206 ui->checkBoxHideSecretFields->setChecked(settings.hideSecretFields);
207 ui->checkBoxHideAllFields->setChecked(settings.hideAllFields);
208 ui->lineEditSecretFields->setText(
209 settings.secretFieldNames.join(QStringLiteral(", ")));
211 ui->checkBoxHideContent->setChecked(settings.hideContent);
212 ui->checkBoxUseMonospace->setChecked(settings.useMonospace);
213 ui->checkBoxDisplayAsIs->setChecked(settings.displayAsIs);
214 ui->checkBoxNoLineWrapping->setChecked(settings.noLineWrapping);
215 ui->checkBoxAddGPGId->setChecked(settings.addGPGId);
216 ui->checkBoxHideOnClose->setChecked(settings.hideOnClose);
217 ui->checkBoxStartMinimized->setChecked(settings.startMinimized);
218
219 ui->checkBoxAvoidCapitals->setChecked(settings.avoidCapitals);
220 ui->checkBoxAvoidNumbers->setChecked(settings.avoidNumbers);
221 ui->checkBoxLessRandom->setChecked(settings.lessRandom);
222 ui->checkBoxUseSymbols->setChecked(settings.useSymbols);
223 ui->plainTextEditTemplate->setPlainText(settings.passTemplate);
224 // All fields only applies while templating is on (#1766), so the two
225 // switches are one choice of three.
226 ui->comboBoxFields->setCurrentIndex(
227 !settings.useTemplate ? 0 : (settings.templateAllFields ? 2 : 1));
228 ui->plainTextEditTemplate->setEnabled(settings.useTemplate);
229 ui->checkBoxAutoPull->setChecked(settings.autoPull);
230 ui->checkBoxAutoPush->setChecked(settings.autoPush);
231 ui->checkBoxGitUseParentRepository->setChecked(
232 settings.gitUseParentRepository);
233 ui->checkBoxAlwaysOnTop->setChecked(settings.alwaysOnTop);
234
235 // Dependent helpers: set after the plain values above so the enable/disable
236 // logic they trigger sees the final widget states.
237 usePass(settings.usePass);
238 useTrayIcon(settings.useTrayIcon);
239 useGit(settings.useGit);
240 useOtp(settings.useOtp);
242 useQrencode(settings.useQrencode);
243 // Before usePwgen (gated on the pwgen path); otherwise readSettings() writes
244 // the .ui defaults over the saved configuration on every OK.
247 usePwgen(settings.usePwgen);
248}
249
251 // Start from the persisted settings so keys this dialog does not own
252 // (window geometry, profiles, etc.) survive the save.
254
255 settings.passExecutable = ui->passPath->text();
256 settings.gitExecutable = ui->gitPath->text();
257 settings.gpgExecutable = ui->gpgPath->text();
258 settings.sshAuthSockOverride = ui->sshAuthSockOverride->text().trimmed();
259 settings.passStore = Util::normalizeFolderPath(ui->storePath->text());
260 settings.usePass = ui->radioButtonPass->isChecked();
261 settings.clipBoardType =
262 static_cast<Enums::ClipBoardType>(ui->comboBoxClipboard->currentIndex());
263 settings.useSelection = ui->checkBoxSelection->isChecked();
264 settings.autoclearSeconds = ui->spinBoxAutoclearSeconds->value();
265 settings.useAutoclear = settings.autoclearSeconds > 0;
266 settings.restoreClipboard = ui->checkBoxRestoreClipboard->isChecked();
267 settings.autoclearPanelSeconds = ui->spinBoxAutoclearPanelSeconds->value();
268 settings.useAutoclearPanel = settings.autoclearPanelSeconds > 0;
269 settings.hidePassword = ui->checkBoxHidePassword->isChecked();
270 settings.hideSecretFields = ui->checkBoxHideSecretFields->isChecked();
271 settings.hideAllFields = ui->checkBoxHideAllFields->isChecked();
272 // As written, an empty list included ("Default" puts the set back).
273 settings.secretFieldNames.clear();
274 const QStringList names =
275 ui->lineEditSecretFields->text().split(QLatin1Char(','));
276 for (const QString &name : names) {
277 if (!name.trimmed().isEmpty()) {
278 settings.secretFieldNames << name.trimmed();
279 }
280 }
281 settings.hideContent = ui->checkBoxHideContent->isChecked();
282 settings.useMonospace = ui->checkBoxUseMonospace->isChecked();
283 settings.displayAsIs = ui->checkBoxDisplayAsIs->isChecked();
284 settings.noLineWrapping = ui->checkBoxNoLineWrapping->isChecked();
285 settings.addGPGId = ui->checkBoxAddGPGId->isChecked();
286 // A disabled control (e.g. no system tray) keeps the persisted value
287 // instead of clobbering it to false.
288 if (ui->checkBoxUseTrayIcon->isEnabled()) {
289 settings.useTrayIcon = ui->checkBoxUseTrayIcon->isChecked();
290 // Switched off here, hide-on-close and start-minimized go off with it.
291 // Their boxes are disabled now and skipped below, so a stored "on"
292 // would come back the next time anything turns the tray on (the
293 // first-run wizard sets useTrayIcon only), and closing would hide.
294 if (!settings.useTrayIcon) {
295 settings.hideOnClose = false;
296 settings.startMinimized = false;
297 }
298 }
299 if (ui->checkBoxHideOnClose->isEnabled()) {
300 settings.hideOnClose = ui->checkBoxHideOnClose->isChecked();
301 }
302 if (ui->checkBoxStartMinimized->isEnabled()) {
303 settings.startMinimized = ui->checkBoxStartMinimized->isChecked();
304 }
305 settings.useGit = ui->checkBoxUseGit->isChecked();
306 // The backends and the auto-pull-on-start read the global keys; #1140
307 // started storing these per profile as well and stopped writing the
308 // globals, which left both checkboxes without effect.
309 settings.autoPush = ui->checkBoxAutoPush->isChecked();
310 settings.autoPull = ui->checkBoxAutoPull->isChecked();
311 settings.gitUseParentRepository =
312 ui->checkBoxGitUseParentRepository->isChecked();
313 settings.useOtp = ui->checkBoxUseOtp->isChecked();
314 settings.useGrepSearch = ui->checkBoxUseGrepSearch->isChecked();
315 settings.useQrencode = ui->checkBoxUseQrencode->isChecked();
316 settings.pwgenExecutable = ui->pwgenPath->text();
317 settings.usePwgen = ui->checkBoxUsePwgen->isChecked();
318 settings.avoidCapitals = ui->checkBoxAvoidCapitals->isChecked();
319 settings.avoidNumbers = ui->checkBoxAvoidNumbers->isChecked();
320 settings.lessRandom = ui->checkBoxLessRandom->isChecked();
321 settings.useSymbols = ui->checkBoxUseSymbols->isChecked();
323 settings.useTemplate = ui->comboBoxFields->currentIndex() > 0;
324 settings.passTemplate = ui->plainTextEditTemplate->toPlainText();
325 settings.templateAllFields = ui->comboBoxFields->currentIndex() == 2;
326 settings.alwaysOnTop = ui->checkBoxAlwaysOnTop->isChecked();
327 settings.version = VERSION;
328
329 return settings;
330}
331
332ConfigDialog::~ConfigDialog() = default;
333
334void ConfigDialog::setGitPath(const QString &path) {
335 ui->gitPath->setText(path);
336 // setText() is silent when the text did not change.
338}
339
340// Every way to a git path ends here: loading the settings, Autodetect, the
341// file dialog and typing in the field.
343 const bool hasGit = !ui->gitPath->text().isEmpty();
344 if (!hasGit && ui->checkBoxUseGit->isChecked()) {
345 // Replacing the path by hand passes through an empty field. Git going
346 // off for good there would stop the commits without a word.
348 useGit(false);
349 }
350 ui->checkBoxUseGit->setEnabled(hasGit);
351 if (hasGit && m_gitOnBeforeEmptyPath) {
353 useGit(true);
354 }
355}
356
358 ui->radioButtonNative->setChecked(!usePass);
359 ui->radioButtonPass->setChecked(usePass);
361}
362
363auto ConfigDialog::isFingerprintList(const QString &setting) -> bool {
364 // 40 hex characters for OpenPGP v4 keys, 64 for v5/v6 (gpg 2.5+).
365 static const QRegularExpression fingerprint(
366 QStringLiteral("^(?:[0-9A-Fa-f]{40}|[0-9A-Fa-f]{64})$"));
367 const QStringList keys = setting.split(QLatin1Char(' '), Qt::SkipEmptyParts);
368 return std::all_of(keys.cbegin(), keys.cend(), [](const QString &key) {
369 return fingerprint.match(key).hasMatch();
370 });
371}
372
373// Profile names must be unique: the settings key profiles by name, so a
374// duplicate would silently overwrite the other. Unique ignoring case:
375// QSettings keys are case-insensitive on Windows (the registry, and INI
376// files there), so "Work" and "work" were one profile, and a settings file
377// can move between systems. For the same reason a name
378// holds no slash: QSettings reads "/" as a group separator, and "\" as one on
379// Windows, so "Work/Client" was stored a group too deep and read back as a
380// profile "Work" without folder or signing key.
382 const QHash<QString, int> &names) const
383 -> ProfileProblems {
384 ProfileProblems problems;
385 if (entry.name.isEmpty()) {
386 problems.name = tr("This field is required");
387 } else if (entry.name.contains(QLatin1Char('/')) ||
388 entry.name.contains(QLatin1Char('\\'))) {
389 problems.name = tr("A profile name cannot contain / or \\");
390 } else if (names.value(entry.name.toCaseFolded()) > 1) {
391 problems.name = tr("Another profile already has this name");
392 }
393 if (entry.profile.path.isEmpty()) {
394 problems.path = tr("This field is required");
395 }
396 // pass compares PASSWORD_STORE_SIGNING_KEY against the fingerprints in
397 // gpg's VALIDSIG line, so anything shorter than a fingerprint would sign
398 // and then never verify. Refuse it here instead of failing at first use.
399 if (!isFingerprintList(entry.profile.signingKey)) {
400 problems.key = tr("Full key fingerprints only (40 or 64 hexadecimal "
401 "characters), separated by spaces");
402 }
403 return problems;
404}
405
406void ConfigDialog::showProblems(int row, const ProfileProblems &problems) {
407 if (QListWidgetItem *item = ui->profileList->item(row)) {
408 item->setBackground(problems.none() ? QBrush() : QBrush(Qt::red));
409 item->setToolTip(problems.none() ? problems.sharedKey : problems.first());
410 }
411 if (row != m_currentEntry) {
412 return;
413 }
414 m_sharedKeyWarning->setText(problems.sharedKey);
415 m_sharedKeyWarning->setVisible(!problems.sharedKey.isEmpty());
416 const auto tipOr = [](const QString &problem, const QString &tip) -> QString {
417 return problem.isEmpty() ? tip : problem;
418 };
419 ui->profileName->setToolTip(tipOr(problems.name, m_nameTip));
420 ui->profilePath->setToolTip(tipOr(problems.path, m_pathTip));
421 ui->profileSigningKey->setToolTip(tipOr(problems.key, m_keyTip));
422}
423
425 // One folder spelled two ways (through a link, another case on a
426 // case-insensitive file system) is one store: compared as the file system
427 // resolves it where it exists. Resolved once per validate(), not once per
428 // pair of profiles.
429 SigningStores resolved;
430 // Keys are looked up in the keyring that signs: the configured GPG home,
431 // as profiles sign with it, not whatever GNUPGHOME QtPass inherited. The
432 // dialog does not edit the home, so the settings are read once, not on
433 // every keystroke; the environment is built each time, as the home may
434 // only appear meanwhile (a key generated from this dialog).
435 if (!m_gpgSettings) {
437 }
438 const QProcessEnvironment env = ProfileInit::gpgEnvironment(*m_gpgSettings);
439 for (const ProfileEntry &entry : std::as_const(m_entries)) {
440 const QString real = QFileInfo(entry.profile.path).canonicalFilePath();
441 resolved.stores << (real.isEmpty() ? QDir::cleanPath(entry.profile.path)
442 : real);
443 resolved.keys << signerKeys(entry.profile.signingKey, env);
444 }
445 return resolved;
446}
447
448auto ConfigDialog::signerKeys(const QString &signingKey,
449 const QProcessEnvironment &env) const
450 -> QSet<QString> {
451 // Verification takes the primary or the signing subkey's fingerprint
452 // from VALIDSIG, and gpg signs for a primary key with its subkey: a key
453 // written as the subkey in one profile and as the primary in another is
454 // one signer (#2087). Only complete IDs are asked about, so typing a key
455 // does not start gpg for every prefix.
456 static const QRegularExpression complete(QStringLiteral(
457 "^(?:0X)?(?:[0-9A-F]{8}|[0-9A-F]{16}|[0-9A-F]{40}|[0-9A-F]{64})$"));
458 const QString gpg = ui->gpgPath->text();
459 QSet<QString> keys;
460 const QStringList given =
461 signingKey.toUpper().split(QLatin1Char(' '), Qt::SkipEmptyParts);
462 for (const QString &key : given) {
463 keys.insert(key);
464 if (gpg.isEmpty() || !complete.match(key).hasMatch()) {
465 continue;
466 }
467 const QString cacheKey = gpg + QLatin1Char('\n') +
468 env.value(QStringLiteral("GNUPGHOME")) +
469 QLatin1Char('\n') + key;
470 auto cached = m_primaryOf.find(cacheKey);
471 if (cached == m_primaryOf.end()) {
472 QString out;
473 // Blocking, once per key: no trustdb check, which a large keyring
474 // would make slow.
475 const int rc = Executor::executeBlocking(
476 env, gpg,
477 {QStringLiteral("--no-tty"), QStringLiteral("--batch"),
478 QStringLiteral("--no-auto-check-trustdb"),
479 QStringLiteral("--with-colons"),
480 QStringLiteral("--with-fingerprint"),
481 QStringLiteral("--with-subkey-fingerprint"),
482 QStringLiteral("--list-keys"), QStringLiteral("--"), key},
483 &out);
484 cached = m_primaryOf.insert(
485 cacheKey, rc == 0 ? primaryFingerprintOf(out, key) : QString());
486 }
487 if (!cached->isEmpty()) {
488 keys.insert(*cached);
489 }
490 }
491 return keys;
492}
493
494void ConfigDialog::changeEvent(QEvent *event) {
495 QDialog::changeEvent(event);
496 if (event->type() != QEvent::ActivationChange) {
497 return;
498 }
499 // A key is imported somewhere else: a terminal, a key manager, or the
500 // key generator this dialog opens. Whatever keyring gpg uses, the dialog
501 // is in the background meanwhile, so a key gpg did not know is asked
502 // about again on return.
503 if (!isActiveWindow()) {
504 const auto forgotten = m_primaryOf.removeIf(
505 [](const std::pair<const QString &, QString &> &lookup) {
506 return lookup.second.isEmpty();
507 });
508 m_recheckSigners = m_recheckSigners || forgotten > 0;
509 } else if (m_recheckSigners) {
510 m_recheckSigners = false;
511 validate();
512 }
513}
514
515auto ConfigDialog::sharingTheKey(int row, const SigningStores &resolved) const
516 -> QStringList {
517 // A list signed for one store verifies in the other when the stores share
518 // a signing key; the folder line names a folder, not a store (#2050).
519 QStringList others;
520 const QSet<QString> &mine = resolved.keys.at(row);
521 if (mine.isEmpty()) {
522 return others;
523 }
524 for (int other = 0; other < m_entries.size(); ++other) {
525 if (other == row || resolved.stores.at(other) == resolved.stores.at(row)) {
526 continue;
527 }
528 if (resolved.keys.at(other).intersects(mine)) {
529 others << m_entries.at(other).name;
530 }
531 }
532 others.sort();
533 return others;
534}
535
537 QHash<QString, int> names;
538 for (const ProfileEntry &entry : std::as_const(m_entries)) {
539 names[entry.name.toCaseFolded()]++;
540 }
541 bool status = true;
542 const SigningStores resolved = signingStores();
543 for (int row = 0; row < m_entries.size(); ++row) {
544 ProfileProblems problems = problemsOf(m_entries.at(row), names);
545 if (const QStringList others = sharingTheKey(row, resolved);
546 !others.isEmpty()) {
547 problems.sharedKey =
548 tr("%1 signs with the same key for another store. A recipient "
549 "list signed for one of these stores is accepted in the other: "
550 "use a separate signing key for each store whose recipients "
551 "differ.")
552 .arg(others.join(QStringLiteral(", ")));
553 }
554 showProblems(row, problems);
555 status = status && problems.none();
556 }
557 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status);
559}
560
562 // Built after the first applySettings(); setProfiles() fills it then.
563 if (m_passGitWarning == nullptr) {
564 return;
565 }
566 QStringList warnings;
567 if (ui->radioButtonPass->isChecked()) {
568 QStringList stores{ui->storePath->text()};
569 for (const ProfileEntry &entry : std::as_const(m_entries)) {
570 stores << entry.profile.path;
571 }
572 stores.removeDuplicates();
573 for (const QString &store : std::as_const(stores)) {
574 const QString repository = Util::repositoryPassClimbsTo(store);
575 if (!repository.isEmpty()) {
576 warnings << tr("pass commits changes in %1 to the Git repository in "
577 "%2: with a colon in the store's path, pass cannot "
578 "keep Git to the store. Run \"git init\" in the store, "
579 "or use native Git/GPG.")
580 .arg(QDir::toNativeSeparators(store),
581 QDir::toNativeSeparators(repository));
582 }
583 }
584 }
585 m_passGitWarning->setText(warnings.join(QStringLiteral("\n\n")));
586 m_passGitWarning->setVisible(!warnings.isEmpty());
587}
588
590 const QString override = ui->sshAuthSockOverride->text().trimmed();
591 if (override.isEmpty()) {
592 return;
593 }
594 QString reason;
595 switch (SshAuthSock::overrideStatus(override)) {
597 return;
599 reason = tr("The path does not exist.");
600 break;
602 reason = tr("The path is not readable.");
603 break;
605 reason = tr("The path is not a Unix domain socket.");
606 break;
607 }
609 this, tr("Potentially invalid SSH_AUTH_SOCK override"),
610 tr("The SSH_AUTH_SOCK override value may be invalid.\n\n%1\n\n"
611 "The value will still be saved as entered.")
612 .arg(reason));
613}
614
616 // As MainWindow::on_profileBox_currentTextChanged does when switching.
618 const QString wasActive = s.activeProfile;
619 QString nowActive;
620 for (const ProfileEntry &entry : std::as_const(m_entries)) {
621 if (!wasActive.isEmpty() && entry.originalName == wasActive) {
622 nowActive = entry.name;
623 }
624 }
625 s.activeProfile = nowActive;
626 const auto active = profiles.constFind(nowActive);
627 if (active != profiles.constEnd()) {
628 // Not the profile's Git flags: those stay the profile's, and the Git
629 // page's values stay what the page says (QtPassSettings::loadEffective()).
630 // The signing key the active profile carries must become the live setting
631 // the backends check .gpg-id signatures against, as
632 // MainWindow::on_profileBox_currentTextChanged does when switching. Without
633 // this, a key entered for the profile in use is saved but never applied, so
634 // QtPass keeps accepting unsigned (or badly signed) .gpg-id lists.
635 s.passSigningKey = active->signingKey;
636 }
637 // A store typed in the store field that is another profile's opens as
638 // that profile, with its signing key; one inside a signed profile's store
639 // takes that key.
642}
643
646 const Profiles existingProfiles = QtPassSettings::getProfiles();
647 // Persist via the facade, which also invalidates the cached Pass backend so
648 // a changed "use pass" mode takes effect.
650 // Profiles are not part of AppSettings yet, so persist them separately.
651 const Profiles profiles = getProfiles();
653 followActiveProfile(profiles);
654 initializeNewProfiles(existingProfiles);
655}
656
658 QString pass = Util::findBinaryInPath("pass");
659 if (!pass.isEmpty()) {
660 ui->passPath->setText(pass);
661 }
662 usePass(!pass.isEmpty());
663 QString gpg = Util::findBinaryInPath("gpg2");
664 if (gpg.isEmpty()) {
665 gpg = Util::findBinaryInPath("gpg");
666 }
667 if (!gpg.isEmpty()) {
668 ui->gpgPath->setText(gpg);
669 }
670 QString git = Util::findBinaryInPath("git");
671 if (!git.isEmpty()) {
672 setGitPath(git);
673 }
674 QString pwgen = Util::findBinaryInPath("pwgen");
675 if (!pwgen.isEmpty()) {
676 setPwgenPath(pwgen);
677 }
678}
679
681
683
685 bool state = ui->radioButtonPass->isChecked();
686 ui->groupBoxNative->setEnabled(!state);
687 ui->groupBoxPass->setEnabled(state);
690 if (state) {
691 ui->spinBoxPasswordLength->setEnabled(false);
692 ui->checkBoxUsePwgen->setEnabled(false);
693 ui->checkBoxAvoidCapitals->setEnabled(false);
694 ui->checkBoxUseSymbols->setEnabled(false);
695 ui->checkBoxLessRandom->setEnabled(false);
696 ui->checkBoxAvoidNumbers->setEnabled(false);
697 ui->labelPasswordChars->setEnabled(false);
698 ui->passwordCharTemplateSelector->setEnabled(false);
699 ui->lineEditPasswordChars->setEnabled(false);
700 } else {
701 // native mode: restore pwgen/charset state from existing handlers
702 ui->spinBoxPasswordLength->setEnabled(true);
704 }
705}
706
708 QFileDialog dialog(this);
709 dialog.setFileMode(QFileDialog::ExistingFile);
710 dialog.setOption(QFileDialog::ReadOnly);
711 if (dialog.exec()) {
712 return dialog.selectedFiles().constFirst();
713 }
714
715 return {};
716}
717
718auto ConfigDialog::selectFolder() -> QString {
719 QFileDialog dialog(this);
720 dialog.setFileMode(QFileDialog::Directory);
721 dialog.setFilter(QDir::NoFilter);
722 dialog.setOption(QFileDialog::ShowDirsOnly);
723 if (dialog.exec()) {
724 return dialog.selectedFiles().constFirst();
725 }
726
727 return {};
728}
729
731 QString git = selectExecutable();
732 if (!git.isEmpty()) {
733 setGitPath(git);
734 }
735}
736
738 QString gpg = selectExecutable();
739 if (!gpg.isEmpty()) {
740 ui->gpgPath->setText(gpg);
741 }
742}
743
745 KeygenDialog d(ui->gpgPath->text(), QtPassSettings::getPass(), this);
746 d.exec();
747}
748
750 QString pass = selectExecutable();
751 if (!pass.isEmpty()) {
752 ui->passPath->setText(pass);
753 }
754}
755
757 QString store = selectFolder();
758 if (!store.isEmpty()) {
759 ui->storePath->setText(store);
760 }
761}
762
763// index 0 is "No clipboard".
765 bool state = index > 0;
766
767 ui->checkBoxSelection->setEnabled(state);
768 ui->checkBoxHidePassword->setEnabled(state);
770 ui->checkBoxHideContent->setEnabled(state);
771 ui->labelAutoclear->setEnabled(state);
772 ui->spinBoxAutoclearSeconds->setEnabled(state);
773 ui->labelSeconds->setEnabled(state);
774 ui->checkBoxRestoreClipboard->setEnabled(state);
775}
776
778 // Each control only while the one it depends on is on: other secrets and
779 // every field only while passwords are hidden; the secret words only while
780 // other secrets are, and not when every field is hidden anyway.
781 const bool hiding = ui->checkBoxHidePassword->isEnabled() &&
782 ui->checkBoxHidePassword->isChecked();
783 ui->checkBoxHideAllFields->setEnabled(hiding);
784 const bool all = hiding && ui->checkBoxHideAllFields->isChecked();
785 ui->checkBoxHideSecretFields->setEnabled(hiding && !all);
786 const bool words =
787 hiding && !all && ui->checkBoxHideSecretFields->isChecked();
788 ui->lineEditSecretFields->setEnabled(words);
789 ui->buttonDefaultSecretFields->setEnabled(words);
790}
791
793 ui->checkBoxSelection->setChecked(useSelection);
795}
796
798 on_comboBoxClipboard_activated(ui->comboBoxClipboard->currentIndex());
799}
800
802 const QString &currentProfile) {
803 // remove weird "" key value pairs
804 profiles.remove(QString());
805
806 m_entries.clear();
807 ui->profileList->clear();
808 int currentRow = -1;
809 for (auto i = profiles.cbegin(); i != profiles.cend(); ++i) {
810 if (i.key() == currentProfile) {
811 currentRow = static_cast<int>(m_entries.size());
812 }
813 m_entries.append({i.key(), i.value(), i.key()});
814 ui->profileList->addItem(i.key());
815 }
816 ui->profileList->setCurrentRow(currentRow);
817 if (currentRow < 0) {
818 loadProfileForm(-1);
819 }
820 validate();
821}
822
824 if (m_currentEntry < 0 || m_currentEntry >= m_entries.size()) {
825 return nullptr;
826 }
827 return &m_entries[m_currentEntry];
828}
829
830// The Git boxes show the profile's own flags, else the global ones; only a
831// click on a box makes the value the profile's own.
833 m_currentEntry = (row >= 0 && row < m_entries.size()) ? row : -1;
834 const ProfileEntry *entry = currentEntry();
835 m_loadingForm = true;
836 ui->profileForm->setEnabled(entry != nullptr);
837 ui->deleteButton->setEnabled(entry != nullptr);
838 ui->profileName->setText(entry ? entry->name : QString());
839 ui->profilePath->setText(entry ? entry->profile.path : QString());
840 ui->profileSigningKey->setText(entry ? entry->profile.signingKey : QString());
841 const bool useGit =
842 entry && entry->profile.useGit.value_or(ui->checkBoxUseGit->isChecked());
843 ui->profileUseGit->setChecked(useGit);
844 ui->profileAutoPush->setChecked(
845 entry &&
846 entry->profile.autoPush.value_or(ui->checkBoxAutoPush->isChecked()));
847 ui->profileAutoPull->setChecked(
848 entry &&
849 entry->profile.autoPull.value_or(ui->checkBoxAutoPull->isChecked()));
850 ui->profileAutoPush->setEnabled(useGit);
851 ui->profileAutoPull->setEnabled(useGit);
852 m_loadingForm = false;
854 validate();
855}
856
858 Profiles profiles;
859 for (const ProfileEntry &entry : std::as_const(m_entries)) {
860 profiles.insert(entry.name, entry.profile);
861 }
862 return profiles;
863}
864
865auto ConfigDialog::ensureProfileFolder(const QString &path) -> bool {
866 if (QDir(path).exists()) {
867 return true;
868 }
869 if (QMessageBox::question(
870 this, tr("Create profile directory?"),
871 tr("Would you like to create a password store at %1?").arg(path),
872 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
873 return false;
874 }
875 if (!Util::mkpathForStore(path)) {
877 this, tr("Error"),
878 tr("Could not create profile directory: %1").arg(path));
879 return false;
880 }
881 return true;
882}
883
885 const Profile &profile,
886 const QString &path) {
887 // Only the recipients come through the active backend. passStore is the
888 // profile, or getGpgIdPath() would pre-tick the active store's recipients;
889 // signing keys are per profile, exactly as the profile switch applies them
890 // (MainWindow::on_profileBox_currentTextChanged).
891 const AppSettings settings = QtPassSettings::load();
892 AppSettings profileSettings = settings;
893 profileSettings.passStore = Util::normalizeFolderPath(path);
894 profileSettings.passSigningKey = profile.signingKey;
895 // needsInit() found no .gpg-id: nothing to preselect, and none that
896 // appears meanwhile is taken (it would be read under the active
897 // profile's signing policy).
898 UsersDialog usersDialog(QtPassSettings::getPass(), profileSettings,
899 profileSettings.passStore,
901 usersDialog.setInitOnAccept(false);
902 usersDialog.setWindowTitle(tr("Select recipients for %1").arg(name));
903 if (usersDialog.exec() != QDialog::Accepted) {
904 return;
905 }
906 QString note;
907 const bool ok = ProfileInit::initialise(
908 path, usersDialog.selectedUsers(), profileSettings,
909 profile.useGit.value_or(settings.useGit), &note);
910 if (!ok) {
911 // ProfileInit writes .gpg-id before it signs and commits. Left behind,
912 // needsInit() would find a store that looks finished, and saving the
913 // profile again would never retry; the wizard takes it back the same
914 // way.
915 QFile::remove(QDir(path).filePath(QStringLiteral(".gpg-id")));
916 QFile::remove(QDir(path).filePath(QStringLiteral(".gpg-id.sig")));
918 this, tr("Could not initialise profile %1").arg(name), note);
919 } else if (!note.isEmpty()) {
920 PlainMessageBox::show(this, QMessageBox::Information,
921 tr("Profile %1").arg(name), note);
922 }
923}
924
925void ConfigDialog::initializeNewProfiles(const Profiles &existingProfiles) {
926 const Profiles newProfiles = getProfiles();
927 // QMap iterates in name order.
928 for (auto it = newProfiles.cbegin(); it != newProfiles.cend(); ++it) {
929 const QString path = QDir::cleanPath(it.value().path);
930 // A store that was already a profile when the dialog opened, under this
931 // or another name: a rename is not a new store.
932 const bool known = std::any_of(
933 existingProfiles.cbegin(), existingProfiles.cend(),
934 [&it](const Profile &old) { return old.path == it.value().path; });
935 // needsInit is false for a missing folder, so it is created first.
936 if (!known && ensureProfileFolder(path) && ProfileInit::needsInit(path)) {
937 initialiseProfileStore(it.key(), it.value(), path);
938 }
939 }
940}
941
943 ProfileEntry entry;
944 entry.name = tr("New profile");
945 entry.profile.path = ui->storePath->text();
946 m_entries.append(entry);
947 ui->profileList->addItem(entry.name);
948 ui->profileList->setCurrentRow(static_cast<int>(m_entries.size()) - 1);
949 ui->profileName->setFocus();
950 ui->profileName->selectAll();
951 validate();
952}
953
955 const QString dir = selectFolder();
956 if (!dir.isEmpty()) {
957 ui->profilePath->setText(dir);
959 }
960}
961
963 const int row = ui->profileList->currentRow();
964 if (row < 0 || row >= m_entries.size()) {
965 QMessageBox::warning(this, tr("No profile selected"),
966 tr("No profile selected to delete"));
967 return;
968 }
969 m_entries.removeAt(row);
970 delete ui->profileList->takeItem(row);
971 // The list moved its current row while the row was being removed, so
972 // currentRowChanged carried the old numbering: the form named the profile
973 // after the one now highlighted, and edits (a signing key) went there.
974 // Load it from the row the list shows now.
975 loadProfileForm(ui->profileList->currentRow());
976}
977
978void ConfigDialog::criticalMessage(const QString &title, const QString &text) {
979 QMessageBox::critical(this, title, text, QMessageBox::Ok, QMessageBox::Ok);
980}
981
982// Looks on Util's PATH (with the macOS and Windows additions) without a
983// subprocess; a hit is stored for the QR display, a miss leaves the setting.
984auto ConfigDialog::isQrencodeAvailable(const QString &configuredPath) -> bool {
985#ifdef Q_OS_WIN
986 Q_UNUSED(configuredPath);
987 return false;
988#else
989 if (!configuredPath.isEmpty()) {
990 const QFileInfo configured(configuredPath);
991 if (configured.isFile() && configured.isExecutable()) {
992 return true;
993 }
994 }
995 const QString found = Util::findBinaryInPath(QStringLiteral("qrencode"));
996 if (found.isEmpty()) {
997 return false;
998 }
1000 return true;
1001#endif
1002}
1003
1004void ConfigDialog::useTrayIcon(bool useSystray) {
1005 if (QSystemTrayIcon::isSystemTrayAvailable()) {
1006 ui->checkBoxUseTrayIcon->setChecked(useSystray);
1007 ui->checkBoxHideOnClose->setEnabled(useSystray);
1008 ui->checkBoxStartMinimized->setEnabled(useSystray);
1009
1010 if (!useSystray) {
1011 ui->checkBoxHideOnClose->setChecked(false);
1012 ui->checkBoxStartMinimized->setChecked(false);
1013 }
1014 }
1015}
1016
1018 bool state = ui->checkBoxUseTrayIcon->isChecked();
1019 ui->checkBoxHideOnClose->setEnabled(state);
1020 ui->checkBoxStartMinimized->setEnabled(state);
1021}
1022
1024 // Without a git path the checkbox is disabled; ticked as well, it could
1025 // not be unticked.
1026 if (ui->gitPath->text().isEmpty()) {
1027 useGit = false;
1028 }
1029 ui->checkBoxUseGit->setChecked(useGit);
1031}
1032
1034 ui->checkBoxUseOtp->setChecked(useOtp);
1035}
1036
1038 ui->checkBoxUseGrepSearch->setChecked(useGrepSearch);
1039}
1040
1042 ui->checkBoxUseQrencode->setChecked(useQrencode);
1043}
1044
1046 ui->checkBoxAddGPGId->setEnabled(ui->checkBoxUseGit->isChecked());
1047 ui->checkBoxAutoPull->setEnabled(ui->checkBoxUseGit->isChecked());
1048 ui->checkBoxAutoPush->setEnabled(ui->checkBoxUseGit->isChecked());
1049 // pass always stops git at the store's parent itself, so the choice only
1050 // means something in native mode.
1051 ui->checkBoxGitUseParentRepository->setEnabled(
1052 ui->checkBoxUseGit->isChecked() && !ui->radioButtonPass->isChecked());
1053}
1054
1056 QString pwgen = selectExecutable();
1057 if (!pwgen.isEmpty()) {
1058 setPwgenPath(pwgen);
1059 }
1060}
1061
1062void ConfigDialog::setPwgenPath(const QString &pwgen) {
1063 ui->pwgenPath->setText(pwgen);
1064 // setText() is silent when the text did not change.
1066}
1067
1068// Every way to a pwgen path ends here: loading the settings (where the backend
1069// step runs while the path is still empty), Autodetect, the file dialog and
1070// typing in the field.
1072 const bool hasPwgen = !ui->pwgenPath->text().isEmpty();
1073 if (!hasPwgen) {
1074 ui->checkBoxUsePwgen->setChecked(false);
1075 }
1076 ui->checkBoxUsePwgen->setEnabled(hasPwgen &&
1077 !ui->radioButtonPass->isChecked());
1079}
1080
1082 if (ui->radioButtonPass->isChecked())
1083 return;
1084 bool usePwgen = ui->checkBoxUsePwgen->isChecked();
1085 ui->checkBoxAvoidCapitals->setEnabled(usePwgen);
1086 ui->checkBoxAvoidNumbers->setEnabled(usePwgen);
1087 ui->checkBoxLessRandom->setEnabled(usePwgen);
1088 ui->checkBoxUseSymbols->setEnabled(usePwgen);
1089 // Only the custom set is editable; a builtin one is saved as it is.
1090 ui->lineEditPasswordChars->setEnabled(
1091 !usePwgen && ui->passwordCharTemplateSelector->currentIndex() ==
1093 ui->labelPasswordChars->setEnabled(!usePwgen);
1094 ui->passwordCharTemplateSelector->setEnabled(!usePwgen);
1095}
1096
1098 if (ui->pwgenPath->text().isEmpty()) {
1099 usePwgen = false;
1100 }
1101 ui->checkBoxUsePwgen->setChecked(usePwgen);
1103}
1104
1106 const PasswordConfiguration &config) {
1107 // Retain the custom charset so it survives even when a builtin set is the
1108 // active selection (the line edit then shows the builtin's characters).
1110 ui->spinBoxPasswordLength->setValue(config.length);
1111 ui->passwordCharTemplateSelector->setCurrentIndex(config.selected);
1113 ui->lineEditPasswordChars->setEnabled(false);
1114 }
1115 ui->lineEditPasswordChars->setText(config.Characters[config.selected]);
1116}
1117
1119 PasswordConfiguration config;
1120 config.length = ui->spinBoxPasswordLength->value();
1121 config.selected = static_cast<PasswordConfiguration::CharacterSet>(
1122 ui->passwordCharTemplateSelector->currentIndex());
1123 // For a builtin selection the line edit shows the builtin's characters;
1124 // reading it would overwrite the saved custom charset.
1127 ui->lineEditPasswordChars->text();
1128 } else {
1130 }
1131 return config;
1132}
1133
1135 ui->lineEditPasswordChars->setText(
1136 QtPassSettings::getPasswordConfiguration().Characters[index]);
1137 if (index == PasswordConfiguration::CUSTOM) {
1138 ui->lineEditPasswordChars->setEnabled(true);
1139 } else {
1140 ui->lineEditPasswordChars->setEnabled(false);
1141 }
1142}
1143
1145
1146void ConfigDialog::onProfileNameEdited(const QString &name) {
1147 ProfileEntry *entry = currentEntry();
1148 if (m_loadingForm || entry == nullptr) {
1149 return;
1150 }
1151 entry->name = name;
1152 if (QListWidgetItem *item = ui->profileList->item(m_currentEntry)) {
1153 item->setText(name);
1154 }
1155 validate();
1157}
1158
1159void ConfigDialog::onProfilePathEdited(const QString &path) {
1160 ProfileEntry *entry = currentEntry();
1161 if (m_loadingForm || entry == nullptr) {
1162 return;
1163 }
1164 entry->profile.path = path;
1165 validate();
1167}
1168
1170 ProfileEntry *entry = currentEntry();
1171 if (m_loadingForm || entry == nullptr) {
1172 return;
1173 }
1174 entry->profile.signingKey = key;
1175 validate();
1176}
1177
1178// A Git box was clicked: the profile now has its own flags.
1180 ProfileEntry *entry = currentEntry();
1181 if (m_loadingForm || entry == nullptr) {
1182 return;
1183 }
1184 entry->profile.useGit = ui->profileUseGit->isChecked();
1185 entry->profile.autoPush = ui->profileAutoPush->isChecked();
1186 entry->profile.autoPull = ui->profileAutoPull->isChecked();
1187 ui->profileAutoPush->setEnabled(ui->profileUseGit->isChecked());
1188 ui->profileAutoPull->setEnabled(ui->profileUseGit->isChecked());
1189}
1190
1192 const ProfileEntry *entry = currentEntry();
1193 if (entry == nullptr) {
1194 ui->statusLabel->setText(QString());
1195 return;
1196 }
1197
1198 QString statusMessage;
1199 if (!entry->name.isEmpty() && !entry->profile.path.isEmpty()) {
1200 const QString path = QDir::cleanPath(entry->profile.path);
1201 if (!QDir(path).exists()) {
1202 statusMessage = tr("New profile: %1 at %2").arg(entry->name, path);
1203 } else {
1204 statusMessage = tr("Profile: %1 at %2").arg(entry->name, path);
1205 }
1206 } else {
1207 statusMessage = tr("Fill in all required fields");
1208 }
1209
1210 ui->statusLabel->setText(statusMessage);
1211}
AppSettings, the value object holding every flat QtPass setting.
void setPasswordConfiguration(const PasswordConfiguration &config)
Apply a password configuration to the dialog controls.
void on_deleteButton_clicked()
Remove the selected profile row (a message when none is); the list's currentRowChanged re-points the ...
std::optional< AppSettings > m_gpgSettings
void on_passwordCharTemplateSelector_activated(int index)
Show the chosen character set's characters in the line edit, editable only for the custom set.
static auto isFingerprintList(const QString &setting) -> bool
Whether a signing-key setting holds only full key fingerprints (40 or 64 hexadecimal characters each,...
void on_toolButtonGit_clicked()
Pick the git executable in a file dialog; a choice enables "useGit", a cancelled dialog keeps the fie...
auto sharingTheKey(int row, const SigningStores &resolved) const -> QStringList
The other profiles, for other stores, whose signing keys share a fingerprint with row row's.
void validate()
Check every profile (problemsOf(), sharingTheKey()), mark the rows and the form, enable OK only when ...
void updatePassGitWarning()
auto ensureProfileFolder(const QString &path) -> bool
Offer to create a new profile's store folder when it is missing.
void on_radioButtonNative_clicked()
Native (gpg/git) backend chosen: enable its group box, disable pass's.
QList< ProfileEntry > m_entries
The profiles as shown; index == row in profileList.
void useOtp(bool useOtp)
Enable or disable OTP support.
void updateSecretFieldsEnabled()
QString m_nameTip
bool m_gitOnBeforeEmptyPath
void loadProfileForm(int row)
Show row row's profile in the form (or clear and disable it for -1), with m_loadingForm set so the fi...
void on_pushButtonGenerateKey_clicked()
Open KeygenDialog for the gpg shown in the dialog.
void setPwgenPath(const QString &path)
Set the path to the pwgen executable.
void on_toolButtonStore_clicked()
Pick the password store folder for the pass backend's store path.
void updateGitCheckbox()
Make "use Git" follow the git path field: enabled with a path, turned off and disabled without one....
void on_checkBoxUseTrayIcon_clicked()
Hide-on-close and start-minimised are only offered with a tray icon.
QHash< QString, QString > m_primaryOf
void useGit(bool useGit)
Enable or disable git integration.
void on_radioButtonPass_clicked()
pass backend chosen: enable its group box, disable the native one.
void showProblems(int row, const ProfileProblems &problems)
Mark row row of the profile list, and the form fields when it is the row being edited,...
int m_currentEntry
Row whose fields the form shows, -1 for none.
void on_profilePathBrowse_clicked()
Pick the selected profile's store folder and store it in its entry.
QLabel * m_sharedKeyWarning
Below the signing key: the profiles that share it, if any.
QScopedPointer< Ui::ConfigDialog > ui
The widgets from configdialog.ui.
void on_checkBoxUsePwgen_clicked()
Enable pwgen's flags or the character-set controls, whichever the "use pwgen" box selects; nothing in...
auto signerKeys(const QString &signingKey, const QProcessEnvironment &env) const -> QSet< QString >
One profile's signing keys as signers: each key as written, plus the primary fingerprint gpg gives fo...
void setProfiles(Profiles profiles, const QString &currentProfile)
Fill the profile list and m_entries from profiles, dropping the empty-named leftover older versions w...
void useQrencode(bool useQrencode)
Enable or disable QR code display.
void on_autodetectButton_clicked()
Fill the pass, gpg (gpg2 first), git and pwgen paths from PATH, keeping a field as it is when nothing...
auto problemsOf(const ProfileEntry &entry, const QHash< QString, int > &names) const -> ProfileProblems
What is wrong with entry's name, store path and signing keys.
void on_comboBoxClipboard_activated(int index)
Enable the controls that only mean something with a clipboard (selection, hiding, autoclear) unless "...
void updatePwgenCheckbox()
Make "use pwgen" follow the pwgen path field: enabled with a path in native mode, unticked and disabl...
void onProfilePathEdited(const QString &path)
The path field was typed in: store it in the entry, validate and refresh the status line.
void usePass(bool usePass)
Tick the pass or the native radio button and enable the matching group box.
void useGrepSearch(bool useGrepSearch)
Enable or disable grep content search.
QLabel * m_passGitWarning
In the pass box: the stores pass would commit outside of, if any.
void initializeNewProfiles(const Profiles &existingProfiles)
For every saved profile whose store was not a profile's store when the dialog opened: offer to create...
ConfigDialog(QWidget *parent)
Construct a ConfigDialog associated with the given main window.
void onProfileSelected(int row)
The profile list's current row changed: show that profile.
auto signingStores() const -> SigningStores
Resolve every profile's store and fingerprints once.
auto selectExecutable() -> QString
Ask for an existing file in a read-only file dialog.
QString m_customPasswordChars
void setGitPath(const QString &path)
Show path as the git executable; an empty path disables and turns off "use Git".
void on_toolButtonPass_clicked()
Pick the pass executable in a file dialog; cancel keeps the field.
void setGroupBoxState()
Enable the group box of the chosen backend and, in pass mode, disable the password-generation control...
bool m_recheckSigners
void onProfileGitToggled()
One of the profile's Git boxes was clicked: all three flags become the profile's own (no longer follo...
void on_checkBoxUseGit_clicked()
Enable the Git-dependent boxes (add .gpg-id, auto pull/push, and in native mode the parent-repository...
auto getPasswordConfiguration() -> PasswordConfiguration
Read the current password configuration from the dialog controls.
auto currentEntry() -> ProfileEntry *
The entry the form is editing.
void initialiseProfileStore(const QString &name, const Profile &profile, const QString &path)
Ask for a new profile's recipients and initialise its store with them, keeping the active backend's s...
void criticalMessage(const QString &title, const QString &text)
QMessageBox::critical with a single OK button. Once a workaround for crashes in Qt 5....
void useTrayIcon(bool useSystray)
Show or hide the system tray icon.
void onProfileSigningKeyEdited(const QString &key)
The signing-key field was typed in: store it in the entry and validate (fingerprints only,...
void followActiveProfile(const Profiles &profiles)
Point the active profile at its new name after a rename (or at none after a deletion),...
void on_toolButtonGpg_clicked()
Pick the gpg executable in a file dialog; cancel keeps the field.
void warnAboutSshAuthSockOverride()
void applySettings(const AppSettings &settings)
Load the dialog's value widgets from an AppSettings struct.
auto getProfiles() -> Profiles
Return all configured profiles.
QString m_keyTip
void on_accepted()
On OK: warn about a dubious SSH_AUTH_SOCK override, save the settings and the profiles,...
void on_checkBoxSelection_clicked()
Re-apply the clipboard gating for the current clipboard mode.
void on_toolButtonPwgen_clicked()
Pick the pwgen executable; a choice enables "use pwgen", a cancelled dialog keeps the field and the c...
void usePwgen(bool usePwgen)
Enable or disable pwgen-based password generation.
QString m_pathTip
void changeEvent(QEvent *event) override
Forget the signing keys gpg did not know while the dialog is in the background, and check them again ...
void updateProfileStatus()
Refresh the status line under the form: the profile's name and cleaned path, marked "New" while the f...
auto isQrencodeAvailable(const QString &configuredPath) -> bool
Whether qrencode can run: configuredPath when it is an executable file, else a qrencode on Util's PAT...
auto readSettings() -> AppSettings
Build an AppSettings struct from the dialog's widgets.
void onProfileNameEdited(const QString &name)
The name field was typed in: store it in the entry and the list item, then validate (duplicates,...
void on_addButton_clicked()
Append a "New profile" row pointing at the global store path, select it and put the cursor in the nam...
auto selectFolder() -> QString
Ask for a directory in a directories-only file dialog.
void useSelection(bool useSelection)
Enable or disable clipboard selection mode.
static auto executeBlocking(const QString &app, const QStringList &args, const QString &input=QString(), QString *process_out=nullptr, QString *process_err=nullptr) -> int
Run a command synchronously and return its exit code.
Definition executor.cpp:700
Handles GPG keypair generation.
static auto needsInit(const QString &path) -> bool
Check if a profile path needs initialization.
static auto initialise(const QString &dir, const QList< UserInfo > &users, const AppSettings &settings, bool useGit, QString *note) -> bool
Write the recipients and, if wanted, put the folder under git.
static auto gpgEnvironment(const AppSettings &s) -> QProcessEnvironment
The environment QtPass runs gpg in outside the active store's backend: the system's,...
static auto getPass() -> Pass *
Get currently active pass backend instance.
static auto getPasswordConfiguration() -> PasswordConfiguration
Get complete password generation configuration.
static auto load() -> AppSettings
Load all flat settings into an AppSettings value object.
static auto getProfiles() -> Profiles
Get all configured profiles.
static void setQrencodeExecutable(const QString &qrencodeExecutable)
Save qrencode executable path.
static auto getProfile(const QString &defaultValue=QVariant().toString()) -> QString
Get active profile name.
static void setProfiles(const Profiles &profiles)
Save all configured profiles.
static void takeProfileOfStore(AppSettings &settings, const Profiles &profiles)
Make settings use the profile whose store it opens.
static void save(const AppSettings &settings)
Persist an AppSettings value object to the singleton store.
@ Valid
Exists, readable, and on Unix a Unix domain socket.
Definition sshauthsock.h:34
@ NotUnixDomainSocket
Unix only: stat() says the path is not S_ISSOCK.
Definition sshauthsock.h:38
@ DoesNotExist
QFileInfo::exists() returned false.
Definition sshauthsock.h:35
static auto overrideStatus(const QString &path) -> OverrideStatus
Validate an SSH_AUTH_SOCK override path. Caller is expected to skip validation when the input is empt...
Dialog for selecting GPG recipients for password encryption.
Definition usersdialog.h:36
auto selectedUsers() const -> QList< UserInfo >
The key list with the user's choice in each entry's enabled flag.
Definition usersdialog.h:84
@ Nothing
None: for a store that had no list when it was chosen.
Definition usersdialog.h:43
void setInitOnAccept(bool initOnAccept)
Choose whether OK runs Pass::Init on the folder.
Definition usersdialog.h:78
static auto repositoryPassClimbsTo(const QString &store) -> QString
The repository above store that pass itself would commit to, if any.
Definition util.cpp:342
static auto configIsValid(const AppSettings &s) -> bool
Verify that the required configuration is complete.
Definition util.cpp:733
static auto mkpathForStore(const QString &path) -> bool
Create path and any missing parents as pass would.
Definition util.cpp:615
static auto normalizeFolderPath(const QString &path) -> QString
Ensure a folder path always ends with '/'.
Definition util.cpp:118
static auto findBinaryInPath(const QString &binary) -> QString
Locate an executable by searching the process PATH and (on Windows) falling back to WSL.
Definition util.cpp:651
Settings dialog: every page of the configuration window and the profile table, with the validation th...
Executor, the FIFO queue every gpg, git and pass child process of QtPass goes through,...
auto primaryFingerprintOf(const QString &output, const QString &key) -> QString
The primary key fingerprint of the key that key names.
Parsing of gpg --with-colons key listings into UserInfo records.
Dialog that collects name, e-mail and passphrase for a new GPG keypair and drives gpg --gen-key --bat...
ClipBoardType
Defines when to copy passwords to clipboard.
Definition enums.h:24
auto show(QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons=QMessageBox::Ok) -> QMessageBox::StandardButton
Show a modal message box with plain text and wait for it.
void warning(QWidget *parent, const QString &title, const QString &text)
Show a warning in plain text.
void attach(QDialog &dialog, const QString &key)
restore() now, save() whenever the dialog finishes.
QMessageBox helpers that force Qt::PlainText so store-controlled names can never be read as rich-text...
QMap< QString, Profile > Profiles
All profiles by name. QMap so iteration order is the name order.
Definition profile.h:81
Initialising a new profile's store (.gpg-id, signature, Git) with blocking processes,...
The "qtpass" logging category.
QtPassSettings, the QSettings singleton behind every saved setting, the profiles and the Pass backend...
SshAuthSock: finding an SSH agent socket for child processes and judging a configured override.
Plain value-object holding all flat QtPass configuration.
Definition appsettings.h:36
bool displayAsIs
Show file content unmodified.
Definition appsettings.h:97
bool useGrepSearch
Enable content (grep) search.
QString gpgExecutable
Path to the gpg/gpg2 executable.
Definition appsettings.h:66
QString qrencodeExecutable
Path to the qrencode executable.
Definition appsettings.h:68
QString sshAuthSockOverride
Manual SSH_AUTH_SOCK override path.
Definition appsettings.h:70
bool lessRandom
Generate memorable (less random) passwords.
bool useSymbols
Include special symbols.
bool hideOnClose
Hide to tray instead of quitting on close.
QStringList secretFieldNames
Definition appsettings.h:91
QString passSigningKey
GPG key used to sign .gpg-id files.
Definition appsettings.h:61
bool usePass
Use the pass CLI (true) or native git/gpg.
Definition appsettings.h:59
QString pwgenExecutable
Path to the pwgen executable.
Definition appsettings.h:67
bool hideContent
Hide the entire content panel.
Definition appsettings.h:95
bool useOtp
Enable native TOTP (OTP) support.
QString passStore
Password-store root path.
Definition appsettings.h:60
bool hidePassword
Definition appsettings.h:85
bool useAutoclearPanel
Clear the content panel after a delay.
Definition appsettings.h:81
bool noLineWrapping
Disable line wrapping in the panel.
Definition appsettings.h:98
QString gitExecutable
Path to the git executable.
Definition appsettings.h:65
bool autoPull
git pull before an entry is edited and before a re-encryption.
bool alwaysOnTop
Keep the main window always on top.
int autoclearPanelSeconds
Panel autoclear delay (seconds).
Definition appsettings.h:82
bool hideSecretFields
Definition appsettings.h:88
bool startMinimized
Start the window minimised.
bool useTrayIcon
Show a system tray icon.
bool gitUseParentRepository
QString passExecutable
Path to the pass executable.
Definition appsettings.h:64
bool avoidCapitals
Exclude uppercase letters.
int autoclearSeconds
Clipboard autoclear delay (seconds).
Definition appsettings.h:80
bool useSelection
Use the X11 primary selection.
Definition appsettings.h:75
bool useGit
Enable git integration.
bool restoreClipboard
Definition appsettings.h:79
bool addGPGId
Auto-add .gpg-id files to git.
Enums::ClipBoardType clipBoardType
Clipboard copy behaviour.
Definition appsettings.h:73
bool hideAllFields
Definition appsettings.h:94
QString version
Last-run application version.
Definition appsettings.h:53
QString passTemplate
Newline-separated template field names.
bool useAutoclear
Definition appsettings.h:76
bool useMonospace
Render content in a monospace font.
Definition appsettings.h:96
bool templateAllFields
Treat every key: line as a field.
bool avoidNumbers
Exclude digits.
bool useQrencode
Enable qrencode support.
QString activeProfile
Name of the active profile.
Definition appsettings.h:56
bool useTemplate
Use the password template.
PasswordConfiguration passwordConfiguration
Length/charset/custom chars.
One row of the profile list while the dialog is open. A QList rather than the Profiles map so a profi...
QString name
The name as typed; may be empty or a duplicate.
Profile profile
What is wrong with one profile's fields; empty strings where nothing is.
QString name
Empty or duplicate name; empty when fine.
auto none() const -> bool
Whether all three fields are fine.
auto first() const -> QString
The first complaint, for a tooltip on the profile's row.
QString path
Missing store path; empty when fine.
QStringList stores
Canonical (or cleaned) store path.
QList< QSet< QString > > keys
Fingerprints of the signing key.
Holds the password generator settings: which character set is selected, the alphabet of every set,...
int length
Length of the generated password, in characters.
CharacterSet selected
Currently active character set selection.
CharacterSet
Character set options for password generation; also the index into Characters.
std::array< QString, CHARSETS_COUNT > Characters
The alphabet of each character set, indexed by CharacterSet. Only the CUSTOM entry is meant to be cha...
One named password store: where it is, how its .gpg-id is signed and, optionally, its own Git switche...
Definition profile.h:26
std::optional< bool > autoPush
Push after commits; unset = global.
Definition profile.h:30
QString path
Password store directory.
Definition profile.h:27
std::optional< bool > autoPull
Pull on start; unset = global.
Definition profile.h:31
std::optional< bool > useGit
Git on/off; unset follows the global.
Definition profile.h:29
QString signingKey
Key(s) that sign this store's .gpg-id.
Definition profile.h:28
UsersDialog, the recipient picker for a folder's .gpg-id.
Util: static helpers for the process environment, binary discovery, store paths, URL safety and the l...
WindowStateStore: saves and restores top-level window geometry through QtPassSettings,...