16#include <QCoreApplication>
22#include <QGuiApplication>
33 QString portable_ini = QCoreApplication::applicationDirPath() +
34 QDir::separator() +
"qtpass.ini";
35 if (QFile(portable_ini).exists()) {
58 -> std::optional<bool> {
64 const auto active = profiles.constFind(name);
65 return active == profiles.constEnd() ? std::nullopt : (*active).*flag;
77#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
78constexpr auto kStoreCase = Qt::CaseInsensitive;
80constexpr auto kStoreCase = Qt::CaseSensitive;
89auto comparableFolder(
const QString &path) -> QString {
90 const QString real = QFileInfo(path).canonicalFilePath();
91 return real.isEmpty() ? QDir::cleanPath(QDir(path).absolutePath()) : real;
102auto sameFolder(
const QString &a,
const QString &b) ->
bool {
105 struct stat second{};
106 if (::stat(QFile::encodeName(a).constData(), &first) == 0 &&
107 ::stat(QFile::encodeName(b).constData(), &second) == 0) {
108 return first.st_dev == second.st_dev && first.st_ino == second.st_ino;
111 return comparableFolder(a).compare(comparableFolder(b), kStoreCase) == 0;
126 for (
auto i = profiles.cbegin(); i != profiles.cend(); ++i) {
127 if (i.key().isEmpty() || i.value().path.isEmpty()) {
130 if (sameFolder(settings.
passStore, i.value().path)) {
135 if (exact.isEmpty() || (profiles.value(exact).signingKey.isEmpty() &&
136 !i.value().signingKey.isEmpty())) {
141 if (!exact.isEmpty()) {
151 if (!s.
activeProfile.isEmpty() && active != profiles.constEnd()) {
174 QStringList childKeys =
getInstance()->childKeys();
175 for (
const auto &key : std::as_const(childKeys)) {
178 profiles.insert(key, profile);
182 QStringList childGroups =
getInstance()->childGroups();
183 for (
const auto &group : std::as_const(childGroups)) {
188 getInstance()->value(group +
"/useGit").toString());
190 getInstance()->value(group +
"/autoPush").toString());
192 getInstance()->value(group +
"/autoPull").toString());
193 profiles.insert(group, profile);
205 const QString activeProfile =
208 if (!activeProfile.isEmpty()) {
213 for (
auto i = profiles.cbegin(); i != profiles.cend(); ++i) {
214 getInstance()->setValue(i.key() +
"/path", i.value().path);
215 getInstance()->setValue(i.key() +
"/signingKey", i.value().signingKey);
260 const QByteArray &defaultValue)
267 const QByteArray &geometry) {
289 returnValue = QDir(returnValue).absolutePath();
293 if (!QDir(returnValue).exists()) {
295 qWarning() <<
"Failed to create password store directory:" << returnValue;
299 if (!returnValue.endsWith(
"/") && !returnValue.endsWith(QDir::separator())) {
300 returnValue += QDir::separator();
342 if (storedValue == defaultValue && defaultValue) {
344 if (QFileInfo(passStore).isDir() &&
345 QFileInfo(passStore + QDir::separator() +
".git").isDir()) {
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
Deleted: QtPassSettings is used through its static functions and never instantiated....
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 auto activeProfileFlag(std::optional< bool > Profile::*flag) -> std::optional< bool >
The active profile's own value of a Git flag.
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 void takeProfileOfStore(AppSettings &settings, const Profiles &profiles)
Make settings use the profile whose store it opens.
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 loadEffective() -> AppSettings
load() with the active profile's own Git flags applied: what the backends and the Git actions run wit...
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 const QString savestate
Saved dock and toolbar state of the main window (mainwindow/savestate). Bytes from QMainWindow::saveS...
static const QString passExecutable
Path of the pass program. Text.
static const QString useGrepSearch
Offer the search in the content of entries. Boolean, default false.
static const QString dialogGeometry
Prefix of the saved geometry of each dialog: the key is dialog/geometry/<dialog name>....
static const QString geometry
Saved geometry of the main window (mainwindow/geometry). Bytes from QWidget::saveGeometry().
static const QString version
Version of QtPass that last wrote the settings. Text.
static const QString showProcessOutput
Show the Process Output panel. Boolean, default false.
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 profile
Name of the active profile, and also the group profile/<name>/ that holds each profile (path,...
static const QString useOtp
Show one-time codes for entries that hold an otpauth:// line. Boolean, default true.
static const QString autoclearSeconds
Seconds until the clipboard is cleared. Integer, default 0.
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 autoPush
Run git push after each change. Boolean, default false; a profile can set its own value.
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 passSigningKey
GPG key used to sign .gpg-id files.
QString pwgenExecutable
Path to the pwgen executable.
QString passStore
Password-store root path.
QString gitExecutable
Path to the git executable.
bool autoPull
git pull before an entry is edited and before a re-encryption.
QString passExecutable
Path to the pass executable.
bool useGit
Enable git integration.
QString activeProfile
Name of the active profile.
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...