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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "siteinfo.h"
|
|
|
|
#include "ui_siteinfo.h"
|
2012-12-28 01:59:39 +01:00
|
|
|
#include "listitemdelegate.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "webview.h"
|
2011-03-22 21:36:15 +01:00
|
|
|
#include "webpage.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "mainapplication.h"
|
2011-03-23 22:36:03 +01:00
|
|
|
#include "downloaditem.h"
|
2011-10-09 14:51:25 +02:00
|
|
|
#include "certificateinfowidget.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2011-11-05 11:51:46 +01:00
|
|
|
#include "iconprovider.h"
|
2015-09-25 18:31:05 +02:00
|
|
|
#include "scripts.h"
|
2015-09-30 15:55:00 +02:00
|
|
|
#include "networkmanager.h"
|
2015-10-14 12:50:30 +02:00
|
|
|
#include "locationbar.h"
|
2015-01-27 11:01:52 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QNetworkDiskCache>
|
|
|
|
#include <QClipboard>
|
2012-12-29 09:01:01 +01:00
|
|
|
#include <QTimer>
|
2015-09-30 16:20:31 +02:00
|
|
|
#include <QGraphicsPixmapItem>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2015-09-25 22:31:04 +02:00
|
|
|
SiteInfo::SiteInfo(WebView* view)
|
|
|
|
: QWidget()
|
2011-10-09 14:51:25 +02:00
|
|
|
, ui(new Ui::SiteInfo)
|
|
|
|
, m_certWidget(0)
|
2012-03-23 17:29:12 +01:00
|
|
|
, m_view(view)
|
2015-09-30 15:55:00 +02:00
|
|
|
, m_imageReply(Q_NULLPTR)
|
2015-09-25 18:31:05 +02:00
|
|
|
, m_baseUrl(view->url())
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2011-03-02 16:57:41 +01:00
|
|
|
ui->setupUi(this);
|
2014-05-28 22:33:04 +02:00
|
|
|
ui->treeTags->setLayoutDirection(Qt::LeftToRight);
|
2015-09-25 22:31:04 +02:00
|
|
|
QzTools::centerWidgetOnScreen(this);
|
2011-11-19 18:21:22 +01:00
|
|
|
|
2013-02-11 17:11:13 +01:00
|
|
|
ListItemDelegate* delegate = new ListItemDelegate(24, ui->listWidget);
|
|
|
|
delegate->setUpdateParentHeight(true);
|
2013-02-20 11:46:05 +01:00
|
|
|
delegate->setUniformItemSizes(true);
|
2013-02-11 17:11:13 +01:00
|
|
|
ui->listWidget->setItemDelegate(delegate);
|
2012-12-28 01:59:39 +01:00
|
|
|
|
2011-11-19 18:21:22 +01:00
|
|
|
ui->listWidget->item(0)->setIcon(QIcon::fromTheme("document-properties", QIcon(":/icons/preferences/document-properties.png")));
|
|
|
|
ui->listWidget->item(1)->setIcon(QIcon::fromTheme("applications-graphics", QIcon(":/icons/preferences/applications-graphics.png")));
|
2011-12-03 14:43:13 +01:00
|
|
|
ui->listWidget->item(0)->setSelected(true);
|
2011-11-19 18:21:22 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
// General
|
|
|
|
ui->heading->setText(QString("<b>%1</b>:").arg(m_view->title()));
|
|
|
|
ui->siteAddress->setText(m_view->url().toString());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
if (m_view->url().scheme() == QL1S("https"))
|
|
|
|
ui->securityLabel->setText(tr("<b>Connection is Encrypted.</b>"));
|
|
|
|
else
|
|
|
|
ui->securityLabel->setText(tr("<b>Connection Not Encrypted.</b>"));
|
2011-03-22 21:36:15 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
m_view->page()->runJavaScript(QSL("document.charset"), [this](const QVariant &res) {
|
|
|
|
ui->encodingLabel->setText(res.toString());
|
|
|
|
});
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
// Meta
|
|
|
|
m_view->page()->runJavaScript(Scripts::getAllMetaAttributes(), [this](const QVariant &res) {
|
|
|
|
const QVariantList &list = res.toList();
|
|
|
|
Q_FOREACH (const QVariant &val, list) {
|
|
|
|
const QVariantMap &meta = val.toMap();
|
|
|
|
QString content = meta.value(QSL("content")).toString();
|
|
|
|
QString name = meta.value(QSL("name")).toString();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
if (name.isEmpty())
|
|
|
|
name = meta.value(QSL("httpequiv")).toString();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
if (content.isEmpty() || name.isEmpty())
|
|
|
|
continue;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeTags);
|
|
|
|
item->setText(0, name);
|
|
|
|
item->setText(1, content);
|
|
|
|
ui->treeTags->addTopLevelItem(item);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2015-09-25 18:31:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Images
|
|
|
|
m_view->page()->runJavaScript(Scripts::getAllImages(), [this](const QVariant &res) {
|
|
|
|
const QVariantList &list = res.toList();
|
|
|
|
Q_FOREACH (const QVariant &val, list) {
|
|
|
|
const QVariantMap &img = val.toMap();
|
|
|
|
QString src = img.value(QSL("src")).toString();
|
|
|
|
QString alt = img.value(QSL("alt")).toString();
|
|
|
|
if (alt.isEmpty()) {
|
|
|
|
if (src.indexOf(QLatin1Char('/')) == -1) {
|
|
|
|
alt = src;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int pos = src.lastIndexOf(QLatin1Char('/'));
|
|
|
|
alt = src.mid(pos);
|
|
|
|
alt.remove(QLatin1Char('/'));
|
|
|
|
}
|
|
|
|
}
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
if (src.isEmpty() || alt.isEmpty())
|
|
|
|
continue;
|
2012-03-23 17:29:12 +01:00
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeImages);
|
|
|
|
item->setText(0, alt);
|
|
|
|
item->setText(1, src);
|
|
|
|
ui->treeImages->addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
});
|
2011-03-22 21:36:15 +01:00
|
|
|
|
2015-09-30 16:20:31 +02:00
|
|
|
connect(ui->saveButton, SIGNAL(clicked(QAbstractButton*)), this, SLOT(saveImage()));
|
2012-03-13 17:51:06 +01:00
|
|
|
connect(ui->listWidget, SIGNAL(currentRowChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(ui->treeImages, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(showImagePreview(QTreeWidgetItem*)));
|
|
|
|
connect(ui->treeImages, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(imagesCustomContextMenuRequested(QPoint)));
|
2012-03-07 12:19:54 +01:00
|
|
|
|
|
|
|
ui->treeImages->setContextMenuPolicy(Qt::CustomContextMenu);
|
2012-09-01 13:56:00 +02:00
|
|
|
ui->treeImages->sortByColumn(-1);
|
|
|
|
|
|
|
|
ui->treeTags->sortByColumn(-1);
|
2013-07-07 12:32:55 +02:00
|
|
|
|
2015-09-25 22:31:04 +02:00
|
|
|
QzTools::setWmClass("Site Info", this);
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
|
|
|
|
2015-10-14 12:50:30 +02:00
|
|
|
bool SiteInfo::canShowSiteInfo(const QUrl &url)
|
|
|
|
{
|
|
|
|
if (LocationBar::convertUrlToText(url).isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (url.scheme() == QL1S("qupzilla") || url.scheme() == QL1S("view-source"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void SiteInfo::imagesCustomContextMenuRequested(const QPoint &p)
|
2011-03-24 22:31:38 +01:00
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->treeImages->itemAt(p);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-03-24 22:31:38 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
|
|
|
|
QMenu menu;
|
|
|
|
menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy Image Location"), this, SLOT(copyActionData()))->setData(item->text(1));
|
|
|
|
menu.addAction(tr("Copy Image Name"), this, SLOT(copyActionData()))->setData(item->text(0));
|
|
|
|
menu.addSeparator();
|
2015-09-30 16:20:31 +02:00
|
|
|
menu.addAction(QIcon::fromTheme("document-save"), tr("Save Image to Disk"), this, SLOT(saveImage()));
|
2012-04-11 18:06:50 +02:00
|
|
|
menu.exec(ui->treeImages->viewport()->mapToGlobal(p));
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SiteInfo::copyActionData()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
qApp->clipboard()->setText(action->data().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 16:20:31 +02:00
|
|
|
void SiteInfo::saveImage()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->treeImages->currentItem();
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ui->mediaPreview->scene() || ui->mediaPreview->scene()->items().isEmpty())
|
|
|
|
return;
|
|
|
|
|
2015-10-23 11:55:14 +02:00
|
|
|
QGraphicsItem *graphicsItem = ui->mediaPreview->scene()->items().at(0);
|
2015-09-30 16:20:31 +02:00
|
|
|
QGraphicsPixmapItem *pixmapItem = static_cast<QGraphicsPixmapItem*>(graphicsItem);
|
|
|
|
if (graphicsItem->type() != QGraphicsPixmapItem::Type || !pixmapItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!pixmapItem || pixmapItem->pixmap().isNull()) {
|
|
|
|
QMessageBox::warning(this, tr("Error!"), tr("This preview is not available!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString imageFileName = QzTools::getFileNameFromUrl(QUrl(item->text(1)));
|
|
|
|
int index = imageFileName.lastIndexOf(QLatin1Char('.'));
|
|
|
|
if (index != -1) {
|
|
|
|
imageFileName = imageFileName.left(index);
|
|
|
|
imageFileName.append(QL1S(".png"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString filePath = QzTools::getSaveFileName("SiteInfo-DownloadImage", this, tr("Save image..."),
|
|
|
|
QDir::homePath() + QDir::separator() + imageFileName,
|
|
|
|
QSL("*.png"));
|
|
|
|
if (filePath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pixmapItem->pixmap().save(filePath, "PNG")) {
|
|
|
|
QMessageBox::critical(this, tr("Error!"), tr("Cannot write to file!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 15:55:00 +02:00
|
|
|
void SiteInfo::showLoadingText()
|
|
|
|
{
|
|
|
|
delete ui->mediaPreview->scene();
|
|
|
|
QGraphicsScene* scene = new QGraphicsScene(ui->mediaPreview);
|
|
|
|
|
|
|
|
scene->addText(tr("Loading..."));
|
|
|
|
|
|
|
|
ui->mediaPreview->setScene(scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SiteInfo::showPixmap(const QPixmap &pixmap)
|
|
|
|
{
|
|
|
|
delete ui->mediaPreview->scene();
|
|
|
|
QGraphicsScene* scene = new QGraphicsScene(ui->mediaPreview);
|
|
|
|
|
|
|
|
if (pixmap.isNull())
|
|
|
|
scene->addText(tr("Preview not available"));
|
|
|
|
else
|
|
|
|
scene->addPixmap(pixmap);
|
|
|
|
|
|
|
|
ui->mediaPreview->setScene(scene);
|
|
|
|
}
|
|
|
|
|
2015-09-25 18:31:05 +02:00
|
|
|
void SiteInfo::showImagePreview(QTreeWidgetItem *item)
|
2011-03-23 22:36:03 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-03-23 22:36:03 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-01-31 21:10:22 +01:00
|
|
|
QUrl imageUrl = QUrl::fromEncoded(item->text(1).toUtf8());
|
2011-12-03 14:43:13 +01:00
|
|
|
if (imageUrl.isRelative()) {
|
|
|
|
imageUrl = m_baseUrl.resolved(imageUrl);
|
|
|
|
}
|
2015-09-30 15:55:00 +02:00
|
|
|
|
|
|
|
QPixmap pixmap;
|
|
|
|
bool loading = false;
|
2011-03-23 22:36:03 +01:00
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (imageUrl.scheme() == QLatin1String("data")) {
|
2011-12-04 16:54:57 +01:00
|
|
|
QByteArray encodedUrl = item->text(1).toUtf8();
|
2012-07-01 18:50:18 +02:00
|
|
|
QByteArray imageData = encodedUrl.mid(encodedUrl.indexOf(',') + 1);
|
2015-09-30 15:55:00 +02:00
|
|
|
pixmap = QzTools::pixmapFromByteArray(imageData);
|
2011-11-05 11:51:46 +01:00
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (imageUrl.scheme() == QLatin1String("file")) {
|
2015-09-30 15:55:00 +02:00
|
|
|
pixmap = QPixmap(imageUrl.toLocalFile());
|
2011-12-03 14:43:13 +01:00
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (imageUrl.scheme() == QLatin1String("qrc")) {
|
2015-09-30 15:55:00 +02:00
|
|
|
pixmap = QPixmap(imageUrl.toString().mid(3)); // Remove qrc from url
|
2011-12-03 14:43:13 +01:00
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
else {
|
2015-09-30 15:55:00 +02:00
|
|
|
delete m_imageReply;
|
|
|
|
m_imageReply = mApp->networkManager()->get(QNetworkRequest(imageUrl));
|
|
|
|
connect(m_imageReply, &QNetworkReply::finished, this, [this]() {
|
|
|
|
if (m_imageReply->error() != QNetworkReply::NoError)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const QByteArray &data = m_imageReply->readAll();
|
|
|
|
showPixmap(QPixmap::fromImage(QImage::fromData(data)));
|
|
|
|
});
|
|
|
|
|
|
|
|
loading = true;
|
|
|
|
showLoadingText();
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
2011-11-05 11:51:46 +01:00
|
|
|
|
2015-09-30 15:55:00 +02:00
|
|
|
if (!loading)
|
|
|
|
showPixmap(pixmap);
|
2011-03-23 22:36:03 +01:00
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
SiteInfo::~SiteInfo()
|
|
|
|
{
|
|
|
|
delete ui;
|
2012-09-11 11:43:11 +02:00
|
|
|
delete m_certWidget;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|