// -------------------------------------------------------------------------------------------------------------------- // // 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.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.Model; using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; using Ookii.Dialogs.Wpf; /// /// The Options View Model /// public class OptionsViewModel : ViewModelBase, IOptionsViewModel { #region Constants and Fields /// /// Backing field for the user setting service. /// private readonly IUserSettingService userSettingService; /// /// The Shell View Model /// private readonly IShellViewModel shellViewModel; /// /// Backing field for the update service. /// private readonly IUpdateService updateService; /// /// 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 libhb features /// private bool disableLibhbFeatures; /// /// The disable p reset update check notification. /// private bool disablePresetUpdateCheckNotification; /// /// 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 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 preferred langauge. /// private string selectedPreferredLangauge; /// /// The selected preferred subtitle language /// private string selectedPreferredSubtitleLangauge; /// /// 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 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(); /// /// The backing field for show advanced passthru options for Audio /// private bool showAdvancedPassthruOpts; /// /// Backing field for clear queue on encode completed. /// private bool clearQueueOnEncodeCompleted; /// /// The options tab that is selected. /// private OptionsTab selectedTab; /// /// Update Message /// private string updateMessage; /// /// Update Available /// private bool updateAvailable; /// /// Download progress backing field. /// private int downloadProgressPercentage; /// /// Backing field for update info. /// private UpdateCheckInformation updateInfo; /// /// The enable process isolation. /// private bool enableProcessIsolation; /// /// The server port. /// private int serverPort; /// /// The server port. /// private bool enableDebugFeatures; /// /// Backing field for EnableLibHb /// private bool enableLibHb; /// /// The show advanced tab backing field. /// private bool showAdvancedTab; /// /// The remove punctuation. /// private bool removePunctuation; /// /// The use system colours for styles. /// private bool useSystemColoursForStyles; #endregion #region Constructors and Destructors /// /// Initializes a new instance of the class. /// /// /// The user Setting Service. /// /// /// The shell View Model. /// /// /// The update Service. /// public OptionsViewModel(IUserSettingService userSettingService, IShellViewModel shellViewModel, IUpdateService updateService) { this.Title = "Options"; this.userSettingService = userSettingService; this.shellViewModel = shellViewModel; this.updateService = updateService; this.OnLoad(); this.SelectedTab = OptionsTab.General; this.UpdateMessage = "Click 'Check for Updates' to check for new versions"; } #endregion #region Window Properties /// /// Gets or sets SelectedTab. /// public OptionsTab SelectedTab { get { return this.selectedTab; } set { this.selectedTab = value; this.NotifyOfPropertyChange(() => this.SelectedTab); } } /// /// Gets or sets the about view model. /// public IAboutViewModel AboutViewModel { get; set; } #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 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"); } } /// /// Gets or sets a value indicating whether use system colours. /// public bool UseSystemColoursForStylesForStyles { get { return this.useSystemColoursForStyles; } set { this.useSystemColoursForStyles = value; this.NotifyOfPropertyChange(() => UseSystemColoursForStylesForStyles); } } #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"); } } /// /// Gets or sets a value indicating whether remove punctuation. /// public bool RemovePunctuation { get { return this.removePunctuation; } set { this.removePunctuation = value; this.NotifyOfPropertyChange(() => RemovePunctuation); } } #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(() => SelectedPreferredLangauge); } } /// /// Gets or sets SelectedPreferredSubtitleLangauge. /// public string SelectedPreferredSubtitleLangauge { get { return this.selectedPreferredSubtitleLangauge; } set { this.selectedPreferredSubtitleLangauge = value; this.NotifyOfPropertyChange(() => SelectedPreferredSubtitleLangauge); } } /// /// 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"); } } /// /// Gets or sets a value indicating whether ShowAdvancedPassthruOpts. /// public bool ShowAdvancedPassthruOpts { get { return this.showAdvancedPassthruOpts; } set { this.showAdvancedPassthruOpts = value; this.NotifyOfPropertyChange(() => this.ShowAdvancedPassthruOpts); } } #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 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 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 ClearQueueOnEncodeCompleted. /// public bool ClearQueueOnEncodeCompleted { get { return this.clearQueueOnEncodeCompleted; } set { this.clearQueueOnEncodeCompleted = value; this.NotifyOfPropertyChange(() => this.ClearQueueOnEncodeCompleted); } } /// /// Gets or sets a value indicating whether ClearQueueOnEncodeCompleted. /// public bool EnableProcessIsolation { get { return this.enableProcessIsolation; } set { this.enableProcessIsolation = value; this.NotifyOfPropertyChange(() => this.EnableProcessIsolation); } } /// /// Gets or sets the server port. /// public int ServerPort { get { return this.serverPort; } set { this.serverPort = value; this.NotifyOfPropertyChange(() => this.ServerPort); } } /// /// Gets or sets a value indicating whether debug features are enabled. /// public bool EnableDebugFeatures { get { return this.enableDebugFeatures; } set { this.enableDebugFeatures = value; this.NotifyOfPropertyChange(() => this.EnableDebugFeatures); } } /// /// Gets or sets a value indicating whether enable lib hb. /// public bool EnableLibHb { get { return this.enableLibHb; } set { this.enableLibHb = value; this.NotifyOfPropertyChange(() => this.EnableLibHb); } } /// /// Gets or sets a value indicating whether enable lib hb. /// public bool ShowAdvancedTab { get { return this.showAdvancedTab; } set { this.showAdvancedTab = value; this.NotifyOfPropertyChange(() => this.ShowAdvancedTab); } } /// /// Gets or sets a value indicating whether DisableLibdvdNav. /// public bool DisableLibHbFeatures { get { return this.disableLibhbFeatures; } set { this.disableLibhbFeatures = value; this.NotifyOfPropertyChange("DisableLibHbFeatures"); } } #endregion #endregion #region About HandBrake /// /// Gets Version. /// public string Version { get { return string.Format("{0} - {1}", VersionHelper.GetVersion(), VersionHelper.GetPlatformBitnessVersion()); } } /// /// Gets or sets UpdateMessage. /// public string UpdateMessage { get { return this.updateMessage; } set { this.updateMessage = value; this.NotifyOfPropertyChange(() => this.UpdateMessage); } } /// /// Gets or sets a value indicating whether UpdateAvailable. /// public bool UpdateAvailable { get { return this.updateAvailable; } set { this.updateAvailable = value; this.NotifyOfPropertyChange(() => this.UpdateAvailable); } } /// /// Gets or sets DownloadProgressPercentage. /// public int DownloadProgressPercentage { get { return this.downloadProgressPercentage; } set { this.downloadProgressPercentage = value; this.NotifyOfPropertyChange(() => this.DownloadProgressPercentage); } } #endregion #region Public Methods /// /// Load / Update the user settings. /// protected override void OnActivate() { this.OnLoad(); base.OnActivate(); } /// /// Load User Settings /// public override void OnLoad() { // ############################# // General // ############################# this.CheckForUpdates = this.userSettingService.GetUserSetting(UserSettingConstants.UpdateStatus); // Days between update checks this.checkForUpdatesFrequencies.Clear(); 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 = 0; break; case 7: this.CheckForUpdatesFrequency = 1; break; case 30: this.CheckForUpdatesFrequency = 2; break; } // On Encode Completeion Action this.whenDoneOptions.Clear(); 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(UserSettingConstants.GrowlEncode); this.GrowlAfterQueue = userSettingService.GetUserSetting(UserSettingConstants.GrowlQueue); this.SendFileAfterEncode = this.userSettingService.GetUserSetting(UserSettingConstants.SendFile); this.SendFileTo = Path.GetFileNameWithoutExtension(this.userSettingService.GetUserSetting(UserSettingConstants.SendFileTo)) ?? string.Empty; this.SendFileToPath = this.userSettingService.GetUserSetting(UserSettingConstants.SendFileTo) ?? string.Empty; this.Arguments = this.userSettingService.GetUserSetting(UserSettingConstants.SendFileToArgs) ?? string.Empty; this.UseSystemColoursForStylesForStyles = this.userSettingService.GetUserSetting(UserSettingConstants.UseSystemColours); // ############################# // 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.Clear(); 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); this.RemovePunctuation = this.userSettingService.GetUserSetting(UserSettingConstants.RemovePunctuation); // ############################# // 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(); langList = (from entry in langList orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); this.selectedLangauges.Clear(); 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); } } this.preferredLanguages.Clear(); this.availableLanguages.Clear(); foreach (string item in langList.Keys) { this.preferredLanguages.Add(item); // In the available languages should be no "Any" and no selected language. if ((item != Constants.Any) && (!this.userSettingService.GetUserSetting(UserSettingConstants.SelectedLanguages).Contains(item))) { this.availableLanguages.Add(item); } } this.SelectedPreferredLangauge = this.userSettingService.GetUserSetting(UserSettingConstants.NativeLanguage) ?? string.Empty; this.SelectedPreferredSubtitleLangauge = this.userSettingService.GetUserSetting(UserSettingConstants.NativeLanguageForSubtitles) ?? string.Empty; this.AddAudioModeOptions.Clear(); this.AddAudioModeOptions.Add("None"); this.AddAudioModeOptions.Add("Add All Remaining Tracks"); this.AddAudioModeOptions.Add("Add All for Selected Languages"); this.AddSubtitleModeOptions.Clear(); this.AddSubtitleModeOptions.Add("None"); this.AddSubtitleModeOptions.Add("Add All (Where possible)"); this.AddSubtitleModeOptions.Add("Add First"); this.AddSubtitleModeOptions.Add("Add all for Selected Languages"); this.AddSubtitleModeOptions.Add("Add only for Prefered Language (First)"); this.AddSubtitleModeOptions.Add("Add all for Prefered Language"); 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); this.ShowAdvancedPassthruOpts = this.userSettingService.GetUserSetting(UserSettingConstants.ShowAdvancedAudioPassthruOpts); // ############################# // CLI // ############################# // Priority level for encodes this.priorityLevelOptions.Clear(); 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(UserSettingConstants.PreventSleep); // Log Verbosity Level this.logVerbosityOptions.Clear(); 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.MinimiseToTray = this.userSettingService.GetUserSetting(UserSettingConstants.MainWindowMinimize); this.DisablePresetUpdateCheckNotification = this.userSettingService.GetUserSetting(UserSettingConstants.PresetNotification); this.ClearQueueOnEncodeCompleted = userSettingService.GetUserSetting(ASUserSettingConstants.ClearCompletedFromQueue); this.ShowAdvancedTab = userSettingService.GetUserSetting(UserSettingConstants.ShowAdvancedTab); // Set the preview count this.PreviewPicturesToScan.Clear(); this.PreviewPicturesToScan.Add(10); this.PreviewPicturesToScan.Add(15); this.PreviewPicturesToScan.Add(20); this.PreviewPicturesToScan.Add(25); this.PreviewPicturesToScan.Add(30); this.PreviewPicturesToScan.Add(35); this.PreviewPicturesToScan.Add(40); this.PreviewPicturesToScan.Add(45); this.PreviewPicturesToScan.Add(50); this.PreviewPicturesToScan.Add(55); this.PreviewPicturesToScan.Add(60); this.SelectedPreviewCount = this.userSettingService.GetUserSetting(ASUserSettingConstants.PreviewScanCount); // x264 step this.ConstantQualityGranularity.Clear(); this.ConstantQualityGranularity.Add("1.00"); this.ConstantQualityGranularity.Add("0.50"); this.ConstantQualityGranularity.Add("0.25"); this.SelectedGranulairty = userSettingService.GetUserSetting(UserSettingConstants.X264Step).ToString("0.00", CultureInfo.InvariantCulture); // Min Title Length this.MinLength = this.userSettingService.GetUserSetting(ASUserSettingConstants.MinScanDuration); // Use dvdnav this.DisableLibdvdNav = userSettingService.GetUserSetting(ASUserSettingConstants.DisableLibDvdNav); int port; int.TryParse(userSettingService.GetUserSetting(UserSettingConstants.ServerPort), out port); this.ServerPort = port; this.EnableProcessIsolation = userSettingService.GetUserSetting(UserSettingConstants.EnableProcessIsolation); this.EnableDebugFeatures = userSettingService.GetUserSetting(UserSettingConstants.EnableDebugFeatures); this.EnableLibHb = userSettingService.GetUserSetting(UserSettingConstants.EnableLibHb); // LibHbFeatures this.DisableLibHbFeatures = userSettingService.GetUserSetting(UserSettingConstants.DisableLibHbFeatures); } /// /// Close this window. /// public void Close() { this.Save(); this.shellViewModel.DisplayWindow(ShellWindow.MainWindow); } /// /// 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 LanguageMoveRight() { if (this.SelectedAvailableToMove.Count > 0) { List copiedList = SelectedAvailableToMove.ToList(); foreach (string item in copiedList) { this.AvailableLanguages.Remove(item); this.SelectedLangauges.Add(item); } this.AvailableLanguages = new BindingList(this.AvailableLanguages.OrderBy(o => o).ToList()); } } /// /// Audio List Move Right /// public void LanguageMoveLeft() { if (this.SelectedLangaugesToMove.Count > 0) { List copiedList = SelectedLangaugesToMove.ToList(); foreach (string item in copiedList) { this.SelectedLangauges.Remove(item); this.AvailableLanguages.Add(item); } } this.AvailableLanguages = new BindingList(this.AvailableLanguages.OrderBy(o => o).ToList()); } /// /// Audio List Clear all selected languages /// public void LanguageClearAll() { foreach (string item in this.SelectedLangauges) { this.AvailableLanguages.Add(item); } this.AvailableLanguages = new BindingList(this.AvailableLanguages.OrderBy(o => o).ToList()); this.SelectedLangauges.Clear(); } /// /// 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 #region Updates /// /// Download an Update /// public void DownloadUpdate() { this.UpdateMessage = "Preparing for Update ..."; this.updateService.DownloadFile(this.updateInfo.DownloadFile, this.DownloadComplete, this.DownloadProgress); } /// /// Check for updates /// public void PerformUpdateCheck() { this.UpdateMessage = "Checking for Updates ..."; this.updateService.CheckForUpdates(this.UpdateCheckComplete); } #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.WhenCompleteAction, this.WhenDone); this.userSettingService.SetUserSetting(UserSettingConstants.GrowlQueue, this.GrowlAfterQueue); this.userSettingService.SetUserSetting(UserSettingConstants.GrowlEncode, this.GrowlAfterEncode); this.userSettingService.SetUserSetting(UserSettingConstants.SendFileTo, this.SendFileToPath); this.userSettingService.SetUserSetting(UserSettingConstants.SendFile, this.SendFileAfterEncode); this.userSettingService.SetUserSetting(UserSettingConstants.SendFileToArgs, this.Arguments); this.userSettingService.SetUserSetting(UserSettingConstants.UseSystemColours, this.UseSystemColoursForStylesForStyles); /* 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); this.userSettingService.SetUserSetting(UserSettingConstants.RemovePunctuation, this.RemovePunctuation); /* Previews */ this.userSettingService.SetUserSetting(UserSettingConstants.VLC_Path, this.VLCPath); /* Audio and Subtitles */ this.userSettingService.SetUserSetting(UserSettingConstants.NativeLanguage, this.SelectedPreferredLangauge); this.userSettingService.SetUserSetting(UserSettingConstants.NativeLanguageForSubtitles, this.SelectedPreferredSubtitleLangauge); 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); this.userSettingService.SetUserSetting(UserSettingConstants.ShowAdvancedAudioPassthruOpts, this.ShowAdvancedPassthruOpts); /* System and Logging */ userSettingService.SetUserSetting(ASUserSettingConstants.ProcessPriority, this.SelectedPriority); userSettingService.SetUserSetting(UserSettingConstants.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.PresetNotification, this.DisablePresetUpdateCheckNotification); userSettingService.SetUserSetting(ASUserSettingConstants.ClearCompletedFromQueue, this.ClearQueueOnEncodeCompleted); userSettingService.SetUserSetting(ASUserSettingConstants.PreviewScanCount, this.SelectedPreviewCount); userSettingService.SetUserSetting(UserSettingConstants.X264Step, double.Parse(this.SelectedGranulairty, CultureInfo.InvariantCulture)); userSettingService.SetUserSetting(UserSettingConstants.ShowAdvancedTab, this.ShowAdvancedTab); userSettingService.SetUserSetting(UserSettingConstants.ShowAdvancedTab, this.ShowAdvancedTab); int value; if (int.TryParse(this.MinLength.ToString(CultureInfo.InvariantCulture), out value)) { this.userSettingService.SetUserSetting(ASUserSettingConstants.MinScanDuration, value); } userSettingService.SetUserSetting(ASUserSettingConstants.DisableLibDvdNav, this.DisableLibdvdNav); userSettingService.SetUserSetting(UserSettingConstants.EnableProcessIsolation, this.EnableProcessIsolation); userSettingService.SetUserSetting(UserSettingConstants.ServerPort, this.ServerPort.ToString()); userSettingService.SetUserSetting(UserSettingConstants.EnableDebugFeatures, this.EnableDebugFeatures); userSettingService.SetUserSetting(UserSettingConstants.DisableLibHbFeatures, this.DisableLibHbFeatures); userSettingService.SetUserSetting(UserSettingConstants.EnableLibHb, this.EnableLibHb); } /// /// Update Check Complete /// /// /// The info. /// private void UpdateCheckComplete(UpdateCheckInformation info) { this.updateInfo = info; if (info.NewVersionAvailable) { this.UpdateMessage = "A New Update is Available!"; this.UpdateAvailable = true; } else { this.UpdateMessage = "There are no new updates at this time."; this.UpdateAvailable = false; } } /// /// Download Progress Action /// /// /// The info. /// private void DownloadProgress(DownloadStatus info) { if (info.TotalBytes == 0 || info.BytesRead == 0) { return; } long p = (info.BytesRead * 100) / info.TotalBytes; int progress; int.TryParse(p.ToString(CultureInfo.InvariantCulture), out progress); this.DownloadProgressPercentage = progress; this.UpdateMessage = string.Format( "Downloading... {0}% - {1}k of {2}k", this.DownloadProgressPercentage, (info.BytesRead / 1024), (info.TotalBytes / 1024)); } /// /// Download Complete Action /// /// /// The info. /// private void DownloadComplete(DownloadStatus info) { this.UpdateAvailable = false; this.UpdateMessage = info.WasSuccessful ? "Update Downloaded" : "Update Failed. You can try downloading the update from http://handbrake.fr"; Process.Start(Path.Combine(Path.GetTempPath(), "handbrake-setup.exe")); Execute.OnUIThread(() => Application.Current.Shutdown()); } /// /// The goto tab. /// /// /// The tab. /// public void GotoTab(OptionsTab tab) { this.SelectedTab = tab; } } }