diff --git a/app/core.cpp b/app/core.cpp index 6408cd795..d568c2a13 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -39,7 +39,8 @@ Core olive::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) { - QString error_capt = tr("Import error"); - 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; } olive::task_manager.AddTask(new ImportTask(parent, urls)); } +const olive::tool::Tool &Core::tool() +{ + return tool_; +} + void Core::SetTool(const olive::tool::Tool &tool) { tool_ = tool; @@ -142,7 +146,7 @@ void Core::StartImportFootage() // Get the selected items from the panel QList 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 // item's parent. @@ -152,7 +156,7 @@ void Core::StartImportFootage() for (int i=0;itype() != Item::kFolder) { sel_item = sel_item->parent(); diff --git a/app/core.h b/app/core.h index e9f6a34dd..5a7905b56 100644 --- a/app/core.h +++ b/app/core.h @@ -74,6 +74,11 @@ public: */ void ImportFiles(const QStringList& urls, Folder *parent); + /** + * @brief Get the currently active tool + */ + const olive::tool::Tool& tool(); + public slots: /** * @brief Set the current application-wide tool diff --git a/app/panel/tool/tool.cpp b/app/panel/tool/tool.cpp index d93e98a1f..d47c80c1d 100644 --- a/app/panel/tool/tool.cpp +++ b/app/panel/tool/tool.cpp @@ -28,6 +28,8 @@ ToolPanel::ToolPanel(QWidget *parent) : { Toolbar* t = new Toolbar(this); + t->SetTool(olive::core.tool()); + setWidget(t); connect(t, SIGNAL(ToolChanged(const olive::tool::Tool&)), &olive::core, SLOT(SetTool(const olive::tool::Tool&))); diff --git a/app/task/import/import.cpp b/app/task/import/import.cpp index efb4b5cbc..332b893d6 100644 --- a/app/task/import/import.cpp +++ b/app/task/import/import.cpp @@ -22,6 +22,7 @@ #include #include +#include #include // FIXME: Only used for test code @@ -46,28 +47,67 @@ bool ImportTask::Action() const QString& url = urls_.at(i); - Footage* f = new Footage(); - QFileInfo file_info(url); - // FIXME: Is it possible for a file to go missing between the Import dialog and here? - // And what is the behavior/result of that? + // Check if this file is a diretory + if (file_info.isDir()) { - f->set_filename(url); - f->set_name(file_info.fileName()); - f->set_timestamp(file_info.lastModified()); + // Use QDir to get a list of all the files in the directory + QDir dir(url); - 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 - ProbeTask* pt = new ProbeTask(f); + // 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(); - // 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()); + f->set_name(file_info.fileName()); - // Queue task in task manager - olive::task_manager.AddTask(pt); + parent_->add_child(f); + + // 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());