Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+260
View File
@@ -0,0 +1,260 @@
/**
* @RDE_HEADER@
* SAAChooser
* $Id$
* $HeadURL$
* $Author$
*
* Created by Steve Kemayou, ESZS, 2025-10-16
*/
#include <ConnectDialog/connect_dialog_nt.h>
#include <LtsSession/lts_session_manager.h>
#include <LtsWidgets/lts_message_dialog.h>
#include <LtsWidgets/lts_global_wait_dialog.h>
#include <QAbstractItemView>
#include <saa_dialog_model.h>
#include "saa_chooser.h"
#include "ui_saa_chooser.h"
#include <QProcess>
#include <QTimer>
namespace SAAInterfaceAdapterAdler
{
SaaChooser::SaaChooser(QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
, m_ui(new Ui::SaaChooser)
, m_close(false)
, m_selected(false)
, m_pingTimer(new QTimer(this))
, m_logger(getLogger("SaaChooser"))
{
m_ui->setupUi(this);
m_pingTimer->setInterval(15000); // ping saa each 30 sec.
setOnlineHelpFilename(QStringLiteral("Extras-SAA"));
}
SaaChooser::~SaaChooser()
{
delete m_ui;
}
void SaaChooser::retranslate()
{
translate(m_ui, tr("SAA"));
}
bool SaaChooser::init(LtsSession::LtsSession *session)
{
m_session = session;
delete m_model;
m_model = new SaaDialogModel(this);
m_model->initModel(m_session);
m_ui->widget->setModel(m_model);
#ifndef LTS_DEBUG
m_ui->widget->hideColumn(SaaDialogModel::Id);
#endif
m_ui->widget->setSortingEnabled(false);
m_ui->widget->setSortIndicator(-1, Qt::AscendingOrder);
m_ui->widget->resizeSection(SaaDialogModel::Columns::Name, 300);
m_ui->widget->resizeSection(SaaDialogModel::Columns::Connected, 300);
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setText(tr("Start"));
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setIcon(QIcon(QStringLiteral("icon:saa_remote_desktop.svg")));
m_buttonBox->connectButton(LtsWidgets::DialogButton::Show, this, &SaaChooser::slotSelectSaa);
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
this, &SaaChooser::enaDisa);
enaDisa();
connect(m_pingTimer, &QTimer::timeout, this, &SaaChooser::startPingSaa);
startPingSaa();
m_pingTimer->start(); // timer to pin saa each .. sec. currently 30sec.
return true;
}
QString SaaChooser::rdesktopCodeToString(RdesktopCodes code)
{
switch(code)
{
case RdesktopCodes::FailedToConnect:
return tr("Failed to connect to remote host");
break;
case RdesktopCodes::ConnectionRefused:
return tr("Connection refused by remote host");
break;
case RdesktopCodes::UnableToConnect:
return tr("Unable to connect to remote host");
break;
case RdesktopCodes::DnsError:
return tr("DNS resolution failed to remote host");
break;
case RdesktopCodes::ConnectionTimeOut:
return tr("Connection timed out");
break;
case RdesktopCodes::NetworkError:
return tr("Remote network error");
case RdesktopCodes::AuthenticationError:
return tr("SAA Authentification failed");
case RdesktopCodes::Unknown:
default:
return tr("Unknown rdesktop error");
break;
}
}
/*!
* \brief SaaChooser::getRdesktopInterpretation
* Protocol Reason Codes
* \param code
* \return
*/
SaaChooser::RdesktopCodes SaaChooser::getRdesktopInterpretation(int code) const
{
DEBUG_LOG(m_logger)<<">> getRdesktopInterpretation: rdesktop error code: "<<code;
switch (code)
{
case 0:
case 62: // on client exit
return RdesktopCodes::Normal;
case 76:
return RdesktopCodes::FailedToConnect;
case 77:
return RdesktopCodes::ConnectionTimeOut;
case 78:
return RdesktopCodes::ConnectionRefused;
case 79:
return RdesktopCodes::NetworkError;
case 80:
case 81:
return RdesktopCodes::DnsError;
case 82:
return RdesktopCodes::AuthenticationError;
default:
return RdesktopCodes::Unknown;
}
}
bool SaaChooser::normalExit(int code) const
{
DEBUG_LOG(m_logger)<<">> process finished!! exitCode: "<<code;
return getRdesktopInterpretation(code) == RdesktopCodes::Normal;
}
void SaaChooser::startPingSaa()
{
if (!m_model)
return;
m_model->pingAllSaa();
}
void SaaChooser::slotSelectSaa()
{
const QModelIndex curIdx = m_ui->widget->currentIndex();
if (!curIdx.isValid())
return;
const AssetManagement::Asset asset = m_model->getRowData(curIdx.row());
const SAAUtils::AsmAssetProps assetProps(QString::fromStdString(asset.properties()));
QPointer<QProcess> process = new QProcess(this);
///------------- QProcess::finished
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, [this, process, asset](int code, QProcess::ExitStatus)
{
if (process != qobject_cast<QProcess * >(sender()))
return;
// set connected to false and update view
if (m_model)
m_model->saaConnected(asset.id(), false);
QString errMsg = QString::fromUtf8(process->readAllStandardError());
if (!normalExit(code))
new LtsWidgets::LtsMessageDialogNew(this, rdesktopCodeToString(getRdesktopInterpretation(code)));
if (!process.isNull())
process->deleteLater();
});
//------------- QProcess::readyReadStandardError
connect(process, &QProcess::readyReadStandardError,
this, [this, process]()
{
if (process != qobject_cast<QProcess *>(sender()) || process.isNull())
return;
ERROR_LOG(m_logger) << ">> SAA Remote desktop: error:" << process->readAllStandardError();
});
//------------- QProcess::readyReadStandardOutput
connect(process, &QProcess::readyReadStandardOutput,
this, [this, process]()
{
if (process != qobject_cast<QProcess *>(sender()) || process.isNull())
return;
INFO_LOG(m_logger) << ">> SAA Remote desktop: " << process->readAllStandardOutput();
});
///------------- QProcess::errorOccurred
connect(process, &QProcess::errorOccurred,
this, [this, process, asset](QProcess::ProcessError )
{
if (process != qobject_cast<QProcess *>(sender()) || process.isNull())
return;
if (process->state() != QProcess::Running)
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
WARNING_LOG(m_logger)<<">> saa with id ("<<asset.id()<<")"<<" started ";
//new LtsWidgets::LtsMessageDialogNew(this, tr("SAA Remote desktop process error: %1.").arg(process->errorString()));
});
///------------- QProcess::started
connect(process, &QProcess::started,
this, [this, asset]()
{
WARNING_LOG(m_logger)<<">> saa with id ("<<asset.id()<<")"<<" started ";
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
// set connected to true and update view
if (m_model)
m_model->saaConnected(asset.id(), true);
});
const QString saaIp = QStringLiteral("%1:%2").arg(assetProps.host).arg(assetProps.port);
QStringList args;
const QString program = QStringLiteral("rdesktop");
args <<QStringLiteral("-g")<<QStringLiteral(" 1920x1100")
<< QStringLiteral("-u")<< assetProps.userName
<< QStringLiteral("-p")<< assetProps.password
<< saaIp;
DEBUG_LOG(m_logger)<<">> Process rdesktop: "<<args.join(QStringLiteral(" "));
process->start(program, args);
if (!process->waitForStarted())
{
ERROR_LOG(m_logger) << "Could not start saa process "<<process->program() <<" " << process->arguments().join(QStringLiteral(" "));
process->deleteLater();
}
}
void SaaChooser::enaDisa()
{
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setEnabled(false);
const QModelIndex curIdx = m_ui->widget->currentIndex();
if (!curIdx.isValid())
return;
const AssetManagement::Asset &asset = m_model->getRowData(curIdx.row());
SAAUtils::AsmAssetProps assetProps(QString::fromStdString(asset.properties()));
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setEnabled(assetProps.hasCredential());
}
void SaaChooser::tableColumnOrganiserSetting()
{
//LtsColumnOrganiser
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
}
} // namespace SAAInterfaceAdapterAdler