Skip to content

Commit

Permalink
- improved tv.db/idtvChannel.bin support (e.g. Panasonic LSW500, LXW700)
Browse files Browse the repository at this point in the history
- fixed error when changing "Auto hide/unhide columns" option while no list is loaded
- added "Feature" to serializers so they can enforce that all TV channels must come before Radio and Data (but share a common number sequence)
  • Loading branch information
PredatH0r committed Oct 28, 2023
1 parent 5476e1f commit 6134eb3
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 11 deletions.
45 changes: 45 additions & 0 deletions source/ChanSort.Api/Controller/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,50 @@ public static bool SequentializeFavPos(ChannelList channelList, int favCount)
}
#endregion

#region EnforceTvBeforeRadioBeforeData()
public bool EnforceTvBeforeRadioBeforeData()
{
bool hadOverlaps = false;

foreach (var list in this.DataRoot.ChannelLists)
{
// separate channels into lists for TV, radio and data
var listByServiceType = new List<ChannelInfo>[3]; // TV/Radio/Data, min/max
for (int i = 0; i < 3; i++)
listByServiceType[i] = new();

foreach (var ch in list.Channels)
{
if (ch.IsDeleted || ch.NewProgramNr < 0 || ch.IsProxy)
continue;
var serviceType = ch.SignalSource & SignalSource.MaskTvRadioData;
var i = serviceType == SignalSource.Tv ? 0 : serviceType == SignalSource.Radio ? 1 : 2;
listByServiceType[i].Add(ch);
}

// sort the lists by the new program number
for (int i=0; i<3; i++)
listByServiceType[i].Sort((a,b) => a.NewProgramNr.CompareTo(b.NewProgramNr));

// make sure that program numbers are strictly increasing (so that there are no overlaps between the tv/radio/data groups)
var lastNr = listByServiceType[0].Count == 0 ? 0 : listByServiceType[0].Last().NewProgramNr;
for (var i = 1; i <= 2; i++)
{
foreach (var ch in listByServiceType[i])
{
if (ch.NewProgramNr <= lastNr)
{
ch.NewProgramNr = ++lastNr;
hadOverlaps = true;
}
else
lastNr = ch.NewProgramNr;
}
}
}

return hadOverlaps;
}
#endregion
}
}
1 change: 1 addition & 0 deletions source/ChanSort.Api/Controller/SerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SupportedFeatures
public bool CanHaveGaps { get; set; } = true;
public bool EncryptedFlagEdit { get; set; }
public DeleteMode DeleteMode { get; set; } = DeleteMode.NotSupported;
public bool EnforceTvBeforeRadioBeforeData { get; set; } = false;


public FavoritesMode FavoritesMode
Expand Down
1 change: 1 addition & 0 deletions source/ChanSort.Loader.Panasonic/IdtvChannelSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public IdtvChannelSerializer(string tvDb) : base(tvDb)

this.Features.FavoritesMode = FavoritesMode.Flags;
this.Features.DeleteMode = DeleteMode.FlagWithPrNr;
this.Features.EnforceTvBeforeRadioBeforeData = true;

this.DataRoot.AddChannelList(new ChannelList(SignalSource.Antenna | SignalSource.Tv | SignalSource.Radio, "Antenna"));
this.DataRoot.AddChannelList(new ChannelList(SignalSource.Cable | SignalSource.Tv | SignalSource.Radio, "Cable"));
Expand Down
27 changes: 16 additions & 11 deletions source/ChanSort/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ private void SaveFiles()
return;
if (!this.PromptHandlingOfUnsortedChannels())
return;
if (this.currentTvSerializer.Features.EnforceTvBeforeRadioBeforeData)
this.Editor.EnforceTvBeforeRadioBeforeData();
this.SaveTvDataFile();
this.DataRoot.NeedsSaving = false;
this.RefreshGrid(this.gviewLeft, this.gviewRight);
Expand Down Expand Up @@ -1613,18 +1615,21 @@ private void ShowGridColumns(XGridView gview)
}

// add custom columns used in the current channel list
foreach (var field in this.CurrentChannelList.VisibleColumnFieldNames)
if (this.CurrentChannelList != null)
{
if (!field.StartsWith("+"))
continue;
var col = gview.Columns[field];
if (col != null)
continue;
col = gview.Columns.AddField(field);
col.Caption = field.Substring(1);
col.FieldName = field;
col.UnboundDataType = typeof(string);
col.VisibleIndex = visIndex++;
foreach (var field in this.CurrentChannelList.VisibleColumnFieldNames)
{
if (!field.StartsWith("+"))
continue;
var col = gview.Columns[field];
if (col != null)
continue;
col = gview.Columns.AddField(field);
col.Caption = field.Substring(1);
col.FieldName = field;
col.UnboundDataType = typeof(string);
col.VisibleIndex = visIndex++;
}
}

--this.ignoreEvents;
Expand Down
47 changes: 47 additions & 0 deletions source/Test.Api/EditorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using ChanSort.Api;

namespace Test.Api;

[TestClass]
public class EditorTest
{
[TestMethod]
public void TestEnforceTvBeforeRadioBeforeData()
{
var list = new ChannelList(SignalSource.All, "All");
list.AddChannel(new ChannelInfo(SignalSource.Tv, 0, 1, ""));
list.AddChannel(new ChannelInfo(SignalSource.Tv, 1, 2, ""));
list.AddChannel(new ChannelInfo(SignalSource.Data, 2, 3, ""));
list.AddChannel(new ChannelInfo(SignalSource.Tv, 3, 4, ""));
list.AddChannel(new ChannelInfo(SignalSource.Radio, 4, 5, ""));
list.AddChannel(new ChannelInfo(SignalSource.Tv, 5, 6, ""));
list.AddChannel(new ChannelInfo(SignalSource.Radio, 6, 7, ""));
list.AddChannel(new ChannelInfo(SignalSource.Tv, 7, 8, ""));
list.AddChannel(new ChannelInfo(SignalSource.Data, 8, 9, ""));
list.AddChannel(new ChannelInfo(SignalSource.Data, 9, 10, ""));
list.AddChannel(new ChannelInfo(SignalSource.Radio, 10, 11, ""));
list.AddChannel(new ChannelInfo(SignalSource.Tv, 11, 12, ""));

var ser = new CsvRefListSerializer("foo.csv");
var dataRoot = new DataRoot(ser);
dataRoot.AddChannelList(list);
dataRoot.ApplyCurrentProgramNumbers();

var editor = new Editor();
editor.DataRoot = dataRoot;
Assert.IsTrue(editor.EnforceTvBeforeRadioBeforeData());

var expected = new[] { 0, 1, 3, 5, 7, 11, 4, 6, 10, 2, 8, 9 };
var newOrder = list.Channels.OrderBy(ch => ch.NewProgramNr).ToList();
for (int i = 0; i<list.Channels.Count; i++)
Assert.AreEqual(expected[i], newOrder[i].RecordIndex);

// running it again should produce no changes
Assert.IsFalse(editor.EnforceTvBeforeRadioBeforeData());
for (int i = 0; i < list.Channels.Count; i++)
Assert.AreEqual(expected[i], newOrder[i].RecordIndex);
}
}

1 change: 1 addition & 0 deletions source/Test.Api/Test.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ChanSort.Api\ChanSort.Api.csproj" />
Expand Down
4 changes: 4 additions & 0 deletions source/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
ChanSort Change Log
===================

2023-10-28
- improved tv.db/idtvChannel.bin support (e.g. Panasonic LSW500, LXW700)
- fixed error when changing "Auto hide/unhide columns" option while no list is loaded

2023-10-22
- fixed loading .txt reference lists
- added support for HB\_DATABASE\_\*.DBM channel lists with file size 74303
Expand Down

0 comments on commit 6134eb3

Please sign in to comment.