diff --git a/sdrsrv/maincore.cpp b/sdrsrv/maincore.cpp index 03b7700f9..77daa699d 100644 --- a/sdrsrv/maincore.cpp +++ b/sdrsrv/maincore.cpp @@ -37,6 +37,7 @@ MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteInstance, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgLoadPreset, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgSavePreset, Message) +MESSAGE_CLASS_DEFINITION(MainCore::MsgDeletePreset, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgAddDeviceSet, Message) MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message) @@ -112,6 +113,14 @@ bool MainCore::handleMessage(const Message& cmd) m_settings.save(); return true; } + else if (MsgDeletePreset::match(cmd)) + { + MsgDeletePreset& notif = (MsgDeletePreset&) cmd; + const Preset *presetToDelete = notif.getPreset(); + // remove preset from settings + m_settings.deletePreset(presetToDelete); + return true; + } else if (MsgAddDeviceSet::match(cmd)) { MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd; diff --git a/sdrsrv/maincore.h b/sdrsrv/maincore.h index abe92dda7..de83fcfee 100644 --- a/sdrsrv/maincore.h +++ b/sdrsrv/maincore.h @@ -119,6 +119,26 @@ private: { } }; + class MsgDeletePreset : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const Preset *getPreset() const { return m_preset; } + + static MsgDeletePreset* create(const Preset *preset) + { + return new MsgDeletePreset(preset); + } + + private: + const Preset *m_preset; + + MsgDeletePreset(const Preset *preset) : + Message(), + m_preset(preset) + { } + }; + class MsgDeleteInstance : public Message { MESSAGE_CLASS_DECLARATION diff --git a/sdrsrv/webapi/webapiadaptersrv.cpp b/sdrsrv/webapi/webapiadaptersrv.cpp index 2bb365ebe..5dbea4248 100644 --- a/sdrsrv/webapi/webapiadaptersrv.cpp +++ b/sdrsrv/webapi/webapiadaptersrv.cpp @@ -651,6 +651,34 @@ int WebAPIAdapterSrv::instancePresetPost( return 200; } +int WebAPIAdapterSrv::instancePresetDelete( + SWGSDRangel::SWGPresetIdentifier& response, + SWGSDRangel::SWGErrorResponse& error) +{ + const Preset *selectedPreset = m_mainCore.m_settings.getPreset(*response.getGroupName(), + response.getCenterFrequency(), + *response.getName()); + + if (selectedPreset == 0) + { + *error.getMessage() = QString("There is no preset [%1, %2, %3]") + .arg(*response.getGroupName()) + .arg(response.getCenterFrequency()) + .arg(*response.getName()); + return 404; + } + + response.setCenterFrequency(selectedPreset->getCenterFrequency()); + *response.getGroupName() = selectedPreset->getGroup(); + *response.getType() = selectedPreset->isSourcePreset() ? "R" : "T"; + *response.getName() = selectedPreset->getDescription(); + + MainCore::MsgDeletePreset *msg = MainCore::MsgDeletePreset::create(const_cast(selectedPreset)); + m_mainCore.m_inputMessageQueue.push(msg); + + return 200; +} + int WebAPIAdapterSrv::instanceDeviceSetsPost( bool tx, SWGSDRangel::SWGSuccessResponse& response, diff --git a/sdrsrv/webapi/webapiadaptersrv.h b/sdrsrv/webapi/webapiadaptersrv.h index 24d373448..758993ad8 100644 --- a/sdrsrv/webapi/webapiadaptersrv.h +++ b/sdrsrv/webapi/webapiadaptersrv.h @@ -113,6 +113,10 @@ public: SWGSDRangel::SWGSuccessResponse& response, SWGSDRangel::SWGErrorResponse& error); + virtual int instancePresetDelete( + SWGSDRangel::SWGPresetIdentifier& response, + SWGSDRangel::SWGErrorResponse& error); + virtual int instanceDeviceSetsDelete( SWGSDRangel::SWGSuccessResponse& response, SWGSDRangel::SWGErrorResponse& error);