Added games picker and play/stop buttons
This commit is contained in:
@@ -9,7 +9,9 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Helper: parse "GAM <cmd> CODE1Name1 CODE2Name2 ..." → name->code map
|
// Helper: parse "GAM <subCmd> XXXXNAME1 XXXXNAME2 ..."
|
||||||
|
// Code is always the first 4 characters; remainder is the display name.
|
||||||
|
// "_S" sequences in the name are replaced with spaces.
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
static QMap<QString,QString> parseGamResponse(const QString &response,
|
static QMap<QString,QString> parseGamResponse(const QString &response,
|
||||||
const QString &subCmd)
|
const QString &subCmd)
|
||||||
@@ -20,15 +22,11 @@ static QMap<QString,QString> parseGamResponse(const QString &response,
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
for (const QString &entry : tokens.mid(2)) {
|
for (const QString &entry : tokens.mid(2)) {
|
||||||
if (entry.isEmpty()) continue;
|
if (entry.size() < 5) continue; // need at least 4-char code + 1-char name
|
||||||
// First up-to-4 uppercase chars = code, remainder = name
|
const QString code = entry.left(4);
|
||||||
int splitPos = 0;
|
QString name = entry.mid(4);
|
||||||
while (splitPos < entry.size() && entry[splitPos].isUpper())
|
|
||||||
++splitPos;
|
|
||||||
const QString code = entry.left(qMin(splitPos, 4));
|
|
||||||
QString name = entry.mid(code.size());
|
|
||||||
name.replace("_S", " ");
|
name.replace("_S", " ");
|
||||||
if (code.isEmpty() || name.isEmpty()) continue;
|
if (name.isEmpty()) continue;
|
||||||
result[name] = code;
|
result[name] = code;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -44,7 +42,7 @@ GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
|
|||||||
|
|
||||||
auto *splitter = new QSplitter(Qt::Horizontal, this);
|
auto *splitter = new QSplitter(Qt::Horizontal, this);
|
||||||
|
|
||||||
// ---- Left pane: Available (not installed) games ----
|
// ---- Left pane: Available (not yet installed) games ----
|
||||||
auto *leftWidget = new QWidget(splitter);
|
auto *leftWidget = new QWidget(splitter);
|
||||||
auto *leftLayout = new QVBoxLayout(leftWidget);
|
auto *leftLayout = new QVBoxLayout(leftWidget);
|
||||||
leftLayout->setContentsMargins(4, 4, 4, 4);
|
leftLayout->setContentsMargins(4, 4, 4, 4);
|
||||||
@@ -61,19 +59,38 @@ GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
|
|||||||
leftLayout->addWidget(m_availableList, 1);
|
leftLayout->addWidget(m_availableList, 1);
|
||||||
leftLayout->addWidget(m_addBtn);
|
leftLayout->addWidget(m_addBtn);
|
||||||
|
|
||||||
// ---- Right pane: Installed games ----
|
// ---- Right pane: Installed games + Start/Stop ----
|
||||||
auto *rightWidget = new QWidget(splitter);
|
auto *rightWidget = new QWidget(splitter);
|
||||||
auto *rightLayout = new QVBoxLayout(rightWidget);
|
auto *rightLayout = new QVBoxLayout(rightWidget);
|
||||||
rightLayout->setContentsMargins(4, 4, 4, 4);
|
rightLayout->setContentsMargins(4, 4, 4, 4);
|
||||||
rightLayout->setSpacing(4);
|
rightLayout->setSpacing(4);
|
||||||
|
|
||||||
auto *instLabel = new QLabel("<b>Installed Games</b>", rightWidget);
|
auto *instLabel = new QLabel("<b>Installed Games</b>", rightWidget);
|
||||||
instLabel->setStyleSheet("color: #555;");
|
instLabel->setStyleSheet("color: #555;");
|
||||||
m_installedList = new QListWidget(rightWidget);
|
m_installedList = new QListWidget(rightWidget);
|
||||||
m_installedList->addItem("Connect to load installed games...");
|
m_installedList->addItem("Connect to load installed games...");
|
||||||
|
|
||||||
|
// Start / Stop button row
|
||||||
|
auto *btnRow = new QHBoxLayout();
|
||||||
|
m_startBtn = new QPushButton("▶ Start Game", rightWidget);
|
||||||
|
m_stopBtn = new QPushButton("■ Stop Game", rightWidget);
|
||||||
|
m_startBtn->setEnabled(false);
|
||||||
|
m_startBtn->setStyleSheet(
|
||||||
|
"QPushButton { color: white; background-color: #2e7d32;"
|
||||||
|
" border-radius: 4px; padding: 3px 10px; }"
|
||||||
|
"QPushButton:hover { background-color: #1b5e20; }"
|
||||||
|
"QPushButton:disabled { background-color: #888; color: #ccc; }");
|
||||||
|
m_stopBtn->setStyleSheet(
|
||||||
|
"QPushButton { color: white; background-color: #c62828;"
|
||||||
|
" border-radius: 4px; padding: 3px 10px; }"
|
||||||
|
"QPushButton:hover { background-color: #b71c1c; }");
|
||||||
|
btnRow->addWidget(m_startBtn);
|
||||||
|
btnRow->addWidget(m_stopBtn);
|
||||||
|
btnRow->addStretch(1);
|
||||||
|
|
||||||
rightLayout->addWidget(instLabel);
|
rightLayout->addWidget(instLabel);
|
||||||
rightLayout->addWidget(m_installedList, 1);
|
rightLayout->addWidget(m_installedList, 1);
|
||||||
|
rightLayout->addLayout(btnRow);
|
||||||
|
|
||||||
splitter->addWidget(leftWidget);
|
splitter->addWidget(leftWidget);
|
||||||
splitter->addWidget(rightWidget);
|
splitter->addWidget(rightWidget);
|
||||||
@@ -83,14 +100,22 @@ GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
|
|||||||
|
|
||||||
layout->addWidget(splitter);
|
layout->addWidget(splitter);
|
||||||
|
|
||||||
// Enable Add button only when something is selected in available list
|
// Enable Add only when available list has selection
|
||||||
connect(m_availableList, &QListWidget::currentRowChanged, this,
|
connect(m_availableList, &QListWidget::currentRowChanged, this,
|
||||||
[this](int row) { m_addBtn->setEnabled(row >= 0); });
|
[this](int row) { m_addBtn->setEnabled(row >= 0); });
|
||||||
connect(m_addBtn, &QPushButton::clicked, this, &GamesPanel::onAddClicked);
|
|
||||||
|
// Enable Start only when installed list has selection
|
||||||
|
connect(m_installedList, &QListWidget::currentRowChanged, this,
|
||||||
|
[this](int row) { m_startBtn->setEnabled(row >= 0); });
|
||||||
|
|
||||||
|
connect(m_addBtn, &QPushButton::clicked, this, &GamesPanel::onAddClicked);
|
||||||
|
connect(m_startBtn, &QPushButton::clicked, this, &GamesPanel::onStartClicked);
|
||||||
|
connect(m_stopBtn, &QPushButton::clicked, this,
|
||||||
|
[this]() { emit commandRequested(QStringLiteral("GST")); });
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Load installed games (GAM list response)
|
// Load installed games (GAM list response)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
void GamesPanel::loadFromResponse(const QString &response)
|
void GamesPanel::loadFromResponse(const QString &response)
|
||||||
{
|
{
|
||||||
@@ -98,11 +123,12 @@ void GamesPanel::loadFromResponse(const QString &response)
|
|||||||
m_installedList->clear();
|
m_installedList->clear();
|
||||||
for (const QString &name : m_installedGames.keys())
|
for (const QString &name : m_installedGames.keys())
|
||||||
m_installedList->addItem(name);
|
m_installedList->addItem(name);
|
||||||
|
m_startBtn->setEnabled(false);
|
||||||
rebuildAvailable();
|
rebuildAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Load all available games (GAM listall response)
|
// Load full catalogue (GAM listall response)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
void GamesPanel::loadAllFromResponse(const QString &response)
|
void GamesPanel::loadAllFromResponse(const QString &response)
|
||||||
{
|
{
|
||||||
@@ -111,7 +137,7 @@ void GamesPanel::loadAllFromResponse(const QString &response)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Rebuild available list = allGames minus installedGames (by code)
|
// Rebuild available list = allGames minus installedGames (matched by code)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
void GamesPanel::rebuildAvailable()
|
void GamesPanel::rebuildAvailable()
|
||||||
{
|
{
|
||||||
@@ -128,7 +154,7 @@ void GamesPanel::rebuildAvailable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Add button clicked → emit GAM add <code>
|
// Add selected available game to installed list
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
void GamesPanel::onAddClicked()
|
void GamesPanel::onAddClicked()
|
||||||
{
|
{
|
||||||
@@ -138,3 +164,15 @@ void GamesPanel::onAddClicked()
|
|||||||
if (!m_allGames.contains(name)) return;
|
if (!m_allGames.contains(name)) return;
|
||||||
emit commandRequested(QString("GAM add %1").arg(m_allGames[name]));
|
emit commandRequested(QString("GAM add %1").arg(m_allGames[name]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Start selected installed game: GST <code> ,p
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
void GamesPanel::onStartClicked()
|
||||||
|
{
|
||||||
|
auto *item = m_installedList->currentItem();
|
||||||
|
if (!item) return;
|
||||||
|
const QString name = item->text();
|
||||||
|
if (!m_installedGames.contains(name)) return;
|
||||||
|
emit commandRequested(QString("GST %1 ,p").arg(m_installedGames[name]));
|
||||||
|
}
|
||||||
|
|||||||
10
GamesPanel.h
10
GamesPanel.h
@@ -13,21 +13,27 @@ class GamesPanel : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit GamesPanel(QWidget *parent = nullptr);
|
explicit GamesPanel(QWidget *parent = nullptr);
|
||||||
void loadFromResponse(const QString &response); // GAM list (installed)
|
void loadFromResponse(const QString &response); // GAM list (installed)
|
||||||
void loadAllFromResponse(const QString &response); // GAM listall (all available)
|
void loadAllFromResponse(const QString &response); // GAM listall (full catalogue)
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void commandRequested(const QString &cmd);
|
void commandRequested(const QString &cmd);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onAddClicked();
|
void onAddClicked();
|
||||||
|
void onStartClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void rebuildAvailable();
|
void rebuildAvailable();
|
||||||
|
|
||||||
|
// Left pane
|
||||||
QListWidget *m_availableList = nullptr;
|
QListWidget *m_availableList = nullptr;
|
||||||
QListWidget *m_installedList = nullptr;
|
|
||||||
QPushButton *m_addBtn = nullptr;
|
QPushButton *m_addBtn = nullptr;
|
||||||
|
|
||||||
|
// Right pane
|
||||||
|
QListWidget *m_installedList = nullptr;
|
||||||
|
QPushButton *m_startBtn = nullptr;
|
||||||
|
QPushButton *m_stopBtn = nullptr;
|
||||||
|
|
||||||
QMap<QString,QString> m_allGames; // name -> code (GAM listall)
|
QMap<QString,QString> m_allGames; // name -> code (GAM listall)
|
||||||
QMap<QString,QString> m_installedGames; // name -> code (GAM list)
|
QMap<QString,QString> m_installedGames; // name -> code (GAM list)
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user