Commit e518e102 authored by Agata Cacko's avatar Agata Cacko

Unify error codes engaged in import/export

Before this patch, there were two layers of error codes:
KisImageBuilder_Result in KisImageBuilderResult.h
later converted into ConversionStatus in KisImportExportFilter.h
In case of usage of libraw, there were also libraw error codes.
After this patch, only one error code system and error messages system
is implemented. Error codes should match the previous ones,
but are not necessarily correct now.
parent 4cb99027
......@@ -53,6 +53,7 @@
#include <kis_guides_config.h>
#include <kis_coordinates_converter.h>
#include <kis_time_range.h>
#include <KisImportExportErrorCode.h>
#include <KoColor.h>
#include <KoColorSpace.h>
......@@ -887,9 +888,9 @@ bool Document::importAnimation(const QList<QString> &files, int firstFrame, int
}
KisAnimationImporter importer(d->document->image(), updater);
KisImportExportFilter::ConversionStatus status = importer.import(files, firstFrame, step);
KisImportExportErrorCode status = importer.import(files, firstFrame, step);
return (status == KisImportExportFilter::OK);
return status.isOk();
}
int Document::framesPerSecond()
......
......@@ -104,16 +104,16 @@ void KisAsyncAnimationFramesSavingRenderer::frameCompletedCallback(int frame, co
m_d->savingDevice->makeCloneFromRough(image->projection(), image->bounds());
KisImportExportFilter::ConversionStatus status = KisImportExportFilter::OK;
KisImportExportErrorCode status = ImportExportCodes::OK;
QString frameNumber = QString("%1").arg(frame + m_d->sequenceNumberingOffset, 4, 10, QChar('0'));
QString filename = m_d->filenamePrefix + frameNumber + m_d->filenameSuffix;
if (!m_d->savingDoc->exportDocumentSync(QUrl::fromLocalFile(filename), m_d->outputMimeType, m_d->exportConfiguration)) {
status = KisImportExportFilter::InternalError;
status = ImportExportCodes::InternalError;
}
if (status == KisImportExportFilter::OK) {
if (status.isOk()) {
emit sigCompleteRegenerationInternal(frame);
} else {
emit sigCancelRegenerationInternal(frame);
......
This diff is collapsed.
......@@ -455,9 +455,9 @@ Q_SIGNALS:
void sigGuidesConfigChanged(const KisGuidesConfig &config);
void sigBackgroundSavingFinished(KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void sigBackgroundSavingFinished(KisImportExportErrorCode status, const QString &errorMessage);
void sigCompleteBackgroundSaving(const KritaUtils::ExportFileJob &job, KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void sigCompleteBackgroundSaving(const KritaUtils::ExportFileJob &job, KisImportExportErrorCode status, const QString &errorMessage);
void sigReferenceImagesChanged();
......@@ -465,10 +465,10 @@ Q_SIGNALS:
private Q_SLOTS:
void finishExportInBackground();
void slotChildCompletedSavingInBackground(KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void slotCompleteAutoSaving(const KritaUtils::ExportFileJob &job, KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void slotChildCompletedSavingInBackground(KisImportExportErrorCode status, const QString &errorMessage);
void slotCompleteAutoSaving(const KritaUtils::ExportFileJob &job, KisImportExportErrorCode status, const QString &errorMessage);
void slotCompleteSavingDocument(const KritaUtils::ExportFileJob &job, KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void slotCompleteSavingDocument(const KritaUtils::ExportFileJob &job, KisImportExportErrorCode status, const QString &errorMessage);
void slotInitiateAsyncAutosaving(KisDocument *clonedDocument);
......@@ -649,7 +649,7 @@ private:
*/
KisDocument *lockAndCloneForSaving();
QString exportErrorToUserMessage(KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
QString exportErrorToUserMessage(KisImportExportErrorCode status, const QString &errorMessage);
QString prettyPathOrUrl() const;
......
......@@ -41,4 +41,6 @@ enum KisImageBuilder_Result {
KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE = 600
};
#endif
......@@ -21,6 +21,8 @@ Boston, MA 02110-1301, USA.
#ifndef KIS_IMPORT_EXPORT_FILTER_H
#define KIS_IMPORT_EXPORT_FILTER_H
#include "KisImageBuilderResult.h"
#include <QObject>
#include <QIODevice>
#include <QMap>
......@@ -39,7 +41,7 @@ class KisDocument;
class KisConfigWidget;
#include "kritaui_export.h"
#include "KisImportExportErrorCode.h"
/**
* @brief The base class for import and export filters.
......@@ -112,7 +114,7 @@ public:
* @return The error status, see the @ref #ConversionStatus enum.
* KisImportExportFilter::OK means that everything is alright.
*/
virtual ConversionStatus convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) = 0;
virtual KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) = 0;
/**
* Get the text version of the status value
......
This diff is collapsed.
......@@ -77,7 +77,7 @@ public:
* If the QString which is returned isEmpty() and the status is OK,
* then we imported the file directly into the document.
*/
KisImportExportFilter::ConversionStatus importDocument(const QString &location, const QString &mimeType);
KisImportExportErrorCode importDocument(const QString &location, const QString &mimeType);
/**
* @brief Exports the given file/document to the specified URL/mimetype.
......@@ -86,9 +86,9 @@ public:
* and when the method returns @p mimeType contains this mimetype.
* Oh, well, export is a C++ keyword ;)
*/
KisImportExportFilter::ConversionStatus exportDocument(const QString &location, const QString& realLocation, const QByteArray &mimeType, bool showWarnings = true, KisPropertiesConfigurationSP exportConfiguration = 0);
KisImportExportErrorCode exportDocument(const QString &location, const QString& realLocation, const QByteArray &mimeType, bool showWarnings = true, KisPropertiesConfigurationSP exportConfiguration = 0);
QFuture<KisImportExportFilter::ConversionStatus> exportDocumentAsyc(const QString &location, const QString& realLocation, const QByteArray &mimeType, KisImportExportFilter::ConversionStatus &status, bool showWarnings = true, KisPropertiesConfigurationSP exportConfiguration = 0);
QFuture<KisImportExportErrorCode> exportDocumentAsyc(const QString &location, const QString& realLocation, const QByteArray &mimeType, KisImportExportErrorCode &status, bool showWarnings = true, KisPropertiesConfigurationSP exportConfiguration = 0);
///@name Static API
//@{
......@@ -136,10 +136,10 @@ private:
void fillStaticExportConfigurationProperties(KisPropertiesConfigurationSP exportConfiguration);
bool askUserAboutExportConfiguration(QSharedPointer<KisImportExportFilter> filter, KisPropertiesConfigurationSP exportConfiguration, const QByteArray &from, const QByteArray &to, bool batchMode, const bool showWarnings, bool *alsoAsKra);
KisImportExportFilter::ConversionStatus doImport(const QString &location, QSharedPointer<KisImportExportFilter> filter);
KisImportExportErrorCode doImport(const QString &location, QSharedPointer<KisImportExportFilter> filter);
KisImportExportFilter::ConversionStatus doExport(const QString &location, QSharedPointer<KisImportExportFilter> filter, KisPropertiesConfigurationSP exportConfiguration, bool alsoAsKra);
KisImportExportFilter::ConversionStatus doExportImpl(const QString &location, QSharedPointer<KisImportExportFilter> filter, KisPropertiesConfigurationSP exportConfiguration);
KisImportExportErrorCode doExport(const QString &location, QSharedPointer<KisImportExportFilter> filter, KisPropertiesConfigurationSP exportConfiguration, bool alsoAsKra);
KisImportExportErrorCode doExportImpl(const QString &location, QSharedPointer<KisImportExportFilter> filter, KisPropertiesConfigurationSP exportConfiguration);
// Private API
KisImportExportManager(const KisImportExportManager& rhs);
......
......@@ -1821,11 +1821,10 @@ void KisMainWindow::importAnimation()
KoUpdaterPtr updater =
!document->fileBatchMode() ? viewManager()->createUnthreadedUpdater(i18n("Import frames")) : 0;
KisAnimationImporter importer(document->image(), updater);
KisImportExportFilter::ConversionStatus status = importer.import(files, firstFrame, step);
if (status != KisImportExportFilter::OK && status != KisImportExportFilter::InternalError) {
QString msg = KisImportExportFilter::conversionStatusString(status);
KisImportExportErrorCode status = importer.import(files, firstFrame, step);
if (!status.isOk() && !status.isInternalError()) {
QString msg = status.errorMessage();
if (!msg.isEmpty())
QMessageBox::critical(0, i18nc("@title:window", "Krita"), i18n("Could not finish import animation:\n%1", msg));
}
......
......@@ -60,7 +60,7 @@ KisAnimationImporter::KisAnimationImporter(KisDocument* document)
KisAnimationImporter::~KisAnimationImporter()
{}
KisImportExportFilter::ConversionStatus KisAnimationImporter::import(QStringList files, int firstFrame, int step)
KisImportExportErrorCode KisAnimationImporter::import(QStringList files, int firstFrame, int step)
{
Q_ASSERT(step > 0);
......@@ -71,7 +71,7 @@ KisImportExportFilter::ConversionStatus KisAnimationImporter::import(QStringList
QScopedPointer<KisDocument> importDoc(KisPart::instance()->createDocument());
importDoc->setFileBatchMode(true);
KisImportExportFilter::ConversionStatus status = KisImportExportFilter::OK;
KisImportExportErrorCode status = ImportExportCodes::OK;
int frame = firstFrame;
int filesProcessed = 0;
......@@ -83,7 +83,7 @@ KisImportExportFilter::ConversionStatus KisAnimationImporter::import(QStringList
Q_FOREACH(QString file, files) {
bool successfullyLoaded = importDoc->openUrl(QUrl::fromLocalFile(file), KisDocument::DontAddToRecent);
if (!successfullyLoaded) {
status = KisImportExportFilter::InternalError;
status = ImportExportCodes::InternalError;
break;
}
......@@ -109,7 +109,7 @@ KisImportExportFilter::ConversionStatus KisAnimationImporter::import(QStringList
}
if (m_d->stop) {
status = KisImportExportFilter::ProgressCancelled;
status = ImportExportCodes::Cancelled;
break;
}
......
......@@ -22,6 +22,7 @@
#include "kis_types.h"
#include "kritaui_export.h"
#include <KisImportExportFilter.h>
#include <KisImportExportErrorCode.h>
class KisDocument;
class KisMainWindow;
......@@ -35,7 +36,7 @@ public:
KisAnimationImporter(KisDocument* document);
~KisAnimationImporter() override;
KisImportExportFilter::ConversionStatus import(QStringList files, int firstFrame, int step);
KisImportExportErrorCode import(QStringList files, int firstFrame, int step);
private Q_SLOTS:
void cancel();
......
......@@ -59,7 +59,7 @@ T runActionImpl(std::function<T()> func)
return watcher.result();
}
KisImportExportFilter::ConversionStatus KisAsyncActionFeedback::runAction(std::function<KisImportExportFilter::ConversionStatus()> func)
KisImportExportErrorCode KisAsyncActionFeedback::runAction(std::function<KisImportExportErrorCode()> func)
{
return runActionImpl(func);
}
......
......@@ -32,7 +32,7 @@ public:
KisAsyncActionFeedback(const QString &message, QWidget *parent);
~KisAsyncActionFeedback();
KisImportExportFilter::ConversionStatus runAction(std::function<KisImportExportFilter::ConversionStatus()> func);
KisImportExportErrorCode runAction(std::function<KisImportExportErrorCode()> func);
void runVoidAction(std::function<void()> func);
void waitForMutex(QMutex *mutex);
......
......@@ -294,7 +294,7 @@ QList<KisNodeSP> KisMimeData::loadNodes(const QMimeData *data,
QBuffer buf(&ba);
KisImportExportFilter *filter = tempDoc->importExportManager()->filterForMimeType(tempDoc->nativeFormatMimeType(), KisImportExportManager::Import);
filter->setBatchMode(true);
bool result = (filter->convert(tempDoc, &buf) == KisImportExportFilter::OK);
bool result = (filter->convert(tempDoc, &buf).isOk());
if (result) {
KisImageWSP tempImage = tempDoc->image();
......
......@@ -67,6 +67,8 @@
#include <kis_cursor_override_hijacker.h>
#include "kis_undo_stores.h"
#include <kis_assert.h>
namespace
{
......@@ -408,7 +410,7 @@ void _flush_fn(png_structp png_ptr)
Q_UNUSED(png_ptr);
}
KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
KisImportExportErrorCode KisPNGConverter::buildImage(QIODevice* iod)
{
dbgFile << "Start decoding PNG File";
......@@ -421,7 +423,7 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
if (png_sig_cmp(signature, 0, 8) != 0) {
#endif
iod->close();
return (KisImageBuilder_RESULT_BAD_FETCH);
return (ImportExportCodes::FileFormatIncorrect);
}
// Initialize the internal structures
......@@ -434,21 +436,21 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, (png_infopp)0, (png_infopp)0);
iod->close();
return (KisImageBuilder_RESULT_FAILURE);
return (ImportExportCodes::Failure);
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)0);
iod->close();
return (KisImageBuilder_RESULT_FAILURE);
return (ImportExportCodes::Failure);
}
// Catch errors
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
iod->close();
return (KisImageBuilder_RESULT_FAILURE);
return (ImportExportCodes::Failure);
}
// Initialize the special
......@@ -493,7 +495,7 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
if (csName.first.isEmpty()) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
iod->close();
return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE;
return ImportExportCodes::FormatColorSpaceUnsupported;
}
bool hasalpha = (color_type == PNG_COLOR_TYPE_RGB_ALPHA || color_type == PNG_COLOR_TYPE_GRAY_ALPHA);
......@@ -633,7 +635,7 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
if (cs == 0) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE;
return ImportExportCodes::FormatColorSpaceUnsupported;
}
// Creating the KisImageSP
......@@ -697,7 +699,7 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
dbgFile << "bad alloc: " << e.what();
// Free only the already allocated png_byte instances.
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return (KisImageBuilder_RESULT_FAILURE);
return (ImportExportCodes::Failure);
}
// Read the palette if the file is indexed
......@@ -801,7 +803,7 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
}
break;
default:
return KisImageBuilder_RESULT_UNSUPPORTED;
return ImportExportCodes::FormatFeaturesUnsupported;
}
}
m_image->addNode(layer.data(), m_image->rootLayer().data());
......@@ -811,11 +813,11 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
// Freeing memory
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return KisImageBuilder_RESULT_OK;
return ImportExportCodes::OK;
}
KisImageBuilder_Result KisPNGConverter::buildImage(const QString &filename)
KisImportExportErrorCode KisPNGConverter::buildImage(const QString &filename)
{
m_path = filename;
......@@ -823,12 +825,12 @@ KisImageBuilder_Result KisPNGConverter::buildImage(const QString &filename)
if (fp.exists()) {
if (!fp.open(QIODevice::ReadOnly)) {
dbgFile << "Failed to open PNG File";
return (KisImageBuilder_RESULT_FAILURE);
return (ImportExportCodes::FileFormatIncorrect);
}
return buildImage(&fp);
}
return (KisImageBuilder_RESULT_NOT_EXIST);
return (ImportExportCodes::FileNotExist);
}
......@@ -864,8 +866,8 @@ bool KisPNGConverter::saveDeviceToStore(const QString &filename, const QRect &im
dev->convertTo(KoColorSpaceRegistry::instance()->rgb8());
}
bool success = pngconv.buildFile(&io, imageRect, xRes, yRes, dev, annotIt, annotIt, options, metaDataStore);
if (success != KisImageBuilder_RESULT_OK) {
KisImportExportErrorCode success = pngconv.buildFile(&io, imageRect, xRes, yRes, dev, annotIt, annotIt, options, metaDataStore);
if (!success.isOk()) {
dbgFile << "Saving PNG failed:" << filename;
delete metaDataStore;
return false;
......@@ -884,25 +886,24 @@ bool KisPNGConverter::saveDeviceToStore(const QString &filename, const QRect &im
}
KisImageBuilder_Result KisPNGConverter::buildFile(const QString &filename, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store* metaData)
KisImportExportErrorCode KisPNGConverter::buildFile(const QString &filename, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store* metaData)
{
dbgFile << "Start writing PNG File " << filename;
// Open a QIODevice for writing
QFile fp (filename);
if (!fp.open(QIODevice::WriteOnly)) {
dbgFile << "Failed to open PNG File for writing";
return (KisImageBuilder_RESULT_FAILURE);
return (KisImportExportErrorCannotWrite(fp.error()));
}
KisImageBuilder_Result result = buildFile(&fp, imageRect, xRes, yRes, device, annotationsStart, annotationsEnd, options, metaData);
KisImportExportErrorCode result = buildFile(&fp, imageRect, xRes, yRes, device, annotationsStart, annotationsEnd, options, metaData);
return result;
}
KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store* metaData)
KisImportExportErrorCode KisPNGConverter::buildFile(QIODevice* iodevice, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store* metaData)
{
if (!device)
return KisImageBuilder_RESULT_INVALID_ARG;
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(!device, ImportExportCodes::InternalError);
if (!options.alpha) {
KisPaintDeviceSP tmp = new KisPaintDevice(device->colorSpace());
......@@ -959,7 +960,7 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, const QRe
// Initialize structures
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if (!png_ptr) {
return (KisImageBuilder_RESULT_FAILURE);
return (ImportExportCodes::Failure);
}
#if defined(PNG_SKIP_sRGB_CHECK_PROFILE) && defined(PNG_SET_OPTION_SUPPORTED)
......@@ -974,13 +975,13 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, const QRe
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, (png_infopp)0);
return (KisImageBuilder_RESULT_FAILURE);
return (ImportExportCodes::Failure);
}
// If an error occurs during writing, libpng will jump here
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
return (KisImageBuilder_RESULT_FAILURE);
return (ImportExportCodes::Failure);
}
// Initialize the writing
// png_init_io(png_ptr, fp);
......@@ -1056,7 +1057,7 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, const QRe
int interlacetype = options.interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(color_type >= 0, KisImageBuilder_RESULT_FAILURE);
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(color_type >= 0, ImportExportCodes::Failure);
png_set_IHDR(png_ptr, info_ptr,
imageRect.width(),
......@@ -1112,7 +1113,7 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, const QRe
// we should ensure we don't access non-existing palette object
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(palette || color_type != PNG_COLOR_TYPE_PALETTE, KisImageBuilder_RESULT_FAILURE);
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(palette || color_type != PNG_COLOR_TYPE_PALETTE, ImportExportCodes::Failure);
// set the palette
if (color_type == PNG_COLOR_TYPE_PALETTE) {
......@@ -1359,7 +1360,7 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, const QRe
}
break;
default:
return KisImageBuilder_RESULT_UNSUPPORTED;
return ImportExportCodes::FormatColorSpaceUnsupported;
}
}
......@@ -1370,7 +1371,7 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, const QRe
// Free memory
png_destroy_write_struct(&png_ptr, &info_ptr);
return KisImageBuilder_RESULT_OK;
return ImportExportCodes::OK;
}
......
......@@ -29,7 +29,7 @@
#include "kis_global.h"
#include "kis_annotation.h"
#include <kritaui_export.h>
#include <KisImageBuilderResult.h>
#include <KisImportExportErrorCode.h>
class KoStore;
class KisDocument;
......@@ -97,12 +97,12 @@ public:
* temporary location.
* @param filename the file name of the image
*/
KisImageBuilder_Result buildImage(const QString &filename);
KisImportExportErrorCode buildImage(const QString &filename);
/**
* Load an image from a QIODevice.
* @param iod device to access the data
*/
KisImageBuilder_Result buildImage(QIODevice* iod);
KisImportExportErrorCode buildImage(QIODevice* iod);
/**
* Save a layer to a PNG
* @param filename the name of the destination file
......@@ -115,8 +115,8 @@ public:
* @param options PNG formatting options
* @param metaData image metadata
*/
KisImageBuilder_Result buildFile(const QString &filename, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store* metaData);
KisImageBuilder_Result buildFile(QIODevice*, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store* metaData);
KisImportExportErrorCode buildFile(const QString &filename, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store* metaData);
KisImportExportErrorCode buildFile(QIODevice*, const QRect &imageRect, const qreal xRes, const qreal yRes, KisPaintDeviceSP device, vKisAnnotationSP_it annotationsStart, vKisAnnotationSP_it annotationsEnd, KisPNGOptions options, KisMetaData::Store* metaData);
/**
* Retrieve the constructed image
*/
......
......@@ -36,6 +36,7 @@
#include <KisMimeDatabase.h>
#include <kis_time_range.h>
#include <KisImportExportManager.h>
#include <KisImportExportErrorCode.h>
#include "DlgAnimationRenderer.h"
#include <dialogs/KisAsyncAnimationFramesSaveDialog.h>
......@@ -173,12 +174,11 @@ void AnimaterionRenderer::renderAnimationImpl(KisDocument *doc, KisAnimationRend
KIS_SAFE_ASSERT_RECOVER_NOOP(dir.exists());
}
KisImportExportFilter::ConversionStatus res;
KisImportExportErrorCode res;
QFile fi(resultFile);
if (!fi.open(QIODevice::WriteOnly)) {
qWarning() << "Could not open" << fi.fileName() << "for writing!";
doc->setErrorMessage(i18n("Could not open %1 for writing!", fi.fileName()));
res = KisImportExportFilter::CreationError;
res = KisImportExportErrorCannotWrite(fi.error());
} else {
fi.close();
}
......@@ -186,8 +186,8 @@ void AnimaterionRenderer::renderAnimationImpl(KisDocument *doc, KisAnimationRend
QScopedPointer<VideoSaver> encoder(new VideoSaver(doc, batchMode));
res = encoder->convert(doc, savedFilesMask, encoderOptions, batchMode);
if (res != KisImportExportFilter::OK) {
QMessageBox::critical(0, i18nc("@title:window", "Krita"), i18n("Could not render animation:\n%1", doc->errorMessage()));
if (!res.isOk()) {
QMessageBox::critical(0, i18nc("@title:window", "Krita"), i18n("Could not render animation:\n%1", res.errorMessage()));
}
if (encoderOptions.shouldDeleteSequence) {
......
......@@ -103,7 +103,7 @@ public:
: m_cancelled(false),
m_ffmpegPath(ffmpegPath) {}
public:
KisImageBuilder_Result runFFMpeg(const QStringList &specialArgs,
KisImportExportErrorCode runFFMpeg(const QStringList &specialArgs,
const QString &actionName,
const QString &logPath,
int totalFrames)
......@@ -137,7 +137,7 @@ public:
}
private:
KisImageBuilder_Result waitForFFMpegProcess(const QString &message,
KisImportExportErrorCode waitForFFMpegProcess(const QString &message,
QFile &progressFile,
QProcess &ffmpegProcess,
int totalFrames)
......@@ -165,16 +165,16 @@ private:
ffmpegProcess.waitForFinished(5000);
}
KisImageBuilder_Result retval = KisImageBuilder_RESULT_OK;
KisImportExportErrorCode retval = ImportExportCodes::OK;
if (ffmpegProcess.state() != QProcess::NotRunning) {
// sorry...
ffmpegProcess.kill();
retval = KisImageBuilder_RESULT_FAILURE;
retval = ImportExportCodes::Failure;
} else if (m_cancelled) {
retval = KisImageBuilder_RESULT_CANCEL;
retval = ImportExportCodes::Cancelled;
} else if (ffmpegProcess.exitCode()) {
retval = KisImageBuilder_RESULT_FAILURE;
retval = ImportExportCodes::Failure;
}
return retval;
......@@ -203,14 +203,14 @@ KisImageSP VideoSaver::image()
return m_image;
}
KisImageBuilder_Result VideoSaver::encode(const QString &savedFilesMask, const KisAnimationRenderingOptions &options)
KisImportExportErrorCode VideoSaver::encode(const QString &savedFilesMask, const KisAnimationRenderingOptions &options)
{
if (!QFileInfo(options.ffmpegPath).exists()) {
m_doc->setErrorMessage(i18n("ffmpeg could not be found at %1", options.ffmpegPath));
return KisImageBuilder_RESULT_FAILURE;
return ImportExportCodes::Failure;
}
KisImageBuilder_Result result = KisImageBuilder_RESULT_OK;
KisImportExportErrorCode resultOuter = ImportExportCodes::OK;
KisImageAnimationInterface *animation = m_image->animationInterface();
......@@ -245,12 +245,12 @@ KisImageBuilder_Result VideoSaver::encode(const QString &savedFilesMask, const K
<< "-vf" << "palettegen"
<< "-y" << palettePath;
KisImageBuilder_Result result =
KisImportExportErrorCode result =
runner->runFFMpeg(args, i18n("Fetching palette..."),
videoDir.filePath("log_generate_palette_gif.log"),
clipRange.duration());
if (result != KisImageBuilder_RESULT_OK) {
if (!result.isOk()) {
return result;
}
}
......@@ -272,12 +272,12 @@ KisImageBuilder_Result VideoSaver::encode(const QString &savedFilesMask, const K
dbgFile << "savedFilesMask" << savedFilesMask << "start" << QString::number(clipRange.start()) << "duration" << clipRange.duration();
KisImageBuilder_Result result =
KisImportExportErrorCode result =
runner->runFFMpeg(args, i18n("Encoding frames..."),
videoDir.filePath("log_encode_gif.log"),
clipRange.duration());
if (result != KisImageBuilder_RESULT_OK) {
if (!result.isOk()) {
return result;
}
}
......@@ -313,30 +313,19 @@ KisImageBuilder_Result VideoSaver::encode(const QString &savedFilesMask, const K
<< "-y" << resultFile;
result = runner->runFFMpeg(args, i18n("Encoding frames..."),
resultOuter = runner->runFFMpeg(args, i18n("Encoding frames..."),
videoDir.filePath("log_encode.log"),
clipRange.duration());
}
return result;
return resultOuter;
}
KisImportExportFilter::ConversionStatus VideoSaver::convert(KisDocument *document, const QString &savedFilesMask, const KisAnimationRenderingOptions &options, bool batchMode)
KisImportExportErrorCode VideoSaver::convert(KisDocument *document, const QString &savedFilesMask, const KisAnimationRenderingOptions &options, bool batchMode)
{
VideoSaver videoSaver(document, batchMode);
KisImageBuilder_Result res = videoSaver.encode(savedFilesMask, options);
if (res == KisImageBuilder_RESULT_OK) {
return KisImportExportFilter::OK;
} else if (res == KisImageBuilder_RESULT_CANCEL) {
return KisImportExportFilter::ProgressCancelled;
}else {
document->setErrorMessage(i18n("FFMpeg failed to convert the image sequence. Check the logfile in your output directory for more information."));
}
return KisImportExportFilter::InternalError;
KisImportExportErrorCode res = videoSaver.encode(savedFilesMask, options);
return res;
}
#include "video_saver.moc"
......@@ -60,9 +60,9 @@ public:
* @param configuration the configuration
* @return whether it is successful or had another failure.
*/
KisImageBuilder_Result encode(const QString &savedFilesMask, const KisAnimationRenderingOptions &options);
KisImportExportErrorCode encode(const QString &savedFilesMask, const KisAnimationRenderingOptions &options);
static KisImportExportFilter::ConversionStatus convert(KisDocument *document, const QString &savedFilesMask, const KisAnimationRenderingOptions &options, bool batchMode);
static KisImportExportErrorCode convert(KisDocument *document, const QString &savedFilesMask, const KisAnimationRenderingOptions &options, bool batchMode);
private: