Fix Windows paths (export profile, renderer, etc)

parent f864233a
......@@ -20,6 +20,7 @@
#include <stdio.h>
#include <QCoreApplication>
#include <QStringList>
#include <QFileInfo>
#include <QString>
#include <QUrl>
#include <QDebug>
......@@ -70,12 +71,11 @@ int main(int argc, char **argv)
QString player = args.takeFirst();
QByteArray srcString = args.takeFirst().toUtf8();
QUrl srcurl = QUrl::fromEncoded(srcString);
QString src = srcurl.path();
QString src = srcurl.toLocalFile();
// The QUrl path() strips the consumer: protocol, so re-add it if necessary
if (srcString.startsWith("consumer:"))
src.prepend(QLatin1String("consumer:"));
QUrl desturl = QUrl::fromEncoded(args.takeFirst().toUtf8());
QString dest = desturl.path();
QString dest = QFileInfo(QUrl::fromEncoded(args.takeFirst().toUtf8()).toLocalFile()).absoluteFilePath();
bool dualpass = false;
bool doerase;
QString vpre;
......
......@@ -188,8 +188,7 @@ void RenderJob::start()
initKdenliveDbusInterface();
// Make sure the destination directory is writable
QString path = QUrl::fromLocalFile(m_dest).toString(QUrl::RemoveFilename | QUrl::RemoveScheme);
QFileInfo checkDestination(path);
QFileInfo checkDestination(QFileInfo(m_dest).absolutePath());
if (!checkDestination.isWritable()) {
slotIsOver(QProcess::NormalExit, false);
}
......@@ -286,7 +285,7 @@ void RenderJob::slotIsOver(QProcess::ExitStatus status, bool isWritable)
QStringList args = m_player.split(QLatin1Char(' '));
QString exec = args.takeFirst();
// Decode url
QString url = QUrl::fromEncoded(args.takeLast().toUtf8()).path();
QString url = QUrl::fromEncoded(args.takeLast().toUtf8()).toLocalFile();
args << url;
QProcess::startDetached(exec, args);
}
......
......@@ -305,7 +305,11 @@ RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, const
header->resizeSection(0, size + 4);
// Find path for Kdenlive renderer
#ifdef Q_OS_WIN
m_renderer = QCoreApplication::applicationDirPath() + QStringLiteral("/kdenlive_render.exe");
#else
m_renderer = QCoreApplication::applicationDirPath() + QStringLiteral("/kdenlive_render");
#endif
if (!QFile::exists(m_renderer)) {
m_renderer = QStandardPaths::findExecutable(QStringLiteral("kdenlive_render"));
if (m_renderer.isEmpty())
......@@ -363,7 +367,7 @@ void RenderWidget::showInfoPanel()
void RenderWidget::setDocumentPath(const QString &path)
{
if (m_view.out_file->url().adjusted(QUrl::RemoveFilename).path() == QUrl::fromLocalFile(m_projectFolder).adjusted(QUrl::RemoveFilename).path()) {
if (m_view.out_file->url().adjusted(QUrl::RemoveFilename).toLocalFile() == QUrl::fromLocalFile(m_projectFolder).adjusted(QUrl::RemoveFilename).toLocalFile()) {
const QString fileName = m_view.out_file->url().fileName();
m_view.out_file->setUrl(QUrl::fromLocalFile(path + fileName));
}
......@@ -942,12 +946,12 @@ void RenderWidget::slotPrepareExport(bool scriptExport, const QString scriptPath
return;
}
QString chapterFile;
if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().path() + ".dvdchapter";
if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().toLocalFile() + ".dvdchapter";
// mantisbt 1051
QDir dir;
if (!dir.mkpath(m_view.out_file->url().adjusted(QUrl::RemoveFilename).path())) {
KMessageBox::sorry(this, i18n("The directory %1, could not be created.\nPlease make sure you have the required permissions.", m_view.out_file->url().adjusted(QUrl::RemoveFilename).path()));
QDir dir(m_view.out_file->url().adjusted(QUrl::RemoveFilename).toLocalFile());
if (!dir.exists() && !dir.mkpath(QStringLiteral("."))) {
KMessageBox::sorry(this, i18n("The directory %1, could not be created.\nPlease make sure you have the required permissions.", m_view.out_file->url().adjusted(QUrl::RemoveFilename).toLocalFile()));
return;
}
......@@ -963,7 +967,7 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut,
if (!item)
return;
QString destBase = m_view.out_file->url().path().trimmed();
QString destBase = m_view.out_file->url().toLocalFile().trimmed();
if (destBase.isEmpty())
return;
......@@ -1220,11 +1224,11 @@ void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut,
}
if (resizeProfile && !KdenliveSettings::gpu_accel())
render_process_args << "consumer:" + (scriptExport ? "$SOURCE_" + QString::number(stemIdx) : playlistPaths.at(stemIdx));
render_process_args << "consumer:" + (scriptExport ? "$SOURCE_" + QString::number(stemIdx) : QUrl::fromLocalFile(playlistPaths.at(stemIdx)).toEncoded());
else
render_process_args << (scriptExport ? "$SOURCE_" + QString::number(stemIdx) : playlistPaths.at(stemIdx));
render_process_args << (scriptExport ? "$SOURCE_" + QString::number(stemIdx) : QUrl::fromLocalFile(playlistPaths.at(stemIdx)).toEncoded());
render_process_args << (scriptExport ? "$TARGET_" + QString::number(stemIdx) : QUrl::fromLocalFile(dest).url());
render_process_args << (scriptExport ? "$TARGET_" + QString::number(stemIdx) : QUrl::fromLocalFile(dest).toEncoded());
if (KdenliveSettings::gpu_accel()) {
render_process_args << QStringLiteral("glsl.=1");
}
......@@ -1528,7 +1532,7 @@ void RenderWidget::refreshView()
QUrl RenderWidget::filenameWithExtension(QUrl url, const QString &extension)
{
if (!url.isValid()) url = QUrl::fromLocalFile(m_projectFolder);
QString directory = url.adjusted(QUrl::RemoveFilename).path();
QString directory = url.adjusted(QUrl::RemoveFilename).toLocalFile();
QString filename = url.fileName();
QString ext;
......@@ -1687,6 +1691,10 @@ void RenderWidget::parseProfiles(const QString &selectedProfile)
// Parse our xml profile
QString exportFile = QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("export/profiles.xml"));
if (exportFile.isEmpty()) {
// Check local folder (non installed)
exportFile = qApp->applicationDirPath() + QStringLiteral("/data/kdenlive/export/profiles.xml");
}
parseFile(exportFile, false);
// Parse some MLT's profiles
......@@ -2166,7 +2174,7 @@ void RenderWidget::parseScriptFiles()
QString target;
QString renderer;
QString melt;
QFile file(scriptpath.path());
QFile file(scriptpath.toLocalFile());
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream stream(&file);
while (!stream.atEnd()) {
......@@ -2197,7 +2205,7 @@ void RenderWidget::parseScriptFiles()
} else item->setIcon(0, QIcon::fromTheme(QStringLiteral("application-x-executable-script")));
item->setSizeHint(0, QSize(m_view.scripts_list->columnWidth(0), fontMetrics().height() * 2));
item->setData(1, Qt::UserRole, QUrl(QUrl::fromEncoded(target.toUtf8())).url(QUrl::PreferLocalFile));
item->setData(1, Qt::UserRole + 1, scriptpath.path());
item->setData(1, Qt::UserRole + 1, scriptpath.toLocalFile());
}
QTreeWidgetItem *script = m_view.scripts_list->topLevelItem(0);
if (script) {
......
......@@ -220,10 +220,10 @@ MainWindow::MainWindow(const QString &MltPath, const QUrl &Url, const QString &
//QIcon::setThemeSearchPaths(QStringList() <<QStringLiteral(":/icons/"));
new RenderingAdaptor(this);
pCore->initialize();
MltConnection::locateMeltAndProfilesPath(MltPath);
QString defaultProfile = KdenliveSettings::default_profile();
KdenliveSettings::setCurrent_profile(defaultProfile.isEmpty() ? ProjectManager::getDefaultProjectFormat() : defaultProfile);
pCore->initialize();
// If using a custom profile, make sure the file exists or fallback to default
if (KdenliveSettings::current_profile().startsWith(QStringLiteral("/")) && !QFile::exists(KdenliveSettings::current_profile())) {
......@@ -3297,7 +3297,7 @@ void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QS
delete getUrl;
return;
}
scriptPath = getUrl->selectedUrl().path();
scriptPath = getUrl->selectedUrl().toLocalFile();
delete getUrl;
}
QFile f(scriptPath);
......@@ -3320,7 +3320,7 @@ void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QS
} else {
out = (int) GenTime(project->projectDuration()).frames(project->fps()) - 2;
}
QString playlistContent = pCore->projectManager()->projectSceneList(project->url().adjusted(QUrl::RemoveFilename).path());
QString playlistContent = pCore->projectManager()->projectSceneList(project->url().adjusted(QUrl::RemoveFilename).toLocalFile());
if (!chapterFile.isEmpty()) {
QDomDocument doc;
QDomElement chapters = doc.createElement(QStringLiteral("chapters"));
......@@ -3490,7 +3490,9 @@ void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QS
plPath = plPath + "_" + QString(trackNames.at(i)).replace(QLatin1String(" "), QLatin1String("_"));
}
// add mlt suffix
plPath += mltSuffix;
if (!plPath.endsWith(mltSuffix)) {
plPath += mltSuffix;
}
playlistPaths << plPath;
qDebug() << "playlistPath: " << plPath << endl;
......
......@@ -31,16 +31,26 @@ MltConnection::MltConnection(QObject* parent) :
void MltConnection::locateMeltAndProfilesPath(const QString& mltPath)
{
QString profilePath = mltPath;
if (!KdenliveSettings::mltpath().isEmpty() && QFile::exists(KdenliveSettings::mltpath())) {
return;
}
if (profilePath.isEmpty() || !QFile::exists(profilePath)) profilePath = qgetenv("MLT_PROFILES_PATH");
if (profilePath.isEmpty() || !QFile::exists(profilePath)) profilePath = qgetenv("MLT_DATA") + "/profiles/";
if (profilePath.isEmpty() || !QFile::exists(profilePath)) profilePath = qgetenv("MLT_PREFIX") + "/share/mlt/profiles/";
if (profilePath.isEmpty() || !QFile::exists(profilePath)) profilePath = KdenliveSettings::mltpath();
if (profilePath.isEmpty() || !QFile::exists(profilePath)) profilePath = QStringLiteral(MLT_DATADIR) + "/profiles/"; // build-time definition
// build-time definition
if (profilePath.isEmpty() || !QFile::exists(profilePath)) profilePath = QStringLiteral(MLT_DATADIR) + "/profiles/";
KdenliveSettings::setMltpath(profilePath);
#ifdef Q_OS_WIN
QString meltPath = QDir::cleanPath(profilePath).section('/', 0, -3) + "melt.exe";
if (!QFile::exists(meltPath)) meltPath = qgetenv("MLT_PREFIX") + "melt.exe";
if (!QFile::exists(meltPath) || profilePath.isEmpty()) {
QString env = qgetenv("MLT_PREFIX");
if (env.isEmpty()) {
env = qApp->applicationDirPath() + QStringLiteral("/");
}
meltPath = env + "melt.exe";
}
#else
QString meltPath = QDir::cleanPath(profilePath).section('/', 0, -3) + "/bin/melt";
if (!QFile::exists(meltPath)) meltPath = qgetenv("MLT_PREFIX") + "/bin/melt";
......@@ -77,12 +87,12 @@ void MltConnection::locateMeltAndProfilesPath(const QString& mltPath)
if (!meltPath.isEmpty()) {
if(meltPath.contains('/')) {
#ifdef Q_OS_WIN
profilePath = meltPath.section('/', 0, -1) + "/share/mlt/profiles/";
profilePath = meltPath.section('/', 0, -2) + "/share/mlt/profiles/";
#else
profilePath = meltPath.section('/', 0, -2) + "/share/mlt/profiles/";
profilePath = meltPath.section('/', 0, -2) + "/share/mlt/profiles/";
#endif
} else {
profilePath = QDir::currentPath() + "/share/mlt/profiles/";
profilePath = qApp->applicationDirPath() + "/share/mlt/profiles/";
}
KdenliveSettings::setMltpath(profilePath);
profilesList = QDir(profilePath).entryList(profilesFilter, QDir::Files);
......@@ -97,7 +107,7 @@ void MltConnection::locateMeltAndProfilesPath(const QString& mltPath)
delete getUrl;
::exit(0);
} else {
profilePath = getUrl->selectedUrl().path();
profilePath = getUrl->selectedUrl().toLocalFile();
delete getUrl;
if (mltPath.isEmpty()) {
::exit(0);
......@@ -109,7 +119,6 @@ void MltConnection::locateMeltAndProfilesPath(const QString& mltPath)
}
}
qDebug() << "MLT profiles path: " << KdenliveSettings::mltpath();
// Parse again MLT profiles to build a list of available video formats
if (profilesList.isEmpty()) {
locateMeltAndProfilesPath();
......
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