2021-04-22 14:00:42 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2021 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2021-04-22 14:00:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ClientConnection.h"
|
|
|
|
|
|
2025-03-19 21:47:24 +00:00
|
|
|
#include "Messages.h"
|
2025-03-08 15:34:45 +00:00
|
|
|
#include "common/Settings.h"
|
2024-08-08 17:41:59 +00:00
|
|
|
|
2021-04-22 14:00:42 +00:00
|
|
|
#include <QHostAddress>
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <QMessageBox>
|
2021-04-22 14:00:42 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
namespace deskflow::gui {
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
//
|
|
|
|
|
// ClientConnection::Deps
|
|
|
|
|
//
|
|
|
|
|
|
2025-11-28 17:55:57 +00:00
|
|
|
void ClientConnection::Deps::showError(QWidget *parent, deskflow::client::ErrorType error, const QString &address) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-08-08 17:41:59 +00:00
|
|
|
messages::showClientConnectError(parent, error, address);
|
2021-04-22 14:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
//
|
|
|
|
|
// ClientConnection
|
|
|
|
|
//
|
2021-04-22 14:59:01 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ClientConnection::handleLogLine(const QString &logLine)
|
|
|
|
|
{
|
2021-04-22 14:59:01 +00:00
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
if (logLine.contains("failed to connect to server")) {
|
2024-08-09 13:03:48 +00:00
|
|
|
|
|
|
|
|
if (!m_showMessage) {
|
|
|
|
|
qDebug("message already shown, skipping");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
m_showMessage = false;
|
2021-04-22 14:00:42 +00:00
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
// ignore the message if it's about the server refusing by name as
|
|
|
|
|
// this will trigger the server to show an 'add client' dialog.
|
|
|
|
|
if (logLine.contains("server refused client with our name")) {
|
|
|
|
|
qDebug("ignoring client name refused message");
|
|
|
|
|
return;
|
2021-04-22 14:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
showMessage(logLine);
|
|
|
|
|
} else if (logLine.contains("connected to server")) {
|
|
|
|
|
m_showMessage = false;
|
|
|
|
|
}
|
2021-04-22 14:00:42 +00:00
|
|
|
}
|
2021-04-28 12:34:04 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ClientConnection::showMessage(const QString &logLine)
|
|
|
|
|
{
|
2025-11-28 17:55:57 +00:00
|
|
|
using enum deskflow::client::ErrorType;
|
2024-08-08 17:41:59 +00:00
|
|
|
|
2025-11-27 14:14:46 +00:00
|
|
|
if (logLine.isEmpty())
|
|
|
|
|
return;
|
2021-04-28 12:34:04 +00:00
|
|
|
|
2025-03-08 12:24:03 +00:00
|
|
|
const auto address = Settings::value(Settings::Client::RemoteHost).toString();
|
2025-11-27 14:14:46 +00:00
|
|
|
auto error = NoError;
|
2024-08-08 17:41:59 +00:00
|
|
|
|
|
|
|
|
if (logLine.contains("server already has a connected client with our name")) {
|
2025-11-27 14:14:46 +00:00
|
|
|
error = AlreadyConnected;
|
2024-08-08 17:41:59 +00:00
|
|
|
} else if (QHostAddress a(address); a.isNull()) {
|
|
|
|
|
qDebug("ip not detected, showing hostname error");
|
2025-11-27 14:14:46 +00:00
|
|
|
error = HostnameError;
|
2024-08-08 17:41:59 +00:00
|
|
|
} else {
|
|
|
|
|
qDebug("ip detected, showing generic error");
|
2025-11-27 14:14:46 +00:00
|
|
|
error = GenericError;
|
2024-08-08 17:41:59 +00:00
|
|
|
}
|
2025-11-27 14:14:46 +00:00
|
|
|
|
|
|
|
|
if (error == NoError)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-11-27 14:21:43 +00:00
|
|
|
Q_EMIT requestShowError(error, address);
|
2025-11-27 14:14:46 +00:00
|
|
|
Q_EMIT messageShowing();
|
|
|
|
|
m_deps->showError(m_pParent, error, address);
|
2021-04-28 12:34:04 +00:00
|
|
|
}
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow::gui
|