2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 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"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "mainapplication.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "history.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "tabbedwebview.h"
|
|
|
|
#include "headerview.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2014-05-03 15:08:47 +02:00
|
|
|
#include "iconprovider.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMessageBox>
|
2014-05-03 15:08:47 +02:00
|
|
|
#include <QClipboard>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
HistoryManager::HistoryManager(BrowserWindow* window, QWidget* parent)
|
2011-10-20 17:56:01 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::HistoryManager)
|
2014-02-19 22:07:21 +01:00
|
|
|
, m_window(window)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-05-03 15:08:47 +02:00
|
|
|
ui->historyTree->setViewType(HistoryTreeView::HistoryManagerViewType);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-05-03 15:08:47 +02:00
|
|
|
connect(ui->historyTree, SIGNAL(urlActivated(QUrl)), this, SLOT(urlActivated(QUrl)));
|
|
|
|
connect(ui->historyTree, SIGNAL(urlCtrlActivated(QUrl)), this, SLOT(urlCtrlActivated(QUrl)));
|
|
|
|
connect(ui->historyTree, SIGNAL(urlShiftActivated(QUrl)), this, SLOT(urlShiftActivated(QUrl)));
|
|
|
|
connect(ui->historyTree, SIGNAL(contextMenuRequested(QPoint)), this, SLOT(createContextMenu(QPoint)));
|
2011-10-18 21:07:58 +02:00
|
|
|
|
2014-05-03 15:08:47 +02:00
|
|
|
connect(ui->deleteB, SIGNAL(clicked()), ui->historyTree, SLOT(removeSelectedItems()));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(ui->clearAll, SIGNAL(clicked()), this, SLOT(clearHistory()));
|
2011-07-30 17:57:14 +02:00
|
|
|
|
2011-07-29 15:39:43 +02:00
|
|
|
ui->historyTree->setFocus();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-05-03 15:08:47 +02:00
|
|
|
BrowserWindow* HistoryManager::getWindow()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-05-03 15:08:47 +02:00
|
|
|
if (!m_window)
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window = mApp->getWindow();
|
|
|
|
return m_window.data();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
void HistoryManager::setMainWindow(BrowserWindow* window)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (window) {
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window = window;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
void HistoryManager::restoreState(const QByteArray &state)
|
2011-04-25 20:56:45 +02:00
|
|
|
{
|
2012-04-30 16:33:14 +02:00
|
|
|
ui->historyTree->header()->restoreState(state);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
QByteArray HistoryManager::saveState()
|
2011-07-31 13:33:44 +02:00
|
|
|
{
|
2012-04-30 16:33:14 +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"),
|
2011-11-06 17:01:23 +01:00
|
|
|
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-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
mApp->history()->clearHistory();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
void HistoryManager::search(const QString &searchText)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-05-03 15:08:47 +02:00
|
|
|
ui->historyTree->search(searchText);
|
2012-02-13 16:59:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-03 15:08:47 +02:00
|
|
|
void HistoryManager::urlActivated(const QUrl &url)
|
2012-02-13 16:59:30 +01:00
|
|
|
{
|
2014-05-03 15:08:47 +02:00
|
|
|
openUrl(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::urlCtrlActivated(const QUrl &url)
|
|
|
|
{
|
|
|
|
openUrlInNewTab(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::urlShiftActivated(const QUrl &url)
|
|
|
|
{
|
|
|
|
openUrlInNewWindow(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::openUrl(const QUrl &url)
|
|
|
|
{
|
|
|
|
const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl();
|
|
|
|
m_window->weView()->load(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::openUrlInNewTab(const QUrl &url)
|
|
|
|
{
|
|
|
|
const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl();
|
|
|
|
m_window->tabWidget()->addView(u, qzSettings->newTabPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::openUrlInNewWindow(const QUrl &url)
|
|
|
|
{
|
|
|
|
const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl();
|
|
|
|
mApp->createWindow(Qz::BW_NewWindow, u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::openUrlInNewPrivateWindow(const QUrl &url)
|
|
|
|
{
|
|
|
|
const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl();
|
|
|
|
mApp->startPrivateBrowsing(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::createContextMenu(const QPoint &pos)
|
|
|
|
{
|
|
|
|
QMenu menu;
|
|
|
|
QAction* actNewTab = menu.addAction(IconProvider::newTabIcon(), tr("Open in new tab"));
|
|
|
|
QAction* actNewWindow = menu.addAction(IconProvider::newWindowIcon(), tr("Open in new window"));
|
|
|
|
QAction* actNewPrivateWindow = menu.addAction(IconProvider::privateBrowsingIcon(), tr("Open in new private window"));
|
|
|
|
|
|
|
|
menu.addSeparator();
|
|
|
|
QAction* actCopyUrl = menu.addAction(tr("Copy url"), this, SLOT(copyUrl()));
|
|
|
|
QAction* actCopyTitle = menu.addAction(tr("Copy title"), this, SLOT(copyTitle()));
|
|
|
|
|
|
|
|
menu.addSeparator();
|
|
|
|
QAction* actDelete = menu.addAction(QIcon::fromTheme(QSL("edit-delete")), tr("Delete"));
|
|
|
|
|
|
|
|
connect(actNewTab, SIGNAL(triggered()), this, SLOT(openUrlInNewTab()));
|
|
|
|
connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openUrlInNewWindow()));
|
|
|
|
connect(actNewPrivateWindow, SIGNAL(triggered()), this, SLOT(openUrlInNewPrivateWindow()));
|
|
|
|
connect(actDelete, SIGNAL(triggered()), ui->historyTree, SLOT(removeSelectedItems()));
|
|
|
|
|
|
|
|
if (ui->historyTree->selectedUrl().isEmpty()) {
|
|
|
|
actNewTab->setDisabled(true);
|
|
|
|
actNewWindow->setDisabled(true);
|
|
|
|
actNewPrivateWindow->setDisabled(true);
|
|
|
|
actCopyTitle->setDisabled(true);
|
|
|
|
actCopyUrl->setDisabled(true);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2014-05-03 15:08:47 +02:00
|
|
|
|
|
|
|
menu.exec(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::copyUrl()
|
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(ui->historyTree->selectedUrl().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryManager::copyTitle()
|
|
|
|
{
|
|
|
|
QApplication::clipboard()->setText(ui->historyTree->currentIndex().data().toString());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HistoryManager::~HistoryManager()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|