From ea5a38faa40bb845eb081f814302164aa6707e71 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 17 Jul 2018 18:58:42 +0200 Subject: [PATCH] Ref T246, data can also be loaded from resource files --- .../components/dbloadoverviewcomponent.cpp | 23 +++++- .../components/dbloadoverviewcomponent.h | 8 +- .../components/dbloadoverviewcomponent.ui | 75 ++++++++++++++++++- .../components/initialdataloadcomponent.cpp | 2 +- src/blackgui/components/settingscomponent.cpp | 2 +- 5 files changed, 103 insertions(+), 7 deletions(-) diff --git a/src/blackgui/components/dbloadoverviewcomponent.cpp b/src/blackgui/components/dbloadoverviewcomponent.cpp index 4e1f58323..d0c0b9d1b 100644 --- a/src/blackgui/components/dbloadoverviewcomponent.cpp +++ b/src/blackgui/components/dbloadoverviewcomponent.cpp @@ -15,6 +15,9 @@ #include "blackgui/guiapplication.h" #include "blackmisc/network/networkutils.h" +#include +#include + using namespace BlackGui; using namespace BlackCore; using namespace BlackMisc; @@ -60,11 +63,17 @@ namespace BlackGui connect(ui->pb_LoadAllFromDB, &QPushButton::pressed, this, &CDbLoadOverviewComponent::loadAllFromDb); connect(ui->pb_LoadAllFromShared, &QPushButton::pressed, this, &CDbLoadOverviewComponent::loadAllFromShared); + connect(ui->pb_LoadAllFromResources, &QPushButton::pressed, this, &CDbLoadOverviewComponent::loadAllFromResourceFiles); if (sGui->hasWebDataServices()) { connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbLoadOverviewComponent::dataLoaded); - QTimer::singleShot(10 * 1000, this, &CDbLoadOverviewComponent::loadInfoObjects); + QPointer myself(this); + QTimer::singleShot(10 * 1000, this, [ = ] + { + if (!myself) { return; } + this->loadInfoObjects(); + }); } } @@ -110,12 +119,13 @@ namespace BlackGui QFrame::resizeEvent(event); } - void CDbLoadOverviewComponent::showVisibleLoadAllButtons(bool shared, bool db) + void CDbLoadOverviewComponent::showVisibleLoadAllButtons(bool shared, bool db, bool disk) { const bool widget = shared || db; ui->wi_LoadAllButtons->setVisible(widget); ui->pb_LoadAllFromDB->setVisible(db); ui->pb_LoadAllFromShared->setVisible(shared); + ui->pb_LoadAllFromResources->setVisible(disk); } void CDbLoadOverviewComponent::loadAllFromDb() @@ -128,6 +138,15 @@ namespace BlackGui this->triggerLoadingFromSharedFiles(CEntityFlags::AllDbEntitiesNoInfoObjects); } + void CDbLoadOverviewComponent::loadAllFromResourceFiles() + { + if (m_loadInProgress) { return; } + if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { return; } + const QMessageBox::StandardButton reply = QMessageBox::warning(this, "Load DB data", "You should only load DB from disk resources if loading from network does not work. Really load?", QMessageBox::Yes | QMessageBox::No); + if (reply != QMessageBox::Yes) { return; } + sGui->getWebDataServices()->initDbCachesFromLocalResourceFiles(true); + } + void CDbLoadOverviewComponent::setGuiValues() { if (!sGui) { return; } diff --git a/src/blackgui/components/dbloadoverviewcomponent.h b/src/blackgui/components/dbloadoverviewcomponent.h index f90b94c24..249ec1979 100644 --- a/src/blackgui/components/dbloadoverviewcomponent.h +++ b/src/blackgui/components/dbloadoverviewcomponent.h @@ -49,7 +49,7 @@ namespace BlackGui void showVisibleSharedRefreshButtons(bool visible); //! Show load all buttons - void showVisibleLoadAllButtons(bool shared, bool db); + void showVisibleLoadAllButtons(bool shared, bool db, bool disk); //! Load all from DB void loadAllFromDb(); @@ -57,6 +57,12 @@ namespace BlackGui //! Load all from shared void loadAllFromShared(); + //! Load all from disk (as of installation) + void loadAllFromResourceFiles(); + + //! Is loading in progress + bool isLoadInProgress() const { return m_loadInProgress; } + protected: //! \copydoc QWidget::resizeEvent virtual void resizeEvent(QResizeEvent *event) override; diff --git a/src/blackgui/components/dbloadoverviewcomponent.ui b/src/blackgui/components/dbloadoverviewcomponent.ui index 5a5caccc1..4da87fe3c 100644 --- a/src/blackgui/components/dbloadoverviewcomponent.ui +++ b/src/blackgui/components/dbloadoverviewcomponent.ui @@ -973,7 +973,7 @@ - load from shared + load from shared @@ -984,7 +984,7 @@ - load from DB + load from DB @@ -992,6 +992,17 @@ + + + + load from disk + + + + :/pastel/icons/pastel/16/disk.png:/pastel/icons/pastel/16/disk.png + + + @@ -1070,6 +1081,66 @@ + + tb_SharedReloadAircraft + tb_DbReloadAircraft + le_AircraftIcaoCacheCount + le_AircraftIcaoDbCount + le_AircraftIcaoSharedCount + le_AircraftIcaoCacheTs + le_AircraftIcaoDbTs + le_AircraftIcaoSharedFileTs + tb_SharedReloadAirlines + tb_DbReloadAirlines + le_AirlinesIcaoCacheCount + le_AirlinesIcaoDbCount + le_AirlinesIcaoSharedCount + le_AirlinesIcaoCacheTs + le_AirlinesIcaoDbTs + le_AirlinesIcaoSharedFileTs + tb_SharedReloadAirports + tb_DbReloadAirports + le_AirportsCacheCount + le_AirportsDbCount + le_AirportsSharedCount + le_AirportsCacheTs + le_AirportsDbTs + le_AirportsSharedFileTs + tb_SharedReloadLiveries + tb_DbReloadLiveries + le_LiveriesCacheCount + le_LiveriesDbCount + le_LiveriesSharedCount + le_LiveriesCacheTs + le_LiveriesDbTs + le_LiveriesSharedFileTs + tb_SharedReloadModels + tb_DbReloadModels + le_ModelsCacheCount + le_ModelsDbCount + le_ModelsSharedCount + le_ModelsCacheTs + le_ModelsDbTs + le_ModelsSharedFileTs + tb_SharedReloadCountries + tb_DbReloadCountries + le_CountriesCacheCount + le_CountriesDbCount + le_CountriesSharedCount + le_CountriesCacheTs + le_CountriesDbTs + le_CountriesSharedFileTs + tb_SharedReloadDistributors + tb_DbReloadDistributors + le_DistributorsCacheCount + le_DistributorsDbCount + le_DistributorsSharedCount + le_DistributorsCacheTs + le_DistributorsDbTs + le_DistributorsSharedFileTs + pb_LoadAllFromShared + pb_LoadAllFromDB + diff --git a/src/blackgui/components/initialdataloadcomponent.cpp b/src/blackgui/components/initialdataloadcomponent.cpp index 8cf5813bc..4ffed6e25 100644 --- a/src/blackgui/components/initialdataloadcomponent.cpp +++ b/src/blackgui/components/initialdataloadcomponent.cpp @@ -19,7 +19,7 @@ namespace BlackGui ui(new Ui::CInitialDataLoadComponent) { ui->setupUi(this); - ui->comp_DataUpdates->showVisibleLoadAllButtons(true, false); + ui->comp_DataUpdates->showVisibleLoadAllButtons(true, false, true); } CInitialDataLoadComponent::~CInitialDataLoadComponent() diff --git a/src/blackgui/components/settingscomponent.cpp b/src/blackgui/components/settingscomponent.cpp index 3c72dfbba..7e435c8f9 100644 --- a/src/blackgui/components/settingscomponent.cpp +++ b/src/blackgui/components/settingscomponent.cpp @@ -51,7 +51,7 @@ namespace BlackGui this->tabBar()->setUsesScrollButtons(true); this->setCurrentIndex(0); // 1st tab ui->comp_DataLoadOverview->showVisibleDbRefreshButtons(CBuildConfig::isDebugBuild() || sGui->isDeveloperFlagSet()); - ui->comp_DataLoadOverview->showVisibleLoadAllButtons(false, false); + ui->comp_DataLoadOverview->showVisibleLoadAllButtons(false, false, false); connect(ui->comp_SettingsGuiGeneral, &CSettingsGuiComponent::changedWindowsOpacity, this, &CSettingsComponent::changedWindowsOpacity); connect(ui->pb_Advanced, &QPushButton::released, this, &CSettingsComponent::onOverviewButtonClicked);