2021-04-22 14:00:42 +00:00
|
|
|
|
/*
|
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2024-08-07 14:05:18 +00:00
|
|
|
|
* Copyright (C) 2021 Symless Ltd.
|
2021-04-22 14:00:42 +00:00
|
|
|
|
*
|
|
|
|
|
|
* 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 <QHostAddress>
|
2024-07-02 19:07:06 +00:00
|
|
|
|
#include <QMessageBox>
|
2021-04-22 14:00:42 +00:00
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
|
namespace synergy::gui {
|
|
|
|
|
|
|
|
|
|
|
|
ClientConnection::ClientConnection(QWidget &parent, AppConfig &appConfig)
|
|
|
|
|
|
: m_parent(parent),
|
|
|
|
|
|
m_appConfig(appConfig) {}
|
2021-04-22 14:00:42 +00:00
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
void ClientConnection::update(const QString &line) {
|
|
|
|
|
|
if (m_checkConnection && checkMainWindow()) {
|
|
|
|
|
|
if (line.contains("failed to connect to server")) {
|
|
|
|
|
|
m_checkConnection = false;
|
|
|
|
|
|
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
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
}
|
2021-04-22 14:00:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
bool ClientConnection::checkMainWindow() {
|
|
|
|
|
|
bool result = m_parent.isActiveWindow();
|
2021-04-22 14:59:01 +00:00
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
if (m_parent.isMinimized() || m_parent.isHidden()) {
|
|
|
|
|
|
m_parent.showNormal();
|
|
|
|
|
|
m_parent.activateWindow();
|
|
|
|
|
|
result = true;
|
|
|
|
|
|
}
|
2021-04-22 14:59:01 +00:00
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
return result;
|
2021-04-22 14:59:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
QString ClientConnection::getMessage(const QString &line) const {
|
|
|
|
|
|
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
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
if (line.contains("server already has a connected client with our name")) {
|
|
|
|
|
|
message =
|
|
|
|
|
|
QObject::tr("Connection failed.\nYou can’t name 2 computers the same.");
|
|
|
|
|
|
} else {
|
2024-08-07 14:05:18 +00:00
|
|
|
|
QHostAddress address(m_appConfig.serverHostname());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
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.")
|
2024-08-07 14:05:18 +00:00
|
|
|
|
.arg(m_appConfig.serverHostname());
|
2021-04-22 14:00:42 +00:00
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
}
|
2021-04-22 14:00:42 +00:00
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
return message;
|
2021-04-22 14:00:42 +00:00
|
|
|
|
}
|
2021-04-28 12:34:04 +00:00
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
void ClientConnection::showMessage(const QString &message) const {
|
|
|
|
|
|
QMessageBox dialog(&m_parent);
|
|
|
|
|
|
dialog.addButton(QObject::tr("Close"), QMessageBox::RejectRole);
|
|
|
|
|
|
dialog.setText(message);
|
|
|
|
|
|
dialog.exec();
|
2021-04-28 12:34:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
|
void ClientConnection::setCheckConnection(bool checkConnection) {
|
|
|
|
|
|
m_checkConnection = checkConnection;
|
2021-04-28 12:34:04 +00:00
|
|
|
|
}
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
|
|
} // namespace synergy::gui
|