]> granicus.if.org Git - handbrake/commitdiff
WinGui:
authorsr55 <sr55.hb@outlook.com>
Sat, 27 Mar 2010 16:08:37 +0000 (16:08 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 27 Mar 2010 16:08:37 +0000 (16:08 +0000)
- Audio Panel will now remove all audio tracks from the audio list if the source has no tracks. When changing back to a source / title that has audio tracks, it will re-add audio tracks that are setup in the selected preset. If no preset is selected it will not re add any tracks.
- Fix duplicate preset created when importing macgui preset.
- Fix CQ/Filesize/AvgBitrate settings not being set correctly with macgui preset import.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3174 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/Controls/AudioPanel.cs
win/C#/Presets/PlistPresetHandler.cs
win/C#/frmMain.cs

index b43e6d0283772acce8ce7390725a2890c07e0ba1..1ed84273ca846ff2d3a7814d155d6b3d6ef73d2b 100644 (file)
@@ -9,7 +9,9 @@ namespace Handbrake.Controls
     using System.Collections;\r
     using System.Linq;\r
     using System.Windows.Forms;\r
+    using Functions;\r
     using Parsing;\r
+    using Presets;\r
     using AudioTrack = Model.AudioTrack;\r
 \r
     public partial class AudioPanel : UserControl\r
@@ -116,16 +118,43 @@ namespace Handbrake.Controls
         /// Set the Track list dropdown from the parsed title captured during the scan\r
         /// </summary>\r
         /// <param name="selectedTitle"></param>\r
-        public void SetTrackList(Title selectedTitle)\r
+        public void SetTrackList(Title selectedTitle, Preset preset)\r
         {\r
-            drp_audioTrack.Items.Clear();\r
-            drp_audioTrack.Items.Add("Automatic");\r
-            drp_audioTrack.Items.Add("None");\r
-            drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
+            if (selectedTitle.AudioTracks.Count == 0)\r
+            {\r
+                lv_audioList.Items.Clear();\r
+                drp_audioTrack.Items.Clear();\r
+                drp_audioTrack.Items.Add("None Found");\r
+                drp_audioTrack.SelectedIndex = 0;\r
+                return;\r
+            }\r
+            else\r
+            {\r
+                drp_audioTrack.Items.Clear();\r
+                drp_audioTrack.Items.Add("Automatic");\r
+                drp_audioTrack.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
+\r
+                if (lv_audioList.Items.Count == 0 && preset != null)\r
+                {\r
+                    QueryParser parsed = QueryParser.Parse(preset.Query);\r
+                    foreach (AudioTrack audioTrack in parsed.AudioInformation)\r
+                    {\r
+                        ListViewItem newTrack = new ListViewItem(GetNewID().ToString());\r
+                        newTrack.SubItems.Add(audioTrack.Track);\r
+                        newTrack.SubItems.Add(audioTrack.Encoder);\r
+                        newTrack.SubItems.Add(audioTrack.MixDown);\r
+                        newTrack.SubItems.Add(audioTrack.SampleRate);\r
+                        newTrack.SubItems.Add(audioTrack.Bitrate);\r
+                        newTrack.SubItems.Add(audioTrack.DRC.ToString());\r
+                        lv_audioList.Items.Add(newTrack);\r
+                    }\r
+                }\r
+\r
+            }\r
 \r
             // Handle Native Language and "Dub Foreign language audio" and "Use Foreign language audio and Subtitles" Options\r
             if (Properties.Settings.Default.NativeLanguage == "Any")\r
-                drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;\r
+                drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 2 ? 1 : 0;\r
             else\r
             {\r
                 if (Properties.Settings.Default.DubAudio) // "Dub Foreign language audio" \r
@@ -155,14 +184,14 @@ namespace Handbrake.Controls
                 }\r
                 else\r
                     drp_audioTrack.SelectedIndex = drp_audioTrack.Items.Count >= 3 ? 2 : 0;\r
-                        // "Use Foreign language audio and Subtitles"\r
+                // "Use Foreign language audio and Subtitles"\r
             }\r
         }\r
 \r
         // Control and ListView\r
         private void controlChanged(object sender, EventArgs e)\r
         {\r
-            Control ctl = (Control) sender;\r
+            Control ctl = (Control)sender;\r
 \r
             switch (ctl.Name)\r
             {\r
@@ -215,7 +244,7 @@ namespace Handbrake.Controls
                     double value;\r
                     if (tb_drc.Value == 0) value = 0;\r
                     else\r
-                        value = ((tb_drc.Value - 1)/10.0) + 1;\r
+                        value = ((tb_drc.Value - 1) / 10.0) + 1;\r
 \r
                     lbl_drc.Text = value.ToString();\r
 \r
@@ -245,7 +274,7 @@ namespace Handbrake.Controls
                 int drcCalculated;\r
                 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text, out drcValue);\r
                 if (drcValue != 0)\r
-                    drcValue = ((drcValue*10) + 1) - 10;\r
+                    drcValue = ((drcValue * 10) + 1) - 10;\r
                 int.TryParse(drcValue.ToString(), out drcCalculated);\r
                 tb_drc.Value = drcCalculated;\r
                 lbl_drc.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[6].Text;\r
@@ -260,9 +289,16 @@ namespace Handbrake.Controls
         // Track Controls\r
         private void btn_addAudioTrack_Click(object sender, EventArgs e)\r
         {\r
+            if (drp_audioTrack.Text == "None Found")\r
+            {\r
+                MessageBox.Show("Your source appears to have no audio tracks that HandBrake supports.", "Warning",\r
+                                MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                return;\r
+            }\r
+\r
             double value = 0;\r
             if (tb_drc.Value != 0)\r
-                value = ((tb_drc.Value - 1)/10.0) + 1;\r
+                value = ((tb_drc.Value - 1) / 10.0) + 1;\r
 \r
             // Create a new row for the Audio list based on the currently selected items in the dropdown.\r
             ListViewItem newTrack = new ListViewItem(GetNewID().ToString());\r
index 4fd08518413a17c3e80d936b696a73241f823e70..142662fd8074b4989c52f8c519fc4b0611c2958c 100644 (file)
@@ -53,8 +53,8 @@ namespace Handbrake.Presets
                 if (!root.HasChildNodes)\r
                 {\r
                     MessageBox.Show(\r
-                        "The Preset file you selected appears to be invlaid or from an older version of HandBrake", \r
-                        "Error", \r
+                        "The Preset file you selected appears to be invlaid or from an older version of HandBrake",\r
+                        "Error",\r
                         MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                     return null;\r
                 }\r
@@ -62,15 +62,15 @@ namespace Handbrake.Presets
             catch (Exception)\r
             {\r
                 MessageBox.Show(\r
-                    "The Preset file you selected appears to be invlaid or from an older version of HandBrake.\n\n Please note, if you are exporting from the MacGui you may need to rebuild your preset so that it uses the current preset plist format.\n The MacGui does not currently update user presets automatically.", \r
-                    "Error", \r
+                    "The Preset file you selected appears to be invlaid or from an older version of HandBrake.\n\n Please note, if you are exporting from the MacGui you may need to rebuild your preset so that it uses the current preset plist format.\n The MacGui does not currently update user presets automatically.",\r
+                    "Error",\r
                     MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
 \r
             // We'll query a query parser object and use it's public var structures to store all the data.\r
             // This will allow the preset loader logic to be used instead of writing custom logic just for this file.\r
             QueryParser queryParsed = new QueryParser();\r
-\r
+            string QualityMode = string.Empty;\r
             /***** Get the Audio Tracks *****/\r
             XmlNode audioListDict = root.ChildNodes[2].ChildNodes[0].FirstChild.ChildNodes[1];\r
             ArrayList AudioInfo = new ArrayList();\r
@@ -113,14 +113,14 @@ namespace Handbrake.Presets
             /***** Get the rest of the settings. *****/\r
             XmlNode presetSettings = root.ChildNodes[2].ChildNodes[0].FirstChild;\r
             for (int i = 2; i < presetSettings.ChildNodes.Count; i += 2)\r
-                // Start from 2 to avoid the audio settings which we don't need.\r
+            // Start from 2 to avoid the audio settings which we don't need.\r
             {\r
                 string key = presetSettings.ChildNodes[i].InnerText;\r
                 string value = presetSettings.ChildNodes[i + 1].InnerText;\r
 \r
                 switch (key)\r
                 {\r
-                        // Output Settings\r
+                    // Output Settings\r
                     case "FileFormat":\r
                         queryParsed.Format = value;\r
                         break;\r
@@ -134,7 +134,7 @@ namespace Handbrake.Presets
                         queryParsed.IpodAtom = value == "1";\r
                         break;\r
 \r
-                        // Picture Settings\r
+                    // Picture Settings\r
                     case "PictureAutoCrop":\r
                         break;\r
                     case "PictureTopCrop":\r
@@ -163,7 +163,7 @@ namespace Handbrake.Presets
                         break;\r
 \r
 \r
-                        // Filters\r
+                    // Filters\r
                     case "PictureDeblock":\r
                         queryParsed.DeBlock = int.Parse(value);\r
                         break;\r
@@ -230,9 +230,9 @@ namespace Handbrake.Presets
                             queryParsed.DeTelecine = value;\r
                         break;\r
 \r
-                        // Video Tab\r
+                    // Video Tab\r
                     case "VideoAvgBitrate":\r
-                        queryParsed.Width = int.Parse(value);\r
+                        queryParsed.AverageVideoBitrate = value;\r
                         break;\r
                     case "VideoEncoder":\r
                         queryParsed.VideoEncoder = value;\r
@@ -246,7 +246,8 @@ namespace Handbrake.Presets
                     case "VideoQualitySlider":\r
                         queryParsed.VideoQuality = float.Parse(value);\r
                         break;\r
-                    case "VideoQualityType":\r
+                    case "VideoQualityType": // The Type of Quality Mode used\r
+                        QualityMode = value;\r
                         break;\r
                     case "VideoTargetSize":\r
                         queryParsed.VideoTargetSize = value;\r
@@ -258,17 +259,17 @@ namespace Handbrake.Presets
                         queryParsed.TwoPass = value == "1";\r
                         break;\r
 \r
-                        // Chapter Markers Tab\r
+                    // Chapter Markers Tab\r
                     case "ChapterMarkers":\r
                         queryParsed.ChapterMarkers = value == "1";\r
                         break;\r
 \r
-                        // Advanced x264 tab\r
+                    // Advanced x264 tab\r
                     case "x264Option":\r
                         queryParsed.H264Query = value;\r
                         break;\r
 \r
-                        // Preset Information\r
+                    // Preset Information\r
                     case "PresetBuildNumber":\r
                         queryParsed.PresetBuildNumber = int.Parse(value);\r
                         break;\r
@@ -292,6 +293,24 @@ namespace Handbrake.Presets
                         break;\r
                 }\r
             }\r
+\r
+            // Kill any Quality values we don't need.\r
+            switch (QualityMode)\r
+            {\r
+                case "0": // FileSize\r
+                    queryParsed.VideoQuality = -1;\r
+                    queryParsed.AverageVideoBitrate = null;\r
+                    break;\r
+                case "1": // Avg Bitrate\r
+                    queryParsed.VideoQuality = -1;\r
+                    queryParsed.VideoTargetSize = null;\r
+                    break;\r
+                case "2": // CQ\r
+                    queryParsed.AverageVideoBitrate = null;\r
+                    queryParsed.VideoTargetSize = null;\r
+                    break;\r
+            }\r
+\r
             return queryParsed;\r
         }\r
 \r
@@ -305,7 +324,7 @@ namespace Handbrake.Presets
 \r
             // Header\r
             Writer.WriteStartDocument();\r
-            Writer.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN", \r
+            Writer.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN",\r
                                 @"http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);\r
 \r
             Writer.WriteStartElement("plist");\r
index 2e9541a029152dba5cd20064e5ad844993fd1cc7..1fb52db5cbcc0260cc775dbd57e1359c38b61998 100644 (file)
@@ -429,7 +429,7 @@ namespace Handbrake
 \r
         private void mnu_importMacPreset_Click(object sender, EventArgs e)\r
         {\r
-            importPreset();\r
+            ImportPreset();\r
         }\r
 \r
         private void btn_new_preset_Click(object sender, EventArgs e)\r
@@ -518,7 +518,7 @@ namespace Handbrake
 \r
         private void pmnu_import_Click(object sender, EventArgs e)\r
         {\r
-            importPreset();\r
+            ImportPreset();\r
         }\r
 \r
         private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
@@ -698,7 +698,7 @@ namespace Handbrake
             }\r
         }\r
 \r
-        private void importPreset()\r
+        private void ImportPreset()\r
         {\r
             if (openPreset.ShowDialog() == DialogResult.OK)\r
             {\r
@@ -720,10 +720,6 @@ namespace Handbrake
                 else\r
                 {\r
                     PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
-                    presetHandler.Add(parsed.PresetName,\r
-                                      QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
-                                      parsed.UsesPictureSettings);\r
-\r
                     if (presetHandler.Add(parsed.PresetName + " (Imported)",\r
                                           QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
                                           parsed.UsesPictureSettings))\r
@@ -1073,7 +1069,7 @@ namespace Handbrake
             drop_chapterFinish.Items.Clear();\r
 \r
             // If the dropdown is set to automatic nothing else needs to be done.\r
-            // Otheriwse if its not, title data has to be loased from parsing.\r
+            // Otheriwse if its not, title data has to be loaded from parsing.\r
             if (drp_dvdtitle.Text != "Automatic")\r
             {\r
                 selectedTitle = drp_dvdtitle.SelectedItem as Title;\r
@@ -1110,7 +1106,7 @@ namespace Handbrake
                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
 \r
                 // Populate the Audio Channels Dropdown\r
-                AudioSettings.SetTrackList(selectedTitle);\r
+                AudioSettings.SetTrackList(selectedTitle, CurrentlySelectedPreset);\r
 \r
                 // Populate the Subtitles dropdown\r
                 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());\r