From 00d380f92e32e5dd56e3eb29acfddbe6db368263 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Mon, 17 Aug 2015 22:21:47 +0200 Subject: [PATCH 01/42] Added: Encoding quality slider user control. --- .../EncodingQualitySliderControl.xaml | 26 +++ .../EncodingQualitySliderControl.xaml.cs | 163 ++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 Application/FileConverter/Controls/EncodingQualitySliderControl.xaml create mode 100644 Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs diff --git a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml new file mode 100644 index 0000000..b3c8b87 --- /dev/null +++ b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + diff --git a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs new file mode 100644 index 0000000..592cf8f --- /dev/null +++ b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs @@ -0,0 +1,163 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.Controls +{ + using System; + using System.Windows; + using System.Windows.Controls; + using System.ComponentModel; + using System.Runtime.CompilerServices; + + /// + /// Interaction logic for EncodingQualitySliderControl.xaml + /// + public partial class EncodingQualitySliderControl : UserControl, INotifyPropertyChanged + { + public static readonly DependencyProperty EncodingModeProperty = DependencyProperty.Register( + "EncodingMode", + typeof(EncodingMode), + typeof(EncodingQualitySliderControl), + null); + + public static readonly DependencyProperty BitrateProperty = DependencyProperty.Register( + "Bitrate", + typeof(double), + typeof(EncodingQualitySliderControl), + null); + + public event PropertyChangedEventHandler PropertyChanged; + + [Category("Behavior")] + public event RoutedPropertyChangedEventHandler ValueChanged; + + public EncodingQualitySliderControl() + { + this.InitializeComponent(); + + (this.Content as FrameworkElement).DataContext = this; + + this.Bitrate = this.GetNearestTickValue(this.Bitrate); + + this.slider.ValueChanged += Slider_ValueChanged; + + DependencyPropertyDescriptor encodingModeDescriptor = DependencyPropertyDescriptor.FromProperty( + EncodingQualitySliderControl.EncodingModeProperty, + typeof(EncodingQualitySliderControl)); + + encodingModeDescriptor.AddValueChanged(this, this.EncodingModeValueChanged); + } + + public EncodingMode EncodingMode + { + get + { + return (EncodingMode)this.GetValue(EncodingQualitySliderControl.EncodingModeProperty); + } + + set + { + this.SetValueDependencyProperty(EncodingQualitySliderControl.EncodingModeProperty, value); + } + } + + public double Bitrate + { + get + { + return (double)this.GetValue(EncodingQualitySliderControl.BitrateProperty); + } + + set + { + //this.SetValue(EncodingQualitySliderControl.BitrateProperty, value); + this.SetValueDependencyProperty(EncodingQualitySliderControl.BitrateProperty, value); + } + } + + private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + this.ValueChanged?.Invoke(this, e); + } + + private void SetValueDependencyProperty(DependencyProperty dependencyProperty, object value, [CallerMemberName] string propertyName = null) + { + this.SetValue(dependencyProperty, value); + + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private void EncodingModeValueChanged(object sender, EventArgs eventArgs) + { + double previousValue = this.Bitrate; + + switch (this.EncodingMode) + { + case EncodingMode.VBR: + { + this.slider.Minimum = 65; + this.slider.Maximum = 245; + this.slider.SelectionStart = 115; + this.slider.SelectionEnd = 245; + this.slider.Ticks.Clear(); + this.slider.Ticks.Add(65); + this.slider.Ticks.Add(85); + this.slider.Ticks.Add(100); + this.slider.Ticks.Add(115); + this.slider.Ticks.Add(130); + this.slider.Ticks.Add(165); + this.slider.Ticks.Add(175); + this.slider.Ticks.Add(190); + this.slider.Ticks.Add(225); + this.slider.Ticks.Add(245); + break; + } + + case EncodingMode.CBR: + { + this.slider.Minimum = 8; + this.slider.Maximum = 320; + this.slider.SelectionStart = 128; + this.slider.SelectionEnd = 256; + this.slider.Ticks.Clear(); + this.slider.Ticks.Add(8); + this.slider.Ticks.Add(16); + this.slider.Ticks.Add(24); + this.slider.Ticks.Add(32); + this.slider.Ticks.Add(40); + this.slider.Ticks.Add(48); + this.slider.Ticks.Add(64); + this.slider.Ticks.Add(80); + this.slider.Ticks.Add(96); + this.slider.Ticks.Add(112); + this.slider.Ticks.Add(128); + this.slider.Ticks.Add(160); + this.slider.Ticks.Add(192); + this.slider.Ticks.Add(224); + this.slider.Ticks.Add(256); + this.slider.Ticks.Add(320); + break; + } + } + + this.Bitrate = this.GetNearestTickValue(previousValue); + } + + private double GetNearestTickValue(double value) + { + double minimumDifference = float.PositiveInfinity; + double nearestTick = value; + for (int index = 0; index < this.slider.Ticks.Count; index++) + { + double tick = this.slider.Ticks[index]; + double difference = System.Math.Abs(value - tick); + if (difference < minimumDifference) + { + minimumDifference = difference; + nearestTick = tick; + } + } + + return nearestTick; + } + } +} From f6547941bc79e88ccbcb724f7738810333379e99 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Mon, 17 Aug 2015 22:24:48 +0200 Subject: [PATCH 02/42] 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 @@ + - \ No newline at end of file + diff --git a/Application/FileConverter/FileConverter.sln.DotSettings b/Application/FileConverter/FileConverter.sln.DotSettings index 570b5eb..6c4d4f7 100644 --- a/Application/FileConverter/FileConverter.sln.DotSettings +++ b/Application/FileConverter/FileConverter.sln.DotSettings @@ -14,6 +14,8 @@ UseExplicitType UseExplicitType // <copyright file="$FILENAME$" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright> + CBR + VBR <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> diff --git a/Application/FileConverter/ValueConverters/BitrateToString.cs b/Application/FileConverter/ValueConverters/BitrateToString.cs index 4d8bf0c..213b843 100644 --- a/Application/FileConverter/ValueConverters/BitrateToString.cs +++ b/Application/FileConverter/ValueConverters/BitrateToString.cs @@ -1,4 +1,4 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.ValueConverters { diff --git a/Application/FileConverter/ValueConverters/ConversionSettingsToString.cs b/Application/FileConverter/ValueConverters/ConversionSettingsToString.cs index 8cf883f..4ed87db 100644 --- a/Application/FileConverter/ValueConverters/ConversionSettingsToString.cs +++ b/Application/FileConverter/ValueConverters/ConversionSettingsToString.cs @@ -1,4 +1,4 @@ -// License: http://www.gnu.org/licenses/gpl.html GPL version 3. +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.ValueConverters { diff --git a/Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs b/Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs index 65f34c0..572be61 100644 --- a/Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs +++ b/Application/FileConverter/ValueConverters/Generic/EqualsConverter.cs @@ -1,6 +1,5 @@ // License: http://www.gnu.org/licenses/gpl.html GPL version 3. - namespace FileConverter.ValueConverters.Generic { using System; diff --git a/Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs b/Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs index 1334b25..6647e28 100644 --- a/Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs +++ b/Application/FileConverter/ValueConverters/Generic/ObjectToValueType.cs @@ -6,7 +6,7 @@ namespace FileConverter.ValueConverters.Generic using System.Globalization; using System.Windows.Data; - public class ObjectToValueType: IValueConverter + public class ObjectToValueType : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { diff --git a/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs b/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs index 52e10ab..eded1f2 100644 --- a/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs +++ b/Application/FileConverter/ValueConverters/OutputTypeToVisibility.cs @@ -3,7 +3,6 @@ namespace FileConverter.ValueConverters { using System; - using System.Collections.Generic; using System.Globalization; using System.Windows.Data; @@ -21,13 +20,13 @@ namespace FileConverter.ValueConverters string referenceTypeName = parameter as string; if (string.IsNullOrEmpty(referenceTypeName)) { - return false; + return "Hidden"; } OutputType referenceType; - if (System.Enum.TryParse(referenceTypeName,out referenceType)) + if (!Enum.TryParse(referenceTypeName, out referenceType)) { - + return "Hidden"; } return outputType == referenceType ? "Visible" : "Hidden"; diff --git a/Application/FileConverter/Version.cs b/Application/FileConverter/Version.cs index 95f2a0c..585c3c5 100644 --- a/Application/FileConverter/Version.cs +++ b/Application/FileConverter/Version.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter { diff --git a/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs b/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs index d307a44..5e89bf6 100644 --- a/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs +++ b/Application/FileConverter/Windows/DiagnosticsWindow.xaml.cs @@ -1,19 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -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.Shapes; +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. namespace FileConverter.Windows { + using System.Windows; + /// /// Interaction logic for DiagnosticsWindow.xaml /// @@ -21,7 +11,7 @@ namespace FileConverter.Windows { public DiagnosticsWindow() { - InitializeComponent(); + this.InitializeComponent(); } } } diff --git a/Application/FileConverter/Windows/MainWindow.xaml.cs b/Application/FileConverter/Windows/MainWindow.xaml.cs index 4e356a0..612a01c 100644 --- a/Application/FileConverter/Windows/MainWindow.xaml.cs +++ b/Application/FileConverter/Windows/MainWindow.xaml.cs @@ -11,8 +11,6 @@ namespace FileConverter public partial class MainWindow : Window, INotifyPropertyChanged { - private bool verboseMode; - private DiagnosticsWindow diagnosticsWindow; private SettingsWindow settingsWindow; diff --git a/Application/FileConverter/XmlHelpers.cs b/Application/FileConverter/XmlHelpers.cs index 1f05e8a..fd40edd 100644 --- a/Application/FileConverter/XmlHelpers.cs +++ b/Application/FileConverter/XmlHelpers.cs @@ -1,75 +1,90 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Windows.Documents; -using System.Xml; -using System.Xml.Serialization; +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. -using FileConverter; - -public class XmlHelpers +namespace FileConverter { - public static void LoadFromFile(string root, string path, ref ICollection collection) + using System; + using System.Collections.Generic; + using System.IO; + using System.Xml; + using System.Xml.Serialization; + + public class XmlHelpers { - if (string.IsNullOrEmpty(path)) + public static void LoadFromFile(string root, string path, ref ICollection collection) { - throw new ArgumentNullException("path"); - } - - XmlRootAttribute xmlRoot = new XmlRootAttribute - { - ElementName = root - }; - - XmlSerializer serializer = new XmlSerializer(typeof(List), xmlRoot); - - try - { - using (StreamReader reader = new StreamReader(path)) - using (XmlReader xmlReader = XmlReader.Create(reader, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true })) + if (string.IsNullOrEmpty(path)) { - List elements = (List)serializer.Deserialize(xmlReader); - foreach (T element in elements) + throw new ArgumentNullException("path"); + } + + XmlRootAttribute xmlRoot = new XmlRootAttribute + { + ElementName = root + }; + + XmlSerializer serializer = new XmlSerializer(typeof(List), xmlRoot); + + try + { + using (StreamReader reader = new StreamReader(path)) { - collection.Add(element); + XmlReaderSettings xmlReaderSettings = new XmlReaderSettings + { + IgnoreWhitespace = true, IgnoreComments = true + }; + + using (XmlReader xmlReader = XmlReader.Create(reader, xmlReaderSettings)) + { + List elements = (List)serializer.Deserialize(xmlReader); + for (int index = 0; index < elements.Count; index++) + { + collection.Add(elements[index]); + } + } } } - } - catch (System.Exception exception) - { - Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message); - } - } - - public static void SaveToFile(string root, string path, ICollection objectsToSerialize) - { - if (string.IsNullOrEmpty(path)) - { - return; - } - - List list = new List(); - list.AddRange(objectsToSerialize); - - XmlRootAttribute xmlRoot = new XmlRootAttribute - { - ElementName = root - }; - - XmlSerializer serializer = new XmlSerializer(typeof(List), xmlRoot); - - try - { - using (StreamWriter writer = new StreamWriter(path)) - using (XmlWriter xmlWriter = XmlWriter.Create(writer, new XmlWriterSettings { Indent = true, IndentChars = " " })) + catch (System.Exception exception) { - serializer.Serialize(xmlWriter, list); + Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message); } } - catch (System.Exception exception) + + public static void SaveToFile(string root, string path, ICollection objectsToSerialize) { - Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message); + if (string.IsNullOrEmpty(path)) + { + return; + } + + List list = new List(); + list.AddRange(objectsToSerialize); + + XmlRootAttribute xmlRoot = new XmlRootAttribute + { + ElementName = root + }; + + XmlSerializer serializer = new XmlSerializer(typeof(List), xmlRoot); + + try + { + using (StreamWriter writer = new StreamWriter(path)) + { + XmlWriterSettings xmlWriterSettings = new XmlWriterSettings + { + Indent = true, IndentChars = " " + }; + + using (XmlWriter xmlWriter = XmlWriter.Create(writer, xmlWriterSettings)) + { + serializer.Serialize(xmlWriter, list); + } + } + } + catch (System.Exception exception) + { + Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message); + } } } -} +} \ No newline at end of file diff --git a/Application/FileConverterExtension/FileConverterExtension.cs b/Application/FileConverterExtension/FileConverterExtension.cs index 4bd42ee..cd10a47 100644 --- a/Application/FileConverterExtension/FileConverterExtension.cs +++ b/Application/FileConverterExtension/FileConverterExtension.cs @@ -16,6 +16,9 @@ namespace FileConverterExtension using SharpShell.Attributes; using SharpShell.SharpContextMenu; + /// + /// File converter context menu extension class. + /// [ComVisible(true), Guid("AF9B72B5-F4E4-44B0-A3D9-B55B748EFE90")] [COMServerAssociation(AssociationType.AllFiles)] public class FileConverterExtension : SharpContextMenu diff --git a/Application/FileConverterExtension/FileConverterExtension.csproj b/Application/FileConverterExtension/FileConverterExtension.csproj index 5ae715c..b325a0e 100644 --- a/Application/FileConverterExtension/FileConverterExtension.csproj +++ b/Application/FileConverterExtension/FileConverterExtension.csproj @@ -62,7 +62,9 @@ - + + true + True True @@ -83,11 +85,11 @@ - - \ No newline at end of file + diff --git a/Application/FileConverterExtension/PresetDefinition.cs b/Application/FileConverterExtension/PresetDefinition.cs index 5f6d9ae..823c5ec 100644 --- a/Application/FileConverterExtension/PresetDefinition.cs +++ b/Application/FileConverterExtension/PresetDefinition.cs @@ -4,9 +4,6 @@ namespace FileConverterExtension { public class PresetDefinition { - public bool Enabled; - public int ExtensionRefCount; - public PresetDefinition(string name) { this.Name = name; @@ -17,5 +14,17 @@ namespace FileConverterExtension get; private set; } + + public bool Enabled + { + get; + set; + } + + public int ExtensionRefCount + { + get; + set; + } } } \ No newline at end of file diff --git a/Application/FileConverterExtension/Settings.StyleCop b/Application/FileConverterExtension/Settings.StyleCop new file mode 100644 index 0000000..67f607a --- /dev/null +++ b/Application/FileConverterExtension/Settings.StyleCop @@ -0,0 +1,24 @@ + + + + + + + False + + + + + False + + + + + False + + + + + + + \ No newline at end of file diff --git a/Installer/Product.wxs b/Installer/Product.wxs index d8a36a9..067a21d 100644 --- a/Installer/Product.wxs +++ b/Installer/Product.wxs @@ -69,26 +69,26 @@ - + - + - + - + - + - + - + From 3e7c7a4a307b0f744b1cf4b41fca8562207df035 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Sat, 22 Aug 2015 15:55:30 +0200 Subject: [PATCH 11/42] Fixed: Close window don't terminate application. --- .../FileConverter/Windows/SettingsWindow.xaml | 3 ++- .../Windows/SettingsWindow.xaml.cs | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index 791f89c..b418de3 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -5,7 +5,8 @@ xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters" xmlns:generic="clr-namespace:FileConverter.ValueConverters.Generic" Height="500" Width="700" MinHeight="370" MinWidth="440" - WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon-16x16.ico"> + WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon-16x16.ico" + Closing="SettingsWindow_OnClosing"> diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml.cs b/Application/FileConverter/Windows/SettingsWindow.xaml.cs index be2a439..6895c07 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml.cs +++ b/Application/FileConverter/Windows/SettingsWindow.xaml.cs @@ -98,13 +98,7 @@ namespace FileConverter private void CloseButton_Click(object sender, RoutedEventArgs e) { - // Load previous preset in order to cancel changes. - Application application = Application.Current as Application; - application.Settings.Load(); - - this.Hide(); - - this.OnSettingsWindowHide?.Invoke(this, new EventArgs()); + this.HideSettingsWindow(); } private void SaveButton_Click(object sender, RoutedEventArgs e) @@ -171,5 +165,23 @@ namespace FileConverter this.SelectedPreset?.SetSettingsValue("Bitrate", bitrateValue.ToString("0")); } + + private void SettingsWindow_OnClosing(object sender, CancelEventArgs e) + { + e.Cancel = true; + + this.HideSettingsWindow(); + } + + private void HideSettingsWindow() + { + // Load previous preset in order to cancel changes. + Application application = Application.Current as Application; + application.Settings.Load(); + + this.Hide(); + + this.OnSettingsWindowHide?.Invoke(this, new EventArgs()); + } } } From 915f93defd2a8311d99464546ab4a9030810ec22 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Wed, 26 Aug 2015 08:52:32 +0200 Subject: [PATCH 12/42] Added: Ogg conversion settings. --- .../EncodingQualitySliderControl.xaml.cs | 27 ++++++++- .../ConversionJobs/ConversionJob_FFMPEG.cs | 4 +- .../ConversionPreset/ConversionPreset.cs | 47 ++++++++++++++-- Application/FileConverter/EncodingMode.cs | 6 +- .../FileConverter/FileConverter.csproj | 3 +- .../ConversionSettingsTemplateSelector.cs | 49 +++++++++++++++++ .../FileConverter/Windows/SettingsWindow.xaml | 55 ++++++++++++++----- .../Windows/SettingsWindow.xaml.cs | 4 +- 8 files changed, 167 insertions(+), 28 deletions(-) create mode 100644 Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs diff --git a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs index d4907e3..cc0e0d0 100644 --- a/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs +++ b/Application/FileConverter/Controls/EncodingQualitySliderControl.xaml.cs @@ -83,7 +83,7 @@ namespace FileConverter.Controls switch (encodingQualitySliderControl.EncodingMode) { - case EncodingMode.VBR: + case EncodingMode.Mp3VBR: { sliderControl.Minimum = 65; sliderControl.Maximum = 245; @@ -103,7 +103,7 @@ namespace FileConverter.Controls break; } - case EncodingMode.CBR: + case EncodingMode.Mp3CBR: { sliderControl.Minimum = 8; sliderControl.Maximum = 320; @@ -128,6 +128,29 @@ namespace FileConverter.Controls sliderControl.Ticks.Add(320); break; } + + case EncodingMode.OggVBR: + { + sliderControl.Minimum = 32; + sliderControl.Maximum = 500; + sliderControl.SelectionStart = 80; + sliderControl.SelectionEnd = 192; + sliderControl.Ticks.Clear(); + sliderControl.Ticks.Add(32); + sliderControl.Ticks.Add(48); + sliderControl.Ticks.Add(64); + sliderControl.Ticks.Add(80); + sliderControl.Ticks.Add(96); + sliderControl.Ticks.Add(112); + sliderControl.Ticks.Add(128); + sliderControl.Ticks.Add(160); + sliderControl.Ticks.Add(192); + sliderControl.Ticks.Add(224); + sliderControl.Ticks.Add(256); + sliderControl.Ticks.Add(320); + sliderControl.Ticks.Add(500); + break; + } } encodingQualitySliderControl.CoerceValue(EncodingQualitySliderControl.BitrateProperty); diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 40f3d21..a788538 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -58,11 +58,11 @@ namespace FileConverter.ConversionJobs int encodingQuality = this.ConversionPreset.GetSettingsValue("Bitrate"); switch (encodingMode) { - case EncodingMode.VBR: + case EncodingMode.Mp3VBR: encoderArgs = string.Format("-codec:a libmp3lame -q:a {0}", this.VBRBitrateToQualityIndex(encodingQuality)); break; - case EncodingMode.CBR: + case EncodingMode.Mp3CBR: encoderArgs = string.Format("-codec:a libmp3lame -b:a {0}k", encodingQuality); break; diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 4acee7b..fb71c69 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -55,12 +55,12 @@ namespace FileConverter { get { - return outputType; + return this.outputType; } set { - outputType = value; + this.outputType = value; this.InitializeDefaultSettings(outputType); this.OnPropertyChanged(); } @@ -71,12 +71,12 @@ namespace FileConverter { get { - return inputTypes; + return this.inputTypes; } set { - inputTypes = value; + this.inputTypes = value; this.OnPropertyChanged(); } } @@ -147,6 +147,11 @@ namespace FileConverter throw new ArgumentNullException("value"); } + if (!this.IsRelevantSetting(settingsKey)) + { + return; + } + if (!this.settings.ContainsKey(settingsKey)) { this.settings.Add(settingsKey, value); @@ -191,14 +196,46 @@ namespace FileConverter this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + private bool IsRelevantSetting(string settingsKey) + { + switch (this.OutputType) + { + case OutputType.Mp3: + switch (settingsKey) + { + case "Encoding": + case "Bitrate": + return true; + } + + break; + + case OutputType.Ogg: + switch (settingsKey) + { + case "Bitrate": + return true; + } + + break; + } + + return false; + } + private void InitializeDefaultSettings(OutputType outputType) { if (outputType == OutputType.Mp3) { - this.InitializeSettingsValue("Encoding", "VBR"); + this.InitializeSettingsValue("Encoding", EncodingMode.Mp3VBR.ToString()); this.InitializeSettingsValue("Bitrate", "190"); } + if (outputType == OutputType.Ogg) + { + this.InitializeSettingsValue("Bitrate", "160"); + } + this.OnPropertyChanged("Settings"); } diff --git a/Application/FileConverter/EncodingMode.cs b/Application/FileConverter/EncodingMode.cs index 0900832..ba84edd 100644 --- a/Application/FileConverter/EncodingMode.cs +++ b/Application/FileConverter/EncodingMode.cs @@ -4,7 +4,9 @@ namespace FileConverter { public enum EncodingMode { - VBR, - CBR, + Mp3VBR, + Mp3CBR, + + OggVBR, } } \ No newline at end of file diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 73bc59c..9e9e1aa 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -96,6 +96,7 @@ DiagnosticsWindow.xaml + SettingsWindow.xaml @@ -177,4 +178,4 @@ --> - + \ No newline at end of file diff --git a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs new file mode 100644 index 0000000..d423d47 --- /dev/null +++ b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs @@ -0,0 +1,49 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.Windows +{ + using System.Windows; + using System.Windows.Controls; + + public class ConversionSettingsTemplateSelector : DataTemplateSelector + { + public DataTemplate DefaultDataTemplate + { + get; + set; + } + + public DataTemplate Mp3SettingsDataTemplate + { + get; + set; + } + + public DataTemplate OggSettingsDataTemplate + { + get; + set; + } + + public override DataTemplate SelectTemplate(object item, DependencyObject container) + { + if (item == null) + { + return this.DefaultDataTemplate; + } + + OutputType outputType = (OutputType)item; + + switch (outputType) + { + case OutputType.Mp3: + return this.Mp3SettingsDataTemplate; + + case OutputType.Ogg: + return this.OggSettingsDataTemplate; + } + + return this.DefaultDataTemplate; + } + } +} diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index b418de3..156866c 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -4,6 +4,7 @@ xmlns:controls="clr-namespace:FileConverter.Controls" xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters" xmlns:generic="clr-namespace:FileConverter.ValueConverters.Generic" + xmlns:windows="clr-namespace:FileConverter.Windows" Height="500" Width="700" MinHeight="370" MinWidth="440" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon-16x16.ico" Closing="SettingsWindow_OnClosing"> @@ -45,6 +46,42 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -109,7 +146,7 @@