diff --git a/src/lib/lib.pro b/src/lib/lib.pro index 3e1e97d6b..85a71c030 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -169,7 +169,6 @@ SOURCES += \ bookmarks/bookmarksimport/bookmarksimportdialog.cpp \ tools/iconfetcher.cpp \ tools/followredirectreply.cpp \ - webview/webhistorywrapper.cpp \ tools/pagethumbnailer.cpp \ plugins/speeddial.cpp \ tools/enhancedmenu.cpp \ @@ -369,7 +368,6 @@ HEADERS += \ bookmarks/bookmarksimport/bookmarksimportdialog.h \ tools/iconfetcher.h \ tools/followredirectreply.h \ - webview/webhistorywrapper.h \ tools/pagethumbnailer.h \ plugins/speeddial.h \ tools/enhancedmenu.h \ diff --git a/src/lib/navigation/navigationbar.cpp b/src/lib/navigation/navigationbar.cpp index 6426195bf..4c6177ea8 100644 --- a/src/lib/navigation/navigationbar.cpp +++ b/src/lib/navigation/navigationbar.cpp @@ -22,12 +22,12 @@ #include "iconprovider.h" #include "websearchbar.h" #include "reloadstopbutton.h" -#include "webhistorywrapper.h" #include "enhancedmenu.h" #include "tabwidget.h" #include "tabbedwebview.h" #include "webpage.h" #include "qzsettings.h" +#include "qztools.h" #include #include @@ -37,31 +37,7 @@ #include #include -QString NavigationBar::titleForUrl(QString title, const QUrl &url) -{ - if (title.isEmpty()) { - title = url.toString(QUrl::RemoveFragment); - } - if (title.isEmpty()) { - return NavigationBar::tr("No Named Page"); - } - if (title.length() > 40) { - title.truncate(40); - title += ".."; - } - - return title; -} - -QIcon NavigationBar::iconForPage(const QUrl &url, const QIcon &sIcon) -{ - QIcon icon; - icon.addPixmap(url.scheme() == QLatin1String("qupzilla") ? QIcon(":icons/qupzilla.png").pixmap(16, 16) : IconProvider::iconForUrl(url).pixmap(16, 16)); - icon.addPixmap(sIcon.pixmap(16, 16), QIcon::Active); - return icon; -} - -static inline void setButtonIconSize(ToolButton* button) +static void setButtonIconSize(ToolButton* button) { QStyleOption opt; opt.initFrom(button); @@ -266,8 +242,8 @@ void NavigationBar::aboutToShowHistoryBackMenu() const QIcon icon = iconForPage(item.url(), IconProvider::standardIcon(QStyle::SP_ArrowBack)); Action* act = new Action(icon, title); act->setData(i); - connect(act, SIGNAL(triggered()), this, SLOT(goAtHistoryIndex())); - connect(act, SIGNAL(ctrlTriggered()), this, SLOT(goAtHistoryIndexInNewTab())); + connect(act, SIGNAL(triggered()), this, SLOT(loadHistoryIndex())); + connect(act, SIGNAL(ctrlTriggered()), this, SLOT(loadHistoryIndexInNewTab())); m_menuBack->addAction(act); } @@ -300,8 +276,8 @@ void NavigationBar::aboutToShowHistoryNextMenu() const QIcon icon = iconForPage(item.url(), IconProvider::standardIcon(QStyle::SP_ArrowForward)); Action* act = new Action(icon, title); act->setData(i); - connect(act, SIGNAL(triggered()), this, SLOT(goAtHistoryIndex())); - connect(act, SIGNAL(ctrlTriggered()), this, SLOT(goAtHistoryIndexInNewTab())); + connect(act, SIGNAL(triggered()), this, SLOT(loadHistoryIndex())); + connect(act, SIGNAL(ctrlTriggered()), this, SLOT(loadHistoryIndexInNewTab())); m_menuForward->addAction(act); } @@ -329,18 +305,16 @@ void NavigationBar::contextMenuRequested(const QPoint &pos) menu.exec(mapToGlobal(pos)); } -void NavigationBar::goAtHistoryIndex() +void NavigationBar::loadHistoryIndex() { QWebHistory* history = m_window->weView()->page()->history(); if (QAction* action = qobject_cast(sender())) { - history->goToItem(history->itemAt(action->data().toInt())); + loadHistoryItem(history->itemAt(action->data().toInt())); } - - refreshHistory(); } -void NavigationBar::goAtHistoryIndexInNewTab(int index) +void NavigationBar::loadHistoryIndexInNewTab(int index) { if (QAction* action = qobject_cast(sender())) { index = action->data().toInt(); @@ -350,15 +324,8 @@ void NavigationBar::goAtHistoryIndexInNewTab(int index) return; } - TabWidget* tabWidget = m_window->tabWidget(); - int tabIndex = tabWidget->duplicateTab(tabWidget->currentIndex()); - - QWebHistory* history = m_window->weView(tabIndex)->page()->history(); - history->goToItem(history->itemAt(index)); - - if (qzSettings->newTabPosition == Qz::NT_SelectedTab) { - tabWidget->setCurrentIndex(tabIndex); - } + QWebHistory* history = m_window->weView()->page()->history(); + loadHistoryItemInNewTab(history->itemAt(index)); } void NavigationBar::refreshHistory() @@ -396,12 +363,7 @@ void NavigationBar::goBackInNewTab() return; } - int itemIndex = WebHistoryWrapper::indexOfItem(history->items(), history->backItem()); - if (itemIndex == -1) { - return; - } - - goAtHistoryIndexInNewTab(itemIndex); + loadHistoryItemInNewTab(history->backItem()); } void NavigationBar::goForward() @@ -418,10 +380,47 @@ void NavigationBar::goForwardInNewTab() return; } - int itemIndex = WebHistoryWrapper::indexOfItem(history->items(), history->forwardItem()); - if (itemIndex == -1) { - return; + loadHistoryItemInNewTab(history->forwardItem()); +} + +QString NavigationBar::titleForUrl(QString title, const QUrl &url) +{ + if (title.isEmpty()) { + title = url.toString(QUrl::RemoveFragment); + } + + if (title.isEmpty()) { + return tr("No Named Page"); + } + + return QzTools::truncatedText(title, 40); +} + +QIcon NavigationBar::iconForPage(const QUrl &url, const QIcon &sIcon) +{ + QIcon icon; + icon.addPixmap(url.scheme() == QL1S("qupzilla") ? QIcon(QSL(":icons/qupzilla.png")).pixmap(16, 16) : IconProvider::iconForUrl(url).pixmap(16, 16)); + icon.addPixmap(sIcon.pixmap(16, 16), QIcon::Active); + return icon; +} + +void NavigationBar::loadHistoryItem(const QWebHistoryItem &item) +{ + m_window->weView()->page()->history()->goToItem(item); + + refreshHistory(); +} + +void NavigationBar::loadHistoryItemInNewTab(const QWebHistoryItem &item) +{ + TabWidget* tabWidget = m_window->tabWidget(); + int tabIndex = tabWidget->duplicateTab(tabWidget->currentIndex()); + + QWebHistory* history = m_window->weView(tabIndex)->page()->history(); + history->goToItem(item); + + if (qzSettings->newTabPosition == Qz::NT_SelectedTab) { + tabWidget->setCurrentIndex(tabIndex); } - goAtHistoryIndexInNewTab(itemIndex); } diff --git a/src/lib/navigation/navigationbar.h b/src/lib/navigation/navigationbar.h index 7378cc864..c337e70ed 100644 --- a/src/lib/navigation/navigationbar.h +++ b/src/lib/navigation/navigationbar.h @@ -24,6 +24,7 @@ class QHBoxLayout; class QSplitter; +class QWebHistoryItem; class ToolButton; class WebSearchBar; @@ -79,8 +80,8 @@ private slots: void aboutToShowHistoryNextMenu(); void aboutToShowHistoryBackMenu(); - void goAtHistoryIndex(); - void goAtHistoryIndexInNewTab(int index = -1); + void loadHistoryIndex(); + void loadHistoryIndexInNewTab(int index = -1); void clearHistory(); void contextMenuRequested(const QPoint &pos); @@ -89,6 +90,9 @@ private: QString titleForUrl(QString title, const QUrl &url); QIcon iconForPage(const QUrl &url, const QIcon &sIcon); + void loadHistoryItem(const QWebHistoryItem &item); + void loadHistoryItemInNewTab(const QWebHistoryItem &item); + BrowserWindow* m_window; QHBoxLayout* m_layout; diff --git a/src/lib/webview/webhistorywrapper.cpp b/src/lib/webview/webhistorywrapper.cpp deleted file mode 100644 index ef2ecd77e..000000000 --- a/src/lib/webview/webhistorywrapper.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#include "webhistorywrapper.h" - -#include -#include -#include - -QList WebHistoryWrapper::forwardItems(int maxItems, QWebHistory* history) -{ - QList list; - QUrl lastUrl = history->currentItem().url(); - - int count = 0; - foreach (const QWebHistoryItem &item, history->forwardItems(maxItems + 5)) { - if (item.url() == lastUrl || count == maxItems) { - continue; - } - - lastUrl = item.url(); - list.append(item); - count++; - } - - return list; -} - -QList WebHistoryWrapper::backItems(int maxItems, QWebHistory* history) -{ - QList list; - QUrl lastUrl = history->currentItem().url(); - - int count = 0; - QList bItems = history->backItems(maxItems + 5); - for (int i = bItems.count() - 1; i >= 0; i--) { - QWebHistoryItem item = bItems.at(i); - if (item.url() == lastUrl || count == maxItems) { - continue; - } - - lastUrl = item.url(); - list.append(item); - count++; - } - - return list; -} - -bool WebHistoryWrapper::canGoForward(QWebHistory* history) -{ - return !forwardItems(1, history).isEmpty(); -} - -bool WebHistoryWrapper::canGoBack(QWebHistory* history) -{ - return !backItems(1, history).isEmpty(); -} - -void WebHistoryWrapper::goBack(QWebHistory* history) -{ - QList items = backItems(1, history); - - if (items.isEmpty()) { - return; - } - - history->goToItem(items.at(0)); -} - -void WebHistoryWrapper::goForward(QWebHistory* history) -{ - QList items = forwardItems(1, history); - - if (items.isEmpty()) { - return; - } - - history->goToItem(items.at(0)); -} - -int WebHistoryWrapper::indexOfItem(const QList &list, const QWebHistoryItem &item) -{ - for (int i = 0; i < list.count(); i++) { - QWebHistoryItem it = list.at(i); - - if (it.lastVisited() == item.lastVisited() && - it.originalUrl() == item.originalUrl() && - it.title() == item.title() && - it.url() == item.url()) { - return i; - } - } - - return -1; -} diff --git a/src/lib/webview/webhistorywrapper.h b/src/lib/webview/webhistorywrapper.h deleted file mode 100644 index b1041aec0..000000000 --- a/src/lib/webview/webhistorywrapper.h +++ /dev/null @@ -1,43 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#ifndef WEBHISTORYWRAPPER_H -#define WEBHISTORYWRAPPER_H - -#include - -#include "qzcommon.h" - -class QWebHistory; -class QWebHistoryItem; - -class WebHistoryWrapper -{ -public: - static QList forwardItems(int maxItems, QWebHistory* history); - static QList backItems(int maxItems, QWebHistory* history); - - static bool canGoForward(QWebHistory* history); - static bool canGoBack(QWebHistory* history); - - static void goBack(QWebHistory* history); - static void goForward(QWebHistory* history); - - static int indexOfItem(const QList &list, const QWebHistoryItem &item); -}; - -#endif // WEBHISTORYWRAPPER_H