diff options
author | sr55 <[email protected]> | 2020-02-05 20:16:03 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2020-02-05 20:16:03 +0000 |
commit | d388fee8e2773792254373eef770c6948ebbc1d4 (patch) | |
tree | 20aa5d8ddbbe81c684665d0f53df4a8b2dd53bfd | |
parent | d212e7c22a0155bab4bc57839383872b919af9fa (diff) |
WinGui: Improve the way the Audio and Subtitle Language selection is handled. When "(Any)" is used, make sure to honour the order of any languages that are also selected as a priority. Fixes #2611
-rw-r--r-- | win/CS/HandBrake.Interop/Utilities/LanguageUtilities.cs | 28 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs | 16 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs | 14 |
3 files changed, 45 insertions, 13 deletions
diff --git a/win/CS/HandBrake.Interop/Utilities/LanguageUtilities.cs b/win/CS/HandBrake.Interop/Utilities/LanguageUtilities.cs index ab5e5b1e5..106247577 100644 --- a/win/CS/HandBrake.Interop/Utilities/LanguageUtilities.cs +++ b/win/CS/HandBrake.Interop/Utilities/LanguageUtilities.cs @@ -10,16 +10,17 @@ namespace HandBrake.Interop.Utilities { using System.Collections.Generic; + using System.ComponentModel; using System.Linq; + using HandBrake.Interop.Interop.HbLib; + /// <summary> /// Language Utilities /// </summary> public class LanguageUtilities { - /// <summary> - /// The language map. - /// </summary> + public static string Any = "(Any)"; private static IDictionary<string, string> languageMap; /// <summary> @@ -35,7 +36,7 @@ namespace HandBrake.Interop.Utilities languageMap = new Dictionary<string, string> { - { "(Any)", "any" }, + { Any, "any" }, { "(Unknown)", "und" }, { "Afar", "aar" }, { "Abkhazian", "abk" }, @@ -309,5 +310,24 @@ namespace HandBrake.Interop.Utilities return null; } + + public static List<string> OrderIsoCodes(List<string> iso6392Codes, IList<string> userLanguages) + { + List<string> orderedSet = new List<string>(); + foreach (var item in userLanguages) + { + string isoCode; + if (MapLanguages().TryGetValue(item, out isoCode)) + { + orderedSet.Add(isoCode); + } + } + + List<string> unorderedSet = iso6392Codes.Where(isoCode => !orderedSet.Contains(isoCode)).ToList(); + + List<string> orderedList = orderedSet.Union(unorderedSet).ToList(); + + return orderedList; + } } } diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index 39a1a224a..cdf494c69 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -627,11 +627,17 @@ namespace HandBrakeWPF.ViewModels private IEnumerable<Audio> GetSelectedLanguagesTracks()
{
// Translate to Iso Codes
- List<string> iso6392Codes = this.AudioBehaviours.SelectedLangauges.Contains(Constants.Any)
- ? LanguageUtilities.GetIsoCodes()
- : LanguageUtilities.GetLanguageCodes(this.AudioBehaviours.SelectedLangauges.ToArray());
-
-
+ List<string> iso6392Codes = new List<string>();
+ if (this.AudioBehaviours.SelectedLangauges.Contains(Constants.Any))
+ {
+ iso6392Codes = LanguageUtilities.GetIsoCodes();
+ iso6392Codes = LanguageUtilities.OrderIsoCodes(iso6392Codes, this.AudioBehaviours.SelectedLangauges);
+ }
+ else
+ {
+ iso6392Codes = LanguageUtilities.GetLanguageCodes(this.AudioBehaviours.SelectedLangauges.ToArray());
+ }
+
List<Audio> orderedTracks = new List<Audio>();
foreach (string code in iso6392Codes)
{
diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs index 7ec789905..d59add6e4 100644 --- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs @@ -710,10 +710,16 @@ namespace HandBrakeWPF.ViewModels private List<Subtitle> GetSelectedLanguagesTracks()
{
// Translate to Iso Codes
- List<string> iso6392Codes = this.SubtitleBehaviours.SelectedLangauges.Contains(Constants.Any)
- ? LanguageUtilities.GetIsoCodes()
- : LanguageUtilities.GetLanguageCodes(
- this.SubtitleBehaviours.SelectedLangauges.ToArray());
+ List<string> iso6392Codes = new List<string>();
+ if (this.SubtitleBehaviours.SelectedLangauges.Contains(Constants.Any))
+ {
+ iso6392Codes = LanguageUtilities.GetIsoCodes();
+ iso6392Codes = LanguageUtilities.OrderIsoCodes(iso6392Codes, this.SubtitleBehaviours.SelectedLangauges);
+ }
+ else
+ {
+ iso6392Codes = LanguageUtilities.GetLanguageCodes(this.SubtitleBehaviours.SelectedLangauges.ToArray());
+ }
List<Subtitle> orderedSubtitles = new List<Subtitle>();
|