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)
{
DeviceUISet *deviceUI = m_deviceUIs[currentSourceTabIndex];
PluginAPI pluginAPI(deviceUI->m_pluginManager, this);
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);
}
@ -344,7 +345,7 @@ void MainWindow::savePresetSettings(Preset* preset)
preset->setSpectrumConfig(deviceUI->m_spectrumGUI->serialize());
preset->clearChannels();
deviceUI->m_pluginManager->saveSettings(preset);
deviceUI->m_deviceAPI->saveChannelSettings(preset);
deviceUI->m_deviceAPI->saveSourceSettings(preset);
preset->setLayout(saveState());

View File

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

View File

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

View File

@ -49,9 +49,9 @@ public:
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 saveSettings(Preset* preset);
// void saveSettings(Preset* preset);
// void saveSourceSettings(Preset* preset);
void freeAll();
@ -68,6 +68,8 @@ public:
void populateChannelComboBox(QComboBox *channels);
void createChannelInstance(int channelPluginIndex, DeviceAPI *deviceAPI);
PluginAPI *getAPI(MainWindow *mainWindow);
private:
struct ChannelInstanceRegistration {
QString m_channelName;