diff --git a/src/blackgui/components/dbloadoverviewcomponent.cpp b/src/blackgui/components/dbloadoverviewcomponent.cpp new file mode 100644 index 000000000..7fa763ba8 --- /dev/null +++ b/src/blackgui/components/dbloadoverviewcomponent.cpp @@ -0,0 +1,123 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "dbloadoverviewcomponent.h" +#include "ui_dbloadoverviewcomponent.h" + +#include "blackcore/webdataservices.h" +#include "blackgui/guiapplication.h" + +using namespace BlackGui; +using namespace BlackMisc; +using namespace BlackMisc::Network; + +namespace BlackGui +{ + namespace Components + { + CDbLoadOverviewComponent::CDbLoadOverviewComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CDbLoadOverviewComponent) + { + ui->setupUi(this); + + ui->lbl_DatabaseUrl->setTextFormat(Qt::RichText); + ui->lbl_DatabaseUrl->setTextInteractionFlags(Qt::TextBrowserInteraction); + ui->lbl_DatabaseUrl->setOpenExternalLinks(true); + + connect(ui->pb_ReloadAircraft, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed); + connect(ui->pb_ReloadAirlines, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed); + connect(ui->pb_ReloadCountries, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed); + connect(ui->pb_ReloadLiveries, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed); + connect(ui->pb_ReloadModels, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed); + connect(ui->pb_ReloadDistributors, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed); + + QTimer::singleShot(2000, this, &CDbLoadOverviewComponent::ps_setValues); + } + + CDbLoadOverviewComponent::~CDbLoadOverviewComponent() + { } + + void CDbLoadOverviewComponent::ps_setValues() + { + if (!sGui) { return; } + if (!sGui->getWebDataServices()) { return; } + + ui->le_AircraftIcaoCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AircraftIcaoEntity)); + ui->le_AirlineIcaoCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AirlineIcaoEntity)); + ui->le_LiveriesCacheTs->setText(cacheTimestampForEntity(CEntityFlags::LiveryEntity)); + ui->le_ModelsCacheTs->setText(cacheTimestampForEntity(CEntityFlags::ModelEntity)); + ui->le_CountriesCacheTs->setText(cacheTimestampForEntity(CEntityFlags::CountryEntity)); + ui->le_DistributorsCacheTs->setText(cacheTimestampForEntity(CEntityFlags::DistributorEntity)); + + ui->le_AircraftIcaoDbTs->setText(dbTimestampForEntity(CEntityFlags::AircraftIcaoEntity)); + ui->le_AirlineIcaoDbTs->setText(dbTimestampForEntity(CEntityFlags::AirlineIcaoEntity)); + ui->le_LiveriesDbTs->setText(dbTimestampForEntity(CEntityFlags::LiveryEntity)); + ui->le_ModelsDbTs->setText(dbTimestampForEntity(CEntityFlags::ModelEntity)); + ui->le_CountriesDbTs->setText(dbTimestampForEntity(CEntityFlags::CountryEntity)); + ui->le_DistributorsDbTs->setText(dbTimestampForEntity(CEntityFlags::DistributorEntity)); + + ui->le_AircraftIcaoCacheCount->setText(cacheCountForEntity(CEntityFlags::AircraftIcaoEntity)); + ui->le_AirlineIcaoCacheCount->setText(cacheCountForEntity(CEntityFlags::AirlineIcaoEntity)); + ui->le_LiveriesCacheCount->setText(cacheCountForEntity(CEntityFlags::LiveryEntity)); + ui->le_ModelsCacheCount->setText(cacheCountForEntity(CEntityFlags::ModelEntity)); + ui->le_CountriesCacheCount->setText(cacheCountForEntity(CEntityFlags::CountryEntity)); + ui->le_DistributorsCacheCount->setText(cacheCountForEntity(CEntityFlags::DistributorEntity)); + + ui->le_AircraftIcaoDbCount->setText(dbCountForEntity(CEntityFlags::AircraftIcaoEntity)); + ui->le_AirlineIcaoDbCount->setText(dbCountForEntity(CEntityFlags::AirlineIcaoEntity)); + ui->le_LiveriesDbCount->setText(dbCountForEntity(CEntityFlags::LiveryEntity)); + ui->le_ModelsDbCount->setText(dbCountForEntity(CEntityFlags::ModelEntity)); + ui->le_CountriesDbCount->setText(dbCountForEntity(CEntityFlags::CountryEntity)); + ui->le_DistributorsDbCount->setText(cacheCountForEntity(CEntityFlags::DistributorEntity)); + + const QString urlHtml("Open"); + const QString url = sGui->getGlobalSetup().getDbHomePageUrl().getFullUrl(); + ui->lbl_DatabaseUrl->setText(urlHtml.arg(url)); + ui->lbl_DatabaseUrl->setToolTip(url); + } + + QString CDbLoadOverviewComponent::formattedTimestamp(const QDateTime &dateTime) + { + if (!dateTime.isValid()) { return "-"; } + return dateTime.toUTC().toString("MM-dd hh:mm:ss"); + } + + QString CDbLoadOverviewComponent::cacheTimestampForEntity(CEntityFlags::Entity entity) + { + const QDateTime ts = sGui->getWebDataServices()->getCacheTimestamp(entity); + return formattedTimestamp(ts); + } + + QString CDbLoadOverviewComponent::dbTimestampForEntity(CEntityFlags::Entity entity) + { + const QDateTime ts = sGui->getWebDataServices()->getDbLatestEntityTimestamp(entity); + return formattedTimestamp(ts); + } + + QString CDbLoadOverviewComponent::cacheCountForEntity(CEntityFlags::Entity entity) + { + const int c = sGui->getWebDataServices()->getCacheCount(entity); + return c < 0 ? "-" : QString::number(c); + } + + QString CDbLoadOverviewComponent::dbCountForEntity(CEntityFlags::Entity entity) + { + const int c = sGui->getWebDataServices()->getDbInfoCount(entity); + return c < 0 ? "-" : QString::number(c); + } + + void CDbLoadOverviewComponent::ps_reloadPressed() + { + QObject *sender = QObject::sender(); + CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(sender->objectName()); + sGui->getWebDataServices()->triggerRead(entity); + } + } // ns +} // ns diff --git a/src/blackgui/components/dbloadoverviewcomponent.h b/src/blackgui/components/dbloadoverviewcomponent.h new file mode 100644 index 000000000..3ebf4537f --- /dev/null +++ b/src/blackgui/components/dbloadoverviewcomponent.h @@ -0,0 +1,66 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_DBLOADOVERVIEWCOMPONENT_H +#define BLACKGUI_COMPONENTS_DBLOADOVERVIEWCOMPONENT_H + +#include "blackgui/blackguiexport.h" +#include "blackmisc/network/entityflags.h" +#include +#include + +namespace Ui { class CDbLoadOverviewComponent; } +namespace BlackGui +{ + namespace Components + { + /*! + * Overview about load state of DB data + */ + class BLACKGUI_EXPORT CDbLoadOverviewComponent : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CDbLoadOverviewComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CDbLoadOverviewComponent(); + + private: + QScopedPointer ui; + + //! Init the value panel + void ps_setValues(); + + //! Timestamp + static QString formattedTimestamp(const QDateTime &dateTime); + + //! Formatted ts for entity + static QString cacheTimestampForEntity(BlackMisc::Network::CEntityFlags::Entity entity); + + //! Formatted ts for entity + static QString dbTimestampForEntity(BlackMisc::Network::CEntityFlags::Entity entity); + + //! Formatted count for entity + static QString cacheCountForEntity(BlackMisc::Network::CEntityFlags::Entity entity); + + //! Formatted count for entity + static QString dbCountForEntity(BlackMisc::Network::CEntityFlags::Entity entity); + + private slots: + //! Reload + void ps_reloadPressed(); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/components/dbloadoverviewcomponent.ui b/src/blackgui/components/dbloadoverviewcomponent.ui new file mode 100644 index 000000000..ac2713bb4 --- /dev/null +++ b/src/blackgui/components/dbloadoverviewcomponent.ui @@ -0,0 +1,437 @@ + + + CDbLoadOverviewComponent + + + + 0 + 0 + 482 + 216 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 2 + + + 2 + + + 2 + + + 2 + + + 4 + + + + + true + + + DB ts + + + + + + + + + + + :/pastel/icons/pastel/16/arrow-refresh.png:/pastel/icons/pastel/16/arrow-refresh.png + + + + + + + true + + + count + + + + + + + true + + + cache ts + + + + + + + true + + + count + + + + + + + + :/pastel/icons/pastel/16/arrow-refresh.png:/pastel/icons/pastel/16/arrow-refresh.png + + + + + + + + + + + :/pastel/icons/pastel/16/arrow-refresh.png:/pastel/icons/pastel/16/arrow-refresh.png + + + + + + + true + + + count + + + + + + + Liveries: + + + + + + + true + + + DB ts + + + + + + + Aircraft: + + + + + + + true + + + DB ts + + + + + + + true + + + count + + + + + + + true + + + cache ts + + + + + + + true + + + cache ts + + + + + + + Countries: + + + + + + + true + + + cache ts + + + + + + + true + + + cache ts + + + + + + + Models: + + + + + + + DB ts: + + + + + + + true + + + count + + + + + + + true + + + cache ts + + + + + + + true + + + DB ts + + + + + + + true + + + count + + + + + + + true + + + DB ts + + + + + + + Airline: + + + + + + + true + + + DB ts + + + + + + + Cache #: + + + + + + + true + + + count + + + + + + + Cache ts: + + + + + + + DB #: + + + + + + + true + + + count + + + + + + + true + + + count + + + + + + + true + + + count + + + + + + + true + + + count + + + + + + + + + + + :/pastel/icons/pastel/16/arrow-refresh.png:/pastel/icons/pastel/16/arrow-refresh.png + + + + + + + + + + + :/pastel/icons/pastel/16/arrow-refresh.png:/pastel/icons/pastel/16/arrow-refresh.png + + + + + + + true + + + count + + + + + + + + + + + :/pastel/icons/pastel/16/arrow-refresh.png:/pastel/icons/pastel/16/arrow-refresh.png + + + + + + + Distributors: + + + + + + + + 0 + 24 + + + + Database: + + + + + + + URL will go here ..... + + + + + + + + + +