Example #1
0
void JobsTabWidget::addDefaultJobs()
{
    TSettings settings;
    for(const QString &path : DEFAULT_JOBS)
    {
        QDir dir(QDir::home());
        if(dir.cd(path))
        {
            JobPtr job(new Job());
            job->setName(dir.dirName());
            QList<QUrl> urls;
            urls << QUrl::fromUserInput(dir.canonicalPath());
            job->setUrls(urls);
            job->save();
            _ui->jobDetailsWidget->jobAdded(job);
        }
    }
    settings.setValue("app/default_jobs_dismissed", true);
    _ui->defaultJobs->hide();
    _ui->addJobButton->show();
}
Example #2
0
JobsTabWidget::JobsTabWidget(QWidget *parent)
    : QWidget(parent), _ui(new Ui::JobsTabWidget)
{
    // Ui initialization
    _ui->setupUi(this);
    _ui->jobListWidget->setAttribute(Qt::WA_MacShowFocusRect, false);
    _ui->jobDetailsWidget->hide();
    _ui->jobsFilterFrame->hide();

    // "Default jobs" handling
    connect(_ui->sureButton, &QPushButton::clicked, this,
            &JobsTabWidget::addDefaultJobs);
    connect(_ui->dismissButton, &QPushButton::clicked, [&]() {
        TSettings settings;
        settings.setValue("app/default_jobs_dismissed", true);
        _ui->defaultJobs->hide();
        _ui->addJobButton->show();
    });

    // Messages between widgets on this tab
    connect(_ui->addJobButton, &QToolButton::clicked, this,
            &JobsTabWidget::addJobClicked);
    connect(_ui->actionAddJob, &QAction::triggered, this,
            &JobsTabWidget::addJobClicked);

    // Connections from the JobDetailsWidget
    connect(_ui->jobDetailsWidget, &JobWidget::collapse, this,
            &JobsTabWidget::hideJobDetails);
    connect(_ui->jobDetailsWidget, &JobWidget::jobAdded, this,
            &JobsTabWidget::displayJobDetails);
    connect(_ui->jobDetailsWidget, &JobWidget::enableSave, _ui->addJobButton,
            &QToolButton::setEnabled);

    // Connections from the JobDetailsWidget that get forwarded on
    connect(_ui->jobDetailsWidget, &JobWidget::jobAdded, this,
            &JobsTabWidget::jobAdded);
    connect(_ui->jobDetailsWidget, &JobWidget::inspectJobArchive, this,
            &JobsTabWidget::displayInspectArchive);
    connect(_ui->jobDetailsWidget, &JobWidget::restoreJobArchive, this,
            &JobsTabWidget::restoreArchive);
    connect(_ui->jobDetailsWidget, &JobWidget::deleteJobArchives, this,
            &JobsTabWidget::deleteArchives);
    connect(_ui->jobDetailsWidget, &JobWidget::backupJob, this,
            &JobsTabWidget::backupJob);
    connect(_ui->jobDetailsWidget, &JobWidget::findMatchingArchives, this,
            &JobsTabWidget::findMatchingArchives);

    // Connections to the JobDetailsWidget
    connect(this, &JobsTabWidget::matchingArchives, _ui->jobDetailsWidget,
            &JobWidget::updateMatchingArchives);

    // Connections from the JobListWidget
    connect(_ui->jobListWidget, &JobListWidget::displayJobDetails, this,
            &JobsTabWidget::displayJobDetails);
    connect(_ui->jobListWidget, &JobListWidget::backupJob, this,
            &JobsTabWidget::backupJob);
    connect(_ui->jobListWidget, &JobListWidget::restoreArchive, this,
            &JobsTabWidget::restoreArchive);
    connect(_ui->jobListWidget, &JobListWidget::deleteJob, this,
            &JobsTabWidget::deleteJob);
    connect(_ui->jobListWidget, &JobListWidget::customContextMenuRequested,
            this, &JobsTabWidget::showJobsListMenu);

    // Connections to the JobListWidget
    connect(this, &JobsTabWidget::backupSelectedItems, _ui->jobListWidget,
            &JobListWidget::backupSelectedItems);
    connect(this, &JobsTabWidget::deleteSelectedItem, _ui->jobListWidget,
            &JobListWidget::deleteSelectedItem);
    connect(this, &JobsTabWidget::restoreSelectedItem, _ui->jobListWidget,
            &JobListWidget::restoreSelectedItem);
    connect(this, &JobsTabWidget::inspectSelectedItem, _ui->jobListWidget,
            &JobListWidget::inspectSelectedItem);

    // Jobs filter
    _ui->jobsFilterButton->setDefaultAction(_ui->actionFilterJobs);
    connect(_ui->actionFilterJobs, &QAction::triggered, [&]() {
        _ui->jobsFilterFrame->setVisible(!_ui->jobsFilterFrame->isVisible());
        if(_ui->jobsFilter->isVisible())
            _ui->jobsFilter->setFocus();
        else
            _ui->jobsFilter->clearEditText();
    });
    connect(_ui->jobsFilter, &QComboBox::editTextChanged, _ui->jobListWidget,
            &JobListWidget::setFilter);
    connect(_ui->jobsFilter, static_cast<void (QComboBox::*)(int)>(
                                 &QComboBox::currentIndexChanged),
            this, [&]() { _ui->jobListWidget->setFocus(); });

    // Update filter results
    connect(_ui->jobListWidget, &JobListWidget::countChanged, this,
            [&](int total, int visible) {
                _ui->jobsCountLabel->setText(
                    tr("Jobs (%1/%2)").arg(visible).arg(total));
            });

    // Right-click context menu
    _ui->jobListWidget->addAction(_ui->actionJobBackup);
    _ui->jobListWidget->addAction(_ui->actionJobDelete);
    _ui->jobListWidget->addAction(_ui->actionJobInspect);
    _ui->jobListWidget->addAction(_ui->actionJobRestore);
    _ui->jobListWidget->addAction(_ui->actionFilterJobs);
    _ui->jobListWidget->addAction(_ui->actionJobBackup);
    _ui->jobListWidget->addAction(_ui->actionAddJob);

    // Connections to the JobListWidget
    connect(this, &JobsTabWidget::jobList, _ui->jobListWidget,
            &JobListWidget::setJobs);
    connect(this, &JobsTabWidget::jobAdded, _ui->jobListWidget,
            &JobListWidget::addJob);
    connect(this, &JobsTabWidget::jobInspectByRef, _ui->jobListWidget,
            &JobListWidget::inspectJobByRef);

    connect(_ui->actionJobBackup, &QAction::triggered, _ui->jobListWidget,
            &JobListWidget::backupSelectedItems);
    connect(_ui->actionJobDelete, &QAction::triggered, _ui->jobListWidget,
            &JobListWidget::deleteSelectedItem);
    connect(_ui->actionJobRestore, &QAction::triggered, _ui->jobListWidget,
            &JobListWidget::restoreSelectedItem);
    connect(_ui->actionJobInspect, &QAction::triggered, _ui->jobListWidget,
            &JobListWidget::inspectSelectedItem);

    //  addJobButton
    QMenu *addJobMenu = new QMenu(_ui->addJobButton);
    addJobMenu->addAction(_ui->actionBackupAllJobs);
    connect(_ui->actionBackupAllJobs, &QAction::triggered, _ui->jobListWidget,
            &JobListWidget::backupAllJobs);
    _ui->addJobButton->setMenu(addJobMenu);

    loadSettings();
    updateUi();
}