try to index media immediately on import
Since indexing is supplemental, it can be made a background task that can occur at more or less any time. So we run it as soon as possible.
This commit is contained in:
@@ -44,9 +44,5 @@ TaskView::TaskView(QWidget* parent) :
|
||||
void TaskView::AddTask(Task *t)
|
||||
{
|
||||
// Create TaskViewItem (UI representation of a Task) and connect it
|
||||
TaskViewItem* item = new TaskViewItem(central_widget_);
|
||||
|
||||
item->SetTask(t);
|
||||
|
||||
layout_->insertWidget(0, item);
|
||||
layout_->insertWidget(0, new TaskViewItem(t));
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
TaskViewItem::TaskViewItem(QWidget *parent) :
|
||||
TaskViewItem::TaskViewItem(Task* task, QWidget *parent) :
|
||||
QFrame(parent),
|
||||
task_(nullptr)
|
||||
task_(task)
|
||||
{
|
||||
// Draw border around this item
|
||||
setFrameShape(QFrame::StyledPanel);
|
||||
@@ -36,6 +36,7 @@ TaskViewItem::TaskViewItem(QWidget *parent) :
|
||||
|
||||
// Create header label
|
||||
task_name_lbl_ = new QLabel(this);
|
||||
task_name_lbl_->setText(task_->GetTitle());
|
||||
layout->addWidget(task_name_lbl_);
|
||||
|
||||
// Create center layout (combines progress bar and a cancel button)
|
||||
@@ -55,54 +56,9 @@ TaskViewItem::TaskViewItem(QWidget *parent) :
|
||||
// Create status label
|
||||
task_status_lbl_ = new QLabel(this);
|
||||
layout->addWidget(task_status_lbl_);
|
||||
}
|
||||
|
||||
void TaskViewItem::SetTask(Task *t)
|
||||
{
|
||||
// Check if we already have a task and disconnect from it if so
|
||||
if (task_ != nullptr) {
|
||||
disconnect(task_, SIGNAL(StatusChanged(Task::Status)), this, SLOT(TaskStatusChange(Task::Status)));
|
||||
disconnect(task_, SIGNAL(ProgressChanged(int)), progress_bar_, SLOT(setValue(int)));
|
||||
disconnect(task_, SIGNAL(destroyed()), this, SLOT(deleteLater()));
|
||||
}
|
||||
|
||||
// Set task
|
||||
task_ = t;
|
||||
|
||||
// Set name label to the name (bolded)
|
||||
task_name_lbl_->setText(QStringLiteral("<b>%1</b>").arg(task_->text()));
|
||||
|
||||
// Connect to the task
|
||||
connect(task_, SIGNAL(StatusChanged(Task::Status)), this, SLOT(TaskStatusChange(Task::Status)));
|
||||
connect(task_, SIGNAL(ProgressChanged(int)), progress_bar_, SLOT(setValue(int)));
|
||||
connect(task_, SIGNAL(Removed()), this, SLOT(deleteLater()));
|
||||
connect(cancel_btn_, SIGNAL(clicked(bool)), task_, SLOT(Cancel()));
|
||||
}
|
||||
|
||||
void TaskViewItem::TaskStatusChange(Task::Status status)
|
||||
{
|
||||
switch (status) {
|
||||
case Task::kWaiting:
|
||||
task_status_lbl_->setText(tr("Waiting..."));
|
||||
progress_bar_->setValue(0);
|
||||
cancel_btn_->setEnabled(true);
|
||||
break;
|
||||
case Task::kWorking:
|
||||
task_status_lbl_->setText(tr("Working..."));
|
||||
progress_bar_->setValue(0);
|
||||
cancel_btn_->setEnabled(true);
|
||||
break;
|
||||
case Task::kFinished:
|
||||
task_status_lbl_->setText(tr("Done"));
|
||||
progress_bar_->setValue(100);
|
||||
cancel_btn_->setEnabled(false);
|
||||
break;
|
||||
case Task::kError:
|
||||
task_status_lbl_->setText(
|
||||
tr("Error: %1").arg(static_cast<Task*>(sender())->error())
|
||||
);
|
||||
progress_bar_->setValue(0);
|
||||
cancel_btn_->setEnabled(false);
|
||||
break;
|
||||
}
|
||||
connect(task_, &Task::ProgressChanged, progress_bar_, &QProgressBar::setValue);
|
||||
connect(task_, &Task::Removed, this, &TaskViewItem::deleteLater);
|
||||
connect(cancel_btn_, &QPushButton::clicked, task_, &Task::Cancel, Qt::DirectConnection);
|
||||
}
|
||||
|
||||
@@ -41,16 +41,7 @@ class TaskViewItem : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TaskViewItem(QWidget* parent);
|
||||
|
||||
/**
|
||||
* @brief Connects a Task to this object
|
||||
*
|
||||
* If a Task has already been connected, this will disconnect this TaskViewItem from the previously connected
|
||||
* Task before connecting to the next one - however there are very few circumstances where this would be necessary
|
||||
* since TaskViewItem is designed to delete itself when a Task is complete.
|
||||
*/
|
||||
void SetTask(Task* t);
|
||||
TaskViewItem(Task *task, QWidget* parent = nullptr);
|
||||
|
||||
private:
|
||||
QLabel* task_name_lbl_;
|
||||
@@ -60,9 +51,6 @@ private:
|
||||
|
||||
Task* task_;
|
||||
|
||||
private slots:
|
||||
void TaskStatusChange(Task::Status status);
|
||||
|
||||
};
|
||||
|
||||
#endif // TASKVIEWITEM_H
|
||||
|
||||
Reference in New Issue
Block a user