Enroute Flight Navigation
A navigation app for VFR pilots
DataManager.h
1/***************************************************************************
2 * Copyright (C) 2019-2026 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QQmlEngine>
24#include <QStandardPaths>
25
26#include "GlobalObject.h"
27#include "dataManagement/Downloadable_MultiFile.h"
28#include "dataManagement/Downloadable_SingleFile.h"
29#include "units/ByteSize.h"
30
31
32namespace DataManagement {
33
69
71{
72 Q_OBJECT
73 QML_ELEMENT
74 QML_SINGLETON
75
76public:
85 explicit DataManager(QObject* parent=nullptr);
86
87 ~DataManager() override = default;
88
89 // No default constructor, important for QML singleton
90 explicit DataManager() = delete;
91
92 // factory function for QML singleton
93 static DataManagement::DataManager* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/)
94 {
96 }
97
98
99 // deferred initialization
100 void deferredInitialization() override;
101
102
103
104 //
105 // PROPERTIES
106 //
107
115 [[nodiscard]] bool appUpdateRequired() const { return m_appUpdateRequired; }
116
122 [[nodiscard]] DataManagement::Downloadable_MultiFile* aviationMaps() { return &m_aviationMaps; }
123
129 [[nodiscard]] DataManagement::Downloadable_MultiFile* baseMapsRaster() { return &m_baseMapsRaster; }
130
136 [[nodiscard]] DataManagement::Downloadable_MultiFile* baseMapsVector() { return &m_baseMapsVector; }
137
143 [[nodiscard]] DataManagement::Downloadable_MultiFile* baseMaps() { return &m_baseMaps; }
144
150 [[nodiscard]] DataManagement::Downloadable_MultiFile* databases() { return &m_databases; }
151
158 [[nodiscard]] DataManagement::Downloadable_MultiFile* items() { return &m_items; }
159
162 [[nodiscard]] DataManagement::Downloadable_SingleFile* mapList() { return &m_mapList; }
163
166 [[nodiscard]] DataManagement::Downloadable_MultiFile* mapsAndData() { return &m_mapsAndData; }
167
173 [[nodiscard]] DataManagement::Downloadable_MultiFile* mapSets() { return &m_mapSets; }
174
180 [[nodiscard]] DataManagement::Downloadable_MultiFile* terrainMaps() { return &m_terrainMaps; }
181
183 Q_PROPERTY(QString whatsNew READ whatsNew NOTIFY whatsNewChanged)
184 [[nodiscard]] QString whatsNew() const { return m_whatsNew; }
185
188 [[nodiscard]] Units::ByteSize whatsNewHash() const { return qHash(m_whatsNew, 0); }
189
190
191 //
192 // Methods
193 //
194
212 Q_INVOKABLE QString import(const QString& fileName, const QString& newName);
213
229 Q_INVOKABLE QString importOpenAir(const QString& fileName, const QString& newName);
230
231public slots:
238
239signals:
242
250 void error(const QString& message);
251
254
255private:
256 Q_DISABLE_COPY_MOVE(DataManager)
257
258 // Clean the data directory.
259 //
260 // - delete all files with unexpected file names
261 // - earlier versions of this program constructed files with names ending in
262 // ".geojson.geojson" or ".mbtiles.mbtiles". We correct those file names
263 // here.
264 // - remove all empty sub directories
265 void cleanDataDirectory();
266
267 // This slot is called when a local file of one of the Downloadables changes
268 // content or existence. If the Downloadable in question has no file
269 // anymore, and has an invalid URL, it is then removed.
270 void onItemFileChanged();
271
272 // This slot updates the DownloadableGroups as well as the propery
273 // 'whatsNew', by reading the file 'maps.json' and by checking the data
274 // directory for locally installed, unsupported files.
275 void updateDataItemListAndWhatsNew();
276
277 // This method checks if a Downloadable item with the given url and
278 // localFileName already exists in _items. If so, it returns a pointer to
279 // that item. If not, then a Downloadable with the url and localFileName is
280 // created and added to _items. Depending on localFileName, it will also be
281 // added to _aviationMap, _baseMaps, or _databases. A pointer to that item is
282 // then returned.
283 DataManagement::Downloadable_SingleFile* createOrRecycleItem(const QUrl& url, const QString& localFileName, const QGeoRectangle& bBox);
284
285 bool m_appUpdateRequired {false};
286
287 // Full path name of data directory, without trailing slash
288 QString m_dataDirectory {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/aviation_maps"};
289
290 // The current whats new string from _aviationMaps.
291 QString m_whatsNew;
292
293 // This Downloadable object manages the central text file that describes the
294 // remotely available aviation maps.
295 DataManagement::Downloadable_SingleFile m_mapList { QUrl(QStringLiteral("https://enroute-data.akaflieg-freiburg.de/enroute-GeoJSONv003/maps.json")), QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/maps.json" };
296
297 // List of geographic maps
298 DataManagement::Downloadable_MultiFile m_aviationMaps {DataManagement::Downloadable_MultiFile::SingleUpdate};
299 DataManagement::Downloadable_MultiFile m_baseMaps {DataManagement::Downloadable_MultiFile::SingleUpdate};
300 DataManagement::Downloadable_MultiFile m_baseMapsRaster {DataManagement::Downloadable_MultiFile::SingleUpdate};
301 DataManagement::Downloadable_MultiFile m_baseMapsVector {DataManagement::Downloadable_MultiFile::SingleUpdate};
302 DataManagement::Downloadable_MultiFile m_databases {DataManagement::Downloadable_MultiFile::SingleUpdate};
303 DataManagement::Downloadable_MultiFile m_items {DataManagement::Downloadable_MultiFile::SingleUpdate};
304 DataManagement::Downloadable_MultiFile m_mapsAndData {DataManagement::Downloadable_MultiFile::SingleUpdate};
305 DataManagement::Downloadable_MultiFile m_terrainMaps {DataManagement::Downloadable_MultiFile::SingleUpdate};
306
307 // List of geographic map sets
308 DataManagement::Downloadable_MultiFile m_mapSets {DataManagement::Downloadable_MultiFile::SingleUpdate};
309};
310
311} // namespace DataManagement
Manages the list of geographic maps.
Definition DataManager.h:71
Units::ByteSize whatsNewHash
Hash of the current "what's new" message.
DataManagement::Downloadable_MultiFile * baseMaps
Downloadable_MultiFile that holds all base maps.
void deferredInitialization() override
Non-constructor initialization.
DataManagement::Downloadable_MultiFile * terrainMaps
Downloadable_MultiFile that holds all terrain maps.
bool appUpdateRequired
Indiates that the app needs to be updated.
DataManagement::Downloadable_MultiFile * aviationMaps
Downloadable_MultiFile that holds all aviation maps.
DataManagement::Downloadable_MultiFile * databases
Downloadable_MultiFile that holds all databases.
Q_INVOKABLE QString importOpenAir(const QString &fileName, const QString &newName)
Import airspace data into the library of locally installed maps.
DataManagement::Downloadable_MultiFile * items
Downloadable_MultiFile that holds all data items.
DataManagement::Downloadable_MultiFile * baseMapsRaster
Downloadable_MultiFile that holds all base maps in raster format.
DataManagement::Downloadable_MultiFile * baseMapsVector
Downloadable_MultiFile that holds all base maps in vector format.
void whatsNewChanged()
Notifier signal.
DataManagement::Downloadable_MultiFile * mapsAndData
Downloadable_MultiFile that holds all the map sets and databases.
DataManager(QObject *parent=nullptr)
Standard constructor.
DataManagement::Downloadable_SingleFile * mapList
Downloadable_SingleFile that holds the list of all maps and databases.
DataManagement::Downloadable_MultiFile * mapSets
Downloadable_MultiFile that holds all map sets.
void error(const QString &message)
Error message for user.
void updateRemoteDataItemListIfOutdated()
Triggers an update of the list of remotely available data items.
QString whatsNew
Current "what's new" message.
Group of closely related downloadable items.
@ SingleUpdate
Update children that are updatable.
static Q_INVOKABLE DataManagement::DataManager * dataManager()
Pointer to appplication-wide static GeoMaps::DataManager instance.
GlobalObject(QObject *parent=nullptr)
Standard constructor.
Convenience class for size_t.
Definition ByteSize.h:37