// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // The Subtitles Defaults View Model // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.ViewModels { using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using HandBrake.Interop.Utilities; using HandBrakeWPF.Model.Subtitles; using HandBrakeWPF.Services.Presets.Model; using HandBrakeWPF.Utilities; using HandBrakeWPF.ViewModels.Interfaces; /// /// The Subtitles View Model /// public class SubtitlesDefaultsViewModel : ViewModelBase, ISubtitlesDefaultsViewModel { #region Constants and Fields private SubtitleBehaviours subtitleBehaviours; private BindingList availableLanguages; #endregion #region Constructors and Destructors /// /// Initializes a new instance of the class. /// public SubtitlesDefaultsViewModel() { this.Langauges = LanguageUtilities.MapLanguages().Keys; this.CharacterCodes = CharCodesUtilities.GetCharacterCodes(); this.SubtitleBehaviours = new SubtitleBehaviours(); this.SelectedAvailableToMove = new BindingList(); this.SelectedLangaugesToMove = new BindingList(); this.availableLanguages = new BindingList(); this.SetupLanguages((Preset)null); } #endregion #region Properties /// /// Gets CharacterCodes. /// public IEnumerable CharacterCodes { get; private set; } /// /// Gets Langauges. /// public IEnumerable Langauges { get; private set; } /// /// Gets or sets the subtitle behaviours. /// public SubtitleBehaviours SubtitleBehaviours { get { return this.subtitleBehaviours; } set { if (Equals(value, this.subtitleBehaviours)) { return; } this.subtitleBehaviours = value; this.NotifyOfPropertyChange(() => this.SubtitleBehaviours); } } /// /// Gets the sbutitle behaviour modes. /// public BindingList SubtitleBehaviourModeList { get { return new BindingList(EnumHelper.GetEnumList().ToList()); } } /// /// Gets the subtitle burn in behaviour mode list. /// public BindingList SubtitleBurnInBehaviourModeList { get { return new BindingList(EnumHelper.GetEnumList().ToList()); } } /// /// Gets AvailableLanguages. /// public BindingList AvailableLanguages { get { return this.availableLanguages; } private set { this.availableLanguages = value; this.NotifyOfPropertyChange("AvailableLanguages"); } } /// /// Gets SelectedLangauges. /// public BindingList SelectedAvailableToMove { get; private set; } /// /// Gets SelectedLangauges. /// public BindingList SelectedLangaugesToMove { get; private set; } #endregion #region Public Methods /// /// Audio List Move Left /// public void LanguageMoveRight() { if (this.SelectedAvailableToMove.Count > 0) { List copiedList = SelectedAvailableToMove.ToList(); foreach (string item in copiedList) { this.AvailableLanguages.Remove(item); this.SubtitleBehaviours.SelectedLangauges.Add(item); } this.AvailableLanguages = new BindingList(this.AvailableLanguages.OrderBy(o => o).ToList()); } } /// /// Audio List Move Right /// public void LanguageMoveLeft() { if (this.SelectedLangaugesToMove.Count > 0) { List copiedList = SelectedLangaugesToMove.ToList(); foreach (string item in copiedList) { this.SubtitleBehaviours.SelectedLangauges.Remove(item); this.AvailableLanguages.Add(item); } } this.AvailableLanguages = new BindingList(this.AvailableLanguages.OrderBy(o => o).ToList()); } /// /// Language List Clear all selected languages /// public void LanguageClearAll() { foreach (string item in this.SubtitleBehaviours.SelectedLangauges) { this.AvailableLanguages.Add(item); } this.AvailableLanguages = new BindingList(this.AvailableLanguages.OrderBy(o => o).ToList()); this.SubtitleBehaviours.SelectedLangauges.Clear(); } public void LaunchHelp() { Process.Start("https://handbrake.fr/docs/en/1.2.0/advanced/audio-subtitle-defaults.html"); } #endregion #region Methods /// /// The setup languages. /// /// /// The preset. /// public void SetupLanguages(Preset preset) { if (preset != null) { this.SetupLanguages(preset.SubtitleTrackBehaviours); } } /// /// The setup languages. /// /// /// The behaviours. /// public void SetupLanguages(SubtitleBehaviours behaviours) { // Step 1, Set the behaviour mode this.SubtitleBehaviours.SelectedBehaviour = SubtitleBehaviourModes.None; this.SubtitleBehaviours.SelectedBurnInBehaviour = SubtitleBurnInBehaviourModes.None; this.SubtitleBehaviours.AddClosedCaptions = false; this.SubtitleBehaviours.AddForeignAudioScanTrack = false; this.SubtitleBehaviours.SelectedLangauges.Clear(); // Step 2, Get all the languages IDictionary langList = LanguageUtilities.MapLanguages(); langList = (from entry in langList orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); // Step 3, Setup Available Languages this.AvailableLanguages.Clear(); foreach (string item in langList.Keys) { this.AvailableLanguages.Add(item); } // Step 4, Set the Selected Languages if (behaviours != null) { this.SubtitleBehaviours.SelectedBehaviour = behaviours.SelectedBehaviour; this.SubtitleBehaviours.SelectedBurnInBehaviour = behaviours.SelectedBurnInBehaviour; this.SubtitleBehaviours.AddClosedCaptions = behaviours.AddClosedCaptions; this.SubtitleBehaviours.AddForeignAudioScanTrack = behaviours.AddForeignAudioScanTrack; foreach (string selectedItem in behaviours.SelectedLangauges) { this.AvailableLanguages.Remove(selectedItem); this.SubtitleBehaviours.SelectedLangauges.Add(selectedItem); } } } #endregion } }