Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Complete the enabling of TV guide colors via user skinnable propertie…
…s. You can now bind GUI controls to enable/disable TV guide colorization.
  • Loading branch information
ajp8164 committed Jan 5, 2012
1 parent 87f6e39 commit 6e94ca7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 47 deletions.
8 changes: 7 additions & 1 deletion TvEngine3/TVLibrary/TvPlugin/TvPlugin/GuideBase.cs
Expand Up @@ -64,7 +64,7 @@ public abstract class GuideBase : GUIDialogWindow
protected bool _useColorsForButtons = false;
protected bool _useColorsForGenres = false;
protected bool _specifyMpaaRatedAsMovie = false;
protected bool _guideColorsLoadedFromSkinSettings = false;
protected bool _guideColorsLoaded = false;
protected long _defaultGenreColorOnNow = 0;
protected long _defaultGenreColorOnLater = 0;
protected long _guideColorChannelButton = 0;
Expand All @@ -74,6 +74,7 @@ public abstract class GuideBase : GUIDialogWindow
protected long _guideColorProgramEnded = 0;
protected long _guideColorProgramSelected = 0;
protected long _guideColorBorderHighlight = 0;
protected List<string> _genreList = new List<string>();
protected Dictionary<string, string> _genreMap = new Dictionary<string, string>();
protected Dictionary<string, long> _genreColorsOnNow = new Dictionary<string, long>();
protected Dictionary<string, long> _genreColorsOnLater = new Dictionary<string, long>();
Expand All @@ -100,6 +101,9 @@ protected void Update(bool selectCurrentShow)
return;
}

// Skin settings may have changed via the MP GUI, reload them.
LoadSkinSettings();

// sets button visible state
UpdateGroupButton();

Expand Down Expand Up @@ -492,6 +496,8 @@ protected void Update(bool selectCurrentShow)

protected abstract void LoadSchedules(bool b);

protected abstract void LoadSkinSettings();

protected abstract void RenderSingleChannel(Channel channel);

protected abstract void setSingleChannelLabelVisibility(bool b);
Expand Down
5 changes: 5 additions & 0 deletions TvEngine3/TVLibrary/TvPlugin/TvPlugin/RadioGuideBase.cs
Expand Up @@ -195,6 +195,11 @@ private void LoadSettings()
Utils.FileExistsInCache(GUIGraphicsContext.GetThemedSkinFile(@"\media\tvguide_hd_program.png"));
}

protected override void LoadSkinSettings()
{
// Nothing to do for RadioGuide.
}

private void SaveSettings()
{
using (Settings xmlwriter = new MPSettings())
Expand Down
69 changes: 45 additions & 24 deletions TvEngine3/TVLibrary/TvPlugin/TvPlugin/TvGuideBase.cs
Expand Up @@ -133,8 +133,6 @@ public TvGuideBase()

private void LoadSettings()
{
List<string> genreList;

using (Settings xmlreader = new MPSettings())
{
String channelName = xmlreader.GetValueAsString("mytv", "channel", String.Empty);
Expand All @@ -153,37 +151,28 @@ private void LoadSettings()
_hdtvProgramText = xmlreader.GetValueAsString("mytv", "hdtvProgramText", "(HDTV)");
_guideContinuousScroll = xmlreader.GetValueAsBool("mytv", "continuousScrollGuide", false);
_loopDelay = xmlreader.GetValueAsInt("gui", "listLoopDelay", 0);
_useColorsForButtons = xmlreader.GetValueAsBool("tvguide", "usecolorsforbuttons", false);
_useBorderHighlight = xmlreader.GetValueAsBool("tvguide", "useborderhighlight", false);
_useColorsForGenres = xmlreader.GetValueAsBool("tvguide", "usecolorsforgenre", false);

// Load the genre map. All of the genre names to load are in a csv list.
String genreNames = xmlreader.GetValueAsString("genremap", "genrenames", String.Empty);
genreList = new List<string>(genreNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
_genreList = new List<string>(genreNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
if (_genreMap.Count == 0)
{
LoadGenreMap(xmlreader, genreList);
LoadGenreMap(xmlreader);
}

// Special genre rules.
_specifyMpaaRatedAsMovie = xmlreader.GetValueAsBool("genremap", "specifympaaratedasmovie", false);
}

// Attempt to load genre colors from the skin settings.
if (_genreColorsOnNow.Count == 0)
// Load settings defined by the skin.
LoadSkinSettings();

// If guide colors were not loaded from skin settings then attempt to load guide colors from the MP settings.
if (_genreColorsOnNow.Count == 0 && !_guideColorsLoaded)
{
using (Settings xmlreader = new SKSettings())
using (Settings xmlreader = new MPSettings())
{
_guideColorsLoadedFromSkinSettings = LoadGuideColors(xmlreader, genreList);
}

// If guide colors were not loaded from skin settings then attempt to load guide colors from the MP settings.
if (!_guideColorsLoadedFromSkinSettings)
{
using (Settings xmlreader = new MPSettings())
{
LoadGuideColors(xmlreader, genreList);
}
LoadGuideColors(xmlreader);
}
}

Expand All @@ -197,12 +186,44 @@ private void LoadSettings()
Utils.FileExistsInCache(GUIGraphicsContext.GetThemedSkinFile(@"\media\tvguide_hd_program.png"));
}

private bool LoadGenreMap(Settings xmlreader, List<string> genreList)
protected override void LoadSkinSettings()
{
String temp;

// Guide coloring options are defined by each skin (and may not be present). Read the settings from skin properties.
temp = GUIPropertyManager.GetProperty("#skin.tvguide.usecolorsforbuttons");
if (temp.Length != 0)
{
_useColorsForButtons = bool.Parse(temp);
}

temp = GUIPropertyManager.GetProperty("#skin.tvguide.useborderhighlight");
if (temp.Length != 0)
{
_useBorderHighlight = bool.Parse(temp);
}

temp = GUIPropertyManager.GetProperty("#skin.tvguide.usecolorsforgenre");
if (temp.Length != 0)
{
_useColorsForGenres = bool.Parse(temp);
}

if (!_guideColorsLoaded)
{
using (Settings xmlreader = new SKSettings())
{
_guideColorsLoaded = LoadGuideColors(xmlreader);
}
}
}

private bool LoadGenreMap(Settings xmlreader)
{
// Each genre map entry is a csv list of "program" genre names (those that may be compared with the genre from the program listings).
// It is an error if a single "program" genre is mapped to more than one genre color category; behavior is undefined for this condition.
List<string> programGenres;
foreach (string genre in genreList)
foreach (string genre in _genreList)
{
programGenres = new List<string>((xmlreader.GetValueAsString("genremap", genre, String.Empty)).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));

Expand All @@ -222,7 +243,7 @@ private bool LoadGenreMap(Settings xmlreader, List<string> genreList)
return _genreMap.Count > 0;
}

private bool LoadGuideColors(Settings xmlreader, List<string> genreList)
private bool LoadGuideColors(Settings xmlreader)
{
List<string> temp;

Expand Down Expand Up @@ -256,7 +277,7 @@ private bool LoadGuideColors(Settings xmlreader, List<string> genreList)
// Each genre color entry is a csv list. The first value is the color for program "on now", the second value is for program "on later".
// If only one value is provided then that value is used for both.
long color0;
foreach (string genre in genreList)
foreach (string genre in _genreList)
{
temp = new List<string>((xmlreader.GetValueAsString("tvguidecolors", genre, String.Empty)).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));

Expand Down
61 changes: 39 additions & 22 deletions mediaportal/Core/guilib/SkinSettings.cs
Expand Up @@ -282,6 +282,8 @@ public static void ResetAllSkinString()
}
}

#region Persistence

private static void LoadBooleanSettings()
{
_skinBoolSettings.Clear();
Expand Down Expand Up @@ -354,6 +356,7 @@ private static void LoadDiscreteSettings()
{
using (Settings xmlReader = new Settings(_skinSettingsFileName))
{
// Theme settings.
GUIGraphicsContext.Theme = xmlReader.GetValueAsString(THEME_SECTION_NAME, THEME_NAME_ENTRY, "");
GUIPropertyManager.SetProperty("#skin.currenttheme", GUIGraphicsContext.ThemeName);

Expand Down Expand Up @@ -402,34 +405,45 @@ public static void Save()
{
using (Settings xmlWriter = new Settings(_skinSettingsFileName))
{
// Save all the boolean settings.
Dictionary<int, SkinBool>.Enumerator bEnumer = _skinBoolSettings.GetEnumerator();
SkinBool bSetting;
while (bEnumer.MoveNext())
SaveBooleanSettings(xmlWriter);
SaveStringSettings(xmlWriter);
SaveDiscreteSettings(xmlWriter);
}
Settings.SaveCache();
}

private static void SaveBooleanSettings(Settings xmlWriter)
{
Dictionary<int, SkinBool>.Enumerator bEnumer = _skinBoolSettings.GetEnumerator();
SkinBool bSetting;
while (bEnumer.MoveNext())
{
bSetting = bEnumer.Current.Value;
if (bSetting.Kind == Kind.PERSISTENT)
{
bSetting = bEnumer.Current.Value;
if (bSetting.Kind == Kind.PERSISTENT)
{
xmlWriter.SetValue("booleansettings", bSetting.Name, bSetting.Value);
}
xmlWriter.SetValue("booleansettings", bSetting.Name, bSetting.Value);
}
}
}

// Save all the string settings.
Dictionary<int, SkinString>.Enumerator strEnumer = _skinStringSettings.GetEnumerator();
SkinString strSetting;
while (strEnumer.MoveNext())
private static void SaveStringSettings(Settings xmlWriter)
{
Dictionary<int, SkinString>.Enumerator strEnumer = _skinStringSettings.GetEnumerator();
SkinString strSetting;
while (strEnumer.MoveNext())
{
strSetting = strEnumer.Current.Value;
if (strSetting.Kind == Kind.PERSISTENT)
{
strSetting = strEnumer.Current.Value;
if (strSetting.Kind == Kind.PERSISTENT)
{
xmlWriter.SetValue("stringsettings", strSetting.Name, strSetting.Value);
}
xmlWriter.SetValue("stringsettings", strSetting.Name, strSetting.Value);
}

// Save discrete settings.
xmlWriter.SetValue(THEME_SECTION_NAME, THEME_NAME_ENTRY, GUIGraphicsContext.ThemeName);
}
Settings.SaveCache();
}

private static void SaveDiscreteSettings(Settings xmlWriter)
{
// Theme settings
xmlWriter.SetValue(THEME_SECTION_NAME, THEME_NAME_ENTRY, GUIGraphicsContext.ThemeName);
}

/// <summary>
Expand Down Expand Up @@ -457,5 +471,8 @@ public static ArrayList GetSkinThemes()
}
return themes;
}

#endregion

}
}

0 comments on commit 6e94ca7

Please sign in to comment.