]> granicus.if.org Git - handbrake/commitdiff
WinGui: Some bug fixes and re-factoring of the preset code.
authorsr55 <sr55.hb@outlook.com>
Sat, 24 Sep 2011 21:52:17 +0000 (21:52 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 24 Sep 2011 21:52:17 +0000 (21:52 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4246 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrake.ApplicationServices/Model/Preset.cs
win/CS/HandBrake.ApplicationServices/Services/PresetService.cs
win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs
win/CS/UserSettingConstants.cs
win/CS/frmMain.cs

index ede38b26f34b833818093baff367f8c60e92fdf9..eedf3f7375a76d6b2edff54d103e0021231bdcfd 100644 (file)
@@ -45,6 +45,11 @@ namespace HandBrake.ApplicationServices.Model
         /// </summary>\r
         public bool IsBuildIn { get; set; }\r
 \r
+        /// <summary>\r
+        /// Gets or sets a value indicating whether IsDefault.\r
+        /// </summary>\r
+        public bool IsDefault { get; set; }\r
+\r
         /// <summary>\r
         ///  Override the ToString Method\r
         /// </summary>\r
index 12afaadbcde6fb67484eda5bc127143f5c34064e..30487f15c746dc1d6f199a38cb681da5e9c664e1 100644 (file)
@@ -13,7 +13,6 @@ namespace HandBrake.ApplicationServices.Services
     using System.Linq;\r
     using System.Text;\r
     using System.Text.RegularExpressions;\r
-    using System.Windows;\r
     using System.Xml.Serialization;\r
 \r
     using HandBrake.ApplicationServices.Exceptions;\r
@@ -87,10 +86,21 @@ namespace HandBrake.ApplicationServices.Services
         }\r
 \r
         /// <summary>\r
-        /// The last preset added.\r
+        /// Gets or sets LastPresetAdded.\r
         /// </summary>\r
         public Preset LastPresetAdded { get; set; }\r
 \r
+        /// <summary>\r
+        /// Gets the DefaultPreset.\r
+        /// </summary>\r
+        public Preset DefaultPreset\r
+        {\r
+            get\r
+            {\r
+                return this.presets.FirstOrDefault(p => p.IsDefault);\r
+            }\r
+        }\r
+\r
         #region Public Methods\r
 \r
         /// <summary>\r
@@ -148,6 +158,11 @@ namespace HandBrake.ApplicationServices.Services
         /// </param>\r
         public void Remove(Preset preset)\r
         {\r
+            if (preset == null || preset.IsDefault)\r
+            {\r
+                return;\r
+            }\r
+\r
             this.presets.Remove(preset);\r
             this.UpdatePresetFiles();\r
         }\r
@@ -163,12 +178,36 @@ namespace HandBrake.ApplicationServices.Services
             List<Preset> removeList = this.presets.Where(p => p.Category == category).ToList();\r
             foreach (Preset preset in removeList)\r
             {\r
+                if (preset.IsDefault)\r
+                {\r
+                    // Skip default preset\r
+                    continue;\r
+                }\r
+\r
                 this.presets.Remove(preset);\r
             }\r
 \r
             this.UpdatePresetFiles();\r
         }\r
 \r
+        /// <summary>\r
+        /// Set Default Preset\r
+        /// </summary>\r
+        /// <param name="name">\r
+        /// The name.\r
+        /// </param>\r
+        public void SetDefault(Preset name)\r
+        {\r
+            foreach (Preset preset in this.presets)\r
+            {\r
+                preset.IsDefault = false;\r
+            }\r
+\r
+            name.IsDefault = true;\r
+            this.UpdatePresetFiles();\r
+        }\r
+\r
+\r
         /// <summary>\r
         /// Get a Preset\r
         /// </summary>\r
@@ -268,6 +307,11 @@ namespace HandBrake.ApplicationServices.Services
                                     IsBuildIn = true\r
                                 };\r
 \r
+                            if (newPreset.Name == "Normal")\r
+                            {\r
+                                newPreset.IsDefault = true;\r
+                            }\r
+\r
                             this.presets.Add(newPreset);\r
                         }\r
                     }\r
index 30b752d7d76b9f00d31bd784308677d4c828caa1..2bbdfffcd6b6cefb9220949eb47908536b73c0a0 100644 (file)
@@ -547,7 +547,7 @@ namespace HandBrake.ApplicationServices.Utilities
             AddEncodeElement(xmlWriter, "PictureWidth", "integer", parsed.Width.ToString());\r
 \r
             // Preset Information\r
-            AddEncodeElement(xmlWriter, "PresetBuildNumber", "string", userSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakeBuild));\r
+            AddEncodeElement(xmlWriter, "PresetBuildNumber", "string", userSettingService.GetUserSetting<int>(ASUserSettingConstants.HandBrakeBuild).ToString());\r
             AddEncodeElement(xmlWriter, "PresetDescription", "string", "No Description");\r
             AddEncodeElement(xmlWriter, "PresetName", "string", preset.Name);\r
             AddEncodeElement(xmlWriter, "Type", "integer", "1"); // 1 is user preset, 0 is built in\r
index 843e0bc9ea4ac9cbde80f1c7d0e9a360e339e8f3..9754bbdc2c6d9fffc62a409ded49428f3e7b2bad 100644 (file)
@@ -12,7 +12,6 @@ namespace Handbrake
     {\r
         public const string UpdateStatus = "updateStatus";\r
         public const string TooltipEnable = "tooltipEnable";\r
-        public const string DefaultPreset = "defaultPreset";\r
         public const string Skipversion = "skipversion";\r
         public const string AutoNaming = "autoNaming";\r
         public const string AutoNamePath = "autoNamePath";\r
index 6687dd54020c3c32283132744abd27b856bd0a66..072b18b2cdc7b8d0b4d1d1ed6858c42b6b2bb2ed 100644 (file)
@@ -182,10 +182,9 @@ namespace Handbrake
                 ToolTip.Active = true;\r
 \r
             // Load the user's default settings or Normal Preset\r
-            if (userSettingService.GetUserSetting<string>(UserSettingConstants.DefaultPreset) != string.Empty\r
-                && presetHandler.GetPreset(userSettingService.GetUserSetting<string>(UserSettingConstants.DefaultPreset)) != null)\r
+            if (this.presetHandler.DefaultPreset != null)\r
             {\r
-                this.loadPreset(userSettingService.GetUserSetting<string>(UserSettingConstants.DefaultPreset));\r
+                this.loadPreset(this.presetHandler.DefaultPreset.Name);\r
             }\r
             else\r
                 loadPreset("Normal");\r
@@ -569,12 +568,7 @@ namespace Handbrake
         /// </param>\r
         private void pmnu_delete_click(object sender, EventArgs e)\r
         {\r
-            if (treeView_presets.SelectedNode != null)\r
-            {\r
-                presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag);\r
-                treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);\r
-            }\r
-            treeView_presets.Select();\r
+            BtnRemovePreset_Click(sender, e);\r
         }\r
 \r
         /// <summary>\r
@@ -639,21 +633,41 @@ namespace Handbrake
                 }\r
                 else\r
                 {\r
+                   Preset preset = treeView_presets.SelectedNode.Tag as Preset;\r
+                   if (preset != null && preset.IsDefault)\r
+                   {\r
+                       MessageBox.Show(\r
+                           "Your default preset can not be deleted. It is a required preset.",\r
+                           "Warning",\r
+                           MessageBoxButtons.OK,\r
+                           MessageBoxIcon.Information);\r
+                   }\r
+\r
                     // Delete the selected item.\r
                     presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag);\r
                 }\r
-                treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);\r
+\r
+                this.LoadPresetPanel();\r
             }\r
 \r
             treeView_presets.Select();\r
+            treeView_presets.ExpandAll();\r
         }\r
 \r
         private void MnuSetDefaultPreset_Click(object sender, EventArgs e)\r
         {\r
             if (treeView_presets.SelectedNode != null)\r
             {\r
-                this.userSettingService.SetUserSetting(UserSettingConstants.DefaultPreset, treeView_presets.SelectedNode.Text);\r
-                MessageBox.Show("New default preset set: " + treeView_presets.SelectedNode.Text, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
+                Preset preset = treeView_presets.SelectedNode.Tag as Preset;\r
+                if (preset != null)\r
+                {\r
+                    MessageBox.Show(\r
+                        "New default preset set: " + treeView_presets.SelectedNode.Text,\r
+                        "Alert",\r
+                        MessageBoxButtons.OK,\r
+                        MessageBoxIcon.Information);\r
+                    this.presetHandler.SetDefault(preset);\r
+                }\r
             }\r
             else\r
                 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
@@ -1548,7 +1562,7 @@ namespace Handbrake
                     text_destination.Text = autoPath;\r
                 else\r
                     MessageBox.Show(\r
-                        "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')",\r
+                        "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')",\r
                         "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             }\r
 \r