importing projects into other projects implemented
This commit is contained in:
+29
-27
@@ -31,48 +31,50 @@
|
|||||||
#include "ui/sourcetable.h"
|
#include "ui/sourcetable.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
LoadDialog::LoadDialog(QWidget *parent, bool autorecovery) : QDialog(parent) {
|
LoadDialog::LoadDialog(QWidget *parent, const QString& fn, bool autorecovery, bool clear) :
|
||||||
setWindowTitle(tr("Loading..."));
|
QDialog(parent)
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
{
|
||||||
|
setWindowTitle(tr("Loading..."));
|
||||||
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
|
||||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||||
|
|
||||||
layout->addWidget(new QLabel(tr("Loading '%1'...").arg(olive::ActiveProjectFilename.mid(olive::ActiveProjectFilename.lastIndexOf('/')+1)), this));
|
layout->addWidget(new QLabel(tr("Loading '%1'...").arg(olive::ActiveProjectFilename.mid(olive::ActiveProjectFilename.lastIndexOf('/')+1)), this));
|
||||||
|
|
||||||
bar = new QProgressBar(this);
|
bar = new QProgressBar(this);
|
||||||
bar->setValue(0);
|
bar->setValue(0);
|
||||||
layout->addWidget(bar);
|
layout->addWidget(bar);
|
||||||
|
|
||||||
cancel_button = new QPushButton(tr("Cancel"), this);
|
cancel_button = new QPushButton(tr("Cancel"), this);
|
||||||
connect(cancel_button, SIGNAL(clicked(bool)), this, SLOT(cancel()));
|
connect(cancel_button, SIGNAL(clicked(bool)), this, SLOT(cancel()));
|
||||||
|
|
||||||
hboxLayout = new QHBoxLayout();
|
hboxLayout = new QHBoxLayout();
|
||||||
hboxLayout->addStretch();
|
hboxLayout->addStretch();
|
||||||
hboxLayout->addWidget(cancel_button);
|
hboxLayout->addWidget(cancel_button);
|
||||||
hboxLayout->addStretch();
|
hboxLayout->addStretch();
|
||||||
|
|
||||||
layout->addLayout(hboxLayout);
|
layout->addLayout(hboxLayout);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
lt = new LoadThread(autorecovery);
|
lt = new LoadThread(fn, autorecovery, clear);
|
||||||
QObject::connect(lt, SIGNAL(success()), this, SLOT(thread_done()));
|
QObject::connect(lt, SIGNAL(success()), this, SLOT(thread_done()));
|
||||||
QObject::connect(lt, SIGNAL(error()), this, SLOT(die()));
|
QObject::connect(lt, SIGNAL(error()), this, SLOT(die()));
|
||||||
QObject::connect(lt, SIGNAL(report_progress(int)), bar, SLOT(setValue(int)));
|
QObject::connect(lt, SIGNAL(report_progress(int)), bar, SLOT(setValue(int)));
|
||||||
lt->start();
|
lt->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadDialog::cancel() {
|
void LoadDialog::cancel() {
|
||||||
lt->cancel();
|
lt->cancel();
|
||||||
lt->wait();
|
lt->wait();
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadDialog::die() {
|
void LoadDialog::die() {
|
||||||
olive::Global->new_project();
|
olive::Global->new_project();
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadDialog::thread_done() {
|
void LoadDialog::thread_done() {
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,18 +30,18 @@
|
|||||||
|
|
||||||
class LoadDialog : public QDialog
|
class LoadDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LoadDialog(QWidget* parent, bool autorecovery);
|
LoadDialog(QWidget* parent, const QString& filename, bool autorecovery, bool clear);
|
||||||
private slots:
|
private slots:
|
||||||
void cancel();
|
void cancel();
|
||||||
void die();
|
void die();
|
||||||
void thread_done();
|
void thread_done();
|
||||||
private:
|
private:
|
||||||
QProgressBar* bar;
|
QProgressBar* bar;
|
||||||
QPushButton* cancel_button;
|
QPushButton* cancel_button;
|
||||||
QHBoxLayout* hboxLayout;
|
QHBoxLayout* hboxLayout;
|
||||||
LoadThread* lt;
|
LoadThread* lt;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOADDIALOG_H
|
#endif // LOADDIALOG_H
|
||||||
|
|||||||
+37
-27
@@ -37,7 +37,12 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTreeWidgetItem>
|
#include <QTreeWidgetItem>
|
||||||
|
|
||||||
LoadThread::LoadThread(bool a) : autorecovery(a), cancelled(false) {
|
LoadThread::LoadThread(const QString& filename, bool autorecovery, bool clear) :
|
||||||
|
filename_(filename),
|
||||||
|
autorecovery_(autorecovery),
|
||||||
|
clear_(clear),
|
||||||
|
cancelled_(false)
|
||||||
|
{
|
||||||
connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
|
connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
|
||||||
connect(this, SIGNAL(success()), this, SLOT(success_func()));
|
connect(this, SIGNAL(success()), this, SLOT(success_func()));
|
||||||
connect(this, SIGNAL(error()), this, SLOT(error_func()));
|
connect(this, SIGNAL(error()), this, SLOT(error_func()));
|
||||||
@@ -45,7 +50,10 @@ LoadThread::LoadThread(bool a) : autorecovery(a), cancelled(false) {
|
|||||||
SIGNAL(start_create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool)),
|
SIGNAL(start_create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool)),
|
||||||
this,
|
this,
|
||||||
SLOT(create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool)));
|
SLOT(create_effect_ui(QXmlStreamReader*, Clip*, int, const QString*, const EffectMeta*, long, bool)));
|
||||||
connect(this, SIGNAL(start_question(const QString&, const QString &, int)), this, SLOT(question_func(const QString &, const QString &, int)));
|
connect(this,
|
||||||
|
SIGNAL(start_question(const QString&, const QString &, int)),
|
||||||
|
this,
|
||||||
|
SLOT(question_func(const QString &, const QString &, int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadThread::load_effect(QXmlStreamReader& stream, Clip* c) {
|
void LoadThread::load_effect(QXmlStreamReader& stream, Clip* c) {
|
||||||
@@ -174,7 +182,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
|||||||
|
|
||||||
int proj_version = olive::kSaveVersion;
|
int proj_version = olive::kSaveVersion;
|
||||||
|
|
||||||
while (!stream.atEnd() && !cancelled) {
|
while (!stream.atEnd() && !cancelled_) {
|
||||||
read_next_start_element(stream);
|
read_next_start_element(stream);
|
||||||
if (stream.name() == root_search) {
|
if (stream.name() == root_search) {
|
||||||
if (type == LOAD_TYPE_VERSION) {
|
if (type == LOAD_TYPE_VERSION) {
|
||||||
@@ -195,7 +203,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
|||||||
internal_proj_url = stream.readElementText();
|
internal_proj_url = stream.readElementText();
|
||||||
internal_proj_dir = QFileInfo(internal_proj_url).absoluteDir();
|
internal_proj_dir = QFileInfo(internal_proj_url).absoluteDir();
|
||||||
} else {
|
} else {
|
||||||
while (!cancelled && !stream.atEnd() && !(stream.name() == root_search && stream.isEndElement())) {
|
while (!cancelled_ && !stream.atEnd() && !(stream.name() == root_search && stream.isEndElement())) {
|
||||||
read_next(stream);
|
read_next(stream);
|
||||||
if (stream.name() == child_search && stream.isStartElement()) {
|
if (stream.name() == child_search && stream.isStartElement()) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -298,7 +306,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!cancelled && !(stream.name() == child_search && stream.isEndElement()) && !stream.atEnd()) {
|
while (!cancelled_ && !(stream.name() == child_search && stream.isEndElement()) && !stream.atEnd()) {
|
||||||
read_next_start_element(stream);
|
read_next_start_element(stream);
|
||||||
if (stream.name() == "marker" && stream.isStartElement()) {
|
if (stream.name() == "marker" && stream.isStartElement()) {
|
||||||
Marker m;
|
Marker m;
|
||||||
@@ -363,7 +371,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load all clips and clip information
|
// load all clips and clip information
|
||||||
while (!cancelled && !(stream.name() == child_search && stream.isEndElement()) && !stream.atEnd()) {
|
while (!cancelled_ && !(stream.name() == child_search && stream.isEndElement()) && !stream.atEnd()) {
|
||||||
read_next_start_element(stream);
|
read_next_start_element(stream);
|
||||||
if (stream.name() == "marker" && stream.isStartElement()) {
|
if (stream.name() == "marker" && stream.isStartElement()) {
|
||||||
Marker m;
|
Marker m;
|
||||||
@@ -448,11 +456,11 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load links and effects
|
// load links and effects
|
||||||
while (!cancelled && !(stream.name() == "clip" && stream.isEndElement()) && !stream.atEnd()) {
|
while (!cancelled_ && !(stream.name() == "clip" && stream.isEndElement()) && !stream.atEnd()) {
|
||||||
read_next(stream);
|
read_next(stream);
|
||||||
if (stream.isStartElement()) {
|
if (stream.isStartElement()) {
|
||||||
if (stream.name() == "linked") {
|
if (stream.name() == "linked") {
|
||||||
while (!cancelled && !(stream.name() == "linked" && stream.isEndElement()) && !stream.atEnd()) {
|
while (!cancelled_ && !(stream.name() == "linked" && stream.isEndElement()) && !stream.atEnd()) {
|
||||||
read_next(stream);
|
read_next(stream);
|
||||||
if (stream.name() == "link" && stream.isStartElement()) {
|
if (stream.name() == "link" && stream.isStartElement()) {
|
||||||
for (int k=0;k<stream.attributes().size();k++) {
|
for (int k=0;k<stream.attributes().size();k++) {
|
||||||
@@ -464,7 +472,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cancelled) return false;
|
if (cancelled_) return false;
|
||||||
} else if (stream.isStartElement()
|
} else if (stream.isStartElement()
|
||||||
&& (stream.name() == "effect"
|
&& (stream.name() == "effect"
|
||||||
|| stream.name() == "opening"
|
|| stream.name() == "opening"
|
||||||
@@ -484,12 +492,12 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cancelled) return false;
|
if (cancelled_) return false;
|
||||||
|
|
||||||
s->clips.append(c);
|
s->clips.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cancelled) return false;
|
if (cancelled_) return false;
|
||||||
|
|
||||||
// correct links, clip IDs, transitions
|
// correct links, clip IDs, transitions
|
||||||
for (int i=0;i<s->clips.size();i++) {
|
for (int i=0;i<s->clips.size();i++) {
|
||||||
@@ -530,12 +538,12 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cancelled) return false;
|
if (cancelled_) return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !cancelled;
|
return !cancelled_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Media* LoadThread::find_loaded_folder_by_id(int id) {
|
Media* LoadThread::find_loaded_folder_by_id(int id) {
|
||||||
@@ -552,7 +560,7 @@ Media* LoadThread::find_loaded_folder_by_id(int id) {
|
|||||||
void LoadThread::run() {
|
void LoadThread::run() {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
|
||||||
QFile file(olive::ActiveProjectFilename);
|
QFile file(filename_);
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
qCritical() << "Could not open file";
|
qCritical() << "Could not open file";
|
||||||
return;
|
return;
|
||||||
@@ -563,9 +571,9 @@ void LoadThread::run() {
|
|||||||
* case the project file has moved without the footage,
|
* case the project file has moved without the footage,
|
||||||
* we check both
|
* we check both
|
||||||
*/
|
*/
|
||||||
proj_dir = QFileInfo(olive::ActiveProjectFilename).absoluteDir();
|
proj_dir = QFileInfo(filename_).absoluteDir();
|
||||||
internal_proj_dir = QFileInfo(olive::ActiveProjectFilename).absoluteDir();
|
internal_proj_dir = QFileInfo(filename_).absoluteDir();
|
||||||
internal_proj_url = olive::ActiveProjectFilename;
|
internal_proj_url = filename_;
|
||||||
|
|
||||||
QXmlStreamReader stream(&file);
|
QXmlStreamReader stream(&file);
|
||||||
|
|
||||||
@@ -583,13 +591,13 @@ void LoadThread::run() {
|
|||||||
// get "element" count
|
// get "element" count
|
||||||
current_element_count = 0;
|
current_element_count = 0;
|
||||||
total_element_count = 0;
|
total_element_count = 0;
|
||||||
while (!cancelled && !stream.atEnd()) {
|
while (!cancelled_ && !stream.atEnd()) {
|
||||||
stream.readNextStartElement();
|
stream.readNextStartElement();
|
||||||
if (is_element(stream)) {
|
if (is_element(stream)) {
|
||||||
total_element_count++;
|
total_element_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cont = !cancelled;
|
cont = !cancelled_;
|
||||||
|
|
||||||
// find project file version
|
// find project file version
|
||||||
if (cont) {
|
if (cont) {
|
||||||
@@ -627,7 +635,7 @@ void LoadThread::run() {
|
|||||||
cont = load_worker(file, stream, MEDIA_TYPE_SEQUENCE);
|
cont = load_worker(file, stream, MEDIA_TYPE_SEQUENCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cancelled) {
|
if (!cancelled_) {
|
||||||
if (!cont) {
|
if (!cont) {
|
||||||
xml_error = false;
|
xml_error = false;
|
||||||
if (show_err) emit error();
|
if (show_err) emit error();
|
||||||
@@ -672,7 +680,7 @@ void LoadThread::run() {
|
|||||||
|
|
||||||
void LoadThread::cancel() {
|
void LoadThread::cancel() {
|
||||||
waitCond.wakeAll();
|
waitCond.wakeAll();
|
||||||
cancelled = true;
|
cancelled_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadThread::question_func(const QString &title, const QString &text, int buttons) {
|
void LoadThread::question_func(const QString &title, const QString &text, int buttons) {
|
||||||
@@ -691,7 +699,7 @@ void LoadThread::error_func() {
|
|||||||
qCritical() << "Error parsing XML." << error_str;
|
qCritical() << "Error parsing XML." << error_str;
|
||||||
QMessageBox::critical(olive::MainWindow,
|
QMessageBox::critical(olive::MainWindow,
|
||||||
tr("XML Parsing Error"),
|
tr("XML Parsing Error"),
|
||||||
tr("Couldn't load '%1'. %2").arg(olive::ActiveProjectFilename, error_str),
|
tr("Couldn't load '%1'. %2").arg(filename_, error_str),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::critical(olive::MainWindow,
|
QMessageBox::critical(olive::MainWindow,
|
||||||
@@ -702,7 +710,7 @@ void LoadThread::error_func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LoadThread::success_func() {
|
void LoadThread::success_func() {
|
||||||
if (autorecovery) {
|
if (autorecovery_) {
|
||||||
QString orig_filename = internal_proj_url;
|
QString orig_filename = internal_proj_url;
|
||||||
int insert_index = internal_proj_url.lastIndexOf(".ove", -1, Qt::CaseInsensitive);
|
int insert_index = internal_proj_url.lastIndexOf(".ove", -1, Qt::CaseInsensitive);
|
||||||
if (insert_index == -1) insert_index = internal_proj_url.length();
|
if (insert_index == -1) insert_index = internal_proj_url.length();
|
||||||
@@ -717,12 +725,14 @@ void LoadThread::success_func() {
|
|||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
olive::Global->update_project_filename(orig_filename);
|
if (clear_) {
|
||||||
|
olive::Global->update_project_filename(orig_filename);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
panel_project->add_recent_project(olive::ActiveProjectFilename);
|
panel_project->add_recent_project(filename_);
|
||||||
}
|
}
|
||||||
|
|
||||||
olive::MainWindow->setWindowModified(autorecovery);
|
olive::MainWindow->setWindowModified(autorecovery_ || !clear_);
|
||||||
if (open_seq != nullptr) {
|
if (open_seq != nullptr) {
|
||||||
olive::Global->set_sequence(open_seq);
|
olive::Global->set_sequence(open_seq);
|
||||||
}
|
}
|
||||||
@@ -762,7 +772,7 @@ void LoadThread::create_effect_ui(
|
|||||||
// lock mutex - ensures the load thread is suspended while this happens
|
// lock mutex - ensures the load thread is suspended while this happens
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
|
||||||
if (cancelled) return;
|
if (cancelled_) return;
|
||||||
if (type == kTransitionNone) {
|
if (type == kTransitionNone) {
|
||||||
if (meta == nullptr) {
|
if (meta == nullptr) {
|
||||||
// create void effect
|
// create void effect
|
||||||
|
|||||||
+5
-3
@@ -34,7 +34,7 @@ class LoadThread : public QThread
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LoadThread(bool a);
|
LoadThread(const QString& filename, bool autorecovery, bool clear);
|
||||||
void run();
|
void run();
|
||||||
void cancel();
|
void cancel();
|
||||||
signals:
|
signals:
|
||||||
@@ -61,7 +61,9 @@ private slots:
|
|||||||
long effect_length,
|
long effect_length,
|
||||||
bool effect_enabled);
|
bool effect_enabled);
|
||||||
private:
|
private:
|
||||||
bool autorecovery;
|
bool autorecovery_;
|
||||||
|
bool clear_;
|
||||||
|
QString filename_;
|
||||||
|
|
||||||
bool load_worker(QFile& f, QXmlStreamReader& stream, int type);
|
bool load_worker(QFile& f, QXmlStreamReader& stream, int type);
|
||||||
void load_effect(QXmlStreamReader& stream, Clip* c);
|
void load_effect(QXmlStreamReader& stream, Clip* c);
|
||||||
@@ -91,7 +93,7 @@ private:
|
|||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
QWaitCondition waitCond;
|
QWaitCondition waitCond;
|
||||||
|
|
||||||
bool cancelled;
|
bool cancelled_;
|
||||||
bool xml_error;
|
bool xml_error;
|
||||||
|
|
||||||
QMessageBox::StandardButton question_btn;
|
QMessageBox::StandardButton question_btn;
|
||||||
|
|||||||
+1
-1
@@ -293,7 +293,7 @@ void OliveGlobal::set_sequence(SequencePtr s)
|
|||||||
|
|
||||||
void OliveGlobal::open_project_worker(const QString& fn, bool autorecovery) {
|
void OliveGlobal::open_project_worker(const QString& fn, bool autorecovery) {
|
||||||
update_project_filename(fn);
|
update_project_filename(fn);
|
||||||
panel_project->load_project(autorecovery);
|
panel_project->load_project(fn, autorecovery, true);
|
||||||
olive::UndoStack.clear();
|
olive::UndoStack.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+178
-104
@@ -655,9 +655,12 @@ void Project::delete_selected_media() {
|
|||||||
void Project::process_file_list(QStringList& files, bool recursive, Media* replace, Media* parent) {
|
void Project::process_file_list(QStringList& files, bool recursive, Media* replace, Media* parent) {
|
||||||
bool imported = false;
|
bool imported = false;
|
||||||
|
|
||||||
|
// retrieve the array of image formats from the user's configuration
|
||||||
|
QStringList image_sequence_formats = olive::CurrentConfig.img_seq_formats.split("|");
|
||||||
|
|
||||||
|
// a cache of image sequence formatted URLS to assist the user in importing image sequences
|
||||||
QVector<QString> image_sequence_urls;
|
QVector<QString> image_sequence_urls;
|
||||||
QVector<bool> image_sequence_importassequence;
|
QVector<bool> image_sequence_importassequence;
|
||||||
QStringList image_sequence_formats = olive::CurrentConfig.img_seq_formats.split("|");
|
|
||||||
|
|
||||||
if (!recursive) last_imported_media.clear();
|
if (!recursive) last_imported_media.clear();
|
||||||
|
|
||||||
@@ -665,8 +668,12 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla
|
|||||||
ComboAction* ca = nullptr;
|
ComboAction* ca = nullptr;
|
||||||
if (create_undo_action) ca = new ComboAction();
|
if (create_undo_action) ca = new ComboAction();
|
||||||
|
|
||||||
|
// Loop through received files
|
||||||
for (int i=0;i<files.size();i++) {
|
for (int i=0;i<files.size();i++) {
|
||||||
|
|
||||||
|
// If this file is a directory, we'll recursively call this function again to process the directory's contents
|
||||||
if (QFileInfo(files.at(i)).isDir()) {
|
if (QFileInfo(files.at(i)).isDir()) {
|
||||||
|
|
||||||
QString folder_name = get_file_name_from_path(files.at(i));
|
QString folder_name = get_file_name_from_path(files.at(i));
|
||||||
Media* folder = create_folder_internal(folder_name);
|
Media* folder = create_folder_internal(folder_name);
|
||||||
|
|
||||||
@@ -689,132 +696,193 @@ void Project::process_file_list(QStringList& files, bool recursive, Media* repla
|
|||||||
}
|
}
|
||||||
|
|
||||||
imported = true;
|
imported = true;
|
||||||
|
|
||||||
} else if (!files.at(i).isEmpty()) {
|
} else if (!files.at(i).isEmpty()) {
|
||||||
QString file(files.at(i));
|
QString file = files.at(i);
|
||||||
bool skip = false;
|
|
||||||
|
|
||||||
/* Heuristic to determine whether file is part of an image sequence */
|
// Check if the user is importing an Olive project file
|
||||||
|
if (file.endsWith(".ove", Qt::CaseInsensitive)) {
|
||||||
|
|
||||||
// check file extension (assume it's not a
|
// This file is an Olive project file. Ask the user if they really want to import it.
|
||||||
|
if (QMessageBox::question(this,
|
||||||
|
tr("Import a Project"),
|
||||||
|
tr("\"%1\" is an Olive project file. It will merge with this project. "
|
||||||
|
"Do you wish to continue?").arg(file),
|
||||||
|
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
||||||
|
|
||||||
|
// load the project without clearing the current one
|
||||||
|
load_project(file, false, false);
|
||||||
|
|
||||||
int lastcharindex = file.lastIndexOf(".");
|
|
||||||
bool found = true;
|
|
||||||
if (lastcharindex != -1 && lastcharindex > file.lastIndexOf('/')) {
|
|
||||||
// image_sequence_formats
|
|
||||||
found = false;
|
|
||||||
QString ext = file.mid(lastcharindex+1);
|
|
||||||
for (int j=0;j<image_sequence_formats.size();j++) {
|
|
||||||
if (ext == image_sequence_formats.at(j)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
lastcharindex = file.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastcharindex == 0) lastcharindex++;
|
// This file is NOT an Olive project file
|
||||||
|
|
||||||
// used for image sequences that don't start at "0"
|
// Used later if this file is part of an already processed image sequence
|
||||||
int start_number = 0;
|
bool skip = false;
|
||||||
|
|
||||||
if (found && file[lastcharindex-1].isDigit()) {
|
/* Heuristic to determine whether file is part of an image sequence */
|
||||||
|
|
||||||
bool is_img_sequence = false;
|
// Firstly, we run a heuristic on whether this file is an image by checking its file extension
|
||||||
|
|
||||||
// how many digits are in the filename?
|
bool file_is_an_image = false;
|
||||||
int digit_count = 0;
|
|
||||||
int digit_test = lastcharindex-1;
|
|
||||||
while (file[digit_test].isDigit()) {
|
|
||||||
digit_count++;
|
|
||||||
digit_test--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// retrieve number from filename
|
// Get the string position of the extension in the filename
|
||||||
digit_test++;
|
int lastcharindex = file.lastIndexOf(".");
|
||||||
int file_number = file.mid(digit_test, digit_count).toInt();
|
|
||||||
|
|
||||||
// Check if there are files with the same filename but just different numbers
|
if (lastcharindex != -1 && lastcharindex > file.lastIndexOf('/')) {
|
||||||
if (QFileInfo::exists(QString(file.left(digit_test) + QString("%1").arg(file_number-1, digit_count, 10, QChar('0')) + file.mid(lastcharindex)))
|
|
||||||
|| QFileInfo::exists(QString(file.left(digit_test) + QString("%1").arg(file_number+1, digit_count, 10, QChar('0')) + file.mid(lastcharindex)))) {
|
|
||||||
is_img_sequence = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_img_sequence) {
|
QString ext = file.mid(lastcharindex+1);
|
||||||
// get the URL that we would pass to FFmpeg to force it to read the image as a sequence
|
|
||||||
QString new_filename = file.left(digit_test) + "%" + QString::number(digit_count) + "d" + file.mid(lastcharindex);
|
|
||||||
|
|
||||||
// add image sequence url to a vector in case the user imported several files that
|
// If the file extension is part of a predetermined list (from Config::img_seq_formats), we'll treat it
|
||||||
// we're interpreting as a possible sequence
|
// as an image
|
||||||
found = false;
|
if (image_sequence_formats.contains(ext, Qt::CaseInsensitive)) {
|
||||||
for (int i=0;i<image_sequence_urls.size();i++) {
|
file_is_an_image = true;
|
||||||
if (image_sequence_urls.at(i) == new_filename) {
|
|
||||||
// either SKIP if we're importing as a sequence, or leave it if we aren't
|
|
||||||
if (image_sequence_importassequence.at(i)) {
|
|
||||||
skip = true;
|
|
||||||
}
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!found) {
|
|
||||||
image_sequence_urls.append(new_filename);
|
|
||||||
if (QMessageBox::question(this,
|
|
||||||
tr("Image sequence detected"),
|
|
||||||
tr("The file '%1' appears to be part of an image sequence. Would you like to import it as such?").arg(file),
|
|
||||||
QMessageBox::Yes | QMessageBox::No,
|
|
||||||
QMessageBox::Yes) == QMessageBox::Yes) {
|
|
||||||
file = new_filename;
|
|
||||||
image_sequence_importassequence.append(true);
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
// try to find the start number for this image sequence
|
// If we're here, the file has no extension, but we'll still check if its an image sequence just in case
|
||||||
int test_file_number = file_number;
|
lastcharindex = file.length();
|
||||||
do {
|
file_is_an_image = true;
|
||||||
test_file_number--;
|
|
||||||
} while (QFileInfo::exists(QString("%1%2%3").arg(file.left(digit_test),
|
}
|
||||||
QString("%1").arg(test_file_number, digit_count, 10, QChar('0')),
|
|
||||||
file.mid(lastcharindex))));
|
// Some image sequence's don't start at "0", if it is indeed an image sequence, we'll use this variable
|
||||||
start_number = test_file_number + 1;
|
// later to determine where it does start
|
||||||
|
int start_number = 0;
|
||||||
|
|
||||||
|
// Check if we passed the earlier heuristic to check whether this is a file, and whether the last number in
|
||||||
|
// the filename (before the extension) is a number
|
||||||
|
if (file_is_an_image && file[lastcharindex-1].isDigit()) {
|
||||||
|
|
||||||
|
// Check how many digits are at the end of this filename
|
||||||
|
int digit_count = 0;
|
||||||
|
int digit_test = lastcharindex-1;
|
||||||
|
while (file[digit_test].isDigit()) {
|
||||||
|
digit_count++;
|
||||||
|
digit_test--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the integer represented at the end of this filename
|
||||||
|
digit_test++;
|
||||||
|
int file_number = file.mid(digit_test, digit_count).toInt();
|
||||||
|
|
||||||
|
// Check whether a file exists with the same format but one number higher or one number lower
|
||||||
|
if (QFileInfo::exists(QString(file.left(digit_test) + QString("%1").arg(file_number-1, digit_count, 10, QChar('0')) + file.mid(lastcharindex)))
|
||||||
|
|| QFileInfo::exists(QString(file.left(digit_test) + QString("%1").arg(file_number+1, digit_count, 10, QChar('0')) + file.mid(lastcharindex)))) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// If so, it certainly looks like it *could* be an image sequence, but we'll ask the user just in case
|
||||||
|
//
|
||||||
|
|
||||||
|
// Firstly we should check if this file is part of a sequence the user has already confirmed as either a
|
||||||
|
// sequence or not a sequence (e.g. if the user happened to select a bunch of images that happen to increase
|
||||||
|
// consecutively). We format the filename with FFmpeg's '%Nd' (N = digits) formatting for reading image
|
||||||
|
// sequences
|
||||||
|
QString new_filename = file.left(digit_test) + "%" + QString::number(digit_count) + "d" + file.mid(lastcharindex);
|
||||||
|
|
||||||
|
int does_url_cache_already_contain_this = image_sequence_urls.indexOf(new_filename);
|
||||||
|
|
||||||
|
if (does_url_cache_already_contain_this > -1) {
|
||||||
|
|
||||||
|
// We've already processed an image with the same formatting
|
||||||
|
|
||||||
|
// Check if the last time we saw this formatting, the user chose to import as a sequence
|
||||||
|
if (image_sequence_importassequence.at(does_url_cache_already_contain_this)) {
|
||||||
|
|
||||||
|
// If so, no need to import this file too, so we signal to the rest of the function to skip this file
|
||||||
|
skip = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not, we can fall-through to the next step which is importing normally
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
image_sequence_importassequence.append(false);
|
|
||||||
|
// If we're here, we've never seen a file with this formatting before, so we'll ask whether to import
|
||||||
|
// as a sequence or not
|
||||||
|
|
||||||
|
// Add this file formatting file to the URL cache
|
||||||
|
image_sequence_urls.append(new_filename);
|
||||||
|
|
||||||
|
// This does look like an image sequence, let's ask the user if it'll indeed be an image sequence
|
||||||
|
if (QMessageBox::question(this,
|
||||||
|
tr("Image sequence detected"),
|
||||||
|
tr("The file '%1' appears to be part of an image sequence. "
|
||||||
|
"Would you like to import it as such?").arg(file),
|
||||||
|
QMessageBox::Yes | QMessageBox::No,
|
||||||
|
QMessageBox::Yes) == QMessageBox::Yes) {
|
||||||
|
|
||||||
|
// Proceed to the next step of this with the formatted filename
|
||||||
|
file = new_filename;
|
||||||
|
|
||||||
|
// Cache the user's answer alongside the image_sequence_urls value - in this case, YES, this will be an
|
||||||
|
// image sequence
|
||||||
|
image_sequence_importassequence.append(true);
|
||||||
|
|
||||||
|
|
||||||
|
// FFmpeg needs to know what file number to start at in the sequence. In case the image sequence doesn't
|
||||||
|
// start at a zero, we'll loop decreasing the number until it doesn't exist anymore
|
||||||
|
QString test_filename_format = QString("%1%2%3").arg(file.left(digit_test), "%1", file.mid(lastcharindex));
|
||||||
|
int test_file_number = file_number;
|
||||||
|
do {
|
||||||
|
test_file_number--;
|
||||||
|
} while (QFileInfo::exists(test_filename_format.arg(QString("%1").arg(test_file_number, digit_count, 10, QChar('0')))));
|
||||||
|
|
||||||
|
// set the image sequence's start number to the last that existed
|
||||||
|
start_number = test_file_number + 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Cache the user's response to the image sequence question - i.e. none of the files imported with this
|
||||||
|
// formatting should be imported as an image sequence
|
||||||
|
image_sequence_importassequence.append(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're not skipping this file, let's import it
|
||||||
|
if (!skip) {
|
||||||
|
Media* item;
|
||||||
|
FootagePtr m;
|
||||||
|
|
||||||
|
if (replace != nullptr) {
|
||||||
|
item = replace;
|
||||||
|
} else {
|
||||||
|
item = new Media(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
m = FootagePtr(new Footage());
|
||||||
|
|
||||||
|
m->using_inout = false;
|
||||||
|
m->url = file;
|
||||||
|
m->name = get_file_name_from_path(files.at(i));
|
||||||
|
m->start_number = start_number;
|
||||||
|
|
||||||
|
item->set_footage(m);
|
||||||
|
|
||||||
|
last_imported_media.append(item);
|
||||||
|
|
||||||
|
if (replace == nullptr) {
|
||||||
|
if (create_undo_action) {
|
||||||
|
ca->append(new AddMediaCommand(item, parent));
|
||||||
|
} else {
|
||||||
|
parent->appendChild(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip) {
|
|
||||||
Media* item;
|
|
||||||
FootagePtr m;
|
|
||||||
|
|
||||||
if (replace != nullptr) {
|
|
||||||
item = replace;
|
|
||||||
} else {
|
|
||||||
item = new Media(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
m = FootagePtr(new Footage());
|
|
||||||
|
|
||||||
m->using_inout = false;
|
|
||||||
m->url = file;
|
|
||||||
m->name = get_file_name_from_path(files.at(i));
|
|
||||||
m->start_number = start_number;
|
|
||||||
|
|
||||||
item->set_footage(m);
|
|
||||||
|
|
||||||
last_imported_media.append(item);
|
|
||||||
|
|
||||||
if (replace == nullptr) {
|
|
||||||
if (create_undo_action) {
|
|
||||||
ca->append(new AddMediaCommand(item, parent));
|
|
||||||
} else {
|
|
||||||
parent->appendChild(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
imported = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (create_undo_action) {
|
if (create_undo_action) {
|
||||||
@@ -966,10 +1034,16 @@ void Project::new_project() {
|
|||||||
olive::MainWindow->setWindowModified(false);
|
olive::MainWindow->setWindowModified(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::load_project(bool autorecovery) {
|
void Project::load_project(const QString& filename, bool autorecovery, bool clear) {
|
||||||
new_project();
|
|
||||||
|
|
||||||
LoadDialog ld(this, autorecovery);
|
// Normally, the user will be closing the previous project to load a new one, but just in case the user
|
||||||
|
// is importing a new project
|
||||||
|
|
||||||
|
if (clear) {
|
||||||
|
new_project();
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadDialog ld(this, filename, autorecovery, clear);
|
||||||
ld.exec();
|
ld.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ public:
|
|||||||
void add_recent_project(QString url);
|
void add_recent_project(QString url);
|
||||||
|
|
||||||
void new_project();
|
void new_project();
|
||||||
void load_project(bool autorecovery);
|
void load_project(const QString &filename, bool autorecovery, bool clear);
|
||||||
void save_project(bool autorecovery);
|
void save_project(bool autorecovery);
|
||||||
|
|
||||||
Media* create_folder_internal(QString name);
|
Media* create_folder_internal(QString name);
|
||||||
|
|||||||
Reference in New Issue
Block a user