13#include <QInputDialog>
17#define WIN32_LEAN_AND_MEAN
18#define WIN32_EXTRA_LEAN
29 : m_mainWindow(mainWindow), clippedText(QString()), freshStart(true) {
31 clearClipboardTimer.setSingleShot(
true);
32 connect(&clearClipboardTimer, SIGNAL(timeout()),
this,
35 QObject::connect(qApp, &QApplication::aboutToQuit,
this,
50 if (fusedav.state() == QProcess::Running) {
52 fusedav.waitForFinished(2000);
71 if (version.isEmpty()) {
73 dbg() <<
"assuming fresh install";
114void QtPass::setMainWindow(
void) {
117 fusedav.setParent(m_mainWindow);
124 &QtPass::passShowHandlerFinished);
134 dbg() <<
"Pass git init called";
140 [=](
const QString &batch) {
147void QtPass::connectPassSignalHandlers(
Pass *pass) {
148 connect(pass, &
Pass::error,
this, &QtPass::processError);
168 &QtPass::onKeyGenerationComplete);
174void QtPass::mountWebDav() {
178 memset(&netres, 0,
sizeof(netres));
179 netres.dwType = RESOURCETYPE_DISK;
180 netres.lpLocalName = 0;
182 DWORD size =
sizeof(dst);
183 DWORD r = WNetUseConnectionA(
184 reinterpret_cast<HWND
>(m_mainWindow->effectiveWinId()), &netres,
187 CONNECT_TEMPORARY | CONNECT_INTERACTIVE | CONNECT_REDIRECT, dst, &size,
192 char message[256] = {0};
193 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, r, 0, message,
195 m_mainWindow->
flashText(tr(
"Failed to connect WebDAV:\n") + message +
196 " (0x" + QString::number(r, 16) +
")",
200 fusedav.start(
"fusedav", QStringList()
207 fusedav.waitForStarted();
208 if (fusedav.state() == QProcess::Running) {
212 pwd = QInputDialog::getText(m_mainWindow, tr(
"QtPass WebDAV password"),
213 tr(
"Enter password to connect to WebDAV:"),
214 QLineEdit::Password,
"", &ok);
216 if (ok && !pwd.isEmpty()) {
217 fusedav.write(pwd.toUtf8() +
'\n');
218 fusedav.closeWriteChannel();
219 fusedav.waitForFinished(2000);
224 QString error = fusedav.readAllStandardError();
225 int prompt = error.indexOf(
"Password:");
227 error.remove(0, prompt + 10);
228 if (fusedav.state() != QProcess::Running)
229 error = tr(
"fusedav exited unexpectedly\n") + error;
230 if (error.size() > 0) {
232 tr(
"Failed to start fusedav to connect WebDAV:\n") + error,
true);
241void QtPass::processError(QProcess::ProcessError error) {
244 case QProcess::FailedToStart:
245 errorString = tr(
"QProcess::FailedToStart");
247 case QProcess::Crashed:
248 errorString = tr(
"QProcess::Crashed");
250 case QProcess::Timedout:
251 errorString = tr(
"QProcess::Timedout");
253 case QProcess::ReadError:
254 errorString = tr(
"QProcess::ReadError");
256 case QProcess::WriteError:
257 errorString = tr(
"QProcess::WriteError");
259 case QProcess::UnknownError:
260 errorString = tr(
"QProcess::UnknownError");
264 m_mainWindow->
flashText(errorString,
true);
268void QtPass::processErrorExit(
int exitCode,
const QString &p_error) {
269 if (!p_error.isEmpty()) {
271 QString error = p_error.toHtmlEscaped();
274 output =
"<span style=\"color: darkgray;\">" + error +
"</span><br />";
276 output =
"<span style=\"color: red;\">" + error +
"</span><br />";
280 output.replace(QStringLiteral("\n"),
"<br />");
282 m_mainWindow->
flashText(output,
false,
true);
295void QtPass::processFinished(
const QString &p_output,
const QString &p_errout) {
296 showInTextBrowser(p_output);
299 processErrorExit(0, p_errout);
304void QtPass::passStoreChanged(
const QString &p_out,
const QString &p_err) {
305 processFinished(p_out, p_err);
309void QtPass::finishedInsert(
const QString &p_output,
const QString &p_errout) {
310 processFinished(p_output, p_errout);
315void QtPass::onKeyGenerationComplete(
const QString &p_output,
316 const QString &p_errout) {
319 qDebug() <<
"Keygen Done";
326 processFinished(p_output, p_errout);
329void QtPass::passShowHandlerFinished(QString output) {
330 showInTextBrowser(std::move(output));
333void QtPass::showInTextBrowser(QString output, QString prefix,
335 output = output.toHtmlEscaped();
338 output.replace(QStringLiteral("\n"),
"<br />");
339 output = prefix + output + postfix;
341 m_mainWindow->
flashText(output,
false,
true);
344void QtPass::doGitPush() {
351 !p_output.isEmpty()) {
352 clippedText = password;
367 QClipboard *clipboard = QApplication::clipboard();
368 bool cleared =
false;
369 if (this->clippedText == clipboard->text(QClipboard::Selection)) {
370 clipboard->clear(QClipboard::Selection);
371 clipboard->setText(QString(
""), QClipboard::Selection);
374 if (this->clippedText == clipboard->text(QClipboard::Clipboard)) {
375 clipboard->clear(QClipboard::Clipboard);
392 QClipboard *clip = QApplication::clipboard();
394 clip->setText(text, QClipboard::Clipboard);
396 clip->setText(text, QClipboard::Selection);
402 clearClipboardTimer.start();
413 QStringList() <<
"-o-"
415 qrencode.write(text.toUtf8());
416 qrencode.closeWriteChannel();
417 qrencode.waitForFinished();
418 QByteArray output(qrencode.readAllStandardOutput());
420 if (qrencode.exitStatus() || qrencode.exitCode()) {
421 QString error(qrencode.readAllStandardError());
425 image.loadFromData(output,
"PNG");
427 QDialog *popup =
new QDialog(0, Qt::Popup | Qt::FramelessWindowHint);
428 QVBoxLayout *layout =
new QVBoxLayout;
429 QLabel *popupLabel =
new QLabel();
430 layout->addWidget(popupLabel);
431 popupLabel->setPixmap(image);
432 popupLabel->setScaledContents(
true);
434 popup->setLayout(layout);
435 popup->move(QCursor::pos());
void startReencryptPath()
The MainWindow class does way too much, not only is it a switchboard, configuration handler and more,...
void startReencryptPath()
MainWindow::startReencryptPath disable ui elements and treeview.
void passShowHandler(const QString &)
void endReencryptPath()
MainWindow::endReencryptPath re-enable ui elements.
void executeWrapperStarted()
void showStatusMessage(QString msg, int timeout=2000)
Displays message in status bar.
void onPush()
MainWindow::onPush do a git push.
void critical(QString, QString)
MainWindow::critical critical message popup wrapper.
void generateGPGKeyPair(QString batch)
void passOtpHandler(const QString &)
QDialog * getKeygenDialog()
const QModelIndex getCurrentTreeViewIndex()
void flashText(const QString &text, const bool isError, const bool isHtml=false)
void setUiElementsEnabled(bool state)
MainWindow::setUiElementsEnabled enable or disable the relevant UI elements.
void on_treeView_clicked(const QModelIndex &index)
MainWindow::on_treeView_clicked read the selected password file.
void config()
MainWindow::config pops up the configuration screen and handles all inter-window communication.
void passShowHandlerFinished(QString output)
Acts as an abstraction for pass or pass imitation.
void startingExecuteWrapper()
void GenerateGPGKeys(QString batch)
Pass::GenerateGPGKeys internal gpg keypair generator . .
void finishedCopy(const QString &, const QString &)
void finishedShow(const QString &)
void finishedRemove(const QString &, const QString &)
void finishedMove(const QString &, const QString &)
void statusMsg(QString, int)
void critical(QString, QString)
void finishedGitInit(const QString &, const QString &)
void finishedInsert(const QString &, const QString &)
void finishedInit(const QString &, const QString &)
void finishedOtpGenerate(const QString &)
void processErrorExit(int exitCode, const QString &err)
void finishedGitPull(const QString &, const QString &)
void finishedGitPush(const QString &, const QString &)
void error(QProcess::ProcessError)
void finishedGenerateGPGKeys(const QString &, const QString &)
void clearClipboard()
MainWindow::clearClipboard remove clipboard contents.
bool init()
QtPass::init make sure we are ready to go as soon as possible.
~QtPass()
QtPass::~QtPass destroy!
void setClippedText(const QString &, const QString &p_output=QString())
QtPass(MainWindow *mainWindow)
void copyTextToClipboard(const QString &text)
MainWindow::copyTextToClipboard copies text to your clipboard.
void showTextAsQRCode(const QString &text)
displays the text as qrcode
static QString getVersion(const QString &defaultValue=QVariant().toString())
static void setAutoclearPanelSeconds(const int &autoClearPanelSeconds)
static QString getWebDavUrl(const QString &defaultValue=QVariant().toString())
static int getAutoclearPanelSeconds(const int &defaultValue=QVariant().toInt())
static void setPassStore(const QString &passStore)
static ImitatePass * getImitatePass()
static QString getPassTemplate(const QString &defaultValue=QVariant().toString())
static int getAutoclearSeconds(const int &defaultValue=QVariant().toInt())
static void setUsePwgen(const bool &usePwgen)
static QString getPwgenExecutable(const QString &defaultValue=QVariant().toString())
static QString getWebDavUser(const QString &defaultValue=QVariant().toString())
static void initExecutables()
static bool isUseWebDav(const bool &defaultValue=QVariant().toBool())
static void setPassTemplate(const QString &passTemplate)
static void setVersion(const QString &version)
static Enums::clipBoardType getClipBoardType(const Enums::clipBoardType &defaultvalue=Enums::CLIPBOARD_NEVER)
static RealPass * getRealPass()
static bool isAutoPush(const bool &defaultValue=QVariant().toBool())
static QString getPassStore(const QString &defaultValue=QVariant().toString())
static void setAutoclearSeconds(const int &autoClearSeconds)
static QString getQrencodeExecutable(const QString &defaultValue=QVariant().toString())
static bool isUseAutoclear(const bool &defaultValue=QVariant().toBool())
static QString getWebDavPassword(const QString &defaultValue=QVariant().toString())
static bool isUseSelection(const bool &defaultValue=QVariant().toBool())
static bool checkConfig()
Util::checkConfig do we have prequisite settings?
static QString findPasswordStore()
Util::findPasswordStore look for common .password-store folder location.
static const QRegularExpression & protocolRegex()