diff --git a/src/blackcore/db/databaseutils.cpp b/src/blackcore/db/databaseutils.cpp index 9c833b293..d0aa87b11 100644 --- a/src/blackcore/db/databaseutils.cpp +++ b/src/blackcore/db/databaseutils.cpp @@ -292,14 +292,14 @@ namespace BlackCore return c; } - CAircraftModelList CDatabaseUtils::updateSimulatorForFsFamily(const CAircraftModelList &ownModels, int maxToStash, IProgressIndicator *progressIndicator, bool processEvents) + CAircraftModelList CDatabaseUtils::updateSimulatorForFsFamily(const CAircraftModelList &ownModels, CStatusMessageList *updateInfo, int maxToStash, IProgressIndicator *progressIndicator, bool processEvents) { - if (!sApp || !sApp->getWebDataServices()) { return CAircraftModelList(); } - CAircraftModelList dbFsFamilyModels(sApp->getWebDataServices()->getModels().getAllFsFamilyModels()); + if (!sApp || !sApp->getWebDataServices() || sApp->isShuttingDown()) { return CAircraftModelList(); } + const CAircraftModelList dbFsFamilyModels(sApp->getWebDataServices()->getModels().getAllFsFamilyModels()); CAircraftModelList stashModels; if (dbFsFamilyModels.isEmpty() || ownModels.isEmpty()) { return stashModels; } const QSet dbKeys = dbFsFamilyModels.getModelStringSet(); - const int maxModelsCount = maxToStash >= 0 ? maxToStash : ownModels.size(); + const int maxModelsCount = (maxToStash >= 0) ? maxToStash : ownModels.size(); if (maxModelsCount < 1) { return stashModels; } int c = 0; // counter @@ -322,21 +322,31 @@ namespace BlackCore } // values to be skipped - if (maxToStash >= 0 && maxToStash == stashModels.size()) { break; } + if (maxToStash >= 0 && stashModels.size() > maxToStash) { break; } if (!dbKeys.contains(ownModel.getModelString())) { continue; } if (ownModel.matchesSimulatorFlag(CSimulatorInfo::XPLANE)) { continue; } // in DB CAircraftModel dbModel = dbFsFamilyModels.findFirstByModelStringOrDefault(ownModel.getModelString()); - if (!dbModel.isLoadedFromDb()) {continue; } - if (dbModel.getSimulator() == ownModel.getSimulator()) { continue; } + if (!dbModel.isLoadedFromDb()) { continue; } // update simulator and add CSimulatorInfo simulator(dbModel.getSimulator()); - simulator.add(ownModel.getSimulator()); + const CSimulatorInfo dbModelSimulator(simulator); + const CSimulatorInfo delta = simulator.add(ownModel.getSimulator()); + if (delta.getSimulator() == CSimulatorInfo::None) { continue; } + dbModel.setSimulator(simulator); - stashModels.push_back(dbModel); + stashModels.push_back(dbModel); // changed DB model + if (updateInfo) + { + const CStatusMessage m = CStatusMessage(getLogCategories()).info("%1 -> %2 (%3) for '%4'") + << dbModelSimulator.toQString(true) << simulator.toQString(true) + << delta.toQString(true) << dbModel.getModelStringAndDbKey(); + updateInfo->push_back(m); + } } + progressIndicator->updateProgressIndicatorAndProcessEvents(100); return stashModels; } diff --git a/src/blackcore/db/databaseutils.h b/src/blackcore/db/databaseutils.h index 9d0cadbf2..569d8d850 100644 --- a/src/blackcore/db/databaseutils.h +++ b/src/blackcore/db/databaseutils.h @@ -71,7 +71,7 @@ namespace BlackCore static int fillInMissingAircraftAndLiveryEntities(BlackMisc::Simulation::CAircraftModelList &models); //! Create stash models if the DB models miss that simulator - static BlackMisc::Simulation::CAircraftModelList updateSimulatorForFsFamily(const BlackMisc::Simulation::CAircraftModelList &ownModels, int maxToStash = -1, BlackCore::IProgressIndicator *progressIndicator = nullptr, bool processEvents = true); + static BlackMisc::Simulation::CAircraftModelList updateSimulatorForFsFamily(const BlackMisc::Simulation::CAircraftModelList &ownModels, BlackMisc::CStatusMessageList *updateInfo, int maxToStash = -1, BlackCore::IProgressIndicator *progressIndicator = nullptr, bool processEvents = true); //! Database JSON from content string, which can be compressed static QJsonDocument databaseJsonToQJsonDocument(const QString &content); diff --git a/src/blackgui/components/dbautosimulatorstashingcomponent.cpp b/src/blackgui/components/dbautosimulatorstashingcomponent.cpp index f73ee6387..289c21462 100644 --- a/src/blackgui/components/dbautosimulatorstashingcomponent.cpp +++ b/src/blackgui/components/dbautosimulatorstashingcomponent.cpp @@ -97,7 +97,7 @@ namespace BlackGui } else { - int selected = this->currentModelView()->selectedRowCount(); + const int selected = this->currentModelView()->selectedRowCount(); ui->le_Selected->setText(QString::number(selected)); } } @@ -108,6 +108,15 @@ namespace BlackGui ui->tvp_StatusMessages->insert(msg); } + void CDbAutoSimulatorStashingComponent::addStatusMessages(const CStatusMessageList &msgs) + { + if (msgs.isEmpty()) { return; } + for (const CStatusMessage &msg : msgs) + { + this->addStatusMessage(msg); + } + } + void CDbAutoSimulatorStashingComponent::addStatusMessage(const CStatusMessage &msg, const CAircraftModel &model) { if (msg.isEmpty()) { return; } @@ -139,13 +148,14 @@ namespace BlackGui const bool selected = ui->rb_SelectedOnly->isChecked(); int ownModelsCount = 0; + CStatusMessageList info; if (selected) { static const QString intro("Checking %1 selected models"); const CAircraftModelList selectedModels(this->currentModelView()->selectedObjects()); ownModelsCount = selectedModels.size(); this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, intro.arg(ownModelsCount))); - m_modelsToStash = CDatabaseUtils::updateSimulatorForFsFamily(selectedModels, maxObjectsStashed, this, true); + m_modelsToStash = CDatabaseUtils::updateSimulatorForFsFamily(selectedModels, &info, maxObjectsStashed, this, true); } else { @@ -160,10 +170,12 @@ namespace BlackGui const QString sim = simulator.toQString(); ownModelsCount += ownModels.size(); this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, intro.arg(ownModels.size()).arg(sim))); - m_modelsToStash.push_back(CDatabaseUtils::updateSimulatorForFsFamily(ownModels, maxObjectsStashed, this, true)); + m_modelsToStash.push_back(CDatabaseUtils::updateSimulatorForFsFamily(ownModels, &info, maxObjectsStashed, this, true)); } } + const QString result("Tested %1 own models, %2 models should be updated in DB"); + this->addStatusMessages(info); this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, result.arg(ownModelsCount).arg(m_modelsToStash.size()))); m_state = Completed; } diff --git a/src/blackgui/components/dbautosimulatorstashingcomponent.h b/src/blackgui/components/dbautosimulatorstashingcomponent.h index e8e479de8..9089a4891 100644 --- a/src/blackgui/components/dbautosimulatorstashingcomponent.h +++ b/src/blackgui/components/dbautosimulatorstashingcomponent.h @@ -76,6 +76,9 @@ namespace BlackGui //! Add a status message void addStatusMessage(const BlackMisc::CStatusMessage &msg); + //! Add a status messages + void addStatusMessages(const BlackMisc::CStatusMessageList &msgs); + //! Add a status message for a given model (prefixed) void addStatusMessage(const BlackMisc::CStatusMessage &msg, const BlackMisc::Simulation::CAircraftModel &model);