Files
seer/src/SeerRunStatusIndicator.cpp
T

141 lines
4.5 KiB
C++
Raw Normal View History

2025-08-26 17:26:05 -05:00
// SPDX-FileCopyrightText: 2021 Ernie Pasveer <epasveer@att.net>
//
// SPDX-License-Identifier: GPL-3.0-or-later
2021-09-01 13:58:59 -05:00
#include "SeerRunStatusIndicator.h"
#include <QtWidgets/QApplication>
#include <QtCore/QDebug>
2025-12-18 13:17:45 +07:00
#include <QGroupBox>
#include <QPainter>
2021-09-01 13:58:59 -05:00
SeerRunStatusIndicator::SeerRunStatusIndicator(QWidget* parent) : QLabel(parent) {
_runStatus = RunStatus::Idle;
2025-12-18 13:17:45 +07:00
// Create group box
_groupBox = new QGroupBox();
_groupBox->setTitle("");
// --- Create two fixed-size labels ---
_coreLabel = new QLabel("Core");
_coreLabel->setAlignment(Qt::AlignCenter);
_coreLabel->setFixedSize(80, 25);
_coreLabel->setStyleSheet("background-color: lightgray; color: black; font-weight: bold;");
_statusLabel = new QLabel("Status");
_statusLabel->setAlignment(Qt::AlignCenter);
_statusLabel->setFixedSize(150, 25);
_statusLabel->setStyleSheet("background-color: lightgray; color: black; font-weight: bold;");
// --- Layout with spacing ---
auto *layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(_coreLabel);
layout->addWidget(_statusLabel);
_groupBox->setLayout(layout);
2021-09-01 13:58:59 -05:00
}
SeerRunStatusIndicator::~SeerRunStatusIndicator() {
}
void SeerRunStatusIndicator::setRunStatus (SeerRunStatusIndicator::RunStatus status) {
// If the status is already set, don't set it again.
if (status == _runStatus) {
return;
}
// Change the status to the new status.
_runStatus = status;
if (status == RunStatus::Idle) {
QApplication::restoreOverrideCursor();
setText("Idle");
}else if (status == RunStatus::Stopped) {
QApplication::restoreOverrideCursor();
setText("Stopped");
}else if (status == RunStatus::Running) {
QApplication::setOverrideCursor(Qt::BusyCursor);
setText("Running");
}else{
QApplication::restoreOverrideCursor();
setText("Unknown");
}
2025-12-18 13:17:45 +07:00
//
if (status == RunStatus::Idle) {
_statusLabel->setText("Idle");
_statusLabel->setStyleSheet("background-color: lightgray; color: black; font-weight: bold;");
}else if (status == RunStatus::Stopped) {
_statusLabel->setText("Stopped");
_statusLabel->setStyleSheet("background-color: red; color: black; font-weight: bold;");
}
else if (status == RunStatus::Stop_By_Breakpoint) {
_statusLabel->setText("Stop by breakpoint");
_statusLabel->setStyleSheet("background-color: yellow; color: black; font-weight: bold;");
}
else if (status == RunStatus::Running) {
_statusLabel->setText("Running");
_statusLabel->setStyleSheet("background-color: green; color: black; font-weight: bold;");
}
else {
_statusLabel->setText("Unknown");
}
emit statusChanged(status);
2021-09-01 13:58:59 -05:00
}
SeerRunStatusIndicator::RunStatus SeerRunStatusIndicator::runStatus () const {
return _runStatus;
}
void SeerRunStatusIndicator::handleText (const QString& text) {
if (text.startsWith("*running,thread-id=\"")) {
// *running,thread-id="all"
// *running,thread-id="2"
setRunStatus(SeerRunStatusIndicator::Running);
2022-02-20 17:51:06 -06:00
}else if (text.startsWith("*stopped")) {
2025-12-18 13:17:45 +07:00
if (text.startsWith("*stopped,reason=\"breakpoint-hit\""))
setRunStatus(SeerRunStatusIndicator::Stop_By_Breakpoint);
else
//^connected,frame={level=\"0\",addr=\"0x00007f48351f80c1\",func=\"read\",args=[],from=\"/lib64/libc.so.6\",arch=\"i386:x86-64\"}"
setRunStatus(SeerRunStatusIndicator::Stopped);
2021-09-01 13:58:59 -05:00
}else if (text.startsWith("=thread-exited")) {
//=thread-exited,id="1",group-id="i1"
setRunStatus(SeerRunStatusIndicator::Stopped);
}else if (text.startsWith("=thread-group-exited")) {
//=thread-group-exited,id="i1"
setRunStatus(SeerRunStatusIndicator::Stopped);
2021-09-01 13:58:59 -05:00
2025-12-18 13:17:45 +07:00
}
else if (text.startsWith("^done,stack")) {
// When finish command is invoked
setRunStatus(SeerRunStatusIndicator::Stopped);
}
else{
2021-09-01 13:58:59 -05:00
// All other text is ignored by this widget.
2025-04-19 10:51:15 -05:00
// qDebug() << text;
2021-09-01 13:58:59 -05:00
}
}
2025-12-18 13:17:45 +07:00
// handle when program stop/ killed
void SeerRunStatusIndicator::handleTerminate() {
_coreLabel->setText("Core");
_coreLabel->setStyleSheet("background-color: lightgray; color: black; font-weight: bold;");
_statusLabel->setText("Status");
_statusLabel->setStyleSheet("background-color: lightgray; color: black; font-weight: bold;");
// also tell SeerProgressIndicator to stop spinning
setRunStatus(SeerRunStatusIndicator::Stopped);
}