From d4327b0f304b99a7650b12622b48e6145794ab65 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 16 Feb 2014 18:39:29 +0000 Subject: WinGui: Initial work to refactor the Audio and Subtitle behavioural based automatic track selections. This is not quite complete yet but close enough for gathering feedback. - Simplified UI design that's now available on the "Subtitle" and "Audio" tabs rather than the Options screen. The settings are no longer part of the app preferences. They are now per-preset. Build in presets default to None. - Selected Languages can now be set independently for Audio and Video. - Preferred Language is now part of the Selected Languages list. - Warning: Import/Export of presets still to be implemented. Design may yet change. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6036 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrake.ApplicationServices.csproj | 4 + .../Model/Audio/AudioBehaviourModes.cs | 28 ++ .../Model/Audio/AudioBehaviours.cs | 103 +++++ .../HandBrake.ApplicationServices/Model/Preset.cs | 14 + .../Model/Subtitle/SubtitleBehaviourModes.cs | 28 ++ .../Model/Subtitle/SubtitleBehaviours.cs | 154 ++++++++ .../Utilities/Converters.cs | 2 +- .../Utilities/LanguageUtilities.cs | 39 +- .../HandBrakeInterop/HandBrakeInstance.cs | 2 - .../Converters/Audio/AudioBehaviourConverter.cs | 90 +++++ .../HandBrakeWPF/Converters/EnumComboConverter.cs | 2 - .../Converters/Options/OptionsTabConverter.cs | 4 +- .../Subtitles/SubtitleBehaviourConverter.cs | 90 +++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 + win/CS/HandBrakeWPF/Model/OptionsTab.cs | 3 - win/CS/HandBrakeWPF/UserSettingConstants.cs | 50 --- .../HandBrakeWPF/ViewModels/AddPresetViewModel.cs | 12 +- win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs | 310 ++++++++++++--- .../ViewModels/Interfaces/IAddPresetViewModel.cs | 10 +- .../ViewModels/Interfaces/IAudioViewModel.cs | 7 + .../ViewModels/Interfaces/ISubtitlesViewModel.cs | 6 + win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 2 +- win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 426 --------------------- .../ViewModels/QueueSelectionViewModel.cs | 12 +- .../HandBrakeWPF/ViewModels/SubtitlesViewModel.cs | 348 ++++++++++++++--- win/CS/HandBrakeWPF/Views/AudioView.xaml | 202 +++++++--- win/CS/HandBrakeWPF/Views/OptionsView.xaml | 105 ----- win/CS/HandBrakeWPF/Views/SubtitlesView.xaml | 106 ++++- 28 files changed, 1402 insertions(+), 759 deletions(-) create mode 100644 win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviourModes.cs create mode 100644 win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviours.cs create mode 100644 win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviourModes.cs create mode 100644 win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviours.cs create mode 100644 win/CS/HandBrakeWPF/Converters/Audio/AudioBehaviourConverter.cs create mode 100644 win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBehaviourConverter.cs (limited to 'win/CS') diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index 6110c187d..6ba1e302d 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -97,7 +97,11 @@ + + + + diff --git a/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviourModes.cs b/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviourModes.cs new file mode 100644 index 000000000..0172b8b1b --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviourModes.cs @@ -0,0 +1,28 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The audio behaviours. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Model.Audio +{ + using System.ComponentModel.DataAnnotations; + + /// + /// The audio behaviours. + /// + public enum AudioBehaviourModes + { + [Display(Name = "None")] + None = 0, + + [Display(Name = "First Matching Selected Language")] + FirstMatch, + + [Display(Name = "All Matching Selected Languages")] + AllMatching, + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviours.cs b/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviours.cs new file mode 100644 index 000000000..119c8d26d --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Model/Audio/AudioBehaviours.cs @@ -0,0 +1,103 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Audio Behaviours +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Model.Audio +{ + using System.ComponentModel; + + using Caliburn.Micro; + + /// + /// Audio Behaviours + /// + public class AudioBehaviours : PropertyChangedBase + { + /// + /// The selected behaviour. + /// + private AudioBehaviourModes selectedBehaviour; + + /// + /// The selected langauges. + /// + private BindingList selectedLangauges; + + /// + /// Initializes a new instance of the class. + /// + public AudioBehaviours() + { + this.SelectedBehaviour = AudioBehaviourModes.None; + this.SelectedLangauges = new BindingList(); + } + + /// + /// Gets or sets the selected behaviour. + /// + public AudioBehaviourModes SelectedBehaviour + { + get + { + return this.selectedBehaviour; + } + + set + { + if (value == this.selectedBehaviour) + { + return; + } + this.selectedBehaviour = value; + this.NotifyOfPropertyChange(() => this.SelectedBehaviour); + } + } + + /// + /// Gets or sets the selected langauges. + /// + public BindingList SelectedLangauges + { + get + { + return this.selectedLangauges; + } + set + { + if (Equals(value, this.selectedLangauges)) + { + return; + } + this.selectedLangauges = value; + this.NotifyOfPropertyChange(() => this.SelectedLangauges); + } + } + + /// + /// Clone this object + /// + /// + /// The . + /// + public AudioBehaviours Clone() + { + AudioBehaviours cloned = new AudioBehaviours + { + SelectedBehaviour = this.selectedBehaviour, + SelectedLangauges = new BindingList() + }; + + foreach (var item in this.SelectedLangauges) + { + cloned.SelectedLangauges.Add(item); + } + + return cloned; + } + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Model/Preset.cs b/win/CS/HandBrake.ApplicationServices/Model/Preset.cs index 7003ca2c7..57faf2968 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Preset.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Preset.cs @@ -11,6 +11,9 @@ namespace HandBrake.ApplicationServices.Model { using Caliburn.Micro; + using HandBrake.ApplicationServices.Model.Audio; + using HandBrake.ApplicationServices.Model.Subtitle; + /// /// A Preset for encoding with. /// @@ -25,6 +28,7 @@ namespace HandBrake.ApplicationServices.Model #endregion + #region Properties /// @@ -89,6 +93,16 @@ namespace HandBrake.ApplicationServices.Model /// public string Version { get; set; } + /// + /// Gets or sets the audio track behaviours. + /// + public AudioBehaviours AudioTrackBehaviours { get; set; } + + /// + /// Gets or sets the subtitle track behaviours. + /// + public SubtitleBehaviours SubtitleTrackBehaviours { get; set; } + #endregion #region Public Methods diff --git a/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviourModes.cs b/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviourModes.cs new file mode 100644 index 000000000..4094c402e --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviourModes.cs @@ -0,0 +1,28 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The subtitle behaviours modes. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Model.Subtitle +{ + using System.ComponentModel.DataAnnotations; + + /// + /// The subtitle behaviours modes. + /// + public enum SubtitleBehaviourModes + { + [Display(Name = "None")] + None = 0, + + [Display(Name = "First Matching Selected Language")] + FirstMatch, + + [Display(Name = "All Matching Selected Languages")] + AllMatching, + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviours.cs b/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviours.cs new file mode 100644 index 000000000..28f5176d1 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Model/Subtitle/SubtitleBehaviours.cs @@ -0,0 +1,154 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// A class to track the behaviours of audio track selection +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Model.Subtitle +{ + using System.ComponentModel; + + using Caliburn.Micro; + + /// + /// A class to track the behaviours of audio track selection + /// + public class SubtitleBehaviours : PropertyChangedBase + { + /// + /// The selected behaviour. + /// + private SubtitleBehaviourModes selectedBehaviour; + + /// + /// The selected langauges. + /// + private BindingList selectedLangauges; + + /// + /// The add foreign audio scan track. + /// + private bool addForeignAudioScanTrack; + + /// + /// The add closed captions. + /// + private bool addClosedCaptions; + + /// + /// Initializes a new instance of the class. + /// + public SubtitleBehaviours() + { + this.SelectedBehaviour = SubtitleBehaviourModes.None; + this.SelectedLangauges = new BindingList(); + } + + /// + /// Gets or sets the selected behaviour. + /// + public SubtitleBehaviourModes SelectedBehaviour + { + get + { + return this.selectedBehaviour; + } + set + { + if (value == this.selectedBehaviour) + { + return; + } + this.selectedBehaviour = value; + this.NotifyOfPropertyChange(() => this.SelectedBehaviour); + } + } + + /// + /// Gets or sets the selected langages. + /// + public BindingList SelectedLangauges + { + get + { + return this.selectedLangauges; + } + set + { + if (Equals(value, this.selectedLangauges)) + { + return; + } + this.selectedLangauges = value; + this.NotifyOfPropertyChange(() => this.SelectedLangauges); + } + } + + /// + /// Gets or sets a value indicating whether add foreign audio scan track. + /// + public bool AddForeignAudioScanTrack + { + get + { + return this.addForeignAudioScanTrack; + } + set + { + if (value.Equals(this.addForeignAudioScanTrack)) + { + return; + } + this.addForeignAudioScanTrack = value; + this.NotifyOfPropertyChange(() => this.AddForeignAudioScanTrack); + } + } + + /// + /// Gets or sets a value indicating whether add closed captions. + /// + public bool AddClosedCaptions + { + get + { + return this.addClosedCaptions; + } + set + { + if (value.Equals(this.addClosedCaptions)) + { + return; + } + this.addClosedCaptions = value; + this.NotifyOfPropertyChange(() => this.AddClosedCaptions); + } + } + + /// + /// Clone this object + /// + /// + /// The . + /// + public SubtitleBehaviours Clone() + { + SubtitleBehaviours cloned = new SubtitleBehaviours + { + SelectedBehaviour = this.selectedBehaviour, + SelectedLangauges = new BindingList(), + AddClosedCaptions = this.addClosedCaptions, + AddForeignAudioScanTrack = this.addForeignAudioScanTrack, + }; + + foreach (var item in this.SelectedLangauges) + { + cloned.SelectedLangauges.Add(item); + } + + return cloned; + } + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs b/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs index 1c6b785bb..9651c6e71 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs @@ -129,7 +129,7 @@ namespace HandBrake.ApplicationServices.Utilities { case Mixdown.Auto: case Mixdown.None: - return "auto"; + return "none"; case Mixdown.Mono: return "mono"; case Mixdown.LeftOnly: diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/LanguageUtilities.cs b/win/CS/HandBrake.ApplicationServices/Utilities/LanguageUtilities.cs index bbfe8f62c..94a1fb201 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/LanguageUtilities.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/LanguageUtilities.cs @@ -11,6 +11,7 @@ namespace HandBrake.ApplicationServices.Utilities { using System.Collections.Generic; using System.Collections.Specialized; + using System.Linq; /// /// Language Utilities @@ -248,6 +249,42 @@ namespace HandBrake.ApplicationServices.Utilities } return iso6392Codes; - } + } + + /// + /// The get language codes. + /// + /// + /// The user languages. + /// + /// + /// The . + /// + public static List GetLanguageCodes(IList userLanguages) + { + // Translate to Iso Codes + List iso6392Codes = new List(); + foreach (var item in userLanguages) + { + string isoCode; + if (LanguageUtilities.MapLanguages().TryGetValue(item, out isoCode)) + { + iso6392Codes.Add(isoCode); + } + } + + return iso6392Codes; + } + + /// + /// The get iso codes. + /// + /// + /// The . + /// + public static List GetIsoCodes() + { + return MapLanguages().Values.ToList(); + } } } diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index fb3cf1f51..72a75c112 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -267,8 +267,6 @@ namespace HandBrake.Interop HBFunctions.hb_scan_stop(this.hbHandle); } - - /// /// Gets an image for the given job and preview /// diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioBehaviourConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioBehaviourConverter.cs new file mode 100644 index 000000000..a53c4e7e9 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioBehaviourConverter.cs @@ -0,0 +1,90 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Audio Behaviour Converter +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Audio +{ + using System; + using System.ComponentModel; + using System.Globalization; + using System.Linq; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Model.Audio; + using HandBrake.ApplicationServices.Utilities; + + /// + /// Audio Behaviour Converter + /// + public class AudioBehaviourConverter : IValueConverter + { + /// + /// The convert. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null && value.GetType() == typeof(BindingList)) + { + return + new BindingList( + EnumHelper.GetEnumDisplayValues(typeof(AudioBehaviourModes)).ToList()); + } + + if (value != null && value.GetType() == typeof(AudioBehaviourModes)) + { + return EnumHelper.GetDisplay((AudioBehaviourModes)value); + } + + return null; + } + + /// + /// The convert back. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + string name = value as string; + if (!string.IsNullOrEmpty(name)) + { + return EnumHelper.GetValue(name); + } + + return null; + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index dd26399db..9214745e8 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -19,8 +19,6 @@ namespace HandBrakeWPF.Converters using HandBrake.Interop.Model.Encoding; using HandBrake.Interop.Model.Encoding.x264; - using HandBrakeWPF.Model; - /// /// Enum Combo Converter /// diff --git a/win/CS/HandBrakeWPF/Converters/Options/OptionsTabConverter.cs b/win/CS/HandBrakeWPF/Converters/Options/OptionsTabConverter.cs index bd1e4c8d0..54897e19c 100644 --- a/win/CS/HandBrakeWPF/Converters/Options/OptionsTabConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Options/OptionsTabConverter.cs @@ -40,9 +40,7 @@ namespace HandBrakeWPF.Converters.Options case OptionsTab.OutputFiles: if ((OptionsTab)parameter == OptionsTab.OutputFiles) return Visibility.Visible; break; - case OptionsTab.AudioAndSubtitles: - if ((OptionsTab)parameter == OptionsTab.AudioAndSubtitles) return Visibility.Visible; - break; + case OptionsTab.Advanced: if ((OptionsTab)parameter == OptionsTab.Advanced) return Visibility.Visible; break; diff --git a/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBehaviourConverter.cs b/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBehaviourConverter.cs new file mode 100644 index 000000000..251565d80 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBehaviourConverter.cs @@ -0,0 +1,90 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Subtitle Behaviour Converter +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Subtitles +{ + using System; + using System.ComponentModel; + using System.Globalization; + using System.Linq; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Model.Subtitle; + using HandBrake.ApplicationServices.Utilities; + + /// + /// Subtitle Behaviour Converter + /// + public class SubtitleBehaviourConverter : IValueConverter + { + /// + /// The convert. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null && value.GetType() == typeof(BindingList)) + { + return + new BindingList( + EnumHelper.GetEnumDisplayValues(typeof(SubtitleBehaviourModes)).ToList()); + } + + if (value != null && value.GetType() == typeof(SubtitleBehaviourModes)) + { + return EnumHelper.GetDisplay((SubtitleBehaviourModes)value); + } + + return null; + } + + /// + /// The convert back. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + string name = value as string; + if (!string.IsNullOrEmpty(name)) + { + return EnumHelper.GetValue(name); + } + + return null; + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index b7c27048f..8e92b7115 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -130,6 +130,8 @@ + + diff --git a/win/CS/HandBrakeWPF/Model/OptionsTab.cs b/win/CS/HandBrakeWPF/Model/OptionsTab.cs index e895b6159..b22807e46 100644 --- a/win/CS/HandBrakeWPF/Model/OptionsTab.cs +++ b/win/CS/HandBrakeWPF/Model/OptionsTab.cs @@ -22,9 +22,6 @@ namespace HandBrakeWPF.Model [Display(Name = "Output Files")] OutputFiles, - [Display(Name = "Audio and Subtitles")] - AudioAndSubtitles, - [Display(Name = "Video")] Video, diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index 129f031b5..80bebe4b3 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -21,11 +21,6 @@ namespace HandBrakeWPF /// public const string HandBrakeBuild = "HandBrakeBuild"; - /// - /// Add Only One Per Langage - /// - public const string AddOnlyOneAudioPerLanguage = "addOnlyOneAudioPerLanguage"; - /// /// Auto name format /// @@ -66,21 +61,6 @@ namespace HandBrakeWPF /// public const string DefaultPlayer = "defaultPlayer"; - /// - /// Dub mode - /// - public const string DubMode = "DubMode"; - - /// - /// Dub Mode Audio - /// - public const string DubModeAudio = "DubModeAudio"; - - /// - /// Dub Mode Subs - /// - public const string DubModeSubtitle = "DubModeSubtitle"; - /// /// Last Update Check /// @@ -96,31 +76,11 @@ namespace HandBrakeWPF /// public const string MinTitleLength = "MinTitleLength"; - /// - /// Native Language Audio - /// - public const string NativeLanguage = "NativeLanguage"; - - /// - /// Native Language Subs - /// - public const string NativeLanguageForSubtitles = "NativeLanguageSubtitles"; - /// /// Preset Notification /// public const string PresetNotification = "presetNotification"; - /// - /// Selected Languages - /// - public const string SelectedLanguages = "SelectedLanguages"; - - /// - /// AUudio Passthru - /// - public const string ShowAdvancedAudioPassthruOpts = "ShowAdvancedAudioPassthruOpts"; - /// /// Skip Version /// @@ -131,11 +91,6 @@ namespace HandBrakeWPF /// public const string UpdateStatus = "updateStatus"; - /// - /// Closed Captions - /// - public const string UseClosedCaption = "useClosedCaption"; - /// /// Use m4v /// @@ -241,11 +196,6 @@ namespace HandBrakeWPF /// public const string ResetWhenDoneAction = "ResetWhenDoneAction"; - /// - /// The add foreign audio scan track. - /// - public const string AddForeignAudioScanTrack = "AddForeignAudioScanTrack"; - /// /// The disable lib dvd nav. /// diff --git a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs index 4235a67dc..bedfb838c 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs @@ -13,6 +13,8 @@ namespace HandBrakeWPF.ViewModels using System.Windows; using HandBrake.ApplicationServices.Model; + using HandBrake.ApplicationServices.Model.Audio; + using HandBrake.ApplicationServices.Model.Subtitle; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services; using HandBrake.ApplicationServices.Services.Interfaces; @@ -132,9 +134,17 @@ namespace HandBrakeWPF.ViewModels /// /// The title. /// - public void Setup(EncodeTask task, Title title) + /// + /// The audio Behaviours. + /// + /// + /// The subtitle Behaviours. + /// + public void Setup(EncodeTask task, Title title, AudioBehaviours audioBehaviours, SubtitleBehaviours subtitleBehaviours) { this.Preset.Task = new EncodeTask(task); + this.Preset.AudioTrackBehaviours = audioBehaviours.Clone(); + this.Preset.SubtitleTrackBehaviours = subtitleBehaviours.Clone(); this.selectedTitle = title; switch (task.Anamorphic) diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index ed619b010..0e25b3f58 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -9,21 +9,21 @@ namespace HandBrakeWPF.ViewModels { + using System; using System.Collections.Generic; using System.Collections.ObjectModel; - using System.Collections.Specialized; + using System.ComponentModel; using System.Linq; using Caliburn.Micro; using HandBrake.ApplicationServices.Model; + using HandBrake.ApplicationServices.Model.Audio; using HandBrake.ApplicationServices.Model.Encoding; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Utilities; using HandBrake.Interop.Model.Encoding; - using HandBrakeWPF.Commands; - using HandBrakeWPF.Model; using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; @@ -42,6 +42,21 @@ namespace HandBrakeWPF.ViewModels /// private Preset currentPreset; + /// + /// The show audio defaults panel. + /// + private bool showAudioDefaultsPanel; + + /// + /// The available languages. + /// + private BindingList availableLanguages; + + /// + /// The audio behaviours. + /// + private AudioBehaviours audioBehaviours; + #region Constructors and Destructors /// @@ -60,12 +75,49 @@ namespace HandBrakeWPF.ViewModels this.AudioEncoders = EnumHelper.GetEnumList(); this.AudioMixdowns = EnumHelper.GetEnumList(); this.SourceTracks = new List public void SetDefaultBehaviour() { - OpenOptionsScreenCommand command = new OpenOptionsScreenCommand(); - command.Execute(OptionsTab.AudioAndSubtitles); + this.ShowAudioDefaultsPanel = true; + } + + /// + /// The show audio defaults. + /// + public void ShowAudioDefaults() + { + this.ShowAudioDefaultsPanel = !this.ShowAudioDefaultsPanel; + } + + /// + /// 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(); } #endregion @@ -203,16 +372,18 @@ namespace HandBrakeWPF.ViewModels this.Task = task; this.currentPreset = preset; + // Audio Behaviours + this.SetupLanguages(preset); + if (preset != null && preset.Task != null) { - int mode = this.UserSettingService.GetUserSetting(UserSettingConstants.DubModeAudio); - if (mode >= 1) + if (this.AudioBehaviours.SelectedBehaviour != AudioBehaviourModes.None) { this.AutomaticTrackSelection(); } else { - this.AddTracksFromPreset(preset); + this.AddTracksFromPreset(preset); } this.AutomaticTrackSelection(); @@ -303,12 +474,6 @@ namespace HandBrakeWPF.ViewModels // For all the source audio tracks foreach (Audio sourceTrack in this.SourceTracks) { - // Step 1: If "Add only One per language" is turned on, check to see if this language is already added. - if (this.CanSkipSourceTrack(sourceTrack)) - { - continue; - } - // Step 2: Check if the track list already contrains this track bool found = this.Task.AudioTracks.Any(audioTrack => Equals(audioTrack.ScannedTrack, sourceTrack)); if (!found) @@ -327,12 +492,6 @@ namespace HandBrakeWPF.ViewModels // Add them if they are not already added. foreach (Audio sourceTrack in this.GetSelectedLanguagesTracks()) { - // Step 1: If "Add only One per language" is turned on, check to see if this language is already added. - if (this.CanSkipSourceTrack(sourceTrack)) - { - continue; - } - // Step 2: Check if the track list already contrains this track bool found = this.Task.AudioTracks.Any(audioTrack => Equals(audioTrack.ScannedTrack, sourceTrack)); if (!found) @@ -361,6 +520,35 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// The add first for selected languages. + /// + private void AddFirstForSelectedLanguages() + { + foreach (Audio sourceTrack in this.GetSelectedLanguagesTracks()) + { + // Step 2: Check if the track list already contrains this track + bool found = this.Task.AudioTracks.Any(audioTrack => Equals(audioTrack.ScannedTrack, sourceTrack)); + if (!found) + { + // Check if we are already using this language + bool foundLanguage = false; + foreach (var item in this.Task.AudioTracks.Where(item => item.ScannedTrack != null && sourceTrack.LanguageCode.Contains(item.ScannedTrack.LanguageCode))) + { + foundLanguage = true; + } + + if (foundLanguage) + { + continue; + } + + // If it doesn't, add it. + this.Add(sourceTrack); + } + } + } + /// /// Attempt to automatically select the correct audio tracks based on the users settings. /// @@ -381,8 +569,7 @@ namespace HandBrakeWPF.ViewModels } // Handle the default selection behaviour. - int mode = this.UserSettingService.GetUserSetting(UserSettingConstants.DubModeAudio); - if (mode == 1 || mode == 2) + 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. @@ -390,12 +577,12 @@ namespace HandBrakeWPF.ViewModels this.AddTracksFromPreset(this.currentPreset); } - switch (mode) + switch (this.AudioBehaviours.SelectedBehaviour) { - case 1: // Adding all remaining audio tracks - this.AddAllRemaining(); + case AudioBehaviourModes.FirstMatch: // Adding all remaining audio tracks + this.AddFirstForSelectedLanguages(); break; - case 2: // Add Langauges tracks for the additional languages selected, in-order. + case AudioBehaviourModes.AllMatching: // Add Langauges tracks for the additional languages selected, in-order. this.AddAllRemainingForSelectedLanguages(); break; } @@ -409,12 +596,18 @@ namespace HandBrakeWPF.ViewModels /// private Audio GetPreferredAudioTrack() { - // Get the preferred Language - IEnumerable