Skip to content

Commit

Permalink
- Philips: show and edit customized titles of favorite lists
Browse files Browse the repository at this point in the history
- fixed non-unique numbers in mixed-source favorite lists when using "Add to Fav A" (Panasonic, Hisense, Sony, Philips)
- function to reorder channels from 1-x is now reordering all channels when only a single one was selected
- function to sort channels by name is now reordering all channels when only a single one was selected
  • Loading branch information
Horst Beham committed Feb 11, 2020
1 parent a901a7f commit bd19d94
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 39 deletions.
28 changes: 16 additions & 12 deletions source/ChanSort.Api/Controller/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,42 +349,46 @@ private void ApplyFavorites(DataRoot refDataRoot, ChannelInfo refChannel, Channe


#region SetFavorites()
public void SetFavorites(List<ChannelInfo> list, Favorites favorites, bool set)
public void SetFavorites(List<ChannelInfo> list, int favIndex, bool set)
{
bool sortedFav = this.DataRoot.SortedFavorites;
int favIndex = 0;
if (sortedFav)
{
for (int mask = (int) favorites; (mask & 1) == 0; mask >>= 1)
++favIndex;
}
var favMask = (Favorites)(1 << favIndex);
var favList = this.DataRoot.ChannelLists.FirstOrDefault(l => l.IsMixedSourceFavoritesList) ?? this.ChannelList;

if (set)
{
int maxPosition = 0;
if (sortedFav)
{
foreach (var channel in this.ChannelList.Channels)
foreach (var channel in favList.Channels)
maxPosition = Math.Max(maxPosition, channel.FavIndex[favIndex]);
}

foreach (var channel in list)
{
if (sortedFav && channel.FavIndex[favIndex] == -1)
channel.FavIndex[favIndex] = ++maxPosition;
channel.Favorites |= favorites;
channel.Favorites |= favMask;
}
}
else
{
foreach (var channel in list)
{
if (sortedFav && channel.FavIndex[favIndex] != -1)
{
channel.FavIndex[favIndex] = -1;
// TODO close gap by pulling down higher numbers
channel.Favorites &= ~favMask;
}

// close gaps when needed
if (sortedFav && !this.DataRoot.AllowGapsInFavNumbers)
{
int i = 0;
foreach (var channel in favList.Channels)
{
if (channel.FavIndex[i] != -1)
channel.FavIndex[i] = ++i;
}
channel.Favorites &= ~favorites;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/ChanSort.Api/Controller/SerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SupportedFeatures
public bool SortedFavorites { get; set; }
public bool MixedSourceFavorites { get; set; }
public bool AllowGapsInFavNumbers { get; set; }

public bool CanEditFavListNames { get; set; }
}
#endregion

Expand Down
20 changes: 20 additions & 0 deletions source/ChanSort.Api/Model/DataRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class DataRoot
public bool CanSkip => this.loader.Features.CanSkipChannels;
public bool CanLock => this.loader.Features.CanLockChannels;
public bool CanHide => this.loader.Features.CanHideChannels;
public bool CanEditFavListName => this.loader.Features.CanEditFavListNames;

public DataRoot(SerializerBase loader)
{
Expand Down Expand Up @@ -246,5 +247,24 @@ public virtual void ValidateAfterSave()
}
#endregion


#region Get/SetFavListCaption()

private readonly Dictionary<int,string> favListCaptions = new Dictionary<int, string>();

public void SetFavListCaption(int favIndex, string caption)
{
favListCaptions[favIndex] = caption;
}

public string GetFavListCaption(int favIndex, bool asTabCaption = false)
{
var hasCaption = favListCaptions.TryGetValue(favIndex, out var caption);
if (!asTabCaption)
return caption;
var letter = (char)('A' + favIndex);
return hasCaption && !string.IsNullOrEmpty(caption) ? letter + ": " + caption : "Fav " + letter;
}
#endregion
}
}
8 changes: 8 additions & 0 deletions source/ChanSort.Loader.PhilipsXml/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Serializer(string inputFile) : base(inputFile)
this.Features.DeleteMode = DeleteMode.Physically;
this.Features.CanSaveAs = false;
this.Features.AllowGapsInFavNumbers = false;
this.Features.CanEditFavListNames = true;

this.DataRoot.AddChannelList(this.terrChannels);
this.DataRoot.AddChannelList(this.cableChannels);
Expand Down Expand Up @@ -357,10 +358,13 @@ private void ParseChannelFormat2(Dictionary<string, string> data, Channel chan)
private void ReadFavList(XmlNode node)
{
int index = ParseInt(node.Attributes["Index"].InnerText);
string name = DecodeName(node.Attributes["Name"].InnerText);
this.Features.SupportedFavorites |= (Favorites) (1 << (index - 1));
this.Features.SortedFavorites = true;
this.Features.MixedSourceFavorites = true;

this.DataRoot.SetFavListCaption(index - 1, name);

if (this.favChannels.Count == 0)
{
foreach (var rootList in this.DataRoot.ChannelLists)
Expand Down Expand Up @@ -547,6 +551,9 @@ private void UpdateFavList()
{
++index;
favListNode.InnerXml = ""; // clear all <FavoriteChannel> child elements but keep the attributes of the current node
var attr = favListNode.Attributes?["Name"];
if (attr != null)
attr.InnerText = EncodeName(this.DataRoot.GetFavListCaption(index - 1));
foreach (var ch in favChannels.Channels.OrderBy(ch => ch.GetPosition(index)))
{
var nr = ch.GetPosition(index);
Expand All @@ -572,6 +579,7 @@ private string EncodeName(string name)
var sb = new StringBuilder();
foreach (var b in bytes)
sb.Append($"0x{b:X2} 0x00 ");
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
#endregion
Expand Down
13 changes: 13 additions & 0 deletions source/ChanSort/ChanSort.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -35,6 +36,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -46,6 +48,7 @@
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
Expand All @@ -57,6 +60,7 @@
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>app.ico</ApplicationIcon>
Expand Down Expand Up @@ -166,6 +170,12 @@
<DependentUpon>ReferenceListForm.cs</DependentUpon>
</Compile>
<Compile Include="Settings.cs" />
<Compile Include="TextInputForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TextInputForm.Designer.cs">
<DependentUpon>TextInputForm.cs</DependentUpon>
</Compile>
<Compile Include="UpdateCheck.cs" />
<Compile Include="WaitForm1.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -347,6 +357,9 @@
<EmbeddedResource Include="ReferenceListForm.ro.resx">
<DependentUpon>ReferenceListForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="TextInputForm.resx">
<DependentUpon>TextInputForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="WaitForm1.cs.resx">
<DependentUpon>WaitForm1.cs</DependentUpon>
</EmbeddedResource>
Expand Down
19 changes: 11 additions & 8 deletions source/ChanSort/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 42 additions & 11 deletions source/ChanSort/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,10 @@ private void UpdateFavoritesEditor(Favorites favorites)
while (this.tabSubList.TabPages.Count > favCount + 1)
this.tabSubList.TabPages.RemoveAt(this.tabSubList.TabPages.Count - 1);
while (this.tabSubList.TabPages.Count < favCount + 1)
{
var page = this.tabSubList.TabPages.Add();
page.Text = "Fav " + (char) ('A' + this.tabSubList.TabPages.Count - 2);
}
this.tabSubList.TabPages.Add();
for (int i = 1; i < this.tabSubList.TabPages.Count; i++)
this.tabSubList.TabPages[i].Text = this.DataRoot.GetFavListCaption(i - 1, true);

if (!this.DataRoot.SortedFavorites || this.subListIndex >= favCount)
{
this.tabSubList.SelectedTabPageIndex = 0;
Expand Down Expand Up @@ -1158,7 +1158,7 @@ private bool SetSlotNumber(string progNr)

private void SortSelectedChannels()
{
var selectedChannels = this.GetSelectedChannels(this.gviewLeft);
var selectedChannels = this.GetSelectedChannels(this.gviewLeft, true);
if (selectedChannels.Count == 0) return;
this.gviewLeft.BeginDataUpdate();
this.gviewRight.BeginDataUpdate();
Expand Down Expand Up @@ -1204,7 +1204,7 @@ private void AddAllUnsortedChannels()

private void RenumberSelectedChannels()
{
var list = this.GetSelectedChannels(this.gviewLeft);
var list = this.GetSelectedChannels(this.gviewLeft, true);
if (list.Count == 0) return;
this.gviewRight.BeginDataUpdate();
this.gviewLeft.BeginDataUpdate();
Expand All @@ -1217,14 +1217,23 @@ private void RenumberSelectedChannels()

#region GetSelectedChannels()

private List<ChannelInfo> GetSelectedChannels(GridView gview)
private List<ChannelInfo> GetSelectedChannels(GridView gview, bool selectAllIfOnlyOneIsSelected = false)
{
var channels = new List<ChannelInfo>();
foreach (var rowHandle in gview.GetSelectedRows())
if (gview.SelectedRowsCount <= 1 && selectAllIfOnlyOneIsSelected)
{
if (gview.IsDataRow(rowHandle))
channels.Add((ChannelInfo) gview.GetRow(rowHandle));
for (int rowHandle=0; rowHandle<gview.RowCount; rowHandle++)
channels.Add((ChannelInfo)gview.GetRow(rowHandle));
}
else
{
foreach (var rowHandle in gview.GetSelectedRows())
{
if (gview.IsDataRow(rowHandle))
channels.Add((ChannelInfo) gview.GetRow(rowHandle));
}
}

return channels;
}

Expand Down Expand Up @@ -1532,7 +1541,7 @@ private void SetFavorite(string fav, bool set)

this.gviewRight.BeginDataUpdate();
this.gviewLeft.BeginDataUpdate();
this.Editor.SetFavorites(list, (Favorites) (1 << idx), set);
this.Editor.SetFavorites(list, idx, set);
this.gviewRight.EndDataUpdate();
this.gviewLeft.EndDataUpdate();
}
Expand Down Expand Up @@ -3311,5 +3320,27 @@ private void grpInputList_Enter(object sender, EventArgs e)

#endregion

#region tabSubList_MouseUp
private void tabSubList_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
var hit = this.tabSubList.CalcHitInfo(e.Location);
if (hit.IsValid && hit.Page != null)
{
using var dlg = new TextInputForm();
dlg.StartPosition = FormStartPosition.Manual;
dlg.Location = this.tabSubList.PointToScreen(e.Location);
var favIndex = this.tabSubList.TabPages.IndexOf(hit.Page) - 1;
dlg.Text = this.DataRoot.GetFavListCaption(favIndex);
if (dlg.ShowDialog(this) == DialogResult.OK)
{
this.DataRoot.SetFavListCaption(favIndex, dlg.Text);
hit.Page.Text = this.DataRoot.GetFavListCaption(favIndex, true);
}
}
}
}
#endregion
}
}
Loading

0 comments on commit bd19d94

Please sign in to comment.