169 lines
4.5 KiB
C++
Executable File
169 lines
4.5 KiB
C++
Executable File
#include "scm_dialog.h"
|
|
#include "scm_dialog_group.h"
|
|
#include "ui_scm_dialog_group.h"
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
namespace ServiceManagement
|
|
{
|
|
GroupWidget::GroupWidget(const Core::ServiceGroupType &groupType, int server, int exercise,
|
|
int32_t replayPartitionId,
|
|
const QString &groupName /* TODO: groupName not needed */, long long timestamp,
|
|
const QVector<int> &neededServices, QWidget *parent)
|
|
: QWidget(parent)
|
|
, m_ui(new Ui::GroupWidget)
|
|
, m_status(ServiceWidget::UNKNOWN)
|
|
, m_server(server)
|
|
, m_exercise(exercise)
|
|
, m_groupName(groupName)
|
|
, m_replayPartitionId(replayPartitionId)
|
|
, m_neededServices(neededServices)
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
connect(m_ui->pbRestart, &QToolButton::clicked, this, &GroupWidget::slotRestartGroup);
|
|
connect(m_ui->pbStart, &QToolButton::clicked, this, &GroupWidget::slotStartGroup);
|
|
connect(m_ui->pbStop, &QToolButton::clicked, this, &GroupWidget::slotStopGroup);
|
|
|
|
setType(groupType);
|
|
setServer(server);
|
|
setExercise(exercise);
|
|
setTimestamp(timestamp);
|
|
|
|
if (getStatus() != ServiceWidget::STOPPED) // when not stopped (but unknown), then set as STARTED
|
|
setStatus(ServiceWidget::STARTED);
|
|
}
|
|
|
|
|
|
GroupWidget::~GroupWidget()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
void GroupWidget::addService(ServiceWidget *service)
|
|
{
|
|
m_ui->lbNoServices->hide(); // min. 1 service available
|
|
|
|
//qWarning() << "GroupWidget::addService: ";
|
|
|
|
if (m_neededServices.contains(service->id())) // does this group need this service?
|
|
{
|
|
//qWarning() << "GroupWidget::addService: service needed";
|
|
|
|
if (!findChild<ServiceWidget *>(service->objectName())) // and the service was not found?
|
|
{
|
|
//qWarning() << "GroupWidget::addService: service currently not found, adding it";
|
|
|
|
m_ui->servicesLayout->addWidget(service);
|
|
checkStatus();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//qWarning() << "GroupWidget::addService: I do not need" << service->id() << ", i need" << m_neededServices;
|
|
}
|
|
}
|
|
|
|
|
|
void GroupWidget::checkStatus()
|
|
{
|
|
// get all service widgets from THIS widget and check our status by their status
|
|
|
|
m_status = ServiceWidget::UNKNOWN; // reset status
|
|
|
|
|
|
const QList<ServiceWidget *> serviceList = findChildren<ServiceWidget *>();
|
|
|
|
if (serviceList.isEmpty())
|
|
m_ui->lbNoServices->show(); // no services left (after deleting)
|
|
|
|
for (const ServiceWidget *serviceWidget : serviceList)
|
|
{
|
|
if (serviceWidget->getStatus() != ServiceWidget::STARTED)
|
|
setStatus(ServiceWidget::STOPPED); // when a single service is not started, the whole group is stopped (or ERROR?)
|
|
}
|
|
|
|
if (getStatus() != ServiceWidget::STOPPED) // when not stopped (but unknown), then set as STARTED
|
|
setStatus(ServiceWidget::STARTED);
|
|
}
|
|
|
|
|
|
ServiceWidget::Status GroupWidget::getStatus() const
|
|
{
|
|
return m_status;
|
|
}
|
|
|
|
|
|
void GroupWidget::setStatus(ServiceWidget::Status status)
|
|
{
|
|
m_status = status;
|
|
|
|
QString newCss;
|
|
switch (m_status)
|
|
{
|
|
case ServiceWidget::STARTED:
|
|
newCss = QLatin1String("background-color: rgb(124, 189, 124);");
|
|
break;
|
|
case ServiceWidget::STOPPED:
|
|
newCss = QLatin1String("background-color: rgb(189, 106, 98);");
|
|
break;
|
|
case ServiceWidget::STARTING:
|
|
case ServiceWidget::STOPPING:
|
|
case ServiceWidget::UNKNOWN:
|
|
break;
|
|
}
|
|
m_ui->frStatus->setStyleSheet(newCss);
|
|
}
|
|
|
|
|
|
void GroupWidget::slotRestartGroup()
|
|
{
|
|
emit signalRestartGroup(m_groupType, m_exercise, m_server, m_replayPartitionId);
|
|
}
|
|
|
|
|
|
void GroupWidget::slotStartGroup()
|
|
{
|
|
emit signalStartGroup(m_groupType, m_exercise, m_server, m_replayPartitionId);
|
|
}
|
|
|
|
|
|
void GroupWidget::slotStopGroup()
|
|
{
|
|
emit signalStopGroup(m_groupType, m_exercise, m_server, m_replayPartitionId);
|
|
}
|
|
|
|
|
|
void GroupWidget::setType(Core::ServiceGroupType type)
|
|
{
|
|
m_groupType = type;
|
|
m_ui->lbGroupName->setText(QStringLiteral("<html><head/><body><p>%1<span style='font-weight:600;'> %2</span></p></body></html>")
|
|
.arg(tr("Services of %1").arg(ServiceManagement::ServiceManagementDialog::groupEnumToGroupName(type)), m_groupName));
|
|
}
|
|
|
|
void GroupWidget::setServer(int server)
|
|
{
|
|
m_server = server;
|
|
}
|
|
|
|
void GroupWidget::setExercise(int exercise)
|
|
{
|
|
m_exercise = exercise;
|
|
}
|
|
|
|
void GroupWidget::setTimestamp(long long timestamp)
|
|
{
|
|
if (timestamp < 1)
|
|
{
|
|
m_ui->lbTimestamp->setText(QString());
|
|
return;
|
|
}
|
|
|
|
m_ui->lbTimestamp->setText(QStringLiteral("<html><head/><body><p>%1:<br/>%2</p></body></html>")
|
|
.arg(tr("Last Heartbeat"), QDateTime::fromMSecsSinceEpoch(timestamp).toString()));
|
|
}
|
|
} // namespace ServiceManagement
|