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

IJHack / QtPass / 27688530046

17 Jun 2026 12:21PM UTC coverage: 57.501% (+0.02%) from 57.477%
27688530046

push

github

web-flow
refactor(pass): inject AppSettings into Pass hierarchy (PR A of #1511) (#1551)

* refactor(pass): inject AppSettings into Pass hierarchy (PR A of #1511)

- Pass::init(AppSettings) replaces no-arg init(); backends store
  m_settings and read executables/paths from it instead of calling
  QtPassSettings getters at runtime
- ImitatePass::pgit/pgpg converted from static free functions to const
  member functions; grepMatchFile (static) inlines the wslpath check
  using its gpgExe parameter
- PassBackendFactory::getPass() loads AppSettings via QtPassSettings::load()
  and normalises passStore via QtPassSettings::getPassStore(), then passes
  the snapshot to pass->init(s)
- realpass.cpp and imitatepass.cpp no longer include qtpasssettings.h
- Integration test and tst_util updated: call pass.init(s) after
  configuring QtPassSettings so m_settings is populated before updateEnv()

Two QtPassSettings calls remain in passbackendfactory.cpp (load + getPassStore);
removal of getGpgIdPath's QtPassSettings dependency is deferred to PR C.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: apply CodeRabbit auto-fixes

Fixed 2 file(s) based on 3 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>

* fix: address review findings on AppSettings injection

- keygendialog: pass getGpgExecutable() to getDefaultKeyTemplate() so
  gpgSupportsEd25519 uses the configured binary, not the "gpg" fallback
  (P1: silent regression on systems where gpg is GPG 1.x but user
  configured gpg2)
- QtPassSettings::load(): normalise passStore (absolutePath + trailing
  slash) so callers get a usable path without a separate getPassStore()
  override; SettingsSerializer::load() preserves raw stored value for
  round-trip fidelity (P2: duplicate override pattern removed)
- passbackendfactory: drop s.passStore = getPassStore() override; inline
  mkdir for first-run directory creation
- pass.cpp: fix clang-format violations (ColumnLimit=80 line breaks... (continued)

52 of 92 new or added lines in 6 files covered. (56.52%)

13 existing lines in 6 files now uncovered.

3990 of 6939 relevant lines covered (57.5%)

23.81 hits per line

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

96.15
/src/qtpasssettings.cpp
1
// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3

4
/**
5
 * @class QtPassSettings
6
 * @brief Singleton settings manager implementation.
7
 *
8
 * Implementation of QtPassSettings singleton. Handles persistence using
9
 * QSettings with support for portable mode (qtpass.ini next to executable).
10
 *
11
 * @see qtpasssettings.h
12
 */
13

14
#include "qtpasssettings.h"
15
#include "pass.h"
16
#include "passbackendfactory.h"
17
#include "settingsserializer.h"
18

19
#include "util.h"
20

21
#include <QCoreApplication>
22
#include <QCursor>
23
#include <QDebug>
24
#include <QGuiApplication>
25
#include <QScreen>
26
#include <utility>
27

28
bool QtPassSettings::initialized = false;
29

30
QtPassSettings *QtPassSettings::m_instance = nullptr;
31
/**
32
 * @brief Returns the singleton instance of QtPassSettings, creating it on first
33
 * access.
34
 * @example
35
 * QtPassSettings *settings = QtPassSettings::getInstance();
36
 * std::cout << settings << std::endl; // Expected output sample: a valid
37
 * QtPassSettings pointer
38
 *
39
 * @return QtPassSettings* - Pointer to the shared QtPassSettings instance.
40
 */
41
auto QtPassSettings::getInstance() -> QtPassSettings * {
1,510✔
42
  if (!QtPassSettings::initialized) {
1,510✔
43
    QString portable_ini = QCoreApplication::applicationDirPath() +
10✔
44
                           QDir::separator() + "qtpass.ini";
10✔
45
    if (QFile(portable_ini).exists()) {
10✔
46
      m_instance = new QtPassSettings(portable_ini, QSettings::IniFormat);
×
47
    } else {
48
      m_instance = new QtPassSettings("IJHack", "QtPass");
20✔
49
    }
50

51
    initialized = true;
10✔
52
  }
53

54
  return m_instance;
1,510✔
55
}
56

57
auto QtPassSettings::load() -> AppSettings {
46✔
58
  AppSettings s = SettingsSerializer::load(*getInstance());
46✔
59
  if (!s.passStore.isEmpty()) {
46✔
60
    s.passStore = QDir::cleanPath(QDir(s.passStore).absolutePath());
92✔
61
    if (!s.passStore.endsWith('/'))
46✔
62
      s.passStore += '/';
46✔
63
  }
64
  return s;
46✔
UNCOV
65
}
×
66

67
void QtPassSettings::save(const AppSettings &settings) {
1✔
68
  SettingsSerializer::save(*getInstance(), settings);
1✔
69
  // A settings save may have changed the "use pass" mode; drop the cached
70
  // backend so the correct one is rebuilt on next use (matches the previous
71
  // setUsePass() side effect).
72
  PassBackendFactory::invalidate();
1✔
73
}
1✔
74

75
/**
76
 * @brief Retrieves the current password configuration from application
77
 * settings.
78
 * @example
79
 * PasswordConfiguration result = QtPassSettings::getPasswordConfiguration();
80
 * std::cout << result.length << std::endl; // Expected output sample
81
 *
82
 * @return PasswordConfiguration - The password configuration populated from
83
 * stored settings, including length, selected character set, and custom
84
 * characters.
85
 */
86
auto QtPassSettings::getPasswordConfiguration() -> PasswordConfiguration {
7✔
87
  PasswordConfiguration config;
7✔
88

89
  config.length =
7✔
90
      getInstance()->value(SettingsConstants::passwordLength, 16).toInt();
7✔
91
  if (config.length <= 0) {
7✔
92
    config.length = 16;
×
93
  }
94
  config.selected = static_cast<PasswordConfiguration::characterSet>(
7✔
95
      getInstance()
7✔
96
          ->value(SettingsConstants::passwordCharsSelection, 0)
14✔
97
          .toInt());
7✔
98
  config.Characters[PasswordConfiguration::CUSTOM] =
99
      getInstance()
7✔
100
          ->value(SettingsConstants::passwordChars, QString())
14✔
101
          .toString();
7✔
102

103
  return config;
7✔
104
}
×
105

106
void QtPassSettings::setPasswordConfiguration(
3✔
107
    const PasswordConfiguration &config) {
108
  getInstance()->setValue(SettingsConstants::passwordLength, config.length);
3✔
109
  getInstance()->setValue(SettingsConstants::passwordCharsSelection,
6✔
110
                          config.selected);
3✔
111
  getInstance()->setValue(SettingsConstants::passwordChars,
6✔
112
                          config.Characters[PasswordConfiguration::CUSTOM]);
3✔
113
}
3✔
114

115
/**
116
 * @brief Retrieves the stored profiles configuration as a nested hash map.
117
 * @details Reads profile data from the settings group, including legacy profile
118
 *          formats from versions <= v1.3.2, and returns each profile name
119
 * mapped to its properties such as path and signing key.
120
 * @example
121
 * QHash<QString, QHash<QString, QString>> profiles =
122
 * QtPassSettings::getProfiles(); std::cout << profiles.size() << std::endl; //
123
 * Expected output: number of profiles
124
 *
125
 * @return QHash<QString, QHash<QString, QString>> - A hash map of profile names
126
 *         mapped to their key/value properties.
127
 */
128
auto QtPassSettings::getProfiles() -> QHash<QString, QHash<QString, QString>> {
28✔
129
  getInstance()->beginGroup(SettingsConstants::profile);
28✔
130
  QHash<QString, QHash<QString, QString>> profiles;
28✔
131

132
  // migration from version <= v1.3.2: profiles datastructure
133
  QStringList childKeys = getInstance()->childKeys();
28✔
134
  if (!childKeys.empty()) {
28✔
135
    for (const auto &key : std::as_const(childKeys)) {
×
136
      QHash<QString, QString> profile;
×
137
      profile.insert("path", getInstance()->value(key).toString());
×
138
      profile.insert("signingKey", "");
×
139
      profile.insert("useGit", "");
×
140
      profile.insert("autoPush", "");
×
141
      profile.insert("autoPull", "");
×
142
      profiles.insert(key, profile);
143
    }
×
144
  }
145
  // /migration from version <= v1.3.2
146

147
  QStringList childGroups = getInstance()->childGroups();
28✔
148
  for (const auto &group : std::as_const(childGroups)) {
56✔
149
    QHash<QString, QString> profile;
28✔
150
    profile.insert("path", getInstance()->value(group + "/path").toString());
56✔
151
    profile.insert("signingKey",
56✔
152
                   getInstance()->value(group + "/signingKey").toString());
56✔
153
    profile.insert("useGit",
56✔
154
                   getInstance()->value(group + "/useGit").toString());
56✔
155
    profile.insert("autoPush",
56✔
156
                   getInstance()->value(group + "/autoPush").toString());
56✔
157
    profile.insert("autoPull",
56✔
158
                   getInstance()->value(group + "/autoPull").toString());
84✔
159
    profiles.insert(group, profile);
160
  }
28✔
161

162
  getInstance()->endGroup();
28✔
163

164
  return profiles;
28✔
165
}
×
166

167
/**
168
 * @brief Stores the profile settings in the application's configuration.
169
 * @example
170
 * QtPassSettings::setProfiles(profiles);
171
 *
172
 * @param profiles - A hash of profile names mapped to their key-value settings,
173
 * such as "path" and "signingKey".
174
 * @return void - This method does not return a value.
175
 */
176
void QtPassSettings::setProfiles(
3✔
177
    const QHash<QString, QHash<QString, QString>> &profiles) {
178
  getInstance()->remove(SettingsConstants::profile);
3✔
179
  getInstance()->beginGroup(SettingsConstants::profile);
3✔
180

181
  QHash<QString, QHash<QString, QString>>::const_iterator i = profiles.begin();
3✔
182
  for (; i != profiles.end(); ++i) {
3✔
183
    getInstance()->setValue(i.key() + "/path", i.value().value("path"));
6✔
184
    getInstance()->setValue(i.key() + "/signingKey",
9✔
185
                            i.value().value("signingKey"));
3✔
186
    getInstance()->setValue(i.key() + "/useGit", i.value().value("useGit"));
6✔
187
    getInstance()->setValue(i.key() + "/autoPush", i.value().value("autoPush"));
6✔
188
    getInstance()->setValue(i.key() + "/autoPull", i.value().value("autoPull"));
9✔
189
  }
190

191
  getInstance()->endGroup();
3✔
192
}
3✔
193

194
auto QtPassSettings::getPass() -> Pass * {
41✔
195
  return PassBackendFactory::getPass();
41✔
196
}
197

198
auto QtPassSettings::getVersion(const QString &defaultValue) -> QString {
13✔
199
  return getInstance()
13✔
200
      ->value(SettingsConstants::version, defaultValue)
26✔
201
      .toString();
26✔
202
}
203
void QtPassSettings::setVersion(const QString &version) {
13✔
204
  getInstance()->setValue(SettingsConstants::version, version);
13✔
205
}
13✔
206

207
auto QtPassSettings::getGeometry(const QByteArray &defaultValue) -> QByteArray {
13✔
208
  return getInstance()
13✔
209
      ->value(SettingsConstants::geometry, defaultValue)
26✔
210
      .toByteArray();
26✔
211
}
212
void QtPassSettings::setGeometry(const QByteArray &geometry) {
1✔
213
  getInstance()->setValue(SettingsConstants::geometry, geometry);
1✔
214
}
1✔
215

216
auto QtPassSettings::getSavestate(const QByteArray &defaultValue)
13✔
217
    -> QByteArray {
218
  return getInstance()
13✔
219
      ->value(SettingsConstants::savestate, defaultValue)
26✔
220
      .toByteArray();
26✔
221
}
222
void QtPassSettings::setSavestate(const QByteArray &saveState) {
1✔
223
  getInstance()->setValue(SettingsConstants::savestate, saveState);
1✔
224
}
1✔
225

226
auto QtPassSettings::getPos(const QPoint &defaultValue) -> QPoint {
13✔
227
  QPoint pos =
228
      getInstance()->value(SettingsConstants::pos, defaultValue).toPoint();
13✔
229
  if (pos == QPoint(0, 0)) {
230
    QScreen *screen = QGuiApplication::screenAt(QCursor::pos());
12✔
231
    if (!screen)
12✔
232
      screen = QGuiApplication::primaryScreen();
×
233
    if (screen)
×
234
      pos = screen->geometry().center();
12✔
235
  }
236
  return pos;
13✔
237
}
238
void QtPassSettings::setPos(const QPoint &pos) {
1✔
239
  if (pos == QPoint(0, 0))
240
    return;
×
241
  getInstance()->setValue(SettingsConstants::pos, pos);
1✔
242
}
243

244
auto QtPassSettings::getSize(const QSize &defaultValue) -> QSize {
13✔
245
  return getInstance()->value(SettingsConstants::size, defaultValue).toSize();
13✔
246
}
247
void QtPassSettings::setSize(const QSize &size) {
1✔
248
  getInstance()->setValue(SettingsConstants::size, size);
1✔
249
}
1✔
250

251
auto QtPassSettings::isMaximized(const bool &defaultValue) -> bool {
16✔
252
  return getInstance()
16✔
253
      ->value(SettingsConstants::maximized, defaultValue)
32✔
254
      .toBool();
32✔
255
}
256
void QtPassSettings::setMaximized(const bool &maximized) {
2✔
257
  getInstance()->setValue(SettingsConstants::maximized, maximized);
2✔
258
}
2✔
259

260
auto QtPassSettings::getDialogGeometry(const QString &key,
24✔
261
                                       const QByteArray &defaultValue)
262
    -> QByteArray {
263
  return getInstance()
24✔
264
      ->value(SettingsConstants::dialogGeometry + "/" + key, defaultValue)
72✔
265
      .toByteArray();
48✔
266
}
267
void QtPassSettings::setDialogGeometry(const QString &key,
1✔
268
                                       const QByteArray &geometry) {
269
  getInstance()->setValue(SettingsConstants::dialogGeometry + "/" + key,
2✔
270
                          geometry);
271
}
1✔
272

273
auto QtPassSettings::getDialogPos(const QString &key,
1✔
274
                                  const QPoint &defaultValue) -> QPoint {
275
  return getInstance()
1✔
276
      ->value(SettingsConstants::dialogPos + "/" + key, defaultValue)
3✔
277
      .toPoint();
2✔
278
}
279
void QtPassSettings::setDialogPos(const QString &key, const QPoint &pos) {
1✔
280
  getInstance()->setValue(SettingsConstants::dialogPos + "/" + key, pos);
2✔
281
}
1✔
282

283
auto QtPassSettings::getDialogSize(const QString &key,
1✔
284
                                   const QSize &defaultValue) -> QSize {
285
  return getInstance()
1✔
286
      ->value(SettingsConstants::dialogSize + "/" + key, defaultValue)
3✔
287
      .toSize();
2✔
288
}
289
void QtPassSettings::setDialogSize(const QString &key, const QSize &size) {
1✔
290
  getInstance()->setValue(SettingsConstants::dialogSize + "/" + key, size);
2✔
291
}
1✔
292

293
auto QtPassSettings::isDialogMaximized(const QString &key,
25✔
294
                                       const bool &defaultValue) -> bool {
295
  return getInstance()
25✔
296
      ->value(SettingsConstants::dialogMaximized + "/" + key, defaultValue)
75✔
297
      .toBool();
50✔
298
}
299
void QtPassSettings::setDialogMaximized(const QString &key,
2✔
300
                                        const bool &maximized) {
301
  getInstance()->setValue(SettingsConstants::dialogMaximized + "/" + key,
6✔
302
                          maximized);
2✔
303
}
2✔
304

305
auto QtPassSettings::isUsePass(const bool &defaultValue) -> bool {
20✔
306
  return getInstance()
20✔
307
      ->value(SettingsConstants::usePass, defaultValue)
40✔
308
      .toBool();
40✔
309
}
310
void QtPassSettings::setUsePass(const bool &usePass) {
18✔
311
  getInstance()->setValue(SettingsConstants::usePass, usePass);
18✔
312
  // Backend selection changed: force re-selection on next getPass().
313
  PassBackendFactory::invalidate();
18✔
314
}
18✔
315

316
auto QtPassSettings::getClipBoardTypeRaw(
18✔
317
    const Enums::clipBoardType &defaultValue) -> int {
318
  return getInstance()
18✔
319
      ->value(SettingsConstants::clipBoardType, static_cast<int>(defaultValue))
36✔
320
      .toInt();
36✔
321
}
322

323
auto QtPassSettings::getClipBoardType(const Enums::clipBoardType &defaultValue)
5✔
324
    -> Enums::clipBoardType {
325
  return static_cast<Enums::clipBoardType>(getClipBoardTypeRaw(defaultValue));
5✔
326
}
327
void QtPassSettings::setClipBoardType(const int &clipBoardType) {
1✔
328
  getInstance()->setValue(SettingsConstants::clipBoardType, clipBoardType);
1✔
329
}
1✔
330

331
auto QtPassSettings::isUseSelection(const bool &defaultValue) -> bool {
4✔
332
  return getInstance()
4✔
333
      ->value(SettingsConstants::useSelection, defaultValue)
8✔
334
      .toBool();
8✔
335
}
336
void QtPassSettings::setUseSelection(const bool &useSelection) {
2✔
337
  getInstance()->setValue(SettingsConstants::useSelection, useSelection);
2✔
338
}
2✔
339

340
auto QtPassSettings::isUseAutoclear(const bool &defaultValue) -> bool {
4✔
341
  return getInstance()
4✔
342
      ->value(SettingsConstants::useAutoclear, defaultValue)
8✔
343
      .toBool();
8✔
344
}
345
void QtPassSettings::setUseAutoclear(const bool &useAutoclear) {
2✔
346
  getInstance()->setValue(SettingsConstants::useAutoclear, useAutoclear);
2✔
347
}
2✔
348

349
auto QtPassSettings::getAutoclearSeconds(const int &defaultValue) -> int {
14✔
350
  return getInstance()
14✔
351
      ->value(SettingsConstants::autoclearSeconds, defaultValue)
28✔
352
      .toInt();
28✔
353
}
354
void QtPassSettings::setAutoclearSeconds(const int &autoClearSeconds) {
2✔
355
  getInstance()->setValue(SettingsConstants::autoclearSeconds,
2✔
356
                          autoClearSeconds);
357
}
2✔
358

359
auto QtPassSettings::isUseAutoclearPanel(const bool &defaultValue) -> bool {
4✔
360
  return getInstance()
4✔
361
      ->value(SettingsConstants::useAutoclearPanel, defaultValue)
8✔
362
      .toBool();
8✔
363
}
364
void QtPassSettings::setUseAutoclearPanel(const bool &useAutoclearPanel) {
2✔
365
  getInstance()->setValue(SettingsConstants::useAutoclearPanel,
4✔
366
                          useAutoclearPanel);
2✔
367
}
2✔
368

369
auto QtPassSettings::getAutoclearPanelSeconds(const int &defaultValue) -> int {
14✔
370
  return getInstance()
14✔
371
      ->value(SettingsConstants::autoclearPanelSeconds, defaultValue)
28✔
372
      .toInt();
28✔
373
}
374
void QtPassSettings::setAutoclearPanelSeconds(
2✔
375
    const int &autoClearPanelSeconds) {
376
  getInstance()->setValue(SettingsConstants::autoclearPanelSeconds,
2✔
377
                          autoClearPanelSeconds);
378
}
2✔
379

380
auto QtPassSettings::isHidePassword(const bool &defaultValue) -> bool {
8✔
381
  return getInstance()
8✔
382
      ->value(SettingsConstants::hidePassword, defaultValue)
16✔
383
      .toBool();
16✔
384
}
385
void QtPassSettings::setHidePassword(const bool &hidePassword) {
2✔
386
  getInstance()->setValue(SettingsConstants::hidePassword, hidePassword);
2✔
387
}
2✔
388

389
auto QtPassSettings::isHideContent(const bool &defaultValue) -> bool {
4✔
390
  return getInstance()
4✔
391
      ->value(SettingsConstants::hideContent, defaultValue)
8✔
392
      .toBool();
8✔
393
}
394
void QtPassSettings::setHideContent(const bool &hideContent) {
2✔
395
  getInstance()->setValue(SettingsConstants::hideContent, hideContent);
2✔
396
}
2✔
397

398
auto QtPassSettings::isUseMonospace(const bool &defaultValue) -> bool {
20✔
399
  return getInstance()
20✔
400
      ->value(SettingsConstants::useMonospace, defaultValue)
40✔
401
      .toBool();
40✔
402
}
403
void QtPassSettings::setUseMonospace(const bool &useMonospace) {
2✔
404
  getInstance()->setValue(SettingsConstants::useMonospace, useMonospace);
2✔
405
}
2✔
406

407
auto QtPassSettings::isDisplayAsIs(const bool &defaultValue) -> bool {
4✔
408
  return getInstance()
4✔
409
      ->value(SettingsConstants::displayAsIs, defaultValue)
8✔
410
      .toBool();
8✔
411
}
412
void QtPassSettings::setDisplayAsIs(const bool &displayAsIs) {
2✔
413
  getInstance()->setValue(SettingsConstants::displayAsIs, displayAsIs);
2✔
414
}
2✔
415

416
auto QtPassSettings::isNoLineWrapping(const bool &defaultValue) -> bool {
16✔
417
  return getInstance()
16✔
418
      ->value(SettingsConstants::noLineWrapping, defaultValue)
32✔
419
      .toBool();
32✔
420
}
421
void QtPassSettings::setNoLineWrapping(const bool &noLineWrapping) {
2✔
422
  getInstance()->setValue(SettingsConstants::noLineWrapping, noLineWrapping);
2✔
423
}
2✔
424

425
auto QtPassSettings::isAddGPGId(const bool &defaultValue) -> bool {
4✔
426
  return getInstance()
4✔
427
      ->value(SettingsConstants::addGPGId, defaultValue)
8✔
428
      .toBool();
8✔
429
}
430
void QtPassSettings::setAddGPGId(const bool &addGPGId) {
2✔
431
  getInstance()->setValue(SettingsConstants::addGPGId, addGPGId);
2✔
432
}
2✔
433

434
/**
435
 * @brief Retrieves the password store path, normalizes it, and ensures the
436
 * directory exists.
437
 * @example
438
 * QString passStore =
439
 * QtPassSettings::getPassStore("/home/user/.password-store"); qDebug() <<
440
 * passStore; // Expected output: "/home/user/.password-store/"
441
 *
442
 * @param defaultValue - Fallback path used when no password store is
443
 * configured.
444
 * @return QString - The normalized absolute password store path, guaranteed to
445
 * end with a path separator.
446
 */
447
auto QtPassSettings::getPassStore(const QString &defaultValue) -> QString {
135✔
448
  QString returnValue = getInstance()
135✔
449
                            ->value(SettingsConstants::passStore, defaultValue)
270✔
450
                            .toString();
135✔
451

452
  // Normalize the path string
453
  returnValue = QDir(returnValue).absolutePath();
270✔
454

455
  // ensure directory exists if never used pass or misconfigured.
456
  // otherwise process->setWorkingDirectory(passStore); will fail on execution.
457
  if (!QDir(returnValue).exists()) {
135✔
458
    if (!QDir().mkdir(returnValue)) {
4✔
459
      qWarning() << "Failed to create password store directory:" << returnValue;
×
460
    }
461
  }
462

463
  // ensure path ends in /
464
  if (!returnValue.endsWith("/") && !returnValue.endsWith(QDir::separator())) {
270✔
465
    returnValue += QDir::separator();
135✔
466
  }
467

468
  return returnValue;
135✔
469
}
470
void QtPassSettings::setPassStore(const QString &passStore) {
71✔
471
  getInstance()->setValue(SettingsConstants::passStore, passStore);
71✔
472
}
71✔
473

474
auto QtPassSettings::getPassSigningKey(const QString &defaultValue) -> QString {
3✔
475
  return getInstance()
3✔
476
      ->value(SettingsConstants::passSigningKey, defaultValue)
6✔
477
      .toString();
6✔
478
}
479
void QtPassSettings::setPassSigningKey(const QString &passSigningKey) {
4✔
480
  getInstance()->setValue(SettingsConstants::passSigningKey, passSigningKey);
4✔
481
}
4✔
482

483
/**
484
 * @brief Initializes executable paths for Pass, Git, GPG, and Pwgen by locating
485
 * them in the system PATH.
486
 * @example
487
 * QtPassSettings::initExecutables();
488
 *
489
 * @return void - This method does not return a value.
490
 */
491
void QtPassSettings::initExecutables() {
12✔
492
  QString passExecutable =
493
      QtPassSettings::getPassExecutable(Util::findBinaryInPath("pass"));
12✔
494
  QtPassSettings::setPassExecutable(passExecutable);
12✔
495

496
  QString gitExecutable =
497
      QtPassSettings::getGitExecutable(Util::findBinaryInPath("git"));
12✔
498
  QtPassSettings::setGitExecutable(gitExecutable);
12✔
499

500
  QString gpgExecutable =
501
      QtPassSettings::getGpgExecutable(Util::findBinaryInPath("gpg2"));
12✔
502
  QtPassSettings::setGpgExecutable(gpgExecutable);
12✔
503

504
  QString pwgenExecutable =
505
      QtPassSettings::getPwgenExecutable(Util::findBinaryInPath("pwgen"));
12✔
506
  QtPassSettings::setPwgenExecutable(pwgenExecutable);
12✔
507
}
12✔
508
auto QtPassSettings::getPassExecutable(const QString &defaultValue) -> QString {
27✔
509
  return getInstance()
27✔
510
      ->value(SettingsConstants::passExecutable, defaultValue)
54✔
511
      .toString();
54✔
512
}
513
void QtPassSettings::setPassExecutable(const QString &passExecutable) {
27✔
514
  getInstance()->setValue(SettingsConstants::passExecutable, passExecutable);
27✔
515
}
27✔
516

517
auto QtPassSettings::getSshAuthSockOverride(const QString &defaultValue)
16✔
518
    -> QString {
519
  return getInstance()
16✔
520
      ->value(SettingsConstants::sshAuthSockOverride, defaultValue)
32✔
521
      .toString();
32✔
522
}
523
void QtPassSettings::setSshAuthSockOverride(const QString &value) {
17✔
524
  getInstance()->setValue(SettingsConstants::sshAuthSockOverride, value);
17✔
525
}
17✔
526

527
auto QtPassSettings::getGitExecutable(const QString &defaultValue) -> QString {
14✔
528
  return getInstance()
14✔
529
      ->value(SettingsConstants::gitExecutable, defaultValue)
28✔
530
      .toString();
28✔
531
}
532
void QtPassSettings::setGitExecutable(const QString &gitExecutable) {
28✔
533
  getInstance()->setValue(SettingsConstants::gitExecutable, gitExecutable);
28✔
534
}
28✔
535

536
auto QtPassSettings::getGpgExecutable(const QString &defaultValue) -> QString {
40✔
537
  return getInstance()
40✔
538
      ->value(SettingsConstants::gpgExecutable, defaultValue)
80✔
539
      .toString();
80✔
540
}
541
void QtPassSettings::setGpgExecutable(const QString &gpgExecutable) {
45✔
542
  getInstance()->setValue(SettingsConstants::gpgExecutable, gpgExecutable);
45✔
543
}
45✔
544

545
auto QtPassSettings::getPwgenExecutable(const QString &defaultValue)
14✔
546
    -> QString {
547
  return getInstance()
14✔
548
      ->value(SettingsConstants::pwgenExecutable, defaultValue)
28✔
549
      .toString();
28✔
550
}
551
void QtPassSettings::setPwgenExecutable(const QString &pwgenExecutable) {
14✔
552
  getInstance()->setValue(SettingsConstants::pwgenExecutable, pwgenExecutable);
14✔
553
}
14✔
554

UNCOV
555
auto QtPassSettings::getGpgHome(const QString &defaultValue) -> QString {
×
UNCOV
556
  return getInstance()
×
UNCOV
557
      ->value(SettingsConstants::gpgHome, defaultValue)
×
UNCOV
558
      .toString();
×
559
}
560

561
auto QtPassSettings::isUseWebDav(const bool &defaultValue) -> bool {
16✔
562
  return getInstance()
16✔
563
      ->value(SettingsConstants::useWebDav, defaultValue)
32✔
564
      .toBool();
32✔
565
}
566
void QtPassSettings::setUseWebDav(const bool &useWebDav) {
2✔
567
  getInstance()->setValue(SettingsConstants::useWebDav, useWebDav);
2✔
568
}
2✔
569

570
auto QtPassSettings::getWebDavUrl(const QString &defaultValue) -> QString {
2✔
571
  return getInstance()
2✔
572
      ->value(SettingsConstants::webDavUrl, defaultValue)
4✔
573
      .toString();
4✔
574
}
575
void QtPassSettings::setWebDavUrl(const QString &webDavUrl) {
2✔
576
  getInstance()->setValue(SettingsConstants::webDavUrl, webDavUrl);
2✔
577
}
2✔
578

579
auto QtPassSettings::getWebDavUser(const QString &defaultValue) -> QString {
2✔
580
  return getInstance()
2✔
581
      ->value(SettingsConstants::webDavUser, defaultValue)
4✔
582
      .toString();
4✔
583
}
584
void QtPassSettings::setWebDavUser(const QString &webDavUser) {
2✔
585
  getInstance()->setValue(SettingsConstants::webDavUser, webDavUser);
2✔
586
}
2✔
587

588
auto QtPassSettings::getWebDavPassword(const QString &defaultValue) -> QString {
2✔
589
  return getInstance()
2✔
590
      ->value(SettingsConstants::webDavPassword, defaultValue)
4✔
591
      .toString();
4✔
592
}
593
void QtPassSettings::setWebDavPassword(const QString &webDavPassword) {
2✔
594
  getInstance()->setValue(SettingsConstants::webDavPassword, webDavPassword);
2✔
595
}
2✔
596

597
auto QtPassSettings::getProfile(const QString &defaultValue) -> QString {
28✔
598
  return getInstance()
28✔
599
      ->value(SettingsConstants::profile, defaultValue)
56✔
600
      .toString();
56✔
601
}
602
void QtPassSettings::setProfile(const QString &profile) {
3✔
603
  getInstance()->setValue(SettingsConstants::profile, profile);
3✔
604
}
3✔
605

606
/**
607
 * @brief Gets the useGit setting for a specific profile.
608
 * @param profileName The profile name.
609
 * @param defaultValue The default value if not set.
610
 * @return The useGit setting for the profile.
611
 */
612
auto QtPassSettings::getProfileUseGit(const QString &profileName,
3✔
613
                                      const bool &defaultValue) -> bool {
614
  QString stored =
615
      getInstance()
3✔
616
          ->value(SettingsConstants::profile + "/" + profileName + "/useGit")
9✔
617
          .toString();
3✔
618
  // If empty or not set, return default (migration-friendly fallback)
619
  if (stored.isEmpty()) {
3✔
620
    return defaultValue;
1✔
621
  }
622
  return stored == "true";
623
}
624

625
/**
626
 * @brief Sets the useGit setting for a specific profile.
627
 * @param profileName The profile name.
628
 * @param useGit The useGit value to set.
629
 */
630
void QtPassSettings::setProfileUseGit(const QString &profileName,
2✔
631
                                      const bool &useGit) {
632
  getInstance()->setValue(SettingsConstants::profile + "/" + profileName +
6✔
633
                              "/useGit",
634
                          useGit ? "true" : "false");
2✔
635
}
2✔
636

637
/**
638
 * @brief Gets the autoPush setting for a specific profile.
639
 * @param profileName The profile name.
640
 * @param defaultValue The default value if not set.
641
 * @return The autoPush setting for the profile.
642
 */
643
auto QtPassSettings::getProfileAutoPush(const QString &profileName,
3✔
644
                                        const bool &defaultValue) -> bool {
645
  QString stored =
646
      getInstance()
3✔
647
          ->value(SettingsConstants::profile + "/" + profileName + "/autoPush")
9✔
648
          .toString();
3✔
649
  if (stored.isEmpty()) {
3✔
650
    return defaultValue;
1✔
651
  }
652
  return stored == "true";
653
}
654

655
/**
656
 * @brief Sets the autoPush setting for a specific profile.
657
 * @param profileName The profile name.
658
 * @param autoPush The autoPush value to set.
659
 */
660
void QtPassSettings::setProfileAutoPush(const QString &profileName,
2✔
661
                                        const bool &autoPush) {
662
  getInstance()->setValue(SettingsConstants::profile + "/" + profileName +
6✔
663
                              "/autoPush",
664
                          autoPush ? "true" : "false");
2✔
665
}
2✔
666

667
/**
668
 * @brief Gets the autoPull setting for a specific profile.
669
 * @param profileName The profile name.
670
 * @param defaultValue The default value if not set.
671
 * @return The autoPull setting for the profile.
672
 */
673
auto QtPassSettings::getProfileAutoPull(const QString &profileName,
3✔
674
                                        const bool &defaultValue) -> bool {
675
  QString stored =
676
      getInstance()
3✔
677
          ->value(SettingsConstants::profile + "/" + profileName + "/autoPull")
9✔
678
          .toString();
3✔
679
  if (stored.isEmpty()) {
3✔
680
    return defaultValue;
1✔
681
  }
682
  return stored == "true";
683
}
684

685
/**
686
 * @brief Sets the autoPull setting for a specific profile.
687
 * @param profileName The profile name.
688
 * @param autoPull The autoPull value to set.
689
 */
690
void QtPassSettings::setProfileAutoPull(const QString &profileName,
2✔
691
                                        const bool &autoPull) {
692
  getInstance()->setValue(SettingsConstants::profile + "/" + profileName +
6✔
693
                              "/autoPull",
694
                          autoPull ? "true" : "false");
2✔
695
}
2✔
696

697
/**
698
 * @brief Determines whether Git should be used for the current QtPass settings.
699
 * @example
700
 * bool result = QtPassSettings::isUseGit(true);
701
 * std::cout << result << std::endl; // Expected output: true or false
702
 *
703
 * @param const bool &defaultValue - The fallback value used when no explicit
704
 * setting is stored.
705
 * @return bool - True if Git usage is enabled, otherwise false.
706
 */
707
auto QtPassSettings::isUseGit(const bool &defaultValue) -> bool {
25✔
708
  bool storedValue =
709
      getInstance()->value(SettingsConstants::useGit, defaultValue).toBool();
25✔
710
  if (storedValue == defaultValue && defaultValue) {
25✔
711
    QString passStore = getPassStore();
4✔
712
    if (QFileInfo(passStore).isDir() &&
4✔
713
        QFileInfo(passStore + QDir::separator() + ".git").isDir()) {
6✔
714
      return true;
715
    }
716
  }
717
  return storedValue;
718
}
719
void QtPassSettings::setUseGit(const bool &useGit) {
6✔
720
  getInstance()->setValue(SettingsConstants::useGit, useGit);
6✔
721
}
6✔
722

723
auto QtPassSettings::isUseGrepSearch(const bool &defaultValue) -> bool {
16✔
724
  return getInstance()
16✔
725
      ->value(SettingsConstants::useGrepSearch, defaultValue)
32✔
726
      .toBool();
32✔
727
}
728

729
void QtPassSettings::setUseGrepSearch(const bool &useGrepSearch) {
2✔
730
  getInstance()->setValue(SettingsConstants::useGrepSearch, useGrepSearch);
2✔
731
}
2✔
732

733
auto QtPassSettings::isUseOtp(const bool &defaultValue) -> bool {
19✔
734
  return getInstance()->value(SettingsConstants::useOtp, defaultValue).toBool();
19✔
735
}
736

737
void QtPassSettings::setUseOtp(const bool &useOtp) {
2✔
738
  getInstance()->setValue(SettingsConstants::useOtp, useOtp);
2✔
739
}
2✔
740

741
auto QtPassSettings::isUseQrencode(const bool &defaultValue) -> bool {
8✔
742
  return getInstance()
8✔
743
      ->value(SettingsConstants::useQrencode, defaultValue)
16✔
744
      .toBool();
16✔
745
}
746

747
void QtPassSettings::setUseQrencode(const bool &useQrencode) {
2✔
748
  getInstance()->setValue(SettingsConstants::useQrencode, useQrencode);
2✔
749
}
2✔
750

751
auto QtPassSettings::getQrencodeExecutable(const QString &defaultValue)
2✔
752
    -> QString {
753
  return getInstance()
2✔
754
      ->value(SettingsConstants::qrencodeExecutable, defaultValue)
4✔
755
      .toString();
4✔
756
}
757
void QtPassSettings::setQrencodeExecutable(const QString &qrencodeExecutable) {
15✔
758
  getInstance()->setValue(SettingsConstants::qrencodeExecutable,
15✔
759
                          qrencodeExecutable);
760
}
15✔
761

762
auto QtPassSettings::isUsePwgen(const bool &defaultValue) -> bool {
6✔
763
  return getInstance()
6✔
764
      ->value(SettingsConstants::usePwgen, defaultValue)
12✔
765
      .toBool();
12✔
766
}
767
void QtPassSettings::setUsePwgen(const bool &usePwgen) {
6✔
768
  getInstance()->setValue(SettingsConstants::usePwgen, usePwgen);
6✔
769
}
6✔
770

771
auto QtPassSettings::isAvoidCapitals(const bool &defaultValue) -> bool {
4✔
772
  return getInstance()
4✔
773
      ->value(SettingsConstants::avoidCapitals, defaultValue)
8✔
774
      .toBool();
8✔
775
}
776
void QtPassSettings::setAvoidCapitals(const bool &avoidCapitals) {
2✔
777
  getInstance()->setValue(SettingsConstants::avoidCapitals, avoidCapitals);
2✔
778
}
2✔
779

780
auto QtPassSettings::isAvoidNumbers(const bool &defaultValue) -> bool {
4✔
781
  return getInstance()
4✔
782
      ->value(SettingsConstants::avoidNumbers, defaultValue)
8✔
783
      .toBool();
8✔
784
}
785
void QtPassSettings::setAvoidNumbers(const bool &avoidNumbers) {
2✔
786
  getInstance()->setValue(SettingsConstants::avoidNumbers, avoidNumbers);
2✔
787
}
2✔
788

789
auto QtPassSettings::isLessRandom(const bool &defaultValue) -> bool {
4✔
790
  return getInstance()
4✔
791
      ->value(SettingsConstants::lessRandom, defaultValue)
8✔
792
      .toBool();
8✔
793
}
794
void QtPassSettings::setLessRandom(const bool &lessRandom) {
2✔
795
  getInstance()->setValue(SettingsConstants::lessRandom, lessRandom);
2✔
796
}
2✔
797

798
auto QtPassSettings::isUseSymbols(const bool &defaultValue) -> bool {
4✔
799
  return getInstance()
4✔
800
      ->value(SettingsConstants::useSymbols, defaultValue)
8✔
801
      .toBool();
8✔
802
}
803
void QtPassSettings::setUseSymbols(const bool &useSymbols) {
2✔
804
  getInstance()->setValue(SettingsConstants::useSymbols, useSymbols);
2✔
805
}
2✔
806

807
void QtPassSettings::setPasswordLength(const int &passwordLength) {
2✔
808
  getInstance()->setValue(SettingsConstants::passwordLength, passwordLength);
2✔
809
}
2✔
810
void QtPassSettings::setPasswordCharsSelection(
6✔
811
    const int &passwordCharsSelection) {
812
  getInstance()->setValue(SettingsConstants::passwordCharsSelection,
6✔
813
                          passwordCharsSelection);
814
}
6✔
815
void QtPassSettings::setPasswordChars(const QString &passwordChars) {
5✔
816
  getInstance()->setValue(SettingsConstants::passwordChars, passwordChars);
5✔
817
}
5✔
818

819
auto QtPassSettings::isUseTrayIcon(const bool &defaultValue) -> bool {
28✔
820
  return getInstance()
28✔
821
      ->value(SettingsConstants::useTrayIcon, defaultValue)
56✔
822
      .toBool();
56✔
823
}
824
void QtPassSettings::setUseTrayIcon(const bool &useTrayIcon) {
2✔
825
  getInstance()->setValue(SettingsConstants::useTrayIcon, useTrayIcon);
2✔
826
}
2✔
827

828
auto QtPassSettings::isHideOnClose(const bool &defaultValue) -> bool {
4✔
829
  return getInstance()
4✔
830
      ->value(SettingsConstants::hideOnClose, defaultValue)
8✔
831
      .toBool();
8✔
832
}
833
void QtPassSettings::setHideOnClose(const bool &hideOnClose) {
2✔
834
  getInstance()->setValue(SettingsConstants::hideOnClose, hideOnClose);
2✔
835
}
2✔
836

837
auto QtPassSettings::isStartMinimized(const bool &defaultValue) -> bool {
4✔
838
  return getInstance()
4✔
839
      ->value(SettingsConstants::startMinimized, defaultValue)
8✔
840
      .toBool();
8✔
841
}
842
void QtPassSettings::setStartMinimized(const bool &startMinimized) {
2✔
843
  getInstance()->setValue(SettingsConstants::startMinimized, startMinimized);
2✔
844
}
2✔
845

846
auto QtPassSettings::isAlwaysOnTop(const bool &defaultValue) -> bool {
16✔
847
  return getInstance()
16✔
848
      ->value(SettingsConstants::alwaysOnTop, defaultValue)
32✔
849
      .toBool();
32✔
850
}
851
void QtPassSettings::setAlwaysOnTop(const bool &alwaysOnTop) {
2✔
852
  getInstance()->setValue(SettingsConstants::alwaysOnTop, alwaysOnTop);
2✔
853
}
2✔
854

855
auto QtPassSettings::isAutoPull(const bool &defaultValue) -> bool {
4✔
856
  return getInstance()
4✔
857
      ->value(SettingsConstants::autoPull, defaultValue)
8✔
858
      .toBool();
8✔
859
}
860
void QtPassSettings::setAutoPull(const bool &autoPull) {
2✔
861
  getInstance()->setValue(SettingsConstants::autoPull, autoPull);
2✔
862
}
2✔
863

864
auto QtPassSettings::isAutoPush(const bool &defaultValue) -> bool {
4✔
865
  return getInstance()
4✔
866
      ->value(SettingsConstants::autoPush, defaultValue)
8✔
867
      .toBool();
8✔
868
}
869
void QtPassSettings::setAutoPush(const bool &autoPush) {
2✔
870
  getInstance()->setValue(SettingsConstants::autoPush, autoPush);
2✔
871
}
2✔
872

873
auto QtPassSettings::getPassTemplate(const QString &defaultValue) -> QString {
14✔
874
  return getInstance()
14✔
875
      ->value(SettingsConstants::passTemplate, defaultValue)
28✔
876
      .toString();
28✔
877
}
878
void QtPassSettings::setPassTemplate(const QString &passTemplate) {
2✔
879
  getInstance()->setValue(SettingsConstants::passTemplate, passTemplate);
2✔
880
}
2✔
881

882
auto QtPassSettings::isUseTemplate(const bool &defaultValue) -> bool {
4✔
883
  return getInstance()
4✔
884
      ->value(SettingsConstants::useTemplate, defaultValue)
8✔
885
      .toBool();
8✔
886
}
887
void QtPassSettings::setUseTemplate(const bool &useTemplate) {
2✔
888
  getInstance()->setValue(SettingsConstants::useTemplate, useTemplate);
2✔
889
}
2✔
890

891
auto QtPassSettings::isTemplateAllFields(const bool &defaultValue) -> bool {
4✔
892
  return getInstance()
4✔
893
      ->value(SettingsConstants::templateAllFields, defaultValue)
8✔
894
      .toBool();
8✔
895
}
896
void QtPassSettings::setTemplateAllFields(const bool &templateAllFields) {
2✔
897
  getInstance()->setValue(SettingsConstants::templateAllFields,
4✔
898
                          templateAllFields);
2✔
899
}
2✔
900

901
auto QtPassSettings::isShowProcessOutput(const bool &defaultValue) -> bool {
19✔
902
  return getInstance()
19✔
903
      ->value(SettingsConstants::showProcessOutput, defaultValue)
38✔
904
      .toBool();
38✔
905
}
906
void QtPassSettings::setShowProcessOutput(const bool &showProcessOutput) {
16✔
907
  getInstance()->setValue(SettingsConstants::showProcessOutput,
32✔
908
                          showProcessOutput);
16✔
909
}
16✔
910

911
auto QtPassSettings::getRealPass() -> RealPass * {
12✔
912
  return PassBackendFactory::getRealPass();
12✔
913
}
914
auto QtPassSettings::getImitatePass() -> ImitatePass * {
36✔
915
  return PassBackendFactory::getImitatePass();
36✔
916
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc