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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "webview.h"
|
|
|
|
#include "webpage.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "tabbar.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"
|
|
|
|
#include "toolbutton.h"
|
2011-03-26 13:34:08 +01:00
|
|
|
|
|
|
|
class NewTabButton : public QToolButton
|
|
|
|
{
|
|
|
|
public:
|
2011-11-06 17:01:23 +01:00
|
|
|
explicit NewTabButton(QWidget* parent) : QToolButton(parent) {
|
2011-04-19 20:46:31 +02:00
|
|
|
#ifndef Q_WS_WIN
|
|
|
|
setIcon(QIcon::fromTheme("list-add"));
|
2011-11-06 17:01:23 +01:00
|
|
|
setIconSize(QSize(16, 16));
|
2011-04-19 20:46:31 +02:00
|
|
|
setAutoRaise(true);
|
|
|
|
#endif
|
2011-03-26 13:34:08 +01:00
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
QSize sizeHint() const {
|
2011-03-26 13:34:08 +01:00
|
|
|
QSize siz = QToolButton::sizeHint();
|
2011-04-03 21:50:44 +02:00
|
|
|
siz.setWidth(26);
|
2011-03-26 13:34:08 +01:00
|
|
|
return siz;
|
|
|
|
}
|
|
|
|
|
2011-04-19 20:46:31 +02:00
|
|
|
#ifdef Q_WS_WIN
|
2011-03-26 13:34:08 +01:00
|
|
|
private:
|
2011-11-06 17:01:23 +01:00
|
|
|
void paintEvent(QPaintEvent*) {
|
2011-03-26 13:34:08 +01:00
|
|
|
QPainter p(this);
|
|
|
|
QStyleOptionTabV3 opt;
|
|
|
|
opt.init(this);
|
|
|
|
style()->drawControl(QStyle::CE_TabBarTab, &opt, &p, this);
|
|
|
|
|
|
|
|
QPixmap pix(":/icons/other/list-add.png");
|
|
|
|
QRect r = this->rect();
|
2011-11-06 17:01:23 +01:00
|
|
|
r.setHeight(r.height() + 3);
|
|
|
|
r.setWidth(r.width() + 3);
|
2011-03-26 13:34:08 +01:00
|
|
|
style()->drawItemPixmap(&p, r, Qt::AlignCenter, pix);
|
|
|
|
}
|
2011-04-19 20:46:31 +02:00
|
|
|
#endif
|
2011-03-26 13:34:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class TabListButton : public QToolButton
|
|
|
|
{
|
|
|
|
public:
|
2011-11-06 17:01:23 +01:00
|
|
|
explicit TabListButton(QWidget* parent) : QToolButton(parent) {
|
2011-03-26 13:34:08 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QSize sizeHint() const {
|
2011-03-26 13:34:08 +01:00
|
|
|
QSize siz = QToolButton::sizeHint();
|
|
|
|
siz.setWidth(20);
|
|
|
|
return siz;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-11-06 17:01:23 +01:00
|
|
|
void paintEvent(QPaintEvent*) {
|
2011-03-26 13:34:08 +01:00
|
|
|
QPainter p(this);
|
|
|
|
QStyleOptionToolButton opt;
|
|
|
|
opt.init(this);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (isDown()) {
|
2011-03-26 13:34:08 +01:00
|
|
|
opt.state |= QStyle::State_On;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (opt.state & QStyle::State_MouseOver) {
|
2011-03-26 13:34:08 +01:00
|
|
|
opt.activeSubControls = QStyle::SC_ToolButton;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (!isChecked() && !isDown()) {
|
|
|
|
opt.state |= QStyle::State_Raised;
|
|
|
|
}
|
2011-03-26 13:34:08 +01:00
|
|
|
opt.state |= QStyle::State_AutoRaise;
|
|
|
|
|
|
|
|
style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this);
|
|
|
|
}
|
|
|
|
};
|
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)
|
|
|
|
, m_isClosingToLastTabIndex(false)
|
|
|
|
, m_closedTabsManager(new ClosedTabsManager(this))
|
|
|
|
, 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(backTab(int)), this, SLOT(backTab(int)));
|
|
|
|
connect(m_tabBar, SIGNAL(forwardTab(int)), this, SLOT(forwardTab(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);
|
|
|
|
m_buttonListTabs->setToolTip(tr("Show list of opened tabs"));
|
2011-09-11 19:15:06 +02:00
|
|
|
m_buttonListTabs->setAutoRaise(true);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-23 14:44:18 +02:00
|
|
|
m_buttonAddTab = new ToolButton(this);
|
|
|
|
m_buttonAddTab->setObjectName("tabwidget-button-addtab");
|
|
|
|
m_buttonAddTab->setAutoRaise(true);
|
|
|
|
m_buttonAddTab->setToolTip(tr("New Tab"));
|
|
|
|
|
|
|
|
connect(m_buttonAddTab, SIGNAL(clicked()), p_QupZilla, SLOT(addTab()));
|
2011-09-11 19:15:06 +02:00
|
|
|
connect(m_menuTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowTabsMenu()));
|
2011-04-19 20:46:31 +02:00
|
|
|
|
|
|
|
loadSettings();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::loadSettings()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
|
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();
|
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);
|
|
|
|
}
|
|
|
|
|
2011-11-09 16:58:25 +01:00
|
|
|
void TabWidget::createKeyPressEvent(QKeyEvent* event)
|
2011-11-07 19:56:53 +01:00
|
|
|
{
|
|
|
|
QTabWidget::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
WebView* actView = weView();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!actView) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
for (int i = 0; i < count(); i++) {
|
2011-03-02 16:57:41 +01:00
|
|
|
WebView* view = weView(i);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!view) {
|
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);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (view == actView) {
|
2011-09-11 19:15:06 +02:00
|
|
|
action->setIcon(QIcon(":/icons/menu/dot.png"));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-12-07 21:32:47 +01:00
|
|
|
action->setIcon(view->siteIcon());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
if (view->title().isEmpty()) {
|
|
|
|
if (view->isLoading()) {
|
|
|
|
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 {
|
2011-03-02 16:57:41 +01:00
|
|
|
QString title = view->title();
|
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();
|
2011-10-21 23:26:34 +02:00
|
|
|
m_menuTabs->addAction(tr("Actually 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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-11 17:03:18 +01:00
|
|
|
int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool selectLine, int position)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-05-21 11:19:19 +02:00
|
|
|
m_lastTabIndex = currentIndex();
|
|
|
|
|
2011-12-05 16:12:48 +01:00
|
|
|
if (url.isEmpty() && openIn != CleanPage && openIn != CleanSelectedPage) {
|
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
|
|
|
|
2011-12-23 17:32:55 +01:00
|
|
|
if (openIn == NewBackgroundTab) {
|
|
|
|
position = currentIndex() + 1;
|
|
|
|
}
|
|
|
|
|
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), "");
|
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
WebView* webView = weView(index);
|
|
|
|
locBar->setWebView(webView);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
setTabText(index, title);
|
2011-07-11 20:30:49 +02:00
|
|
|
webView->animationLoading(index, true)->movie()->stop();
|
2011-11-06 17:01:23 +01:00
|
|
|
webView->animationLoading(index, false)->setPixmap(_iconForUrl(url).pixmap(16, 16));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-05 16:12:48 +01:00
|
|
|
if (openIn == NewSelectedTab || openIn == CleanSelectedPage) {
|
2011-03-02 16:57:41 +01:00
|
|
|
setCurrentIndex(index);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
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()) {
|
2011-09-14 17:40:16 +02:00
|
|
|
webView->load(url);
|
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
|
|
|
|
2011-12-05 16:12:48 +01:00
|
|
|
if (openIn == NewSelectedTab || openIn == CleanSelectedPage) {
|
2011-05-21 11:19:19 +02:00
|
|
|
m_isClosingToLastTabIndex = true;
|
2011-07-11 20:30:49 +02:00
|
|
|
m_locationBars->setCurrentWidget(locBar);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void TabWidget::setTabText(int index, const QString &text)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-10-14 23:12:10 +02:00
|
|
|
QString newtext = text;
|
2011-11-05 18:36:53 +01:00
|
|
|
newtext.remove("&"); // Avoid Alt+letter shortcuts
|
2011-03-25 19:16:21 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (WebTab* webTab = qobject_cast<WebTab*>(p_QupZilla->tabWidget()->widget(index))) {
|
|
|
|
if (webTab->isPinned()) {
|
2011-03-25 19:16:21 +01:00
|
|
|
newtext = "";
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
2011-11-03 20:12:35 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QTabWidget::setTabText(index, newtext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::closeTab(int index)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (count() == 1) {
|
2011-12-23 05:05:20 +01:00
|
|
|
p_QupZilla->close();
|
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
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
WebView* webView = weView(index);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!webView) {
|
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
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (webView->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
|
2011-12-11 17:03:18 +01:00
|
|
|
m_closedTabsManager->saveView(webView, 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
|
|
|
|
2011-12-04 20:09:44 +01:00
|
|
|
widget(index)->deleteLater();
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (count() == 1 && m_hideTabBarWithOneTab) {
|
2011-07-11 20:30:49 +02:00
|
|
|
tabBar()->setVisible(false);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-05-21 11:19:19 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
// if (count() < 1)
|
|
|
|
// p_QupZilla->close();
|
|
|
|
}
|
|
|
|
|
2011-05-21 11:19:19 +02:00
|
|
|
void TabWidget::tabMoved(int before, int after)
|
|
|
|
{
|
|
|
|
Q_UNUSED(before)
|
|
|
|
Q_UNUSED(after)
|
|
|
|
m_isClosingToLastTabIndex = false;
|
|
|
|
}
|
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
void TabWidget::currentTabChanged(int index)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (index < 0) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-05-21 11:19:19 +02:00
|
|
|
m_isClosingToLastTabIndex = false;
|
2011-07-11 20:30:49 +02:00
|
|
|
WebView* webView = weView();
|
2011-08-03 22:39:30 +02:00
|
|
|
LocationBar* locBar = webView->webTab()->locationBar();
|
2011-05-21 11:19:19 +02:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
QString title = webView->title();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (title.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
title = tr("No Named Page");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
p_QupZilla->setWindowTitle(title + " - QupZilla");
|
2011-07-11 20:30:49 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_locationBars->indexOf(locBar) != -1) {
|
2011-08-03 22:39:30 +02:00
|
|
|
m_locationBars->setCurrentWidget(locBar);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-11 20:30:49 +02:00
|
|
|
p_QupZilla->ipLabel()->setText(webView->getIp());
|
|
|
|
|
|
|
|
if (webView->isLoading()) {
|
|
|
|
p_QupZilla->ipLabel()->hide();
|
|
|
|
p_QupZilla->progressBar()->setVisible(true);
|
|
|
|
p_QupZilla->progressBar()->setValue(webView->getLoading());
|
2011-09-11 19:15:06 +02:00
|
|
|
p_QupZilla->navigationBar()->showStopButton();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-07-11 20:30:49 +02:00
|
|
|
p_QupZilla->progressBar()->setVisible(false);
|
2011-09-11 19:15:06 +02:00
|
|
|
p_QupZilla->navigationBar()->showReloadButton();
|
2011-07-11 20:30:49 +02:00
|
|
|
p_QupZilla->ipLabel()->show();
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
webView->setFocus();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
m_tabBar->updateCloseButton(index);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabWidget::closeAllButCurrent(int index)
|
|
|
|
{
|
2011-04-18 21:35:57 +02:00
|
|
|
WebTab* akt = qobject_cast<WebTab*>(widget(index));
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(WebTab * tab, allTabs(false)) {
|
|
|
|
if (akt == widget(tab->view()->tabIndex())) {
|
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
|
|
|
closeTab(tab->view()->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
|
|
|
{
|
|
|
|
QUrl url = weView(index)->url();
|
|
|
|
QByteArray history;
|
|
|
|
QDataStream tabHistoryStream(&history, QIODevice::WriteOnly);
|
|
|
|
tabHistoryStream << *weView(index)->history();
|
|
|
|
|
2011-12-20 18:58:42 +01:00
|
|
|
int id = addView(url, tabText(index), TabWidget::NewNotSelectedTab);
|
2011-04-08 17:27:08 +02:00
|
|
|
QDataStream historyStream(history);
|
|
|
|
historyStream >> *weView(id)->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
|
|
|
|
|
|
|
int index = addView(QUrl(), tab.title, TabWidget::NewSelectedTab, false, tab.position);
|
2011-05-07 12:59:53 +02:00
|
|
|
QDataStream historyStream(tab.history);
|
2011-03-02 16:57:41 +01:00
|
|
|
historyStream >> *weView(index)->history();
|
2011-05-07 12:59:53 +02:00
|
|
|
|
2011-09-14 17:40:16 +02:00
|
|
|
weView(index)->load(tab.url);
|
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
|
|
|
|
|
|
|
QList<ClosedTabsManager::Tab> closedTabs = m_closedTabsManager->allClosedTabs();
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(ClosedTabsManager::Tab tab, closedTabs) {
|
2011-05-16 21:36:39 +02:00
|
|
|
int index = addView(QUrl(), tab.title);
|
|
|
|
QDataStream historyStream(tab.history);
|
|
|
|
historyStream >> *weView(index)->history();
|
|
|
|
|
2011-09-14 17:40:16 +02:00
|
|
|
weView(index)->load(tab.url);
|
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
|
|
|
}
|
|
|
|
|
2011-04-18 21:35:57 +02:00
|
|
|
QList<WebTab*> TabWidget::allTabs(bool withPinned)
|
|
|
|
{
|
|
|
|
QList<WebTab*> allTabs;
|
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
WebTab* tab = qobject_cast<WebTab*>(widget(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);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
if (WebView* tab = weView(i)) {
|
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(widget(i));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!webTab || !webTab->isPinned()) {
|
2011-03-25 19:16:21 +01:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-25 19:16:21 +01:00
|
|
|
|
2011-12-14 15:16:09 +01:00
|
|
|
tabs.append(tab->url().toString());
|
2011-03-25 19:16:21 +01:00
|
|
|
if (tab->history()->count() != 0) {
|
|
|
|
QByteArray tabHistory;
|
|
|
|
QDataStream tabHistoryStream(&tabHistory, QIODevice::WriteOnly);
|
|
|
|
tabHistoryStream << *tab->history();
|
|
|
|
tabsHistory.append(tabHistory);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-25 19:16:21 +01:00
|
|
|
tabsHistory << QByteArray();
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-25 19:16:21 +01:00
|
|
|
tabs.append(QString::null);
|
|
|
|
tabsHistory.append(QByteArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stream << tabs;
|
|
|
|
stream << tabsHistory;
|
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;
|
|
|
|
|
|
|
|
for (int i = 0; i < pinnedTabs.count(); ++i) {
|
|
|
|
QUrl url = QUrl::fromEncoded(pinnedTabs.at(i).toUtf8());
|
|
|
|
|
|
|
|
QByteArray historyState = tabHistory.value(i);
|
|
|
|
int addedIndex;
|
|
|
|
if (!historyState.isEmpty()) {
|
2011-12-07 21:48:50 +01:00
|
|
|
addedIndex = addView(QUrl(), tr("New tab"), CleanPage);
|
2011-03-25 19:16:21 +01:00
|
|
|
QDataStream historyStream(historyState);
|
|
|
|
historyStream >> *weView(addedIndex)->history();
|
2011-09-14 17:40:16 +02:00
|
|
|
weView(addedIndex)->load(url);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-25 19:16:21 +01:00
|
|
|
addedIndex = addView(url);
|
|
|
|
}
|
2011-10-18 21:07:58 +02:00
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(widget(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QByteArray TabWidget::saveState()
|
|
|
|
{
|
|
|
|
QByteArray data;
|
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
QStringList tabs;
|
|
|
|
QList<QByteArray> tabsHistory;
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
2011-03-17 17:03:04 +01:00
|
|
|
if (WebView* tab = weView(i)) {
|
2011-03-25 19:16:21 +01:00
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(widget(i));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (webTab && webTab->isPinned()) {
|
2011-03-25 19:16:21 +01:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-25 19:16:21 +01:00
|
|
|
|
2011-12-14 15:16:09 +01:00
|
|
|
tabs.append(tab->url().toString());
|
2011-03-02 16:57:41 +01:00
|
|
|
if (tab->history()->count() != 0) {
|
|
|
|
QByteArray tabHistory;
|
|
|
|
QDataStream tabHistoryStream(&tabHistory, QIODevice::WriteOnly);
|
|
|
|
tabHistoryStream << *tab->history();
|
|
|
|
tabsHistory.append(tabHistory);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-02 16:57:41 +01:00
|
|
|
tabsHistory << QByteArray();
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-02 16:57:41 +01:00
|
|
|
tabs.append(QString::null);
|
|
|
|
tabsHistory.append(QByteArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stream << tabs;
|
|
|
|
stream << currentIndex();
|
|
|
|
stream << tabsHistory;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TabWidget::restoreState(const QByteArray &state)
|
|
|
|
{
|
|
|
|
QByteArray sd = state;
|
|
|
|
QDataStream stream(&sd, QIODevice::ReadOnly);
|
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
|
|
|
|
|
|
|
QStringList openTabs;
|
|
|
|
int currentTab;
|
|
|
|
QList<QByteArray> tabHistory;
|
2011-04-07 18:00:26 +02:00
|
|
|
stream >> openTabs;
|
|
|
|
stream >> currentTab;
|
2011-03-02 16:57:41 +01:00
|
|
|
stream >> tabHistory;
|
|
|
|
|
|
|
|
for (int i = 0; i < openTabs.count(); ++i) {
|
|
|
|
QUrl url = QUrl::fromEncoded(openTabs.at(i).toUtf8());
|
|
|
|
|
|
|
|
QByteArray historyState = tabHistory.value(i);
|
|
|
|
if (!historyState.isEmpty()) {
|
2011-12-07 21:48:50 +01:00
|
|
|
int index = addView(QUrl(), tr("New tab"), CleanPage);
|
2011-03-02 16:57:41 +01:00
|
|
|
QDataStream historyStream(historyState);
|
|
|
|
historyStream >> *weView(index)->history();
|
2011-09-14 17:40:16 +02:00
|
|
|
weView(index)->load(url);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-02 16:57:41 +01:00
|
|
|
addView(url);
|
|
|
|
}
|
|
|
|
}
|
2011-04-07 18:00:26 +02:00
|
|
|
|
2011-03-25 19:16:21 +01:00
|
|
|
setCurrentIndex(currentTab);
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabWidget::~TabWidget()
|
|
|
|
{
|
|
|
|
}
|