Commit 48ce0caf authored by John Tourtellott's avatar John Tourtellott
Browse files

Update logic to enable/disable polling widgets

* Accounts for both presence of jobs and if user is logged in
* More brute-force logic than needed for this implementation
parent d7a6c808
...@@ -78,20 +78,18 @@ qtJobsWidget::qtJobsWidget(QWidget* parentWidget) ...@@ -78,20 +78,18 @@ qtJobsWidget::qtJobsWidget(QWidget* parentWidget)
this->ui->m_pollingStateLabel->setText(text); this->ui->m_pollingStateLabel->setText(text);
}); });
// Check if we are logged in // Initialize polling widgets
QSharedPointer<cumulus::CumulusProxy> cumulus = cumulus::CumulusProxy::instance(); if (!this->enablePollingWidgets())
if (cumulus->isAuthenticated())
{ {
this->enablePollingWidgets(true); // If not enabled, see if we need to connect to login signal
QSharedPointer<cumulus::CumulusProxy> cumulus = cumulus::CumulusProxy::instance();
if (!cumulus->isAuthenticated())
{
QObject::connect(cumulus.get(), &cumulus::CumulusProxy::authenticationFinished, [this]() {
this->enablePollingWidgets();
});
}
} }
else
{
this->enablePollingWidgets(false);
QObject::connect(cumulus.get(), &cumulus::CumulusProxy::authenticationFinished, [this]() {
this->enablePollingWidgets(true);
});
}
} }
void qtJobsWidget::setProject(smtk::project::ProjectPtr project) void qtJobsWidget::setProject(smtk::project::ProjectPtr project)
...@@ -105,6 +103,9 @@ void qtJobsWidget::setProject(smtk::project::ProjectPtr project) ...@@ -105,6 +103,9 @@ void qtJobsWidget::setProject(smtk::project::ProjectPtr project)
void qtJobsWidget::onJobAdded(const QString& cumulusJobId) void qtJobsWidget::onJobAdded(const QString& cumulusJobId)
{ {
m_jobs_model->onJobAdded(cumulusJobId); m_jobs_model->onJobAdded(cumulusJobId);
this->enablePollingWidgets();
// Future: add argument to enablePollingWidgets() that new job was added.
// In that case we can presume that user is logged in and there is at least one job.
} }
void qtJobsWidget::toggleDetailsVisibility( void qtJobsWidget::toggleDetailsVisibility(
...@@ -195,8 +196,19 @@ void qtJobsWidget::pollingCheckBoxStateChanged(bool checked) ...@@ -195,8 +196,19 @@ void qtJobsWidget::pollingCheckBoxStateChanged(bool checked)
this->ui->m_updateStatusButton->setEnabled(!checked); this->ui->m_updateStatusButton->setEnabled(!checked);
} }
void qtJobsWidget::enablePollingWidgets(bool enable) bool qtJobsWidget::enablePollingWidgets()
{ {
bool enable = false;
// Enable widgets if model has data and user logged into cumulus
if (m_jobs_model->rowCount() > 0)
{
// Check if user is signed in
QSharedPointer<cumulus::CumulusProxy> cumulus = cumulus::CumulusProxy::instance();
enable = cumulus->isAuthenticated();
}
// Set widget states
this->ui->m_enablePollingCheckBox->setEnabled(enable); this->ui->m_enablePollingCheckBox->setEnabled(enable);
this->ui->m_pollingStateLabel->setEnabled(enable); this->ui->m_pollingStateLabel->setEnabled(enable);
this->ui->m_updateStatusButton->setEnabled(enable && !this->ui->m_enablePollingCheckBox->isChecked()); this->ui->m_updateStatusButton->setEnabled(enable && !this->ui->m_enablePollingCheckBox->isChecked());
...@@ -204,6 +216,8 @@ void qtJobsWidget::enablePollingWidgets(bool enable) ...@@ -204,6 +216,8 @@ void qtJobsWidget::enablePollingWidgets(bool enable)
{ {
this->ui->m_pollingStateLabel->setText("Off"); this->ui->m_pollingStateLabel->setText("Off");
} }
return enable;
} }
} // namespace ace3p } // namespace ace3p
......
...@@ -63,7 +63,9 @@ protected slots: ...@@ -63,7 +63,9 @@ protected slots:
void pollingCheckBoxStateChanged(bool checked); void pollingCheckBoxStateChanged(bool checked);
protected: protected:
void enablePollingWidgets(bool enable); // Enables polling widget if signed in and jobs exists.
// Returns true if widgets are enabled.
bool enablePollingWidgets();
private: private:
// @brief pointer to UI information // @brief pointer to UI information
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment