void JobsTabWidget::backupJob(JobPtr job)
{
    if(!job)
        return;

    if(!job->validateUrls())
    {
        if(job->urls().isEmpty())
        {
            QMessageBox::warning(this, tr("Job error"),
                                 tr("Job %1 has no backup paths selected. "
                                    "Nothing to back up.")
                                     .arg(job->name()));
            return;
        }
        else
        {
            QMessageBox::StandardButton confirm = QMessageBox::question(
                this, tr("Job warning"),
                tr("Some backup paths for Job %1 are not"
                   " accessible anymore and thus backup may"
                   " be incomplete."
                   " Proceed with backup?")
                    .arg(job->name()));
            if(confirm != QMessageBox::Yes)
                return;
        }
    }
    emit backupNow(job->createBackupTask());
}
void JobListWidget::execDeleteJob(JobListWidgetItem *jobItem)
{
    if(!jobItem)
    {
        DEBUG << "Null JobListWidgetItem passed.";
        return;
    }

    JobPtr job = jobItem->job();

    QMessageBox::StandardButton confirm =
        QMessageBox::question(this, tr("Confirm action"),
                              tr("Are you sure you want to delete job \"%1\" "
                                 "(this cannot be undone)?")
                                  .arg(job->name()));
    if(confirm != QMessageBox::Yes)
        return;

    bool purgeArchives = false;
    if(!job->archives().isEmpty())
    {
        QMessageBox::StandardButton delArchives =
            QMessageBox::question(this, tr("Confirm action"),
                                  tr("Also delete %1 archives "
                                     "belonging to this job "
                                     "(this cannot be undone)?")
                                      .arg(job->archives().count()));
        if(delArchives == QMessageBox::Yes)
            purgeArchives = true;
    }
    emit deleteJob(job, purgeArchives);
    delete jobItem;
    emit countChanged(count(), visibleItemsCount());
}
void JobListWidget::addJob(JobPtr job)
{
    if(!job)
    {
        DEBUG << "Null JobPtr passed.";
        return;
    }

    JobListWidgetItem *item = new JobListWidgetItem(job);
    connect(item, &JobListWidgetItem::requestBackup, this,
            &JobListWidget::backupItem);
    connect(item, &JobListWidgetItem::requestInspect, this,
            &JobListWidget::inspectItem);
    connect(item, &JobListWidgetItem::requestRestore, this,
            &JobListWidget::restoreItem);
    connect(item, &JobListWidgetItem::requestDelete, this,
            &JobListWidget::deleteItem);
    insertItem(count(), item);
    setItemWidget(item, item->widget());
    item->setHidden(!job->name().contains(_filter));
    emit countChanged(count(), visibleItemsCount());
}