refactor: MainWindow, remove m_currentIPValid by reducing its scope to the method where its used

This commit is contained in:
sithlord48 2025-12-30 17:21:33 -05:00 committed by Chris Rizzitello
parent 1973005e98
commit c2314ad893
2 changed files with 6 additions and 10 deletions

View file

@ -83,8 +83,7 @@ MainWindow::MainWindow()
m_actionStartCore{new QAction(this)}, m_actionStartCore{new QAction(this)},
m_actionRestartCore{new QAction(this)}, m_actionRestartCore{new QAction(this)},
m_actionStopCore{new QAction(this)}, m_actionStopCore{new QAction(this)},
m_networkMonitor{new NetworkMonitor(this)}, m_networkMonitor{new NetworkMonitor(this)}
m_currentIPValid(true)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -1290,22 +1289,21 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
ipList.append(address.toString()); ipList.append(address.toString());
} }
bool IPValid = true;
QString suggestedIP = m_serverStartSuggestedIP.toString(); QString suggestedIP = m_serverStartSuggestedIP.toString();
if ((suggestedIP != m_currentIpAddress.toString()) || !addresses.contains(m_serverStartSuggestedIP)) { if ((suggestedIP != m_currentIpAddress.toString()) || !addresses.contains(m_serverStartSuggestedIP)) {
m_currentIPValid = false; IPValid = false;
for (const auto &address : std::as_const(m_serverStartIPs)) { for (const auto &address : std::as_const(m_serverStartIPs)) {
if (addresses.contains(address)) { if (addresses.contains(address)) {
suggestedIP = address.toString(); suggestedIP = address.toString();
m_currentIpAddress = address; m_currentIpAddress = address;
m_currentIPValid = true; IPValid = true;
break; break;
} }
} }
} else {
m_currentIPValid = true;
} }
if (m_currentIPValid) { if (IPValid) {
labelText.append(suggestedIP); labelText.append(suggestedIP);
} else { } else {
labelText.append(colorText.arg(palette().linkVisited().color().name(), suggestedIP)); labelText.append(colorText.arg(palette().linkVisited().color().name(), suggestedIP));
@ -1314,8 +1312,7 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
} else { } else {
// Server is not running - update normally // Server is not running - update normally
m_currentIpAddress = m_networkMonitor->getSuggestedIPv4Address(); m_currentIpAddress = m_networkMonitor->getSuggestedIPv4Address();
m_currentIPValid = m_currentIpAddress.isNull(); QString displayIP = m_currentIpAddress.isNull() ? m_currentIpAddress.toString() : ipList.first();
QString displayIP = m_currentIPValid ? m_currentIpAddress.toString() : ipList.first();
labelText.append(displayIP); labelText.append(displayIP);
} }

View file

@ -231,5 +231,4 @@ private:
// Server IP strategy optimization // Server IP strategy optimization
QList<QHostAddress> m_serverStartIPs; QList<QHostAddress> m_serverStartIPs;
QHostAddress m_serverStartSuggestedIP; QHostAddress m_serverStartSuggestedIP;
bool m_currentIPValid;
}; };