import: safely handle unsupported files

Fixes #1191
This commit is contained in:
itsmattkc
2020-09-18 12:58:55 +10:00
parent e733d1c278
commit 8506c82a0c
7 changed files with 148 additions and 8 deletions
+2
View File
@@ -18,5 +18,7 @@ set(OLIVE_SOURCES
${OLIVE_SOURCES}
task/project/import/import.h
task/project/import/import.cpp
task/project/import/importerrordialog.h
task/project/import/importerrordialog.cpp
PARENT_SCOPE
)
+4 -1
View File
@@ -122,7 +122,10 @@ void ProjectImportTask::Import(Folder *folder, const QFileInfoList &import, int
f->set_project(nullptr);
if (f->status() != Footage::kInvalid) {
if (f->status() == Footage::kInvalid) {
// Add to list so we can tell the user about it later
invalid_files_.append(file_info.absoluteFilePath());
} else {
// Create undoable command that adds the items to the model
new ProjectViewModel::AddItemCommand(model_,
folder,
+12
View File
@@ -42,6 +42,16 @@ public:
return command_;
}
const QStringList& GetInvalidFiles() const
{
return invalid_files_;
}
bool HasInvalidFiles() const
{
return !invalid_files_.isEmpty();
}
protected:
virtual bool Run() override;
@@ -58,6 +68,8 @@ private:
int file_count_;
QStringList invalid_files_;
};
OLIVE_NAMESPACE_EXIT
@@ -0,0 +1,53 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "importerrordialog.h"
#include <QDialogButtonBox>
#include <QLabel>
#include <QListWidget>
#include <QVBoxLayout>
OLIVE_NAMESPACE_ENTER
ProjectImportErrorDialog::ProjectImportErrorDialog(const QStringList& filenames, QWidget* parent) :
QDialog(parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
setWindowTitle(tr("Import Error"));
layout->addWidget(new QLabel(tr("The following files failed to import. Olive likely does not "
"support their formats.")));
QListWidget* list_widget = new QListWidget();
foreach (const QString& s, filenames) {
list_widget->addItem(s);
}
layout->addWidget(list_widget);
QDialogButtonBox* buttons = new QDialogButtonBox();
buttons->setStandardButtons(QDialogButtonBox::Ok);
buttons->setCenterButtons(true);
connect(buttons, &QDialogButtonBox::accepted, this, &ProjectImportErrorDialog::accept);
layout->addWidget(buttons);
}
OLIVE_NAMESPACE_EXIT
@@ -0,0 +1,40 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef PROJECTIMPORTERRORDIALOG_H
#define PROJECTIMPORTERRORDIALOG_H
#include <QDialog>
#include "common/define.h"
OLIVE_NAMESPACE_ENTER
class ProjectImportErrorDialog : public QDialog
{
Q_OBJECT
public:
ProjectImportErrorDialog(const QStringList& filenames, QWidget* parent = nullptr);
};
OLIVE_NAMESPACE_EXIT
#endif // PROJECTIMPORTERRORDIALOG_H