File indexing completed on 2024-05-12 04:58:26

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2018 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 "closedtabsmanager.h"
0019 #include "mainapplication.h"
0020 #include "qztools.h"
0021 
0022 #include <QWebEngineHistory>
0023 
0024 ClosedTabsManager::ClosedTabsManager()
0025 = default;
0026 
0027 void ClosedTabsManager::saveTab(WebTab *tab)
0028 {
0029     if (mApp->isPrivate()) {
0030         return;
0031     }
0032 
0033     // Don't save empty tab
0034     if (tab->url().isEmpty() && tab->history()->items().isEmpty()) {
0035         return;
0036     }
0037 
0038     Tab closedTab;
0039     closedTab.position = tab->tabIndex();
0040     closedTab.parentTab = tab->parentTab();
0041     closedTab.tabState = WebTab::SavedTab(tab);
0042     m_closedTabs.prepend(closedTab);
0043 }
0044 
0045 bool ClosedTabsManager::isClosedTabAvailable() const
0046 {
0047     return !m_closedTabs.isEmpty();
0048 }
0049 
0050 ClosedTabsManager::Tab ClosedTabsManager::takeLastClosedTab()
0051 {
0052     Tab tab;
0053     if (!m_closedTabs.isEmpty()) {
0054         tab = m_closedTabs.takeFirst();
0055     }
0056     return tab;
0057 }
0058 
0059 ClosedTabsManager::Tab ClosedTabsManager::takeTabAt(int index)
0060 {
0061     Tab tab;
0062     if (QzTools::containsIndex(m_closedTabs, index)) {
0063         tab = m_closedTabs.takeAt(index);
0064     }
0065     return tab;
0066 }
0067 
0068 QVector<ClosedTabsManager::Tab> ClosedTabsManager::closedTabs() const
0069 {
0070     return m_closedTabs;
0071 }
0072 
0073 void ClosedTabsManager::clearClosedTabs()
0074 {
0075     m_closedTabs.clear();
0076 }