12#include "settingsconstants.h"
14#include <QApplication>
40 if (version.isEmpty()) {
41 qCDebug(lcQtPass) <<
"assuming fresh install";
54 SettingsConstants::otpMigratedToNative,
true);
69 ->value(SettingsConstants::otpMigratedToNative,
false)
73 SettingsConstants::otpMigratedToNative,
true);
99 if (error.isEmpty()) {
102 const QString colour =
103 exitCode == 0 ? QStringLiteral(
"darkgray") : QStringLiteral(
"red");
105 error, QStringLiteral(
"<span style=\"color: %1;\">").arg(colour),
106 QStringLiteral(
"</span><br />")));
117 if (!output.isEmpty()) {
136 const QString &errout) {
138 emit
statusMessage(tr(
"GPG key pair generated successfully"), 10000);
143 const QString &postfix) -> QString {
147 output.replace(QStringLiteral(
"\n"),
"<br />");
148 return prefix + output + postfix;
160 ? QStringLiteral(
"/usr/bin/qrencode")
164 qrencode.start(qrExe, QStringList() <<
"-o-"
168 if (!qrencode.waitForStarted()) {
169 emit
statusMessage(tr(
"Could not start qrencode: %1").arg(qrExe), 2000);
172 qrencode.write(text.toUtf8());
173 qrencode.closeWriteChannel();
175 if (!qrencode.waitForFinished()) {
177 emit
statusMessage(tr(
"qrencode did not finish in time"), 2000);
180 QByteArray output(qrencode.readAllStandardOutput());
182 const bool crashed = qrencode.exitStatus() != QProcess::NormalExit;
184 const bool failed = !crashed && qrencode.exitCode() != 0;
185 if (crashed || failed) {
186 QString error(qrencode.readAllStandardError());
187 if (error.trimmed().isEmpty()) {
189 ? tr(
"qrencode crashed")
190 : tr(
"qrencode exited with code %1").arg(qrencode.exitCode());
195 image.loadFromData(output,
"PNG");
202 auto *popup =
new QDialog(
nullptr, Qt::Popup | Qt::FramelessWindowHint);
203 popup->setAttribute(Qt::WA_DeleteOnClose);
204 auto *layout =
new QVBoxLayout;
205 auto *popupLabel =
new QLabel();
206 layout->addWidget(popupLabel);
207 popupLabel->setPixmap(image);
208 popupLabel->setScaledContents(
true);
210 popup->setLayout(layout);
211 popup->move(QCursor::pos());
static void detachFromTerminal(QProcess &process)
Make process start its child without a controlling terminal.
Abstract base class for password store operations.
void finishedInsert(const QString &out, const QString &err)
An Insert() succeeded: the entry is in the store and, with Git in use, committed.
void finishedGenerateGPGKeys(const QString &out, const QString &err)
GenerateGPGKeys() succeeded; the new key pair is in the keyring.
void finishedCopy(const QString &out, const QString &err)
A Copy() succeeded; the copy exists beside the original.
void finishedMove(const QString &out, const QString &err)
A Move() succeeded; the entry or folder is under its new name.
void finishedGitPull(const QString &out, const QString &err)
git pull succeeded; entries may have changed on disk.
void finishedGitPush(const QString &out, const QString &err)
git push succeeded.
void processErrorExit(int exitCode, const QString &err)
An operation ended in failure: its process exited non-zero, could not be started or crashed,...
void finishedGitInit(const QString &out, const QString &err)
git init in the store succeeded; the store is a repository now and the tree is re-read.
void finishedInit(const QString &out, const QString &err)
An Init() succeeded: the folder's .gpg-id holds the new recipient list.
void finishedRemove(const QString &out, const QString &err)
A Remove() succeeded; the entry or folder is gone from the store.
void operationFinished()
A backend operation is over, successfully or not; the interface can be enabled again.
void statusMessage(const QString &message, int timeout)
A short message for the status bar.
ClipboardManager m_clipboard
The clipboard handling for this application instance, exposed through clipboard(); parented to this o...
static auto formatOutput(QString output, const QString &prefix=QString(), const QString &postfix=QString()) -> QString
Turn a process' plain-text output into the HTML the text browser shows: http(s) URLs become links,...
void entryInserted()
An entry was written; the view of the current entry is stale.
void processFinished(const QString &output, const QString &errout)
Slot for Pass::finishedGitPull / finishedGitPush and the common tail of the other slots: emit the std...
void pushRequested()
The store changed and the settings ask for an automatic push.
void connectPassSignalHandlers(Pass *pass)
Connect the completion signals of one backend to the slots that turn them into output,...
void outputReady(const QString &html)
Formatted output (see formatOutput()) or an error rendered in colour, ready for the text browser.
void finishedInsert(const QString &output, const QString &errout)
Slot for Pass::finishedInsert: like passStoreChanged(), then emit entryInserted() so the window refre...
void reportError(int exitCode, const QString &error)
Show a process' stderr in colour through outputReady(): red for a failure, dark grey for the chatter ...
void onKeyGenerationComplete(const QString &output, const QString &errout)
Slot for Pass::finishedGenerateGPGKeys: a status message followed by processFinished()....
void passStoreChanged(const QString &output, const QString &errout)
Slot for the backend signals that change the store on disk (git init, remove, init,...
void init()
Resolve the password store and the executables and migrate the settings of an older version (fresh-in...
QtPass(QObject *parent=nullptr)
Construct the glue and connect it to both pass backends.
void doGitPush()
Emit pushRequested() when the settings ask for automatic push.
static QDialog * createQRCodePopup(const QPixmap &image)
Create a frameless popup dialog, placed at the cursor, showing the given QR code. Split out of showTe...
~QtPass() override
Destroy the QtPass instance and clean up signal connections.
void processErrorExit(int exitCode, const QString &error)
Slot for Pass::processErrorExit: report the error in red and emit operationFinished().
void showTextAsQRCode(const QString &text)
Render text as a QR code with qrencode and show it in a popup at the cursor; failures are reported th...
static auto getInstance() -> QtPassSettings *
Get the singleton instance.
static void setPassStore(const QString &passStore)
Save password store path.
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 void setVersion(const QString &version)
Save application version.
static auto getRealPass() -> RealPass *
Get real pass backend instance.
static auto getImitatePass() -> ImitatePass *
Get imitate pass backend instance.
static void save(const AppSettings &settings)
Persist an AppSettings value object to the singleton store.
static auto isAutoPush(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether automatic push is enabled.
static auto findPasswordStore() -> QString
Locate the password store directory.
static auto linkifyUrls(const QString &text, bool *linked=nullptr) -> QString
Turn plain text into HTML with clickable links for safe web URLs.
Executor, the FIFO queue every gpg, git and pass child process of QtPass goes through,...
ImitatePass, the backend that does what pass does by running gpg and git itself.
QtPass: UI-neutral glue that turns backend completion signals into formatted output,...
The "qtpass" logging category.
QtPassSettings, the QSettings singleton behind every saved setting, the profiles and the Pass backend...
Plain value-object holding all flat QtPass configuration.
QString qrencodeExecutable
Path to the qrencode executable.
QString pwgenExecutable
Path to the pwgen executable.
bool useOtp
Enable native TOTP (OTP) support.
int autoclearPanelSeconds
Panel autoclear delay (seconds).
bool usePwgen
Use pwgen for password generation.
int autoclearSeconds
Clipboard autoclear delay (seconds).
QString passTemplate
Newline-separated template field names.
Util: static helpers for the process environment, binary discovery, store paths, URL safety and the l...