refactor: MainWindow::updateIpLabel, simplify IPValid checks
This commit is contained in:
parent
889689bd8e
commit
d324dd1a93
1 changed files with 8 additions and 17 deletions
|
|
@ -1282,31 +1282,22 @@ void MainWindow::updateIpLabel(const QStringList &addresses)
|
||||||
QStringList ipList = addresses;
|
QStringList ipList = addresses;
|
||||||
|
|
||||||
// Determine which IP to show and tooltip based on server state
|
// Determine which IP to show and tooltip based on server state
|
||||||
|
bool IPValid = true;
|
||||||
if (serverStarted) {
|
if (serverStarted) {
|
||||||
// ipList should only include valid ip from servers start
|
// ipList should only include valid ip from servers start
|
||||||
const QRegularExpression ipListFilter(QStringLiteral("(%1)").arg(m_serverStartIPs.join("|")));
|
const QRegularExpression ipListFilter(QStringLiteral("(%1)").arg(m_serverStartIPs.join("|")));
|
||||||
ipList = addresses.filter(ipListFilter);
|
ipList = addresses.filter(ipListFilter);
|
||||||
bool IPValid = true;
|
if ((m_serverStartSuggestedIP != m_currentIpAddress) || !ipList.contains(m_serverStartSuggestedIP)) {
|
||||||
QString suggestedIP = m_serverStartSuggestedIP;
|
IPValid = !ipList.isEmpty();
|
||||||
if ((suggestedIP != m_currentIpAddress) || !ipList.contains(m_serverStartSuggestedIP)) {
|
|
||||||
IPValid = false;
|
|
||||||
if (!ipList.isEmpty()) {
|
|
||||||
suggestedIP = ipList.first();
|
|
||||||
m_currentIpAddress = suggestedIP;
|
|
||||||
IPValid = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (IPValid) {
|
if (IPValid) {
|
||||||
labelText.append(suggestedIP);
|
|
||||||
} else {
|
|
||||||
labelText.append(colorText.arg(palette().linkVisited().color().name(), suggestedIP));
|
|
||||||
toolTipText.append(tr("\nA bound IP is now invalid, you may need to restart the server."));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Server is not running - update normally
|
|
||||||
m_currentIpAddress = ipList.first();
|
m_currentIpAddress = ipList.first();
|
||||||
labelText.append(m_currentIpAddress);
|
labelText.append(m_currentIpAddress);
|
||||||
|
} else {
|
||||||
|
labelText.append(colorText.arg(palette().linkVisited().color().name(), m_serverStartSuggestedIP));
|
||||||
|
toolTipText.append(tr("\nA bound IP is now invalid, you may need to restart the server."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipList.count() < 2) {
|
if (ipList.count() < 2) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue