Skip to content

Commit

Permalink
migrate babel devices settings
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Dec 5, 2022
1 parent a77d626 commit 99a1390
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
Expand Up @@ -25,6 +25,7 @@ A registry for :py:class:`QgsAbstractBabelFormat` GPSBabel formats.
%End
public:


QgsBabelFormatRegistry();
%Docstring
Constructor for QgsBabelFormatRegistry.
Expand Down
41 changes: 12 additions & 29 deletions src/core/gps/qgsbabelformatregistry.cpp
Expand Up @@ -18,7 +18,6 @@
#include "qgsbabelformatregistry.h"
#include "qgsbabelformat.h"
#include "qgsbabelgpsdevice.h"
#include "qgssettings.h"
#include <QString>
#include <QRegularExpression>

Expand Down Expand Up @@ -265,44 +264,28 @@ void QgsBabelFormatRegistry::reloadFromSettings()
QStringLiteral( "%babel -t -i garmin -o gpx %in %out" ),
QStringLiteral( "%babel -t -i gpx -o garmin %in %out" ) );

QgsSettings settings;

bool useOldPath = false;
QStringList deviceNames = settings.value( QStringLiteral( "babelDeviceList" ), QVariant(), QgsSettings::Gps ).toStringList();
if ( deviceNames.empty() ) // migrate old settings
{
useOldPath = true;
deviceNames = settings.value( QStringLiteral( "Plugin-GPS/devicelist" ) ).toStringList();
}
bool useOldSettingPath = QgsBabelFormatRegistry::settingsBabelDeviceList.migrateFromKey( QStringLiteral( "Plugin-GPS/devicelist" ) );
QStringList deviceNames = QgsBabelFormatRegistry::settingsBabelDeviceList.value();

for ( const QString &device : std::as_const( deviceNames ) )
{
QString baseKey;
QgsSettings::Section section = QgsSettings::Gps;
if ( !useOldPath )
baseKey = QStringLiteral( "babelDevices/%1" ).arg( device );
else
if ( useOldSettingPath )
{
baseKey = QStringLiteral( "/Plugin-GPS/devices/%1" ).arg( device );
section = QgsSettings::NoSection;
settingsBabelWptDownload.migrateFromKey( QStringLiteral( "/Plugin-GPS/devices/%1/wptdownload" ), device );
settingsBabelWptUpload.migrateFromKey( QStringLiteral( "/Plugin-GPS/devices/%1/wptupload" ), device );
settingsBabelRteDownload.migrateFromKey( QStringLiteral( "/Plugin-GPS/devices/%1/rtedownload" ), device );
settingsBabelRteUpload.migrateFromKey( QStringLiteral( "/Plugin-GPS/devices/%1/rteupload" ), device );
settingsBabelTrkDownload.migrateFromKey( QStringLiteral( "/Plugin-GPS/devices/%1/trkdownload" ), device );
settingsBabelTrkUpload.migrateFromKey( QStringLiteral( "/Plugin-GPS/devices/%1/trkupload" ), device );
}

const QString wptDownload = settings.value( QStringLiteral( "%1/wptdownload" ).arg( baseKey ), QVariant(), section ).toString();
const QString wptUpload = settings.value( QStringLiteral( "%1/wptupload" ).arg( baseKey ), QVariant(), section ).toString();
const QString rteDownload = settings.value( QStringLiteral( "%1/rtedownload" ).arg( baseKey ), QVariant(), section ).toString();
const QString rteUpload = settings.value( QStringLiteral( "%1/rteupload" ).arg( baseKey ), QVariant(), section ).toString();
const QString trkDownload = settings.value( QStringLiteral( "%1/trkdownload" ).arg( baseKey ), QVariant(), section ).toString();
const QString trkUpload = settings.value( QStringLiteral( "%1/trkupload" ).arg( baseKey ), QVariant(), section ).toString();

// don't leak memory if there's already a device with this name...
delete mDevices.value( device );

mDevices[device] = new QgsBabelGpsDeviceFormat( wptDownload,
wptUpload,
rteDownload,
rteUpload,
trkDownload,
trkUpload );
mDevices[device] = new QgsBabelGpsDeviceFormat( settingsBabelWptDownload.value( device ), settingsBabelWptUpload.value( device ),
settingsBabelRteDownload.value( device ), settingsBabelRteUpload.value( device ),
settingsBabelTrkDownload.value( device ), settingsBabelTrkUpload.value( device ) );
}
}

16 changes: 16 additions & 0 deletions src/core/gps/qgsbabelformatregistry.h
Expand Up @@ -17,6 +17,7 @@
#define QGSBABELFORMATREGISTRY_H

#include "qgis_core.h"
#include "qgssettingsentryimpl.h"
#include "qgis.h"

class QgsBabelSimpleImportFormat;
Expand All @@ -36,6 +37,21 @@ class CORE_EXPORT QgsBabelFormatRegistry
{
public:

#ifndef SIP_RUN
static const inline QgsSettingsEntryStringList settingsBabelDeviceList = QgsSettingsEntryStringList( QStringLiteral( "babelDeviceList" ), QgsSettings::Prefix::GPS, QStringList() );

static const inline QgsSettingsEntryString settingsBabelWptDownload = QgsSettingsEntryString( QStringLiteral( "babelDevices/%1/wptdownload" ), QgsSettings::Prefix::GPS );
static const inline QgsSettingsEntryString settingsBabelWptUpload = QgsSettingsEntryString( QStringLiteral( "babelDevices/%1/wptupload" ), QgsSettings::Prefix::GPS );
static const inline QgsSettingsEntryString settingsBabelRteDownload = QgsSettingsEntryString( QStringLiteral( "babelDevices/%1/rtedownload" ), QgsSettings::Prefix::GPS );
static const inline QgsSettingsEntryString settingsBabelRteUpload = QgsSettingsEntryString( QStringLiteral( "babelDevices/%1/rteupload" ), QgsSettings::Prefix::GPS );
static const inline QgsSettingsEntryString settingsBabelTrkDownload = QgsSettingsEntryString( QStringLiteral( "babelDevices/%1/trkdownload" ), QgsSettings::Prefix::GPS );
static const inline QgsSettingsEntryString settingsBabelTrkUpload = QgsSettingsEntryString( QStringLiteral( "babelDevices/%1/trkupload" ), QgsSettings::Prefix::GPS );

static const inline QgsSettingsEntryGroup settingsBabelDeviceGroup = QgsSettingsEntryGroup( {&settingsBabelWptDownload, &settingsBabelWptUpload,
&settingsBabelRteDownload, &settingsBabelRteUpload,
&settingsBabelTrkDownload, &settingsBabelTrkUpload } );
#endif

/**
* Constructor for QgsBabelFormatRegistry.
*
Expand Down

0 comments on commit 99a1390

Please sign in to comment.