From 0230e654a30643c9035007adc3fb323a12405885 Mon Sep 17 00:00:00 2001 From: Mathew Horner Date: Wed, 24 Jun 2020 01:20:42 -0500 Subject: [PATCH] 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 --- CHANGES | 1 + src/platform/qt/SettingsView.cpp | 2 ++ src/platform/qt/SettingsView.ui | 26 ++++++++++++++++++-------- src/platform/qt/Window.cpp | 23 +++++++++++++++-------- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index ce92bd976..76087f076 100644 --- a/CHANGES +++ b/CHANGES @@ -36,6 +36,7 @@ Misc: - 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: diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index 510528a12..4eb99c55e 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -400,6 +400,7 @@ void SettingsView::updateConfig() { 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 @@ void SettingsView::reloadConfig() { 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); diff --git a/src/platform/qt/SettingsView.ui b/src/platform/qt/SettingsView.ui index 0847639a7..0dfb884d2 100644 --- a/src/platform/qt/SettingsView.ui +++ b/src/platform/qt/SettingsView.ui @@ -586,21 +586,21 @@ - + Enable Discord Rich Presence - + Qt::Horizontal - + Automatically save state @@ -610,7 +610,7 @@ - + Automatically load state @@ -620,14 +620,14 @@ - + Qt::Horizontal - + Automatically save cheats @@ -637,7 +637,7 @@ - + Automatically load cheats @@ -647,7 +647,7 @@ - + Show OSD messages @@ -657,6 +657,16 @@ + + + + Show filename instead of ROM name in title bar + + + true + + + diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 8b0b6e2c3..c139ebf31 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -1030,18 +1030,25 @@ void Window::updateTitle(float fps) { const NoIntroDB* db = GBAApp::app()->gameDB(); NoIntroGame game{}; uint32_t crc32 = 0; - m_controller->thread()->core->checksum(m_controller->thread()->core, &crc32, CHECKSUM_CRC32); - - char gameTitle[17] = { '\0' }; mCore* core = m_controller->thread()->core; - core->getGameTitle(core, gameTitle); - title = gameTitle; + core->checksum(m_controller->thread()->core, &crc32, CHECKSUM_CRC32); + QString filePath = windowFilePath(); + + 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 + } + 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());