Qt: Setting to show filename in title bar instead of ROM name. (#1807) * All: Setting to display the file name of the currently loaded ROM instead of the game name in the title bar (closes mgba.io/i/1784) * Utilize ConfigController getOption method and restructured to not use dynamically allocated memory for the temporary title * Grab actual path name, use getOption to avoid having to modify the core, update CHANGES file, and moved core declaration to condense code. * Change CHANGES text * Qt: Simplify settings UI for PR Co-authored-by: Vicki Pfau <vi@endrift.com>
Mathew Horner mathewhorner123@gmail.com
Wed, 24 Jun 2020 01:20:42 -0500
4 files changed,
36 insertions(+),
16 deletions(-)
M
CHANGES
→
CHANGES
@@ -36,6 +36,7 @@ - Qt: Renderer can be changed while a game is running
- Qt: Add hex index to palette view - Qt: Add transformation matrix info to sprite view - Qt: Add per-page scrolling to memory view (fixes mgba.io/i/1795) + - Qt: Add setting to display ROM filename in title (closes mgba.io/i/1784) 0.8.2: (2020-06-14) Emulation fixes:
M
src/platform/qt/SettingsView.cpp
→
src/platform/qt/SettingsView.cpp
@@ -400,6 +400,7 @@ saveSetting("preload", m_ui.preload);
saveSetting("showFps", m_ui.showFps); saveSetting("cheatAutoload", m_ui.cheatAutoload); saveSetting("cheatAutosave", m_ui.cheatAutosave); + saveSetting("showFilename", m_ui.showFilename); saveSetting("autoload", m_ui.autoload); saveSetting("autosave", m_ui.autosave); saveSetting("logToFile", m_ui.logToFile);@@ -574,6 +575,7 @@ loadSetting("preload", m_ui.preload);
loadSetting("showFps", m_ui.showFps, true); loadSetting("cheatAutoload", m_ui.cheatAutoload, true); loadSetting("cheatAutosave", m_ui.cheatAutosave, true); + loadSetting("showFilename", m_ui.showFilename, false); loadSetting("autoload", m_ui.autoload, true); loadSetting("autosave", m_ui.autosave, false); loadSetting("logToFile", m_ui.logToFile);
M
src/platform/qt/SettingsView.ui
→
src/platform/qt/SettingsView.ui
@@ -586,21 +586,21 @@ <bool>true</bool>
</property> </widget> </item> - <item row="13" column="1"> + <item row="14" column="1"> <widget class="QCheckBox" name="useDiscordPresence"> <property name="text"> <string>Enable Discord Rich Presence</string> </property> </widget> </item> - <item row="14" column="0" colspan="2"> + <item row="15" column="0" colspan="2"> <widget class="Line" name="line_13"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="15" column="1"> + <item row="16" column="1"> <widget class="QCheckBox" name="autosave"> <property name="text"> <string>Automatically save state</string>@@ -610,7 +610,7 @@ <bool>true</bool>
</property> </widget> </item> - <item row="16" column="1"> + <item row="17" column="1"> <widget class="QCheckBox" name="autoload"> <property name="text"> <string>Automatically load state</string>@@ -620,14 +620,14 @@ <bool>true</bool>
</property> </widget> </item> - <item row="17" column="0" colspan="2"> + <item row="18" column="0" colspan="2"> <widget class="Line" name="line_16"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> - <item row="18" column="1"> + <item row="19" column="1"> <widget class="QCheckBox" name="cheatAutosave"> <property name="text"> <string>Automatically save cheats</string>@@ -637,7 +637,7 @@ <bool>true</bool>
</property> </widget> </item> - <item row="19" column="1"> + <item row="20" column="1"> <widget class="QCheckBox" name="cheatAutoload"> <property name="text"> <string>Automatically load cheats</string>@@ -647,10 +647,20 @@ <bool>true</bool>
</property> </widget> </item> - <item row="12" column="1"> + <item row="13" column="1"> <widget class="QCheckBox" name="showOSD"> <property name="text"> <string>Show OSD messages</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="12" column="1"> + <widget class="QCheckBox" name="showFilename"> + <property name="text"> + <string>Show filename instead of ROM name in title bar</string> </property> <property name="checked"> <bool>true</bool>
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -1030,18 +1030,25 @@ CoreController::Interrupter interrupter(m_controller);
const NoIntroDB* db = GBAApp::app()->gameDB(); NoIntroGame game{}; uint32_t crc32 = 0; - m_controller->thread()->core->checksum(m_controller->thread()->core, &crc32, CHECKSUM_CRC32); + mCore* core = m_controller->thread()->core; + core->checksum(m_controller->thread()->core, &crc32, CHECKSUM_CRC32); + QString filePath = windowFilePath(); - char gameTitle[17] = { '\0' }; - mCore* core = m_controller->thread()->core; - core->getGameTitle(core, gameTitle); - title = gameTitle; + if (m_config->getOption("showFilename").toInt() && !filePath.isNull()) { + QFileInfo fileInfo(filePath); + title = fileInfo.fileName(); + } else { + char gameTitle[17] = { '\0' }; + core->getGameTitle(core, gameTitle); + title = gameTitle; #ifdef USE_SQLITE3 - if (db && crc32 && NoIntroDBLookupGameByCRC(db, crc32, &game)) { - title = QLatin1String(game.name); + if (db && crc32 && NoIntroDBLookupGameByCRC(db, crc32, &game)) { + title = QLatin1String(game.name); + } +#endif } -#endif + MultiplayerController* multiplayer = m_controller->multiplayerController(); if (multiplayer && multiplayer->attached() > 1) { title += tr(" - Player %1 of %2").arg(multiplayer->playerId(m_controller.get()) + 1).arg(multiplayer->attached());