QT save fixes II (#3119)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / linux-sdl-gcc (push) Blocked by required conditions
Build and Release / linux-qt-gcc (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions

* added recentFiles save/load

* gui language

* fixups for language

* fixed language issue with savedata (it was saving based on gui language and not on console language)

* clang fix

* elf dirs added

* added theme
This commit is contained in:
georgemoralis 2025-06-20 12:28:32 +03:00 committed by GitHub
parent 423254692a
commit 43321fb45a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 188 additions and 266 deletions

View file

@ -39,8 +39,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
MainWindow::~MainWindow() {
SaveWindowState();
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
Config::saveMainWindow(config_dir / "config.toml");
}
bool MainWindow::Init() {
@ -297,7 +295,7 @@ void MainWindow::CreateDockWindows() {
m_game_list_frame->setObjectName("gamelist");
m_game_grid_frame.reset(new GameGridFrame(m_gui_settings, m_game_info, m_compat_info, this));
m_game_grid_frame->setObjectName("gamegridlist");
m_elf_viewer.reset(new ElfViewer(this));
m_elf_viewer.reset(new ElfViewer(m_gui_settings, this));
m_elf_viewer->setObjectName("elflist");
int table_mode = m_gui_settings->GetValue(gui::gl_mode).toInt();
@ -492,7 +490,7 @@ void MainWindow::CreateConnects() {
#endif
connect(ui->aboutAct, &QAction::triggered, this, [this]() {
auto aboutDialog = new AboutDialog(this);
auto aboutDialog = new AboutDialog(m_gui_settings, this);
aboutDialog->exec();
});
@ -771,14 +769,14 @@ void MainWindow::CreateConnects() {
QString gameName = QString::fromStdString(firstGame.name);
TrophyViewer* trophyViewer =
new TrophyViewer(trophyPath, gameTrpPath, gameName, allTrophyGames);
new TrophyViewer(m_gui_settings, trophyPath, gameTrpPath, gameName, allTrophyGames);
trophyViewer->show();
});
// Themes
connect(ui->setThemeDark, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Dark, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Dark));
m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Dark));
if (isIconBlack) {
SetUiIcons(false);
isIconBlack = false;
@ -786,7 +784,7 @@ void MainWindow::CreateConnects() {
});
connect(ui->setThemeLight, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Light, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Light));
m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Light));
if (!isIconBlack) {
SetUiIcons(true);
isIconBlack = true;
@ -794,7 +792,7 @@ void MainWindow::CreateConnects() {
});
connect(ui->setThemeGreen, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Green, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Green));
m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Green));
if (isIconBlack) {
SetUiIcons(false);
isIconBlack = false;
@ -802,7 +800,7 @@ void MainWindow::CreateConnects() {
});
connect(ui->setThemeBlue, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Blue, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Blue));
m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Blue));
if (isIconBlack) {
SetUiIcons(false);
isIconBlack = false;
@ -810,7 +808,7 @@ void MainWindow::CreateConnects() {
});
connect(ui->setThemeViolet, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Violet, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Violet));
m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Violet));
if (isIconBlack) {
SetUiIcons(false);
isIconBlack = false;
@ -818,7 +816,7 @@ void MainWindow::CreateConnects() {
});
connect(ui->setThemeGruvbox, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Gruvbox, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Gruvbox));
m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Gruvbox));
if (isIconBlack) {
SetUiIcons(false);
isIconBlack = false;
@ -826,7 +824,7 @@ void MainWindow::CreateConnects() {
});
connect(ui->setThemeTokyoNight, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::TokyoNight, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::TokyoNight));
m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::TokyoNight));
if (isIconBlack) {
SetUiIcons(false);
isIconBlack = false;
@ -834,7 +832,7 @@ void MainWindow::CreateConnects() {
});
connect(ui->setThemeOled, &QAction::triggered, &m_window_themes, [this]() {
m_window_themes.SetWindowTheme(Theme::Oled, ui->mw_searchbar);
Config::setMainWindowTheme(static_cast<int>(Theme::Oled));
m_gui_settings->SetValue(gui::gen_theme, static_cast<int>(Theme::Oled));
if (isIconBlack) {
SetUiIcons(false);
isIconBlack = false;
@ -981,7 +979,7 @@ void MainWindow::InstallDirectory() {
}
void MainWindow::SetLastUsedTheme() {
Theme lastTheme = static_cast<Theme>(Config::getMainWindowTheme());
Theme lastTheme = static_cast<Theme>(m_gui_settings->GetValue(gui::gen_theme).toInt());
m_window_themes.SetWindowTheme(lastTheme, ui->mw_searchbar);
switch (lastTheme) {
@ -1122,33 +1120,32 @@ void MainWindow::HandleResize(QResizeEvent* event) {
}
void MainWindow::AddRecentFiles(QString filePath) {
std::vector<std::string> vec = Config::getRecentFiles();
if (!vec.empty()) {
if (filePath.toStdString() == vec.at(0)) {
QList<QString> list = gui_settings::Var2List(m_gui_settings->GetValue(gui::gen_recentFiles));
if (!list.empty()) {
if (filePath == list.at(0)) {
return;
}
auto it = std::find(vec.begin(), vec.end(), filePath.toStdString());
if (it != vec.end()) {
vec.erase(it);
auto it = std::find(list.begin(), list.end(), filePath);
if (it != list.end()) {
list.erase(it);
}
}
vec.insert(vec.begin(), filePath.toStdString());
if (vec.size() > 6) {
vec.pop_back();
list.insert(list.begin(), filePath);
if (list.size() > 6) {
list.pop_back();
}
Config::setRecentFiles(vec);
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
Config::saveMainWindow(config_dir / "config.toml");
m_gui_settings->SetValue(gui::gen_recentFiles, gui_settings::List2Var(list));
CreateRecentGameActions(); // Refresh the QActions.
}
void MainWindow::CreateRecentGameActions() {
m_recent_files_group = new QActionGroup(this);
ui->menuRecent->clear();
std::vector<std::string> vec = Config::getRecentFiles();
for (int i = 0; i < vec.size(); i++) {
QList<QString> list = gui_settings::Var2List(m_gui_settings->GetValue(gui::gen_recentFiles));
for (int i = 0; i < list.size(); i++) {
QAction* recentFileAct = new QAction(this);
recentFileAct->setText(QString::fromStdString(vec.at(i)));
recentFileAct->setText(list.at(i));
ui->menuRecent->addAction(recentFileAct);
m_recent_files_group->addAction(recentFileAct);
}
@ -1165,7 +1162,7 @@ void MainWindow::CreateRecentGameActions() {
}
void MainWindow::LoadTranslation() {
auto language = QString::fromStdString(Config::getEmulatorLanguage());
auto language = m_gui_settings->GetValue(gui::gen_guiLanguage).toString();
const QString base_dir = QStringLiteral(":/translations");
QString base_path = QStringLiteral("%1/%2.qm").arg(base_dir).arg(language);
@ -1190,8 +1187,8 @@ void MainWindow::LoadTranslation() {
}
}
void MainWindow::OnLanguageChanged(const std::string& locale) {
Config::setEmulatorLanguage(locale);
void MainWindow::OnLanguageChanged(const QString& locale) {
m_gui_settings->SetValue(gui::gen_guiLanguage, locale);
LoadTranslation();
}