OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index def400c..bf00e22 100644 (file)
@@ -1,5 +1,6 @@
 using System;\r
 using System.Collections.Generic;\r
+using System.Collections.Specialized;\r
 using System.ComponentModel;\r
 using System.Data;\r
 using System.Drawing;\r
@@ -9,73 +10,140 @@ using System.Net;
 using System.IO;\r
 using System.Diagnostics;\r
 using System.Threading;\r
+using System.Runtime.InteropServices;\r
+using System.Globalization;\r
+using System.Text.RegularExpressions;\r
 \r
 \r
 namespace Handbrake\r
 {\r
     public partial class frmMain : Form\r
     {\r
+        // -------------------------------------------------------------- \r
+        // Applicaiton Startup Stuff\r
+        // --------------------------------------------------------------\r
+\r
+        #region Application Startup\r
+\r
+        // Some stuff that needs to be Initialized. \r
         private Process hbProc;\r
         private Parsing.DVD thisDVD;\r
+        private frmQueue queueWindow = new frmQueue();\r
 \r
-        // --------------------------------------------------------------\r
-        // Some windows that require only 1 instance.\r
-        // --------------------------------------------------------------\r
-        private frmQueue queueWindow = new frmQueue();  \r
-        \r
-        // -------------------------------------------------------------- \r
-        // Stuff that needs doing on startup.\r
-        // - Load users default settings. (if required)\r
-        // - Do an update check (if required)\r
-        // --------------------------------------------------------------\r
-        private frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
-        \r
+        // The main window beings here...\r
         public frmMain()\r
         {\r
+            // Load the splash screen in this thread\r
+            Form splash = new frmSplashScreen();\r
+            splash.Show();\r
+\r
+            //Create a label that can be updated from the parent thread.\r
+            Label lblStatus = new Label();\r
 \r
+            //Size the label\r
+            lblStatus.Size = new Size(250, 20);\r
 \r
+            //Position the label\r
+            lblStatus.Location = new Point(10, 280);\r
 \r
-            \r
+            //Put the label on the splash form\r
+            splash.Controls.Add(lblStatus);\r
 \r
-            ThreadPool.QueueUserWorkItem(showSplash);\r
-            Thread.Sleep(3000);\r
+            //Fire a thread to wait for 2 seconds.  The splash screen will exit when the time expires\r
+            Thread timer = new Thread(splashTimer);\r
+            timer.Start();\r
 \r
             InitializeComponent();\r
 \r
-            // This is a quick Hack fix for the cross-thread problem with frmDvdIndo ************************\r
-            dvdInfoWindow.Show();\r
-            dvdInfoWindow.Hide();\r
-            // **********************************************************************************************\r
+            // show the form, but leave disabled until preloading is complete\r
+            this.Enabled = false;\r
 \r
+            // Show the main form\r
+            this.Show();\r
+\r
+            // Forces frmMain to draw\r
+            Application.DoEvents();\r
 \r
             // Set the Version number lable to the corect version.\r
-            Version.Text = "Version " + Properties.Settings.Default.GuiVersion;\r
+            Version.Text = "Version " + Properties.Settings.Default.CliVersion;\r
 \r
+            // update the status\r
+            lblStatus.Text = "Checking for updates ...";\r
+            // redraw the splash screen\r
+            Application.DoEvents();\r
             // Run the update checker.\r
             updateCheck();\r
-\r
-            // Now load the users default if required.\r
+            Thread.Sleep(200);\r
+\r
+            // Update the presets\r
+            lblStatus.Text = "Updaing Presets ...";\r
+            Application.DoEvents();\r
+            updatePresets();\r
+            Thread.Sleep(200);\r
+\r
+            // Now load the users default if required. (Will overide the above setting)\r
+            lblStatus.Text = "Loading User Default Settings...";\r
+            Application.DoEvents();\r
+            loadNormalPreset();\r
             loadUserDefaults();\r
+            Thread.Sleep(100);\r
+\r
+            // Enable or disable tooltips\r
+            lblStatus.Text = "Loading Tooltips ...";\r
+            Application.DoEvents();\r
+            tooltip();\r
+            Thread.Sleep(100);\r
 \r
-            // Display the quick start window if required.\r
-            quickStart();\r
+            // Hide the preset bar if required.\r
+            hidePresetBar();\r
 \r
-            //MessageBox.Show(System.Environment.OSVersion.Version.ToString());\r
-        \r
+            //Finished Loading\r
+            lblStatus.Text = "Loading Complete!";\r
+            Application.DoEvents();\r
+            Thread.Sleep(200);\r
+\r
+            // Wait until splash screen is done\r
+            while (timer.IsAlive)\r
+            { Thread.Sleep(100); }\r
+\r
+            //Close the splash screen\r
+            splash.Close();\r
+            splash.Dispose();\r
+\r
+            // Turn the interface back to the user\r
+            this.Enabled = true;\r
         }\r
 \r
-        public void showSplash(object sender)\r
+        private void splashTimer(object sender)\r
         {\r
+            Thread.Sleep(2000);  //sit for 2 seconds then exit\r
+        }\r
+\r
+        private void showSplash(object sender)\r
+        {\r
+            // Display splash screen for 1.5 Seconds\r
             Form splash = new frmSplashScreen();\r
             splash.Show();\r
-            Thread.Sleep(3000);\r
-            splash.Close();\r
+            Thread.Sleep(1500);\r
+            splash.Close(); // Then close.\r
         }\r
 \r
-        public void loadUserDefaults()\r
-        { \r
+        private void loadNormalPreset()\r
+        {\r
+            ListViewItem item = listview_presets.FindItemWithText("Normal");\r
+\r
+            if (item != null)\r
+            {\r
+                listview_presets.SelectedItems.Clear();\r
+                item.Selected = true;\r
+            }\r
+        }\r
+\r
+        private void loadUserDefaults()\r
+        {\r
             try\r
             {\r
+                // Load the users default settings or if the user has not got this option enabled, load the normal preset.\r
                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
                 {\r
                     // Source\r
@@ -108,7 +176,7 @@ namespace Handbrake
                     {\r
                         check_2PassEncode.CheckState = CheckState.Checked;\r
                     }\r
-  \r
+\r
                     drp_deInterlace_option.Text = Properties.Settings.Default.DeInterlace;\r
                     drp_deNoise.Text = Properties.Settings.Default.denoise;\r
 \r
@@ -142,6 +210,12 @@ namespace Handbrake
                     {\r
                         check_largeFile.CheckState = CheckState.Checked;\r
                     }\r
+\r
+                    if (Properties.Settings.Default.chapterMarker == "Checked")\r
+                    {\r
+                        Check_ChapterMarkers.CheckState = CheckState.Checked;\r
+                    }\r
+\r
                     // Audio Settings Tab\r
                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
@@ -153,6 +227,8 @@ namespace Handbrake
                         CheckCRF.CheckState = CheckState.Checked;\r
                     }\r
                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
+\r
+                    groupBox_output.Text = "Output Settings (Preset: " + Properties.Settings.Default.selectedPreset + ")";\r
                 }\r
             }\r
             catch (Exception)\r
@@ -161,146 +237,104 @@ namespace Handbrake
             }\r
         }\r
 \r
-        public void updateCheck()\r
+        private Boolean updateCheck()\r
         {\r
-            if (Properties.Settings.Default.updateStatus == "Checked")\r
+            try\r
             {\r
-                try\r
+                if (Properties.Settings.Default.updateStatus == "Checked")\r
                 {\r
                     String updateFile = Properties.Settings.Default.updateFile;\r
                     WebClient client = new WebClient();\r
                     String data = client.DownloadString(updateFile);\r
                     String[] versionData = data.Split('\n');\r
 \r
-                    if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
-                    {\r
-                        lbl_update.Visible = true;\r
-                    }\r
+                    int verdata = int.Parse(versionData[0].Replace(".", ""));\r
+                    int vergui = int.Parse(Properties.Settings.Default.GuiVersion.Replace(".", ""));\r
+                    int verd1 = int.Parse(versionData[1].Replace(".", ""));\r
+                    int cliversion = int.Parse(Properties.Settings.Default.CliVersion.Replace(".", ""));\r
+\r
+                    Boolean update = ((verdata > vergui) || (verd1 > cliversion));\r
+\r
+                    lbl_update.Visible = update;\r
+\r
+                    return update;\r
                 }\r
-                catch (Exception)\r
+                else\r
                 {\r
-                    // Silently ignore the error\r
+                    return false;\r
                 }\r
             }\r
+            catch (Exception)\r
+            {\r
+                // Silently ignore the error\r
+                return false;\r
+            }\r
+        }\r
+\r
+        private void tooltip()\r
+        {\r
+            if (Properties.Settings.Default.tooltipEnable == "Checked")\r
+            {\r
+                ToolTip.Active = true;\r
+            }\r
         }\r
 \r
-        public void quickStart()\r
+        private void hidePresetBar()\r
         {\r
-            if ((Properties.Settings.Default.QuickStartWindow == "Checked") || (Properties.Settings.Default.QuickStartWindow == ""))\r
+            if (Properties.Settings.Default.hidePresets == "Checked")\r
             {\r
-                frmQuickStart quickstart = new frmQuickStart();\r
-                quickstart.ShowDialog();\r
+                btn_presets.Visible = true;\r
+                this.Width = 591;\r
             }\r
+\r
         }\r
 \r
+        #endregion\r
 \r
         // -------------------------------------------------------------- \r
         // The main Menu bar.\r
         // -------------------------------------------------------------- \r
 \r
         #region File Menu\r
-\r
         private void mnu_open_Click(object sender, EventArgs e)\r
         {\r
             string filename;\r
             File_Open.ShowDialog();\r
             filename = File_Open.FileName;\r
+\r
             if (filename != "")\r
             {\r
                 try\r
                 {\r
-                    // Create StreamReader & open file\r
-                    StreamReader line = new StreamReader(filename);\r
-                    string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
-                    \r
-                    // Read in the data and set the correct GUI component with the setting.\r
-                    text_source.Text = line.ReadLine();\r
-                    drp_dvdtitle.Text = line.ReadLine();\r
-                    drop_chapterStart.Text = line.ReadLine();\r
-                    drop_chapterFinish.Text = line.ReadLine();\r
-                    text_destination.Text = line.ReadLine();\r
-                    drp_videoEncoder.Text = line.ReadLine();\r
-                    drp_audioCodec.Text = line.ReadLine();\r
-                    text_width.Text = line.ReadLine();\r
-                    text_height.Text = line.ReadLine();\r
-                    text_top.Text = line.ReadLine();\r
-                    text_bottom.Text = line.ReadLine();\r
-                    text_left.Text = line.ReadLine();\r
-                    text_right.Text = line.ReadLine();\r
-                    drp_subtitle.Text = line.ReadLine();\r
-                    text_bitrate.Text = line.ReadLine();\r
-                    text_filesize.Text = line.ReadLine();\r
-                    slider_videoQuality.Value = int.Parse(line.ReadLine());\r
-\r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_2PassEncode.CheckState = CheckState.Checked;\r
-                    }\r
-\r
-                    drp_deInterlace_option.Text = line.ReadLine();\r
-\r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_grayscale.CheckState = CheckState.Checked;\r
-                    }\r
+                    // Some things that need to be done to reset some gui components:\r
+                    CheckPixelRatio.CheckState = CheckState.Unchecked;\r
 \r
-                    drp_videoFramerate.Text = line.ReadLine();\r
+                    //---------------------------\r
+                    // Get the Preset\r
+                    // ---------------------------\r
 \r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-                    }\r
-\r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        CheckPixelRatio.CheckState = CheckState.Checked;\r
-                    }\r
+                    // Create StreamReader & open file\r
+                    StreamReader line = new StreamReader(filename);\r
 \r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_turbo.CheckState = CheckState.Checked;\r
-                    }\r
+                    // Send the query from the file to the Query Parser class\r
+                    Functions.QueryParser presetQuery = Functions.QueryParser.Parse(line.ReadLine());\r
 \r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_largeFile.CheckState = CheckState.Checked;\r
-                    }\r
-   \r
-                    drp_audioBitrate.Text = line.ReadLine();\r
-                    drp_audioSampleRate.Text = line.ReadLine();\r
-                    drp_audioChannels.Text = line.ReadLine();\r
-                    drp_audioMixDown.Text = line.ReadLine();\r
-                    \r
-                    // Advanced H264 Options\r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        CheckCRF.CheckState = CheckState.Checked;\r
-                    }\r
-                    rtf_h264advanced.Text = line.ReadLine();\r
+                    // Now load the preset\r
+                    presetLoader(presetQuery, filename);\r
 \r
                     // Close the stream\r
                     line.Close();\r
-\r
-\r
-                    // Fix for SliderValue not appearing when Opening saved file\r
-                    SliderValue.Text = slider_videoQuality.Value + "%";\r
-\r
-                } catch (Exception){\r
+                }\r
+                catch (Exception exc)\r
+                {\r
                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
+                    MessageBox.Show(exc.ToString());\r
                 }\r
             }\r
         }\r
 \r
         private void mnu_save_Click(object sender, EventArgs e)\r
         {\r
-\r
             string filename;\r
             File_Save.ShowDialog();\r
             filename = File_Save.FileName;\r
@@ -311,64 +345,25 @@ namespace Handbrake
                     // Create a StreamWriter and open the file\r
                     StreamWriter line = new StreamWriter(filename);\r
 \r
-                    //Source\r
-                    line.WriteLine(text_source.Text);\r
-                    line.WriteLine(drp_dvdtitle.Text);\r
-                    line.WriteLine(drop_chapterStart.Text);\r
-                    line.WriteLine(drop_chapterFinish.Text);\r
-                    //Destination\r
-                    line.WriteLine(text_destination.Text);\r
-                    line.WriteLine(drp_videoEncoder.Text);\r
-                    line.WriteLine(drp_audioCodec.Text);\r
-                    line.WriteLine(text_width.Text);\r
-                    line.WriteLine(text_height.Text);\r
-                    //Picture Settings Tab\r
-                    line.WriteLine(text_top.Text);\r
-                    line.WriteLine(text_bottom.Text);\r
-                    line.WriteLine(text_left.Text);\r
-                    line.WriteLine(text_right.Text);\r
-                    line.WriteLine(drp_subtitle.Text);\r
-                    //Video Settings Tab\r
-                    line.WriteLine(text_bitrate.Text);\r
-                    line.WriteLine(text_filesize.Text);\r
-                    line.WriteLine(slider_videoQuality.Value.ToString());\r
-                    line.WriteLine(check_2PassEncode.CheckState.ToString());\r
-                    line.WriteLine(drp_deInterlace_option.Text);\r
-                    line.WriteLine(check_grayscale.CheckState.ToString());\r
-                    line.WriteLine(drp_videoFramerate.Text);\r
-                    line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
-                    line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
-                    line.WriteLine(check_turbo.CheckState.ToString());\r
-                    line.WriteLine(check_largeFile.CheckState.ToString());\r
-                    //Audio Settings Tab\r
-                    line.WriteLine(drp_audioBitrate.Text);\r
-                    line.WriteLine(drp_audioSampleRate.Text);\r
-                    line.WriteLine(drp_audioChannels.Text);\r
-                    line.WriteLine(drp_audioMixDown.Text);\r
-                    //H264 Tab\r
-                    line.WriteLine(CheckCRF.CheckState.ToString());\r
-                    line.WriteLine(rtf_h264advanced.Text);\r
+                    // Generate and write the query string to the file\r
+                    String query = GenerateTheQuery();\r
+                    line.WriteLine(query);\r
+\r
                     // close the stream\r
                     line.Close();\r
                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
                 }\r
-                catch(Exception)\r
+                catch (Exception)\r
                 {\r
                     MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
                 }\r
-                \r
-            }\r
-        }\r
 \r
-        private void mnu_update_Click(object sender, EventArgs e)\r
-        {\r
-            Form Update = new frmUpdate();\r
-            Update.ShowDialog();\r
+            }\r
         }\r
 \r
         private void mnu_exit_Click(object sender, EventArgs e)\r
         {\r
-            this.Close();\r
+            Application.Exit();\r
         }\r
 \r
         #endregion\r
@@ -380,28 +375,10 @@ namespace Handbrake
             showQueue();\r
         }\r
 \r
-       \r
         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
         {\r
-            try\r
-            {\r
-                dvdInfoWindow.Show();\r
-                \r
-            }\r
-            catch (Exception)\r
-            {\r
-                // No action required\r
-            }\r
-\r
-            // BUG *******************************************************\r
-            // Cross-thread operation not valid: Control 'rtf_dvdInfo' accessed from a thread other than the thread it was created on.\r
-            // This happens when the DVD is scanned and this item is then selected.\r
-            // If this item is selected so a blank copy of the window appears, then a DVD is scanned, there is no cross-thread issue.\r
-            // NOTE: Try/catch added to prevent final build crashing.\r
-            // NOTE2: Included a quick fix in frmMain(). Simply show and hide the window when starting the app.\r
-            // Note3: Suspect the problem lies with line 30.\r
-            // ***********************************************************\r
-\r
+            frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
+            dvdInfoWindow.Show();\r
         }\r
 \r
         private void mnu_options_Click(object sender, EventArgs e)\r
@@ -413,374 +390,278 @@ namespace Handbrake
         #endregion\r
 \r
         #region Presets Menu\r
-        // Need to write a handler for file extension\r
 \r
-        private void mnu_animation_Click(object sender, EventArgs e)\r
+        private void mnu_presetReset_Click(object sender, EventArgs e)\r
         {\r
-            // NEEDS MKV\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "1000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=5:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=5:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip:filter=2,2";\r
-            drp_deInterlace_option.Text = "Origional (Fast)";\r
-            check_2PassEncode.CheckState = CheckState.Checked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Checked;\r
-            drp_audioCodec.Text = "AAC";\r
+            listview_presets.Items.Clear();\r
+            updatePresets();\r
+            MessageBox.Show("Presets have been updated", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
         }\r
 \r
-        private void mnu_appleTv_Click(object sender, EventArgs e)\r
+        private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "2500";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AAC";\r
+            ListViewItem item = listview_presets.FindItemWithText("Normal");\r
+\r
+            if (item != null)\r
+            {\r
+                listview_presets.SelectedItems.Clear();\r
+                item.Selected = true;\r
+            }\r
+\r
+            if (presetStatus == false)\r
+            {\r
+                this.Width = 881;\r
+                presetStatus = true;\r
+                btn_presets.Text = "Hide Presets";\r
+            }\r
         }\r
 \r
-        private void mnu_bedlam_Click(object sender, EventArgs e)\r
+        #endregion\r
+\r
+        #region Help Menu\r
+\r
+\r
+        private void mnu_quickStart_Click(object sender, EventArgs e)\r
         {\r
-            // NEEDS MKV\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "1800";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=16:mixed-refs:bframes=6:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=7:me-range=64:analyse=all:8x8dct:trellis=2:no-fast-pskip:no-dct-decimate:filter=-2,-1";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Checked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Checked;\r
-            drp_audioCodec.Text = "AC3";\r
+            Form QuickStart = new frmQuickStart();\r
+            QuickStart.ShowDialog();\r
         }\r
 \r
-        private void mnu_blind_Click(object sender, EventArgs e)\r
+        private void mnu_wiki_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "512";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "512";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "128";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AAC";\r
+            Process.Start("http://handbrake.m0k.org/trac");\r
         }\r
 \r
-        private void mnu_broke_Click(object sender, EventArgs e)\r
+        private void mnu_faq_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "640";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "";\r
-            text_filesize.Text = "695";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "128";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=3:mixed-refs:bframes=6:bime:weightb:b-rdo:b-pyramid::direct=auto:me=umh:subme=6:trellis=1:analyse=all:8x8dct:no-fast-pskip";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Checked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Checked;\r
-            drp_audioCodec.Text = "AAC";\r
+            Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
         }\r
 \r
-        private void mnu_Classic_Click(object sender, EventArgs e)\r
+        private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "1000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Unchecked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AAC";\r
+            Process.Start("http://handbrake.m0k.org/?page_id=11");\r
         }\r
 \r
-        private void mnu_CQR_Click(object sender, EventArgs e)\r
+        private void mnu_homepage_Click(object sender, EventArgs e)\r
         {\r
-            // NEEDS MKV\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 64;\r
-            SliderValue.Text = "64%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=3:mixed-refs:bframes=3:b-pyramid:b-rdo:bime:weightb:filter=-2,-1:subme=6:trellis=1:analyse=all:8x8dct:me=umh ";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AC3";\r
+            Process.Start("http://handbrake.m0k.org");\r
         }\r
 \r
-        private void mnu_DSQ_Click(object sender, EventArgs e)\r
+        private void mnu_forum_Click(object sender, EventArgs e)\r
         {\r
-            // Needs MKV\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "1600";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=5:mixed-refs:bframes=3:bime:weightb:b-rdo:b-pyramid:me=umh:subme=7:trellis=1:analyse=all:8x8dct:no-fast-pskip";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Checked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Checked;\r
-            drp_audioCodec.Text = "AC3";\r
+            Process.Start("http://handbrake.m0k.org/forum");\r
         }\r
 \r
-        private void mnu_film_Click(object sender, EventArgs e)\r
+        private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
         {\r
-            // Needs MKV\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "2000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:no-fast-pskip";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Checked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Checked;\r
-            drp_audioCodec.Text = "AC3";\r
+            Boolean update = updateCheck();\r
+            if (update == true)\r
+            {\r
+                MessageBox.Show("There is a new update available. Please visit http://handbrake.m0k.org for details!", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
+            }\r
+            else\r
+            {\r
+                MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
+            }\r
         }\r
 \r
-        private void mnu_iphone_Click(object sender, EventArgs e)\r
+        private void mnu_about_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "480";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "960";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "128";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AAC";\r
+            Form About = new frmAbout();\r
+            About.ShowDialog();\r
         }\r
 \r
-        private void mnu_ipod_Click(object sender, EventArgs e)\r
+        #endregion\r
+\r
+        // -------------------------------------------------------------- \r
+        // Buttons on the main Window\r
+        // --------------------------------------------------------------\r
+\r
+        #region Buttons\r
+\r
+        private void btn_Browse_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "640";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "1500";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AAC";\r
+            String filename = "";\r
+            text_source.Text = "";\r
+            frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
+\r
+            if (RadioDVD.Checked)\r
+            {\r
+                DVD_Open.ShowDialog();\r
+                filename = DVD_Open.SelectedPath;\r
+                if (filename != "")\r
+                {\r
+                    Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
+                    text_source.Text = filename;\r
+                    frmRD.ShowDialog();\r
+                }\r
+            }\r
+            else\r
+            {\r
+                ISO_Open.ShowDialog();\r
+                filename = ISO_Open.FileName;\r
+                if (filename != "")\r
+                {\r
+                    Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
+                    text_source.Text = filename;\r
+                    frmRD.ShowDialog();\r
+                }\r
+            }\r
+\r
+            // Check if there was titles in the dvd title dropdown \r
+            if (filename == "")\r
+            {\r
+                text_source.Text = "Click 'Browse' to continue";\r
+            }\r
+\r
+            // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.\r
+            if (drp_dvdtitle.Items.Count == 0)\r
+            {\r
+                MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source. Please refer to the FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
+            }\r
         }\r
 \r
-        private void mnu_ipodLow_Click(object sender, EventArgs e)\r
+        private void btn_destBrowse_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "320";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "700";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "keyint=300:keyint-min=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:subme=6:no-fast-pskip=1";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AAC";\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
+            // Should be a nicer way to do this.\r
+            DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", "").Replace(".m4v", "").Replace(".mkv", "").Replace(".ogm", "").Replace(".avi", "");\r
+\r
+            // Show the dialog and set the main form file path\r
+            DVD_Save.ShowDialog();\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
+            {\r
+                string destination = text_destination.Text;\r
+                destination = destination.Replace(".mp4", ".m4v");\r
+                text_destination.Text = destination;\r
+            }\r
         }\r
 \r
-        private void mnu_normal_Click(object sender, EventArgs e)\r
+        private void btn_h264Clear_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "1500";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=2:bframes=2:subme=5:me=umh";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Checked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Checked;\r
-            drp_audioCodec.Text = "AAC";\r
+            rtf_h264advanced.Text = "";\r
         }\r
 \r
-        private void mnu_PS3_Click(object sender, EventArgs e)\r
+        private void GenerateQuery_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "2500";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "level=41:subme=5:me=umh";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AAC";\r
+            String query = GenerateTheQuery();\r
+            QueryEditorText.Text = query;\r
         }\r
 \r
-        private void mnu_psp_Click(object sender, EventArgs e)\r
+        private void btn_ClearQuery_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "368";\r
-            text_height.Text = "208";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "1024";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Unchecked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Unchecked;\r
-            drp_audioCodec.Text = "AAC";\r
+            QueryEditorText.Text = "";\r
         }\r
 \r
-        private void mnu_qt_Click(object sender, EventArgs e)\r
+        private void btn_queue_Click(object sender, EventArgs e)\r
         {\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "2000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct-auto:me=umh:subme=5:analyse=all:8x8dct:trellis=1:no-fast-pskip";\r
-            drp_deInterlace_option.Text = "None";\r
-            check_2PassEncode.CheckState = CheckState.Checked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Checked;\r
-            drp_audioCodec.Text = "AAC";\r
+\r
+            if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")\r
+                MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+            else\r
+            {\r
+                string query;\r
+                if (QueryEditorText.Text == "")\r
+                {\r
+                    query = GenerateTheQuery();\r
+                }\r
+                else\r
+                {\r
+                    query = QueryEditorText.Text;\r
+                }\r
+                queueWindow.list_queue.Items.Add(query);\r
+                queueWindow.Show();\r
+            }\r
         }\r
 \r
-        private void mnu_television_Click(object sender, EventArgs e)\r
+        private void btn_copy_Click(object sender, EventArgs e)\r
         {\r
-            // NEEDS MKV\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "1300";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            Check_ChapterMarkers.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "ref=3:mixed-refs:bframes=6:bime:weightb:direct=auto:b-pyramid:me=umh:subme=6:analyse=all:8x8dct:trellis=1:nr=150:no-fast-pskip";\r
-            drp_deInterlace_option.Text = "Origional (Fast)";\r
-            check_2PassEncode.CheckState = CheckState.Checked;\r
-            drp_crop.Text = "No Crop";\r
-            check_turbo.CheckState = CheckState.Checked;\r
-            drp_audioCodec.Text = "AAC";\r
+            if (QueryEditorText.Text != "")\r
+                Clipboard.SetText(QueryEditorText.Text, TextDataFormat.Text);\r
+        }\r
+\r
+        private void showQueue()\r
+        {\r
+            queueWindow.Show();\r
         }\r
 \r
+        #endregion\r
+\r
+        // -------------------------------------------------------------- \r
+        // Main Window Preset System\r
+        // --------------------------------------------------------------\r
 \r
+        #region Preset System\r
+\r
+        // Import Current Presets\r
+        private void updatePresets()\r
+        {\r
+            string[] presets = new string[17];\r
+            presets[0] = "Animation";\r
+            presets[1] = "AppleTV";\r
+            presets[2] = "Bedlam";\r
+            presets[3] = "Blind";\r
+            presets[4] = "Broke";\r
+            presets[5] = "Classic";\r
+            presets[6] = "Constant Quality Rate";\r
+            presets[7] = "Deux Six Quatre";\r
+            presets[8] = "Film";\r
+            presets[9] = "iPhone / iPod Touch";\r
+            presets[10] = "iPod High-Rez";\r
+            presets[11] = "iPod Low-Rez";\r
+            presets[12] = "Normal";\r
+            presets[13] = "PS3";\r
+            presets[14] = "PSP";\r
+            presets[15] = "QuickTime";\r
+            presets[16] = "Television";\r
+\r
+            ListViewItem preset_listview = new ListViewItem();\r
+            string[] presetList = new string[1];\r
+\r
+            foreach (string preset in presets)\r
+            {\r
+                presetList[0] = preset;\r
+                preset_listview = new ListViewItem(presetList);\r
 \r
-        private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)\r
+                // Now Fill Out List View with Items\r
+                listview_presets.Items.Add(preset_listview);\r
+            }\r
+\r
+            string appPath = Application.StartupPath.ToString() + "\\";\r
+            string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " --preset-list >" + '"' + appPath + "presets.dat" + '"' + " 2>&1" + '"';\r
+            Process hbproc = Process.Start("CMD.exe", strCmdLine);\r
+            hbproc.WaitForExit();\r
+            hbproc.Dispose();\r
+            hbproc.Close();\r
+\r
+        }\r
+\r
+        // Varibles\r
+        private Boolean presetStatus = false;\r
+\r
+        // Buttons\r
+        private void btn_presets_Click(object sender, EventArgs e)\r
+        {\r
+            if (presetStatus == false)\r
+            {\r
+                this.Width = 881;\r
+                presetStatus = true;\r
+                btn_presets.Text = "Hide Presets";\r
+            }\r
+            else\r
+            {\r
+                this.Width = 590;\r
+                presetStatus = false;\r
+                btn_presets.Text = "Show Presets";\r
+            }\r
+\r
+        }\r
+\r
+        private void btn_setDefault_Click(object sender, EventArgs e)\r
         {\r
             //Source\r
             Properties.Settings.Default.DVDSource = text_source.Text;\r
@@ -814,156 +695,76 @@ namespace Handbrake
             Properties.Settings.Default.detelecine = check_detelecine.CheckState.ToString();\r
             Properties.Settings.Default.denoise = drp_deNoise.Text;\r
             Properties.Settings.Default.deblock = check_deblock.CheckState.ToString();\r
+            Properties.Settings.Default.chapterMarker = Check_ChapterMarkers.CheckState.ToString();\r
             //Audio Settings Tab\r
-            Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
-            Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
-            Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
-            //H264 Tab\r
-            Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
-            Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
-            Properties.Settings.Default.Save();\r
-        }\r
-\r
-        #endregion\r
-\r
-        #region Help Menu\r
-\r
-        private void mnu_wiki_Click(object sender, EventArgs e)\r
-        {\r
-           Process.Start("http://handbrake.m0k.org/trac");\r
-        }\r
-\r
-        private void mnu_faq_Click(object sender, EventArgs e)\r
-        {\r
-            Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
-        }\r
-\r
-        private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
-        {\r
-            Process.Start("http://handbrake.m0k.org/?page_id=11");\r
-        }\r
-\r
-        private void mnu_homepage_Click(object sender, EventArgs e)\r
-        {\r
-           Process.Start("http://handbrake.m0k.org");\r
-        }\r
-\r
-        private void mnu_forum_Click(object sender, EventArgs e)\r
-        {\r
-            Process.Start("http://handbrake.m0k.org/forum");\r
-        }\r
-\r
-        private void mnu_about_Click(object sender, EventArgs e)\r
-        {\r
-                       Form About = new frmAbout();\r
-            About.ShowDialog();\r
-        }\r
-\r
-        #endregion\r
-\r
-        // -------------------------------------------------------------- \r
-        // Buttons on the main Window\r
-        // --------------------------------------------------------------\r
-\r
-        #region Buttons\r
-        private void btn_Browse_Click(object sender, EventArgs e)\r
-        {\r
-            String filename =""; \r
-                   text_source.Text = ""; \r
-                                \r
-                   if (RadioDVD.Checked) \r
-                   { \r
-                       DVD_Open.ShowDialog(); \r
-                       filename = DVD_Open.SelectedPath; \r
-                       if (filename != "") \r
-                       { \r
-                           Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); \r
-                           text_source.Text = filename; \r
-                           frmRD.ShowDialog(); \r
-                       } \r
-                    } \r
-                    else \r
-                    { \r
-                       ISO_Open.ShowDialog(); \r
-                       filename = ISO_Open.FileName; \r
-                       if (filename != "") \r
-                       { \r
-                           Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); \r
-                           text_source.Text = filename; \r
-                           frmRD.ShowDialog(); \r
-                       } \r
-                    }   \r
-                \r
-                    // Check if there was titles in the dvd title dropdown \r
-                    if (filename == "") \r
-                    { \r
-                       text_source.Text = "Click 'Browse' to continue"; \r
-                    } \r
-                \r
-                    if (drp_dvdtitle.Items.Count == 0) \r
-                    { \r
-                       MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source. Please refer to the FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); \r
-                    }                  \r
-        }\r
-\r
-        private void btn_destBrowse_Click(object sender, EventArgs e)\r
-        {\r
-            // TODO: Need to write some code to check if there is a reasonable amount of disk space left.\r
-\r
-            DVD_Save.ShowDialog();\r
-            text_destination.Text = DVD_Save.FileName;\r
-\r
-            if (Check_ChapterMarkers.Checked)\r
-            {\r
-                string destination = text_destination.Text;\r
-                destination = destination.Replace(".mp4", ".m4v");\r
-                text_destination.Text = destination;\r
-            }\r
+            Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
+            Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
+            Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
+            //H264 Tab\r
+            Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
+            Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
+            //Preset\r
+            Properties.Settings.Default.selectedPreset = groupBox_output.Text.Replace("Output Settings (Preset: ", "").Replace("\"", "").Replace(")", "");\r
+            // Save the new default Settings\r
+            Properties.Settings.Default.Save();\r
+            MessageBox.Show("New default settings saved.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
         }\r
 \r
-        private void btn_h264Clear_Click(object sender, EventArgs e)\r
+        // Preset Selection\r
+        private void listview_presets_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            rtf_h264advanced.Text = "";\r
-        }\r
 \r
-        private void GenerateQuery_Click(object sender, EventArgs e)\r
-        {\r
-            String query = GenerateTheQuery();\r
-            QueryEditorText.Text = query;\r
-        }\r
+            string selectedPreset = null;\r
+            ListView.SelectedListViewItemCollection name = null;\r
+            name = listview_presets.SelectedItems;\r
 \r
-        private void btn_ClearQuery_Click(object sender, EventArgs e)\r
-        {\r
-            QueryEditorText.Text = "";\r
-        }\r
+            if (listview_presets.SelectedItems.Count != 0)\r
+                selectedPreset = name[0].SubItems[0].Text;\r
 \r
-        private void btn_queue_Click(object sender, EventArgs e)\r
-        {\r
-            if (text_destination.Text != "" && text_source.Text != "")\r
+            try\r
             {\r
-                string query;\r
-                if (QueryEditorText.Text == "")\r
-                {\r
-                    query = GenerateTheQuery();\r
-                }\r
-                else\r
+                string appPath = Application.StartupPath.ToString() + "\\";\r
+                StreamReader presetInput = new StreamReader(appPath + "presets.dat");\r
+\r
+                while (!presetInput.EndOfStream)\r
                 {\r
-                    query = QueryEditorText.Text;\r
+                    if ((char)presetInput.Peek() == '+')\r
+                    {\r
+                        string preset = presetInput.ReadLine().Replace("+ ", "");\r
+                        Regex r = new Regex("(:  )"); // Split on hyphens. \r
+                        string[] presetName = r.Split(preset);\r
+\r
+                        if (selectedPreset == "iPhone / iPod Touch")\r
+                        {\r
+                            selectedPreset = "iPhone";\r
+                        }\r
+\r
+                        if (selectedPreset == presetName[0])\r
+                        {\r
+                            // Need to disable anamorphic now, otherwise it may overide the width / height values later.\r
+                            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
+\r
+                            // Send the query from the file to the Query Parser class\r
+                            Functions.QueryParser presetQuery = Functions.QueryParser.Parse(preset);\r
+\r
+                            // Now load the preset\r
+                            presetLoader(presetQuery, selectedPreset);\r
+                        }\r
+                        \r
+                    }\r
+                    else\r
+                    {\r
+                        presetInput.ReadLine();\r
+                    }\r
                 }\r
-                queueWindow.list_queue.Items.Add(query);\r
-                queueWindow.Show();\r
-            } \r
-            else \r
+            }\r
+            catch (Exception exc)\r
             {\r
-                MessageBox.Show("No Source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
-        }\r
 \r
-        private void showQueue()\r
-        {\r
-            queueWindow.Show();\r
+           \r
         }\r
-\r
         #endregion\r
 \r
         //---------------------------------------------------\r
@@ -977,21 +778,25 @@ namespace Handbrake
 \r
         private void btn_encode_Click(object sender, EventArgs e)\r
         {\r
-            btn_eCancel.Enabled = true;\r
-            String query = "";\r
-            lbl_encode.Visible = false;\r
\r
-            if (QueryEditorText.Text == "")\r
-            {\r
-                query = GenerateTheQuery();\r
-            }\r
+            if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")\r
+                MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             else\r
             {\r
-                query = QueryEditorText.Text;\r
-            }\r
+                btn_eCancel.Enabled = true;\r
+                String query = "";\r
+                if (QueryEditorText.Text == "")\r
+                {\r
+                    query = GenerateTheQuery();\r
+                }\r
+                else\r
+                {\r
+                    query = QueryEditorText.Text;\r
+                }\r
 \r
-            ThreadPool.QueueUserWorkItem(procMonitor, query);\r
-            lbl_encode.Text = "Encoding Started";\r
+                ThreadPool.QueueUserWorkItem(procMonitor, query);\r
+                lbl_encode.Visible = true;\r
+                lbl_encode.Text = "Encoding in Progress";\r
+            }\r
         }\r
 \r
         private void btn_eCancel_Click(object sender, EventArgs e)\r
@@ -1000,7 +805,12 @@ namespace Handbrake
             process.setNull();\r
             lbl_encode.Text = "Encoding Canceled";\r
         }\r
-   \r
+\r
+        [DllImport("user32.dll")]\r
+        public static extern void LockWorkStation();\r
+        [DllImport("user32.dll")]\r
+        public static extern int ExitWindowsEx(int uFlags, int dwReason);\r
+\r
         private void procMonitor(object state)\r
         {\r
             // Make sure we are not already encoding and if we are then display an error.\r
@@ -1011,12 +821,11 @@ namespace Handbrake
             else\r
             {\r
                 hbProc = process.runCli(this, (string)state, false, false, false, false);\r
-                MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
                 hbProc.WaitForExit();\r
 \r
                 try\r
                 {\r
-\r
+                    /*\r
                     //*****************************************************************************************\r
                     // BUG!\r
                     // When the below code is used and standard error is set to true, hbcli is outputing a\r
@@ -1025,7 +834,7 @@ namespace Handbrake
                     //*****************************************************************************************\r
 \r
                     \r
-                    /*Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
+                    Parsing.Parser encode = new Parsing.Parser(hbProc.StandardOutput.BaseStream);\r
                     encode.OnEncodeProgress += encode_OnEncodeProgress;\r
                     while (!encode.EndOfStream)\r
                     {\r
@@ -1034,20 +843,61 @@ namespace Handbrake
 \r
                     hbProc.WaitForExit();\r
                     process.closeCLI();\r
-                    */\r
+                     */\r
+\r
                 }\r
-                catch (Exception)\r
+                catch (Exception exc)\r
                 {\r
                     // Do nothing\r
+                    MessageBox.Show(exc.ToString());\r
                 }\r
 \r
-                MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
+\r
+                setEncodeLabel();\r
                 hbProc = null;\r
+\r
+                // Do something whent he encode ends.\r
+                switch (Properties.Settings.Default.CompletionOption)\r
+                {\r
+                    case "Shutdown":\r
+                        System.Diagnostics.Process.Start("Shutdown", "-s -t 60");\r
+                        break;\r
+                    case "Log Off":\r
+                        ExitWindowsEx(0, 0);\r
+                        break;\r
+                    case "Suspend":\r
+                        Application.SetSuspendState(PowerState.Suspend, true, true);\r
+                        break;\r
+                    case "Hibernate":\r
+                        Application.SetSuspendState(PowerState.Hibernate, true, true);\r
+                        break;\r
+                    case "Lock System":\r
+                        LockWorkStation();\r
+                        break;\r
+                    case "Quit HandBrake":\r
+                        Application.Exit();\r
+                        break;\r
+                    default:\r
+                        break;\r
+                }\r
+            }\r
+        }\r
+\r
+        private delegate void UpdateUIHandler();\r
+\r
+        private void setEncodeLabel()\r
+        {\r
+            if (this.InvokeRequired)\r
+            {\r
+                this.BeginInvoke(new UpdateUIHandler(setEncodeLabel));\r
+                return;\r
             }\r
+            lbl_encode.Text = "Encoding Finished";\r
         }\r
 \r
         private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
         {\r
+\r
             if (this.InvokeRequired)\r
             {\r
                 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
@@ -1067,7 +917,7 @@ namespace Handbrake
 \r
         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            lbl_chptWarn.Visible = false;\r
+            drop_chapterStart.BackColor = Color.White;\r
             QueryEditorText.Text = "";\r
             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
             {\r
@@ -1078,23 +928,21 @@ namespace Handbrake
 \r
                     if (chapterFinish < chapterStart)\r
                     {\r
-                        lbl_chptWarn.Visible = true;\r
-                        lbl_chptWarn.Text = "Invalid Chapter Range!";\r
+                        drop_chapterStart.BackColor = Color.LightCoral;\r
                     }\r
                 }\r
                 catch (Exception)\r
                 {\r
-                    lbl_chptWarn.Visible = true;\r
-                    lbl_chptWarn.Text = "Invalid Chapter Range!";\r
+                    drop_chapterStart.BackColor = Color.LightCoral;\r
                 }\r
             }\r
 \r
-            \r
+\r
         }\r
 \r
         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            lbl_chptWarn.Visible = false;\r
+            drop_chapterFinish.BackColor = Color.White;\r
             QueryEditorText.Text = "";\r
             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
             {\r
@@ -1105,14 +953,12 @@ namespace Handbrake
 \r
                     if (chapterFinish < chapterStart)\r
                     {\r
-                        lbl_chptWarn.Visible = true;\r
-                        lbl_chptWarn.Text = "Invalid Chapter Range!";\r
+                        drop_chapterFinish.BackColor = Color.LightCoral;\r
                     }\r
                 }\r
                 catch (Exception)\r
                 {\r
-                    lbl_chptWarn.Visible = true;\r
-                    lbl_chptWarn.Text = "Invalid Chapter Range!";\r
+                    drop_chapterFinish.BackColor = Color.LightCoral;\r
                 }\r
             }\r
         }\r
@@ -1150,13 +996,13 @@ namespace Handbrake
 \r
         private void text_width_TextChanged(object sender, EventArgs e)\r
         {\r
-\r
             try\r
             {\r
                 if (CheckPixelRatio.Checked)\r
                 {\r
                     text_width.Text = "";\r
-                    text_width.BackColor = Color.White;\r
+                    text_width.BackColor = Color.LightCoral;\r
+                    CheckPixelRatio.BackColor = Color.LightCoral;\r
                 }\r
                 else\r
                 {\r
@@ -1184,41 +1030,44 @@ namespace Handbrake
                     else\r
                     {\r
                         text_height.Text = height.ToString();\r
+                        text_width.BackColor = Color.LightGreen;\r
                     }\r
                 }\r
             }\r
             catch (Exception)\r
             {\r
                 // No need to throw an error here.\r
+                // Note on non english systems, this will throw an error because of double.Parse(lbl_Aspect.Text); not working.\r
             }\r
-               \r
-          \r
+\r
+\r
         }\r
 \r
         private void text_height_TextChanged(object sender, EventArgs e)\r
         {\r
             try\r
             {\r
-                if (text_height.Text != "Auto")\r
+                if (CheckPixelRatio.Checked)\r
                 {\r
-                    if (CheckPixelRatio.Checked)\r
+                    text_height.Text = "";\r
+                    text_height.BackColor = Color.LightCoral;\r
+                    CheckPixelRatio.BackColor = Color.LightCoral;\r
+                }\r
+                else\r
+                {\r
+                    if ((int.Parse(text_height.Text) % 16) != 0)\r
                     {\r
-                        text_height.Text = "";\r
-                        text_width.BackColor = Color.White;\r
+                        text_height.BackColor = Color.LightCoral;\r
                     }\r
                     else\r
                     {\r
-                        if ((int.Parse(text_height.Text) % 16) != 0)\r
-                        {\r
-                            text_height.BackColor = Color.LightCoral;\r
-                        }\r
-                        else\r
-                        {\r
-                            text_height.BackColor = Color.LightGreen;\r
-                        }\r
+                        text_height.BackColor = Color.LightGreen;\r
                     }\r
                 }\r
-            } catch(Exception){\r
+\r
+            }\r
+            catch (Exception)\r
+            {\r
                 // No need to alert the user.\r
             }\r
         }\r
@@ -1227,10 +1076,10 @@ namespace Handbrake
         {\r
             if ((string)drp_crop.SelectedItem == "Manual")\r
             {\r
-            text_left.Enabled = true;\r
-            text_right.Enabled = true;\r
-            text_top.Enabled = true;\r
-            text_bottom.Enabled = true;\r
+                text_left.Enabled = true;\r
+                text_right.Enabled = true;\r
+                text_top.Enabled = true;\r
+                text_bottom.Enabled = true;\r
             }\r
 \r
             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
@@ -1268,18 +1117,50 @@ namespace Handbrake
 \r
             }\r
         }\r
-        \r
+\r
         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
         {\r
             text_width.Text = "";\r
             text_height.Text = "";\r
             text_width.BackColor = Color.White;\r
             text_height.BackColor = Color.White;\r
+            CheckPixelRatio.BackColor = TabPage1.BackColor;\r
+        }\r
+\r
+        private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)\r
+        {\r
+            if (check_2PassEncode.CheckState.ToString() == "Checked")\r
+            {\r
+                if (drp_videoEncoder.Text.Contains("H.264"))\r
+                {\r
+                    check_turbo.Enabled = true;\r
+                }\r
+            }\r
+            else\r
+            {\r
+                check_turbo.Enabled = false;\r
+                check_turbo.CheckState = CheckState.Unchecked;\r
+            }\r
+        }\r
+\r
+        private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
+        {\r
+            if (!text_destination.Text.Contains(".mp4"))\r
+            {\r
+                lbl_largeMp4Warning.Text = "Warning: Only mp4 files are supported";\r
+                lbl_largeMp4Warning.ForeColor = Color.Red;\r
+                check_largeFile.CheckState = CheckState.Unchecked;\r
+            }\r
+            else\r
+            {\r
+                lbl_largeMp4Warning.Text = "Warning: Breaks iPod, @TV, PS3 compatibility.";\r
+                lbl_largeMp4Warning.ForeColor = Color.Black;\r
+            }\r
         }\r
 \r
         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
         {\r
-            if (drp_dvdtitle.Items.Count == 1)\r
+            if (drp_dvdtitle.Items.Count == 0)\r
             {\r
                 MessageBox.Show("There are no titles to select. Please scan the DVD by clicking the 'browse' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
             }\r
@@ -1300,7 +1181,7 @@ namespace Handbrake
                 drp_audioMixDown.Items.Add("Dolby Surround");\r
                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
-                \r
+\r
                 drp_audioBitrate.Items.Clear();\r
                 drp_audioBitrate.Items.Add("32");\r
                 drp_audioBitrate.Items.Add("40");\r
@@ -1336,7 +1217,6 @@ namespace Handbrake
                 drp_audioBitrate.Items.Add("224");\r
                 drp_audioBitrate.Items.Add("256");\r
                 drp_audioBitrate.Items.Add("320");\r
-                drp_audioBitrate.Items.Add("384");\r
             }\r
         }\r
 \r
@@ -1375,14 +1255,11 @@ namespace Handbrake
                 destination = destination.Replace(".mp4", ".m4v");\r
                 text_destination.Text = destination;\r
             }\r
-        }\r
-\r
-        private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
-        {\r
-            if (!text_destination.Text.Contains(".mp4"))\r
+            else\r
             {\r
-                MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-                check_largeFile.CheckState = CheckState.Unchecked;\r
+                string destination = text_destination.Text;\r
+                destination = destination.Replace(".m4v", ".mp4");\r
+                text_destination.Text = destination;\r
             }\r
         }\r
 \r
@@ -1396,11 +1273,15 @@ namespace Handbrake
                 CheckCRF.Enabled = false;\r
                 check_turbo.Enabled = false;\r
                 h264Tab.Enabled = false;\r
+                rtf_h264advanced.Text = "";\r
             }\r
             else\r
             {\r
                 CheckCRF.Enabled = true;\r
-                check_turbo.Enabled = true;\r
+                if (check_2PassEncode.CheckState.ToString() == "Checked")\r
+                {\r
+                    check_turbo.Enabled = true;\r
+                }\r
                 h264Tab.Enabled = true;\r
             }\r
 \r
@@ -1431,7 +1312,7 @@ namespace Handbrake
 \r
                 // Set the Recommended Cropping values\r
                 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
-                \r
+\r
                 // Populate the Start chapter Dropdown\r
                 drop_chapterStart.Items.Clear();\r
                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
@@ -1470,16 +1351,14 @@ namespace Handbrake
 \r
         #endregion\r
 \r
-        /* \r
-         * ---------------------------------------------------\r
-         * \r
-         * The query Generation function.\r
-         * \r
-         * ---------------------------------------------------\r
-         */\r
+        //---------------------------------------------------\r
+        //  Some Functions\r
+        //  - Query Generation\r
+        //---------------------------------------------------\r
 \r
         #region Program Functions\r
 \r
+        // Generate a CLI Query String\r
         public string GenerateTheQuery()\r
         {\r
             string source = text_source.Text;\r
@@ -1489,19 +1368,14 @@ namespace Handbrake
             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
             string dvdChapter = "";\r
 \r
-            if (source ==  "")\r
-                MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-            else\r
-            {\r
-                source = " -i " + '"' + source+ '"'; //'"'+\r
-            }\r
+            source = " -i " + '"' + source + '"';\r
 \r
-            if (dvdTitle ==  "Automatic")\r
+            if (dvdTitle == "Automatic")\r
                 dvdTitle = "";\r
             else\r
             {\r
                 string[] titleInfo = dvdTitle.Split(' ');\r
-                dvdTitle = " -t "+ titleInfo[0];\r
+                dvdTitle = " -t " + titleInfo[0];\r
             }\r
 \r
             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
@@ -1511,7 +1385,7 @@ namespace Handbrake
             else\r
                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
 \r
-            string querySource = source+ dvdTitle+ dvdChapter;\r
+            string querySource = source + dvdTitle + dvdChapter;\r
             // ----------------------------------------------------------------------\r
 \r
             // Destination\r
@@ -1522,7 +1396,7 @@ namespace Handbrake
             string width = text_width.Text;\r
             string height = text_height.Text;\r
 \r
-            if (destination ==  "")\r
+            if (destination == "")\r
                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             else\r
                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
@@ -1549,7 +1423,7 @@ namespace Handbrake
                     videoEncoder = " -e x264";\r
                     break;\r
             }\r
-           \r
+\r
             switch (audioEncoder)\r
             {\r
                 case "AAC":\r
@@ -1569,8 +1443,8 @@ namespace Handbrake
                     break;\r
             }\r
 \r
-            if (width !=  "")\r
-                width = " -w "+ width;\r
+            if (width != "")\r
+                width = " -w " + width;\r
 \r
 \r
             if (height == "Auto")\r
@@ -1581,9 +1455,9 @@ namespace Handbrake
             {\r
                 height = " -l " + height;\r
             }\r
-            \r
 \r
-            string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
+\r
+            string queryDestination = destination + videoEncoder + audioEncoder + width + height;\r
             // ----------------------------------------------------------------------\r
 \r
             // Picture Settings Tab\r
@@ -1607,17 +1481,28 @@ namespace Handbrake
             else if (cropSetting == "No Crop")\r
                 cropOut = " --crop 0:0:0:0 ";\r
             else\r
+            {\r
+                if (text_top.Text == "")\r
+                    cropTop = "0";\r
+                if (text_bottom.Text == "")\r
+                    cropBottom = "0";\r
+                if (text_left.Text == "")\r
+                    cropLeft = "0";\r
+                if (text_right.Text == "")\r
+                    cropRight = "0";\r
+\r
                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
+            }\r
 \r
-            if (subtitles ==  "None")\r
+            if (subtitles == "None")\r
                 subtitles = "";\r
-            else if (subtitles ==  "")\r
+            else if (subtitles == "")\r
                 subtitles = "";\r
             else\r
             {\r
                 string[] tempSub;\r
                 tempSub = subtitles.Split(' ');\r
-                subtitles = " -s "+ tempSub[0];\r
+                subtitles = " -s " + tempSub[0];\r
             }\r
 \r
             switch (deInterlace_Option)\r
@@ -1625,20 +1510,20 @@ namespace Handbrake
                 case "None":\r
                     deinterlace = "";\r
                     break;\r
-                case "Origional (Fast)":\r
-                    deinterlace = " --deinterlace";\r
+                case "Original (Fast)":\r
+                    deinterlace = " --deinterlace=fast";\r
                     break;\r
                 case "yadif (Slow)":\r
-                    deinterlace = " --deinterlace=" + '"' + "1" + '"';\r
+                    deinterlace = " --deinterlace=slow";\r
                     break;\r
                 case "yadif + mcdeint (Slower)":\r
-                    deinterlace = " --deinterlace=" + '"' + "1:-1:1" + '"';\r
+                    deinterlace = " --deinterlace=slower";\r
                     break;\r
                 case "yadif + mcdeint (Slowest)":\r
-                    deinterlace = " --deinterlace=" + '"' + "3:-1:2" + '"';\r
+                    deinterlace = " --deinterlace=slowest";\r
                     break;\r
                 default:\r
-                    deinterlace = " --deinterlace=";\r
+                    deinterlace = "";\r
                     break;\r
             }\r
 \r
@@ -1669,40 +1554,38 @@ namespace Handbrake
             string denoise = "";\r
             string CRF = CheckCRF.CheckState.ToString();\r
 \r
-\r
-            if ((CRF == "Checked"))\r
+            if (CRF == "Checked")\r
                 CRF = " -Q ";\r
             else\r
                 CRF = "";\r
 \r
-            if (videoBitrate !=  "")\r
-                videoBitrate = " -b "+ videoBitrate;\r
+            if (videoBitrate != "")\r
+                videoBitrate = " -b " + videoBitrate;\r
 \r
-            if (videoFilesize !=  "")\r
-                videoFilesize = " -S "+ videoFilesize;\r
+            if (videoFilesize != "")\r
+                videoFilesize = " -S " + videoFilesize;\r
 \r
             // Video Quality Setting\r
 \r
-            if ((videoQuality ==  0))\r
+            if ((videoQuality == 0))\r
                 vidQSetting = "";\r
             else\r
             {\r
                 videoQuality = videoQuality / 100;\r
-                if (videoQuality ==  1)\r
+                if (videoQuality == 1)\r
                 {\r
                     vidQSetting = "1.0";\r
                 }\r
-\r
-                vidQSetting = " -q " + videoQuality.ToString();\r
+                vidQSetting = " -q " + videoQuality.ToString(new CultureInfo("en-US")); \r
             }\r
 \r
             if (check_2PassEncode.Checked)\r
                 twoPassEncoding = " -2 ";\r
 \r
-            if (videoFramerate ==  "Automatic")\r
+            if (videoFramerate == "Automatic")\r
                 videoFramerate = "";\r
             else\r
-                videoFramerate = " -r "+ videoFramerate;\r
+                videoFramerate = " -r " + videoFramerate;\r
 \r
             if (check_turbo.Checked)\r
                 turboH264 = " -T ";\r
@@ -1722,17 +1605,20 @@ namespace Handbrake
                     denoise = "";\r
                     break;\r
                 case "Weak":\r
-                    denoise = " --denoise=3:2:3:3";\r
+                    denoise = " --denoise=weak";\r
+                    break;\r
+                case "Medium":\r
+                    denoise = " --denoise=medium";\r
                     break;\r
                 case "Strong":\r
-                    denoise = " --denoise=7:7:5:5";\r
+                    denoise = " --denoise=strong";\r
                     break;\r
                 default:\r
                     denoise = "";\r
                     break;\r
             }\r
 \r
-            string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + videoFramerate + turboH264 + largeFile + deblock + detelecine + denoise;\r
+            string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + CRF + twoPassEncoding + videoFramerate + turboH264 + largeFile + deblock + detelecine + denoise;\r
             // ----------------------------------------------------------------------\r
 \r
             // Audio Settings Tab\r
@@ -1743,21 +1629,21 @@ namespace Handbrake
             string Mixdown = drp_audioMixDown.Text;\r
             string SixChannelAudio = "";\r
 \r
-            if (audioBitrate !=  "")\r
-                audioBitrate = " -B "+ audioBitrate;\r
+            if (audioBitrate != "")\r
+                audioBitrate = " -B " + audioBitrate;\r
 \r
-            if (audioSampleRate !=  "")\r
-                audioSampleRate = " -R "+ audioSampleRate;\r
+            if (audioSampleRate != "")\r
+                audioSampleRate = " -R " + audioSampleRate;\r
 \r
-            if (audioChannels ==  "Automatic")\r
+            if (audioChannels == "Automatic")\r
                 audioChannels = "";\r
-            else if (audioChannels ==  "")\r
+            else if (audioChannels == "")\r
                 audioChannels = "";\r
             else\r
             {\r
                 string[] tempSub;\r
                 tempSub = audioChannels.Split(' ');\r
-                audioChannels = " -a "+ tempSub[0];\r
+                audioChannels = " -a " + tempSub[0];\r
             }\r
 \r
             switch (Mixdown)\r
@@ -1781,28 +1667,28 @@ namespace Handbrake
                     Mixdown = "6ch";\r
                     break;\r
                 default:\r
-                    Mixdown = "stero";\r
+                    Mixdown = "";\r
                     break;\r
             }\r
 \r
-            if (Mixdown !=  "")\r
-                SixChannelAudio = " -6 "+ Mixdown;\r
+            if (Mixdown != "")\r
+                SixChannelAudio = " -6 " + Mixdown;\r
             else\r
                 SixChannelAudio = "";\r
 \r
-            string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
+            string queryAudioSettings = audioBitrate + audioSampleRate + audioChannels + SixChannelAudio;\r
             // ----------------------------------------------------------------------\r
 \r
             //  H.264 Tab\r
 \r
-            \r
+\r
             string h264Advanced = rtf_h264advanced.Text;\r
-            \r
-            if ((h264Advanced ==  ""))\r
+\r
+            if ((h264Advanced == ""))\r
                 h264Advanced = "";\r
             else\r
-                h264Advanced = " -x "+ h264Advanced;\r
-    \r
+                h264Advanced = " -x " + h264Advanced;\r
+\r
 \r
             string h264Settings = h264Advanced;\r
             // ----------------------------------------------------------------------\r
@@ -1812,10 +1698,10 @@ namespace Handbrake
             string processors = Properties.Settings.Default.Processors;\r
             //  Number of Processors Handler\r
 \r
-            if (processors ==  "Automatic")\r
+            if (processors == "Automatic")\r
                 processors = "";\r
             else\r
-                processors = " -C "+ processors+ " ";\r
+                processors = " -C " + processors + " ";\r
 \r
 \r
             string queryAdvancedSettings = processors;\r
@@ -1824,15 +1710,206 @@ namespace Handbrake
             //  Verbose option (Program Settings)\r
 \r
             string verbose = "";\r
-            if (Properties.Settings.Default.verbose ==  "Checked")\r
+            if (Properties.Settings.Default.verbose == "Checked")\r
                 verbose = " -v ";\r
 \r
             // ----------------------------------------------------------------------\r
 \r
-            return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
+            return querySource + queryDestination + queryPictureSettings + queryVideoSettings + h264Settings + queryAudioSettings + queryAdvancedSettings + verbose;\r
+        }\r
+\r
+        // Load a Preset\r
+        private void presetLoader(Functions.QueryParser presetQuery, string name)\r
+        {\r
+            // ---------------------------\r
+            // Setup the GUI\r
+            // ---------------------------\r
+\r
+            // Source tab\r
+            #region source\r
+            if (presetQuery.Source != "")\r
+                text_source.Text = presetQuery.Source;\r
+\r
+            if (presetQuery.DVDTitle != 0)\r
+                drp_dvdtitle.Text = presetQuery.DVDTitle.ToString();\r
+\r
+            if (presetQuery.DVDChapterStart != 0)\r
+                drop_chapterStart.Text = presetQuery.DVDChapterStart.ToString();\r
+\r
+            if (presetQuery.DVDChapterFinish != 0)\r
+                drop_chapterFinish.Text = presetQuery.DVDChapterFinish.ToString();\r
+\r
+            if (presetQuery.Format != "")\r
+            {\r
+                string destination = text_destination.Text;\r
+                destination = destination.Replace(".mp4", "." + presetQuery.Format);\r
+                destination = destination.Replace(".m4v", "." + presetQuery.Format);\r
+                destination = destination.Replace(".avi", "." + presetQuery.Format);\r
+                destination = destination.Replace(".mkv", "." + presetQuery.Format);\r
+                destination = destination.Replace(".ogm", "." + presetQuery.Format);\r
+                text_destination.Text = destination;\r
+            }\r
+\r
+            #endregion\r
+\r
+            // Destination tab\r
+            #region destination\r
+\r
+            if (presetQuery.Destination != "")\r
+                text_destination.Text = presetQuery.Destination;\r
+\r
+            drp_videoEncoder.Text = presetQuery.VideoEncoder;\r
+            drp_audioCodec.Text = presetQuery.AudioEncoder;\r
+            if (presetQuery.Width != 0)\r
+            {\r
+                text_width.Text = presetQuery.Width.ToString();\r
+           \r
+            }\r
+            else\r
+            {\r
+                text_width.Text = "";\r
+                text_width.BackColor = Color.White;\r
+            }\r
+\r
+            if (presetQuery.Height != 0)\r
+            {\r
+                text_height.Text = presetQuery.Height.ToString();\r
+            }\r
+            else\r
+            {\r
+                text_height.Text = "";\r
+                text_height.BackColor = Color.White;\r
+            }\r
+            #endregion\r
+\r
+            // Picture Settings Tab\r
+            #region Picture\r
+            drp_crop.Text = "Manual";\r
+            text_top.Text = presetQuery.CropTop;\r
+            text_bottom.Text = presetQuery.CropBottom;\r
+            text_left.Text = presetQuery.CropLeft;\r
+            text_right.Text = presetQuery.CropRight;\r
+\r
+            drp_deInterlace_option.Text = presetQuery.DeInterlace;\r
+            drp_deNoise.Text = presetQuery.DeNoise;\r
+\r
+            if (presetQuery.DeTelecine == true)\r
+            {\r
+                check_detelecine.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_detelecine.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+\r
+            if (presetQuery.DeBlock == true)\r
+            {\r
+                check_deblock.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_deblock.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            if (presetQuery.ChapterMarkers == true)\r
+            {\r
+                Check_ChapterMarkers.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                Check_ChapterMarkers.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            if (presetQuery.Anamorphic == true)\r
+            {\r
+                CheckPixelRatio.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                CheckPixelRatio.CheckState = CheckState.Unchecked;\r
+            }\r
+            #endregion\r
+\r
+            // Video Settings Tab\r
+            #region video\r
+            text_bitrate.Text = presetQuery.AverageVideoBitrate;\r
+            text_filesize.Text = presetQuery.VideoTargetSize;\r
+            slider_videoQuality.Value = presetQuery.VideoQuality;\r
+            if (slider_videoQuality.Value != 0)\r
+            {\r
+                CheckCRF.Enabled = true;\r
+                int ql = presetQuery.VideoQuality;\r
+                SliderValue.Text = ql.ToString() + "%";\r
+            }\r
+\r
+            if (presetQuery.TwoPass == true)\r
+            {\r
+                check_2PassEncode.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_2PassEncode.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            if (presetQuery.Grayscale == true)\r
+            {\r
+                check_grayscale.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_grayscale.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            drp_videoFramerate.Text = presetQuery.VideoFramerate;\r
+\r
+            if (presetQuery.TurboFirstPass == true)\r
+            {\r
+                check_turbo.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_turbo.CheckState = CheckState.Unchecked;\r
+            }\r
+\r
+            if (presetQuery.LargeMP4 == true)\r
+            {\r
+                check_largeFile.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                check_largeFile.CheckState = CheckState.Unchecked;\r
+            }\r
+            if (presetQuery.CRF == true)\r
+            {\r
+                CheckCRF.CheckState = CheckState.Checked;\r
+            }\r
+            else\r
+            {\r
+                CheckCRF.CheckState = CheckState.Unchecked;\r
+            }\r
+            #endregion\r
+\r
+            // Audio Settings Tab\r
+            #region audio\r
+            drp_audioBitrate.Text = presetQuery.AudioBitrate;\r
+            drp_audioSampleRate.Text = presetQuery.AudioSampleBitrate;\r
+            drp_audioChannels.Text = presetQuery.AudioTrack1;\r
+            drp_audioMixDown.Text = presetQuery.AudioTrackMix;\r
+            drp_subtitle.Text = presetQuery.Subtitles;\r
+            #endregion\r
+\r
+            // H264 Tab & Preset Name\r
+            #region other\r
+            rtf_h264advanced.Text = presetQuery.H264Query;\r
+\r
+            // Set the preset name\r
+            groupBox_output.Text = "Output Settings (Preset: " + name + ")";\r
+            #endregion\r
         }\r
 \r
         #endregion\r
+\r
         // This is the END of the road ------------------------------------------------------------------------------\r
     }\r
 }
\ No newline at end of file