change: change code style to Linux style except indent.

This commit is contained in:
Mike Solar
2025-08-03 03:09:40 +08:00
parent 65ab76edc8
commit 74f73ab3be
789 changed files with 77113 additions and 68888 deletions
+194 -178
View File
@@ -28,258 +28,274 @@
#include "node/nodeundo.h"
#include "node/project/footage/footage.h"
namespace olive {
ProjectImportTask::ProjectImportTask(Folder *folder, const QStringList &filenames) :
command_(nullptr),
folder_(folder)
namespace olive
{
foreach (const QString& f, filenames) {
filenames_.append(QFileInfo(f));
}
file_count_ = Core::CountFilesInFileList(filenames_);
ProjectImportTask::ProjectImportTask(Folder *folder,
const QStringList &filenames)
: command_(nullptr)
, folder_(folder)
{
foreach (const QString &f, filenames) {
filenames_.append(QFileInfo(f));
}
SetTitle(tr("Importing %n file(s)", nullptr, file_count_));
file_count_ = Core::CountFilesInFileList(filenames_);
SetTitle(tr("Importing %n file(s)", nullptr, file_count_));
}
const int &ProjectImportTask::GetFileCount() const
{
return file_count_;
return file_count_;
}
bool ProjectImportTask::Run()
{
command_ = new MultiUndoCommand();
command_ = new MultiUndoCommand();
int imported = 0;
int imported = 0;
Import(folder_, filenames_, imported, command_);
Import(folder_, filenames_, imported, command_);
if (IsCancelled()) {
delete command_;
command_ = nullptr;
return false;
} else {
return true;
}
if (IsCancelled()) {
delete command_;
command_ = nullptr;
return false;
} else {
return true;
}
}
void ProjectImportTask::Import(Folder *folder, QFileInfoList import, int &counter, MultiUndoCommand* parent_command)
void ProjectImportTask::Import(Folder *folder, QFileInfoList import,
int &counter, MultiUndoCommand *parent_command)
{
for (int i=0; i<import.size(); i++) {
if (IsCancelled()) {
break;
}
for (int i = 0; i < import.size(); i++) {
if (IsCancelled()) {
break;
}
const QFileInfo& file_info = import.at(i);
const QFileInfo &file_info = import.at(i);
// Check if this file is a directory
if (file_info.isDir()) {
// Check if this file is a directory
if (file_info.isDir()) {
// QDir::entryList only returns filenames, we can use entryInfoList() to get full paths
QFileInfoList entry_list =
QDir(file_info.absoluteFilePath()).entryInfoList();
// QDir::entryList only returns filenames, we can use entryInfoList() to get full paths
QFileInfoList entry_list = QDir(file_info.absoluteFilePath()).entryInfoList();
// Strip out "." and ".." (for some reason QDir::NoDotAndDotDot doesn't work with entryInfoList, so we have to
// check manually)
for (int j = 0; j < entry_list.size(); j++) {
if (entry_list.at(j).fileName() == QStringLiteral(".") ||
entry_list.at(j).fileName() == QStringLiteral("..")) {
entry_list.removeAt(j);
j--;
}
}
// Strip out "." and ".." (for some reason QDir::NoDotAndDotDot doesn't work with entryInfoList, so we have to
// check manually)
for (int j=0;j<entry_list.size();j++) {
if (entry_list.at(j).fileName() == QStringLiteral(".")
|| entry_list.at(j).fileName() == QStringLiteral("..")) {
entry_list.removeAt(j);
j--;
}
}
// Only proceed if the empty actually has files in it
if (!entry_list.isEmpty()) {
// Create a folder corresponding to the directory
Folder *f = new Folder();
// Only proceed if the empty actually has files in it
if (!entry_list.isEmpty()) {
// Create a folder corresponding to the directory
Folder* f = new Folder();
f->SetLabel(file_info.fileName());
f->SetLabel(file_info.fileName());
// Create undoable command that adds the items to the model
AddItemToFolder(folder, f, parent_command);
// Create undoable command that adds the items to the model
AddItemToFolder(folder, f, parent_command);
// Recursively follow this path
Import(f, entry_list, counter, parent_command);
}
// Recursively follow this path
Import(f, entry_list, counter, parent_command);
}
} else {
Footage *footage = new Footage();
} else {
footage->SetCancelPointer(this->GetCancelAtom());
Footage* footage = new Footage();
footage->set_filename(file_info.absoluteFilePath());
footage->SetLabel(file_info.fileName());
footage->SetCancelPointer(this->GetCancelAtom());
footage->SetCancelPointer(nullptr);
footage->set_filename(file_info.absoluteFilePath());
footage->SetLabel(file_info.fileName());
if (footage->IsValid()) {
// See if this footage is an image sequence
ValidateImageSequence(footage, import, i);
footage->SetCancelPointer(nullptr);
// Create undoable command that adds the items to the model
AddItemToFolder(folder, footage, parent_command);
if (footage->IsValid()) {
// See if this footage is an image sequence
ValidateImageSequence(footage, import, i);
// Add to vector
imported_footage_.push_back(footage);
} else {
// Add to list so we can tell the user about it later
invalid_files_.append(file_info.absoluteFilePath());
// Create undoable command that adds the items to the model
AddItemToFolder(folder, footage, parent_command);
delete footage;
}
// Add to vector
imported_footage_.push_back(footage);
} else {
// Add to list so we can tell the user about it later
invalid_files_.append(file_info.absoluteFilePath());
counter++;
delete footage;
}
counter++;
emit ProgressChanged(static_cast<double>(counter) / static_cast<double>(file_count_));
}
}
emit ProgressChanged(static_cast<double>(counter) /
static_cast<double>(file_count_));
}
}
}
void ProjectImportTask::ValidateImageSequence(Footage *footage, QFileInfoList& info_list, int index)
void ProjectImportTask::ValidateImageSequence(Footage *footage,
QFileInfoList &info_list,
int index)
{
// Heuristically determine whether this file is part of an image sequence or not
//
// By this point we've established that video contains a single still image stream. Now we'll
// see if it ends with numbers.
if (Decoder::GetImageSequenceDigitCount(footage->filename()) > 0
&& !image_sequence_ignore_files_.contains(footage->filename())
&& footage->InputArraySize(Footage::kVideoParamsInput)) {
VideoParams video_stream = footage->GetVideoParams(0);
QSize dim(video_stream.width(), video_stream.height());
// Heuristically determine whether this file is part of an image sequence or not
//
// By this point we've established that video contains a single still image stream. Now we'll
// see if it ends with numbers.
if (Decoder::GetImageSequenceDigitCount(footage->filename()) > 0 &&
!image_sequence_ignore_files_.contains(footage->filename()) &&
footage->InputArraySize(Footage::kVideoParamsInput)) {
VideoParams video_stream = footage->GetVideoParams(0);
QSize dim(video_stream.width(), video_stream.height());
int64_t ind = Decoder::GetImageSequenceIndex(footage->filename());
int64_t ind = Decoder::GetImageSequenceIndex(footage->filename());
// Check if files around exist around it with that follow a sequence
QString previous_img_fn = Decoder::TransformImageSequenceFileName(footage->filename(), ind - 1);
QString next_img_fn = Decoder::TransformImageSequenceFileName(footage->filename(), ind + 1);
// Check if files around exist around it with that follow a sequence
QString previous_img_fn = Decoder::TransformImageSequenceFileName(
footage->filename(), ind - 1);
QString next_img_fn = Decoder::TransformImageSequenceFileName(
footage->filename(), ind + 1);
Footage* previous_file = new Footage(previous_img_fn);
Footage* next_file = new Footage(next_img_fn);
Footage *previous_file = new Footage(previous_img_fn);
Footage *next_file = new Footage(next_img_fn);
// Finally see if these files have the same dimensions
if ((previous_file->IsValid() && CompareStillImageSize(previous_file, dim))
|| (next_file->IsValid() && CompareStillImageSize(next_file, dim))) {
// By this point, we've established this file is a still image with a number at the end of
// the filename surrounded by adjacent numbers. It could be a still image! But let's ask the
// user just in case...
bool is_sequence;
// Finally see if these files have the same dimensions
if ((previous_file->IsValid() &&
CompareStillImageSize(previous_file, dim)) ||
(next_file->IsValid() && CompareStillImageSize(next_file, dim))) {
// By this point, we've established this file is a still image with a number at the end of
// the filename surrounded by adjacent numbers. It could be a still image! But let's ask the
// user just in case...
bool is_sequence;
QMetaObject::invokeMethod(Core::instance(),
"ConfirmImageSequence",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, is_sequence),
Q_ARG(QString, footage->filename()));
QMetaObject::invokeMethod(Core::instance(), "ConfirmImageSequence",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, is_sequence),
Q_ARG(QString, footage->filename()));
int64_t seq_index = Decoder::GetImageSequenceIndex(footage->filename());
int64_t seq_index =
Decoder::GetImageSequenceIndex(footage->filename());
// Heuristic to find the first and last images (users can always override this later in
// FootagePropertiesDialog)
int64_t start_index = GetImageSequenceLimit(footage->filename(), seq_index, false);
int64_t end_index = GetImageSequenceLimit(footage->filename(), seq_index, true);
// Heuristic to find the first and last images (users can always override this later in
// FootagePropertiesDialog)
int64_t start_index =
GetImageSequenceLimit(footage->filename(), seq_index, false);
int64_t end_index =
GetImageSequenceLimit(footage->filename(), seq_index, true);
// Depending on the user's choice, either remove them from the list or don't ask for the
// remainders
for (int64_t j=start_index; j<=end_index; j++) {
QString entry_fn = Decoder::TransformImageSequenceFileName(footage->filename(), j);
// Depending on the user's choice, either remove them from the list or don't ask for the
// remainders
for (int64_t j = start_index; j <= end_index; j++) {
QString entry_fn = Decoder::TransformImageSequenceFileName(
footage->filename(), j);
if (is_sequence) {
// If this is part of the sequence we're importing here, remove it
for (int i=index+1; i<info_list.size(); i++) {
if (info_list.at(i).absoluteFilePath() == entry_fn) {
if (is_sequence) {
info_list.removeAt(i);
}
break;
}
}
} else {
image_sequence_ignore_files_.append(entry_fn);
}
}
if (is_sequence) {
// If this is part of the sequence we're importing here, remove it
for (int i = index + 1; i < info_list.size(); i++) {
if (info_list.at(i).absoluteFilePath() == entry_fn) {
if (is_sequence) {
info_list.removeAt(i);
}
break;
}
}
} else {
image_sequence_ignore_files_.append(entry_fn);
}
}
if (is_sequence) {
// User has confirmed it is a still image, let's set it accordingly.
video_stream.set_video_type(VideoParams::kVideoTypeImageSequence);
if (is_sequence) {
// User has confirmed it is a still image, let's set it accordingly.
video_stream.set_video_type(
VideoParams::kVideoTypeImageSequence);
rational default_timebase = OLIVE_CONFIG("DefaultSequenceFrameRate").value<rational>();
video_stream.set_time_base(default_timebase);
video_stream.set_frame_rate(default_timebase.flipped());
rational default_timebase =
OLIVE_CONFIG("DefaultSequenceFrameRate").value<rational>();
video_stream.set_time_base(default_timebase);
video_stream.set_frame_rate(default_timebase.flipped());
video_stream.set_start_time(start_index);
video_stream.set_duration(end_index - start_index + 1);
video_stream.set_start_time(start_index);
video_stream.set_duration(end_index - start_index + 1);
footage->SetVideoParams(video_stream, 0);
}
}
footage->SetVideoParams(video_stream, 0);
}
}
delete previous_file;
delete next_file;
}
delete previous_file;
delete next_file;
}
}
void ProjectImportTask::AddItemToFolder(Folder *folder, Node *item, MultiUndoCommand *command)
void ProjectImportTask::AddItemToFolder(Folder *folder, Node *item,
MultiUndoCommand *command)
{
// Create undoable command that adds the items to the model
Project* project = folder_->project();
// Create undoable command that adds the items to the model
Project *project = folder_->project();
NodeAddCommand* nac = new NodeAddCommand(project, item);
nac->PushToThread(project->thread());
command->add_child(nac);
NodeAddCommand *nac = new NodeAddCommand(project, item);
nac->PushToThread(project->thread());
command->add_child(nac);
command->add_child(new FolderAddChild(folder, item));
command->add_child(new FolderAddChild(folder, item));
}
bool ProjectImportTask::ItemIsStillImageFootageOnly(Footage* footage)
bool ProjectImportTask::ItemIsStillImageFootageOnly(Footage *footage)
{
if (footage->GetTotalStreamCount() != 1) {
// Footage with more than one stream (usually video+audio) most likely isn't an image sequence
return false;
}
if (footage->GetTotalStreamCount() != 1) {
// Footage with more than one stream (usually video+audio) most likely isn't an image sequence
return false;
}
VideoParams vp = footage->GetVideoParams(0);
VideoParams vp = footage->GetVideoParams(0);
// Footage must be valid and video stream must be a still image to be an image sequence
return vp.is_valid() && vp.video_type() == VideoParams::kVideoTypeStill;
// Footage must be valid and video stream must be a still image to be an image sequence
return vp.is_valid() && vp.video_type() == VideoParams::kVideoTypeStill;
}
bool ProjectImportTask::CompareStillImageSize(Footage* footage, const QSize &sz)
bool ProjectImportTask::CompareStillImageSize(Footage *footage, const QSize &sz)
{
if (!ItemIsStillImageFootageOnly(footage)) {
return false;
}
if (!ItemIsStillImageFootageOnly(footage)) {
return false;
}
VideoParams stream = footage->GetVideoParams(0);
VideoParams stream = footage->GetVideoParams(0);
return stream.width() == sz.width() && stream.height() == sz.height();
return stream.width() == sz.width() && stream.height() == sz.height();
}
int64_t ProjectImportTask::GetImageSequenceLimit(const QString& start_fn, int64_t start, bool up)
int64_t ProjectImportTask::GetImageSequenceLimit(const QString &start_fn,
int64_t start, bool up)
{
QString test_filename;
int test_index;
QString test_filename;
int test_index;
forever {
if (up) {
test_index = start + 1;
} else {
test_index = start - 1;
}
forever
{
if (up) {
test_index = start + 1;
} else {
test_index = start - 1;
}
test_filename = Decoder::TransformImageSequenceFileName(start_fn, test_index);
test_filename =
Decoder::TransformImageSequenceFileName(start_fn, test_index);
if (!QFileInfo::exists(test_filename)) {
// Reached end of index
break;
}
if (!QFileInfo::exists(test_filename)) {
// Reached end of index
break;
}
start = test_index;
}
start = test_index;
}
return start;
return start;
}
}
+39 -34
View File
@@ -28,63 +28,68 @@
#include "task/task.h"
#include "widget/projectexplorer/projectviewmodel.h"
namespace olive {
class ProjectImportTask : public Task
namespace olive
{
Q_OBJECT
class ProjectImportTask : public Task {
Q_OBJECT
public:
ProjectImportTask(Folder* folder, const QStringList& filenames);
ProjectImportTask(Folder *folder, const QStringList &filenames);
const int& GetFileCount() const;
const int &GetFileCount() const;
MultiUndoCommand* GetCommand() const
{
return command_;
}
MultiUndoCommand *GetCommand() const
{
return command_;
}
const QStringList& GetInvalidFiles() const
{
return invalid_files_;
}
const QStringList &GetInvalidFiles() const
{
return invalid_files_;
}
bool HasInvalidFiles() const
{
return !invalid_files_.isEmpty();
}
bool HasInvalidFiles() const
{
return !invalid_files_.isEmpty();
}
const QVector<Footage*> &GetImportedFootage() const { return imported_footage_; }
const QVector<Footage *> &GetImportedFootage() const
{
return imported_footage_;
}
protected:
virtual bool Run() override;
virtual bool Run() override;
private:
void Import(Folder* folder, QFileInfoList import, int& counter, MultiUndoCommand *parent_command);
void Import(Folder *folder, QFileInfoList import, int &counter,
MultiUndoCommand *parent_command);
void ValidateImageSequence(Footage *footage, QFileInfoList &info_list, int index);
void ValidateImageSequence(Footage *footage, QFileInfoList &info_list,
int index);
void AddItemToFolder(Folder* folder, Node* item, MultiUndoCommand* command);
void AddItemToFolder(Folder *folder, Node *item, MultiUndoCommand *command);
static bool ItemIsStillImageFootageOnly(Footage *footage);
static bool ItemIsStillImageFootageOnly(Footage *footage);
static bool CompareStillImageSize(Footage *footage, const QSize& sz);
static bool CompareStillImageSize(Footage *footage, const QSize &sz);
static int64_t GetImageSequenceLimit(const QString &start_fn, int64_t start, bool up);
static int64_t GetImageSequenceLimit(const QString &start_fn, int64_t start,
bool up);
MultiUndoCommand* command_;
MultiUndoCommand *command_;
Folder* folder_;
Folder *folder_;
QFileInfoList filenames_;
QFileInfoList filenames_;
int file_count_;
int file_count_;
QStringList invalid_files_;
QStringList invalid_files_;
QList<QString> image_sequence_ignore_files_;
QVector<Footage*> imported_footage_;
QList<QString> image_sequence_ignore_files_;
QVector<Footage *> imported_footage_;
};
}
+22 -18
View File
@@ -25,29 +25,33 @@
#include <QListWidget>
#include <QVBoxLayout>
namespace olive {
ProjectImportErrorDialog::ProjectImportErrorDialog(const QStringList& filenames, QWidget* parent) :
QDialog(parent)
namespace olive
{
QVBoxLayout* layout = new QVBoxLayout(this);
setWindowTitle(tr("Import Error"));
ProjectImportErrorDialog::ProjectImportErrorDialog(const QStringList &filenames,
QWidget *parent)
: QDialog(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(new QLabel(tr("The following files failed to import. Olive likely does not "
"support their formats.")));
setWindowTitle(tr("Import Error"));
QListWidget* list_widget = new QListWidget();
foreach (const QString& s, filenames) {
list_widget->addItem(s);
}
layout->addWidget(list_widget);
layout->addWidget(new QLabel(
tr("The following files failed to import. Olive likely does not "
"support their formats.")));
QDialogButtonBox* buttons = new QDialogButtonBox();
buttons->setStandardButtons(QDialogButtonBox::Ok);
buttons->setCenterButtons(true);
connect(buttons, &QDialogButtonBox::accepted, this, &ProjectImportErrorDialog::accept);
layout->addWidget(buttons);
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);
}
}
+6 -6
View File
@@ -25,14 +25,14 @@
#include "common/define.h"
namespace olive {
class ProjectImportErrorDialog : public QDialog
namespace olive
{
Q_OBJECT
public:
ProjectImportErrorDialog(const QStringList& filenames, QWidget* parent = nullptr);
class ProjectImportErrorDialog : public QDialog {
Q_OBJECT
public:
ProjectImportErrorDialog(const QStringList &filenames,
QWidget *parent = nullptr);
};
}