Skip to content

Commit

Permalink
Minor config improvements. Modified Qt recent ROM menu to drop file e…
Browse files Browse the repository at this point in the history
…ntries that no longer exist on disk.
  • Loading branch information
thor2016 committed Feb 20, 2024
1 parent cb45321 commit 3661454
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/drivers/Qt/ConsoleWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ consoleWin_t::~consoleWin_t(void)
#ifdef __FCEU_QSCRIPT_ENABLE__
QtScriptManager::destroy();
#endif

NetPlayCloseSession();

// The closeApp function call stops all threads.
// Calling quit on threads should not happen here.
//printf("Thread Finished: %i \n", emulatorThread->isFinished() );
Expand Down Expand Up @@ -931,9 +934,9 @@ void consoleWin_t::createMainMenu(void)
movieMenu = menubar->addMenu(tr("&Movie"));
optMenu = menubar->addMenu(tr("&Options"));
emuMenu = menubar->addMenu(tr("&Emulation"));
netPlayMenu = menubar->addMenu(tr("&NetPlay"));
toolsMenu = menubar->addMenu(tr("&Tools"));
debugMenu = menubar->addMenu(tr("&Debug"));
netPlayMenu = menubar->addMenu(tr("&NetPlay"));
helpMenu = menubar->addMenu(tr("&Help"));

//-----------------------------------------------------------------------
Expand Down Expand Up @@ -2219,8 +2222,9 @@ void consoleWin_t::buildRecentRomMenu(void)
g_config->getOption( buf, &s);

//printf("Recent Rom:%i '%s'\n", i, s.c_str() );
bool fileExists = !s.empty() && QFile::exists(tr(s.c_str()));

if ( s.size() > 0 )
if ( fileExists )
{
act = new consoleRecentRomAction( tr(s.c_str()), recentRomMenu);

Expand All @@ -2234,6 +2238,13 @@ void consoleWin_t::buildRecentRomMenu(void)

romList.push_front( sptr );
}
else
{
// Clear the option if file does not exist
s.clear();

g_config->setOption( buf, s);
}
}
}
//---------------------------------------------------------------------------
Expand All @@ -2251,11 +2262,17 @@ void consoleWin_t::saveRecentRomMenu(void)
s = *it;
sprintf(buf, "SDL.RecentRom%02i", i);

g_config->setOption( buf, s->c_str() );
g_config->setOption( buf, *s );

//printf("Recent Rom:%u '%s'\n", i, s->c_str() );
i--;
}
for (i = romList.size(); i < 10; i++)
{
sprintf(buf, "SDL.RecentRom%02i", i);
g_config->setOption( buf, "");
}

}
//---------------------------------------------------------------------------
void consoleWin_t::addRecentRom( const char *rom )
Expand Down
42 changes: 42 additions & 0 deletions src/drivers/common/configSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,26 @@ Config::setOption(const std::string &name,
return 0;
}

/**
* Sets the specified option to the given string value.
*/
int
Config::setOption(const std::string &name,
const char *value)
{
std::map<std::string, std::string>::iterator opt_i;

// confirm that the option exists
opt_i = _strOptMap.find(name);
if(opt_i == _strOptMap.end()) {
return -1;
}

// set the option
opt_i->second = value;
return 0;
}

/**
* Sets the specified option to the given string value.
*/
Expand All @@ -375,6 +395,28 @@ Config::setOption(const std::string &name,
return 0;
}

#ifdef __QT_DRIVER__
/**
* Sets the specified option to the given string value.
*/
int
Config::setOption(const std::string &name,
const QString &value)
{
std::map<std::string, std::string>::iterator opt_i;

// confirm that the option exists
opt_i = _strOptMap.find(name);
if(opt_i == _strOptMap.end()) {
return -1;
}

// set the option
opt_i->second = value.toLocal8Bit().constData();
return 0;
}
#endif

/**
* Sets the specified option to the given function.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/common/configSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ class Config {
/**
* Sets a configuration option. Can be called at any time.
*/
int setOption(const std::string &, const char *);
int setOption(const std::string &, const std::string &);
int setOption(const std::string &, int);
int setOption(const std::string &, double);
int setOption(const std::string &, void (*)(const std::string &));
#ifdef __QT_DRIVER__
int setOption(const std::string &, const QString &);
#endif

#ifdef __QT_DRIVER__
int getOption(const std::string &, QString *) const;
Expand Down

0 comments on commit 3661454

Please sign in to comment.