diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index 2f4a3f4..e4704f1 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -84,7 +84,7 @@ namespace FileConverter { this.cancelAutoExit = true; } - + private void Initialize() { // Load settigns. diff --git a/Application/FileConverter/ConversionPreset.cs b/Application/FileConverter/ConversionPreset.cs index 85899f3..6d397a2 100644 --- a/Application/FileConverter/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset.cs @@ -1,9 +1,9 @@ // License: http://www.gnu.org/licenses/gpl.html GPL version 3. -using System.Collections.Generic; - namespace FileConverter { + using System; + using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; @@ -16,10 +16,9 @@ namespace FileConverter public class ConversionPreset : INotifyPropertyChanged, IDataErrorInfo { private string name; - private OutputType outputType; - private List inputTypes; + private Dictionary settings = new Dictionary(); public ConversionPreset() { @@ -81,21 +80,35 @@ namespace FileConverter } } - [XmlIgnore] - public ConversionPreset.Setting[] Settings + [XmlElement] + public ConversionSetting[] Settings { - get; - set; - } + get + { + int index = 0; + ConversionSetting[] settings = new ConversionSetting[this.settings.Count]; + foreach (KeyValuePair keyValuePair in this.settings) + { + settings[index] = new ConversionSetting(keyValuePair); + index++; + } - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } + return settings; + } - public class Setting - { + set + { + this.settings.Clear(); + if (value != null) + { + for (int index = 0; index < value.Length; index++) + { + this.SetSettingsValue(value[index].Key, value[index].Value); + } + } + + this.OnPropertyChanged(); + } } public string this[string columnName] @@ -114,10 +127,70 @@ namespace FileConverter } } - private string Validate(string properyName) + public void SetSettingsValue(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); + } + + this.settings[settingsKey] = value; + + this.OnPropertyChanged("Settings"); + } + + public string GetSettingsValue(string settingsKey) + { + if (string.IsNullOrEmpty(settingsKey)) + { + throw new ArgumentNullException("key"); + } + + if (this.settings.ContainsKey(settingsKey)) + { + return this.settings[settingsKey]; + } + + return this.GetDefaultValue(settingsKey); + } + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private string GetDefaultValue(string settingsKey) + { + if (this.OutputType == OutputType.Mp3) + { + switch (settingsKey) + { + case "Encoding": + return "VBR"; + + case "Bitrate": + return "190"; + } + } + + return null; + } + + private string Validate(string propertyName) { // Return error message if there is an error, else return empty or null string. - switch (properyName) + switch (propertyName) { case "Name": { @@ -147,5 +220,28 @@ namespace FileConverter return string.Empty; } + + public struct ConversionSetting + { + public ConversionSetting(KeyValuePair keyValuePair) + { + this.Key = keyValuePair.Key; + this.Value = keyValuePair.Value; + } + + [XmlAttribute] + public string Key + { + get; + set; + } + + [XmlAttribute] + public string Value + { + get; + set; + } + } } } diff --git a/Application/FileConverter/EncodingMode.cs b/Application/FileConverter/EncodingMode.cs new file mode 100644 index 0000000..44b348d --- /dev/null +++ b/Application/FileConverter/EncodingMode.cs @@ -0,0 +1,10 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter +{ + public enum EncodingMode + { + VBR, + CBR, + } +} \ No newline at end of file diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 4e77add..340e9da 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -51,7 +51,9 @@ + + @@ -71,10 +73,22 @@ MSBuild:Compile Designer + + EncodingQualitySliderControl.xaml + + + + + + + + + + DiagnosticsWindow.xaml @@ -83,6 +97,10 @@ + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -143,6 +161,7 @@ +