1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "webview.h"
#include <QWebFrame>
#include <QNetworkReply>
#include <QMessageBox>
#include <QTimer>
WebView::WebView(QWidget* parent)
: QWebView(parent),
_timer(new QTimer(this)),
_abortedDownload(false) {
_timer->setSingleShot(true);
connect(page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested()));
page()->setForwardUnsupportedContent(true);
connect(page(), SIGNAL(unsupportedContent(QNetworkReply*)),this,SLOT(unsupportedContent(QNetworkReply*)));
connect(page(), SIGNAL(downloadRequested(QNetworkRequest)),this,SLOT(downloadRequest(QNetworkRequest)));
connect(_timer, SIGNAL(timeout()), this, SLOT(downloadDeniedMessage()));
}
void WebView::windowCloseRequested()
{
// If we have an old URL stored on the stack, navigate back to it, otherwise we return and nothing happens
if (_urls.empty())
return;
QUrl url = _urls.pop();
page()->mainFrame()->load(url);
}
QWebView* WebView::createWindow(QWebPage::WebWindowType)
{
// Remember current URL, then return the current Web View so no new window opens
_urls.push(this->url());
return this;
}
void WebView::unsupportedContent(QNetworkReply* rep)
{
_abortedDownload = true;
rep->abort();
rep->deleteLater();
_timer->start(1);
}
void WebView::downloadRequest(QNetworkRequest)
{
_timer->start(1);
}
void WebView::downloadDeniedMessage()
{
QMessageBox::warning(this->parentWidget(), QString::fromUtf8("Denied"),
QString::fromUtf8("The requested action triggered a download, which is not allowed.\n\n"
"Diese Aktion löst einen Download aus, was nicht erlaubt ist."));
}
|