1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Supporting data: scheme

You can now enter image with data: scheme to locationbar to show it and
data: images will now be showed in Site Info dialog
This commit is contained in:
nowrep 2011-11-05 11:51:46 +01:00
parent 5f7d2d108b
commit b62ed5edb3
7 changed files with 62 additions and 29 deletions

Binary file not shown.

View File

@ -28,6 +28,15 @@ QByteArray qz_pixmapToByteArray(const QPixmap &pix)
return QByteArray();
}
QPixmap qz_pixmapFromByteArray(const QByteArray &data)
{
QPixmap image;
QByteArray bArray = QByteArray::fromBase64(data);
image.loadFromData(bArray);
return image;
}
QByteArray qz_readAllFileContents(const QString &filename)
{
QFile file(filename);
@ -115,7 +124,8 @@ QString qz_ensureUniqueFilename(const QString &pathToFile)
if (index == -1) {
tmpFileName.append("("+QString::number(i)+")");
} else {
}
else {
tmpFileName = tmpFileName.mid(0, index) + "("+QString::number(i)+")" + tmpFileName.mid(index);
}
i++;
@ -123,6 +133,17 @@ QString qz_ensureUniqueFilename(const QString &pathToFile)
return tmpFileName;
}
QString qz_getFileNameFromUrl(const QUrl &url)
{
QString fileName = url.toString(QUrl::RemoveFragment | QUrl::RemoveQuery | QUrl::RemoveScheme | QUrl::RemovePort);
if (fileName.indexOf("/") != -1) {
int pos = fileName.lastIndexOf("/");
fileName = fileName.mid(pos);
fileName.remove("/");
}
return fileName;
}
QString qz_buildSystem()
{
#ifdef Q_OS_LINUX

View File

@ -26,8 +26,11 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QUrl>
#include <QIcon>
QByteArray qz_pixmapToByteArray(const QPixmap &pix);
QPixmap qz_pixmapFromByteArray(const QByteArray &data);
QByteArray qz_readAllFileContents(const QString &filename);
void qz_centerWidgetOnScreen(QWidget* w);
@ -37,6 +40,7 @@ QString qz_samePartOfStrings(const QString &one, const QString &other);
QUrl qz_makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl);
QString qz_ensureUniqueFilename(const QString &name);
QString qz_getFileNameFromUrl(const QUrl &url);
QString qz_buildSystem();

View File

@ -22,6 +22,8 @@
#include "webpage.h"
#include "downloaditem.h"
#include "certificateinfowidget.h"
#include "globalfunctions.h"
#include "iconprovider.h"
QString SiteInfo::showCertInfo(const QString &string)
{
@ -144,28 +146,21 @@ void SiteInfo::downloadImage()
if (!item)
return;
QUrl imageUrl = item->text(1);
if (imageUrl.host().isEmpty()) {
imageUrl.setHost(QUrl(ui->siteAddress->text()).host());
imageUrl.setScheme(QUrl(ui->siteAddress->text()).scheme());
}
QIODevice* cacheData = mApp->networkCache()->data(imageUrl);
if (!cacheData) {
if (m_activePixmap.isNull()) {
QMessageBox::warning(this, tr("Error!"), tr("This preview is not available!"));
return;
}
QString filePath = QFileDialog::getSaveFileName(this, tr("Save image..."), QDir::homePath()+"/"+item->text(0));
QString imageFileName = qz_getFileNameFromUrl(QUrl(item->text(1)));
QString filePath = QFileDialog::getSaveFileName(this, tr("Save image..."), QDir::homePath() + "/" + imageFileName);
if (filePath.isEmpty())
return;
QFile file(filePath);
if (!file.open(QFile::WriteOnly)) {
if (!m_activePixmap.save(filePath)) {
QMessageBox::critical(this, tr("Error!"), tr("Cannot write to file!"));
return;
}
file.write(cacheData->readAll());
file.close();
}
}
@ -174,26 +169,30 @@ void SiteInfo::showImagePreview(QTreeWidgetItem *item)
if (!item)
return;
QUrl imageUrl = item->text(1);
if (imageUrl.host().isEmpty()) {
imageUrl.setHost(QUrl(ui->siteAddress->text()).host());
imageUrl.setScheme(QUrl(ui->siteAddress->text()).scheme());
}
QIODevice* cacheData = mApp->networkCache()->data(imageUrl);
QPixmap pixmap;
bool invalidPixmap = false;
QGraphicsScene* scene = new QGraphicsScene(ui->mediaPreview);
if (!cacheData)
invalidPixmap = true;
else {
pixmap.loadFromData(cacheData->readAll());
if (pixmap.isNull())
invalidPixmap = true;
if (imageUrl.scheme() == "data") {
QByteArray encodedUrl = item->text(1).toAscii();
QByteArray imageData = encodedUrl.mid(encodedUrl.indexOf(",") + 1);
m_activePixmap = qz_pixmapFromByteArray(imageData);
}
if (invalidPixmap)
else {
if (imageUrl.host().isEmpty()) {
imageUrl.setHost(QUrl(ui->siteAddress->text()).host());
imageUrl.setScheme(QUrl(ui->siteAddress->text()).scheme());
}
QIODevice* cacheData = mApp->networkCache()->data(imageUrl);
if (!cacheData)
m_activePixmap = QPixmap();
else
m_activePixmap.loadFromData(cacheData->readAll());
}
if (m_activePixmap.isNull())
scene->addText(tr("Preview not available"));
else
scene->addPixmap(pixmap);
scene->addPixmap(m_activePixmap);
ui->mediaPreview->setScene(scene);
}

View File

@ -52,6 +52,8 @@ private:
Ui::SiteInfo* ui;
QupZilla* p_QupZilla;
CertificateInfoWidget* m_certWidget;
QPixmap m_activePixmap;
};
#endif // SITEINFO_H

View File

@ -775,6 +775,13 @@ void WebView::load(const QUrl &url)
page()->mainFrame()->evaluateJavaScript(url.toString());
return;
}
if (url.scheme() == "data") {
QWebView::load(url);
m_aboutToLoadUrl = url;
return;
}
if (isUrlValid(url)) {
QWebView::load(url);
m_aboutToLoadUrl = url;

View File

@ -808,7 +808,7 @@ p, li { white-space: pre-wrap; }
<message>
<location filename="../src/other/browsinglibrary.cpp" line="148"/>
<source>Database successfully optimized.&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Database Size Before: &lt;/b&gt;%1&lt;br/&gt;&lt;b&gt;Database Size After: &lt;/b&gt;%2</source>
<translation type="unfinished"></translation>
<translation>Datenbank erfolgreich optimiert.&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Datenbankgröße vorher: &lt;/b&gt;%1&lt;br/&gt;&lt;b&gt;Datenbankgröße nachher: &lt;/b&gt;%2</translation>
</message>
</context>
<context>