2024-08-07 14:05:18 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2024-08-07 14:05:18 +00:00
|
|
|
* 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-10 23:58:24 +00:00
|
|
|
#include "gui/config/ServerConfigDialogState.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
|
|
|
|
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
|
|
|
//
|
|
|
|
|
// ServerConnection::Deps
|
|
|
|
|
//
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
messages::NewClientPromptResult
|
|
|
|
|
ServerConnection::Deps::showNewClientPrompt(QWidget *parent, const QString &clientName) const
|
|
|
|
|
{
|
2024-08-08 17:41:59 +00:00
|
|
|
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,
|
2024-10-17 18:04:35 +00:00
|
|
|
const config::ServerConfigDialogState &serverConfigDialogState, std::shared_ptr<Deps> deps
|
|
|
|
|
)
|
2024-08-08 17:41:59 +00:00
|
|
|
: 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),
|
2024-08-10 23:58:24 +00:00
|
|
|
m_serverConfigDialogState(serverConfigDialogState),
|
2024-10-17 18:04:35 +00:00
|
|
|
m_pDeps(deps)
|
|
|
|
|
{
|
|
|
|
|
}
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ServerConnection::handleLogLine(const QString &logLine)
|
|
|
|
|
{
|
2024-08-08 17:41:59 +00:00
|
|
|
ServerMessage message(logLine);
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
if (!message.isNewClientMessage()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-10 23:58:24 +00:00
|
|
|
if (m_messageShowing) {
|
|
|
|
|
qDebug("new client message already shown, skipping for now");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_serverConfigDialogState.isVisible()) {
|
|
|
|
|
qDebug("server config dialog visible, skipping new client prompt");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
if (m_appConfig.useExternalConfig()) {
|
|
|
|
|
qDebug("external config enabled, skipping new client prompt");
|
|
|
|
|
return;
|
2024-08-07 14:05:18 +00:00
|
|
|
}
|
2024-08-09 18:20:10 +00:00
|
|
|
|
|
|
|
|
const auto client = message.getClientName();
|
|
|
|
|
|
|
|
|
|
if (m_receivedClients.contains(client)) {
|
2024-10-17 18:04:35 +00:00
|
|
|
qDebug("already got request, skipping new client prompt for: %s", qPrintable(client));
|
2024-08-09 18:20:10 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleNewClient(message.getClientName());
|
2024-08-07 14:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ServerConnection::handleNewClient(const QString &clientName)
|
|
|
|
|
{
|
2024-08-08 17:41:59 +00:00
|
|
|
using enum messages::NewClientPromptResult;
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
m_receivedClients.append(clientName);
|
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
if (m_serverConfig.isFull()) {
|
2024-10-17 18:04:35 +00:00
|
|
|
qDebug("server config full, skipping new client prompt for: %s", qPrintable(clientName));
|
2024-08-07 14:05:18 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_serverConfig.screenExists(clientName)) {
|
2024-10-17 18:04:35 +00:00
|
|
|
qDebug("client already added, skipping new client prompt for: %s", qPrintable(clientName));
|
2024-08-07 14:05:18 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 04:08:10 +00:00
|
|
|
Q_EMIT messageShowing();
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
m_messageShowing = true;
|
2024-08-08 17:41:59 +00:00
|
|
|
const auto result = m_pDeps->showNewClientPrompt(m_pParent, clientName);
|
2024-08-09 18:20:10 +00:00
|
|
|
m_messageShowing = false;
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
if (result == Add) {
|
2024-08-07 17:40:31 +00:00
|
|
|
qDebug("accepted dialog, adding client: %s", qPrintable(clientName));
|
2024-10-21 04:08:10 +00:00
|
|
|
Q_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));
|
|
|
|
|
} else {
|
2024-08-08 17:41:59 +00:00
|
|
|
qFatal("unexpected add client result");
|
2024-08-07 14:05:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow::gui
|