libosmscout  1.1.1
MapManager.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_MAPMANAGER_H
2 #define OSMSCOUT_CLIENT_QT_MAPMANAGER_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2016 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include <QObject>
24 #include <QStringList>
25 #include <QList>
26 #include <QDir>
27 #include <QTimer>
28 
30 
31 #include <osmscout/MapProvider.h>
32 #include <osmscout/Settings.h>
35 
36 #include <QtGlobal>
37 #include <QStorageInfo>
38 
39 namespace osmscout {
40 
47 {
48  Q_OBJECT
49 
51 
52 public:
53  static const char* FILE_METADATA;
54 
55  MapDownloadJob(QNetworkAccessManager *webCtrl, AvailableMapsModelMap map, QDir target, bool replaceExisting);
56 
62  ~MapDownloadJob() override;
63 
64  void start();
65 
66  inline QString getMapName() const
67  {
68  return map.getName();
69  }
70 
71  inline QStringList getMapPath() const
72  {
73  return map.getPath();
74  }
75 
76  inline uint64_t expectedSize() const override
77  {
78  return map.getSize();
79  }
80 };
81 
88 {
89 public:
90  MapDirectory() = default;
91  explicit MapDirectory(QDir dir);
92  ~MapDirectory() = default;
93 
94  MapDirectory(const MapDirectory &other) = default;
95  MapDirectory &operator=(const MapDirectory &other) = default;
96 
97  MapDirectory(MapDirectory &&other) = default;
98  MapDirectory &operator=(MapDirectory &&other) = default;
99 
100  QDir getDir() const
101  {
102  return dir;
103  }
104 
108  bool deleteDatabase();
109 
114  bool isValid() const
115  {
116  return valid;
117  }
118 
123  bool hasMetadata() const
124  {
125  return metadata;
126  }
127 
134  QString getName() const
135  {
136  return name;
137  }
138 
143  QStringList getPath() const
144  {
145  return path;
146  }
147 
152  inline QDateTime getCreation() const
153  {
154  return creation;
155  }
156 
157  inline bool operator<(const MapDirectory &o) const
158  {
159  if (getName() == o.getName()){
160  return getDir().absolutePath() < o.getDir().absolutePath();
161  }
162  return getName() < o.getName();
163  }
164 
165 private:
166  QDir dir;
167  bool valid{false};
168  bool metadata{false};
169  QString name;
170  QStringList path;
171  QDateTime creation;
172 };
173 
179 class OSMSCOUT_CLIENT_QT_API MapManager: public QObject
180 {
181  Q_OBJECT
182 
183 private:
184  QStringList databaseLookupDirs;
185  QList<MapDirectory> databaseDirectories;
186  QList<MapDownloadJob*> downloadJobs;
187  QNetworkAccessManager webCtrl;
188 
189 public slots:
190  void lookupDatabases();
191  void onJobFinished();
192  void onJobFailed(QString errorMessage);
193 
194 signals:
195  void mapDownloadFails(QString message);
196  void databaseListChanged(QList<QDir> databaseDirectories);
197  void downloadJobsChanged();
198 
199 public:
200  MapManager(QStringList databaseLookupDirs, SettingsRef settings);
201 
202  ~MapManager() override;
203 
211  void downloadMap(AvailableMapsModelMap map, QDir dir, bool replaceExisting = true);
212  void downloadNext();
213 
214  inline QList<MapDownloadJob*> getDownloadJobs() const {
215  return downloadJobs;
216  }
217 
218  inline QStringList getLookupDirectories() const
219  {
220  return databaseLookupDirs;
221  }
222 
223  inline QList<MapDirectory> getDatabaseDirectories() const
224  {
225  return databaseDirectories;
226  }
227 };
228 
232 using MapManagerRef = std::shared_ptr<MapManager>;
233 
234 }
235 
236 #endif /* OSMSCOUT_CLIENT_QT_MAPMANAGER_H */
std::shared_ptr< Settings > SettingsRef
Definition: Settings.h:171
static const char * FILE_METADATA
Definition: MapManager.h:53
Definition: MapManager.h:46
QDateTime getCreation() const
Definition: MapManager.h:152
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
Definition: FileDownloader.h:131
QStringList getMapPath() const
Definition: MapManager.h:71
QList< MapDownloadJob * > getDownloadJobs() const
Definition: MapManager.h:214
QString getName() const
Definition: MapManager.h:134
std::shared_ptr< MapManager > MapManagerRef
Definition: MapManager.h:232
QList< MapDirectory > getDatabaseDirectories() const
Definition: MapManager.h:223
QStringList getLookupDirectories() const
Definition: MapManager.h:218
uint64_t expectedSize() const override
Definition: MapManager.h:76
bool isValid() const
Definition: MapManager.h:114
Definition: Area.h:38
Definition: MapManager.h:179
Definition: AvailableMapsModel.h:120
QString getMapName() const
Definition: MapManager.h:66
bool hasMetadata() const
Definition: MapManager.h:123
bool operator<(const MapDirectory &o) const
Definition: MapManager.h:157
Definition: MapManager.h:87
QStringList getPath() const
Definition: MapManager.h:143
QDir getDir() const
Definition: MapManager.h:100