2011-12-04 16:54:57 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-12-04 16:54:57 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-10-29 23:01:17 +02:00
|
|
|
#include "webhistorywrapper.h"
|
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QUrl>
|
2012-04-04 13:21:53 +02:00
|
|
|
#include <QVariant>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QWebHistory>
|
|
|
|
|
2011-10-29 23:01:17 +02:00
|
|
|
QList<QWebHistoryItem> WebHistoryWrapper::forwardItems(int maxItems, QWebHistory* history)
|
|
|
|
{
|
|
|
|
QList<QWebHistoryItem> list;
|
|
|
|
QUrl lastUrl = history->currentItem().url();
|
|
|
|
|
|
|
|
int count = 0;
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QWebHistoryItem &item, history->forwardItems(maxItems + 5)) {
|
2011-11-06 17:01:23 +01:00
|
|
|
if (item.url() == lastUrl || count == maxItems) {
|
2011-10-29 23:01:17 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-29 23:01:17 +02:00
|
|
|
|
|
|
|
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);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (item.url() == lastUrl || count == maxItems) {
|
2011-10-29 23:01:17 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-29 23:01:17 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (items.isEmpty()) {
|
2011-10-29 23:01:17 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-29 23:01:17 +02:00
|
|
|
|
|
|
|
history->goToItem(items.at(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebHistoryWrapper::goForward(QWebHistory* history)
|
|
|
|
{
|
|
|
|
QList<QWebHistoryItem> items = forwardItems(1, history);
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (items.isEmpty()) {
|
2011-10-29 23:01:17 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-29 23:01:17 +02:00
|
|
|
|
|
|
|
history->goToItem(items.at(0));
|
|
|
|
}
|
2011-12-12 18:30:08 +01:00
|
|
|
|
|
|
|
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() &&
|
2011-12-12 21:14:43 +01:00
|
|
|
it.originalUrl() == item.originalUrl() &&
|
|
|
|
it.title() == item.title() &&
|
|
|
|
it.url() == item.url()) {
|
2011-12-12 18:30:08 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|