// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // The Audio Defaults View Model // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.ViewModels { using System.Collections.Generic; using System.ComponentModel; using System.Linq; using Caliburn.Micro; using HandBrake.ApplicationServices.Interop.Model.Encoding; using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Commands; using HandBrakeWPF.Model.Audio; using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.Services.Presets.Model; using HandBrakeWPF.ViewModels.Interfaces; /// /// The Audio View Model /// public class AudioDefaultsViewModel : ViewModelBase, IAudioDefaultsViewModel { /// /// The available languages. /// private BindingList availableLanguages; /// /// The audio behaviours. /// private AudioBehaviours audioBehaviours; #region Constructors and Destructors /// /// Initializes a new instance of the class. /// /// /// The window manager. /// /// /// The user Setting Service. /// public AudioDefaultsViewModel(IWindowManager windowManager, IUserSettingService userSettingService) { this.AudioEncoders = EnumHelper.GetEnumList(); this.AudioBehaviours = new AudioBehaviours(); this.SelectedAvailableToMove = new BindingList(); this.SelectedLangaugesToMove = new BindingList(); this.AvailableLanguages = new BindingList(); this.SetupLanguages(null); } #endregion #region Properties /// /// Gets or sets the audio behaviours. /// public AudioBehaviours AudioBehaviours { get { return this.audioBehaviours; } set { if (Equals(value, this.audioBehaviours)) { return; } this.audioBehaviours = value; this.NotifyOfPropertyChange(() => this.AudioBehaviours); } } /// /// Gets the audio behaviour modes. /// public BindingList AudioBehaviourModeList { get { return new BindingList(EnumHelper.GetEnumList().ToList()); } } /// /// Gets or sets AudioEncoders. /// public IEnumerable AudioEncoders { get; set; } /// /// Gets or sets AvailableLanguages. /// public BindingList AvailableLanguages { get { return this.availableLanguages; } set { this.availableLanguages = value; this.NotifyOfPropertyChange("AvailableLanguages"); } } /// /// Gets or sets SelectedLangauges. /// public BindingList SelectedAvailableToMove { get; set; } /// /// Gets or sets SelectedLangauges. /// public BindingList SelectedLangaugesToMove { get; 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.AudioBehaviours.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.AudioBehaviours.SelectedLangauges.Remove(item); this.AvailableLanguages.Add(item); } } this.AvailableLanguages = new BindingList(this.AvailableLanguages.OrderBy(o => o).ToList()); } /// /// Audio List Clear all selected languages /// public void LanguageClearAll() { foreach (string item in this.AudioBehaviours.SelectedLangauges) { this.AvailableLanguages.Add(item); } this.AvailableLanguages = new BindingList(this.AvailableLanguages.OrderBy(o => o).ToList()); this.AudioBehaviours.SelectedLangauges.Clear(); } /// /// The close. /// public void Close() { CloseOverlayPanelCommand command = new CloseOverlayPanelCommand(); command.Execute(null); } #endregion #region Methods /// /// The setup languages. /// /// /// The preset. /// private void SetupLanguages(Preset preset) { // Step 1, Set the behaviour mode this.AudioBehaviours.SelectedBehaviour = AudioBehaviourModes.None; this.AudioBehaviours.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 (preset != null && preset.AudioTrackBehaviours != null) { this.AudioBehaviours.SelectedBehaviour = preset.AudioTrackBehaviours.SelectedBehaviour; foreach (string selectedItem in preset.AudioTrackBehaviours.SelectedLangauges) { this.AvailableLanguages.Remove(selectedItem); this.AudioBehaviours.SelectedLangauges.Add(selectedItem); } } } #endregion } }