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 "webtab.h"
|
|
|
|
#include "qupzilla.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-07-11 20:30:49 +02:00
|
|
|
#include "webpage.h"
|
2011-03-25 19:16:21 +01:00
|
|
|
#include "tabbar.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
2011-07-11 20:30:49 +02:00
|
|
|
#include "locationbar.h"
|
2012-03-11 15:17:12 +01:00
|
|
|
#include "globalfunctions.h"
|
|
|
|
#include "webviewsettings.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QVBoxLayout>
|
2012-03-11 15:17:12 +01:00
|
|
|
#include <QWebHistory>
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
WebTab::SavedTab::SavedTab(WebTab* webTab)
|
|
|
|
{
|
|
|
|
if (webTab->isRestored()) {
|
|
|
|
WebView* view = webTab->view();
|
|
|
|
|
|
|
|
title = view->title();
|
|
|
|
url = view->url();
|
|
|
|
icon = view->icon();
|
|
|
|
|
|
|
|
QDataStream historyStream(&history, QIODevice::WriteOnly);
|
|
|
|
historyStream << *view->history();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*this = webTab->savedTab();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::SavedTab::clear()
|
|
|
|
{
|
|
|
|
title.clear();
|
|
|
|
url.clear();
|
|
|
|
icon = QIcon();
|
|
|
|
history.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab)
|
|
|
|
{
|
|
|
|
stream << tab.title;
|
|
|
|
stream << tab.url;
|
|
|
|
stream << tab.icon;
|
|
|
|
stream << tab.history;
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab)
|
|
|
|
{
|
|
|
|
stream >> tab.title;
|
|
|
|
stream >> tab.url;
|
|
|
|
stream >> tab.icon;
|
|
|
|
stream >> tab.history;
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-07-11 20:30:49 +02:00
|
|
|
WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar)
|
2011-10-14 20:14:57 +02:00
|
|
|
: QWidget()
|
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_locationBar(locationBar)
|
|
|
|
, m_pinned(false)
|
|
|
|
, m_inspectorVisible(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
m_layout = new QVBoxLayout(this);
|
2011-11-06 17:01:23 +01:00
|
|
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_layout->setSpacing(0);
|
2011-07-19 15:18:49 +02:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
m_view = new TabbedWebView(p_QupZilla, this);
|
|
|
|
WebPage* page = new WebPage(p_QupZilla);
|
|
|
|
m_view->setWebPage(page);
|
|
|
|
m_layout->addWidget(m_view);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-07-19 15:18:49 +02:00
|
|
|
setLayout(m_layout);
|
2011-05-07 12:59:53 +02:00
|
|
|
setAutoFillBackground(true); // We don't want this transparent
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
connect(m_view, SIGNAL(showNotification(QWidget*)), this, SLOT(showNotification(QWidget*)));
|
|
|
|
connect(m_view, SIGNAL(iconChanged()), m_locationBar.data(), SLOT(siteIconChanged()));
|
|
|
|
connect(m_view, SIGNAL(loadStarted()), m_locationBar.data(), SLOT(clearIcon()));
|
|
|
|
connect(m_view, SIGNAL(loadFinished(bool)), m_locationBar.data(), SLOT(siteIconChanged()));
|
|
|
|
connect(m_view, SIGNAL(urlChanged(QUrl)), m_locationBar.data(), SLOT(showUrl(QUrl)));
|
|
|
|
connect(m_view, SIGNAL(rssChanged(bool)), m_locationBar.data(), SLOT(showRSSIcon(bool)));
|
|
|
|
connect(m_view->webPage(), SIGNAL(privacyChanged(bool)), m_locationBar.data(), SLOT(setPrivacy(bool)));
|
|
|
|
connect(m_locationBar.data(), SIGNAL(loadUrl(QUrl)), m_view, SLOT(load(QUrl)));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
TabbedWebView* WebTab::view() const
|
2011-12-18 16:57:14 +01:00
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
return m_view;
|
2011-12-18 16:57:14 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
void WebTab::setCurrentTab()
|
|
|
|
{
|
|
|
|
if (!isRestored()) {
|
|
|
|
p_restoreTab(m_savedTab);
|
|
|
|
|
|
|
|
m_savedTab.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl WebTab::url() const
|
|
|
|
{
|
|
|
|
if (isRestored()) {
|
|
|
|
return m_view->url();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return m_savedTab.url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WebTab::title() const
|
|
|
|
{
|
|
|
|
if (isRestored()) {
|
|
|
|
return m_view->title();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return m_savedTab.title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon WebTab::icon() const
|
|
|
|
{
|
|
|
|
if (isRestored()) {
|
|
|
|
return m_view->icon();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return m_savedTab.icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebHistory* WebTab::history() const
|
|
|
|
{
|
|
|
|
return m_view->history();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::reload()
|
|
|
|
{
|
|
|
|
m_view->reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::stop()
|
|
|
|
{
|
|
|
|
m_view->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebTab::isLoading() const
|
|
|
|
{
|
|
|
|
return m_view->isLoading();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebTab::isPinned() const
|
2011-12-18 16:57:14 +01:00
|
|
|
{
|
|
|
|
return m_pinned;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::setPinned(bool state)
|
|
|
|
{
|
|
|
|
m_pinned = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::setLocationBar(LocationBar* bar)
|
|
|
|
{
|
|
|
|
m_locationBar = bar;
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
LocationBar* WebTab::locationBar() const
|
2011-12-18 16:57:14 +01:00
|
|
|
{
|
|
|
|
return m_locationBar.data();
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
bool WebTab::inspectorVisible() const
|
2011-12-18 16:57:14 +01:00
|
|
|
{
|
|
|
|
return m_inspectorVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::setInspectorVisible(bool v)
|
|
|
|
{
|
|
|
|
m_inspectorVisible = v;
|
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
WebTab::SavedTab WebTab::savedTab() const
|
|
|
|
{
|
|
|
|
return m_savedTab;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebTab::isRestored() const
|
|
|
|
{
|
|
|
|
return m_savedTab.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::restoreTab(const WebTab::SavedTab &tab)
|
|
|
|
{
|
|
|
|
if (WebViewSettings::loadTabsOnActivation) {
|
|
|
|
m_savedTab = tab;
|
|
|
|
int index = tabIndex();
|
|
|
|
|
|
|
|
m_view->animationLoading(index, false)->setPixmap(tab.icon.pixmap(16, 16));
|
|
|
|
m_view->tabWidget()->setTabText(index, tab.title);
|
|
|
|
m_locationBar.data()->showUrl(tab.url);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p_restoreTab(tab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::p_restoreTab(const QUrl &url, const QByteArray &history)
|
|
|
|
{
|
|
|
|
QDataStream historyStream(history);
|
|
|
|
historyStream >> *m_view->history();
|
|
|
|
|
|
|
|
m_view->load(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::p_restoreTab(const WebTab::SavedTab &tab)
|
|
|
|
{
|
|
|
|
p_restoreTab(tab.url, tab.history);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void WebTab::showNotification(QWidget* notif)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_layout->count() > 1) {
|
2011-03-02 16:57:41 +01:00
|
|
|
delete m_layout->itemAt(0)->widget();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
m_layout->insertWidget(0, notif);
|
2011-03-02 17:54:12 +01:00
|
|
|
notif->show();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
int WebTab::tabIndex() const
|
2011-03-25 19:16:21 +01:00
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
return m_view->tabIndex();
|
2011-03-25 19:16:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebTab::pinTab(int index)
|
|
|
|
{
|
|
|
|
TabWidget* tabWidget = p_QupZilla->tabWidget();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!tabWidget) {
|
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
|
|
|
|
|
|
|
if (m_pinned) { //Unpin tab
|
|
|
|
m_pinned = false;
|
2012-01-21 20:27:45 +01:00
|
|
|
tabWidget->setTabText(index, m_view->title());
|
2011-03-25 19:16:21 +01:00
|
|
|
tabWidget->getTabBar()->updateCloseButton(index);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else { // Pin tab
|
2011-03-25 19:16:21 +01:00
|
|
|
m_pinned = true;
|
|
|
|
tabWidget->setCurrentIndex(0); // <<-- those 2 lines fixes
|
2011-05-07 12:59:53 +02:00
|
|
|
tabWidget->getTabBar()->moveTab(index, 0); // | weird behavior with bad
|
|
|
|
tabWidget->setTabText(0, ""); // | tabwidget update if we
|
2011-03-25 19:16:21 +01:00
|
|
|
tabWidget->setCurrentIndex(0); // <<-- are moving current tab
|
|
|
|
tabWidget->getTabBar()->updateCloseButton(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-14 11:46:06 +01:00
|
|
|
void WebTab::disconnectObjects()
|
|
|
|
{
|
|
|
|
disconnect(this);
|
|
|
|
disconnect(m_locationBar.data());
|
2012-01-21 20:27:45 +01:00
|
|
|
disconnect(m_view);
|
2012-01-14 11:46:06 +01:00
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
WebTab::~WebTab()
|
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
if (m_locationBar) {
|
2011-12-09 21:56:01 +01:00
|
|
|
delete m_locationBar.data();
|
2011-12-04 20:35:49 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|