Issue #115 Main connect button is checked iff network is connected

This commit is contained in:
Mat Sutcliffe
2021-09-01 20:40:50 +01:00
parent 8952229b82
commit 2ac1a13894
2 changed files with 17 additions and 18 deletions

View File

@@ -57,8 +57,7 @@ namespace BlackGui
connect(ui->pb_MainWeather, &QPushButton::released, this, &CMainKeypadAreaComponent::buttonSelected); connect(ui->pb_MainWeather, &QPushButton::released, this, &CMainKeypadAreaComponent::buttonSelected);
// non info areas // non info areas
connect(ui->pb_Connect, &QPushButton::pressed, this, &CMainKeypadAreaComponent::buttonSelected); connect(ui->pb_Connect, &QPushButton::released, this, &CMainKeypadAreaComponent::buttonSelected);
connect(ui->pb_Connect, &QPushButton::pressed, this, &CMainKeypadAreaComponent::disableButtonBriefly);
connect(ui->pb_Opacity050, &QPushButton::pressed, this, &CMainKeypadAreaComponent::buttonSelected); connect(ui->pb_Opacity050, &QPushButton::pressed, this, &CMainKeypadAreaComponent::buttonSelected);
connect(ui->pb_Opacity100, &QPushButton::pressed, this, &CMainKeypadAreaComponent::buttonSelected); connect(ui->pb_Opacity100, &QPushButton::pressed, this, &CMainKeypadAreaComponent::buttonSelected);
connect(ui->pb_SoundMaxVolume, &QPushButton::pressed, this, &CMainKeypadAreaComponent::buttonSelected); connect(ui->pb_SoundMaxVolume, &QPushButton::pressed, this, &CMainKeypadAreaComponent::buttonSelected);
@@ -107,6 +106,8 @@ namespace BlackGui
if (pb) { pb->setChecked(true); } if (pb) { pb->setChecked(true); }
} }
this->updateConnectionStatus();
Q_UNUSED(dockedIndexes) Q_UNUSED(dockedIndexes)
} }
@@ -153,6 +154,7 @@ namespace BlackGui
else if (senderButton == ui->pb_Connect) else if (senderButton == ui->pb_Connect)
{ {
emit this->connectPressed(); emit this->connectPressed();
this->updateConnectionStatus();
} }
else if (senderButton == ui->pb_Audio) else if (senderButton == ui->pb_Audio)
{ {
@@ -167,7 +169,7 @@ namespace BlackGui
// Connected button // Connected button
if (to.isConnected()) if (to.isConnected())
{ {
ui->pb_Connect->setText("Discon."); // full terms some too wide ui->pb_Connect->setText("Connected");
ui->pb_Connect->setChecked(true); ui->pb_Connect->setChecked(true);
// moved to stylesheet: ui->pb_Connect->setStyleSheet("background-color: green"); // moved to stylesheet: ui->pb_Connect->setStyleSheet("background-color: green");
} }
@@ -255,19 +257,8 @@ namespace BlackGui
ui->pb_MainTextMessages->setChecked(false); ui->pb_MainTextMessages->setChecked(false);
ui->pb_MainUsers->setChecked(false); ui->pb_MainUsers->setChecked(false);
ui->pb_MainWeather->setChecked(false); ui->pb_MainWeather->setChecked(false);
}
void CMainKeypadAreaComponent::disableButtonBriefly() this->updateConnectionStatus();
{
QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
if (!pb) { return; }
pb->setEnabled(false);
QPointer<CMainKeypadAreaComponent> myself(this);
QTimer::singleShot(750, [ = ]
{
if (!sGui || sGui->isShuttingDown() || !myself) { return; }
pb->setEnabled(true);
});
} }
void CMainKeypadAreaComponent::update() void CMainKeypadAreaComponent::update()
@@ -277,11 +268,19 @@ namespace BlackGui
{ {
this->muteChanged(sGui->getCContextAudioBase()->isMuted()); this->muteChanged(sGui->getCContextAudioBase()->isMuted());
} }
this->updateConnectionStatus();
}
void CMainKeypadAreaComponent::updateConnectionStatus()
{
if (sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected()) if (sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected())
{ {
this->connectionStatusChanged(CConnectionStatus::Connected, CConnectionStatus::Connected); this->connectionStatusChanged(CConnectionStatus::Connected, CConnectionStatus::Connected);
} }
else
{
this->connectionStatusChanged(CConnectionStatus::Disconnected, CConnectionStatus::Disconnected);
}
} }
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -94,12 +94,12 @@ namespace BlackGui
//! Info area buttons //! Info area buttons
void unsetInfoAreaButtons(); void unsetInfoAreaButtons();
//! Disable button for some (short) time to avoid double click
void disableButtonBriefly();
//! Update values //! Update values
void update(); void update();
//! Update connection status
void updateConnectionStatus();
QScopedPointer<Ui::CMainKeypadAreaComponent> ui; QScopedPointer<Ui::CMainKeypadAreaComponent> ui;
BlackMisc::CIdentifier m_identifier { "MainKeypadAreaComponent", this }; BlackMisc::CIdentifier m_identifier { "MainKeypadAreaComponent", this };
}; };