OSDN Git Service

Change the fifo size from being statically tuned for a Mac Pro with 4 CPUs to dynamic...
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index 59e31c5..06bc526 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,60 +10,82 @@ using System.Net;
 using System.IO;\r
 using System.Diagnostics;\r
 using System.Threading;\r
+using System.Runtime.InteropServices;\r
+\r
 \r
 namespace Handbrake\r
 {\r
+\r
     public partial class frmMain : Form\r
     {\r
-        private Process hbProc;\r
-        private Parsing.DVD thisDVD;\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
+        // Applicaiton Startup Stuff\r
         // --------------------------------------------------------------\r
-        private frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
-        \r
+\r
+        #region Application Startup\r
+\r
+        private Process hbProc;\r
+        private Parsing.DVD thisDVD;        \r
+        private frmQueue queueWindow = new frmQueue();  \r
+\r
         public frmMain()\r
         {\r
-            \r
-            ThreadPool.QueueUserWorkItem(showSplash);\r
-            Thread.Sleep(3000);\r
+\r
+            // Load the splash screen on another thread. Once completed wait for 1 second.\r
+            ThreadPool.QueueUserWorkItem(showSplash); \r
+            Thread.Sleep(1000);\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
+            //dvdInfoWindow.Show();\r
+            //dvdInfoWindow.Hide();\r
             // **********************************************************************************************\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
             // Run the update checker.\r
             updateCheck();\r
 \r
-            // Now load the users default if required.\r
+            // Now load the users default if required. (Will overide the above setting)\r
             loadUserDefaults();\r
+\r
+            // Enable or disable tooltips\r
+            tooltip();\r
+\r
+            // Hide the presets part of the window\r
+            this.Width = 590;\r
+\r
+            showPresets();\r
+\r
+            /*\r
+             * This code can be used for storing preset and preset name information in future versions.\r
+             * Please ignore it for the moment.\r
+            // Create and initialize a new StringCollection.\r
+            StringCollection myCol = new StringCollection();\r
+            // Add a range of elements from an array to the end of the StringCollection.\r
+            String[] myArr = new String[] { "RED", "orange", "yellow", "RED", "green", "blue", "RED", "indigo", "violet", "RED" };\r
+            myCol.AddRange(myArr);\r
+            Properties.Settings.Default.BuiltInPresets = myCol;\r
+            MessageBox.Show(Properties.Settings.Default.BuiltInPresets.ToString());\r
+            */\r
         }\r
 \r
-        public void showSplash(object sender)\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
-        public void loadUserDefaults()\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
@@ -95,10 +118,21 @@ namespace Handbrake
                     {\r
                         check_2PassEncode.CheckState = CheckState.Checked;\r
                     }\r
-                    if (Properties.Settings.Default.DeInterlace == "Checked")\r
+\r
+                    drp_deInterlace_option.Text = Properties.Settings.Default.DeInterlace;\r
+                    drp_deNoise.Text = Properties.Settings.Default.denoise;\r
+\r
+                    if (Properties.Settings.Default.detelecine == "Checked")\r
+                    {\r
+                        check_detelecine.CheckState = CheckState.Checked;\r
+                    }\r
+\r
+                    if (Properties.Settings.Default.detelecine == "Checked")\r
                     {\r
-                        check_DeInterlace.CheckState = CheckState.Checked;\r
+                        check_deblock.CheckState = CheckState.Checked;\r
                     }\r
+\r
+\r
                     if (Properties.Settings.Default.Grayscale == "Checked")\r
                     {\r
                         check_grayscale.CheckState = CheckState.Checked;\r
@@ -129,6 +163,13 @@ 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
+                else\r
+                {\r
+                    // Load the default preset on lauch\r
+                    ListBox_Presets.SelectedItem = "Normal";\r
                 }\r
             }\r
             catch (Exception)\r
@@ -137,36 +178,329 @@ 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
+        private void showPresets()\r
+        {\r
+            if (Properties.Settings.Default.showPresets == "Checked")\r
+            {\r
+                btn_presets.Visible = false;\r
+                this.Width = 881;\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
+        private void mnu_exit_Click(object sender, EventArgs e)\r
+        {\r
+            Application.Exit();\r
+        }\r
+\r
+        #endregion\r
+\r
+        #region Tools Menu\r
+\r
+        private void mnu_encode_Click(object sender, EventArgs e)\r
+        {\r
+            showQueue();\r
+        }\r
+   \r
+        private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
+        {\r
+            frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
+            dvdInfoWindow.Show();\r
+        }\r
+\r
+        private void mnu_options_Click(object sender, EventArgs e)\r
+        {\r
+            Form Options = new frmOptions();\r
+            Options.ShowDialog();\r
+        }\r
+\r
+        #endregion\r
+\r
+        #region Presets Menu\r
+\r
+        private void mnu_presetReset_Click(object sender, EventArgs e)\r
+        {\r
+            ListBox_Presets.Items.Clear();\r
+            ListBox_Presets.Items.Add("Animation");\r
+            ListBox_Presets.Items.Add("AppleTV");\r
+            ListBox_Presets.Items.Add("Bedlam");\r
+            ListBox_Presets.Items.Add("Blind");\r
+            ListBox_Presets.Items.Add("Broke");\r
+            ListBox_Presets.Items.Add("Classic");\r
+            ListBox_Presets.Items.Add("Constant Quality Rate");\r
+            ListBox_Presets.Items.Add("Deux Six Quatre");\r
+            ListBox_Presets.Items.Add("Film");\r
+            ListBox_Presets.Items.Add("iPhone");\r
+            ListBox_Presets.Items.Add("iPod High-Rez");\r
+            ListBox_Presets.Items.Add("iPod Low-Rez");\r
+            ListBox_Presets.Items.Add("Normal");\r
+            ListBox_Presets.Items.Add("PS3");\r
+            ListBox_Presets.Items.Add("PSP");\r
+            ListBox_Presets.Items.Add("QuickTime");\r
+            ListBox_Presets.Items.Add("Television");\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_SelectDefault_Click(object sender, EventArgs e)\r
+        {\r
+            ListBox_Presets.SelectedItem = "Normal";\r
+            if (presetStatus == false)\r
+            {\r
+                this.Width = 881;\r
+                presetStatus = true;\r
+                btn_presets.Text = "Hide Presets";\r
+            }\r
+        }\r
+\r
+        #endregion\r
+\r
+        #region Help Menu\r
+\r
+\r
+        private void mnu_quickStart_Click(object sender, EventArgs e)\r
+        {\r
+            Form QuickStart = new frmQuickStart();\r
+            QuickStart.ShowDialog();\r
+        }\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_UpdateCheck_Click(object sender, EventArgs e)\r
+        {\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_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
+\r
+        private void btn_Browse_Click(object sender, EventArgs e)\r
+        {\r
+            String filename = ""; \r
+                   text_source.Text = "";\r
+            frmDvdInfo dvdInfoWindow = new frmDvdInfo();                \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 btn_destBrowse_Click(object sender, EventArgs e)\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
+        }\r
+\r
+        private void btn_h264Clear_Click(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
+\r
+        private void btn_ClearQuery_Click(object sender, EventArgs e)\r
+        {\r
+            QueryEditorText.Text = "";\r
+        }\r
+\r
+        private void btn_queue_Click(object sender, EventArgs e)\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 btn_copy_Click(object sender, EventArgs e)\r
+        {\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
+        // 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_addPreset_Click(object sender, EventArgs e)\r
         {\r
             string filename;\r
             File_Open.ShowDialog();\r
@@ -178,7 +512,7 @@ namespace Handbrake
                     // 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
+\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
@@ -204,11 +538,7 @@ namespace Handbrake
                         check_2PassEncode.CheckState = CheckState.Checked;\r
                     }\r
 \r
-                    temporyLine = line.ReadLine();\r
-                    if (temporyLine == "Checked")\r
-                    {\r
-                        check_DeInterlace.CheckState = CheckState.Checked;\r
-                    }\r
+                    drp_deInterlace_option.Text = line.ReadLine();\r
 \r
                     temporyLine = line.ReadLine();\r
                     if (temporyLine == "Checked")\r
@@ -241,12 +571,12 @@ namespace Handbrake
                     {\r
                         check_largeFile.CheckState = CheckState.Checked;\r
                     }\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
+\r
                     // Advanced H264 Options\r
                     temporyLine = line.ReadLine();\r
                     if (temporyLine == "Checked")\r
@@ -262,15 +592,16 @@ namespace Handbrake
                     // Fix for SliderValue not appearing when Opening saved file\r
                     SliderValue.Text = slider_videoQuality.Value + "%";\r
 \r
-                } catch (Exception){\r
+                }\r
+                catch (Exception)\r
+                {\r
                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
                 }\r
             }\r
         }\r
 \r
-        private void mnu_save_Click(object sender, EventArgs e)\r
+        private void btn_removePreset_Click(object sender, EventArgs e)\r
         {\r
-\r
             string filename;\r
             File_Save.ShowDialog();\r
             filename = File_Save.FileName;\r
@@ -303,7 +634,7 @@ namespace Handbrake
                     line.WriteLine(text_filesize.Text);\r
                     line.WriteLine(slider_videoQuality.Value.ToString());\r
                     line.WriteLine(check_2PassEncode.CheckState.ToString());\r
-                    line.WriteLine(check_DeInterlace.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
@@ -320,375 +651,212 @@ namespace Handbrake
                     line.WriteLine(rtf_h264advanced.Text);\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
-                {\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
-        private void mnu_exit_Click(object sender, EventArgs e)\r
-        {\r
-            this.Close();\r
-        }\r
-\r
-        #endregion\r
-\r
-        #region Tools Menu\r
-\r
-        private void mnu_encode_Click(object sender, EventArgs e)\r
-        {\r
-            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
-            }\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
-        }\r
-\r
-        private void mnu_options_Click(object sender, EventArgs e)\r
-        {\r
-            Form Options = new frmOptions();\r
-            Options.ShowDialog();\r
-        }\r
-\r
-        #endregion\r
-\r
-        #region Presets Menu\r
-\r
-        private void mnu_preset_ipod133_Click(object sender, EventArgs e)\r
-        {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "640";\r
-            text_height.Text = "480";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "1000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            rtf_h264advanced.Text = "";\r
-            drp_crop.Text = "No Crop";\r
-        }\r
-\r
-        private void mnu_preset_ipod178_Click(object sender, EventArgs e)\r
-        {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "640";\r
-            text_height.Text = "352";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "1000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            rtf_h264advanced.Text = "";\r
-            drp_crop.Text = "No Crop";\r
-        }\r
-\r
-        private void mnu_preset_ipod235_Click(object sender, EventArgs e)\r
-        {\r
-            CheckPixelRatio.CheckState = CheckState.Unchecked;\r
-            text_width.Text = "640";\r
-            text_height.Text = "272";\r
-            drp_videoEncoder.Text = "H.264 (iPod)";\r
-            text_bitrate.Text = "1000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            rtf_h264advanced.Text = "";\r
-            drp_crop.Text = "No Crop";\r
-        }\r
-\r
-        private void mnu_appleTv_Click(object sender, EventArgs e)\r
-        {\r
-            text_width.Text = "";\r
-            text_height.Text = "";\r
-            drp_videoEncoder.Text = "H.264";\r
-            text_bitrate.Text = "3000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";\r
-            drp_crop.Text = "No Crop";\r
-            \r
-        }\r
-\r
-        private void mnu_presetPS3_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 = "3000";\r
-            text_filesize.Text = "";\r
-            slider_videoQuality.Value = 0;\r
-            SliderValue.Text = "0%";\r
-            drp_audioBitrate.Text = "160";\r
-            CheckPixelRatio.CheckState = CheckState.Checked;\r
-            drp_audioSampleRate.Text = "48";\r
-            rtf_h264advanced.Text = "level=41";\r
-            drp_crop.Text = "No Crop";\r
-        }\r
-\r
-        private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)\r
-        {\r
-            //Source\r
-            Properties.Settings.Default.DVDSource = text_source.Text;\r
-            Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
-            Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
-            Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
-            //Destination\r
-            Properties.Settings.Default.VideoDest = text_destination.Text;\r
-            Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
-            Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
-            Properties.Settings.Default.Width = text_width.Text;\r
-            Properties.Settings.Default.Height = text_height.Text;\r
-            //Picture Settings Tab\r
-            Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
-            Properties.Settings.Default.CropTop = text_top.Text;\r
-            Properties.Settings.Default.CropBottom = text_bottom.Text;\r
-            Properties.Settings.Default.CropLeft = text_left.Text;\r
-            Properties.Settings.Default.CropRight = text_right.Text;\r
-            Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
-            //Video Settings Tab\r
-            Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
-            Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
-            Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
-            Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
-            Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString();\r
-            Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
-            Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
-            Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
-            Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
-            Properties.Settings.Default.largeFile = check_largeFile.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_onlineDocs_Click(object sender, EventArgs e)\r
-        {\r
-            Process.Start("http://handbrake.m0k.org/?page_id=11");\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_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
-        private void btn_Browse_Click(object sender, EventArgs e)\r
-        {\r
-            \r
-            String filename ="";\r
-            text_source.Text = "";\r
-            \r
-            //int scanTwice = 0;\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
+                    MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
                 }\r
-            }\r
-            else\r
-            {\r
-                ISO_Open.ShowDialog();\r
-                filename = ISO_Open.FileName;\r
-                if (filename != "")\r
+                catch (Exception)\r
                 {\r
-                    Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
-                    text_source.Text = filename;\r
-                    frmRD.ShowDialog();\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
-            // Check if there was titles in the dvd title dropdown\r
-            // If there isn't any, rescan the DVD. hbcli occasionally fails (see bug in encode) with standard error.\r
-            if (filename != "")\r
-            {\r
-               // Disbaled the 2nd pass for the time being.\r
-               /* if (drp_dvdtitle.Items.Count == 0) \r
-                {\r
-                    if (scanTwice == 0)\r
-                    {\r
-                        MessageBox.Show("Scan Failed. Waiting 5 Seconds before attempting to re-scan the source a 2nd time.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
-                        Thread.Sleep(3000);\r
-                        Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);\r
-                        frmRD.ShowDialog();\r
-                        scanTwice = 1;\r
-                    }\r
-                }*/\r
-            }\r
-            else\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
 \r
-        private void btn_destBrowse_Click(object sender, EventArgs e)\r
+        private void btn_setDefault_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
+            //Source\r
+            Properties.Settings.Default.DVDSource = text_source.Text;\r
+            Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
+            Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
+            Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
+            //Destination\r
+            Properties.Settings.Default.VideoDest = text_destination.Text;\r
+            Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
+            Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
+            Properties.Settings.Default.Width = text_width.Text;\r
+            Properties.Settings.Default.Height = text_height.Text;\r
+            //Picture Settings Tab\r
+            Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
+            Properties.Settings.Default.CropTop = text_top.Text;\r
+            Properties.Settings.Default.CropBottom = text_bottom.Text;\r
+            Properties.Settings.Default.CropLeft = text_left.Text;\r
+            Properties.Settings.Default.CropRight = text_right.Text;\r
+            Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
+            //Video Settings Tab\r
+            Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
+            Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
+            Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
+            Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
+            Properties.Settings.Default.DeInterlace = drp_deInterlace_option.Text;\r
+            Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
+            Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
+            Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
+            Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
+            Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
+            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
+            //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
+            try\r
             {\r
-                string destination = text_destination.Text;\r
-                destination = destination.Replace(".mp4", ".m4v");\r
-                text_destination.Text = destination;\r
+                Properties.Settings.Default.selectedPreset = ListBox_Presets.SelectedItem.ToString();\r
             }\r
+            catch (Exception exc)\r
+            {\r
+                // If the user has not selected an item, then an exception may be thrown. Catch and ignore.\r
+            }\r
+            Properties.Settings.Default.Save();\r
         }\r
 \r
-        private void btn_h264Clear_Click(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
-\r
-        private void btn_ClearQuery_Click(object sender, EventArgs e)\r
-        {\r
-            QueryEditorText.Text = "";\r
-        }\r
-\r
-        private void btn_queue_Click(object sender, EventArgs e)\r
+        // Preset Seleciton\r
+        private void ListBox_Presets_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            if (text_destination.Text != "" && text_source.Text != "")\r
+            string selectedPreset = null;\r
+            if (ListBox_Presets.SelectedItem != null)\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
-            else \r
+                selectedPreset = ListBox_Presets.SelectedItem.ToString();\r
+            }\r
+            else\r
+            {\r
+                selectedPreset = "";\r
+            }\r
+\r
+            switch (selectedPreset)\r
             {\r
-                MessageBox.Show("No Source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                case "Animation":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "1000", "", 0, "0%", "160", CheckState.Checked, "48", "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", "Origional (Fast)", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Apple Animation)");\r
+                    setMkv();\r
+                    break;\r
+                case "AppleTV":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "2500", "", 0, "0%", "160", CheckState.Checked, "48", "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Apple TV)");\r
+                    break;\r
+                case "Bedlam":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "1800", "", 0, "0%", "160", CheckState.Checked, "48", "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", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Bedlam)");\r
+                    setMkv();\r
+                    break;\r
+                case "Blind":\r
+                    setGuiSetttings(CheckState.Unchecked, "512", "", "H.264", "512", "", 0, "0%", "128", CheckState.Checked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Blind)");\r
+                    break;\r
+                case "Broke":\r
+                    setGuiSetttings(CheckState.Unchecked, "640", "", "H.264", "", "695", 0, "0%", "128", CheckState.Checked, "48", "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", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Broke)");\r
+                    break;\r
+                case "Classic":\r
+                    setGuiSetttings(CheckState.Unchecked, "", "", "H.264", "1000", "", 0, "0%", "160", CheckState.Unchecked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: Classic)");\r
+                    break;\r
+                case "Constant Quality Rate":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "", "", 64, "64%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=3:b-pyramid:b-rdo:bime:weightb:filter=-2,-1:subme=6:trellis=1:analyse=all:8x8dct:me=umh", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AC3", "Output Settings (Preset: CQR)");\r
+                    setMkv();\r
+                    break;\r
+                case "Deux Six Quatre":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "1600", "", 0, "0%", "160", CheckState.Checked, "48", "ref=5:mixed-refs:bframes=3:bime:weightb:b-rdo:b-pyramid:me=umh:subme=7:trellis=1:analyse=all:8x8dct:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AC3", "Output Settings (Preset: DSQ)");\r
+                    setMkv();\r
+                    break;\r
+                case "Film":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "2000", "", 0, "0%", "160", CheckState.Checked, "48", "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", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AC3", "Output Settings (Preset: Film)");\r
+                    setMkv();\r
+                    break;\r
+                case "iPhone":\r
+                    setGuiSetttings(CheckState.Unchecked, "480", "", "H.264", "960", "", 0, "0%", "128", CheckState.Checked, "48", "cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPhone)");\r
+                    break;\r
+                case "iPod High-Rez":\r
+                    setGuiSetttings(CheckState.Unchecked, "640", "", "H.264", "1500", "", 0, "0%", "160", CheckState.Checked, "48", "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", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPod High Rez)");\r
+                    break;\r
+                case "iPod Low-Rez":\r
+                    setGuiSetttings(CheckState.Unchecked, "320", "", "H.264", "700", "", 0, "0%", "160", CheckState.Checked, "48", "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", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: iPod Low Rez)");\r
+                    break;\r
+                case "Normal":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "1500", "", 0, "0%", "160", CheckState.Checked, "48", "ref=2:bframes=2:subme=5:me=umh", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Normal)");\r
+                    break;\r
+                case "PS3":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "2500", "", 0, "0%", "160", CheckState.Checked, "48", "level=41:subme=5:me=umh", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: PS3)");\r
+                    break;\r
+                case "PSP":\r
+                    setGuiSetttings(CheckState.Unchecked, "368", "208", "Mpeg 4", "1024", "", 0, "0%", "160", CheckState.Unchecked, "48", "", "None", CheckState.Unchecked, "No Crop", CheckState.Unchecked, "AAC", "Output Settings (Preset: PSP)");\r
+                    break;\r
+                case "QuickTime":\r
+                    setGuiSetttings(CheckState.Checked, "", "", "H.264", "2000", "", 0, "0%", "160", CheckState.Checked, "48", "ref=3:mixed-refs:bframes=3:bime:weightb:b-rdo:direct-auto:me=umh:subme=5:analyse=all:8x8dct:trellis=1:no-fast-pskip", "None", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Quicktime)");\r
+                    break;\r
+                case "Television":\r
+                    setGuiSetttings(CheckState.Unchecked, "", "", "H.264", "1300", "", 0, "0%", "160", CheckState.Checked, "48", "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", "Origional (Fast)", CheckState.Checked, "No Crop", CheckState.Checked, "AAC", "Output Settings (Preset: Television)");\r
+                    setMkv();\r
+                    break;\r
+                default:\r
+                    break;\r
             }\r
         }\r
 \r
-        private void showQueue()\r
+        // Functions - It's a bit dirty but i'll sort this out later. Simply done to reduce the amount of code above.\r
+        private void setGuiSetttings(CheckState anamorphic, string width, string height, string vencoder, string bitrate, string filesize, int quality, string qpercent, string audioBit, CheckState chpt, string audioSample, string h264, string deinterlace, CheckState twopass, string crop, CheckState turbo, string audioCodec, string preset)\r
         {\r
-            queueWindow.Show();\r
+            CheckPixelRatio.CheckState = anamorphic;\r
+            text_width.Text = width;\r
+            text_height.Text = height;\r
+            drp_videoEncoder.Text = vencoder;\r
+            text_bitrate.Text = bitrate;\r
+            text_filesize.Text = filesize;\r
+            slider_videoQuality.Value = quality;\r
+            SliderValue.Text = qpercent;\r
+            drp_audioBitrate.Text = audioBit;\r
+            Check_ChapterMarkers.CheckState = chpt;\r
+            drp_audioSampleRate.Text = audioSample;\r
+            rtf_h264advanced.Text = h264;\r
+            drp_deInterlace_option.Text = deinterlace;\r
+            check_2PassEncode.CheckState = twopass;\r
+            drp_crop.Text = crop;\r
+            check_turbo.CheckState = turbo;\r
+            drp_audioCodec.Text = audioCodec;\r
+\r
+            groupBox_output.Text = preset;\r
         }\r
 \r
+        private void setMkv()\r
+        {\r
+            // Set file extension to MKV\r
+            string destination = text_destination.Text;\r
+            destination = destination.Replace(".mp4", ".mkv");\r
+            destination = destination.Replace(".avi", ".mkv");\r
+            destination = destination.Replace(".m4v", ".mkv");\r
+            destination = destination.Replace(".ogm", ".mkv");\r
+            text_destination.Text = destination;\r
+        }\r
 \r
-\r
-\r
+        #endregion\r
 \r
         //---------------------------------------------------\r
         // Encode / Cancel Buttons\r
         // Encode Progress Text Handler\r
         //---------------------------------------------------\r
 \r
+        #region Encode/CLI\r
+\r
         Functions.CLI process = new Functions.CLI();\r
 \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
@@ -697,7 +865,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
@@ -708,12 +881,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
@@ -722,7 +894,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
@@ -731,20 +903,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
@@ -753,14 +966,18 @@ namespace Handbrake
             }\r
             lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
         }\r
-        \r
+\r
+        #endregion\r
+\r
         //---------------------------------------------------\r
         //  Items that require actions on frmMain\r
         //---------------------------------------------------\r
 \r
+        #region frmMain Actions\r
+\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
@@ -771,14 +988,12 @@ 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
@@ -787,7 +1002,7 @@ namespace Handbrake
 \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
@@ -798,14 +1013,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
@@ -883,6 +1096,7 @@ namespace Handbrake
             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
@@ -892,20 +1106,23 @@ namespace Handbrake
         {\r
             try\r
             {\r
-                if (CheckPixelRatio.Checked)\r
-                {\r
-                    text_height.Text = "";\r
-                    text_width.BackColor = Color.White;\r
-                }\r
-                else\r
+                if (text_height.Text != "Auto")\r
                 {\r
-                    if ((int.Parse(text_height.Text) % 16) != 0)\r
+                    if (CheckPixelRatio.Checked)\r
                     {\r
-                        text_height.BackColor = Color.LightCoral;\r
+                        text_height.Text = "";\r
+                        text_width.BackColor = Color.White;\r
                     }\r
                     else\r
                     {\r
-                        text_height.BackColor = Color.LightGreen;\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
                     }\r
                 }\r
             } catch(Exception){\r
@@ -969,7 +1186,7 @@ namespace Handbrake
 \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
@@ -1026,7 +1243,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
@@ -1065,6 +1281,12 @@ namespace Handbrake
                 destination = destination.Replace(".mp4", ".m4v");\r
                 text_destination.Text = destination;\r
             }\r
+            else\r
+            {\r
+                string destination = text_destination.Text;\r
+                destination = destination.Replace(".m4v", ".mp4");\r
+                text_destination.Text = destination;\r
+            }\r
         }\r
 \r
         private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
@@ -1086,6 +1308,7 @@ namespace Handbrake
                 CheckCRF.Enabled = false;\r
                 check_turbo.Enabled = false;\r
                 h264Tab.Enabled = false;\r
+                rtf_h264advanced.Text = "";\r
             }\r
             else\r
             {\r
@@ -1158,9 +1381,15 @@ namespace Handbrake
             }\r
         }\r
 \r
+        #endregion\r
+\r
         //---------------------------------------------------\r
-        //  The query Generation function.\r
+        //  Some Functions\r
+        //  - Query Generation\r
         //---------------------------------------------------\r
+\r
+        #region Program Functions\r
+\r
         public string GenerateTheQuery()\r
         {\r
             string source = text_source.Text;\r
@@ -1170,12 +1399,7 @@ 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
                 dvdTitle = "";\r
@@ -1252,10 +1476,16 @@ namespace Handbrake
 \r
             if (width !=  "")\r
                 width = " -w "+ width;\r
-            \r
 \r
-            if (height !=  "")\r
-                height = " -l "+ height;\r
+\r
+            if (height == "Auto")\r
+            {\r
+                height = "";\r
+            }\r
+            else if (height != "")\r
+            {\r
+                height = " -l " + height;\r
+            }\r
             \r
 \r
             string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
@@ -1270,6 +1500,11 @@ namespace Handbrake
             string cropRight = text_right.Text;\r
             string subtitles = drp_subtitle.Text;\r
             string cropOut = "";\r
+            string deInterlace_Option = drp_deInterlace_option.Text;\r
+            string deinterlace = "";\r
+            string grayscale = "";\r
+            string pixelRatio = "";\r
+            string ChapterMarkers = "";\r
             // Returns Crop Query\r
 \r
             if (cropSetting == "Auto Crop")\r
@@ -1277,7 +1512,18 @@ 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
                 subtitles = "";\r
@@ -1290,23 +1536,60 @@ namespace Handbrake
                 subtitles = " -s "+ tempSub[0];\r
             }\r
 \r
-            string queryPictureSettings = cropOut+ subtitles;\r
+            switch (deInterlace_Option)\r
+            {\r
+                case "None":\r
+                    deinterlace = "";\r
+                    break;\r
+                case "Origional (Fast)":\r
+                    deinterlace = " --deinterlace=1";\r
+                    break;\r
+                case "yadif (Slow)":\r
+                    deinterlace = " --deinterlace=" + '"' + "0" + '"';\r
+                    break;\r
+                case "yadif + mcdeint (Slower)":\r
+                    deinterlace = " --deinterlace=" + '"' + "2:-1:1" + '"';\r
+                    break;\r
+                case "yadif + mcdeint (Slowest)":\r
+                    deinterlace = " --deinterlace=" + '"' + "1:-1:1" + '"';\r
+                    break;\r
+                default:\r
+                    deinterlace = "";\r
+                    break;\r
+            }\r
+\r
+            if (check_grayscale.Checked)\r
+                grayscale = " -g ";\r
+\r
+            if (CheckPixelRatio.Checked)\r
+                pixelRatio = " -p ";\r
+\r
+            if (Check_ChapterMarkers.Checked)\r
+                ChapterMarkers = " -m ";\r
+\r
+            string queryPictureSettings = cropOut + subtitles + deinterlace + grayscale + pixelRatio + ChapterMarkers;\r
             // ----------------------------------------------------------------------\r
 \r
             // Video Settings Tab\r
 \r
             string videoBitrate = text_bitrate.Text;\r
             string videoFilesize = text_filesize.Text;\r
-            int videoQuality = slider_videoQuality.Value;\r
+            double videoQuality = slider_videoQuality.Value;\r
             string vidQSetting = "";\r
             string twoPassEncoding = "";\r
-            string deinterlace = "";\r
-            string grayscale = "";\r
             string videoFramerate = drp_videoFramerate.Text;\r
-            string pixelRatio = "";\r
-            string ChapterMarkers = "";\r
             string turboH264 = "";\r
             string largeFile = "";\r
+            string deblock = "";\r
+            string detelecine = "";\r
+            string denoise = "";\r
+            string CRF = CheckCRF.CheckState.ToString();\r
+\r
+\r
+            if ((CRF == "Checked"))\r
+                CRF = " -Q ";\r
+            else\r
+                CRF = "";\r
 \r
             if (videoBitrate !=  "")\r
                 videoBitrate = " -b "+ videoBitrate;\r
@@ -1320,7 +1603,7 @@ namespace Handbrake
                 vidQSetting = "";\r
             else\r
             {\r
-                videoQuality = videoQuality/ 100;\r
+                videoQuality = videoQuality / 100;\r
                 if (videoQuality ==  1)\r
                 {\r
                     vidQSetting = "1.0";\r
@@ -1332,30 +1615,43 @@ namespace Handbrake
             if (check_2PassEncode.Checked)\r
                 twoPassEncoding = " -2 ";\r
 \r
-            if (check_DeInterlace.Checked)\r
-                deinterlace = " -d ";\r
-\r
-            if (check_grayscale.Checked)\r
-                grayscale = " -g ";\r
-\r
             if (videoFramerate ==  "Automatic")\r
                 videoFramerate = "";\r
             else\r
                 videoFramerate = " -r "+ videoFramerate;\r
 \r
-            if (CheckPixelRatio.Checked)\r
-                pixelRatio = " -p ";\r
-\r
-            if (Check_ChapterMarkers.Checked)\r
-                ChapterMarkers = " -m ";\r
-\r
             if (check_turbo.Checked)\r
                 turboH264 = " -T ";\r
 \r
             if (check_largeFile.Checked)\r
                 largeFile = " -4 ";\r
 \r
-            string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile;\r
+            if (check_deblock.Checked)\r
+                deblock = " --deblock";\r
+\r
+            if (check_detelecine.Checked)\r
+                detelecine = " --detelecine";\r
+\r
+            switch (drp_deNoise.Text)\r
+            {\r
+                case "None":\r
+                    denoise = "";\r
+                    break;\r
+                case "Weak":\r
+                    denoise = " --denoise=2:1:2:3";\r
+                    break;\r
+                case "Medium":\r
+                    denoise = " --denoise=3:2:2:3";\r
+                    break;\r
+                case "Strong":\r
+                    denoise = " --denoise=7:7:5:5";\r
+                    break;\r
+                default:\r
+                    denoise = "";\r
+                    break;\r
+            }\r
+\r
+            string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + videoFramerate + turboH264 + largeFile + deblock + detelecine + denoise;\r
             // ----------------------------------------------------------------------\r
 \r
             // Audio Settings Tab\r
@@ -1418,20 +1714,16 @@ namespace Handbrake
 \r
             //  H.264 Tab\r
 \r
-            string CRF = CheckCRF.CheckState.ToString();\r
+            \r
             string h264Advanced = rtf_h264advanced.Text;\r
-            if ((CRF ==  "1"))\r
-                CRF = " -Q ";\r
-            else\r
-                CRF = "";\r
-\r
+            \r
             if ((h264Advanced ==  ""))\r
                 h264Advanced = "";\r
             else\r
                 h264Advanced = " -x "+ h264Advanced;\r
     \r
 \r
-            string h264Settings = CRF+ h264Advanced;\r
+            string h264Settings = h264Advanced;\r
             // ----------------------------------------------------------------------\r
 \r
             // Processors (Program Settings)\r
@@ -1459,8 +1751,8 @@ namespace Handbrake
             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
         }\r
 \r
-        \r
+        #endregion\r
 \r
         // This is the END of the road ------------------------------------------------------------------------------\r
     }\r
-}
\ No newline at end of file
+}\r