changed items to shared ptrs

This commit is contained in:
itsmattkc
2019-07-06 12:50:00 -05:00
parent a6971b3fde
commit b62ec30015
12 changed files with 98 additions and 42 deletions
+9 -3
View File
@@ -59,6 +59,11 @@ void ImportTask::Import(const QStringList &files, Folder *folder, QUndoCommand *
{
for (int i=0;i<files.size();i++) {
// Stop here if the Task has been cancelled
if (cancelled()) {
break;
}
const QString& url = files.at(i);
QFileInfo file_info(url);
@@ -75,7 +80,8 @@ void ImportTask::Import(const QStringList &files, Folder *folder, QUndoCommand *
// 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();
ItemPtr f = std::make_shared<Folder>();
f->set_name(file_info.fileName());
@@ -95,12 +101,12 @@ void ImportTask::Import(const QStringList &files, Folder *folder, QUndoCommand *
}
// Recursively follow this path
Import(full_urls, f, parent_command);
Import(full_urls, static_cast<Folder*>(f.get()), parent_command);
}
} else {
Footage* f = new Footage();
FootagePtr f = std::make_shared<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?
+2 -2
View File
@@ -24,7 +24,7 @@
#include "decoder/probeserver.h"
ProbeTask::ProbeTask(Footage *footage) :
ProbeTask::ProbeTask(FootagePtr footage) :
footage_(footage)
{
QString base_filename = QFileInfo(footage_->filename()).fileName();
@@ -34,7 +34,7 @@ ProbeTask::ProbeTask(Footage *footage) :
bool ProbeTask::Action()
{
olive::ProbeMedia(footage_);
olive::ProbeMedia(footage_.get());
return true;
}
+2 -2
View File
@@ -38,12 +38,12 @@ class ProbeTask : public Task
{
Q_OBJECT
public:
ProbeTask(Footage* footage);
ProbeTask(FootagePtr footage);
virtual bool Action() override;
private:
Footage* footage_;
FootagePtr footage_;
};
#endif // PROBE_H
+21 -1
View File
@@ -23,7 +23,8 @@
Task::Task() :
status_(kWaiting),
thread_(this),
text_(tr("Task"))
text_(tr("Task")),
cancelled_(false)
{
connect(&thread_, SIGNAL(finished()), this, SLOT(ThreadComplete()));
}
@@ -55,6 +56,8 @@ bool Task::Start()
}
}
cancelled_ = false;
set_status(kWorking);
thread_.start();
@@ -90,6 +93,18 @@ void Task::AddDependency(Task *dependency)
dependencies_.append(dependency);
}
void Task::Cancel()
{
if (status_ != kWorking) {
return;
}
cancelled_ = true;
// FIXME: Should we limit the wait time?
thread_.wait();
}
void Task::set_error(const QString &s)
{
error_ = s;
@@ -100,6 +115,11 @@ void Task::set_text(const QString &s)
text_ = s;
}
bool Task::cancelled()
{
return cancelled_;
}
void Task::set_status(const Task::Status &status)
{
status_ = status;
+19
View File
@@ -141,6 +141,18 @@ public:
*/
void AddDependency(Task* dependency);
public slots:
/**
* @brief Cancel the Task
*
* Sends a signal to the Task to stop and waits for the Task to finish before returning. Tasks must be responsive to
* cancelling so that the main thread doesn't halt for too long.
*
* Cancel()'s function is fairly simple, it sets cancelled_ to TRUE and waits for the thread to return. It's the
* responsibility of the code in Action() to be able to respond quickly to cancelled_ changing.
*/
void Cancel();
protected:
/**
* @brief Set the error message
@@ -159,6 +171,11 @@ protected:
*/
void set_text(const QString& s);
/**
* @brief Returns whether the thread has been explicitly cancelled or not
*/
bool cancelled();
signals:
/**
* @brief Signal emitted whenever the Task status changes
@@ -197,6 +214,8 @@ private:
QList<Task*> dependencies_;
bool cancelled_;
private slots:
/**
* @brief A slot when the inner thread completes either successfully or unsuccessfully