mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T224, improved check of DB data availability in swift GUI
* some renamings * check for empty caches as well * using fixed timestamp checks * display info about loading objects
This commit is contained in:
@@ -112,6 +112,11 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CEntityFlags::Entity CEntityFlags::entityFlagToEntity(CEntityFlags::EntityFlag entityFlag)
|
||||||
|
{
|
||||||
|
return static_cast<Entity>(static_cast<int>(entityFlag));
|
||||||
|
}
|
||||||
|
|
||||||
CEntityFlags::EntityFlag CEntityFlags::entityToEntityFlag(Entity entity)
|
CEntityFlags::EntityFlag CEntityFlags::entityToEntityFlag(Entity entity)
|
||||||
{
|
{
|
||||||
return static_cast<EntityFlag>(static_cast<int>(entity));
|
return static_cast<EntityFlag>(static_cast<int>(entity));
|
||||||
|
|||||||
@@ -86,9 +86,12 @@ namespace BlackMisc
|
|||||||
static QString flagToString(ReadState flag);
|
static QString flagToString(ReadState flag);
|
||||||
|
|
||||||
//! Flag to severity
|
//! Flag to severity
|
||||||
static BlackMisc::CStatusMessage::StatusSeverity flagToSeverity(ReadState state);
|
static CStatusMessage::StatusSeverity flagToSeverity(ReadState state);
|
||||||
|
|
||||||
//! To flag
|
//! To entity (when explicit conversion is needed)
|
||||||
|
static Entity entityFlagToEntity(EntityFlag entityFlag);
|
||||||
|
|
||||||
|
//! To flag (when explicit conversion is needed)
|
||||||
static EntityFlag entityToEntityFlag(Entity entity);
|
static EntityFlag entityToEntityFlag(Entity entity);
|
||||||
|
|
||||||
//! Return single entity and remove it from entities
|
//! Return single entity and remove it from entities
|
||||||
|
|||||||
@@ -398,6 +398,7 @@ void SwiftGuiStd::navigatorClosed()
|
|||||||
|
|
||||||
void SwiftGuiStd::verifyModelSet()
|
void SwiftGuiStd::verifyModelSet()
|
||||||
{
|
{
|
||||||
|
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||||
const CSimulatorInfo sims = sGui->getIContextSimulator()->simulatorsWithInitializedModelSet();
|
const CSimulatorInfo sims = sGui->getIContextSimulator()->simulatorsWithInitializedModelSet();
|
||||||
if (sims.isNoSimulator())
|
if (sims.isNoSimulator())
|
||||||
{
|
{
|
||||||
@@ -405,31 +406,65 @@ void SwiftGuiStd::verifyModelSet()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwiftGuiStd::sharedInfoObjectsLoaded()
|
void SwiftGuiStd::checkDbDataLoaded()
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web services");
|
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Wrong thread");
|
Q_ASSERT_X(sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web services");
|
||||||
const CEntityFlags::Entity newEntities = sGui->getWebDataServices()->getEntitiesWithNewerSharedFile(CEntityFlags::AllDbEntities);
|
Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Wrong thread, needs to run in main thread");
|
||||||
if (newEntities == CEntityFlags::NoEntity) { return; }
|
CEntityFlags::Entity loadEntities = sGui->getWebDataServices()->getEntitiesWithNewerSharedFile(CEntityFlags::AllDbEntities);
|
||||||
CStatusMessage sm = CStatusMessage(this).info("New data for shared files:");
|
const CEntityFlags::Entity checkForEmpty = CEntityFlags::entityFlagToEntity(CEntityFlags::AllDbEntitiesNoInfoObjects) & ~loadEntities;
|
||||||
CStatusMessageList sms({sm});
|
|
||||||
const QSet<CEntityFlags::Entity> newSingleEntities = CEntityFlags::asSingleEntities(newEntities);
|
// it can happen the timestamps are not newer, but the data are empty
|
||||||
|
// - can happen if caches are copied and the TS does not represent the DB timestamp
|
||||||
|
// - cache files have been deleted
|
||||||
|
// - sync all DB entities
|
||||||
|
// - fast if there are no data
|
||||||
|
// - no impact if already synced
|
||||||
|
// - slow if newer synced before and all has to be done now
|
||||||
|
if (!m_dbDataLoading) { sGui->getWebDataServices()->synchronizeDbCaches(checkForEmpty); }
|
||||||
|
|
||||||
|
// we have no newer timestamps, but incomplete data
|
||||||
|
loadEntities |= sGui->getWebDataServices()->getEmptyEntities();
|
||||||
|
if (loadEntities == CEntityFlags::NoEntity)
|
||||||
|
{
|
||||||
|
m_dbDataLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CStatusMessage sm = m_dbDataLoading ?
|
||||||
|
CStatusMessage(this).info("Loading in progress:") :
|
||||||
|
CStatusMessage(this).info("New data for shared files:");
|
||||||
|
CStatusMessageList sms(sm);
|
||||||
|
const QSet<CEntityFlags::Entity> newSingleEntities = CEntityFlags::asSingleEntities(loadEntities);
|
||||||
|
const QString m = m_dbDataLoading ? QStringLiteral("Loading data for '%1'") : QStringLiteral("Load data for '%1'?");
|
||||||
for (CEntityFlags::Entity newSingleEntity : newSingleEntities)
|
for (CEntityFlags::Entity newSingleEntity : newSingleEntities)
|
||||||
{
|
{
|
||||||
sm = CStatusMessage(this).info("Load data for '%1'?") << CEntityFlags::flagToString(newSingleEntity);
|
sm = CStatusMessage(this).info(m) << CEntityFlags::flagToString(newSingleEntity);
|
||||||
sms.push_back(sm);
|
sms.push_back(sm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// allow to init GUI completely before showing overlays
|
constexpr int checkAgain = 5000;
|
||||||
const int delay = 2500;
|
if (m_dbDataLoading)
|
||||||
|
{
|
||||||
|
// already loading
|
||||||
|
ui->fr_CentralFrameInside->showOverlayMessages(sms, false, 1.2 * checkAgain);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// data need to be loaded
|
||||||
|
constexpr int delay = 2500; // allow to init GUI completely before showing overlays
|
||||||
QTimer::singleShot(delay, this, [ = ]
|
QTimer::singleShot(delay, this, [ = ]
|
||||||
{
|
{
|
||||||
// delayed call
|
// delayed call
|
||||||
auto lambda = [newEntities]()
|
auto lambda = [ = ]()
|
||||||
{
|
{
|
||||||
sGui->getWebDataServices()->triggerLoadingDirectlyFromSharedFiles(newEntities, false);
|
sGui->getWebDataServices()->triggerLoadingDirectlyFromSharedFiles(loadEntities, false);
|
||||||
|
m_dbDataLoading = true;
|
||||||
|
|
||||||
|
// re-check
|
||||||
|
QTimer::singleShot(checkAgain, this, &SwiftGuiStd::checkDbDataLoaded);
|
||||||
};
|
};
|
||||||
ui->fr_CentralFrameInside->showOverlayMessagesWithConfirmation(sms, false, "Load data?", lambda);
|
ui->fr_CentralFrameInside->showOverlayMessagesWithConfirmation(sms, false, "Load DB data?", lambda);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ private:
|
|||||||
bool m_contextNetworkAvailable = false; //!< network context available?
|
bool m_contextNetworkAvailable = false; //!< network context available?
|
||||||
bool m_contextAudioAvailable = false; //!< audio context available?
|
bool m_contextAudioAvailable = false; //!< audio context available?
|
||||||
bool m_displayingDBusReconnect = false; //!< currently displaying reconnect dialog
|
bool m_displayingDBusReconnect = false; //!< currently displaying reconnect dialog
|
||||||
|
bool m_dbDataLoading = false; //!< DB or shared data loading in progress
|
||||||
QTimer m_timerContextWatchdog { this }; //!< core available?
|
QTimer m_timerContextWatchdog { this }; //!< core available?
|
||||||
BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< own aircraft's state
|
BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< own aircraft's state
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ private:
|
|||||||
void initStyleSheet();
|
void initStyleSheet();
|
||||||
|
|
||||||
//! 1st data reads
|
//! 1st data reads
|
||||||
void initialDataReads();
|
void initialContextDataReads();
|
||||||
|
|
||||||
//! Init data (post GUI init)
|
//! Init data (post GUI init)
|
||||||
void init();
|
void init();
|
||||||
@@ -155,7 +156,7 @@ private:
|
|||||||
bool isMainPageSelected(MainPageIndex mainPage) const;
|
bool isMainPageSelected(MainPageIndex mainPage) const;
|
||||||
|
|
||||||
//! Stop all timers
|
//! Stop all timers
|
||||||
//! \param disconnect also disconnect signal/slots
|
//! \param disconnectSignalSlots also disconnect signal/slots
|
||||||
void stopAllTimers(bool disconnectSignalSlots);
|
void stopAllTimers(bool disconnectSignalSlots);
|
||||||
|
|
||||||
//! Play notifcation sound
|
//! Play notifcation sound
|
||||||
@@ -246,8 +247,8 @@ private:
|
|||||||
//! Checks if model set is available
|
//! Checks if model set is available
|
||||||
void verifyModelSet();
|
void verifyModelSet();
|
||||||
|
|
||||||
//! The shared info objects have been loaded
|
//! Ckeck if the DB data have been loaded
|
||||||
void sharedInfoObjectsLoaded();
|
void checkDbDataLoaded();
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pop_macro("interface")
|
#pragma pop_macro("interface")
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "swiftguistd.h"
|
||||||
|
#include "ui_swiftguistd.h"
|
||||||
#include "blackconfig/buildconfig.h"
|
#include "blackconfig/buildconfig.h"
|
||||||
#include "blackcore/webdataservices.h"
|
#include "blackcore/webdataservices.h"
|
||||||
#include "blackcore/context/contextnetwork.h"
|
#include "blackcore/context/contextnetwork.h"
|
||||||
@@ -32,9 +34,8 @@
|
|||||||
#include "blackmisc/loghandler.h"
|
#include "blackmisc/loghandler.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/logpattern.h"
|
#include "blackmisc/logpattern.h"
|
||||||
|
#include "blackmisc/slot.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
#include "swiftguistd.h"
|
|
||||||
#include "ui_swiftguistd.h"
|
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
@@ -117,9 +118,7 @@ void SwiftGuiStd::init()
|
|||||||
this->initGuiSignals();
|
this->initGuiSignals();
|
||||||
|
|
||||||
// signal / slots contexts / timers
|
// signal / slots contexts / timers
|
||||||
bool s = connect(sGui->getWebDataServices(), &CWebDataServices::sharedInfoObjectsRead, this, &SwiftGuiStd::sharedInfoObjectsLoaded, Qt::QueuedConnection);
|
bool s = connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &SwiftGuiStd::onConnectionStatusChanged, Qt::QueuedConnection);
|
||||||
Q_ASSERT(s);
|
|
||||||
s = connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &SwiftGuiStd::onConnectionStatusChanged, Qt::QueuedConnection);
|
|
||||||
Q_ASSERT(s);
|
Q_ASSERT(s);
|
||||||
s = connect(sGui->getIContextNetwork(), &IContextNetwork::kicked, this, &SwiftGuiStd::onKickedFromNetwork, Qt::QueuedConnection);
|
s = connect(sGui->getIContextNetwork(), &IContextNetwork::kicked, this, &SwiftGuiStd::onKickedFromNetwork, Qt::QueuedConnection);
|
||||||
Q_ASSERT(s);
|
Q_ASSERT(s);
|
||||||
@@ -130,6 +129,11 @@ void SwiftGuiStd::init()
|
|||||||
s = connect(&m_timerContextWatchdog, &QTimer::timeout, this, &SwiftGuiStd::handleTimerBasedUpdates);
|
s = connect(&m_timerContextWatchdog, &QTimer::timeout, this, &SwiftGuiStd::handleTimerBasedUpdates);
|
||||||
Q_ASSERT(s);
|
Q_ASSERT(s);
|
||||||
Q_UNUSED(s);
|
Q_UNUSED(s);
|
||||||
|
|
||||||
|
// check if DB data have been loaded
|
||||||
|
// only check once, so data can be loaded and
|
||||||
|
connectOnce(sGui->getWebDataServices(), &CWebDataServices::sharedInfoObjectsRead, this, &SwiftGuiStd::checkDbDataLoaded, Qt::QueuedConnection);
|
||||||
|
|
||||||
// start timers, update timers will be started when network is connected
|
// start timers, update timers will be started when network is connected
|
||||||
m_timerContextWatchdog.start(2500);
|
m_timerContextWatchdog.start(2500);
|
||||||
|
|
||||||
@@ -137,7 +141,7 @@ void SwiftGuiStd::init()
|
|||||||
this->setContextAvailability();
|
this->setContextAvailability();
|
||||||
|
|
||||||
// data
|
// data
|
||||||
this->initialDataReads();
|
this->initialContextDataReads();
|
||||||
|
|
||||||
// start screen and complete menu
|
// start screen and complete menu
|
||||||
this->setMainPageToInfoArea();
|
this->setMainPageToInfoArea();
|
||||||
@@ -156,8 +160,8 @@ void SwiftGuiStd::init()
|
|||||||
|
|
||||||
emit sGui->startUpCompleted(true);
|
emit sGui->startUpCompleted(true);
|
||||||
m_init = true;
|
m_init = true;
|
||||||
QTimer::singleShot(2500, this, &SwiftGuiStd::verifyModelSet);
|
|
||||||
|
|
||||||
|
QTimer::singleShot(2500, this, &SwiftGuiStd::verifyModelSet);
|
||||||
if (!sGui->isNetworkAccessible())
|
if (!sGui->isNetworkAccessible())
|
||||||
{
|
{
|
||||||
CLogMessage(this).error("No network interface, software will not work properly");
|
CLogMessage(this).error("No network interface, software will not work properly");
|
||||||
@@ -240,7 +244,7 @@ void SwiftGuiStd::initGuiSignals()
|
|||||||
connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedWholeInfoAreaFloating, this, &SwiftGuiStd::onChangedMainInfoAreaFloating);
|
connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedWholeInfoAreaFloating, this, &SwiftGuiStd::onChangedMainInfoAreaFloating);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwiftGuiStd::initialDataReads()
|
void SwiftGuiStd::initialContextDataReads()
|
||||||
{
|
{
|
||||||
this->setContextAvailability();
|
this->setContextAvailability();
|
||||||
if (!m_coreAvailable)
|
if (!m_coreAvailable)
|
||||||
|
|||||||
Reference in New Issue
Block a user