swift
Loading...
Searching...
No Matches
dbliverycomponent.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QStringBuilder>
7#include <QtGlobal>
8
9#include "ui_dbliverycomponent.h"
10
13#include "gui/guiapplication.h"
15
16using namespace swift::core;
17using namespace swift::gui::views;
18using namespace swift::misc::aviation;
19using namespace swift::misc::network;
20
22{
25 {
26 ui->setupUi(this);
27 this->setViewWithIndicator(ui->tvp_Liveries);
28 connect(ui->tvp_Liveries, &CLiveryView::requestNewBackendData, this, &CDbLiveryComponent::onReload);
29
30 // filter and drag and drop
31 ui->tvp_Liveries->setFilterWidget(ui->filter_Livery);
32 ui->tvp_Liveries->allowDragDrop(true, false);
33 ui->tvp_Liveries->menuAddItems(CViewBaseNonTemplate::MenuCopy);
34
35 connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbLiveryComponent::onLiveriesRead,
37 connect(sGui->getWebDataServices(), &CWebDataServices::entityDownloadProgress, this,
38 &CDbLiveryComponent::onEntityDownloadProgress, Qt::QueuedConnection);
40 sGui->getWebDataServices()->getLiveriesCount());
41 }
42
44
45 CLiveryView *CDbLiveryComponent::view() { return ui->tvp_Liveries; }
46
47 void CDbLiveryComponent::filter(const swift::misc::aviation::CLivery &livery) { ui->filter_Livery->filter(livery); }
48
49 void CDbLiveryComponent::filterByAirline(const CAirlineIcaoCode &icao) { ui->filter_Livery->filter(icao); }
50
51 void CDbLiveryComponent::onLiveriesRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count)
52 {
53 using namespace std::chrono_literals;
54
55 Q_UNUSED(count);
56 if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices())
57 {
58 return;
59 }
60 if (!entity.testFlag(CEntityFlags::LiveryEntity))
61 {
62 return;
63 }
64
66 {
67 this->showOverlayHTMLMessage(QStringLiteral("Updating %1").arg(CEntityFlags::entitiesToString(entity)), 2s);
68 ui->tvp_Liveries->updateContainerMaybeAsync(sGui->getWebDataServices()->getLiveries());
69 }
70 else
71 {
72 this->showOverlayHTMLMessage(u"Current state: " % CEntityFlags::entitiesToString(entity) % u" " %
74 10s);
75 }
76 }
77
78 void CDbLiveryComponent::onEntityDownloadProgress(CEntityFlags::Entity entity, int logId, int progress,
79 qint64 current, qint64 max, const QUrl &url)
80 {
81 using namespace std::chrono_literals;
82
83 if (!entity.testFlag(CEntityFlags::LiveryEntity))
84 {
85 return;
86 }
87 this->showDownloadProgress(progress, current, max, url, 5s);
88 Q_UNUSED(logId);
89 }
90
91 void CDbLiveryComponent::onReload()
92 {
94 {
95 return;
96 }
98 }
99} // namespace swift::gui::components
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
void entityDownloadProgress(swift::misc::network::CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url)
Download progress for an entity.
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 dataRead(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CEntityFlags::ReadState state, int number, const QUrl &url)
Combined read signal.
void setViewWithIndicator(swift::gui::views::CViewBaseNonTemplate *viewWithIndicator)
Set the corresponding view.
bool showOverlayHTMLMessage(const QString &htmlMessage, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
void showDownloadProgress(int progress, qint64 current, qint64 max, const QUrl &url, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
COverlayMessagesFrame(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor.
CDbLiveryComponent(QWidget *parent=nullptr)
Constructor.
void filterByAirline(const swift::misc::aviation::CAirlineIcaoCode &icao)
Filter by airline ICAO.
swift::gui::views::CLiveryView * view()
The livery view.
void filter(const swift::misc::aviation::CLivery &livery)
Filter by livery.
void requestNewBackendData()
Load data from backend (where it makes sense).
@ MenuCopy
copy (for copy/paste)
Definition viewbase.h:132
Value object for ICAO classification.
Value object encapsulating information about an airpot.
Definition livery.h:29
static bool isFinishedReadState(ReadState state)
Any finished state.
static const QString & stateToString(ReadState flag)
Convert to string.
static QString entitiesToString(CEntityFlags::Entity entities, const QString &separator=", ")
Entities to string list.
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.
Definition actionbind.cpp:7
High level reusable GUI components.
Views, mainly QTableView.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QueuedConnection
QWidget(QWidget *parent, Qt::WindowFlags f)