mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-20 17:42:20 +01:00
Fixed: Conversion settings binding (for encoding type)
This commit is contained in:
1 parent
ae3328b029
commit
a3a930d44c
5 files changed
+69
-25
No files matched your search
@@ -18,7 +18,7 @@ namespace FileConverter
|
||||
private string name;
|
||||
private OutputType outputType;
|
||||
private List<string> inputTypes;
|
||||
private Dictionary<string, string> settings = new Dictionary<string, string>();
|
||||
private ConversionSettings settings = new ConversionSettings();
|
||||
|
||||
public ConversionPreset()
|
||||
{
|
||||
@@ -61,6 +61,7 @@ namespace FileConverter
|
||||
set
|
||||
{
|
||||
outputType = value;
|
||||
this.InitializeDefaultSettings(outputType);
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
@@ -80,8 +81,8 @@ namespace FileConverter
|
||||
}
|
||||
}
|
||||
|
||||
[XmlElement]
|
||||
public ConversionSetting[] Settings
|
||||
[XmlElement("Settings")]
|
||||
public ConversionSetting[] XmlSerializableSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -98,7 +99,6 @@ namespace FileConverter
|
||||
|
||||
set
|
||||
{
|
||||
this.settings.Clear();
|
||||
if (value != null)
|
||||
{
|
||||
for (int index = 0; index < value.Length; index++)
|
||||
@@ -107,7 +107,15 @@ namespace FileConverter
|
||||
}
|
||||
}
|
||||
|
||||
this.OnPropertyChanged();
|
||||
this.OnPropertyChanged("Settings");
|
||||
}
|
||||
}
|
||||
|
||||
public IConversionSettings Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.settings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +169,7 @@ namespace FileConverter
|
||||
return this.settings[settingsKey];
|
||||
}
|
||||
|
||||
return this.GetDefaultValue(settingsKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetSettingsValue<T>(string settingsKey)
|
||||
@@ -183,21 +191,33 @@ namespace FileConverter
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private string GetDefaultValue(string settingsKey)
|
||||
private void InitializeDefaultSettings(OutputType outputType)
|
||||
{
|
||||
if (this.OutputType == OutputType.Mp3)
|
||||
if (outputType == OutputType.Mp3)
|
||||
{
|
||||
switch (settingsKey)
|
||||
{
|
||||
case "Encoding":
|
||||
return "VBR";
|
||||
|
||||
case "Bitrate":
|
||||
return "190";
|
||||
}
|
||||
this.InitializeSettingsValue("Encoding", "VBR");
|
||||
this.InitializeSettingsValue("Bitrate", "190");
|
||||
}
|
||||
|
||||
return null;
|
||||
this.OnPropertyChanged("Settings");
|
||||
}
|
||||
|
||||
private void InitializeSettingsValue(string settingsKey, string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(settingsKey))
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
|
||||
if (!this.settings.ContainsKey(settingsKey))
|
||||
{
|
||||
this.settings.Add(settingsKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string Validate(string propertyName)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
public interface IConversionSettings : IReadOnlyDictionary<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
public class ConversionSettings : Dictionary<string, string>, IConversionSettings
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@
|
||||
</Compile>
|
||||
<Compile Include="ConversionJobs\ConversionJobFactory.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_FFMPEG.cs" />
|
||||
<Compile Include="ConversionSettings.cs" />
|
||||
<Compile Include="EncodingMode.cs" />
|
||||
<Compile Include="ValueConverters\ApplicationVersionToApplicationName.cs" />
|
||||
<Compile Include="ConversionPreset.cs" />
|
||||
|
||||
@@ -15,12 +15,12 @@ namespace FileConverter.ValueConverters
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(value is ConversionPreset))
|
||||
if (!(value is IConversionSettings))
|
||||
{
|
||||
throw new ArgumentException("The value must be a conversion preset array.");
|
||||
}
|
||||
|
||||
ConversionPreset preset = (ConversionPreset)value;
|
||||
IConversionSettings settings = (IConversionSettings)value;
|
||||
|
||||
string parameterString = parameter as string;
|
||||
if (parameterString == null)
|
||||
@@ -29,13 +29,24 @@ namespace FileConverter.ValueConverters
|
||||
}
|
||||
|
||||
string[] parameters = parameterString.Split(',');
|
||||
if (parameters.Length != 1)
|
||||
if (parameters.Length < 1 || parameters.Length > 2)
|
||||
{
|
||||
throw new ArgumentException("The parameter format must be 'SettingsKey'.");
|
||||
throw new ArgumentException("The parameter format must be 'SettingsKey[,DefaultValue]'.");
|
||||
}
|
||||
|
||||
string key = parameters[0];
|
||||
return preset.GetSettingsValue(key);
|
||||
string setting;
|
||||
if (settings.TryGetValue(key, out setting))
|
||||
{
|
||||
return setting;
|
||||
}
|
||||
|
||||
if (parameters.Length >= 2)
|
||||
{
|
||||
return parameters[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
|
||||
@@ -134,12 +134,12 @@
|
||||
<StackPanel Margin="0,5,0,5" Visibility="{Binding SelectedPreset.OutputType, Converter={StaticResource OutputTypeToVisibility}, ConverterParameter='Mp3', ElementName=window, Mode=OneWay}">
|
||||
<DockPanel>
|
||||
<Label Content="Encoding :" />
|
||||
<RadioButton Name="VBRradioButton" Content="VBR" ToolTip="Variable bitrate encoding" Margin="5" Checked="EncodingTypeRadio_Checked" IsChecked="{Binding SelectedPreset, ConverterParameter=Encoding|VBR, Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=OneWay}" />
|
||||
<RadioButton Name="CBRradioButton" Content="CBR" ToolTip="Constant bitrate encoding" Margin="5" Checked="EncodingTypeRadio_Checked" IsChecked="{Binding SelectedPreset, ConverterParameter=Encoding|CBR, Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=OneWay}"/>
|
||||
<RadioButton Name="VBRradioButton" Content="VBR" ToolTip="Variable bitrate encoding" Margin="5" Checked="EncodingTypeRadio_Checked" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter='Encoding|VBR', Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=OneWay}" />
|
||||
<RadioButton Name="CBRradioButton" Content="CBR" ToolTip="Constant bitrate encoding" Margin="5" Checked="EncodingTypeRadio_Checked" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter='Encoding|CBR', Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=OneWay}"/>
|
||||
</DockPanel>
|
||||
<DockPanel>
|
||||
<Label Content="Quality :" />
|
||||
<controls:EncodingQualitySliderControl x:Name="EncodingQualitySlider" EncodingMode="{Binding SelectedPreset, Converter={StaticResource ConversionSettingsToEnum}, ConverterParameter='Encoding|FileConverter.EncodingMode', ElementName=window, Mode=OneWay}" Bitrate="{Binding SelectedPreset, Converter={StaticResource ConversionSettingsToValueType}, ConverterParameter='Bitrate|System.Double', ElementName=window, Mode=OneWay}" ValueChanged="EncodingQualitySlider_ValueChanged"/>
|
||||
<controls:EncodingQualitySliderControl x:Name="EncodingQualitySlider" EncodingMode="{Binding SelectedPreset.Settings, ConverterParameter='Encoding|FileConverter.EncodingMode', Converter={StaticResource ConversionSettingsToEnum}, ElementName=window, Mode=OneWay, TargetNullValue=VBR}" Bitrate="{Binding SelectedPreset.Settings, ConverterParameter='Bitrate|System.Double', Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=OneWay, TargetNullValue=190}" ValueChanged="EncodingQualitySlider_ValueChanged"/>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
Reference in new issue
Block a user