From 43f5cb91cd2cd0553ab2bf3ef9bbb71e438acbd8 Mon Sep 17 00:00:00 2001 From: Tichau Date: Sun, 26 Apr 2015 22:28:54 +0200 Subject: [PATCH] Add conversion presets and settings window. --- Application/FileConverter/Application.xaml.cs | 25 +++++- Application/FileConverter/ConversionPreset.cs | 57 ++++++++++++ .../FileConverter/FileConverter.csproj | 16 +++- Application/FileConverter/MainWindow.xaml | 70 ++++++++------- Application/FileConverter/MainWindow.xaml.cs | 24 ++---- Application/FileConverter/Settings.cs | 20 +++++ Application/FileConverter/SettingsWindow.xaml | 86 +++++++++++++++++++ .../FileConverter/SettingsWindow.xaml.cs | 83 ++++++++++++++++++ .../ApplicationVersionToApplicationName.cs | 28 ++++++ .../ConversionStateToBrush.cs | 0 .../ValueConverters/InputTypesToBool.cs | 34 ++++++++ 11 files changed, 388 insertions(+), 55 deletions(-) create mode 100644 Application/FileConverter/ConversionPreset.cs create mode 100644 Application/FileConverter/Settings.cs create mode 100644 Application/FileConverter/SettingsWindow.xaml create mode 100644 Application/FileConverter/SettingsWindow.xaml.cs create mode 100644 Application/FileConverter/ValueConverters/ApplicationVersionToApplicationName.cs rename Application/FileConverter/{ => ValueConverters}/ConversionStateToBrush.cs (100%) create mode 100644 Application/FileConverter/ValueConverters/InputTypesToBool.cs diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index ff8062d..857e0b8 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -18,12 +18,11 @@ namespace FileConverter using System; using System.Collections.Generic; using System.Collections.ObjectModel; - using System.Diagnostics.CodeAnalysis; using System.Threading; public partial class Application : System.Windows.Application { - public static readonly Version Version = new Version() + private static readonly Version Version = new Version() { Major = 0, Minor = 1, @@ -36,6 +35,8 @@ namespace FileConverter public Application() { + this.ConvertionJobs = this.conversionJobs.AsReadOnly(); + this.Initialize(); if (this.initialized) @@ -45,12 +46,26 @@ namespace FileConverter } } + public static Version ApplicationVersion + { + get + { + return Application.Version; + } + } + public ReadOnlyCollection ConvertionJobs { get; private set; } + public Settings Settings + { + get; + private set; + } + public bool Verbose { get; @@ -59,8 +74,12 @@ namespace FileConverter private void Initialize() { - this.ConvertionJobs = this.conversionJobs.AsReadOnly(); + // Load settigns. + Diagnostics.Log("Retrieve arguments..."); + this.Settings = new Settings(); + this.Settings.Load(); + // Retrieve arguments. Diagnostics.Log("Retrieve arguments..."); string[] args = Environment.GetCommandLineArgs(); diff --git a/Application/FileConverter/ConversionPreset.cs b/Application/FileConverter/ConversionPreset.cs new file mode 100644 index 0000000..1322df0 --- /dev/null +++ b/Application/FileConverter/ConversionPreset.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FileConverter +{ + public class ConversionPreset + { + public ConversionPreset() + { + this.Name = "New Preset"; + } + + public ConversionPreset(string name, OutputType outputType, string[] inputTypes) + { + this.Name = name; + this.OutputType = outputType; + this.InputTypes = new List(); + this.InputTypes.AddRange(inputTypes); + } + + [System.Xml.Serialization.XmlAttribute] + public string Name + { + get; + set; + } + + [System.Xml.Serialization.XmlAttribute] + public OutputType OutputType + { + get; + set; + } + + [System.Xml.Serialization.XmlElement] + public List InputTypes + { + get; + private set; + } + + [System.Xml.Serialization.XmlElement] + public Setting[] Settings + { + get; + private set; + } + + public class Setting + { + + } + } +} diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 00e1396..4e1cf3b 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -71,6 +71,13 @@ MSBuild:Compile Designer + + + + + + SettingsWindow.xaml + MSBuild:Compile @@ -80,13 +87,17 @@ Application.xaml Code - + MainWindow.xaml Code + + Designer + MSBuild:Compile + @@ -120,6 +131,9 @@ + + + + + + + + + + + + + + + + + + diff --git a/Application/FileConverter/SettingsWindow.xaml.cs b/Application/FileConverter/SettingsWindow.xaml.cs new file mode 100644 index 0000000..7d097fd --- /dev/null +++ b/Application/FileConverter/SettingsWindow.xaml.cs @@ -0,0 +1,83 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter +{ + using System; + using System.Runtime.CompilerServices; + using System.Windows; + using System.ComponentModel; + using System.Windows.Controls; + + using FileConverter.Annotations; + + /// + /// Interaction logic for Settings.xaml + /// + public partial class SettingsWindow : Window, INotifyPropertyChanged + { + private ConversionPreset selectedPreset; + + public SettingsWindow() + { + this.InitializeComponent(); + + Application application = Application.Current as Application; + this.PresetList.ItemsSource = application.Settings.conversionPresets; + + OutputType[] outputTypes = new[] + { + OutputType.Flac, + OutputType.Mp3, + OutputType.Ogg, + OutputType.Wav, + }; + + this.OutputFormats.ItemsSource = outputTypes; + } + + public event PropertyChangedEventHandler PropertyChanged; + + public ConversionPreset SelectedPreset + { + get + { + return this.selectedPreset; + } + + set + { + this.selectedPreset = value; + this.OnPropertyChanged(); + } + } + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChangedEventHandler handler = this.PropertyChanged; + if (handler != null) + { + handler(this, new PropertyChangedEventArgs(propertyName)); + } + } + + private void ToggleButton_OnChecked(object sender, RoutedEventArgs e) + { + CheckBox checkBox = sender as System.Windows.Controls.CheckBox; + string inputFormat = checkBox.Content as string; + + if (!this.selectedPreset.InputTypes.Contains(inputFormat)) + { + this.selectedPreset.InputTypes.Add(inputFormat); + } + } + + private void ToggleButton_OnUnchecked(object sender, RoutedEventArgs e) + { + CheckBox checkBox = sender as System.Windows.Controls.CheckBox; + string inputFormat = checkBox.Content as string; + + this.selectedPreset.InputTypes.Remove(inputFormat); + } + } +} diff --git a/Application/FileConverter/ValueConverters/ApplicationVersionToApplicationName.cs b/Application/FileConverter/ValueConverters/ApplicationVersionToApplicationName.cs new file mode 100644 index 0000000..25a5715 --- /dev/null +++ b/Application/FileConverter/ValueConverters/ApplicationVersionToApplicationName.cs @@ -0,0 +1,28 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter +{ + using System; + using System.Globalization; + using System.Windows.Data; + + public class ApplicationVersionToApplicationName : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (!(value is Version)) + { + return "File Converter"; + } + + Version version = (Version)value; + + return string.Format("File Converter v{0}", version.ToString()); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Application/FileConverter/ConversionStateToBrush.cs b/Application/FileConverter/ValueConverters/ConversionStateToBrush.cs similarity index 100% rename from Application/FileConverter/ConversionStateToBrush.cs rename to Application/FileConverter/ValueConverters/ConversionStateToBrush.cs diff --git a/Application/FileConverter/ValueConverters/InputTypesToBool.cs b/Application/FileConverter/ValueConverters/InputTypesToBool.cs new file mode 100644 index 0000000..b75dcd7 --- /dev/null +++ b/Application/FileConverter/ValueConverters/InputTypesToBool.cs @@ -0,0 +1,34 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Windows.Data; + + public class InputTypesToBool : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + List intputTypes = value as List; + if (intputTypes == null) + { + throw new ArgumentException("The value must be an list of string."); + } + + string referenceTypeName = parameter as string; + if (string.IsNullOrEmpty(referenceTypeName)) + { + return false; + } + + return intputTypes.Contains(referenceTypeName); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +}