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"
|
|
|
|
#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"
|
2013-02-09 13:00:45 +01:00
|
|
|
#include "qzsettings.h"
|
2013-03-23 20:39:55 +01:00
|
|
|
#include "qtwin.h"
|
2011-03-26 13:34:08 +01:00
|
|
|
|
2013-03-23 20:39:55 +01:00
|
|
|
#include <QTimer>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMovie>
|
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>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QWebHistory>
|
2014-02-10 18:38:47 +01:00
|
|
|
#include <QWebFrame>
|
2012-05-27 12:44:56 +02:00
|
|
|
#include <QClipboard>
|
2012-03-05 23:34:00 +01:00
|
|
|
#include <QFile>
|
2013-11-26 14:14:36 +01:00
|
|
|
#include <QScrollArea>
|
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);
|
|
|
|
}
|
|
|
|
|
2011-11-05 18:36:53 +01:00
|
|
|
TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
|
2013-11-26 14:14:36 +01:00
|
|
|
: TabStackedWidget(parent)
|
2011-11-06 17:01:23 +01:00
|
|
|
, p_QupZilla(mainClass)
|
2013-02-17 11:05:35 +01:00
|
|
|
, m_lastTabIndex(-1)
|
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);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(currentChanged(int)), p_QupZilla, SLOT(refreshHistory()));
|
|
|
|
|
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-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
|
|
|
|
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");
|
2013-11-26 14:14:36 +01:00
|
|
|
m_menuTabs = new MenuTabs(m_tabBar);
|
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()));
|
|
|
|
|
2014-01-01 18:23:56 +01:00
|
|
|
// Copy of buttons
|
2013-11-26 14:14:36 +01:00
|
|
|
m_buttonListTabs2 = new ToolButton(m_tabBar);
|
|
|
|
m_buttonListTabs2->setObjectName("tabwidget-button-opentabs");
|
2014-01-01 18:23:56 +01:00
|
|
|
m_buttonListTabs2->setProperty("outside-tabbar", true);
|
2013-11-26 14:14:36 +01:00
|
|
|
m_buttonListTabs2->setMenu(m_menuTabs);
|
|
|
|
m_buttonListTabs2->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
m_buttonListTabs2->setToolTip(tr("List of tabs"));
|
|
|
|
m_buttonListTabs2->setAutoRaise(true);
|
|
|
|
m_buttonListTabs2->setFocusPolicy(Qt::NoFocus);
|
2014-01-01 18:23:56 +01:00
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
m_buttonAddTab2 = new AddTabButton(this, m_tabBar);
|
2014-01-01 18:23:56 +01:00
|
|
|
m_buttonAddTab2->setProperty("outside-tabbar", true);
|
2013-11-26 14:14:36 +01:00
|
|
|
connect(m_buttonAddTab2, SIGNAL(clicked()), p_QupZilla, SLOT(addTab()));
|
2014-01-01 18:23:56 +01:00
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
m_tabBar->addMainBarWidget(m_buttonAddTab2, Qt::AlignRight);
|
|
|
|
m_tabBar->addMainBarWidget(m_buttonListTabs2, Qt::AlignRight);
|
|
|
|
m_buttonAddTab2->hide();
|
|
|
|
m_buttonListTabs2->hide();
|
|
|
|
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");
|
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();
|
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
|
|
|
|
|
|
|
if (m_closedInsteadOpened) {
|
|
|
|
disconnect(m_menuTabs, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
connect(m_menuTabs, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
void TabWidget::tabBarOverFlowChanged(bool overFlowed)
|
|
|
|
{
|
|
|
|
m_buttonAddTab2->setVisible(overFlowed);
|
|
|
|
m_buttonListTabs2->setVisible(overFlowed);
|
|
|
|
}
|
|
|
|
|
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;
|
2012-08-09 04:00:09 +02:00
|
|
|
//RTL Support
|
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
2012-08-20 21:50:31 +02:00
|
|
|
posX = qMax(posX - m_buttonAddTab->width(), m_buttonListTabs->width());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
posX = qMin(posX, m_tabBar->width() - m_buttonAddTab->width() - m_buttonListTabs->width());
|
2012-08-09 04:00:09 +02: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();
|
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-09-04 12:42:45 +02:00
|
|
|
title.replace(QLatin1Char('&'), QLatin1String("&&"));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (title.length() > 40) {
|
2011-03-02 16:57:41 +01:00
|
|
|
title.truncate(40);
|
2012-09-04 12:42:45 +02:00
|
|
|
title += QLatin1String("..");
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
action->setText(title);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
// needed when clicking on action of the current tab
|
|
|
|
m_tabBar->ensureVisible(tab->tabIndex());
|
|
|
|
|
2013-08-21 14:38:37 +02:00
|
|
|
setCurrentIndex(tab->tabIndex());
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
int TabWidget::addView(const QUrl &url, const Qz::NewTabPositionFlags &openFlags, bool selectLine, bool pinned)
|
2012-01-18 16:52:30 +01:00
|
|
|
{
|
2013-11-26 14:14:36 +01:00
|
|
|
return addView(QNetworkRequest(url), openFlags, selectLine, pinned);
|
2012-01-18 16:52:30 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
int TabWidget::addView(const QNetworkRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine, bool pinned)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-11-26 14:14:36 +01:00
|
|
|
return addView(req, tr("New tab"), openFlags, selectLine, -1, pinned);
|
2012-03-10 13:57:50 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
int TabWidget::addView(const QUrl &url, const QString &title, const Qz::NewTabPositionFlags &openFlags, bool selectLine, int position, bool pinned)
|
2012-03-10 13:57:50 +01:00
|
|
|
{
|
2013-11-26 14:14:36 +01:00
|
|
|
return addView(QNetworkRequest(url), title, openFlags, selectLine, position, pinned);
|
2012-03-10 13:57:50 +01:00
|
|
|
}
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
int TabWidget::addView(QNetworkRequest req, const QString &title, const Qz::NewTabPositionFlags &openFlags, bool selectLine, int position, bool pinned)
|
2012-03-10 13:57:50 +01:00
|
|
|
{
|
2013-03-23 20:39:55 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
if (p_QupZilla->isTransparentBackgroundAllowed()) {
|
|
|
|
QtWin::extendFrameIntoClientArea(p_QupZilla);
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-12 13:50:06 +01:00
|
|
|
// Pause updates, so pages that loads instantly (eg. qupzilla: internal pages) don't cause
|
|
|
|
// flickering in navigationbar (load button and locationbar)
|
|
|
|
// Also disable updates of tabwidget, so background of webview doesn't flashes
|
|
|
|
p_QupZilla->navigationBar()->pauseUpdates();
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2013-11-26 14:14:36 +01:00
|
|
|
index = addTab(new WebTab(p_QupZilla, locBar), QString(), pinned);
|
2011-12-11 17:03:18 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-11-26 14:14:36 +01:00
|
|
|
index = insertTab(position, new WebTab(p_QupZilla, locBar), QString(), pinned);
|
2011-12-11 17:03:18 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
TabbedWebView* webView = weTab(index)->view();
|
2011-07-11 20:30:49 +02:00
|
|
|
locBar->setWebView(webView);
|
2014-02-12 13:50:06 +01:00
|
|
|
locBar->showUrl(url);
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
setTabText(index, title);
|
2012-04-22 20:51:28 +02:00
|
|
|
setTabIcon(index, qIconProvider->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-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-07-13 22:45:40 +02:00
|
|
|
req.setUrl(url);
|
2012-03-10 13:57:50 +01:00
|
|
|
webView->load(req);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2013-02-28 19:38:12 +01:00
|
|
|
if (selectLine && p_QupZilla->locationBar()->text().isEmpty()) {
|
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
|
|
|
|
2013-02-06 17:42:32 +01:00
|
|
|
if (openFlags & Qz::NT_NotSelectedTab) {
|
|
|
|
WebTab* currentWebTab = weTab();
|
|
|
|
// Workarounding invalid QWebPage::viewportSize() until QWebView is shown
|
|
|
|
// Fixes invalid scrolling to anchor(#) links
|
|
|
|
if (currentWebTab && currentWebTab->view()) {
|
|
|
|
TabbedWebView* currentView = currentWebTab->view();
|
|
|
|
webView->resize(currentView->size());
|
|
|
|
webView->page()->setViewportSize(currentView->page()->viewportSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 13:50:06 +01:00
|
|
|
setUpdatesEnabled(true);
|
|
|
|
|
2013-03-23 20:39:55 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
QTimer::singleShot(0, p_QupZilla, SLOT(applyBlurToMainWindow()));
|
|
|
|
#endif
|
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());
|
|
|
|
tab->locationBar()->setWebView(tab->view());
|
|
|
|
|
|
|
|
int index = addTab(tab, QString());
|
|
|
|
setTabText(index, tab->title());
|
2013-09-03 08:29:12 +02:00
|
|
|
|
|
|
|
if (!tab->isLoading()) {
|
|
|
|
setTabIcon(index, tab->icon());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
startTabAnimation(index);
|
|
|
|
}
|
2013-05-13 22:01:36 +02:00
|
|
|
|
|
|
|
connect(tab->view(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
|
|
|
connect(tab->view(), SIGNAL(changed()), mApp, SLOT(setStateChanged()));
|
|
|
|
connect(tab->view(), SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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-03-11 15:17:12 +01:00
|
|
|
WebTab* webTab = weTab(index);
|
2012-08-24 19:24:48 +02:00
|
|
|
if (!webTab || !validIndex(index)) {
|
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-09-04 12:42:45 +02:00
|
|
|
if (!force && webView->url().toString() == QLatin1String("qupzilla:restore") && mApp->restoreManager()) {
|
2012-08-21 20:28:38 +02:00
|
|
|
// Don't close restore page!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!force && count() == 1) {
|
2012-04-17 14:00:32 +02:00
|
|
|
if (m_dontQuitWithOneTab && mApp->windowCount() == 1) {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 19:27:58 +01:00
|
|
|
// Save last tab url and history
|
|
|
|
m_closedTabsManager->saveView(webTab, index);
|
|
|
|
|
2014-02-10 18:38:47 +01:00
|
|
|
// window.onbeforeunload handling
|
2014-02-11 22:25:32 +01:00
|
|
|
if (!webView->onBeforeUnload()) {
|
|
|
|
m_closedTabsManager->takeLastClosedTab();
|
|
|
|
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)));
|
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)));
|
2012-04-25 11:35:13 +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-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();
|
2013-08-21 14:38:37 +02:00
|
|
|
|
|
|
|
if (!m_closedInsteadOpened && m_menuTabs->isVisible()) {
|
|
|
|
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
|
|
|
}
|
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-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index) || 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-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
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
webTab->setCurrentTab();
|
2012-02-27 17:51:57 +01:00
|
|
|
p_QupZilla->currentTabChanged();
|
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;
|
2012-09-03 22:40:52 +02:00
|
|
|
m_lastTabIndex = before;
|
2011-05-21 11:19:19 +02:00
|
|
|
}
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
void TabWidget::startTabAnimation(int index)
|
|
|
|
{
|
2012-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index)) {
|
2012-03-13 17:51:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:22:38 +01:00
|
|
|
QLabel* label = qobject_cast<QLabel*>(m_tabBar->tabButton(index, m_tabBar->iconButtonPosition()));
|
2012-03-13 17:51:06 +01:00
|
|
|
if (!label) {
|
|
|
|
label = new QLabel();
|
2013-03-03 21:04:21 +01:00
|
|
|
label->setObjectName("tab-icon");
|
2013-02-20 21:22:38 +01:00
|
|
|
m_tabBar->setTabButton(index, m_tabBar->iconButtonPosition(), label);
|
2012-03-13 17:51:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (label->movie()) {
|
|
|
|
label->movie()->start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMovie* movie = new QMovie(":icons/other/progress.gif", QByteArray(), label);
|
|
|
|
movie->start();
|
|
|
|
|
|
|
|
label->setMovie(movie);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::stopTabAnimation(int index)
|
|
|
|
{
|
2012-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index)) {
|
2012-03-13 17:51:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:22:38 +01:00
|
|
|
QLabel* label = qobject_cast<QLabel*>(m_tabBar->tabButton(index, m_tabBar->iconButtonPosition()));
|
2012-03-13 17:51:06 +01:00
|
|
|
|
|
|
|
if (label && label->movie()) {
|
|
|
|
label->movie()->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-13 17:51:06 +01:00
|
|
|
void TabWidget::setTabIcon(int index, const QIcon &icon)
|
|
|
|
{
|
2012-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index)) {
|
2012-03-13 17:51:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-20 21:22:38 +01:00
|
|
|
QLabel* label = qobject_cast<QLabel*>(m_tabBar->tabButton(index, m_tabBar->iconButtonPosition()));
|
2012-03-13 17:51:06 +01:00
|
|
|
if (!label) {
|
|
|
|
label = new QLabel();
|
2013-03-03 21:04:21 +01:00
|
|
|
label->setObjectName("tab-icon");
|
2012-03-13 17:51:06 +01:00
|
|
|
label->resize(16, 16);
|
2013-02-20 21:22:38 +01:00
|
|
|
m_tabBar->setTabButton(index, m_tabBar->iconButtonPosition(), label);
|
2012-03-13 17:51:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-08-24 19:24:48 +02:00
|
|
|
if (!validIndex(index)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-27 17:51:57 +01:00
|
|
|
QString newtext = text;
|
2012-09-04 12:42:45 +02:00
|
|
|
newtext.replace(QLatin1Char('&'), QLatin1String("&&")); // Avoid Alt+letter shortcuts
|
2012-02-27 17:51:57 +01:00
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
if (WebTab* webTab = weTab(index)) {
|
2012-02-27 17:51:57 +01:00
|
|
|
if (webTab->isPinned()) {
|
2012-09-02 11:42:41 +02:00
|
|
|
newtext.clear();
|
2012-02-27 17:51:57 +01:00
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-10 18:29:22 +02:00
|
|
|
setTabToolTip(index, text);
|
2013-11-26 14:14:36 +01:00
|
|
|
TabStackedWidget::setTabText(index, newtext);
|
2012-02-27 17:51:57 +01:00
|
|
|
}
|
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-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;
|
|
|
|
}
|
|
|
|
|
2013-02-09 13:00:45 +01:00
|
|
|
TabBar* TabWidget::getTabBar() const
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
disconnect(tab->view(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
|
|
|
|
disconnect(tab->view(), SIGNAL(changed()), mApp, SLOT(setStateChanged()));
|
|
|
|
disconnect(tab->view(), SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
|
|
|
|
|
|
|
|
QupZilla* window = mApp->makeNewWindow(Qz::BW_NewWindow);
|
|
|
|
tab->moveToWindow(window);
|
|
|
|
window->openWithTab(tab);
|
|
|
|
|
|
|
|
if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) {
|
|
|
|
setCurrentIndex(m_lastTabIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
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);
|
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
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolButton* TabWidget::buttonListTabs() const
|
|
|
|
{
|
|
|
|
return m_buttonListTabs;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddTabButton* TabWidget::buttonAddTab() const
|
|
|
|
{
|
|
|
|
return m_buttonAddTab;
|
|
|
|
}
|
|
|
|
|
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;
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const ClosedTabsManager::Tab &tab, closedTabsManager()->allClosedTabs()) {
|
2012-01-24 19:12:31 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2012-06-26 11:49:39 +02:00
|
|
|
if (mApp->isPrivateSession()) {
|
|
|
|
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
|
|
|
|
2012-04-04 18:48:54 +02:00
|
|
|
QFile file(mApp->currentProfilePath() + "pinnedtabs.dat");
|
2011-03-25 19:16:21 +01:00
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
file.write(data);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::restorePinnedTabs()
|
|
|
|
{
|
2012-06-26 11:49:39 +02:00
|
|
|
if (mApp->isPrivateSession()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-04 18:48:54 +02:00
|
|
|
QFile file(mApp->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;
|
|
|
|
if (version != Qz::sessionVersion) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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()) {
|
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
|
|
|
}
|
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()
|
|
|
|
{
|
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);
|
|
|
|
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
|
|
|
|
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-03-16 23:28:23 +01:00
|
|
|
m_isRestoringState = true;
|
2013-02-23 11:59:08 +01:00
|
|
|
setUpdatesEnabled(false);
|
2012-03-16 23:28:23 +01:00
|
|
|
|
2013-02-15 22:18:46 +01:00
|
|
|
Qz::BrowserWindow type = p_QupZilla->windowType();
|
|
|
|
|
|
|
|
if (type == Qz::BW_FirstAppWindow || type == Qz::BW_MacFirstWindow) {
|
|
|
|
restorePinnedTabs();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
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-16 23:28:23 +01:00
|
|
|
m_isRestoringState = false;
|
2013-02-23 11:59:08 +01:00
|
|
|
setUpdatesEnabled(true);
|
|
|
|
|
2012-03-16 23:28:23 +01:00
|
|
|
|
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-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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|