Commit 2147b5c1 authored by David Faure's avatar David Faure
Browse files

Port the Open code away from NetAccess.

Summary:
NetAccess::download used a temp file, to then load that with
QImageReader.

I'm using an in-memory buffer instead, mostly because it's
less code. It should also be faster, at the expense of more
memory usage of course (the PNG data should be less than the
image data anyway).

Test Plan: Opening files still works

Reviewers: broulik, andreagenor, tcanabrava, vkrause

Reviewed By: vkrause

Maniphest Tasks: T11576

Differential Revision: https://phabricator.kde.org/D25477
parent d6ef2fb8
......@@ -48,10 +48,12 @@
#include <QImage>
#include <QMimeDatabase>
#include <QImageReader>
#include <QBuffer>
#include <KJobWidgets>
#include "kpLogCategories.h"
#include <kio/netaccess.h> // kdelibs4support
#include <KLocalizedString>
#include <KIO/StoredTransferJob>
#include <kmessagebox.h>
//---------------------------------------------------------------------
......@@ -93,8 +95,14 @@ QImage kpDocument::getPixmapFromFile(const QUrl &url, bool suppressDoesntExistDi
*metaInfo = kpDocumentMetaInfo ();
}
QString tempFile;
if (url.isEmpty () || !KIO::NetAccess::download (url, tempFile, parent))
if (url.isEmpty ()) {
return {};
}
KIO::StoredTransferJob *job = KIO::storedGet (url);
KJobWidgets::setWindow(job, parent);
if (!job->exec())
{
if (!suppressDoesntExistDialog)
{
......@@ -109,28 +117,28 @@ QImage kpDocument::getPixmapFromFile(const QUrl &url, bool suppressDoesntExistDi
return {};
}
QByteArray data = job->data();
QMimeDatabase db;
QMimeType mimeType = db.mimeTypeForFile(tempFile);
QMimeType mimeType = db.mimeTypeForFileNameAndData(url.fileName(), data);
if (saveOptions) {
saveOptions->setMimeType(mimeType.name());
}
#if DEBUG_KP_DOCUMENT
qCDebug(kpLogDocument) << "\ttempFile=" << tempFile;
qCDebug(kpLogDocument) << "\tmimetype=" << mimeType.name();
qCDebug(kpLogDocument) << "\tsrc=" << url.path ();
#endif
QImageReader reader(tempFile);
QBuffer buffer(&data);
buffer.open(QIODevice::ReadOnly);
QImageReader reader(&buffer);
reader.setAutoTransform(true);
reader.setDecideFormatFromContent(true);
QImage image = reader.read();
KIO::NetAccess::removeTempFile(tempFile);
if (image.isNull ())
{
KMessageBox::sorry (parent,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment