321 - adds a preferred tuner option to the channel's source configuration

so that on startup, the application attempts to source the channel from
the preferred tuner.

If the tuner is currently not available, or if the tuner cannot source
the channel, then the next available tuner is selected.
This commit is contained in:
Denny
2018-02-09 07:11:38 -05:00
parent 1c06c4382f
commit c2fcc9e85d
6 changed files with 324 additions and 66 deletions

View File

@@ -70,6 +70,28 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
return null;
}
/**
* Find a tuner that matches the name argument
*
* @param name of the tuner
* @return named tuner or null
*/
public Tuner getTuner(String name)
{
if(name != null)
{
for(Tuner tuner: mTuners)
{
if(tuner.getName().equalsIgnoreCase(name))
{
return tuner;
}
}
}
return null;
}
public void addTuners( List<Tuner> Tuners )
{
for( Tuner tuner: Tuners )
@@ -270,6 +292,31 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
Iterator<Tuner> it = mTuners.iterator();
Tuner tuner;
if(config.hasPreferredTuner())
{
tuner = getTuner(config.getPreferredTuner());
if(tuner != null)
{
try
{
retVal = tuner.getChannel( tunerChannel );
if(retVal != null)
{
return retVal;
}
}
catch(Exception e)
{
//Fall through to logger below
}
}
mLog.info("Unable to source channel [" + config.getFrequency() + "] from preferred tuner [" +
config.getPreferredTuner() + "] - searching for another tuner");
}
while( it.hasNext() && retVal == null )
{
@@ -285,12 +332,10 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
}
catch ( SourceException e )
{
mLog.error( "error obtaining channel from tuner [" +
tuner.getName() + "]", e );
mLog.error( "error obtaining channel from tuner [" + tuner.getName() + "]", e );
}
}
return retVal;
}
}