feat: improve connections status bar info
This commit is contained in:
parent
0d6837a948
commit
a73e8df01e
4 changed files with 67 additions and 9 deletions
|
|
@ -320,6 +320,7 @@ void MainWindow::connectSlots()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect(&m_serverConnection, &ServerConnection::configureClient, this, &MainWindow::serverConnectionConfigureClient);
|
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_serverConnection, &ServerConnection::messageShowing, this, &MainWindow::showAndActivate);
|
||||||
connect(&m_clientConnection, &ClientConnection::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 connection = m_coreProcess.connectionState();
|
||||||
const auto process = m_coreProcess.processState();
|
const auto process = m_coreProcess.processState();
|
||||||
|
const bool isServer = (m_coreProcess.mode() == CoreMode::Server);
|
||||||
|
|
||||||
updateSecurityIcon(false);
|
updateSecurityIcon(false);
|
||||||
switch (process) {
|
switch (process) {
|
||||||
|
|
@ -899,7 +901,7 @@ void MainWindow::updateStatus()
|
||||||
using enum CoreConnectionState;
|
using enum CoreConnectionState;
|
||||||
|
|
||||||
case Listening: {
|
case Listening: {
|
||||||
if (m_coreProcess.mode() == CoreMode::Server) {
|
if (isServer) {
|
||||||
updateSecurityIcon(true);
|
updateSecurityIcon(true);
|
||||||
setStatus(tr("%1 is waiting for clients").arg(kAppName));
|
setStatus(tr("%1 is waiting for clients").arg(kAppName));
|
||||||
}
|
}
|
||||||
|
|
@ -913,7 +915,10 @@ void MainWindow::updateStatus()
|
||||||
|
|
||||||
case Connected: {
|
case Connected: {
|
||||||
updateSecurityIcon(true);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1139,6 +1144,37 @@ bool MainWindow::regenerateLocalFingerprints()
|
||||||
return true;
|
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()
|
void MainWindow::daemonIpcClientConnectionFailed()
|
||||||
{
|
{
|
||||||
if (deskflow::gui::messages::showDaemonOffline(this)) {
|
if (deskflow::gui::messages::showDaemonOffline(this)) {
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,8 @@ private:
|
||||||
// Returns true if successful
|
// Returns true if successful
|
||||||
bool regenerateLocalFingerprints();
|
bool regenerateLocalFingerprints();
|
||||||
|
|
||||||
|
void serverClientsChanged(const QStringList &clients);
|
||||||
|
|
||||||
inline static const auto m_guiSocketName = QStringLiteral("deskflow-gui");
|
inline static const auto m_guiSocketName = QStringLiteral("deskflow-gui");
|
||||||
inline static const auto m_nameRegEx = QRegularExpression(QStringLiteral("^[\\w\\-_\\.]{0,255}$"));
|
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)
|
void ServerConnection::handleLogLine(const QString &logLine)
|
||||||
{
|
{
|
||||||
ServerMessage message(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()) {
|
if (!message.isNewClientMessage()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -62,20 +75,18 @@ void ServerConnection::handleLogLine(const QString &logLine)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto &client = message.getClientName(); m_receivedClients.contains(client)) {
|
if (m_connectedClients.contains(clientName)) {
|
||||||
qDebug("already got request, skipping new client prompt for: %s", qPrintable(client));
|
qDebug("already got request, skipping new client prompt for: %s", qPrintable(clientName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNewClient(message.getClientName());
|
handleNewClient(clientName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConnection::handleNewClient(const QString &clientName)
|
void ServerConnection::handleNewClient(const QString &clientName)
|
||||||
{
|
{
|
||||||
using enum messages::NewClientPromptResult;
|
using enum messages::NewClientPromptResult;
|
||||||
|
|
||||||
m_receivedClients.append(clientName);
|
|
||||||
|
|
||||||
if (m_serverConfig.isFull()) {
|
if (m_serverConfig.isFull()) {
|
||||||
qDebug("server config full, skipping new client prompt for: %s", qPrintable(clientName));
|
qDebug("server config full, skipping new client prompt for: %s", qPrintable(clientName));
|
||||||
return;
|
return;
|
||||||
|
|
@ -102,6 +113,14 @@ void ServerConnection::handleNewClient(const QString &clientName)
|
||||||
} else {
|
} else {
|
||||||
qFatal("unexpected add client result");
|
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
|
} // namespace deskflow::gui
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include "gui/Messages.h"
|
#include "gui/Messages.h"
|
||||||
#include "gui/config/IServerConfig.h"
|
#include "gui/config/IServerConfig.h"
|
||||||
|
|
@ -35,14 +34,16 @@ public:
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void messageShowing();
|
void messageShowing();
|
||||||
void configureClient(const QString &clientName);
|
void configureClient(const QString &clientName);
|
||||||
|
void clientsChanged(const QStringList &clients);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleNewClient(const QString &clientName);
|
void handleNewClient(const QString &clientName);
|
||||||
|
QStringList connectedClients() const;
|
||||||
|
|
||||||
QWidget *m_pParent;
|
QWidget *m_pParent;
|
||||||
IServerConfig &m_serverConfig;
|
IServerConfig &m_serverConfig;
|
||||||
std::shared_ptr<Deps> m_pDeps;
|
std::shared_ptr<Deps> m_pDeps;
|
||||||
QStringList m_receivedClients;
|
QSet<QString> m_connectedClients;
|
||||||
bool m_messageShowing = false;
|
bool m_messageShowing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue