Limit import files

This commit is contained in:
2026-01-05 16:36:43 +08:00
parent 4bd453bab0
commit 6b64abb1fa
5 changed files with 205 additions and 7 deletions
+117 -3
View File
@@ -74,6 +74,72 @@
#include "widget/menu/menushared.h"
#include "window/mainwindow/mainwindow.h"
namespace {
QStringList FootageVideoExtensions()
{
return QStringList{
QStringLiteral("mp4"), QStringLiteral("mov"), QStringLiteral("m4v"),
QStringLiteral("avi"), QStringLiteral("mpg"), QStringLiteral("mpeg"),
QStringLiteral("m2ts"), QStringLiteral("mts"), QStringLiteral("ts"),
QStringLiteral("webm"), QStringLiteral("wmv"), QStringLiteral("flv"),
QStringLiteral("3gp"), QStringLiteral("3g2"), QStringLiteral("mxf")
};
}
QStringList FootageAudioExtensions()
{
return QStringList{
QStringLiteral("wav"), QStringLiteral("mp3"), QStringLiteral("flac"),
QStringLiteral("aac"), QStringLiteral("ogg"), QStringLiteral("opus"),
QStringLiteral("m4a"), QStringLiteral("alac"), QStringLiteral("aif"),
QStringLiteral("aiff"), QStringLiteral("aifc"), QStringLiteral("wma")
};
}
QStringList FootageImageExtensions()
{
return QStringList{
QStringLiteral("png"), QStringLiteral("jpg"), QStringLiteral("jpeg"),
QStringLiteral("tif"), QStringLiteral("tiff"), QStringLiteral("bmp"),
QStringLiteral("gif"), QStringLiteral("exr"), QStringLiteral("dpx"),
QStringLiteral("webp")
};
}
QString BuildFootageFilterGroup(const QString &label,
const QStringList &extensions)
{
QStringList patterns;
patterns.reserve(extensions.size());
for (const QString &ext : extensions) {
patterns.append(QStringLiteral("*.%1").arg(ext));
}
return QStringLiteral("%1 (%2)")
.arg(label, patterns.join(QLatin1Char(' ')));
}
QString BuildFootageFileDialogFilter()
{
QStringList all = FootageVideoExtensions() + FootageAudioExtensions() +
FootageImageExtensions();
all.removeDuplicates();
QStringList groups;
groups << BuildFootageFilterGroup(QObject::tr("Common Media Files"), all);
groups << BuildFootageFilterGroup(QObject::tr("Video Files"),
FootageVideoExtensions());
groups << BuildFootageFilterGroup(QObject::tr("Audio Files"),
FootageAudioExtensions());
groups << BuildFootageFilterGroup(QObject::tr("Image Files"),
FootageImageExtensions());
return groups.join(QStringLiteral(";;"));
}
} // namespace
namespace olive
{
@@ -102,6 +168,29 @@ Core *Core::instance()
return instance_;
}
QString Core::FootageFileDialogFilter()
{
return BuildFootageFileDialogFilter();
}
QStringList Core::AllowedFootageExtensions()
{
QStringList all = FootageVideoExtensions() + FootageAudioExtensions() +
FootageImageExtensions();
all.removeDuplicates();
return all;
}
bool Core::IsFootageExtensionAllowed(const QString &path)
{
const QString ext = QFileInfo(path).suffix().toLower();
if (ext.isEmpty()) {
return false;
}
return AllowedFootageExtensions().contains(ext);
}
void Core::DeclareTypesForQt()
{
qRegisterMetaType<olive::core::rational>();
@@ -240,7 +329,31 @@ void Core::ImportFiles(const QStringList &urls, Folder *parent)
return;
}
ProjectImportTask *pim = new ProjectImportTask(parent, urls);
QStringList filtered_urls;
QStringList rejected_urls;
filtered_urls.reserve(urls.size());
for (const QString &url : urls) {
if (IsFootageExtensionAllowed(url)) {
filtered_urls.append(url);
} else {
rejected_urls.append(url);
}
}
if (!rejected_urls.isEmpty()) {
QMessageBox::warning(
main_window_, tr("Unsupported media"),
tr("Skipped %1 file(s) that are not allowed by the current media "
"type filter.")
.arg(rejected_urls.size()));
}
if (filtered_urls.isEmpty()) {
return;
}
ProjectImportTask *pim = new ProjectImportTask(parent, filtered_urls);
if (!pim->GetFileCount()) {
// No files to import
@@ -333,8 +446,9 @@ void Core::DialogAboutShow()
void Core::DialogImportShow()
{
// Open dialog for user to select files
QStringList files =
QFileDialog::getOpenFileNames(main_window_, tr("Import footage..."));
QStringList files = QFileDialog::getOpenFileNames(
main_window_, tr("Import footage..."), QString(),
FootageFileDialogFilter());
// Check if the user actually selected files to import
if (!files.isEmpty()) {