2012-01-21 20:27:45 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "tabbedwebview.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "webpage.h"
|
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "networkmanager.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "tabbar.h"
|
|
|
|
#include "webtab.h"
|
|
|
|
#include "statusbarmessage.h"
|
|
|
|
#include "progressbar.h"
|
|
|
|
#include "navigationbar.h"
|
|
|
|
#include "iconprovider.h"
|
|
|
|
#include "searchenginesmanager.h"
|
2012-01-24 23:28:18 +01:00
|
|
|
#include "enhancedmenu.h"
|
2012-02-04 18:45:59 +01:00
|
|
|
#include "adblockicon.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMovie>
|
|
|
|
#include <QStatusBar>
|
|
|
|
#include <QHostInfo>
|
|
|
|
#include <QWebFrame>
|
2012-08-31 15:19:07 +02:00
|
|
|
#include <QContextMenuEvent>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-08-20 21:40:38 +02:00
|
|
|
bool TabbedWebView::m_navigationVisible = false;
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
TabbedWebView::TabbedWebView(QupZilla* mainClass, WebTab* webTab)
|
|
|
|
: WebView(webTab)
|
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_tabWidget(p_QupZilla->tabWidget())
|
|
|
|
, m_webTab(webTab)
|
2012-01-24 23:28:18 +01:00
|
|
|
, m_menu(new Menu(this))
|
2012-01-21 20:27:45 +01:00
|
|
|
, m_mouseTrack(false)
|
|
|
|
, m_hasRss(false)
|
|
|
|
, m_rssChecked(false)
|
|
|
|
{
|
|
|
|
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
|
2012-08-24 20:53:53 +02:00
|
|
|
connect(this, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
|
2012-01-21 20:27:45 +01:00
|
|
|
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
|
|
|
|
connect(this, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged()));
|
|
|
|
connect(this, SIGNAL(iconChanged()), this, SLOT(slotIconChanged()));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(statusBarMessage(QString)), p_QupZilla->statusBar(), SLOT(showMessage(QString)));
|
|
|
|
|
|
|
|
connect(mApp->networkManager(), SIGNAL(wantsFocus(QUrl)), this, SLOT(getFocus(QUrl)));
|
|
|
|
|
|
|
|
connect(p_QupZilla, SIGNAL(setWebViewMouseTracking(bool)), this, SLOT(trackMouse(bool)));
|
|
|
|
|
|
|
|
// Tracking mouse also on tabs created in fullscreen
|
|
|
|
trackMouse(p_QupZilla->isFullScreen());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::setWebPage(WebPage* page)
|
|
|
|
{
|
2012-04-03 20:23:15 +02:00
|
|
|
page->setWebView(this);
|
|
|
|
page->setParent(this);
|
|
|
|
setPage(page);
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2012-04-03 20:23:15 +02:00
|
|
|
connect(page, SIGNAL(linkHovered(QString, QString, QString)), this, SLOT(linkHovered(QString, QString, QString)));
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::slotIconChanged()
|
|
|
|
{
|
2012-02-04 19:43:43 +01:00
|
|
|
const QString &urlScheme = url().scheme();
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (urlScheme == QLatin1String("file") || urlScheme == QLatin1String("qupzilla")
|
|
|
|
|| title().contains(tr("Failed loading page"))) {
|
2012-01-21 20:27:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
showIcon();
|
|
|
|
}
|
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
void TabbedWebView::inspectElement()
|
|
|
|
{
|
2012-02-04 18:45:59 +01:00
|
|
|
p_QupZilla->showWebInspector(false);
|
2012-01-22 11:49:58 +01:00
|
|
|
triggerPageAction(QWebPage::InspectElement);
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
WebTab* TabbedWebView::webTab() const
|
|
|
|
{
|
|
|
|
return m_webTab;
|
|
|
|
}
|
|
|
|
|
2012-02-24 21:03:44 +01:00
|
|
|
TabWidget* TabbedWebView::tabWidget() const
|
|
|
|
{
|
|
|
|
return m_tabWidget;
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
QString TabbedWebView::getIp() const
|
|
|
|
{
|
|
|
|
return m_currentIp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TabbedWebView::isCurrent()
|
|
|
|
{
|
|
|
|
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_tabWidget->currentIndex()));
|
|
|
|
if (!webTab) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (webTab->view() == this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::urlChanged(const QUrl &url)
|
|
|
|
{
|
|
|
|
if (isCurrent()) {
|
|
|
|
p_QupZilla->navigationBar()->refreshHistory();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastUrl() != url) {
|
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 20:53:53 +02:00
|
|
|
void TabbedWebView::loadProgress(int prog)
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
|
|
|
if (prog > 60) {
|
|
|
|
checkRss();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isCurrent()) {
|
|
|
|
p_QupZilla->updateLoadingActions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 11:04:14 +02:00
|
|
|
void TabbedWebView::userLoadAction(const QUrl &url)
|
|
|
|
{
|
|
|
|
QNetworkRequest request(url);
|
|
|
|
request.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
|
|
|
|
|
|
|
load(request);
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
void TabbedWebView::slotLoadStarted()
|
|
|
|
{
|
|
|
|
m_rssChecked = false;
|
|
|
|
emit rssChanged(false);
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
m_tabWidget->startTabAnimation(tabIndex());
|
2012-01-21 20:27:45 +01:00
|
|
|
|
|
|
|
if (title().isNull()) {
|
|
|
|
m_tabWidget->setTabText(tabIndex(), tr("Loading..."));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentIp.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::slotLoadFinished()
|
|
|
|
{
|
2012-03-13 17:51:06 +01:00
|
|
|
m_tabWidget->stopTabAnimation(tabIndex());
|
2012-01-21 20:27:45 +01:00
|
|
|
|
|
|
|
showIcon();
|
|
|
|
QHostInfo::lookupHost(url().host(), this, SLOT(setIp(QHostInfo)));
|
|
|
|
|
|
|
|
if (isCurrent()) {
|
|
|
|
p_QupZilla->updateLoadingActions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::setIp(const QHostInfo &info)
|
|
|
|
{
|
|
|
|
if (info.addresses().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
m_currentIp = QString("%1 (%2)").arg(info.hostName(), info.addresses().at(0).toString());
|
2012-01-21 20:27:45 +01:00
|
|
|
|
|
|
|
if (isCurrent()) {
|
|
|
|
emit ipChanged(m_currentIp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::titleChanged()
|
|
|
|
{
|
2012-02-04 19:43:43 +01:00
|
|
|
const QString &t = title();
|
2012-01-21 20:27:45 +01:00
|
|
|
|
|
|
|
if (isCurrent()) {
|
|
|
|
p_QupZilla->setWindowTitle(tr("%1 - QupZilla").arg(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_tabWidget->setTabText(tabIndex(), t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::showIcon()
|
|
|
|
{
|
|
|
|
if (isLoading()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon icon_ = icon();
|
2012-03-13 17:51:06 +01:00
|
|
|
if (icon_.isNull()) {
|
2012-04-22 20:51:28 +02:00
|
|
|
icon_ = qIconProvider->emptyWebIcon();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
2012-03-13 17:51:06 +01:00
|
|
|
|
|
|
|
m_tabWidget->setTabIcon(tabIndex(), icon_);
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::linkHovered(const QString &link, const QString &title, const QString &content)
|
|
|
|
{
|
|
|
|
Q_UNUSED(title)
|
|
|
|
Q_UNUSED(content)
|
|
|
|
|
|
|
|
if (isCurrent()) {
|
2012-09-02 11:42:41 +02:00
|
|
|
if (link.isEmpty()) {
|
|
|
|
p_QupZilla->statusBarMessage()->clearMessage();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-09-02 11:42:41 +02:00
|
|
|
p_QupZilla->statusBarMessage()->showMessage(link);
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabbedWebView::tabIndex() const
|
|
|
|
{
|
2012-03-13 15:10:18 +01:00
|
|
|
return m_tabWidget->indexOf(m_webTab);
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* TabbedWebView::overlayForJsAlert()
|
|
|
|
{
|
|
|
|
return m_webTab;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::closeView()
|
|
|
|
{
|
|
|
|
emit wantsCloseTab(tabIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::checkRss()
|
|
|
|
{
|
|
|
|
if (m_rssChecked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_rssChecked = true;
|
|
|
|
QWebFrame* frame = page()->mainFrame();
|
2012-02-04 19:43:43 +01:00
|
|
|
const QWebElementCollection &links = frame->findAllElements("link[type=\"application/rss+xml\"]");
|
2012-01-21 20:27:45 +01:00
|
|
|
|
|
|
|
m_hasRss = links.count() != 0;
|
|
|
|
emit rssChanged(m_hasRss);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
|
|
|
m_menu->clear();
|
|
|
|
|
2012-02-04 19:43:43 +01:00
|
|
|
const QWebHitTestResult &hitTest = page()->mainFrame()->hitTestContent(event->pos());
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
createContextMenu(m_menu, hitTest, event->pos());
|
2012-02-04 18:45:59 +01:00
|
|
|
m_menu->addAction(p_QupZilla->adBlockIcon()->menuAction());
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2012-01-22 11:49:58 +01:00
|
|
|
m_menu->addSeparator();
|
|
|
|
m_menu->addAction(tr("Inspect Element"), this, SLOT(inspectElement()));
|
2012-01-21 20:27:45 +01:00
|
|
|
|
|
|
|
if (!m_menu->isEmpty()) {
|
|
|
|
//Prevent choosing first option with double rightclick
|
2012-03-23 17:29:12 +01:00
|
|
|
const QPoint &pos = event->globalPos();
|
2012-01-21 20:27:45 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
m_menu->popup(p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebView::contextMenuEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::stop()
|
|
|
|
{
|
2012-01-22 11:49:58 +01:00
|
|
|
triggerPageAction(QWebPage::Stop);
|
2012-01-21 20:27:45 +01:00
|
|
|
slotLoadFinished();
|
|
|
|
}
|
|
|
|
|
2012-03-10 13:57:50 +01:00
|
|
|
void TabbedWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position)
|
2012-01-21 20:27:45 +01:00
|
|
|
{
|
2012-03-10 13:57:50 +01:00
|
|
|
QNetworkRequest req(urla);
|
|
|
|
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
|
|
|
|
|
|
|
m_tabWidget->addView(req, position);
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
2012-02-24 21:03:44 +01:00
|
|
|
void TabbedWebView::openNewTab()
|
|
|
|
{
|
2012-03-10 13:57:50 +01:00
|
|
|
m_tabWidget->addView(QUrl());
|
2012-02-24 21:03:44 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
void TabbedWebView::getFocus(const QUrl &urla)
|
|
|
|
{
|
|
|
|
if (urla == url()) {
|
|
|
|
m_tabWidget->setCurrentWidget(m_webTab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (m_mouseTrack) {
|
|
|
|
if (m_navigationVisible) {
|
|
|
|
m_navigationVisible = false;
|
|
|
|
p_QupZilla->showNavigationWithFullscreen();
|
|
|
|
}
|
|
|
|
else if (event->y() < 5) {
|
|
|
|
m_navigationVisible = true;
|
|
|
|
p_QupZilla->showNavigationWithFullscreen();
|
|
|
|
}
|
|
|
|
}
|
2012-03-05 13:16:34 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
WebView::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabbedWebView::disconnectObjects()
|
|
|
|
{
|
|
|
|
disconnect(this);
|
|
|
|
disconnect(p_QupZilla->statusBar());
|
2012-03-05 13:16:34 +01:00
|
|
|
|
|
|
|
WebView::disconnectObjects();
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TabbedWebView::~TabbedWebView()
|
|
|
|
{
|
|
|
|
}
|