summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2015-04-18 13:28:40 +0200
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2015-04-18 13:35:24 +0200
commit9cf684177f400500f032f422130044382370c02e (patch)
treea3536f7e2768ee844962378a639973cbb8977267
parent180587a00de32253622e7977828a7a227126f186 (diff)
Add WebDAV support.
Not added to the config dialog yet. Note: The Debian version of fusedav will not work with several WebDAV implementations. All necessary patches are on the Debian bugtracker though (as upstream is dead and the "official" successor project on github doesn't seem to work at all with any WebDAV implementation I could try). Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
-rw-r--r--mainwindow.cpp80
-rw-r--r--mainwindow.h6
2 files changed, 85 insertions, 1 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp
index b7495b13..3074249b 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -7,6 +7,10 @@
#include <QInputDialog>
#include <QMessageBox>
#include <QTimer>
+#ifdef Q_OS_WIN
+#include <windows.h>
+#undef DELETE
+#endif
/**
* @brief MainWindow::MainWindow
@@ -15,7 +19,8 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
- process(new QProcess(this))
+ process(new QProcess(this)),
+ fusedav(this)
{
// connect(process.data(), SIGNAL(readyReadStandardOutput()), this, SLOT(readyRead()));
connect(process.data(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
@@ -29,6 +34,14 @@ MainWindow::MainWindow(QWidget *parent) :
*/
MainWindow::~MainWindow()
{
+#ifdef Q_OS_WIN
+ if (useWebDav) WNetCancelConnection2A(passStore.toUtf8().constData(), 0, 1);
+#else
+ if (fusedav.state() == QProcess::Running) {
+ fusedav.terminate();
+ fusedav.waitForFinished(2000);
+ }
+#endif
}
void MainWindow::normalizePassStore() {
@@ -49,6 +62,59 @@ QSettings &MainWindow::getSettings() {
return *settings;
}
+void MainWindow::mountWebDav() {
+#ifdef Q_OS_WIN
+ char dst[20] = {0};
+ NETRESOURCEA netres;
+ memset(&netres, 0, sizeof(netres));
+ netres.dwType = RESOURCETYPE_DISK;
+ netres.lpLocalName = 0;
+ netres.lpRemoteName = webDavUrl.toUtf8().data();
+ DWORD size = sizeof(dst);
+ DWORD r = WNetUseConnectionA(reinterpret_cast<HWND>(effectiveWinId()), &netres, webDavPassword.toUtf8().constData(),
+ webDavUser.toUtf8().constData(), CONNECT_TEMPORARY | CONNECT_INTERACTIVE | CONNECT_REDIRECT,
+ dst, &size, 0);
+ if (r == NO_ERROR) {
+ passStore = dst;
+ } else {
+ char message[256] = {0};
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, r, 0, message, sizeof(message), 0);
+ ui->textBrowser->setTextColor(Qt::red);
+ ui->textBrowser->setText(tr("Failed to connect WebDAV:\n") + message + " (0x" + QString::number(r, 16) + ")");
+ }
+#else
+ fusedav.start("fusedav -o nonempty -u \"" + webDavUser + "\" " + webDavUrl + " \"" + passStore + '"');
+ fusedav.waitForStarted();
+ if (fusedav.state() == QProcess::Running) {
+ QString pwd = webDavPassword;
+ bool ok = true;
+ if (pwd.isEmpty()) {
+ pwd = QInputDialog::getText(this, tr("QtPass WebDAV password"),
+ tr("Enter password to connect to WebDAV:"), QLineEdit::Password, "", &ok);
+ }
+ if (ok && !pwd.isEmpty()) {
+ fusedav.write(pwd.toUtf8() + '\n');
+ fusedav.closeWriteChannel();
+ fusedav.waitForFinished(2000);
+ } else {
+ fusedav.terminate();
+ }
+ }
+ QString error = fusedav.readAllStandardError();
+ int prompt = error.indexOf("Password:");
+ if (prompt >= 0) {
+ error.remove(0, prompt + 10);
+ }
+ if (fusedav.state() != QProcess::Running) {
+ error = tr("fusedav exited unexpectedly\n") + error;
+ }
+ if (error.size() > 0) {
+ ui->textBrowser->setTextColor(Qt::red);
+ ui->textBrowser->setText(tr("Failed to start fusedav to connect WebDAV:\n") + error);
+ }
+#endif
+}
+
/**
* @brief MainWindow::checkConfig
*/
@@ -87,10 +153,22 @@ void MainWindow::checkConfig() {
}
gpgHome = settings.value("gpgHome").toString();
+ useWebDav = (settings.value("useWebDav") == "true");
+ webDavUrl = settings.value("webDavUrl").toString();
+ webDavUser = settings.value("webDavUser").toString();
+ webDavPassword = settings.value("webDavPassword").toString();
+
if (passExecutable == "" && (gitExecutable == "" || gpgExecutable == "")) {
config();
}
+ // TODO: this needs to be before we try to access the store,
+ // but it would be better to do it after the Window is shown,
+ // as the long delay it can cause is irritating otherwise.
+ if (useWebDav) {
+ mountWebDav();
+ }
+
model.setNameFilters(QStringList() << "*.gpg");
model.setNameFilterDisables(false);
diff --git a/mainwindow.h b/mainwindow.h
index b7fa84b5..19243556 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -70,6 +70,11 @@ private:
QString gitExecutable;
QString gpgExecutable;
QString gpgHome;
+ bool useWebDav;
+ QString webDavUrl;
+ QString webDavUser;
+ QString webDavPassword;
+ QProcess fusedav;
QString clippedPass;
actionType currentAction;
QString lastDecrypt;
@@ -87,6 +92,7 @@ private:
QSettings &getSettings();
QList<UserInfo> listKeys(QString keystring = "");
QString getRecipientString(QString for_file, QString separator = " ");
+ void mountWebDav();
};
#endif // MAINWINDOW_H