From f6547941bc79e88ccbcb724f7738810333379e99 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Mon, 17 Aug 2015 22:24:48 +0200 Subject: [PATCH] Added: Quality slider for mp3 output type. - Add quality slider. - Fixed: application now don't quit when settings window lost focus. - New generic converters. --- Application/FileConverter/Application.xaml.cs | 2 +- Application/FileConverter/ConversionPreset.cs | 132 +++++++++++++++--- Application/FileConverter/EncodingMode.cs | 10 ++ .../FileConverter/FileConverter.csproj | 19 +++ .../FileConverter.sln.DotSettings | 1 + Application/FileConverter/Settings.cs | 4 +- .../ApplicationVersionToApplicationName.cs | 2 +- .../ValueConverters/BitrateToString.cs | 28 ++++ .../ConversionSettingsToString.cs | 46 ++++++ .../ValueConverters/ConversionStateToBrush.cs | 2 +- .../Generic/BoolToVisibility.cs | 28 ++++ .../Generic/EqualsConverter.cs | 27 ++++ .../Generic/ObjectToValueType.cs | 38 +++++ .../ValueConverters/Generic/StringToEnum.cs | 40 ++++++ .../Generic/ValueConverterGroup.cs | 41 ++++++ .../ValueConverters/InputTypesToBool.cs | 2 +- .../ValueConverters/OutputTypeToVisibility.cs | 41 ++++++ .../FileConverter/Windows/MainWindow.xaml | 6 +- .../FileConverter/Windows/MainWindow.xaml.cs | 4 +- .../FileConverter/Windows/SettingsWindow.xaml | 75 +++++++--- .../Windows/SettingsWindow.xaml.cs | 31 ++++ 21 files changed, 532 insertions(+), 47 deletions(-) create mode 100644 Application/FileConverter/EncodingMode.cs create mode 100644 Application/FileConverter/ValueConverters/BitrateToString.cs create mode 100644 Application/FileConverter/ValueConverters/ConversionSettingsToString.cs create mode 100644 Application/FileConverter/ValueConverters/Generic/BoolToVisibility.cs create mode 100644 Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs create mode 100644 Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs create mode 100644 Application/FileConverter/ValueConverters/Generic/StringToEnum.cs create mode 100644 Application/FileConverter/ValueConverters/Generic/ValueConverterGroup.cs create mode 100644 Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs 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 @@ +