14#include <QApplication>
40 if (version.isEmpty()) {
41 qCDebug(lcQtPass) <<
"assuming fresh install";
103 if (error.isEmpty()) {
106 const QString colour =
107 exitCode == 0 ? QStringLiteral(
"darkgray") : QStringLiteral(
"red");
109 error, QStringLiteral(
"<span style=\"color: %1;\">").arg(colour),
110 QStringLiteral(
"</span><br />")));
121 if (!output.isEmpty()) {
140 const QString &errout) {
142 emit
statusMessage(tr(
"GPG key pair generated successfully"), 10000);
147 const QString &postfix,
bool links) -> QString {
152 output.replace(QStringLiteral(
"\r\n"), QStringLiteral(
"\n"));
159 output.replace(QStringLiteral(
"\n"),
"<br />");
163 return prefix + QStringLiteral(
"<span style=\"white-space: pre-wrap;\">") +
164 output + QStringLiteral(
"</span>") + postfix;
174 pass !=
nullptr && pass->autoPushHeld()) {
176 "re-encryption did not finish. Re-encrypt again, "
187 ? QStringLiteral(
"/usr/bin/qrencode")
191 qrencode.start(qrExe, QStringList() <<
"-o-"
195 if (!qrencode.waitForStarted()) {
196 emit
statusMessage(tr(
"Could not start qrencode: %1").arg(qrExe), 2000);
199 qrencode.write(text.toUtf8());
200 qrencode.closeWriteChannel();
202 if (!qrencode.waitForFinished()) {
204 emit
statusMessage(tr(
"qrencode did not finish in time"), 2000);
207 QByteArray output(qrencode.readAllStandardOutput());
209 const bool crashed = qrencode.exitStatus() != QProcess::NormalExit;
211 const bool failed = !crashed && qrencode.exitCode() != 0;
212 if (crashed || failed) {
213 QString error(qrencode.readAllStandardError());
214 if (error.trimmed().isEmpty()) {
216 ? tr(
"qrencode crashed")
217 : tr(
"qrencode exited with code %1").arg(qrencode.exitCode());
222 image.loadFromData(output,
"PNG");
235 auto *popup =
new QDialog(
nullptr, Qt::Popup | Qt::FramelessWindowHint);
236 popup->setAttribute(Qt::WA_DeleteOnClose);
237 auto *layout =
new QVBoxLayout;
238 auto *popupLabel =
new QLabel();
239 layout->addWidget(popupLabel);
240 popupLabel->setPixmap(image);
241 popupLabel->setScaledContents(
true);
243 popup->setLayout(layout);
244 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(), bool links=true) -> 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 closeQRCode()
Close the QR code popup showTextAsQRCode() has open, if any: the autoclear of the panel takes the cod...
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.
QPointer< QDialog > m_qrPopup
The QR code popup while showTextAsQRCode() has it open.
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 getPass() -> Pass *
Get currently active pass backend instance.
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 const QString firstRunPending
Set on a fresh install until QtPass is first set up: the first-run wizard finished,...
static const QString otpMigratedToNative
Marker that the one-time useOtp migration has run.
static auto withoutOtherBlockBreaks(QString text) -> QString
text with every block break other than a line feed (isOtherBlockBreak()) shown as a space,...
static auto findPasswordStore() -> QString
Locate the password store directory.
static auto boundSpaceRuns(const QString &text) -> QString
text with every run of white space other than tabs and line feeds cut to kMaxSpaceRun characters,...
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...
Names of the keys QtPass stores its settings under.
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).
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...