diff options
author | Scott <[email protected]> | 2015-09-26 21:05:40 +0100 |
---|---|---|
committer | Scott <[email protected]> | 2015-09-26 21:30:32 +0100 |
commit | 1320d77d36f096c7aa5b1697d3aaf9aa35d5e199 (patch) | |
tree | 1a9964eac27b7689b39a2e5adbf019a7295b6a9b /win/CS/HandBrakeWPF | |
parent | e703a7961f12a3e02c475754862a1f4a57a04646 (diff) |
App Services Tidyup Contd
Moving all the helper and utility classes to the gui project
Diffstat (limited to 'win/CS/HandBrakeWPF')
39 files changed, 628 insertions, 9 deletions
diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioBehaviourConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioBehaviourConverter.cs index 7763a49d1..667e372b7 100644 --- a/win/CS/HandBrakeWPF/Converters/Audio/AudioBehaviourConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioBehaviourConverter.cs @@ -18,6 +18,7 @@ namespace HandBrakeWPF.Converters.Audio using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Model.Audio;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// Audio Behaviour Converter
diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs index e9bb60fce..06a079f8f 100644 --- a/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs @@ -18,6 +18,8 @@ namespace HandBrakeWPF.Converters.Audio using HandBrake.ApplicationServices.Utilities;
+ using HandBrakeWPF.Utilities;
+
using AudioEncoder = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoder;
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
using OutputFormat = HandBrakeWPF.Services.Encode.Model.Models.OutputFormat;
diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioQueueDisplayConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioQueueDisplayConverter.cs index d3072e131..512fa0774 100644 --- a/win/CS/HandBrakeWPF/Converters/Audio/AudioQueueDisplayConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioQueueDisplayConverter.cs @@ -17,6 +17,8 @@ namespace HandBrakeWPF.Converters.Audio using HandBrake.ApplicationServices.Utilities;
+ using HandBrakeWPF.Utilities;
+
using AudioEncoder = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoder;
using AudioTrack = HandBrakeWPF.Services.Encode.Model.Models.AudioTrack;
diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs index b7e9cd392..9808cbb58 100644 --- a/win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs @@ -16,6 +16,8 @@ namespace HandBrakeWPF.Converters.Audio using HandBrake.ApplicationServices.Utilities;
+ using HandBrakeWPF.Utilities;
+
using AudioEncoderRateType = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoderRateType;
/// <summary>
diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioTrackDefaultBehaviourConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioTrackDefaultBehaviourConverter.cs index 2c779bbce..297488b65 100644 --- a/win/CS/HandBrakeWPF/Converters/Audio/AudioTrackDefaultBehaviourConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioTrackDefaultBehaviourConverter.cs @@ -18,6 +18,7 @@ namespace HandBrakeWPF.Converters.Audio using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Model.Audio;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// Audio Behaviour Converter
diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index 2c9f8bd90..2f92db92c 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -18,6 +18,9 @@ namespace HandBrakeWPF.Converters using HandBrake.ApplicationServices.Utilities;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
+ using HandBrakeWPF.Services.Queue.Model;
+ using HandBrakeWPF.Utilities;
+
using OutputFormat = HandBrakeWPF.Services.Encode.Model.Models.OutputFormat;
using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode;
diff --git a/win/CS/HandBrakeWPF/Converters/EnumToDescConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumToDescConverter.cs new file mode 100644 index 000000000..43c175e20 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/EnumToDescConverter.cs @@ -0,0 +1,62 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="EnumToDescConverter.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Enum to Description Converter +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Converters +{ + using System; + using System.ComponentModel; + + using HandBrake.ApplicationServices.Utilities; + + using HandBrakeWPF.Utilities; + + /// <summary> + /// Enum to Description Converter + /// </summary> + public class EnumToDescConverter : EnumConverter + { + /// <summary> + /// Initializes a new instance of the <see cref="EnumToDescConverter"/> class. + /// </summary> + /// <param name="type"> + /// The type. + /// </param> + public EnumToDescConverter(Type type) + : base(type) + { + } + + /// <summary> + /// Convert To an Object. + /// </summary> + /// <param name="context"> + /// The context. + /// </param> + /// <param name="culture"> + /// The culture. + /// </param> + /// <param name="value"> + /// The value. + /// </param> + /// <param name="destinationType"> + /// The destination type. + /// </param> + /// <returns> + /// The Enum Object + /// </returns> + public override object ConvertTo( + ITypeDescriptorContext context, + System.Globalization.CultureInfo culture, + object value, + Type destinationType) + { + return EnumHelper<Enum>.GetDescription((Enum)value); + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/Options/OptionsTabNameConverter.cs b/win/CS/HandBrakeWPF/Converters/Options/OptionsTabNameConverter.cs index beddd18be..b60e626f6 100644 --- a/win/CS/HandBrakeWPF/Converters/Options/OptionsTabNameConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Options/OptionsTabNameConverter.cs @@ -16,6 +16,7 @@ namespace HandBrakeWPF.Converters.Options using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Model;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// A Converter to get the Display Name of each options tab.
diff --git a/win/CS/HandBrakeWPF/Converters/QueueStatusToVisibilityConverter.cs b/win/CS/HandBrakeWPF/Converters/QueueStatusToVisibilityConverter.cs index 68503b741..4392c162b 100644 --- a/win/CS/HandBrakeWPF/Converters/QueueStatusToVisibilityConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/QueueStatusToVisibilityConverter.cs @@ -16,6 +16,8 @@ namespace HandBrakeWPF.Converters using HandBrake.ApplicationServices.Model;
+ using HandBrakeWPF.Services.Queue.Model;
+
/// <summary>
/// Boolean to Visibility Converter
/// </summary>
diff --git a/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBehaviourConverter.cs b/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBehaviourConverter.cs index e9acbe728..e488d71e8 100644 --- a/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBehaviourConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBehaviourConverter.cs @@ -18,6 +18,7 @@ namespace HandBrakeWPF.Converters.Subtitles using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Model.Subtitles;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// Subtitle Behaviour Converter
diff --git a/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBurnInBehaviourConverter.cs b/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBurnInBehaviourConverter.cs index 76be941bc..af706b4c0 100644 --- a/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBurnInBehaviourConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBurnInBehaviourConverter.cs @@ -18,6 +18,7 @@ namespace HandBrakeWPF.Converters.Subtitles using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Model.Subtitles;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// Subtitle Behaviour Converter
diff --git a/win/CS/HandBrakeWPF/Converters/Video/ScalingConverter.cs b/win/CS/HandBrakeWPF/Converters/Video/ScalingConverter.cs index d7f7779d5..442d525fe 100644 --- a/win/CS/HandBrakeWPF/Converters/Video/ScalingConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Video/ScalingConverter.cs @@ -17,6 +17,7 @@ namespace HandBrakeWPF.Converters.Video using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Model;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// Video Scaling Converter
diff --git a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs index a0aba003f..eb0a9c22a 100644 --- a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs @@ -18,6 +18,8 @@ namespace HandBrakeWPF.Converters.Video using HandBrake.ApplicationServices.Utilities;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
+ using HandBrakeWPF.Utilities;
+
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
using OutputFormat = HandBrakeWPF.Services.Encode.Model.Models.OutputFormat;
diff --git a/win/CS/HandBrakeWPF/Converters/Video/VideoOptionsTooltipConverter.cs b/win/CS/HandBrakeWPF/Converters/Video/VideoOptionsTooltipConverter.cs index edf14d6ee..3937cc373 100644 --- a/win/CS/HandBrakeWPF/Converters/Video/VideoOptionsTooltipConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Video/VideoOptionsTooltipConverter.cs @@ -16,6 +16,8 @@ namespace HandBrakeWPF.Converters.Video using HandBrake.ApplicationServices.Utilities;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
+ using HandBrakeWPF.Utilities;
+
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
/// <summary>
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 980adffa2..d47736b6c 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -144,6 +144,7 @@ <Compile Include="Converters\Audio\AudioRateTypeConverter.cs" />
<Compile Include="Converters\Audio\AudioTrackDefaultBehaviourConverter.cs" />
<Compile Include="Converters\Audio\AudioBehaviourConverter.cs" />
+ <Compile Include="Converters\EnumToDescConverter.cs" />
<Compile Include="Converters\Filters\DenoisePresetConverter.cs" />
<Compile Include="Converters\Subtitles\SubtitleBurnInBehaviourConverter.cs" />
<Compile Include="Converters\Subtitles\SubtitleBehaviourConverter.cs" />
@@ -226,7 +227,12 @@ <Compile Include="Utilities\DelayedActionProcessor.cs" />
<Compile Include="Utilities\DPIAwareness.cs" />
<Compile Include="Utilities\DriveUtilities.cs" />
+ <Compile Include="Utilities\EnumHelper.cs" />
+ <Compile Include="Utilities\Execute.cs" />
+ <Compile Include="Utilities\ExtensionMethods.cs" />
<Compile Include="Utilities\HandBrakeApp.cs" />
+ <Compile Include="Utilities\Interfaces\INotifyPropertyChangedEx.cs" />
+ <Compile Include="Utilities\PropertyChangedBase.cs" />
<Compile Include="Utilities\Win7.cs" />
<Compile Include="ViewModels\CountdownAlertViewModel.cs" />
<Compile Include="ViewModels\Interfaces\ICountdownAlertViewModel.cs" />
diff --git a/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs b/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs index 8d49f5ab7..e88f1ade6 100644 --- a/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs +++ b/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviours.cs @@ -12,7 +12,7 @@ namespace HandBrakeWPF.Model.Audio using System.ComponentModel;
using System.Linq;
- using HandBrake.ApplicationServices.Utilities;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// Audio Behaviours
diff --git a/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs b/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs index e31ad2042..8859b1c01 100644 --- a/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs +++ b/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs @@ -12,7 +12,7 @@ namespace HandBrakeWPF.Model.Subtitles using System.ComponentModel;
using System.Linq;
- using HandBrake.ApplicationServices.Utilities;
+ using HandBrakeWPF.Utilities;
/// <summary>
/// A class to track the behaviours of audio track selection
diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs index 8c60024f6..bf456c859 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs @@ -24,6 +24,8 @@ namespace HandBrakeWPF.Services.Encode.Factories using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Utilities; + using HandBrakeWPF.Utilities; + using AudioEncoder = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoder; using AudioEncoderRateType = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoderRateType; using AudioTrack = HandBrakeWPF.Services.Encode.Model.Models.AudioTrack; diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs index e40def17f..f4d5a988e 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs @@ -16,7 +16,8 @@ namespace HandBrakeWPF.Services.Encode.Model using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Interop.Model.Encoding; - using HandBrake.ApplicationServices.Utilities; + + using HandBrakeWPF.Utilities; using AllowedPassthru = HandBrakeWPF.Services.Encode.Model.Models.AllowedPassthru; using AudioEncoder = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoder; diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs index c435e88ec..dea5f41e6 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs @@ -21,6 +21,7 @@ namespace HandBrakeWPF.Services.Encode.Model.Models using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Services.Scan.Model; + using HandBrakeWPF.Utilities; using Newtonsoft.Json; diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/ChapterMarker.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/ChapterMarker.cs index da6979a4a..e2fdb25e3 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/ChapterMarker.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/ChapterMarker.cs @@ -11,7 +11,7 @@ namespace HandBrakeWPF.Services.Encode.Model.Models { using System; - using HandBrake.ApplicationServices.Utilities; + using HandBrakeWPF.Utilities; /// <summary> /// A Movie Chapter diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/SubtitleTrack.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/SubtitleTrack.cs index 9f2ea9ded..b4cb45d61 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/SubtitleTrack.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/SubtitleTrack.cs @@ -11,9 +11,8 @@ namespace HandBrakeWPF.Services.Encode.Model.Models { using System; - using HandBrake.ApplicationServices.Utilities; - using HandBrakeWPF.Services.Scan.Model; + using HandBrakeWPF.Utilities; /// <summary> /// Subtitle Information diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index 4be9cc038..b19cd9df3 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -24,6 +24,7 @@ namespace HandBrakeWPF.Services.Presets.Factories using HandBrakeWPF.Model.Picture;
using HandBrakeWPF.Model.Subtitles;
using HandBrakeWPF.Services.Presets.Model;
+ using HandBrakeWPF.Utilities;
using AudioEncoder = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoder;
using AudioTrack = HandBrakeWPF.Services.Encode.Model.Models.AudioTrack;
diff --git a/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs b/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs index 113e02e38..78ed92090 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs @@ -11,6 +11,7 @@ namespace HandBrakeWPF.Services.Presets.Model {
using HandBrakeWPF.Model.Audio;
using HandBrakeWPF.Model.Subtitles;
+ using HandBrakeWPF.Utilities;
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode;
@@ -23,7 +24,7 @@ namespace HandBrakeWPF.Services.Presets.Model /// https://github.com/Caliburn-Micro/Caliburn.Micro/issues/89
/// https://github.com/Caliburn-Micro/Caliburn.Micro/issues/96
/// </remarks>
- public class Preset : HandBrake.ApplicationServices.Utilities.PropertyChangedBase // Delibery not
+ public class Preset : PropertyChangedBase // Delibery not
{
#region Constants and Fields
diff --git a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueItemStatus.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueItemStatus.cs index c60945abd..92eab43e1 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueItemStatus.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueItemStatus.cs @@ -7,7 +7,7 @@ // </summary>
// --------------------------------------------------------------------------------------------------------------------
-namespace HandBrake.ApplicationServices.Model
+namespace HandBrakeWPF.Services.Queue.Model
{
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
diff --git a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs index 79de64c24..572300dd6 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Model/QueueTask.cs @@ -10,7 +10,8 @@ namespace HandBrakeWPF.Services.Queue.Model
{
using HandBrake.ApplicationServices.Model;
- using HandBrake.ApplicationServices.Utilities;
+
+ using HandBrakeWPF.Utilities;
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
diff --git a/win/CS/HandBrakeWPF/Services/Scan/Model/Subtitle.cs b/win/CS/HandBrakeWPF/Services/Scan/Model/Subtitle.cs index 920ef711e..3cca29ab7 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/Model/Subtitle.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/Model/Subtitle.cs @@ -15,6 +15,7 @@ namespace HandBrakeWPF.Services.Scan.Model using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.Services.Encode.Model.Models; + using HandBrakeWPF.Utilities; /// <summary> /// An object that represents a subtitle associated with a Title, in a DVD diff --git a/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs b/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs new file mode 100644 index 000000000..29202efe6 --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs @@ -0,0 +1,160 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="EnumHelper.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Enum Helpers +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Utilities +{ + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.ComponentModel; + using System.ComponentModel.DataAnnotations; + using System.Diagnostics; + using System.Linq; + using System.Reflection; + + using HandBrake.ApplicationServices.Attributes; + + /// <summary> + /// Enum Helpers + /// </summary> + /// <typeparam name="T"> + /// The Type Parameter + /// </typeparam> + public class EnumHelper<T> + { + /// <summary> + /// Get the description of an Enum + /// </summary> + /// <param name="value"> + /// The value. + /// </param> + /// <returns> + /// The Description string + /// </returns> + public static string GetDescription(T value) + { + FieldInfo fieldInfo = value.GetType().GetField(value.ToString()); + DescriptionAttribute[] attributes = + (DescriptionAttribute[])fieldInfo.GetCustomAttributes( + typeof(DescriptionAttribute), false); + return (attributes.Length > 0) ? attributes[0].Description : value.ToString(); + } + + /// <summary> + /// Get the Display Value of the Enum Model + /// </summary> + /// <param name="value">An Enum with Display Attributes</param> + /// <returns>A string name</returns> + public static string GetDisplay(T value) + { + FieldInfo fieldInfo = value.GetType().GetField(value.ToString()); + DisplayAttribute[] attributes = (DisplayAttribute[])fieldInfo.GetCustomAttributes(typeof(DisplayAttribute), false); + + return (attributes.Length > 0) ? attributes[0].Name : value.ToString(); + } + + /// <summary> + /// Get the Enumeration for a given Enum Description + /// </summary> + /// <param name="description">The String description</param> + /// <returns>The Enum Value</returns> + public static T GetValue(string description) + { + return GetValue(description, false); + } + + /// <summary> + /// Get the Enumeration for a given Enum Description + /// </summary> + /// <param name="description">The String description</param> + /// <param name="insensitiveCase">Turn of sensitivity to cases.</param> + /// <returns>The Enum Value</returns> + public static T GetValue(string description, bool insensitiveCase) + { + foreach (T val in Enum.GetValues(typeof(T))) + { + string currDescription = GetDescription(val); + string currDisplay = GetDisplay(val); + string shortName = GetShortName(val); + if (currDescription == description || currDisplay == description || shortName == description) + { + return val; + } + + if (insensitiveCase && (currDescription.ToLower() == description.ToLower() || currDisplay.ToLower() == description.ToLower() || shortName.ToLower() == description.ToLower())) + { + return val; + } + } + + Debug.WriteLine("EnumHelper.GetValue: The Description for the enum was not recognized: " + description); + + return default(T); + } + + /// <summary> + /// The get short name. + /// </summary> + /// <param name="value"> + /// The value. + /// </param> + /// <returns> + /// The <see cref="string"/>. + /// </returns> + public static string GetShortName(T value) + { + FieldInfo fieldInfo = value.GetType().GetField(value.ToString()); + ShortName[] attributes = (ShortName[])fieldInfo.GetCustomAttributes(typeof(ShortName), false); + + return (attributes.Length > 0) ? attributes[0].Name : value.ToString(); + } + + /// <summary> + /// Return a list of all the enum values. + /// </summary> + /// <returns> + /// An Enum Oject List + /// </returns> + public static IEnumerable<T> GetEnumList() + { + return Enum.GetValues(typeof(T)).Cast<T>().ToList(); + } + + /// <summary> + /// Get a list of string names for each enum value. + /// </summary> + /// <param name="enumType"> + /// The enum type. + /// </param> + /// <returns> + /// A collection of strings that represent all the enum values + /// </returns> + public static IEnumerable<string> GetEnumDisplayValues(Type enumType) + { + var strings = new Collection<string>(); + foreach (T e in Enum.GetValues(enumType)) + strings.Add(GetDisplay(e)); + return strings; + } + + /// <summary> + /// Get a list of string names for each enum value passed in. + /// </summary> + /// <param name="items"> + /// The items. + /// </param> + /// <returns> + /// A collection of strings that represent all the enum values + /// </returns> + public static IEnumerable<string> GetEnumDisplayValuesSubset(IEnumerable<T> items) + { + return items.Select(GetDisplay).ToList(); + } + } +} diff --git a/win/CS/HandBrakeWPF/Utilities/Execute.cs b/win/CS/HandBrakeWPF/Utilities/Execute.cs new file mode 100644 index 000000000..34fdf3a44 --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/Execute.cs @@ -0,0 +1,153 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright company="HandBrake Project (http://handbrake.fr)" file="Execute.cs"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Enables easy marshalling of code to the UI thread. +// Borrowed from Caliburn Micro. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Utilities +{ + using System; + using System.ComponentModel; + using System.Diagnostics; + using System.Threading.Tasks; + using System.Windows; + using System.Windows.Threading; + + /// <summary> + /// Enables easy marshalling of code to the UI thread. + /// </summary> + public static class Execute + { + private static System.Action<System.Action> executor = (System.Action<System.Action>)(action => action()); + private static Dispatcher dispatcher; + private static bool? inDesignMode; + + /// <summary> + /// Gets a value indicating whether or not the framework is in design-time mode. + /// </summary> + public static bool InDesignMode + { + get + { + if (!Execute.inDesignMode.HasValue) + { + Execute.inDesignMode = new bool?((bool)DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(FrameworkElement)).Metadata.DefaultValue); + if (!Execute.inDesignMode.GetValueOrDefault(false) && Process.GetCurrentProcess().ProcessName.StartsWith("devenv", StringComparison.Ordinal)) + Execute.inDesignMode = new bool?(true); + } + return Execute.inDesignMode.GetValueOrDefault(false); + } + } + + /// <summary> + /// Initializes the framework using the current dispatcher. + /// </summary> + public static void InitializeWithDispatcher() + { + Execute.dispatcher = Dispatcher.CurrentDispatcher; + Execute.executor = (System.Action<System.Action>)null; + } + + /// <summary> + /// Resets the executor to use a non-dispatcher-based action executor. + /// </summary> + public static void ResetWithoutDispatcher() + { + executor = (System.Action<System.Action>)(action => action()); + dispatcher = (Dispatcher)null; + } + + /// <summary> + /// Sets a custom UI thread marshaller. + /// </summary> + /// <param name="marshaller">The marshaller.</param> + [Obsolete] + public static void SetUIThreadMarshaller(System.Action<System.Action> marshaller) + { + Execute.executor = marshaller; + Execute.dispatcher = (Dispatcher)null; + } + + /// <summary> + /// The validate dispatcher. + /// </summary> + /// <exception cref="InvalidOperationException"> + /// Not initialized with dispatcher. + /// </exception> + private static void ValidateDispatcher() + { + if (Execute.dispatcher == null) + throw new InvalidOperationException("Not initialized with dispatcher."); + } + + /// <summary> + /// Executes the action on the UI thread asynchronously. + /// </summary> + /// <param name="action">The action to execute.</param> + public static void BeginOnUIThread(this System.Action action) + { + Execute.ValidateDispatcher(); + Execute.dispatcher.BeginInvoke((Delegate)action); + } + + /// <summary> + /// Executes the action on the UI thread asynchronously. + /// </summary> + /// <param name="action"> + /// The action to execute. + /// </param> + /// <returns> + /// The <see cref="Task"/>. + /// </returns> + public static Task OnUIThreadAsync(this System.Action action) + { + Execute.ValidateDispatcher(); + TaskCompletionSource<object> taskSource = new TaskCompletionSource<object>(); + System.Action action1 = (System.Action)(() => + { + try + { + action(); + taskSource.SetResult((object)null); + } + catch (Exception ex) + { + taskSource.SetException(ex); + } + }); + Execute.dispatcher.BeginInvoke((Delegate)action1); + return (Task)taskSource.Task; + } + + /// <summary> + /// The check access. + /// </summary> + /// <returns> + /// The <see cref="bool"/>. + /// </returns> + private static bool CheckAccess() + { + if (Execute.dispatcher != null) + return Execute.dispatcher.CheckAccess(); + return true; + } + + /// <summary> + /// Executes the action on the UI thread. + /// </summary> + /// <param name="action">The action to execute.</param> + public static void OnUIThread(this System.Action action) + { + if (Execute.executor != null) + Execute.executor(action); + else if (Execute.CheckAccess()) + action(); + else + Execute.OnUIThreadAsync(action).Wait(); + } + } +} diff --git a/win/CS/HandBrakeWPF/Utilities/ExtensionMethods.cs b/win/CS/HandBrakeWPF/Utilities/ExtensionMethods.cs new file mode 100644 index 000000000..f25b8be8e --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/ExtensionMethods.cs @@ -0,0 +1,45 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="ExtensionMethods.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// The extension methods. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Utilities +{ + using System.Linq.Expressions; + using System.Reflection; + + /// <summary> + /// The extension methods. + /// </summary> + public static class ExtensionMethods + { + /// <summary> + /// Converts an expression into a <see cref="MemberInfo"/>. + /// </summary> + /// <param name="expression"> + /// The expression to convert. + /// </param> + /// <returns> + /// The member info. + /// </returns> + public static MemberInfo GetMemberInfo(this Expression expression) + { + var lambda = (LambdaExpression)expression; + + MemberExpression memberExpression; + if (lambda.Body is UnaryExpression) + { + var unaryExpression = (UnaryExpression)lambda.Body; + memberExpression = (MemberExpression)unaryExpression.Operand; + } + else + memberExpression = (MemberExpression)lambda.Body; + + return memberExpression.Member; + } + } +} diff --git a/win/CS/HandBrakeWPF/Utilities/Interfaces/INotifyPropertyChangedEx.cs b/win/CS/HandBrakeWPF/Utilities/Interfaces/INotifyPropertyChangedEx.cs new file mode 100644 index 000000000..0030ee7b7 --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/Interfaces/INotifyPropertyChangedEx.cs @@ -0,0 +1,37 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="INotifyPropertyChangedEx.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Extends <see cref="T:System.ComponentModel.INotifyPropertyChanged" /> such that the change event can be raised by external parties. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Utilities.Interfaces +{ + using System.ComponentModel; + + /// <summary> + /// Extends <see cref="T:System.ComponentModel.INotifyPropertyChanged"/> such that the change event can be raised by external parties. + /// </summary> + public interface INotifyPropertyChangedEx : INotifyPropertyChanged + { + /// <summary> + /// Enables/Disables property change notification. + /// </summary> + bool IsNotifying { get; set; } + + /// <summary> + /// Notifies subscribers of the property change. + /// </summary> + /// <param name="propertyName"> + /// Name of the property. + /// </param> + void NotifyOfPropertyChange(string propertyName); + + /// <summary> + /// Raises a change notification indicating that all bindings should be refreshed. + /// </summary> + void Refresh(); + } +} diff --git a/win/CS/HandBrakeWPF/Utilities/PropertyChangedBase.cs b/win/CS/HandBrakeWPF/Utilities/PropertyChangedBase.cs new file mode 100644 index 000000000..ae3a401b2 --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/PropertyChangedBase.cs @@ -0,0 +1,121 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright company="HandBrake Project (http://handbrake.fr)" file="PropertyChangedBase.cs"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling. +// Borrowed from Caliburn Micro +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Utilities +{ + using System; + using System.ComponentModel; + using System.Linq.Expressions; + using System.Runtime.Serialization; + + using INotifyPropertyChangedEx = HandBrakeWPF.Utilities.Interfaces.INotifyPropertyChangedEx; + + /// <summary> + /// A base class that implements the infrastructure for property change notification and automatically performs UI thread marshalling. + /// </summary> + [Serializable] + public class PropertyChangedBase : INotifyPropertyChangedEx, INotifyPropertyChanged + { + [NonSerialized] + private bool isNotifying; + + /// <summary> + /// Gets or sets a value indicating whether the Enables/Disables property change notification. + /// </summary> + [Browsable(false)] + public bool IsNotifying + { + get + { + return this.isNotifying; + } + set + { + this.isNotifying = value; + } + } + + /// <summary> + /// Occurs when a property value changes. + /// </summary> + public event PropertyChangedEventHandler PropertyChanged = (param0, param1) => { }; + + /// <summary> + /// Initializes a new instance of the <see cref="PropertyChangedBase"/> class. + /// Creates an instance of <see cref="T:HandBrakeWPF.Utilities.PropertyChangedBase"/>. + /// </summary> + public PropertyChangedBase() + { + this.IsNotifying = true; + } + + /// <summary> + /// Raises a change notification indicating that all bindings should be refreshed. + /// </summary> + public void Refresh() + { + this.NotifyOfPropertyChange(string.Empty); + } + + /// <summary> + /// Notifies subscribers of the property change. + /// </summary> + /// <param name="propertyName">Name of the property.</param> + public virtual void NotifyOfPropertyChange(string propertyName) + { + if (!this.IsNotifying) + return; + Execute.OnUIThread((System.Action)(() => this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName)))); + } + + /// <summary> + /// Notifies subscribers of the property change. + /// </summary> + /// <typeparam name="TProperty">The type of the property.</typeparam><param name="property">The property expression.</param> + public void NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>> property) + { + this.NotifyOfPropertyChange(ExtensionMethods.GetMemberInfo((Expression)property).Name); + } + + /// <summary> + /// Raises the <see cref="E:PropertyChanged"/> event directly. + /// </summary> + /// <param name="e">The <see cref="T:System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param> + [EditorBrowsable(EditorBrowsableState.Never)] + protected void OnPropertyChanged(PropertyChangedEventArgs e) + { + PropertyChangedEventHandler changedEventHandler = this.PropertyChanged; + if (changedEventHandler == null) + return; + changedEventHandler((object)this, e); + } + + /// <summary> + /// Called when the object is deserialized. + /// </summary> + /// <param name="c">The streaming context.</param> + [OnDeserialized] + public void OnDeserialized(StreamingContext c) + { + this.IsNotifying = true; + } + + /// <summary> + /// Used to indicate whether or not the IsNotifying property is serialized to Xml. + /// </summary> + /// <returns> + /// Whether or not to serialize the IsNotifying property. The default is false. + /// </returns> + public virtual bool ShouldSerializeIsNotifying() + { + return false; + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs index 6ef7f01f5..2d8a7bd68 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs @@ -23,6 +23,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Services.Presets.Interfaces;
using HandBrakeWPF.Services.Presets.Model;
using HandBrakeWPF.Services.Scan.Model;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index d732b0cd6..0966b18fd 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -25,6 +25,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Presets.Model;
using HandBrakeWPF.Services.Scan.Model;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using AllowedPassthru = HandBrakeWPF.Services.Encode.Model.Models.AllowedPassthru;
diff --git a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs index 07906b204..8810c65d9 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -20,6 +20,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Presets.Model;
using HandBrakeWPF.Services.Scan.Model;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using DenoisePreset = HandBrakeWPF.Services.Encode.Model.Models.DenoisePreset;
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 04c2df797..b581bdfcd 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -25,6 +25,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Model;
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Interfaces;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using Ookii.Dialogs.Wpf;
diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs index c2fefd4f6..73df64ddd 100644 --- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs @@ -20,6 +20,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Presets.Model;
using HandBrakeWPF.Services.Scan.Model;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using Microsoft.Win32;
diff --git a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs index 0b263e3fa..eb3ee984e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs @@ -26,6 +26,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Presets.Model;
using HandBrakeWPF.Services.Scan.Model;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using Clipboard = System.Windows.Clipboard;
diff --git a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs index 4071eeb3c..cd8dfea5a 100644 --- a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs @@ -26,6 +26,7 @@ namespace HandBrakeWPF.Views using HandBrakeWPF.ViewModels.Interfaces;
using Application = System.Windows.Application;
+ using Execute = Caliburn.Micro.Execute;
/// <summary>
/// Interaction logic for ShellView.xaml
|