refactor: MainWindow, remove m_currentIPValid by reducing its scope to the method where its used
This commit is contained in:
committed by
Chris Rizzitello
parent
1973005e98
commit
c2314ad893
@ -83,8 +83,7 @@ MainWindow::MainWindow()
|
||||
m_actionStartCore{new QAction(this)},
|
||||
m_actionRestartCore{new QAction(this)},
|
||||
m_actionStopCore{new QAction(this)},
|
||||
m_networkMonitor{new NetworkMonitor(this)},
|
||||
m_currentIPValid(true)
|
||||
m_networkMonitor{new NetworkMonitor(this)}
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -1290,22 +1289,21 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||
ipList.append(address.toString());
|
||||
}
|
||||
|
||||
bool IPValid = true;
|
||||
QString suggestedIP = m_serverStartSuggestedIP.toString();
|
||||
if ((suggestedIP != m_currentIpAddress.toString()) || !addresses.contains(m_serverStartSuggestedIP)) {
|
||||
m_currentIPValid = false;
|
||||
IPValid = false;
|
||||
for (const auto &address : std::as_const(m_serverStartIPs)) {
|
||||
if (addresses.contains(address)) {
|
||||
suggestedIP = address.toString();
|
||||
m_currentIpAddress = address;
|
||||
m_currentIPValid = true;
|
||||
IPValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_currentIPValid = true;
|
||||
}
|
||||
|
||||
if (m_currentIPValid) {
|
||||
if (IPValid) {
|
||||
labelText.append(suggestedIP);
|
||||
} else {
|
||||
labelText.append(colorText.arg(palette().linkVisited().color().name(), suggestedIP));
|
||||
@ -1314,8 +1312,7 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||
} else {
|
||||
// Server is not running - update normally
|
||||
m_currentIpAddress = m_networkMonitor->getSuggestedIPv4Address();
|
||||
m_currentIPValid = m_currentIpAddress.isNull();
|
||||
QString displayIP = m_currentIPValid ? m_currentIpAddress.toString() : ipList.first();
|
||||
QString displayIP = m_currentIpAddress.isNull() ? m_currentIpAddress.toString() : ipList.first();
|
||||
labelText.append(displayIP);
|
||||
}
|
||||
|
||||
|
||||
@ -231,5 +231,4 @@ private:
|
||||
// Server IP strategy optimization
|
||||
QList<QHostAddress> m_serverStartIPs;
|
||||
QHostAddress m_serverStartSuggestedIP;
|
||||
bool m_currentIPValid;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user