From f62a6501bae828a835383e6226f3bd86173e36ae Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 24 Sep 2011 21:52:17 +0000 Subject: WinGui: Some bug fixes and re-factoring of the preset code. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4246 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrake.ApplicationServices/Model/Preset.cs | 5 +++ .../Services/PresetService.cs | 48 +++++++++++++++++++++- .../Utilities/PlistUtility.cs | 2 +- win/CS/UserSettingConstants.cs | 1 - win/CS/frmMain.cs | 40 ++++++++++++------ 5 files changed, 79 insertions(+), 17 deletions(-) (limited to 'win') diff --git a/win/CS/HandBrake.ApplicationServices/Model/Preset.cs b/win/CS/HandBrake.ApplicationServices/Model/Preset.cs index ede38b26f..eedf3f737 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Preset.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Preset.cs @@ -45,6 +45,11 @@ namespace HandBrake.ApplicationServices.Model /// public bool IsBuildIn { get; set; } + /// + /// Gets or sets a value indicating whether IsDefault. + /// + public bool IsDefault { get; set; } + /// /// Override the ToString Method /// diff --git a/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs b/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs index 12afaadbc..30487f15c 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs @@ -13,7 +13,6 @@ namespace HandBrake.ApplicationServices.Services using System.Linq; using System.Text; using System.Text.RegularExpressions; - using System.Windows; using System.Xml.Serialization; using HandBrake.ApplicationServices.Exceptions; @@ -87,10 +86,21 @@ namespace HandBrake.ApplicationServices.Services } /// - /// The last preset added. + /// Gets or sets LastPresetAdded. /// public Preset LastPresetAdded { get; set; } + /// + /// Gets the DefaultPreset. + /// + public Preset DefaultPreset + { + get + { + return this.presets.FirstOrDefault(p => p.IsDefault); + } + } + #region Public Methods /// @@ -148,6 +158,11 @@ namespace HandBrake.ApplicationServices.Services /// public void Remove(Preset preset) { + if (preset == null || preset.IsDefault) + { + return; + } + this.presets.Remove(preset); this.UpdatePresetFiles(); } @@ -163,12 +178,36 @@ namespace HandBrake.ApplicationServices.Services List removeList = this.presets.Where(p => p.Category == category).ToList(); foreach (Preset preset in removeList) { + if (preset.IsDefault) + { + // Skip default preset + continue; + } + this.presets.Remove(preset); } this.UpdatePresetFiles(); } + /// + /// Set Default Preset + /// + /// + /// The name. + /// + public void SetDefault(Preset name) + { + foreach (Preset preset in this.presets) + { + preset.IsDefault = false; + } + + name.IsDefault = true; + this.UpdatePresetFiles(); + } + + /// /// Get a Preset /// @@ -268,6 +307,11 @@ namespace HandBrake.ApplicationServices.Services IsBuildIn = true }; + if (newPreset.Name == "Normal") + { + newPreset.IsDefault = true; + } + this.presets.Add(newPreset); } } diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs index 30b752d7d..2bbdfffcd 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs @@ -547,7 +547,7 @@ namespace HandBrake.ApplicationServices.Utilities AddEncodeElement(xmlWriter, "PictureWidth", "integer", parsed.Width.ToString()); // Preset Information - AddEncodeElement(xmlWriter, "PresetBuildNumber", "string", userSettingService.GetUserSetting(ASUserSettingConstants.HandBrakeBuild)); + AddEncodeElement(xmlWriter, "PresetBuildNumber", "string", userSettingService.GetUserSetting(ASUserSettingConstants.HandBrakeBuild).ToString()); AddEncodeElement(xmlWriter, "PresetDescription", "string", "No Description"); AddEncodeElement(xmlWriter, "PresetName", "string", preset.Name); AddEncodeElement(xmlWriter, "Type", "integer", "1"); // 1 is user preset, 0 is built in diff --git a/win/CS/UserSettingConstants.cs b/win/CS/UserSettingConstants.cs index 843e0bc9e..9754bbdc2 100644 --- a/win/CS/UserSettingConstants.cs +++ b/win/CS/UserSettingConstants.cs @@ -12,7 +12,6 @@ namespace Handbrake { public const string UpdateStatus = "updateStatus"; public const string TooltipEnable = "tooltipEnable"; - public const string DefaultPreset = "defaultPreset"; public const string Skipversion = "skipversion"; public const string AutoNaming = "autoNaming"; public const string AutoNamePath = "autoNamePath"; diff --git a/win/CS/frmMain.cs b/win/CS/frmMain.cs index 6687dd540..072b18b2c 100644 --- a/win/CS/frmMain.cs +++ b/win/CS/frmMain.cs @@ -182,10 +182,9 @@ namespace Handbrake ToolTip.Active = true; // Load the user's default settings or Normal Preset - if (userSettingService.GetUserSetting(UserSettingConstants.DefaultPreset) != string.Empty - && presetHandler.GetPreset(userSettingService.GetUserSetting(UserSettingConstants.DefaultPreset)) != null) + if (this.presetHandler.DefaultPreset != null) { - this.loadPreset(userSettingService.GetUserSetting(UserSettingConstants.DefaultPreset)); + this.loadPreset(this.presetHandler.DefaultPreset.Name); } else loadPreset("Normal"); @@ -569,12 +568,7 @@ namespace Handbrake /// private void pmnu_delete_click(object sender, EventArgs e) { - if (treeView_presets.SelectedNode != null) - { - presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag); - treeView_presets.Nodes.Remove(treeView_presets.SelectedNode); - } - treeView_presets.Select(); + BtnRemovePreset_Click(sender, e); } /// @@ -639,21 +633,41 @@ namespace Handbrake } else { + Preset preset = treeView_presets.SelectedNode.Tag as Preset; + if (preset != null && preset.IsDefault) + { + MessageBox.Show( + "Your default preset can not be deleted. It is a required preset.", + "Warning", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + // Delete the selected item. presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag); } - treeView_presets.Nodes.Remove(treeView_presets.SelectedNode); + + this.LoadPresetPanel(); } treeView_presets.Select(); + treeView_presets.ExpandAll(); } private void MnuSetDefaultPreset_Click(object sender, EventArgs e) { if (treeView_presets.SelectedNode != null) { - this.userSettingService.SetUserSetting(UserSettingConstants.DefaultPreset, treeView_presets.SelectedNode.Text); - MessageBox.Show("New default preset set: " + treeView_presets.SelectedNode.Text, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); + Preset preset = treeView_presets.SelectedNode.Tag as Preset; + if (preset != null) + { + MessageBox.Show( + "New default preset set: " + treeView_presets.SelectedNode.Text, + "Alert", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + this.presetHandler.SetDefault(preset); + } } else MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); @@ -1548,7 +1562,7 @@ namespace Handbrake text_destination.Text = autoPath; else MessageBox.Show( - "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a valid default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'General' Tab -> 'Default Path')", + "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a valid default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'Output Files' Tab -> 'Default Path')", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } -- cgit v1.2.3