From 48d0fb17f8349dbc1c6de18bead2900ce3c2a791 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 11 Jan 2010 11:44:38 +0100 Subject: History (back) menu fixed! Finally.. --- src/mainwindow.cpp | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8ad53315..9352ec36 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1110,20 +1110,23 @@ void MainWindow::aboutToShowBackMenu() if (!currentTab()) return; QWebHistory *history = currentTab()->view()->history(); - int historyCount = history->count(); + int pivot = history->currentItemIndex(); + int offset = 0; + QList historyList = history->backItems(8); //no more than 8 elements! + int listCount = historyList.count(); + if(pivot >= 8) + offset = pivot - 8; + - // Limit history views in the menu to 8 - if(historyCount > 8) - historyCount = 8; - for (int i = history->backItems(historyCount).count() - 1; i >= 0; --i) + for(int i = listCount - 1; i>=0; --i) { - QWebHistoryItem item = history->backItems(history->count()).at(i); + QWebHistoryItem item = historyList.at(i); KAction *action = new KAction(this); - action->setData( i - history->currentItemIndex() ); - QIcon icon = Application::icon(item.url()); - action->setIcon(icon); - action->setText(item.title()); + action->setData(i + offset); + QIcon icon = Application::icon( item.url() ); + action->setIcon( icon ); + action->setText( item.title() ); m_historyBackMenu->addAction(action); } } @@ -1131,24 +1134,14 @@ void MainWindow::aboutToShowBackMenu() void MainWindow::openActionUrl(QAction *action) { - int offset = action->data().toInt(); - QWebHistory *history = currentTab()->view()->history(); - - if(!history->itemAt(offset).isValid()) - { - kDebug() << "Invalid Offset!"; - return; - } - - if (offset < 0) + int index = action->data().toInt(); + + QWebHistory *history = currentTab()->view()->history(); + if(!history->itemAt(index).isValid()) { - history->goToItem(history->itemAt(offset)); // back + kDebug() << "Invalid Index!: "<< index; return; } - if (offset > 0) - { - history->goToItem(history->forwardItems(history->count() - offset).back()); // forward FIXME CRASH - } - + history->goToItem( history->itemAt(index) ); } -- cgit v1.2.1