From 4814178961aecffde645decdd571d08e96365085 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 22 Aug 2018 21:02:30 +0200 Subject: [PATCH] Own models component message box if disk loaded models shall be written to cache --- .../components/dbownmodelscomponent.cpp | 23 +++++++++++++++---- .../components/dbownmodelscomponent.h | 8 ++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/blackgui/components/dbownmodelscomponent.cpp b/src/blackgui/components/dbownmodelscomponent.cpp index 932cd542d..09416e146 100644 --- a/src/blackgui/components/dbownmodelscomponent.cpp +++ b/src/blackgui/components/dbownmodelscomponent.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace BlackMisc; using namespace BlackMisc::Simulation; @@ -50,9 +51,10 @@ namespace BlackGui ui->tvp_OwnAircraftModels->setSimulatorForLoading(ui->comp_SimulatorSelector->getValue()); connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::requestUpdate, this, &CDbOwnModelsComponent::requestOwnModelsUpdate); + connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::jsonLoadCompleted, this, &CDbOwnModelsComponent::onViewDiskLoadingFinished, Qt::QueuedConnection); connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelsComponent::onSimulatorSelectorChanged); - connect(&CMultiAircraftModelLoaderProvider::multiModelLoaderInstance(), &CMultiAircraftModelLoaderProvider::loadingFinished, this, &CDbOwnModelsComponent::onOwnModelsLoadingFinished, Qt::QueuedConnection); - connect(&CMultiAircraftModelLoaderProvider::multiModelLoaderInstance(), &CMultiAircraftModelLoaderProvider::diskLoadingStarted, this, &CDbOwnModelsComponent::onOwnModelsDiskLoadingStarted, Qt::QueuedConnection); + connect(&CMultiAircraftModelLoaderProvider::multiModelLoaderInstance(), &CMultiAircraftModelLoaderProvider::loadingFinished, this, &CDbOwnModelsComponent::onModelLoaderLoadingFinished, Qt::QueuedConnection); + connect(&CMultiAircraftModelLoaderProvider::multiModelLoaderInstance(), &CMultiAircraftModelLoaderProvider::diskLoadingStarted, this, &CDbOwnModelsComponent::onModelLoaderDiskLoadingStarted, Qt::QueuedConnection); connect(&CMultiAircraftModelLoaderProvider::multiModelLoaderInstance(), &CMultiAircraftModelLoaderProvider::cacheChanged, this, &CDbOwnModelsComponent::onCacheChanged, Qt::QueuedConnection); // Last selection isPinned -> no sync needed @@ -511,13 +513,13 @@ namespace BlackGui m_modelLoader->startLoading(mode, static_cast(&CDatabaseUtils::consolidateModelsWithDbData), modelDirectories); } - void CDbOwnModelsComponent::onOwnModelsDiskLoadingStarted(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode) + void CDbOwnModelsComponent::onModelLoaderDiskLoadingStarted(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode) { const CStatusMessage msg = CLogMessage(this).info("Started disk loading for '%1' in mode '%2'") << simulator.toQString(true) << IAircraftModelLoader::enumToString(mode); this->showOverlayMessage(msg, 5000); } - void CDbOwnModelsComponent::onOwnModelsLoadingFinished(const CStatusMessageList &statusMessages, const CSimulatorInfo &simulator, IAircraftModelLoader::LoadFinishedInfo info) + void CDbOwnModelsComponent::onModelLoaderLoadingFinished(const CStatusMessageList &statusMessages, const CSimulatorInfo &simulator, IAircraftModelLoader::LoadFinishedInfo info) { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Expect single simulator"); if (statusMessages.isSuccess() && m_modelLoader) @@ -551,6 +553,19 @@ namespace BlackGui this->setSimulator(simulator); } + void CDbOwnModelsComponent::onViewDiskLoadingFinished(const CStatusMessage &status) + { + if (status.isFailure()) { return; } + QMessageBox msgBox(QMessageBox::Question, "Loaded models from disk", "Loaded models from disk file.\nSave to cache or just temporarily keep them?\n\nHint: Saving them will override the loaded models from the simulator.\nNormally you would not want that (cancel).", QMessageBox::Save | QMessageBox::Cancel, this); + msgBox.setDefaultButton(QMessageBox::Cancel); + const QMessageBox::StandardButton reply = static_cast(msgBox.exec()); + if (reply != QMessageBox::Cancel) { return; } + const CAircraftModelList models = ui->tvp_OwnAircraftModels->container(); + if (models.isEmpty()) { return; } + const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue(); + m_modelLoader->setModelsForSimulator(models, simulator); + } + void CDbOwnModelsComponent::onCacheChanged(const CSimulatorInfo &simulator) { const CAircraftModelList models(m_modelLoader->getCachedModels(simulator)); diff --git a/src/blackgui/components/dbownmodelscomponent.h b/src/blackgui/components/dbownmodelscomponent.h index de740b959..8db72d913 100644 --- a/src/blackgui/components/dbownmodelscomponent.h +++ b/src/blackgui/components/dbownmodelscomponent.h @@ -32,7 +32,6 @@ #include class QAction; -class QWidget; namespace Ui { class CDbOwnModelsComponent; } namespace BlackGui @@ -137,10 +136,13 @@ namespace BlackGui void loadInstalledModels(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode, const QStringList &modelDirectories = {}); //! On disk loading started - void onOwnModelsDiskLoadingStarted(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode); + void onModelLoaderDiskLoadingStarted(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode); //! Model loading finished - void onOwnModelsLoadingFinished(const BlackMisc::CStatusMessageList &statusMessages, const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadFinishedInfo info); + void onModelLoaderLoadingFinished(const BlackMisc::CStatusMessageList &statusMessages, const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadFinishedInfo info); + + //! Loading from disk (via view context menu) + void onViewDiskLoadingFinished(const BlackMisc::CStatusMessage &status); //! Cache has been changed void onCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);