Added a clear button to the metadata editor.

This commit is contained in:
Leon Styhre 2020-09-27 10:41:00 +02:00
parent 08a2602fe2
commit 0946988fdb
3 changed files with 65 additions and 82 deletions

View file

@ -265,49 +265,45 @@ void GuiGamelistOptions::openMetaDataEd()
p.game = file;
p.system = file->getSystem();
std::function<void()> clearGameBtnFunc;
std::function<void()> deleteGameBtnFunc;
std::function<void()> 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<MetaDataDecl>& 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<MetaDataDecl>& 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));
}
}

View file

@ -39,8 +39,8 @@ GuiMetaDataEd::GuiMetaDataEd(
ScraperSearchParams scraperParams,
const std::string& /*header*/,
std::function<void()> saveCallback,
std::function<void()> deleteGameFunc,
std::function<void()> deleteMediaFunc)
std::function<void()> clearGameFunc,
std::function<void()> 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<ButtonComponent>(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<ButtonComponent>(mWindow, "DELETE MEDIA",
"delete game", deleteMediaBtnFunc));
"YES", clearSelf, "NO", nullptr)); };
buttons.push_back(std::make_shared<ButtonComponent>(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<ButtonComponent>(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<ButtonComponent>(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<ButtonComponent>(mWindow, "DELETE MEDIA",
"delete game", deleteMediaBtnFunc));
}
}
mButtons = makeButtonGrid(mWindow, buttons);

View file

@ -30,8 +30,8 @@ public:
ScraperSearchParams params,
const std::string& header,
std::function<void()> savedCallback,
std::function<void()> deleteGameFunc,
std::function<void()> deleteMediaFunc);
std::function<void()> clearGameFunc,
std::function<void()> deleteGameFunc);
bool input(InputConfig* config, Input input) override;
void onSizeChanged() override;
@ -61,8 +61,8 @@ private:
std::vector<MetaDataDecl> mMetaDataDecl;
MetaDataList* mMetaData;
std::function<void()> mSavedCallback;
std::function<void()> mClearGameFunc;
std::function<void()> mDeleteGameFunc;
std::function<void()> mDeleteMediaFunc;
bool mMediaFilesUpdated;
};