diff options
-rw-r--r-- | src/analyzer/analyzerpanel.cpp | 8 | ||||
-rw-r--r-- | src/filterurljob.cpp | 9 | ||||
-rw-r--r-- | src/filterurljob.h | 3 | ||||
-rw-r--r-- | src/mainwindow.cpp | 130 | ||||
-rw-r--r-- | src/mainwindow.h | 5 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 4 | ||||
-rw-r--r-- | src/webinspectorpanel.cpp | 27 | ||||
-rw-r--r-- | src/webinspectorpanel.h | 9 | ||||
-rw-r--r-- | src/webpage.cpp | 86 | ||||
-rw-r--r-- | src/webpage.h | 11 | ||||
-rw-r--r-- | src/webview.cpp | 9 |
11 files changed, 216 insertions, 85 deletions
diff --git a/src/analyzer/analyzerpanel.cpp b/src/analyzer/analyzerpanel.cpp index be346300..9198cade 100644 --- a/src/analyzer/analyzerpanel.cpp +++ b/src/analyzer/analyzerpanel.cpp @@ -79,10 +79,7 @@ void NetworkAnalyzerPanel::toggle(bool enable) connect(manager, SIGNAL(networkData(QNetworkAccessManager::Operation, const QNetworkRequest &, QNetworkReply *)), _viewer, SLOT(addRequest(QNetworkAccessManager::Operation, const QNetworkRequest &, QNetworkReply *) ) ); - -// mainWindow()->currentTab()->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); -// findChild<QWebInspector *>()->setPage(mainWindow()->currentTab()->page()); - show(); + show(); } else { @@ -91,13 +88,12 @@ void NetworkAnalyzerPanel::toggle(bool enable) _viewer, SLOT(addRequest(QNetworkAccessManager::Operation, const QNetworkRequest &, QNetworkReply *) ) ); hide(); -// mainWindow()->currentTab()->view()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false); } } void NetworkAnalyzerPanel::changeCurrentPage() { - bool enable = mainWindow()->currentTab()->view()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled); + bool enable = mainWindow()->currentTab()->page()->hasNetworkAnalyzerEnabled(); toggle(enable); } diff --git a/src/filterurljob.cpp b/src/filterurljob.cpp index c887ac62..b27df74c 100644 --- a/src/filterurljob.cpp +++ b/src/filterurljob.cpp @@ -30,12 +30,17 @@ // KDE Includes #include <KUriFilterData> + +KUriFilter *FilterUrlJob::s_uriFilter; + + FilterUrlJob::FilterUrlJob(WebView *view, const QString &urlString, QObject *parent) : Job(parent) , _view(view) , _urlString(urlString) { - uriFilter = KUriFilter::self(); + if(!s_uriFilter) + s_uriFilter = KUriFilter::self(); } @@ -58,7 +63,7 @@ void FilterUrlJob::run() KUriFilterData data(_urlString); data.setCheckForExecutables(false); // if true, queries like "rekonq" or "dolphin" are considered as executables - if (uriFilter->filterUri(data) && data.uriType() != KUriFilterData::Error) + if (s_uriFilter->filterUri(data) && data.uriType() != KUriFilterData::Error) { QString tempUrlString = data.uri().url(); _url = KUrl(tempUrlString); diff --git a/src/filterurljob.h b/src/filterurljob.h index c10c5e35..0955c969 100644 --- a/src/filterurljob.h +++ b/src/filterurljob.h @@ -60,7 +60,8 @@ private: WebView *_view; QString _urlString; KUrl _url; - KUriFilter *uriFilter; + + static KUriFilter *s_uriFilter; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1488980f..c56dcf76 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -639,17 +639,23 @@ void MainWindow::preferences() void MainWindow::updateActions() { + bool rekonqPage = currentTab()->page()->isOnRekonqPage(); + kDebug() << "UPDATE ACTIONS: rekonq page = " << rekonqPage; + QAction *historyBackAction = actionByName(KStandardAction::name(KStandardAction::Back)); - historyBackAction->setEnabled(currentTab()->view()->history()->canGoBack()); + if( rekonqPage ) + historyBackAction->setEnabled(true); + else + historyBackAction->setEnabled(currentTab()->view()->history()->canGoBack()); QAction *historyForwardAction = actionByName(KStandardAction::name(KStandardAction::Forward)); historyForwardAction->setEnabled(currentTab()->view()->history()->canGoForward()); - QAction *openClosedTabsAction = actionByName(QLatin1String("open_closed_tabs")); + QAction *openClosedTabsAction = actionByName( QL1S("open_closed_tabs") ); openClosedTabsAction->setEnabled(mainView()->recentlyClosedTabs().size() > 0); // update closed tabs menu - KActionMenu *am = dynamic_cast<KActionMenu *>(actionByName(QLatin1String("closed_tab_menu"))); + KActionMenu *am = dynamic_cast<KActionMenu *>(actionByName( QL1S("closed_tab_menu") )); if (!am) return; @@ -861,16 +867,19 @@ void MainWindow::zoomIn() m_zoomSlider->setValue(m_zoomSlider->value() + 1); } + void MainWindow::zoomNormal() { m_zoomSlider->setValue(10); } + void MainWindow::zoomOut() { m_zoomSlider->setValue(m_zoomSlider->value() - 1); } + void MainWindow::setZoomFactor(int factor) { if (!currentTab()) @@ -878,6 +887,7 @@ void MainWindow::setZoomFactor(int factor) currentTab()->view()->setZoomFactor(QVariant(factor).toReal() / 10); } + void MainWindow::setZoomSliderFactor(qreal factor) { m_zoomSlider->setValue(factor*10); @@ -989,8 +999,8 @@ WebTab *MainWindow::currentTab() const void MainWindow::browserLoading(bool v) { - QAction *stop = actionCollection()->action("stop"); - QAction *reload = actionCollection()->action("view_redisplay"); + QAction *stop = actionCollection()->action( QL1S("stop") ); + QAction *reload = actionCollection()->action( QL1S("view_redisplay") ); if (v) { disconnect(m_stopReloadAction, SIGNAL(triggered(bool)), reload , SIGNAL(triggered(bool))); @@ -1014,56 +1024,68 @@ void MainWindow::browserLoading(bool v) void MainWindow::openPrevious(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers keyboardModifiers) { QWebHistory *history = currentTab()->view()->history(); - if (history->canGoBack()) + QWebHistoryItem *item = 0; + + if (currentTab()->page()->isOnRekonqPage()) { - QWebHistoryItem *item; - if (currentTab()->view()->page()->isOnRekonqPage()) + item = new QWebHistoryItem(history->currentItem()); + currentTab()->view()->page()->setIsOnRekonqPage(false); + } + else + { + if (history->canGoBack()) { - item = new QWebHistoryItem(history->currentItem()); - currentTab()->view()->page()->setIsOnRekonqPage(false); - } - else item = new QWebHistoryItem(history->backItem()); - - if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier) - { - Application::instance()->loadUrl(item->url(), Rekonq::SettingOpenTab); - } - else - { - history->goToItem(*item); } + } - updateActions(); + if(!item) + return; + + if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier) + { + Application::instance()->loadUrl(item->url(), Rekonq::SettingOpenTab); + } + else + { + history->goToItem(*item); } + updateActions(); } void MainWindow::openNext(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers keyboardModifiers) { QWebHistory *history = currentTab()->view()->history(); - if (history->canGoForward()) + QWebHistoryItem *item = 0; + + if (currentTab()->view()->page()->isOnRekonqPage()) { - QWebHistoryItem *item; - if (currentTab()->view()->page()->isOnRekonqPage()) + item = new QWebHistoryItem(history->currentItem()); + currentTab()->view()->page()->setIsOnRekonqPage(false); + } + else + { + if (history->canGoForward()) { - item = new QWebHistoryItem(history->currentItem()); - currentTab()->view()->page()->setIsOnRekonqPage(false); - } - else item = new QWebHistoryItem(history->forwardItem()); - - if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier) - { - Application::instance()->loadUrl(item->url(), Rekonq::SettingOpenTab); } - else - { - history->goToItem(*item); - } - updateActions(); } + + if(!item) + return; + + if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier) + { + Application::instance()->loadUrl(item->url(), Rekonq::SettingOpenTab); + } + else + { + history->goToItem(*item); + } + + updateActions(); } @@ -1377,3 +1399,37 @@ void MainWindow::enableNetworkAnalysis(bool b) currentTab()->page()->enableNetworkAnalyzer(b); m_analyzerPanel->toggle(b); } + + +bool MainWindow::queryClose() +{ + if (m_view->count() > 1) + { + int answer = KMessageBox::questionYesNoCancel( + this, + i18np("Are you sure you want to close the window?\n" "You have 1 tab open", + "Are you sure you want to close the window?\n" "You have %1 tabs open" , + m_view->count()), + i18n("Are you sure you want to close the window?"), + KStandardGuiItem::quit(), + KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")), + KStandardGuiItem::cancel(), + "confirmClosingMultipleTabs" + ); + + switch (answer) + { + case KMessageBox::Yes: + // Quit + return true; + + case KMessageBox::No: + // Close only the current tab + m_view->closeTab(); + + default: + return false; + } + } + return true; +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 55e3f8cf..1f6c6931 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -100,6 +100,8 @@ public slots: void printRequested(QWebFrame *frame = 0); + void updateActions(); + signals: // switching tabs void ctrlTabPressed(); @@ -113,10 +115,11 @@ protected: */ void keyPressEvent(QKeyEvent *event); + bool queryClose(); + private slots: void postLaunch(); void browserLoading(bool); - void updateActions(); void updateWindowTitle(const QString &title = QString()); // history related diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index 4313d569..21e3fe9c 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -76,6 +76,8 @@ UrlResolver::UrlResolver(const QString &typedUrl) QString protocol = "^(http://|https://|file://|ftp://)"; + QString local = "^/"; + QString ipv4 = "^0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"\ "\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"; @@ -89,7 +91,7 @@ UrlResolver::UrlResolver(const QString &typedUrl) "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ "pro)"; - _browseRegexp = QRegExp("(" + protocol + ")|(" + address + ")|(" + ipv6 + ")|(" + ipv4 +")"); + _browseRegexp = QRegExp("(" + protocol + ")|(" + local + ")|(" + address + ")|(" + ipv6 + ")|(" + ipv4 +")"); } } diff --git a/src/webinspectorpanel.cpp b/src/webinspectorpanel.cpp index 31833ea9..3d1a5a1e 100644 --- a/src/webinspectorpanel.cpp +++ b/src/webinspectorpanel.cpp @@ -42,9 +42,9 @@ WebInspectorPanel::WebInspectorPanel(QString title, QWidget *parent) : QDockWidget(title, parent) + , _inspector(0) { setObjectName("webInspectorDock"); - setWidget(new QWebInspector(this)); } @@ -55,31 +55,34 @@ void WebInspectorPanel::closeEvent(QCloseEvent *event) } -MainWindow* WebInspectorPanel::mainWindow() -{ - return qobject_cast< MainWindow* >(parentWidget()); -} - - void WebInspectorPanel::toggle(bool enable) { - mainWindow()->actionByName("web_inspector")->setChecked(enable); + MainWindow *w = qobject_cast<MainWindow *>(parent()); + w->actionByName( QL1S("web_inspector") )->setChecked(enable); if (enable) { - mainWindow()->currentTab()->view()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); - findChild<QWebInspector *>()->setPage(mainWindow()->currentTab()->page()); + w->currentTab()->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); + if(!_inspector) + { + _inspector = new QWebInspector(this); + _inspector->setPage( w->currentTab()->page() ); + setWidget(_inspector); + } show(); } else { + w->currentTab()->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false); + delete _inspector; + _inspector = 0; hide(); - mainWindow()->currentTab()->view()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false); } } void WebInspectorPanel::changeCurrentPage() { - bool enable = mainWindow()->currentTab()->view()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled); + MainWindow *w = qobject_cast<MainWindow *>(parent()); + bool enable = w->currentTab()->page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled); toggle(enable); } diff --git a/src/webinspectorpanel.h b/src/webinspectorpanel.h index 8b1e3507..1f0ea06b 100644 --- a/src/webinspectorpanel.h +++ b/src/webinspectorpanel.h @@ -35,7 +35,11 @@ #include "mainwindow.h" // Qt Includes -#include <QDockWidget> +#include <QtGui/QDockWidget> + +// Forward +class QWebInspector; + /** Docked web inspector @@ -54,8 +58,7 @@ public slots: protected: virtual void closeEvent(QCloseEvent *event); - MainWindow *mainWindow(); - + QWebInspector *_inspector; }; #endif diff --git a/src/webpage.cpp b/src/webpage.cpp index 81486a32..9da75a91 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -44,6 +44,7 @@ #include "webpluginfactory.h" #include "networkaccessmanager.h" #include "adblockmanager.h" +#include "urlbar.h" #include "sslinfodialog_p.h" @@ -238,19 +239,56 @@ WebPage *WebPage::createWindow(QWebPage::WebWindowType type) void WebPage::handleUnsupportedContent(QNetworkReply *reply) { - // NOTE + Q_ASSERT (reply); + // NOTE: + // Until kio implements a way to resume/continue a network + // request. We must abort the reply to prevent a zombie process + // from continuing to download the unsupported content! + reply->abort(); + // This is probably needed just in ONE stupid case.. if (_protHandler.postHandling(reply->request(), mainFrame())) return; if (reply->error() == QNetworkReply::NoError) { - const KUrl url(reply->url()); - - QString mimeType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + KUrl replyUrl = reply->url(); + + // HACK ------------------------------------------- + QString mimeType; + QString suggestedFileName; + + QString app = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + QStringList headerList = app.split( ';' ); + + kDebug() << headerList; + kDebug() << headerList.count(); + + if(headerList.count() > 0) + { + mimeType = headerList.takeFirst().trimmed(); + Q_FOREACH(const QString &head, headerList) + { + if( head.contains( QL1S("name") ) ) + { + // this is not so sure.. :) + suggestedFileName = head; + suggestedFileName = suggestedFileName.remove( QL1S("name=") ); + suggestedFileName = suggestedFileName.remove( '"' ); + suggestedFileName = suggestedFileName.trimmed(); + break; + } + } + } + else + { + mimeType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + } + // ------------------------------------------------ + KService::Ptr appService = KMimeTypeTrader::self()->preferredService(mimeType); - bool isLocal = url.isLocalFile(); + bool isLocal = replyUrl.isLocalFile(); if (appService.isNull()) // no service can handle this. We can just download it.. { @@ -258,7 +296,7 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) isLocal ? KMessageBox::sorry(view(), i18n("No service can handle this :(")) - : downloadRequest(reply->request()); + : downloadThings(reply->request(), suggestedFileName); return; } @@ -266,12 +304,15 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) if (!isLocal) { - KParts::BrowserOpenOrSaveQuestion dlg(Application::instance()->mainWindow(), url, mimeType); + KParts::BrowserOpenOrSaveQuestion dlg(Application::instance()->mainWindow(), replyUrl, mimeType); + if(!suggestedFileName.isEmpty()) + dlg.setSuggestedFileName(suggestedFileName); + switch (dlg.askEmbedOrSave()) { case KParts::BrowserOpenOrSaveQuestion::Save: kDebug() << "service handling: download!"; - downloadRequest(reply->request()); + downloadThings(reply->request(), suggestedFileName); return; case KParts::BrowserOpenOrSaveQuestion::Cancel: @@ -286,30 +327,34 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) KService::List partServices = KMimeTypeTrader::self()->query(mimeType, QL1S("KParts/ReadOnlyPart")); if (partServices.count() > 0) { + QString p = replyUrl.pathOrUrl(); + // A part can handle this. Embed it! QString html; html += "<html>"; html += "<head>"; html += "<title>"; - html += url.pathOrUrl(); + html += p; html += "</title>"; html += "<style type=\"text/css\">"; html += "* { border: 0; padding: 0; margin: 0; }"; html += "</style>"; html += "</head>"; html += "<body>"; - html += "<embed src=\"" + url.pathOrUrl() + "\" width=\"100%\" height=\"100%\" />"; + html += "<object type=\"" + mimeType + "\" data=\"" + p + "\" width=\"100%\" height=\"100%\" />"; html += "</body>"; html += "</html>"; - mainFrame()->setHtml(html); + mainFrame()->setHtml(html); _isOnRekonqPage = true; kDebug() << "EMBED true"; + Application::instance()->mainWindow()->mainView()->urlBar()->setQUrl(replyUrl); + Application::instance()->mainWindow()->updateActions(); } else { // No parts, just app services. Load it! - KRun::run(*appService, url, 0); + KRun::run(*appService, replyUrl, 0); } return; @@ -446,15 +491,28 @@ QString WebPage::errorPage(QNetworkReply *reply) // this code is actually copied from KWebPage::downloadRequest to save // downloads data before. If you have some better ideas about, // feel free to let us know about :) -void WebPage::downloadRequest(const QNetworkRequest &request) +void WebPage::downloadThings(const QNetworkRequest &request, const QString &suggestedFileName) { KUrl destUrl; KUrl srcUrl(request.url()); + + if( !ReKonfig::kgetDownload() && suggestedFileName.isEmpty() ) + { + kDebug() << "Using KWebPage downloadRequest.."; + Application::historyManager()->addDownload(srcUrl.pathOrUrl() , destUrl.pathOrUrl()); + KWebPage::downloadRequest(request); + return; + } + int result = KIO::R_OVERWRITE; do { - destUrl = KFileDialog::getSaveFileName(srcUrl.fileName(), QString(), view()); + QString fName = suggestedFileName.isEmpty() + ? srcUrl.fileName() + : suggestedFileName; + + destUrl = KFileDialog::getSaveFileName(fName, QString(), view()); if (destUrl.isLocalFile()) { diff --git a/src/webpage.h b/src/webpage.h index 9b2243bc..eff4c3fc 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -67,7 +67,6 @@ public: inline void setIsOnRekonqPage(bool b) { _isOnRekonqPage = b; }; public slots: - virtual void downloadRequest(const QNetworkRequest &request); void downloadAllContentsWithKGet(QPoint); protected: @@ -84,7 +83,15 @@ private slots: void showSSLInfo(QPoint); void updateImage(bool ok); -private: + /** + * This new slot is needed to provide integration between rekonq & KGet, + * to better manage file names and to not overwrite KWebPage default behavior on need + * + * @see KWebPage::downloadRequest. + */ + void downloadThings(const QNetworkRequest &request, const QString &suggestedFileName = QString()); + +private: QString errorPage(QNetworkReply *reply); QUrl _loadingUrl; diff --git a/src/webview.cpp b/src/webview.cpp index e7226740..1996d6af 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -76,14 +76,11 @@ WebView::WebView(QWidget* parent) setPage(page); // download system - connect(this, SIGNAL(linkShiftClicked(const KUrl &)), - page, SLOT(downloadUrl(const KUrl &))); - connect(page, SIGNAL(downloadRequested(const QNetworkRequest &)), - page, SLOT(downloadRequest(const QNetworkRequest &))); + connect(this, SIGNAL(linkShiftClicked(const KUrl &)), page, SLOT(downloadUrl(const KUrl &))); + connect(page, SIGNAL(downloadRequested(const QNetworkRequest &)), page, SLOT(downloadThings(const QNetworkRequest &))); // middle click || ctrl + click signal - connect(this, SIGNAL(linkMiddleOrCtrlClicked(const KUrl &)), - this, SLOT(loadUrlInNewTab(const KUrl &))); + connect(this, SIGNAL(linkMiddleOrCtrlClicked(const KUrl &)), this, SLOT(loadUrlInNewTab(const KUrl &))); // loadUrl signal connect(this, SIGNAL(loadUrl(const KUrl &, const Rekonq::OpenType &)), |