mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-14 01:27:34 -05:00
Work in progress - program compiles and runs
This commit is contained in:
@@ -17,15 +17,20 @@
|
||||
******************************************************************************/
|
||||
package playlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import alias.AliasDirectory;
|
||||
import controller.channel.Channel;
|
||||
import controller.channel.map.ChannelMapList;
|
||||
import controller.system.SystemList;
|
||||
|
||||
@XmlSeeAlso( { AliasDirectory.class,
|
||||
Channel.class,
|
||||
ChannelMapList.class,
|
||||
SystemList.class } )
|
||||
|
||||
@@ -35,11 +40,23 @@ public class Playlist
|
||||
private AliasDirectory mAliasDirectory = new AliasDirectory();
|
||||
private ChannelMapList mChannelMapList = new ChannelMapList();
|
||||
private SystemList mSystemList = new SystemList();
|
||||
private List<Channel> mChannels = new ArrayList<>();
|
||||
|
||||
public Playlist()
|
||||
{
|
||||
}
|
||||
|
||||
@XmlElement( name = "channel" )
|
||||
public List<Channel> getChannels()
|
||||
{
|
||||
return mChannels;
|
||||
}
|
||||
|
||||
public void setChannels( List<Channel> channels )
|
||||
{
|
||||
mChannels = channels;
|
||||
}
|
||||
|
||||
@XmlElement( name = "alias_directory" )
|
||||
public AliasDirectory getAliasDirectory()
|
||||
{
|
||||
@@ -64,6 +81,13 @@ public class Playlist
|
||||
mSystemList = list;
|
||||
}
|
||||
|
||||
public boolean hasSystemList()
|
||||
{
|
||||
return mSystemList != null &&
|
||||
mSystemList.getSystem() != null &&
|
||||
!mSystemList.getSystem().isEmpty();
|
||||
}
|
||||
|
||||
@XmlElement( name = "channel_maps" )
|
||||
public ChannelMapList getChannelMapList()
|
||||
{
|
||||
|
||||
@@ -35,6 +35,10 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import properties.SystemProperties;
|
||||
import controller.channel.Channel;
|
||||
import controller.channel.ChannelModel;
|
||||
import controller.site.Site;
|
||||
import controller.system.SystemList;
|
||||
|
||||
public class PlaylistManager
|
||||
{
|
||||
@@ -43,8 +47,11 @@ public class PlaylistManager
|
||||
|
||||
private Playlist mPlaylist = new Playlist();
|
||||
|
||||
public PlaylistManager()
|
||||
private ChannelModel mChannelModel;
|
||||
|
||||
public PlaylistManager( ChannelModel channelModel )
|
||||
{
|
||||
mChannelModel = channelModel;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -52,6 +59,15 @@ public class PlaylistManager
|
||||
{
|
||||
return mPlaylist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers data from persisted playlist into system models
|
||||
*/
|
||||
private void transferPlaylistToModels()
|
||||
{
|
||||
//Load channels
|
||||
mChannelModel.addChannels( mPlaylist.getChannels() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads playlist from the current playlist file, or the default playlist file,
|
||||
@@ -70,6 +86,8 @@ public class PlaylistManager
|
||||
props.get( "playlist.currentfilename", defaultPlaylistFile );
|
||||
|
||||
load( playlistFolder.resolve( playlistFile ) );
|
||||
|
||||
transferPlaylistToModels();
|
||||
}
|
||||
|
||||
|
||||
@@ -205,5 +223,44 @@ public class PlaylistManager
|
||||
{
|
||||
mPlaylist = new Playlist();
|
||||
}
|
||||
|
||||
//Check for and convert from legacy play list format
|
||||
if( mPlaylist.hasSystemList() )
|
||||
{
|
||||
convertPlaylistFormat();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts playlist data over to new format
|
||||
*/
|
||||
private void convertPlaylistFormat()
|
||||
{
|
||||
mLog.info( "Legacy playlist format detected - converting ..." );
|
||||
|
||||
//Playlist version 1 to version 2 format conversion. In order to keep
|
||||
//backwards compatibility, transfer all of the System-Site-Channel
|
||||
//objects over to the new channel list format
|
||||
SystemList systemList = mPlaylist.getSystemList();
|
||||
|
||||
for( controller.system.System system: systemList.getSystem() )
|
||||
{
|
||||
for( Site site: system.getSite() )
|
||||
{
|
||||
for( Channel channel: site.getChannel() )
|
||||
{
|
||||
channel.setSystem( system.getName() );
|
||||
channel.setSite( site.getName() );
|
||||
|
||||
mPlaylist.getChannels().add( channel );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mPlaylist.getSystemList().clearSystems();
|
||||
|
||||
mLog.info( "Converted [" + mPlaylist.getChannels().size() + "] channels to new playlist format" );
|
||||
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user