File indexing completed on 2024-05-12 04:58:21
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "historysidebar.h" 0019 #include "ui_historysidebar.h" 0020 #include "browserwindow.h" 0021 #include "tabwidget.h" 0022 #include "tabbedwebview.h" 0023 #include "mainapplication.h" 0024 #include "qzsettings.h" 0025 #include "iconprovider.h" 0026 0027 HistorySideBar::HistorySideBar(BrowserWindow* window, QWidget* parent) 0028 : QWidget(parent) 0029 , ui(new Ui::HistorySideBar) 0030 , m_window(window) 0031 { 0032 ui->setupUi(this); 0033 ui->historyTree->setViewType(HistoryTreeView::HistorySidebarViewType); 0034 0035 connect(ui->historyTree, &HistoryTreeView::urlActivated, this, &HistorySideBar::urlActivated); 0036 connect(ui->historyTree, &HistoryTreeView::urlCtrlActivated, this, &HistorySideBar::urlCtrlActivated); 0037 connect(ui->historyTree, &HistoryTreeView::urlShiftActivated, this, &HistorySideBar::urlShiftActivated); 0038 connect(ui->historyTree, &HistoryTreeView::contextMenuRequested, this, &HistorySideBar::createContextMenu); 0039 0040 connect(ui->search, &QLineEdit::textEdited, ui->historyTree, &HistoryTreeView::search); 0041 } 0042 0043 void HistorySideBar::urlActivated(const QUrl &url) 0044 { 0045 openUrl(url); 0046 } 0047 0048 void HistorySideBar::urlCtrlActivated(const QUrl &url) 0049 { 0050 openUrlInNewTab(url); 0051 } 0052 0053 void HistorySideBar::urlShiftActivated(const QUrl &url) 0054 { 0055 openUrlInNewWindow(url); 0056 } 0057 0058 void HistorySideBar::openUrl(const QUrl &url) 0059 { 0060 const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl(); 0061 m_window->weView()->load(u); 0062 } 0063 0064 void HistorySideBar::openUrlInNewTab(const QUrl &url) 0065 { 0066 const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl(); 0067 m_window->tabWidget()->addView(u, qzSettings->newTabPosition); 0068 } 0069 0070 void HistorySideBar::openUrlInNewWindow(const QUrl &url) 0071 { 0072 const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl(); 0073 mApp->createWindow(Qz::BW_NewWindow, u); 0074 } 0075 0076 void HistorySideBar::openUrlInNewPrivateWindow(const QUrl &url) 0077 { 0078 const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl(); 0079 mApp->startPrivateBrowsing(u); 0080 } 0081 0082 void HistorySideBar::createContextMenu(const QPoint &pos) 0083 { 0084 QMenu menu; 0085 QAction* actNewTab = menu.addAction(IconProvider::newTabIcon(), tr("Open in new tab")); 0086 QAction* actNewWindow = menu.addAction(IconProvider::newWindowIcon(), tr("Open in new window")); 0087 QAction* actNewPrivateWindow = menu.addAction(IconProvider::privateBrowsingIcon(), tr("Open in new private window")); 0088 0089 menu.addSeparator(); 0090 QAction* actDelete = menu.addAction(QIcon::fromTheme(QSL("edit-delete")), tr("Delete")); 0091 0092 connect(actNewTab, SIGNAL(triggered()), this, SLOT(openUrlInNewTab())); 0093 connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openUrlInNewWindow())); 0094 connect(actNewPrivateWindow, SIGNAL(triggered()), this, SLOT(openUrlInNewPrivateWindow())); 0095 connect(actDelete, &QAction::triggered, ui->historyTree, &HistoryTreeView::removeSelectedItems); 0096 0097 if (ui->historyTree->selectedUrl().isEmpty()) { 0098 actNewTab->setDisabled(true); 0099 actNewWindow->setDisabled(true); 0100 actNewPrivateWindow->setDisabled(true); 0101 } 0102 0103 menu.exec(pos); 0104 } 0105 0106 void HistorySideBar::showEvent(QShowEvent *event) 0107 { 0108 QWidget::showEvent(event); 0109 ui->search->setFocus(); 0110 } 0111 0112 HistorySideBar::~HistorySideBar() 0113 { 0114 delete ui; 0115 }