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

IJHack / QtPass / 45478341018

24 Nov 2026 08:12PM UTC coverage: 94.775% (-0.004%) from 94.779%
45478341018

push

github

web-flow
First-run wizard: take gpg's listing when it exits with 2 (#2321)

gpg exits with 2 after a complete secret-key listing when one key in
the keyring is one it cannot handle (an unsupported algorithm, a
broken subkey). FirstRunWizard::secretKeys() threw that listing away,
so the key page claimed there was no secret key yet and pushed the
user towards generating a new one.

secretKeys() now parses the listing on exit 2 and returns gpg's
stderr through an optional problem argument. The message goes through
Util::displayable() and is cut to 400 characters, and the key page
shows it in a plain-text label instead of the "no secret key yet"
hint. Any other failure still lists no keys.

Scan: ANT-2026-S38OMDEL

Signed-off-by: Anne Jan Brouwer <brouwer@annejan.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

15 of 16 new or added lines in 1 file covered. (93.75%)

9868 of 10412 relevant lines covered (94.78%)

20736.83 hits per line

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

99.7
/src/firstrunwizard.cpp
1
// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
/**
4
 * @file
5
 * @brief Implements FirstRunWizard and its pages; the store is created and
6
 * initialised in FirstRunWizard::initialiseStore() on Finish.
7
 */
8
#include "firstrunwizard.h"
9
#include "executor.h"
10
#include "gpgkeystate.h"
11
#include "imitatepass.h"
12
#include "keygendialog.h"
13
#include "passbackendfactory.h"
14
#include "plainmessagebox.h"
15
#include "profileinit.h"
16
#include "qtpasssettings.h"
17
#include "settingsconstants.h"
18
#include "util.h"
19
#include <QCheckBox>
20
#include <QDateTime>
21
#include <QDir>
22
#include <QFile>
23
#include <QFileDialog>
24
#include <QFileInfo>
25
#include <QFormLayout>
26
#include <QHBoxLayout>
27
#include <QLabel>
28
#include <QLineEdit>
29
#include <QListWidget>
30
#include <QMessageBox>
31
#include <QPushButton>
32
#include <QSystemTrayIcon>
33
#include <QToolButton>
34
#include <QVBoxLayout>
35
#include <functional>
36
#ifdef Q_OS_WIN
37
#include <windows.h>
38
#endif
39

40
namespace {
41

42
/// A line edit with a "…" button that opens a file or folder picker.
43
auto pathRow(QLineEdit *edit, QWidget *parent,
112 ✔
44
             const std::function<QString()> &pick) -> QWidget * {
45
  auto *row = new QWidget(parent);
112 ✔
46
  auto *layout = new QHBoxLayout(row);
112 ✔
47
  layout->setContentsMargins(0, 0, 0, 0);
112 ✔
48
  layout->addWidget(edit);
112 ✔
49
  auto *browse = new QToolButton(row);
112 ✔
50
  browse->setText(QStringLiteral("…"));
224 ✔
51
  browse->setToolTip(FirstRunWizard::tr("Browse"));
112 ✔
52
  layout->addWidget(browse);
112 ✔
53
  QObject::connect(browse, &QToolButton::clicked, edit, [edit, pick]() {
224 ✔
54
    const QString chosen = pick();
3 ✔
55
    if (!chosen.isEmpty()) {
3 ✔
56
      edit->setText(chosen);
2 ✔
57
      emit edit->textEdited(chosen);
2 ✔
58
    }
59
  });
3 ✔
60
  return row;
112 ✔
61
}
62

63
auto runnable(const QString &exe) -> bool {
229 ✔
64
  return Executor::parseWslCommand(exe).has_value() ||
229 ✔
65
         (!exe.isEmpty() && QFileInfo(exe).isExecutable());
229 ✔
66
}
67

68
} // namespace
69

70
// --------------------------------------------------------------------------
71

72
FirstRunWizard::FirstRunWizard(QWidget *parent)
28 ✔
73
    : QWizard(parent), m_settings(QtPassSettings::load()),
28 ✔
74
      m_detectChoices(QtPassSettings::getInstance()
28 ✔
75
                          ->value(SettingsConstants::firstRunPending, false)
56 ✔
76
                          .toBool()) {
56 ✔
77
  setWindowTitle(tr("Welcome to QtPass"));
28 ✔
78
  setWizardStyle(QWizard::ModernStyle);
28 ✔
79
  setOption(QWizard::NoBackButtonOnStartPage);
28 ✔
80
  setOption(QWizard::HaveHelpButton, false);
28 ✔
81

82
  auto *intro = new QWizardPage(this);
28 ✔
83
  intro->setTitle(tr("Welcome to QtPass"));
28 ✔
84
  auto *introLayout = new QVBoxLayout(intro);
28 ✔
85
  auto *introText = new QLabel(
86
      tr("QtPass is a graphical front-end for <i>pass</i>, the standard Unix "
28 ✔
87
         "password manager: every password is a file encrypted with GnuPG, "
88
         "kept in a folder you can put under Git.<br><br>The next pages find "
89
         "GnuPG, make sure you have a key to encrypt to and pick the folder "
90
         "your passwords live in. Nothing is written until you press "
91
         "Finish."),
92
      intro);
28 ✔
93
  introText->setWordWrap(true);
28 ✔
94
  introText->setTextFormat(Qt::RichText);
28 ✔
95
  introLayout->addWidget(introText);
28 ✔
96
  setPage(IntroPage, intro);
28 ✔
97
  setPage(ProgramsPage, new ProgramsWizardPage(this));
28 ✔
98
  setPage(KeyPage, new KeyWizardPage(this));
28 ✔
99
  setPage(StorePage, new StoreWizardPage(this));
28 ✔
100
  setPage(DonePage, new DoneWizardPage(this));
28 ✔
101
  setStartId(IntroPage);
28 ✔
102
  resize(640, 480);
103
}
28 ✔
104

105
auto FirstRunWizard::secretKeys(const QString &gpgExecutable, QString *problem)
23 ✔
106
    -> QList<UserInfo> {
107
  if (!runnable(gpgExecutable)) {
23 ✔
108
    return {};
2 ✔
109
  }
110
  QString out;
21 ✔
111
  QString err;
21 ✔
112
  const int rc = Executor::executeBlocking(
126 ✔
113
      gpgExecutable,
114
      {QStringLiteral("--no-tty"), QStringLiteral("--with-colons"),
21 ✔
115
       QStringLiteral("--with-fingerprint"),
21 ✔
116
       QStringLiteral("--list-secret-keys")},
21 ✔
117
      &out, &err);
118
  if (rc != 0 && problem != nullptr) {
21 ✔
119
    constexpr qsizetype kMaxProblem = 400;
120
    // It may quote a user ID someone else chose: no bidi overrides or other
121
    // controls that change how the text around them reads.
122
    *problem = Util::displayable(err.trimmed());
8 ✔
123
    if (problem->size() > kMaxProblem) {
4 ✔
NEW
124
      *problem = problem->left(kMaxProblem) + QChar(0x2026);
×
125
    }
126
  }
127
  // Exit 2 is gpg's "an error occurred", also after a complete listing in
128
  // which one key could not be handled: setup must not stall on that key.
129
  if (rc != 0 && rc != 2) {
21 ✔
130
    return {};
2 ✔
131
  }
132
  return parseGpgColonOutput(out, true);
19 ✔
133
}
134

135
auto FirstRunWizard::isStore(const QString &path) -> bool {
178 ✔
136
  return !path.isEmpty() &&
178 ✔
137
         QFile::exists(QDir(path).filePath(QStringLiteral(".gpg-id")));
534 ✔
138
}
139

140
auto FirstRunWizard::initialiseStore(const QString &store) -> bool {
5 ✔
141
  QList<UserInfo> recipients;
5 ✔
142
  for (const UserInfo &key : std::as_const(m_keys)) {
10 ✔
143
    if (key.enabled) {
5 ✔
144
      recipients.append(key);
145
    }
146
  }
147
  const bool created = !QDir(store).exists();
5 ✔
148
  if (created && !Util::mkpathForStore(store)) {
5 ✔
149
    PlainMessageBox::warning(
1 ✔
150
        this, tr("Error"),
1 ✔
151
        tr("Failed to create password-store at: %1").arg(store));
2 ✔
152
    return false;
1 ✔
153
  }
154
#ifdef Q_OS_WIN
155
  // Only a folder made here is hidden, like ~/.password-store on Unix; a
156
  // folder the user picked keeps its attributes.
157
  if (created) {
158
    SetFileAttributes(store.toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN);
159
  }
160
#endif
161
  QString note;
4 ✔
162
  if (!ProfileInit::initialise(store, recipients, m_settings, m_settings.useGit,
4 ✔
163
                               &note)) {
164
    // ProfileInit writes .gpg-id before it signs and commits; take it back so
165
    // a second Finish runs the whole initialisation again instead of finding
166
    // a store that looks finished.
167
    QFile::remove(QDir(store).filePath(QStringLiteral(".gpg-id")));
2 ✔
168
    QFile::remove(QDir(store).filePath(QStringLiteral(".gpg-id.sig")));
2 ✔
169
    PlainMessageBox::warning(this, tr("Password store not initialised"), note);
1 ✔
170
    return false;
1 ✔
171
  }
172
  if (!note.isEmpty()) {
3 ✔
173
    // ProfileInit's own note talks of switching profiles; on the first run
174
    // the folder simply becomes the store.
175
    PlainMessageBox::show(
2 ✔
176
        this, QMessageBox::Information, tr("Password store"),
1 ✔
177
        tr("%1 already contains encrypted files; they were not "
1 ✔
178
           "re-encrypted to the ticked keys. Open Users after the start "
179
           "to do that.")
180
            .arg(QDir::toNativeSeparators(store)));
2 ✔
181
  }
182
  return true;
183
}
184

185
auto FirstRunWizard::initialiseGit(const QString &store) -> bool {
3 ✔
186
  QString note;
3 ✔
187
  if (ProfileInit::initGit(store, m_settings, &note)) {
3 ✔
188
    return true;
189
  }
190
  // Take the repository back too, so a second Finish retries the whole thing
191
  // instead of skipping a .git that never got its first commit.
192
  QDir(QDir(store).filePath(QStringLiteral(".git"))).removeRecursively();
4 ✔
193
  PlainMessageBox::warning(this, tr("Password store not initialised"), note);
2 ✔
194
  return false;
2 ✔
195
}
196

197
void FirstRunWizard::accept() {
9 ✔
198
  // The Finish button validates the page before calling this; a programmatic
199
  // accept() gets the same treatment so the last page's choices are in.
200
  if (currentPage() != nullptr && !currentPage()->validatePage()) {
9 ✔
201
    return;
4 ✔
202
  }
203
  const QString store = QDir::cleanPath(m_settings.passStore);
9 ✔
204
  const bool needsGit =
205
      m_settings.useGit && !QDir(store).exists(QStringLiteral(".git"));
13 ✔
206
  const bool ready = !isStore(store) ? initialiseStore(store)
9 ✔
207
                     : needsGit      ? initialiseGit(store)
4 ✔
208
                                     : true;
209
  if (!ready) {
8 ✔
210
    return;
211
  }
212
  m_settings.passStore = Util::normalizeFolderPath(store);
5 ✔
213
  QtPassSettings::save(m_settings);
5 ✔
214
  // Chosen now: a later run (the store lost its list) keeps these choices.
215
  QtPassSettings::getInstance()->remove(SettingsConstants::firstRunPending);
5 ✔
216
  // The backend cached the old paths at construction.
217
  PassBackendFactory::invalidate();
5 ✔
218
  QWizard::accept();
5 ✔
219
}
220

221
// --------------------------------------------------------------------------
222

223
ProgramsWizardPage::ProgramsWizardPage(FirstRunWizard *wizard)
28 ✔
224
    : QWizardPage(wizard), m_wizard(wizard), m_gpg(new QLineEdit(this)),
28 ✔
225
      m_git(new QLineEdit(this)), m_pass(new QLineEdit(this)),
28 ✔
226
      m_usePass(new QCheckBox(tr("Use the pass command-line tool"), this)),
56 ✔
227
      m_gpgStatus(new QLabel(this)) {
56 ✔
228
  setTitle(tr("Programs"));
56 ✔
229
  setSubTitle(tr("GnuPG does the encrypting. pass and Git are optional; "
28 ✔
230
                 "QtPass can do their work itself."));
231
  auto *layout = new QFormLayout(this);
28 ✔
232
  auto pickExe = [this]() {
2 ✔
233
    return QFileDialog::getOpenFileName(this, tr("Select executable"),
2 ✔
234
                                        QString(), tr("All files (*)"));
4 ✔
235
  };
236
  layout->addRow(tr("GnuPG"), pathRow(m_gpg, this, pickExe));
84 ✔
237
  m_gpgStatus->setWordWrap(true);
28 ✔
238
  layout->addRow(QString(), m_gpgStatus);
56 ✔
239
  layout->addRow(tr("Git"), pathRow(m_git, this, pickExe));
84 ✔
240
  layout->addRow(tr("pass"), pathRow(m_pass, this, pickExe));
84 ✔
241
  m_usePass->setToolTip(tr("Run the pass script for every operation instead "
28 ✔
242
                           "of calling gpg and git directly"));
243
  layout->addRow(QString(), m_usePass);
28 ✔
244
  for (QLineEdit *edit : {m_gpg, m_git, m_pass}) {
112 ✔
245
    connect(edit, &QLineEdit::textEdited, this,
84 ✔
246
            &ProgramsWizardPage::updateStatus);
168 ✔
247
  }
248
}
28 ✔
249

250
void ProgramsWizardPage::initializePage() {
16 ✔
251
  AppSettings &s = m_wizard->m_settings;
16 ✔
252
  // QtPassSettings::initExecutables() fills empty paths from PATH only; a
253
  // stored path whose binary has moved would be shown as an error here, so
254
  // look it up again in that case.
255
  auto detect = [](QString &stored, const QStringList &names) {
64 ✔
256
    if (runnable(stored)) {
64 ✔
257
      return;
258
    }
259
    for (const QString &name : names) {
80 ✔
260
      const QString found = Util::findBinaryInPath(name);
42 ✔
261
      if (!found.isEmpty()) {
42 ✔
262
        stored = found;
1 ✔
263
        return;
264
      }
265
    }
266
  };
267
  detect(s.gpgExecutable, {QStringLiteral("gpg2"), QStringLiteral("gpg")});
64 ✔
268
  detect(s.gitExecutable, {QStringLiteral("git")});
48 ✔
269
  detect(s.passExecutable, {QStringLiteral("pass")});
48 ✔
270
  detect(s.pwgenExecutable, {QStringLiteral("pwgen")});
48 ✔
271
  m_gpg->setText(s.gpgExecutable);
16 ✔
272
  m_git->setText(s.gitExecutable);
16 ✔
273
  m_pass->setText(s.passExecutable);
16 ✔
274
  // Detected only the first time: a choice saved before (the wizard also
275
  // runs for a store whose recipient list went missing) stays, or Next and
276
  // Finish switched the backend without a word.
277
  m_usePass->setChecked(m_wizard->m_detectChoices
32 ✔
278
                            ? s.usePass || runnable(s.passExecutable)
13 ✔
279
                            : s.usePass);
3 ✔
280
  updateStatus();
16 ✔
281
}
16 ✔
282

283
void ProgramsWizardPage::updateStatus() {
19 ✔
284
  const QString gpg = m_gpg->text().trimmed();
38 ✔
285
  if (gpg.isEmpty()) {
19 ✔
286
    m_gpgStatus->setText(tr("GnuPG was not found. Install it (gpg or gpg2) "
4 ✔
287
                            "and enter its location here."));
288
  } else if (!runnable(gpg)) {
17 ✔
289
    m_gpgStatus->setText(tr("%1 is not an executable file.").arg(gpg));
2 ✔
290
  } else {
291
    m_gpgStatus->setText(QString());
32 ✔
292
  }
293
  m_usePass->setEnabled(runnable(m_pass->text().trimmed()));
38 ✔
294
  if (!m_usePass->isEnabled()) {
19 ✔
295
    m_usePass->setChecked(false);
16 ✔
296
  }
297
  emit completeChanged();
19 ✔
298
}
19 ✔
299

300
auto ProgramsWizardPage::isComplete() const -> bool {
71 ✔
301
  return runnable(m_gpg->text().trimmed());
213 ✔
302
}
303

304
auto ProgramsWizardPage::validatePage() -> bool {
12 ✔
305
  AppSettings &s = m_wizard->m_settings;
12 ✔
306
  s.gpgExecutable = m_gpg->text().trimmed();
12 ✔
307
  s.gitExecutable = m_git->text().trimmed();
12 ✔
308
  s.passExecutable = m_pass->text().trimmed();
12 ✔
309
  s.usePass = m_usePass->isChecked();
12 ✔
310
  return true;
12 ✔
311
}
312

313
// --------------------------------------------------------------------------
314

315
KeyWizardPage::KeyWizardPage(FirstRunWizard *wizard)
28 ✔
316
    : QWizardPage(wizard), m_wizard(wizard), m_list(new QListWidget(this)),
28 ✔
317
      m_generate(new QPushButton(tr("Generate a new key pair…"), this)),
56 ✔
318
      m_status(new QLabel(this)) {
56 ✔
319
  setTitle(tr("Your key"));
56 ✔
320
  setSubTitle(tr("Passwords are encrypted to GnuPG keys. Tick the keys that "
28 ✔
321
                 "should be able to open a new store; you need at least one "
322
                 "with its secret half on this machine."));
323
  auto *layout = new QVBoxLayout(this);
28 ✔
324
  layout->addWidget(m_list);
28 ✔
325
  // What gpg reports is shown here: as text, never as markup.
326
  m_status->setTextFormat(Qt::PlainText);
28 ✔
327
  m_status->setWordWrap(true);
28 ✔
328
  layout->addWidget(m_status);
28 ✔
329
  auto *buttons = new QHBoxLayout;
28 ✔
330
  buttons->addStretch();
28 ✔
331
  buttons->addWidget(m_generate);
28 ✔
332
  layout->addLayout(buttons);
28 ✔
333
  connect(m_generate, &QPushButton::clicked, this, &KeyWizardPage::generate);
28 ✔
334
  connect(m_list, &QListWidget::itemChanged, this,
28 ✔
335
          [this]() { emit completeChanged(); });
69 ✔
336
}
28 ✔
337

338
void KeyWizardPage::initializePage() { reload(); }
17 ✔
339

340
void KeyWizardPage::reload() {
18 ✔
341
  QString problem;
18 ✔
342
  m_wizard->m_keys =
18 ✔
343
      FirstRunWizard::secretKeys(m_wizard->m_settings.gpgExecutable, &problem);
18 ✔
344
  m_list->clear();
18 ✔
345
  const QDateTime now = QDateTime::currentDateTime();
18 ✔
346
  for (UserInfo &key : m_wizard->m_keys) {
55 ✔
347
    // An expired or otherwise unusable key would make every encryption to
348
    // the new store fail; list it, but do not tick it.
349
    QString why;
19 ✔
350
    if (key.expiry.isValid() && key.expiry < now) {
20 ✔
351
      why = tr("expired");
1 ✔
352
    } else if (!key.isValid()) {
353
      why = tr("not usable");
1 ✔
354
    }
355
    key.enabled = why.isEmpty();
19 ✔
356
    QString label = QStringLiteral("%1\n%2").arg(key.name, key.key_id);
38 ✔
357
    if (!why.isEmpty()) {
19 ✔
358
      label += QStringLiteral(" (%1)").arg(why);
4 ✔
359
    }
360
    auto *item = new QListWidgetItem(label, m_list);
19 ✔
361
    item->setFlags(key.enabled ? (item->flags() | Qt::ItemIsUserCheckable)
38 ✔
362
                               : (item->flags() & ~Qt::ItemIsEnabled));
363
    item->setCheckState(key.enabled ? Qt::Checked : Qt::Unchecked);
21 ✔
364
  }
365
  // gpg's own words when it did not exit cleanly: "no secret key yet" would
366
  // send the user to make a key they may well have.
367
  if (!problem.isEmpty()) {
18 ✔
368
    //: %1 is what GnuPG reported, in its own words.
369
    m_status->setText(tr("GnuPG reported a problem while listing the secret "
4 ✔
370
                         "keys:\n%1")
371
                          .arg(problem));
4 ✔
372
  } else {
373
    m_status->setText(
16 ✔
374
        m_wizard->m_keys.isEmpty()
16 ✔
375
            ? tr("GnuPG has no secret key yet. Generate one here, "
32 ✔
376
                 "or import your existing key with gpg first.")
377
            : QString());
378
  }
379
  emit completeChanged();
18 ✔
380
}
36 ✔
381

382
void KeyWizardPage::generate() {
1 ✔
383
  // A backend of the wizard's own, set up from its copy of the settings, so
384
  // the chosen gpg is used and nothing is written before Finish. Each Pass
385
  // owns its Executor; the shared backend is not involved.
386
  ImitatePass pass;
1 ✔
387
  pass.init(m_wizard->m_settings);
1 ✔
388
  KeygenDialog d(m_wizard->m_settings.gpgExecutable, &pass, this);
1 ✔
389
  d.exec();
1 ✔
390
  reload();
1 ✔
391
}
1 ✔
392

393
auto KeyWizardPage::isComplete() const -> bool { return true; }
147 ✔
394

395
auto KeyWizardPage::validatePage() -> bool {
17 ✔
396
  for (int i = 0; i < m_list->count() && i < m_wizard->m_keys.size(); ++i) {
40 ✔
397
    m_wizard->m_keys[i].enabled = m_list->item(i)->checkState() == Qt::Checked;
23 ✔
398
  }
399
  return true;
17 ✔
400
}
401

402
// --------------------------------------------------------------------------
403

404
StoreWizardPage::StoreWizardPage(FirstRunWizard *wizard)
28 ✔
405
    : QWizardPage(wizard), m_wizard(wizard), m_path(new QLineEdit(this)),
28 ✔
406
      m_useGit(new QCheckBox(tr("Keep the store under Git"), this)),
56 ✔
407
      m_status(new QLabel(this)) {
56 ✔
408
  setTitle(tr("Password store"));
56 ✔
409
  setSubTitle(tr("The folder your passwords live in. An existing store is "
28 ✔
410
                 "used as it is; an empty or missing folder is set up for "
411
                 "the keys you ticked."));
412
  auto *layout = new QFormLayout(this);
28 ✔
413
  layout->addRow(tr("Folder"), pathRow(m_path, this, [this]() {
84 ✔
414
                   return QFileDialog::getExistingDirectory(
415
                       this, tr("Choose the password store folder"),
1 ✔
416
                       m_path->text());
3 ✔
417
                 }));
418
  m_status->setWordWrap(true);
28 ✔
419
  layout->addRow(QString(), m_status);
28 ✔
420
  layout->addRow(QString(), m_useGit);
28 ✔
421
  connect(m_path, &QLineEdit::textEdited, this, &StoreWizardPage::updateStatus);
28 ✔
422
}
28 ✔
423

424
void StoreWizardPage::initializePage() {
22 ✔
425
  QString path = m_wizard->m_settings.passStore;
22 ✔
426
  if (path.isEmpty()) {
22 ✔
427
    path = Util::findPasswordStore();
10 ✔
428
  }
429
  m_path->setText(QDir::toNativeSeparators(QDir::cleanPath(path)));
22 ✔
430
  const QString clean = QDir::cleanPath(path);
22 ✔
431
  const bool repository = QDir(clean).exists(QStringLiteral(".git"));
44 ✔
432
  bool haveGit = runnable(m_wizard->m_settings.gitExecutable);
22 ✔
433
  // A first commit needs a name and an e-mail; without them Finish would
434
  // fail at the very end. Ask git now and say what to do instead.
435
  const bool identity =
436
      haveGit && (repository || ProfileInit::gitIdentityConfigured(
31 ✔
437
                                    QDir::homePath(), m_wizard->m_settings));
9 ✔
438
  m_useGit->setToolTip(
22 ✔
439
      haveGit && !identity
22 ✔
440
          ? tr("Git has no name and e-mail to commit with yet. Run\n"
22 ✔
441
               "git config --global user.name \"Your Name\"\n"
442
               "git config --global user.email you@example.org\n"
443
               "and turn Git on in Settings afterwards.")
444
          : tr("Every change becomes a commit; a folder that is no "
445
               "repository yet gets one"));
446
  haveGit = haveGit && identity;
22 ✔
447
  m_useGit->setEnabled(haveGit);
22 ✔
448
  // On for a repository or a store still to be made, off for an existing
449
  // store that is no repository: turning Git on there would make every
450
  // remove fail in a folder git knows nothing about. A choice saved before
451
  // stays (see ProgramsWizardPage::initializePage()).
452
  m_useGit->setChecked(haveGit &&
44 ✔
453
                       (m_wizard->m_detectChoices
11 ✔
454
                            ? m_wizard->m_settings.useGit || repository ||
13 ✔
455
                                  !FirstRunWizard::isStore(clean)
4 ✔
456
                            : m_wizard->m_settings.useGit));
2 ✔
457
  updateStatus();
22 ✔
458
}
22 ✔
459

460
auto StoreWizardPage::recipients() const -> int {
94 ✔
461
  int ticked = 0;
462
  for (const UserInfo &key : std::as_const(m_wizard->m_keys)) {
202 ✔
463
    ticked += key.enabled ? 1 : 0;
158 ✔
464
  }
465
  return ticked;
94 ✔
466
}
467

468
void StoreWizardPage::updateStatus() {
30 ✔
469
  const QString path = QDir::cleanPath(m_path->text().trimmed());
60 ✔
470
  QString text;
30 ✔
471
  if (path.isEmpty()) {
30 ✔
472
    text = tr("Enter a folder.");
1 ✔
473
  } else if (FirstRunWizard::isStore(path)) {
29 ✔
474
    const int entries = static_cast<int>(
475
        Util::regularFilesUnder(path, {QStringLiteral("*.gpg")}).size());
21 ✔
476
    text = tr("An existing password store with %n entries.", nullptr, entries);
7 ✔
477
  } else if (QDir(path).exists()) {
22 ✔
478
    text = QDir(path).isEmpty()
12 ✔
479
               ? tr("An empty folder; it will be set up as a password store.")
12 ✔
480
               : tr("This folder is not a password store yet; a .gpg-id for "
481
                    "the ticked keys will be written into it.");
482
  } else {
483
    text = tr("The folder does not exist yet; it will be created.");
16 ✔
484
  }
485
  if (!path.isEmpty() && !FirstRunWizard::isStore(path) && recipients() == 0) {
30 ✔
486
    text += QLatin1Char(' ') +
9 ✔
487
            tr("Go back and tick at least one key to encrypt it to.");
18 ✔
488
  }
489
  m_status->setText(text);
30 ✔
490
  emit completeChanged();
30 ✔
491
}
30 ✔
492

493
auto StoreWizardPage::isComplete() const -> bool {
100 ✔
494
  const QString path = QDir::cleanPath(m_path->text().trimmed());
300 ✔
495
  if (path.isEmpty()) {
100 ✔
496
    return false;
497
  }
498
  return FirstRunWizard::isStore(path) || recipients() > 0;
97 ✔
499
}
500

501
auto StoreWizardPage::validatePage() -> bool {
11 ✔
502
  m_wizard->m_settings.passStore =
11 ✔
503
      QDir::fromNativeSeparators(m_path->text().trimmed());
22 ✔
504
  m_wizard->m_settings.useGit = m_useGit->isEnabled() && m_useGit->isChecked();
11 ✔
505
  return true;
11 ✔
506
}
507

508
// --------------------------------------------------------------------------
509

510
DoneWizardPage::DoneWizardPage(FirstRunWizard *wizard)
28 ✔
511
    : QWizardPage(wizard), m_wizard(wizard), m_summary(new QLabel(this)),
28 ✔
512
      m_hidePassword(new QCheckBox(tr("Hide passwords until asked"), this)),
56 ✔
513
      m_trayIcon(new QCheckBox(tr("Show an icon in the system tray"), this)) {
84 ✔
514
  setTitle(tr("Ready"));
56 ✔
515
  setSubTitle(tr("Everything else can be changed later in Settings."));
28 ✔
516
  auto *layout = new QVBoxLayout(this);
28 ✔
517
  m_summary->setWordWrap(true);
28 ✔
518
  m_summary->setTextFormat(Qt::RichText);
28 ✔
519
  layout->addWidget(m_summary);
28 ✔
520
  layout->addSpacing(12);
28 ✔
521
  m_hidePassword->setToolTip(
28 ✔
522
      tr("Show the password line as dots; Show password reveals it"));
28 ✔
523
  layout->addWidget(m_hidePassword);
28 ✔
524
  layout->addWidget(m_trayIcon);
28 ✔
525
  layout->addStretch();
28 ✔
526
  setFinalPage(true);
28 ✔
527
}
28 ✔
528

529
void DoneWizardPage::initializePage() {
10 ✔
530
  const AppSettings &s = m_wizard->m_settings;
10 ✔
531
  const QString store = QDir::toNativeSeparators(QDir::cleanPath(s.passStore));
10 ✔
532
  QStringList lines;
10 ✔
533
  lines << tr("Store: %1").arg(store.toHtmlEscaped());
20 ✔
534
  if (FirstRunWizard::isStore(s.passStore)) {
10 ✔
535
    lines << tr("It is already a password store and is used as it is.");
4 ✔
536
  } else if (s.useGit) {
6 ✔
537
    lines << tr("It will be set up for the ticked keys and put under Git.");
2 ✔
538
  } else {
539
    lines << tr("It will be set up for the ticked keys.");
4 ✔
540
  }
541
  lines << tr("GnuPG: %1").arg(s.gpgExecutable.toHtmlEscaped());
20 ✔
542
  lines << (s.usePass ? tr("Operations run through pass.")
10 ✔
543
                      : tr("Operations run through gpg and git directly."));
544
  m_summary->setText(lines.join(QStringLiteral("<br>")));
20 ✔
545
  m_hidePassword->setChecked(true);
10 ✔
546
  const bool tray = QSystemTrayIcon::isSystemTrayAvailable();
10 ✔
547
  m_trayIcon->setVisible(tray);
10 ✔
548
  m_trayIcon->setChecked(tray && s.useTrayIcon);
10 ✔
549
}
10 ✔
550

551
auto DoneWizardPage::validatePage() -> bool {
14 ✔
552
  m_wizard->m_settings.hidePassword = m_hidePassword->isChecked();
14 ✔
553
  m_wizard->m_settings.useTrayIcon =
14 ✔
554
      m_trayIcon->isVisible() && m_trayIcon->isChecked();
14 ✔
555
  return true;
14 ✔
556
}
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