summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/webview.cpp26
-rw-r--r--src/webview.h3
2 files changed, 26 insertions, 3 deletions
diff --git a/src/webview.cpp b/src/webview.cpp
index 73d2b25..09bf427 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -11,6 +11,7 @@
#include <QWebElement>
#include <QRegularExpression>
#include <QWebPage>
+#include <QNetworkAccessManager>
// Override user-agent to make it appear mobile
class UaWebPage : public QWebPage
@@ -23,6 +24,19 @@ public:
}
};
+class Nam : public QNetworkAccessManager
+{
+public:
+ explicit Nam(QObject *parent = nullptr) : QNetworkAccessManager(parent) {}
+protected:
+ virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
+ QIODevice *outgoingData = nullptr) override {
+ auto cp(request);
+ cp.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, QVariant(false));
+ return QNetworkAccessManager::createRequest(op, cp, outgoingData);
+ }
+};
+
QRegularExpression UaWebPage::re("(\\S+)$");
WebView::WebView(QWidget* parent)
@@ -30,12 +44,14 @@ WebView::WebView(QWidget* parent)
_timerAbortMessage(new QTimer(this)),
_abortedDownload(false),
_inErrorState(false),
- _timerReset(new QTimer(this))
+ _timerReset(new QTimer(this)),
+ _firstLoad(false)
{
this->setPage(new UaWebPage);
_timerAbortMessage->setSingleShot(true);
_timerReset->setSingleShot(true);
connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested()));
+ page()->setNetworkAccessManager(new Nam(this));
page()->setForwardUnsupportedContent(true);
page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
//page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
@@ -132,6 +148,11 @@ void WebView::onLoadFinished(bool ok)
} else {
_timerReset->start(60000);
}
+ if (_firstLoad) {
+ _firstLoad = false;
+ this->page()->history()->clear();
+ this->history()->clear();
+ }
}
void WebView::reset(const QString baseUrl)
@@ -147,9 +168,10 @@ void WebView::reset(const QString baseUrl)
q.addQueryItem("token", _token);
url.setQuery(q);
_urls.clear();
+ qDebug() << "Bahnahne";
this->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar);
- this->history()->clear();
this->setUrl(url);
+ _firstLoad = true;
_timerAbortMessage->stop();
_timerReset->stop();
QTimer::singleShot(5000, [this]() {
diff --git a/src/webview.h b/src/webview.h
index a03d517..98c596d 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -36,7 +36,7 @@ protected slots:
void unsupportedContent(QNetworkReply*);
void downloadRequest(QNetworkRequest);
void downloadDeniedMessage();
- void onLoadFinished(bool ok);
+ void onLoadFinished(bool ok);
private:
QStack<QUrl> _urls;
@@ -45,6 +45,7 @@ private:
bool _inErrorState;
QString _token;
QTimer *_timerReset;
+ bool _firstLoad;
};
#endif