From a8c98d2da676d507a0754ec191d53a1122a40220 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 19 May 2012 21:02:08 +0000 Subject: WinGui: When Changing the output format, limit to only valid choices in the video and audio encoder dropdowns. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4688 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Functions/EnumHelper.cs | 17 ++++ .../Model/Encoding/AudioTrack.cs | 2 - .../Converters/Audio/AudioEncoderConverter.cs | 95 ++++++++++++++++++++++ .../HandBrakeWPF/Converters/EnumComboConverter.cs | 15 +--- .../Converters/Video/VideoEncoderConverter.cs | 93 +++++++++++++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 + win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs | 16 ++++ .../ViewModels/Interfaces/IAudioViewModel.cs | 4 + .../ViewModels/Interfaces/IVideoViewModel.cs | 4 + win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 10 +-- win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs | 13 +++ win/CS/HandBrakeWPF/Views/AudioView.xaml | 19 ++++- win/CS/HandBrakeWPF/Views/FiltersView.xaml.cs | 26 +++--- win/CS/HandBrakeWPF/Views/VideoView.xaml | 21 ++++- 14 files changed, 299 insertions(+), 38 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs create mode 100644 win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs (limited to 'win') diff --git a/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs b/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs index 0308069f9..9bbfc30d0 100644 --- a/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs +++ b/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs @@ -102,5 +102,22 @@ namespace HandBrake.ApplicationServices.Functions strings.Add(GetDisplay(e)); return strings; } + + /// + /// Get a list of string names for each enum value passed in. + /// + /// + /// The items. + /// + /// + /// The type of the enum + /// + /// + /// A collection of strings that represent all the enum values + /// + public static IEnumerable GetEnumDisplayValuesSubset(IEnumerable items) + { + return items.Select(GetDisplay).ToList(); + } } } diff --git a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs index 14a87bd00..a9d42861a 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs @@ -7,8 +7,6 @@ // // -------------------------------------------------------------------------------------------------------------------- -using System.Collections.Generic; - namespace HandBrake.ApplicationServices.Model.Encoding { using System; diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs new file mode 100644 index 000000000..5c82b33ed --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs @@ -0,0 +1,95 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Audio Encoder Converter +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Audio +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Functions; + using HandBrake.ApplicationServices.Model; + using HandBrake.ApplicationServices.Model.Encoding; + using HandBrake.Interop.Model.Encoding; + + /// + /// Audio Encoder Converter + /// + public class AudioEncoderConverter : IMultiValueConverter + { + /// + /// Gets a list of audio encoders OR returns the string name of an encoder depending on the input. + /// + /// + /// The values. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// IEnumberable AudioEncoder or String encoder name. + /// + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + // TODO -> Be smarter and only show the available Passthru options. + if (values.Count() == 2) + { + List encoders = EnumHelper.GetEnumList().ToList(); + EncodeTask task = values[1] as EncodeTask; + + if (task != null && task.OutputFormat != OutputFormat.Mkv) + { + encoders.Remove(AudioEncoder.Vorbis); + encoders.Remove(AudioEncoder.ffflac); + } + + return EnumHelper.GetEnumDisplayValuesSubset(encoders); + } + + return EnumHelper.GetDisplay((AudioEncoder)values[0]); + } + + /// + /// Convert from a string name, to enum value. + /// + /// + /// The value. + /// + /// + /// The target types. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// Returns the audio encoder enum item. + /// + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + string name = value as string; + if (!string.IsNullOrEmpty(name)) + { + return new object[] { EnumHelper.GetValue(name)}; + } + + return null; + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index bb6a4be61..a4b8b6df0 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -65,10 +65,7 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetEnumDisplayValues(typeof(Mixdown)); } - if (value is IEnumerable) - { - return EnumHelper.GetEnumDisplayValues(typeof(AudioEncoder)); - } + if (value is IEnumerable) { return EnumHelper.GetEnumDisplayValues(typeof(PresetPictureSettingsMode)); @@ -113,10 +110,7 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetDisplay((Mixdown)value); } - if (targetType == typeof(AudioEncoder) || value.GetType() == typeof(AudioEncoder)) - { - return EnumHelper.GetDisplay((AudioEncoder)value); - } + if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) { return EnumHelper.GetDisplay((PresetPictureSettingsMode)value); @@ -188,10 +182,7 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetValue(value.ToString()); } - if (targetType == typeof(AudioEncoder) || value.GetType() == typeof(AudioEncoder)) - { - return EnumHelper.GetValue(value.ToString()); - } + if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) { return EnumHelper.GetValue(value.ToString()); diff --git a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs new file mode 100644 index 000000000..a6f29357f --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs @@ -0,0 +1,93 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Video Encoder Converter +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Video +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Functions; + using HandBrake.ApplicationServices.Model; + using HandBrake.ApplicationServices.Model.Encoding; + using HandBrake.Interop.Model.Encoding; + + /// + /// Video Encoder Converter + /// + public class VideoEncoderConverter : IMultiValueConverter + { + /// + /// Gets a list of Video encoders OR returns the string name of an encoder depending on the input. + /// + /// + /// The values. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// IEnumberable VideoEncoder or String encoder name. + /// + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Count() == 2) + { + List encoders = EnumHelper.GetEnumList().ToList(); + EncodeTask task = values[1] as EncodeTask; + + if (task != null && task.OutputFormat != OutputFormat.Mkv) + { + encoders.Remove(VideoEncoder.Theora); + } + + return EnumHelper.GetEnumDisplayValuesSubset(encoders); + } + + return EnumHelper.GetDisplay((VideoEncoder)values[0]); + } + + /// + /// Convert from a string name, to enum value. + /// + /// + /// The value. + /// + /// + /// The target types. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// Returns the video encoder enum item. + /// + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + string name = value as string; + if (!string.IsNullOrEmpty(name)) + { + return new object[] { EnumHelper.GetValue(name)}; + } + + return null; + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 8e952cbe8..c263e1552 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -111,7 +111,9 @@ Designer + + diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index 1936a9898..06bd20326 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -138,6 +138,22 @@ namespace HandBrakeWPF.ViewModels this.Task.AudioTracks.Remove(track); } + /// + /// Trigger a Notify Property Changed on the Task to force various UI elements to update. + /// + public void RefreshTask() + { + this.NotifyOfPropertyChange(() => this.Task); + + if (Task.OutputFormat == OutputFormat.Mp4) + { + foreach (AudioTrack track in this.Task.AudioTracks.Where(track => track.Encoder == AudioEncoder.ffflac || track.Encoder == AudioEncoder.Vorbis)) + { + track.Encoder = AudioEncoder.ffaac; + } + } + } + #endregion #region Implemented Interfaces diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IAudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IAudioViewModel.cs index e1d4328c6..6f3edca2a 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IAudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IAudioViewModel.cs @@ -14,5 +14,9 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// public interface IAudioViewModel : ITabInterface { + /// + /// Trigger a Notify Property Changed on the Task to force various UI elements to update. + /// + void RefreshTask(); } } diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IVideoViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IVideoViewModel.cs index d89e90ac6..d3b162501 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IVideoViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IVideoViewModel.cs @@ -14,5 +14,9 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// public interface IVideoViewModel : ITabInterface { + /// + /// Trigger a Notify Property Changed on the Task to force various UI elements to update. + /// + void RefreshTask(); } } diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 8a3f2eb60..6c5576442 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -689,9 +689,14 @@ namespace HandBrakeWPF.ViewModels set { this.selectedOutputFormat = value; + this.CurrentTask.OutputFormat = value; this.NotifyOfPropertyChange(() => SelectedOutputFormat); + this.NotifyOfPropertyChange(() => this.CurrentTask.OutputFormat); this.NotifyOfPropertyChange(() => IsMkv); this.SetExtension(string.Format(".{0}", this.selectedOutputFormat.ToString().ToLower())); // TODO, tidy up + + this.VideoViewModel.RefreshTask(); + this.AudioViewModel.RefreshTask(); } } @@ -1196,19 +1201,15 @@ namespace HandBrakeWPF.ViewModels { case 0: // Auto newExtension = this.CurrentTask.RequiresM4v ? ".m4v" : ".mp4"; - this.CurrentTask.OutputFormat = newExtension == ".m4v" ? OutputFormat.M4V : OutputFormat.Mp4; break; case 1: // MP4 newExtension = ".mp4"; - this.CurrentTask.OutputFormat = OutputFormat.Mp4; break; case 2: // M4v newExtension = ".m4v"; - this.CurrentTask.OutputFormat = OutputFormat.M4V; break; } - this.selectedOutputFormat = OutputFormat.Mp4; this.IsMkv = false; } @@ -1220,7 +1221,6 @@ namespace HandBrakeWPF.ViewModels this.CurrentTask.OptimizeMP4 = false; this.CurrentTask.IPod5GSupport = false; this.selectedOutputFormat = OutputFormat.Mkv; - this.CurrentTask.OutputFormat = OutputFormat.Mkv; } // Update The browse file extension display diff --git a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs index 6ca5618ed..bf7c76c55 100644 --- a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs @@ -508,6 +508,19 @@ namespace HandBrakeWPF.ViewModels //this.DisplayX264Options = encoder == VideoEncoder.X264; } + /// + /// Trigger a Notify Property Changed on the Task to force various UI elements to update. + /// + public void RefreshTask() + { + this.NotifyOfPropertyChange(() => this.Task); + + if (Task.OutputFormat == OutputFormat.Mp4 && this.SelectedVideoEncoder == VideoEncoder.Theora) + { + this.SelectedVideoEncoder = VideoEncoder.X264; + } + } + #endregion #region Advanced diff --git a/win/CS/HandBrakeWPF/Views/AudioView.xaml b/win/CS/HandBrakeWPF/Views/AudioView.xaml index ea112a750..15bf24113 100644 --- a/win/CS/HandBrakeWPF/Views/AudioView.xaml +++ b/win/CS/HandBrakeWPF/Views/AudioView.xaml @@ -15,6 +15,7 @@ + @@ -102,9 +103,21 @@ SelectedItem="{Binding ScannedTrack}"/> - + + + + + + + + + + + + + diff --git a/win/CS/HandBrakeWPF/Views/FiltersView.xaml.cs b/win/CS/HandBrakeWPF/Views/FiltersView.xaml.cs index 35e978b7f..826b1e9af 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Interaction logic for FiltersView.xaml +// +// -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Views { + using System.Windows.Controls; + /// /// Interaction logic for FiltersView.xaml /// public partial class FiltersView : UserControl { + /// + /// Initializes a new instance of the class. + /// public FiltersView() { InitializeComponent(); diff --git a/win/CS/HandBrakeWPF/Views/VideoView.xaml b/win/CS/HandBrakeWPF/Views/VideoView.xaml index 5f35886f0..b49ae924b 100644 --- a/win/CS/HandBrakeWPF/Views/VideoView.xaml +++ b/win/CS/HandBrakeWPF/Views/VideoView.xaml @@ -3,12 +3,14 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:Converters="clr-namespace:HandBrakeWPF.Converters" mc:Ignorable="d" > + xmlns:Converters="clr-namespace:HandBrakeWPF.Converters" + xmlns:Video="clr-namespace:HandBrakeWPF.Converters.Video" mc:Ignorable="d" > + @@ -30,8 +32,21 @@ - + + + + + + + + + + + + + + + -- cgit v1.2.3