swift
datainfoareacomponent.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 <QDateTime>
7 #include <QIcon>
8 #include <QTabWidget>
9 #include <QtGlobal>
10 
11 #include "ui_datainfoareacomponent.h"
12 
13 #include "core/webdataservices.h"
21 #include "gui/guiapplication.h"
22 #include "misc/directoryutils.h"
23 #include "misc/icons.h"
24 #include "misc/logmessage.h"
26 #include "misc/statusmessage.h"
27 #include "misc/swiftdirectories.h"
28 #include "misc/verify.h"
29 
30 using namespace swift::misc;
31 using namespace swift::misc::network;
32 using namespace swift::gui;
33 using namespace swift::gui::components;
34 
35 namespace swift::gui::components
36 {
37  CDataInfoAreaComponent::CDataInfoAreaComponent(QWidget *parent)
38  : CInfoArea(parent), ui(new Ui::CDataInfoAreaComponent)
39  {
40  ui->setupUi(this);
41  this->initInfoArea(); // init base class
42  this->setWindowIcon(CIcons::swiftDatabase24());
43  this->setTabBarPosition(QTabWidget::North);
44  }
45 
47 
48  CDbModelComponent *CDataInfoAreaComponent::getModelComponent() const { return ui->comp_DbModels; }
49 
50  CDbLiveryComponent *CDataInfoAreaComponent::getLiveryComponent() const { return ui->comp_DbLiveries; }
51 
52  CDbDistributorComponent *CDataInfoAreaComponent::getDistributorComponent() const { return ui->comp_DbDistributors; }
53 
54  CDbAircraftIcaoComponent *CDataInfoAreaComponent::getAircraftComponent() const { return ui->comp_DbAircraftIcao; }
55 
56  CDbAirlineIcaoComponent *CDataInfoAreaComponent::getAirlineComponent() const { return ui->comp_DbAirlineIcao; }
57 
58  CDbCountryComponent *CDataInfoAreaComponent::getCountryComponent() const { return ui->comp_DbCountries; }
59 
61  {
62  return ui->comp_DbAircraftCategories;
63  }
64 
66  {
68  {
69  CLogMessage(this).warning(u"No connection to DB yet, no new data loaded which can be written");
70  return false;
71  }
72 
73  // write to disk
74  const bool s = sGui->getWebDataServices()->writeDbDataToDisk(CSwiftDirectories::staticDbFilesDirectory());
75  if (s) { CLogMessage(this).info(u"Written DB data"); }
76  else { CLogMessage(this).error(u"Cannot write DB data"); }
77  return s;
78  }
79 
81  {
82  if (!sGui) { return false; }
84 
85  // info
86  bool ok = false;
87  if (msgs.isSuccess())
88  {
89  CLogMessage(this).info(u"Read DB data from directory: %1") << CSwiftDirectories::staticDbFilesDirectory();
90  ui->comp_DbAircraftIcao->showLoadIndicator();
91  ui->comp_DbAirlineIcao->showLoadIndicator();
92  ui->comp_DbCountries->showLoadIndicator();
93  ui->comp_DbDistributors->showLoadIndicator();
94  ui->comp_DbLiveries->showLoadIndicator();
95  ui->comp_DbModels->showLoadIndicator();
96  ok = true;
97  }
98  else { CLogMessage::preformatted(msgs); }
99  return ok;
100  }
101 
103  {
104  InfoArea area = static_cast<InfoArea>(areaIndex);
105  switch (area)
106  {
107  case InfoAreaAircraftIcao:
108  case InfoAreaAirlineIcao:
109  case InfoAreaLiveries:
110  case InfoAreaModels:
111  case InfoAreaCountries:
112  case InfoAreaAircraftCategories:
113  default: return QSize(800, 600);
114  }
115  }
116 
117  const QPixmap &CDataInfoAreaComponent::indexToPixmap(int areaIndex) const
118  {
119  InfoArea area = static_cast<InfoArea>(areaIndex);
120  switch (area)
121  {
122  case InfoAreaAircraftIcao: return CIcons::appAircraftIcao16();
123  case InfoAreaAirlineIcao: return CIcons::appAirlineIcao16();
124  case InfoAreaLiveries: return CIcons::appLiveries16();
125  case InfoAreaDistributors: return CIcons::appDistributors16();
126  case InfoAreaModels: return CIcons::appModels16();
127  case InfoAreaCountries: return CIcons::appCountries16();
128  case InfoAreaAircraftCategories: return CIcons::appAircraftCategories16();
129  default: return CIcons::empty();
130  }
131  }
132 
134  {
136  CEntityFlags::AllDbEntitiesNoInfoObjectsNoAirportsAndCategories, QDateTime());
137  }
138 
139  void CDataInfoAreaComponent::requestUpdatedData(CEntityFlags::Entity entity)
140  {
141  bool requested = false;
142  if (entity.testFlag(CEntityFlags::ModelEntity))
143  {
144  ui->comp_DbModels->requestUpdatedData();
145  requested = true;
146  }
147 
148  // sanity
149  SWIFT_VERIFY_X(requested, Q_FUNC_INFO, "Entity not supported");
150  Q_UNUSED(requested);
151  }
152 } // namespace swift::gui::components
CWebDataServices * getWebDataServices() const
Get the web data services.
bool hasSuccesfullyConnectedSwiftDb() const
Has already successfully connect swift DB?
swift::misc::CStatusMessageList initDbCachesFromLocalResourceFiles(bool inBackground)
Init caches from local DB files.
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.
bool writeDbDataToDisk(const QString &dir)
Write data to disk (mainly for testing scenarios)
Info area, hosting dockable widgets.
Definition: infoarea.h:41
void setTabBarPosition(QTabWidget::TabPosition position)
Tab position for docked widgets tab.
Definition: infoarea.cpp:874
void initInfoArea()
Init area after(!) GUI is initialized.
Definition: infoarea.cpp:47
Info area containing the DB data (models, liveries ...)
void requestUpdateOfAllDbData()
Request update of all DB data.
CDbAirlineIcaoComponent * getAirlineComponent() const
DB airline ICAO component.
CDbModelComponent * getModelComponent() const
DB model component.
CDbAircraftIcaoComponent * getAircraftComponent() const
DB aircraft ICAO component.
CDbDistributorComponent * getDistributorComponent() const
DB distributor component.
CDbAircraftCategoryComponent * getAircraftCategoryComponent() const
DB aircraft category componentxs.
bool writeDbDataToResourceDir() const
Write to resource dir.
void requestUpdatedData(swift::misc::network::CEntityFlags::Entity entity)
Load new data (based on timestamp, incremental)
CDbLiveryComponent * getLiveryComponent() const
DB livery component.
CDbCountryComponent * getCountryComponent() const
DB country component.
virtual QSize getPreferredSizeWhenFloating(int areaIndex) const
Preferred size when floating (size hint)
virtual const QPixmap & indexToPixmap(int areaIndex) const
Info area (index) to icon.
Class for emitting a log message.
Definition: logmessage.h:27
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
Status messages, e.g. from Core -> GUI.
bool isSuccess() const
All messages are marked as success.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Definition: aboutdialog.cpp:13
GUI related classes.
Free functions in swift::misc.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
Definition: verify.h:26