diff --git a/include-gpl/settings/preset.h b/include-gpl/settings/preset.h index 891507388..856760a5e 100644 --- a/include-gpl/settings/preset.h +++ b/include-gpl/settings/preset.h @@ -18,6 +18,25 @@ public: }; typedef QList ChannelConfigs; + struct SourceConfig + { + QString m_sourceId; + QString m_sourceSerial; + int m_sourceSequence; + QByteArray m_config; + + SourceConfig(const QString& sourceId, + const QString& sourceSerial, + int sourceSequence, + const QByteArray& config) : + m_sourceId(sourceId), + m_sourceSerial(sourceSerial), + m_sourceSequence(sourceSequence), + m_config(config) + { } + }; + typedef QList SourceConfigs; + Preset(); void resetToDefaults(); @@ -55,6 +74,15 @@ public: const int getSourceSequence() const { return m_sourceSequence; } const QByteArray& getSourceConfig() const { return m_sourceConfig; } + void addOrUpdateSourceConfig(const QString& sourceId, + const QString& sourceSerial, + int sourceSequence, + const QByteArray& config); + + const QByteArray* findBestSourceConfig(const QString& sourceId, + const QString& sourceSerial, + int sourceSequence); + protected: // group and preset description QString m_group; @@ -77,6 +105,9 @@ protected: // channels and configurations ChannelConfigs m_channelConfigs; + // sources and configurations + SourceConfigs m_sourceConfigs; + // screen and dock layout QByteArray m_layout; }; diff --git a/sdrbase/settings/preset.cpp b/sdrbase/settings/preset.cpp index dbe76ef71..aad525689 100644 --- a/sdrbase/settings/preset.cpp +++ b/sdrbase/settings/preset.cpp @@ -83,3 +83,101 @@ bool Preset::deserialize(const QByteArray& data) return false; } } + +void Preset::addOrUpdateSourceConfig(const QString& sourceId, + const QString& sourceSerial, + int sourceSequence, + const QByteArray& config) +{ + SourceConfigs::iterator it = m_sourceConfigs.begin(); + + for (; it != m_sourceConfigs.end(); ++it) + { + if (it->m_sourceId == sourceId) + { + if (sourceSerial.isNull() || sourceSerial.isEmpty()) + { + if (it->m_sourceSequence == sourceSequence) + { + break; + } + } + else + { + if (it->m_sourceSerial == sourceSerial) + { + break; + } + } + } + } + + if (it == m_sourceConfigs.end()) + { + m_sourceConfigs.push_back(SourceConfig(sourceId, sourceSerial, sourceSequence, config)); + } + else + { + it->m_config = config; + } +} + +const QByteArray* Preset::findBestSourceConfig(const QString& sourceId, + const QString& sourceSerial, + int sourceSequence) +{ + SourceConfigs::const_iterator it = m_sourceConfigs.begin(); + SourceConfigs::const_iterator itFirstOfKind = m_sourceConfigs.end(); + SourceConfigs::const_iterator itMatchSequence = m_sourceConfigs.end(); + + for (; it != m_sourceConfigs.end(); ++it) + { + if (it->m_sourceId == sourceId) + { + if (itFirstOfKind == m_sourceConfigs.end()) + { + itFirstOfKind = it; + } + + if (sourceSerial.isNull() || sourceSerial.isEmpty()) + { + if (it->m_sourceSequence == sourceSequence) + { + break; + } + } + else + { + if (it->m_sourceSerial == sourceSerial) + { + break; + } + else if(it->m_sourceSequence == sourceSequence) + { + itMatchSequence = it; + } + } + } + } + + if (it == m_sourceConfigs.end()) // no exact match + { + if (itMatchSequence != m_sourceConfigs.end()) // match sequence ? + { + return &(itMatchSequence->m_config); + } + else if (itFirstOfKind != m_sourceConfigs.end()) // match source type ? + { + return &(itFirstOfKind->m_config); + } + else // definitely not found ! + { + return 0; + } + } + else // exact match + { + return &(it->m_config); + } +} +