summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-08-21 21:09:22 -0400
committerpommicket <pommicket@gmail.com>2025-08-21 21:16:06 -0400
commita807b7349c0366ea105098c36b42af9dba2e4909 (patch)
tree02aae9273270144ea9dfaccd31a4bb484fd6d8fc
parenta71b0ecc36665c8d28d19e0c0e06f70713b816ab (diff)
Macondo executable "Choose File..." option
-rw-r--r--quacker/macondo.cpp54
-rw-r--r--quacker/macondo.h5
2 files changed, 46 insertions, 13 deletions
diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp
index a5776e9..fe0f670 100644
--- a/quacker/macondo.cpp
+++ b/quacker/macondo.cpp
@@ -1,7 +1,5 @@
/*
TODO:
-- configurable execPath
- - Choose file... button
- save options
- detect Macondo crashing?
- configurable max plies
@@ -11,13 +9,15 @@ TODO:
#include "macondo.h"
#include "macondobackend.h"
-#include <QGridLayout>
-#include <QPushButton>
#include <QCheckBox>
-#include <QLabel>
+#include <QFileDialog>
+#include <QGridLayout>
#include <QGroupBox>
-#include <QMessageBox>
+#include <QLabel>
#include <QLineEdit>
+#include <QMessageBox>
+#include <QOperatingSystemVersion>
+#include <QPushButton>
Macondo::Macondo(Quackle::Game *game) : View() {
m_game = game;
@@ -32,7 +32,9 @@ Macondo::Macondo(Quackle::Game *game) : View() {
connectBackendSignals();
QLabel *execPathLabel = new QLabel(tr("Macondo executable"));
QPushButton *selectExecButton = new QPushButton(tr("Choose File..."));
+ connect(selectExecButton, SIGNAL(clicked()), this, SLOT(chooseExecPath()));
m_execPath = new QLineEdit;
+ connect(m_execPath, SIGNAL(editingFinished()), this, SLOT(execPathChanged()));
m_solve = new QPushButton(tr("Solve"));
m_solve->setDisabled(true);
QGroupBox *pegBox = new QGroupBox(tr("Pre-endgame options"));
@@ -52,20 +54,44 @@ Macondo::Macondo(Quackle::Game *game) : View() {
layout->addWidget(pegBox);
layout->addWidget(m_solve);
connect(m_solve, SIGNAL(clicked()), this, SLOT(solve()));
- connect(m_execPath, SIGNAL(editingFinished()), this, SLOT(newExecPath()));
}
Macondo::~Macondo() {
delete m_backend;
}
-void Macondo::newExecPath() {
- std::string newPath = m_execPath->text().toStdString();
- m_backend->setExecPath(newPath);
- m_initOptions->execPath = newPath;
+void Macondo::setExecPath(const std::string &path) {
+ m_backend->setExecPath(path);
+ m_initOptions->execPath = path;
+ m_execPath->setText(QString::fromStdString(path));
+}
+
+void Macondo::chooseExecPath() {
+ QString filter;
+ if (QOperatingSystemVersion::current().type() == QOperatingSystemVersion::Windows) {
+ filter = tr("Executable files (*.exe)");
+ }
+ QString path = QFileDialog::getOpenFileName(this, tr("Select Macondo executable..."), QString(), filter);
+ setExecPath(path.toStdString());
+}
+
+void Macondo::execPathChanged() {
+ setExecPath(m_execPath->text().toStdString());
+}
+
+bool Macondo::checkExecPath() {
+ if (m_initOptions->execPath.empty()) {
+ QMessageBox::critical(this,
+ tr("Can't run Macondo"),
+ tr("Please fill in the location of Macondo on your computer.")
+ );
+ return false;
+ }
+ return true;
}
void Macondo::simulate() {
+ if (!checkExecPath()) return;
if (m_isSolving) {
// don't start a simulation if we're solving a (pre-)endgame
return;
@@ -82,6 +108,7 @@ bool Macondo::isRunning() const {
}
void Macondo::solve() {
+ if (!checkExecPath()) return;
bool wasSolving = m_isSolving;
if (isRunning())
stop();
@@ -93,7 +120,10 @@ void Macondo::solve() {
MacondoPreEndgameOptions options;
if (m_generatedMovesOnly->isChecked()) {
if (m_movesFromKibitzer.empty()) {
- QMessageBox::critical(this, tr("Can't run pre-endgame solver"), tr("Please generate moves to analyze or uncheck 'Generated moves only'"));
+ QMessageBox::critical(this,
+ tr("Can't run pre-endgame solver"),
+ tr("Please generate moves to analyze or uncheck 'Generated moves only'")
+ );
return;
}
options.movesToAnalyze = m_movesFromKibitzer;
diff --git a/quacker/macondo.h b/quacker/macondo.h
index 406cc31..258ea55 100644
--- a/quacker/macondo.h
+++ b/quacker/macondo.h
@@ -41,9 +41,12 @@ public slots:
void positionChanged(const Quackle::GamePosition *position) override;
private slots:
void gotMoves(const Quackle::MoveList &moves);
- void newExecPath();
+ void execPathChanged();
+ void chooseExecPath();
private:
+ void setExecPath(const std::string &);
void connectBackendSignals();
+ bool checkExecPath();
void updateSolveButton();
QCheckBox *m_useMacondo;
QCheckBox *m_generatedMovesOnly;