mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-20 09:32:54 +01:00
Added: Quality slider for mp3 output type.
- Add quality slider. - Fixed: application now don't quit when settings window lost focus. - New generic converters.
This commit is contained in:
1 parent
00d380f92e
commit
f6547941bc
21 files changed
+532
-47
No files matched your search
@@ -84,7 +84,7 @@ namespace FileConverter
|
||||
{
|
||||
this.cancelAutoExit = true;
|
||||
}
|
||||
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
// Load settigns.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// <copyright file="FileConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
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<string> inputTypes;
|
||||
private Dictionary<string, string> settings = new Dictionary<string, string>();
|
||||
|
||||
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<string, string> 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<string, string> keyValuePair)
|
||||
{
|
||||
this.Key = keyValuePair.Key;
|
||||
this.Value = keyValuePair.Value;
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public string Key
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public string Value
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// <copyright file="Mode.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
public enum EncodingMode
|
||||
{
|
||||
VBR,
|
||||
CBR,
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,9 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Printing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -71,10 +73,22 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Controls\EncodingQualitySliderControl.xaml.cs">
|
||||
<DependentUpon>EncodingQualitySliderControl.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="EncodingMode.cs" />
|
||||
<Compile Include="ValueConverters\ApplicationVersionToApplicationName.cs" />
|
||||
<Compile Include="ConversionPreset.cs" />
|
||||
<Compile Include="ValueConverters\BitrateToString.cs" />
|
||||
<Compile Include="ValueConverters\Generic\BoolToVisibility.cs" />
|
||||
<Compile Include="ValueConverters\ConversionSettingsToString.cs" />
|
||||
<Compile Include="ValueConverters\Generic\EqualsConverter.cs" />
|
||||
<Compile Include="ValueConverters\Generic\ObjectToValueType.cs" />
|
||||
<Compile Include="ValueConverters\InputTypesToBool.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="ValueConverters\OutputTypeToVisibility.cs" />
|
||||
<Compile Include="ValueConverters\Generic\StringToEnum.cs" />
|
||||
<Compile Include="ValueConverters\Generic\ValueConverterGroup.cs" />
|
||||
<Compile Include="Windows\DiagnosticsWindow.xaml.cs">
|
||||
<DependentUpon>DiagnosticsWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -83,6 +97,10 @@
|
||||
</Compile>
|
||||
<Compile Include="Version.cs" />
|
||||
<Compile Include="XmlHelpers.cs" />
|
||||
<Page Include="Controls\EncodingQualitySliderControl.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Windows\DiagnosticsWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
@@ -143,6 +161,7 @@
|
||||
<Resource Include="Resources\ApplicationIcon-16x16.ico" />
|
||||
<Resource Include="Resources\ApplicationIcon-256x256.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1601/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1602/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SuggestUseVarKeywordEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedMember_002ELocal/@EntryIndexedValue">HINT</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ABSTRACT_ACCESSORHOLDER_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace FileConverter
|
||||
{
|
||||
registryKey.DeleteSubKey(subKeyNames[index]);
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show("Can't apply settings in registry (ErrorCode=2).", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return false;
|
||||
@@ -352,7 +352,7 @@ namespace FileConverter
|
||||
process.Start();
|
||||
process.WaitForExit();
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show("Can't apply settings in registry because the application has no administrator privileges.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// <copyright file="ApplicationVersionToApplicationName.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
namespace FileConverter.ValueConverters
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// <copyright file="InputTypesToBool.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class BitrateToString : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is double))
|
||||
{
|
||||
throw new ArgumentException("The value must be a double value.");
|
||||
}
|
||||
|
||||
double bitrate = (double)value;
|
||||
|
||||
return string.Format("{0} kbit/s", bitrate.ToString("0"));
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// <copyright file="InputTypesToBool.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class ConversionSettingsToString : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(value is ConversionPreset))
|
||||
{
|
||||
throw new ArgumentException("The value must be a conversion preset array.");
|
||||
}
|
||||
|
||||
ConversionPreset preset = (ConversionPreset)value;
|
||||
|
||||
string parameterString = parameter as string;
|
||||
if (parameterString == null)
|
||||
{
|
||||
throw new ArgumentException("The parameter must be a string value.");
|
||||
}
|
||||
|
||||
string[] parameters = parameterString.Split(',');
|
||||
if (parameters.Length != 1)
|
||||
{
|
||||
throw new ArgumentException("The parameter format must be 'SettingsKey'.");
|
||||
}
|
||||
|
||||
string key = parameters[0];
|
||||
return preset.GetSettingsValue(key);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// <copyright file="ConversionStateToBrush.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
namespace FileConverter.ValueConverters
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// <copyright file="BoolToVisibility.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters.Generic
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class BoolToVisibility : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is bool))
|
||||
{
|
||||
throw new ArgumentException("The value must be a boolean.");
|
||||
}
|
||||
|
||||
bool booleanValue = (bool)value;
|
||||
|
||||
return booleanValue ? "Visible" : "Hidden";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// <copyright file="EqualsConverter.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
|
||||
namespace FileConverter.ValueConverters.Generic
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class EqualsConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return parameter == null;
|
||||
}
|
||||
|
||||
return value.Equals(parameter);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// <copyright file="ObjectToValueType.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters.Generic
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class ObjectToValueType: IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string typeName = parameter as string;
|
||||
if (typeName == null)
|
||||
{
|
||||
throw new ArgumentNullException("parameter", "The parameter must contains a convertible type.");
|
||||
}
|
||||
|
||||
Type type = Type.GetType(typeName);
|
||||
if (type == null)
|
||||
{
|
||||
throw new Exception("Invalid enum type " + typeName + ".");
|
||||
}
|
||||
|
||||
return System.Convert.ChangeType(value, type);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// <copyright file="StringToEnum.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters.Generic
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class StringToEnum : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
string stringValue = value as string;
|
||||
if (value == null)
|
||||
{
|
||||
// TODO default value ?
|
||||
return null;
|
||||
}
|
||||
|
||||
string typeName = parameter as string;
|
||||
if (typeName == null)
|
||||
{
|
||||
throw new ArgumentNullException("parameter", "The parameter must contains the enum type.");
|
||||
}
|
||||
|
||||
Type enumType = Type.GetType(typeName);
|
||||
if (enumType == null)
|
||||
{
|
||||
throw new Exception("Invalid enum type " + typeName + ".");
|
||||
}
|
||||
|
||||
return Enum.Parse(enumType, stringValue);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// <copyright file="ValueConverterGroup.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters.Generic
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class ValueConverterGroup : List<IValueConverter>, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
string parameterString = parameter as string;
|
||||
if (parameterString == null)
|
||||
{
|
||||
throw new ArgumentException("The parameter must be a string value.");
|
||||
}
|
||||
|
||||
string[] parameters = parameterString.Split('|');
|
||||
if (parameters.Length != this.Count)
|
||||
{
|
||||
throw new ArgumentException("The parameter format must be 'Converter1Parameters|Converter2Parameters|...'.");
|
||||
}
|
||||
|
||||
object result = value;
|
||||
for (int index = 0; index < this.Count; index++)
|
||||
{
|
||||
IValueConverter converter = this[index];
|
||||
result = converter.Convert(result, targetType, parameters[index], culture);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// <copyright file="InputTypesToBool.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
namespace FileConverter.ValueConverters
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// <copyright file="OutputTypeToVisibility.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.ValueConverters
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
public class OutputTypeToVisibility : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is OutputType))
|
||||
{
|
||||
throw new ArgumentException("The value must be an output type enum value.");
|
||||
}
|
||||
|
||||
OutputType outputType = (OutputType)value;
|
||||
|
||||
string referenceTypeName = parameter as string;
|
||||
if (string.IsNullOrEmpty(referenceTypeName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OutputType referenceType;
|
||||
if (System.Enum.TryParse<OutputType>(referenceTypeName,out referenceType))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return outputType == referenceType ? "Visible" : "Hidden";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,11 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="FileConverter.MainWindow"
|
||||
xmlns:local="clr-namespace:FileConverter"
|
||||
xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters"
|
||||
x:Name="FileConverterMainWindow" Height="500" Width="950" MinHeight="250" MinWidth="450" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon-16x16.ico">
|
||||
<Window.Resources>
|
||||
<local:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<local:ConversionStateToBrush x:Key="ConversionStateToColor" />
|
||||
<valueConverters:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
<valueConverters:ConversionStateToBrush x:Key="ConversionStateToColor" />
|
||||
</Window.Resources>
|
||||
<Window.Title>
|
||||
<Binding Converter="{StaticResource ApplicationVersionToApplicationName}" Mode="OneWay" Path="(local:Application.ApplicationVersion)"/>
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace FileConverter
|
||||
this.Hide();
|
||||
|
||||
this.ShowSettingsWindow();
|
||||
this.settingsWindow.Deactivated += this.SettingsWindow_Closed;
|
||||
this.settingsWindow.OnSettingsWindowHide += this.SettingsWindow_Closed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace FileConverter
|
||||
|
||||
private void SettingsWindow_Closed(object sender, System.EventArgs e)
|
||||
{
|
||||
settingsWindow.Deactivated -= this.SettingsWindow_Closed;
|
||||
settingsWindow.OnSettingsWindowHide -= this.SettingsWindow_Closed;
|
||||
this.Close();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,31 @@
|
||||
<Window x:Name="window" x:Class="FileConverter.SettingsWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:FileConverter"
|
||||
Height="370" Width="520" MinHeight="370" MinWidth="440"
|
||||
xmlns:controls="clr-namespace:FileConverter.Controls"
|
||||
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">
|
||||
<Window.Resources>
|
||||
<local:InputTypesToBool x:Key="InputTypesToBool"/>
|
||||
<local:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
<generic:BoolToVisibility x:Key="BoolToVisibility"/>
|
||||
<valueConverters:InputTypesToBool x:Key="InputTypesToBool"/>
|
||||
<valueConverters:OutputTypeToVisibility x:Key="OutputTypeToVisibility"/>
|
||||
<valueConverters:ApplicationVersionToApplicationName x:Key="ApplicationVersionToApplicationName"/>
|
||||
|
||||
<generic:ValueConverterGroup x:Key="ConversionSettingsToEnum">
|
||||
<valueConverters:ConversionSettingsToString/>
|
||||
<generic:StringToEnum/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
<generic:ValueConverterGroup x:Key="ConversionSettingsEquals">
|
||||
<valueConverters:ConversionSettingsToString/>
|
||||
<generic:EqualsConverter/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
<generic:ValueConverterGroup x:Key="ConversionSettingsToValueType">
|
||||
<valueConverters:ConversionSettingsToString/>
|
||||
<generic:ObjectToValueType/>
|
||||
</generic:ValueConverterGroup>
|
||||
|
||||
<Style TargetType="{x:Type TextBox}">
|
||||
<Setter Property="Validation.ErrorTemplate">
|
||||
@@ -13,10 +33,10 @@
|
||||
<ControlTemplate>
|
||||
<DockPanel LastChildFill="true">
|
||||
<Border Background="#F44336" DockPanel.Dock="right" Margin="5,0,0,0" Width="20" Height="20" CornerRadius="10"
|
||||
ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">
|
||||
ToolTip="{Binding AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=customAdorner}">
|
||||
<TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="white"/>
|
||||
</Border>
|
||||
<AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center" >
|
||||
<AdornedElementPlaceholder x:Name="customAdorner" VerticalAlignment="Center" >
|
||||
<Border BorderBrush="#F44336" BorderThickness="1" />
|
||||
</AdornedElementPlaceholder>
|
||||
</DockPanel>
|
||||
@@ -29,11 +49,11 @@
|
||||
<Binding Converter="{StaticResource ApplicationVersionToApplicationName}" Mode="OneWay" Path="(local:Application.ApplicationVersion)"/>
|
||||
</Window.Title>
|
||||
|
||||
<Grid Margin="10">
|
||||
<Grid.CommandBindings>
|
||||
<Grid x:Name="grid" Margin="10">
|
||||
<Grid.CommandBindings>
|
||||
<CommandBinding Command="New" CanExecute="CanSaveSettings" />
|
||||
</Grid.CommandBindings>
|
||||
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="48"/>
|
||||
<RowDefinition Height="*"/>
|
||||
@@ -91,19 +111,38 @@
|
||||
<TextBox Name="PresetNameTextBox" Grid.Row="0" Grid.Column="1" Margin="5,2,25,2" Text="{Binding SelectedPreset.Name, Mode=TwoWay, ElementName=window, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" TextWrapping="Wrap" Width="Auto" />
|
||||
|
||||
<GroupBox Grid.Row="1" Grid.Column="0" Header="Input formats" Margin="5">
|
||||
<StackPanel>
|
||||
<CheckBox Content="Ape" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Ape', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Flac" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Flac', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Mp3" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Mp3', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Ogg" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Ogg', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Wav" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Wav', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Wma" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Wma', ElementName=window, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
<TreeView x:Name="treeView" Margin="5">
|
||||
<TreeViewItem Header="Audio" IsExpanded="True">
|
||||
<CheckBox Content="Ape" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Ape', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Flac" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Flac', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Mp3" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Mp3', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Ogg" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Ogg', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Wav" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Wav', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Wma" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Wma', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="M4a" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='M4a', ElementName=window, Mode=OneWay}"/>
|
||||
</TreeViewItem>
|
||||
<TreeViewItem Header="Video" IsExpanded="True">
|
||||
<CheckBox Content="Avi" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Avi', ElementName=window, Mode=OneWay}"/>
|
||||
<CheckBox Content="Mp4" Height="20" VerticalAlignment="Top" Margin="2" Checked="ToggleButton_OnChecked" Unchecked="ToggleButton_OnUnchecked" IsChecked="{Binding SelectedPreset.InputTypes, Converter={StaticResource InputTypesToBool}, ConverterParameter='Mp4', ElementName=window, Mode=OneWay}"/>
|
||||
</TreeViewItem>
|
||||
</TreeView>
|
||||
</GroupBox>
|
||||
|
||||
<GroupBox Header="Output format" Grid.Row="1" Grid.Column="1" Margin="5">
|
||||
<ComboBox Name="OutputFormats" Grid.Row="1" Grid.Column="1" Margin="5" Height="25" VerticalAlignment="Top" SelectedItem="{Binding SelectedPreset.OutputType, ElementName=window, Mode=TwoWay}">
|
||||
</ComboBox>
|
||||
<StackPanel>
|
||||
<ComboBox Name="OutputFormats" Margin="5" Height="25" VerticalAlignment="Top" SelectedItem="{Binding SelectedPreset.OutputType, ElementName=window, Mode=TwoWay}"/>
|
||||
<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}"/>
|
||||
</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"/>
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.ComponentModel;
|
||||
@@ -9,6 +10,7 @@ namespace FileConverter
|
||||
using System.Windows.Input;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
using FileConverter.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for Settings.xaml
|
||||
@@ -40,6 +42,8 @@ namespace FileConverter
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public event System.EventHandler<System.EventArgs> OnSettingsWindowHide;
|
||||
|
||||
public ConversionPreset SelectedPreset
|
||||
{
|
||||
get
|
||||
@@ -96,6 +100,8 @@ namespace FileConverter
|
||||
application.Settings.Load();
|
||||
|
||||
this.Hide();
|
||||
|
||||
this.OnSettingsWindowHide?.Invoke(this, new EventArgs());
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -105,6 +111,8 @@ namespace FileConverter
|
||||
application.Settings.Save();
|
||||
|
||||
this.Hide();
|
||||
|
||||
this.OnSettingsWindowHide?.Invoke(this, new EventArgs());
|
||||
}
|
||||
|
||||
private void AddPresetButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -127,5 +135,28 @@ namespace FileConverter
|
||||
{
|
||||
e.CanExecute = this.settings != null && string.IsNullOrEmpty(this.settings.Error);
|
||||
}
|
||||
|
||||
private void EncodingTypeRadio_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RadioButton radioButton = sender as RadioButton;
|
||||
string content = radioButton.Content as string;
|
||||
if (content == "VBR")
|
||||
{
|
||||
this.SelectedPreset?.SetSettingsValue("Encoding", "VBR");
|
||||
}
|
||||
else if (content == "CBR")
|
||||
{
|
||||
this.SelectedPreset?.SetSettingsValue("Encoding", "CBR");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unknown encoding type.");
|
||||
}
|
||||
}
|
||||
|
||||
private void EncodingQualitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> eventArgs)
|
||||
{
|
||||
this.SelectedPreset?.SetSettingsValue("Bitrate", eventArgs.NewValue.ToString("0"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user