Temporary fix: Locate missing media file from project

This commit is contained in:
baydam
2019-03-20 21:08:28 +00:00
parent f6ff029394
commit a84dd96bcf
2 changed files with 37 additions and 17 deletions
+17
View File
@@ -99,6 +99,22 @@ void ProjectReader::parseProject(const QDomElement& project)
{
manager.addPaint(paint);
_window->addPaintItem(paint->getId(), paint->getIcon(), paint->getName());
// Locate media file if not found
if (paint->getType() == "media")
{
QSharedPointer<Video> media = qSharedPointerCast<Video>(paint);
Q_CHECK_PTR(media);
if (!_window->fileExists(media->getUri()))
media->setUri(_window->locateMediaFile(media->getUri(), false));
}
if (paint->getType() == "image")
{
QSharedPointer<Image> image = qSharedPointerCast<Image>(paint);
Q_CHECK_PTR(image);
if (!_window->fileExists(image->getUri()))
image->setUri(_window->locateMediaFile(image->getUri(), true));
}
}
paintNode = paintNode.nextSibling();
}
@@ -134,6 +150,7 @@ Paint::ptr ProjectReader::parsePaint(const QDomElement& paintElem)
{
// Create new instance.
Paint::ptr paint (qobject_cast<Paint*>(metaObject->newInstance( Q_ARG(int, id)) ));
if (paint.isNull())
{
qDebug() << QObject::tr("Problem at creation of paint.") << endl;
+20 -17
View File
@@ -1097,11 +1097,7 @@ uid MainWindow::createMediaPaint(uid paintId, QString uri, float x, float y,
else
{
// Check if file exists before
//if (! fileExists(uri))
//uri = locateMediaFile(uri, isImage);
Texture* tex = 0;
Texture* tex = nullptr;
if (isImage)
tex = new Image(uri, paintId);
else {
@@ -3078,13 +3074,9 @@ QString MainWindow::locateMediaFile(const QString &uri, bool isImage)
QFileInfo file(uri);
// The name of the file
QString filename = file.fileName();
// The directory name
QString directory = file.absolutePath();
// Handle the case where it is video or image
QString mediaFilter = isImage ? MM::IMAGE_FILES_FILTER : MM::VIDEO_FILES_FILTER;
QString mediaType = isImage ? "Images" : "Videos";
// New linked uri
QString url;
// Show a warning and offer to locate the file
QMessageBox::warning(this,
@@ -3094,18 +3086,29 @@ QString MainWindow::locateMediaFile(const QString &uri, bool isImage)
.arg(filename));
// Set the new uri
url = QFileDialog::getOpenFileName(this,
tr("Locate file %1").arg(filename),
directory,
tr("%1 files (%2)")
.arg(mediaType)
.arg(mediaFilter));
#ifdef Q_OS_LINUX
QString newUri = QFileDialog::getOpenFileName(this,
tr("Locate file %1").arg(filename),
file.absolutePath(),
tr("%1 files (%2)")
.arg(mediaType)
.arg(mediaFilter),
nullptr, QFileDialog::DontUseNativeDialog);
#else
QString newUri = QFileDialog::getOpenFileName(this,
tr("Locate file %1").arg(filename),
file.absolutePath(),
tr("%1 files (%2)")
.arg(mediaType)
.arg(mediaFilter));
#endif
return newUri;
return url;
}
MainWindow* MainWindow::window() {
static MainWindow* instance = 0;
static MainWindow* instance = nullptr;
if (!instance) {
instance = new MainWindow;
}