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

IJHack / QtPass / 27715987383

17 Jun 2026 07:58PM UTC coverage: 56.049% (-1.0%) from 57.077%
27715987383

Pull #1562

github

web-flow
Merge 189de87e3 into fd4120a46
Pull Request #1562: refactor(#1511): delete 30 dead getter wrappers from QtPassSettings

9 of 9 new or added lines in 1 file covered. (100.0%)

20 existing lines in 1 file now uncovered.

3827 of 6828 relevant lines covered (56.05%)

24.62 hits per line

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

90.42
/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,132✔
42
  if (!QtPassSettings::initialized) {
1,132✔
43
    QString portable_ini = QCoreApplication::applicationDirPath() +
8✔
44
                           QDir::separator() + "qtpass.ini";
8✔
45
    if (QFile(portable_ini).exists()) {
8✔
46
      m_instance = new QtPassSettings(portable_ini, QSettings::IniFormat);
×
47
    } else {
48
      m_instance = new QtPassSettings("IJHack", "QtPass");
16✔
49
    }
50

51
    initialized = true;
8✔
52
  }
53

54
  return m_instance;
1,132✔
55
}
56

57
auto QtPassSettings::load() -> AppSettings {
207✔
58
  AppSettings s = SettingsSerializer::load(*getInstance());
207✔
59
  if (!s.passStore.isEmpty()) {
207✔
60
    s.passStore = QDir::cleanPath(QDir(s.passStore).absolutePath());
408✔
61
    if (!s.passStore.endsWith('/'))
204✔
62
      s.passStore += '/';
204✔
63
  }
64
  return s;
207✔
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 * {
53✔
195
  return PassBackendFactory::getPass();
53✔
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
void QtPassSettings::setMaximized(const bool &maximized) {
2✔
252
  getInstance()->setValue(SettingsConstants::maximized, maximized);
2✔
253
}
2✔
254

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

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

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

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

300
void QtPassSettings::setUsePass(const bool &usePass) {
18✔
301
  getInstance()->setValue(SettingsConstants::usePass, usePass);
18✔
302
  // Backend selection changed: force re-selection on next getPass().
303
  PassBackendFactory::invalidate();
18✔
304
}
18✔
305

306
void QtPassSettings::setClipBoardType(const int &clipBoardType) {
1✔
307
  getInstance()->setValue(SettingsConstants::clipBoardType, clipBoardType);
1✔
308
}
1✔
309

310
void QtPassSettings::setUseSelection(const bool &useSelection) {
2✔
311
  getInstance()->setValue(SettingsConstants::useSelection, useSelection);
2✔
312
}
2✔
313

314
void QtPassSettings::setUseAutoclear(const bool &useAutoclear) {
2✔
315
  getInstance()->setValue(SettingsConstants::useAutoclear, useAutoclear);
2✔
316
}
2✔
317

318
auto QtPassSettings::getAutoclearSeconds(const int &defaultValue) -> int {
12✔
319
  return getInstance()
12✔
320
      ->value(SettingsConstants::autoclearSeconds, defaultValue)
24✔
321
      .toInt();
24✔
322
}
323
void QtPassSettings::setAutoclearSeconds(const int &autoClearSeconds) {
2✔
324
  getInstance()->setValue(SettingsConstants::autoclearSeconds,
2✔
325
                          autoClearSeconds);
326
}
2✔
327

328
void QtPassSettings::setUseAutoclearPanel(const bool &useAutoclearPanel) {
2✔
329
  getInstance()->setValue(SettingsConstants::useAutoclearPanel,
4✔
330
                          useAutoclearPanel);
2✔
331
}
2✔
332

UNCOV
333
auto QtPassSettings::getAutoclearPanelSeconds(const int &defaultValue) -> int {
×
UNCOV
334
  return getInstance()
×
UNCOV
335
      ->value(SettingsConstants::autoclearPanelSeconds, defaultValue)
×
UNCOV
336
      .toInt();
×
337
}
338
void QtPassSettings::setAutoclearPanelSeconds(
2✔
339
    const int &autoClearPanelSeconds) {
340
  getInstance()->setValue(SettingsConstants::autoclearPanelSeconds,
2✔
341
                          autoClearPanelSeconds);
342
}
2✔
343

344
void QtPassSettings::setHidePassword(const bool &hidePassword) {
2✔
345
  getInstance()->setValue(SettingsConstants::hidePassword, hidePassword);
2✔
346
}
2✔
347

348
void QtPassSettings::setHideContent(const bool &hideContent) {
2✔
349
  getInstance()->setValue(SettingsConstants::hideContent, hideContent);
2✔
350
}
2✔
351

352
void QtPassSettings::setUseMonospace(const bool &useMonospace) {
2✔
353
  getInstance()->setValue(SettingsConstants::useMonospace, useMonospace);
2✔
354
}
2✔
355

356
void QtPassSettings::setDisplayAsIs(const bool &displayAsIs) {
2✔
357
  getInstance()->setValue(SettingsConstants::displayAsIs, displayAsIs);
2✔
358
}
2✔
359

360
void QtPassSettings::setNoLineWrapping(const bool &noLineWrapping) {
2✔
361
  getInstance()->setValue(SettingsConstants::noLineWrapping, noLineWrapping);
2✔
362
}
2✔
363

364
void QtPassSettings::setAddGPGId(const bool &addGPGId) {
2✔
365
  getInstance()->setValue(SettingsConstants::addGPGId, addGPGId);
2✔
366
}
2✔
367

368
/**
369
 * @brief Retrieves the password store path, normalizes it, and ensures the
370
 * directory exists.
371
 * @example
372
 * QString passStore =
373
 * QtPassSettings::getPassStore("/home/user/.password-store"); qDebug() <<
374
 * passStore; // Expected output: "/home/user/.password-store/"
375
 *
376
 * @param defaultValue - Fallback path used when no password store is
377
 * configured.
378
 * @return QString - The normalized absolute password store path, guaranteed to
379
 * end with a path separator.
380
 */
381
auto QtPassSettings::getPassStore(const QString &defaultValue) -> QString {
33✔
382
  QString returnValue = getInstance()
33✔
383
                            ->value(SettingsConstants::passStore, defaultValue)
66✔
384
                            .toString();
33✔
385

386
  // Normalize the path string
387
  returnValue = QDir(returnValue).absolutePath();
66✔
388

389
  // ensure directory exists if never used pass or misconfigured.
390
  // otherwise process->setWorkingDirectory(passStore); will fail on execution.
391
  if (!QDir(returnValue).exists()) {
33✔
392
    if (!QDir().mkdir(returnValue)) {
4✔
393
      qWarning() << "Failed to create password store directory:" << returnValue;
×
394
    }
395
  }
396

397
  // ensure path ends in /
398
  if (!returnValue.endsWith("/") && !returnValue.endsWith(QDir::separator())) {
66✔
399
    returnValue += QDir::separator();
33✔
400
  }
401

402
  return returnValue;
33✔
403
}
404
void QtPassSettings::setPassStore(const QString &passStore) {
51✔
405
  getInstance()->setValue(SettingsConstants::passStore, passStore);
51✔
406
}
51✔
407

408
auto QtPassSettings::getPassSigningKey(const QString &defaultValue) -> QString {
1✔
409
  return getInstance()
1✔
410
      ->value(SettingsConstants::passSigningKey, defaultValue)
2✔
411
      .toString();
2✔
412
}
413
void QtPassSettings::setPassSigningKey(const QString &passSigningKey) {
4✔
414
  getInstance()->setValue(SettingsConstants::passSigningKey, passSigningKey);
4✔
415
}
4✔
416

417
/**
418
 * @brief Initializes executable paths for Pass, Git, GPG, and Pwgen by locating
419
 * them in the system PATH.
420
 * @example
421
 * QtPassSettings::initExecutables();
422
 *
423
 * @return void - This method does not return a value.
424
 */
425
void QtPassSettings::initExecutables() {
12✔
426
  const AppSettings s = QtPassSettings::load();
12✔
427
  QtPassSettings::setPassExecutable(s.passExecutable.isEmpty()
12✔
428
                                        ? Util::findBinaryInPath("pass")
24✔
429
                                        : s.passExecutable);
430
  QtPassSettings::setGitExecutable(s.gitExecutable.isEmpty()
12✔
431
                                       ? Util::findBinaryInPath("git")
24✔
432
                                       : s.gitExecutable);
433
  QtPassSettings::setGpgExecutable(s.gpgExecutable.isEmpty()
12✔
434
                                       ? Util::findBinaryInPath("gpg2")
24✔
435
                                       : s.gpgExecutable);
436
  QtPassSettings::setPwgenExecutable(s.pwgenExecutable.isEmpty()
12✔
437
                                         ? Util::findBinaryInPath("pwgen")
24✔
438
                                         : s.pwgenExecutable);
439
}
12✔
440
auto QtPassSettings::getPassExecutable(const QString &defaultValue) -> QString {
13✔
441
  return getInstance()
13✔
442
      ->value(SettingsConstants::passExecutable, defaultValue)
26✔
443
      .toString();
26✔
444
}
445
void QtPassSettings::setPassExecutable(const QString &passExecutable) {
14✔
446
  getInstance()->setValue(SettingsConstants::passExecutable, passExecutable);
14✔
447
}
14✔
448

449
auto QtPassSettings::getSshAuthSockOverride(const QString &defaultValue)
10✔
450
    -> QString {
451
  return getInstance()
10✔
452
      ->value(SettingsConstants::sshAuthSockOverride, defaultValue)
20✔
453
      .toString();
20✔
454
}
455
void QtPassSettings::setSshAuthSockOverride(const QString &value) {
12✔
456
  getInstance()->setValue(SettingsConstants::sshAuthSockOverride, value);
12✔
457
}
12✔
458

459
void QtPassSettings::setGitExecutable(const QString &gitExecutable) {
15✔
460
  getInstance()->setValue(SettingsConstants::gitExecutable, gitExecutable);
15✔
461
}
15✔
462

463
void QtPassSettings::setGpgExecutable(const QString &gpgExecutable) {
32✔
464
  getInstance()->setValue(SettingsConstants::gpgExecutable, gpgExecutable);
32✔
465
}
32✔
466

UNCOV
467
auto QtPassSettings::getPwgenExecutable(const QString &defaultValue)
×
468
    -> QString {
UNCOV
469
  return getInstance()
×
UNCOV
470
      ->value(SettingsConstants::pwgenExecutable, defaultValue)
×
UNCOV
471
      .toString();
×
472
}
473
void QtPassSettings::setPwgenExecutable(const QString &pwgenExecutable) {
14✔
474
  getInstance()->setValue(SettingsConstants::pwgenExecutable, pwgenExecutable);
14✔
475
}
14✔
476

477
auto QtPassSettings::getGpgHome(const QString &defaultValue) -> QString {
×
478
  return getInstance()
×
479
      ->value(SettingsConstants::gpgHome, defaultValue)
×
480
      .toString();
×
481
}
482

483
auto QtPassSettings::isUseWebDav(const bool &defaultValue) -> bool {
12✔
484
  return getInstance()
12✔
485
      ->value(SettingsConstants::useWebDav, defaultValue)
24✔
486
      .toBool();
24✔
487
}
488
void QtPassSettings::setUseWebDav(const bool &useWebDav) {
2✔
489
  getInstance()->setValue(SettingsConstants::useWebDav, useWebDav);
2✔
490
}
2✔
491

492
void QtPassSettings::setWebDavUrl(const QString &webDavUrl) {
2✔
493
  getInstance()->setValue(SettingsConstants::webDavUrl, webDavUrl);
2✔
494
}
2✔
495

496
void QtPassSettings::setWebDavUser(const QString &webDavUser) {
2✔
497
  getInstance()->setValue(SettingsConstants::webDavUser, webDavUser);
2✔
498
}
2✔
499

500
void QtPassSettings::setWebDavPassword(const QString &webDavPassword) {
2✔
501
  getInstance()->setValue(SettingsConstants::webDavPassword, webDavPassword);
2✔
502
}
2✔
503

504
auto QtPassSettings::getProfile(const QString &defaultValue) -> QString {
26✔
505
  return getInstance()
26✔
506
      ->value(SettingsConstants::profile, defaultValue)
52✔
507
      .toString();
52✔
508
}
509
void QtPassSettings::setProfile(const QString &profile) {
3✔
510
  getInstance()->setValue(SettingsConstants::profile, profile);
3✔
511
}
3✔
512

513
/**
514
 * @brief Gets the useGit setting for a specific profile.
515
 * @param profileName The profile name.
516
 * @param defaultValue The default value if not set.
517
 * @return The useGit setting for the profile.
518
 */
519
auto QtPassSettings::getProfileUseGit(const QString &profileName,
3✔
520
                                      const bool &defaultValue) -> bool {
521
  QString stored =
522
      getInstance()
3✔
523
          ->value(SettingsConstants::profile + "/" + profileName + "/useGit")
9✔
524
          .toString();
3✔
525
  // If empty or not set, return default (migration-friendly fallback)
526
  if (stored.isEmpty()) {
3✔
527
    return defaultValue;
1✔
528
  }
529
  return stored == "true";
530
}
531

532
/**
533
 * @brief Sets the useGit setting for a specific profile.
534
 * @param profileName The profile name.
535
 * @param useGit The useGit value to set.
536
 */
537
void QtPassSettings::setProfileUseGit(const QString &profileName,
2✔
538
                                      const bool &useGit) {
539
  getInstance()->setValue(SettingsConstants::profile + "/" + profileName +
6✔
540
                              "/useGit",
541
                          useGit ? "true" : "false");
2✔
542
}
2✔
543

544
/**
545
 * @brief Gets the autoPush setting for a specific profile.
546
 * @param profileName The profile name.
547
 * @param defaultValue The default value if not set.
548
 * @return The autoPush setting for the profile.
549
 */
550
auto QtPassSettings::getProfileAutoPush(const QString &profileName,
3✔
551
                                        const bool &defaultValue) -> bool {
552
  QString stored =
553
      getInstance()
3✔
554
          ->value(SettingsConstants::profile + "/" + profileName + "/autoPush")
9✔
555
          .toString();
3✔
556
  if (stored.isEmpty()) {
3✔
557
    return defaultValue;
1✔
558
  }
559
  return stored == "true";
560
}
561

562
/**
563
 * @brief Sets the autoPush setting for a specific profile.
564
 * @param profileName The profile name.
565
 * @param autoPush The autoPush value to set.
566
 */
567
void QtPassSettings::setProfileAutoPush(const QString &profileName,
2✔
568
                                        const bool &autoPush) {
569
  getInstance()->setValue(SettingsConstants::profile + "/" + profileName +
6✔
570
                              "/autoPush",
571
                          autoPush ? "true" : "false");
2✔
572
}
2✔
573

574
/**
575
 * @brief Gets the autoPull setting for a specific profile.
576
 * @param profileName The profile name.
577
 * @param defaultValue The default value if not set.
578
 * @return The autoPull setting for the profile.
579
 */
580
auto QtPassSettings::getProfileAutoPull(const QString &profileName,
3✔
581
                                        const bool &defaultValue) -> bool {
582
  QString stored =
583
      getInstance()
3✔
584
          ->value(SettingsConstants::profile + "/" + profileName + "/autoPull")
9✔
585
          .toString();
3✔
586
  if (stored.isEmpty()) {
3✔
587
    return defaultValue;
1✔
588
  }
589
  return stored == "true";
590
}
591

592
/**
593
 * @brief Sets the autoPull setting for a specific profile.
594
 * @param profileName The profile name.
595
 * @param autoPull The autoPull value to set.
596
 */
597
void QtPassSettings::setProfileAutoPull(const QString &profileName,
2✔
598
                                        const bool &autoPull) {
599
  getInstance()->setValue(SettingsConstants::profile + "/" + profileName +
6✔
600
                              "/autoPull",
601
                          autoPull ? "true" : "false");
2✔
602
}
2✔
603

604
/**
605
 * @brief Determines whether Git should be used for the current QtPass settings.
606
 * @example
607
 * bool result = QtPassSettings::isUseGit(true);
608
 * std::cout << result << std::endl; // Expected output: true or false
609
 *
610
 * @param const bool &defaultValue - The fallback value used when no explicit
611
 * setting is stored.
612
 * @return bool - True if Git usage is enabled, otherwise false.
613
 */
614
auto QtPassSettings::isUseGit(const bool &defaultValue) -> bool {
6✔
615
  bool storedValue =
616
      getInstance()->value(SettingsConstants::useGit, defaultValue).toBool();
6✔
617
  if (storedValue == defaultValue && defaultValue) {
6✔
618
    QString passStore = getPassStore();
4✔
619
    if (QFileInfo(passStore).isDir() &&
4✔
620
        QFileInfo(passStore + QDir::separator() + ".git").isDir()) {
6✔
621
      return true;
622
    }
623
  }
624
  return storedValue;
625
}
626
void QtPassSettings::setUseGit(const bool &useGit) {
6✔
627
  getInstance()->setValue(SettingsConstants::useGit, useGit);
6✔
628
}
6✔
629

630
auto QtPassSettings::isUseGrepSearch(const bool &defaultValue) -> bool {
12✔
631
  return getInstance()
12✔
632
      ->value(SettingsConstants::useGrepSearch, defaultValue)
24✔
633
      .toBool();
24✔
634
}
635

636
void QtPassSettings::setUseGrepSearch(const bool &useGrepSearch) {
2✔
637
  getInstance()->setValue(SettingsConstants::useGrepSearch, useGrepSearch);
2✔
638
}
2✔
639

640
auto QtPassSettings::isUseOtp(const bool &defaultValue) -> bool {
15✔
641
  return getInstance()->value(SettingsConstants::useOtp, defaultValue).toBool();
15✔
642
}
643

644
void QtPassSettings::setUseOtp(const bool &useOtp) {
2✔
645
  getInstance()->setValue(SettingsConstants::useOtp, useOtp);
2✔
646
}
2✔
647

648
void QtPassSettings::setUseQrencode(const bool &useQrencode) {
2✔
649
  getInstance()->setValue(SettingsConstants::useQrencode, useQrencode);
2✔
650
}
2✔
651

652
void QtPassSettings::setQrencodeExecutable(const QString &qrencodeExecutable) {
15✔
653
  getInstance()->setValue(SettingsConstants::qrencodeExecutable,
15✔
654
                          qrencodeExecutable);
655
}
15✔
656

657
void QtPassSettings::setUsePwgen(const bool &usePwgen) {
6✔
658
  getInstance()->setValue(SettingsConstants::usePwgen, usePwgen);
6✔
659
}
6✔
660

661
void QtPassSettings::setAvoidCapitals(const bool &avoidCapitals) {
2✔
662
  getInstance()->setValue(SettingsConstants::avoidCapitals, avoidCapitals);
2✔
663
}
2✔
664

665
void QtPassSettings::setAvoidNumbers(const bool &avoidNumbers) {
2✔
666
  getInstance()->setValue(SettingsConstants::avoidNumbers, avoidNumbers);
2✔
667
}
2✔
668

669
void QtPassSettings::setLessRandom(const bool &lessRandom) {
2✔
670
  getInstance()->setValue(SettingsConstants::lessRandom, lessRandom);
2✔
671
}
2✔
672

673
void QtPassSettings::setUseSymbols(const bool &useSymbols) {
2✔
674
  getInstance()->setValue(SettingsConstants::useSymbols, useSymbols);
2✔
675
}
2✔
676

677
void QtPassSettings::setPasswordLength(const int &passwordLength) {
2✔
678
  getInstance()->setValue(SettingsConstants::passwordLength, passwordLength);
2✔
679
}
2✔
680
void QtPassSettings::setPasswordCharsSelection(
6✔
681
    const int &passwordCharsSelection) {
682
  getInstance()->setValue(SettingsConstants::passwordCharsSelection,
6✔
683
                          passwordCharsSelection);
684
}
6✔
685
void QtPassSettings::setPasswordChars(const QString &passwordChars) {
5✔
686
  getInstance()->setValue(SettingsConstants::passwordChars, passwordChars);
5✔
687
}
5✔
688

689
void QtPassSettings::setUseTrayIcon(const bool &useTrayIcon) {
2✔
690
  getInstance()->setValue(SettingsConstants::useTrayIcon, useTrayIcon);
2✔
691
}
2✔
692

UNCOV
693
auto QtPassSettings::isHideOnClose(const bool &defaultValue) -> bool {
×
UNCOV
694
  return getInstance()
×
UNCOV
695
      ->value(SettingsConstants::hideOnClose, defaultValue)
×
UNCOV
696
      .toBool();
×
697
}
698
void QtPassSettings::setHideOnClose(const bool &hideOnClose) {
2✔
699
  getInstance()->setValue(SettingsConstants::hideOnClose, hideOnClose);
2✔
700
}
2✔
701

702
void QtPassSettings::setStartMinimized(const bool &startMinimized) {
2✔
703
  getInstance()->setValue(SettingsConstants::startMinimized, startMinimized);
2✔
704
}
2✔
705

UNCOV
706
auto QtPassSettings::isAlwaysOnTop(const bool &defaultValue) -> bool {
×
UNCOV
707
  return getInstance()
×
UNCOV
708
      ->value(SettingsConstants::alwaysOnTop, defaultValue)
×
UNCOV
709
      .toBool();
×
710
}
711
void QtPassSettings::setAlwaysOnTop(const bool &alwaysOnTop) {
2✔
712
  getInstance()->setValue(SettingsConstants::alwaysOnTop, alwaysOnTop);
2✔
713
}
2✔
714

715
void QtPassSettings::setAutoPull(const bool &autoPull) {
2✔
716
  getInstance()->setValue(SettingsConstants::autoPull, autoPull);
2✔
717
}
2✔
718

UNCOV
719
auto QtPassSettings::isAutoPush(const bool &defaultValue) -> bool {
×
UNCOV
720
  return getInstance()
×
UNCOV
721
      ->value(SettingsConstants::autoPush, defaultValue)
×
UNCOV
722
      .toBool();
×
723
}
724
void QtPassSettings::setAutoPush(const bool &autoPush) {
2✔
725
  getInstance()->setValue(SettingsConstants::autoPush, autoPush);
2✔
726
}
2✔
727

728
auto QtPassSettings::getPassTemplate(const QString &defaultValue) -> QString {
12✔
729
  return getInstance()
12✔
730
      ->value(SettingsConstants::passTemplate, defaultValue)
24✔
731
      .toString();
24✔
732
}
733
void QtPassSettings::setPassTemplate(const QString &passTemplate) {
2✔
734
  getInstance()->setValue(SettingsConstants::passTemplate, passTemplate);
2✔
735
}
2✔
736

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

741
void QtPassSettings::setTemplateAllFields(const bool &templateAllFields) {
2✔
742
  getInstance()->setValue(SettingsConstants::templateAllFields,
4✔
743
                          templateAllFields);
2✔
744
}
2✔
745

746
auto QtPassSettings::isShowProcessOutput(const bool &defaultValue) -> bool {
15✔
747
  return getInstance()
15✔
748
      ->value(SettingsConstants::showProcessOutput, defaultValue)
30✔
749
      .toBool();
30✔
750
}
751
void QtPassSettings::setShowProcessOutput(const bool &showProcessOutput) {
16✔
752
  getInstance()->setValue(SettingsConstants::showProcessOutput,
32✔
753
                          showProcessOutput);
16✔
754
}
16✔
755

756
auto QtPassSettings::getRealPass() -> RealPass * {
12✔
757
  return PassBackendFactory::getRealPass();
12✔
758
}
759
auto QtPassSettings::getImitatePass() -> ImitatePass * {
36✔
760
  return PassBackendFactory::getImitatePass();
36✔
761
}
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