refactor: Mainwindow::updateIpLabel return early if we are using fixedIp from settings
This commit is contained in:
parent
c2314ad893
commit
a84e91a3f2
1 changed files with 42 additions and 39 deletions
|
|
@ -1274,53 +1274,56 @@ void MainWindow::updateIpLabel(const QList<QHostAddress> &addresses)
|
||||||
labelText.append(colorText.arg(palette().linkVisited().color().name(), ip));
|
labelText.append(colorText.arg(palette().linkVisited().color().name(), ip));
|
||||||
toolTipText.append(tr("\nInterface is not active. Unable to start server."));
|
toolTipText.append(tr("\nInterface is not active. Unable to start server."));
|
||||||
}
|
}
|
||||||
} else {
|
ui->lblIpAddresses->setText(labelText);
|
||||||
labelText = tr("Suggested IP: ");
|
ui->lblIpAddresses->setToolTip(toolTipText);
|
||||||
toolTipText = tr("<p>If connecting via the hostname fails, try %1</p>");
|
return;
|
||||||
static auto s_toolTipSuggestIP = tr("the suggested IP.");
|
}
|
||||||
static auto s_toolTipIpList = tr("one of the following IPs:<br/>%1");
|
|
||||||
|
|
||||||
// Determine which IP to show and tooltip based on server state
|
labelText = tr("Suggested IP: ");
|
||||||
if (m_coreProcess.isStarted()) {
|
toolTipText = tr("<p>If connecting via the hostname fails, try %1</p>");
|
||||||
// ipList should only include valid ip from servers start
|
static auto s_toolTipSuggestIP = tr("the suggested IP.");
|
||||||
ipList.clear();
|
static auto s_toolTipIpList = tr("one of the following IPs:<br/>%1");
|
||||||
|
|
||||||
|
// Determine which IP to show and tooltip based on server state
|
||||||
|
if (m_coreProcess.isStarted()) {
|
||||||
|
// ipList should only include valid ip from servers start
|
||||||
|
ipList.clear();
|
||||||
|
for (const auto &address : std::as_const(m_serverStartIPs)) {
|
||||||
|
if (addresses.contains(address))
|
||||||
|
ipList.append(address.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPValid = true;
|
||||||
|
QString suggestedIP = m_serverStartSuggestedIP.toString();
|
||||||
|
if ((suggestedIP != m_currentIpAddress.toString()) || !addresses.contains(m_serverStartSuggestedIP)) {
|
||||||
|
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)) {
|
||||||
ipList.append(address.toString());
|
suggestedIP = address.toString();
|
||||||
}
|
m_currentIpAddress = address;
|
||||||
|
IPValid = true;
|
||||||
bool IPValid = true;
|
break;
|
||||||
QString suggestedIP = m_serverStartSuggestedIP.toString();
|
|
||||||
if ((suggestedIP != m_currentIpAddress.toString()) || !addresses.contains(m_serverStartSuggestedIP)) {
|
|
||||||
IPValid = false;
|
|
||||||
for (const auto &address : std::as_const(m_serverStartIPs)) {
|
|
||||||
if (addresses.contains(address)) {
|
|
||||||
suggestedIP = address.toString();
|
|
||||||
m_currentIpAddress = address;
|
|
||||||
IPValid = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = m_networkMonitor->getSuggestedIPv4Address();
|
|
||||||
QString displayIP = m_currentIpAddress.isNull() ? m_currentIpAddress.toString() : ipList.first();
|
|
||||||
labelText.append(displayIP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipList.count() < 2) {
|
if (IPValid) {
|
||||||
toolTipText = toolTipText.arg(s_toolTipSuggestIP);
|
labelText.append(suggestedIP);
|
||||||
} else {
|
} else {
|
||||||
toolTipText = toolTipText.arg(s_toolTipIpList.arg(ipList.join("<br/>")));
|
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 = m_networkMonitor->getSuggestedIPv4Address();
|
||||||
|
QString displayIP = m_currentIpAddress.isNull() ? m_currentIpAddress.toString() : ipList.first();
|
||||||
|
labelText.append(displayIP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ipList.count() < 2) {
|
||||||
|
toolTipText = toolTipText.arg(s_toolTipSuggestIP);
|
||||||
|
} else {
|
||||||
|
toolTipText = toolTipText.arg(s_toolTipIpList.arg(ipList.join("<br/>")));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->lblIpAddresses->setText(labelText);
|
ui->lblIpAddresses->setText(labelText);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue