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)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-22 14:59:01 +00:00
|
|
|
|
void ClientConnection::update(const QString& line)
|
2021-04-22 14:00:42 +00:00
|
|
|
|
{
|
2021-04-28 12:34:04 +00:00
|
|
|
|
if (m_checkConnection && checkMainWindow())
|
2021-04-22 14:00:42 +00:00
|
|
|
|
{
|
2021-04-28 12:34:04 +00:00
|
|
|
|
if (line.contains("failed to connect to server"))
|
|
|
|
|
|
{
|
|
|
|
|
|
m_checkConnection = false;
|
2021-05-20 16:59:05 +00:00
|
|
|
|
if (!line.contains("server refused client with our name") &&
|
|
|
|
|
|
!line.contains("Trying next address"))
|
2021-04-28 12:34:04 +00:00
|
|
|
|
{
|
2021-05-13 11:44:28 +00:00
|
|
|
|
showMessage(getMessage(line));
|
2021-04-28 12:34:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (line.contains("connected to server"))
|
|
|
|
|
|
{
|
|
|
|
|
|
m_checkConnection = false;
|
|
|
|
|
|
}
|
2021-04-22 14:00:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-22 14:59:01 +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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-13 11:44:28 +00:00
|
|
|
|
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
|
|
|
|
|
2021-05-13 11:44:28 +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.");
|
2021-05-13 11:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2021-04-28 12:34:04 +00:00
|
|
|
|
|
2021-05-13 11:44:28 +00:00
|
|
|
|
void ClientConnection::showMessage(const QString& message) const
|
2021-04-28 12:34:04 +00:00
|
|
|
|
{
|
2021-05-13 11:44:28 +00:00
|
|
|
|
QMessageBox dialog(&m_parent);
|
|
|
|
|
|
dialog.addButton(QObject::tr("Close"), QMessageBox::RejectRole);
|
|
|
|
|
|
dialog.setText(message);
|
|
|
|
|
|
dialog.exec();
|
2021-04-28 12:34:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ClientConnection::setCheckConnection(bool checkConnection)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_checkConnection = checkConnection;
|
|
|
|
|
|
}
|