1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-22 18:22:10 +02:00
falkonOfficial/src/lib/history/historymanager.cpp

113 lines
3.2 KiB
C++
Raw Normal View History

2011-03-03 18:29:20 +01:00
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
2011-03-03 18:29:20 +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-03-02 16:57:41 +01:00
#include "historymanager.h"
#include "ui_historymanager.h"
#include "qupzilla.h"
#include "mainapplication.h"
#include "history.h"
#include "browsinglibrary.h"
#include "tabwidget.h"
#include "tabbedwebview.h"
#include "historymodel.h"
#include "headerview.h"
#include "qzsettings.h"
2011-03-02 16:57:41 +01:00
#include <QMessageBox>
HistoryManager::HistoryManager(QupZilla* mainClass, QWidget* parent)
: QWidget(parent)
, ui(new Ui::HistoryManager)
, p_QupZilla(mainClass)
2011-03-02 16:57:41 +01:00
{
ui->setupUi(this);
connect(ui->historyTree, SIGNAL(openLink(QUrl,HistoryView::OpenBehavior)), this, SLOT(openLink(QUrl,HistoryView::OpenBehavior)));
connect(ui->deleteB, SIGNAL(clicked()), ui->historyTree, SLOT(removeItems()));
2011-03-02 16:57:41 +01:00
connect(ui->clearAll, SIGNAL(clicked()), this, SLOT(clearHistory()));
connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb()));
ui->historyTree->setFocus();
2011-03-02 16:57:41 +01:00
}
QupZilla* HistoryManager::getQupZilla()
{
if (!p_QupZilla) {
2011-03-04 13:59:07 +01:00
p_QupZilla = mApp->getWindow();
}
return p_QupZilla.data();
2011-03-02 16:57:41 +01:00
}
2011-03-17 17:03:04 +01:00
void HistoryManager::setMainWindow(QupZilla* window)
2011-03-02 16:57:41 +01:00
{
if (window) {
2011-03-02 16:57:41 +01:00
p_QupZilla = window;
}
2011-03-02 16:57:41 +01:00
}
void HistoryManager::restoreState(const QByteArray &state)
{
ui->historyTree->header()->restoreState(state);
2011-03-02 16:57:41 +01:00
}
QByteArray HistoryManager::saveState()
2011-07-31 13:33:44 +02:00
{
return ui->historyTree->header()->saveState();
2011-07-31 13:33:44 +02:00
}
2011-03-02 16:57:41 +01:00
void HistoryManager::clearHistory()
{
QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Confirmation"),
tr("Are you sure to delete all history?"), QMessageBox::Yes | QMessageBox::No);
if (button != QMessageBox::Yes) {
2011-03-02 16:57:41 +01:00
return;
}
2011-03-02 16:57:41 +01:00
mApp->history()->clearHistory();
mApp->history()->optimizeHistory();
2011-03-02 16:57:41 +01:00
}
void HistoryManager::search(const QString &searchText)
2011-03-02 16:57:41 +01:00
{
ui->historyTree->filterModel()->setFilterFixedString(searchText);
}
void HistoryManager::openLink(const QUrl &url, HistoryView::OpenBehavior openIn)
{
if (openIn == HistoryView::OpenInNewTab) {
getQupZilla()->tabWidget()->addView(url, qzSettings->newTabPosition);
}
else {
getQupZilla()->weView()->load(url);
2011-03-02 16:57:41 +01:00
}
}
void HistoryManager::optimizeDb()
{
BrowsingLibrary* b = qobject_cast<BrowsingLibrary*>(parentWidget()->parentWidget());
if (!b) {
return;
}
b->optimizeDatabase();
}
2011-03-02 16:57:41 +01:00
HistoryManager::~HistoryManager()
{
delete ui;
}