QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
settingsserializer.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
10#include "settingsconstants.h"
11
12#include <QDebug>
13#include <QSettings>
14
18
19 int length = qs.value(SettingsConstants::passwordLength, 16).toInt();
20 if (length <= 0) {
21 length = 16;
22 }
23 config.length = length;
24
25 // The ini value is untrusted: anything outside the enum would be used as an
26 // index into PasswordConfiguration::Characters, so clamp it here, once, and
27 // every consumer sees a valid selection.
28 const int selected =
30 if (selected < 0 || selected >= PasswordConfiguration::CHARSETS_COUNT) {
31 qWarning() << "Ignoring out-of-range passwordCharsSelection" << selected;
33 } else {
34 config.selected =
35 static_cast<PasswordConfiguration::CharacterSet>(selected);
36 }
37
39 qs.value(SettingsConstants::passwordChars, QString()).toString();
40
41 return config;
42}
43
44auto SettingsSerializer::load(QSettings &qs) -> AppSettings {
46
47 // Window / session
48 s.version = qs.value(SettingsConstants::version).toString();
49 s.geometry = qs.value(SettingsConstants::geometry).toByteArray();
50 s.savestate = qs.value(SettingsConstants::savestate).toByteArray();
51 s.activeProfile = qs.value(SettingsConstants::profile).toString();
52
53 // Backend selection / store
54 s.usePass = qs.value(SettingsConstants::usePass, false).toBool();
55 s.passStore = qs.value(SettingsConstants::passStore).toString();
57
58 // Executables
60 s.gitExecutable = qs.value(SettingsConstants::gitExecutable).toString();
61 s.gpgExecutable = qs.value(SettingsConstants::gpgExecutable).toString();
64 qs.value(SettingsConstants::qrencodeExecutable).toString();
65 s.gpgHome = qs.value(SettingsConstants::gpgHome).toString();
67 qs.value(SettingsConstants::sshAuthSockOverride).toString();
68
69 // Clipboard / autoclear
70 s.clipBoardType = static_cast<Enums::ClipBoardType>(
72 static_cast<int>(Enums::CLIPBOARD_NEVER))
73 .toInt());
74 s.useSelection = qs.value(SettingsConstants::useSelection, false).toBool();
75 s.useAutoclear = qs.value(SettingsConstants::useAutoclear, false).toBool();
77 qs.value(SettingsConstants::restoreClipboard, true).toBool();
80 qs.value(SettingsConstants::useAutoclearPanel, false).toBool();
83
84 // Content display
85 s.hidePassword = qs.value(SettingsConstants::hidePassword, false).toBool();
87 qs.value(SettingsConstants::hideSecretFields, true).toBool();
88 s.hideAllFields = qs.value(SettingsConstants::hideAllFields, false).toBool();
89 // Never saved (a new settings file, or one from 1.8): the default set.
90 // Saved, it is what the user left, an empty list included.
91 if (qs.contains(SettingsConstants::secretFieldNames)) {
92 s.secretFieldNames.clear();
93 const QStringList names =
94 qs.value(SettingsConstants::secretFieldNames).toStringList();
95 for (const QString &name : names) {
96 if (!name.trimmed().isEmpty()) {
97 s.secretFieldNames << name.trimmed();
98 }
99 }
100 } else {
102 }
103 s.hideContent = qs.value(SettingsConstants::hideContent, false).toBool();
104 s.useMonospace = qs.value(SettingsConstants::useMonospace, false).toBool();
105 s.displayAsIs = qs.value(SettingsConstants::displayAsIs, false).toBool();
107 qs.value(SettingsConstants::noLineWrapping, false).toBool();
108
109 // Features
110 // Default true: AppSettings::addGPGId defaults to true.
111 s.addGPGId = qs.value(SettingsConstants::addGPGId, true).toBool();
112 s.useGit = qs.value(SettingsConstants::useGit, false).toBool();
113 s.useGrepSearch = qs.value(SettingsConstants::useGrepSearch, false).toBool();
114 // Defaults to true: OTP no longer depends on an external extension, and a
115 // stored value from an older profile still wins over this default.
116 s.useOtp = qs.value(SettingsConstants::useOtp, true).toBool();
117 s.useQrencode = qs.value(SettingsConstants::useQrencode, false).toBool();
118 s.usePwgen = qs.value(SettingsConstants::usePwgen, false).toBool();
119 s.autoPull = qs.value(SettingsConstants::autoPull, false).toBool();
120 s.autoPush = qs.value(SettingsConstants::autoPush, false).toBool();
122 qs.value(SettingsConstants::gitUseParentRepository, false).toBool();
124 qs.value(SettingsConstants::showProcessOutput, false).toBool();
125 s.showMenuBar = qs.value(SettingsConstants::showMenuBar, false).toBool();
126
127 // Templates
128 s.passTemplate = qs.value(SettingsConstants::passTemplate).toString();
129 s.useTemplate = qs.value(SettingsConstants::useTemplate, false).toBool();
131 qs.value(SettingsConstants::templateAllFields, false).toBool();
132
133 // Password generation
135 s.avoidCapitals = qs.value(SettingsConstants::avoidCapitals, false).toBool();
136 s.avoidNumbers = qs.value(SettingsConstants::avoidNumbers, false).toBool();
137 s.lessRandom = qs.value(SettingsConstants::lessRandom, false).toBool();
138 s.useSymbols = qs.value(SettingsConstants::useSymbols, false).toBool();
139
140 // System / tray
141 s.useTrayIcon = qs.value(SettingsConstants::useTrayIcon, false).toBool();
142 s.hideOnClose = qs.value(SettingsConstants::hideOnClose, false).toBool();
144 qs.value(SettingsConstants::startMinimized, false).toBool();
145 s.alwaysOnTop = qs.value(SettingsConstants::alwaysOnTop, false).toBool();
146
147 return s;
148}
149
150void SettingsSerializer::save(QSettings &qs, const AppSettings &s) {
151 // Window / session
152 qs.setValue(SettingsConstants::version, s.version);
156
157 // Backend selection / store
158 qs.setValue(SettingsConstants::usePass, s.usePass);
161
162 // Executables
168 qs.setValue(SettingsConstants::gpgHome, s.gpgHome);
170
171 // Clipboard / autoclear
173 static_cast<int>(s.clipBoardType));
181
182 // Content display
191
192 // Features
194 qs.setValue(SettingsConstants::useGit, s.useGit);
196 qs.setValue(SettingsConstants::useOtp, s.useOtp);
199 // The WebDAV mount was removed in 2.0; drop its keys, including the
200 // plaintext webDavPassword, from configurations written by older versions.
201 for (const auto &obsolete :
202 {QStringLiteral("useWebDav"), QStringLiteral("webDavUrl"),
203 QStringLiteral("webDavUser"), QStringLiteral("webDavPassword")}) {
204 qs.remove(obsolete);
205 }
212
213 // Templates
217
218 // Password generation
222 static_cast<int>(s.passwordConfiguration.selected));
223 qs.setValue(
230
231 // System / tray
236}
static const QString savestate
Saved dock and toolbar state of the main window (mainwindow/savestate). Bytes from QMainWindow::saveS...
static const QString useSelection
Copy to the X11 primary selection instead of the clipboard, where the platform has one....
static const QString passExecutable
Path of the pass program. Text.
static const QString noLineWrapping
Do not wrap long lines in the content panel. Boolean, default false.
static const QString restoreClipboard
When autoclear runs, put back what was on the clipboard before the copy. Boolean, default true.
static const QString useGrepSearch
Offer the search in the content of entries. Boolean, default false.
static const QString autoPull
With Git in use: run git pull before an entry is edited and before entries are re-encrypted....
static const QString lessRandom
pwgen: passwords that are easier to remember; off adds --secure. Boolean, default false.
static const QString secretFieldNames
Field names that hideSecretFields masks. List of text; absent means AppSettings::defaultSecretFieldNa...
static const QString pwgenExecutable
Path of the pwgen program. Text.
static const QString geometry
Saved geometry of the main window (mainwindow/geometry). Bytes from QWidget::saveGeometry().
static const QString gpgHome
GnuPG home folder that takes the place of GNUPGHOME when it exists. Path as text, empty for none.
static const QString version
Version of QtPass that last wrote the settings. Text.
static const QString passTemplate
Field names of the entry template, one per line. Text.
static const QString showProcessOutput
Show the Process Output panel. Boolean, default false.
static const QString useAutoclear
Clear the clipboard some time after a copy. Boolean, default false.
static const QString clipBoardType
When a password goes to the clipboard, as an Enums::ClipBoardType number. Integer,...
static const QString autoclearPanelSeconds
Seconds until the content panel is cleared. Integer, default 0.
static const QString avoidNumbers
pwgen: no digits (--no-numerals). Boolean, default false.
static const QString useAutoclearPanel
Clear the content panel some time after an entry is shown. Boolean, default false.
static const QString gitUseParentRepository
Let Git use a repository in a folder above the store when the store has none of its own....
static const QString usePass
Run the pass program (true) or call gpg and Git directly (false). Boolean, default false.
static const QString hideOnClose
With a tray icon: closing the window hides it to the tray and QtPass keeps running....
static const QString alwaysOnTop
Keep the main window above other windows. Boolean, default false.
static const QString useGit
Use Git in the store. Boolean, default false; a profile can set its own value.
static const QString gitExecutable
Path of the git program. Text.
static const QString gpgExecutable
Path of the gpg or gpg2 program. Text.
static const QString profile
Name of the active profile, and also the group profile/<name>/ that holds each profile (path,...
static const QString hideSecretFields
With hidePassword: mask the fields named in secretFieldNames too. Boolean, default true.
static const QString hideAllFields
With hidePassword: mask every field, not only the secret ones. Boolean, default false.
static const QString useTrayIcon
Show an icon in the system tray. Boolean, default false.
static const QString passwordCharsSelection
Character set of the built-in generator, as a PasswordConfiguration::CharacterSet number....
static const QString useOtp
Show one-time codes for entries that hold an otpauth:// line. Boolean, default true.
static const QString startMinimized
With useTrayIcon and a system tray present: start with the window hidden in the tray....
static const QString hideContent
Show no content of an entry at all. Boolean, default false.
static const QString avoidCapitals
pwgen: no capital letters (--no-capitalize). Boolean, default false.
static const QString autoclearSeconds
Seconds until the clipboard is cleared. Integer, default 0.
static const QString usePwgen
Generate passwords with the pwgen program, not with the built-in generator. Boolean,...
static const QString useMonospace
Show the content in a monospace font. Boolean, default false.
static const QString passwordLength
Length of a generated password. Integer, default 16; a value of 0 or less is read as 16.
static const QString qrencodeExecutable
Path of the qrencode program. Text.
static const QString passStore
Root folder of the password store. Path as text.
static const QString passwordChars
The user's own alphabet for the CUSTOM character set. Text.
static const QString displayAsIs
Show the file content as it is, without splitting it into fields. Boolean, default false.
static const QString sshAuthSockOverride
Value for SSH_AUTH_SOCK that replaces the one found. Path as text, empty for none.
static const QString useSymbols
pwgen: include symbols (--symbols). Boolean, default false.
static const QString passSigningKey
Keys that sign and check the .gpg-id files, separated by spaces. Text. Empty means the exported PASSW...
static const QString templateAllFields
With useTemplate: show every key: value line as a field, not only the template's. Boolean,...
static const QString addGPGId
With Git in use: add a changed .gpg-id file to Git. Boolean, default true.
static const QString showMenuBar
Show the menu bar. Boolean, default false.
static const QString useQrencode
Offer QR codes made with the qrencode program. Boolean, default false.
static const QString useTemplate
Offer the template fields in the entry dialog. Boolean, default false.
static const QString autoPush
Run git push after each change. Boolean, default false; a profile can set its own value.
static const QString hidePassword
Mask the password line in the content panel. Boolean, default false.
static auto loadPasswordConfiguration(QSettings &qs) -> PasswordConfiguration
Read only the password generation settings from a QSettings store.
static void save(QSettings &qs, const AppSettings &settings)
Write all flat settings to a QSettings store.
static auto load(QSettings &qs) -> AppSettings
Read all flat settings from a QSettings store.
ClipBoardType
Defines when to copy passwords to clipboard.
Definition enums.h:24
@ CLIPBOARD_NEVER
Definition enums.h:25
Names of the keys QtPass stores its settings under.
SettingsSerializer: the flat AppSettings fields to and from their QSettings keys, without side effect...
Plain value-object holding all flat QtPass configuration.
Definition appsettings.h:36
bool displayAsIs
Show file content unmodified.
Definition appsettings.h:97
QByteArray geometry
Main-window saved geometry.
Definition appsettings.h:54
bool useGrepSearch
Enable content (grep) search.
QString gpgExecutable
Path to the gpg/gpg2 executable.
Definition appsettings.h:66
QString qrencodeExecutable
Path to the qrencode executable.
Definition appsettings.h:68
QString sshAuthSockOverride
Manual SSH_AUTH_SOCK override path.
Definition appsettings.h:70
bool lessRandom
Generate memorable (less random) passwords.
bool useSymbols
Include special symbols.
bool hideOnClose
Hide to tray instead of quitting on close.
QStringList secretFieldNames
Definition appsettings.h:91
QString passSigningKey
GPG key used to sign .gpg-id files.
Definition appsettings.h:61
bool usePass
Use the pass CLI (true) or native git/gpg.
Definition appsettings.h:59
QString pwgenExecutable
Path to the pwgen executable.
Definition appsettings.h:67
bool hideContent
Hide the entire content panel.
Definition appsettings.h:95
bool useOtp
Enable native TOTP (OTP) support.
QString passStore
Password-store root path.
Definition appsettings.h:60
bool hidePassword
Definition appsettings.h:85
bool useAutoclearPanel
Clear the content panel after a delay.
Definition appsettings.h:81
bool noLineWrapping
Disable line wrapping in the panel.
Definition appsettings.h:98
bool showMenuBar
Show the menu bar (Ctrl+M toggles it).
QString gitExecutable
Path to the git executable.
Definition appsettings.h:65
QString gpgHome
GPG home directory (read-only externally).
Definition appsettings.h:69
static auto defaultSecretFieldNames() -> QStringList
The secret field names a new or emptied setting starts with: what an entry commonly holds besides its...
Definition appsettings.h:42
bool autoPull
git pull before an entry is edited and before a re-encryption.
bool alwaysOnTop
Keep the main window always on top.
int autoclearPanelSeconds
Panel autoclear delay (seconds).
Definition appsettings.h:82
bool hideSecretFields
Definition appsettings.h:88
bool showProcessOutput
Show external process output.
bool startMinimized
Start the window minimised.
bool useTrayIcon
Show a system tray icon.
bool gitUseParentRepository
QString passExecutable
Path to the pass executable.
Definition appsettings.h:64
bool avoidCapitals
Exclude uppercase letters.
int autoclearSeconds
Clipboard autoclear delay (seconds).
Definition appsettings.h:80
bool useSelection
Use the X11 primary selection.
Definition appsettings.h:75
bool useGit
Enable git integration.
bool restoreClipboard
Definition appsettings.h:79
bool addGPGId
Auto-add .gpg-id files to git.
Enums::ClipBoardType clipBoardType
Clipboard copy behaviour.
Definition appsettings.h:73
bool hideAllFields
Definition appsettings.h:94
QString version
Last-run application version.
Definition appsettings.h:53
QByteArray savestate
Main-window saved dock/toolbar state.
Definition appsettings.h:55
QString passTemplate
Newline-separated template field names.
bool useAutoclear
Definition appsettings.h:76
bool useMonospace
Render content in a monospace font.
Definition appsettings.h:96
bool templateAllFields
Treat every key: line as a field.
bool avoidNumbers
Exclude digits.
bool useQrencode
Enable qrencode support.
QString activeProfile
Name of the active profile.
Definition appsettings.h:56
bool useTemplate
Use the password template.
PasswordConfiguration passwordConfiguration
Length/charset/custom chars.
Holds the password generator settings: which character set is selected, the alphabet of every set,...
int length
Length of the generated password, in characters.
CharacterSet selected
Currently active character set selection.
CharacterSet
Character set options for password generation; also the index into Characters.
std::array< QString, CHARSETS_COUNT > Characters
The alphabet of each character set, indexed by CharacterSet. Only the CUSTOM entry is meant to be cha...