refactor: MainWindow, unify how Automatic and Fixed Ip are displayed
This commit is contained in:
committed by
Chris Rizzitello
parent
d324dd1a93
commit
09c1bd1582
@ -429,7 +429,7 @@ void MainWindow::coreProcessError(CoreProcess::Error error)
|
||||
void MainWindow::startCore()
|
||||
{
|
||||
// Save current IP state when server starts
|
||||
if (m_coreProcess.mode() == CoreMode::Server) {
|
||||
if (m_coreProcess.mode() == CoreMode::Server && Settings::value(Settings::Core::Interface).isNull()) {
|
||||
m_serverStartIPs = m_networkMonitor->getAvailableIPv4Addresses();
|
||||
m_serverStartSuggestedIP = m_serverStartIPs.isEmpty() ? "" : m_serverStartIPs.first();
|
||||
}
|
||||
@ -707,6 +707,11 @@ void MainWindow::applyConfig()
|
||||
updateLocalFingerprint();
|
||||
setTrayIcon();
|
||||
|
||||
if (const auto ip = Settings::value(Settings::Core::Interface).toString(); !ip.isEmpty()) {
|
||||
m_serverStartIPs = {ip};
|
||||
m_serverStartSuggestedIP = ip;
|
||||
}
|
||||
|
||||
const auto coreMode = Settings::value(Settings::Core::CoreMode).value<Settings::CoreMode>();
|
||||
|
||||
if (coreMode == Settings::CoreMode::None)
|
||||
@ -1250,46 +1255,25 @@ void MainWindow::updateIpLabel(const QStringList &addresses)
|
||||
|
||||
static const auto colorText = QStringLiteral(R"(<span style="color:%1;">%2</span>)");
|
||||
const bool serverStarted = m_coreProcess.isStarted();
|
||||
const bool fixedIP = !Settings::value(Settings::Core::Interface).isNull();
|
||||
|
||||
if (addresses.isEmpty() && !serverStarted || (serverStarted && m_serverStartSuggestedIP.isEmpty())) {
|
||||
if (!fixedIP && addresses.isEmpty() && !serverStarted || (serverStarted && m_serverStartSuggestedIP.isEmpty())) {
|
||||
ui->lblIpAddresses->setText(colorText.arg(palette().linkVisited().color().name(), tr("No IP Detected")));
|
||||
ui->lblIpAddresses->setToolTip(tr("Unable to detect an IP address. Check your network connection is active."));
|
||||
return;
|
||||
}
|
||||
|
||||
QString labelText;
|
||||
QString toolTipText;
|
||||
|
||||
// If we have a fixed IP we will use it
|
||||
if (const auto ip = Settings::value(Settings::Core::Interface).toString(); !ip.isEmpty()) {
|
||||
labelText = tr("Using IP: ");
|
||||
toolTipText = tr("Selected as the interface in settings.");
|
||||
if (addresses.contains(ip, Qt::CaseInsensitive)) {
|
||||
labelText.append(ip);
|
||||
} else {
|
||||
labelText.append(colorText.arg(palette().linkVisited().color().name(), ip));
|
||||
toolTipText.append(tr("\nInterface is not active. Unable to start server."));
|
||||
}
|
||||
ui->lblIpAddresses->setText(labelText);
|
||||
ui->lblIpAddresses->setToolTip(toolTipText);
|
||||
return;
|
||||
}
|
||||
|
||||
labelText = tr("Suggested IP: ");
|
||||
toolTipText = tr("<p>If connecting via the hostname fails, try %1</p>");
|
||||
QString labelText = fixedIP ? tr("Using IP: ") : tr("Suggested IP: ");
|
||||
QString toolTipText = tr("<p>If connecting via the hostname fails, try %1</p>");
|
||||
|
||||
// Get all available IPs for tooltip
|
||||
QStringList ipList = addresses;
|
||||
const bool filterIpList = (serverStarted || fixedIP);
|
||||
const QRegularExpression ipListFilter(filterIpList ? QStringLiteral("(%1)").arg(m_serverStartIPs.join("|")) : "");
|
||||
const QStringList ipList = addresses.filter(ipListFilter);
|
||||
|
||||
// Determine which IP to show and tooltip based on server state
|
||||
bool IPValid = true;
|
||||
if (serverStarted) {
|
||||
// ipList should only include valid ip from servers start
|
||||
const QRegularExpression ipListFilter(QStringLiteral("(%1)").arg(m_serverStartIPs.join("|")));
|
||||
ipList = addresses.filter(ipListFilter);
|
||||
if ((m_serverStartSuggestedIP != m_currentIpAddress) || !ipList.contains(m_serverStartSuggestedIP)) {
|
||||
IPValid = !ipList.isEmpty();
|
||||
}
|
||||
if (filterIpList && (m_serverStartSuggestedIP != m_currentIpAddress) || !ipList.contains(m_serverStartSuggestedIP)) {
|
||||
IPValid = !ipList.isEmpty();
|
||||
}
|
||||
|
||||
if (IPValid) {
|
||||
@ -1300,7 +1284,7 @@ void MainWindow::updateIpLabel(const QStringList &addresses)
|
||||
toolTipText.append(tr("\nA bound IP is now invalid, you may need to restart the server."));
|
||||
}
|
||||
|
||||
if (ipList.count() < 2) {
|
||||
if (ipList.count() < 2 || fixedIP) {
|
||||
toolTipText = toolTipText.arg(tr("the suggested IP."));
|
||||
} else {
|
||||
toolTipText = toolTipText.arg(tr("one of the following IPs:<br/>%1").arg(ipList.join("<br/>")));
|
||||
|
||||
@ -423,10 +423,6 @@ Do you want to connect to the server?
|
||||
<source>Using IP: </source>
|
||||
<translation type="unfinished">Usando IP: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Selected as the interface in settings.</source>
|
||||
<translation type="unfinished">Seleccionado como la interfaz en la configuración.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Suggested IP: </source>
|
||||
<translation type="unfinished">IP sugerida: </translation>
|
||||
@ -473,12 +469,6 @@ La dirección IP asignada ahora no es válida; es posible que deba reiniciar el
|
||||
<source>invalid certificate, generating a new one</source>
|
||||
<translation type="unfinished">certificado no válido, generando uno nuevo</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>
|
||||
Interface is not active. Unable to start server.</source>
|
||||
<translation type="unfinished">
|
||||
La interfaz no está activa. No se puede iniciar el servidor.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 will retry in a moment...</source>
|
||||
<translation type="unfinished">%1 lo intentará nuevamente en un momento...</translation>
|
||||
|
||||
@ -411,10 +411,6 @@ Vuoi connetterti al server?
|
||||
<source>Using IP: </source>
|
||||
<translation type="unfinished">Utilizzo dell'indirizzo IP: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Selected as the interface in settings.</source>
|
||||
<translation type="unfinished">Selezionata come interfaccia nelle impostazioni.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Suggested IP: </source>
|
||||
<translation type="unfinished">IP suggerito: </translation>
|
||||
@ -481,12 +477,6 @@ Nomi validi:
|
||||
<source>invalid certificate, generating a new one</source>
|
||||
<translation type="unfinished">certificato non valido, ne viene generato uno nuovo</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>
|
||||
Interface is not active. Unable to start server.</source>
|
||||
<translation type="unfinished">
|
||||
L'interfaccia non è attiva. Impossibile avviare il server.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1 will retry in a moment...</source>
|
||||
<translation>%1 riproverà tra un momento...</translation>
|
||||
|
||||
@ -375,10 +375,6 @@ Do you want to connect to the server?
|
||||
<source>Using IP: </source>
|
||||
<translation type="unfinished">IPアドレスを使用する: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Selected as the interface in settings.</source>
|
||||
<translation type="unfinished">設定でインターフェースとして選択されています。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><p>If connecting via the hostname fails, try %1</p></source>
|
||||
<translation><p>ホスト名での接続が失敗する場合は %1 を試してください。</p></translation>
|
||||
@ -540,12 +536,6 @@ Valid names:
|
||||
%1</source>
|
||||
<translation>クライアント:
|
||||
%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>
|
||||
Interface is not active. Unable to start server.</source>
|
||||
<translation type="unfinished">
|
||||
インターフェースがアクティブではありません。サーバーを起動できません。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Suggested IP: </source>
|
||||
|
||||
@ -377,10 +377,6 @@ Do you want to connect to the server?
|
||||
<source>Using IP: </source>
|
||||
<translation type="unfinished">Использование IP-адреса: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Selected as the interface in settings.</source>
|
||||
<translation type="unfinished">Выбран в качестве интерфейса в настройках.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><p>If connecting via the hostname fails, try %1</p></source>
|
||||
<translation><p>Если подключение по имени хоста не получается, попробуй %1</p></translation>
|
||||
@ -544,12 +540,6 @@ Valid names:
|
||||
%1</source>
|
||||
<translation>Клиент:
|
||||
%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>
|
||||
Interface is not active. Unable to start server.</source>
|
||||
<translation type="unfinished">
|
||||
Интерфейс неактивен. Невозможно запустить сервер.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Suggested IP: </source>
|
||||
|
||||
@ -375,10 +375,6 @@ Do you want to connect to the server?
|
||||
<source>Using IP: </source>
|
||||
<translation type="unfinished">使用IP地址: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Selected as the interface in settings.</source>
|
||||
<translation type="unfinished">在设置中选择为接口。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source><p>If connecting via the hostname fails, try %1</p></source>
|
||||
<translation><p>如果通过主机名连接失败,请尝试 %1</p></translation>
|
||||
@ -540,12 +536,6 @@ Valid names:
|
||||
%1</source>
|
||||
<translation>客户端:
|
||||
%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>
|
||||
Interface is not active. Unable to start server.</source>
|
||||
<translation type="unfinished">
|
||||
接口未激活。无法启动服务器。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Suggested IP: </source>
|
||||
|
||||
Reference in New Issue
Block a user