copied swisssurfer from https://dev.marc.waeckerlin.org/svn/swisssurfer/trunk, version 15,refs #1
This commit is contained in:
978
swisssurfer/src/browser.hxx
Normal file
978
swisssurfer/src/browser.hxx
Normal file
@@ -0,0 +1,978 @@
|
||||
/*! @file
|
||||
|
||||
@id $Id: browser.hxx 15 2010-06-03 14:17:27Z marc $
|
||||
*/
|
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#ifndef BROWSER_HXX
|
||||
#define BROWSER_HXX
|
||||
|
||||
#include <ui_browser.h>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QProgressBar>
|
||||
#include <QtGui/QSlider>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtWebKit/QWebHistory>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QSslError>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
|
||||
#include <proxyface/proxy.hxx>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#define LOG qDebug()<<__PRETTY_FUNCTION__;
|
||||
|
||||
class SslClientAuthNetworkAccessManager: public QNetworkAccessManager {
|
||||
Q_OBJECT;
|
||||
public:
|
||||
SslClientAuthNetworkAccessManager(QObject* parent = 0):
|
||||
QNetworkAccessManager(parent) {
|
||||
LOG;
|
||||
}
|
||||
virtual ~SslClientAuthNetworkAccessManager() {
|
||||
LOG;
|
||||
}
|
||||
protected:
|
||||
virtual QNetworkReply* createRequest(Operation op,
|
||||
const QNetworkRequest& req,
|
||||
QIODevice* outgoingData = 0 ) {
|
||||
LOG;
|
||||
QNetworkReply* rep
|
||||
(QNetworkAccessManager::createRequest(op, req, outgoingData));
|
||||
//qDebug()<<"Reply created: "<<(int)rep;
|
||||
qDebug()<<"Reply to URL: "<<rep->url().toString();
|
||||
return rep;
|
||||
}
|
||||
};
|
||||
|
||||
class Browser: public QMainWindow, protected Ui::Browser {
|
||||
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
|
||||
Browser(const QString& url, bool kiosk = false, bool proxydetection = true):
|
||||
_url(0), _home(url), _proxy(0),
|
||||
_kiosk(kiosk) {
|
||||
LOG;
|
||||
if (!check(url))
|
||||
throw std::runtime_error(tr("access to URL %1 not allowed")
|
||||
.arg(url).toStdString());
|
||||
setupUi(this);
|
||||
actionProxySettings->setEnabled(proxydetection);
|
||||
if (proxydetection) {
|
||||
_proxy = new gui::Proxy(url, this);
|
||||
assert(connect(_proxy, SIGNAL(proxyFound(const QUrl&,
|
||||
const QNetworkProxy&)),
|
||||
SLOT(startDownload(QUrl, const QNetworkProxy&))));
|
||||
assert(connect(_proxy, SIGNAL(temporaryError
|
||||
(QNetworkReply::NetworkError,
|
||||
QString, QString)),
|
||||
SLOT(proxy_error(QNetworkReply::NetworkError,
|
||||
QString, QString))));
|
||||
assert(connect(_proxy, SIGNAL(proxyError(QNetworkReply::NetworkError)),
|
||||
SLOT(proxy_error(QNetworkReply::NetworkError))));
|
||||
}
|
||||
_toolbar->addWidget(_url = new QLineEdit(_toolbar));
|
||||
_url->setText(url);
|
||||
assert(connect(_url, SIGNAL(returnPressed()), SLOT(load())));
|
||||
if (_kiosk) {
|
||||
_menu->hide();
|
||||
_url->setEnabled(false);
|
||||
}
|
||||
statusBar()->addPermanentWidget(_progress = new QProgressBar());
|
||||
statusBar()->addPermanentWidget(_zoom = new QSlider(Qt::Horizontal));
|
||||
_zoom->setMinimum(1);
|
||||
_zoom->setMaximum(100);
|
||||
_zoom->setValue(10);
|
||||
assert(connect(_zoom, SIGNAL(valueChanged(int)), SLOT(zoom(int))));
|
||||
_browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
|
||||
_browser->page()->setNetworkAccessManager
|
||||
(new SslClientAuthNetworkAccessManager);
|
||||
// QWebPage WebAction
|
||||
connect(_browser->pageAction(QWebPage::OpenLink),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredOpenLink(bool)));
|
||||
connect(_browser->pageAction(QWebPage::OpenLinkInNewWindow),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredOpenLinkInNewWindow(bool)));
|
||||
connect(_browser->pageAction(QWebPage::OpenFrameInNewWindow),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredOpenFrameInNewWindow(bool)));
|
||||
connect(_browser->pageAction(QWebPage::DownloadLinkToDisk),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredDownloadLinkToDisk(bool)));
|
||||
connect(_browser->pageAction(QWebPage::CopyLinkToClipboard),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredCopyLinkToClipboard(bool)));
|
||||
connect(_browser->pageAction(QWebPage::OpenImageInNewWindow),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredOpenImageInNewWindow(bool)));
|
||||
connect(_browser->pageAction(QWebPage::DownloadImageToDisk),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredDownloadImageToDisk(bool)));
|
||||
connect(_browser->pageAction(QWebPage::CopyImageToClipboard),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredCopyImageToClipboard(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Back),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredBack(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Forward),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredForward(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Stop),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredStop(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Reload),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredReload(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Cut),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredCut(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Copy),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredCopy(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Paste),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredPaste(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Undo),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredUndo(bool)));
|
||||
connect(_browser->pageAction(QWebPage::Redo),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredRedo(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToNextChar),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToNextChar(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToPreviousChar),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToPreviousChar(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToNextWord),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToNextWord(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToPreviousWord),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToPreviousWord(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToNextLine),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToNextLine(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToPreviousLine),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToPreviousLine(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToStartOfLine),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToStartOfLine(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToEndOfLine),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToEndOfLine(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToStartOfBlock),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToStartOfBlock(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToEndOfBlock),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToEndOfBlock(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToStartOfDocument),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToStartOfDocument(bool)));
|
||||
connect(_browser->pageAction(QWebPage::MoveToEndOfDocument),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredMoveToEndOfDocument(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectNextChar),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectNextChar(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectPreviousChar),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectPreviousChar(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectNextWord),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectNextWord(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectPreviousWord),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectPreviousWord(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectNextLine),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectNextLine(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectPreviousLine),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectPreviousLine(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectStartOfLine),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectStartOfLine(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectEndOfLine),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectEndOfLine(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectStartOfBlock),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectStartOfBlock(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectEndOfBlock),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectEndOfBlock(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectStartOfDocument),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectStartOfDocument(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectEndOfDocument),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectEndOfDocument(bool)));
|
||||
connect(_browser->pageAction(QWebPage::DeleteStartOfWord),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredDeleteStartOfWord(bool)));
|
||||
connect(_browser->pageAction(QWebPage::DeleteEndOfWord),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredDeleteEndOfWord(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SetTextDirectionDefault),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSetTextDirectionDefault(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SetTextDirectionLeftToRight),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSetTextDirectionLeftToRight(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SetTextDirectionRightToLeft),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSetTextDirectionRightToLeft(bool)));
|
||||
connect(_browser->pageAction(QWebPage::ToggleBold),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredToggleBold(bool)));
|
||||
connect(_browser->pageAction(QWebPage::ToggleItalic),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredToggleItalic(bool)));
|
||||
connect(_browser->pageAction(QWebPage::ToggleUnderline),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredToggleUnderline(bool)));
|
||||
connect(_browser->pageAction(QWebPage::InspectElement),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredInspectElement(bool)));
|
||||
connect(_browser->pageAction(QWebPage::InsertParagraphSeparator),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredInsertParagraphSeparator(bool)));
|
||||
connect(_browser->pageAction(QWebPage::InsertLineSeparator),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredInsertLineSeparator(bool)));
|
||||
connect(_browser->pageAction(QWebPage::SelectAll),
|
||||
SIGNAL(triggered(bool)),
|
||||
SLOT(triggeredSelectAll(bool)));
|
||||
// QWebPage
|
||||
assert(connect(_browser->page(), SIGNAL(contentsChanged()),
|
||||
SLOT(contentsChanged())));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(databaseQuotaExceeded(QWebFrame*, QString)),
|
||||
SLOT(databaseQuotaExceeded(QWebFrame*, QString))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(downloadRequested(const QNetworkRequest&)),
|
||||
SLOT(downloadRequested(const QNetworkRequest&))));
|
||||
assert(connect(_browser->page(), SIGNAL(frameCreated(QWebFrame*)),
|
||||
SLOT(frameCreated(QWebFrame*))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(geometryChangeRequested(const QRect&)),
|
||||
SLOT(geometryChangeRequested(const QRect&))));
|
||||
assert(connect(_browser->page(), SIGNAL(linkClicked(const QUrl&)),
|
||||
SLOT(linkClicked(const QUrl&))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(linkHovered(const QString&, const QString&,
|
||||
const QString&)),
|
||||
SLOT(linkHovered(const QString&, const QString&,
|
||||
const QString&))));
|
||||
assert(connect(_browser->page(), SIGNAL(loadFinished(bool)),
|
||||
SLOT(loadFinished(bool))));
|
||||
assert(connect(_browser->page(), SIGNAL(loadProgress(int)),
|
||||
SLOT(loadProgress(int))));
|
||||
assert(connect(_browser->page(), SIGNAL(loadStarted()),
|
||||
SLOT(loadStarted())));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(menuBarVisibilityChangeRequested(bool)),
|
||||
SLOT(menuBarVisibilityChangeRequested(bool))));
|
||||
assert(connect(_browser->page(), SIGNAL(microFocusChanged()),
|
||||
SLOT(microFocusChanged())));
|
||||
assert(connect(_browser->page(), SIGNAL(printRequested(QWebFrame*)),
|
||||
SLOT(printRequested(QWebFrame*))));
|
||||
assert(connect(_browser->page(), SIGNAL(repaintRequested(const QRect&)),
|
||||
SLOT(repaintRequested(const QRect&))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(restoreFrameStateRequested(QWebFrame*)),
|
||||
SLOT(restoreFrameStateRequested(QWebFrame*))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(saveFrameStateRequested(QWebFrame*,
|
||||
QWebHistoryItem*)),
|
||||
SLOT(saveFrameStateRequested(QWebFrame*,
|
||||
QWebHistoryItem*))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(scrollRequested(int, int, const QRect&)),
|
||||
SLOT(scrollRequested(int, int, const QRect&))));
|
||||
assert(connect(_browser->page(), SIGNAL(selectionChanged()),
|
||||
SLOT(selectionChanged())));
|
||||
assert(connect(_browser->page(), SIGNAL(statusBarMessage(const QString&)),
|
||||
SLOT(statusBarMessage(const QString&))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(statusBarVisibilityChangeRequested(bool)),
|
||||
SLOT(statusBarVisibilityChangeRequested(bool))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(toolBarVisibilityChangeRequested(bool)),
|
||||
SLOT(toolBarVisibilityChangeRequested(bool))));
|
||||
assert(connect(_browser->page(),
|
||||
SIGNAL(unsupportedContent(QNetworkReply*)),
|
||||
SLOT(unsupportedContent(QNetworkReply*))));
|
||||
assert(connect(_browser->page(), SIGNAL(windowCloseRequested()),
|
||||
SLOT(windowCloseRequested())));
|
||||
// QNetworkAccessManager
|
||||
assert(connect(_browser->page()->networkAccessManager(),
|
||||
SIGNAL(authenticationRequired(QNetworkReply*,
|
||||
QAuthenticator*)),
|
||||
SLOT(authenticationRequired(QNetworkReply*,
|
||||
QAuthenticator*))));
|
||||
assert(connect(_browser->page()->networkAccessManager(),
|
||||
SIGNAL(finished(QNetworkReply*)),
|
||||
SLOT(finished(QNetworkReply*))));
|
||||
assert(connect(_browser->page()->networkAccessManager(),
|
||||
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,
|
||||
QAuthenticator*)),
|
||||
SLOT(proxyAuthenticationRequired(const QNetworkProxy&,
|
||||
QAuthenticator*))));
|
||||
assert(connect(_browser->page()->networkAccessManager(),
|
||||
SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)),
|
||||
SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&))));
|
||||
load(url);
|
||||
}
|
||||
|
||||
QString networkError(QNetworkReply::NetworkError err) {
|
||||
LOG;
|
||||
switch (err) {
|
||||
case QNetworkReply::NoError:
|
||||
return tr("Network connection successful, remote host can be"
|
||||
" reached.");
|
||||
case QNetworkReply::ConnectionRefusedError:
|
||||
return tr("The remote server refused the connection (the server is"
|
||||
" not accepting requests).");
|
||||
case QNetworkReply::RemoteHostClosedError:
|
||||
return tr("The remote server closed the connection prematurely,"
|
||||
" before the entire reply was received and processed.");
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
return tr("The remote host name was not found (invalid hostname).");
|
||||
case QNetworkReply::TimeoutError:
|
||||
return tr("The connection to the remote server timed out.");
|
||||
case QNetworkReply::OperationCanceledError:
|
||||
return tr("The operation was canceled via calls to abort() or"
|
||||
" close() before it was finished.");
|
||||
case QNetworkReply::SslHandshakeFailedError:
|
||||
return tr("The SSL/TLS handshake failed and the encrypted channel"
|
||||
" could not be established. The sslErrors() signal should"
|
||||
" have been emitted.");
|
||||
case QNetworkReply::ProxyConnectionRefusedError:
|
||||
return tr("The connection to the proxy server was refused (the"
|
||||
" proxy server is not accepting requests).");
|
||||
case QNetworkReply::ProxyConnectionClosedError:
|
||||
return tr("The proxy server closed the connection prematurely,"
|
||||
" before the entire reply was received and processed.");
|
||||
case QNetworkReply::ProxyNotFoundError:
|
||||
return tr("The proxy host name was not found (invalid proxy"
|
||||
" hostname).");
|
||||
case QNetworkReply::ProxyTimeoutError:
|
||||
return tr("The connection to the proxy timed out or the proxy did"
|
||||
" not reply in time to the request sent.");
|
||||
case QNetworkReply::ProxyAuthenticationRequiredError:
|
||||
return tr("The proxy requires authentication in order to honour the"
|
||||
" request but did not accept any credentials offered"
|
||||
" (if any).");
|
||||
case QNetworkReply::ContentAccessDenied:
|
||||
return tr("The access to the remote content was denied (similar to"
|
||||
" HTTP error 401).");
|
||||
case QNetworkReply::ContentOperationNotPermittedError:
|
||||
return tr("The operation requested on the remote content is not"
|
||||
" permitted.");
|
||||
case QNetworkReply::ContentNotFoundError:
|
||||
return tr("The remote content was not found at the server (similar"
|
||||
" to HTTP error 404).");
|
||||
case QNetworkReply::AuthenticationRequiredError:
|
||||
return tr("The remote server requires authentication to serve the"
|
||||
" content but the credentials provided were not accepted"
|
||||
" (if any).");
|
||||
case QNetworkReply::ProtocolUnknownError:
|
||||
return tr("The Network Access API cannot honor the request because"
|
||||
" the protocol is not known.");
|
||||
case QNetworkReply::ProtocolInvalidOperationError:
|
||||
return tr("The requested operation is invalid for this protocol.");
|
||||
case QNetworkReply::UnknownNetworkError:
|
||||
return tr("An unknown network-related error was detected.");
|
||||
case QNetworkReply::UnknownProxyError:
|
||||
return tr("An unknown proxy-related error was detected.");
|
||||
case QNetworkReply::UnknownContentError:
|
||||
return tr("An unknonwn error related to the remote content was"
|
||||
" detected.");
|
||||
case QNetworkReply::ProtocolFailure:
|
||||
return tr("A breakdown in protocol was detected (parsing error,"
|
||||
" invalid or unexpected responses, etc.).");
|
||||
default:
|
||||
return tr("<strong>Unknown network error (code: %1).</string>")
|
||||
.arg(err);
|
||||
}
|
||||
}
|
||||
|
||||
bool check(QUrl page) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
void load() {
|
||||
LOG;
|
||||
load(_url->text());
|
||||
}
|
||||
|
||||
void load(QString page) {
|
||||
if (QUrl(page).scheme()=="") page = "http://"+page;
|
||||
load(QUrl(page));
|
||||
}
|
||||
|
||||
void load(QUrl page) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("Checking: %1").arg(page.toString()));
|
||||
try {
|
||||
if (!check(page)) {
|
||||
qDebug()<<"########## BLACK LISTED IGNORED ##########";
|
||||
statusBar()->showMessage(tr("Forbidden: %1").arg(page.toString()));
|
||||
QMessageBox::warning(this, tr("Access Denied"),
|
||||
tr("<p>Access denied due to security"
|
||||
" considerations.</p><p>You are not"
|
||||
" allowed to connect to %1.")
|
||||
.arg(page.toString()));
|
||||
return;
|
||||
}
|
||||
if (_proxy) _proxy->checkUrl(page.toString());
|
||||
_progress->setValue(0);
|
||||
_progress->setMaximum(0);
|
||||
_progress->show();
|
||||
if (!_proxy) startDownload(page);
|
||||
} catch (...) {
|
||||
reply_error(QNetworkReply::ProxyNotFoundError);
|
||||
} // no network
|
||||
}
|
||||
|
||||
void startDownload(QUrl url, const QNetworkProxy& proxy) {
|
||||
LOG;
|
||||
QNetworkProxy::setApplicationProxy(proxy);
|
||||
startDownload(url);
|
||||
}
|
||||
|
||||
void startDownload(QUrl url) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("Reading: %1").arg(url.toString()));
|
||||
if (!url.isValid()) {
|
||||
statusBar()->showMessage(tr("Illegal URL: %1").arg(url.errorString()));
|
||||
_progress->hide();
|
||||
return;
|
||||
}
|
||||
//if (url.scheme()=="") url.setScheme("http");
|
||||
_browser->load(url);
|
||||
}
|
||||
|
||||
void reply_error(QNetworkReply::NetworkError err) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("network error"));
|
||||
_error += tr("<h2>%1</h2><p>%2</p>")
|
||||
.arg(tr("Reply Error"))
|
||||
.arg(networkError(err));
|
||||
}
|
||||
|
||||
//! intermediate proxy error
|
||||
void proxy_error(QNetworkReply::NetworkError err,
|
||||
QString errStr, QString proxy) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("proxy error"));
|
||||
_error += tr("<h2>%1</h2><p>Proxy: %3</p><p>%2</p><p>%4</p>")
|
||||
.arg(tr("Possible Proxy Failed"))
|
||||
.arg(networkError(err))
|
||||
.arg(proxy)
|
||||
.arg(errStr);
|
||||
}
|
||||
|
||||
//! final proxy error
|
||||
void proxy_error(QNetworkReply::NetworkError err) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("proxy error"));
|
||||
_error = tr("<h2>%1</h2><p>%2</p>")
|
||||
.arg(tr("Connection Cannot Be Established"))
|
||||
.arg(networkError(err)) + _error;
|
||||
on__browser_loadFinished(false);
|
||||
}
|
||||
|
||||
void zoom(int i) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("Zoom: %1%").arg(100.0*i/10.0));
|
||||
_browser->setZoomFactor(i/10.0);
|
||||
}
|
||||
|
||||
void on_actionHome_activated() {
|
||||
LOG;
|
||||
load(_home);
|
||||
}
|
||||
|
||||
void on__browser_urlChanged(const QUrl& url) {
|
||||
LOG;
|
||||
if (_url) _url->setText(url.toString());
|
||||
}
|
||||
|
||||
void on__browser_linkClicked(const QUrl& url) {
|
||||
LOG;
|
||||
load(url);
|
||||
}
|
||||
|
||||
void on__browser_iconChanged() {
|
||||
LOG;
|
||||
setWindowIcon(_browser->icon());
|
||||
}
|
||||
|
||||
void on__browser_titleChanged(const QString& text) {
|
||||
LOG;
|
||||
setWindowTitle(trUtf8("%1 - SwissSurfer").arg(text));
|
||||
}
|
||||
|
||||
void on__browser_statusBarMessage(const QString& text) {
|
||||
LOG;
|
||||
qDebug()<<"Message: "<<text;
|
||||
if (text.size()) statusBar()->showMessage(tr("Info: %1").arg(text));
|
||||
}
|
||||
|
||||
void on__browser_loadProgress(int i) {
|
||||
LOG;
|
||||
_progress->setValue(i);
|
||||
}
|
||||
|
||||
void on__browser_loadStarted() {
|
||||
LOG;
|
||||
_progress->setValue(0);
|
||||
_progress->setMaximum(100);
|
||||
_progress->show();
|
||||
actionStop->setEnabled(true);
|
||||
actionForward->setEnabled(false);
|
||||
actionBack->setEnabled(false);
|
||||
actionReload->setEnabled(false);
|
||||
actionHome->setEnabled(false);
|
||||
}
|
||||
|
||||
void on__browser_loadFinished(bool ok) {
|
||||
LOG;
|
||||
if (!ok) {
|
||||
_browser->setHtml(tr("<html><title>Page Load Error</title>"
|
||||
"<body><h1>Page Load Error</h1>%1"
|
||||
"</body></html>")
|
||||
.arg(_error),
|
||||
_errorUrl);
|
||||
statusBar()->showMessage(tr("download error"));
|
||||
} else {
|
||||
statusBar()->showMessage(tr("done."));
|
||||
}
|
||||
_error.clear();
|
||||
_progress->hide();
|
||||
on__browser_iconChanged();
|
||||
actionStop->setEnabled(false);
|
||||
actionForward->setEnabled(_browser->history()->canGoForward());
|
||||
actionBack->setEnabled(_browser->history()->canGoBack());
|
||||
actionReload->setEnabled(true);
|
||||
actionHome->setEnabled(true);
|
||||
}
|
||||
|
||||
void on_actionNew_triggered() {
|
||||
LOG;
|
||||
(new Browser(_browser->url().toString(), _kiosk))->show();
|
||||
}
|
||||
|
||||
void on_actionClose_triggered() {
|
||||
LOG;
|
||||
close();
|
||||
}
|
||||
|
||||
void on_actionProxySettings_triggered() {
|
||||
LOG;
|
||||
if (_proxy) _proxy->show();
|
||||
}
|
||||
|
||||
//@name QWebPage slots
|
||||
//@{
|
||||
|
||||
void triggeredOpenLink(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredOpenLinkInNewWindow(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredOpenFrameInNewWindow(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredDownloadLinkToDisk(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredCopyLinkToClipboard(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredOpenImageInNewWindow(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredDownloadImageToDisk(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredCopyImageToClipboard(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredBack(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredForward(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredStop(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredReload(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredCut(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredCopy(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredPaste(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredUndo(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredRedo(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToNextChar(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToPreviousChar(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToNextWord(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToPreviousWord(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToNextLine(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToPreviousLine(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToStartOfLine(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToEndOfLine(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToStartOfBlock(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToEndOfBlock(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToStartOfDocument(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredMoveToEndOfDocument(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectNextChar(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectPreviousChar(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectNextWord(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectPreviousWord(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectNextLine(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectPreviousLine(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectStartOfLine(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectEndOfLine(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectStartOfBlock(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectEndOfBlock(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectStartOfDocument(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectEndOfDocument(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredDeleteStartOfWord(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredDeleteEndOfWord(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSetTextDirectionDefault(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSetTextDirectionLeftToRight(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSetTextDirectionRightToLeft(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredToggleBold(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredToggleItalic(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredToggleUnderline(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredInspectElement(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredInsertParagraphSeparator(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredInsertLineSeparator(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void triggeredSelectAll(bool) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
//@name QWebPage slots
|
||||
//@{
|
||||
|
||||
void contentsChanged() {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void databaseQuotaExceeded(QWebFrame* frame, QString databaseName) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void downloadRequested(const QNetworkRequest& request) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void frameCreated(QWebFrame* frame) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void geometryChangeRequested(const QRect& geom) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void linkClicked(const QUrl& url) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void linkHovered(const QString& link, const QString& title,
|
||||
const QString& textContent) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("%1", "statusbar for hovered link %1=url")
|
||||
.arg(link));
|
||||
}
|
||||
|
||||
void loadFinished(bool ok) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void loadProgress(int progress) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void loadStarted() {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void menuBarVisibilityChangeRequested(bool visible) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void microFocusChanged() {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void printRequested(QWebFrame* frame) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void repaintRequested(const QRect& dirtyRect) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void restoreFrameStateRequested(QWebFrame* frame) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void saveFrameStateRequested(QWebFrame* frame, QWebHistoryItem* item) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void scrollRequested(int dx, int dy, const QRect& rectToScroll) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void selectionChanged() {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void statusBarMessage(const QString& text) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void statusBarVisibilityChangeRequested(bool visible) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void toolBarVisibilityChangeRequested(bool visible) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void unsupportedContent(QNetworkReply* reply) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("unsupported content"));
|
||||
_error += tr("<h2>%1</h2><p>URL: %3</p><p>%2</p>")
|
||||
.arg(tr("Unsuported Content"))
|
||||
.arg(networkError(reply->error()))
|
||||
.arg(reply->url().toString());
|
||||
_errorUrl = reply->url();
|
||||
}
|
||||
|
||||
void windowCloseRequested() {
|
||||
LOG;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
//@name QNetworkAccessManager signals
|
||||
//@{
|
||||
|
||||
void authenticationRequired(QNetworkReply* reply,
|
||||
QAuthenticator* authenticator) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("authentication required"));
|
||||
_error += tr("<h2>%1</h2><p>URL: %3</p><p>%2</p>")
|
||||
.arg(tr("Authentication Required"))
|
||||
.arg(networkError(reply->error()))
|
||||
.arg(reply->url().toString());
|
||||
_errorUrl = reply->url();
|
||||
}
|
||||
|
||||
void finished(QNetworkReply* reply) {
|
||||
LOG;
|
||||
if (reply->error()!=QNetworkReply::NoError) {
|
||||
_error += tr("<h2>%1</h2><p>URL: %3</p><p>%2</p>")
|
||||
.arg(tr("Network Error"))
|
||||
.arg(networkError(reply->error()))
|
||||
.arg(reply->url().toString());
|
||||
_errorUrl = reply->url();
|
||||
}
|
||||
}
|
||||
|
||||
void proxyAuthenticationRequired(const QNetworkProxy& proxy,
|
||||
QAuthenticator* authenticator) {
|
||||
LOG;
|
||||
}
|
||||
|
||||
void sslErrors(QNetworkReply* reply, const QList<QSslError>& errors) {
|
||||
LOG;
|
||||
statusBar()->showMessage(tr("ssl error"));
|
||||
QString e;
|
||||
for (QList<QSslError>::const_iterator err(errors.begin());
|
||||
err!=errors.end(); ++err)
|
||||
e+=tr("<li>%1</li>", "single ssl error").arg(err->errorString());
|
||||
_error += tr("<h2>%1</h2><p>URL: %4</p><p>%2</p>"
|
||||
"<h3>SSL Errors</h3>"
|
||||
"<p><ul>%3</ul></p>")
|
||||
.arg(tr("SSL Error"))
|
||||
.arg(networkError(reply->error()))
|
||||
.arg(e)
|
||||
.arg(reply->url().toString());
|
||||
_errorUrl = reply->url();
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
QLineEdit* _url;
|
||||
QSlider* _zoom;
|
||||
QProgressBar* _progress;
|
||||
QString _home;
|
||||
gui::Proxy* _proxy;
|
||||
bool _kiosk;
|
||||
bool _proxydetection;
|
||||
QString _error;
|
||||
QUrl _errorUrl;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user