2024-08-07 14:05:18 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
|
* Copyright (C) 2021 Symless Ltd.
|
|
|
|
|
*
|
|
|
|
|
* 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 "ServerConnection.h"
|
|
|
|
|
|
|
|
|
|
#include "ServerMessage.h"
|
2024-08-08 17:41:59 +00:00
|
|
|
#include "messages.h"
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
2024-08-07 17:40:31 +00:00
|
|
|
#include <QPushButton>
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
namespace synergy::gui {
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
//
|
|
|
|
|
// ServerConnection::Deps
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
messages::NewClientPromptResult ServerConnection::Deps::showNewClientPrompt(
|
|
|
|
|
QWidget *parent, const QString &clientName) const {
|
|
|
|
|
return messages::showNewClientPrompt(parent, clientName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// ServerConnection
|
|
|
|
|
//
|
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
ServerConnection::ServerConnection(
|
2024-08-08 17:41:59 +00:00
|
|
|
QWidget *parent, IAppConfig &appConfig, IServerConfig &serverConfig,
|
|
|
|
|
std::shared_ptr<Deps> deps)
|
|
|
|
|
: m_pParent(parent),
|
2024-08-07 14:05:18 +00:00
|
|
|
m_appConfig(appConfig),
|
2024-08-08 17:41:59 +00:00
|
|
|
m_serverConfig(serverConfig),
|
|
|
|
|
m_pDeps(deps) {}
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
void ServerConnection::handleLogLine(const QString &logLine) {
|
|
|
|
|
ServerMessage message(logLine);
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
if (!m_appConfig.useExternalConfig() && message.isNewClientMessage() &&
|
|
|
|
|
!m_ignoredClients.contains(message.getClientName())) {
|
2024-08-08 17:41:59 +00:00
|
|
|
handleNewClient(message.getClientName());
|
2024-08-07 14:05:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
void ServerConnection::handleNewClient(const QString &clientName) {
|
|
|
|
|
using enum messages::NewClientPromptResult;
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
if (m_serverConfig.isFull()) {
|
|
|
|
|
qDebug(
|
|
|
|
|
"server config full, skipping add client prompt for: %s",
|
|
|
|
|
qPrintable(clientName));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_serverConfig.screenExists(clientName)) {
|
|
|
|
|
qDebug(
|
|
|
|
|
"client already added, skipping add client prompt for: %s",
|
|
|
|
|
qPrintable(clientName));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
emit messageShowing();
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
const auto result = m_pDeps->showNewClientPrompt(m_pParent, clientName);
|
|
|
|
|
if (result == Add) {
|
2024-08-07 17:40:31 +00:00
|
|
|
qDebug("accepted dialog, adding client: %s", qPrintable(clientName));
|
2024-08-07 14:05:18 +00:00
|
|
|
emit configureClient(clientName);
|
2024-08-08 17:41:59 +00:00
|
|
|
} else if (result == Ignore) {
|
2024-08-07 17:40:31 +00:00
|
|
|
qDebug("declined dialog, ignoring client: %s", qPrintable(clientName));
|
2024-08-07 14:05:18 +00:00
|
|
|
m_ignoredClients.append(clientName);
|
2024-08-07 17:40:31 +00:00
|
|
|
} else {
|
2024-08-08 17:41:59 +00:00
|
|
|
qFatal("unexpected add client result");
|
2024-08-07 14:05:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace synergy::gui
|