diff options
author | sr55 <[email protected]> | 2012-05-19 21:02:08 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2012-05-19 21:02:08 +0000 |
commit | a8c98d2da676d507a0754ec191d53a1122a40220 (patch) | |
tree | ae847166896db64e8e7c1d78b1962f909bc19a6c /win/CS/HandBrakeWPF | |
parent | b5a8be6d070e651d475978e06459a1f565d855f5 (diff) |
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
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r-- | win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs | 95 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs | 15 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs | 93 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs | 16 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/Interfaces/IAudioViewModel.cs | 4 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/Interfaces/IVideoViewModel.cs | 4 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 10 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs | 13 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/AudioView.xaml | 19 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/FiltersView.xaml.cs | 26 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/VideoView.xaml | 21 |
12 files changed, 282 insertions, 36 deletions
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 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="AudioEncoderConverter.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Audio Encoder Converter
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+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;
+
+ /// <summary>
+ /// Audio Encoder Converter
+ /// </summary>
+ public class AudioEncoderConverter : IMultiValueConverter
+ {
+ /// <summary>
+ /// Gets a list of audio encoders OR returns the string name of an encoder depending on the input.
+ /// </summary>
+ /// <param name="values">
+ /// The values.
+ /// </param>
+ /// <param name="targetType">
+ /// The target type.
+ /// </param>
+ /// <param name="parameter">
+ /// The parameter.
+ /// </param>
+ /// <param name="culture">
+ /// The culture.
+ /// </param>
+ /// <returns>
+ /// IEnumberable AudioEncoder or String encoder name.
+ /// </returns>
+ 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<AudioEncoder> encoders = EnumHelper<AudioEncoder>.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<AudioEncoder>.GetEnumDisplayValuesSubset(encoders);
+ }
+
+ return EnumHelper<AudioEncoder>.GetDisplay((AudioEncoder)values[0]);
+ }
+
+ /// <summary>
+ /// Convert from a string name, to enum value.
+ /// </summary>
+ /// <param name="value">
+ /// The value.
+ /// </param>
+ /// <param name="targetTypes">
+ /// The target types.
+ /// </param>
+ /// <param name="parameter">
+ /// The parameter.
+ /// </param>
+ /// <param name="culture">
+ /// The culture.
+ /// </param>
+ /// <returns>
+ /// Returns the audio encoder enum item.
+ /// </returns>
+ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+ {
+ string name = value as string;
+ if (!string.IsNullOrEmpty(name))
+ {
+ return new object[] { EnumHelper<AudioEncoder>.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<Mixdown>.GetEnumDisplayValues(typeof(Mixdown));
}
- if (value is IEnumerable<AudioEncoder>)
- {
- return EnumHelper<AudioEncoder>.GetEnumDisplayValues(typeof(AudioEncoder));
- }
+
if (value is IEnumerable<PresetPictureSettingsMode>)
{
return EnumHelper<PresetPictureSettingsMode>.GetEnumDisplayValues(typeof(PresetPictureSettingsMode));
@@ -113,10 +110,7 @@ namespace HandBrakeWPF.Converters {
return EnumHelper<Mixdown>.GetDisplay((Mixdown)value);
}
- if (targetType == typeof(AudioEncoder) || value.GetType() == typeof(AudioEncoder))
- {
- return EnumHelper<AudioEncoder>.GetDisplay((AudioEncoder)value);
- }
+
if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode))
{
return EnumHelper<PresetPictureSettingsMode>.GetDisplay((PresetPictureSettingsMode)value);
@@ -188,10 +182,7 @@ namespace HandBrakeWPF.Converters {
return EnumHelper<Mixdown>.GetValue(value.ToString());
}
- if (targetType == typeof(AudioEncoder) || value.GetType() == typeof(AudioEncoder))
- {
- return EnumHelper<AudioEncoder>.GetValue(value.ToString());
- }
+
if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode))
{
return EnumHelper<PresetPictureSettingsMode>.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 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="VideoEncoderConverter.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Video Encoder Converter
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+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;
+
+ /// <summary>
+ /// Video Encoder Converter
+ /// </summary>
+ public class VideoEncoderConverter : IMultiValueConverter
+ {
+ /// <summary>
+ /// Gets a list of Video encoders OR returns the string name of an encoder depending on the input.
+ /// </summary>
+ /// <param name="values">
+ /// The values.
+ /// </param>
+ /// <param name="targetType">
+ /// The target type.
+ /// </param>
+ /// <param name="parameter">
+ /// The parameter.
+ /// </param>
+ /// <param name="culture">
+ /// The culture.
+ /// </param>
+ /// <returns>
+ /// IEnumberable VideoEncoder or String encoder name.
+ /// </returns>
+ public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (values.Count() == 2)
+ {
+ List<VideoEncoder> encoders = EnumHelper<VideoEncoder>.GetEnumList().ToList();
+ EncodeTask task = values[1] as EncodeTask;
+
+ if (task != null && task.OutputFormat != OutputFormat.Mkv)
+ {
+ encoders.Remove(VideoEncoder.Theora);
+ }
+
+ return EnumHelper<VideoEncoder>.GetEnumDisplayValuesSubset(encoders);
+ }
+
+ return EnumHelper<VideoEncoder>.GetDisplay((VideoEncoder)values[0]);
+ }
+
+ /// <summary>
+ /// Convert from a string name, to enum value.
+ /// </summary>
+ /// <param name="value">
+ /// The value.
+ /// </param>
+ /// <param name="targetTypes">
+ /// The target types.
+ /// </param>
+ /// <param name="parameter">
+ /// The parameter.
+ /// </param>
+ /// <param name="culture">
+ /// The culture.
+ /// </param>
+ /// <returns>
+ /// Returns the video encoder enum item.
+ /// </returns>
+ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+ {
+ string name = value as string;
+ if (!string.IsNullOrEmpty(name))
+ {
+ return new object[] { EnumHelper<VideoEncoder>.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 @@ <SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Converters\Audio\AudioBitrateConverter.cs" />
+ <Compile Include="Converters\Audio\AudioEncoderConverter.cs" />
<Compile Include="Converters\BooleanToHiddenVisibilityConverter.cs" />
+ <Compile Include="Converters\Video\VideoEncoderConverter.cs" />
<Compile Include="ViewModels\Interfaces\ITitleSpecificViewModel.cs" />
<Compile Include="ViewModels\TitleSpecificViewModel.cs" />
<Compile Include="Views\TitleSpecificView.xaml.cs">
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);
}
+ /// <summary>
+ /// Trigger a Notify Property Changed on the Task to force various UI elements to update.
+ /// </summary>
+ 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 /// </summary>
public interface IAudioViewModel : ITabInterface
{
+ /// <summary>
+ /// Trigger a Notify Property Changed on the Task to force various UI elements to update.
+ /// </summary>
+ 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 /// </summary>
public interface IVideoViewModel : ITabInterface
{
+ /// <summary>
+ /// Trigger a Notify Property Changed on the Task to force various UI elements to update.
+ /// </summary>
+ 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;
}
+ /// <summary>
+ /// Trigger a Notify Property Changed on the Task to force various UI elements to update.
+ /// </summary>
+ 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 @@ <Conveters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
<Conveters:BooleanToHiddenVisibilityConverter x:Key="boolToHiddenVisConverter" />
<Audio:AudioBitrateConverter x:Key="audioBitrateConverter" />
+ <Audio:AudioEncoderConverter x:Key="audioEncoderConverter" />
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
@@ -102,9 +103,21 @@ SelectedItem="{Binding ScannedTrack}"/>
<TextBlock Text="Codec" FontWeight="Bold" Grid.Column="2" VerticalAlignment="Center" />
- <ComboBox Width="100" Grid.Column="3" Margin="5,0,5,0" Height="22"
- ItemsSource="{Binding DataContext.AudioEncoders, Converter={StaticResource enumComboConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
- SelectedItem="{Binding Encoder, Converter={StaticResource enumComboConverter}}"/>
+ <ComboBox Width="100" Grid.Column="3" Margin="5,0,5,0" Height="22">
+ <ComboBox.SelectedItem>
+ <MultiBinding Converter="{StaticResource audioEncoderConverter}">
+ <Binding Path="Encoder" />
+ </MultiBinding>
+ </ComboBox.SelectedItem>
+ <ComboBox.ItemsSource>
+ <MultiBinding Converter="{StaticResource audioEncoderConverter}">
+ <Binding Path="DataContext.AudioEncoders"
+ RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
+ <Binding Path="DataContext.Task"
+ RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
+ </MultiBinding>
+ </ComboBox.ItemsSource>
+ </ComboBox>
<TextBlock Text="Bitrate" FontWeight="Bold" Grid.Column="4" VerticalAlignment="Center"
Visibility="{Binding IsPassthru, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
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;
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="FiltersView.xaml.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Interaction logic for FiltersView.xaml
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Views
{
+ using System.Windows.Controls;
+
/// <summary>
/// Interaction logic for FiltersView.xaml
/// </summary>
public partial class FiltersView : UserControl
{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="FiltersView"/> class.
+ /// </summary>
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" >
<UserControl.Resources>
<Converters:BooleanConverter x:Key="boolConverter" />
<Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
<Converters:EnumComboConverter x:Key="enumComboConverter" />
+ <Video:VideoEncoderConverter x:Key="videoEncoderConverter" />
</UserControl.Resources>
<Grid Margin="10,5,0,0">
@@ -30,8 +32,21 @@ <StackPanel Orientation="Horizontal" Margin="0,0,0,10" >
<TextBlock Text="Video Codec:" Width="100" />
- <ComboBox Width="120" ItemsSource="{Binding VideoEncoders, Converter={StaticResource enumComboConverter}, Mode=TwoWay}"
- SelectedItem="{Binding SelectedVideoEncoder, Converter={StaticResource enumComboConverter}, Mode=TwoWay}" />
+
+ <ComboBox Width="120">
+ <ComboBox.SelectedItem>
+ <MultiBinding Converter="{StaticResource videoEncoderConverter}">
+ <Binding Path="SelectedVideoEncoder" />
+ </MultiBinding>
+ </ComboBox.SelectedItem>
+ <ComboBox.ItemsSource>
+ <MultiBinding Converter="{StaticResource videoEncoderConverter}">
+ <Binding Path="VideoEncoders"/>
+ <Binding Path="Task" />
+ </MultiBinding>
+ </ComboBox.ItemsSource>
+ </ComboBox>
+
</StackPanel>
<StackPanel Orientation="Horizontal">
|