diff --git a/src/drivers/Qt/StateRecorderConf.cpp b/src/drivers/Qt/StateRecorderConf.cpp index 34909c5a..3aeaf144 100644 --- a/src/drivers/Qt/StateRecorderConf.cpp +++ b/src/drivers/Qt/StateRecorderConf.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "Qt/throttle.h" #include "Qt/fceuWrapper.h" @@ -305,36 +306,89 @@ void StateRecorderDialog_t::closeEvent(QCloseEvent *event) { QSettings settings; settings.setValue("stateRecorderWindow/geometry", saveGeometry()); - done(0); - deleteLater(); - event->accept(); + + if (dataSavedCheck()) + { + done(0); + deleteLater(); + event->accept(); + } } //---------------------------------------------------------------------------- void StateRecorderDialog_t::closeWindow(void) { QSettings settings; settings.setValue("stateRecorderWindow/geometry", saveGeometry()); - done(0); - deleteLater(); + + if (dataSavedCheck()) + { + done(0); + deleteLater(); + } } //---------------------------------------------------------------------------- -void StateRecorderDialog_t::applyChanges(void) +void StateRecorderDialog_t::packConfig( StateRecorderConfigData &config ) { - StateRecorderConfigData config; - config.historyDurationMinutes = static_cast( historyDuration->value() ); config.timeBetweenSnapsMinutes = static_cast( snapMinutes->value() ) + ( static_cast( snapSeconds->value() ) / 60.0f ); config.compressionLevel = cmprLvlCbox->currentData().toInt(); config.loadPauseTimeSeconds = pauseDuration->value(); config.pauseOnLoad = static_cast( pauseOnLoadCbox->currentData().toInt() ); +} +//---------------------------------------------------------------------------- +bool StateRecorderDialog_t::dataSavedCheck(void) +{ + bool okToClose = true; + const StateRecorderConfigData &curConfig = FCEU_StateRecorderGetConfigData(); + + StateRecorderConfigData selConfig; + + packConfig( selConfig ); + + if ( selConfig.compare( curConfig ) == false ) + { + QMessageBox msgBox(QMessageBox::Question, tr("State Recorder"), + tr("Setting selections have not yet been saved.\nDo you wish to save/apply the new settings?"), + QMessageBox::No | QMessageBox::Yes, this); + + msgBox.setDefaultButton( QMessageBox::Yes ); + + int ret = msgBox.exec(); + + if ( ret == QMessageBox::Yes ) + { + applyChanges(); + } + } + return okToClose; +} +//---------------------------------------------------------------------------- +void StateRecorderDialog_t::applyChanges(void) +{ + StateRecorderConfigData config; + + packConfig( config ); FCEU_WRAPPER_LOCK(); FCEU_StateRecorderSetEnabled( recorderEnable->isChecked() ); FCEU_StateRecorderSetConfigData( config ); if (FCEU_StateRecorderRunning()) { - // TODO restart with new settings + QMessageBox msgBox(QMessageBox::Question, tr("State Recorder"), + tr("New settings will not take effect until state recorder is restarted. Do you wish to restart?"), + QMessageBox::No | QMessageBox::Yes, this); + + msgBox.setDefaultButton( QMessageBox::Yes ); + + int ret = msgBox.exec(); + + if ( ret == QMessageBox::Yes ) + { + FCEU_StateRecorderStop(); + FCEU_StateRecorderStart(); + updateStatusDisplay(); + } } FCEU_WRAPPER_UNLOCK(); diff --git a/src/drivers/Qt/StateRecorderConf.h b/src/drivers/Qt/StateRecorderConf.h index de1919cf..d87e0c45 100644 --- a/src/drivers/Qt/StateRecorderConf.h +++ b/src/drivers/Qt/StateRecorderConf.h @@ -19,6 +19,8 @@ #include #include +struct StateRecorderConfigData; + class StateRecorderDialog_t : public QDialog { Q_OBJECT @@ -51,11 +53,13 @@ protected: double saveTimeMs; + bool dataSavedCheck(void); void recalcMemoryUsage(void); void updateStartStopBuffon(void); void updateRecorderStatusLabel(void); void updateBufferSizeStatus(void); void updateStatusDisplay(void); + void packConfig( StateRecorderConfigData &config ); public slots: void closeWindow(void); diff --git a/src/state.h b/src/state.h index dbc5066a..119c5f92 100644 --- a/src/state.h +++ b/src/state.h @@ -17,6 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#pragma once #include enum ENUM_SSLOADPARAMS @@ -101,6 +102,11 @@ struct StateRecorderConfigData loadPauseTimeSeconds = 3; pauseOnLoad = TEMPORARY_PAUSE; } + + bool compare( const StateRecorderConfigData &other ) + { + return memcmp( this, &other, sizeof(StateRecorderConfigData) ) == 0; + } }; int FCEU_StateRecorderStart(void);