16#include <QCoreApplication>
22#include <QGuiApplication>
33 QString portable_ini = QCoreApplication::applicationDirPath() +
34 QDir::separator() +
"qtpass.ini";
35 if (QFile(portable_ini).exists()) {
68 getInstance()->beginGroup(SettingsConstants::profile);
73 for (
const auto &key : std::as_const(childKeys)) {
76 profiles.insert(key, profile);
80 QStringList childGroups =
getInstance()->childGroups();
81 for (
const auto &group : std::as_const(childGroups)) {
86 getInstance()->value(group +
"/useGit").toString());
88 getInstance()->value(group +
"/autoPush").toString());
90 getInstance()->value(group +
"/autoPull").toString());
91 profiles.insert(group, profile);
103 const QString activeProfile =
104 getInstance()->value(SettingsConstants::profile).toString();
106 if (!activeProfile.isEmpty()) {
107 getInstance()->setValue(SettingsConstants::profile, activeProfile);
109 getInstance()->beginGroup(SettingsConstants::profile);
111 for (
auto i = profiles.cbegin(); i != profiles.cend(); ++i) {
112 getInstance()->setValue(i.key() +
"/path", i.value().path);
113 getInstance()->setValue(i.key() +
"/signingKey", i.value().signingKey);
131 ->value(SettingsConstants::version, defaultValue)
135 getInstance()->setValue(SettingsConstants::version, version);
140 ->value(SettingsConstants::geometry, defaultValue)
144 getInstance()->setValue(SettingsConstants::geometry, geometry);
150 ->value(SettingsConstants::savestate, defaultValue)
154 getInstance()->setValue(SettingsConstants::savestate, saveState);
158 const QByteArray &defaultValue)
161 ->value(SettingsConstants::dialogGeometry +
"/" + key, defaultValue)
165 const QByteArray &geometry) {
166 getInstance()->setValue(SettingsConstants::dialogGeometry +
"/" + key,
171 getInstance()->setValue(SettingsConstants::usePass, usePass);
178 ->value(SettingsConstants::autoclearSeconds, defaultValue)
184 ->value(SettingsConstants::passStore, defaultValue)
187 returnValue = QDir(returnValue).absolutePath();
191 if (!QDir(returnValue).exists()) {
193 qWarning() <<
"Failed to create password store directory:" << returnValue;
197 if (!returnValue.endsWith(
"/") && !returnValue.endsWith(QDir::separator())) {
198 returnValue += QDir::separator();
204 getInstance()->setValue(SettingsConstants::passStore, passStore);
223 ->value(SettingsConstants::passExecutable, defaultValue)
229 ->value(SettingsConstants::profile, defaultValue)
235 getInstance()->value(SettingsConstants::useGit, defaultValue).toBool();
236 if (storedValue == defaultValue && defaultValue) {
238 if (QFileInfo(passStore).isDir() &&
239 QFileInfo(passStore + QDir::separator() +
".git").isDir()) {
247 ->value(SettingsConstants::useGrepSearch, defaultValue)
252 return getInstance()->value(SettingsConstants::useOtp, defaultValue).toBool();
256 getInstance()->setValue(SettingsConstants::qrencodeExecutable,
262 ->value(SettingsConstants::hideOnClose, defaultValue)
267 ->value(SettingsConstants::alwaysOnTop, defaultValue)
273 ->value(SettingsConstants::autoPush, defaultValue)
279 ->value(SettingsConstants::showProcessOutput, defaultValue)
Implementation that imitates 'pass' when the real tool is unavailable.
static auto getPass() -> Pass *
Get the active backend, constructing and initialising it on first use after construction or invalidat...
static auto getRealPass() -> RealPass *
Get the lazily-constructed RealPass backend.
static auto isIdle() -> bool
Whether neither backend runs or waits for anything: after a switch of backend the previous one is kep...
static auto getImitatePass() -> ImitatePass *
Get the lazily-constructed ImitatePass backend.
static void invalidate()
Forget the currently active backend.
Abstract base class for password store operations.
Singleton that stores QtPass settings, handles persistence and defaults.
static bool initialized
Whether getInstance() has chosen the store and built m_instance.
static auto getInstance() -> QtPassSettings *
Get the singleton instance.
static void setPassStore(const QString &passStore)
Save password store path.
static auto getPass() -> Pass *
Get currently active pass backend instance.
static auto getPasswordConfiguration() -> PasswordConfiguration
Get complete password generation configuration.
static auto isUseGit(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether Git integration is enabled.
static auto isUseOtp(const bool &defaultValue=true) -> bool
Check whether OTP support is enabled.
static auto getPassStore(const QString &defaultValue=QVariant().toString()) -> QString
Get password store directory path.
static auto getVersion(const QString &defaultValue=QVariant().toString()) -> QString
Get saved application version.
static void initExecutables()
Initialize executable paths by auto-detecting them.
static auto load() -> AppSettings
Load all flat settings into an AppSettings value object.
static auto isUseGrepSearch(const bool &defaultValue=false) -> bool
Check whether content search is enabled.
QtPassSettings()=delete
Private default constructor to enforce singleton usage and prevent direct instantiation.
static void setVersion(const QString &version)
Save application version.
static auto getProfiles() -> Profiles
Get all configured profiles.
static auto getRealPass() -> RealPass *
Get real pass backend instance.
static void setQrencodeExecutable(const QString &qrencodeExecutable)
Save qrencode executable path.
static auto getProfile(const QString &defaultValue=QVariant().toString()) -> QString
Get active profile name.
static auto isShowProcessOutput(const bool &defaultValue=false) -> bool
Get showProcessOutput setting.
static void setProfiles(const Profiles &profiles)
Save all configured profiles.
static void setUsePass(const bool &usePass)
Save use pass setting.
static void setSavestate(const QByteArray &saveState)
Save window state.
static auto isAlwaysOnTop(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether main window should stay always on top.
static void setDialogGeometry(const QString &key, const QByteArray &geometry)
Save dialog geometry.
static auto getPassExecutable(const QString &defaultValue=QVariant().toString()) -> QString
Get pass executable path.
static auto getDialogGeometry(const QString &key, const QByteArray &defaultValue=QVariant().toByteArray()) -> QByteArray
Get saved dialog geometry.
static auto getImitatePass() -> ImitatePass *
Get imitate pass backend instance.
static auto isHideOnClose(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether closing the window hides the application.
static void save(const AppSettings &settings)
Persist an AppSettings value object to the singleton store.
static QtPassSettings * m_instance
static auto getAutoclearSeconds(const int &defaultValue=QVariant().toInt()) -> int
Get autoclear delay in seconds.
static auto isAutoPush(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether automatic push is enabled.
static void setGeometry(const QByteArray &geometry)
Save window geometry.
static auto getGeometry(const QByteArray &defaultValue=QVariant().toByteArray()) -> QByteArray
Get saved window geometry.
static auto getSavestate(const QByteArray &defaultValue=QVariant().toByteArray()) -> QByteArray
Get saved window state.
static auto backendsIdle() -> bool
Whether no backend, the active one or one kept from before a switch, runs or waits for anything (Pass...
Implementation of Pass that wraps the 'pass' command-line tool.
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.
static auto mkpathForStore(const QString &path) -> bool
Create path and any missing parents as pass would.
static auto findBinaryInPath(const QString &binary) -> QString
Locate an executable by searching the process PATH and (on Windows) falling back to WSL.
Pass, the abstract password-store backend that RealPass and ImitatePass implement,...
PassBackendFactory, which constructs the two Pass backends on demand and hands out the one the settin...
QMap< QString, Profile > Profiles
All profiles by name. QMap so iteration order is the name order.
QtPassSettings, the QSettings singleton behind every saved setting, the profiles and the Pass backend...
SettingsSerializer: the flat AppSettings fields to and from their QSettings keys, without side effect...
Plain value-object holding all flat QtPass configuration.
QString gpgExecutable
Path to the gpg/gpg2 executable.
QString pwgenExecutable
Path to the pwgen executable.
QString passStore
Password-store root path.
QString gitExecutable
Path to the git executable.
QString passExecutable
Path to the pass executable.
Holds the password generator settings: which character set is selected, the alphabet of every set,...
One named password store: where it is, how its .gpg-id is signed and, optionally, its own Git switche...
std::optional< bool > autoPush
Push after commits; unset = global.
QString path
Password store directory.
std::optional< bool > autoPull
Pull on start; unset = global.
std::optional< bool > useGit
Git on/off; unset follows the global.
static auto flagToString(std::optional< bool > flag) -> QString
Format a flag the way it is stored.
static auto flagFromString(const QString &value) -> std::optional< bool >
Parse the on-disk tri-state.
QString signingKey
Key(s) that sign this store's .gpg-id.
Util: static helpers for the process environment, binary discovery, store paths, URL safety and the l...