Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+151
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Notifcation plugin for TAB connection states
|
||||
* $Id: tab_notification_gui_plugin.cpp 65000 2025-08-08 05:22:36Z fritsche_h $
|
||||
* $HeadURL: svn://192.168.133.21/TDS/branches/product/release_candidates/guez/3dws_rc/Lts/Plugins/TrainingAreaBase/Gui/Notification/tab_notification_gui_plugin.cpp $
|
||||
* $Author: fritsche_h $
|
||||
* Created by Philipp Dassow, SLST, 2017-09-19
|
||||
*/
|
||||
|
||||
|
||||
#include "tab_notification_gui_plugin.h"
|
||||
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsNotification/lts_notification.h>
|
||||
#include <QCoreApplication>
|
||||
#include <TrainingAreaBase/logger.h>
|
||||
|
||||
namespace TrainingAreaBase
|
||||
{
|
||||
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
|
||||
{
|
||||
return std::make_shared<InterfaceImpl>(session);
|
||||
}
|
||||
|
||||
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
|
||||
: GuiPluginBase::Interface(session, getLogger("Notification"))
|
||||
, m_dtc(nullptr)
|
||||
, m_noti(nullptr)
|
||||
{}
|
||||
|
||||
InterfaceImpl::~InterfaceImpl()
|
||||
{
|
||||
delete m_noti;
|
||||
}
|
||||
|
||||
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
|
||||
{
|
||||
QVector<LtsWidgets::PluginData> ret;
|
||||
|
||||
{
|
||||
LtsWidgets::PluginData plData;
|
||||
plData.menuGroup = menuGroup();
|
||||
plData.createInstant = LtsWidgets::CreateInstantType::CreateInstantAndDiscardAction;
|
||||
plData.directFunc = [this](const LtsWidgets::PluginData &)
|
||||
{
|
||||
if (m_noti != nullptr)
|
||||
return;
|
||||
|
||||
m_noti = m_session->createNotification(QStringLiteral("TabConnections"));
|
||||
setDefaultToolTip();
|
||||
|
||||
connect(m_dtc.get(), &TrainingAreaBase::Interface::Dtc::connectionsChanged, this, &InterfaceImpl::onConnections);
|
||||
|
||||
auto cb = [this](const Connections &data) { onConnections(data, DataModification::eAdded); };
|
||||
m_dtc->waitForHistoricalDataConnections(3000);
|
||||
m_dtc->connectionss(cb);
|
||||
};
|
||||
ret.append(plData);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool InterfaceImpl::fetchInterfaces()
|
||||
{
|
||||
if (!m_session->getDtc<TrainingAreaBase::DataInterface>(m_dtc))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InterfaceImpl::clearInterfaces()
|
||||
{
|
||||
m_dtc = nullptr;
|
||||
}
|
||||
|
||||
void InterfaceImpl::onConnections(const Connections &data, DataModification modType)
|
||||
{
|
||||
switch (modType)
|
||||
{
|
||||
case DataModification::eAdded:
|
||||
case DataModification::eModified:
|
||||
{
|
||||
QStringList sl;
|
||||
sl.reserve(data.connections().size());
|
||||
|
||||
bool allConnected = true;
|
||||
InterfaceImpl::State state = InterfaceImpl::State::Red;
|
||||
|
||||
if (data.connections().size() == 0)
|
||||
allConnected = false;
|
||||
else
|
||||
{
|
||||
for (auto it = data.connections().begin(); it != data.connections().end(); ++it)
|
||||
{
|
||||
const TrainingAreaBase::ConnectionState &connection = *it;
|
||||
const QString name = QCoreApplication::translate("dds", connection.name().c_str());
|
||||
if (connection.state())
|
||||
{
|
||||
state = InterfaceImpl::State::Yellow;
|
||||
sl += tr("%1 connected").arg(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
allConnected = false;
|
||||
sl += tr("%1 disconnected").arg(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allConnected)
|
||||
state = InterfaceImpl::State::Green;
|
||||
|
||||
if (sl.size())
|
||||
{
|
||||
setIcon(state);
|
||||
m_noti->setToolTip(sl.join(QLatin1Char('\n')));
|
||||
}
|
||||
else
|
||||
setDefaultToolTip();
|
||||
break;
|
||||
}
|
||||
case DataModification::eRemoved:
|
||||
setDefaultToolTip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InterfaceImpl::setDefaultToolTip()
|
||||
{
|
||||
m_noti->setToolTip(tr("Exercise has no data connections"));
|
||||
setIcon(InterfaceImpl::State::Red);
|
||||
}
|
||||
|
||||
void InterfaceImpl::setIcon(InterfaceImpl::State state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case InterfaceImpl::State::Green:
|
||||
m_noti->setIcon(QIcon(QStringLiteral("icon:/network-wireless-green.svg")));
|
||||
break;
|
||||
case InterfaceImpl::State::Yellow:
|
||||
m_noti->setIcon(QIcon(QStringLiteral("icon:/network-wireless-yellow.svg")));
|
||||
break;
|
||||
case InterfaceImpl::State::Red:
|
||||
m_noti->setIcon(QIcon(QStringLiteral("icon:/network-wireless-red.svg")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace TrainingAreaBase
|
||||
Reference in new issue
Block a user