Commit 46047b49 authored by Halla Rempt's avatar Halla Rempt
Browse files

Port away from using KIO in our filters

Done in the 2.9 branch to keep the code as close as possible to what
we have in frameworks; in frameworks, kio asserts if there is no sycoca
which means we have to drop using kio.

We lose network transparent file access, but a) I am sure that no artist
was using that anyway and b) that only works with the KDE file dialog
which is available only to a minority of users and c) having that code
separately in every filter was a mistake anywhere, we weren't consistent
so some filters had the code and others didn't.
parent cd4be707
......@@ -23,9 +23,8 @@
#include <QSlider>
#include <QApplication>
#include <kio/netaccess.h>
#include <kpluginfactory.h>
#include <kurl.h>
#include <KoColorSpace.h>
#include <KisFilterChain.h>
......@@ -70,14 +69,10 @@ KisImportExportFilter::ConversionStatus KisBMPImport::convert(const QByteArray&
if (!filename.isEmpty()) {
KUrl url(filename);
if (url.isEmpty())
return KisImportExportFilter::FileNotFound;
if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, qApp -> activeWindow())) {
if (url.isEmpty() || !url.isLocalFile()) {
return KisImportExportFilter::FileNotFound;
}
QString localFile = url.toLocalFile();
QImage img(localFile);
......
......@@ -31,10 +31,9 @@
#include "exr_extra_tags.h"
#include <QApplication>
#include <QMessageBox>
#include <kio/netaccess.h>
#include <kurl.h>
#include <KoColorSpaceRegistry.h>
#include <KoCompositeOpRegistry.h>
......@@ -841,22 +840,11 @@ KisImageBuilder_Result exrConverter::buildImage(const KUrl& uri)
if (uri.isEmpty())
return KisImageBuilder_RESULT_NO_URI;
if (!KIO::NetAccess::exists(uri, KIO::NetAccess::DestinationSide, QApplication::activeWindow())) {
if (!uri.isLocalFile()) {
return KisImageBuilder_RESULT_NOT_EXIST;
}
return decode(uri);
// We're not set up to handle asynchronous loading at the moment.
KisImageBuilder_Result result = KisImageBuilder_RESULT_FAILURE;
QString tmpFile;
if (KIO::NetAccess::download(uri, tmpFile, qApp->activeWindow())) {
KUrl uriTF;
uriTF.setPath(tmpFile);
result = decode(uriTF);
KIO::NetAccess::removeTempFile(tmpFile);
}
return result;
}
......
......@@ -25,8 +25,6 @@
#include <QMessageBox>
#include <kio/netaccess.h>
#include <KoColorSpaceRegistry.h>
#include <KoColorSpaceTraits.h>
#include <KoColorSpaceConstants.h>
......@@ -273,22 +271,10 @@ KisImageBuilder_Result jp2Converter::buildImage(const KUrl& uri)
if (uri.isEmpty())
return KisImageBuilder_RESULT_NO_URI;
if (!KIO::NetAccess::exists(uri, KIO::NetAccess::SourceSide, QApplication::activeWindow())) {
if (!uri.isLocalFile()) {
return KisImageBuilder_RESULT_NOT_EXIST;
}
// We're not set up to handle asynchronous loading at the moment.
KisImageBuilder_Result result = KisImageBuilder_RESULT_FAILURE;
QString tmpFile;
if (KIO::NetAccess::download(uri, tmpFile, QApplication::activeWindow())) {
KUrl uriTF;
uriTF.setPath(tmpFile);
result = decode(uriTF);
KIO::NetAccess::removeTempFile(tmpFile);
}
return result;
return decode(uri);
}
......
......@@ -41,9 +41,6 @@ extern "C" {
#include <QMessageBox>
#include <klocale.h>
#include <kio/netaccess.h>
#include <kio/deletejob.h>
#include <KoDocumentInfo.h>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
......@@ -434,22 +431,12 @@ KisImageBuilder_Result KisJPEGConverter::buildImage(const KUrl& uri)
if (uri.isEmpty())
return KisImageBuilder_RESULT_NO_URI;
if (!KIO::NetAccess::exists(uri, KIO::NetAccess::SourceSide, QApplication::activeWindow())) {
return KisImageBuilder_RESULT_NOT_EXIST;
}
// We're not set up to handle asynchronous loading at the moment.
KisImageBuilder_Result result = KisImageBuilder_RESULT_FAILURE;
QString tmpFile;
if (KIO::NetAccess::download(uri, tmpFile, QApplication::activeWindow())) {
KUrl uriTF;
uriTF.setPath(tmpFile);
result = decode(uriTF);
KIO::NetAccess::removeTempFile(tmpFile);
if (!uri.isLocalFile()) {
return KisImageBuilder_RESULT_NOT_EXIST;
}
return decode(uri);
return result;
}
......@@ -724,7 +711,6 @@ KisImageBuilder_Result KisJPEGConverter::buildFile(const KUrl& uri, KisPaintLaye
}
break;
default:
KIO::del(uri); // asynchronous, but I guess that's ok
delete [] row_pointer;
jpeg_destroy_compress(&cinfo);
return KisImageBuilder_RESULT_UNSUPPORTED;
......
......@@ -19,8 +19,6 @@
#include <QApplication>
#include <kio/netaccess.h>
#include <KoStore.h>
#include <KoStoreDevice.h>
......@@ -50,7 +48,7 @@ KisImageBuilder_Result OraConverter::buildImage(const KUrl& uri)
if (uri.isEmpty())
return KisImageBuilder_RESULT_NO_URI;
if (!KIO::NetAccess::exists(uri, KIO::NetAccess::SourceSide, QApplication::activeWindow())) {
if (!uri.isLocalFile()) {
return KisImageBuilder_RESULT_NOT_EXIST;
}
......@@ -60,7 +58,6 @@ KisImageBuilder_Result OraConverter::buildImage(const KUrl& uri)
return KisImageBuilder_RESULT_FAILURE;
}
OraLoadContext olc(store);
KisOpenRasterStackLoadVisitor orslv(m_doc->createUndoStore(), &olc);
orslv.loadImage();
......@@ -69,7 +66,6 @@ KisImageBuilder_Result OraConverter::buildImage(const KUrl& uri)
delete store;
return KisImageBuilder_RESULT_OK;
}
KisImageWSP OraConverter::image()
......@@ -90,6 +86,7 @@ KisImageBuilder_Result OraConverter::buildFile(const KUrl& uri, KisImageWSP imag
if (!uri.isLocalFile())
return KisImageBuilder_RESULT_NOT_LOCAL;
// Open file for writing
KoStore* store = KoStore::createStore(QApplication::activeWindow(), uri, KoStore::Write, "image/openraster", KoStore::Zip);
if (!store) {
......
......@@ -36,8 +36,6 @@
#include <kpluginfactory.h>
#include <kpassworddialog.h>
#include <kio/netaccess.h>
// calligra's headers
#include <KisFilterChain.h>
#include <KoColorSpace.h>
......@@ -77,16 +75,10 @@ KisPDFImport::ConversionStatus KisPDFImport::convert(const QByteArray& , const Q
KUrl url(filename);
if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, QApplication::activeWindow())) {
if (!url.isLocalFile()) {
return KisImportExportFilter::FileNotFound;
}
// We're not set up to handle asynchronous loading at the moment.
QString tmpFile;
if (KIO::NetAccess::download(url, tmpFile, QApplication::activeWindow())) {
url.setPath(tmpFile);
}
Poppler::Document* pdoc = Poppler::Document::load(url.toLocalFile());
if (!pdoc) {
......@@ -101,7 +93,6 @@ KisPDFImport::ConversionStatus KisPDFImport::convert(const QByteArray& , const Q
return KisImportExportFilter::StorageCreationError;
}
while (pdoc->isLocked()) {
KPasswordDialog dlg(0);
dlg.setPrompt(i18n("A password is required to read that pdf"));
......@@ -157,24 +148,12 @@ KisPDFImport::ConversionStatus KisPDFImport::convert(const QByteArray& , const Q
QImage img = page->renderToImage(wdg->intResolution->value(), wdg->intResolution->value(), 0, 0, width, height);
layer->paintDevice()->convertFromQImage(img, 0, 0, 0);
// XXX: this rendering in tiles is a good idea, but: a) it is slower b) it is buggy -- see bug https://bugs.kde.org/show_bug.cgi?id=300554
// for (int x = 0; x < width; x += 1000) {
// int currentWidth = (x + 1000 > width) ? (width - x) : 1000;
// for (int y = 0; y < height; y += 1000) {
// int currentHeight = (y + 1000 > height) ? (height - x) : 1000;
// qDebug() << wdg->intHorizontal->value() << wdg->intVertical->value() << x << y << currentWidth << currentHeight;
// QImage img = page->renderToImage(wdg->intHorizontal->value(), wdg->intVertical->value(), x, y, currentWidth, currentHeight);
// layer->paintDevice()->convertFromQImage(img, 0, x, y);
// }
// }
delete page;
image->addNode(layer, image->rootLayer(), 0);
loadUpdater->setProgress(*it + 1);
}
doc->setCurrentImage(image);
KIO::NetAccess::removeTempFile(tmpFile);
delete pdoc;
delete kdb;
......
......@@ -25,8 +25,7 @@
#include <QFile>
#include <kpluginfactory.h>
#include <kio/netaccess.h>
#include <kurl.h>
#include <KoColorSpaceRegistry.h>
#include <KisFilterChain.h>
......@@ -76,35 +75,19 @@ KisImportExportFilter::ConversionStatus KisPPMImport::convert(const QByteArray&
KUrl url(filename);
dbgFile << "Import: " << url;
if (url.isEmpty())
return KisImportExportFilter::FileNotFound;
if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, qApp -> activeWindow())) {
dbgFile << "Inexistant file";
if (!url.isLocalFile()) {
return KisImportExportFilter::FileNotFound;
}
// We're not set up to handle asynchronous loading at the moment.
QString tmpFile;
KisImportExportFilter::ConversionStatus result;
if (KIO::NetAccess::download(url, tmpFile, QApplication::activeWindow())) {
KUrl uriTF(tmpFile);
// open the file
QFile *fp = new QFile(uriTF.toLocalFile());
if (fp->exists()) {
doc->prepareForImport();
result = loadFromDevice(fp, doc);
} else {
result = KisImportExportFilter::CreationError;
}
KIO::NetAccess::removeTempFile(tmpFile);
return result;
QFile fp(url.toLocalFile());
if (fp.exists()) {
doc->prepareForImport();
return loadFromDevice(&fp, doc);
}
dbgFile << "Download failed";
return KisImportExportFilter::CreationError;
}
......
......@@ -19,8 +19,6 @@
#include <QApplication>
#include <kio/netaccess.h>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoColorModelStandardIds.h>
......@@ -317,28 +315,16 @@ KisImageBuilder_Result PSDLoader::decode(const KUrl& uri)
return KisImageBuilder_RESULT_OK;
}
KisImageBuilder_Result PSDLoader::buildImage(const KUrl& uri)
{
if (uri.isEmpty())
return KisImageBuilder_RESULT_NO_URI;
if (!KIO::NetAccess::exists(uri, KIO::NetAccess::SourceSide, qApp->activeWindow())) {
if (!uri.isLocalFile()) {
return KisImageBuilder_RESULT_NOT_EXIST;
}
// We're not set up to handle asynchronous loading at the moment.
KisImageBuilder_Result result = KisImageBuilder_RESULT_FAILURE;
QString tmpFile;
if (KIO::NetAccess::download(uri, tmpFile, qApp->activeWindow())) {
KUrl uriTF;
uriTF.setPath( tmpFile );
result = decode(uriTF);
KIO::NetAccess::removeTempFile(tmpFile);
}
return result;
return decode(uri);
}
......
......@@ -24,9 +24,8 @@
#include <QSlider>
#include <QApplication>
#include <kio/netaccess.h>
#include <kpluginfactory.h>
#include <kurl.h>
#include <KoColorSpace.h>
#include <KisFilterChain.h>
......@@ -264,7 +263,7 @@ KisImportExportFilter::ConversionStatus KisTGAImport::convert(const QByteArray&
if (url.isEmpty())
return KisImportExportFilter::FileNotFound;
if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, qApp -> activeWindow())) {
if (!url.isLocalFile()) {
return KisImportExportFilter::FileNotFound;
}
......
......@@ -187,7 +187,6 @@ KisImageBuilder_Result KisTIFFConverter::decode(const KUrl& uri)
TIFF *image = 0;
if ((image = TIFFOpen(QFile::encodeName(uri.toLocalFile()), "r")) == NULL) {
dbgFile << "Could not open the file, either it does not exist, either it is not a TIFF :" << uri.toLocalFile();
return (KisImageBuilder_RESULT_BAD_FETCH);
}
do {
......@@ -614,21 +613,11 @@ KisImageBuilder_Result KisTIFFConverter::buildImage(const KUrl& uri)
if (uri.isEmpty())
return KisImageBuilder_RESULT_NO_URI;
if (!KIO::NetAccess::exists(uri, KIO::NetAccess::SourceSide, qApp -> activeWindow())) {
if (!uri.isLocalFile()) {
return KisImageBuilder_RESULT_NOT_EXIST;
}
// We're not set up to handle asynchronous loading at the moment.
KisImageBuilder_Result result = KisImageBuilder_RESULT_FAILURE;
QString tmpFile;
if (KIO::NetAccess::download(uri, tmpFile, qApp -> activeWindow())) {
KUrl uriTF(tmpFile);
result = decode(uriTF);
KIO::NetAccess::removeTempFile(tmpFile);
}
return result;
return decode(uri);
}
......
......@@ -26,8 +26,7 @@
#include <qendian.h>
#include <kpluginfactory.h>
#include <kio/netaccess.h>
#include <kurl.h>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
......@@ -120,36 +119,20 @@ KisImportExportFilter::ConversionStatus KisXCFImport::convert(const QByteArray&
KUrl url(filename);
dbgFile << "Import: " << url;
if (url.isEmpty())
return KisImportExportFilter::FileNotFound;
if (!KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, qApp -> activeWindow())) {
dbgFile << "Inexistant file";
if (!url.isLocalFile()) {
return KisImportExportFilter::FileNotFound;
}
// We're not set up to handle asynchronous loading at the moment.
QString tmpFile;
KisImportExportFilter::ConversionStatus result;
if (KIO::NetAccess::download(url, tmpFile, QApplication::activeWindow())) {
KUrl uriTF(tmpFile);
// open the file
QFile *fp = new QFile(uriTF.toLocalFile());
if (fp->exists()) {
doc->prepareForImport();
result = loadFromDevice(fp, doc);
} else {
result = KisImportExportFilter::CreationError;
}
KIO::NetAccess::removeTempFile(tmpFile);
return result;
QFile fp(url.toLocalFile());
if (fp.exists()) {
doc->prepareForImport();
return loadFromDevice(&fp, doc);
}
dbgFile << "Download failed";
return KisImportExportFilter::DownloadFailed;
return KisImportExportFilter::CreationError;
}
QString layerModeG2K(GimpLayerModeEffects mode)
......
......@@ -39,7 +39,6 @@
#include <QApplication>
#include <klocale.h>
#include <kio/netaccess.h>
#include <KoColorSpace.h>
#include <KoDocumentInfo.h>
......@@ -782,35 +781,18 @@ KisImageBuilder_Result KisPNGConverter::buildImage(const KUrl& uri)
if (uri.isEmpty())
return KisImageBuilder_RESULT_NO_URI;
if (!KIO::NetAccess::exists(uri, KIO::NetAccess::SourceSide, qApp -> activeWindow())) {
if (!uri.isLocalFile()) {
return KisImageBuilder_RESULT_NOT_EXIST;
}
m_path = uri.prettyUrl();
// We're not set up to handle asynchronous loading at the moment.
KisImageBuilder_Result result = KisImageBuilder_RESULT_FAILURE;
QString tmpFile;
if (KIO::NetAccess::download(uri, tmpFile, qApp -> activeWindow())) {
KUrl uriTF;
uriTF.setPath(tmpFile);
// open the file
dbgFile << QFile::encodeName(uriTF.toLocalFile()) << " " << uriTF.toLocalFile() << " " << uriTF;
// QFile *fp = new QFile(QFile::encodeName(uriTF.path()) );
QFile *fp = new QFile(uriTF.toLocalFile());
if (fp->exists()) {
result = buildImage(fp);
} else {
result = (KisImageBuilder_RESULT_NOT_EXIST);
}
delete fp;
KIO::NetAccess::removeTempFile(tmpFile);
QFile fp(uri.toLocalFile());
if (fp.exists()) {
return buildImage(&fp);
}
return (KisImageBuilder_RESULT_NOT_EXIST);
return result;
}
......
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