QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
passbackendfactory.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
9
10#include "passbackendfactory.h"
11#include "appsettings.h"
12#include "pass.h"
13#include "qtpasssettings.h"
14#include "util.h"
15
16#include <QDebug>
17#include <QDir>
18
20QScopedPointer<RealPass> PassBackendFactory::realPass;
21QScopedPointer<ImitatePass> PassBackendFactory::imitatePass;
22
24 if (!pass) {
25 // With the active profile's Git flags: what the backend runs with.
27 // Ensure store directory exists (first-run side effect — load() normalises
28 // the path but does not create the directory).
29 if (!QDir(s.passStore).exists() && !Util::mkpathForStore(s.passStore)) {
30 qWarning() << "Failed to create password store directory:" << s.passStore;
31 }
32 if (s.usePass) {
33 pass = getRealPass();
34 } else {
36 }
37 if (pass) {
38 pass->init(s);
39 }
40 }
41 return pass;
42}
43
45 if (realPass.isNull()) {
46 realPass.reset(new RealPass());
47 }
48 return realPass.data();
49}
50
52 if (imitatePass.isNull()) {
53 imitatePass.reset(new ImitatePass());
55 imitatePass->init(s);
56 }
57 return imitatePass.data();
58}
59
61 return (realPass.isNull() || realPass->isIdle()) &&
62 (imitatePass.isNull() || imitatePass->isIdle());
63}
64
AppSettings, the value object holding every flat QtPass setting.
Implementation that imitates 'pass' when the real tool is unavailable.
Definition imitatepass.h:41
ImitatePass()
Construct the backend and connect its content search.
static auto getPass() -> Pass *
Get the active backend, constructing and initialising it on first use after construction or invalidat...
static QScopedPointer< ImitatePass > imitatePass
The gpg and git backend, constructed on first use.
static Pass * pass
The backend getPass() last selected; null until the first call and again after invalidate()....
static auto getRealPass() -> RealPass *
Get the lazily-constructed RealPass backend.
static QScopedPointer< RealPass > realPass
The pass backend, constructed on first use.
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.
Definition pass.h:77
static auto loadEffective() -> AppSettings
load() with the active profile's own Git flags applied: what the backends and the Git actions run wit...
Implementation of Pass that wraps the 'pass' command-line tool.
Definition realpass.h:35
RealPass()
Construct a RealPass instance.
Definition realpass.cpp:46
static auto mkpathForStore(const QString &path) -> bool
Create path and any missing parents as pass would.
Definition util.cpp:615
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...
QtPassSettings, the QSettings singleton behind every saved setting, the profiles and the Pass backend...
Plain value-object holding all flat QtPass configuration.
Definition appsettings.h:36
bool usePass
Use the pass CLI (true) or native git/gpg.
Definition appsettings.h:59
QString passStore
Password-store root path.
Definition appsettings.h:60
Util: static helpers for the process environment, binary discovery, store paths, URL safety and the l...