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/>.
|
|
|
|
* ============================================================ */
|
2012-03-05 11:30:18 +01:00
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "tabbar.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "webpage.h"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "webtab.h"
|
2011-03-26 13:34:08 +01:00
|
|
|
#include "clickablelabel.h"
|
2011-05-07 12:59:53 +02:00
|
|
|
#include "closedtabsmanager.h"
|
2012-01-08 12:38:02 +01:00
|
|
|
#include "locationbar.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2014-03-09 21:51:42 +01:00
|
|
|
#include "datapaths.h"
|
2013-02-09 13:00:45 +01:00
|
|
|
#include "qzsettings.h"
|
2014-03-17 15:01:28 +01:00
|
|
|
#include "qztools.h"
|
2014-03-17 10:43:18 +01:00
|
|
|
#include "tabicon.h"
|
2014-03-19 12:01:53 +01:00
|
|
|
#include "qtwin.h"
|
2011-03-26 13:34:08 +01:00
|
|
|
|
2014-03-18 20:00:34 +01:00
|
|
|
#include <QFile>
|
2013-03-23 20:39:55 +01:00
|
|
|
#include <QTimer>
|
2012-12-20 14:45:35 +01:00
|
|
|
#include <QMimeData>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QStackedWidget>
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QMouseEvent>
|
2015-01-27 11:01:52 +01:00
|
|
|
#include <QWebEngineHistory>
|
2012-05-27 12:44:56 +02:00
|
|
|
#include <QClipboard>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
AddTabButton::AddTabButton(TabWidget* tabWidget, TabBar* tabBar)
|
2013-11-26 14:14:36 +01:00
|
|
|
: ToolButton(tabBar)
|
2012-03-05 11:30:18 +01:00
|
|
|
, m_tabBar(tabBar)
|
|
|
|
, m_tabWidget(tabWidget)
|
2011-03-26 13:34:08 +01:00
|
|
|
{
|
2012-03-05 11:30:18 +01:00
|
|
|
setObjectName("tabwidget-button-addtab");
|
|
|
|
setAutoRaise(true);
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
setAcceptDrops(true);
|
|
|
|
setToolTip(TabWidget::tr("New Tab"));
|
|
|
|
}
|
2011-03-26 13:34:08 +01:00
|
|
|
|
2012-05-27 12:44:56 +02:00
|
|
|
void AddTabButton::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
|
|
|
m_tabBar->wheelEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddTabButton::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::MiddleButton && rect().contains(event->pos())) {
|
2013-06-02 16:46:26 +02:00
|
|
|
m_tabWidget->addTabFromClipboard();
|
2012-05-27 12:44:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ToolButton::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
void AddTabButton::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
{
|
|
|
|
const QMimeData* mime = event->mimeData();
|
|
|
|
|
|
|
|
if (mime->hasUrls()) {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
return;
|
2011-03-26 13:34:08 +01:00
|
|
|
}
|
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
ToolButton::dragEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddTabButton::dropEvent(QDropEvent* event)
|
2011-03-26 13:34:08 +01:00
|
|
|
{
|
2012-03-05 11:30:18 +01:00
|
|
|
const QMimeData* mime = event->mimeData();
|
2011-03-26 13:34:08 +01:00
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
if (!mime->hasUrls()) {
|
|
|
|
ToolButton::dropEvent(event);
|
|
|
|
return;
|
2011-03-26 13:34:08 +01:00
|
|
|
}
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QUrl &url, mime->urls()) {
|
2013-01-25 23:49:46 +01:00
|
|
|
m_tabWidget->addView(url, Qz::NT_SelectedNewEmptyTab);
|
2011-03-26 13:34:08 +01:00
|
|
|
}
|
2012-03-05 11:30:18 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-06-14 12:28:38 +02:00
|
|
|
void MenuTabs::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::MiddleButton) {
|
|
|
|
QAction* action = actionAt(event->pos());
|
2013-08-21 14:38:37 +02:00
|
|
|
if (action && action->isEnabled()) {
|
|
|
|
WebTab* tab = qobject_cast<WebTab*>(qvariant_cast<QWidget*>(action->data()));
|
|
|
|
if (tab) {
|
|
|
|
emit closeTab(tab->tabIndex());
|
|
|
|
action->setEnabled(false);
|
|
|
|
event->accept();
|
|
|
|
}
|
2013-06-14 12:28:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
QMenu::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
TabWidget::TabWidget(BrowserWindow* window, QWidget* parent)
|
2013-11-26 14:14:36 +01:00
|
|
|
: TabStackedWidget(parent)
|
2014-02-19 22:07:21 +01:00
|
|
|
, m_window(window)
|
2014-03-17 15:01:28 +01:00
|
|
|
, m_locationBars(new QStackedWidget)
|
|
|
|
, m_closedTabsManager(new ClosedTabsManager)
|
2013-02-17 11:05:35 +01:00
|
|
|
, m_lastTabIndex(-1)
|
2012-02-27 17:51:57 +01:00
|
|
|
, m_lastBackgroundTabIndex(-1)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-03-17 15:01:28 +01:00
|
|
|
setObjectName(QSL("tabwidget"));
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
m_tabBar = new TabBar(m_window, this);
|
2011-03-02 16:57:41 +01:00
|
|
|
setTabBar(m_tabBar);
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
connect(this, SIGNAL(currentChanged(int)), m_window, SLOT(refreshHistory()));
|
2014-03-10 00:47:07 +01:00
|
|
|
connect(this, SIGNAL(changed()), mApp, SLOT(changeOcurred()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-08-28 10:40:03 +02:00
|
|
|
connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
|
|
|
|
connect(m_tabBar, SIGNAL(stopTab(int)), this, SLOT(stopTab(int)));
|
|
|
|
connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
|
|
|
|
connect(m_tabBar, SIGNAL(closeAllButCurrent(int)), this, SLOT(closeAllButCurrent(int)));
|
2011-04-08 17:27:08 +02:00
|
|
|
connect(m_tabBar, SIGNAL(duplicateTab(int)), this, SLOT(duplicateTab(int)));
|
2013-05-13 22:01:36 +02:00
|
|
|
connect(m_tabBar, SIGNAL(detachTab(int)), this, SLOT(detachTab(int)));
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int,int)));
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2011-10-23 14:44:18 +02:00
|
|
|
connect(m_tabBar, SIGNAL(moveAddTabButton(int)), this, SLOT(moveAddTabButton(int)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-10 00:47:07 +01:00
|
|
|
connect(mApp, SIGNAL(settingsReloaded()), this, SLOT(loadSettings()));
|
2014-03-09 12:49:45 +01:00
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
m_menuTabs = new MenuTabs(this);
|
|
|
|
connect(m_menuTabs, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
|
|
|
|
|
|
|
|
m_menuClosedTabs = new QMenu(this);
|
|
|
|
|
2014-03-31 10:33:17 +02:00
|
|
|
// AddTab button displayed next to last tab
|
|
|
|
m_buttonAddTab = new AddTabButton(this, m_tabBar);
|
|
|
|
connect(m_buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab()));
|
|
|
|
|
|
|
|
// AddTab button displayed outside tabbar (as corner widget)
|
|
|
|
m_buttonAddTab2 = new AddTabButton(this, m_tabBar);
|
|
|
|
m_buttonAddTab2->setProperty("outside-tabbar", true);
|
|
|
|
m_buttonAddTab2->hide();
|
|
|
|
connect(m_buttonAddTab2, SIGNAL(clicked()), m_window, SLOT(addTab()));
|
|
|
|
|
|
|
|
// ClosedTabs button displayed as a permanent corner widget
|
2014-03-17 15:01:28 +01:00
|
|
|
m_buttonClosedTabs = new ToolButton(m_tabBar);
|
|
|
|
m_buttonClosedTabs->setObjectName("tabwidget-button-closedtabs");
|
|
|
|
m_buttonClosedTabs->setMenu(m_menuClosedTabs);
|
|
|
|
m_buttonClosedTabs->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
m_buttonClosedTabs->setToolTip(tr("Closed tabs"));
|
|
|
|
m_buttonClosedTabs->setAutoRaise(true);
|
|
|
|
m_buttonClosedTabs->setFocusPolicy(Qt::NoFocus);
|
|
|
|
m_buttonClosedTabs->setShowMenuInside(true);
|
|
|
|
connect(m_buttonClosedTabs, SIGNAL(aboutToShowMenu()), this, SLOT(aboutToShowClosedTabsMenu()));
|
|
|
|
|
|
|
|
// ListTabs button is showed only when tabbar overflows
|
2013-11-26 14:14:36 +01:00
|
|
|
m_buttonListTabs = new ToolButton(m_tabBar);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_buttonListTabs->setObjectName("tabwidget-button-opentabs");
|
2011-03-02 16:57:41 +01:00
|
|
|
m_buttonListTabs->setMenu(m_menuTabs);
|
|
|
|
m_buttonListTabs->setPopupMode(QToolButton::InstantPopup);
|
2012-01-23 11:05:47 +01:00
|
|
|
m_buttonListTabs->setToolTip(tr("List of tabs"));
|
2011-09-11 19:15:06 +02:00
|
|
|
m_buttonListTabs->setAutoRaise(true);
|
2012-01-08 12:38:02 +01:00
|
|
|
m_buttonListTabs->setFocusPolicy(Qt::NoFocus);
|
2014-02-13 15:27:02 +01:00
|
|
|
m_buttonListTabs->setShowMenuInside(true);
|
2014-03-17 15:01:28 +01:00
|
|
|
m_buttonListTabs->hide();
|
|
|
|
connect(m_buttonListTabs, SIGNAL(aboutToShowMenu()), this, SLOT(aboutToShowTabsMenu()));
|
2014-01-01 18:23:56 +01:00
|
|
|
|
2014-03-18 17:35:44 +01:00
|
|
|
m_tabBar->addCornerWidget(m_buttonAddTab2, Qt::TopRightCorner);
|
2014-03-31 10:33:17 +02:00
|
|
|
m_tabBar->addCornerWidget(m_buttonClosedTabs, Qt::TopRightCorner);
|
2014-03-18 17:35:44 +01:00
|
|
|
m_tabBar->addCornerWidget(m_buttonListTabs, Qt::TopRightCorner);
|
2013-11-26 14:14:36 +01:00
|
|
|
connect(m_tabBar, SIGNAL(overFlowChanged(bool)), this, SLOT(tabBarOverFlowChanged(bool)));
|
|
|
|
|
2012-01-23 11:05:47 +01:00
|
|
|
loadSettings();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::loadSettings()
|
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Browser-Tabs-Settings");
|
2014-03-12 22:31:33 +01:00
|
|
|
m_dontCloseWithOneTab = settings.value("dontCloseWithOneTab", false).toBool();
|
2014-03-24 18:13:37 +01:00
|
|
|
m_showClosedTabsButton = settings.value("showClosedTabsButton", false).toBool();
|
2012-01-26 17:21:11 +01:00
|
|
|
m_newTabAfterActive = settings.value("newTabAfterActive", true).toBool();
|
2013-01-25 23:49:46 +01:00
|
|
|
m_newEmptyTabAfterActive = settings.value("newEmptyTabAfterActive", false).toBool();
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
2012-04-04 18:48:54 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Web-URL-Settings");
|
2011-12-16 22:08:10 +01:00
|
|
|
m_urlOnNewTab = settings.value("newTabUrl", "qupzilla:speeddial").toUrl();
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
m_tabBar->loadSettings();
|
2013-08-21 14:38:37 +02:00
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
updateClosedTabsButton();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* TabWidget::weTab()
|
2012-01-21 23:19:38 +01:00
|
|
|
{
|
2012-03-11 15:17:12 +01:00
|
|
|
return weTab(currentIndex());
|
2012-01-21 23:19:38 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* TabWidget::weTab(int index)
|
2012-01-21 23:19:38 +01:00
|
|
|
{
|
2012-03-11 15:17:12 +01:00
|
|
|
return qobject_cast<WebTab*>(widget(index));
|
2012-01-21 23:19:38 +01:00
|
|
|
}
|
|
|
|
|
2014-03-17 10:43:18 +01:00
|
|
|
TabIcon* TabWidget::tabIcon(int index)
|
|
|
|
{
|
2014-03-18 20:00:34 +01:00
|
|
|
return weTab(index)->tabIcon();
|
2014-03-17 10:43:18 +01:00
|
|
|
}
|
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
bool TabWidget::validIndex(int index) const
|
|
|
|
{
|
|
|
|
return index >= 0 && index < count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::updateClosedTabsButton()
|
|
|
|
{
|
|
|
|
if (!m_showClosedTabsButton) {
|
|
|
|
m_buttonClosedTabs->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_buttonClosedTabs->setEnabled(canRestoreTab());
|
|
|
|
}
|
|
|
|
|
2014-03-18 17:35:44 +01:00
|
|
|
void TabWidget::tabBarOverFlowChanged(bool overflowed)
|
2011-10-24 17:46:45 +02:00
|
|
|
{
|
2014-03-17 15:01:28 +01:00
|
|
|
// Show buttons inside tabbar
|
2014-03-18 17:35:44 +01:00
|
|
|
m_buttonAddTab->setVisible(!overflowed);
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
// Show buttons displayed outside tabbar (corner widgets)
|
2014-03-18 17:35:44 +01:00
|
|
|
m_buttonAddTab2->setVisible(overflowed);
|
|
|
|
m_buttonListTabs->setVisible(overflowed);
|
2014-03-31 10:33:17 +02:00
|
|
|
m_buttonClosedTabs->setVisible(m_showClosedTabsButton);
|
2013-11-26 14:14:36 +01:00
|
|
|
}
|
|
|
|
|
2011-10-23 14:44:18 +02:00
|
|
|
void TabWidget::moveAddTabButton(int posX)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
int posY = (m_tabBar->height() - m_buttonAddTab->height()) / 2;
|
2014-03-17 15:01:28 +01:00
|
|
|
|
2012-08-09 04:00:09 +02:00
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
2014-03-31 10:33:17 +02:00
|
|
|
posX = qMax(posX - m_buttonAddTab->width(), 0);
|
2012-08-20 21:50:31 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-03-31 10:33:17 +02:00
|
|
|
posX = qMin(posX, m_tabBar->width() - m_buttonAddTab->width());
|
2012-08-09 04:00:09 +02:00
|
|
|
}
|
2014-03-17 15:01:28 +01:00
|
|
|
|
2011-10-23 14:44:18 +02:00
|
|
|
m_buttonAddTab->move(posX, posY);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void TabWidget::aboutToShowTabsMenu()
|
|
|
|
{
|
|
|
|
m_menuTabs->clear();
|
2014-03-17 15:01:28 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
for (int i = 0; i < count(); i++) {
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* tab = weTab(i);
|
|
|
|
if (!tab) {
|
2011-03-02 16:57:41 +01:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2014-03-17 15:01:28 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QAction* action = new QAction(this);
|
2014-03-17 15:01:28 +01:00
|
|
|
action->setIcon(i == currentIndex() ? QIcon(QSL(":/icons/menu/dot.png")) : tab->icon());
|
|
|
|
|
2014-04-01 18:47:19 +02:00
|
|
|
QString title = tab->title();
|
|
|
|
title.replace(QLatin1Char('&'), QLatin1String("&&"));
|
|
|
|
action->setText(QzTools::truncatedText(title, 40));
|
2014-03-17 15:01:28 +01:00
|
|
|
|
2013-08-21 14:38:37 +02:00
|
|
|
action->setData(QVariant::fromValue(qobject_cast<QWidget*>(tab)));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(actionChangeIndex()));
|
|
|
|
m_menuTabs->addAction(action);
|
|
|
|
}
|
2014-03-17 15:01:28 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
m_menuTabs->addSeparator();
|
2014-01-09 22:53:01 +01:00
|
|
|
m_menuTabs->addAction(tr("Currently you have %n opened tab(s)", "", count()))->setEnabled(false);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
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);
|
2014-03-30 12:46:06 +02:00
|
|
|
QAction* act = m_menuClosedTabs->addAction(tab.icon, title, this, SLOT(restoreClosedTab()));
|
2014-03-17 15:01:28 +01:00
|
|
|
act->setData(i++);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_menuClosedTabs->isEmpty()) {
|
|
|
|
m_menuClosedTabs->addAction(tr("Empty"))->setEnabled(false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_menuClosedTabs->addSeparator();
|
|
|
|
m_menuClosedTabs->addAction(tr("Restore All Closed Tabs"), this, SLOT(restoreAllClosedTabs()));
|
|
|
|
m_menuClosedTabs->addAction(tr("Clear list"), this, SLOT(clearClosedTabsList()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void TabWidget::actionChangeIndex()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2013-08-21 14:38:37 +02:00
|
|
|
WebTab* tab = qobject_cast<WebTab*>(qvariant_cast<QWidget*>(action->data()));
|
|
|
|
if (tab) {
|
2013-11-26 14:14:36 +01:00
|
|
|
m_tabBar->ensureVisible(tab->tabIndex());
|
2013-08-21 14:38:37 +02:00
|
|
|
setCurrentIndex(tab->tabIndex());
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
int TabWidget::addView(const LoadRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine, bool pinned)
|
2012-01-18 16:52:30 +01:00
|
|
|
{
|
2014-03-19 21:27:43 +01:00
|
|
|
return addView(req, QString(), openFlags, selectLine, -1, pinned);
|
2012-01-18 16:52:30 +01:00
|
|
|
}
|
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
int TabWidget::addView(const LoadRequest &req, const QString &title, const Qz::NewTabPositionFlags &openFlags, bool selectLine, int position, bool pinned)
|
2012-03-10 13:57:50 +01:00
|
|
|
{
|
|
|
|
QUrl url = req.url();
|
2011-05-21 11:19:19 +02:00
|
|
|
m_lastTabIndex = currentIndex();
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
if (url.isEmpty() && !(openFlags & Qz::NT_CleanTab)) {
|
2011-03-02 16:57:41 +01:00
|
|
|
url = m_urlOnNewTab;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-01-25 23:49:46 +01:00
|
|
|
bool openAfterActive = m_newTabAfterActive && !(openFlags & Qz::NT_TabAtTheEnd);
|
|
|
|
|
|
|
|
if (openFlags == Qz::NT_SelectedNewEmptyTab && m_newEmptyTabAfterActive) {
|
|
|
|
openAfterActive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openAfterActive && position == -1) {
|
2012-01-07 12:09:39 +01:00
|
|
|
// If we are opening newBgTab from pinned tab, make sure it won't be
|
|
|
|
// opened between other pinned tabs
|
2012-06-15 17:43:19 +02:00
|
|
|
if (openFlags & Qz::NT_NotSelectedTab && m_lastBackgroundTabIndex != -1) {
|
2012-02-27 17:51:57 +01:00
|
|
|
position = m_lastBackgroundTabIndex + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
position = qMax(currentIndex() + 1, m_tabBar->pinnedTabsCount());
|
|
|
|
}
|
2011-12-23 17:32:55 +01:00
|
|
|
}
|
|
|
|
|
2014-03-18 20:00:34 +01:00
|
|
|
WebTab* webTab = new WebTab(m_window);
|
|
|
|
webTab->locationBar()->showUrl(url);
|
|
|
|
m_locationBars->addWidget(webTab->locationBar());
|
2011-12-11 17:03:18 +01:00
|
|
|
|
2014-03-18 20:00:34 +01:00
|
|
|
int index = insertTab(position == -1 ? count() : position, webTab, QString(), pinned);
|
2014-04-04 17:03:44 +02:00
|
|
|
webTab->attach(m_window);
|
2014-03-22 23:59:38 +01:00
|
|
|
|
|
|
|
if (!title.isEmpty()) {
|
2014-04-01 18:47:19 +02:00
|
|
|
m_tabBar->setTabText(index, title);
|
2014-03-22 23:59:38 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
if (openFlags & Qz::NT_SelectedTab) {
|
2011-03-02 16:57:41 +01:00
|
|
|
setCurrentIndex(index);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-02-27 17:51:57 +01:00
|
|
|
else {
|
|
|
|
m_lastBackgroundTabIndex = index;
|
|
|
|
}
|
2011-11-05 18:36:53 +01:00
|
|
|
|
2014-03-18 20:00:34 +01:00
|
|
|
connect(webTab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
2015-09-29 16:37:22 +02:00
|
|
|
connect(webTab->webView(), SIGNAL(urlChanged(QUrl)), this, SIGNAL(changed()));
|
2014-03-18 20:00:34 +01:00
|
|
|
connect(webTab->webView(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-03-19 21:27:43 +01:00
|
|
|
if (url.isValid() && url != req.url()) {
|
|
|
|
LoadRequest r(req);
|
|
|
|
r.setUrl(url);
|
|
|
|
webTab->webView()->load(r);
|
|
|
|
}
|
2015-02-08 10:10:36 +01:00
|
|
|
else if (req.url().isValid()) {
|
2014-03-18 20:00:34 +01:00
|
|
|
webTab->webView()->load(req);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
if (selectLine && m_window->locationBar()->text().isEmpty()) {
|
|
|
|
m_window->locationBar()->setFocus();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2014-03-13 12:07:05 +01:00
|
|
|
// Make sure user notice opening new background tabs
|
|
|
|
if (!(openFlags & Qz::NT_SelectedTab)) {
|
|
|
|
m_tabBar->ensureVisible(index);
|
|
|
|
}
|
|
|
|
|
2014-03-06 16:12:36 +01:00
|
|
|
emit changed();
|
2011-03-02 16:57:41 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2013-05-13 22:01:36 +02:00
|
|
|
int TabWidget::addView(WebTab* tab)
|
|
|
|
{
|
|
|
|
m_locationBars->addWidget(tab->locationBar());
|
|
|
|
int index = addTab(tab, QString());
|
2014-04-04 17:03:44 +02:00
|
|
|
tab->attach(m_window);
|
2013-09-03 08:29:12 +02:00
|
|
|
|
2014-03-18 20:00:34 +01:00
|
|
|
connect(tab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
|
|
|
connect(tab->webView(), SIGNAL(changed()), this, SIGNAL(changed()));
|
|
|
|
connect(tab->webView(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
2013-05-13 22:01:36 +02:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2013-06-02 16:46:26 +02:00
|
|
|
void TabWidget::addTabFromClipboard()
|
|
|
|
{
|
|
|
|
QString selectionClipboard = QApplication::clipboard()->text(QClipboard::Selection);
|
|
|
|
QUrl guessedUrl = WebView::guessUrlFromString(selectionClipboard);
|
|
|
|
|
|
|
|
if (!guessedUrl.isEmpty()) {
|
|
|
|
addView(guessedUrl, Qz::NT_SelectedNewEmptyTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-21 20:28:38 +02:00
|
|
|
void TabWidget::closeTab(int index, bool force)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-04-19 18:24:09 +02:00
|
|
|
if (index == -1)
|
2011-03-02 16:57:41 +01:00
|
|
|
index = currentIndex();
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
2014-04-19 18:24:09 +02:00
|
|
|
if (!webTab || !validIndex(index))
|
2011-07-11 20:30:49 +02:00
|
|
|
return;
|
|
|
|
|
2014-03-18 20:00:34 +01:00
|
|
|
TabbedWebView* webView = webTab->webView();
|
2014-04-19 18:24:09 +02:00
|
|
|
bool isRestorePage = webView->url().toString() == QL1S("qupzilla:restore");
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2014-03-12 22:31:33 +01:00
|
|
|
// Don't close restore page!
|
2014-04-19 18:24:09 +02:00
|
|
|
if (!force && isRestorePage && mApp->restoreManager())
|
2012-08-21 20:28:38 +02:00
|
|
|
return;
|
|
|
|
|
2014-03-12 22:31:33 +01:00
|
|
|
// window.onbeforeunload handling
|
2014-04-19 18:24:09 +02:00
|
|
|
if (!webView->onBeforeUnload())
|
2014-03-12 22:31:33 +01:00
|
|
|
return;
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2014-03-12 22:31:33 +01:00
|
|
|
// Save tab url and history
|
2014-04-19 18:24:09 +02:00
|
|
|
if (!isRestorePage)
|
|
|
|
m_closedTabsManager->saveTab(webTab, index);
|
2014-02-10 19:27:58 +01:00
|
|
|
|
2014-03-12 22:31:33 +01:00
|
|
|
// This would close last tab, so we close the window instead
|
|
|
|
if (!force && count() == 1) {
|
2014-03-13 11:11:15 +01:00
|
|
|
// If we are not closing window upon closing last tab, let's just load new-tab-url
|
2014-03-12 22:31:33 +01:00
|
|
|
if (m_dontCloseWithOneTab) {
|
2014-03-13 11:11:15 +01:00
|
|
|
if (webView->url() == m_urlOnNewTab) {
|
|
|
|
// We don't want to accumulate more than one closed tab, if user tries
|
|
|
|
// to close the last tab multiple times
|
|
|
|
m_closedTabsManager->takeLastClosedTab();
|
|
|
|
}
|
|
|
|
webView->load(m_urlOnNewTab);
|
2014-03-12 22:31:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_window->close();
|
2014-02-11 22:25:32 +01:00
|
|
|
return;
|
2014-01-02 12:09:04 +01:00
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
m_locationBars->removeWidget(webView->webTab()->locationBar());
|
|
|
|
disconnect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
2015-09-29 16:31:23 +02:00
|
|
|
disconnect(webView, SIGNAL(urlChanged(QUrl)), this, SIGNAL(changed()));
|
2014-02-19 22:07:21 +01:00
|
|
|
disconnect(webView, SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
2012-04-25 11:35:13 +02:00
|
|
|
|
2012-02-27 17:51:57 +01:00
|
|
|
m_lastBackgroundTabIndex = -1;
|
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
if (m_menuTabs->isVisible()) {
|
2013-08-21 14:38:37 +02:00
|
|
|
QAction* labelAction = m_menuTabs->actions().last();
|
2014-01-09 22:53:01 +01:00
|
|
|
labelAction->setText(tr("Currently you have %n opened tab(s)", "", count() - 1));
|
2013-08-21 14:38:37 +02:00
|
|
|
}
|
2014-03-06 16:12:36 +01:00
|
|
|
|
2014-03-13 11:11:15 +01:00
|
|
|
removeTab(index);
|
2014-03-25 16:55:00 +01:00
|
|
|
webTab->deleteLater();
|
2014-03-13 11:11:15 +01:00
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
updateClosedTabsButton();
|
|
|
|
|
2014-03-06 16:12:36 +01:00
|
|
|
emit changed();
|
2012-01-04 16:00:59 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2012-02-27 17:51:57 +01:00
|
|
|
void TabWidget::currentTabChanged(int index)
|
2012-01-04 16:00:59 +01:00
|
|
|
{
|
2014-04-08 15:47:48 +02:00
|
|
|
if (!validIndex(index))
|
2012-02-27 17:51:57 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_lastBackgroundTabIndex = -1;
|
2012-09-03 22:40:52 +02:00
|
|
|
m_lastTabIndex = index;
|
2012-02-27 17:51:57 +01:00
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
|
|
|
LocationBar* locBar = webTab->locationBar();
|
2012-02-27 17:51:57 +01:00
|
|
|
|
2013-02-09 13:00:45 +01:00
|
|
|
if (locBar && m_locationBars->indexOf(locBar) != -1) {
|
2012-02-27 17:51:57 +01:00
|
|
|
m_locationBars->setCurrentWidget(locBar);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-02-27 17:51:57 +01:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
m_window->currentTabChanged();
|
2014-03-06 16:12:36 +01:00
|
|
|
|
|
|
|
emit changed();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-21 11:19:19 +02:00
|
|
|
void TabWidget::tabMoved(int before, int after)
|
|
|
|
{
|
|
|
|
Q_UNUSED(before)
|
|
|
|
Q_UNUSED(after)
|
2012-02-04 19:43:43 +01:00
|
|
|
|
2012-02-27 17:51:57 +01:00
|
|
|
m_lastBackgroundTabIndex = -1;
|
2012-09-03 22:40:52 +02:00
|
|
|
m_lastTabIndex = before;
|
2011-05-21 11:19:19 +02:00
|
|
|
}
|
|
|
|
|
2012-09-03 22:40:52 +02:00
|
|
|
void TabWidget::setCurrentIndex(int index)
|
|
|
|
{
|
|
|
|
m_lastTabIndex = currentIndex();
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
TabStackedWidget::setCurrentIndex(index);
|
2012-09-03 22:40:52 +02:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:19:10 +01:00
|
|
|
void TabWidget::nextTab()
|
|
|
|
{
|
|
|
|
QKeyEvent fakeEvent(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::ControlModifier);
|
|
|
|
keyPressEvent(&fakeEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::previousTab()
|
|
|
|
{
|
|
|
|
QKeyEvent fakeEvent(QKeyEvent::KeyPress, Qt::Key_Backtab, QFlags<Qt::KeyboardModifier>(Qt::ControlModifier + Qt::ShiftModifier));
|
|
|
|
keyPressEvent(&fakeEvent);
|
|
|
|
}
|
|
|
|
|
2012-08-24 19:24:48 +02:00
|
|
|
int TabWidget::normalTabsCount() const
|
|
|
|
{
|
|
|
|
return m_tabBar->normalTabsCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabWidget::pinnedTabsCount() const
|
|
|
|
{
|
|
|
|
return m_tabBar->pinnedTabsCount();
|
|
|
|
}
|
|
|
|
|
2012-02-27 17:51:57 +01:00
|
|
|
void TabWidget::reloadTab(int index)
|
|
|
|
{
|
2012-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
weTab(index)->reload();
|
2012-02-27 17:51:57 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-09-03 22:40:52 +02:00
|
|
|
int TabWidget::lastTabIndex() const
|
|
|
|
{
|
|
|
|
return m_lastTabIndex;
|
|
|
|
}
|
|
|
|
|
2014-03-18 17:35:44 +01:00
|
|
|
int TabWidget::extraReservedWidth() const
|
|
|
|
{
|
2014-03-31 10:33:17 +02:00
|
|
|
return m_buttonAddTab->width();
|
2014-03-18 17:35:44 +01:00
|
|
|
}
|
|
|
|
|
2014-04-04 17:14:31 +02:00
|
|
|
TabBar* TabWidget::tabBar() const
|
2013-02-09 13:00:45 +01:00
|
|
|
{
|
|
|
|
return m_tabBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClosedTabsManager* TabWidget::closedTabsManager() const
|
|
|
|
{
|
|
|
|
return m_closedTabsManager;
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void TabWidget::reloadAllTabs()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
for (int i = 0; i < count(); i++) {
|
2011-03-02 16:57:41 +01:00
|
|
|
reloadTab(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
void TabWidget::stopTab(int index)
|
|
|
|
{
|
2012-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
weTab(index)->stop();
|
2012-01-21 23:19:38 +01:00
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void TabWidget::closeAllButCurrent(int index)
|
|
|
|
{
|
2012-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* akt = weTab(index);
|
2011-04-18 21:35:57 +02:00
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (WebTab* tab, allTabs(false)) {
|
2012-03-11 15:17:12 +01:00
|
|
|
int tabIndex = tab->tabIndex();
|
|
|
|
if (akt == widget(tabIndex)) {
|
2011-04-18 21:35:57 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-03-11 15:17:12 +01:00
|
|
|
closeTab(tabIndex);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 22:01:36 +02:00
|
|
|
void TabWidget::detachTab(int index)
|
|
|
|
{
|
|
|
|
WebTab* tab = weTab(index);
|
|
|
|
|
|
|
|
if (tab->isPinned() || count() == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_locationBars->removeWidget(tab->locationBar());
|
2014-03-18 20:00:34 +01:00
|
|
|
disconnect(tab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
2015-09-29 16:31:23 +02:00
|
|
|
disconnect(tab->webView(), SIGNAL(urlChanged(QUrl)), this, SIGNAL(changed()));
|
2014-03-18 20:00:34 +01:00
|
|
|
disconnect(tab->webView(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
|
2013-05-13 22:01:36 +02:00
|
|
|
|
2014-04-01 18:47:19 +02:00
|
|
|
tab->detach();
|
|
|
|
|
2014-03-10 00:47:07 +01:00
|
|
|
BrowserWindow* window = mApp->createWindow(Qz::BW_NewWindow);
|
2014-03-10 16:55:11 +01:00
|
|
|
window->setStartTab(tab);
|
2013-05-13 22:01:36 +02:00
|
|
|
}
|
|
|
|
|
2011-12-29 15:45:29 +01:00
|
|
|
int TabWidget::duplicateTab(int index)
|
2011-04-08 17:27:08 +02:00
|
|
|
{
|
2012-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-12 18:22:01 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QUrl url = webTab->url();
|
|
|
|
const QString title = webTab->title();
|
|
|
|
const QByteArray history = webTab->historyData();
|
2011-04-08 17:27:08 +02:00
|
|
|
|
2012-03-10 13:57:50 +01:00
|
|
|
QNetworkRequest req(url);
|
|
|
|
req.setRawHeader("Referer", url.toEncoded());
|
2012-07-13 11:04:14 +02:00
|
|
|
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
2012-03-10 13:57:50 +01:00
|
|
|
|
2012-03-16 23:28:23 +01:00
|
|
|
int id = addView(req, title, Qz::NT_CleanNotSelectedTab);
|
2012-03-12 18:22:01 +01:00
|
|
|
weTab(id)->setHistoryData(history);
|
2011-12-29 15:45:29 +01:00
|
|
|
|
|
|
|
return id;
|
2011-04-08 17:27:08 +02:00
|
|
|
}
|
|
|
|
|
2013-02-07 15:01:25 +01:00
|
|
|
void TabWidget::restoreClosedTab(QObject* obj)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-02-07 15:01:25 +01:00
|
|
|
if (!obj) {
|
|
|
|
obj = sender();
|
|
|
|
}
|
2014-03-17 15:01:28 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_closedTabsManager->isClosedTabAvailable()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-05-07 12:59:53 +02:00
|
|
|
|
|
|
|
ClosedTabsManager::Tab tab;
|
|
|
|
|
2013-02-07 15:01:25 +01:00
|
|
|
QAction* action = qobject_cast<QAction*>(obj);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (action && action->data().toInt() != 0) {
|
2014-02-10 19:27:58 +01:00
|
|
|
tab = m_closedTabsManager->takeTabAt(action->data().toInt());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-02-10 19:27:58 +01:00
|
|
|
tab = m_closedTabsManager->takeLastClosedTab();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-11 17:03:18 +01:00
|
|
|
|
2014-02-01 19:21:49 +01:00
|
|
|
if (tab.position < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
int index = addView(QUrl(), tab.title, Qz::NT_CleanSelectedTab, false, tab.position);
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
|
|
|
webTab->p_restoreTab(tab.url, tab.history);
|
2014-03-17 15:01:28 +01:00
|
|
|
|
|
|
|
updateClosedTabsButton();
|
2011-05-07 12:59:53 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 21:36:39 +02:00
|
|
|
void TabWidget::restoreAllClosedTabs()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_closedTabsManager->isClosedTabAvailable()) {
|
2011-05-16 21:36:39 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-05-16 21:36:39 +02:00
|
|
|
|
2014-02-10 19:27:58 +01:00
|
|
|
const QLinkedList<ClosedTabsManager::Tab> &closedTabs = m_closedTabsManager->allClosedTabs();
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const ClosedTabsManager::Tab &tab, closedTabs) {
|
2012-01-22 00:20:29 +01:00
|
|
|
int index = addView(QUrl(), tab.title, Qz::NT_CleanSelectedTab);
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
|
|
|
webTab->p_restoreTab(tab.url, tab.history);
|
2011-05-16 21:36:39 +02:00
|
|
|
}
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
clearClosedTabsList();
|
2011-05-16 21:36:39 +02:00
|
|
|
}
|
|
|
|
|
2011-07-28 21:59:56 +02:00
|
|
|
void TabWidget::clearClosedTabsList()
|
|
|
|
{
|
|
|
|
m_closedTabsManager->clearList();
|
2014-03-17 15:01:28 +01:00
|
|
|
updateClosedTabsButton();
|
2011-07-28 21:59:56 +02:00
|
|
|
}
|
|
|
|
|
2013-02-09 13:00:45 +01:00
|
|
|
bool TabWidget::canRestoreTab() const
|
2011-05-07 12:59:53 +02:00
|
|
|
{
|
|
|
|
return m_closedTabsManager->isClosedTabAvailable();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-02-09 13:00:45 +01:00
|
|
|
QStackedWidget* TabWidget::locationBars() const
|
|
|
|
{
|
|
|
|
return m_locationBars;
|
|
|
|
}
|
|
|
|
|
2014-03-17 15:01:28 +01:00
|
|
|
ToolButton* TabWidget::buttonClosedTabs() const
|
2013-02-09 13:00:45 +01:00
|
|
|
{
|
2014-03-17 15:01:28 +01:00
|
|
|
return m_buttonClosedTabs;
|
2013-02-09 13:00:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AddTabButton* TabWidget::buttonAddTab() const
|
|
|
|
{
|
|
|
|
return m_buttonAddTab;
|
|
|
|
}
|
|
|
|
|
2013-02-26 12:58:04 +01:00
|
|
|
QList<WebTab*> TabWidget::allTabs(bool withPinned)
|
2011-04-18 21:35:57 +02:00
|
|
|
{
|
|
|
|
QList<WebTab*> allTabs;
|
2012-02-04 19:43:43 +01:00
|
|
|
|
2011-04-18 21:35:57 +02:00
|
|
|
for (int i = 0; i < count(); i++) {
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* tab = weTab(i);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!tab || (!withPinned && tab->isPinned())) {
|
2011-04-18 21:35:57 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-18 21:35:57 +02:00
|
|
|
allTabs.append(tab);
|
|
|
|
}
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2011-04-18 21:35:57 +02:00
|
|
|
return allTabs;
|
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
void TabWidget::savePinnedTabs()
|
|
|
|
{
|
2014-03-10 00:47:07 +01:00
|
|
|
if (mApp->isPrivate()) {
|
2012-06-26 11:49:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
QByteArray data;
|
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
|
|
|
|
2012-12-20 15:22:14 +01:00
|
|
|
stream << Qz::sessionVersion;
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
QStringList tabs;
|
|
|
|
QList<QByteArray> tabsHistory;
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
2012-03-12 18:22:01 +01:00
|
|
|
WebTab* tab = weTab(i);
|
|
|
|
if (!tab || !tab->isPinned()) {
|
|
|
|
continue;
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
2012-03-12 18:22:01 +01:00
|
|
|
|
|
|
|
tabs.append(tab->url().toEncoded());
|
|
|
|
tabsHistory.append(tab->historyData());
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
2012-03-12 18:22:01 +01:00
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
stream << tabs;
|
|
|
|
stream << tabsHistory;
|
2012-03-12 18:22:01 +01:00
|
|
|
|
2014-03-09 22:17:13 +01:00
|
|
|
QFile file(DataPaths::currentProfilePath() + "/pinnedtabs.dat");
|
2011-03-25 19:16:21 +01:00
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(data);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::restorePinnedTabs()
|
|
|
|
{
|
2014-03-10 00:47:07 +01:00
|
|
|
if (mApp->isPrivate()) {
|
2012-06-26 11:49:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-09 22:17:13 +01:00
|
|
|
QFile file(DataPaths::currentProfilePath() + "/pinnedtabs.dat");
|
2011-03-25 19:16:21 +01:00
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
QByteArray sd = file.readAll();
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
QDataStream stream(&sd, QIODevice::ReadOnly);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (stream.atEnd()) {
|
2011-03-25 19:16:21 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-25 19:16:21 +01:00
|
|
|
|
2012-12-20 15:22:14 +01:00
|
|
|
int version;
|
|
|
|
stream >> version;
|
2014-03-14 14:08:38 +01:00
|
|
|
if (version != Qz::sessionVersion && version != Qz::sessionVersionQt5) {
|
2012-12-20 15:22:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
QStringList pinnedTabs;
|
|
|
|
stream >> pinnedTabs;
|
|
|
|
QList<QByteArray> tabHistory;
|
|
|
|
stream >> tabHistory;
|
|
|
|
|
|
|
|
for (int i = 0; i < pinnedTabs.count(); ++i) {
|
|
|
|
QUrl url = QUrl::fromEncoded(pinnedTabs.at(i).toUtf8());
|
|
|
|
|
|
|
|
QByteArray historyState = tabHistory.value(i);
|
|
|
|
int addedIndex;
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
if (!historyState.isEmpty()) {
|
2013-11-26 14:14:36 +01:00
|
|
|
addedIndex = addView(QUrl(), Qz::NT_CleanSelectedTab, false, true);
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2012-08-24 19:24:48 +02:00
|
|
|
weTab(addedIndex)->p_restoreTab(url, historyState);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-11-26 14:14:36 +01:00
|
|
|
addedIndex = addView(url, tr("New tab"), Qz::NT_SelectedTab, false, -1, true);
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
2012-03-11 15:17:12 +01:00
|
|
|
|
|
|
|
WebTab* webTab = weTab(addedIndex);
|
|
|
|
|
2011-10-14 23:12:10 +02:00
|
|
|
if (webTab) {
|
2011-03-25 19:16:21 +01:00
|
|
|
webTab->setPinned(true);
|
2011-10-14 23:12:10 +02:00
|
|
|
}
|
2011-03-25 19:16:21 +01:00
|
|
|
|
2012-09-03 22:40:52 +02:00
|
|
|
m_tabBar->updatePinnedTabCloseButton(addedIndex);
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QByteArray TabWidget::saveState()
|
|
|
|
{
|
2013-02-26 12:56:11 +01:00
|
|
|
QVector<WebTab::SavedTab> tabList;
|
2012-03-11 15:17:12 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
WebTab* webTab = weTab(i);
|
2015-09-27 18:46:16 +02:00
|
|
|
if (!webTab)
|
2012-03-11 15:17:12 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
WebTab::SavedTab tab(webTab);
|
|
|
|
tabList.append(tab);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QByteArray data;
|
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
stream << tabList.count();
|
2011-03-25 19:16:21 +01:00
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const WebTab::SavedTab &tab, tabList) {
|
2012-03-11 15:17:12 +01:00
|
|
|
stream << tab;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
stream << currentIndex();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2013-02-26 12:56:11 +01:00
|
|
|
bool TabWidget::restoreState(const QVector<WebTab::SavedTab> &tabs, int currentTab)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-08-21 20:28:38 +02:00
|
|
|
for (int i = 0; i < tabs.size(); ++i) {
|
|
|
|
WebTab::SavedTab tab = tabs.at(i);
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2015-09-27 18:46:16 +02:00
|
|
|
int index = addView(QUrl(), Qz::NT_CleanSelectedTab, false, tab.isPinned);
|
2012-03-11 15:17:12 +01:00
|
|
|
weTab(index)->restoreTab(tab);
|
2015-09-27 18:46:16 +02:00
|
|
|
|
|
|
|
if (tab.isPinned)
|
|
|
|
m_tabBar->updatePinnedTabCloseButton(index);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-04-07 18:00:26 +02:00
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
setCurrentIndex(currentTab);
|
2014-04-08 15:47:48 +02:00
|
|
|
|
|
|
|
// WebTab is restoring state on showEvent
|
|
|
|
weTab()->hide();
|
|
|
|
weTab()->show();
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-24 19:24:48 +02:00
|
|
|
void TabWidget::closeRecoveryTab()
|
|
|
|
{
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (WebTab* tab, allTabs(false)) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (tab->url().toString() == QLatin1String("qupzilla:restore")) {
|
2012-08-24 19:24:48 +02:00
|
|
|
closeTab(tab->tabIndex(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
TabWidget::~TabWidget()
|
|
|
|
{
|
2012-02-29 18:33:50 +01:00
|
|
|
delete m_closedTabsManager;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|