Commit 97402490 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Make relative file fetching in animation renderer a bit more robust

When the image is not yet saved, the default base for relative paths
should be 'Pictures' filder.
parent ce50e5ce
......@@ -31,6 +31,7 @@ set(kritaglobal_LIB_SRCS
kis_config_notifier.cpp
KisDeleteLaterWrapper.cpp
KisUsageLogger.cpp
KisFileUtils.cpp
)
add_library(kritaglobal SHARED ${kritaglobal_LIB_SRCS} )
......
/*
* Copyright (c) 2019 Dmitry Kazakov <dimula73@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KisFileUtils.h"
#include <QString>
#include <QFileInfo>
#include <QDir>
namespace KritaUtils {
QString resolveAbsoluteFilePath(const QString &baseDir, const QString &fileName)
{
if (QFileInfo(fileName).isAbsolute()) {
return fileName;
}
QFileInfo fallbackBaseDirInfo(baseDir);
return QFileInfo(QDir(fallbackBaseDirInfo.isDir() ?
fallbackBaseDirInfo.absoluteFilePath() :
fallbackBaseDirInfo.absolutePath()),
fileName).absoluteFilePath();
}
}
/*
* Copyright (c) 2019 Dmitry Kazakov <dimula73@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KISFILEUTILS_H
#define KISFILEUTILS_H
#include "kritaglobal_export.h"
class QString;
namespace KritaUtils {
/**
* @brief Resolve absolute file path from a file path and base dir
*
* If the @p filePath is absolute, just return this path, otherwise
* try to merge @p baseDir and @p filePath to form an absolute file
* path
*/
QString KRITAGLOBAL_EXPORT resolveAbsoluteFilePath(const QString &baseDir, const QString &filePath);
}
#endif // KISFILEUTILS_H
......@@ -23,6 +23,7 @@
#include <QDebug>
#include "KoIcon.h"
#include <KisFileUtils.h>
KisFileNameRequester::KisFileNameRequester(QWidget *parent)
: QWidget(parent)
......@@ -55,7 +56,6 @@ void KisFileNameRequester::setConfigurationName(const QString &name)
void KisFileNameRequester::setFileName(const QString &path)
{
m_ui->txtFileName->setText(path);
m_basePath = path;
emit fileSelected(path);
}
......@@ -91,13 +91,15 @@ void KisFileNameRequester::slotSelectFile()
{
dialog.setCaption(i18n("Select a directory to load..."));
}
if (m_basePath.isEmpty()) {
dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
}
else {
dialog.setDefaultDir(m_basePath);
}
const QString basePath =
KritaUtils::resolveAbsoluteFilePath(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation),
m_basePath);
const QString filePath =
KritaUtils::resolveAbsoluteFilePath(basePath, m_ui->txtFileName->text());
dialog.setDefaultDir(filePath, true);
dialog.setMimeTypeFilters(m_mime_filter_list, m_mime_default_filter);
QString newFileName = dialog.filename();
......
......@@ -129,7 +129,6 @@ DlgAnimationRenderer::DlgAnimationRenderer(KisDocument *doc, QWidget *parent)
}
m_page->videoFilename->setMode(KoFileDialog::SaveFile);
m_page->videoFilename->setStartDir(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
connect(m_page->bnExportOptions, SIGNAL(clicked()), this, SLOT(sequenceMimeTypeSelected()));
connect(m_page->bnRenderOptions, SIGNAL(clicked()), this, SLOT(selectRenderOptions()));
......@@ -196,10 +195,12 @@ void DlgAnimationRenderer::getDefaultVideoEncoderOptions(const QString &mimeType
void DlgAnimationRenderer::loadAnimationOptions(const KisAnimationRenderingOptions &options)
{
const QString documentPath = m_doc->localFilePath();
m_page->txtBasename->setText(options.basename);
if (!options.lastDocuemntPath.isEmpty() &&
options.lastDocuemntPath == m_doc->localFilePath()) {
options.lastDocuemntPath == documentPath) {
m_page->intStart->setValue(options.firstFrame);
m_page->intEnd->setValue(options.lastFrame);
......@@ -207,7 +208,12 @@ void DlgAnimationRenderer::loadAnimationOptions(const KisAnimationRenderingOptio
m_page->intWidth->setValue(options.width);
m_page->intHeight->setValue(options.height);
m_page->intFramesPerSecond->setValue(options.frameRate);
m_page->videoFilename->setStartDir(options.resolveAbsoluteDocumentFilePath(documentPath));
m_page->videoFilename->setFileName(options.videoFileName);
m_page->dirRequester->setStartDir(options.resolveAbsoluteDocumentFilePath(documentPath));
m_page->dirRequester->setFileName(options.directory);
} else {
m_page->intStart->setValue(m_image->animationInterface()->playbackRange().start());
m_page->intEnd->setValue(m_image->animationInterface()->playbackRange().end());
......@@ -215,10 +221,13 @@ void DlgAnimationRenderer::loadAnimationOptions(const KisAnimationRenderingOptio
m_page->intWidth->setValue(m_image->width());
m_page->intHeight->setValue(m_image->height());
m_page->intFramesPerSecond->setValue(m_image->animationInterface()->framerate());
m_page->videoFilename->setStartDir(options.resolveAbsoluteDocumentFilePath(documentPath));
m_page->videoFilename->setFileName(defaultVideoFileName(m_doc, options.videoMimeType));
}
m_page->dirRequester->setStartDir(options.resolveAbsoluteDocumentFilePath(documentPath));
m_page->dirRequester->setFileName(options.directory);
}
for (int i = 0; i < m_page->cmbMimetype->count(); ++i) {
if (m_page->cmbMimetype->itemData(i).toString() == options.frameMimeType) {
......@@ -256,6 +265,7 @@ void DlgAnimationRenderer::loadAnimationOptions(const KisAnimationRenderingOptio
&m_forceHDRVideo);
}
m_page->ffmpegLocation->setStartDir(QFileInfo(m_doc->localFilePath()).path());
m_page->ffmpegLocation->setFileName(findFFMpeg(options.ffmpegPath));
}
......
......@@ -21,7 +21,8 @@
#include <QStandardPaths>
#include <QFileInfo>
#include <QDir>
#include <KisFileUtils.h>
KisAnimationRenderingOptions::KisAnimationRenderingOptions()
: videoMimeType("video/mp4"),
......@@ -32,28 +33,38 @@ KisAnimationRenderingOptions::KisAnimationRenderingOptions()
}
inline QString composePath(const QString &pathChunk, const QString &fileNameChunk)
QString KisAnimationRenderingOptions::resolveAbsoluteDocumentFilePath(const QString &documentPath) const
{
if (QFileInfo(fileNameChunk).isAbsolute()) {
return fileNameChunk;
}
return QFileInfo(QDir(QFileInfo(pathChunk).absolutePath()),
fileNameChunk).absoluteFilePath();
return
!documentPath.isEmpty() ?
documentPath :
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
}
QString KisAnimationRenderingOptions::resolveAbsoluteVideoFilePath() const
QString KisAnimationRenderingOptions::resolveAbsoluteVideoFilePath(const QString &documentPath) const
{
return composePath(lastDocuemntPath, videoFileName);
const QString basePath = resolveAbsoluteDocumentFilePath(documentPath);
return KritaUtils::resolveAbsoluteFilePath(basePath, videoFileName);
}
QString KisAnimationRenderingOptions::resolveAbsoluteFramesDirectory() const
QString KisAnimationRenderingOptions::resolveAbsoluteFramesDirectory(const QString &documentPath) const
{
if (renderMode() == RENDER_VIDEO_ONLY) {
return QFileInfo(resolveAbsoluteVideoFilePath()).absolutePath();
}
return composePath(lastDocuemntPath, directory);
const QString basePath = resolveAbsoluteDocumentFilePath(documentPath);
return KritaUtils::resolveAbsoluteFilePath(basePath, directory);
}
QString KisAnimationRenderingOptions::resolveAbsoluteVideoFilePath() const
{
return resolveAbsoluteVideoFilePath(lastDocuemntPath);
}
QString KisAnimationRenderingOptions::resolveAbsoluteFramesDirectory() const
{
return resolveAbsoluteFramesDirectory(lastDocuemntPath);
}
KisAnimationRenderingOptions::RenderMode KisAnimationRenderingOptions::renderMode() const
......
......@@ -50,9 +50,14 @@ struct KisAnimationRenderingOptions
QString customFFMpegOptions;
KisPropertiesConfigurationSP frameExportConfig;
QString resolveAbsoluteDocumentFilePath(const QString &documentPath) const;
QString resolveAbsoluteVideoFilePath(const QString &documentPath) const;
QString resolveAbsoluteFramesDirectory(const QString &documentPath) const;
QString resolveAbsoluteVideoFilePath() const;
QString resolveAbsoluteFramesDirectory() const;
enum RenderMode {
RENDER_FRAMES_ONLY,
RENDER_VIDEO_ONLY,
......
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