summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.cpp96
-rw-r--r--src/mainwindow.h3
-rw-r--r--src/webpage.cpp65
3 files changed, 116 insertions, 48 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 1488980f..efc6e3c7 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())
+ {
+ item = new QWebHistoryItem(history->currentItem());
+ currentTab()->view()->page()->setIsOnRekonqPage(false);
+ }
+ else
{
- QWebHistoryItem *item;
- if (currentTab()->view()->page()->isOnRekonqPage())
+ 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();
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 55e3f8cf..d8f6114f 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();
@@ -116,7 +118,6 @@ protected:
private slots:
void postLaunch();
void browserLoading(bool);
- void updateActions();
void updateWindowTitle(const QString &title = QString());
// history related
diff --git a/src/webpage.cpp b/src/webpage.cpp
index 81486a32..b0397870 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..
{
@@ -266,7 +304,10 @@ 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:
@@ -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;