summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2019-06-24 21:15:49 +0100
committersr55 <[email protected]>2019-06-24 21:16:01 +0100
commitb52b25d167d76106c8666c788c17e7a33f713f4d (patch)
treea01ff14c78959c9b4151819c78e46701c1cbf53b /win/CS/HandBrakeWPF/Services
parent1613a41853551dedc5b3219f05ed32aacbc85b79 (diff)
WinGui: Refactor "When Done" to use an enum to avoid language issues. Also change "suspend" to "sleep" to be consistent with the OS. Fixes #2162
Diffstat (limited to 'win/CS/HandBrakeWPF/Services')
-rw-r--r--win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs5
-rw-r--r--win/CS/HandBrakeWPF/Services/PrePostActionService.cs26
-rw-r--r--win/CS/HandBrakeWPF/Services/Presets/PresetService.cs2
-rw-r--r--win/CS/HandBrakeWPF/Services/UpdateService.cs2
-rw-r--r--win/CS/HandBrakeWPF/Services/UserSettingService.cs4
5 files changed, 16 insertions, 23 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs b/win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs
index 2dee3cde9..e2ce7530d 100644
--- a/win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs
+++ b/win/CS/HandBrakeWPF/Services/Interfaces/IUserSettingService.cs
@@ -51,15 +51,12 @@ namespace HandBrakeWPF.Services.Interfaces
/// <param name="name">
/// The name.
/// </param>
- /// <param name="convertType">
- /// The convert Type.
- /// </param>
/// <typeparam name="T">
/// The Type of the setting
/// </typeparam>
/// <returns>
/// The user setting
/// </returns>
- T GetUserSetting<T>(string name, Type convertType = null);
+ T GetUserSetting<T>(string name);
}
} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
index 7d3233fc7..67b5cf263 100644
--- a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
+++ b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
@@ -21,6 +21,7 @@ namespace HandBrakeWPF.Services
using HandBrakeWPF.EventArgs;
using HandBrakeWPF.Instance;
+ using HandBrakeWPF.Model.Options;
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Logging;
@@ -138,7 +139,7 @@ namespace HandBrakeWPF.Services
this.PlayWhenDoneSound();
}
- if (this.userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction) == "Do nothing")
+ if (this.userSettingService.GetUserSetting<int>(UserSettingConstants.WhenCompleteAction) == (int)WhenDone.DoNothing)
{
return;
}
@@ -151,7 +152,7 @@ namespace HandBrakeWPF.Services
Execute.OnUIThread(
() =>
{
- titleSpecificView.SetAction(this.userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction));
+ titleSpecificView.SetAction((WhenDone)this.userSettingService.GetUserSetting<int>(UserSettingConstants.WhenCompleteAction));
this.windowManager.ShowDialog(titleSpecificView);
isCancelled = titleSpecificView.IsCancelled;
});
@@ -159,36 +160,31 @@ namespace HandBrakeWPF.Services
if (!isCancelled)
{
- this.ServiceLogMessage(string.Format("Performing 'When Done' Action: {0}", this.userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction)));
+ this.ServiceLogMessage(string.Format("Performing 'When Done' Action: {0}", this.userSettingService.GetUserSetting<int>(UserSettingConstants.WhenCompleteAction)));
// Do something when the encode ends.
- switch (this.userSettingService.GetUserSetting<string>(UserSettingConstants.WhenCompleteAction))
+ switch ((WhenDone)this.userSettingService.GetUserSetting<int>(UserSettingConstants.WhenCompleteAction))
{
- case "Shutdown":
- case "Herunterfahren":
+ case WhenDone.Shutdown:
ProcessStartInfo shutdown = new ProcessStartInfo("Shutdown", "-s -t 60");
shutdown.UseShellExecute = false;
Process.Start(shutdown);
Execute.OnUIThread(() => System.Windows.Application.Current.Shutdown());
break;
- case "Log off":
- case "Ausloggen":
+ case WhenDone.LogOff:
this.scanService.Dispose();
Win32.ExitWindowsEx(0, 0);
break;
- case "Suspend":
+ case WhenDone.Sleep:
Application.SetSuspendState(PowerState.Suspend, true, true);
break;
- case "Hibernate":
- case "Ruhezustand":
+ case WhenDone.Hibernate:
Application.SetSuspendState(PowerState.Hibernate, true, true);
break;
- case "Lock System":
- case "System sperren":
+ case WhenDone.LockSystem:
Win32.LockWorkStation();
break;
- case "Quit HandBrake":
- case "HandBrake beenden":
+ case WhenDone.QuickHandBrake:
Execute.OnUIThread(() => System.Windows.Application.Current.Shutdown());
break;
}
diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
index 37926a352..01dd40f51 100644
--- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
+++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
@@ -711,7 +711,7 @@ namespace HandBrakeWPF.Services.Presets
}
// Force Upgrade of presets
- if (this.userSettingService.GetUserSetting<int>(UserSettingConstants.ForcePresetReset, typeof(int)) < ForcePresetReset)
+ if (this.userSettingService.GetUserSetting<int>(UserSettingConstants.ForcePresetReset) < ForcePresetReset)
{
this.userSettingService.SetUserSetting(UserSettingConstants.ForcePresetReset, ForcePresetReset);
diff --git a/win/CS/HandBrakeWPF/Services/UpdateService.cs b/win/CS/HandBrakeWPF/Services/UpdateService.cs
index 64c909f4d..61c326455 100644
--- a/win/CS/HandBrakeWPF/Services/UpdateService.cs
+++ b/win/CS/HandBrakeWPF/Services/UpdateService.cs
@@ -77,7 +77,7 @@ namespace HandBrakeWPF.Services
if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.UpdateStatus))
{
DateTime lastUpdateCheck = this.userSettingService.GetUserSetting<DateTime>(UserSettingConstants.LastUpdateCheckDate);
- int checkFrequency = this.userSettingService.GetUserSetting<int>(UserSettingConstants.DaysBetweenUpdateCheck, typeof(int)) == 0 ? 7 : 30;
+ int checkFrequency = this.userSettingService.GetUserSetting<int>(UserSettingConstants.DaysBetweenUpdateCheck) == 0 ? 7 : 30;
if (DateTime.Now.Subtract(lastUpdateCheck).TotalDays > checkFrequency)
{
diff --git a/win/CS/HandBrakeWPF/Services/UserSettingService.cs b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
index cc9e11145..9ae00d275 100644
--- a/win/CS/HandBrakeWPF/Services/UserSettingService.cs
+++ b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
@@ -88,11 +88,11 @@ namespace HandBrakeWPF.Services
/// <returns>
/// The user setting
/// </returns>
- public T GetUserSetting<T>(string name, Type conversionType = null)
+ public T GetUserSetting<T>(string name)
{
if (this.userSettings.ContainsKey(name))
{
- if (conversionType != null && typeof(int) == conversionType)
+ if (typeof(T) == typeof(int))
{
object storedValue = this.userSettings[name];
object converted = storedValue?.ToString().ToInt();