#include "intent_open_local_deck.h" #include "../deck_loader/deck_file_format.h" #include "../deck_loader/deck_loader.h" #include "../widgets/tabs/tab_supervisor.h" #include "intent_wait_for_database_load.h" #include IntentOpenLocalDeck::IntentOpenLocalDeck(TabSupervisor *_tabSupervisor, const QString &_file) : Intent(), tabSupervisor(_tabSupervisor), file(_file) { } bool IntentOpenLocalDeck::checkPrecondition() const { return CardDatabaseManager::getInstance()->getLoadStatus() == LoadStatus::Ok; } void IntentOpenLocalDeck::onPreconditionSatisfied() { std::optional deckOpt = DeckLoader::loadFromFile(file, DeckFileFormat::getFormatFromName(file), true); if (deckOpt) { tabSupervisor->openDeckInNewTab(deckOpt.value()); emitFinished(); } else { emitFailed(tr("Unable to load deck file %1").arg(file)); } } void IntentOpenLocalDeck::onPreconditionNotSatisfied() { runDependency(new IntentWaitForDatabaseLoad); }