QGCMapEngine.h 4 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38


/**
 * @file
 *   @brief Map Tile Cache
 *
 *   @author Gus Grubba <mavlink@grubba.com>
 *
 */

#ifndef QGC_MAP_ENGINE_H
#define QGC_MAP_ENGINE_H

#include <QString>

#include "QGCMapUrlEngine.h"
#include "QGCMapEngineData.h"
#include "QGCTileCacheWorker.h"


//-----------------------------------------------------------------------------
class QGCMapEngine : public QObject
{
    Q_OBJECT
public:
    QGCMapEngine                ();
    ~QGCMapEngine               ();

    void                        init                ();
    void                        addTask             (QGCMapTask *task);
39 40 41
    void                        cacheTile           (QString type, int x, int y, int z, const QByteArray& image, const QString& format, qulonglong set = UINT64_MAX);
    void                        cacheTile           (QString type, const QString& hash, const QByteArray& image, const QString& format, qulonglong set = UINT64_MAX);
    QGCFetchTileTask*           createFetchTileTask (QString type, int x, int y, int z);
dogmaphobic's avatar
dogmaphobic committed
42 43 44
    QStringList                 getMapNameList      ();
    const QString               userAgent           () { return _userAgent; }
    void                        setUserAgent        (const QString& ua) { _userAgent = ua; }
45
    QString         hashToType          (const QString& hash);
dogmaphobic's avatar
dogmaphobic committed
46 47 48 49 50 51
    quint32                     getMaxDiskCache     ();
    void                        setMaxDiskCache     (quint32 size);
    quint32                     getMaxMemCache      ();
    void                        setMaxMemCache      (quint32 size);
    const QString               getCachePath        () { return _cachePath; }
    const QString               getCacheFilename    () { return _cacheFile; }
52
    void                        testInternet        ();
dogmaphobic's avatar
dogmaphobic committed
53
    bool                        wasCacheReset       () { return _cacheWasReset; }
54
    bool                        isInternetActive    () { return _isInternetActive; }
dogmaphobic's avatar
dogmaphobic committed
55 56 57 58

    UrlFactory*                 urlFactory          () { return _urlFactory; }

    //-- Tile Math
59 60
    static QGCTileSet           getTileCount        (int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, QString mapType);
    static QString              getTileHash         (QString type, int x, int y, int z);
61
    static QString              getTypeFromName     (const QString &name);
dogmaphobic's avatar
dogmaphobic committed
62
    static QString              bigSizeToString     (quint64 size);
63
    static QString              storageFreeSizeToString(quint64 size_MB);
dogmaphobic's avatar
dogmaphobic committed
64
    static QString              numberToString      (quint64 number);
65
    static int                  concurrentDownloads (QString type);
dogmaphobic's avatar
dogmaphobic committed
66 67 68 69

private slots:
    void _updateTotals          (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize);
    void _pruned                ();
70
    void _internetStatus        (bool active);
dogmaphobic's avatar
dogmaphobic committed
71 72 73

signals:
    void updateTotals           (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize);
74
    void internetUpdated        ();
dogmaphobic's avatar
dogmaphobic committed
75

76
private:
dogmaphobic's avatar
dogmaphobic committed
77
    void _wipeOldCaches         ();
dogmaphobic's avatar
dogmaphobic committed
78
    void _checkWipeDirectory    (const QString& dirPath);
dogmaphobic's avatar
dogmaphobic committed
79
    bool _wipeDirectory         (const QString& dirPath);
80

dogmaphobic's avatar
dogmaphobic committed
81 82 83 84 85 86 87 88 89
private:
    QGCCacheWorker          _worker;
    QString                 _cachePath;
    QString                 _cacheFile;
    UrlFactory*             _urlFactory;
    QString                 _userAgent;
    quint32                 _maxDiskCache;
    quint32                 _maxMemCache;
    bool                    _prunning;
dogmaphobic's avatar
dogmaphobic committed
90
    bool                    _cacheWasReset;
91
    bool                    _isInternetActive;
dogmaphobic's avatar
dogmaphobic committed
92 93 94 95 96 97
};

extern QGCMapEngine*    getQGCMapEngine();
extern void             destroyMapEngine();

#endif // QGC_MAP_ENGINE_H