refactor: Mainwindow, adjust how and where the ip address is shown.
- Add a new method updateNetworkInfo to update lblIpAddresses This method can be hooked to the system network info in the future when we want to have this be more dynamic. - Only show the IP address when in server mode. - When showing the IP address show either the suggested IP or a message the user maybe offline - Use the linkVisited color to for our error message
This commit is contained in:
committed by
Chris Rizzitello
parent
a7048f76f9
commit
0dfd4ebc4a
@ -220,7 +220,8 @@ void MainWindow::setupControls()
|
|||||||
secureSocket(false);
|
secureSocket(false);
|
||||||
|
|
||||||
ui->btnConfigureServer->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
|
ui->btnConfigureServer->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
|
||||||
ui->lblIpAddresses->setText(tr("This computer's IP addresses: %1").arg(getIPAddresses()));
|
|
||||||
|
updateNetworkInfo();
|
||||||
|
|
||||||
if (Settings::value(Settings::Core::LastVersion).toString() != kVersion) {
|
if (Settings::value(Settings::Core::LastVersion).toString() != kVersion) {
|
||||||
Settings::setValue(Settings::Core::LastVersion, kVersion);
|
Settings::setValue(Settings::Core::LastVersion, kVersion);
|
||||||
@ -567,6 +568,7 @@ void MainWindow::coreModeToggled()
|
|||||||
|
|
||||||
void MainWindow::updateModeControls(bool serverMode)
|
void MainWindow::updateModeControls(bool serverMode)
|
||||||
{
|
{
|
||||||
|
ui->lblIpAddresses->setVisible(serverMode);
|
||||||
ui->serverOptions->setVisible(serverMode);
|
ui->serverOptions->setVisible(serverMode);
|
||||||
ui->clientOptions->setVisible(!serverMode);
|
ui->clientOptions->setVisible(!serverMode);
|
||||||
ui->lblNoMode->setVisible(false);
|
ui->lblNoMode->setVisible(false);
|
||||||
@ -606,6 +608,48 @@ void MainWindow::updateSecurityIcon(bool visible)
|
|||||||
m_lblSecurityStatus->setPixmap(icon.pixmap(QSize(32, 32)));
|
m_lblSecurityStatus->setPixmap(icon.pixmap(QSize(32, 32)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateNetworkInfo()
|
||||||
|
{
|
||||||
|
static const auto colorText = QStringLiteral(R"(<span style="color:%1;">%2</span>)");
|
||||||
|
|
||||||
|
QStringList ipList;
|
||||||
|
QString suggestedAddress;
|
||||||
|
|
||||||
|
bool hinted = false;
|
||||||
|
|
||||||
|
const auto addresses = QNetworkInterface::allAddresses();
|
||||||
|
for (const auto &address : addresses) {
|
||||||
|
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost) &&
|
||||||
|
!address.isInSubnet(QHostAddress::parseSubnet("169.254.0.0/16"))) {
|
||||||
|
// usually 192.168.x.x is a useful ip for the user, so indicate
|
||||||
|
// this by coloring it in the "link" color
|
||||||
|
if (!hinted && address.isInSubnet(QHostAddress::parseSubnet("192.168/16"))) {
|
||||||
|
suggestedAddress = address.toString();
|
||||||
|
ipList.append(colorText.arg(palette().link().color().name(), suggestedAddress));
|
||||||
|
hinted = true;
|
||||||
|
} else {
|
||||||
|
ipList.append(address.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ipList.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->lblIpAddresses->setText(
|
||||||
|
QStringLiteral("Suggested IP: %1").arg(suggestedAddress.isEmpty() ? ipList.first() : suggestedAddress)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (auto toolTipBase = tr("<p>If connecting via the hostname fails, try %1</p>"); ipList.count() < 2) {
|
||||||
|
ui->lblIpAddresses->setToolTip(toolTipBase.arg(tr("the suggested IP.")));
|
||||||
|
} else {
|
||||||
|
ui->lblIpAddresses->setToolTip(toolTipBase.arg(tr("one of the following IPs:<br/>%1").arg(ipList.join("br/>"))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::serverConnectionConfigureClient(const QString &clientName)
|
void MainWindow::serverConnectionConfigureClient(const QString &clientName)
|
||||||
{
|
{
|
||||||
Settings::setValue(Settings::Server::ConfigVisible, true);
|
Settings::setValue(Settings::Server::ConfigVisible, true);
|
||||||
@ -996,36 +1040,6 @@ void MainWindow::coreConnectionStateChanged(CoreConnectionState state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::getIPAddresses() const
|
|
||||||
{
|
|
||||||
QStringList result;
|
|
||||||
bool hinted = false;
|
|
||||||
const auto localnet = QHostAddress::parseSubnet("192.168.0.0/16");
|
|
||||||
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
|
||||||
|
|
||||||
for (const auto &address : addresses) {
|
|
||||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost) &&
|
|
||||||
!address.isInSubnet(QHostAddress::parseSubnet("169.254.0.0/16"))) {
|
|
||||||
|
|
||||||
// usually 192.168.x.x is a useful ip for the user, so indicate
|
|
||||||
// this by coloring it in the "link" color.
|
|
||||||
if (!hinted && address.isInSubnet(localnet)) {
|
|
||||||
QString format = R"(<span style="color:%1;">%2</span>)";
|
|
||||||
result.append(format.arg(palette().link().color().name(), address.toString()));
|
|
||||||
hinted = true;
|
|
||||||
} else {
|
|
||||||
result.append(address.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.isEmpty()) {
|
|
||||||
result.append("Unknown");
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.join(", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::updateLocalFingerprint()
|
void MainWindow::updateLocalFingerprint()
|
||||||
{
|
{
|
||||||
const bool tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool();
|
const bool tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool();
|
||||||
|
|||||||
@ -113,6 +113,7 @@ private:
|
|||||||
|
|
||||||
void showMyFingerprint();
|
void showMyFingerprint();
|
||||||
void updateSecurityIcon(bool visible);
|
void updateSecurityIcon(bool visible);
|
||||||
|
void updateNetworkInfo();
|
||||||
|
|
||||||
void coreModeToggled();
|
void coreModeToggled();
|
||||||
void updateModeControls(bool serverMode);
|
void updateModeControls(bool serverMode);
|
||||||
@ -126,7 +127,6 @@ private:
|
|||||||
void setIcon();
|
void setIcon();
|
||||||
void setStatus(const QString &status);
|
void setStatus(const QString &status);
|
||||||
void updateFromLogLine(const QString &line);
|
void updateFromLogLine(const QString &line);
|
||||||
[[nodiscard]] QString getIPAddresses() const;
|
|
||||||
void checkConnected(const QString &line);
|
void checkConnected(const QString &line);
|
||||||
void checkFingerprint(const QString &line);
|
void checkFingerprint(const QString &line);
|
||||||
[[nodiscard]] QString getTimeStamp() const;
|
[[nodiscard]] QString getTimeStamp() const;
|
||||||
|
|||||||
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>735</width>
|
<width>781</width>
|
||||||
<height>515</height>
|
<height>483</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -131,31 +131,25 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>40</width>
|
<width>6</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lblIpAddresses">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="lblIpAddresses">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string><html><head/><body><p>The highlighted IP is the one we think you should use. The server listens on all IPs, so the other IPs may work as well.</p></body></html></string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">This computer's IP addresses:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|||||||
Reference in New Issue
Block a user