refs #888, loadingFinished with CStatusMessage

This commit is contained in:
Klaus Basan
2017-02-24 21:14:08 +01:00
parent 8e55baaf85
commit 5a91f561be
6 changed files with 26 additions and 16 deletions

View File

@@ -439,10 +439,10 @@ namespace BlackGui
this->m_modelLoader->startLoading(mode, &CDatabaseUtils::consolidateModelsWithDbData, directory);
}
void CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished(bool success, const CSimulatorInfo &simulator)
void CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished(const CStatusMessage &status, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Expect single simulator");
if (success && this->m_modelLoader)
if (status.isSuccess() && this->m_modelLoader)
{
const CAircraftModelList models(this->m_modelLoader->getAircraftModels());
const int modelsLoaded = models.size();
@@ -456,7 +456,7 @@ namespace BlackGui
else
{
ui->tvp_OwnAircraftModels->clear();
CLogMessage(this).error("Loading of models failed, simulator %1") << simulator.toQString();
CLogMessage(this).error("Loading of models failed, simulator '%1', details: %2") << simulator.toQString() << status.getMessage();
}
ui->le_Simulator->setText(simulator.toQString());
ui->comp_SimulatorSelector->setValue(simulator);

View File

@@ -122,7 +122,7 @@ namespace BlackGui
void ps_loadInstalledModels(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode, const QString &directory = "");
//! Model loading finished
void ps_onOwnModelsLoadingFinished(bool success, const BlackMisc::Simulation::CSimulatorInfo &simulator);
void ps_onOwnModelsLoadingFinished(const BlackMisc::CStatusMessage &status, const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Request simulator models
void ps_requestSimulatorModels(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode, const QString &directory = "");

View File

@@ -63,8 +63,10 @@ namespace BlackMisc
}
}
void IAircraftModelLoader::ps_loadFinished(bool success)
void IAircraftModelLoader::ps_loadFinished(const CStatusMessage &status, const BlackMisc::Simulation::CSimulatorInfo &simulator)
{
// remark: in the past status used to be bool, now it is CStatusMessage
// so there is some redundancy here between status and m_loadingMessages
this->m_loadingInProgress = false;
if (this->m_loadingMessages.hasWarningOrErrorMessages())
{
@@ -72,13 +74,14 @@ namespace BlackMisc
}
else
{
CLogMessage(this).info("Loading finished, success %1") << boolToYesNo(success);
CLogMessage(this).info("Loading finished, success '%1' for '%2'") << status.getMessage() << simulator.toQString();
}
}
void IAircraftModelLoader::ps_cacheChanged(const CSimulatorInfo &simInfo)
{
emit this->loadingFinished(true, simInfo);
static const CStatusMessage status(this, CStatusMessage::SeverityInfo, "Cached changed");
emit this->loadingFinished(status, simInfo);
}
QStringList IAircraftModelLoader::getModelDirectoriesOrDefault() const
@@ -130,7 +133,8 @@ namespace BlackMisc
const bool useCachedData = !mode.testFlag(CacheSkipped) && this->hasCachedData();
if (useCachedData && (mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly)))
{
emit loadingFinished(true, this->getSimulator());
static const CStatusMessage status(this, CStatusMessage::SeverityInfo, "Using cached data");
emit loadingFinished(status, this->getSimulator());
return;
}
else if (useCachedData && mode.testFlag(CacheUntilNewer))
@@ -138,7 +142,8 @@ namespace BlackMisc
//! \todo currently too slow with remote files, does not make sense with that overhead
if (!this->areModelFilesUpdated())
{
emit loadingFinished(true, this->getSimulator());
static const CStatusMessage status(this, CStatusMessage::SeverityInfo, "No updated model files");
emit loadingFinished(status, this->getSimulator());
return;
}
}

View File

@@ -152,7 +152,7 @@ namespace BlackMisc
signals:
//! Parsing is finished or cache has been loaded
void loadingFinished(bool success, const BlackMisc::Simulation::CSimulatorInfo &simulator);
void loadingFinished(const BlackMisc::CStatusMessage &status, const BlackMisc::Simulation::CSimulatorInfo &simulator);
protected:
//! Constructor
@@ -178,7 +178,7 @@ namespace BlackMisc
protected slots:
//! Loading finished, also logs messages
void ps_loadFinished(bool success);
void ps_loadFinished(const CStatusMessage &status, const CSimulatorInfo &simulator);
//! A cache has been changed
void ps_cacheChanged(const CSimulatorInfo &simInfo);

View File

@@ -65,6 +65,9 @@ namespace BlackMisc
void CAircraftCfgParser::startLoadingFromDisk(LoadMode mode, const ModelConsolidation &modelConsolidation, const QString &directory)
{
static const CStatusMessage statusLoadingOk(this, CStatusMessage::SeverityInfo, "Aircraft config parser loaded data");
static const CStatusMessage statusLoadingError(this, CStatusMessage::SeverityError, "Aircraft config parser did not load data");
const CSimulatorInfo simulator = this->getSimulator();
const QString modelDirectory(!directory.isEmpty() ? directory : this->m_settings.getFirstModelDirectoryOrDefault(simulator)); // expect only one directory
const QStringList excludedDirectoryPatterns(this->m_settings.getModelExcludeDirectoryPatternsOrDefault(simulator)); // copy
@@ -100,11 +103,13 @@ namespace BlackMisc
this->setCachedModels(models, simulator); // not thread safe
}
// currently I treat no data as error
emit this->loadingFinished(hasData, simulator);
emit this->loadingFinished(hasData ? statusLoadingOk : statusLoadingError, simulator);
}
else
{
emit this->loadingFinished(false, simulator);
CStatusMessage status = this->m_loadingMessages.toSingleMessage();
status.setSeverity(CStatusMessage::SeverityError);
emit this->loadingFinished(status, simulator);
}
});
}
@@ -121,7 +126,7 @@ namespace BlackMisc
this->setCachedModels(models); // not thread safe
}
// currently I treat no data as error
emit this->loadingFinished(hasData, simulator);
emit this->loadingFinished(hasData ? statusLoadingOk : statusLoadingError, simulator);
}
}

View File

@@ -80,7 +80,7 @@ namespace BlackMisc
if (modelDirectory.isEmpty())
{
this->clearCache();
emit loadingFinished(false, simulator);
emit loadingFinished(CStatusMessage(this, CStatusMessage::SeverityError, "Model directory '%1' is empty") << modelDirectory, simulator);
return;
}
@@ -123,7 +123,7 @@ namespace BlackMisc
void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models)
{
this->setCachedModels(models);
emit loadingFinished(true, this->getSimulator());
emit loadingFinished(CStatusMessage(this, CStatusMessage::SeverityInfo, "Updated '%1' models") << models.size(), this->getSimulator());
}
QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const