2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 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"
|
|
|
|
#include "qupzilla.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.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"
|
2011-07-11 20:30:49 +02:00
|
|
|
#include "progressbar.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "navigationbar.h"
|
2012-01-08 12:38:02 +01:00
|
|
|
#include "locationbar.h"
|
|
|
|
#include "websearchbar.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2011-03-26 13:34:08 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QStyleOptionToolButton>
|
|
|
|
#include <QMovie>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QStackedWidget>
|
|
|
|
#include <QWebHistory>
|
2012-03-05 23:34:00 +01:00
|
|
|
#include <QFile>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
AddTabButton::AddTabButton(TabWidget* tabWidget, TabBar* tabBar)
|
|
|
|
: ToolButton(tabWidget)
|
|
|
|
, 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-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
|
|
|
}
|
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
foreach(const QUrl & url, mime->urls()) {
|
|
|
|
m_tabWidget->addView(url, Qz::NT_SelectedTabAtTheEnd);
|
2011-03-26 13:34:08 +01:00
|
|
|
}
|
2012-03-05 11:30:18 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-05 18:36:53 +01:00
|
|
|
TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
|
2011-11-06 17:01:23 +01:00
|
|
|
: QTabWidget(parent)
|
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_lastTabIndex(0)
|
2012-02-27 17:51:57 +01:00
|
|
|
, m_lastBackgroundTabIndex(-1)
|
2011-11-06 17:01:23 +01:00
|
|
|
, m_isClosingToLastTabIndex(false)
|
2012-03-16 23:28:23 +01:00
|
|
|
, m_isRestoringState(false)
|
2012-02-29 18:33:50 +01:00
|
|
|
, m_closedTabsManager(new ClosedTabsManager)
|
|
|
|
, m_locationBars(new QStackedWidget)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
setObjectName("tabwidget");
|
2011-10-14 23:12:10 +02:00
|
|
|
m_tabBar = new TabBar(p_QupZilla, this);
|
2011-03-02 16:57:41 +01:00
|
|
|
setTabBar(m_tabBar);
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(this, SIGNAL(currentChanged(int)), p_QupZilla, SLOT(refreshHistory()));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
|
|
|
|
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)));
|
2011-11-06 17:01:23 +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-10-24 17:46:45 +02:00
|
|
|
connect(m_tabBar, SIGNAL(showButtons()), this, SLOT(showButtons()));
|
|
|
|
connect(m_tabBar, SIGNAL(hideButtons()), this, SLOT(hideButtons()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
m_buttonListTabs = new ToolButton(this);
|
|
|
|
m_buttonListTabs->setObjectName("tabwidget-button-opentabs");
|
2011-12-04 20:09:44 +01:00
|
|
|
m_menuTabs = new QMenu(this);
|
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);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
m_buttonAddTab = new AddTabButton(this, m_tabBar);
|
2011-10-23 14:44:18 +02:00
|
|
|
|
|
|
|
connect(m_buttonAddTab, SIGNAL(clicked()), p_QupZilla, SLOT(addTab()));
|
2012-01-23 11:05:47 +01:00
|
|
|
connect(m_menuTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowClosedTabsMenu()));
|
|
|
|
|
|
|
|
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");
|
2011-11-06 17:01:23 +01:00
|
|
|
m_hideTabBarWithOneTab = settings.value("hideTabsWithOneTab", false).toBool();
|
2012-01-20 14:12:26 +01:00
|
|
|
m_dontQuitWithOneTab = settings.value("dontQuitWithOneTab", false).toBool();
|
2012-01-23 00:23:45 +01:00
|
|
|
m_closedInsteadOpened = settings.value("closedInsteadOpenedTabs", false).toBool();
|
2012-01-26 17:21:11 +01:00
|
|
|
m_newTabAfterActive = settings.value("newTabAfterActive", true).toBool();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void TabWidget::resizeEvent(QResizeEvent* e)
|
2011-09-11 19:15:06 +02:00
|
|
|
{
|
|
|
|
QPoint posit;
|
|
|
|
posit.setY(0);
|
|
|
|
posit.setX(width() - m_buttonListTabs->width());
|
|
|
|
m_buttonListTabs->move(posit);
|
|
|
|
|
|
|
|
QTabWidget::resizeEvent(e);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-10-24 17:46:45 +02:00
|
|
|
void TabWidget::showButtons()
|
|
|
|
{
|
|
|
|
m_buttonListTabs->show();
|
|
|
|
m_buttonAddTab->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::hideButtons()
|
|
|
|
{
|
|
|
|
m_buttonListTabs->hide();
|
|
|
|
m_buttonAddTab->hide();
|
|
|
|
}
|
|
|
|
|
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;
|
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();
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* actTab = weTab();
|
|
|
|
if (!actTab) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
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
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
QAction* action = new QAction(this);
|
2012-03-11 15:17:12 +01:00
|
|
|
if (tab == actTab) {
|
2011-09-11 19:15:06 +02:00
|
|
|
action->setIcon(QIcon(":/icons/menu/dot.png"));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-03-11 15:17:12 +01:00
|
|
|
action->setIcon(tab->icon());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-03-11 15:17:12 +01:00
|
|
|
if (tab->title().isEmpty()) {
|
|
|
|
if (tab->isLoading()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
action->setText(tr("Loading..."));
|
|
|
|
action->setIcon(QIcon(":/icons/other/progress.gif"));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-02 16:57:41 +01:00
|
|
|
action->setText(tr("No Named Page"));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
else {
|
2012-03-11 15:17:12 +01:00
|
|
|
QString title = tab->title();
|
2012-02-04 18:45:59 +01:00
|
|
|
title.replace("&", "&&");
|
2011-11-06 17:01:23 +01:00
|
|
|
if (title.length() > 40) {
|
2011-03-02 16:57:41 +01:00
|
|
|
title.truncate(40);
|
2011-11-06 17:01:23 +01:00
|
|
|
title += "..";
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
action->setText(title);
|
|
|
|
}
|
|
|
|
action->setData(i);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(actionChangeIndex()));
|
|
|
|
|
|
|
|
m_menuTabs->addAction(action);
|
|
|
|
}
|
|
|
|
m_menuTabs->addSeparator();
|
2012-01-29 11:59:39 +01:00
|
|
|
m_menuTabs->addAction(tr("Currently you have %1 opened tabs").arg(count()))->setEnabled(false);
|
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())) {
|
2011-03-02 16:57:41 +01:00
|
|
|
setCurrentIndex(action->data().toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
int TabWidget::addView(const QUrl &url, const Qz::NewTabPositionFlags &openFlags, bool selectLine)
|
2012-01-18 16:52:30 +01:00
|
|
|
{
|
2012-03-10 13:57:50 +01:00
|
|
|
return addView(QNetworkRequest(url), openFlags, selectLine);
|
2012-01-18 16:52:30 +01:00
|
|
|
}
|
|
|
|
|
2012-03-10 13:57:50 +01:00
|
|
|
int TabWidget::addView(const QNetworkRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-03-10 13:57:50 +01:00
|
|
|
return addView(req, tr("New tab"), openFlags, selectLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabWidget::addView(const QUrl &url, const QString &title, const Qz::NewTabPositionFlags &openFlags, bool selectLine, int position)
|
|
|
|
{
|
|
|
|
return addView(QNetworkRequest(url), title, openFlags, selectLine, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewTabPositionFlags &openFlags, bool selectLine, int position)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-01-29 11:23:16 +01:00
|
|
|
if (position == -1 && m_newTabAfterActive && !(openFlags & Qz::NT_TabAtTheEnd)) {
|
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-03-01 18:32:53 +01: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
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
LocationBar* locBar = new LocationBar(p_QupZilla);
|
|
|
|
m_locationBars->addWidget(locBar);
|
2011-12-11 17:03:18 +01:00
|
|
|
int index;
|
|
|
|
|
|
|
|
if (position == -1) {
|
|
|
|
index = addTab(new WebTab(p_QupZilla, locBar), "");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
index = insertTab(position, new WebTab(p_QupZilla, locBar), "");
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
TabbedWebView* webView = weTab(index)->view();
|
2011-07-11 20:30:49 +02:00
|
|
|
locBar->setWebView(webView);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
setTabText(index, title);
|
2012-03-13 17:51:06 +01:00
|
|
|
setTabIcon(index, IconProvider::emptyWebIcon());
|
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
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (count() == 1 && m_hideTabBarWithOneTab) {
|
2011-03-02 16:57:41 +01:00
|
|
|
tabBar()->setVisible(false);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
tabBar()->setVisible(true);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
connect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
2011-07-28 12:12:00 +02:00
|
|
|
connect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged()));
|
2011-07-11 20:30:49 +02:00
|
|
|
connect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.isValid()) {
|
2012-03-10 13:57:50 +01:00
|
|
|
req.setUrl(url);
|
|
|
|
webView->load(req);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (selectLine) {
|
2011-03-02 16:57:41 +01:00
|
|
|
p_QupZilla->locationBar()->setFocus();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2012-04-03 20:23:15 +02:00
|
|
|
if (openFlags & Qz::NT_SelectedTab || openFlags & Qz::NT_NotSelectedTab) {
|
2011-05-21 11:19:19 +02:00
|
|
|
m_isClosingToLastTabIndex = true;
|
2011-07-11 20:30:49 +02:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::closeTab(int index)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (index == -1) {
|
2011-03-02 16:57:41 +01:00
|
|
|
index = currentIndex();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
|
|
|
if (!webTab) {
|
2011-07-11 20:30:49 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
TabbedWebView* webView = webTab->view();
|
2012-04-03 20:23:15 +02:00
|
|
|
WebPage* webPage = webView->page();
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
if (count() == 1) {
|
|
|
|
if (m_dontQuitWithOneTab) {
|
2012-02-18 23:21:36 +01:00
|
|
|
webView->load(m_urlOnNewTab);
|
2012-01-21 20:27:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p_QupZilla->close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-14 11:46:06 +01:00
|
|
|
if (webTab->isPinned()) {
|
2011-10-14 23:12:10 +02:00
|
|
|
emit pinnedTabClosed();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-14 23:12:10 +02:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
m_locationBars->removeWidget(webView->webTab()->locationBar());
|
|
|
|
disconnect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
2011-07-29 15:39:43 +02:00
|
|
|
disconnect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged()));
|
2011-07-11 20:30:49 +02:00
|
|
|
disconnect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
|
|
|
|
//Save last tab url and history
|
2012-03-12 18:22:01 +01:00
|
|
|
m_closedTabsManager->saveView(webTab, index);
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) {
|
2011-07-11 20:30:49 +02:00
|
|
|
setCurrentIndex(m_lastTabIndex);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2012-01-04 16:00:59 +01:00
|
|
|
if (count() == 2 && m_hideTabBarWithOneTab) {
|
|
|
|
tabBar()->setVisible(false);
|
|
|
|
}
|
|
|
|
|
2012-02-27 17:51:57 +01:00
|
|
|
m_lastBackgroundTabIndex = -1;
|
|
|
|
|
2012-01-14 11:46:06 +01:00
|
|
|
webPage->disconnectObjects();
|
|
|
|
webView->disconnectObjects();
|
|
|
|
webTab->disconnectObjects();
|
|
|
|
|
|
|
|
webTab->deleteLater();
|
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
|
|
|
{
|
2012-03-16 23:28:23 +01:00
|
|
|
if (index < 0 || m_isRestoringState) {
|
2012-02-27 17:51:57 +01:00
|
|
|
return;
|
2012-01-04 16:00:59 +01:00
|
|
|
}
|
2012-02-27 17:51:57 +01:00
|
|
|
|
2012-04-03 20:23:15 +02:00
|
|
|
m_isClosingToLastTabIndex = m_lastBackgroundTabIndex == index;
|
2012-02-27 17:51:57 +01:00
|
|
|
m_lastBackgroundTabIndex = -1;
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
|
|
|
LocationBar* locBar = webTab->locationBar();
|
2012-02-27 17:51:57 +01:00
|
|
|
|
|
|
|
if (m_locationBars->indexOf(locBar) != -1) {
|
|
|
|
m_locationBars->setCurrentWidget(locBar);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-02-27 17:51:57 +01:00
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
webTab->setCurrentTab();
|
2012-02-27 17:51:57 +01:00
|
|
|
p_QupZilla->currentTabChanged();
|
|
|
|
m_tabBar->updateCloseButton(index);
|
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
|
|
|
|
2011-05-21 11:19:19 +02:00
|
|
|
m_isClosingToLastTabIndex = false;
|
2012-02-27 17:51:57 +01:00
|
|
|
m_lastBackgroundTabIndex = -1;
|
2011-05-21 11:19:19 +02:00
|
|
|
}
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
void TabWidget::startTabAnimation(int index)
|
|
|
|
{
|
|
|
|
if (index == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLabel* label = qobject_cast<QLabel*>(m_tabBar->tabButton(index, QTabBar::LeftSide));
|
|
|
|
if (!label) {
|
|
|
|
label = new QLabel();
|
|
|
|
m_tabBar->setTabButton(index, QTabBar::LeftSide, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (label->movie()) {
|
|
|
|
label->movie()->start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMovie* movie = new QMovie(":icons/other/progress.gif", QByteArray(), label);
|
|
|
|
movie->setSpeed(70);
|
|
|
|
movie->start();
|
|
|
|
|
|
|
|
label->setMovie(movie);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::stopTabAnimation(int index)
|
|
|
|
{
|
|
|
|
if (index == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLabel* label = qobject_cast<QLabel*>(m_tabBar->tabButton(index, QTabBar::LeftSide));
|
|
|
|
|
|
|
|
if (label && label->movie()) {
|
|
|
|
label->movie()->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::setTabIcon(int index, const QIcon &icon)
|
|
|
|
{
|
|
|
|
if (index == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLabel* label = qobject_cast<QLabel*>(m_tabBar->tabButton(index, QTabBar::LeftSide));
|
|
|
|
if (!label) {
|
|
|
|
label = new QLabel();
|
|
|
|
label->resize(16, 16);
|
|
|
|
m_tabBar->setTabButton(index, QTabBar::LeftSide, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
label->setPixmap(icon.pixmap(16, 16));
|
|
|
|
}
|
|
|
|
|
2012-02-27 17:51:57 +01:00
|
|
|
void TabWidget::setTabText(int index, const QString &text)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-02-27 17:51:57 +01:00
|
|
|
QString newtext = text;
|
|
|
|
newtext.replace("&", "&&"); // Avoid Alt+letter shortcuts
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
if (WebTab* webTab = weTab(index)) {
|
2012-02-27 17:51:57 +01:00
|
|
|
if (webTab->isPinned()) {
|
|
|
|
newtext = "";
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-27 17:51:57 +01:00
|
|
|
QTabWidget::setTabText(index, newtext);
|
|
|
|
}
|
2011-05-21 11:19:19 +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-02-27 17:51:57 +01:00
|
|
|
void TabWidget::reloadTab(int index)
|
|
|
|
{
|
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-02-27 17:51:57 +01:00
|
|
|
void TabWidget::showTabBar()
|
|
|
|
{
|
|
|
|
if (count() == 1 && m_hideTabBarWithOneTab) {
|
|
|
|
tabBar()->hide();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tabBar()->show();
|
|
|
|
}
|
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-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-03-11 15:17:12 +01:00
|
|
|
WebTab* akt = weTab(index);
|
2011-04-18 21:35:57 +02:00
|
|
|
|
2011-11-06 17:01:23 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-29 15:45:29 +01:00
|
|
|
int TabWidget::duplicateTab(int index)
|
2011-04-08 17:27:08 +02:00
|
|
|
{
|
2012-03-12 18:22:01 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
2012-03-11 15:17:12 +01:00
|
|
|
|
2012-03-12 18:22:01 +01:00
|
|
|
const QUrl &url = webTab->url();
|
2012-03-16 23:28:23 +01:00
|
|
|
const QString &title = webTab->title();
|
2012-03-12 18:22:01 +01:00
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void TabWidget::restoreClosedTab()
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
QAction* action = qobject_cast<QAction*>(sender());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (action && action->data().toInt() != 0) {
|
2011-05-07 12:59:53 +02:00
|
|
|
tab = m_closedTabsManager->getTabAt(action->data().toInt());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-05-07 12:59:53 +02:00
|
|
|
tab = m_closedTabsManager->getFirstClosedTab();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-11 17:03:18 +01:00
|
|
|
|
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);
|
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
|
|
|
|
2012-02-04 19:43:43 +01:00
|
|
|
const QList<ClosedTabsManager::Tab> &closedTabs = m_closedTabsManager->allClosedTabs();
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2012-01-24 19:12:31 +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
|
|
|
|
2011-05-16 21:36:39 +02:00
|
|
|
m_closedTabsManager->clearList();
|
|
|
|
}
|
|
|
|
|
2011-07-28 21:59:56 +02:00
|
|
|
void TabWidget::clearClosedTabsList()
|
|
|
|
{
|
|
|
|
m_closedTabsManager->clearList();
|
|
|
|
}
|
|
|
|
|
2011-05-07 12:59:53 +02:00
|
|
|
bool TabWidget::canRestoreTab()
|
|
|
|
{
|
|
|
|
return m_closedTabsManager->isClosedTabAvailable();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-23 00:23:45 +01:00
|
|
|
void TabWidget::aboutToShowClosedTabsMenu()
|
|
|
|
{
|
2012-01-23 11:05:47 +01:00
|
|
|
if (!m_closedInsteadOpened) {
|
2012-01-24 19:12:31 +01:00
|
|
|
aboutToShowTabsMenu();
|
2012-01-23 00:23:45 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-01-24 19:12:31 +01:00
|
|
|
m_menuTabs->clear();
|
|
|
|
int i = 0;
|
|
|
|
foreach(const ClosedTabsManager::Tab & tab, this->closedTabsManager()->allClosedTabs()) {
|
|
|
|
QString title = tab.title;
|
|
|
|
if (title.length() > 40) {
|
|
|
|
title.truncate(40);
|
|
|
|
title += "..";
|
|
|
|
}
|
|
|
|
m_menuTabs->addAction(_iconForUrl(tab.url), title, this, SLOT(restoreClosedTab()))->setData(i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
m_menuTabs->addSeparator();
|
|
|
|
if (i == 0) {
|
|
|
|
m_menuTabs->addAction(tr("Empty"))->setEnabled(false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_menuTabs->addAction(tr("Restore All Closed Tabs"), this, SLOT(restoreAllClosedTabs()));
|
|
|
|
m_menuTabs->addAction(tr("Clear list"), this, SLOT(clearClosedTabsList()));
|
|
|
|
}
|
2012-01-23 00:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 21:35:57 +02:00
|
|
|
QList<WebTab*> TabWidget::allTabs(bool withPinned)
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
QByteArray data;
|
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QFile file(mApp->getActiveProfilPath() + "pinnedtabs.dat");
|
2011-03-25 19:16:21 +01:00
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(data);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::restorePinnedTabs()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
QFile file(mApp->getActiveProfilPath() + "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
|
|
|
|
|
|
|
QStringList pinnedTabs;
|
|
|
|
stream >> pinnedTabs;
|
|
|
|
QList<QByteArray> tabHistory;
|
|
|
|
stream >> tabHistory;
|
|
|
|
|
2012-03-16 23:28:23 +01:00
|
|
|
m_isRestoringState = true;
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
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()) {
|
2012-01-22 00:20:29 +01:00
|
|
|
addedIndex = addView(QUrl(), Qz::NT_CleanSelectedTab);
|
2012-03-11 15:17:12 +01:00
|
|
|
|
|
|
|
weTab(i)->p_restoreTab(url, historyState);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-25 19:16:21 +01:00
|
|
|
addedIndex = addView(url);
|
|
|
|
}
|
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
|
|
|
emit pinnedTabAdded();
|
|
|
|
}
|
2011-03-25 19:16:21 +01:00
|
|
|
|
2011-12-07 21:48:50 +01:00
|
|
|
m_tabBar->updateCloseButton(addedIndex);
|
2011-03-25 19:16:21 +01:00
|
|
|
m_tabBar->moveTab(addedIndex, i);
|
|
|
|
}
|
2012-03-16 23:28:23 +01:00
|
|
|
|
|
|
|
m_isRestoringState = false;
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QByteArray TabWidget::saveState()
|
|
|
|
{
|
2012-03-11 15:17:12 +01:00
|
|
|
QList<WebTab::SavedTab> tabList;
|
|
|
|
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
WebTab* webTab = weTab(i);
|
|
|
|
if (!webTab || webTab->isPinned()) {
|
|
|
|
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
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
foreach(const WebTab::SavedTab & tab, tabList) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
bool TabWidget::restoreState(const QByteArray &state)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-03-13 17:51:06 +01:00
|
|
|
QDataStream stream(state);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (stream.atEnd()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
int tabListCount = 0;
|
|
|
|
int currentTab = 0;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
stream >> tabListCount;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-16 23:28:23 +01:00
|
|
|
m_isRestoringState = true;
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
for (int i = 0; i < tabListCount; ++i) {
|
|
|
|
WebTab::SavedTab tab;
|
|
|
|
stream >> tab;
|
|
|
|
|
|
|
|
int index = addView(QUrl(), Qz::NT_CleanSelectedTab);
|
|
|
|
weTab(index)->restoreTab(tab);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-04-07 18:00:26 +02:00
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
stream >> currentTab;
|
|
|
|
|
2012-03-16 23:28:23 +01:00
|
|
|
m_isRestoringState = false;
|
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
setCurrentIndex(currentTab);
|
2012-03-11 15:17:12 +01:00
|
|
|
currentTabChanged(currentTab);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-14 11:46:06 +01:00
|
|
|
void TabWidget::disconnectObjects()
|
|
|
|
{
|
|
|
|
disconnect(this);
|
|
|
|
disconnect(mApp);
|
2012-03-05 13:16:34 +01:00
|
|
|
disconnect(p_QupZilla);
|
2012-01-14 11:46:06 +01:00
|
|
|
disconnect(p_QupZilla->ipLabel());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|