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

IJHack / QtPass / 27660144570

17 Jun 2026 01:44AM UTC coverage: 57.523% (+0.05%) from 57.477%
27660144570

Pull #1551

github

web-flow
Merge bae10e9e5 into 4da97561f
Pull Request #1551: refactor(pass): inject AppSettings into Pass hierarchy (PR A of #1511)

42 of 72 new or added lines in 4 files covered. (58.33%)

11 existing lines in 6 files now uncovered.

3980 of 6919 relevant lines covered (57.52%)

23.94 hits per line

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

96.29
/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,531✔
42
  if (!QtPassSettings::initialized) {
1,531✔
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,531✔
55
}
56

57
auto QtPassSettings::load() -> AppSettings {
46✔
58
  return SettingsSerializer::load(*getInstance());
46✔
59
}
60

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

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

83
  config.length =
7✔
84
      getInstance()->value(SettingsConstants::passwordLength, 16).toInt();
7✔
85
  if (config.length <= 0) {
7✔
86
    config.length = 16;
×
87
  }
88
  config.selected = static_cast<PasswordConfiguration::characterSet>(
7✔
89
      getInstance()
7✔
90
          ->value(SettingsConstants::passwordCharsSelection, 0)
14✔
91
          .toInt());
7✔
92
  config.Characters[PasswordConfiguration::CUSTOM] =
93
      getInstance()
7✔
94
          ->value(SettingsConstants::passwordChars, QString())
14✔
95
          .toString();
7✔
96

97
  return config;
7✔
98
}
×
99

100
void QtPassSettings::setPasswordConfiguration(
3✔
101
    const PasswordConfiguration &config) {
102
  getInstance()->setValue(SettingsConstants::passwordLength, config.length);
3✔
103
  getInstance()->setValue(SettingsConstants::passwordCharsSelection,
6✔
104
                          config.selected);
3✔
105
  getInstance()->setValue(SettingsConstants::passwordChars,
6✔
106
                          config.Characters[PasswordConfiguration::CUSTOM]);
3✔
107
}
3✔
108

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

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

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

156
  getInstance()->endGroup();
28✔
157

158
  return profiles;
28✔
159
}
×
160

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

175
  QHash<QString, QHash<QString, QString>>::const_iterator i = profiles.begin();
3✔
176
  for (; i != profiles.end(); ++i) {
3✔
177
    getInstance()->setValue(i.key() + "/path", i.value().value("path"));
6✔
178
    getInstance()->setValue(i.key() + "/signingKey",
9✔
179
                            i.value().value("signingKey"));
3✔
180
    getInstance()->setValue(i.key() + "/useGit", i.value().value("useGit"));
6✔
181
    getInstance()->setValue(i.key() + "/autoPush", i.value().value("autoPush"));
6✔
182
    getInstance()->setValue(i.key() + "/autoPull", i.value().value("autoPull"));
9✔
183
  }
184

185
  getInstance()->endGroup();
3✔
186
}
3✔
187

188
auto QtPassSettings::getPass() -> Pass * {
41✔
189
  return PassBackendFactory::getPass();
41✔
190
}
191

192
auto QtPassSettings::getVersion(const QString &defaultValue) -> QString {
13✔
193
  return getInstance()
13✔
194
      ->value(SettingsConstants::version, defaultValue)
26✔
195
      .toString();
26✔
196
}
197
void QtPassSettings::setVersion(const QString &version) {
13✔
198
  getInstance()->setValue(SettingsConstants::version, version);
13✔
199
}
13✔
200

201
auto QtPassSettings::getGeometry(const QByteArray &defaultValue) -> QByteArray {
13✔
202
  return getInstance()
13✔
203
      ->value(SettingsConstants::geometry, defaultValue)
26✔
204
      .toByteArray();
26✔
205
}
206
void QtPassSettings::setGeometry(const QByteArray &geometry) {
1✔
207
  getInstance()->setValue(SettingsConstants::geometry, geometry);
1✔
208
}
1✔
209

210
auto QtPassSettings::getSavestate(const QByteArray &defaultValue)
13✔
211
    -> QByteArray {
212
  return getInstance()
13✔
213
      ->value(SettingsConstants::savestate, defaultValue)
26✔
214
      .toByteArray();
26✔
215
}
216
void QtPassSettings::setSavestate(const QByteArray &saveState) {
1✔
217
  getInstance()->setValue(SettingsConstants::savestate, saveState);
1✔
218
}
1✔
219

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

238
auto QtPassSettings::getSize(const QSize &defaultValue) -> QSize {
13✔
239
  return getInstance()->value(SettingsConstants::size, defaultValue).toSize();
13✔
240
}
241
void QtPassSettings::setSize(const QSize &size) {
1✔
242
  getInstance()->setValue(SettingsConstants::size, size);
1✔
243
}
1✔
244

245
auto QtPassSettings::isMaximized(const bool &defaultValue) -> bool {
16✔
246
  return getInstance()
16✔
247
      ->value(SettingsConstants::maximized, defaultValue)
32✔
248
      .toBool();
32✔
249
}
250
void QtPassSettings::setMaximized(const bool &maximized) {
2✔
251
  getInstance()->setValue(SettingsConstants::maximized, maximized);
2✔
252
}
2✔
253

254
auto QtPassSettings::getDialogGeometry(const QString &key,
24✔
255
                                       const QByteArray &defaultValue)
256
    -> QByteArray {
257
  return getInstance()
24✔
258
      ->value(SettingsConstants::dialogGeometry + "/" + key, defaultValue)
72✔
259
      .toByteArray();
48✔
260
}
261
void QtPassSettings::setDialogGeometry(const QString &key,
1✔
262
                                       const QByteArray &geometry) {
263
  getInstance()->setValue(SettingsConstants::dialogGeometry + "/" + key,
2✔
264
                          geometry);
265
}
1✔
266

267
auto QtPassSettings::getDialogPos(const QString &key,
1✔
268
                                  const QPoint &defaultValue) -> QPoint {
269
  return getInstance()
1✔
270
      ->value(SettingsConstants::dialogPos + "/" + key, defaultValue)
3✔
271
      .toPoint();
2✔
272
}
273
void QtPassSettings::setDialogPos(const QString &key, const QPoint &pos) {
1✔
274
  getInstance()->setValue(SettingsConstants::dialogPos + "/" + key, pos);
2✔
275
}
1✔
276

277
auto QtPassSettings::getDialogSize(const QString &key,
1✔
278
                                   const QSize &defaultValue) -> QSize {
279
  return getInstance()
1✔
280
      ->value(SettingsConstants::dialogSize + "/" + key, defaultValue)
3✔
281
      .toSize();
2✔
282
}
283
void QtPassSettings::setDialogSize(const QString &key, const QSize &size) {
1✔
284
  getInstance()->setValue(SettingsConstants::dialogSize + "/" + key, size);
2✔
285
}
1✔
286

287
auto QtPassSettings::isDialogMaximized(const QString &key,
25✔
288
                                       const bool &defaultValue) -> bool {
289
  return getInstance()
25✔
290
      ->value(SettingsConstants::dialogMaximized + "/" + key, defaultValue)
75✔
291
      .toBool();
50✔
292
}
293
void QtPassSettings::setDialogMaximized(const QString &key,
2✔
294
                                        const bool &maximized) {
295
  getInstance()->setValue(SettingsConstants::dialogMaximized + "/" + key,
6✔
296
                          maximized);
2✔
297
}
2✔
298

299
auto QtPassSettings::isUsePass(const bool &defaultValue) -> bool {
20✔
300
  return getInstance()
20✔
301
      ->value(SettingsConstants::usePass, defaultValue)
40✔
302
      .toBool();
40✔
303
}
304
void QtPassSettings::setUsePass(const bool &usePass) {
18✔
305
  getInstance()->setValue(SettingsConstants::usePass, usePass);
18✔
306
  // Backend selection changed: force re-selection on next getPass().
307
  PassBackendFactory::invalidate();
18✔
308
}
18✔
309

310
auto QtPassSettings::getClipBoardTypeRaw(
18✔
311
    const Enums::clipBoardType &defaultValue) -> int {
312
  return getInstance()
18✔
313
      ->value(SettingsConstants::clipBoardType, static_cast<int>(defaultValue))
36✔
314
      .toInt();
36✔
315
}
316

317
auto QtPassSettings::getClipBoardType(const Enums::clipBoardType &defaultValue)
5✔
318
    -> Enums::clipBoardType {
319
  return static_cast<Enums::clipBoardType>(getClipBoardTypeRaw(defaultValue));
5✔
320
}
321
void QtPassSettings::setClipBoardType(const int &clipBoardType) {
1✔
322
  getInstance()->setValue(SettingsConstants::clipBoardType, clipBoardType);
1✔
323
}
1✔
324

325
auto QtPassSettings::isUseSelection(const bool &defaultValue) -> bool {
4✔
326
  return getInstance()
4✔
327
      ->value(SettingsConstants::useSelection, defaultValue)
8✔
328
      .toBool();
8✔
329
}
330
void QtPassSettings::setUseSelection(const bool &useSelection) {
2✔
331
  getInstance()->setValue(SettingsConstants::useSelection, useSelection);
2✔
332
}
2✔
333

334
auto QtPassSettings::isUseAutoclear(const bool &defaultValue) -> bool {
4✔
335
  return getInstance()
4✔
336
      ->value(SettingsConstants::useAutoclear, defaultValue)
8✔
337
      .toBool();
8✔
338
}
339
void QtPassSettings::setUseAutoclear(const bool &useAutoclear) {
2✔
340
  getInstance()->setValue(SettingsConstants::useAutoclear, useAutoclear);
2✔
341
}
2✔
342

343
auto QtPassSettings::getAutoclearSeconds(const int &defaultValue) -> int {
14✔
344
  return getInstance()
14✔
345
      ->value(SettingsConstants::autoclearSeconds, defaultValue)
28✔
346
      .toInt();
28✔
347
}
348
void QtPassSettings::setAutoclearSeconds(const int &autoClearSeconds) {
2✔
349
  getInstance()->setValue(SettingsConstants::autoclearSeconds,
2✔
350
                          autoClearSeconds);
351
}
2✔
352

353
auto QtPassSettings::isUseAutoclearPanel(const bool &defaultValue) -> bool {
4✔
354
  return getInstance()
4✔
355
      ->value(SettingsConstants::useAutoclearPanel, defaultValue)
8✔
356
      .toBool();
8✔
357
}
358
void QtPassSettings::setUseAutoclearPanel(const bool &useAutoclearPanel) {
2✔
359
  getInstance()->setValue(SettingsConstants::useAutoclearPanel,
4✔
360
                          useAutoclearPanel);
2✔
361
}
2✔
362

363
auto QtPassSettings::getAutoclearPanelSeconds(const int &defaultValue) -> int {
14✔
364
  return getInstance()
14✔
365
      ->value(SettingsConstants::autoclearPanelSeconds, defaultValue)
28✔
366
      .toInt();
28✔
367
}
368
void QtPassSettings::setAutoclearPanelSeconds(
2✔
369
    const int &autoClearPanelSeconds) {
370
  getInstance()->setValue(SettingsConstants::autoclearPanelSeconds,
2✔
371
                          autoClearPanelSeconds);
372
}
2✔
373

374
auto QtPassSettings::isHidePassword(const bool &defaultValue) -> bool {
8✔
375
  return getInstance()
8✔
376
      ->value(SettingsConstants::hidePassword, defaultValue)
16✔
377
      .toBool();
16✔
378
}
379
void QtPassSettings::setHidePassword(const bool &hidePassword) {
2✔
380
  getInstance()->setValue(SettingsConstants::hidePassword, hidePassword);
2✔
381
}
2✔
382

383
auto QtPassSettings::isHideContent(const bool &defaultValue) -> bool {
4✔
384
  return getInstance()
4✔
385
      ->value(SettingsConstants::hideContent, defaultValue)
8✔
386
      .toBool();
8✔
387
}
388
void QtPassSettings::setHideContent(const bool &hideContent) {
2✔
389
  getInstance()->setValue(SettingsConstants::hideContent, hideContent);
2✔
390
}
2✔
391

392
auto QtPassSettings::isUseMonospace(const bool &defaultValue) -> bool {
20✔
393
  return getInstance()
20✔
394
      ->value(SettingsConstants::useMonospace, defaultValue)
40✔
395
      .toBool();
40✔
396
}
397
void QtPassSettings::setUseMonospace(const bool &useMonospace) {
2✔
398
  getInstance()->setValue(SettingsConstants::useMonospace, useMonospace);
2✔
399
}
2✔
400

401
auto QtPassSettings::isDisplayAsIs(const bool &defaultValue) -> bool {
4✔
402
  return getInstance()
4✔
403
      ->value(SettingsConstants::displayAsIs, defaultValue)
8✔
404
      .toBool();
8✔
405
}
406
void QtPassSettings::setDisplayAsIs(const bool &displayAsIs) {
2✔
407
  getInstance()->setValue(SettingsConstants::displayAsIs, displayAsIs);
2✔
408
}
2✔
409

410
auto QtPassSettings::isNoLineWrapping(const bool &defaultValue) -> bool {
16✔
411
  return getInstance()
16✔
412
      ->value(SettingsConstants::noLineWrapping, defaultValue)
32✔
413
      .toBool();
32✔
414
}
415
void QtPassSettings::setNoLineWrapping(const bool &noLineWrapping) {
2✔
416
  getInstance()->setValue(SettingsConstants::noLineWrapping, noLineWrapping);
2✔
417
}
2✔
418

419
auto QtPassSettings::isAddGPGId(const bool &defaultValue) -> bool {
4✔
420
  return getInstance()
4✔
421
      ->value(SettingsConstants::addGPGId, defaultValue)
8✔
422
      .toBool();
8✔
423
}
424
void QtPassSettings::setAddGPGId(const bool &addGPGId) {
2✔
425
  getInstance()->setValue(SettingsConstants::addGPGId, addGPGId);
2✔
426
}
2✔
427

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

446
  // Normalize the path string
447
  returnValue = QDir(returnValue).absolutePath();
332✔
448

449
  // ensure directory exists if never used pass or misconfigured.
450
  // otherwise process->setWorkingDirectory(passStore); will fail on execution.
451
  if (!QDir(returnValue).exists()) {
166✔
452
    if (!QDir().mkdir(returnValue)) {
6✔
453
      qWarning() << "Failed to create password store directory:" << returnValue;
×
454
    }
455
  }
456

457
  // ensure path ends in /
458
  if (!returnValue.endsWith("/") && !returnValue.endsWith(QDir::separator())) {
332✔
459
    returnValue += QDir::separator();
166✔
460
  }
461

462
  return returnValue;
166✔
463
}
464
void QtPassSettings::setPassStore(const QString &passStore) {
71✔
465
  getInstance()->setValue(SettingsConstants::passStore, passStore);
71✔
466
}
71✔
467

468
auto QtPassSettings::getPassSigningKey(const QString &defaultValue) -> QString {
3✔
469
  return getInstance()
3✔
470
      ->value(SettingsConstants::passSigningKey, defaultValue)
6✔
471
      .toString();
6✔
472
}
473
void QtPassSettings::setPassSigningKey(const QString &passSigningKey) {
4✔
474
  getInstance()->setValue(SettingsConstants::passSigningKey, passSigningKey);
4✔
475
}
4✔
476

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

490
  QString gitExecutable =
491
      QtPassSettings::getGitExecutable(Util::findBinaryInPath("git"));
12✔
492
  QtPassSettings::setGitExecutable(gitExecutable);
12✔
493

494
  QString gpgExecutable =
495
      QtPassSettings::getGpgExecutable(Util::findBinaryInPath("gpg2"));
12✔
496
  QtPassSettings::setGpgExecutable(gpgExecutable);
12✔
497

498
  QString pwgenExecutable =
499
      QtPassSettings::getPwgenExecutable(Util::findBinaryInPath("pwgen"));
12✔
500
  QtPassSettings::setPwgenExecutable(pwgenExecutable);
12✔
501
}
12✔
502
auto QtPassSettings::getPassExecutable(const QString &defaultValue) -> QString {
27✔
503
  return getInstance()
27✔
504
      ->value(SettingsConstants::passExecutable, defaultValue)
54✔
505
      .toString();
54✔
506
}
507
void QtPassSettings::setPassExecutable(const QString &passExecutable) {
27✔
508
  getInstance()->setValue(SettingsConstants::passExecutable, passExecutable);
27✔
509
}
27✔
510

511
auto QtPassSettings::getSshAuthSockOverride(const QString &defaultValue)
16✔
512
    -> QString {
513
  return getInstance()
16✔
514
      ->value(SettingsConstants::sshAuthSockOverride, defaultValue)
32✔
515
      .toString();
32✔
516
}
517
void QtPassSettings::setSshAuthSockOverride(const QString &value) {
17✔
518
  getInstance()->setValue(SettingsConstants::sshAuthSockOverride, value);
17✔
519
}
17✔
520

521
auto QtPassSettings::getGitExecutable(const QString &defaultValue) -> QString {
14✔
522
  return getInstance()
14✔
523
      ->value(SettingsConstants::gitExecutable, defaultValue)
28✔
524
      .toString();
28✔
525
}
526
void QtPassSettings::setGitExecutable(const QString &gitExecutable) {
28✔
527
  getInstance()->setValue(SettingsConstants::gitExecutable, gitExecutable);
28✔
528
}
28✔
529

530
auto QtPassSettings::getGpgExecutable(const QString &defaultValue) -> QString {
30✔
531
  return getInstance()
30✔
532
      ->value(SettingsConstants::gpgExecutable, defaultValue)
60✔
533
      .toString();
60✔
534
}
535
void QtPassSettings::setGpgExecutable(const QString &gpgExecutable) {
45✔
536
  getInstance()->setValue(SettingsConstants::gpgExecutable, gpgExecutable);
45✔
537
}
45✔
538

539
auto QtPassSettings::getPwgenExecutable(const QString &defaultValue)
14✔
540
    -> QString {
541
  return getInstance()
14✔
542
      ->value(SettingsConstants::pwgenExecutable, defaultValue)
28✔
543
      .toString();
28✔
544
}
545
void QtPassSettings::setPwgenExecutable(const QString &pwgenExecutable) {
14✔
546
  getInstance()->setValue(SettingsConstants::pwgenExecutable, pwgenExecutable);
14✔
547
}
14✔
548

UNCOV
549
auto QtPassSettings::getGpgHome(const QString &defaultValue) -> QString {
×
UNCOV
550
  return getInstance()
×
UNCOV
551
      ->value(SettingsConstants::gpgHome, defaultValue)
×
UNCOV
552
      .toString();
×
553
}
554

555
auto QtPassSettings::isUseWebDav(const bool &defaultValue) -> bool {
16✔
556
  return getInstance()
16✔
557
      ->value(SettingsConstants::useWebDav, defaultValue)
32✔
558
      .toBool();
32✔
559
}
560
void QtPassSettings::setUseWebDav(const bool &useWebDav) {
2✔
561
  getInstance()->setValue(SettingsConstants::useWebDav, useWebDav);
2✔
562
}
2✔
563

564
auto QtPassSettings::getWebDavUrl(const QString &defaultValue) -> QString {
2✔
565
  return getInstance()
2✔
566
      ->value(SettingsConstants::webDavUrl, defaultValue)
4✔
567
      .toString();
4✔
568
}
569
void QtPassSettings::setWebDavUrl(const QString &webDavUrl) {
2✔
570
  getInstance()->setValue(SettingsConstants::webDavUrl, webDavUrl);
2✔
571
}
2✔
572

573
auto QtPassSettings::getWebDavUser(const QString &defaultValue) -> QString {
2✔
574
  return getInstance()
2✔
575
      ->value(SettingsConstants::webDavUser, defaultValue)
4✔
576
      .toString();
4✔
577
}
578
void QtPassSettings::setWebDavUser(const QString &webDavUser) {
2✔
579
  getInstance()->setValue(SettingsConstants::webDavUser, webDavUser);
2✔
580
}
2✔
581

582
auto QtPassSettings::getWebDavPassword(const QString &defaultValue) -> QString {
2✔
583
  return getInstance()
2✔
584
      ->value(SettingsConstants::webDavPassword, defaultValue)
4✔
585
      .toString();
4✔
586
}
587
void QtPassSettings::setWebDavPassword(const QString &webDavPassword) {
2✔
588
  getInstance()->setValue(SettingsConstants::webDavPassword, webDavPassword);
2✔
589
}
2✔
590

591
auto QtPassSettings::getProfile(const QString &defaultValue) -> QString {
28✔
592
  return getInstance()
28✔
593
      ->value(SettingsConstants::profile, defaultValue)
56✔
594
      .toString();
56✔
595
}
596
void QtPassSettings::setProfile(const QString &profile) {
3✔
597
  getInstance()->setValue(SettingsConstants::profile, profile);
3✔
598
}
3✔
599

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

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

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

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

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

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

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

717
auto QtPassSettings::isUseGrepSearch(const bool &defaultValue) -> bool {
16✔
718
  return getInstance()
16✔
719
      ->value(SettingsConstants::useGrepSearch, defaultValue)
32✔
720
      .toBool();
32✔
721
}
722

723
void QtPassSettings::setUseGrepSearch(const bool &useGrepSearch) {
2✔
724
  getInstance()->setValue(SettingsConstants::useGrepSearch, useGrepSearch);
2✔
725
}
2✔
726

727
auto QtPassSettings::isUseOtp(const bool &defaultValue) -> bool {
19✔
728
  return getInstance()->value(SettingsConstants::useOtp, defaultValue).toBool();
19✔
729
}
730

731
void QtPassSettings::setUseOtp(const bool &useOtp) {
2✔
732
  getInstance()->setValue(SettingsConstants::useOtp, useOtp);
2✔
733
}
2✔
734

735
auto QtPassSettings::isUseQrencode(const bool &defaultValue) -> bool {
8✔
736
  return getInstance()
8✔
737
      ->value(SettingsConstants::useQrencode, defaultValue)
16✔
738
      .toBool();
16✔
739
}
740

741
void QtPassSettings::setUseQrencode(const bool &useQrencode) {
2✔
742
  getInstance()->setValue(SettingsConstants::useQrencode, useQrencode);
2✔
743
}
2✔
744

745
auto QtPassSettings::getQrencodeExecutable(const QString &defaultValue)
2✔
746
    -> QString {
747
  return getInstance()
2✔
748
      ->value(SettingsConstants::qrencodeExecutable, defaultValue)
4✔
749
      .toString();
4✔
750
}
751
void QtPassSettings::setQrencodeExecutable(const QString &qrencodeExecutable) {
15✔
752
  getInstance()->setValue(SettingsConstants::qrencodeExecutable,
15✔
753
                          qrencodeExecutable);
754
}
15✔
755

756
auto QtPassSettings::isUsePwgen(const bool &defaultValue) -> bool {
6✔
757
  return getInstance()
6✔
758
      ->value(SettingsConstants::usePwgen, defaultValue)
12✔
759
      .toBool();
12✔
760
}
761
void QtPassSettings::setUsePwgen(const bool &usePwgen) {
6✔
762
  getInstance()->setValue(SettingsConstants::usePwgen, usePwgen);
6✔
763
}
6✔
764

765
auto QtPassSettings::isAvoidCapitals(const bool &defaultValue) -> bool {
4✔
766
  return getInstance()
4✔
767
      ->value(SettingsConstants::avoidCapitals, defaultValue)
8✔
768
      .toBool();
8✔
769
}
770
void QtPassSettings::setAvoidCapitals(const bool &avoidCapitals) {
2✔
771
  getInstance()->setValue(SettingsConstants::avoidCapitals, avoidCapitals);
2✔
772
}
2✔
773

774
auto QtPassSettings::isAvoidNumbers(const bool &defaultValue) -> bool {
4✔
775
  return getInstance()
4✔
776
      ->value(SettingsConstants::avoidNumbers, defaultValue)
8✔
777
      .toBool();
8✔
778
}
779
void QtPassSettings::setAvoidNumbers(const bool &avoidNumbers) {
2✔
780
  getInstance()->setValue(SettingsConstants::avoidNumbers, avoidNumbers);
2✔
781
}
2✔
782

783
auto QtPassSettings::isLessRandom(const bool &defaultValue) -> bool {
4✔
784
  return getInstance()
4✔
785
      ->value(SettingsConstants::lessRandom, defaultValue)
8✔
786
      .toBool();
8✔
787
}
788
void QtPassSettings::setLessRandom(const bool &lessRandom) {
2✔
789
  getInstance()->setValue(SettingsConstants::lessRandom, lessRandom);
2✔
790
}
2✔
791

792
auto QtPassSettings::isUseSymbols(const bool &defaultValue) -> bool {
4✔
793
  return getInstance()
4✔
794
      ->value(SettingsConstants::useSymbols, defaultValue)
8✔
795
      .toBool();
8✔
796
}
797
void QtPassSettings::setUseSymbols(const bool &useSymbols) {
2✔
798
  getInstance()->setValue(SettingsConstants::useSymbols, useSymbols);
2✔
799
}
2✔
800

801
void QtPassSettings::setPasswordLength(const int &passwordLength) {
2✔
802
  getInstance()->setValue(SettingsConstants::passwordLength, passwordLength);
2✔
803
}
2✔
804
void QtPassSettings::setPasswordCharsSelection(
6✔
805
    const int &passwordCharsSelection) {
806
  getInstance()->setValue(SettingsConstants::passwordCharsSelection,
6✔
807
                          passwordCharsSelection);
808
}
6✔
809
void QtPassSettings::setPasswordChars(const QString &passwordChars) {
5✔
810
  getInstance()->setValue(SettingsConstants::passwordChars, passwordChars);
5✔
811
}
5✔
812

813
auto QtPassSettings::isUseTrayIcon(const bool &defaultValue) -> bool {
28✔
814
  return getInstance()
28✔
815
      ->value(SettingsConstants::useTrayIcon, defaultValue)
56✔
816
      .toBool();
56✔
817
}
818
void QtPassSettings::setUseTrayIcon(const bool &useTrayIcon) {
2✔
819
  getInstance()->setValue(SettingsConstants::useTrayIcon, useTrayIcon);
2✔
820
}
2✔
821

822
auto QtPassSettings::isHideOnClose(const bool &defaultValue) -> bool {
4✔
823
  return getInstance()
4✔
824
      ->value(SettingsConstants::hideOnClose, defaultValue)
8✔
825
      .toBool();
8✔
826
}
827
void QtPassSettings::setHideOnClose(const bool &hideOnClose) {
2✔
828
  getInstance()->setValue(SettingsConstants::hideOnClose, hideOnClose);
2✔
829
}
2✔
830

831
auto QtPassSettings::isStartMinimized(const bool &defaultValue) -> bool {
4✔
832
  return getInstance()
4✔
833
      ->value(SettingsConstants::startMinimized, defaultValue)
8✔
834
      .toBool();
8✔
835
}
836
void QtPassSettings::setStartMinimized(const bool &startMinimized) {
2✔
837
  getInstance()->setValue(SettingsConstants::startMinimized, startMinimized);
2✔
838
}
2✔
839

840
auto QtPassSettings::isAlwaysOnTop(const bool &defaultValue) -> bool {
16✔
841
  return getInstance()
16✔
842
      ->value(SettingsConstants::alwaysOnTop, defaultValue)
32✔
843
      .toBool();
32✔
844
}
845
void QtPassSettings::setAlwaysOnTop(const bool &alwaysOnTop) {
2✔
846
  getInstance()->setValue(SettingsConstants::alwaysOnTop, alwaysOnTop);
2✔
847
}
2✔
848

849
auto QtPassSettings::isAutoPull(const bool &defaultValue) -> bool {
4✔
850
  return getInstance()
4✔
851
      ->value(SettingsConstants::autoPull, defaultValue)
8✔
852
      .toBool();
8✔
853
}
854
void QtPassSettings::setAutoPull(const bool &autoPull) {
2✔
855
  getInstance()->setValue(SettingsConstants::autoPull, autoPull);
2✔
856
}
2✔
857

858
auto QtPassSettings::isAutoPush(const bool &defaultValue) -> bool {
4✔
859
  return getInstance()
4✔
860
      ->value(SettingsConstants::autoPush, defaultValue)
8✔
861
      .toBool();
8✔
862
}
863
void QtPassSettings::setAutoPush(const bool &autoPush) {
2✔
864
  getInstance()->setValue(SettingsConstants::autoPush, autoPush);
2✔
865
}
2✔
866

867
auto QtPassSettings::getPassTemplate(const QString &defaultValue) -> QString {
14✔
868
  return getInstance()
14✔
869
      ->value(SettingsConstants::passTemplate, defaultValue)
28✔
870
      .toString();
28✔
871
}
872
void QtPassSettings::setPassTemplate(const QString &passTemplate) {
2✔
873
  getInstance()->setValue(SettingsConstants::passTemplate, passTemplate);
2✔
874
}
2✔
875

876
auto QtPassSettings::isUseTemplate(const bool &defaultValue) -> bool {
4✔
877
  return getInstance()
4✔
878
      ->value(SettingsConstants::useTemplate, defaultValue)
8✔
879
      .toBool();
8✔
880
}
881
void QtPassSettings::setUseTemplate(const bool &useTemplate) {
2✔
882
  getInstance()->setValue(SettingsConstants::useTemplate, useTemplate);
2✔
883
}
2✔
884

885
auto QtPassSettings::isTemplateAllFields(const bool &defaultValue) -> bool {
4✔
886
  return getInstance()
4✔
887
      ->value(SettingsConstants::templateAllFields, defaultValue)
8✔
888
      .toBool();
8✔
889
}
890
void QtPassSettings::setTemplateAllFields(const bool &templateAllFields) {
2✔
891
  getInstance()->setValue(SettingsConstants::templateAllFields,
4✔
892
                          templateAllFields);
2✔
893
}
2✔
894

895
auto QtPassSettings::isShowProcessOutput(const bool &defaultValue) -> bool {
19✔
896
  return getInstance()
19✔
897
      ->value(SettingsConstants::showProcessOutput, defaultValue)
38✔
898
      .toBool();
38✔
899
}
900
void QtPassSettings::setShowProcessOutput(const bool &showProcessOutput) {
16✔
901
  getInstance()->setValue(SettingsConstants::showProcessOutput,
32✔
902
                          showProcessOutput);
16✔
903
}
16✔
904

905
auto QtPassSettings::getRealPass() -> RealPass * {
12✔
906
  return PassBackendFactory::getRealPass();
12✔
907
}
908
auto QtPassSettings::getImitatePass() -> ImitatePass * {
36✔
909
  return PassBackendFactory::getImitatePass();
36✔
910
}
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