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

Port the Open code away from NetAccess.

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

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:
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) {
qCDebug(kpLogDocument) << "\ttempFile=" << tempFile;
qCDebug(kpLogDocument) << "\tmimetype=" <<;
qCDebug(kpLogDocument) << "\tsrc=" << url.path ();
QImageReader reader(tempFile);
QBuffer buffer(&data);;
QImageReader reader(&buffer);
QImage image =;
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