[WebHistoryWrapper] Removed unused WebHistoryWrapper class

remotes/origin/falkon
nowrep 12 years ago
parent 0b4be9055e
commit db2d879717
  1. 2
      src/lib/lib.pro
  2. 107
      src/lib/navigation/navigationbar.cpp
  3. 8
      src/lib/navigation/navigationbar.h
  4. 110
      src/lib/webview/webhistorywrapper.cpp
  5. 43
      src/lib/webview/webhistorywrapper.h

@ -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 \

@ -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 <QTimer>
#include <QSplitter>
@ -37,31 +37,7 @@
#include <QMouseEvent>
#include <QStyleOption>
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<QAction*>(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<QAction*>(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);
}

@ -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;

@ -1,110 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "webhistorywrapper.h"
#include <QUrl>
#include <QVariant>
#include <QWebHistory>
QList<QWebHistoryItem> WebHistoryWrapper::forwardItems(int maxItems, QWebHistory* history)
{
QList<QWebHistoryItem> 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<QWebHistoryItem> WebHistoryWrapper::backItems(int maxItems, QWebHistory* history)
{
QList<QWebHistoryItem> list;
QUrl lastUrl = history->currentItem().url();
int count = 0;
QList<QWebHistoryItem> 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<QWebHistoryItem> items = backItems(1, history);
if (items.isEmpty()) {
return;
}
history->goToItem(items.at(0));
}
void WebHistoryWrapper::goForward(QWebHistory* history)
{
QList<QWebHistoryItem> items = forwardItems(1, history);
if (items.isEmpty()) {
return;
}
history->goToItem(items.at(0));
}
int WebHistoryWrapper::indexOfItem(const QList<QWebHistoryItem> &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;
}

@ -1,43 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef WEBHISTORYWRAPPER_H
#define WEBHISTORYWRAPPER_H
#include <QList>
#include "qzcommon.h"
class QWebHistory;
class QWebHistoryItem;
class WebHistoryWrapper
{
public:
static QList<QWebHistoryItem> forwardItems(int maxItems, QWebHistory* history);
static QList<QWebHistoryItem> 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<QWebHistoryItem> &list, const QWebHistoryItem &item);
};
#endif // WEBHISTORYWRAPPER_H
Loading…
Cancel
Save