SYNERGY-799 Restore lost functionality

This commit is contained in:
Serhii Hadzhilov 2021-04-16 14:41:36 +03:00
parent 8c9a261ed5
commit 32bb5cbd7f
2 changed files with 39 additions and 0 deletions

View file

@ -130,6 +130,7 @@ MainWindow::MainWindow (AppConfig& appConfig,
m_pLabelScreenName->setText(appConfig.screenName()); m_pLabelScreenName->setText(appConfig.screenName());
connect(m_AppConfig, SIGNAL(screenNameChanged()), this, SLOT(updateScreenName())); connect(m_AppConfig, SIGNAL(screenNameChanged()), this, SLOT(updateScreenName()));
m_pLabelIpAddresses->setText(getIPAddresses());
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
// ipc must always be enabled, so that we can disable command when switching to desktop mode. // ipc must always be enabled, so that we can disable command when switching to desktop mode.
@ -1038,6 +1039,38 @@ void MainWindow::setVisible(bool visible)
#endif #endif
} }
QString MainWindow::getIPAddresses()
{
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.isLinkLocal()) {
// usually 192.168.x.x is a useful ip for the user, so indicate
// this by making it bold.
if (!hinted && address.isInSubnet(localnet)) {
QString format = "<b>%1</b>";
result.append(format.arg(address.toString()));
hinted = true;
}
else {
result.append(address.toString());
}
}
}
if (result.isEmpty()) {
result.append(tr("Unknown"));
}
return result.join(", ");
}
void MainWindow::changeEvent(QEvent* event) void MainWindow::changeEvent(QEvent* event)
{ {
if (event != 0) if (event != 0)
@ -1066,6 +1099,11 @@ void MainWindow::changeEvent(QEvent* event)
void MainWindow::addZeroconfServer(const QString name) void MainWindow::addZeroconfServer(const QString name)
{ {
// don't add yourself to the server list.
if (getIPAddresses().contains(name)) {
return;
}
if (m_pComboServerList->findText(name) == -1) { if (m_pComboServerList->findText(name) == -1) {
m_pComboServerList->addItem(name); m_pComboServerList->addItem(name);
} }

View file

@ -182,6 +182,7 @@ public slots:
void setStatus(const QString& status); void setStatus(const QString& status);
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors); void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
void updateFromLogLine(const QString& line); void updateFromLogLine(const QString& line);
QString getIPAddresses();
void stopService(); void stopService();
void stopDesktop(); void stopDesktop();
void changeEvent(QEvent* event); void changeEvent(QEvent* event);