File indexing completed on 2025-02-02 05:02:32

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef MAPDOWNLOADMANAGER_H
0008 #define MAPDOWNLOADMANAGER_H
0009 
0010 #include <QDateTime>
0011 #include <QObject>
0012 
0013 #include <vector>
0014 
0015 class ReservationManager;
0016 
0017 namespace SolidExtras {
0018 class NetworkStatus;
0019 }
0020 
0021 namespace KOSMIndoorMap {
0022 class MapLoader;
0023 }
0024 
0025 /** Downloads indoor map tiles for upcoming trips. */
0026 class MapDownloadManager : public QObject
0027 {
0028     Q_OBJECT
0029 public:
0030     explicit MapDownloadManager(QObject *parent = nullptr);
0031     ~MapDownloadManager() override;
0032 
0033     void setReservationManager(ReservationManager *resMgr);
0034     // TODO always process complete trip groups?
0035     // TODO should we also handle transfer locations?
0036 
0037     /** Trigger download of missing map data immediately, regardless of the current network state. */
0038     Q_INVOKABLE void download();
0039 
0040     void setAutomaticDownloadEnabled(bool enable);
0041 
0042     // TODO progress reporting, cancel?
0043 
0044 Q_SIGNALS:
0045     /** All pending downloads have been completed. */
0046     void finished();
0047 
0048 private:
0049     bool canAutoDownload() const;
0050     void addAutomaticRequestForBatch(const QString &batchId);
0051     void addRequestForBatch(const QString &batchId);
0052     void addRequest(double lat, double lon, const QDateTime &cacheUntil);
0053     void downloadNext();
0054     void downloadFinished();
0055     void networkStatusChanged();
0056 
0057     ReservationManager *m_resMgr = nullptr;
0058     bool m_autoDownloadEnabled = false;
0059 
0060     struct Request {
0061         double lat;
0062         double lon;
0063         QDateTime cacheUntil;
0064     };
0065     std::vector<Request> m_pendingRequests;
0066     std::vector<Request> m_cachedRequests;
0067     Request m_currentRequest;
0068 
0069     KOSMIndoorMap::MapLoader *m_loader = nullptr;
0070     SolidExtras::NetworkStatus *m_netStatus = nullptr;
0071 };
0072 
0073 #endif // MAPDOWNLOADMANAGER_H