1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -49,7 +49,6 @@
#include "networkmanager.h" #include "networkmanager.h"
#include "datapaths.h" #include "datapaths.h"
#include "qztools.h" #include "qztools.h"
#include "followredirectreply.h"
#include <QFile> #include <QFile>
#include <QTimer> #include <QTimer>
@ -144,14 +143,13 @@ void AdBlockSubscription::updateSubscription()
return; return;
} }
m_reply = new FollowRedirectReply(m_url, mApp->networkManager()); m_reply = mApp->networkManager()->get(QNetworkRequest(m_url));
connect(m_reply, &QNetworkReply::finished, this, &AdBlockSubscription::subscriptionDownloaded);
connect(m_reply, SIGNAL(finished()), this, SLOT(subscriptionDownloaded()));
} }
void AdBlockSubscription::subscriptionDownloaded() void AdBlockSubscription::subscriptionDownloaded()
{ {
if (m_reply != qobject_cast<FollowRedirectReply*>(sender())) { if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
return; return;
} }

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -54,8 +54,7 @@
#include "adblocksearchtree.h" #include "adblocksearchtree.h"
class QUrl; class QUrl;
class QNetworkReply;
class FollowRedirectReply;
class QUPZILLA_EXPORT AdBlockSubscription : public QObject class QUPZILLA_EXPORT AdBlockSubscription : public QObject
{ {
@ -102,7 +101,7 @@ protected slots:
protected: protected:
virtual bool saveDownloadedData(const QByteArray &data); virtual bool saveDownloadedData(const QByteArray &data);
FollowRedirectReply* m_reply; QNetworkReply *m_reply;
QVector<AdBlockRule*> m_rules; QVector<AdBlockRule*> m_rules;
private: private:

View File

@ -189,7 +189,6 @@ SOURCES += \
tools/emptynetworkreply.cpp \ tools/emptynetworkreply.cpp \
tools/enhancedmenu.cpp \ tools/enhancedmenu.cpp \
tools/focusselectlineedit.cpp \ tools/focusselectlineedit.cpp \
tools/followredirectreply.cpp \
tools/frame.cpp \ tools/frame.cpp \
tools/headerview.cpp \ tools/headerview.cpp \
tools/horizontallistwidget.cpp \ tools/horizontallistwidget.cpp \
@ -373,7 +372,6 @@ HEADERS += \
tools/emptynetworkreply.h \ tools/emptynetworkreply.h \
tools/enhancedmenu.h \ tools/enhancedmenu.h \
tools/focusselectlineedit.h \ tools/focusselectlineedit.h \
tools/followredirectreply.h \
tools/frame.h \ tools/frame.h \
tools/headerview.h \ tools/headerview.h \
tools/horizontallistwidget.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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -18,17 +18,17 @@
#include "iconloader.h" #include "iconloader.h"
#include "mainapplication.h" #include "mainapplication.h"
#include "networkmanager.h" #include "networkmanager.h"
#include "followredirectreply.h"
#include "qztools.h" #include "qztools.h"
#include <QTimer> #include <QTimer>
#include <QNetworkReply>
IconLoader::IconLoader(const QUrl &url, QObject *parent) IconLoader::IconLoader(const QUrl &url, QObject *parent)
: QObject(parent) : QObject(parent)
, m_reply(Q_NULLPTR) , m_reply(Q_NULLPTR)
{ {
m_reply = new FollowRedirectReply(url, mApp->networkManager()); m_reply = mApp->networkManager()->get(QNetworkRequest(url));
connect(m_reply, &FollowRedirectReply::finished, this, &IconLoader::finished); connect(m_reply, &QNetworkReply::finished, this, &IconLoader::finished);
} }
void IconLoader::finished() void IconLoader::finished()
@ -37,6 +37,5 @@ void IconLoader::finished()
const QByteArray data = m_reply->readAll(); const QByteArray data = m_reply->readAll();
emit iconLoaded(QIcon(QPixmap::fromImage(QImage::fromData(data)))); emit iconLoaded(QIcon(QPixmap::fromImage(QImage::fromData(data))));
delete m_reply; m_reply->deleteLater();
m_reply = Q_NULLPTR;
} }

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - QtWebEngine based browser * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -23,6 +23,7 @@
#include "qzcommon.h" #include "qzcommon.h"
class QIcon; class QIcon;
class QNetworkReply;
class FollowRedirectReply; class FollowRedirectReply;
@ -40,7 +41,7 @@ private slots:
void finished(); void finished();
private: private:
FollowRedirectReply* m_reply; QNetworkReply* m_reply;
}; };
#endif // ICONLOADER_H #endif // ICONLOADER_H

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* GreaseMonkey plugin for QupZilla * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -20,21 +20,21 @@
#include "gm_script.h" #include "gm_script.h"
#include "webpage.h" #include "webpage.h"
#include "followredirectreply.h"
#include "mainapplication.h" #include "mainapplication.h"
#include "networkmanager.h" #include "networkmanager.h"
#include "qztools.h" #include "qztools.h"
#include "qzregexp.h"
#include <QFile> #include <QFile>
#include <QSettings> #include <QSettings>
#include "qzregexp.h" #include <QNetworkReply>
GM_Downloader::GM_Downloader(const QUrl &url, GM_Manager* manager) GM_Downloader::GM_Downloader(const QUrl &url, GM_Manager* manager)
: QObject() : QObject()
, m_manager(manager) , m_manager(manager)
{ {
m_reply = new FollowRedirectReply(url, mApp->networkManager()); m_reply = mApp->networkManager()->get(QNetworkRequest(url));
connect(m_reply, SIGNAL(finished()), this, SLOT(scriptDownloaded())); connect(m_reply, &QNetworkReply::finished, this, &GM_Downloader::scriptDownloaded);
} }
void GM_Downloader::updateScript(const QString &fileName) void GM_Downloader::updateScript(const QString &fileName)
@ -44,7 +44,7 @@ void GM_Downloader::updateScript(const QString &fileName)
void GM_Downloader::scriptDownloaded() void GM_Downloader::scriptDownloaded()
{ {
if (m_reply != qobject_cast<FollowRedirectReply*>(sender())) { if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
deleteLater(); deleteLater();
return; return;
} }
@ -96,7 +96,7 @@ void GM_Downloader::scriptDownloaded()
void GM_Downloader::requireDownloaded() void GM_Downloader::requireDownloaded()
{ {
if (m_reply != qobject_cast<FollowRedirectReply*>(sender())) { if (m_reply != qobject_cast<QNetworkReply*>(sender())) {
emit error(); emit error();
deleteLater(); deleteLater();
return; return;
@ -126,7 +126,7 @@ void GM_Downloader::requireDownloaded()
QSettings settings(m_manager->settinsPath() + QL1S("/greasemonkey/requires/requires.ini"), QSettings::IniFormat); QSettings settings(m_manager->settinsPath() + QL1S("/greasemonkey/requires/requires.ini"), QSettings::IniFormat);
settings.beginGroup("Files"); 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() void GM_Downloader::downloadRequires()
{ {
if (!m_requireUrls.isEmpty()) { if (!m_requireUrls.isEmpty()) {
m_reply = new FollowRedirectReply(m_requireUrls.takeFirst(), mApp->networkManager()); m_reply = mApp->networkManager()->get(QNetworkRequest(m_requireUrls.takeFirst()));
connect(m_reply, SIGNAL(finished()), this, SLOT(requireDownloaded())); connect(m_reply, &QNetworkReply::finished, this, &GM_Downloader::requireDownloaded);
} }
else { else {
emit finished(m_fileName); emit finished(m_fileName);

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* GreaseMonkey plugin for QupZilla * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -22,9 +22,9 @@
#include <QList> #include <QList>
#include <QUrl> #include <QUrl>
class GM_Manager; class QNetworkReply;
class FollowRedirectReply; class GM_Manager;
class GM_Downloader : public QObject class GM_Downloader : public QObject
{ {
@ -46,7 +46,7 @@ private:
void downloadRequires(); void downloadRequires();
GM_Manager* m_manager; GM_Manager* m_manager;
FollowRedirectReply* m_reply; QNetworkReply *m_reply;
QString m_fileName; QString m_fileName;
QList<QUrl> m_requireUrls; QList<QUrl> m_requireUrls;

View File

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