Verified Commit cee71e38 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Replace KIO::AccessManager with regular QNetworkAccessManager

KIO::AM provides integration with KDE-wide cookiejar, which is useless for us
as we do not use cookies while talking to Google. Using QNAM gives us exactly
the same features we need minus dependency on KIOWidgets framework.
parent 677a7ed2
Pipeline #36366 passed with stage
in 19 minutes and 16 seconds
......@@ -45,7 +45,6 @@ find_package(Qt5 ${QT_REQUIRED_VERSION} REQUIRED COMPONENTS
)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
KIO
Wallet
)
......
......@@ -15,6 +15,7 @@
class FakeNetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT
public:
class Scenario
{
......
......@@ -6,10 +6,6 @@
#include "fakenetworkaccessmanagerfactory.h"
FakeNetworkAccessManagerFactory::FakeNetworkAccessManagerFactory()
{
}
void FakeNetworkAccessManagerFactory::setScenarios(const QList<FakeNetworkAccessManager::Scenario> &scenarios)
{
mScenarios = scenarios;
......
......@@ -15,7 +15,7 @@
class FakeNetworkAccessManagerFactory : public KGAPI2::NetworkAccessManagerFactory
{
public:
explicit FakeNetworkAccessManagerFactory();
explicit FakeNetworkAccessManagerFactory() = default;
static FakeNetworkAccessManagerFactory *get(); // instance+dynamic_cast
......
......@@ -65,7 +65,6 @@ PUBLIC
Qt5::Core
PRIVATE
Qt5::Network
KF5::KIOWidgets
KF5::Wallet
)
......
......@@ -57,7 +57,7 @@ void ModifyJob::dispatchRequest(QNetworkAccessManager* accessManager, const QNet
r.setRawHeader("If-Match", "*");
}
// Note: there is a problem with PUT when using KIO::AccessManager - it
// Note: there is a problem with PUT when using QNAM - it
// doesn't transfer the body correctly.
// Using sendCustomRequest() works just fine.
//accessManager->put(r, data);
......
/*
* This file is part of LibKGAPI library
*
* SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org>
* SPDX-FileCopyrightText: 2018 - 2020 Daniel Vrátil <dvratil@kde.org>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
......@@ -9,40 +9,33 @@
#include "networkaccessmanagerfactory_p.h"
#include "../debug.h"
#include <KIO/AccessManager>
#include <QNetworkAccessManager>
using namespace KGAPI2;
NetworkAccessManagerFactory *NetworkAccessManagerFactory::sInstance = nullptr;
std::unique_ptr<NetworkAccessManagerFactory> NetworkAccessManagerFactory::sInstance;
class KIONetworkAccessManagerFactory : public NetworkAccessManagerFactory
class QtNetworkAccessManagerFactory : public NetworkAccessManagerFactory
{
public:
QNetworkAccessManager *networkAccessManager(QObject *parent) const override
{
return new KIO::Integration::AccessManager(parent);
auto *nam = new QNetworkAccessManager(parent);
nam->setStrictTransportSecurityEnabled(true);
nam->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
return nam;
}
};
NetworkAccessManagerFactory::NetworkAccessManagerFactory()
{
}
NetworkAccessManagerFactory::~NetworkAccessManagerFactory()
{
}
void NetworkAccessManagerFactory::setFactory(NetworkAccessManagerFactory *factory)
{
delete sInstance;
sInstance = factory;
sInstance.reset(factory);
}
NetworkAccessManagerFactory *NetworkAccessManagerFactory::instance()
{
if (!sInstance) {
sInstance = new KIONetworkAccessManagerFactory();
setFactory(new QtNetworkAccessManagerFactory);
}
return sInstance;
return sInstance.get();
}
......@@ -14,22 +14,25 @@ class QObject;
#include "kgapicore_export.h"
#include <memory>
namespace KGAPI2 {
// Export for use in unit-tests, header not installed though
class KGAPICORE_EXPORT NetworkAccessManagerFactory
{
public:
virtual ~NetworkAccessManagerFactory() = default;
static NetworkAccessManagerFactory *instance();
static void setFactory(NetworkAccessManagerFactory *factory);
virtual QNetworkAccessManager *networkAccessManager(QObject *parent = nullptr) const = 0;
protected:
static NetworkAccessManagerFactory *sInstance;
static std::unique_ptr<NetworkAccessManagerFactory> sInstance;
explicit NetworkAccessManagerFactory();
virtual ~NetworkAccessManagerFactory();
explicit NetworkAccessManagerFactory() = default;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment