feat: improve connections status bar info
This commit is contained in:
@ -320,6 +320,7 @@ void MainWindow::connectSlots()
|
||||
#endif
|
||||
|
||||
connect(&m_serverConnection, &ServerConnection::configureClient, this, &MainWindow::serverConnectionConfigureClient);
|
||||
connect(&m_serverConnection, &ServerConnection::clientsChanged, this, &MainWindow::serverClientsChanged);
|
||||
|
||||
connect(&m_serverConnection, &ServerConnection::messageShowing, this, &MainWindow::showAndActivate);
|
||||
connect(&m_clientConnection, &ClientConnection::messageShowing, this, &MainWindow::showAndActivate);
|
||||
@ -873,6 +874,7 @@ void MainWindow::updateStatus()
|
||||
{
|
||||
const auto connection = m_coreProcess.connectionState();
|
||||
const auto process = m_coreProcess.processState();
|
||||
const bool isServer = (m_coreProcess.mode() == CoreMode::Server);
|
||||
|
||||
updateSecurityIcon(false);
|
||||
switch (process) {
|
||||
@ -899,7 +901,7 @@ void MainWindow::updateStatus()
|
||||
using enum CoreConnectionState;
|
||||
|
||||
case Listening: {
|
||||
if (m_coreProcess.mode() == CoreMode::Server) {
|
||||
if (isServer) {
|
||||
updateSecurityIcon(true);
|
||||
setStatus(tr("%1 is waiting for clients").arg(kAppName));
|
||||
}
|
||||
@ -913,7 +915,10 @@ void MainWindow::updateStatus()
|
||||
|
||||
case Connected: {
|
||||
updateSecurityIcon(true);
|
||||
setStatus(tr("%1 is connected").arg(kAppName));
|
||||
if (!isServer) {
|
||||
setStatus(tr("%1 is connected as client of %2")
|
||||
.arg(kAppName, Settings::value(Settings::Client::RemoteHost).toString()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1139,6 +1144,37 @@ bool MainWindow::regenerateLocalFingerprints()
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::serverClientsChanged(const QStringList &clients)
|
||||
{
|
||||
if (m_coreProcess.mode() != CoreMode::Server || !m_coreProcess.isStarted())
|
||||
return;
|
||||
|
||||
switch (clients.size()) {
|
||||
case 0:
|
||||
setStatus(tr("%1 is waiting for clients").arg(kAppName));
|
||||
ui->statusBar->setToolTip("");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
setStatus(tr("%1 is connected to a client: %2").arg(kAppName, clients.first()));
|
||||
ui->statusBar->setToolTip("");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
setStatus(
|
||||
tr("%1 is connected, with %2 clients: %3").arg(kAppName, QString::number(clients.size()), clients.join(", "))
|
||||
);
|
||||
ui->statusBar->setToolTip(tr("Clients:\n %1").arg(clients.join("\n")));
|
||||
break;
|
||||
default:
|
||||
setStatus(tr("%1 is connected, with %n client(s)", "", clients.size()).arg(kAppName));
|
||||
ui->statusBar->setToolTip(tr("Clients:\n %1").arg(clients.join("\n")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::daemonIpcClientConnectionFailed()
|
||||
{
|
||||
if (deskflow::gui::messages::showDaemonOffline(this)) {
|
||||
|
||||
@ -159,6 +159,8 @@ private:
|
||||
// Returns true if successful
|
||||
bool regenerateLocalFingerprints();
|
||||
|
||||
void serverClientsChanged(const QStringList &clients);
|
||||
|
||||
inline static const auto m_guiSocketName = QStringLiteral("deskflow-gui");
|
||||
inline static const auto m_nameRegEx = QRegularExpression(QStringLiteral("^[\\w\\-_\\.]{0,255}$"));
|
||||
|
||||
|
||||
@ -42,6 +42,19 @@ ServerConnection::ServerConnection(QWidget *parent, IServerConfig &serverConfig,
|
||||
void ServerConnection::handleLogLine(const QString &logLine)
|
||||
{
|
||||
ServerMessage message(logLine);
|
||||
const auto clientName = message.getClientName();
|
||||
|
||||
if (message.isDisconnectedMessage()) {
|
||||
m_connectedClients.remove(clientName);
|
||||
Q_EMIT clientsChanged(connectedClients());
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.isConnectedMessage()) {
|
||||
m_connectedClients.insert(clientName);
|
||||
Q_EMIT clientsChanged(connectedClients());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!message.isNewClientMessage()) {
|
||||
return;
|
||||
@ -62,20 +75,18 @@ void ServerConnection::handleLogLine(const QString &logLine)
|
||||
return;
|
||||
}
|
||||
|
||||
if (const auto &client = message.getClientName(); m_receivedClients.contains(client)) {
|
||||
qDebug("already got request, skipping new client prompt for: %s", qPrintable(client));
|
||||
if (m_connectedClients.contains(clientName)) {
|
||||
qDebug("already got request, skipping new client prompt for: %s", qPrintable(clientName));
|
||||
return;
|
||||
}
|
||||
|
||||
handleNewClient(message.getClientName());
|
||||
handleNewClient(clientName);
|
||||
}
|
||||
|
||||
void ServerConnection::handleNewClient(const QString &clientName)
|
||||
{
|
||||
using enum messages::NewClientPromptResult;
|
||||
|
||||
m_receivedClients.append(clientName);
|
||||
|
||||
if (m_serverConfig.isFull()) {
|
||||
qDebug("server config full, skipping new client prompt for: %s", qPrintable(clientName));
|
||||
return;
|
||||
@ -102,6 +113,14 @@ void ServerConnection::handleNewClient(const QString &clientName)
|
||||
} else {
|
||||
qFatal("unexpected add client result");
|
||||
}
|
||||
|
||||
m_connectedClients.insert(clientName);
|
||||
Q_EMIT clientsChanged(connectedClients());
|
||||
}
|
||||
|
||||
QStringList ServerConnection::connectedClients() const
|
||||
{
|
||||
return QStringList(m_connectedClients.begin(), m_connectedClients.end());
|
||||
}
|
||||
|
||||
} // namespace deskflow::gui
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "gui/Messages.h"
|
||||
#include "gui/config/IServerConfig.h"
|
||||
@ -35,14 +34,16 @@ public:
|
||||
Q_SIGNALS:
|
||||
void messageShowing();
|
||||
void configureClient(const QString &clientName);
|
||||
void clientsChanged(const QStringList &clients);
|
||||
|
||||
private:
|
||||
void handleNewClient(const QString &clientName);
|
||||
QStringList connectedClients() const;
|
||||
|
||||
QWidget *m_pParent;
|
||||
IServerConfig &m_serverConfig;
|
||||
std::shared_ptr<Deps> m_pDeps;
|
||||
QStringList m_receivedClients;
|
||||
QSet<QString> m_connectedClients;
|
||||
bool m_messageShowing = false;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user