mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-23 10:35:03 +00:00
added recentFiles save/load
This commit is contained in:
parent
1437c5a1de
commit
c9a117c95c
@ -83,7 +83,6 @@ std::filesystem::path settings_addon_install_dir = {};
|
||||
std::filesystem::path save_data_path = {};
|
||||
u32 mw_themes = 0;
|
||||
std::vector<std::string> m_elf_viewer;
|
||||
std::vector<std::string> m_recent_files;
|
||||
std::string emulator_language = "en_US";
|
||||
static bool isFullscreen = false;
|
||||
static std::string fullscreenMode = "Windowed";
|
||||
@ -493,11 +492,6 @@ void setElfViewer(const std::vector<std::string>& elfList) {
|
||||
m_elf_viewer = elfList;
|
||||
}
|
||||
|
||||
void setRecentFiles(const std::vector<std::string>& recentFiles) {
|
||||
m_recent_files.resize(recentFiles.size());
|
||||
m_recent_files = recentFiles;
|
||||
}
|
||||
|
||||
void setEmulatorLanguage(std::string language) {
|
||||
emulator_language = language;
|
||||
}
|
||||
@ -551,10 +545,6 @@ std::vector<std::string> getElfViewer() {
|
||||
return m_elf_viewer;
|
||||
}
|
||||
|
||||
std::vector<std::string> getRecentFiles() {
|
||||
return m_recent_files;
|
||||
}
|
||||
|
||||
std::string getEmulatorLanguage() {
|
||||
return emulator_language;
|
||||
}
|
||||
@ -694,7 +684,6 @@ void load(const std::filesystem::path& path) {
|
||||
|
||||
settings_addon_install_dir = toml::find_fs_path_or(gui, "addonInstallDir", {});
|
||||
m_elf_viewer = toml::find_or<std::vector<std::string>>(gui, "elfDirs", {});
|
||||
m_recent_files = toml::find_or<std::vector<std::string>>(gui, "recentFiles", {});
|
||||
emulator_language = toml::find_or<std::string>(gui, "emulatorLanguage", "en_US");
|
||||
}
|
||||
|
||||
@ -892,7 +881,6 @@ void saveMainWindow(const std::filesystem::path& path) {
|
||||
|
||||
data["GUI"]["theme"] = mw_themes;
|
||||
data["GUI"]["elfDirs"] = m_elf_viewer;
|
||||
data["GUI"]["recentFiles"] = m_recent_files;
|
||||
|
||||
// Sorting of TOML sections
|
||||
sortTomlSections(data);
|
||||
|
@ -139,7 +139,6 @@ const std::vector<bool> getGameInstallDirsEnabled();
|
||||
std::filesystem::path getAddonInstallDir();
|
||||
u32 getMainWindowTheme();
|
||||
std::vector<std::string> getElfViewer();
|
||||
std::vector<std::string> getRecentFiles();
|
||||
std::string getEmulatorLanguage();
|
||||
|
||||
void setDefaultValues();
|
||||
|
@ -17,6 +17,8 @@ const QString game_grid = "game_grid";
|
||||
const gui_value gen_checkForUpdates = gui_value(general_settings, "checkForUpdates", false);
|
||||
const gui_value gen_showChangeLog = gui_value(general_settings, "showChangeLog", false);
|
||||
const gui_value gen_updateChannel = gui_value(general_settings, "updateChannel", "Release");
|
||||
const gui_value gen_recentFiles =
|
||||
gui_value(main_window, "recentFiles", QVariant::fromValue(QList<QString>()));
|
||||
|
||||
// main window settings
|
||||
const gui_value mw_geometry = gui_value(main_window, "geometry", QByteArray());
|
||||
|
@ -1122,33 +1122,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);
|
||||
}
|
||||
|
@ -75,3 +75,17 @@ void settings::SetValue(const QString& key, const QString& name, const QVariant&
|
||||
}
|
||||
}
|
||||
}
|
||||
QVariant settings::List2Var(const QList<QString>& list) {
|
||||
QByteArray ba;
|
||||
QDataStream stream(&ba, QIODevice::WriteOnly);
|
||||
stream << list;
|
||||
return QVariant(ba);
|
||||
}
|
||||
|
||||
QList<QString> settings::Var2List(const QVariant& var) {
|
||||
QList<QString> list;
|
||||
QByteArray ba = var.toByteArray();
|
||||
QDataStream stream(&ba, QIODevice::ReadOnly);
|
||||
stream >> list;
|
||||
return list;
|
||||
}
|
@ -35,6 +35,8 @@ public:
|
||||
|
||||
QVariant GetValue(const QString& key, const QString& name, const QVariant& def) const;
|
||||
QVariant GetValue(const gui_value& entry) const;
|
||||
static QVariant List2Var(const QList<QString>& list);
|
||||
static QList<QString> Var2List(const QVariant& var);
|
||||
|
||||
public Q_SLOTS:
|
||||
/** Remove entry */
|
||||
|
Loading…
Reference in New Issue
Block a user