From 0946988fdb902f34ca6d69c40acbab284fc687b0 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 27 Sep 2020 10:41:00 +0200 Subject: [PATCH] Added a clear button to the metadata editor. --- es-app/src/guis/GuiGamelistOptions.cpp | 72 ++++++++++++-------------- es-app/src/guis/GuiMetaDataEd.cpp | 69 ++++++++++-------------- es-app/src/guis/GuiMetaDataEd.h | 6 +-- 3 files changed, 65 insertions(+), 82 deletions(-) diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 9c2d4e40d..61cdfd4b2 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -265,49 +265,45 @@ void GuiGamelistOptions::openMetaDataEd() p.game = file; p.system = file->getSystem(); + std::function clearGameBtnFunc; std::function deleteGameBtnFunc; - std::function deleteMediaBtnFunc; - deleteMediaBtnFunc = [this, file] { - LOG(LogInfo) << "Deleting all game media files for '" << file->getFullPath() << "'."; - ViewController::get()->getGameListView( - file->getSystem()).get()->removeMedia(file); - }; - - if (file->getType() == FOLDER) { - deleteGameBtnFunc = [this, file] { + clearGameBtnFunc = [this, file] { + if (file->getType() == FOLDER) { LOG(LogInfo) << "Deleting the media files and gamelist.xml entry for the folder '" << file->getFullPath() << "'"; - ViewController::get()->getGameListView( - file->getSystem()).get()->removeMedia(file); + } + else { + LOG(LogInfo) << "Deleting the media files and gamelist.xml entry for the file '" << + file->getFullPath() << "'"; + } + ViewController::get()->getGameListView(file->getSystem()).get()->removeMedia(file); - // Manually reset all the metadata values, set the name to the actual folder name. - const std::vector& mdd = file->metadata.getMDD(); - for (auto it = mdd.cbegin(); it != mdd.cend(); it++) { - if (it->key == "name") { - file->metadata.set(it->key, file->getDisplayName()); - continue; - } - file->metadata.set(it->key, it->defaultValue); + // Manually reset all the metadata values, set the name to the actual file/folder name. + const std::vector& mdd = file->metadata.getMDD(); + for (auto it = mdd.cbegin(); it != mdd.cend(); it++) { + if (it->key == "name") { + file->metadata.set(it->key, file->getDisplayName()); + continue; } + file->metadata.set(it->key, it->defaultValue); + } - ViewController::get()->reloadGameListView(file->getParent()->getSystem()); - // Remove the folder entry from the gamelist.xml file. - file->setDeletionFlag(); - file->getParent()->getSystem()->writeMetaData(); - }; - } - else { - deleteGameBtnFunc = [this, file] { - LOG(LogInfo) << "Deleting the game file '" << file->getFullPath() << - "', all its media files and its gamelist.xml entry."; - CollectionSystemManager::get()->deleteCollectionFiles(file); - ViewController::get()->getGameListView( - file->getSystem()).get()->removeMedia(file); - ViewController::get()->getGameListView( - file->getSystem()).get()->remove(file, true); - }; - } + ViewController::get()->reloadGameListView(file->getParent()->getSystem()); + // Remove the folder entry from the gamelist.xml file. + file->setDeletionFlag(); + file->getParent()->getSystem()->writeMetaData(); + }; + + deleteGameBtnFunc = [this, file] { + LOG(LogInfo) << "Deleting the game file '" << file->getFullPath() << + "', all its media files and its gamelist.xml entry."; + CollectionSystemManager::get()->deleteCollectionFiles(file); + ViewController::get()->getGameListView( + file->getSystem()).get()->removeMedia(file); + ViewController::get()->getGameListView( + file->getSystem()).get()->remove(file, true); + }; if (file->getType() == FOLDER) { mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, @@ -315,7 +311,7 @@ void GuiGamelistOptions::openMetaDataEd() Utils::FileSystem::getFileName(file->getPath()), std::bind( &IGameListView::onFileChanged, ViewController::get()->getGameListView( file->getSystem()).get(), file, FILE_METADATA_CHANGED), - deleteGameBtnFunc, deleteMediaBtnFunc)); + clearGameBtnFunc, deleteGameBtnFunc)); } else { mWindow->pushGui(new GuiMetaDataEd(mWindow, &file->metadata, @@ -323,7 +319,7 @@ void GuiGamelistOptions::openMetaDataEd() Utils::FileSystem::getFileName(file->getPath()), std::bind( &IGameListView::onFileChanged, ViewController::get()->getGameListView( file->getSystem()).get(), file, FILE_METADATA_CHANGED), - deleteGameBtnFunc, deleteMediaBtnFunc)); + clearGameBtnFunc, deleteGameBtnFunc)); } } diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 898e6d8b3..4df039154 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -39,8 +39,8 @@ GuiMetaDataEd::GuiMetaDataEd( ScraperSearchParams scraperParams, const std::string& /*header*/, std::function saveCallback, - std::function deleteGameFunc, - std::function deleteMediaFunc) + std::function clearGameFunc, + std::function deleteGameFunc) : GuiComponent(window), mScraperParams(scraperParams), mBackground(window, ":/graphics/frame.png"), @@ -48,8 +48,8 @@ GuiMetaDataEd::GuiMetaDataEd( mMetaDataDecl(mdd), mMetaData(md), mSavedCallback(saveCallback), - mDeleteGameFunc(deleteGameFunc), - mDeleteMediaFunc(deleteMediaFunc) + mClearGameFunc(clearGameFunc), + mDeleteGameFunc(deleteGameFunc) { addChild(&mBackground); addChild(&mGrid); @@ -254,34 +254,35 @@ GuiMetaDataEd::GuiMetaDataEd( [&] { delete this; })); if (scraperParams.game->getType() == FOLDER) { - if (mDeleteGameFunc) { - auto deleteFilesAndSelf = [&] { mDeleteGameFunc(); delete this; }; - auto deleteGameBtnFunc = [this, deleteFilesAndSelf] { + if (mClearGameFunc) { + auto clearSelf = [&] { mClearGameFunc(); delete this; }; + auto clearSelfBtnFunc = [this, clearSelf] { mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(), - "THIS WILL DELETE THE MEDIA FILES AND\n" - "THE GAMELIST.XML ENTRY FOR THIS FOLDER.\n" - "HOWEVER NEITHER THE FOLDER ITSELF OR\n" - "ANY DATA FOR THE FILES INSIDE THE FOLDER\n" + "THIS WILL DELETE ANY MEDIA FILES AND\n" + "THE GAMELIST.XML ENTRY FOR THIS FOLDER,\n" + "BUT NEITHER THE FOLDER ITSELF OR ANY\n" + "DATA FOR THE FILES INSIDE THE FOLDER\n" "WILL BE DELETED. ARE YOU SURE?", - "YES", deleteFilesAndSelf, "NO", nullptr)); }; - buttons.push_back(std::make_shared(mWindow, "DELETE", - "delete game", deleteGameBtnFunc)); - } - - if (mDeleteMediaFunc) { - auto deleteFilesAndSelf = [&] { mDeleteMediaFunc(); delete this; }; - auto deleteMediaBtnFunc = [this, deleteFilesAndSelf] { - mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(), - "THIS WILL DELETE ALL THE MEDIA FILES\n" - "FOR THE ACTUAL FOLDER, BUT NO MEDIA\n" - "FOR ANY FILES INSIDE THE FOLDER WILL\n" - "BE DELETED. ARE YOU SURE?", - "YES", deleteFilesAndSelf, "NO", nullptr)); }; - buttons.push_back(std::make_shared(mWindow, "DELETE MEDIA", - "delete game", deleteMediaBtnFunc)); + "YES", clearSelf, "NO", nullptr)); }; + buttons.push_back(std::make_shared(mWindow, "CLEAR", + "clear folder", clearSelfBtnFunc)); } } else { + if (mClearGameFunc) { + auto clearSelf = [&] { mClearGameFunc(); delete this; }; + auto clearSelfBtnFunc = [this, clearSelf] { + mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(), + "THIS WILL DELETE ANY MEDIA FILES\n" + "AND THE GAMELIST.XML ENTRY FOR\n" + "THIS GAME FILE, BUT THE FILE ITSELF\n" + "WILL NOT BE REMOVED.\n" + "ARE YOU SURE?", + "YES", clearSelf, "NO", nullptr)); }; + buttons.push_back(std::make_shared(mWindow, "CLEAR", + "clear file", clearSelfBtnFunc)); + } + if (mDeleteGameFunc) { auto deleteFilesAndSelf = [&] { mDeleteGameFunc(); delete this; }; auto deleteGameBtnFunc = [this, deleteFilesAndSelf] { @@ -294,20 +295,6 @@ GuiMetaDataEd::GuiMetaDataEd( buttons.push_back(std::make_shared(mWindow, "DELETE", "delete game", deleteGameBtnFunc)); } - - if (mDeleteMediaFunc) { - auto deleteFilesAndSelf = [&] { mDeleteMediaFunc(); delete this; }; - auto deleteMediaBtnFunc = [this, deleteFilesAndSelf] { - mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(), - "THIS WILL DELETE ALL GAME\n" - "MEDIA FILES, BUT WILL KEEP\n" - "THE ACTUAL GAME FILE AND\n" - "THE GAMELIST.XML ENTRY.\n" - "ARE YOU SURE?", - "YES", deleteFilesAndSelf, "NO", nullptr)); }; - buttons.push_back(std::make_shared(mWindow, "DELETE MEDIA", - "delete game", deleteMediaBtnFunc)); - } } mButtons = makeButtonGrid(mWindow, buttons); diff --git a/es-app/src/guis/GuiMetaDataEd.h b/es-app/src/guis/GuiMetaDataEd.h index 8a4662271..036a85cf7 100644 --- a/es-app/src/guis/GuiMetaDataEd.h +++ b/es-app/src/guis/GuiMetaDataEd.h @@ -30,8 +30,8 @@ public: ScraperSearchParams params, const std::string& header, std::function savedCallback, - std::function deleteGameFunc, - std::function deleteMediaFunc); + std::function clearGameFunc, + std::function deleteGameFunc); bool input(InputConfig* config, Input input) override; void onSizeChanged() override; @@ -61,8 +61,8 @@ private: std::vector mMetaDataDecl; MetaDataList* mMetaData; std::function mSavedCallback; + std::function mClearGameFunc; std::function mDeleteGameFunc; - std::function mDeleteMediaFunc; bool mMediaFilesUpdated; };