// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// The Options View Model
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.ViewModels
{
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using Caliburn.Micro;
using HandBrake.ApplicationServices;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using Ookii.Dialogs.Wpf;
///
/// The Options View Model
///
[Export(typeof(IOptionsViewModel))]
public class OptionsViewModel : ViewModelBase, IOptionsViewModel
{
#region Constants and Fields
///
/// Backing field for the user setting service.
///
private readonly IUserSettingService userSettingService;
///
/// The add audio mode options.
///
private BindingList addAudioModeOptions = new BindingList();
///
/// The add closed captions.
///
private bool addClosedCaptions;
///
/// The add only one audio track per language.
///
private bool addOnlyOneAudioTrackPerLanguage;
///
/// The add subtitle mode options.
///
private BindingList addSubtitleModeOptions = new BindingList();
///
/// The arguments.
///
private string arguments;
///
/// The auto name default path.
///
private string autoNameDefaultPath;
///
/// The automatically name files.
///
private bool automaticallyNameFiles;
///
/// The autoname format.
///
private string autonameFormat;
///
/// The available languages.
///
private BindingList availableLanguages = new BindingList();
///
/// The change to title case.
///
private bool changeToTitleCase;
///
/// The check for updates.
///
private bool checkForUpdates;
///
/// The check for updates frequencies.
///
private BindingList checkForUpdatesFrequencies = new BindingList();
///
/// The check for updates frequency.
///
private int checkForUpdatesFrequency;
///
/// The clear old olgs.
///
private bool clearOldOlgs;
///
/// The constant quality granularity.
///
private BindingList constantQualityGranularity = new BindingList();
///
/// The copy log to encode directory.
///
private bool copyLogToEncodeDirectory;
///
/// The copy log to sepcficed location.
///
private bool copyLogToSepcficedLocation;
///
/// The disable libdvd nav.
///
private bool disableLibdvdNav;
///
/// The disable p reset update check notification.
///
private bool disablePresetUpdateCheckNotification;
///
/// The display status messages tray icon.
///
private bool displayStatusMessagesTrayIcon;
///
/// The enable gui tooltips.
///
private bool enableGuiTooltips;
///
/// The enable query editor.
///
private bool enableQueryEditor;
///
/// The growl after encode.
///
private bool growlAfterEncode;
///
/// The growl after queue.
///
private bool growlAfterQueue;
///
/// The log directory.
///
private string logDirectory;
///
/// The log verbosity options.
///
private BindingList logVerbosityOptions = new BindingList();
///
/// The min length.
///
private long minLength;
///
/// The minimise to tray.
///
private bool minimiseToTray;
///
/// The mp 4 extension options.
///
private BindingList mp4ExtensionOptions = new BindingList();
///
/// The prevent sleep.
///
private bool preventSleep;
///
/// The preview pictures to scan.
///
private BindingList previewPicturesToScan = new BindingList();
///
/// The priority level options.
///
private BindingList priorityLevelOptions = new BindingList();
///
/// The prompt on different query.
///
private bool promptOnDifferentQuery;
///
/// The remove underscores.
///
private bool removeUnderscores;
///
/// The selected add audio mode.
///
private int selectedAddAudioMode;
///
/// The selected add subtitle mode.
///
private int selectedAddSubtitleMode;
///
/// The selected granulairty.
///
private string selectedGranulairty;
///
/// The selected mp 4 extension.
///
private int selectedMp4Extension;
///
/// The selected preferred languages.
///
private BindingList preferredLanguages = new BindingList();
///
/// The selected preferreed langauge.
///
private string selectedPreferredLangauge;
///
/// The selected preview count.
///
private int selectedPreviewCount;
///
/// The selected priority.
///
private string selectedPriority;
///
/// The selected verbosity.
///
private int selectedVerbosity;
///
/// The send file after encode.
///
private bool sendFileAfterEncode;
///
/// The send file to.
///
private string sendFileTo;
///
/// The send file to Path.
///
private string sendFileToPath;
///
/// The show cli window.
///
private bool showCliWindow;
///
/// The vlc path.
///
private string vlcPath;
///
/// The when done.
///
private string whenDone;
///
/// The when done options.
///
private BindingList whenDoneOptions = new BindingList();
///
/// Selected Langauges
///
private BindingList selectedLangauges = new BindingList();
#endregion
#region Constructors and Destructors
///
/// Initializes a new instance of the class.
///
///
/// The window manager.
///
///
/// The user Setting Service.
///
public OptionsViewModel(IWindowManager windowManager, IUserSettingService userSettingService)
: base(windowManager)
{
this.userSettingService = userSettingService;
this.Load();
}
#endregion
#region Properties
#region General
///
/// Gets or sets a value indicating whether CheckForUpdates.
///
public bool CheckForUpdates
{
get
{
return this.checkForUpdates;
}
set
{
this.checkForUpdates = value;
this.NotifyOfPropertyChange("CheckForUpdates");
}
}
///
/// Gets or sets CheckForUpdatesFrequencies.
///
public BindingList CheckForUpdatesFrequencies
{
get
{
return this.checkForUpdatesFrequencies;
}
set
{
this.checkForUpdatesFrequencies = value;
this.NotifyOfPropertyChange("CheckForUpdatesFrequencies");
}
}
///
/// Gets or sets a value indicating whether CheckForUpdatesFrequency.
///
public int CheckForUpdatesFrequency
{
get
{
return this.checkForUpdatesFrequency;
}
set
{
this.checkForUpdatesFrequency = value;
this.NotifyOfPropertyChange("CheckForUpdatesFrequency");
}
}
///
/// Gets or sets Arguments.
///
public string Arguments
{
get
{
return this.arguments;
}
set
{
this.arguments = value;
this.NotifyOfPropertyChange("Arguments");
}
}
///
/// Gets or sets a value indicating whether GrowlAfterEncode.
///
public bool GrowlAfterEncode
{
get
{
return this.growlAfterEncode;
}
set
{
this.growlAfterEncode = value;
this.NotifyOfPropertyChange("GrowlAfterEncode");
}
}
///
/// Gets or sets a value indicating whether GrowlAfterQueue.
///
public bool GrowlAfterQueue
{
get
{
return this.growlAfterQueue;
}
set
{
this.growlAfterQueue = value;
this.NotifyOfPropertyChange("GrowlAfterQueue");
}
}
///
/// Gets or sets a value indicating whether SendFileAfterEncode.
///
public bool SendFileAfterEncode
{
get
{
return this.sendFileAfterEncode;
}
set
{
this.sendFileAfterEncode = value;
this.NotifyOfPropertyChange("SendFileAfterEncode");
}
}
///
/// Gets or sets SendFileTo.
///
public string SendFileTo
{
get
{
return this.sendFileTo;
}
set
{
this.sendFileTo = value;
this.NotifyOfPropertyChange("SendFileTo");
}
}
///
/// Gets or sets SendFileToPath.
///
public string SendFileToPath
{
get
{
return this.sendFileToPath;
}
set
{
this.sendFileToPath = value;
this.NotifyOfPropertyChange("SendFileToPath");
}
}
///
/// Gets or sets a value indicating whether EnableGuiTooltips.
///
public bool EnableGuiTooltips
{
get
{
return this.enableGuiTooltips;
}
set
{
this.enableGuiTooltips = value;
this.NotifyOfPropertyChange("EnableGuiTooltips");
}
}
///
/// Gets or sets WhenDone.
///
public string WhenDone
{
get
{
return this.whenDone;
}
set
{
this.whenDone = value;
this.NotifyOfPropertyChange("WhenDone");
}
}
///
/// Gets or sets WhenDoneOptions.
///
public BindingList WhenDoneOptions
{
get
{
return this.whenDoneOptions;
}
set
{
this.whenDoneOptions = value;
this.NotifyOfPropertyChange("WhenDoneOptions");
}
}
#endregion
#region Output Files
///
/// Gets or sets AutoNameDefaultPath.
///
public string AutoNameDefaultPath
{
get
{
return this.autoNameDefaultPath;
}
set
{
this.autoNameDefaultPath = value;
this.NotifyOfPropertyChange("AutoNameDefaultPath");
}
}
///
/// Gets or sets a value indicating whether AutomaticallyNameFiles.
///
public bool AutomaticallyNameFiles
{
get
{
return this.automaticallyNameFiles;
}
set
{
this.automaticallyNameFiles = value;
this.NotifyOfPropertyChange("AutomaticallyNameFiles");
}
}
///
/// Gets or sets AutonameFormat.
///
public string AutonameFormat
{
get
{
return this.autonameFormat;
}
set
{
this.autonameFormat = value;
this.NotifyOfPropertyChange("AutonameFormat");
}
}
///
/// Gets or sets a value indicating whether ChangeToTitleCase.
///
public bool ChangeToTitleCase
{
get
{
return this.changeToTitleCase;
}
set
{
this.changeToTitleCase = value;
this.NotifyOfPropertyChange("ChangeToTitleCase");
}
}
///
/// Gets or sets Mp4ExtensionOptions.
///
public BindingList Mp4ExtensionOptions
{
get
{
return this.mp4ExtensionOptions;
}
set
{
this.mp4ExtensionOptions = value;
this.NotifyOfPropertyChange("Mp4ExtensionOptions");
}
}
///
/// Gets or sets a value indicating whether RemoveUnderscores.
///
public bool RemoveUnderscores
{
get
{
return this.removeUnderscores;
}
set
{
this.removeUnderscores = value;
this.NotifyOfPropertyChange("RemoveUnderscores");
}
}
///
/// Gets or sets SelectedMp4Extension.
///
public int SelectedMp4Extension
{
get
{
return this.selectedMp4Extension;
}
set
{
this.selectedMp4Extension = value;
this.NotifyOfPropertyChange("SelectedMp4Extension");
}
}
#endregion
#region Preview
///
/// Gets or sets VLCPath.
///
public string VLCPath
{
get
{
return this.vlcPath;
}
set
{
this.vlcPath = value;
this.NotifyOfPropertyChange("VLCPath");
}
}
#endregion
#region Audio and Subtitles
///
/// Gets or sets preferredLanguages.
///
public BindingList PreferredLanguages
{
get
{
return this.preferredLanguages;
}
set
{
this.preferredLanguages = value;
this.NotifyOfPropertyChange("preferredLanguages");
}
}
///
/// Gets or sets SelectedPreferreedLangauge.
///
public string SelectedPreferredLangauge
{
get
{
return this.selectedPreferredLangauge;
}
set
{
this.selectedPreferredLangauge = value;
this.NotifyOfPropertyChange("SelectedPreferreedLangauge");
}
}
///
/// Gets or sets AvailableLanguages.
///
public BindingList AvailableLanguages
{
get
{
return this.availableLanguages;
}
set
{
this.availableLanguages = value;
this.NotifyOfPropertyChange("AvailableLanguages");
}
}
///
/// Gets or sets SelectedLangauges.
///
public BindingList SelectedLangauges
{
get
{
return this.selectedLangauges;
}
set
{
this.selectedLangauges = value;
this.NotifyOfPropertyChange("SelectedLangauges");
}
}
///
/// Gets or sets SelectedLangauges.
///
public BindingList SelectedAvailableToMove { get; set; }
///
/// Gets or sets SelectedLangauges.
///
public BindingList SelectedLangaugesToMove { get; set; }
///
/// Gets or sets AddAudioModeOptions.
///
public BindingList AddAudioModeOptions
{
get
{
return this.addAudioModeOptions;
}
set
{
this.addAudioModeOptions = value;
this.NotifyOfPropertyChange("AddAudioModeOptions");
}
}
///
/// Gets or sets a value indicating whether AddClosedCaptions.
///
public bool AddClosedCaptions
{
get
{
return this.addClosedCaptions;
}
set
{
this.addClosedCaptions = value;
this.NotifyOfPropertyChange("AddClosedCaptions");
}
}
///
/// Gets or sets a value indicating whether AddOnlyOneAudioTrackPerLanguage.
///
public bool AddOnlyOneAudioTrackPerLanguage
{
get
{
return this.addOnlyOneAudioTrackPerLanguage;
}
set
{
this.addOnlyOneAudioTrackPerLanguage = value;
this.NotifyOfPropertyChange("AddOnlyOneAudioTrackPerLanguage");
}
}
///
/// Gets or sets AddSubtitleModeOptions.
///
public BindingList AddSubtitleModeOptions
{
get
{
return this.addSubtitleModeOptions;
}
set
{
this.addSubtitleModeOptions = value;
this.NotifyOfPropertyChange("AddSubtitleModeOptions");
}
}
///
/// Gets or sets SelectedAddAudioMode.
///
public int SelectedAddAudioMode
{
get
{
return this.selectedAddAudioMode;
}
set
{
this.selectedAddAudioMode = value;
this.NotifyOfPropertyChange("SelectedAddAudioMode");
}
}
///
/// Gets or sets SelectedAddSubtitleMode.
///
public int SelectedAddSubtitleMode
{
get
{
return this.selectedAddSubtitleMode;
}
set
{
this.selectedAddSubtitleMode = value;
this.NotifyOfPropertyChange("SelectedAddSubtitleMode");
}
}
#endregion
#region System and Logging
///
/// Gets or sets a value indicating whether CopyLogToEncodeDirectory.
///
public bool CopyLogToEncodeDirectory
{
get
{
return this.copyLogToEncodeDirectory;
}
set
{
this.copyLogToEncodeDirectory = value;
this.NotifyOfPropertyChange("CopyLogToEncodeDirectory");
}
}
///
/// Gets or sets a value indicating whether CopyLogToSepcficedLocation.
///
public bool CopyLogToSepcficedLocation
{
get
{
return this.copyLogToSepcficedLocation;
}
set
{
this.copyLogToSepcficedLocation = value;
this.NotifyOfPropertyChange("CopyLogToSepcficedLocation");
}
}
///
/// Gets or sets a value indicating whether ClearOldOlgs.
///
public bool ClearOldOlgs
{
get
{
return this.clearOldOlgs;
}
set
{
this.clearOldOlgs = value;
this.NotifyOfPropertyChange("ClearOldOlgs");
}
}
///
/// Gets or sets LogDirectory.
///
public string LogDirectory
{
get
{
return this.logDirectory;
}
set
{
this.logDirectory = value;
this.NotifyOfPropertyChange("LogDirectory");
}
}
///
/// Gets or sets a value indicating whether PreventSleep.
///
public bool PreventSleep
{
get
{
return this.preventSleep;
}
set
{
this.preventSleep = value;
this.NotifyOfPropertyChange("PreventSleep");
}
}
///
/// Gets or sets PriorityLevelOptions.
///
public BindingList PriorityLevelOptions
{
get
{
return this.priorityLevelOptions;
}
set
{
this.priorityLevelOptions = value;
this.NotifyOfPropertyChange("PriorityLevelOptions");
}
}
///
/// Gets or sets a value indicating whether SelectedGranulairty.
///
public string SelectedGranulairty
{
get
{
return this.selectedGranulairty;
}
set
{
this.selectedGranulairty = value;
this.NotifyOfPropertyChange("SelectedGranulairty");
}
}
///
/// Gets or sets SelectedPriority.
///
public string SelectedPriority
{
get
{
return this.selectedPriority;
}
set
{
this.selectedPriority = value;
this.NotifyOfPropertyChange("SelectedPriority");
}
}
#endregion
#region Advanced
///
/// Gets or sets a value indicating whether EnableQueryEditor.
///
public bool EnableQueryEditor
{
get
{
return this.enableQueryEditor;
}
set
{
this.enableQueryEditor = value;
this.NotifyOfPropertyChange("EnableQueryEditor");
}
}
///
/// Gets or sets a value indicating whether PromptOnDifferentQuery.
///
public bool PromptOnDifferentQuery
{
get
{
return this.promptOnDifferentQuery;
}
set
{
this.promptOnDifferentQuery = value;
this.NotifyOfPropertyChange("PromptOnDifferentQuery");
}
}
///
/// Gets or sets ConstantQualityGranularity.
///
public BindingList ConstantQualityGranularity
{
get
{
return this.constantQualityGranularity;
}
set
{
this.constantQualityGranularity = value;
this.NotifyOfPropertyChange("ConstantQualityGranularity");
}
}
///
/// Gets or sets a value indicating whether DisableLibdvdNav.
///
public bool DisableLibdvdNav
{
get
{
return this.disableLibdvdNav;
}
set
{
this.disableLibdvdNav = value;
this.NotifyOfPropertyChange("DisableLibdvdNav");
}
}
///
/// Gets or sets a value indicating whether disablePresetUpdateCheckNotification.
///
public bool DisablePresetUpdateCheckNotification
{
get
{
return this.disablePresetUpdateCheckNotification;
}
set
{
this.disablePresetUpdateCheckNotification = value;
this.NotifyOfPropertyChange("DisablePresetUpdateCheckNotification");
}
}
///
/// Gets or sets a value indicating whether DisplayStatusMessagesTrayIcon.
///
public bool DisplayStatusMessagesTrayIcon
{
get
{
return this.displayStatusMessagesTrayIcon;
}
set
{
this.displayStatusMessagesTrayIcon = value;
this.NotifyOfPropertyChange("DisplayStatusMessagesTrayIcon");
}
}
///
/// Gets or sets LogVerbosityOptions.
///
public BindingList LogVerbosityOptions
{
get
{
return this.logVerbosityOptions;
}
set
{
this.logVerbosityOptions = value;
this.NotifyOfPropertyChange("LogVerbosityOptions");
}
}
///
/// Gets or sets MinLength.
///
public long MinLength
{
get
{
return this.minLength;
}
set
{
this.minLength = value;
this.NotifyOfPropertyChange("MinLength");
}
}
///
/// Gets or sets a value indicating whether MinimiseToTray.
///
public bool MinimiseToTray
{
get
{
return this.minimiseToTray;
}
set
{
this.minimiseToTray = value;
this.NotifyOfPropertyChange("MinimiseToTray");
}
}
///
/// Gets or sets PreviewPicturesToScan.
///
public BindingList PreviewPicturesToScan
{
get
{
return this.previewPicturesToScan;
}
set
{
this.previewPicturesToScan = value;
this.NotifyOfPropertyChange("PreviewPicturesToScan");
}
}
///
/// Gets or sets SelectedPreviewCount.
///
public int SelectedPreviewCount
{
get
{
return this.selectedPreviewCount;
}
set
{
this.selectedPreviewCount = value;
this.NotifyOfPropertyChange("SelectedPreviewCount");
}
}
///
/// Gets or sets SelectedVerbosity.
///
public int SelectedVerbosity
{
get
{
return this.selectedVerbosity;
}
set
{
this.selectedVerbosity = value;
this.NotifyOfPropertyChange("SelectedVerbosity");
}
}
///
/// Gets or sets a value indicating whether ShowCliWindow.
///
public bool ShowCliWindow
{
get
{
return this.showCliWindow;
}
set
{
this.showCliWindow = value;
this.NotifyOfPropertyChange("ShowCliWindow");
}
}
#endregion
#endregion
#region Public Methods
///
/// Load User Settings
///
public override void OnLoad()
{
// #############################
// General
// #############################
this.enableGuiTooltips = this.userSettingService.GetUserSetting(UserSettingConstants.TooltipEnable);
this.checkForUpdates = this.userSettingService.GetUserSetting(UserSettingConstants.UpdateStatus);
// Days between update checks
this.checkForUpdatesFrequencies.Add("Daily");
this.checkForUpdatesFrequencies.Add("Weekly");
this.checkForUpdatesFrequencies.Add("Monthly");
// TODO Refactor this.
switch (this.userSettingService.GetUserSetting(UserSettingConstants.DaysBetweenUpdateCheck))
{
case 1:
this.checkForUpdatesFrequency = 1;
break;
case 7:
this.checkForUpdatesFrequency = 2;
break;
case 30:
this.checkForUpdatesFrequency = 3;
break;
}
// On Encode Completeion Action
this.whenDoneOptions.Add("Do nothing");
this.whenDoneOptions.Add("Shutdown");
this.whenDoneOptions.Add("Suspend");
this.whenDoneOptions.Add("Hibernate");
this.whenDoneOptions.Add("Lock system");
this.whenDoneOptions.Add("Log off");
this.whenDoneOptions.Add("Quit HandBrake");
this.whenDone = userSettingService.GetUserSetting("WhenCompleteAction");
this.growlAfterEncode = userSettingService.GetUserSetting(ASUserSettingConstants.GrowlEncode);
this.growlAfterQueue = userSettingService.GetUserSetting(ASUserSettingConstants.GrowlQueue);
this.sendFileAfterEncode = this.userSettingService.GetUserSetting(ASUserSettingConstants.SendFile);
this.sendFileTo = Path.GetFileNameWithoutExtension(this.userSettingService.GetUserSetting(ASUserSettingConstants.SendFileTo)) ?? string.Empty;
this.sendFileToPath = this.userSettingService.GetUserSetting(ASUserSettingConstants.SendFileTo) ?? string.Empty;
this.arguments = this.userSettingService.GetUserSetting(ASUserSettingConstants.SendFileToArgs) ?? string.Empty;
// #############################
// Output Settings
// #############################
// Enable auto naming feature.)
this.automaticallyNameFiles = this.userSettingService.GetUserSetting(UserSettingConstants.AutoNaming);
// Store the auto name path
this.autoNameDefaultPath = this.userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath) ?? string.Empty;
if (string.IsNullOrEmpty(this.autoNameDefaultPath))
this.autoNameDefaultPath = "Click 'Browse' to set the default location";
// Store auto name format
this.autonameFormat = this.userSettingService.GetUserSetting(UserSettingConstants.AutoNameFormat) ?? string.Empty;
// Use iPod/iTunes friendly .m4v extension for MP4 files.
this.mp4ExtensionOptions.Add("Automatic");
this.mp4ExtensionOptions.Add("Always use MP4");
this.mp4ExtensionOptions.Add("Always use M4V");
this.selectedMp4Extension = this.userSettingService.GetUserSetting(UserSettingConstants.UseM4v);
// Remove Underscores
this.removeUnderscores = this.userSettingService.GetUserSetting(UserSettingConstants.AutoNameRemoveUnderscore);
// Title case
this.changeToTitleCase = this.userSettingService.GetUserSetting(UserSettingConstants.AutoNameTitleCase);
// #############################
// Picture Tab
// #############################
// VLC Path
this.vlcPath = this.userSettingService.GetUserSetting(UserSettingConstants.VLC_Path) ?? string.Empty;
// #############################
// Audio and Subtitles Tab
// #############################
this.SelectedAvailableToMove = new BindingList();
this.SelectedLangaugesToMove = new BindingList();
IDictionary langList = LanguageUtilities.MapLanguages();
foreach (string selectedItem in this.userSettingService.GetUserSetting(UserSettingConstants.SelectedLanguages))
{
// removing wrong keys when a new Language list comes out.
if (langList.ContainsKey(selectedItem))
{
this.selectedLangauges.Add(selectedItem);
}
}
foreach (string item in langList.Keys)
{
this.preferredLanguages.Add(item);
// In the available languages should be no "Any" and no selected language.
if ((item != "Any") && (!this.userSettingService.GetUserSetting(UserSettingConstants.SelectedLanguages).Contains(item)))
{
this.availableLanguages.Add(item);
}
}
this.selectedPreferredLangauge = this.userSettingService.GetUserSetting(UserSettingConstants.NativeLanguage) ?? string.Empty;
this.AddAudioModeOptions.Add("None");
this.AddAudioModeOptions.Add("All Remaining Tracks");
this.AddAudioModeOptions.Add("All for Selected Languages");
this.AddSubtitleModeOptions.Add("None");
this.AddSubtitleModeOptions.Add("All");
this.AddSubtitleModeOptions.Add("First");
this.AddSubtitleModeOptions.Add("Selected");
this.AddSubtitleModeOptions.Add("Preferred Only");
this.selectedAddAudioMode = this.userSettingService.GetUserSetting(UserSettingConstants.DubModeAudio);
this.selectedAddSubtitleMode = this.userSettingService.GetUserSetting(UserSettingConstants.DubModeSubtitle);
this.addOnlyOneAudioTrackPerLanguage = this.userSettingService.GetUserSetting(UserSettingConstants.AddOnlyOneAudioPerLanguage);
this.addClosedCaptions = this.userSettingService.GetUserSetting(UserSettingConstants.UseClosedCaption);
// #############################
// CLI
// #############################
// Priority level for encodes
this.priorityLevelOptions.Add("Realtime");
this.priorityLevelOptions.Add("High");
this.priorityLevelOptions.Add("Above Normal");
this.priorityLevelOptions.Add("Normal");
this.priorityLevelOptions.Add("Below Normal");
this.priorityLevelOptions.Add("Low");
this.selectedPriority = userSettingService.GetUserSetting(ASUserSettingConstants.ProcessPriority);
this.preventSleep = userSettingService.GetUserSetting(ASUserSettingConstants.PreventSleep);
// Log Verbosity Level
this.logVerbosityOptions.Add(0);
this.logVerbosityOptions.Add(1);
this.logVerbosityOptions.Add(2);
this.selectedVerbosity = userSettingService.GetUserSetting(ASUserSettingConstants.Verbosity);
// Logs
this.copyLogToEncodeDirectory = userSettingService.GetUserSetting(ASUserSettingConstants.SaveLogWithVideo);
this.copyLogToSepcficedLocation = userSettingService.GetUserSetting(ASUserSettingConstants.SaveLogToCopyDirectory);
// The saved log path
this.logDirectory = userSettingService.GetUserSetting(ASUserSettingConstants.SaveLogCopyDirectory) ?? string.Empty;
this.clearOldOlgs = this.userSettingService.GetUserSetting(UserSettingConstants.ClearOldLogs);
// #############################
// Advanced
// #############################
// Minimise to Tray
this.displayStatusMessagesTrayIcon = this.userSettingService.GetUserSetting(UserSettingConstants.TrayIconAlerts);
this.minimiseToTray = this.userSettingService.GetUserSetting(UserSettingConstants.MainWindowMinimize);
this.enableQueryEditor = this.userSettingService.GetUserSetting(UserSettingConstants.QueryEditorTab);
this.promptOnDifferentQuery = this.userSettingService.GetUserSetting(UserSettingConstants.PromptOnUnmatchingQueries);
this.disablePresetUpdateCheckNotification = this.userSettingService.GetUserSetting(UserSettingConstants.PresetNotification);
this.showCliWindow = userSettingService.GetUserSetting(ASUserSettingConstants.ShowCLI);
// Set the preview count
this.PreviewPicturesToScan.Add(10);
this.PreviewPicturesToScan.Add(15);
this.PreviewPicturesToScan.Add(20);
this.PreviewPicturesToScan.Add(25);
this.PreviewPicturesToScan.Add(30);
this.selectedPreviewCount = this.userSettingService.GetUserSetting(ASUserSettingConstants.PreviewScanCount);
// x264 step
this.ConstantQualityGranularity.Add("1.0");
this.ConstantQualityGranularity.Add("0.50");
this.ConstantQualityGranularity.Add("0.25");
this.ConstantQualityGranularity.Add("0.20");
this.selectedGranulairty = userSettingService.GetUserSetting(ASUserSettingConstants.X264Step).ToString("0.00", CultureInfo.InvariantCulture);
// Min Title Length
this.minLength = this.userSettingService.GetUserSetting(ASUserSettingConstants.MinScanDuration);
// Use Experimental dvdnav
this.disableLibdvdNav = userSettingService.GetUserSetting(ASUserSettingConstants.DisableLibDvdNav);
}
///
/// Close this window.
///
public void Close()
{
this.Save();
this.TryClose();
}
///
/// Browse - Send File To
///
public void BrowseSendFileTo()
{
VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "All files (*.*)|*.*" };
dialog.ShowDialog();
this.SendFileTo = Path.GetFileNameWithoutExtension(dialog.FileName);
this.sendFileToPath = dialog.FileName;
}
///
/// Browse Auto Name Path
///
public void BrowseAutoNamePath()
{
VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog { Description = "Please select a folder.", UseDescriptionForTitle = true };
dialog.ShowDialog();
this.AutoNameDefaultPath = dialog.SelectedPath;
}
///
/// Browse VLC Path
///
public void BrowseVlcPath()
{
VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "All files (*.exe)|*.exe" };
dialog.ShowDialog();
this.VLCPath = dialog.FileName;
}
///
/// Audio List Move Left
///
public void LanguageMoveLeft()
{
if (this.AvailableLanguages.Count > 0)
{
List copiedList = SelectedAvailableToMove.ToList();
foreach (string item in copiedList)
{
this.AvailableLanguages.Remove(item);
this.SelectedLangauges.Add(item);
}
}
}
///
/// Audio List Move Right
///
public void LanguageMoveRight()
{
if (this.SelectedLangauges.Count > 0)
{
List copiedList = SelectedLangaugesToMove.ToList();
foreach (string item in copiedList)
{
this.SelectedLangauges.Remove(item);
this.AvailableLanguages.Add(item);
}
}
}
///
/// Audio List Clear all selected languages
///
public void LanguageClearAll()
{
foreach (string item in this.SelectedLangauges)
{
this.AvailableLanguages.Add(item);
}
this.SelectedLangauges.Clear();
}
///
/// Audio List Language Move UP
///
public void LanguageMoveUp()
{
List langauges = this.SelectedLangauges.ToList();
foreach (string item in langauges)
{
if (this.SelectedLangaugesToMove.Contains(item))
{
int index = this.SelectedLangauges.IndexOf(item);
if (index != 0)
{
this.SelectedLangauges.Remove(item);
this.SelectedLangauges.Insert(index - 1, item);
}
}
}
}
///
/// Audio List Language Move Down
///
public void LanguageMoveDown()
{
List langauges = this.SelectedLangauges.ToList();
int count = this.SelectedLangauges.Count;
foreach (string item in langauges)
{
if (this.SelectedLangaugesToMove.Contains(item))
{
int index = this.SelectedLangauges.IndexOf(item);
if ((index + 1) != count)
{
this.SelectedLangauges.Remove(item);
this.SelectedLangauges.Insert(index + 1, item);
}
}
}
}
///
/// Browse - Log Path
///
public void BrowseLogPath()
{
VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog { Description = "Please select a folder.", UseDescriptionForTitle = true };
dialog.ShowDialog();
this.LogDirectory = dialog.SelectedPath;
}
///
/// View the Default Log Directory for HandBrake
///
public void ViewLogDirectory()
{
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
string windir = Environment.GetEnvironmentVariable("WINDIR");
Process prc = new Process { StartInfo = { FileName = windir + @"\explorer.exe", Arguments = logDir } };
prc.Start();
}
///
/// Clear HandBrakes log directory.
///
public void ClearLogHistory()
{
MessageBoxResult result = MessageBox.Show("Are you sure you wish to clear the log file directory?", "Clear Logs",
MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
GeneralUtilities.ClearLogFiles(0);
MessageBox.Show("HandBrake's Log file directory has been cleared!", "Notice", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
#endregion
///
/// Save the settings selected
///
private void Save()
{
/* General */
this.userSettingService.SetUserSetting(UserSettingConstants.UpdateStatus, this.CheckForUpdates);
this.userSettingService.SetUserSetting(UserSettingConstants.DaysBetweenUpdateCheck, this.CheckForUpdatesFrequency);
this.userSettingService.SetUserSetting(UserSettingConstants.TooltipEnable, this.EnableGuiTooltips);
this.userSettingService.SetUserSetting(ASUserSettingConstants.WhenCompleteAction, this.WhenDone);
this.userSettingService.SetUserSetting(ASUserSettingConstants.GrowlQueue, this.GrowlAfterQueue);
this.userSettingService.SetUserSetting(ASUserSettingConstants.GrowlEncode, this.GrowlAfterEncode);
this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFileTo, this.SendFileToPath);
this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFile, this.SendFileAfterEncode);
this.userSettingService.SetUserSetting(ASUserSettingConstants.SendFileToArgs, this.Arguments);
/* Output Files */
this.userSettingService.SetUserSetting(UserSettingConstants.AutoNaming, this.AutomaticallyNameFiles);
this.userSettingService.SetUserSetting(UserSettingConstants.AutoNameFormat, this.AutonameFormat);
this.userSettingService.SetUserSetting(UserSettingConstants.AutoNamePath, this.AutoNameDefaultPath);
this.userSettingService.SetUserSetting(UserSettingConstants.UseM4v, this.SelectedMp4Extension);
this.userSettingService.SetUserSetting(UserSettingConstants.AutoNameRemoveUnderscore, this.RemoveUnderscores);
this.userSettingService.SetUserSetting(UserSettingConstants.AutoNameTitleCase, this.ChangeToTitleCase);
/* Previews */
this.userSettingService.SetUserSetting(UserSettingConstants.VLC_Path, this.VLCPath);
/* Audio and Subtitles */
this.userSettingService.SetUserSetting(UserSettingConstants.NativeLanguage, this.SelectedPreferredLangauge);
StringCollection collection = new StringCollection();
collection.AddRange(this.SelectedLangauges.ToArray());
this.userSettingService.SetUserSetting(UserSettingConstants.SelectedLanguages, collection);
this.userSettingService.SetUserSetting(UserSettingConstants.AddOnlyOneAudioPerLanguage, this.AddOnlyOneAudioTrackPerLanguage);
this.userSettingService.SetUserSetting(UserSettingConstants.UseClosedCaption, this.AddClosedCaptions);
this.userSettingService.SetUserSetting(UserSettingConstants.DubModeAudio, this.SelectedAddAudioMode);
this.userSettingService.SetUserSetting(UserSettingConstants.DubModeSubtitle, this.SelectedAddSubtitleMode);
/* System and Logging */
userSettingService.SetUserSetting(ASUserSettingConstants.ProcessPriority, this.SelectedPriority);
userSettingService.SetUserSetting(ASUserSettingConstants.PreventSleep, this.PreventSleep);
userSettingService.SetUserSetting(ASUserSettingConstants.Verbosity, this.SelectedVerbosity);
userSettingService.SetUserSetting(ASUserSettingConstants.SaveLogWithVideo, this.CopyLogToEncodeDirectory);
userSettingService.SetUserSetting(ASUserSettingConstants.SaveLogToCopyDirectory, this.CopyLogToSepcficedLocation);
userSettingService.SetUserSetting(ASUserSettingConstants.SaveLogCopyDirectory, this.LogDirectory);
userSettingService.SetUserSetting(UserSettingConstants.ClearOldLogs, this.ClearOldOlgs);
/* Advanced */
userSettingService.SetUserSetting(UserSettingConstants.MainWindowMinimize, this.MinimiseToTray);
userSettingService.SetUserSetting(UserSettingConstants.TrayIconAlerts, this.DisplayStatusMessagesTrayIcon);
userSettingService.SetUserSetting(UserSettingConstants.QueryEditorTab, this.EnableQueryEditor);
userSettingService.SetUserSetting(UserSettingConstants.PromptOnUnmatchingQueries, this.PromptOnDifferentQuery);
userSettingService.SetUserSetting(UserSettingConstants.PresetNotification, this.DisablePresetUpdateCheckNotification);
userSettingService.SetUserSetting(ASUserSettingConstants.ShowCLI, this.ShowCliWindow);
userSettingService.SetUserSetting(ASUserSettingConstants.PreviewScanCount, this.SelectedPreviewCount);
userSettingService.SetUserSetting(ASUserSettingConstants.X264Step, double.Parse(this.SelectedGranulairty));
int value;
if (int.TryParse(this.MinLength.ToString(), out value))
{
this.userSettingService.SetUserSetting(ASUserSettingConstants.MinScanDuration, value);
}
userSettingService.SetUserSetting(ASUserSettingConstants.DisableLibDvdNav, this.DisableLibdvdNav);
}
}
}