reimplemented importing folders
This commit is contained in:
+10
-6
@@ -39,7 +39,8 @@
|
|||||||
Core olive::core;
|
Core olive::core;
|
||||||
|
|
||||||
Core::Core() :
|
Core::Core() :
|
||||||
main_window_(nullptr)
|
main_window_(nullptr),
|
||||||
|
tool_(olive::tool::kPointer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,16 +102,19 @@ olive::MainWindow *Core::main_window()
|
|||||||
|
|
||||||
void Core::ImportFiles(const QStringList &urls, Folder* parent)
|
void Core::ImportFiles(const QStringList &urls, Folder* parent)
|
||||||
{
|
{
|
||||||
QString error_capt = tr("Import error");
|
|
||||||
|
|
||||||
if (urls.isEmpty()) {
|
if (urls.isEmpty()) {
|
||||||
QMessageBox::critical(main_window_, error_capt, tr("Nothing to import"));
|
QMessageBox::critical(main_window_, tr("Import error"), tr("Nothing to import"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
olive::task_manager.AddTask(new ImportTask(parent, urls));
|
olive::task_manager.AddTask(new ImportTask(parent, urls));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const olive::tool::Tool &Core::tool()
|
||||||
|
{
|
||||||
|
return tool_;
|
||||||
|
}
|
||||||
|
|
||||||
void Core::SetTool(const olive::tool::Tool &tool)
|
void Core::SetTool(const olive::tool::Tool &tool)
|
||||||
{
|
{
|
||||||
tool_ = tool;
|
tool_ = tool;
|
||||||
@@ -142,7 +146,7 @@ void Core::StartImportFootage()
|
|||||||
// Get the selected items from the panel
|
// Get the selected items from the panel
|
||||||
QList<Item*> selected_items = active_project_panel->SelectedItems();
|
QList<Item*> selected_items = active_project_panel->SelectedItems();
|
||||||
|
|
||||||
// Heuristic for finding the selected folder
|
// Heuristic for finding the selected folder:
|
||||||
//
|
//
|
||||||
// - If `folder` is nullptr, we set the first folder we find. Either the item itself if it's a folder, or the
|
// - If `folder` is nullptr, we set the first folder we find. Either the item itself if it's a folder, or the
|
||||||
// item's parent.
|
// item's parent.
|
||||||
@@ -152,7 +156,7 @@ void Core::StartImportFootage()
|
|||||||
for (int i=0;i<selected_items.size();i++) {
|
for (int i=0;i<selected_items.size();i++) {
|
||||||
Item* sel_item = selected_items.at(i);
|
Item* sel_item = selected_items.at(i);
|
||||||
|
|
||||||
// If this item is not a folder, presumably its parent is
|
// If this item is not a folder, presumably it's parent is
|
||||||
if (sel_item->type() != Item::kFolder) {
|
if (sel_item->type() != Item::kFolder) {
|
||||||
sel_item = sel_item->parent();
|
sel_item = sel_item->parent();
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void ImportFiles(const QStringList& urls, Folder *parent);
|
void ImportFiles(const QStringList& urls, Folder *parent);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the currently active tool
|
||||||
|
*/
|
||||||
|
const olive::tool::Tool& tool();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @brief Set the current application-wide tool
|
* @brief Set the current application-wide tool
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ ToolPanel::ToolPanel(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
Toolbar* t = new Toolbar(this);
|
Toolbar* t = new Toolbar(this);
|
||||||
|
|
||||||
|
t->SetTool(olive::core.tool());
|
||||||
|
|
||||||
setWidget(t);
|
setWidget(t);
|
||||||
|
|
||||||
connect(t, SIGNAL(ToolChanged(const olive::tool::Tool&)), &olive::core, SLOT(SetTool(const olive::tool::Tool&)));
|
connect(t, SIGNAL(ToolChanged(const olive::tool::Tool&)), &olive::core, SLOT(SetTool(const olive::tool::Tool&)));
|
||||||
|
|||||||
+55
-15
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
// FIXME: Only used for test code
|
// FIXME: Only used for test code
|
||||||
@@ -46,28 +47,67 @@ bool ImportTask::Action()
|
|||||||
|
|
||||||
const QString& url = urls_.at(i);
|
const QString& url = urls_.at(i);
|
||||||
|
|
||||||
Footage* f = new Footage();
|
|
||||||
|
|
||||||
QFileInfo file_info(url);
|
QFileInfo file_info(url);
|
||||||
|
|
||||||
// FIXME: Is it possible for a file to go missing between the Import dialog and here?
|
// Check if this file is a diretory
|
||||||
// And what is the behavior/result of that?
|
if (file_info.isDir()) {
|
||||||
|
|
||||||
f->set_filename(url);
|
// Use QDir to get a list of all the files in the directory
|
||||||
f->set_name(file_info.fileName());
|
QDir dir(url);
|
||||||
f->set_timestamp(file_info.lastModified());
|
|
||||||
|
|
||||||
parent_->add_child(f);
|
// QDir::entryList only returns filenames, we can use entryInfoList() to get full paths
|
||||||
|
QFileInfoList entry_list = dir.entryInfoList();
|
||||||
|
|
||||||
// Create ProbeTask to analyze this media
|
// Only proceed if the empty actually has files in it
|
||||||
ProbeTask* pt = new ProbeTask(f);
|
if (!entry_list.isEmpty()) {
|
||||||
|
// Create a folder corresponding to the directory
|
||||||
|
Folder* f = new Folder();
|
||||||
|
|
||||||
// The task won't work unless it's in the main thread and we're definitely not
|
f->set_name(file_info.fileName());
|
||||||
// FIXME: Should Tasks check what thread they're in and move themselves to the main thread?
|
|
||||||
pt->moveToThread(qApp->thread());
|
|
||||||
|
|
||||||
// Queue task in task manager
|
parent_->add_child(f);
|
||||||
olive::task_manager.AddTask(pt);
|
|
||||||
|
// Convert QFileInfoList into QStringList
|
||||||
|
QStringList full_urls;
|
||||||
|
|
||||||
|
foreach (QFileInfo info, entry_list) {
|
||||||
|
if (info.fileName() != ".." && info.fileName() != ".") {
|
||||||
|
full_urls.append(info.absoluteFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start a new import task for this folder too
|
||||||
|
ImportTask* it = new ImportTask(f, full_urls);
|
||||||
|
|
||||||
|
it->moveToThread(qApp->thread());
|
||||||
|
|
||||||
|
olive::task_manager.AddTask(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Footage* f = new Footage();
|
||||||
|
|
||||||
|
// FIXME: Is it possible for a file to go missing between the Import dialog and here?
|
||||||
|
// And what is the behavior/result of that?
|
||||||
|
|
||||||
|
f->set_filename(url);
|
||||||
|
f->set_name(file_info.fileName());
|
||||||
|
f->set_timestamp(file_info.lastModified());
|
||||||
|
|
||||||
|
parent_->add_child(f);
|
||||||
|
|
||||||
|
// Create ProbeTask to analyze this media
|
||||||
|
ProbeTask* pt = new ProbeTask(f);
|
||||||
|
|
||||||
|
// The task won't work unless it's in the main thread and we're definitely not
|
||||||
|
// FIXME: Should Tasks check what thread they're in and move themselves to the main thread?
|
||||||
|
pt->moveToThread(qApp->thread());
|
||||||
|
|
||||||
|
// Queue task in task manager
|
||||||
|
olive::task_manager.AddTask(pt);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
emit ProgressChanged(i * 100 / urls_.size());
|
emit ProgressChanged(i * 100 / urls_.size());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user