mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
SiteInfo: Bring back showing previews of images
This commit is contained in:
parent
abe13dd22d
commit
bd215a69ed
@ -26,6 +26,7 @@
|
|||||||
#include "qztools.h"
|
#include "qztools.h"
|
||||||
#include "iconprovider.h"
|
#include "iconprovider.h"
|
||||||
#include "scripts.h"
|
#include "scripts.h"
|
||||||
|
#include "networkmanager.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -47,6 +48,7 @@ SiteInfo::SiteInfo(WebView* view)
|
|||||||
, ui(new Ui::SiteInfo)
|
, ui(new Ui::SiteInfo)
|
||||||
, m_certWidget(0)
|
, m_certWidget(0)
|
||||||
, m_view(view)
|
, m_view(view)
|
||||||
|
, m_imageReply(Q_NULLPTR)
|
||||||
, m_baseUrl(view->url())
|
, m_baseUrl(view->url())
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
@ -159,6 +161,29 @@ void SiteInfo::copyActionData()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void SiteInfo::showImagePreview(QTreeWidgetItem *item)
|
void SiteInfo::showImagePreview(QTreeWidgetItem *item)
|
||||||
{
|
{
|
||||||
if (!item) {
|
if (!item) {
|
||||||
@ -168,39 +193,38 @@ void SiteInfo::showImagePreview(QTreeWidgetItem *item)
|
|||||||
if (imageUrl.isRelative()) {
|
if (imageUrl.isRelative()) {
|
||||||
imageUrl = m_baseUrl.resolved(imageUrl);
|
imageUrl = m_baseUrl.resolved(imageUrl);
|
||||||
}
|
}
|
||||||
QGraphicsScene* scene = new QGraphicsScene(ui->mediaPreview);
|
|
||||||
|
QPixmap pixmap;
|
||||||
|
bool loading = false;
|
||||||
|
|
||||||
if (imageUrl.scheme() == QLatin1String("data")) {
|
if (imageUrl.scheme() == QLatin1String("data")) {
|
||||||
QByteArray encodedUrl = item->text(1).toUtf8();
|
QByteArray encodedUrl = item->text(1).toUtf8();
|
||||||
QByteArray imageData = encodedUrl.mid(encodedUrl.indexOf(',') + 1);
|
QByteArray imageData = encodedUrl.mid(encodedUrl.indexOf(',') + 1);
|
||||||
m_activePixmap = QzTools::pixmapFromByteArray(imageData);
|
pixmap = QzTools::pixmapFromByteArray(imageData);
|
||||||
}
|
}
|
||||||
else if (imageUrl.scheme() == QLatin1String("file")) {
|
else if (imageUrl.scheme() == QLatin1String("file")) {
|
||||||
m_activePixmap = QPixmap(imageUrl.toLocalFile());
|
pixmap = QPixmap(imageUrl.toLocalFile());
|
||||||
}
|
}
|
||||||
else if (imageUrl.scheme() == QLatin1String("qrc")) {
|
else if (imageUrl.scheme() == QLatin1String("qrc")) {
|
||||||
m_activePixmap = QPixmap(imageUrl.toString().mid(3)); // Remove qrc from url
|
pixmap = QPixmap(imageUrl.toString().mid(3)); // Remove qrc from url
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#if QTWEBENGINE_DISABLED
|
delete m_imageReply;
|
||||||
QIODevice* cacheData = mApp->networkCache()->data(imageUrl);
|
m_imageReply = mApp->networkManager()->get(QNetworkRequest(imageUrl));
|
||||||
if (!cacheData) {
|
connect(m_imageReply, &QNetworkReply::finished, this, [this]() {
|
||||||
m_activePixmap = QPixmap();
|
if (m_imageReply->error() != QNetworkReply::NoError)
|
||||||
}
|
return;
|
||||||
else {
|
|
||||||
m_activePixmap.loadFromData(cacheData->readAll());
|
const QByteArray &data = m_imageReply->readAll();
|
||||||
}
|
showPixmap(QPixmap::fromImage(QImage::fromData(data)));
|
||||||
#endif
|
});
|
||||||
|
|
||||||
|
loading = true;
|
||||||
|
showLoadingText();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_activePixmap.isNull()) {
|
if (!loading)
|
||||||
scene->addText(tr("Preview not available"));
|
showPixmap(pixmap);
|
||||||
}
|
|
||||||
else {
|
|
||||||
scene->addPixmap(m_activePixmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->mediaPreview->setScene(scene);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SiteInfo::~SiteInfo()
|
SiteInfo::~SiteInfo()
|
||||||
|
@ -28,7 +28,7 @@ namespace Ui
|
|||||||
class SiteInfo;
|
class SiteInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
class QListWidgetItem;
|
class QNetworkReply;
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
|
|
||||||
class WebView;
|
class WebView;
|
||||||
@ -50,11 +50,14 @@ private slots:
|
|||||||
void copyActionData();
|
void copyActionData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void showLoadingText();
|
||||||
|
void showPixmap(const QPixmap &pixmap);
|
||||||
|
|
||||||
Ui::SiteInfo* ui;
|
Ui::SiteInfo* ui;
|
||||||
CertificateInfoWidget* m_certWidget;
|
CertificateInfoWidget* m_certWidget;
|
||||||
WebView* m_view;
|
WebView* m_view;
|
||||||
|
QNetworkReply *m_imageReply;
|
||||||
|
|
||||||
QPixmap m_activePixmap;
|
|
||||||
QUrl m_baseUrl;
|
QUrl m_baseUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user