From 806a8a7f3299c3d137c0abe0249226b7aa65a680 Mon Sep 17 00:00:00 2001 From: Michael M Date: Fri, 9 Jun 2017 13:00:19 -0700 Subject: [PATCH] MappingWindow: store profile filename in QComboBox userdata --- .../Config/Mapping/MappingWindow.cpp | 52 +++++++++---------- Source/Core/DolphinQt2/Settings.cpp | 27 ---------- Source/Core/DolphinQt2/Settings.h | 3 -- 3 files changed, 24 insertions(+), 58 deletions(-) diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingWindow.cpp b/Source/Core/DolphinQt2/Config/Mapping/MappingWindow.cpp index fe1706f7c0..7e83e0e4ae 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingWindow.cpp +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingWindow.cpp @@ -13,8 +13,10 @@ #include "DolphinQt2/Config/Mapping/MappingWindow.h" +#include "Common/FileSearch.h" #include "Common/FileUtil.h" #include "Common/IniFile.h" +#include "Common/StringUtil.h" #include "Core/Core.h" #include "DolphinQt2/Config/Mapping/GCKeyboardEmu.h" #include "DolphinQt2/Config/Mapping/GCPadEmu.h" @@ -132,14 +134,14 @@ void MappingWindow::ConnectWidgets() void MappingWindow::OnDeleteProfilePressed() { - auto& settings = Settings::Instance(); const QString profile_name = m_profiles_combo->currentText(); - if (!settings.GetProfiles(m_config).contains(profile_name)) + const QString profile_path = m_profiles_combo->currentData().toString(); + + if (!File::Exists(profile_path.toStdString())) { - QMessageBox error; + QMessageBox error(this); error.setIcon(QMessageBox::Critical); error.setText(tr("The profile '%1' does not exist").arg(profile_name)); - error.exec(); return; } @@ -158,32 +160,22 @@ void MappingWindow::OnDeleteProfilePressed() m_profiles_combo->removeItem(m_profiles_combo->currentIndex()); + File::Delete(profile_path.toStdString()); + QMessageBox result(this); - - std::string profile_path = settings.GetProfileINIPath(m_config, profile_name).toStdString(); - - File::CreateFullPath(profile_path); - - File::Delete(profile_path); - result.setIcon(QMessageBox::Information); result.setText(tr("Successfully deleted '%1'.").arg(profile_name)); } void MappingWindow::OnLoadProfilePressed() { - const QString profile_name = m_profiles_combo->currentText(); + const QString profile_path = m_profiles_combo->currentData().toString(); - if (profile_name.isEmpty()) + if (m_profiles_combo->currentIndex() == 0) return; - std::string profile_path = - Settings::Instance().GetProfileINIPath(m_config, profile_name).toStdString(); - - File::CreateFullPath(profile_path); - IniFile ini; - ini.Load(profile_path); + ini.Load(profile_path.toStdString()); m_controller->LoadConfig(ini.GetOrCreateSection("Profile")); m_controller->UpdateReferences(g_controller_interface); @@ -196,23 +188,21 @@ void MappingWindow::OnLoadProfilePressed() void MappingWindow::OnSaveProfilePressed() { const QString profile_name = m_profiles_combo->currentText(); + const QString profile_path = m_profiles_combo->currentData().toString(); if (profile_name.isEmpty()) return; - std::string profile_path = - Settings::Instance().GetProfileINIPath(m_config, profile_name).toStdString(); - - File::CreateFullPath(profile_path); + File::CreateFullPath(profile_path.toStdString()); IniFile ini; m_controller->SaveConfig(ini.GetOrCreateSection("Profile")); - ini.Save(profile_path); + ini.Save(profile_path.toStdString()); if (m_profiles_combo->currentIndex() == 0) { - m_profiles_combo->addItem(profile_name); + m_profiles_combo->addItem(profile_name, profile_path); m_profiles_combo->setCurrentIndex(m_profiles_combo->count() - 1); } } @@ -314,10 +304,16 @@ void MappingWindow::ChangeMappingType(MappingWindow::Type type) if (m_config) { m_controller = m_config->GetController(GetPort()); - m_profiles_combo->addItem(QStringLiteral("")); - for (const auto& item : Settings::Instance().GetProfiles(m_config)) - m_profiles_combo->addItem(item); + + const std::string profiles_path = + File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + m_config->GetProfileName(); + for (const auto& filename : Common::DoFileSearch({profiles_path}, {".ini"})) + { + std::string basename; + SplitPath(filename, nullptr, &basename, nullptr); + m_profiles_combo->addItem(QString::fromStdString(basename), QString::fromStdString(filename)); + } } SetLayoutComplex(type != Type::MAPPING_GCPAD_WIIU); diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index bf1a07ea03..53178baa16 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -8,7 +8,6 @@ #include "AudioCommon/AudioCommon.h" #include "Common/Config/Config.h" -#include "Common/FileSearch.h" #include "Common/FileUtil.h" #include "Common/StringUtil.h" #include "Core/ConfigManager.h" @@ -40,17 +39,6 @@ void Settings::SetThemeName(const QString& theme_name) emit ThemeChanged(); } -QString Settings::GetProfilesDir() const -{ - return QString::fromStdString(File::GetUserPath(D_CONFIG_IDX) + "Profiles/"); -} - -QString Settings::GetProfileINIPath(const InputConfig* config, const QString& name) const -{ - return GetProfilesDir() + QString::fromStdString(config->GetProfileName()) + QDir::separator() + - name + QStringLiteral(".ini"); -} - QStringList Settings::GetPaths() const { QStringList list; @@ -141,21 +129,6 @@ void Settings::DecreaseVolume(int volume) emit VolumeChanged(GetVolume()); } -QVector Settings::GetProfiles(const InputConfig* config) const -{ - const std::string path = GetProfilesDir().toStdString() + config->GetProfileName(); - QVector vec; - - for (const auto& file : Common::DoFileSearch({path}, {".ini"})) - { - std::string basename; - SplitPath(file, nullptr, &basename, nullptr); - vec.push_back(QString::fromStdString(basename)); - } - - return vec; -} - bool Settings::IsLogVisible() const { return QSettings().value(QStringLiteral("logging/logvisible")).toBool(); diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index 56be9df511..4177fe6b77 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -40,9 +40,6 @@ public: // UI void SetThemeName(const QString& theme_name); - QString GetProfilesDir() const; - QVector GetProfiles(const InputConfig* config) const; - QString GetProfileINIPath(const InputConfig* config, const QString& name) const; bool IsInDevelopmentWarningEnabled() const; bool IsLogVisible() const;