diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/webpage.cpp | 243 | ||||
-rw-r--r-- | src/webpage.h | 9 | ||||
-rw-r--r-- | src/webview.cpp | 42 | ||||
-rw-r--r-- | src/webview.h | 5 |
4 files changed, 61 insertions, 238 deletions
diff --git a/src/webpage.cpp b/src/webpage.cpp index 4c361f7b..cfbc32cf 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -62,8 +62,6 @@ #include <QtWebKit/QWebSettings> #include <QtWebKit/QWebView> -// #include <QtUiTools/QUiLoader> - WebPage::WebPage(QObject *parent) : KWebPage(parent) @@ -75,105 +73,6 @@ WebPage::WebPage(QObject *parent) } -void WebPage::manageNetworkErrors(QNetworkReply* reply) -{ - switch(reply->error()) - { - - case QNetworkReply::NoError: - kDebug() << "NoError"; - return; - break; - - case QNetworkReply::ConnectionRefusedError: - kDebug() << "ConnectionRefusedError"; - break; - - case QNetworkReply::RemoteHostClosedError: - kDebug() << "RemoteHostClosedError"; - break; - - case QNetworkReply::HostNotFoundError: - kDebug() << "HostNotFoundError"; - break; - - case QNetworkReply::TimeoutError: - kDebug() << "TimeoutError"; - break; - - case QNetworkReply::OperationCanceledError: - kDebug() << "OperationCanceledError"; - break; - - case QNetworkReply::SslHandshakeFailedError: - kDebug() << "SslHandshakeFailedError"; - break; - - case QNetworkReply::ProxyConnectionRefusedError: - kDebug() << "ProxyConnectionRefusedError"; - break; - - case QNetworkReply::ProxyConnectionClosedError: - kDebug() << "ProxyConnectionClosedError"; - break; - - case QNetworkReply::ProxyNotFoundError: - kDebug() << "ProxyNotFoundError"; - break; - - case QNetworkReply::ProxyTimeoutError: - kDebug() << "ProxyTimeoutError"; - break; - - case QNetworkReply::ProxyAuthenticationRequiredError: - kDebug() << "ProxyAuthenticationRequiredError"; - break; - - case QNetworkReply::ContentAccessDenied: - kDebug() << "ContentAccessDenied"; - break; - - case QNetworkReply::ContentOperationNotPermittedError: - kDebug() << "ContentOperationNotPermittedError"; - break; - - case QNetworkReply::ContentNotFoundError: - kDebug() << "ContentNotFoundError"; - break; - - case QNetworkReply::AuthenticationRequiredError: - kDebug() << "AuthenticationRequiredError"; - break; - - case QNetworkReply::ProtocolUnknownError: - kDebug() << "ProtocolUnknownError"; - break; - - case QNetworkReply::ProtocolInvalidOperationError: - kDebug() << "ProtocolInvalidOperationError"; - break; - - case QNetworkReply::UnknownNetworkError: - kDebug() << "UnknownNetworkError"; - break; - - case QNetworkReply::UnknownProxyError: - kDebug() << "UnknownProxyError"; - break; - - case QNetworkReply::UnknownContentError: - kDebug() << "UnknownContentError"; - break; - - case QNetworkReply::ProtocolFailure: - kDebug() << "ProtocolFailure"; - break; - - }; - viewErrorPage(reply); -} - - bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { @@ -185,44 +84,23 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r return false; } - - switch (type) + // create convenience fake api:// protocol for KDE apidox search and Qt docs + if (scheme == QLatin1String("api")) { - // user activated a submit button for an HTML form. - case QWebPage::NavigationTypeFormSubmitted: - kDebug() << "NavigationTypeFormSubmitted"; - kDebug() << request.url(); - break; - - // An HTML form was submitted a second time. - case QWebPage::NavigationTypeFormResubmitted: - kDebug() << "NavigationTypeFormResubmitted"; - break; - - // A navigation to another document using a method not listed above. - case QWebPage::NavigationTypeOther: - kDebug() << "NavigationTypeOther"; - break; - - // user clicked on a link or pressed return on a focused link. - case QWebPage::NavigationTypeLinkClicked: - kDebug() << "NavigationTypeLinkClicked"; - break; - - // Navigation to a previously shown document in the back or forward history is requested. - case QWebPage::NavigationTypeBackOrForward: - kDebug() << "NavigationTypeBackOrForward"; - break; - - // user activated the reload action. - case QWebPage::NavigationTypeReload: - kDebug() << "NavigationTypeReload"; - break; - - // should be nothing.. - default: - kDebug() << "Default NON extant case.."; - break; + QString path; + QString className = request.url().host().toLower(); + if (className[0] == 'k') + { + path = QString("http://api.kde.org/new.classmapper.php?class=%1").arg(className); + } + else if (className[0] == 'q') + { + path = QString("http://doc.trolltech.com/4.5/%1.html").arg(className); + } + KUrl url(path); + + Application::instance()->mainWindow()->loadUrl(url); + return false; } return QWebPage::acceptNavigationRequest(frame, request, type); @@ -245,42 +123,24 @@ KWebPage *WebPage::createWindow(QWebPage::WebWindowType type) } -void WebPage::slotHandleUnsupportedContent(QNetworkReply *reply) -{ - // create convenience fake api:// protocol for KDE apidox search and Qt docs - if (reply->url().scheme() == "api") - { - QString path; - QString className = reply->url().host().toLower(); - if (className[0] == 'k') - { - path = QString("http://api.kde.org/new.classmapper.php?class=%1").arg(className); - } - else if (className[0] == 'q') - { - path = QString("http://doc.trolltech.com/4.5/%1.html").arg(className); - } - KUrl url(path); +// FIXME: implement here (perhaps) mimetype discerning && file loading (KToolInvocation??) +// void WebPage::slotHandleUnsupportedContent(QNetworkReply *reply) +// { +// +// if (reply->error() == QNetworkReply::NoError) +// { +// return slotDownloadRequested(reply->request(), reply); +// } +// +// viewErrorPage(reply); +// } - Application::instance()->mainWindow()->loadUrl(url); + +void WebPage::manageNetworkErrors(QNetworkReply* reply) +{ + if(reply->error() == QNetworkReply::NoError) return; - } - if (reply->error() == QNetworkReply::NoError) - { - return slotDownloadRequested(reply->request(), reply); -// // st iframe unwanted download fix -// if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) -// { -// KUrl srcUrl = reply->url(); -// Application::downloadManager()->newDownload(srcUrl); -// } -// else -// { -// kDebug() << "invalid content type header"; -// } -// return; - } viewErrorPage(reply); } @@ -306,26 +166,27 @@ void WebPage::viewErrorPage(QNetworkReply *reply) .arg(reply->errorString()) .arg(reply->url().toString()); -// QList<QWebFrame*> frames; -// frames.append(mainFrame()); -// while (!frames.isEmpty()) -// { -// QWebFrame *firstFrame = frames.takeFirst(); -// if (firstFrame->url() == reply->url()) -// { -// firstFrame->setHtml(html, reply->url()); -// return; -// } -// QList<QWebFrame *> children = firstFrame->childFrames(); -// foreach(QWebFrame *frame, children) -// { -// frames.append(frame); -// } -// } -// if (m_loadingUrl == reply->url()) -// { + // test + QList<QWebFrame*> frames; + frames.append(mainFrame()); + while (!frames.isEmpty()) + { + QWebFrame *firstFrame = frames.takeFirst(); + if (firstFrame->url() == reply->url()) + { + firstFrame->setHtml(html, reply->url()); + return; + } + QList<QWebFrame *> children = firstFrame->childFrames(); + foreach(QWebFrame *frame, children) + { + frames.append(frame); + } + } + if (m_loadingUrl == reply->url()) + { mainFrame()->setHtml(html, reply->url()); // Don't put error pages to the history. Application::historyManager()->removeHistoryEntry(reply->url(), mainFrame()->title()); -// } -}
\ No newline at end of file + } +} diff --git a/src/webpage.h b/src/webpage.h index 5fd69702..1f8777bd 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -65,17 +65,12 @@ protected: KWebPage *createWindow(QWebPage::WebWindowType type); -protected Q_SLOTS: - virtual void slotHandleUnsupportedContent(QNetworkReply *reply); +// protected Q_SLOTS: +// virtual void slotHandleUnsupportedContent(QNetworkReply *reply); private: void viewErrorPage(QNetworkReply *); - friend class WebView; - - // set the webview mousepressedevent -// Qt::KeyboardModifiers m_keyboardModifiers; -// Qt::MouseButtons m_pressedButtons; KUrl m_loadingUrl; }; diff --git a/src/webview.cpp b/src/webview.cpp index 16f7b6e5..4f6ba097 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -75,7 +75,7 @@ WebView::WebView(QWidget* parent) connect(this, SIGNAL(loadProgress(int)), this, SLOT(setProgress(int))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); - connect(this, SIGNAL(openUrlInNewTab(const KUrl &)), this, SLOT(load(const KUrl &))); + connect(this, SIGNAL(openUrlInNewTab(const KUrl &)), this, SLOT(openLinkInNewTab(const KUrl &))); } @@ -218,10 +218,11 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) } -// void WebView::openLinkInNewTab() -// { -// pageAction(QWebPage::OpenLinkInNewWindow)->trigger(); -// } +void WebView::openLinkInNewTab(const KUrl &url) +{ + Application::instance()->newWebView(); + load(url); +} void WebView::loadFinished() @@ -235,37 +236,6 @@ void WebView::loadFinished() } -// void WebView::mousePressEvent(QMouseEvent *event) -// { -// m_page->m_pressedButtons = event->buttons(); -// m_page->m_keyboardModifiers = event->modifiers(); -// QWebView::mousePressEvent(event); -// } -// -// -// void WebView::mouseReleaseEvent(QMouseEvent *event) -// { -// QWebView::mouseReleaseEvent(event); -// if (!event->isAccepted() && (m_page->m_pressedButtons & Qt::MidButton)) -// { -// KUrl url(QApplication::clipboard()->text(QClipboard::Selection)); -// if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) -// { -// setUrl(url); -// } -// } -// } - - -// void WebView::downloadRequested(const QNetworkRequest &request) -// { -// KUrl srcUrl = request.url(); -// QString path = ReKonfig::downloadDir() + QString("/") + srcUrl.fileName(); -// KUrl destUrl = KUrl(path); -// Application::downloadManager()->newDownload(srcUrl); -// } - - void WebView::keyPressEvent(QKeyEvent *event) { if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_Tab)) diff --git a/src/webview.h b/src/webview.h index ae420de4..2ac018d7 100644 --- a/src/webview.h +++ b/src/webview.h @@ -68,8 +68,6 @@ signals: void shiftCtrlTabPressed(); protected: -// void mousePressEvent(QMouseEvent *event); -// void mouseReleaseEvent(QMouseEvent *event); void contextMenuEvent(QContextMenuEvent *event); /** @@ -86,8 +84,7 @@ private slots: void loadFinished(); void setStatusBarText(const QString &string); -// void downloadRequested(const QNetworkRequest &request); -// void open LinkInNewTab(); + void openLinkInNewTab(const KUrl &); private: WebPage *m_page; |