]> granicus.if.org Git - handbrake/commitdiff
WinGui:
authorsr55 <sr55.hb@outlook.com>
Tue, 14 Apr 2009 22:41:45 +0000 (22:41 +0000)
committersr55 <sr55.hb@outlook.com>
Tue, 14 Apr 2009 22:41:45 +0000 (22:41 +0000)
- Patch by ExDeus - http://forum.handbrake.fr/viewtopic.php?f=4&t=9642&start=25#p54267
- Few redundant code functions removed, code layout tweaks.

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

win/C#/Controls/x264Panel.cs
win/C#/Functions/Main.cs
win/C#/Functions/PresetLoader.cs
win/C#/frmMain.Designer.cs
win/C#/frmMain.cs

index 6790bb7439a1ef64efb064eb3495cf7f49ddabcd..dd1572abbe2f56ab38cff39766f91d7cc23fade1 100644 (file)
@@ -8,6 +8,11 @@ namespace Handbrake.Controls
         public x264Panel()\r
         {\r
             InitializeComponent();\r
+\r
+            if (Properties.Settings.Default.tooltipEnable == "Checked")\r
+                setToolTipActive(true);\r
+\r
+            reset2Defaults();\r
         }\r
 \r
         public string x264Query\r
index a7e0626b55136e74ce2c1ca20ba6cb698b8a8d5e..93b29399cf97eba6d602b22e08bc80f877e59c71 100644 (file)
@@ -278,9 +278,8 @@ namespace Handbrake.Functions
         /// Get's HandBrakes version data from the CLI.\r
         /// </summary>\r
         /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>\r
-        public ArrayList getCliVersionData()\r
+        public void setCliVersionData()\r
         {\r
-            ArrayList cliVersionData = new ArrayList();\r
             String line;\r
 \r
             // 0 = SVN Build / Version\r
@@ -298,6 +297,7 @@ namespace Handbrake.Functions
             try\r
             {\r
                 cliProcess.Start();\r
+                cliProcess.Kill();\r
                 // Retrieve standard output and report back to parent thread until the process is complete\r
                 TextReader stdOutput = cliProcess.StandardError;\r
 \r
@@ -310,9 +310,9 @@ namespace Handbrake.Functions
                     {\r
                         string data = line.Replace("(", "").Replace(")", "").Replace("HandBrake ", "");\r
                         string[] arr = data.Split(' ');\r
-                        cliVersionData.Add(arr[0]);\r
-                        cliVersionData.Add(arr[1]);\r
-                        return cliVersionData;\r
+\r
+                        Properties.Settings.Default.hb_build = int.Parse(arr[1]);\r
+                        Properties.Settings.Default.hb_version = arr[0];\r
                     }\r
                     if (cliProcess.TotalProcessorTime.Seconds > 10) // Don't wait longer than 10 seconds.\r
                         killCLI();\r
@@ -323,10 +323,6 @@ namespace Handbrake.Functions
             {\r
                 MessageBox.Show("Unable to retrieve version information from the CLI. \nError:\n" + e);\r
             }\r
-\r
-            cliVersionData.Add(0);\r
-            cliVersionData.Add("0");\r
-            return cliVersionData;\r
         }\r
         private static void killCLI()\r
         {\r
index 21bd5f974dd048f3b95beb8c9fa8ba74cc14b9fb..53cc363aa04ee5d4fdfbd1205382500aef453ca3 100644 (file)
@@ -14,13 +14,12 @@ namespace Handbrake.Functions
         /// <param name="presetQuery">The Parsed CLI Query</param>\r
         /// <param name="name">Name of the preset</param>\r
         /// <param name="pictureSettings">Save picture settings in the preset</param>\r
-        public static void presetLoader(frmMain mainWindow, Functions.QueryParser presetQuery, string name, Boolean pictureSettings)\r
+        public static void presetLoader(frmMain mainWindow, QueryParser presetQuery, string name, Boolean pictureSettings)\r
         {\r
             // ---------------------------\r
             // Setup the GUI\r
             // ---------------------------\r
 \r
-            // Source tab\r
             #region source\r
             // Reset some vaules to stock first to prevent errors.\r
             mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;\r
@@ -37,7 +36,6 @@ namespace Handbrake.Functions
 \r
             #endregion\r
 \r
-            // Destination tab\r
             #region destination\r
 \r
             mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;\r
@@ -59,9 +57,12 @@ namespace Handbrake.Functions
 \r
             mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4 ? CheckState.Checked : CheckState.Unchecked;\r
 \r
+            mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;\r
+\r
+            mainWindow.setContainerOpts(); // select the container options according to the selected format\r
+\r
             #endregion\r
 \r
-            // Picture Settings Tab\r
             #region Picture\r
             mainWindow.check_autoCrop.Checked = true;\r
             if (presetQuery.CropBottom == "0" && presetQuery.CropTop == "0")\r
@@ -122,7 +123,6 @@ namespace Handbrake.Functions
 \r
             #endregion\r
 \r
-            // Filters Tab\r
             #region Filters\r
 \r
             mainWindow.ctl_decomb.setOption(presetQuery.Decomb);\r
@@ -147,8 +147,7 @@ namespace Handbrake.Functions
             }\r
             #endregion\r
 \r
-            // Video Settings Tab\r
-            #region video\r
+            #region Video\r
             if (presetQuery.AverageVideoBitrate != null)\r
             {\r
                 mainWindow.radio_avgBitrate.Checked = true;\r
@@ -209,16 +208,8 @@ namespace Handbrake.Functions
 \r
             mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;\r
 \r
-            if (presetQuery.LargeMP4)\r
-                mainWindow.check_largeFile.CheckState = CheckState.Checked;\r
-            else\r
-            {\r
-                mainWindow.check_largeFile.CheckState = CheckState.Unchecked;\r
-                mainWindow.check_largeFile.BackColor = Color.Transparent;\r
-            }\r
             #endregion\r
 \r
-            // Chapter Markers Tab\r
             #region Chapter Markers\r
 \r
             if (presetQuery.ChapterMarkers)\r
@@ -231,7 +222,6 @@ namespace Handbrake.Functions
 \r
             #endregion\r
 \r
-            // Audio Settings Tab\r
             #region Audio\r
             // Clear the audio listing\r
             mainWindow.lv_audioList.Items.Clear();\r
@@ -295,8 +285,7 @@ namespace Handbrake.Functions
 \r
             #endregion\r
 \r
-            // H264 Tab & Preset Name\r
-            #region other\r
+            #region Other\r
             mainWindow.x264Panel.x264Query = presetQuery.H264Query;\r
 \r
             // Set the preset name\r
index 31a435507514ad8afdd45c9db12faafbd466d5ca..6f5afee36e06dbc43311827b4bd9c2b061849e05 100644 (file)
@@ -273,7 +273,6 @@ namespace Handbrake
             // \r
             // DVD_Save\r
             // \r
-            this.DVD_Save.CheckFileExists = true;\r
             this.DVD_Save.Filter = "mp4|*.mp4|m4v|*.m4v|mkv|*.mkv";\r
             this.DVD_Save.SupportMultiDottedExtensions = true;\r
             // \r
index ded23908be49219afed72ff35aed7312dc973f8d..759a1023d7e047ff2a25404444c25a8fe04cf3f8 100644 (file)
@@ -14,31 +14,34 @@ using System.Diagnostics;
 using System.Threading;\r
 using Handbrake.Functions;\r
 using Handbrake.Presets;\r
+using Handbrake.Queue;\r
+using Handbrake.Parsing;\r
 \r
 namespace Handbrake\r
 {\r
     public partial class frmMain : Form\r
     {\r
         // Objects which may be used by one or more other objects\r
-        private delegate void UpdateWindowHandler();\r
         Main hb_common_func = new Main();\r
         Encode encodeHandler = new Encode();\r
-        Queue.QueueHandler encodeQueue = new Queue.QueueHandler();\r
+        QueueHandler encodeQueue = new QueueHandler();\r
         PresetsHandler presetHandler = new PresetsHandler();\r
-        Parsing.Title selectedTitle;\r
-        Parsing.DVD thisDVD;\r
-\r
-        // Objects belonging to this window only\r
         QueryGenerator queryGen = new QueryGenerator();\r
 \r
         // Globals: Mainly used for tracking.\r
+        Title selectedTitle;\r
+        DVD thisDVD;\r
+        Process hbproc;\r
         private frmQueue queueWindow;\r
         private frmPreview qtpreview;\r
+        private Form splash;\r
         private string lastAction;\r
         public int maxWidth;\r
         public int maxHeight;\r
-        Process hbproc;\r
-        private Form splash;\r
+\r
+        // Delegates\r
+        private delegate void UpdateWindowHandler();\r
+        private delegate void updateStatusChanger();\r
 \r
         // Applicaiton Startup ************************************************\r
 \r
@@ -46,28 +49,25 @@ namespace Handbrake
 \r
         public frmMain()\r
         {\r
-            // Load the splash screen in this thread\r
+            // Load and setup the splash screen in this thread\r
             splash = new frmSplashScreen();\r
             splash.Show();\r
-\r
-            //Create a label that can be updated from the parent thread.\r
             Label lblStatus = new Label { Size = new Size(250, 20), Location = new Point(10, 280) };\r
             splash.Controls.Add(lblStatus);\r
+\r
             InitializeComponent();\r
 \r
             // Update the users config file with the CLI version data.\r
             lblStatus.Text = "Setting Version Data ...";\r
             Application.DoEvents();\r
-            ArrayList x = hb_common_func.getCliVersionData();\r
-            Properties.Settings.Default.hb_build = int.Parse(x[1].ToString());\r
-            Properties.Settings.Default.hb_version = x[0].ToString();\r
+            hb_common_func.setCliVersionData();\r
 \r
-            // show the form, but leave disabled until preloading is complete then show the main form\r
+            // Show the form, but leave disabled until preloading is complete then show the main form\r
             this.Enabled = false;\r
             this.Show();\r
             Application.DoEvents(); // Forces frmMain to draw\r
 \r
-            // update the status\r
+            // Check for new versions, if update checking is enabled\r
             if (Properties.Settings.Default.updateStatus == "Checked")\r
             {\r
                 lblStatus.Text = "Checking for updates ...";\r
@@ -80,7 +80,6 @@ namespace Handbrake
             // Setup the GUI components\r
             lblStatus.Text = "Setting up the GUI ...";\r
             Application.DoEvents();\r
-            x264Panel.reset2Defaults(); // Initialize all the x264 widgets to their default values\r
             loadPresetPanel();                       // Load the Preset Panel\r
             treeView_presets.ExpandAll();\r
             lbl_encode.Text = "";\r
@@ -92,7 +91,6 @@ namespace Handbrake
             // Load the user's default settings or Normal Preset\r
             if (Properties.Settings.Default.defaultSettings == "Checked" && Properties.Settings.Default.defaultPreset != "")\r
             {\r
-                // Ok, so, we've selected a preset. Now we want to load it.\r
                 if (presetHandler.getPreset(Properties.Settings.Default.defaultPreset) != null)\r
                 {\r
                     string query = presetHandler.getPreset(Properties.Settings.Default.defaultPreset).Query;\r
@@ -120,10 +118,7 @@ namespace Handbrake
 \r
             // Enabled GUI tooltip's if Required\r
             if (Properties.Settings.Default.tooltipEnable == "Checked")\r
-            {\r
-                x264Panel.setToolTipActive(true);\r
                 ToolTip.Active = true;\r
-            }\r
 \r
             //Finished Loading\r
             lblStatus.Text = "Loading Complete!";\r
@@ -139,8 +134,7 @@ namespace Handbrake
             queueRecovery();\r
         }\r
 \r
-        // Startup Functions\r
-        private delegate void updateStatusChanger();\r
+        // Startup Functions   \r
         private void startupUpdateCheck()\r
         {\r
             try\r
@@ -226,7 +220,7 @@ namespace Handbrake
         }\r
         private void encodeStarted(object sender, EventArgs e)\r
         {\r
-            setLastAction("encode");\r
+            lastAction = "encode";\r
             setEncodeStarted();\r
         }\r
         private void encodeEnded(object sender, EventArgs e)\r
@@ -978,8 +972,10 @@ namespace Handbrake
         {\r
             // This removes the file extension from the filename box on the save file dialog.\r
             // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.\r
-            if (Path.HasExtension(text_destination.Text))\r
-                DVD_Save.FileName = Path.Combine(Path.GetDirectoryName(text_destination.Text), Path.GetFileNameWithoutExtension(text_destination.Text));\r
+            DVD_Save.FileName = Path.GetFileNameWithoutExtension(text_destination.Text);\r
+\r
+            if (Path.IsPathRooted(text_destination.Text))\r
+                DVD_Save.InitialDirectory = Path.GetDirectoryName(text_destination.Text);\r
 \r
             // Show the dialog and set the main form file path\r
             if (drop_format.SelectedIndex.Equals(0))\r
@@ -994,13 +990,31 @@ namespace Handbrake
                 if (DVD_Save.FileName.StartsWith("\\"))\r
                     MessageBox.Show("Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
                 else\r
-                {\r
-                    setAudioByContainer(DVD_Save.FileName);\r
+                {   \r
+                    // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames\r
+                    switch (DVD_Save.FilterIndex)\r
+                    {\r
+                        case 1:\r
+                            if (!Path.GetExtension(DVD_Save.FileName).Equals(".mp4", StringComparison.InvariantCultureIgnoreCase))\r
+                                DVD_Save.FileName += ".mp4";        \r
+                            break;    \r
+                        case 2:\r
+                            if (!Path.GetExtension(DVD_Save.FileName).Equals(".m4v", StringComparison.InvariantCultureIgnoreCase))   \r
+                                DVD_Save.FileName += ".m4v";     \r
+                            break;  \r
+                        case 3:   \r
+                            if (!Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))     \r
+                                DVD_Save.FileName += ".mkv";   \r
+                            break;   \r
+                        default:   \r
+                            //do nothing  \r
+                            break; \r
+                    }\r
                     text_destination.Text = DVD_Save.FileName;\r
 \r
                     // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)\r
                     if (Check_ChapterMarkers.Checked)\r
-                        text_destination.Text = text_destination.Text.Replace(".mp4", ".m4v");\r
+                        drop_format.SelectedIndex = 1;\r
                 }\r
             }\r
         }\r
@@ -1038,21 +1052,7 @@ namespace Handbrake
         //Video Tab\r
         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            if ((text_destination.Text.Contains(".mp4")) || (text_destination.Text.Contains(".m4v")))\r
-            {\r
-                check_largeFile.Enabled = true;\r
-                check_optimiseMP4.Enabled = true;\r
-                check_iPodAtom.Enabled = true;\r
-            }\r
-            else\r
-            {\r
-                check_largeFile.Enabled = false;\r
-                check_optimiseMP4.Enabled = false;\r
-                check_iPodAtom.Enabled = false;\r
-                check_largeFile.Checked = false;\r
-                check_optimiseMP4.Checked = false;\r
-                check_iPodAtom.Checked = false;\r
-            }\r
+            setContainerOpts();\r
 \r
             //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
             if (drp_videoEncoder.Text.Contains("H.264"))\r
@@ -1061,7 +1061,7 @@ namespace Handbrake
                     check_turbo.Enabled = true;\r
 \r
                 h264Tab.Enabled = true;\r
-                if ((text_destination.Text.Contains(".mp4")) || (text_destination.Text.Contains(".m4v")))\r
+                if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))\r
                     check_iPodAtom.Enabled = true;\r
                 else\r
                     check_iPodAtom.Enabled = false;\r
@@ -1121,6 +1121,28 @@ namespace Handbrake
                     break;\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Set the container format options\r
+        /// </summary>\r
+        public void setContainerOpts()\r
+        {\r
+            if ((text_destination.Text.Contains(".mp4")) || (text_destination.Text.Contains(".m4v")))\r
+            {\r
+                check_largeFile.Enabled = true;\r
+                check_optimiseMP4.Enabled = true;\r
+                check_iPodAtom.Enabled = true;\r
+            }\r
+            else\r
+            {\r
+                check_largeFile.Enabled = false;\r
+                check_optimiseMP4.Enabled = false;\r
+                check_iPodAtom.Enabled = false;\r
+                check_largeFile.Checked = false;\r
+                check_optimiseMP4.Checked = false;\r
+                check_iPodAtom.Checked = false;\r
+            }\r
+        }\r
         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
         {\r
             switch (drp_videoEncoder.Text)\r
@@ -1728,6 +1750,64 @@ namespace Handbrake
         }\r
         #endregion\r
 \r
+        #region GUI\r
+        /// <summary>\r
+        /// Set the GUI to it's finished encoding state.\r
+        /// </summary>\r
+        private void setEncodeFinished()\r
+        {\r
+            try\r
+            {\r
+                if (InvokeRequired)\r
+                {\r
+                    BeginInvoke(new UpdateWindowHandler(setEncodeFinished));\r
+                    return;\r
+                }\r
+\r
+                lbl_encode.Text = "Encoding Finished";\r
+                btn_start.Text = "Start";\r
+                btn_start.ToolTipText = "Start the encoding process";\r
+                btn_start.Image = Properties.Resources.Play;\r
+\r
+                // If the window is minimized, display the notification in a popup.\r
+                if (FormWindowState.Minimized == this.WindowState)\r
+                {\r
+                    notifyIcon.BalloonTipText = lbl_encode.Text;\r
+                    notifyIcon.ShowBalloonTip(500);\r
+                }\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show(exc.ToString());\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Set the GUI to it's started encoding state.\r
+        /// </summary>\r
+        private void setEncodeStarted()\r
+        {\r
+            try\r
+            {\r
+                if (InvokeRequired)\r
+                {\r
+                    BeginInvoke(new UpdateWindowHandler(setEncodeStarted));\r
+                    return;\r
+                }\r
+\r
+                lbl_encode.Visible = true;\r
+                lbl_encode.Text = "Encoding in Progress";\r
+                btn_start.Text = "Stop";\r
+                btn_start.ToolTipText = "Stop the encoding process. \nWarning: This may break your file. Press ctrl-c in the CLI window if you wish it to exit cleanly.";\r
+                btn_start.Image = Properties.Resources.stop;\r
+            }\r
+            catch (Exception exc)\r
+            {\r
+                MessageBox.Show(exc.ToString());\r
+            }\r
+        }\r
+        #endregion\r
+\r
         #region DVD Drive Detection\r
         // Source Button Drive Detection\r
         private delegate void ProgressUpdateHandler();\r
@@ -1895,81 +1975,6 @@ namespace Handbrake
         #endregion\r
 \r
         #region Public Methods\r
-\r
-        /// <summary>\r
-        /// Setup the GUI for Encoding or finished Encoding.\r
-        /// 1 = Encode Running\r
-        /// 0 = Encode Finished.\r
-        /// </summary>\r
-        public void setEncodeFinished()\r
-        {\r
-            try\r
-            {\r
-                if (InvokeRequired)\r
-                {\r
-                    BeginInvoke(new UpdateWindowHandler(setEncodeFinished));\r
-                    return;\r
-                }\r
-\r
-                lbl_encode.Text = "Encoding Finished";\r
-                btn_start.Text = "Start";\r
-                btn_start.ToolTipText = "Start the encoding process";\r
-                btn_start.Image = Properties.Resources.Play;\r
-\r
-                // If the window is minimized, display the notification in a popup.\r
-                if (FormWindowState.Minimized == this.WindowState)\r
-                {\r
-                    notifyIcon.BalloonTipText = lbl_encode.Text;\r
-                    notifyIcon.ShowBalloonTip(500);\r
-                }\r
-            }\r
-            catch (Exception exc)\r
-            {\r
-                MessageBox.Show(exc.ToString());\r
-            }\r
-        }\r
-        public void setEncodeStarted()\r
-        {\r
-            try\r
-            {\r
-                if (InvokeRequired)\r
-                {\r
-                    BeginInvoke(new UpdateWindowHandler(setEncodeStarted));\r
-                    return;\r
-                }\r
-\r
-                lbl_encode.Visible = true;\r
-                lbl_encode.Text = "Encoding in Progress";\r
-                btn_start.Text = "Stop";\r
-                btn_start.ToolTipText = "Stop the encoding process. \nWarning: This may break your file. Press ctrl-c in the CLI window if you wish it to exit cleanly.";\r
-                btn_start.Image = Properties.Resources.stop;\r
-            }\r
-            catch (Exception exc)\r
-            {\r
-                MessageBox.Show(exc.ToString());\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Action can be "encode" or "scan"\r
-        /// Set the last action varible in the main window.\r
-        /// This is used to control which log file is displayed when the Activity window is displayed.\r
-        /// </summary>\r
-        /// <param name="last">String</param>\r
-        public void setLastAction(string last)\r
-        {\r
-            this.lastAction = last;\r
-        }\r
-\r
-        /// <summary>\r
-        /// DVD parseing. Pass in a parsed DVD.\r
-        /// </summary>\r
-        /// <param name="dvd"></param>\r
-        public void setStreamReader(Parsing.DVD dvd)\r
-        {\r
-            this.thisDVD = dvd;\r
-        }\r
-\r
         /// <summary>\r
         /// Reload the preset panel display\r
         /// </summary>\r
@@ -2058,7 +2063,6 @@ namespace Handbrake
                 treeView_presets.Nodes.Add(preset_treeview);\r
             }\r
         }\r
-\r
         #endregion\r
 \r
         #region overrides\r