QGCMapEngineManager.cc 19.1 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * 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


/// @file
Gus Grubba's avatar
Gus Grubba committed
12
///     @author Gus Grubba <gus@auterion.com>
dogmaphobic's avatar
dogmaphobic committed
13

Gus Grubba's avatar
Gus Grubba committed
14
#if !defined(__mobile__)
Gus Grubba's avatar
Gus Grubba committed
15
//-- TODO: #include "QGCQFileDialog.h"
Gus Grubba's avatar
Gus Grubba committed
16 17
#endif

dogmaphobic's avatar
dogmaphobic committed
18 19 20 21
#include "QGCMapEngineManager.h"
#include "QGCApplication.h"
#include "QGCMapTileSet.h"
#include "QGCMapUrlEngine.h"
dogmaphobic's avatar
dogmaphobic committed
22 23

#include <QSettings>
dogmaphobic's avatar
dogmaphobic committed
24
#include <QStorageInfo>
Gus Grubba's avatar
Gus Grubba committed
25
#include <stdio.h>
dogmaphobic's avatar
dogmaphobic committed
26 27 28 29 30 31

QGC_LOGGING_CATEGORY(QGCMapEngineManagerLog, "QGCMapEngineManagerLog")

static const char* kQmlOfflineMapKeyName = "QGCOfflineMap";

//-----------------------------------------------------------------------------
32 33
QGCMapEngineManager::QGCMapEngineManager(QGCApplication* app, QGCToolbox* toolbox)
    : QGCTool(app, toolbox)
dogmaphobic's avatar
dogmaphobic committed
34 35 36 37 38 39 40 41 42
    , _topleftLat(0.0)
    , _topleftLon(0.0)
    , _bottomRightLat(0.0)
    , _bottomRightLon(0.0)
    , _minZoom(0)
    , _maxZoom(0)
    , _setID(UINT64_MAX)
    , _freeDiskSpace(0)
    , _diskSpace(0)
43
    , _fetchElevation(true)
Gus Grubba's avatar
Gus Grubba committed
44 45 46
    , _actionProgress(0)
    , _importAction(ActionNone)
    , _importReplace(false)
dogmaphobic's avatar
dogmaphobic committed
47 48 49 50 51 52 53
{

}

//-----------------------------------------------------------------------------
QGCMapEngineManager::~QGCMapEngineManager()
{
54
    _tileSets.clear();
dogmaphobic's avatar
dogmaphobic committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::setToolbox(QGCToolbox *toolbox)
{
   QGCTool::setToolbox(toolbox);
   QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
   qmlRegisterUncreatableType<QGCMapEngineManager>("QGroundControl.QGCMapEngineManager", 1, 0, "QGCMapEngineManager", "Reference only");
   connect(getQGCMapEngine(), &QGCMapEngine::updateTotals, this, &QGCMapEngineManager::_updateTotals);
   _updateDiskFreeSpace();
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::updateForCurrentView(double lon0, double lat0, double lon1, double lat1, int minZoom, int maxZoom, const QString& mapName)
{
    _topleftLat     = lat0;
    _topleftLon     = lon0;
    _bottomRightLat = lat1;
    _bottomRightLon = lon1;
    _minZoom        = minZoom;
    _maxZoom        = maxZoom;
78 79 80 81

    _imageSet.clear();
    _elevationSet.clear();

dogmaphobic's avatar
dogmaphobic committed
82
    for(int z = minZoom; z <= maxZoom; z++) {
83
        QGCTileSet set = QGCMapEngine::getTileCount(z, lon0, lat0, lon1, lat1, mapName);
84
        _imageSet += set;
dogmaphobic's avatar
dogmaphobic committed
85
    }
86
    if (_fetchElevation) {
87
        QGCTileSet set = QGCMapEngine::getTileCount(1, lon0, lat0, lon1, lat1, "Airmap Elevation");
88
        _elevationSet += set;
89
    }
90

91 92 93 94
    emit tileCountChanged();
    emit tileSizeChanged();

    qCDebug(QGCMapEngineManagerLog) << "updateForCurrentView" << lat0 << lon0 << lat1 << lon1 << minZoom << maxZoom;
dogmaphobic's avatar
dogmaphobic committed
95 96 97 98 99 100
}

//-----------------------------------------------------------------------------
QString
QGCMapEngineManager::tileCountStr()
{
101
    return QGCMapEngine::numberToString(_imageSet.tileCount + _elevationSet.tileCount);
dogmaphobic's avatar
dogmaphobic committed
102 103 104 105 106 107
}

//-----------------------------------------------------------------------------
QString
QGCMapEngineManager::tileSizeStr()
{
108
    return QGCMapEngine::bigSizeToString(_imageSet.tileSize + _elevationSet.tileSize);
dogmaphobic's avatar
dogmaphobic committed
109 110 111 112 113 114 115
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::loadTileSets()
{
    if(_tileSets.count()) {
116
        _tileSets.clear();
dogmaphobic's avatar
dogmaphobic committed
117 118 119 120 121 122 123 124 125 126 127 128 129
        emit tileSetsChanged();
    }
    QGCFetchTileSetTask* task = new QGCFetchTileSetTask();
    connect(task, &QGCFetchTileSetTask::tileSetFetched, this, &QGCMapEngineManager::_tileSetFetched);
    connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
    getQGCMapEngine()->addTask(task);
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::_tileSetFetched(QGCCachedTileSet* tileSet)
{
    //-- A blank (default) type means it uses various types and not just one
130
    if(tileSet->type() == "Invalid") {
dogmaphobic's avatar
dogmaphobic committed
131 132 133 134 135 136 137 138 139
        tileSet->setMapTypeStr("Various");
    }
    _tileSets.append(tileSet);
    tileSet->setManager(this);
    emit tileSetsChanged();
}

//-----------------------------------------------------------------------------
void
dogmaphobic's avatar
dogmaphobic committed
140
QGCMapEngineManager::startDownload(const QString& name, const QString& mapType)
dogmaphobic's avatar
dogmaphobic committed
141
{
142
    if(_imageSet.tileSize) {
dogmaphobic's avatar
dogmaphobic committed
143
        QGCCachedTileSet* set = new QGCCachedTileSet(name);
dogmaphobic's avatar
dogmaphobic committed
144 145 146 147 148 149 150
        set->setMapTypeStr(mapType);
        set->setTopleftLat(_topleftLat);
        set->setTopleftLon(_topleftLon);
        set->setBottomRightLat(_bottomRightLat);
        set->setBottomRightLon(_bottomRightLon);
        set->setMinZoom(_minZoom);
        set->setMaxZoom(_maxZoom);
151
        set->setTotalTileSize(_imageSet.tileSize);
152
        set->setTotalTileCount(static_cast<quint32>(_imageSet.tileCount));
153
        set->setType(mapType);
dogmaphobic's avatar
dogmaphobic committed
154 155 156 157 158 159 160 161
        QGCCreateTileSetTask* task = new QGCCreateTileSetTask(set);
        //-- Create Tile Set (it will also create a list of tiles to download)
        connect(task, &QGCCreateTileSetTask::tileSetSaved, this, &QGCMapEngineManager::_tileSetSaved);
        connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
        getQGCMapEngine()->addTask(task);
    } else {
        qWarning() <<  "QGCMapEngineManager::startDownload() No Tiles to save";
    }
162
    if (mapType != "Airmap Elevation" && _fetchElevation) {
163
        QGCCachedTileSet* set = new QGCCachedTileSet(name + " Elevation");
164
        set->setMapTypeStr("Airmap Elevation");
165 166 167 168 169 170
        set->setTopleftLat(_topleftLat);
        set->setTopleftLon(_topleftLon);
        set->setBottomRightLat(_bottomRightLat);
        set->setBottomRightLon(_bottomRightLon);
        set->setMinZoom(1);
        set->setMaxZoom(1);
171
        set->setTotalTileSize(_elevationSet.tileSize);
172
        set->setTotalTileCount(static_cast<quint32>(_elevationSet.tileCount));
173
        set->setType("Airmap Elevation");
174 175 176 177 178 179 180 181
        QGCCreateTileSetTask* task = new QGCCreateTileSetTask(set);
        //-- Create Tile Set (it will also create a list of tiles to download)
        connect(task, &QGCCreateTileSetTask::tileSetSaved, this, &QGCMapEngineManager::_tileSetSaved);
        connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
        getQGCMapEngine()->addTask(task);
    } else {
        qWarning() <<  "QGCMapEngineManager::startDownload() No Tiles to save";
    }
dogmaphobic's avatar
dogmaphobic committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::_tileSetSaved(QGCCachedTileSet *set)
{
    qCDebug(QGCMapEngineManagerLog) << "New tile set saved (" << set->name() << "). Starting download...";
    _tileSets.append(set);
    emit tileSetsChanged();
    //-- Start downloading tiles
    set->createDownloadTask();
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::saveSetting (const QString& key, const QString& value)
{
    QSettings settings;
    settings.beginGroup(kQmlOfflineMapKeyName);
    settings.setValue(key, value);
}

//-----------------------------------------------------------------------------
QString
QGCMapEngineManager::loadSetting (const QString& key, const QString& defaultValue)
{
    QSettings settings;
    settings.beginGroup(kQmlOfflineMapKeyName);
    return settings.value(key, defaultValue).toString();
}

//-----------------------------------------------------------------------------
QStringList
QGCMapEngineManager::mapList()
{
    return getQGCMapEngine()->getMapNameList();
}
219 220 221 222 223 224 225 226 227 228 229 230 231
//-----------------------------------------------------------------------------
QStringList
QGCMapEngineManager::mapProviderList()
{
    // Extract Provider name from MapName ( format : "Provider Type")
    QStringList mapList = getQGCMapEngine()->getMapNameList();
    mapList.replaceInStrings(QRegExp("^([^\\ ]*) (.*)$"),"\\1");
    mapList.removeDuplicates();
    return mapList;
}

//-----------------------------------------------------------------------------
QStringList
Pierre TILAK's avatar
Pierre TILAK committed
232
QGCMapEngineManager::mapTypeList(QString provider)
233 234 235
{
    // Extract type name from MapName ( format : "Provider Type")
    QStringList mapList = getQGCMapEngine()->getMapNameList();
Pierre TILAK's avatar
Pierre TILAK committed
236 237
    mapList = mapList.filter(QRegularExpression(provider));
    mapList.replaceInStrings(QRegExp("^([^\\ ]*) (.*)$"),"\\2");
238 239 240
    mapList.removeDuplicates();
    return mapList;
}
dogmaphobic's avatar
dogmaphobic committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278

//-----------------------------------------------------------------------------
quint32
QGCMapEngineManager::maxMemCache()
{
    return getQGCMapEngine()->getMaxMemCache();
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::setMaxMemCache(quint32 size)
{
    getQGCMapEngine()->setMaxMemCache(size);
}

//-----------------------------------------------------------------------------
quint32
QGCMapEngineManager::maxDiskCache()
{
    return getQGCMapEngine()->getMaxDiskCache();
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::setMaxDiskCache(quint32 size)
{
    getQGCMapEngine()->setMaxDiskCache(size);
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::deleteTileSet(QGCCachedTileSet* tileSet)
{
    qCDebug(QGCMapEngineManagerLog) << "Deleting tile set " << tileSet->name();
    //-- If deleting default set, delete it all
    if(tileSet->defaultSet()) {
        for(int i = 0; i < _tileSets.count(); i++ ) {
            QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
279 280 281
            if(set) {
                set->setDeleting(true);
            }
dogmaphobic's avatar
dogmaphobic committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295
        }
        QGCResetTask* task = new QGCResetTask();
        connect(task, &QGCResetTask::resetCompleted, this, &QGCMapEngineManager::_resetCompleted);
        connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
        getQGCMapEngine()->addTask(task);
    } else {
        tileSet->setDeleting(true);
        QGCDeleteTileSetTask* task = new QGCDeleteTileSetTask(tileSet->setID());
        connect(task, &QGCDeleteTileSetTask::tileSetDeleted, this, &QGCMapEngineManager::_tileSetDeleted);
        connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
        getQGCMapEngine()->addTask(task);
    }
}

Gus Grubba's avatar
Gus Grubba committed
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
//-----------------------------------------------------------------------------
void
QGCMapEngineManager::renameTileSet(QGCCachedTileSet* tileSet, QString newName)
{
    //-- Name must be unique
    int idx = 1;
    QString name = newName;
    while(findName(name)) {
        name = QString("%1 (%2)").arg(newName).arg(idx++);
    }
    qCDebug(QGCMapEngineManagerLog) << "Renaming tile set " << tileSet->name() << "to" << name;
    tileSet->setName(name);
    QGCRenameTileSetTask* task = new QGCRenameTileSetTask(tileSet->setID(), name);
    connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
    getQGCMapEngine()->addTask(task);
    emit tileSet->nameChanged();
}

dogmaphobic's avatar
dogmaphobic committed
314 315 316 317 318 319 320 321 322 323 324 325 326
//-----------------------------------------------------------------------------
void
QGCMapEngineManager::_resetCompleted()
{
    //-- Reload sets
    loadTileSets();
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::_tileSetDeleted(quint64 setID)
{
    //-- Tile Set successfully deleted
327
    QGCCachedTileSet* setToDelete = nullptr;
dogmaphobic's avatar
dogmaphobic committed
328 329 330
    int i = 0;
    for(i = 0; i < _tileSets.count(); i++ ) {
        QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
331
        if (set && set->setID() == setID) {
dogmaphobic's avatar
dogmaphobic committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
            setToDelete = set;
            break;
        }
    }
    if(setToDelete) {
        _tileSets.removeAt(i);
        delete setToDelete;
    }
    emit tileSetsChanged();
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::taskError(QGCMapTask::TaskType type, QString error)
{
    QString task;
    switch(type) {
    case QGCMapTask::taskFetchTileSets:
        task = "Fetch Tile Set";
        break;
    case QGCMapTask::taskCreateTileSet:
        task = "Create Tile Set";
        break;
    case QGCMapTask::taskGetTileDownloadList:
        task = "Get Tile Download List";
        break;
    case QGCMapTask::taskUpdateTileDownloadState:
        task = "Update Tile Download Status";
        break;
    case QGCMapTask::taskDeleteTileSet:
        task = "Delete Tile Set";
        break;
    case QGCMapTask::taskReset:
        task = "Reset Tile Sets";
        break;
367 368 369
    case QGCMapTask::taskExport:
        task = "Export Tile Sets";
        break;
dogmaphobic's avatar
dogmaphobic committed
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
    default:
        task = "Database Error";
        break;
    }
    QString serror = "Error in task: " + task;
    serror += "\nError description:\n";
    serror += error;
    qWarning() << "QGCMapEngineManager::_taskError()";
    setErrorMessage(serror);
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::_updateTotals(quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize)
{
    for(int i = 0; i < _tileSets.count(); i++ ) {
        QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
387
        if (set && set->defaultSet()) {
dogmaphobic's avatar
dogmaphobic committed
388 389 390 391
            set->setSavedTileSize(totalsize);
            set->setSavedTileCount(totaltiles);
            set->setTotalTileCount(defaulttiles);
            set->setTotalTileSize(defaultsize);
dogmaphobic's avatar
dogmaphobic committed
392 393 394 395 396 397 398 399 400 401 402 403
            return;
        }
    }
    _updateDiskFreeSpace();
}

//-----------------------------------------------------------------------------
bool
QGCMapEngineManager::findName(const QString& name)
{
    for(int i = 0; i < _tileSets.count(); i++ ) {
        QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
404
        if (set && set->name() == name) {
dogmaphobic's avatar
dogmaphobic committed
405 406 407 408 409 410
            return true;
        }
    }
    return false;
}

411 412 413 414 415
//-----------------------------------------------------------------------------
void
QGCMapEngineManager::selectAll() {
    for(int i = 0; i < _tileSets.count(); i++ ) {
        QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
416 417 418
        if(set) {
            set->setSelected(true);
        }
419 420 421 422 423 424 425 426
    }
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::selectNone() {
    for(int i = 0; i < _tileSets.count(); i++ ) {
        QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
427 428 429
        if(set) {
            set->setSelected(false);
        }
430 431 432 433 434 435 436 437 438
    }
}

//-----------------------------------------------------------------------------
int
QGCMapEngineManager::selectedCount() {
    int count = 0;
    for(int i = 0; i < _tileSets.count(); i++ ) {
        QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
439
        if(set && set->selected()) {
440 441 442 443 444 445
            count++;
        }
    }
    return count;
}

Gus Grubba's avatar
Gus Grubba committed
446 447 448 449 450 451 452 453 454 455 456
//-----------------------------------------------------------------------------
bool
QGCMapEngineManager::importSets(QString path) {
    _importAction = ActionNone;
    emit importActionChanged();
    QString dir = path;
    if(dir.isEmpty()) {
#if defined(__mobile__)
        //-- TODO: This has to be something fixed
        dir = QDir(QDir::homePath()).filePath(QString("export_%1.db").arg(QDateTime::currentDateTime().toTime_t()));
#else
Gus Grubba's avatar
Gus Grubba committed
457 458 459 460 461
        dir = QString(); //-- TODO: QGCQFileDialog::getOpenFileName(
        //    nullptr,
        //    "Import Tile Set",
        //    QDir::homePath(),
        //    "Tile Sets (*.qgctiledb)");
Gus Grubba's avatar
Gus Grubba committed
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
#endif
    }
    if(!dir.isEmpty()) {
        _importAction = ActionImporting;
        emit importActionChanged();
        QGCImportTileTask* task = new QGCImportTileTask(dir, _importReplace);
        connect(task, &QGCImportTileTask::actionCompleted, this, &QGCMapEngineManager::_actionCompleted);
        connect(task, &QGCImportTileTask::actionProgress, this, &QGCMapEngineManager::_actionProgressHandler);
        connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
        getQGCMapEngine()->addTask(task);
        return true;
    }
    return false;
}

477
//-----------------------------------------------------------------------------
Gus Grubba's avatar
Gus Grubba committed
478
bool
479
QGCMapEngineManager::exportSets(QString path) {
Gus Grubba's avatar
Gus Grubba committed
480 481
    _importAction = ActionNone;
    emit importActionChanged();
482 483
    QString dir = path;
    if(dir.isEmpty()) {
Gus Grubba's avatar
Gus Grubba committed
484
#if defined(__mobile__)
485
        dir = QDir(QDir::homePath()).filePath(QString("export_%1.db").arg(QDateTime::currentDateTime().toTime_t()));
Gus Grubba's avatar
Gus Grubba committed
486
#else
Gus Grubba's avatar
Gus Grubba committed
487 488 489 490 491 492 493
        dir = QString(); //-- TODO: QGCQFileDialog::getSaveFileName(
        //    MainWindow::instance(),
        //    "Export Tile Set",
        //    QDir::homePath(),
        //    "Tile Sets (*.qgctiledb)",
        //    "qgctiledb",
        //    true);
Gus Grubba's avatar
Gus Grubba committed
494
#endif
495
    }
Gus Grubba's avatar
Gus Grubba committed
496 497 498 499 500 501 502 503 504
    if(!dir.isEmpty()) {
        QVector<QGCCachedTileSet*> sets;
        for(int i = 0; i < _tileSets.count(); i++ ) {
            QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
            if(set->selected()) {
                sets.append(set);
            }
        }
        if(sets.count()) {
Gus Grubba's avatar
Gus Grubba committed
505 506
            _importAction = ActionExporting;
            emit importActionChanged();
Gus Grubba's avatar
Gus Grubba committed
507
            QGCExportTileTask* task = new QGCExportTileTask(sets, dir);
Gus Grubba's avatar
Gus Grubba committed
508 509
            connect(task, &QGCExportTileTask::actionCompleted, this, &QGCMapEngineManager::_actionCompleted);
            connect(task, &QGCExportTileTask::actionProgress, this, &QGCMapEngineManager::_actionProgressHandler);
Gus Grubba's avatar
Gus Grubba committed
510 511 512
            connect(task, &QGCMapTask::error, this, &QGCMapEngineManager::taskError);
            getQGCMapEngine()->addTask(task);
            return true;
513 514
        }
    }
Gus Grubba's avatar
Gus Grubba committed
515
    return false;
516 517 518 519
}

//-----------------------------------------------------------------------------
void
Gus Grubba's avatar
Gus Grubba committed
520
QGCMapEngineManager::_actionProgressHandler(int percentage)
521
{
Gus Grubba's avatar
Gus Grubba committed
522 523
    _actionProgress = percentage;
    emit actionProgressChanged();
Gus Grubba's avatar
Gus Grubba committed
524
}
525

Gus Grubba's avatar
Gus Grubba committed
526 527
//-----------------------------------------------------------------------------
void
Gus Grubba's avatar
Gus Grubba committed
528
QGCMapEngineManager::_actionCompleted()
Gus Grubba's avatar
Gus Grubba committed
529
{
Gus Grubba's avatar
Gus Grubba committed
530
    ImportAction oldState = _importAction;
Gus Grubba's avatar
Gus Grubba committed
531 532
    _importAction = ActionDone;
    emit importActionChanged();
Gus Grubba's avatar
Gus Grubba committed
533 534 535 536 537 538 539 540 541 542 543 544
    //-- If we just imported, reload it all
    if(oldState == ActionImporting) {
        loadTileSets();
    }
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::resetAction()
{
    _importAction = ActionNone;
    emit importActionChanged();
545 546
}

dogmaphobic's avatar
dogmaphobic committed
547 548 549 550 551 552 553 554 555
//-----------------------------------------------------------------------------
QString
QGCMapEngineManager::getUniqueName()
{
    QString test = "Tile Set ";
    QString name;
    int count = 1;
    while (true) {
        name = test;
Gus Grubba's avatar
Gus Grubba committed
556
        name += QString().sprintf("%03d", count++);
dogmaphobic's avatar
dogmaphobic committed
557 558 559 560 561 562 563 564 565 566 567 568
        if(!findName(name))
            return name;
    }
}

//-----------------------------------------------------------------------------
void
QGCMapEngineManager::_updateDiskFreeSpace()
{
    QString path = getQGCMapEngine()->getCachePath();
    if(!path.isEmpty()) {
        QStorageInfo info(path);
569 570
        quint32 total = static_cast<quint32>(info.bytesTotal() / 1024);
        quint32 free  = static_cast<quint32>(info.bytesFree()  / 1024);
dogmaphobic's avatar
dogmaphobic committed
571 572 573 574 575 576 577 578
        qCDebug(QGCMapEngineManagerLog) << info.rootPath() << "has" << free << "Mbytes available.";
        if(_freeDiskSpace != free) {
            _freeDiskSpace = free;
            _diskSpace = total;
            emit freeDiskSpaceChanged();
        }
    }
}