Commit b19050f8 authored by Halla Rempt's avatar Halla Rempt
Browse files

CCBUG:373077 Image split: show error dialogs only once

parent e264e421
......@@ -24,11 +24,11 @@
#include <QStringList>
#include <QDir>
#include <QDesktopServices>
#include <QMessageBox>
#include <klocalizedstring.h>
#include <kpluginfactory.h>
#include <KisImportExportManager.h>
#include <KoFileDialog.h>
#include <KisDocument.h>
......@@ -60,7 +60,7 @@ Imagesplit::~Imagesplit()
{
}
void Imagesplit::saveAsImage(const QRect &imgSize, const QString &mimeType, const QString &url)
bool Imagesplit::saveAsImage(const QRect &imgSize, const QString &mimeType, const QString &url)
{
KisImageWSP image = m_view->image();
......@@ -76,11 +76,20 @@ void Imagesplit::saveAsImage(const QRect &imgSize, const QString &mimeType, cons
dst->addNode(paintLayer, KisNodeSP(0));
dst->refreshGraph();
document->setFileBatchMode(true);
document->setOutputMimeType(mimeType.toLatin1());
document->exportDocument(QUrl::fromLocalFile(url));
document->setFileBatchMode(true);
if (!document->exportDocument(QUrl::fromLocalFile(url))) {
if (document->errorMessage().isEmpty()) {
QMessageBox::critical(0, i18nc("@title:window", "Krita"), i18n("Could not save\n%1", document->localFilePath()));
} else {
QMessageBox::critical(0, i18nc("@title:window", "Krita"), i18n("Could not save %1\nReason: %2", document->localFilePath(), document->errorMessage()));
}
return false;
}
delete document;
return true;
}
void Imagesplit::slotImagesplit()
......@@ -118,10 +127,15 @@ void Imagesplit::slotImagesplit()
int img_height = image->height() / (numHorizontalLines + 1);
bool stop = false;
if (dlgImagesplit->autoSave()) {
KoFileDialog dialog(m_view->mainWindow(), KoFileDialog::OpenDirectory, "OpenDocument");
dialog.setCaption(i18n("Save Image on Split"));
dialog.setDefaultDir(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
QStringList mimeFilter = m_view->document()->importExportManager()->mimeFilter(KisImportExportManager::Export);
QString defaultMime = QString::fromLatin1(m_view->document()->mimeType());
dialog.setMimeTypeFilters(mimeFilter, defaultMime);
QUrl directory = QUrl::fromUserInput(dialog.filename());
if (directory.isEmpty())
......@@ -142,7 +156,13 @@ void Imagesplit::slotImagesplit()
qDebug() << "\tsuffix" << suffix;
QString fileName = dlgImagesplit->suffix() + '_' + QString::number(k) + suffix;
QString url = homepath + '/' + fileName;
saveAsImage(QRect((i * img_width), (j * img_height), img_width, img_height), listMimeFilter.at(dlgImagesplit->cmbIndex), url);
if (!saveAsImage(QRect((i * img_width), (j * img_height), img_width, img_height), listMimeFilter.at(dlgImagesplit->cmbIndex), url)) {
stop = true;
break;
}
}
if (stop) {
break;
}
}
}
......@@ -153,14 +173,25 @@ void Imagesplit::slotImagesplit()
KoFileDialog dialog(m_view->mainWindow(), KoFileDialog::SaveFile, "OpenDocument");
dialog.setCaption(i18n("Save Image on Split"));
dialog.setDefaultDir(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
dialog.setMimeTypeFilters(listMimeFilter);
QStringList mimeFilter = m_view->document()->importExportManager()->mimeFilter(KisImportExportManager::Export);
QString defaultMime = QString::fromLatin1(m_view->document()->mimeType());
dialog.setMimeTypeFilters(mimeFilter, defaultMime);
QUrl url = QUrl::fromUserInput(dialog.filename());
QString mimefilter = KisMimeDatabase::mimeTypeForFile(url.toLocalFile());
if (url.isEmpty())
return;
saveAsImage(QRect((i * img_width), (j * img_height), img_width, img_height), mimefilter, url.toLocalFile());
if (!saveAsImage(QRect((i * img_width), (j * img_height), img_width, img_height), mimefilter, url.toLocalFile())) {
stop = true;
break;
}
}
if (stop) {
break;
}
}
......
......@@ -36,7 +36,7 @@ public:
private Q_SLOTS:
void slotImagesplit();
void saveAsImage(const QRect &imgSize, const QString &mimeType, const QString &url);
bool saveAsImage(const QRect &imgSize, const QString &mimeType, const QString &url);
};
#endif // IMAGESPLIT_H
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