1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-27 15:26:33 -04:00

Multi device support: use device API for channel load and save

This commit is contained in:
f4exb 2016-05-16 19:55:01 +02:00
parent 2f1c9eac6e
commit 00864bfb6c
4 changed files with 81 additions and 77 deletions

View File

@ -315,8 +315,9 @@ void MainWindow::loadPresetSettings(const Preset* preset)
if (currentSourceTabIndex >= 0) if (currentSourceTabIndex >= 0)
{ {
DeviceUISet *deviceUI = m_deviceUIs[currentSourceTabIndex]; DeviceUISet *deviceUI = m_deviceUIs[currentSourceTabIndex];
PluginAPI pluginAPI(deviceUI->m_pluginManager, this);
deviceUI->m_spectrumGUI->deserialize(preset->getSpectrumConfig()); deviceUI->m_spectrumGUI->deserialize(preset->getSpectrumConfig());
deviceUI->m_pluginManager->loadChannelSettings(preset, deviceUI->m_deviceAPI); deviceUI->m_deviceAPI->loadChannelSettings(preset, &pluginAPI);
deviceUI->m_deviceAPI->loadSourceSettings(preset); deviceUI->m_deviceAPI->loadSourceSettings(preset);
} }
@ -344,7 +345,7 @@ void MainWindow::savePresetSettings(Preset* preset)
preset->setSpectrumConfig(deviceUI->m_spectrumGUI->serialize()); preset->setSpectrumConfig(deviceUI->m_spectrumGUI->serialize());
preset->clearChannels(); preset->clearChannels();
deviceUI->m_pluginManager->saveSettings(preset); deviceUI->m_deviceAPI->saveChannelSettings(preset);
deviceUI->m_deviceAPI->saveSourceSettings(preset); deviceUI->m_deviceAPI->saveSourceSettings(preset);
preset->setLayout(saveState()); preset->setLayout(saveState());

View File

@ -53,6 +53,7 @@ protected:
~PluginAPI(); ~PluginAPI();
friend class PluginManager; friend class PluginManager;
friend class MainWindow;
}; };
#endif // INCLUDE_PLUGINAPI_H #endif // INCLUDE_PLUGINAPI_H

View File

@ -85,67 +85,67 @@ void PluginManager::registerSampleSource(const QString& sourceName, PluginInterf
m_sampleSourceRegistrations.append(SampleSourceRegistration(sourceName, plugin)); m_sampleSourceRegistrations.append(SampleSourceRegistration(sourceName, plugin));
} }
void PluginManager::loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI) //void PluginManager::loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI)
{ //{
fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); // fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
//
// copy currently open channels and clear list // // copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; // ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
m_channelInstanceRegistrations.clear(); // m_channelInstanceRegistrations.clear();
//
for(int i = 0; i < preset->getChannelCount(); i++) // for(int i = 0; i < preset->getChannelCount(); i++)
{ // {
const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i); // const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i);
ChannelInstanceRegistration reg; // ChannelInstanceRegistration reg;
//
// if we have one instance available already, use it // // if we have one instance available already, use it
//
for(int i = 0; i < openChannels.count(); i++) // for(int i = 0; i < openChannels.count(); i++)
{ // {
qDebug("PluginManager::loadSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel)); // qDebug("PluginManager::loadSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel));
//
if(openChannels[i].m_channelName == channelConfig.m_channel) // if(openChannels[i].m_channelName == channelConfig.m_channel)
{ // {
qDebug("PluginManager::loadSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName)); // qDebug("PluginManager::loadSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName));
reg = openChannels.takeAt(i); // reg = openChannels.takeAt(i);
m_channelInstanceRegistrations.append(reg); // m_channelInstanceRegistrations.append(reg);
break; // break;
} // }
} // }
//
// if we haven't one already, create one // // if we haven't one already, create one
//
if(reg.m_gui == NULL) // if(reg.m_gui == NULL)
{ // {
for(int i = 0; i < m_channelRegistrations.count(); i++) // for(int i = 0; i < m_channelRegistrations.count(); i++)
{ // {
if(m_channelRegistrations[i].m_channelName == channelConfig.m_channel) // if(m_channelRegistrations[i].m_channelName == channelConfig.m_channel)
{ // {
qDebug("PluginManager::loadSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel)); // qDebug("PluginManager::loadSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel));
reg = ChannelInstanceRegistration(channelConfig.m_channel, m_channelRegistrations[i].m_plugin->createChannel(channelConfig.m_channel, deviceAPI)); // reg = ChannelInstanceRegistration(channelConfig.m_channel, m_channelRegistrations[i].m_plugin->createChannel(channelConfig.m_channel, deviceAPI));
break; // break;
} // }
} // }
} // }
//
if(reg.m_gui != NULL) // if(reg.m_gui != NULL)
{ // {
qDebug("PluginManager::loadSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channel)); // qDebug("PluginManager::loadSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channel));
reg.m_gui->deserialize(channelConfig.m_config); // reg.m_gui->deserialize(channelConfig.m_config);
} // }
} // }
//
// everything, that is still "available" is not needed anymore // // everything, that is still "available" is not needed anymore
for(int i = 0; i < openChannels.count(); i++) // for(int i = 0; i < openChannels.count(); i++)
{ // {
qDebug("PluginManager::loadSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName)); // qDebug("PluginManager::loadSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName));
openChannels[i].m_gui->destroy(); // openChannels[i].m_gui->destroy();
} // }
//
renameChannelInstances(); // renameChannelInstances();
//
// loadSourceSettings(preset); // FIXME //// loadSourceSettings(preset); // FIXME
} //}
//void PluginManager::loadSourceSettings(const Preset* preset) //void PluginManager::loadSourceSettings(const Preset* preset)
//{ //{
@ -179,18 +179,18 @@ bool PluginManager::ChannelInstanceRegistration::operator<(const ChannelInstance
} }
} }
void PluginManager::saveSettings(Preset* preset) //void PluginManager::saveSettings(Preset* preset)
{ //{
qDebug("PluginManager::saveSettings"); // qDebug("PluginManager::saveSettings");
// saveSourceSettings(preset); // FIXME //// saveSourceSettings(preset); // FIXME
//
qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type // qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
//
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) // for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{ // {
preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize()); // preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize());
} // }
} //}
//void PluginManager::saveSourceSettings(Preset* preset) //void PluginManager::saveSourceSettings(Preset* preset)
//{ //{

View File

@ -49,9 +49,9 @@ public:
PluginAPI::ChannelRegistrations *getChannelRegistrations() { return &m_channelRegistrations; } PluginAPI::ChannelRegistrations *getChannelRegistrations() { return &m_channelRegistrations; }
void loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI); // void loadChannelSettings(const Preset* preset, DeviceAPI *deviceAPI);
// void loadSourceSettings(const Preset* preset); // void loadSourceSettings(const Preset* preset);
void saveSettings(Preset* preset); // void saveSettings(Preset* preset);
// void saveSourceSettings(Preset* preset); // void saveSourceSettings(Preset* preset);
void freeAll(); void freeAll();
@ -68,6 +68,8 @@ public:
void populateChannelComboBox(QComboBox *channels); void populateChannelComboBox(QComboBox *channels);
void createChannelInstance(int channelPluginIndex, DeviceAPI *deviceAPI); void createChannelInstance(int channelPluginIndex, DeviceAPI *deviceAPI);
PluginAPI *getAPI(MainWindow *mainWindow);
private: private:
struct ChannelInstanceRegistration { struct ChannelInstanceRegistration {
QString m_channelName; QString m_channelName;