diff options
author | pommicket <pommicket@gmail.com> | 2025-08-21 21:38:39 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-08-21 21:38:39 -0400 |
commit | b721c4a19a10f436329f2441156f45b19924205a (patch) | |
tree | e411c55fa1a1ef8adacee6c887e4b46481792833 | |
parent | a807b7349c0366ea105098c36b42af9dba2e4909 (diff) |
Save Macondo settings
-rw-r--r-- | quacker/macondo.cpp | 40 | ||||
-rw-r--r-- | quacker/macondo.h | 3 | ||||
-rw-r--r-- | quacker/macondobackend.cpp | 13 | ||||
-rw-r--r-- | quacker/macondobackend.h | 4 | ||||
-rw-r--r-- | quacker/quacker.cpp | 9 |
5 files changed, 49 insertions, 20 deletions
diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp index fe0f670..a222126 100644 --- a/quacker/macondo.cpp +++ b/quacker/macondo.cpp @@ -18,15 +18,18 @@ TODO: #include <QMessageBox> #include <QOperatingSystemVersion> #include <QPushButton> +#include <QSettings> + +#include "customqsettings.h" Macondo::Macondo(Quackle::Game *game) : View() { + CustomQSettings settings; m_game = game; QFont boldFont; boldFont.setWeight(QFont::Bold); m_useMacondo = new QCheckBox(tr("Use Macondo for 'Simulate'")); - const char *home = getenv("HOME"); - std::string execPath = home ? home : "/"; - execPath += "/apps/macondo/macondo"; + m_useMacondo->setChecked(settings.value("macondo/useForSimulate", false).toBool()); + std::string execPath = settings.value("macondo/execPath", "").toString().toStdString(); m_initOptions = std::make_unique<MacondoInitOptions>(execPath); m_backend = new MacondoBackend(game, *m_initOptions); connectBackendSignals(); @@ -34,6 +37,7 @@ Macondo::Macondo(Quackle::Game *game) : View() { QPushButton *selectExecButton = new QPushButton(tr("Choose File...")); connect(selectExecButton, SIGNAL(clicked()), this, SLOT(chooseExecPath())); m_execPath = new QLineEdit; + m_execPath->setText(QString::fromStdString(execPath)); connect(m_execPath, SIGNAL(editingFinished()), this, SLOT(execPathChanged())); m_solve = new QPushButton(tr("Solve")); m_solve->setDisabled(true); @@ -41,6 +45,7 @@ Macondo::Macondo(Quackle::Game *game) : View() { QVBoxLayout *pegLayout = new QVBoxLayout; m_generatedMovesOnly = new QCheckBox(tr("Generated moves only")); m_generatedMovesOnly->setToolTip("Only analyze the moves that have been generated in the 'Choices' box."); + m_generatedMovesOnly->setChecked(settings.value("macondo/generatedMovesOnly", false).toBool()); pegLayout->addWidget(m_generatedMovesOnly); pegBox->setLayout(pegLayout); QHBoxLayout *execPathLayout = new QHBoxLayout; @@ -57,13 +62,19 @@ Macondo::Macondo(Quackle::Game *game) : View() { } Macondo::~Macondo() { + CustomQSettings settings; + settings.setValue("macondo/useForSimulate", m_useMacondo->isChecked()); + settings.setValue("macondo/generatedMovesOnly", m_generatedMovesOnly->isChecked()); delete m_backend; } void Macondo::setExecPath(const std::string &path) { m_backend->setExecPath(path); m_initOptions->execPath = path; - m_execPath->setText(QString::fromStdString(path)); + QString qpath = QString::fromStdString(path); + m_execPath->setText(qpath); + CustomQSettings settings; + settings.setValue("macondo/execPath", qpath); } void Macondo::chooseExecPath() { @@ -80,27 +91,36 @@ void Macondo::execPathChanged() { } bool Macondo::checkExecPath() { - if (m_initOptions->execPath.empty()) { + const std::string &execPath = m_initOptions->execPath; + if (execPath.empty()) { QMessageBox::critical(this, tr("Can't run Macondo"), tr("Please fill in the location of Macondo on your computer.") ); return false; } + if (!QFile::exists(QString::fromStdString(execPath))) { + QString message = QString(tr("File %1 does not exist.")).arg(execPath.c_str()); + QMessageBox::critical(this, + tr("Macondo not found"), + message + ); + return false; + } return true; } -void Macondo::simulate() { - if (!checkExecPath()) return; +bool Macondo::simulate() { + if (!checkExecPath()) return false; if (m_isSolving) { // don't start a simulation if we're solving a (pre-)endgame - return; + return true; } if (isRunning()) stop(); clearMoves(); MacondoSimulateOptions options; - m_backend->simulate(options, m_movesFromKibitzer); + return m_backend->simulate(options, m_movesFromKibitzer); } bool Macondo::isRunning() const { @@ -133,8 +153,8 @@ void Macondo::solve() { MacondoEndgameOptions options; m_backend->solveEndgame(options); } - emit runningSolver(); m_isSolving = true; + emit runningSolver(); } updateSolveButton(); } diff --git a/quacker/macondo.h b/quacker/macondo.h index 258ea55..83eb031 100644 --- a/quacker/macondo.h +++ b/quacker/macondo.h @@ -30,12 +30,13 @@ public: return any; } bool isRunning() const; + // Start Macondo simulation -- returns false if there was an error starting Macondo. + bool simulate(); inline bool isSolving() const { return m_isSolving; } signals: void runningSolver(); void stoppedSolver(); public slots: - void simulate(); void solve(); void gameChanged(Quackle::Game *game) override; void positionChanged(const Quackle::GamePosition *position) override; diff --git a/quacker/macondobackend.cpp b/quacker/macondobackend.cpp index 0a4e945..bc046c9 100644 --- a/quacker/macondobackend.cpp +++ b/quacker/macondobackend.cpp @@ -100,19 +100,22 @@ MacondoBackend::MacondoBackend(Quackle::Game *game, const MacondoInitOptions &op m_updateTimer->start(); } -void MacondoBackend::startProcess() { - if (m_process) return; +bool MacondoBackend::startProcess() { + if (m_process) return true; m_process = new QProcess(this); QStringList args; m_process->start(m_execPath.c_str(), args); connect(m_process, SIGNAL(started()), this, SLOT(processStarted())); connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus))); + return true; } -void MacondoBackend::simulate(const MacondoSimulateOptions &options, const Quackle::MoveList &moves) { - startProcess(); +bool MacondoBackend::simulate(const MacondoSimulateOptions &options, const Quackle::MoveList &moves) { + if (!startProcess()) + return false; m_movesToLoad = moves; m_command = Command::Simulate; + return true; } void MacondoBackend::solveEndgame(const MacondoEndgameOptions &) { @@ -414,7 +417,7 @@ void MacondoBackend::timer() { data = m_process->readAllStandardOutput(); anyNewOutput |= data.size() != 0; m_processOutput.append(data); - //printf("%.*s",data.size(), data.constData()); + printf("%.*s",data.size(), data.constData()); fflush(stdout); } const char *dots = updateDots(anyNewOutput); diff --git a/quacker/macondobackend.h b/quacker/macondobackend.h index bda9048..c8bcfdf 100644 --- a/quacker/macondobackend.h +++ b/quacker/macondobackend.h @@ -29,7 +29,7 @@ Q_OBJECT public: MacondoBackend(Quackle::Game *game, const MacondoInitOptions &); ~MacondoBackend(); - void simulate(const MacondoSimulateOptions &options, const Quackle::MoveList &moves); + bool simulate(const MacondoSimulateOptions &options, const Quackle::MoveList &moves); void solveEndgame(const MacondoEndgameOptions &options); void solvePreEndgame(const MacondoPreEndgameOptions &options); std::string getSimResults(); @@ -53,7 +53,7 @@ private: SolvePreEndgame, SolveEndgame, }; - void startProcess(); + bool startProcess(); void loadGCG(); void killProcess(); void removeTempGCG(); diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp index cde9175..32486e0 100644 --- a/quacker/quacker.cpp +++ b/quacker/quacker.cpp @@ -1066,8 +1066,13 @@ void TopLevel::simulate(bool startSimulation) //m_simulatorWidget->setVisible(startSimulation); if (startSimulation) { - if (m_macondo->useForSimulation()) - m_macondo->simulate(); + if (m_macondo->useForSimulation()) { + if (!m_macondo->simulate()) { + // Macondo failed to start + m_simulateAction->setChecked(false); + return; + } + } logfileChanged(); incrementSimulation(); } |