aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-13 14:01:01 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-13 14:01:01 +0200
commit29ba3288d0d342e79d14676a02af555c6d43c3e6 (patch)
treeb4201b61782df21cf22fa8efad8619d1e9f2adb5 /src
parentUpdate readme (diff)
downloadsmolbote-29ba3288d0d342e79d14676a02af555c6d43c3e6.tar.xz
unstable: KWallet integration
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt10
-rw-r--r--src/mainwindow/mainwindow.cpp4
-rw-r--r--src/wallet/wallet.cpp44
-rw-r--r--src/wallet/wallet.h18
-rw-r--r--src/webengine/webview.cpp12
5 files changed, 82 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a44a44f..b772792 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -47,6 +47,10 @@ set(srclist
webengine/webview.cpp
webengine/webview.h
+ # wallet (form autofill)
+ wallet/wallet.cpp
+ wallet/wallet.h
+
# interfaces
${PROJECT_SOURCE_DIR}/include/plugininterface.h
${PROJECT_SOURCE_DIR}/include/profileinterface.h
@@ -92,10 +96,8 @@ if(Breakpad)
endif()
if(Plasma)
- target_link_libraries(${poi_exe} KF5::WindowSystem)
- target_compile_definitions(${poi_exe}
- PRIVATE PLASMA_BLUR # give the main window a translucent background and blur
- )
+ target_link_libraries(${poi_exe} KF5::Wallet KF5::WindowSystem)
+ target_compile_definitions(${poi_exe} PRIVATE PLASMA)
endif(Plasma)
target_compile_definitions(${poi_exe}
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 1f81b86..b0c5e5e 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -37,7 +37,7 @@
#include <configuration/configuration.h>
#include <web/profilemanager.h>
#include <web/webprofile.h>
-#ifdef PLASMA_BLUR
+#ifdef PLASMA
#include <KWindowEffects>
#endif
@@ -76,7 +76,7 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa
ui->setupUi(this);
-#ifdef PLASMA_BLUR
+#ifdef PLASMA
setAttribute(Qt::WA_TranslucentBackground, true);
KWindowEffects::enableBlurBehind(this->winId(), true);
#endif
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
new file mode 100644
index 0000000..c795cf2
--- /dev/null
+++ b/src/wallet/wallet.cpp
@@ -0,0 +1,44 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#include "wallet.h"
+#include <QWebEngineView>
+
+#ifdef PLASMA
+#include <kwallet.h>
+#endif
+
+void Wallet::autocompleteForm(QWebEngineView *view)
+{
+#ifdef PLASMA
+ const auto findFormFunction = QLatin1Literal("index = undefined; for(var i = 0; i < document.forms.length; ++i) { if(document.forms[i].autocomplete) { index = i } }; index");
+ view->page()->runJavaScript(findFormFunction, [view](const QVariant &v) {
+ if(!v.isNull()) {
+ auto autofillFunction = QString("inputs = document.forms[%1].getElementsByTagName('input');"
+ "for(var i = 0; i < inputs.length; ++i) {"
+ " if(inputs[i].type == 'email') { inputs[i].value='%2' }"
+ " if(inputs[i].type == 'password') { inputs[i].value='%3' }"
+ "}");
+
+ auto *wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), view->window()->winId());
+ if(wallet) {
+ wallet->setFolder("smolbote");
+ QMap<QString, QString> map;
+ wallet->readMap(view->url().host(), map);
+ qDebug() << map;
+
+ const auto username = map.firstKey();
+ QString password;
+ wallet->readPassword(map.value(username), password);
+ view->page()->runJavaScript(autofillFunction.arg(v.toString(), username, password));
+ }
+ delete wallet;
+ }
+ });
+#endif
+}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
new file mode 100644
index 0000000..d2fdb71
--- /dev/null
+++ b/src/wallet/wallet.h
@@ -0,0 +1,18 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_WALLET_H
+#define SMOLBOTE_WALLET_H
+
+class QWebEngineView;
+
+namespace Wallet {
+ void autocompleteForm(QWebEngineView *view);
+}
+
+#endif // SMOLBOTE_WALLET_H
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp
index f8be48e..59ad32a 100644
--- a/src/webengine/webview.cpp
+++ b/src/webengine/webview.cpp
@@ -23,6 +23,7 @@
#include <web/profilemanager.h>
#include <web/webprofile.h>
#include "browser.h"
+#include "wallet/wallet.h"
inline QAction *historyAction(QWebEngineView *view, const QWebEngineHistoryItem &item)
{
@@ -120,6 +121,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
QMenu *menu = new QMenu(this);
const auto ctxdata = page()->contextMenuData();
+ // back, forward, reload, mute buttons, added to all variants of the context menu
{
auto *navButtons = new QWidgetAction(this);
@@ -288,6 +290,16 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
menu->addAction(zoomWidgetAction);
}
+#ifdef QT_DEBUG
+ {
+ menu->addSeparator();
+ auto *autofillAction = menu->addAction(tr("Autofill form"));
+ connect(autofillAction, &QAction::triggered, this, [this]() {
+ Wallet::autocompleteForm(this);
+ });
+ };
+#endif
+
menu->setMinimumWidth(250);
menu->exec(event->globalPos());
}