Skip to content
Snippets Groups Projects
AppSettings.cc 8.26 KiB
Newer Older
  • Learn to ignore specific revisions
  • /****************************************************************************
     *
    
    Gus Grubba's avatar
    Gus Grubba committed
     * (c) 2009-2020 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.
     *
     ****************************************************************************/
    
    #include "AppSettings.h"
    
    #include "QGCPalette.h"
    #include "QGCApplication.h"
    
    #include "ParameterManager.h"
    
    
    #include <QQmlEngine>
    
    Don Gagne's avatar
    Don Gagne committed
    #include <QtQml>
    
    const char* AppSettings::parameterFileExtension =   "params";
    
    const char* AppSettings::planFileExtension =        "plan";
    
    const char* AppSettings::missionFileExtension =     "mission";
    
    const char* AppSettings::waypointsFileExtension =   "waypoints";
    
    const char* AppSettings::fenceFileExtension =       "fence";
    const char* AppSettings::rallyPointFileExtension =  "rally";
    const char* AppSettings::telemetryFileExtension =   "tlog";
    
    const char* AppSettings::kmlFileExtension =         "kml";
    
    const char* AppSettings::shpFileExtension =         "shp";
    
    const char* AppSettings::logFileExtension =         "ulg";
    
    const char* AppSettings::parameterDirectory =       "Parameters";
    const char* AppSettings::telemetryDirectory =       "Telemetry";
    const char* AppSettings::missionDirectory =         "Missions";
    const char* AppSettings::logDirectory =             "Logs";
    
    const char* AppSettings::videoDirectory =           "Video";
    
    const char* AppSettings::crashDirectory =           "CrashLogs";
    
    DECLARE_SETTINGGROUP(App, "")
    
        qmlRegisterUncreatableType<AppSettings>("QGroundControl.SettingsManager", 1, 0, "AppSettings", "Reference only");
    
    Don Gagne's avatar
    Don Gagne committed
        QGCPalette::setGlobalTheme(indoorPalette()->rawValue().toBool() ? QGCPalette::Dark : QGCPalette::Light);
    
    
        // Instantiate savePath so we can check for override and setup default path if needed
    
    
    DonLakeFlyer's avatar
    DonLakeFlyer committed
        SettingsFact* savePathFact = qobject_cast<SettingsFact*>(savePath());
    
        QString appName = qgcApp()->applicationName();
    
    Don Gagne's avatar
     
    Don Gagne committed
    #ifdef __mobile__
        // Mobile builds always use the runtime generated location for savePath. The reason is that for example on iOS the save path includes
        // a UID for the app in it. When you then update the app that UID could change which in turn makes any saved value invalid.
        if (true) {
    #else
    
        if (savePathFact->rawValue().toString().isEmpty() && _nameToMetaDataMap[savePathName]->rawDefaultValue().toString().isEmpty()) {
    
    Don Gagne's avatar
     
    Don Gagne committed
    #endif
    
    DonLakeFlyer's avatar
    DonLakeFlyer committed
    #ifdef __ios__
    
            QDir rootDir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
    
    DonLakeFlyer's avatar
    DonLakeFlyer committed
    #else
    
            QDir rootDir = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
    
    DonLakeFlyer's avatar
    DonLakeFlyer committed
    #endif
    
            savePathFact->setVisible(false);
    #else
            QDir rootDir = QDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
    #endif
            savePathFact->setRawValue(rootDir.filePath(appName));
        }
    
        connect(savePathFact, &Fact::rawValueChanged, this, &AppSettings::savePathsChanged);
        connect(savePathFact, &Fact::rawValueChanged, this, &AppSettings::_checkSavePathDirectories);
    
        //-- Keep track of language changes
    
        SettingsFact* languageFact = qobject_cast<SettingsFact*>(language());
        connect(languageFact, &Fact::rawValueChanged, this, &AppSettings::_languageChanged);
    
    DECLARE_SETTINGSFACT(AppSettings, offlineEditingFirmwareType)
    DECLARE_SETTINGSFACT(AppSettings, offlineEditingVehicleType)
    DECLARE_SETTINGSFACT(AppSettings, offlineEditingCruiseSpeed)
    DECLARE_SETTINGSFACT(AppSettings, offlineEditingHoverSpeed)
    DECLARE_SETTINGSFACT(AppSettings, offlineEditingAscentSpeed)
    DECLARE_SETTINGSFACT(AppSettings, offlineEditingDescentSpeed)
    DECLARE_SETTINGSFACT(AppSettings, batteryPercentRemainingAnnounce)
    DECLARE_SETTINGSFACT(AppSettings, defaultMissionItemAltitude)
    DECLARE_SETTINGSFACT(AppSettings, telemetrySave)
    DECLARE_SETTINGSFACT(AppSettings, telemetrySaveNotArmed)
    DECLARE_SETTINGSFACT(AppSettings, audioMuted)
    
    DECLARE_SETTINGSFACT(AppSettings, checkInternet)
    
    DECLARE_SETTINGSFACT(AppSettings, virtualJoystick)
    
    DECLARE_SETTINGSFACT(AppSettings, virtualJoystickCentralized)
    
    DECLARE_SETTINGSFACT(AppSettings, appFontPointSize)
    DECLARE_SETTINGSFACT(AppSettings, showLargeCompass)
    DECLARE_SETTINGSFACT(AppSettings, savePath)
    DECLARE_SETTINGSFACT(AppSettings, autoLoadMissions)
    DECLARE_SETTINGSFACT(AppSettings, useChecklist)
    
    DECLARE_SETTINGSFACT(AppSettings, enforceChecklist)
    
    DECLARE_SETTINGSFACT(AppSettings, mapboxToken)
    DECLARE_SETTINGSFACT(AppSettings, esriToken)
    DECLARE_SETTINGSFACT(AppSettings, defaultFirmwareType)
    DECLARE_SETTINGSFACT(AppSettings, gstDebugLevel)
    DECLARE_SETTINGSFACT(AppSettings, followTarget)
    
    Don Gagne's avatar
     
    Don Gagne committed
    DECLARE_SETTINGSFACT(AppSettings, apmStartMavlinkStreams)
    
    DECLARE_SETTINGSFACT(AppSettings, enableTaisync)
    DECLARE_SETTINGSFACT(AppSettings, enableTaisyncVideo)
    
    DECLARE_SETTINGSFACT(AppSettings, enableMicrohard)
    
    DECLARE_SETTINGSFACT(AppSettings, language)
    
    DECLARE_SETTINGSFACT(AppSettings, disableAllPersistence)
    
    Gus Grubba's avatar
    Gus Grubba committed
    DECLARE_SETTINGSFACT(AppSettings, usePairing)
    
    DECLARE_SETTINGSFACT(AppSettings, saveCsvTelemetry)
    
    DECLARE_SETTINGSFACT(AppSettings, firstTimeStart)
    
    
    DECLARE_SETTINGSFACT_NO_FUNC(AppSettings, indoorPalette)
    {
        if (!_indoorPaletteFact) {
            _indoorPaletteFact = _createSettingsFact(indoorPaletteName);
            connect(_indoorPaletteFact, &Fact::rawValueChanged, this, &AppSettings::_indoorPaletteChanged);
        }
        return _indoorPaletteFact;
    }
    
    
    void AppSettings::_languageChanged()
    {
        qgcApp()->setLanguage();
    }
    
    
    void AppSettings::_checkSavePathDirectories(void)
    {
        QDir savePathDir(savePath()->rawValue().toString());
        if (!savePathDir.exists()) {
            QDir().mkpath(savePathDir.absolutePath());
        }
        if (savePathDir.exists()) {
            savePathDir.mkdir(parameterDirectory);
            savePathDir.mkdir(telemetryDirectory);
            savePathDir.mkdir(missionDirectory);
    
            savePathDir.mkdir(logDirectory);
    
            savePathDir.mkdir(videoDirectory);
    
            savePathDir.mkdir(crashDirectory);
    
    void AppSettings::_indoorPaletteChanged(void)
    {
    
    Don Gagne's avatar
    Don Gagne committed
        QGCPalette::setGlobalTheme(indoorPalette()->rawValue().toBool() ? QGCPalette::Dark : QGCPalette::Light);
    
    QString AppSettings::missionSavePath(void)
    {
        QString path = savePath()->rawValue().toString();
        if (!path.isEmpty() && QDir(path).exists()) {
            QDir dir(path);
            return dir.filePath(missionDirectory);
        }
    
        return QString();
    
    }
    
    QString AppSettings::parameterSavePath(void)
    {
        QString path = savePath()->rawValue().toString();
        if (!path.isEmpty() && QDir(path).exists()) {
            QDir dir(path);
            return dir.filePath(parameterDirectory);
        }
    
        return QString();
    
    }
    
    QString AppSettings::telemetrySavePath(void)
    {
        QString path = savePath()->rawValue().toString();
        if (!path.isEmpty() && QDir(path).exists()) {
            QDir dir(path);
            return dir.filePath(telemetryDirectory);
        }
    
        return QString();
    
    QString AppSettings::logSavePath(void)
    {
        QString path = savePath()->rawValue().toString();
        if (!path.isEmpty() && QDir(path).exists()) {
            QDir dir(path);
            return dir.filePath(logDirectory);
        }
    
        return QString();
    
    QString AppSettings::videoSavePath(void)
    {
        QString path = savePath()->rawValue().toString();
        if (!path.isEmpty() && QDir(path).exists()) {
            QDir dir(path);
            return dir.filePath(videoDirectory);
        }
    
        return QString();
    }
    
    QString AppSettings::crashSavePath(void)
    {
        QString path = savePath()->rawValue().toString();
        if (!path.isEmpty() && QDir(path).exists()) {
            QDir dir(path);
            return dir.filePath(crashDirectory);
        }
        return QString();
    
    MAV_AUTOPILOT AppSettings::offlineEditingFirmwareTypeFromFirmwareType(MAV_AUTOPILOT firmwareType)
    {
        if (firmwareType != MAV_AUTOPILOT_PX4 && firmwareType != MAV_AUTOPILOT_ARDUPILOTMEGA) {
            firmwareType = MAV_AUTOPILOT_GENERIC;
        }
        return firmwareType;
    }
    
    MAV_TYPE AppSettings::offlineEditingVehicleTypeFromVehicleType(MAV_TYPE vehicleType)
    {
        if (QGCMAVLink::isRover(vehicleType)) {
            return MAV_TYPE_GROUND_ROVER;
        } else if (QGCMAVLink::isSub(vehicleType)) {
            return MAV_TYPE_SUBMARINE;
        } else if (QGCMAVLink::isVTOL(vehicleType)) {
            return MAV_TYPE_VTOL_QUADROTOR;
        } else if (QGCMAVLink::isFixedWing(vehicleType)) {
            return MAV_TYPE_FIXED_WING;
        } else {
            return MAV_TYPE_QUADROTOR;
        }
    }