1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Remove FollowRedirectReply

QNetworkAccessManager now supports redirects, so there is
no need for it anymore.
This commit is contained in:
David Rosca 2016-03-20 19:59:52 +01:00
parent 7b726970f3
commit 6eb0693e7d
10 changed files with 29 additions and 179 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2016 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
@ -49,7 +49,6 @@
#include "networkmanager.h"
#include "datapaths.h"
#include "qztools.h"
#include "followredirectreply.h"
#include <QFile>
#include <QTimer>
@ -144,14 +143,13 @@ void AdBlockSubscription::updateSubscription()
return;
}
m_reply = new FollowRedirectReply(m_url, mApp->networkManager());
connect(m_reply, SIGNAL(finished()), this, SLOT(subscriptionDownloaded()));
m_reply = mApp->networkManager()->get(QNetworkRequest(m_url));
connect(m_reply, &QNetworkReply::finished, this, &AdBlockSubscription::subscriptionDownloaded);
}
void AdBlockSubscription::subscriptionDownloaded()
{
if (m_reply != qobject_cast<FollowRedirectReply*>(sender())) {
if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
return;
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2016 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
@ -54,8 +54,7 @@
#include "adblocksearchtree.h"
class QUrl;
class FollowRedirectReply;
class QNetworkReply;
class QUPZILLA_EXPORT AdBlockSubscription : public QObject
{
@ -102,7 +101,7 @@ protected slots:
protected:
virtual bool saveDownloadedData(const QByteArray &data);
FollowRedirectReply* m_reply;
QNetworkReply *m_reply;
QVector<AdBlockRule*> m_rules;
private:

View File

@ -189,7 +189,6 @@ SOURCES += \
tools/emptynetworkreply.cpp \
tools/enhancedmenu.cpp \
tools/focusselectlineedit.cpp \
tools/followredirectreply.cpp \
tools/frame.cpp \
tools/headerview.cpp \
tools/horizontallistwidget.cpp \
@ -373,7 +372,6 @@ HEADERS += \
tools/emptynetworkreply.h \
tools/enhancedmenu.h \
tools/focusselectlineedit.h \
tools/followredirectreply.h \
tools/frame.h \
tools/headerview.h \
tools/horizontallistwidget.h \

View File

@ -1,84 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 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 "followredirectreply.h"
#include <QNetworkAccessManager>
FollowRedirectReply::FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager, QObject *parent)
: QObject(parent)
, m_manager(manager)
, m_redirectCount(0)
{
m_reply = m_manager->get(QNetworkRequest(url));
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
QNetworkReply* FollowRedirectReply::reply() const
{
return m_reply;
}
QUrl FollowRedirectReply::originalUrl() const
{
return m_reply->request().url();
}
QUrl FollowRedirectReply::url() const
{
return m_reply->url();
}
QNetworkReply::NetworkError FollowRedirectReply::error() const
{
return m_reply->error();
}
QString FollowRedirectReply::errorString() const
{
return m_reply->errorString();
}
QByteArray FollowRedirectReply::readAll()
{
return m_reply->readAll();
}
void FollowRedirectReply::replyFinished()
{
int replyStatus = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if ((replyStatus != 301 && replyStatus != 302) || m_redirectCount == 5) {
emit finished();
return;
}
m_redirectCount++;
QUrl redirectUrl = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
m_reply->close();
m_reply->deleteLater();
m_reply = m_manager->get(QNetworkRequest(redirectUrl));
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
FollowRedirectReply::~FollowRedirectReply()
{
m_reply->close();
m_reply->deleteLater();
}

View File

@ -1,60 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 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/>.
* ============================================================ */
#ifndef FOLLOWREDIRECTREPLY_H
#define FOLLOWREDIRECTREPLY_H
#include <QObject>
#include <QNetworkReply>
#include "qzcommon.h"
class QNetworkAccessManager;
class QNetworkReply;
class QUrl;
class QUPZILLA_EXPORT FollowRedirectReply : public QObject
{
Q_OBJECT
public:
explicit FollowRedirectReply(const QUrl &url, QNetworkAccessManager* manager, QObject *parent = Q_NULLPTR);
~FollowRedirectReply();
QNetworkReply* reply() const;
QUrl originalUrl() const;
QUrl url() const;
QNetworkReply::NetworkError error() const;
QString errorString() const;
QByteArray readAll();
signals:
void finished();
private slots:
void replyFinished();
private:
QNetworkAccessManager* m_manager;
QNetworkReply* m_reply;
int m_redirectCount;
};
#endif // FOLLOWREDIRECTREPLY_H

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - QtWebEngine based browser
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
* Copyright (C) 2015-2016 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
@ -18,17 +18,17 @@
#include "iconloader.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "followredirectreply.h"
#include "qztools.h"
#include <QTimer>
#include <QNetworkReply>
IconLoader::IconLoader(const QUrl &url, QObject *parent)
: QObject(parent)
, m_reply(Q_NULLPTR)
{
m_reply = new FollowRedirectReply(url, mApp->networkManager());
connect(m_reply, &FollowRedirectReply::finished, this, &IconLoader::finished);
m_reply = mApp->networkManager()->get(QNetworkRequest(url));
connect(m_reply, &QNetworkReply::finished, this, &IconLoader::finished);
}
void IconLoader::finished()
@ -37,6 +37,5 @@ void IconLoader::finished()
const QByteArray data = m_reply->readAll();
emit iconLoaded(QIcon(QPixmap::fromImage(QImage::fromData(data))));
delete m_reply;
m_reply = Q_NULLPTR;
m_reply->deleteLater();
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - QtWebEngine based browser
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
* Copyright (C) 2015-2016 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
@ -23,6 +23,7 @@
#include "qzcommon.h"
class QIcon;
class QNetworkReply;
class FollowRedirectReply;
@ -40,7 +41,7 @@ private slots:
void finished();
private:
FollowRedirectReply* m_reply;
QNetworkReply* m_reply;
};
#endif // ICONLOADER_H

View File

@ -1,6 +1,6 @@
/* ============================================================
* GreaseMonkey plugin for QupZilla
* Copyright (C) 2012-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2012-2016 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
@ -20,21 +20,21 @@
#include "gm_script.h"
#include "webpage.h"
#include "followredirectreply.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "qztools.h"
#include "qzregexp.h"
#include <QFile>
#include <QSettings>
#include "qzregexp.h"
#include <QNetworkReply>
GM_Downloader::GM_Downloader(const QUrl &url, GM_Manager* manager)
: QObject()
, m_manager(manager)
{
m_reply = new FollowRedirectReply(url, mApp->networkManager());
connect(m_reply, SIGNAL(finished()), this, SLOT(scriptDownloaded()));
m_reply = mApp->networkManager()->get(QNetworkRequest(url));
connect(m_reply, &QNetworkReply::finished, this, &GM_Downloader::scriptDownloaded);
}
void GM_Downloader::updateScript(const QString &fileName)
@ -44,7 +44,7 @@ void GM_Downloader::updateScript(const QString &fileName)
void GM_Downloader::scriptDownloaded()
{
if (m_reply != qobject_cast<FollowRedirectReply*>(sender())) {
if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
deleteLater();
return;
}
@ -96,7 +96,7 @@ void GM_Downloader::scriptDownloaded()
void GM_Downloader::requireDownloaded()
{
if (m_reply != qobject_cast<FollowRedirectReply*>(sender())) {
if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
emit error();
deleteLater();
return;
@ -126,7 +126,7 @@ void GM_Downloader::requireDownloaded()
QSettings settings(m_manager->settinsPath() + QL1S("/greasemonkey/requires/requires.ini"), QSettings::IniFormat);
settings.beginGroup("Files");
settings.setValue(m_reply->originalUrl().toString(), fileName);
settings.setValue(m_reply->request().url().toString(), fileName);
}
}
@ -139,8 +139,8 @@ void GM_Downloader::requireDownloaded()
void GM_Downloader::downloadRequires()
{
if (!m_requireUrls.isEmpty()) {
m_reply = new FollowRedirectReply(m_requireUrls.takeFirst(), mApp->networkManager());
connect(m_reply, SIGNAL(finished()), this, SLOT(requireDownloaded()));
m_reply = mApp->networkManager()->get(QNetworkRequest(m_requireUrls.takeFirst()));
connect(m_reply, &QNetworkReply::finished, this, &GM_Downloader::requireDownloaded);
}
else {
emit finished(m_fileName);

View File

@ -1,6 +1,6 @@
/* ============================================================
* GreaseMonkey plugin for QupZilla
* Copyright (C) 2012-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2012-2016 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
@ -22,9 +22,9 @@
#include <QList>
#include <QUrl>
class GM_Manager;
class QNetworkReply;
class FollowRedirectReply;
class GM_Manager;
class GM_Downloader : public QObject
{
@ -46,7 +46,7 @@ private:
void downloadRequires();
GM_Manager* m_manager;
FollowRedirectReply* m_reply;
QNetworkReply *m_reply;
QString m_fileName;
QList<QUrl> m_requireUrls;

View File

@ -21,7 +21,6 @@
#include "qzregexp.h"
#include "delayedfilewatcher.h"
#include "followredirectreply.h"
#include "mainapplication.h"
#include <QFile>