deskflow/src/gui/src/ClientConnection.cpp

98 lines
2.8 KiB
C++
Raw Normal View History

2021-04-22 14:00:42 +00:00
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ClientConnection.h"
#include "MainWindow.h"
#include <QMessageBox>
#include <QHostAddress>
ClientConnection::ClientConnection(MainWindow& parent) :
m_parent(parent)
{
}
void ClientConnection::update(const QString& line)
2021-04-22 14:00:42 +00:00
{
if (m_checkConnection && checkMainWindow())
2021-04-22 14:00:42 +00:00
{
if (line.contains("failed to connect to server"))
{
m_checkConnection = false;
SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 (#7008) * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Fix connection without brackets *Fix config screen bug * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Update changelog * SYNERGY-970 Mac client listens on ipv4 only but attempts to connect on ipv6 #6964 *Add logging in case of several IP of hostname * Synergy 970 synergy1. user is not able to connect to server using ipv6 without wrapping ip in square quotes *Update changelog * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Fix Sonar warnings * SUNERGY-885-Mac client listens on ipv4 only but attempts to connect on ipv6 *Update Changelog * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix include * Sunergy-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix sonar warnings * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Add loggic to connect to first from reachable server addresses * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix code smells * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix build * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix memory leak * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Added logic for temporary ipv6 filtering from connect * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Temporary disable ipv6 parsing and resolving tests Co-authored-by: Andrii Batyiev <andrii-external@symless.com>
2021-05-20 16:59:05 +00:00
if (!line.contains("server refused client with our name") &&
!line.contains("Trying next address"))
{
showMessage(getMessage(line));
}
}
else if (line.contains("connected to server"))
{
m_checkConnection = false;
}
2021-04-22 14:00:42 +00:00
}
}
bool ClientConnection::checkMainWindow()
{
bool result = m_parent.isActiveWindow();
if (m_parent.isMinimized() || m_parent.isHidden())
{
m_parent.showNormal();
m_parent.activateWindow();
result = true;
}
return result;
}
QString ClientConnection::getMessage(const QString& line) const
2021-04-22 14:00:42 +00:00
{
2021-05-14 11:04:20 +00:00
QString message(QObject::tr("Connection failed.\nCheck the IP address on the server, your TLS and firewall settings."));
2021-04-22 14:00:42 +00:00
if (line.contains("server already has a connected client with our name"))
2021-04-22 14:00:42 +00:00
{
2021-05-14 11:04:20 +00:00
message = QObject::tr("Connection failed.\nYou can’t name 2 computers the same.");
}
else
{
QHostAddress address(m_parent.appConfig().getServerHostname());
if (address.isNull())
{
message = QObject::tr("We can’t connect to the server \"%1\" try to connect using the server IP address and check your firewall settings.")
.arg(m_parent.appConfig().getServerHostname());
}
2021-04-22 14:00:42 +00:00
}
return message;
}
void ClientConnection::showMessage(const QString& message) const
{
QMessageBox dialog(&m_parent);
dialog.addButton(QObject::tr("Close"), QMessageBox::RejectRole);
dialog.setText(message);
dialog.exec();
}
void ClientConnection::setCheckConnection(bool checkConnection)
{
m_checkConnection = checkConnection;
}