swift
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 
11 #include "core/webdataservices.h"
13 #include "gui/guiapplication.h"
14 #include "gui/views/liveryview.h"
15 
16 using namespace swift::core;
17 using namespace swift::gui::views;
18 using namespace swift::misc::aviation;
19 using namespace swift::misc::network;
20 
21 namespace swift::gui::components
22 {
23  CDbLiveryComponent::CDbLiveryComponent(QWidget *parent)
24  : COverlayMessagesFrame(parent), ui(new Ui::CDbLiveryComponent)
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,
36  Qt::QueuedConnection);
37  connect(sGui->getWebDataServices(), &CWebDataServices::entityDownloadProgress, this,
38  &CDbLiveryComponent::onEntityDownloadProgress, Qt::QueuedConnection);
39  this->onLiveriesRead(CEntityFlags::LiveryEntity, CEntityFlags::ReadFinished,
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()) { return; }
57  if (!entity.testFlag(CEntityFlags::LiveryEntity)) { return; }
58 
59  if (CEntityFlags::isFinishedReadState(readState))
60  {
61  this->showOverlayHTMLMessage(QStringLiteral("Updating %1").arg(CEntityFlags::entitiesToString(entity)), 2s);
62  ui->tvp_Liveries->updateContainerMaybeAsync(sGui->getWebDataServices()->getLiveries());
63  }
64  else
65  {
66  this->showOverlayHTMLMessage(u"Current state: " % CEntityFlags::entitiesToString(entity) % u" " %
67  CEntityFlags::stateToString(readState),
68  10s);
69  }
70  }
71 
72  void CDbLiveryComponent::onEntityDownloadProgress(CEntityFlags::Entity entity, int logId, int progress,
73  qint64 current, qint64 max, const QUrl &url)
74  {
75  using namespace std::chrono_literals;
76 
77  if (!entity.testFlag(CEntityFlags::LiveryEntity)) { return; }
78  this->showDownloadProgress(progress, current, max, url, 5s);
79  Q_UNUSED(logId);
80  }
81 
82  void CDbLiveryComponent::onReload()
83  {
84  if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { return; }
85  sGui->getWebDataServices()->triggerLoadingDirectlyFromDb(CEntityFlags::LiveryEntity);
86  }
87 } // namespace swift::gui::components
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
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.
swift::misc::aviation::CLiveryList getLiveries() const
Liveries.
int getLiveriesCount() const
Liveries count.
void setViewWithIndicator(swift::gui::views::CViewBaseNonTemplate *viewWithIndicator)
Set the corresponding view.
bool showOverlayHTMLMessage(const QString &htmlMessage, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
HTML message.
void showDownloadProgress(int progress, qint64 current, qint64 max, const QUrl &url, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Download progress.
Using this class provides a QFrame with the overlay functionality already integrated.
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.
Value object for ICAO classification.
Value object encapsulating information about an airpot.
Definition: livery.h:29
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.
Definition: aboutdialog.cpp:13
Views, mainly QTableView.