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 "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"
|
2011-11-05 11:51:46 +01:00
|
|
|
#include "globalfunctions.h"
|
|
|
|
#include "iconprovider.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QNetworkDiskCache>
|
|
|
|
#include <QWebFrame>
|
|
|
|
#include <QClipboard>
|
2012-03-23 17:29:12 +01:00
|
|
|
#include <QWebSecurityOrigin>
|
|
|
|
#include <QWebDatabase>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-04-26 19:47:12 +02:00
|
|
|
QString SiteInfo::showCertInfo(const QString &string)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (string.isEmpty()) {
|
2011-04-26 19:47:12 +02:00
|
|
|
return tr("<not set in certificate>");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return string;
|
|
|
|
}
|
2011-04-26 19:47:12 +02:00
|
|
|
}
|
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
SiteInfo::SiteInfo(WebView* view, QWidget* parent)
|
2011-10-09 14:51:25 +02:00
|
|
|
: QDialog(parent)
|
|
|
|
, ui(new Ui::SiteInfo)
|
|
|
|
, m_certWidget(0)
|
2012-03-23 17:29:12 +01:00
|
|
|
, m_view(view)
|
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);
|
2011-11-19 18:21:22 +01:00
|
|
|
|
2012-12-28 01:59:39 +01:00
|
|
|
ListItemDelegate* delegate = new ListItemDelegate(24, ui->listWidget);
|
|
|
|
ui->listWidget->setItemDelegate(delegate);
|
|
|
|
|
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")));
|
2012-03-23 17:29:12 +01:00
|
|
|
ui->listWidget->item(2)->setIcon(QIcon::fromTheme("text-x-sql", QIcon(":/icons/preferences/text-x-sql.png")));
|
|
|
|
ui->listWidget->item(3)->setIcon(QIcon::fromTheme("dialog-password", QIcon(":/icons/preferences/dialog-password.png")));
|
2011-12-03 14:43:13 +01:00
|
|
|
ui->listWidget->item(0)->setSelected(true);
|
2011-11-19 18:21:22 +01:00
|
|
|
|
2012-12-28 01:59:39 +01:00
|
|
|
ui->listWidget->setFixedHeight(delegate->itemHeight());
|
|
|
|
|
2012-04-03 19:28:12 +02:00
|
|
|
WebPage* webPage = view->page();
|
2011-03-02 16:57:41 +01:00
|
|
|
QWebFrame* frame = view->page()->mainFrame();
|
|
|
|
QString title = view->title();
|
2012-01-21 20:27:45 +01:00
|
|
|
QSslCertificate cert = webPage->sslCertificate();
|
2012-03-12 18:22:01 +01:00
|
|
|
m_baseUrl = frame->baseUrl();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-22 21:36:15 +01:00
|
|
|
//GENERAL
|
|
|
|
ui->heading->setText(QString("<b>%1</b>:").arg(title));
|
2012-04-03 19:28:12 +02:00
|
|
|
ui->siteAddress->setText(view->url().toString());
|
2012-08-23 15:40:10 +02:00
|
|
|
ui->sizeLabel->setText(qz_fileSizeToString(webPage->totalBytes()));
|
2011-03-23 22:36:03 +01:00
|
|
|
QString encoding;
|
2011-03-22 21:36:15 +01:00
|
|
|
|
|
|
|
//Meta
|
2011-03-02 16:57:41 +01:00
|
|
|
QWebElementCollection meta = frame->findAllElements("meta");
|
2011-11-06 17:01:23 +01:00
|
|
|
for (int i = 0; i < meta.count(); i++) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QWebElement element = meta.at(i);
|
|
|
|
|
|
|
|
QString content = element.attribute("content");
|
|
|
|
QString name = element.attribute("name");
|
2011-11-06 17:01:23 +01:00
|
|
|
if (name.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
name = element.attribute("http-equiv");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (!element.attribute("charset").isEmpty()) {
|
2011-03-23 22:36:03 +01:00
|
|
|
encoding = element.attribute("charset");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
if (content.contains(QLatin1String("charset="))) {
|
|
|
|
encoding = content.mid(content.indexOf(QLatin1String("charset=")) + 8);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (content.isEmpty() || name.isEmpty()) {
|
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
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeTags);
|
|
|
|
item->setText(0, name);
|
|
|
|
item->setText(1, content);
|
|
|
|
ui->treeTags->addTopLevelItem(item);
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
if (encoding.isEmpty()) {
|
2011-03-23 22:36:03 +01:00
|
|
|
encoding = mApp->webSettings()->defaultTextEncoding();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-23 22:36:03 +01:00
|
|
|
ui->encodingLabel->setText(encoding.toUpper());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-03-22 21:36:15 +01:00
|
|
|
//MEDIA
|
2011-03-02 16:57:41 +01:00
|
|
|
QWebElementCollection img = frame->findAllElements("img");
|
2011-11-06 17:01:23 +01:00
|
|
|
for (int i = 0; i < img.count(); i++) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QWebElement element = img.at(i);
|
|
|
|
|
|
|
|
QString src = element.attribute("src");
|
|
|
|
QString alt = element.attribute("alt");
|
|
|
|
if (alt.isEmpty()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (src.indexOf(QLatin1Char('/')) == -1) {
|
2011-03-02 16:57:41 +01:00
|
|
|
alt = src;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
else {
|
2012-09-04 12:42:45 +02:00
|
|
|
int pos = src.lastIndexOf(QLatin1Char('/'));
|
2011-03-02 16:57:41 +01:00
|
|
|
alt = src.mid(pos);
|
2012-09-04 12:42:45 +02:00
|
|
|
alt.remove(QLatin1Char('/'));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
if (src.isEmpty() || alt.isEmpty()) {
|
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
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeImages);
|
|
|
|
item->setText(0, alt);
|
|
|
|
item->setText(1, src);
|
|
|
|
ui->treeImages->addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
|
2012-03-23 17:29:12 +01:00
|
|
|
//DATABASES
|
2012-04-17 14:00:32 +02:00
|
|
|
const QList<QWebDatabase> &databases = frame->securityOrigin().databases();
|
2012-03-23 17:29:12 +01:00
|
|
|
|
|
|
|
int counter = 0;
|
|
|
|
foreach(const QWebDatabase & b, databases) {
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(ui->databaseList);
|
|
|
|
item->setText(b.displayName());
|
|
|
|
item->setData(Qt::UserRole + 10, counter);
|
|
|
|
|
|
|
|
++counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (counter == 0) {
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(ui->databaseList);
|
|
|
|
item->setText(tr("No databases are used by this page."));
|
|
|
|
item->setFlags(item->flags() & Qt::ItemIsSelectable);
|
|
|
|
}
|
|
|
|
|
2011-03-22 21:36:15 +01:00
|
|
|
//SECURITY
|
2012-12-20 14:45:35 +01:00
|
|
|
if (qz_isCertificateValid(cert)) {
|
2011-03-23 22:36:03 +01:00
|
|
|
ui->securityLabel->setText(tr("<b>Connection is Encrypted.</b>"));
|
|
|
|
ui->certLabel->setText(tr("<b>Your connection to this page is secured with this certificate: </b>"));
|
2011-10-09 14:51:25 +02:00
|
|
|
m_certWidget = new CertificateInfoWidget(cert);
|
|
|
|
ui->certFrame->addWidget(m_certWidget);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-03-23 22:36:03 +01:00
|
|
|
ui->securityLabel->setText(tr("<b>Connection Not Encrypted.</b>"));
|
2011-03-22 21:36:15 +01:00
|
|
|
ui->certLabel->setText(tr("<b>Your connection to this page is not secured!</b>"));
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
connect(ui->listWidget, SIGNAL(currentRowChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
|
2011-03-23 22:36:03 +01:00
|
|
|
connect(ui->secDetailsButton, SIGNAL(clicked()), this, SLOT(securityDetailsClicked()));
|
2012-03-07 12:19:54 +01:00
|
|
|
connect(ui->saveButton, SIGNAL(clicked(QAbstractButton*)), this, SLOT(downloadImage()));
|
|
|
|
|
2012-03-23 17:29:12 +01:00
|
|
|
connect(ui->databaseList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(databaseItemChanged(QListWidgetItem*)));
|
2011-11-06 17:01:23 +01:00
|
|
|
connect(ui->treeImages, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(showImagePreview(QTreeWidgetItem*)));
|
|
|
|
connect(ui->treeImages, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(imagesCustomContextMenuRequested(const 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);
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
|
|
|
|
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();
|
2012-03-07 12:19:54 +01:00
|
|
|
menu.addAction(QIcon::fromTheme("document-save"), tr("Save Image to Disk"), this, SLOT(downloadImage()));
|
2012-04-11 18:06:50 +02:00
|
|
|
menu.exec(ui->treeImages->viewport()->mapToGlobal(p));
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
|
|
|
|
2012-03-23 17:29:12 +01:00
|
|
|
void SiteInfo::databaseItemChanged(QListWidgetItem* item)
|
|
|
|
{
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = item->data(Qt::UserRole + 10).toInt();
|
|
|
|
const QList<QWebDatabase> &list = m_view->page()->mainFrame()->securityOrigin().databases();
|
|
|
|
|
|
|
|
if (id > list.count() - 1) {
|
|
|
|
qDebug("database is shit");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QWebDatabase &db = list.at(id);
|
|
|
|
|
|
|
|
ui->databaseName->setText(QString("%1 (%2)").arg(db.displayName(), db.name()));
|
|
|
|
ui->databasePath->setText(db.fileName());
|
2012-08-23 15:40:10 +02:00
|
|
|
ui->databaseSize->setText(qz_fileSizeToString(db.size()));
|
2012-03-23 17:29:12 +01:00
|
|
|
}
|
|
|
|
|
2011-03-24 22:31:38 +01:00
|
|
|
void SiteInfo::copyActionData()
|
|
|
|
{
|
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
|
|
|
qApp->clipboard()->setText(action->data().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SiteInfo::downloadImage()
|
|
|
|
{
|
2012-03-07 12:19:54 +01:00
|
|
|
QTreeWidgetItem* item = ui->treeImages->currentItem();
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
|
2012-03-07 12:19:54 +01:00
|
|
|
if (m_activePixmap.isNull()) {
|
|
|
|
QMessageBox::warning(this, tr("Error!"), tr("This preview is not available!"));
|
|
|
|
return;
|
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
|
2012-03-07 12:19:54 +01:00
|
|
|
QString imageFileName = qz_getFileNameFromUrl(QUrl(item->text(1)));
|
2011-11-05 11:51:46 +01:00
|
|
|
|
2012-03-07 12:19:54 +01:00
|
|
|
QString filePath = QFileDialog::getSaveFileName(this, tr("Save image..."), QDir::homePath() + "/" + imageFileName);
|
|
|
|
if (filePath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
|
2012-03-07 12:19:54 +01:00
|
|
|
if (!m_activePixmap.save(filePath)) {
|
|
|
|
QMessageBox::critical(this, tr("Error!"), tr("Cannot write to file!"));
|
|
|
|
return;
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
2011-03-23 22:36:03 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01: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);
|
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
QGraphicsScene* scene = new QGraphicsScene(ui->mediaPreview);
|
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);
|
2011-11-05 11:51:46 +01:00
|
|
|
m_activePixmap = qz_pixmapFromByteArray(imageData);
|
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (imageUrl.scheme() == QLatin1String("file")) {
|
2011-12-07 18:57:42 +01:00
|
|
|
m_activePixmap = 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")) {
|
2011-12-03 14:43:13 +01:00
|
|
|
m_activePixmap = QPixmap(imageUrl.toString().mid(3)); // Remove qrc from url
|
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
else {
|
2011-11-05 11:51:46 +01:00
|
|
|
QIODevice* cacheData = mApp->networkCache()->data(imageUrl);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!cacheData) {
|
2011-11-05 11:51:46 +01:00
|
|
|
m_activePixmap = QPixmap();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-11-05 11:51:46 +01:00
|
|
|
m_activePixmap.loadFromData(cacheData->readAll());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-24 22:31:38 +01:00
|
|
|
}
|
2011-11-05 11:51:46 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_activePixmap.isNull()) {
|
2011-03-24 22:31:38 +01:00
|
|
|
scene->addText(tr("Preview not available"));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-11-05 11:51:46 +01:00
|
|
|
scene->addPixmap(m_activePixmap);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-23 22:36:03 +01:00
|
|
|
|
|
|
|
ui->mediaPreview->setScene(scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SiteInfo::securityDetailsClicked()
|
|
|
|
{
|
2012-03-23 17:29:12 +01:00
|
|
|
ui->listWidget->setCurrentRow(3);
|
2011-03-22 21:36:15 +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
|
|
|
}
|