OSDN Git Service

LinGui: make Help->Guide work on windows/mingw
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index 0f27287..1a1cfae 100644 (file)
@@ -1,51 +1,84 @@
 /*  frmMain.cs $\r
-       \r
-          This file is part of the HandBrake source code.\r
-          Homepage: <http://handbrake.fr/>.\r
-          It may be used under the terms of the GNU General Public License. */\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Drawing;\r
-using System.Globalization;\r
-using System.Windows.Forms;\r
-using System.IO;\r
-using System.Diagnostics;\r
-using System.Threading;\r
-using Handbrake.EncodeQueue;\r
-using Handbrake.Functions;\r
-using Handbrake.Presets;\r
-using Handbrake.Parsing;\r
+    This file is part of the HandBrake source code.\r
+    Homepage: <http://handbrake.fr/>.\r
+    It may be used under the terms of the GNU General Public License. */\r
 \r
 namespace Handbrake\r
 {\r
+    using System;\r
+    using System.Collections.Generic;\r
+    using System.ComponentModel;\r
+    using System.Diagnostics;\r
+    using System.Drawing;\r
+    using System.Globalization;\r
+    using System.IO;\r
+    using System.Reflection;\r
+    using System.Threading;\r
+    using System.Windows.Forms;\r
+    using Functions;\r
+    using Model;\r
+    using Parsing;\r
+    using Presets;\r
+    using Properties;\r
+    using Services;\r
+\r
     public partial class frmMain : Form\r
     {\r
         // Objects which may be used by one or more other objects *************\r
-        EncodeAndQueueHandler encodeQueue = new EncodeAndQueueHandler();\r
-        PresetsHandler presetHandler = new PresetsHandler();\r
-        QueryGenerator queryGen = new QueryGenerator();\r
+        private Queue encodeQueue = new Queue();\r
+        private PresetsHandler presetHandler = new PresetsHandler();\r
 \r
-        // Globals: Mainly used for tracking. *********************************\r
-        public Title selectedTitle;\r
-        private DVD thisDVD;\r
+        // Windows ************************************************************\r
         private frmQueue queueWindow;\r
         private frmPreview qtpreview;\r
         private frmActivityWindow ActivityWindow;\r
-        private Form splash;\r
+        private frmSplashScreen splash = new frmSplashScreen();\r
+\r
+        // Globals: Mainly used for tracking. *********************************\r
+        public Title selectedTitle;\r
         public string sourcePath;\r
-        private string lastAction;\r
+        private SourceType selectedSourceType;\r
+        private string dvdDrivePath;\r
+        private string dvdDriveLabel;\r
+        private Preset CurrentlySelectedPreset;\r
+        private DVD currentSource;\r
+        private ScanService SourceScan = new ScanService();\r
+        private List<DriveInformation> drives;\r
+        private Thread encodeMonitor;\r
 \r
         // Delegates **********************************************************\r
         private delegate void UpdateWindowHandler();\r
 \r
         // Applicaiton Startup ************************************************\r
 \r
+        #region Properties\r
+\r
+        /// <summary>\r
+        /// Gets SourceName.\r
+        /// </summary>\r
+        public string SourceName\r
+        {\r
+            get\r
+            {\r
+                if (this.selectedSourceType == SourceType.DvdDrive)\r
+                {\r
+                    return this.dvdDriveLabel;\r
+                }\r
+\r
+                if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")\r
+                    return Path.GetFileNameWithoutExtension(this.sourcePath);\r
+\r
+                return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));\r
+            }\r
+        }\r
+\r
+        #endregion\r
+\r
         #region Application Startup\r
+\r
         public frmMain()\r
         {\r
             // Load and setup the splash screen in this thread\r
-            splash = new frmSplashScreen();\r
             splash.Show(this);\r
             Label lblStatus = new Label { Size = new Size(150, 20), Location = new Point(182, 102) };\r
             splash.Controls.Add(lblStatus);\r
@@ -53,11 +86,17 @@ namespace Handbrake
             InitializeComponent();\r
 \r
             // Update the users config file with the CLI version data.\r
-            lblStatus.Text = "Setting Version Data ...";\r
-            Application.DoEvents();\r
-            Main.setCliVersionData();\r
+            UpdateSplashStatus(lblStatus, "Checking CLI Version Data ...");\r
+            Main.SetCliVersionData();\r
+            Main.CheckForValidCliVersion();\r
+\r
+            if (Settings.Default.hb_version.Contains("svn"))\r
+            {\r
+                Version v = Assembly.GetExecutingAssembly().GetName().Version;\r
+                this.Text += " " + v.ToString(4);\r
+            }\r
 \r
-            // Show the form, but leave disabled until preloading is complete then show the main form\r
+            // Show the form, but leave disabled until preloading is complete then show the main form)\r
             this.Enabled = false;\r
             this.Show();\r
             Application.DoEvents(); // Forces frmMain to draw\r
@@ -70,58 +109,55 @@ namespace Handbrake
                 TimeSpan elapsed = now.Subtract(lastCheck);\r
                 if (elapsed.TotalDays > Properties.Settings.Default.daysBetweenUpdateCheck)\r
                 {\r
-                    lblStatus.Text = "Checking for updates ...";\r
-                    Application.DoEvents();\r
-\r
+                    UpdateSplashStatus(lblStatus, "Checking for updates ...");\r
                     Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false);\r
                 }\r
             }\r
 \r
+            // Clear the log files in the background\r
+            if (Properties.Settings.Default.clearOldLogs)\r
+            {\r
+                UpdateSplashStatus(lblStatus, "Clearing Old Log Files ..");\r
+                Thread clearLog = new Thread(Main.ClearOldLogs);\r
+                clearLog.Start();\r
+            }\r
+\r
             // Setup the GUI components\r
-            lblStatus.Text = "Setting up the GUI ...";\r
-            Application.DoEvents();\r
-            loadPresetPanel();                       // Load the Preset Panel\r
+            UpdateSplashStatus(lblStatus, "Setting up the GUI ...");\r
+            LoadPresetPanel(); // Load the Preset Panel\r
             treeView_presets.ExpandAll();\r
-            lbl_encode.Text = "";\r
-            queueWindow = new frmQueue(encodeQueue);        // Prepare the Queue\r
+            lbl_encode.Text = string.Empty;\r
+            drop_mode.SelectedIndex = 0;\r
+            queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue\r
             if (!Properties.Settings.Default.QueryEditorTab)\r
                 tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.\r
+            if (Properties.Settings.Default.tooltipEnable)\r
+                ToolTip.Active = true;\r
 \r
             // Load the user's default settings or Normal Preset\r
-            if (Properties.Settings.Default.defaultSettings && Properties.Settings.Default.defaultPreset != "")\r
+            if (Properties.Settings.Default.defaultPreset != string.Empty && presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)\r
             {\r
-                if (presetHandler.getPreset(Properties.Settings.Default.defaultPreset) != null)\r
+                string query = presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).Query;\r
+                if (query != null)\r
                 {\r
-                    string query = presetHandler.getPreset(Properties.Settings.Default.defaultPreset).Query;\r
-                    Boolean loadPictureSettings = presetHandler.getPreset(Properties.Settings.Default.defaultPreset).PictureSettings;\r
+                    x264Panel.Reset2Defaults();\r
 \r
-                    if (query != null)\r
-                    {\r
-                        //Ok, Reset all the H264 widgets before changing the preset\r
-                        x264Panel.reset2Defaults();\r
-\r
-                        // Send the query from the file to the Query Parser class, then load the preset\r
-                        QueryParser presetQuery = QueryParser.Parse(query);\r
-                        PresetLoader.presetLoader(this, presetQuery, Properties.Settings.Default.defaultPreset, loadPictureSettings);\r
+                    QueryParser presetQuery = QueryParser.Parse(query);\r
+                    PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset,\r
+                                            presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).PictureSettings);\r
 \r
-                        // The x264 widgets will need updated, so do this now:\r
-                        x264Panel.X264_StandardizeOptString();\r
-                        x264Panel.X264_SetCurrentSettingsInPanel();\r
-                    }\r
+                    x264Panel.X264_StandardizeOptString();\r
+                    x264Panel.X264_SetCurrentSettingsInPanel();\r
                 }\r
-                else\r
-                    loadNormalPreset();\r
             }\r
             else\r
                 loadNormalPreset();\r
 \r
-            // Enabled GUI tooltip's if Required\r
-            if (Properties.Settings.Default.tooltipEnable)\r
-                ToolTip.Active = true;\r
+            // Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)\r
+            GrowlCommunicator.Register();\r
 \r
-            //Finished Loading\r
-            lblStatus.Text = "Loading Complete!";\r
-            Application.DoEvents();\r
+            // Finished Loading\r
+            UpdateSplashStatus(lblStatus, "Loading Complete.");\r
             splash.Close();\r
             splash.Dispose();\r
             this.Enabled = true;\r
@@ -154,16 +190,19 @@ namespace Handbrake
             catch (Exception ex)\r
             {\r
                 if ((bool)result.AsyncState)\r
-                    MessageBox.Show("Unable to check for updates, Please try again later. \n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                    Main.ShowExceptiowWindow("Unable to check for updates, Please try again later.", ex.ToString());\r
             }\r
         }\r
 \r
         // Startup Functions   \r
         private void queueRecovery()\r
         {\r
-            if (Main.check_queue_recovery())\r
+            if (Main.CheckQueueRecovery())\r
             {\r
-                DialogResult result = MessageBox.Show("HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?", "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+                DialogResult result =\r
+                    MessageBox.Show(\r
+                        "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?",\r
+                        "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
 \r
                 if (result == DialogResult.Yes)\r
                     encodeQueue.LoadQueueFromFile("hb_queue_recovery.xml"); // Start Recovery\r
@@ -176,23 +215,31 @@ namespace Handbrake
                 }\r
             }\r
         }\r
+\r
+        private void UpdateSplashStatus(Label status, string text)\r
+        {\r
+            status.Text = text;\r
+            Application.DoEvents();\r
+        }\r
+\r
         #endregion\r
 \r
         #region Events\r
+\r
         // Encoding Events for setting up the GUI\r
         private void events()\r
         {\r
             // Handle Widget changes when preset is selected.\r
-            registerPresetEventHandler();\r
+            RegisterPresetEventHandler();\r
 \r
             // Handle Window Resize\r
             if (Properties.Settings.Default.MainWindowMinimize)\r
                 this.Resize += new EventHandler(frmMain_Resize);\r
 \r
             // Handle Encode Start / Finish / Pause\r
-            encodeQueue.CurrentJobCompleted += new EventHandler(encodeEnded);\r
             encodeQueue.QueuePauseRequested += new EventHandler(encodePaused);\r
-            encodeQueue.NewJobStarted += new EventHandler(encodeStarted);\r
+            encodeQueue.EncodeStarted += new EventHandler(encodeStarted);\r
+            encodeQueue.EncodeEnded += new EventHandler(encodeEnded);\r
 \r
             // Handle a file being draged onto the GUI.\r
             this.DragEnter += new DragEventHandler(frmMain_DragEnter);\r
@@ -200,7 +247,7 @@ namespace Handbrake
         }\r
 \r
         // Change the preset label to custom when a user changes a setting. Don't want to give the impression that users can change settings and still be using a preset\r
-        public void registerPresetEventHandler()\r
+        private void RegisterPresetEventHandler()\r
         {\r
             // Output Settings\r
             drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);\r
@@ -209,7 +256,7 @@ namespace Handbrake
             check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);\r
 \r
             // Picture Settings\r
-            //PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);\r
+            PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);\r
 \r
             // Filter Settings\r
             Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);\r
@@ -228,7 +275,8 @@ namespace Handbrake
             // Advanced Tab\r
             x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);\r
         }\r
-        public void unRegisterPresetEventHandler()\r
+\r
+        private void UnRegisterPresetEventHandler()\r
         {\r
             // Output Settings \r
             drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);\r
@@ -237,7 +285,7 @@ namespace Handbrake
             check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);\r
 \r
             // Picture Settings\r
-            //PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);\r
+            PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);\r
 \r
             // Filter Settings\r
             Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);\r
@@ -256,9 +304,11 @@ namespace Handbrake
             // Advanced Tab\r
             x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);\r
         }\r
+\r
         private void changePresetLabel(object sender, EventArgs e)\r
         {\r
             labelPreset.Text = "Output Settings (Preset: Custom)";\r
+            CurrentlySelectedPreset = null;\r
         }\r
 \r
         private static void frmMain_DragEnter(object sender, DragEventArgs e)\r
@@ -266,6 +316,7 @@ namespace Handbrake
             if (e.Data.GetDataPresent(DataFormats.FileDrop, false))\r
                 e.Effect = DragDropEffects.All;\r
         }\r
+\r
         private void frmMain_DragDrop(object sender, DragEventArgs e)\r
         {\r
             string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];\r
@@ -273,187 +324,264 @@ namespace Handbrake
 \r
             if (fileList != null)\r
             {\r
-                if (fileList[0].StartsWith("\\"))\r
+                if (!string.IsNullOrEmpty(fileList[0]))\r
                 {\r
-                    MessageBox.Show(\r
-                        "Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer",\r
-                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-                    UpdateSourceLabel();\r
+                    this.selectedSourceType = SourceType.VideoFile;\r
+                    StartScan(fileList[0], 0);\r
                 }\r
                 else\r
-                {\r
-                    if (fileList[0] != "")\r
-                    {\r
-                        setupGUIforScan(fileList[0]);\r
-                        startScan(fileList[0]);\r
-                    }\r
-                    else\r
-                        UpdateSourceLabel();\r
-                }\r
+                    UpdateSourceLabel();\r
             }\r
             else\r
                 UpdateSourceLabel();\r
         }\r
+\r
         private void encodeStarted(object sender, EventArgs e)\r
         {\r
-            lastAction = "encode";\r
-            setEncodeStarted();\r
+            SetEncodeStarted();\r
 \r
             // Experimental HBProc Process Monitoring.\r
             if (Properties.Settings.Default.enocdeStatusInGui)\r
             {\r
-                Thread encodeMon = new Thread(encodeMonitorThread);\r
-                encodeMon.Start();\r
+                encodeMonitor = new Thread(EncodeMonitorThread);\r
+                encodeMonitor.Start();\r
             }\r
         }\r
+\r
         private void encodeEnded(object sender, EventArgs e)\r
         {\r
-            setEncodeFinished();\r
+            SetEncodeFinished();\r
         }\r
+\r
         private void encodePaused(object sender, EventArgs e)\r
         {\r
-            setEncodeFinished();\r
+            SetEncodeFinished();\r
         }\r
+\r
         #endregion\r
 \r
         // User Interface Menus / Tool Strips *********************************\r
 \r
         #region File Menu\r
+\r
+        /// <summary>\r
+        /// Kill The scan menu Item\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_killCLI_Click(object sender, EventArgs e)\r
         {\r
-            killScan();\r
+            KillScan();\r
         }\r
+\r
+        /// <summary>\r
+        /// Exit the Application Menu Item\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\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
+        /// <summary>\r
+        /// Menu - Start Button\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_encode_Click(object sender, EventArgs e)\r
         {\r
             queueWindow.Show();\r
         }\r
+\r
+        /// <summary>\r
+        /// Menu - Display the Log Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_encodeLog_Click(object sender, EventArgs e)\r
         {\r
-            String file = lastAction == "scan" ? "last_scan_log.txt" : "last_encode_log.txt";\r
-\r
-            frmActivityWindow dvdInfoWindow = new frmActivityWindow(file, encodeQueue, this);\r
+            frmActivityWindow dvdInfoWindow = new frmActivityWindow(encodeQueue, SourceScan);\r
             dvdInfoWindow.Show();\r
         }\r
+\r
+        /// <summary>\r
+        /// Menu - Display the Options Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_options_Click(object sender, EventArgs e)\r
         {\r
-            Form options = new frmOptions();\r
+            Form options = new frmOptions(this);\r
             options.ShowDialog();\r
         }\r
+\r
         #endregion\r
 \r
         #region Presets Menu\r
+\r
+        /// <summary>\r
+        /// Reset the Built in Presets\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_presetReset_Click(object sender, EventArgs e)\r
         {\r
-            presetHandler.updateBuiltInPresets();\r
-            loadPresetPanel();\r
+            presetHandler.UpdateBuiltInPresets();\r
+            LoadPresetPanel();\r
             if (treeView_presets.Nodes.Count == 0)\r
-                MessageBox.Show("Unable to load the presets.xml file. Please select \"Update Built-in Presets\" from the Presets Menu. \nMake sure you are running the program in Admin mode if running on Vista. See Windows FAQ for details!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                MessageBox.Show(\r
+                    "Unable to load the presets.xml file. Please select \"Update Built-in Presets\" from the Presets Menu. \nMake sure you are running the program in Admin mode if running on Vista. See Windows FAQ for details!",\r
+                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             else\r
                 MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
 \r
             treeView_presets.ExpandAll();\r
         }\r
+\r
+        /// <summary>\r
+        /// Delete the selected preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_delete_preset_Click(object sender, EventArgs e)\r
         {\r
-            presetHandler.removeBuiltInPresets();\r
-            loadPresetPanel(); // Reload the preset panel\r
+            presetHandler.RemoveBuiltInPresets();\r
+            LoadPresetPanel(); // Reload the preset panel\r
         }\r
+\r
+        /// <summary>\r
+        /// Select the Normal preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
         {\r
             loadNormalPreset();\r
         }\r
+\r
+        /// <summary>\r
+        /// Import a plist Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_importMacPreset_Click(object sender, EventArgs e)\r
         {\r
-            Import imp = new Import();\r
-            if (openPreset.ShowDialog() == DialogResult.OK)\r
-            {\r
-                QueryParser parsed = imp.importMacPreset(openPreset.FileName);\r
-                if (presetHandler.checkIfUserPresetExists(parsed.PresetName + " (Imported)"))\r
-                {\r
-                    DialogResult result = MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?", "Overwrite preset?", \r
-                                                           MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
-                    if (result == DialogResult.Yes)\r
-                    {\r
-                        PresetLoader.presetLoader(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
-                        presetHandler.updatePreset(parsed.PresetName + " (Imported)", queryGen.generateTheQuery(this),\r
-                                                   parsed.UsesPictureSettings);\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    PresetLoader.presetLoader(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
-                    presetHandler.addPreset(parsed.PresetName, queryGen.generateTheQuery(this), parsed.UsesPictureSettings);\r
+            ImportPreset();\r
+        }\r
 \r
-                    if (presetHandler.addPreset(parsed.PresetName + " (Imported)", queryGen.generateTheQuery(this), parsed.UsesPictureSettings))\r
-                    {\r
-                        TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)") { ForeColor = Color.Black };\r
-                        treeView_presets.Nodes.Add(preset_treeview);\r
-                    }\r
-                }\r
-            }\r
+        /// <summary>\r
+        /// Export a Plist Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void mnu_exportMacPreset_Click(object sender, EventArgs e)\r
+        {\r
+            ExportPreset();\r
         }\r
+\r
+        /// <summary>\r
+        /// Create a new Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_new_preset_Click(object sender, EventArgs e)\r
         {\r
-            Form preset = new frmAddPreset(this, queryGen.generateTheQuery(this), presetHandler);\r
+            Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+                                           presetHandler);\r
             preset.ShowDialog();\r
         }\r
+\r
         #endregion\r
 \r
         #region Help Menu\r
-        private void mnu_handbrake_forums_Click(object sender, EventArgs e)\r
-        {\r
-            Process.Start("http://forum.handbrake.fr/");\r
-        }\r
+\r
+        /// <summary>\r
+        /// Menu - Display the User Guide Web Page\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_user_guide_Click(object sender, EventArgs e)\r
         {\r
             Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");\r
         }\r
-        private void mnu_handbrake_home_Click(object sender, EventArgs e)\r
-        {\r
-            Process.Start("http://handbrake.fr");\r
-        }\r
+\r
+        /// <summary>\r
+        /// Menu - Check for Updates\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
         {\r
             lbl_updateCheck.Visible = true;\r
             Main.BeginCheckForUpdates(new AsyncCallback(updateCheckDoneMenu), false);\r
         }\r
-        private void updateCheckDoneMenu(IAsyncResult result)\r
-        {\r
-            // Make sure it's running on the calling thread\r
-            if (InvokeRequired)\r
-            {\r
-                Invoke(new MethodInvoker(() => updateCheckDoneMenu(result)));\r
-                return;\r
-            }\r
-            UpdateCheckInformation info;\r
-            try\r
-            {\r
-                // Get the information about the new build, if any, and close the window\r
-                info = Main.EndCheckForUpdates(result);\r
-                \r
-                if (info.NewVersionAvailable && info.BuildInformation != null)\r
-                {\r
-                    frmUpdater updateWindow = new frmUpdater(info.BuildInformation);\r
-                    updateWindow.ShowDialog();\r
-                }\r
-                else\r
-                    MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
-                lbl_updateCheck.Visible = false;\r
-                return;\r
-            }\r
-            catch (Exception ex)\r
-            {\r
-                if ((bool)result.AsyncState)\r
-                    MessageBox.Show("Unable to check for updates, Please try again later. \n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-            }\r
-        }\r
+\r
+        /// <summary>\r
+        /// Menu - Display the About Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void mnu_about_Click(object sender, EventArgs e)\r
         {\r
             using (frmAbout About = new frmAbout())\r
@@ -461,72 +589,174 @@ namespace Handbrake
                 About.ShowDialog();\r
             }\r
         }\r
+\r
         #endregion\r
 \r
         #region Preset Bar\r
-        // Right Click Menu Code\r
+\r
+        /// <summary>\r
+        /// RMenu - Expand All\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_expandAll_Click(object sender, EventArgs e)\r
         {\r
             treeView_presets.ExpandAll();\r
         }\r
+\r
+        /// <summary>\r
+        /// RMenu - Collaspe All\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_collapse_Click(object sender, EventArgs e)\r
         {\r
             treeView_presets.CollapseAll();\r
         }\r
+\r
+        /// <summary>\r
+        /// Menu - Import Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void pmnu_import_Click(object sender, EventArgs e)\r
+        {\r
+            ImportPreset();\r
+        }\r
+\r
+        /// <summary>\r
+        /// RMenu - Save Changes to Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
         {\r
-            DialogResult result = MessageBox.Show("Do you wish to include picture settings when updating the preset: " + treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);\r
+            DialogResult result =\r
+                MessageBox.Show(\r
+                    "Do you wish to include picture settings when updating the preset: " +\r
+                    treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,\r
+                    MessageBoxIcon.Question);\r
             if (result == DialogResult.Yes)\r
-                presetHandler.updatePreset(treeView_presets.SelectedNode.Text, QueryGenerator.generateTabbedComponentsQuery(this), true);\r
+                presetHandler.Update(treeView_presets.SelectedNode.Text,\r
+                                     QueryGenerator.GenerateTabbedComponentsQuery(this), true);\r
             else if (result == DialogResult.No)\r
-                presetHandler.updatePreset(treeView_presets.SelectedNode.Text, QueryGenerator.generateTabbedComponentsQuery(this), false);\r
+                presetHandler.Update(treeView_presets.SelectedNode.Text,\r
+                                     QueryGenerator.GenerateTabbedComponentsQuery(this), false);\r
         }\r
+\r
+        /// <summary>\r
+        /// RMenu - Delete Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void pmnu_delete_click(object sender, EventArgs e)\r
         {\r
             if (treeView_presets.SelectedNode != null)\r
             {\r
-                presetHandler.remove(treeView_presets.SelectedNode.Text);\r
+                presetHandler.Remove(treeView_presets.SelectedNode.Text);\r
                 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);\r
             }\r
             treeView_presets.Select();\r
         }\r
-        private void presets_menu_Opening(object sender, System.ComponentModel.CancelEventArgs e)\r
+\r
+        /// <summary>\r
+        /// Preset Menu Is Opening. Setup the Menu\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void presets_menu_Opening(object sender, CancelEventArgs e)\r
         {\r
             // Make sure that the save menu is always disabled by default\r
             pmnu_saveChanges.Enabled = false;\r
 \r
             // Now enable the save menu if the selected preset is a user preset\r
             if (treeView_presets.SelectedNode != null)\r
-                if (presetHandler.checkIfUserPresetExists(treeView_presets.SelectedNode.Text))\r
+                if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))\r
                     pmnu_saveChanges.Enabled = true;\r
 \r
             treeView_presets.Select();\r
         }\r
 \r
         // Presets Management\r
+\r
+        /// <summary>\r
+        /// Button - Add a preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_addPreset_Click(object sender, EventArgs e)\r
         {\r
-            Form preset = new frmAddPreset(this, QueryGenerator.generateTabbedComponentsQuery(this), presetHandler);\r
+            Form preset = new frmAddPreset(this, QueryGenerator.GenerateTabbedComponentsQuery(this), presetHandler);\r
             preset.ShowDialog();\r
         }\r
+\r
+        /// <summary>\r
+        /// Button - remove a Preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_removePreset_Click(object sender, EventArgs e)\r
         {\r
-            DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+            DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",\r
+                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
             if (result == DialogResult.Yes)\r
             {\r
                 if (treeView_presets.SelectedNode != null)\r
                 {\r
-                    presetHandler.remove(treeView_presets.SelectedNode.Text);\r
+                    presetHandler.Remove(treeView_presets.SelectedNode.Text);\r
                     treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);\r
                 }\r
             }\r
             treeView_presets.Select();\r
         }\r
+\r
+        /// <summary>\r
+        /// Button - Set the selected preset as the default\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_setDefault_Click(object sender, EventArgs e)\r
         {\r
             if (treeView_presets.SelectedNode != null)\r
             {\r
-                DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+                DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",\r
+                                                      "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
                 if (result == DialogResult.Yes)\r
                 {\r
                     Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;\r
@@ -537,6 +767,16 @@ namespace Handbrake
             else\r
                 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
         }\r
+\r
+        /// <summary>\r
+        /// PresetBar Mouse Down event\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void treeview_presets_mouseUp(object sender, MouseEventArgs e)\r
         {\r
             if (e.Button == MouseButtons.Right)\r
@@ -552,27 +792,48 @@ namespace Handbrake
 \r
             treeView_presets.Select();\r
         }\r
+\r
+        /// <summary>\r
+        /// Preset Bar after selecting the preset\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)\r
         {\r
             selectPreset();\r
         }\r
+\r
+        /// <summary>\r
+        /// Preset Bar - Handle the Delete Key\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void treeView_presets_deleteKey(object sender, KeyEventArgs e)\r
         {\r
             if (e.KeyCode == Keys.Delete)\r
             {\r
-                DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+                DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",\r
+                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
                 if (result == DialogResult.Yes)\r
                 {\r
                     if (treeView_presets.SelectedNode != null)\r
-                        presetHandler.remove(treeView_presets.SelectedNode.Text);\r
+                        presetHandler.Remove(treeView_presets.SelectedNode.Text);\r
 \r
                     // Remember each nodes expanded status so we can reload it\r
-                    List<Boolean> nodeStatus = new List<Boolean>();\r
+                    List<bool> nodeStatus = new List<bool>();\r
                     foreach (TreeNode node in treeView_presets.Nodes)\r
                         nodeStatus.Add(node.IsExpanded);\r
 \r
                     // Now reload the preset panel\r
-                    loadPresetPanel();\r
+                    LoadPresetPanel();\r
 \r
                     // And finally, re-expand any of the nodes if required\r
                     int i = 0;\r
@@ -586,35 +847,48 @@ namespace Handbrake
                 }\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Select the selected preset and setup the GUI\r
+        /// </summary>\r
         private void selectPreset()\r
         {\r
             if (treeView_presets.SelectedNode != null)\r
             {\r
                 // Ok, so, we've selected a preset. Now we want to load it.\r
                 string presetName = treeView_presets.SelectedNode.Text;\r
-                if (presetHandler.getPreset(presetName) != null)\r
+                Preset preset = presetHandler.GetPreset(presetName);\r
+                if (preset != null)\r
                 {\r
-                    string query = presetHandler.getPreset(presetName).Query;\r
-                    Boolean loadPictureSettings = presetHandler.getPreset(presetName).PictureSettings;\r
+                    string query = presetHandler.GetPreset(presetName).Query;\r
+                    bool loadPictureSettings = presetHandler.GetPreset(presetName).PictureSettings;\r
 \r
                     if (query != null)\r
                     {\r
-                        //Ok, Reset all the H264 widgets before changing the preset\r
-                        x264Panel.reset2Defaults();\r
+                        // Ok, Reset all the H264 widgets before changing the preset\r
+                        x264Panel.Reset2Defaults();\r
 \r
                         // Send the query from the file to the Query Parser class\r
                         QueryParser presetQuery = QueryParser.Parse(query);\r
 \r
                         // Now load the preset\r
-                        PresetLoader.presetLoader(this, presetQuery, presetName, loadPictureSettings);\r
+                        PresetLoader.LoadPreset(this, presetQuery, presetName, loadPictureSettings);\r
 \r
                         // The x264 widgets will need updated, so do this now:\r
                         x264Panel.X264_StandardizeOptString();\r
                         x264Panel.X264_SetCurrentSettingsInPanel();\r
+\r
+                        // Finally, let this window have a copy of the preset settings.\r
+                        CurrentlySelectedPreset = preset;\r
+                        PictureSettings.SetPresetCropWarningLabel(preset);\r
                     }\r
                 }\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Load the Normal Preset\r
+        /// </summary>\r
         private void loadNormalPreset()\r
         {\r
             foreach (TreeNode treenode in treeView_presets.Nodes)\r
@@ -626,58 +900,173 @@ namespace Handbrake
                 }\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Import a plist preset\r
+        /// </summary>\r
+        private void ImportPreset()\r
+        {\r
+            if (openPreset.ShowDialog() == DialogResult.OK)\r
+            {\r
+                QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);\r
+                if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))\r
+                {\r
+                    DialogResult result =\r
+                        MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",\r
+                                        "Overwrite preset?",\r
+                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
+                    if (result == DialogResult.Yes)\r
+                    {\r
+                        PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
+                        presetHandler.Update(parsed.PresetName + " (Imported)",\r
+                                             QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+                                             parsed.UsesPictureSettings);\r
+                    }\r
+                }\r
+                else\r
+                {\r
+                    PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
+                    if (presetHandler.Add(parsed.PresetName + " (Imported)",\r
+                                          QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+                                          parsed.UsesPictureSettings))\r
+                    {\r
+                        TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")\r
+                                                       {\r
+                                                           ForeColor = Color.Black\r
+                                                       };\r
+                        treeView_presets.Nodes.Add(preset_treeview);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Export a plist Preset\r
+        /// </summary>\r
+        private void ExportPreset()\r
+        {\r
+            MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+            return;\r
+\r
+            SaveFileDialog savefiledialog = new SaveFileDialog();\r
+            savefiledialog.Filter = "plist|*.plist";\r
+\r
+            if (treeView_presets.SelectedNode != null)\r
+            {\r
+\r
+                if (savefiledialog.ShowDialog() == DialogResult.OK)\r
+                {\r
+                    Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);\r
+                    PlistPresetHandler.Export(savefiledialog.FileName, preset);\r
+                }\r
+            }\r
+        }\r
+\r
         #endregion\r
 \r
         #region ToolStrip\r
+\r
+        /// <summary>\r
+        /// Toolbar - When the Source button is clicked, Clear any DVD drives and add any available DVD drives that can be used as a source.\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_source_Click(object sender, EventArgs e)\r
         {\r
-            if (Properties.Settings.Default.drive_detection)\r
+            // Remove old Drive Menu Items.\r
+            List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();\r
+            foreach (var item in btn_source.DropDownItems)\r
             {\r
-                mnu_dvd_drive.Visible = true;\r
-                Thread driveInfoThread = new Thread(getDriveInfoThread);\r
-                driveInfoThread.Start();\r
+                if (item.GetType() == typeof(ToolStripMenuItem))\r
+                {\r
+                    ToolStripMenuItem menuItem = (ToolStripMenuItem)item;\r
+                    if (menuItem.Name.StartsWith("Drive"))\r
+                    {\r
+                        itemsToRemove.Add(menuItem);\r
+                    }\r
+                }\r
             }\r
-            else\r
-                mnu_dvd_drive.Visible = false;\r
+\r
+            foreach (ToolStripMenuItem item in itemsToRemove)\r
+                btn_source.DropDownItems.Remove(item);\r
+\r
+            Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);\r
+            driveInfoThread.Start();\r
         }\r
+\r
+        /// <summary>\r
+        /// Toolbar - Start The Encode\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_start_Click(object sender, EventArgs e)\r
         {\r
             if (btn_start.Text == "Stop")\r
             {\r
-                DialogResult result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+                DialogResult result;\r
+                if (Properties.Settings.Default.enocdeStatusInGui &&\r
+                    !Properties.Settings.Default.showCliForInGuiEncodeStatus)\r
+                {\r
+                    result = MessageBox.Show(\r
+                        "Are you sure you wish to cancel the encode?\n\nPlease note, when 'Enable in-GUI encode status' is enabled, stopping this encode will render the file unplayable. ",\r
+                        "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+                }\r
+                else\r
+                {\r
+                    result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?",\r
+                                             MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+                }\r
 \r
                 if (result == DialogResult.Yes)\r
                 {\r
                     // Pause The Queue\r
-                    encodeQueue.RequestPause();\r
+                    encodeQueue.Pause();\r
 \r
-                    // Allow the CLI to exit cleanly\r
-                    Win32.SetForegroundWindow((int)encodeQueue.processHandle);\r
-                    SendKeys.Send("^C");\r
-\r
-                    // Update the GUI\r
-                    setEncodeFinished();\r
+                    if (Properties.Settings.Default.enocdeStatusInGui &&\r
+                        !Properties.Settings.Default.showCliForInGuiEncodeStatus)\r
+                    {\r
+                        encodeQueue.Stop();\r
+                        if (encodeQueue.HbProcess != null)\r
+                            encodeQueue.HbProcess.WaitForExit();\r
+                    }\r
+                    else\r
+                    {\r
+                        encodeQueue.SafelyClose();\r
+                    }\r
                 }\r
             }\r
             else\r
             {\r
-                if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(sourcePath) && !string.IsNullOrEmpty(text_destination.Text)))\r
+                if (encodeQueue.Count != 0 ||\r
+                    (!string.IsNullOrEmpty(sourcePath) && !string.IsNullOrEmpty(text_destination.Text)))\r
                 {\r
-                    string generatedQuery = queryGen.generateTheQuery(this);\r
-                    string specifiedQuery = rtf_query.Text != "" ? rtf_query.Text : queryGen.generateTheQuery(this);\r
+                    string generatedQuery = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+                    string specifiedQuery = rtf_query.Text != string.Empty\r
+                                                ? rtf_query.Text\r
+                                                : QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
                     string query = string.Empty;\r
 \r
                     // Check to make sure the generated query matches the GUI settings\r
-                    if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) && generatedQuery != specifiedQuery)\r
+                    if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) &&\r
+                        generatedQuery != specifiedQuery)\r
                     {\r
                         DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " +\r
-                            "does not match the current GUI settings. Because the manual query takes " +\r
-                            "priority over the GUI, your recently updated settings will not be taken " +\r
-                            "into account when encoding this job." + Environment.NewLine + Environment.NewLine +\r
-                            "Do you want to replace the manual query with the GUI-generated query?",\r
-                            "Manual Query does not Match GUI",\r
-                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,\r
-                            MessageBoxDefaultButton.Button3);\r
+                                                              "does not match the current GUI settings.\n\nBecause the manual query takes " +\r
+                                                              "priority over the GUI, your recently updated settings will not be taken " +\r
+                                                              "into account when encoding this job." +\r
+                                                              Environment.NewLine + Environment.NewLine +\r
+                                                              "Do you want to replace the manual query with the updated GUI-generated query?",\r
+                                                              "Manual Query does not Match GUI",\r
+                                                              MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,\r
+                                                              MessageBoxDefaultButton.Button3);\r
 \r
                         switch (result)\r
                         {\r
@@ -697,67 +1086,110 @@ namespace Handbrake
                     }\r
                     else\r
                     {\r
-                        query = generatedQuery;\r
+                        query = specifiedQuery;\r
                     }\r
 \r
                     DialogResult overwrite = DialogResult.Yes;\r
-                    if (text_destination.Text != "")\r
+                    if (text_destination.Text != string.Empty)\r
                         if (File.Exists(text_destination.Text))\r
-                            overwrite = MessageBox.Show("The destination file already exists. Are you sure you want to overwrite it?", "Overwrite File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+                            overwrite =\r
+                                MessageBox.Show(\r
+                                    "The destination file already exists. Are you sure you want to overwrite it?",\r
+                                    "Overwrite File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
 \r
                     if (overwrite == DialogResult.Yes)\r
                     {\r
                         if (encodeQueue.Count == 0)\r
-                            encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
+                            encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
 \r
-                        queueWindow.setQueue();\r
+                        queueWindow.SetQueue();\r
                         if (encodeQueue.Count > 1)\r
                             queueWindow.Show(false);\r
 \r
-                        setEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
-                        if (ActivityWindow != null)\r
-                            ActivityWindow.setLogView(false);\r
-                        encodeQueue.StartEncodeQueue(); // Start The Queue Encoding Process\r
-                        lastAction = "encode";   // Set the last action to encode - Used for activity window.\r
+                        SetEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
+                        encodeQueue.Start(); // Start The Queue Encoding Process\r
                     }\r
+\r
                     this.Focus();\r
                 }\r
                 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
-                    MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                    MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,\r
+                                    MessageBoxIcon.Warning);\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Toolbar - Add the current job to the Queue\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_add2Queue_Click(object sender, EventArgs e)\r
         {\r
             if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
                 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             else\r
             {\r
-                String query = queryGen.generateTheQuery(this);\r
-                if (rtf_query.Text != "")\r
+                if (!Directory.Exists(Path.GetDirectoryName(text_destination.Text)))\r
+                {\r
+                    MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                    return;\r
+                }\r
+\r
+                string query = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+                if (rtf_query.Text != string.Empty)\r
                     query = rtf_query.Text;\r
 \r
                 if (encodeQueue.CheckForDestinationDuplicate(text_destination.Text))\r
                 {\r
-                    DialogResult result = MessageBox.Show("There is already a queue item for this destination path. \n\n If you continue, the encode will be overwritten. Do you wish to continue?",\r
-                  "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
+                    DialogResult result =\r
+                        MessageBox.Show(\r
+                            "There is already a queue item for this destination path. \n\n If you continue, the encode will be overwritten. Do you wish to continue?",\r
+                            "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
                     if (result == DialogResult.Yes)\r
-                        encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
-\r
+                        encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
                 }\r
                 else\r
-                    encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
+                    encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+\r
+                lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
 \r
                 queueWindow.Show();\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Toolbar - Show the Queue\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_showQueue_Click(object sender, EventArgs e)\r
         {\r
             queueWindow.Show();\r
+            queueWindow.Activate();\r
         }\r
+\r
+        /// <summary>\r
+        /// Toolbar - Show the Preview Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void tb_preview_Click(object sender, EventArgs e)\r
         {\r
             if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
-                MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,\r
+                                MessageBoxIcon.Warning);\r
             else\r
             {\r
                 if (qtpreview == null)\r
@@ -771,20 +1203,42 @@ namespace Handbrake
                     qtpreview.Show();\r
                 }\r
                 else\r
-                    MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                    MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,\r
+                                    MessageBoxIcon.Warning);\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// Toolbar - Show the Activity log Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
         {\r
-            String file = lastAction == "scan" ? "last_scan_log.txt" : "last_encode_log.txt";\r
-            if (ActivityWindow == null)\r
-                ActivityWindow = new frmActivityWindow(file, encodeQueue, this);\r
-            \r
+            if (ActivityWindow == null || !ActivityWindow.IsHandleCreated)\r
+                ActivityWindow = new frmActivityWindow(encodeQueue, SourceScan);\r
+\r
             ActivityWindow.Show();\r
+            ActivityWindow.Activate();\r
         }\r
+\r
         #endregion\r
 \r
         #region System Tray Icon\r
+\r
+        /// <summary>\r
+        /// Handle Resizing of the main window when deaing with the Notify Icon\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void frmMain_Resize(object sender, EventArgs e)\r
         {\r
             if (FormWindowState.Minimized == this.WindowState)\r
@@ -795,6 +1249,16 @@ namespace Handbrake
             else if (FormWindowState.Normal == this.WindowState)\r
                 notifyIcon.Visible = false;\r
         }\r
+\r
+        /// <summary>\r
+        /// Double Click the Tray Icon\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)\r
         {\r
             this.Visible = true;\r
@@ -802,6 +1266,16 @@ namespace Handbrake
             this.WindowState = FormWindowState.Normal;\r
             notifyIcon.Visible = false;\r
         }\r
+\r
+        /// <summary>\r
+        /// Tray Icon - Restore Menu Item - Resture the Window\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
         private void btn_restore_Click(object sender, EventArgs e)\r
         {\r
             this.Visible = true;\r
@@ -809,125 +1283,97 @@ namespace Handbrake
             this.WindowState = FormWindowState.Normal;\r
             notifyIcon.Visible = false;\r
         }\r
+\r
         #endregion\r
 \r
-        #region Tab Control\r
+        #region Main Window and Tab Control\r
 \r
-        //Source\r
+        // Source\r
         private void btn_dvd_source_Click(object sender, EventArgs e)\r
         {\r
-            // Enable the creation of chapter markers.\r
-            Check_ChapterMarkers.Enabled = true;\r
-\r
-            // Set the last action to scan. \r
-            // This is used for tracking which file to load in the activity window\r
-            lastAction = "scan";\r
-            sourcePath = string.Empty;\r
-\r
             if (DVD_Open.ShowDialog() == DialogResult.OK)\r
             {\r
-                String filename = DVD_Open.SelectedPath;\r
-\r
-                if (filename.StartsWith("\\"))\r
-                {\r
-                    MessageBox.Show(\r
-                        "Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer",\r
-                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-                    UpdateSourceLabel();\r
-                }\r
-                else\r
-                {\r
-                    if (filename != "")\r
-                    {\r
-                        sourcePath = Path.GetFullPath(filename);\r
-                        setupGUIforScan(filename);\r
-                        startScan(filename);\r
-                    } else\r
-                        UpdateSourceLabel();\r
-                }\r
+                this.selectedSourceType = SourceType.Folder;\r
+                SelectSource(DVD_Open.SelectedPath);\r
             }\r
             else\r
                 UpdateSourceLabel();\r
         }\r
+\r
         private void btn_file_source_Click(object sender, EventArgs e)\r
         {\r
-            // Set the last action to scan. \r
-            // This is used for tracking which file to load in the activity window\r
-            lastAction = "scan";\r
-            sourcePath = string.Empty;\r
-\r
             if (ISO_Open.ShowDialog() == DialogResult.OK)\r
             {\r
-                String filename = ISO_Open.FileName;\r
-                if (filename.StartsWith("\\"))\r
-                    MessageBox.Show(\r
-                        "Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer",\r
-                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-                else\r
+                this.selectedSourceType = SourceType.VideoFile;\r
+                SelectSource(ISO_Open.FileName);\r
+            }\r
+            else\r
+                UpdateSourceLabel();\r
+        }\r
+\r
+        private void mnu_dvd_drive_Click(object sender, EventArgs e)\r
+        {\r
+            ToolStripMenuItem item = sender as ToolStripMenuItem;\r
+            if (item != null)\r
+            {\r
+                string driveId = item.Name.Replace("Drive", string.Empty);\r
+                int id;\r
+                if (int.TryParse(driveId, out id))\r
                 {\r
-                    if (filename != "")\r
-                    {\r
-                        sourcePath = Path.GetFileName(filename);\r
-                        setupGUIforScan(filename);\r
-                        startScan(filename);\r
-                    } else\r
-                        UpdateSourceLabel();\r
+\r
+                    this.dvdDrivePath = drives[id].RootDirectory;\r
+                    this.dvdDriveLabel = drives[id].VolumeLabel;\r
+\r
+                    if (this.dvdDrivePath == null) return;\r
+                    this.selectedSourceType = SourceType.DvdDrive;\r
+                    SelectSource(this.dvdDrivePath);\r
                 }\r
             }\r
-            UpdateSourceLabel();\r
         }\r
-        private void mnu_dvd_drive_Click(object sender, EventArgs e)\r
+\r
+        private void SelectSource(string file)\r
         {\r
-            // Enable the creation of chapter markers.\r
             Check_ChapterMarkers.Enabled = true;\r
-\r
-            // Set the last action to scan. \r
-            // This is used for tracking which file to load in the activity window\r
-            lastAction = "scan";\r
             sourcePath = string.Empty;\r
 \r
-            if (mnu_dvd_drive.Text.Contains("VIDEO_TS"))\r
+            if (file == string.Empty) // Must have a file or path\r
             {\r
-                string[] path = mnu_dvd_drive.Text.Split(' ');\r
-                String filename = path[0];\r
-                sourcePath = Path.GetFullPath(filename);\r
-                setupGUIforScan(filename);\r
-                startScan(filename);\r
+                UpdateSourceLabel();\r
+                return;\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
-                MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.\nYour Source may be copy protected, badly mastered or a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
-\r
-            UpdateSourceLabel();\r
-\r
-            lbl_encode.Text = "";\r
+            sourcePath = Path.GetFileName(file);\r
+            StartScan(file, 0);\r
         }\r
+\r
         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
         {\r
             if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))\r
-                MessageBox.Show("There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
+                MessageBox.Show(\r
+                    "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",\r
+                    "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
         }\r
+\r
         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
-            unRegisterPresetEventHandler();\r
-            // Reset some values on the form\r
-            PictureSettings.lbl_Aspect.Text = "Select a Title";\r
-            //lbl_RecomendedCrop.Text = "Select a Title";\r
+            UnRegisterPresetEventHandler();\r
+            drop_mode.SelectedIndex = 0;\r
+\r
             drop_chapterStart.Items.Clear();\r
             drop_chapterFinish.Items.Clear();\r
 \r
             // If the dropdown is set to automatic nothing else needs to be done.\r
-            // Otheriwse if its not, title data has to be loased from parsing.\r
+            // Otheriwse if its not, title data has to be loaded from parsing.\r
             if (drp_dvdtitle.Text != "Automatic")\r
             {\r
                 selectedTitle = drp_dvdtitle.SelectedItem as Title;\r
                 lbl_duration.Text = selectedTitle.Duration.ToString();\r
-                PictureSettings.Source = selectedTitle;  // Setup Picture Settings Tab Control\r
+                PictureSettings.CurrentlySelectedPreset = CurrentlySelectedPreset;\r
+                PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control\r
 \r
                 // Populate the Angles dropdown\r
                 drop_angle.Items.Clear();\r
-                if (Properties.Settings.Default.dvdnav)\r
+                if (!Properties.Settings.Default.noDvdNav)\r
                 {\r
                     drop_angle.Visible = true;\r
                     lbl_angle.Visible = true;\r
@@ -954,30 +1400,32 @@ namespace Handbrake
                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
 \r
                 // Populate the Audio Channels Dropdown\r
-                AudioSettings.setTrackList(selectedTitle);\r
+                AudioSettings.SetTrackList(selectedTitle, CurrentlySelectedPreset);\r
 \r
                 // Populate the Subtitles dropdown\r
-                Subtitles.drp_subtitleTracks.Items.Clear();\r
-                Subtitles.drp_subtitleTracks.Items.Add("Foreign Audio Search (Bitmap)");\r
-                Subtitles.drp_subtitleTracks.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
-                Subtitles.drp_subtitleTracks.SelectedIndex = 0;\r
-                Subtitles.setSubtitleTrackAuto();\r
+                Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());\r
             }\r
+            // Update the source label if we have multiple streams\r
+            if (selectedTitle != null)\r
+                if (!string.IsNullOrEmpty(selectedTitle.SourceName))\r
+                    labelSource.Text = labelSource.Text = Path.GetFileName(selectedTitle.SourceName);\r
 \r
-            // Run the autoName & chapterNaming functions\r
+            // Run the AutoName & ChapterNaming functions\r
             if (Properties.Settings.Default.autoNaming)\r
             {\r
-                string autoPath = Main.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, sourcePath, text_destination.Text, drop_format.SelectedIndex);\r
+                string autoPath = Main.AutoName(this);\r
                 if (autoPath != null)\r
                     text_destination.Text = autoPath;\r
                 else\r
-                    MessageBox.Show("You currently have automatic file naming enabled for the destination box, but you do not have a default direcotry set. You should set this in the program options (see Tools Menu)", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                    MessageBox.Show(\r
+                        "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'General' Tab -> 'Default Path')",\r
+                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             }\r
 \r
             data_chpt.Rows.Clear();\r
             if (selectedTitle.Chapters.Count != 1)\r
             {\r
-                DataGridView chapterGridView = Main.chapterNaming(data_chpt, drop_chapterFinish.Text);\r
+                DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);\r
                 if (chapterGridView != null)\r
                     data_chpt = chapterGridView;\r
             }\r
@@ -991,91 +1439,154 @@ namespace Handbrake
             data_chpt.Columns[0].Width = 166;\r
             data_chpt.Columns[0].Width = 165;\r
 \r
-            registerPresetEventHandler();\r
+            RegisterPresetEventHandler();\r
         }\r
-        private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
-        {\r
-            int c_start, c_end;\r
 \r
-            if (drop_chapterFinish.Text == "Auto" && drop_chapterFinish.Items.Count != 0)\r
-                drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;\r
+        private void chapersChanged(object sender, EventArgs e)\r
+        {\r
+            if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.\r
+                return;\r
 \r
-            int.TryParse(drop_chapterStart.Text, out c_start);\r
-            int.TryParse(drop_chapterFinish.Text, out c_end);\r
+            Control ctl = (Control)sender;\r
+            int chapterStart, chapterEnd;\r
+            int.TryParse(drop_chapterStart.Text, out chapterStart);\r
+            int.TryParse(drop_chapterFinish.Text, out chapterEnd);\r
 \r
-            if (c_end != 0)\r
+            switch (ctl.Name)\r
             {\r
-                if (c_start > c_end)\r
-                    drop_chapterFinish.Text = c_start.ToString();\r
+                case "drop_chapterStart":\r
+                    if (drop_chapterFinish.SelectedIndex == -1 && drop_chapterFinish.Items.Count != 0)\r
+                        drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;\r
+\r
+                    if (chapterEnd != 0)\r
+                        if (chapterStart > chapterEnd)\r
+                            drop_chapterFinish.Text = chapterStart.ToString();\r
+                    break;\r
+                case "drop_chapterFinish":\r
+                    if (drop_chapterStart.Items.Count >= 1 && drop_chapterStart.SelectedIndex == -1)\r
+                        drop_chapterStart.SelectedIndex = 0;\r
+\r
+                    if (chapterStart != 0)\r
+                        if (chapterEnd < chapterStart)\r
+                            drop_chapterFinish.Text = chapterStart.ToString();\r
+\r
+                    // Add more rows to the Chapter menu if needed.\r
+                    if (Check_ChapterMarkers.Checked)\r
+                    {\r
+                        int i = data_chpt.Rows.Count, finish = 0;\r
+                        int.TryParse(drop_chapterFinish.Text, out finish);\r
+\r
+                        while (i < finish)\r
+                        {\r
+                            int n = data_chpt.Rows.Add();\r
+                            data_chpt.Rows[n].Cells[0].Value = (i + 1);\r
+                            data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);\r
+                            data_chpt.Rows[n].Cells[0].ValueType = typeof(int);\r
+                            data_chpt.Rows[n].Cells[1].ValueType = typeof(string);\r
+                            i++;\r
+                        }\r
+                    }\r
+                    break;\r
             }\r
 \r
-            lbl_duration.Text = Main.calculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle).ToString();\r
+            // Update the Duration\r
+            lbl_duration.Text =\r
+                Main.CalculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle)\r
+                    .ToString();\r
 \r
             // Run the Autonaming function\r
             if (Properties.Settings.Default.autoNaming)\r
-                text_destination.Text = Main.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, sourcePath, text_destination.Text, drop_format.SelectedIndex);\r
+                text_destination.Text = Main.AutoName(this);\r
 \r
             // Disable chapter markers if only 1 chapter is selected.\r
-            if (c_start == c_end)\r
+            if (chapterStart == chapterEnd)\r
             {\r
-                Check_ChapterMarkers.Checked = false;\r
                 Check_ChapterMarkers.Enabled = false;\r
+                btn_importChapters.Enabled = false;\r
+                data_chpt.Enabled = false;\r
             }\r
             else\r
-                Check_ChapterMarkers.Enabled = true;\r
-        }\r
-        private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
-        {\r
-            int c_start, c_end;\r
-\r
-            if (drop_chapterStart.Text == "Auto" && drop_chapterStart.Items.Count >= 1)\r
-                drop_chapterStart.SelectedIndex = 1;\r
-\r
-            int.TryParse(drop_chapterStart.Text, out c_start);\r
-            int.TryParse(drop_chapterFinish.Text, out c_end);\r
-\r
-            if (c_start != 0)\r
             {\r
-                if (c_end < c_start)\r
-                    drop_chapterFinish.Text = c_start.ToString();\r
+                Check_ChapterMarkers.Enabled = true;\r
+                if (Check_ChapterMarkers.Checked)\r
+                {\r
+                    btn_importChapters.Enabled = true;\r
+                    data_chpt.Enabled = true;\r
+                }\r
             }\r
+        }\r
 \r
-            lbl_duration.Text = Main.calculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle).ToString();\r
-\r
-            // Run the Autonaming function\r
-            if (Properties.Settings.Default.autoNaming)\r
-                text_destination.Text = Main.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, sourcePath, text_destination.Text, drop_format.SelectedIndex);\r
+        private void SecondsOrFramesChanged(object sender, EventArgs e)\r
+        {\r
+            int start, end;\r
+            int.TryParse(drop_chapterStart.Text, out start);\r
+            int.TryParse(drop_chapterFinish.Text, out end);\r
+            double duration = end - start;\r
 \r
-            // Add more rows to the Chapter menu if needed.\r
-            if (Check_ChapterMarkers.Checked)\r
+            switch (drop_mode.SelectedIndex)\r
             {\r
-                int i = data_chpt.Rows.Count, finish = 0;\r
-\r
-                if (drop_chapterFinish.Text != "Auto")\r
-                    int.TryParse(drop_chapterFinish.Text, out finish);\r
+                case 1:\r
+                    lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();\r
+                    return;\r
+                case 2:\r
+                    if (selectedTitle != null)\r
+                    {\r
+                        duration = duration / selectedTitle.Fps;\r
+                        lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();\r
+                    }\r
+                    else\r
+                        lbl_duration.Text = "--:--:--";\r
 \r
-                while (i < finish)\r
-                {\r
-                    int n = data_chpt.Rows.Add();\r
-                    data_chpt.Rows[n].Cells[0].Value = (i + 1);\r
-                    data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);\r
-                    data_chpt.Rows[n].Cells[0].ValueType = typeof(int);\r
-                    data_chpt.Rows[n].Cells[1].ValueType = typeof(string);\r
-                    i++;\r
-                }\r
+                    return;\r
             }\r
+        }\r
 \r
-            // Disable chapter markers if only 1 chapter is selected.\r
-            if (c_start == c_end)\r
+        private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)\r
+        {\r
+            // Reset\r
+            this.drop_chapterFinish.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);\r
+            this.drop_chapterStart.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);\r
+\r
+            // Do Work\r
+            switch (drop_mode.SelectedIndex)\r
             {\r
-                Check_ChapterMarkers.Checked = false;\r
-                Check_ChapterMarkers.Enabled = false;\r
+                case 0:\r
+                    drop_chapterStart.DropDownStyle = ComboBoxStyle.DropDownList;\r
+                    drop_chapterFinish.DropDownStyle = ComboBoxStyle.DropDownList;\r
+                    if (drop_chapterStart.Items.Count != 0)\r
+                    {\r
+                        drop_chapterStart.SelectedIndex = 0;\r
+                        drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;\r
+                    }\r
+                    else\r
+                        lbl_duration.Text = "--:--:--";\r
+                    return;\r
+                case 1:\r
+                    this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);\r
+                    this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);\r
+                    drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;\r
+                    drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;\r
+                    if (selectedTitle != null)\r
+                    {\r
+                        drop_chapterStart.Text = "0";\r
+                        drop_chapterFinish.Text = selectedTitle.Duration.TotalSeconds.ToString();\r
+                    }\r
+                    return;\r
+                case 2:\r
+                    this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);\r
+                    this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);\r
+                    drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;\r
+                    drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;\r
+                    if (selectedTitle != null)\r
+                    {\r
+                        drop_chapterStart.Text = "0";\r
+                        drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();\r
+                    }\r
+                    return;\r
             }\r
-            else\r
-                Check_ChapterMarkers.Enabled = true;\r
         }\r
 \r
-        //Destination\r
+        // Destination\r
         private void btn_destBrowse_Click(object sender, EventArgs e)\r
         {\r
             // This removes the file extension from the filename box on the save file dialog.\r
@@ -1093,36 +1604,35 @@ namespace Handbrake
 \r
             if (DVD_Save.ShowDialog() == DialogResult.OK)\r
             {\r
-                if (DVD_Save.FileName.StartsWith("\\"))\r
-                    MessageBox.Show("Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-                else\r
+                // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames\r
+                switch (DVD_Save.FilterIndex)\r
                 {\r
-                    // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames\r
-                    switch (DVD_Save.FilterIndex)\r
-                    {\r
-                        case 1:\r
-                            if (!Path.GetExtension(DVD_Save.FileName).Equals(".mp4", StringComparison.InvariantCultureIgnoreCase))\r
-                                if (Properties.Settings.Default.useM4v)\r
-                                    DVD_Save.FileName += ".m4v";\r
-                                else\r
-                                    DVD_Save.FileName += ".mp4";\r
-                            break;\r
-                        case 2:\r
-                            if (!Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))\r
-                                DVD_Save.FileName += ".mkv";\r
-                            break;\r
-                        default:\r
-                            //do nothing  \r
-                            break;\r
-                    }\r
-                    text_destination.Text = DVD_Save.FileName;\r
-\r
-                    // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)\r
-                    if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)\r
-                        setExtension(".m4v");\r
+                    case 1:\r
+                        if (\r
+                            !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",\r
+                                                                         StringComparison.InvariantCultureIgnoreCase))\r
+                            if (Properties.Settings.Default.useM4v)\r
+                                DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");\r
+                            else\r
+                                DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");\r
+                        break;\r
+                    case 2:\r
+                        if (\r
+                            !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))\r
+                            DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");\r
+                        break;\r
+                    default:\r
+                        // do nothing  \r
+                        break;\r
                 }\r
+                text_destination.Text = DVD_Save.FileName;\r
+\r
+                // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)\r
+                if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)\r
+                    SetExtension(".m4v");\r
             }\r
         }\r
+\r
         private void text_destination_TextChanged(object sender, EventArgs e)\r
         {\r
             string path = text_destination.Text;\r
@@ -1138,20 +1648,20 @@ namespace Handbrake
             switch (drop_format.SelectedIndex)\r
             {\r
                 case 0:\r
-                    if (Properties.Settings.Default.useM4v)\r
-                        setExtension(".m4v");\r
+                    if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||\r
+                        AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())\r
+                        SetExtension(".m4v");\r
                     else\r
-                        setExtension(".mp4");\r
+                        SetExtension(".mp4");\r
                     break;\r
                 case 1:\r
-                    setExtension(".mkv");\r
+                    SetExtension(".mkv");\r
                     break;\r
             }\r
 \r
-            AudioSettings.setAudioByContainer(drop_format.Text);\r
-            Subtitles.setContainer(drop_format.SelectedIndex);\r
+            AudioSettings.SetContainer(drop_format.Text);\r
 \r
-            if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))\r
+            if (drop_format.Text.Contains("MP4"))\r
             {\r
                 if (drp_videoEncoder.Items.Contains("VP3 (Theora)"))\r
                 {\r
@@ -1162,19 +1672,26 @@ namespace Handbrake
             else if (drop_format.Text.Contains("MKV"))\r
                 drp_videoEncoder.Items.Add("VP3 (Theora)");\r
         }\r
-        private void setExtension(string newExtension)\r
+\r
+        public void SetExtension(string newExtension)\r
         {\r
-            text_destination.Text = text_destination.Text.Replace(".mp4", newExtension);\r
-            text_destination.Text = text_destination.Text.Replace(".m4v", newExtension);\r
-            text_destination.Text = text_destination.Text.Replace(".mkv", newExtension);\r
+            if (newExtension == ".mp4" || newExtension == ".m4v")\r
+                if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||\r
+                    Subtitles.RequiresM4V())\r
+                    newExtension = ".m4v";\r
+                else\r
+                    newExtension = ".mp4";\r
+\r
+            if (Path.HasExtension(newExtension))\r
+                text_destination.Text = Path.ChangeExtension(text_destination.Text, newExtension);\r
         }\r
 \r
-        //Video Tab\r
+        // Video Tab\r
         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
             setContainerOpts();\r
 \r
-            //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
+            // Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
             if (drp_videoEncoder.Text.Contains("H.264"))\r
             {\r
                 if (check_2PassEncode.CheckState == CheckState.Checked)\r
@@ -1191,7 +1708,7 @@ namespace Handbrake
                 check_turbo.CheckState = CheckState.Unchecked;\r
                 check_turbo.Enabled = false;\r
                 tab_advanced.Enabled = false;\r
-                x264Panel.x264Query = "";\r
+                x264Panel.X264Query = string.Empty;\r
                 check_iPodAtom.Enabled = false;\r
                 check_iPodAtom.Checked = false;\r
             }\r
@@ -1201,7 +1718,7 @@ namespace Handbrake
             {\r
                 case "MPEG-4 (FFmpeg)":\r
                     if (slider_videoQuality.Value > 31)\r
-                        slider_videoQuality.Value = 20;   // Just reset to 70% QP 10 on encode change.\r
+                        slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.\r
                     slider_videoQuality.Minimum = 1;\r
                     slider_videoQuality.Maximum = 31;\r
                     break;\r
@@ -1210,39 +1727,25 @@ namespace Handbrake
                     slider_videoQuality.TickFrequency = 1;\r
 \r
                     CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");\r
-                    double multiplier = 1.0 / Properties.Settings.Default.x264cqstep;\r
+                    double cqStep = Properties.Settings.Default.x264cqstep;\r
+                    double multiplier = 1.0 / cqStep;\r
                     double value = slider_videoQuality.Value * multiplier;\r
 \r
-                    switch (Properties.Settings.Default.x264cqstep.ToString(culture))\r
-                    {\r
-                        case "0.20":\r
-                            slider_videoQuality.Maximum = 255;\r
-                            break;\r
-                        case "0.25":\r
-                            slider_videoQuality.Maximum = 204;\r
-                            break;\r
-                        case "0.50":\r
-                            slider_videoQuality.Maximum = 40;\r
-                            break;\r
-                        case "1.0":\r
-                            slider_videoQuality.Maximum = 51;\r
-                            break;\r
-                        default:\r
-                            slider_videoQuality.Maximum = 51;\r
-                            break;\r
-                    }\r
+                    slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);\r
+\r
                     if (value < slider_videoQuality.Maximum)\r
                         slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;\r
 \r
                     break;\r
                 case "VP3 (Theora)":\r
                     if (slider_videoQuality.Value > 63)\r
-                        slider_videoQuality.Value = 45;  // Just reset to 70% QP 45 on encode change.\r
+                        slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.\r
                     slider_videoQuality.Minimum = 0;\r
                     slider_videoQuality.Maximum = 63;\r
                     break;\r
             }\r
         }\r
+\r
         /// <summary>\r
         /// Set the container format options\r
         /// </summary>\r
@@ -1264,32 +1767,56 @@ namespace Handbrake
                 check_iPodAtom.Checked = false;\r
             }\r
         }\r
+\r
+        private double _cachedCqStep = Properties.Settings.Default.x264cqstep;\r
+\r
+        /// <summary>\r
+        /// Update the CQ slider for x264 for a new CQ step. This is set from option\r
+        /// </summary>\r
+        public void setQualityFromSlider()\r
+        {\r
+            // Work out the current RF value.\r
+            double cqStep = _cachedCqStep;\r
+            double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
+\r
+            // Change the maximum value for the slider\r
+            slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);\r
+\r
+            // Reset the CQ slider to RF0\r
+            slider_videoQuality.Value = slider_videoQuality.Maximum;\r
+\r
+            // Reset the CQ slider back to the previous value as close as possible\r
+            double cqStepNew = Properties.Settings.Default.x264cqstep;\r
+            double rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;\r
+            while (rfValueCurrent < rfValue)\r
+            {\r
+                slider_videoQuality.Value--;\r
+                rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;\r
+            }\r
+\r
+            // Cache the CQ step for the next calculation\r
+            _cachedCqStep = Properties.Settings.Default.x264cqstep;\r
+        }\r
+\r
         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
         {\r
+            double cqStep = Properties.Settings.Default.x264cqstep;\r
             switch (drp_videoEncoder.Text)\r
             {\r
                 case "MPEG-4 (FFmpeg)":\r
-                    double rfValue = 31 - (slider_videoQuality.Value - 1);\r
-                    double max = slider_videoQuality.Maximum;\r
-                    double min = slider_videoQuality.Minimum;\r
-                    double val = ((max - min) - (rfValue - min)) / (max - min);\r
-                    SliderValue.Text = Math.Round((val * 100), 2) + "% QP:" + (32 - slider_videoQuality.Value);\r
+                    lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);\r
                     break;\r
                 case "H.264 (x264)":\r
-                    rfValue = 51.0 - slider_videoQuality.Value * Properties.Settings.Default.x264cqstep;\r
-                    max = slider_videoQuality.Maximum * Properties.Settings.Default.x264cqstep;\r
-                    min = slider_videoQuality.Minimum;\r
-                    val = ((max - min) - (rfValue - min)) / (max - min);\r
+                    double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
                     rfValue = Math.Round(rfValue, 2);\r
-                    SliderValue.Text = Math.Round((val * 100), 2) + "% RF:" + rfValue;\r
+                    lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));\r
                     break;\r
                 case "VP3 (Theora)":\r
-                    rfValue = slider_videoQuality.Value;\r
-                    double value = rfValue / 63;\r
-                    SliderValue.Text = Math.Round((value * 100), 2) + "% QP:" + slider_videoQuality.Value;\r
+                    lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;\r
                     break;\r
             }\r
         }\r
+\r
         private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)\r
         {\r
             text_bitrate.Enabled = false;\r
@@ -1298,6 +1825,7 @@ namespace Handbrake
 \r
             check_2PassEncode.Enabled = true;\r
         }\r
+\r
         private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)\r
         {\r
             text_bitrate.Enabled = true;\r
@@ -1306,6 +1834,7 @@ namespace Handbrake
 \r
             check_2PassEncode.Enabled = true;\r
         }\r
+\r
         private void radio_cq_CheckedChanged(object sender, EventArgs e)\r
         {\r
             text_bitrate.Enabled = false;\r
@@ -1315,6 +1844,7 @@ namespace Handbrake
             check_2PassEncode.Enabled = false;\r
             check_2PassEncode.CheckState = CheckState.Unchecked;\r
         }\r
+\r
         private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)\r
         {\r
             if (check_2PassEncode.CheckState.ToString() == "Checked")\r
@@ -1335,151 +1865,178 @@ namespace Handbrake
             if (Check_ChapterMarkers.Checked)\r
             {\r
                 if (drop_format.SelectedIndex != 1)\r
-                    setExtension(".m4v");\r
-                data_chpt.Rows.Clear();\r
+                    SetExtension(".m4v");\r
                 data_chpt.Enabled = true;\r
-                DataGridView chapterGridView = Main.chapterNaming(data_chpt, drop_chapterFinish.Text);\r
-                if (chapterGridView != null)\r
-                    data_chpt = chapterGridView;\r
+                btn_importChapters.Enabled = true;\r
             }\r
             else\r
             {\r
                 if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v)\r
-                    setExtension(".mp4");\r
-                data_chpt.Rows.Clear();\r
+                    SetExtension(".mp4");\r
                 data_chpt.Enabled = false;\r
+                btn_importChapters.Enabled = false;\r
+            }\r
+        }\r
+\r
+        private void btn_importChapters_Click(object sender, EventArgs e)\r
+        {\r
+            if (File_ChapterImport.ShowDialog() == DialogResult.OK)\r
+            {\r
+                string filename = File_ChapterImport.FileName;\r
+                DataGridView imported = Main.ImportChapterNames(data_chpt, filename);\r
+                if (imported != null)\r
+                    data_chpt = imported;\r
+            }\r
+        }\r
+\r
+        private void btn_export_Click(object sender, EventArgs e)\r
+        {\r
+            SaveFileDialog saveFileDialog = new SaveFileDialog();\r
+            saveFileDialog.Filter = "Csv File|*.csv";\r
+            saveFileDialog.DefaultExt = "csv";\r
+            if (saveFileDialog.ShowDialog() == DialogResult.OK)\r
+            {\r
+                string filename = saveFileDialog.FileName;\r
+\r
+                Main.SaveChapterMarkersToCsv(this, filename);\r
+            }\r
+        }\r
+\r
+        private void mnu_resetChapters_Click(object sender, EventArgs e)\r
+        {\r
+            data_chpt.Rows.Clear();\r
+            DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);\r
+            if (chapterGridView != null)\r
+            {\r
+                data_chpt = chapterGridView;\r
             }\r
         }\r
 \r
         // Query Editor Tab\r
         private void btn_generate_Query_Click(object sender, EventArgs e)\r
         {\r
-            rtf_query.Text = queryGen.generateTheQuery(this);\r
+            rtf_query.Text = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
         }\r
+\r
         private void btn_clear_Click(object sender, EventArgs e)\r
         {\r
             rtf_query.Clear();\r
         }\r
+\r
         #endregion\r
 \r
         // MainWindow Components, Actions and Functions ***********************\r
 \r
         #region Source Scan\r
-        public Boolean isScanning { get; set; }\r
-        private static int scanProcessID { get; set; }\r
-        private void setupGUIforScan(String filename)\r
-        {\r
+\r
+        /// <summary>\r
+        /// Start the Scan Process\r
+        /// </summary>\r
+        /// <param name="filename">\r
+        /// The filename.\r
+        /// </param>\r
+        /// <param name="title">\r
+        /// The title.\r
+        /// </param>\r
+        private void StartScan(string filename, int title)\r
+        {\r
+            // Setup the GUI components for the scan.\r
             sourcePath = filename;\r
-            foreach (Control ctrl in Controls)\r
-            {\r
-                if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))\r
-                    ctrl.Enabled = false;\r
-            }\r
-            lbl_encode.Visible = true;\r
-            lbl_encode.Text = "Scanning ...";\r
-            //gb_source.Text = "Source: Scanning ...";\r
-            btn_source.Enabled = false;\r
-            btn_start.Enabled = false;\r
-            btn_showQueue.Enabled = false;\r
-            btn_add2Queue.Enabled = false;\r
-            tb_preview.Enabled = false;\r
-            mnu_killCLI.Visible = true;\r
-        }\r
-        private void startScan(String filename)\r
-        {\r
+\r
+            this.DisableGUI();\r
+\r
+            // Start the Scan\r
             try\r
             {\r
-                lbl_encode.Visible = true;\r
-                lbl_encode.Text = "Scanning...";\r
-                if (ActivityWindow != null)\r
-                    ActivityWindow.setLogView(true);\r
-                isScanning = true;\r
-                ThreadPool.QueueUserWorkItem(scanProcess, filename);\r
+                SourceScan.Scan(sourcePath, title);\r
+                SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);\r
+                SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);\r
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("frmMain.cs - startScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
         }\r
-        private void scanProcess(object state)\r
-        {\r
-            try\r
-            {\r
-                string inputFile = (string)state;\r
-                string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
-                string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
-                string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");\r
-\r
-                // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)\r
-                if (File.Exists(dvdInfoPath))\r
-                    File.Delete(dvdInfoPath);\r
 \r
-                String dvdnav = string.Empty;\r
-                if (Properties.Settings.Default.dvdnav)\r
-                    dvdnav = " --dvdnav";\r
-                string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 {2} -v >""{3}"" 2>&1""", handbrakeCLIPath, inputFile, dvdnav, dvdInfoPath);\r
-\r
-                ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine) { WindowStyle = ProcessWindowStyle.Hidden };\r
-\r
-                Boolean cleanExit = true;\r
-                using (hbproc = Process.Start(hbParseDvd))\r
-                {\r
-                    Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.\r
-                    scanProcessID = Main.getCliProcess(before);\r
-                    hbproc.WaitForExit();\r
-                    if (hbproc.ExitCode != 0)\r
-                        cleanExit = false;\r
-                }\r
-\r
-                if (cleanExit) // If 0 exit code, CLI exited cleanly.\r
-                {\r
-                    if (!File.Exists(dvdInfoPath))\r
-                    {\r
-                        throw new Exception(\r
-                            "Unable to retrieve the DVD Info. last_scan_log.txt is missing. \nExpected location of last_scan_log.txt: \n" +\r
-                            dvdInfoPath);\r
-                    }\r
+        /// <summary>\r
+        /// Update the Status label for the scan\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void SourceScan_ScanStatusChanged(object sender, EventArgs e)\r
+        {\r
+            UpdateScanStatusLabel();\r
+        }\r
 \r
-                    using (StreamReader sr = new StreamReader(dvdInfoPath))\r
-                    {\r
-                        thisDVD = DVD.Parse(sr);\r
-                        sr.Close();\r
-                        sr.Dispose();\r
-                    }\r
+        /// <summary>\r
+        /// Update the UI after the scan has completed\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void SourceScan_ScanCompleted(object sender, EventArgs e)\r
+        {\r
+            UpdateGuiAfterScan();\r
+        }\r
 \r
-                    updateUIafterScan();\r
-                }\r
-            }\r
-            catch (Exception exc)\r
+        /// <summary>\r
+        /// Update the Scan Status Label\r
+        /// </summary>\r
+        private void UpdateScanStatusLabel()\r
+        {\r
+            if (InvokeRequired)\r
             {\r
-                MessageBox.Show("frmMain.cs - scanProcess() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                enableGUI();\r
+                BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));\r
+                return;\r
             }\r
+            lbl_encode.Text = SourceScan.ScanStatus;\r
         }\r
-        private void updateUIafterScan()\r
+\r
+        /// <summary>\r
+        /// Reset the GUI when the scan has completed\r
+        /// </summary>\r
+        private void UpdateGuiAfterScan()\r
         {\r
+            if (InvokeRequired)\r
+            {\r
+                BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));\r
+                return;\r
+            }\r
+\r
             try\r
             {\r
-                if (InvokeRequired)\r
-                {\r
-                    BeginInvoke(new UpdateWindowHandler(updateUIafterScan));\r
-                    return;\r
-                }\r
+                currentSource = SourceScan.SouceData;\r
 \r
                 // Setup some GUI components\r
                 drp_dvdtitle.Items.Clear();\r
-                if (thisDVD.Titles.Count != 0)\r
-                    drp_dvdtitle.Items.AddRange(thisDVD.Titles.ToArray());\r
-                drp_dvdtitle.Text = "Automatic";\r
-                drop_chapterFinish.Text = "Auto";\r
-                drop_chapterStart.Text = "Auto";\r
+                if (currentSource.Titles.Count != 0)\r
+                    drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());\r
 \r
-                // Now select the longest title\r
-                if (thisDVD.Titles.Count != 0)\r
-                    drp_dvdtitle.SelectedItem = Main.selectLongestTitle(thisDVD);\r
+                foreach (Title title in currentSource.Titles)\r
+                {\r
+                    if (title.MainTitle)\r
+                    {\r
+                        drp_dvdtitle.SelectedItem = title;\r
+                    }\r
+                }\r
+\r
+                if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)\r
+                {\r
+                    drp_dvdtitle.SelectedIndex = 0;\r
+                }\r
 \r
                 // Enable the creation of chapter markers if the file is an image of a dvd.\r
-                if (sourcePath.ToLower().Contains(".iso") || sourcePath.Contains("VIDEO_TS"))\r
+                int start, end;\r
+                int.TryParse(drop_chapterStart.Items[0].ToString(), out start);\r
+                int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);\r
+                if (end > start)\r
                     Check_ChapterMarkers.Enabled = true;\r
                 else\r
                 {\r
@@ -1492,29 +2049,33 @@ namespace Handbrake
                 if (drp_dvdtitle.Items.Count == 0)\r
                 {\r
                     MessageBox.Show(\r
-                        "No Title(s) found. \n\nYour Source may be copy protected, badly mastered or a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).",\r
+                        "No Title(s) found. \n\nYour Source may be copy protected, badly mastered or in a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).",\r
                         "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
                     sourcePath = string.Empty;\r
                 }\r
                 UpdateSourceLabel();\r
 \r
                 // Enable the GUI components and enable any disabled components\r
-                enableGUI();\r
+                EnableGUI();\r
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                enableGUI();\r
+                MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,\r
+                                MessageBoxIcon.Error);\r
+                EnableGUI();\r
             }\r
         }\r
-        private void enableGUI()\r
+\r
+        /// <summary>\r
+        /// Enable the GUI\r
+        /// </summary>\r
+        private void EnableGUI()\r
         {\r
             try\r
             {\r
                 if (InvokeRequired)\r
-                    BeginInvoke(new UpdateWindowHandler(enableGUI));\r
+                    BeginInvoke(new UpdateWindowHandler(EnableGUI));\r
                 lbl_encode.Text = "Scan Completed";\r
-                //gb_source.Text = "Source";\r
                 foreach (Control ctrl in Controls)\r
                     ctrl.Enabled = true;\r
                 btn_start.Enabled = true;\r
@@ -1526,72 +2087,122 @@ namespace Handbrake
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show("frmMain.cs - enableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
         }\r
-        private void killScan()\r
+\r
+        /// <summary>\r
+        /// Disable the GUI\r
+        /// </summary>\r
+        private void DisableGUI()\r
         {\r
-            try\r
-            {\r
-                enableGUI();\r
-                resetGUI();\r
+            foreach (Control ctrl in Controls)\r
+                if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))\r
+                    ctrl.Enabled = false;\r
 \r
-                Process[] prs = Process.GetProcesses();\r
-                foreach (Process process in prs)\r
-                {\r
-                    if (process.Id == scanProcessID)\r
-                    {\r
-                        process.Refresh();\r
-                        if (!process.HasExited)\r
-                            process.Kill();\r
-                    }\r
-                }\r
-            }\r
-            catch (Exception ex)\r
-            {\r
-                MessageBox.Show("Unable to kill HandBrakeCLI.exe \nYou may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically within the next few minutes. \n\nError Information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-            }\r
+            lbl_encode.Visible = true;\r
+            lbl_encode.Text = "Scanning ...";\r
+            btn_source.Enabled = false;\r
+            btn_start.Enabled = false;\r
+            btn_showQueue.Enabled = false;\r
+            btn_add2Queue.Enabled = false;\r
+            tb_preview.Enabled = false;\r
+            mnu_killCLI.Visible = true;\r
         }\r
-        private void resetGUI()\r
+\r
+        /// <summary>\r
+        /// Kill the Scan\r
+        /// </summary>\r
+        private void KillScan()\r
+        {\r
+            SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+            EnableGUI();\r
+            ResetGUI();\r
+\r
+            SourceScan.Stop();\r
+\r
+            lbl_encode.Text = "Scan Cancelled!";\r
+        }\r
+\r
+        /// <summary>\r
+        /// Reset the GUI\r
+        /// </summary>\r
+        private void ResetGUI()\r
         {\r
             drp_dvdtitle.Items.Clear();\r
-            drp_dvdtitle.Text = "Automatic";\r
             drop_chapterStart.Items.Clear();\r
-            drop_chapterStart.Text = "Auto";\r
             drop_chapterFinish.Items.Clear();\r
-            drop_chapterFinish.Text = "Auto";\r
             lbl_duration.Text = "Select a Title";\r
             PictureSettings.lbl_src_res.Text = "Select a Title";\r
-            PictureSettings.lbl_Aspect.Text = "Select a Title";\r
-            sourcePath = "Source";\r
-            text_destination.Text = "";\r
-            thisDVD = null;\r
+            sourcePath = String.Empty;\r
+            text_destination.Text = String.Empty;\r
             selectedTitle = null;\r
-            isScanning = false;\r
         }\r
 \r
+        /// <summary>\r
+        /// Update the Source Label\r
+        /// </summary>\r
         private void UpdateSourceLabel()\r
         {\r
-            labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : Path.GetFileName(sourcePath);\r
+            labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;\r
+\r
+            if (selectedTitle != null)\r
+                if (!string.IsNullOrEmpty(selectedTitle.SourceName))\r
+                    // If it's one of multiple source files, make sure we don't use the folder name\r
+                    labelSource.Text = Path.GetFileName(selectedTitle.SourceName);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Take a job from the Queue, rescan it, and reload the GUI for that job.\r
+        /// </summary>\r
+        /// <param name="job">\r
+        /// The job.\r
+        /// </param>\r
+        public void RecievingJob(Job job)\r
+        {\r
+            string query = job.Query;\r
+            StartScan(job.Source, job.Title);\r
+\r
+            if (query != null)\r
+            {\r
+                // Ok, Reset all the H264 widgets before changing the preset\r
+                x264Panel.Reset2Defaults();\r
+\r
+                // Send the query from the file to the Query Parser class\r
+                QueryParser presetQuery = QueryParser.Parse(query);\r
+\r
+                // Now load the preset\r
+                PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue", true);\r
+\r
+                // The x264 widgets will need updated, so do this now:\r
+                x264Panel.X264_StandardizeOptString();\r
+                x264Panel.X264_SetCurrentSettingsInPanel();\r
+\r
+                // Finally, let this window have a copy of the preset settings.\r
+                CurrentlySelectedPreset = null;\r
+                PictureSettings.SetPresetCropWarningLabel(null);\r
+            }\r
         }\r
 \r
         #endregion\r
 \r
-        #region GUI\r
+        #region GUI Functions and Actions\r
+\r
         /// <summary>\r
         /// Set the GUI to it's finished encoding state.\r
         /// </summary>\r
-        private void setEncodeFinished()\r
+        private void SetEncodeFinished()\r
         {\r
             try\r
             {\r
                 if (InvokeRequired)\r
                 {\r
-                    BeginInvoke(new UpdateWindowHandler(setEncodeFinished));\r
+                    BeginInvoke(new UpdateWindowHandler(SetEncodeFinished));\r
                     return;\r
                 }\r
 \r
                 lbl_encode.Text = "Encoding Finished";\r
+                ProgressBarStatus.Visible = false;\r
                 btn_start.Text = "Start";\r
                 btn_start.ToolTipText = "Start the encoding process";\r
                 btn_start.Image = Properties.Resources.Play;\r
@@ -1613,18 +2224,19 @@ namespace Handbrake
         /// <summary>\r
         /// Set the GUI to it's started encoding state.\r
         /// </summary>\r
-        private void setEncodeStarted()\r
+        private void SetEncodeStarted()\r
         {\r
             try\r
             {\r
                 if (InvokeRequired)\r
                 {\r
-                    BeginInvoke(new UpdateWindowHandler(setEncodeStarted));\r
+                    BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));\r
                     return;\r
                 }\r
-\r
                 lbl_encode.Visible = true;\r
-                lbl_encode.Text = "Encoding in Progress";\r
+                ProgressBarStatus.Value = 0;\r
+                ProgressBarStatus.Visible = true;\r
+                lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";\r
                 btn_start.Text = "Stop";\r
                 btn_start.ToolTipText = "Stop the encoding process.";\r
                 btn_start.Image = Properties.Resources.stop;\r
@@ -1634,109 +2246,229 @@ namespace Handbrake
                 MessageBox.Show(exc.ToString());\r
             }\r
         }\r
-        #endregion\r
 \r
-        #region DVD Drive Detection\r
-        private delegate void ProgressUpdateHandler();\r
-        private void getDriveInfoThread()\r
+        /// <summary>\r
+        /// Set the DVD Drive selection in the "Source" Menu\r
+        /// </summary>\r
+        private void SetDriveSelectionMenuItem()\r
         {\r
             try\r
             {\r
                 if (InvokeRequired)\r
                 {\r
-                    BeginInvoke(new ProgressUpdateHandler(getDriveInfoThread));\r
+                    BeginInvoke(new UpdateWindowHandler(SetDriveSelectionMenuItem));\r
                     return;\r
                 }\r
 \r
-                Boolean foundDrive = false;\r
-                DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();\r
-                foreach (DriveInfo curDrive in theCollectionOfDrives)\r
+                drives = Main.GetDrives();\r
+\r
+                List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();\r
+                foreach (DriveInformation drive in drives)\r
                 {\r
-                    if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady)\r
-                    {\r
-                        if (File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))\r
+                    ToolStripMenuItem menuItem = new ToolStripMenuItem\r
                         {\r
-                            mnu_dvd_drive.Text = curDrive.RootDirectory + "VIDEO_TS (" + curDrive.VolumeLabel + ")";\r
-                            foundDrive = true;\r
-                            break;\r
-                        }\r
-                    }\r
+                            Name = drive.ToString(),\r
+                            Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",\r
+                            Image = Resources.disc_small\r
+                        };\r
+                    menuItem.Click += new EventHandler(mnu_dvd_drive_Click);\r
+                    menuItems.Add(menuItem);\r
                 }\r
 \r
-                if (foundDrive == false)\r
-                    mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
+                foreach (ToolStripMenuItem item in menuItems)\r
+                    btn_source.DropDownItems.Add(item);\r
             }\r
-            catch (Exception)\r
+            catch (Exception exc)\r
             {\r
-                mnu_dvd_drive.Text = "[No DVD Drive Ready / Found]";\r
+                MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);\r
             }\r
         }\r
-        #endregion\r
 \r
-        #region Public Methods\r
         /// <summary>\r
         /// Access the preset Handler and setup the preset panel.\r
         /// </summary>\r
-        public void loadPresetPanel()\r
+        private void LoadPresetPanel()\r
         {\r
-            if (presetHandler.checkIfPresetsAreOutOfDate())\r
+            if (presetHandler.CheckIfPresetsAreOutOfDate())\r
                 if (!Properties.Settings.Default.presetNotification)\r
                     MessageBox.Show(splash,\r
-                    "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",\r
-                    "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
+                                    "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",\r
+                                    "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
 \r
-            presetHandler.getPresetPanel(ref treeView_presets);\r
+            presetHandler.GetPresetPanel(ref treeView_presets);\r
             treeView_presets.Update();\r
-        }       \r
+        }\r
+\r
+        /// <summary>\r
+        /// Get the title from the selected item in the title dropdown.\r
+        /// </summary>\r
+        /// <returns>\r
+        /// The title.\r
+        /// </returns>\r
+        private int getTitle()\r
+        {\r
+            int title = 0;\r
+            if (drp_dvdtitle.SelectedItem != null)\r
+            {\r
+                string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');\r
+                int.TryParse(titleInfo[0], out title);\r
+            }\r
+\r
+            return title;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Handle the Update Check Finishing.\r
+        /// </summary>\r
+        /// <param name="result">\r
+        /// The result.\r
+        /// </param>\r
+        private void updateCheckDoneMenu(IAsyncResult result)\r
+        {\r
+            // Make sure it's running on the calling thread\r
+            if (InvokeRequired)\r
+            {\r
+                Invoke(new MethodInvoker(() => updateCheckDoneMenu(result)));\r
+                return;\r
+            }\r
+            UpdateCheckInformation info;\r
+            try\r
+            {\r
+                // Get the information about the new build, if any, and close the window\r
+                info = Main.EndCheckForUpdates(result);\r
+\r
+                if (info.NewVersionAvailable && info.BuildInformation != null)\r
+                {\r
+                    frmUpdater updateWindow = new frmUpdater(info.BuildInformation);\r
+                    updateWindow.ShowDialog();\r
+                }\r
+                else\r
+                    MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,\r
+                                    MessageBoxIcon.Information);\r
+                lbl_updateCheck.Visible = false;\r
+                return;\r
+            }\r
+            catch (Exception ex)\r
+            {\r
+                if ((bool)result.AsyncState)\r
+                    MessageBox.Show(\r
+                        "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,\r
+                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+            }\r
+        }\r
+\r
         #endregion\r
 \r
         #region Overrides\r
+\r
+        /// <summary>\r
+        /// Handle GUI shortcuts\r
+        /// </summary>\r
+        /// <param name="msg">Message</param>\r
+        /// <param name="keyData">Keys</param>\r
+        /// <returns>Bool</returns>\r
+        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)\r
+        {\r
+            if (keyData == (Keys.Control | Keys.S))\r
+            {\r
+                btn_start_Click(this, new EventArgs());\r
+                return true;\r
+            }\r
+\r
+            if (keyData == (Keys.Control | Keys.A))\r
+            {\r
+                btn_add2Queue_Click(this, new EventArgs());\r
+                return true;\r
+            }\r
+            return base.ProcessCmdKey(ref msg, keyData);\r
+        }\r
+\r
         /// <summary>\r
         /// If the queue is being processed, prompt the user to confirm application close.\r
         /// </summary>\r
-        /// <param name="e"></param>\r
+        /// <param name="e">FormClosingEventArgs</param>\r
         protected override void OnFormClosing(FormClosingEventArgs e)\r
         {\r
             // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.\r
-            if ((encodeQueue.isEncoding) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0))\r
+            if (encodeQueue.IsEncoding)\r
             {\r
-                DialogResult result = MessageBox.Show("HandBrake has queue items to process. Closing HandBrake will not stop the current encoding, but will stop processing the queue.\n\nDo you want to close HandBrake?",\r
-                    "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+                DialogResult result =\r
+                    MessageBox.Show(\r
+                        "HandBrake has queue items to process. Closing HandBrake will stop the current encoding.\n\nDo you want to close HandBrake?",\r
+                        "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+\r
                 if (result == DialogResult.No)\r
                     e.Cancel = true;\r
+\r
+                // Try to safely close out if we can, or kill the cli if using in-gui status\r
+                if (Settings.Default.enocdeStatusInGui)\r
+                    encodeQueue.Stop();\r
+                else\r
+                    encodeQueue.SafelyClose();\r
+            }\r
+\r
+            if (SourceScan.IsScanning)\r
+            {\r
+                SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+                SourceScan.Stop();\r
             }\r
             base.OnFormClosing(e);\r
         }\r
+\r
         #endregion\r
 \r
-        #region In-GUI Encode Status (Experimental)\r
+        #region In-GUI Encode Status\r
 \r
-        private void encodeMonitorThread()\r
+        /// <summary>\r
+        /// Starts a new thread to monitor and process the CLI encode status\r
+        /// </summary>\r
+        private void EncodeMonitorThread()\r
         {\r
             try\r
             {\r
-                Parser encode = new Parser(encodeQueue.hbProcess.StandardOutput.BaseStream);\r
-                encode.OnEncodeProgress += encodeOnEncodeProgress;\r
+                Parser encode = new Parser(encodeQueue.HbProcess.StandardOutput.BaseStream);\r
+                encode.OnEncodeProgress += EncodeOnEncodeProgress;\r
                 while (!encode.EndOfStream)\r
-                {\r
-                    encode.readEncodeStatus();\r
-                }\r
+                    encode.ReadEncodeStatus();\r
+\r
+                SetEncodeFinished();\r
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show(exc.ToString());\r
+                MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
         }\r
-        private void encodeOnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
+\r
+        /// <summary>\r
+        /// Displays the Encode status in the GUI\r
+        /// </summary>\r
+        /// <param name="sender">The sender</param>\r
+        /// <param name="currentTask">The current task</param>\r
+        /// <param name="taskCount">Number of tasks</param>\r
+        /// <param name="percentComplete">Percent complete</param>\r
+        /// <param name="currentFps">Current encode speed in fps</param>\r
+        /// <param name="av">Avg encode speed</param>\r
+        /// <param name="timeRemaining">Time Left</param>\r
+        private void EncodeOnEncodeProgress(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float av, TimeSpan timeRemaining)\r
         {\r
             if (this.InvokeRequired)\r
             {\r
-                this.BeginInvoke(new EncodeProgressEventHandler(encodeOnEncodeProgress),\r
-                    new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
+                this.BeginInvoke(\r
+                    new EncodeProgressEventHandler(EncodeOnEncodeProgress),\r
+                    new[] { sender, currentTask, taskCount, percentComplete, currentFps, av, timeRemaining });\r
                 return;\r
             }\r
-            lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
+            lbl_encode.Text =\r
+                string.Format(\r
+                "{0:00.00}%,    FPS: {1:000.0},    Avg FPS: {2:000.0},    Time Remaining: {3}",\r
+                percentComplete,\r
+                currentFps,\r
+                av,\r
+                timeRemaining);\r
+\r
+            ProgressBarStatus.Value = (int)Math.Round(percentComplete);\r
         }\r
+\r
         #endregion\r
 \r
         // This is the END of the road ****************************************\r