9#include "ui_dbloadoverviewcomponent.h"
21using namespace swift::misc::network;
28 Q_ASSERT_X(sGui, Q_FUNC_INFO,
"missing sGui");
38 ui->lbl_DatabaseUrl->setOpenExternalLinks(
true);
41 ui->lbl_SharedUrls->setOpenExternalLinks(
true);
53 &CDbLoadOverviewComponent::refreshSharedPressed);
55 &CDbLoadOverviewComponent::refreshSharedPressed);
57 &CDbLoadOverviewComponent::refreshSharedPressed);
59 &CDbLoadOverviewComponent::refreshSharedPressed);
61 &CDbLoadOverviewComponent::refreshSharedPressed);
63 &CDbLoadOverviewComponent::refreshSharedPressed);
65 &CDbLoadOverviewComponent::refreshSharedPressed);
67 &CDbLoadOverviewComponent::refreshSharedPressed);
74 if (sGui->hasWebDataServices())
77 &CDbLoadOverviewComponent::dataLoaded);
80 if (!myself || !sGui || sGui->isShuttingDown())
84 this->loadInfoObjects();
85 this->adjustTextWidth();
96 ui->lbl_DbRefresh->setVisible(
visible);
97 ui->tb_DbReloadAircraft->setVisible(
visible);
98 ui->tb_DbReloadAirlines->setVisible(
visible);
99 ui->tb_DbReloadAirports->setVisible(
visible);
100 ui->tb_DbReloadCountries->setVisible(
visible);
101 ui->tb_DbReloadLiveries->setVisible(
visible);
102 ui->tb_DbReloadModels->setVisible(
visible);
103 ui->tb_DbReloadDistributors->setVisible(
visible);
104 ui->tb_DbReloadCategories->setVisible(
visible);
109 ui->lbl_SharedRefresh->setVisible(
visible);
110 ui->tb_SharedReloadAircraft->setVisible(
visible);
111 ui->tb_SharedReloadAirlines->setVisible(
visible);
112 ui->tb_SharedReloadAirports->setVisible(
visible);
113 ui->tb_SharedReloadCountries->setVisible(
visible);
114 ui->tb_SharedReloadLiveries->setVisible(
visible);
115 ui->tb_SharedReloadModels->setVisible(
visible);
116 ui->tb_SharedReloadDistributors->setVisible(
visible);
117 ui->tb_SharedReloadCategories->setVisible(
visible);
126 this->adjustTextWidth();
133 const bool widget = shared ||
db;
134 ui->wi_LoadAllButtons->setVisible(widget);
135 ui->pb_LoadAllFromDB->setVisible(
db);
136 ui->pb_LoadAllFromShared->setVisible(shared);
137 ui->pb_LoadAllFromResources->setVisible(disk);
156 if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices())
161 this,
"Load DB data",
162 "You should only load DB from disk resources if loading from network does not work. Really load?",
168 sGui->getWebDataServices()->initDbCachesFromLocalResourceFiles(
true);
171 void CDbLoadOverviewComponent::setGuiValues()
177 if (!sGui->hasWebDataServices())
237 const QString dbUrlHtml(
"<a href=\"%2\">%3</a>");
238 const QString url = sGui->getGlobalSetup().getDbHomePageUrl().getFullUrl();
239 ui->lbl_DatabaseUrl->setText(dbUrlHtml.arg(url, url));
240 ui->lbl_DatabaseUrl->setToolTip(url);
243 this->setSharedUrlValues();
249 void CDbLoadOverviewComponent::setSharedUrlValues()
251 if (m_sharedValueCheckInProgress)
260 m_sharedValueCheckInProgress =
true;
263 const QString valueHtml(
"<img src=\"%1\"> %2");
264 const QString urlLinkHtml(
"<a href=\"%1\">%2</a>");
271 m_sharedValueCheckInProgress =
false;
275 values.
push_back(valueHtml.arg(canConnect ? m_imgOk : m_imgFailed,
276 urlLinkHtml.arg(sharedUrl.getFullUrl(), sharedUrl.getHost())));
278 const QString sharedUrlTable =
toHtmTable(values, 2);
279 ui->lbl_SharedUrls->setText(sharedUrlTable);
280 ui->lbl_SharedUrls->setMinimumHeight(28);
282 ui->lbl_SharedUrls->setToolTip(currentlyUsedSharedUrl.
isEmpty() ?
"No shared URL" :
283 "currently used: " + currentlyUsedSharedUrl);
286 m_sharedValueCheckInProgress =
false;
289 bool CDbLoadOverviewComponent::isInitialized()
const {
return !ui->le_AircraftIcaoCacheCount->text().isEmpty(); }
291 QString CDbLoadOverviewComponent::formattedTimestamp(
const QDateTime &dateTime)
300 QString CDbLoadOverviewComponent::cacheTimestampForEntity(CEntityFlags::Entity entity)
303 return formattedTimestamp(ts);
306 QString CDbLoadOverviewComponent::dbTimestampForEntity(CEntityFlags::Entity entity)
309 return formattedTimestamp(ts);
312 QString CDbLoadOverviewComponent::cacheCountForEntity(CEntityFlags::Entity entity)
318 QString CDbLoadOverviewComponent::sharedFileTimestampForEntity(CEntityFlags::Entity entity)
321 return formattedTimestamp(ts);
324 QString CDbLoadOverviewComponent::sharedCountForEntity(CEntityFlags::Entity entity)
330 QString CDbLoadOverviewComponent::dbCountForEntity(CEntityFlags::Entity entity)
336 void CDbLoadOverviewComponent::admitCaches()
346 void CDbLoadOverviewComponent::refreshDbPressed()
354 this->triggerLoadingFromDb(entity);
357 void CDbLoadOverviewComponent::triggerLoadingFromDb(CEntityFlags::Entity entities)
359 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
366 const CEntityFlags::Entity triggeredEntities =
380 void CDbLoadOverviewComponent::refreshSharedPressed()
388 this->triggerLoadingFromSharedFiles(entity);
391 void CDbLoadOverviewComponent::triggerLoadingFromSharedFiles(CEntityFlags::Entity entities)
399 const CEntityFlags::Entity triggeredEntities =
412 void CDbLoadOverviewComponent::dataLoaded(CEntityFlags::Entity entities,
CEntityFlags::ReadState state,
int number,
425 m_dsTriggerGuiUpdate.inputSignal();
428 void CDbLoadOverviewComponent::loadInfoObjects()
466 m_dsTriggerGuiUpdate.inputSignal();
470 void CDbLoadOverviewComponent::adjustTextWidth()
472 const QSize s = this->
size();
474 const int thresholdW = qRound(sizeFont.
width() * 2.0);
475 if (s.
width() > thresholdW)
477 ui->lbl_DbCount->setText(
"DB count");
478 ui->lbl_CacheCount->setText(
"Cache count");
479 ui->lbl_SharedCount->setText(
"Shared count");
483 ui->lbl_DbCount->setText(
"DB#");
484 ui->lbl_CacheCount->setText(
"C#");
485 ui->lbl_SharedCount->setText(
"S#");
data::CGlobalSetup getGlobalSetup() const
Global setup.
bool hasWebDataServices() const
Web data services available?
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
int getSharedInfoObjectCount(swift::misc::network::CEntityFlags::Entity entity) const
Count for entity from shared entity objects.
swift::core::db::CInfoDataReader * getSharedInfoDataReader() const
Shared info data reader.
QDateTime getLatestDbEntityTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Corresponding DB timestamp if applicable.
swift::misc::network::CEntityFlags::Entity triggerLoadingDirectlyFromSharedFiles(swift::misc::network::CEntityFlags::Entity whatToRead, bool checkCacheTsUpfront)
Trigger reload from shared files, loads the data and bypasses caches.
QDateTime getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Corresponding cache timestamp if applicable.
QDateTime getLatestSharedInfoObjectTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Shared info object timestamp.
swift::misc::network::CEntityFlags::Entity triggerLoadingDirectlyFromDb(swift::misc::network::CEntityFlags::Entity whatToRead, const QDateTime &newerThan=QDateTime())
Trigger reload from DB, loads the DB data and bypasses the caches checks and info objects.
void triggerReadOfSharedInfoObjects()
Trigger read of shared info objects.
void dataRead(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CEntityFlags::ReadState state, int number, const QUrl &url)
Combined read signal.
swift::core::db::CInfoDataReader * getDbInfoDataReader() const
DB info data reader.
int getCacheCount(swift::misc::network::CEntityFlags::Entity entity) const
Cache count for entity.
int getDbInfoObjectCount(swift::misc::network::CEntityFlags::Entity entity) const
Count for entity from DB entity objects.
void triggerReadOfDbInfoObjects()
Trigger read of DB info objects.
void admitDbCaches(swift::misc::network::CEntityFlags::Entity entities)
Admit all DB caches specified.
const swift::misc::network::CUrl & getSwiftSharedUrl() const
Shared URL.
int getInfoObjectCount() const
Get info list size (either shared or from DB).
static QSizeF fontMetricsLazyDog43Chars(bool withRatio=false)
43 characters width/height "the quick brown ..."
void centerLoadIndicator()
Center load indicator.
bool m_loadInProgress
flag indicating loading
void showLoading(std::chrono::milliseconds timeout=std::chrono::milliseconds(0), bool processEvents=true)
Show load indicator.
void hideLoading()
Hide load indicator.
CLoadIndicatorEnabled(QWidget *usingWidget)
Ctor.
bool isShowingLoadIndicator() const
Showing load indicator?
void resizeEvent(QResizeEvent *event)
void showVisibleLoadAllButtons(bool shared, bool db, bool disk)
Show load all buttons.
void loadAllFromShared()
Load all from shared.
void loadAllFromDb()
Load all from DB.
void display()
Initialize.
CDbLoadOverviewComponent(QWidget *parent=nullptr)
Constructor.
~CDbLoadOverviewComponent()
Destructor.
void showVisibleSharedRefreshButtons(bool visible)
Visible shared refresh buttons.
void loadAllFromResourceFiles()
Load all from disk (as of installation).
void showVisibleDbRefreshButtons(bool visible)
Visible DB refresh buttons.
QString toQString(bool i18n=false) const
Cast as QString.
static bool isFinishedReadState(ReadState state)
Any finished state.
static Entity singleEntityByName(const QString &name)
Get by name.
@ AircraftCategoryEntity
aircraft category entities
@ AllDbEntitiesNoInfoObjects
all DB entities, no info objects
@ CountryEntity
country codes
@ DbInfoObjectEntity
info about DB data (kind of metadata)
@ AirlineIcaoEntity
ICAO codes for airlines.
@ SharedInfoObjectEntity
info about shared DB data (metadata)
@ AircraftIcaoEntity
ICAO codes for aircraft.
@ AllDbEntities
all DB stuff
@ DistributorEntity
distributors
ReadState
State of operation.
static bool anySwiftDbEntity(Entity entities)
Representing at least one DB entity.
static bool canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs=getTimeoutMs())
Can connect?
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Classes interacting with the swift database (aka "datastore").
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Free functions in swift::misc.
QString toHtmTable(const QStringList &values, int columns)
Values as HTML table.
qint64 currentMSecsSinceEpoch()
bool isValid() const const
QString toString(QStringView format) const const
QDateTime toUTC() const const
QFrame(QWidget *parent, Qt::WindowFlags f)
virtual bool event(QEvent *e) override
void push_back(QList< T >::parameter_type value)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QObject * sender() const const
qreal width() const const
bool isEmpty() const const
QString number(double n, char format, int precision)