9 #include "ui_dbloadoverviewcomponent.h"
21 using namespace swift::misc::network;
25 CDbLoadOverviewComponent::CDbLoadOverviewComponent(QWidget *parent)
28 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"missing sGui");
36 ui->lbl_DatabaseUrl->setTextFormat(Qt::RichText);
37 ui->lbl_DatabaseUrl->setTextInteractionFlags(Qt::TextBrowserInteraction);
38 ui->lbl_DatabaseUrl->setOpenExternalLinks(
true);
39 ui->lbl_SharedUrls->setTextFormat(Qt::RichText);
40 ui->lbl_SharedUrls->setTextInteractionFlags(Qt::TextBrowserInteraction);
41 ui->lbl_SharedUrls->setOpenExternalLinks(
true);
43 connect(ui->tb_DbReloadAircraft, &QToolButton::pressed,
this, &CDbLoadOverviewComponent::refreshDbPressed);
44 connect(ui->tb_DbReloadAirlines, &QToolButton::pressed,
this, &CDbLoadOverviewComponent::refreshDbPressed);
45 connect(ui->tb_DbReloadAirports, &QToolButton::pressed,
this, &CDbLoadOverviewComponent::refreshDbPressed);
46 connect(ui->tb_DbReloadCountries, &QToolButton::pressed,
this, &CDbLoadOverviewComponent::refreshDbPressed);
47 connect(ui->tb_DbReloadLiveries, &QToolButton::pressed,
this, &CDbLoadOverviewComponent::refreshDbPressed);
48 connect(ui->tb_DbReloadModels, &QToolButton::pressed,
this, &CDbLoadOverviewComponent::refreshDbPressed);
49 connect(ui->tb_DbReloadDistributors, &QToolButton::pressed,
this, &CDbLoadOverviewComponent::refreshDbPressed);
50 connect(ui->tb_DbReloadCategories, &QToolButton::pressed,
this, &CDbLoadOverviewComponent::refreshDbPressed);
52 connect(ui->tb_SharedReloadAircraft, &QToolButton::pressed,
this,
53 &CDbLoadOverviewComponent::refreshSharedPressed);
54 connect(ui->tb_SharedReloadAirlines, &QToolButton::pressed,
this,
55 &CDbLoadOverviewComponent::refreshSharedPressed);
56 connect(ui->tb_SharedReloadAirports, &QToolButton::pressed,
this,
57 &CDbLoadOverviewComponent::refreshSharedPressed);
58 connect(ui->tb_SharedReloadCountries, &QToolButton::pressed,
this,
59 &CDbLoadOverviewComponent::refreshSharedPressed);
60 connect(ui->tb_SharedReloadLiveries, &QToolButton::pressed,
this,
61 &CDbLoadOverviewComponent::refreshSharedPressed);
62 connect(ui->tb_SharedReloadModels, &QToolButton::pressed,
this,
63 &CDbLoadOverviewComponent::refreshSharedPressed);
64 connect(ui->tb_SharedReloadDistributors, &QToolButton::pressed,
this,
65 &CDbLoadOverviewComponent::refreshSharedPressed);
66 connect(ui->tb_SharedReloadCategories, &QToolButton::pressed,
this,
67 &CDbLoadOverviewComponent::refreshSharedPressed);
71 connect(ui->pb_LoadAllFromResources, &QPushButton::pressed,
this,
77 &CDbLoadOverviewComponent::dataLoaded);
78 QPointer<CDbLoadOverviewComponent> myself(
this);
81 this->loadInfoObjects();
82 this->adjustTextWidth();
93 ui->lbl_DbRefresh->setVisible(visible);
94 ui->tb_DbReloadAircraft->setVisible(visible);
95 ui->tb_DbReloadAirlines->setVisible(visible);
96 ui->tb_DbReloadAirports->setVisible(visible);
97 ui->tb_DbReloadCountries->setVisible(visible);
98 ui->tb_DbReloadLiveries->setVisible(visible);
99 ui->tb_DbReloadModels->setVisible(visible);
100 ui->tb_DbReloadDistributors->setVisible(visible);
101 ui->tb_DbReloadCategories->setVisible(visible);
106 ui->lbl_SharedRefresh->setVisible(visible);
107 ui->tb_SharedReloadAircraft->setVisible(visible);
108 ui->tb_SharedReloadAirlines->setVisible(visible);
109 ui->tb_SharedReloadAirports->setVisible(visible);
110 ui->tb_SharedReloadCountries->setVisible(visible);
111 ui->tb_SharedReloadLiveries->setVisible(visible);
112 ui->tb_SharedReloadModels->setVisible(visible);
113 ui->tb_SharedReloadDistributors->setVisible(visible);
114 ui->tb_SharedReloadCategories->setVisible(visible);
123 this->adjustTextWidth();
125 QFrame::resizeEvent(event);
130 const bool widget = shared || db;
131 ui->wi_LoadAllButtons->setVisible(widget);
132 ui->pb_LoadAllFromDB->setVisible(db);
133 ui->pb_LoadAllFromShared->setVisible(shared);
134 ui->pb_LoadAllFromResources->setVisible(disk);
139 this->triggerLoadingFromDb(CEntityFlags::AllDbEntitiesNoInfoObjects);
144 this->triggerLoadingFromSharedFiles(CEntityFlags::AllDbEntitiesNoInfoObjects);
151 const QMessageBox::StandardButton reply = QMessageBox::warning(
152 this,
"Load DB data",
153 "You should only load DB from disk resources if loading from network does not work. Really load?",
154 QMessageBox::Yes | QMessageBox::No);
155 if (reply != QMessageBox::Yes) {
return; }
159 void CDbLoadOverviewComponent::setGuiValues()
161 if (!
sGui) {
return; }
164 ui->le_AircraftIcaoCacheCount->setText(cacheCountForEntity(CEntityFlags::AircraftIcaoEntity));
165 ui->le_AirlinesIcaoCacheCount->setText(cacheCountForEntity(CEntityFlags::AirlineIcaoEntity));
166 ui->le_AirportsCacheCount->setText(cacheCountForEntity(CEntityFlags::AirportEntity));
167 ui->le_LiveriesCacheCount->setText(cacheCountForEntity(CEntityFlags::LiveryEntity));
168 ui->le_ModelsCacheCount->setText(cacheCountForEntity(CEntityFlags::ModelEntity));
169 ui->le_CountriesCacheCount->setText(cacheCountForEntity(CEntityFlags::CountryEntity));
170 ui->le_DistributorsCacheCount->setText(cacheCountForEntity(CEntityFlags::DistributorEntity));
171 ui->le_CategoriesCacheCount->setText(cacheCountForEntity(CEntityFlags::AircraftCategoryEntity));
173 ui->le_AircraftIcaoDbCount->setText(dbCountForEntity(CEntityFlags::AircraftIcaoEntity));
174 ui->le_AirlinesIcaoDbCount->setText(dbCountForEntity(CEntityFlags::AirlineIcaoEntity));
175 ui->le_AirportsDbCount->setText(dbCountForEntity(CEntityFlags::AirportEntity));
176 ui->le_LiveriesDbCount->setText(dbCountForEntity(CEntityFlags::LiveryEntity));
177 ui->le_ModelsDbCount->setText(dbCountForEntity(CEntityFlags::ModelEntity));
178 ui->le_CountriesDbCount->setText(dbCountForEntity(CEntityFlags::CountryEntity));
179 ui->le_DistributorsDbCount->setText(dbCountForEntity(CEntityFlags::DistributorEntity));
180 ui->le_CategoriesDbCount->setText(dbCountForEntity(CEntityFlags::AircraftCategoryEntity));
182 ui->le_AircraftIcaoSharedCount->setText(sharedCountForEntity(CEntityFlags::AircraftIcaoEntity));
183 ui->le_AirlinesIcaoSharedCount->setText(sharedCountForEntity(CEntityFlags::AirlineIcaoEntity));
184 ui->le_AirportsSharedCount->setText(sharedCountForEntity(CEntityFlags::AirportEntity));
185 ui->le_LiveriesSharedCount->setText(sharedCountForEntity(CEntityFlags::LiveryEntity));
186 ui->le_ModelsSharedCount->setText(sharedCountForEntity(CEntityFlags::ModelEntity));
187 ui->le_CountriesSharedCount->setText(sharedCountForEntity(CEntityFlags::CountryEntity));
188 ui->le_DistributorsSharedCount->setText(sharedCountForEntity(CEntityFlags::DistributorEntity));
189 ui->le_CategoriesSharedCount->setText(sharedCountForEntity(CEntityFlags::AircraftCategoryEntity));
191 ui->le_AircraftIcaoCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AircraftIcaoEntity));
192 ui->le_AirlinesIcaoCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AirlineIcaoEntity));
193 ui->le_AirportsCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AirportEntity));
194 ui->le_LiveriesCacheTs->setText(cacheTimestampForEntity(CEntityFlags::LiveryEntity));
195 ui->le_ModelsCacheTs->setText(cacheTimestampForEntity(CEntityFlags::ModelEntity));
196 ui->le_CountriesCacheTs->setText(cacheTimestampForEntity(CEntityFlags::CountryEntity));
197 ui->le_DistributorsCacheTs->setText(cacheTimestampForEntity(CEntityFlags::DistributorEntity));
198 ui->le_CategoriesCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AircraftCategoryEntity));
200 ui->le_AircraftIcaoDbTs->setText(dbTimestampForEntity(CEntityFlags::AircraftIcaoEntity));
201 ui->le_AirlinesIcaoDbTs->setText(dbTimestampForEntity(CEntityFlags::AirlineIcaoEntity));
202 ui->le_AirportsDbTs->setText(dbTimestampForEntity(CEntityFlags::AirportEntity));
203 ui->le_LiveriesDbTs->setText(dbTimestampForEntity(CEntityFlags::LiveryEntity));
204 ui->le_ModelsDbTs->setText(dbTimestampForEntity(CEntityFlags::ModelEntity));
205 ui->le_CountriesDbTs->setText(dbTimestampForEntity(CEntityFlags::CountryEntity));
206 ui->le_DistributorsDbTs->setText(dbTimestampForEntity(CEntityFlags::DistributorEntity));
207 ui->le_CategoriesDbTs->setText(dbTimestampForEntity(CEntityFlags::AircraftCategoryEntity));
209 ui->le_AircraftIcaoSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::AircraftIcaoEntity));
210 ui->le_AirlinesIcaoSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::AirlineIcaoEntity));
211 ui->le_AirportsSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::AirportEntity));
212 ui->le_LiveriesSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::LiveryEntity));
213 ui->le_ModelsSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::ModelEntity));
214 ui->le_CountriesSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::CountryEntity));
215 ui->le_DistributorsSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::DistributorEntity));
216 ui->le_CategoriesSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::AircraftCategoryEntity));
219 const QString dbUrlHtml(
"<a href=\"%2\">%3</a>");
221 ui->lbl_DatabaseUrl->setText(dbUrlHtml.arg(url, url));
222 ui->lbl_DatabaseUrl->setToolTip(url);
225 this->setSharedUrlValues();
231 void CDbLoadOverviewComponent::setSharedUrlValues()
233 if (m_sharedValueCheckInProgress) {
return; }
234 if ((QDateTime::currentMSecsSinceEpoch() - m_sharedLastCheck) < 5000) {
return; }
236 m_sharedValueCheckInProgress =
true;
239 const QString valueHtml(
"<img src=\"%1\"> %2");
240 const QString urlLinkHtml(
"<a href=\"%1\">%2</a>");
247 m_sharedValueCheckInProgress =
false;
250 const bool canConnect = CNetworkUtils::canConnect(sharedUrl);
251 values.push_back(valueHtml.arg(canConnect ? m_imgOk : m_imgFailed,
252 urlLinkHtml.arg(sharedUrl.getFullUrl(), sharedUrl.getHost())));
254 const QString sharedUrlTable =
toHtmTable(values, 2);
255 ui->lbl_SharedUrls->setText(sharedUrlTable);
256 ui->lbl_SharedUrls->setMinimumHeight(28);
258 ui->lbl_SharedUrls->setToolTip(currentlyUsedSharedUrl.isEmpty() ?
"No shared URL" :
259 "currently used: " + currentlyUsedSharedUrl);
261 m_sharedLastCheck = QDateTime::currentMSecsSinceEpoch();
262 m_sharedValueCheckInProgress =
false;
265 bool CDbLoadOverviewComponent::isInitialized()
const {
return !ui->le_AircraftIcaoCacheCount->text().isEmpty(); }
267 QString CDbLoadOverviewComponent::formattedTimestamp(
const QDateTime &dateTime)
269 if (!dateTime.isValid()) {
return "-"; }
270 return dateTime.toUTC().toString(
"yy-MM-dd hh:mm:ss");
273 QString CDbLoadOverviewComponent::cacheTimestampForEntity(CEntityFlags::Entity entity)
276 return formattedTimestamp(ts);
279 QString CDbLoadOverviewComponent::dbTimestampForEntity(CEntityFlags::Entity entity)
282 return formattedTimestamp(ts);
285 QString CDbLoadOverviewComponent::cacheCountForEntity(CEntityFlags::Entity entity)
288 return c < 0 ?
"-" : QString::number(c);
291 QString CDbLoadOverviewComponent::sharedFileTimestampForEntity(CEntityFlags::Entity entity)
294 return formattedTimestamp(ts);
297 QString CDbLoadOverviewComponent::sharedCountForEntity(CEntityFlags::Entity entity)
300 return c < 0 ?
"-" : QString::number(c);
303 QString CDbLoadOverviewComponent::dbCountForEntity(CEntityFlags::Entity entity)
306 return c < 0 ?
"-" : QString::number(c);
309 void CDbLoadOverviewComponent::admitCaches()
316 void CDbLoadOverviewComponent::refreshDbPressed()
319 const QObject *sender = QObject::sender();
320 const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(sender->objectName());
321 this->triggerLoadingFromDb(entity);
324 void CDbLoadOverviewComponent::triggerLoadingFromDb(CEntityFlags::Entity entities)
326 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
330 const CEntityFlags::Entity triggeredEntities =
332 if (triggeredEntities == CEntityFlags::NoEntity) {
return; }
341 void CDbLoadOverviewComponent::refreshSharedPressed()
344 const QObject *sender = QObject::sender();
345 const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(sender->objectName());
346 this->triggerLoadingFromSharedFiles(entity);
349 void CDbLoadOverviewComponent::triggerLoadingFromSharedFiles(CEntityFlags::Entity entities)
354 const CEntityFlags::Entity triggeredEntities =
356 if (triggeredEntities == CEntityFlags::NoEntity) {
return; }
364 void CDbLoadOverviewComponent::dataLoaded(CEntityFlags::Entity entities,
CEntityFlags::ReadState state,
int number,
370 if (!CEntityFlags::isFinishedReadState(state))
return;
371 if (!entities.testFlag(CEntityFlags::SharedInfoObjectEntity) &&
372 !entities.testFlag(CEntityFlags::DbInfoObjectEntity) && !CEntityFlags::anySwiftDbEntity(entities))
380 void CDbLoadOverviewComponent::loadInfoObjects()
401 if (direct) { m_dsTriggerGuiUpdate.
inputSignal(); }
404 void CDbLoadOverviewComponent::adjustTextWidth()
406 const QSize s = this->size();
408 const int thresholdW = qRound(sizeFont.width() * 2.0);
409 if (s.width() > thresholdW)
411 ui->lbl_DbCount->setText(
"DB count");
412 ui->lbl_CacheCount->setText(
"Cache count");
413 ui->lbl_SharedCount->setText(
"Shared count");
417 ui->lbl_DbCount->setText(
"DB#");
418 ui->lbl_CacheCount->setText(
"C#");
419 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 * getDbInfoDataReader() const
DB 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::CStatusMessageList initDbCachesFromLocalResourceFiles(bool inBackground)
Init caches from local DB files.
swift::core::db::CInfoDataReader * getSharedInfoDataReader() const
Shared info data reader.
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.
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.
swift::misc::network::CUrl getDbHomePageUrl() const
Home page 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 ..."
Enable widget class for load indicator.
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.
bool isShowingLoadIndicator() const
Showing load indicator?
Overview about load state of DB data.
virtual 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.
virtual ~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.
void inputSignal()
Received input signal, or manually trigger.
QString toQString(bool i18n=false) const
Cast as QString.
ReadState
State of operation.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
QString getFullUrl(bool withQuery=true) const
Qualified name.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
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.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...