From 257b3cc03cb5dc4cf1c2006dd14282cd2ff904d5 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 22 Feb 2014 17:10:47 +0000 Subject: [PATCH] WinGui: Further work on the new Audio and Subtitle automatic behaviour system. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6060 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Model/Audio/AudioBehaviours.cs | 12 ++ .../Model/Preset.cs | 21 +++- .../Model/Subtitle/SubtitleBehaviours.cs | 12 ++ .../HandBrakeWPF/ViewModels/AudioViewModel.cs | 108 +++++++----------- .../HandBrakeWPF/ViewModels/MainViewModel.cs | 4 +- 5 files changed, 88 insertions(+), 69 deletions(-) diff --git a/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviours.cs b/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviours.cs index 119c8d26d..4363ec56d 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviours.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviours.cs @@ -37,6 +37,18 @@ namespace HandBrake.ApplicationServices.Model.Audio this.SelectedLangauges = new BindingList(); } + /// + /// Initializes a new instance of the class. + /// + /// + /// The behaviours. + /// + public AudioBehaviours(AudioBehaviours behaviours) + { + this.SelectedBehaviour = behaviours.SelectedBehaviour; + this.SelectedLangauges = new BindingList(behaviours.selectedLangauges); + } + /// /// Gets or sets the selected behaviour. /// diff --git a/win/CS/HandBrake.ApplicationServices/Model/Preset.cs b/win/CS/HandBrake.ApplicationServices/Model/Preset.cs index 57faf2968..e281e12b6 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Preset.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Preset.cs @@ -28,7 +28,6 @@ namespace HandBrake.ApplicationServices.Model #endregion - #region Properties /// @@ -107,6 +106,26 @@ namespace HandBrake.ApplicationServices.Model #region Public Methods + /// + /// Update this preset. + /// The given parameters should be copy-constructed. + /// + /// + /// The task. + /// + /// + /// The audio behaviours. + /// + /// + /// The subtitle behaviours. + /// + public void Update(EncodeTask task, AudioBehaviours audioBehaviours, SubtitleBehaviours subtitleBehaviours) + { + this.Task = task; + this.AudioTrackBehaviours = audioBehaviours; + this.SubtitleTrackBehaviours = subtitleBehaviours; + } + /// /// Override the ToString Method /// diff --git a/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviours.cs b/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviours.cs index 28f5176d1..c96357c3b 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviours.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviours.cs @@ -47,6 +47,18 @@ namespace HandBrake.ApplicationServices.Model.Subtitle this.SelectedLangauges = new BindingList(); } + /// + /// Initializes a new instance of the class. + /// + /// + /// The behaviours. + /// + public SubtitleBehaviours(SubtitleBehaviours behaviours) + { + this.SelectedBehaviour = behaviours.selectedBehaviour; + this.SelectedLangauges = new BindingList(behaviours.SelectedLangauges); + } + /// /// Gets or sets the selected behaviour. /// diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index 0e25b3f58..73741313f 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -9,7 +9,6 @@ namespace HandBrakeWPF.ViewModels { - using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; @@ -377,19 +376,11 @@ namespace HandBrakeWPF.ViewModels if (preset != null && preset.Task != null) { - if (this.AudioBehaviours.SelectedBehaviour != AudioBehaviourModes.None) - { - this.AutomaticTrackSelection(); - } - else - { - this.AddTracksFromPreset(preset); - } - - this.AutomaticTrackSelection(); + this.SetupTracks(); this.Task.AllowedPassthruOptions = new AllowedPassthru(preset.Task.AllowedPassthruOptions); } + this.NotifyOfPropertyChange(() => this.Task); } @@ -435,7 +426,7 @@ namespace HandBrakeWPF.ViewModels } else { - this.AutomaticTrackSelection(); + this.SetupTracks(); } // Force UI Updates @@ -485,39 +476,43 @@ namespace HandBrakeWPF.ViewModels } /// - /// Add all remaining for selected languages. + /// Attempt to automatically select the correct audio tracks based on the users settings. /// - public void AddAllRemainingForSelectedLanguages() + private void SetupTracks() { - // Add them if they are not already added. - foreach (Audio sourceTrack in this.GetSelectedLanguagesTracks()) + if (!this.SourceTracks.Any()) { - // Step 2: Check if the track list already contrains this track - bool found = this.Task.AudioTracks.Any(audioTrack => Equals(audioTrack.ScannedTrack, sourceTrack)); - if (!found) - { - // If it doesn't, add it. - this.Add(sourceTrack); - } + // Clear out the old tracks + this.Task.AudioTracks.Clear(); + + return; } - } - /// - /// Add the required tracks for the current preset - /// - /// - /// The preset. - /// - private void AddTracksFromPreset(Preset preset) - { - // Clear out the old tracks + // Step 1, Cleanup Previous Tracks this.Task.AudioTracks.Clear(); - // Add the preset audio tracks with the preferred language - foreach (AudioTrack track in preset.Task.AudioTracks) + // Step 2, Sanity Check + if (this.SourceTracks == null || !this.SourceTracks.Any()) + { + return; + } + + // Step 3, Setup the tracks from the preset + foreach (AudioTrack track in this.currentPreset.Task.AudioTracks) { this.Task.AudioTracks.Add(new AudioTrack(track) { ScannedTrack = this.GetPreferredAudioTrack() }); } + + // Step 4, Handle the default selection behaviour. + switch (this.AudioBehaviours.SelectedBehaviour) + { + case AudioBehaviourModes.FirstMatch: // Adding all remaining audio tracks + this.AddFirstForSelectedLanguages(); + break; + case AudioBehaviourModes.AllMatching: // Add Langauges tracks for the additional languages selected, in-order. + this.AddAllRemainingForSelectedLanguages(); + break; + } } /// @@ -550,41 +545,20 @@ namespace HandBrakeWPF.ViewModels } /// - /// Attempt to automatically select the correct audio tracks based on the users settings. + /// Add all remaining for selected languages. /// - private void AutomaticTrackSelection() + public void AddAllRemainingForSelectedLanguages() { - if (!this.SourceTracks.Any()) - { - // Clear out the old tracks - this.Task.AudioTracks.Clear(); - - return; - } - - // We've changed source, so lets try reset the language, description and formats as close as possible to the previous track. - foreach (AudioTrack track in this.Task.AudioTracks) - { - track.ScannedTrack = this.GetPreferredAudioTrack(); - } - - // Handle the default selection behaviour. - if (this.AudioBehaviours.SelectedBehaviour != AudioBehaviourModes.None) - { - // First, we'll clear out all current tracks and go back to what the current preset has. - // This will alteast provide a consistent behavior when switching tracks. - this.Task.AudioTracks.Clear(); - this.AddTracksFromPreset(this.currentPreset); - } - - switch (this.AudioBehaviours.SelectedBehaviour) + // Add them if they are not already added. + foreach (Audio sourceTrack in this.GetSelectedLanguagesTracks()) { - case AudioBehaviourModes.FirstMatch: // Adding all remaining audio tracks - this.AddFirstForSelectedLanguages(); - break; - case AudioBehaviourModes.AllMatching: // Add Langauges tracks for the additional languages selected, in-order. - this.AddAllRemainingForSelectedLanguages(); - break; + // Step 2: Check if the track list already contrains this track + bool found = this.Task.AudioTracks.Any(audioTrack => Equals(audioTrack.ScannedTrack, sourceTrack)); + if (!found) + { + // If it doesn't, add it. + this.Add(sourceTrack); + } } } diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index aa60adf68..d9c2640f8 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -23,7 +23,9 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Factories; using HandBrake.ApplicationServices.Model; + using HandBrake.ApplicationServices.Model.Audio; using HandBrake.ApplicationServices.Model.Encoding; + using HandBrake.ApplicationServices.Model.Subtitle; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services.Interfaces; using HandBrake.ApplicationServices.Utilities; @@ -1495,7 +1497,7 @@ namespace HandBrakeWPF.ViewModels if (this.errorService.ShowMessageBox(Resources.Main_PresetUpdateConfrimation, Resources.AreYouSure, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { - this.SelectedPreset.Task = new EncodeTask(this.CurrentTask); + this.SelectedPreset.Update(new EncodeTask(this.CurrentTask), new AudioBehaviours(this.AudioViewModel.AudioBehaviours), new SubtitleBehaviours(this.SubtitleViewModel.SubtitleBehaviours)); this.presetService.Update(this.SelectedPreset); this.errorService.ShowMessageBox( -- 2.40.0