mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
ClosedTabsManager: Rewrite to use WebTab::SavedTab
This commit is contained in:
parent
200e602d01
commit
16fcae4202
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2014-2018 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
|
||||
|
@ -145,13 +145,11 @@ void HistoryMenu::aboutToShowClosedTabs()
|
|||
|
||||
TabWidget* tabWidget = m_window->tabWidget();
|
||||
|
||||
int i = 0;
|
||||
const QLinkedList<ClosedTabsManager::Tab> closedTabs = tabWidget->closedTabsManager()->allClosedTabs();
|
||||
|
||||
foreach (const ClosedTabsManager::Tab &tab, closedTabs) {
|
||||
const QString title = QzTools::truncatedText(tab.title, 40);
|
||||
QAction* act = m_menuClosedTabs->addAction(tab.icon, title, tabWidget, SLOT(restoreClosedTab()));
|
||||
act->setData(i++);
|
||||
const auto closedTabs = tabWidget->closedTabsManager()->closedTabs();
|
||||
for (int i = 0; i < closedTabs.count(); ++i) {
|
||||
const ClosedTabsManager::Tab tab = closedTabs.at(i);
|
||||
const QString title = QzTools::truncatedText(tab.tabState.title, 40);
|
||||
m_menuClosedTabs->addAction(tab.tabState.icon, title, tabWidget, SLOT(restoreClosedTab()))->setData(i);
|
||||
}
|
||||
|
||||
if (m_menuClosedTabs->isEmpty()) {
|
||||
|
|
|
@ -267,13 +267,11 @@ void TabWidget::aboutToShowClosedTabsMenu()
|
|||
{
|
||||
m_menuClosedTabs->clear();
|
||||
|
||||
int i = 0;
|
||||
const QLinkedList<ClosedTabsManager::Tab> closedTabs = closedTabsManager()->allClosedTabs();
|
||||
|
||||
foreach (const ClosedTabsManager::Tab &tab, closedTabs) {
|
||||
const QString title = QzTools::truncatedText(tab.title, 40);
|
||||
QAction* act = m_menuClosedTabs->addAction(tab.icon, title, this, SLOT(restoreClosedTab()));
|
||||
act->setData(i++);
|
||||
const auto closedTabs = closedTabsManager()->closedTabs();
|
||||
for (int i = 0; i < closedTabs.count(); ++i) {
|
||||
const ClosedTabsManager::Tab tab = closedTabs.at(i);
|
||||
const QString title = QzTools::truncatedText(tab.tabState.title, 40);
|
||||
m_menuClosedTabs->addAction(tab.tabState.icon, title, this, SLOT(restoreClosedTab()))->setData(i);
|
||||
}
|
||||
|
||||
if (m_menuClosedTabs->isEmpty()) {
|
||||
|
@ -430,8 +428,9 @@ void TabWidget::closeTab(int index)
|
|||
TabbedWebView *webView = webTab->webView();
|
||||
|
||||
// Save tab url and history
|
||||
if (webView->url().toString() != QL1S("falkon:restore"))
|
||||
m_closedTabsManager->saveTab(webTab, index);
|
||||
if (webView->url().toString() != QL1S("falkon:restore")) {
|
||||
m_closedTabsManager->saveTab(webTab);
|
||||
}
|
||||
|
||||
m_locationBars->removeWidget(webView->webTab()->locationBar());
|
||||
disconnect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
||||
|
@ -440,13 +439,6 @@ void TabWidget::closeTab(int index)
|
|||
|
||||
m_lastBackgroundTabIndex = -1;
|
||||
|
||||
if (m_menuTabs->isVisible()) {
|
||||
QAction* labelAction = m_menuTabs->actions().last();
|
||||
//~ singular Currently you have %n opened tab
|
||||
//~ plural Currently you have %n opened tabs
|
||||
labelAction->setText(tr("Currently you have %n opened tab(s)", "", count() - 1));
|
||||
}
|
||||
|
||||
removeTab(index);
|
||||
webTab->deleteLater();
|
||||
|
||||
|
@ -709,9 +701,9 @@ void TabWidget::restoreClosedTab(QObject* obj)
|
|||
return;
|
||||
}
|
||||
|
||||
int index = addView(QUrl(), tab.title, Qz::NT_CleanSelectedTab, false, tab.position);
|
||||
int index = addView(QUrl(), tab.tabState.title, Qz::NT_CleanSelectedTab, false, tab.position);
|
||||
WebTab* webTab = weTab(index);
|
||||
webTab->p_restoreTab(tab.url, tab.history, tab.zoomLevel);
|
||||
webTab->p_restoreTab(tab.tabState);
|
||||
|
||||
updateClosedTabsButton();
|
||||
}
|
||||
|
@ -722,12 +714,11 @@ void TabWidget::restoreAllClosedTabs()
|
|||
return;
|
||||
}
|
||||
|
||||
const QLinkedList<ClosedTabsManager::Tab> &closedTabs = m_closedTabsManager->allClosedTabs();
|
||||
|
||||
foreach (const ClosedTabsManager::Tab &tab, closedTabs) {
|
||||
int index = addView(QUrl(), tab.title, Qz::NT_CleanSelectedTab);
|
||||
const auto closedTabs = m_closedTabsManager->closedTabs();
|
||||
for (const ClosedTabsManager::Tab &tab : closedTabs) {
|
||||
int index = addView(QUrl(), tab.tabState.title, Qz::NT_CleanSelectedTab);
|
||||
WebTab* webTab = weTab(index);
|
||||
webTab->p_restoreTab(tab.url, tab.history, tab.zoomLevel);
|
||||
webTab->p_restoreTab(tab.tabState);
|
||||
}
|
||||
|
||||
clearClosedTabsList();
|
||||
|
@ -735,7 +726,7 @@ void TabWidget::restoreAllClosedTabs()
|
|||
|
||||
void TabWidget::clearClosedTabsList()
|
||||
{
|
||||
m_closedTabsManager->clearList();
|
||||
m_closedTabsManager->clearClosedTabs();
|
||||
updateClosedTabsButton();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2018 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
|
||||
|
@ -16,18 +16,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "closedtabsmanager.h"
|
||||
#include "webtab.h"
|
||||
#include "qztools.h"
|
||||
#include "mainapplication.h"
|
||||
#include "qztools.h"
|
||||
|
||||
#include <QWebEngineHistory>
|
||||
#include <QWebEngineSettings>
|
||||
|
||||
ClosedTabsManager::ClosedTabsManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ClosedTabsManager::saveTab(WebTab* tab, int position)
|
||||
void ClosedTabsManager::saveTab(WebTab *tab)
|
||||
{
|
||||
if (mApp->isPrivate()) {
|
||||
return;
|
||||
|
@ -39,17 +37,12 @@ void ClosedTabsManager::saveTab(WebTab* tab, int position)
|
|||
}
|
||||
|
||||
Tab closedTab;
|
||||
closedTab.url = tab->url();
|
||||
closedTab.title = tab->title();
|
||||
closedTab.icon = tab->icon();
|
||||
closedTab.position = position;
|
||||
closedTab.history = tab->historyData();
|
||||
closedTab.zoomLevel = tab->zoomLevel();
|
||||
|
||||
closedTab.position = tab->tabIndex();
|
||||
closedTab.tabState = WebTab::SavedTab(tab);
|
||||
m_closedTabs.prepend(closedTab);
|
||||
}
|
||||
|
||||
bool ClosedTabsManager::isClosedTabAvailable()
|
||||
bool ClosedTabsManager::isClosedTabAvailable() const
|
||||
{
|
||||
return !m_closedTabs.isEmpty();
|
||||
}
|
||||
|
@ -57,40 +50,27 @@ bool ClosedTabsManager::isClosedTabAvailable()
|
|||
ClosedTabsManager::Tab ClosedTabsManager::takeLastClosedTab()
|
||||
{
|
||||
Tab tab;
|
||||
tab.position = -1;
|
||||
|
||||
if (m_closedTabs.count() > 0) {
|
||||
if (!m_closedTabs.isEmpty()) {
|
||||
tab = m_closedTabs.takeFirst();
|
||||
}
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
ClosedTabsManager::Tab ClosedTabsManager::takeTabAt(int index)
|
||||
{
|
||||
Tab tab;
|
||||
tab.position = -1;
|
||||
|
||||
QLinkedList<Tab>::iterator it;
|
||||
int i = 0;
|
||||
|
||||
for (it = m_closedTabs.begin(); it != m_closedTabs.end(); ++it, ++i) {
|
||||
if (i == index) {
|
||||
tab = *it;
|
||||
m_closedTabs.erase(it);
|
||||
break;
|
||||
}
|
||||
if (QzTools::containsIndex(m_closedTabs, index)) {
|
||||
tab = m_closedTabs.takeAt(index);
|
||||
}
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
QLinkedList<ClosedTabsManager::Tab> ClosedTabsManager::allClosedTabs()
|
||||
QVector<ClosedTabsManager::Tab> ClosedTabsManager::closedTabs() const
|
||||
{
|
||||
return m_closedTabs;
|
||||
}
|
||||
|
||||
void ClosedTabsManager::clearList()
|
||||
void ClosedTabsManager::clearClosedTabs()
|
||||
{
|
||||
m_closedTabs.clear();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2018 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
|
||||
|
@ -18,10 +18,9 @@
|
|||
#ifndef CLOSEDTABSMANAGER_H
|
||||
#define CLOSEDTABSMANAGER_H
|
||||
|
||||
#include <QUrl>
|
||||
#include <QIcon>
|
||||
#include <QLinkedList>
|
||||
#include <QVector>
|
||||
|
||||
#include "webtab.h"
|
||||
#include "qzcommon.h"
|
||||
|
||||
class WebTab;
|
||||
|
@ -30,36 +29,29 @@ class FALKON_EXPORT ClosedTabsManager
|
|||
{
|
||||
public:
|
||||
struct Tab {
|
||||
QUrl url;
|
||||
QString title;
|
||||
QIcon icon;
|
||||
QByteArray history;
|
||||
int position;
|
||||
int zoomLevel;
|
||||
int position = -1;
|
||||
WebTab::SavedTab tabState;
|
||||
|
||||
bool operator==(const Tab &a) const {
|
||||
return (a.url == url &&
|
||||
a.history == history &&
|
||||
a.position == position);
|
||||
bool isValid() const {
|
||||
return position > -1;
|
||||
}
|
||||
};
|
||||
|
||||
explicit ClosedTabsManager();
|
||||
|
||||
void saveTab(WebTab* tab, int position);
|
||||
bool isClosedTabAvailable();
|
||||
void saveTab(WebTab *tab);
|
||||
bool isClosedTabAvailable() const;
|
||||
|
||||
// Takes tab that was most recently closed
|
||||
Tab takeLastClosedTab();
|
||||
// Takes tab at given index
|
||||
Tab takeTabAt(int index);
|
||||
|
||||
QLinkedList<Tab> allClosedTabs();
|
||||
void clearList();
|
||||
QVector<Tab> closedTabs() const;
|
||||
void clearClosedTabs();
|
||||
|
||||
private:
|
||||
QLinkedList<Tab> m_closedTabs;
|
||||
|
||||
QVector<Tab> m_closedTabs;
|
||||
};
|
||||
|
||||
// Hint to Qt to use std::realloc on item moving
|
||||
|
|
Loading…
Reference in New Issue
Block a user