mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
KDESupport: Add basic support for KIO
BUG: 391924 FIXED-IN: 3.1.0
This commit is contained in:
parent
72b7bf65de
commit
933dadc6b2
@ -95,10 +95,12 @@ if (PKG_CONFIG_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Optional: KWallet
|
||||
# Optional: KWallet + KIO
|
||||
set(KF5_MIN_VERSION "5.27.0")
|
||||
find_package(KF5Wallet ${KF5_MIN_VERSION} CONFIG)
|
||||
set_package_properties(KF5Wallet PROPERTIES DESCRIPTION "KWallet password backend plugin" TYPE OPTIONAL)
|
||||
set_package_properties(KF5Wallet PROPERTIES DESCRIPTION "KDESupport plugin" TYPE OPTIONAL)
|
||||
find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG)
|
||||
set_package_properties(KF5KIO PROPERTIES DESCRIPTION "KDESupport plugin" TYPE OPTIONAL)
|
||||
|
||||
# Optional: PySide2
|
||||
find_package(PySide2 "2.0.0")
|
||||
|
@ -14,8 +14,8 @@ if (GNOME_KEYRING_FOUND)
|
||||
add_subdirectory(GnomeKeyringPasswords)
|
||||
endif()
|
||||
|
||||
if (KF5Wallet_FOUND)
|
||||
add_subdirectory(KWalletPasswords)
|
||||
if (KF5Wallet_FOUND AND KF5KIO_FOUND)
|
||||
add_subdirectory(KDESupport)
|
||||
endif()
|
||||
|
||||
if (ENABLE_PYTHON_PLUGINS)
|
||||
|
@ -1,6 +1,7 @@
|
||||
set(KDESupport_SRCS
|
||||
kdesupportplugin.cpp
|
||||
kwalletpasswordbackend.cpp
|
||||
kioschemehandler.cpp
|
||||
)
|
||||
|
||||
ecm_create_qm_loader(KDESupport_SRCS falkon_kdesupport_qt)
|
||||
@ -12,4 +13,4 @@ qt5_add_resources(RSCS ${KDESupport_RSCS})
|
||||
|
||||
add_library(KDESupport MODULE ${KDESupport_SRCS} ${RSCS})
|
||||
install(TARGETS KDESupport DESTINATION ${FALKON_INSTALL_PLUGINDIR})
|
||||
target_link_libraries(KDESupport FalkonPrivate KF5::Wallet)
|
||||
target_link_libraries(KDESupport FalkonPrivate KF5::Wallet KF5::KIOCore KF5::KIOWidgets)
|
||||
|
@ -24,6 +24,12 @@
|
||||
#include "autofill.h"
|
||||
#include "passwordmanager.h"
|
||||
#include "desktopfile.h"
|
||||
#include "kioschemehandler.h"
|
||||
#include "webpage.h"
|
||||
|
||||
#include <KProtocolInfo>
|
||||
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
KDESupportPlugin::KDESupportPlugin()
|
||||
: QObject()
|
||||
@ -43,12 +49,30 @@ void KDESupportPlugin::init(InitState state, const QString &settingsPath)
|
||||
|
||||
m_backend = new KWalletPasswordBackend;
|
||||
mApp->autoFill()->passwordManager()->registerBackend(QSL("KWallet"), m_backend);
|
||||
|
||||
const auto protocols = KProtocolInfo::protocols();
|
||||
for (const QString &protocol : protocols) {
|
||||
if (WebPage::internalSchemes().contains(protocol)) {
|
||||
continue;
|
||||
}
|
||||
KIOSchemeHandler *handler = new KIOSchemeHandler(protocol, this);
|
||||
m_kioSchemeHandlers.append(handler);
|
||||
mApp->webProfile()->installUrlSchemeHandler(protocol.toUtf8(), handler);
|
||||
WebPage::addSupportedScheme(protocol);
|
||||
}
|
||||
}
|
||||
|
||||
void KDESupportPlugin::unload()
|
||||
{
|
||||
mApp->autoFill()->passwordManager()->unregisterBackend(m_backend);
|
||||
delete m_backend;
|
||||
|
||||
for (KIOSchemeHandler *handler : qAsConst(m_kioSchemeHandlers)) {
|
||||
mApp->webProfile()->removeUrlSchemeHandler(handler);
|
||||
WebPage::removeSupportedScheme(handler->protocol());
|
||||
delete handler;
|
||||
}
|
||||
m_kioSchemeHandlers.clear();
|
||||
}
|
||||
|
||||
bool KDESupportPlugin::testPlugin()
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "plugininterface.h"
|
||||
|
||||
class KWalletPasswordBackend;
|
||||
class KIOSchemeHandler;
|
||||
|
||||
class KDESupportPlugin : public QObject, public PluginInterface
|
||||
{
|
||||
@ -38,7 +39,7 @@ public:
|
||||
|
||||
private:
|
||||
KWalletPasswordBackend* m_backend;
|
||||
|
||||
QVector<KIOSchemeHandler*> m_kioSchemeHandlers;
|
||||
};
|
||||
|
||||
#endif // KDESUPPORTPLUGIN_H
|
||||
|
63
src/plugins/KDESupport/kioschemehandler.cpp
Normal file
63
src/plugins/KDESupport/kioschemehandler.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* ============================================================
|
||||
* KDESupport - KDE support plugin for Falkon
|
||||
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "kioschemehandler.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QPointer>
|
||||
#include <QNetworkReply>
|
||||
#include <QWebEngineUrlRequestJob>
|
||||
|
||||
#include <KIO/AccessManager>
|
||||
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(KIO::Integration::AccessManager, s_knam, (nullptr))
|
||||
|
||||
KIOSchemeHandler::KIOSchemeHandler(const QString &protocol, QObject *parent)
|
||||
: QWebEngineUrlSchemeHandler(parent)
|
||||
, m_protocol(protocol)
|
||||
{
|
||||
}
|
||||
|
||||
QString KIOSchemeHandler::protocol() const
|
||||
{
|
||||
return m_protocol;
|
||||
}
|
||||
|
||||
void KIOSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
|
||||
{
|
||||
if (job->requestMethod() != QByteArray("GET")) {
|
||||
qWarning() << "Unsupported method" << job->requestMethod();
|
||||
job->fail(QWebEngineUrlRequestJob::RequestFailed);
|
||||
return;
|
||||
}
|
||||
|
||||
QPointer<QWebEngineUrlRequestJob> jobPtr = job;
|
||||
QNetworkReply *reply = s_knam()->get(QNetworkRequest(job->requestUrl()));
|
||||
connect(reply, &QNetworkReply::finished, this, [=]() {
|
||||
if (!jobPtr) {
|
||||
reply->deleteLater();
|
||||
return;
|
||||
}
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
reply->deleteLater();
|
||||
qWarning() << "Error:" << reply->errorString();
|
||||
job->fail(QWebEngineUrlRequestJob::RequestFailed);
|
||||
} else {
|
||||
job->reply(reply->header(QNetworkRequest::ContentTypeHeader).toByteArray(), reply);
|
||||
}
|
||||
});
|
||||
}
|
33
src/plugins/KDESupport/kioschemehandler.h
Normal file
33
src/plugins/KDESupport/kioschemehandler.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* ============================================================
|
||||
* KDESupport - KDE support plugin for Falkon
|
||||
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#pragma once
|
||||
|
||||
#include <QWebEngineUrlSchemeHandler>
|
||||
|
||||
class KIOSchemeHandler : public QWebEngineUrlSchemeHandler
|
||||
{
|
||||
public:
|
||||
explicit KIOSchemeHandler(const QString &protocol, QObject *parent = nullptr);
|
||||
|
||||
QString protocol() const;
|
||||
|
||||
void requestStarted(QWebEngineUrlRequestJob *job) override;
|
||||
|
||||
private:
|
||||
QString m_protocol;
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
[Desktop Entry]
|
||||
Name=KDE Support
|
||||
Comment=Provides support for storing passwords in KWallet
|
||||
Comment=Provides support for KIO and storing passwords in KWallet
|
||||
|
||||
Icon=:kdesupport/data/icon.svg
|
||||
Type=Service
|
||||
|
Loading…
Reference in New Issue
Block a user