diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-13 14:01:01 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-13 14:01:01 +0200 |
commit | 29ba3288d0d342e79d14676a02af555c6d43c3e6 (patch) | |
tree | b4201b61782df21cf22fa8efad8619d1e9f2adb5 /src/wallet | |
parent | Update readme (diff) | |
download | smolbote-29ba3288d0d342e79d14676a02af555c6d43c3e6.tar.xz |
unstable: KWallet integration
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet.cpp | 44 | ||||
-rw-r--r-- | src/wallet/wallet.h | 18 |
2 files changed, 62 insertions, 0 deletions
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 |