135 lines
3.0 KiB
C++
Executable File
135 lines
3.0 KiB
C++
Executable File
#include "scm_dialog_service.h"
|
|
#include "ui_scm_dialog_service.h"
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
namespace ServiceManagement
|
|
{
|
|
ServiceWidget::ServiceWidget(int32_t id, long long pid, const QString &name,
|
|
const Core::RunningState &state, const QString &errorString, QWidget *parent)
|
|
: QWidget(parent)
|
|
, m_ui(new Ui::ServiceWidget)
|
|
, m_status(ServiceWidget::UNKNOWN)
|
|
, m_id(id)
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
connect(m_ui->pbRestart, &QToolButton::clicked, this, &ServiceWidget::slotRestartService);
|
|
|
|
setName(name);
|
|
setPid(pid);
|
|
setErrorString(errorString);
|
|
setState(state);
|
|
}
|
|
|
|
|
|
ServiceWidget::~ServiceWidget()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
void ServiceWidget::setName(const QString &name)
|
|
{
|
|
m_ui->lbServiceName->setText(name);
|
|
}
|
|
|
|
|
|
void ServiceWidget::setPid(long long pid)
|
|
{
|
|
m_ui->lbPID->setText(QStringLiteral("<html><head/><body><p>%1:<br/>%2</p></body></html>")
|
|
.arg(tr("Process ID")).arg(pid));
|
|
}
|
|
|
|
|
|
void ServiceWidget::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()));
|
|
}
|
|
|
|
|
|
void ServiceWidget::setErrorString(const QString &errorString)
|
|
{
|
|
if (errorString.isEmpty())
|
|
{
|
|
m_ui->lbError->setText(QString());
|
|
return;
|
|
}
|
|
|
|
m_ui->lbError->setText(QStringLiteral("<html><head/><body><p><span style='color:#aa0000;'>%1:<br/>%2</span></p></body></html>").arg(tr("Error"), errorString));
|
|
}
|
|
|
|
|
|
void ServiceWidget::setState(Core::RunningState state)
|
|
{
|
|
auto status = ServiceWidget::UNKNOWN;
|
|
switch (state.underlying())
|
|
{
|
|
// STARTING
|
|
case Core::RunningState::inner_enum::Starting:
|
|
status = ServiceWidget::STARTING;
|
|
break;
|
|
|
|
// STARTED
|
|
case Core::RunningState::inner_enum::Running:
|
|
status = ServiceWidget::STARTED;
|
|
break;
|
|
|
|
// STOPPING
|
|
case Core::RunningState::inner_enum::Stopping:
|
|
status = ServiceWidget::STOPPING;
|
|
break;
|
|
|
|
// STOPPED
|
|
case Core::RunningState::inner_enum::StartingError:
|
|
case Core::RunningState::inner_enum::NotYetStarted:
|
|
case Core::RunningState::inner_enum::StoppedNormally:
|
|
case Core::RunningState::inner_enum::StoppedError: // FIXME: how does that look like? was STARTED but is not stoppable and still STARTED?
|
|
status = ServiceWidget::STOPPED;
|
|
break;
|
|
}
|
|
setStatus(status);
|
|
}
|
|
|
|
|
|
void ServiceWidget::setStatus(const Status status)
|
|
{
|
|
m_status = status;
|
|
|
|
switch (m_status)
|
|
{
|
|
case ServiceWidget::STARTED:
|
|
m_ui->frStatus->setStyleSheet(greenStyleSheet());
|
|
break;
|
|
|
|
case ServiceWidget::STOPPED:
|
|
m_ui->frStatus->setStyleSheet(redStyleSheet());
|
|
break;
|
|
|
|
default:
|
|
m_ui->frStatus->setStyleSheet(orangeStyleSheet());
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
ServiceWidget::Status ServiceWidget::getStatus() const
|
|
{
|
|
return m_status;
|
|
}
|
|
|
|
|
|
void ServiceWidget::slotRestartService()
|
|
{
|
|
emit signalRestartService(m_id);
|
|
}
|
|
} // namespace ServiceManagement
|