Hello,

here a patch that fix history navigation on error...

setHtml() doesn't udpate history, so when displaying an error message, 
backItem is in fact currentItem.

This patch workaround this saving error state.

There is a (commented and not tested) fix for back menu but there is something 
strange, currentItem in fact have error page title but backward page url... 
Seems to be a bug in qtwebkit, but i wan't to be sure that it's not rekonq 
that change historyItem title. Any idea ?

--
Cédric
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 128648b..20743a1 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1012,13 +1012,22 @@ void MainWindow::openPrevious(Qt::MouseButtons mouseButtons, Qt::KeyboardModifie
     QWebHistory *history = currentTab()->view()->history();
     if (history->canGoBack())
     {
+        QWebHistoryItem *item;
+	if (currentTab()->view()->page()->isOnErrorPage())
+        {
+            item = new QWebHistoryItem(history->currentItem());
+            currentTab()->view()->page()->setIsOnErrorPage(false);
+        }
+        else
+            item = new QWebHistoryItem(history->backItem());
+
         if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier)
         {
-            Application::instance()->loadUrl(history->backItem().url(), Rekonq::SettingOpenTab);
+            Application::instance()->loadUrl(item->url(), Rekonq::SettingOpenTab);
         }
         else
         {
-            history->goToItem(history->backItem());
+            history->goToItem(*item);
         }
 
         updateActions();
@@ -1032,13 +1041,22 @@ void MainWindow::openNext(Qt::MouseButtons mouseButtons, Qt::KeyboardModifiers k
     QWebHistory *history = currentTab()->view()->history();
     if (history->canGoForward())
     {
+        QWebHistoryItem *item;
+	if (currentTab()->view()->page()->isOnErrorPage())
+        {
+            item = new QWebHistoryItem(history->currentItem());
+            currentTab()->view()->page()->setIsOnErrorPage(false);
+        }
+        else
+            item = new QWebHistoryItem(history->forwardItem());
+
         if (mouseButtons == Qt::MidButton || keyboardModifiers == Qt::ControlModifier)
         {
-            Application::instance()->loadUrl(history->forwardItem().url(), Rekonq::SettingOpenTab);
+            Application::instance()->loadUrl(item->url(), Rekonq::SettingOpenTab);
         }
         else
         {
-            history->goToItem(history->forwardItem());
+            history->goToItem(*item);
         }
         updateActions();
     }
@@ -1249,6 +1267,22 @@ void MainWindow::aboutToShowBackMenu()
     if (pivot >= 8)
         offset = pivot - 8;
 
+    /*
+     * Need a bug report upstream. 
+     * Seems setHtml() do some garbage in history
+     * Here history->currentItem() have backItem url and currentItem (error page) title
+     *
+    if (currentTab()->view()->page()->isOnErrorPage())
+    {
+        QWebHistoryItem item = history->currentItem();
+        KAction *action = new KAction(this);
+        action->setData(listCount + offset++);
+        KIcon icon = Application::icon(item.url());
+        action->setIcon(icon);
+        action->setText(item.title());
+        m_historyBackMenu->addAction(action);
+    }*/
+         
     for (int i = listCount - 1; i >= 0; --i)
     {
         QWebHistoryItem item = historyList.at(i);
diff --git a/src/webpage.cpp b/src/webpage.cpp
index d266b25..06c7d2c 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -103,6 +103,9 @@ WebPage::WebPage(QWidget *parent)
         : KWebPage(parent, KWalletIntegration)
         , _networkAnalyzer(false)
 {
+    // ----- Error page
+    setIsOnErrorPage(false);
+
     // ----- handling unsupported content...
     setForwardUnsupportedContent(true);
     connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *)));
@@ -379,7 +382,10 @@ void WebPage::manageNetworkErrors(QNetworkReply *reply)
     case QNetworkReply::ProtocolInvalidOperationError:       // requested operation is invalid for this protocol
 
         if (reply->url() == _loadingUrl)
+        {
             mainFrame()->setHtml(errorPage(reply), reply->url());
+            _isOnErrorPage = true;
+        }
         break;
 
     default:
@@ -593,6 +599,18 @@ bool WebPage::hasNetworkAnalyzerEnabled() const
 }
 
 
+bool WebPage::isOnErrorPage()
+{
+    return _isOnErrorPage;
+}
+
+
+void WebPage::setIsOnErrorPage(bool is)
+{
+    _isOnErrorPage = is;
+}
+
+
 void WebPage::enableNetworkAnalyzer(bool b)
 {
     _networkAnalyzer = b;
diff --git a/src/webpage.h b/src/webpage.h
index 74695f3..21f6788 100644
--- a/src/webpage.h
+++ b/src/webpage.h
@@ -61,8 +61,10 @@ public:
     ~WebPage();
 
     bool hasNetworkAnalyzerEnabled() const;
+    bool isOnErrorPage();
+    void setIsOnErrorPage(bool);
     void enableNetworkAnalyzer(bool);
-    
+
 public slots:
     virtual void downloadRequest(const QNetworkRequest &request);
     void downloadAllContentsWithKGet(QPoint);
@@ -89,6 +91,7 @@ private:
     WebSslInfo _sslInfo;
     
     bool _networkAnalyzer;
+    bool _isOnErrorPage;
 };
 
 #endif
_______________________________________________
rekonq mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/rekonq

Reply via email to