OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index 4e3a73f..18e39f7 100644 (file)
@@ -14,6 +14,7 @@ using System.Diagnostics;
 using System.Threading;\r
 using Handbrake.EncodeQueue;\r
 using Handbrake.Functions;\r
+using Handbrake.Model;\r
 using Handbrake.Presets;\r
 using Handbrake.Parsing;\r
 \r
@@ -22,13 +23,11 @@ namespace Handbrake
     public partial class frmMain : Form\r
     {\r
         // Objects which may be used by one or more other objects *************\r
-        EncodeAndQueueHandler encodeQueue = new EncodeAndQueueHandler();\r
+        Queue encodeQueue = new Queue();\r
         PresetsHandler presetHandler = new PresetsHandler();\r
-        QueryGenerator queryGen = new QueryGenerator();\r
 \r
         // Globals: Mainly used for tracking. *********************************\r
         public Title selectedTitle;\r
-        private DVD thisDVD;\r
         private frmQueue queueWindow;\r
         private frmPreview qtpreview;\r
         private frmActivityWindow ActivityWindow;\r
@@ -38,6 +37,8 @@ namespace Handbrake
         private SourceType selectedSourceType;\r
         private string dvdDrivePath;\r
         private string dvdDriveLabel;\r
+        private Preset CurrentlySelectedPreset;\r
+        private DVD currentSource;\r
 \r
         // Delegates **********************************************************\r
         private delegate void UpdateWindowHandler();\r
@@ -58,7 +59,7 @@ namespace Handbrake
             // Update the users config file with the CLI version data.\r
             lblStatus.Text = "Setting Version Data ...";\r
             Application.DoEvents();\r
-            Main.setCliVersionData();\r
+            Main.SetCliVersionData();\r
 \r
             // Show the form, but leave disabled until preloading is complete then show the main form\r
             this.Enabled = false;\r
@@ -80,13 +81,23 @@ namespace Handbrake
                 }\r
             }\r
 \r
+            // Clear the log files in the background\r
+            if (Properties.Settings.Default.clearOldLogs)\r
+            {\r
+                lblStatus.Text = "Clearing Old Log Files ...";\r
+                Application.DoEvents();\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
+            LoadPresetPanel();                       // Load the Preset Panel\r
             treeView_presets.ExpandAll();\r
             lbl_encode.Text = "";\r
-            queueWindow = new frmQueue(encodeQueue);        // Prepare the Queue\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
 \r
@@ -100,14 +111,11 @@ namespace Handbrake
 \r
                     if (query != null)\r
                     {\r
-                        //Ok, Reset all the H264 widgets before changing the preset\r
-                        x264Panel.reset2Defaults();\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
+                        PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset, loadPictureSettings);\r
 \r
-                        // The x264 widgets will need updated, so do this now:\r
                         x264Panel.X264_StandardizeOptString();\r
                         x264Panel.X264_SetCurrentSettingsInPanel();\r
                     }\r
@@ -167,7 +175,7 @@ namespace Handbrake
         // Startup Functions   \r
         private void queueRecovery()\r
         {\r
-            if (Main.checkQueueRecovery())\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
 \r
@@ -194,7 +202,10 @@ namespace Handbrake
                     return this.dvdDriveLabel;\r
                 }\r
 \r
-                return Path.GetFileNameWithoutExtension(this.sourcePath);\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
         #endregion\r
@@ -211,9 +222,10 @@ namespace Handbrake
                 this.Resize += new EventHandler(frmMain_Resize);\r
 \r
             // Handle Encode Start / Finish / Pause\r
-            encodeQueue.CurrentJobCompleted += new EventHandler(encodeEnded);\r
+\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
@@ -280,6 +292,7 @@ namespace Handbrake
         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
@@ -294,20 +307,13 @@ namespace Handbrake
 \r
             if (fileList != null)\r
             {\r
-                if (fileList[0].StartsWith("\\"))\r
+                if (fileList[0] != "")\r
                 {\r
-                    MessageBox.Show(\r
-                        "Sorry, HandBrake does not support UNC file paths. \nTry mounting the network 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
-                        startScan(fileList[0]);\r
-                    else\r
-                        UpdateSourceLabel();\r
-                }\r
+                    UpdateSourceLabel();\r
             }\r
             else\r
                 UpdateSourceLabel();\r
@@ -315,22 +321,22 @@ namespace Handbrake
         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
+                Thread encodeMon = new Thread(EncodeMonitorThread);\r
                 encodeMon.Start();\r
             }\r
         }\r
         private void encodeEnded(object sender, EventArgs e)\r
         {\r
-            setEncodeFinished();\r
+            SetEncodeFinished();\r
         }\r
         private void encodePaused(object sender, EventArgs e)\r
         {\r
-            setEncodeFinished();\r
+            SetEncodeFinished();\r
         }\r
         #endregion\r
 \r
@@ -339,7 +345,7 @@ namespace Handbrake
         #region File Menu\r
         private void mnu_killCLI_Click(object sender, EventArgs e)\r
         {\r
-            killScan();\r
+            KillScan();\r
         }\r
         private void mnu_exit_Click(object sender, EventArgs e)\r
         {\r
@@ -354,9 +360,7 @@ namespace Handbrake
         }\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(lastAction);\r
             dvdInfoWindow.Show();\r
         }\r
         private void mnu_options_Click(object sender, EventArgs e)\r
@@ -370,7 +374,7 @@ namespace Handbrake
         private void mnu_presetReset_Click(object sender, EventArgs e)\r
         {\r
             presetHandler.UpdateBuiltInPresets();\r
-            loadPresetPanel();\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
             else\r
@@ -381,7 +385,7 @@ namespace Handbrake
         private void mnu_delete_preset_Click(object sender, EventArgs e)\r
         {\r
             presetHandler.RemoveBuiltInPresets();\r
-            loadPresetPanel(); // Reload the preset panel\r
+            LoadPresetPanel(); // Reload the preset panel\r
         }\r
         private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
         {\r
@@ -393,16 +397,12 @@ namespace Handbrake
         }\r
         private void btn_new_preset_Click(object sender, EventArgs e)\r
         {\r
-            Form preset = new frmAddPreset(this, queryGen.GenerateCLIQuery(this, 0, null), presetHandler);\r
+            Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null), presetHandler);\r
             preset.ShowDialog();\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
         private void mnu_user_guide_Click(object sender, EventArgs e)\r
         {\r
             Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");\r
@@ -568,7 +568,7 @@ namespace Handbrake
                         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
@@ -588,7 +588,8 @@ namespace Handbrake
             {\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
@@ -596,17 +597,21 @@ namespace Handbrake
                     if (query != null)\r
                     {\r
                         //Ok, Reset all the H264 widgets before changing the preset\r
-                        x264Panel.reset2Defaults();\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
@@ -624,27 +629,26 @@ namespace Handbrake
         }\r
         private void importPreset()\r
         {\r
-            Import imp = new Import();\r
             if (openPreset.ShowDialog() == DialogResult.OK)\r
             {\r
-                QueryParser parsed = imp.importMacPreset(openPreset.FileName);\r
+                QueryParser parsed = PlistPresetHandler.Import(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.Update(parsed.PresetName + " (Imported)", queryGen.GenerateCLIQuery(this, 0, null),\r
+                        PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
+                        presetHandler.Update(parsed.PresetName + " (Imported)", QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
                                                    parsed.UsesPictureSettings);\r
                     }\r
                 }\r
                 else\r
                 {\r
-                    PresetLoader.presetLoader(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
-                    presetHandler.Add(parsed.PresetName, queryGen.GenerateCLIQuery(this, 0, null), parsed.UsesPictureSettings);\r
+                    PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
+                    presetHandler.Add(parsed.PresetName, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null), parsed.UsesPictureSettings);\r
 \r
-                    if (presetHandler.Add(parsed.PresetName + " (Imported)", queryGen.GenerateCLIQuery(this, 0, null), parsed.UsesPictureSettings))\r
+                    if (presetHandler.Add(parsed.PresetName + " (Imported)", QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null), parsed.UsesPictureSettings))\r
                     {\r
                         TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)") { ForeColor = Color.Black };\r
                         treeView_presets.Nodes.Add(preset_treeview);\r
@@ -658,44 +662,62 @@ namespace Handbrake
         private void btn_source_Click(object sender, EventArgs e)\r
         {\r
             mnu_dvd_drive.Visible = true;\r
-            Thread driveInfoThread = new Thread(getDriveInfoThread);\r
+            Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);\r
             driveInfoThread.Start();\r
         }\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 && !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
+                    if (Properties.Settings.Default.enocdeStatusInGui && !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
                     // Update the GUI\r
-                    setEncodeFinished();\r
+                    SetEncodeFinished();\r
                 }\r
             }\r
             else\r
             {\r
                 if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(sourcePath) && !string.IsNullOrEmpty(text_destination.Text)))\r
                 {\r
-                    string generatedQuery = queryGen.GenerateCLIQuery(this, 0, null);\r
-                    string specifiedQuery = rtf_query.Text != "" ? rtf_query.Text : queryGen.GenerateCLIQuery(this, 0, null);\r
+                    string generatedQuery = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+                    string specifiedQuery = rtf_query.Text != "" ? rtf_query.Text : 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
                     {\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
+                            "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." + Environment.NewLine + Environment.NewLine +\r
-                            "Do you want to replace the manual query with the GUI-generated query?",\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
@@ -718,7 +740,7 @@ namespace Handbrake
                     }\r
                     else\r
                     {\r
-                        query = generatedQuery;\r
+                        query = specifiedQuery;\r
                     }\r
 \r
                     DialogResult overwrite = DialogResult.Yes;\r
@@ -729,20 +751,19 @@ namespace Handbrake
                     if (overwrite == DialogResult.Yes)\r
                     {\r
                         if (encodeQueue.Count == 0)\r
-                            encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
+                            encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\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
-                        encodeQueue.StartEncodeQueue(); // Start The Queue Encoding Process\r
+                        SetEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
+                        encodeQueue.Start(); // Start The Queue Encoding Process\r
                         lastAction = "encode";   // Set the last action to encode - Used for activity window.\r
-\r
-                        if (ActivityWindow != null)\r
-                            ActivityWindow.SetLogView(false);\r
-\r
                     }\r
+                    if (ActivityWindow != null)\r
+                        ActivityWindow.SetEncodeMode();\r
+\r
                     this.Focus();\r
                 }\r
                 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
@@ -755,7 +776,7 @@ namespace Handbrake
                 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             else\r
             {\r
-                String query = queryGen.GenerateCLIQuery(this, 0, null);\r
+                String query = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
                 if (rtf_query.Text != "")\r
                     query = rtf_query.Text;\r
 \r
@@ -764,11 +785,11 @@ namespace Handbrake
                     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
                     if (result == DialogResult.Yes)\r
-                        encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
+                        encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\r
 \r
                 }\r
                 else\r
-                    encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
+                    encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != ""));\r
 \r
                 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
 \r
@@ -802,11 +823,24 @@ namespace Handbrake
         }\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
+            if (ActivityWindow == null || !ActivityWindow.IsHandleCreated)\r
+                ActivityWindow = new frmActivityWindow(lastAction);\r
+            else\r
+                switch (lastAction)\r
+                {\r
+                    case "scan":\r
+                        ActivityWindow.SetScanMode();\r
+                        break;\r
+                    case "encode":\r
+                        ActivityWindow.SetEncodeMode();\r
+                        break;\r
+                    default:\r
+                        ActivityWindow.SetEncodeMode();\r
+                        break;\r
+                }\r
 \r
             ActivityWindow.Show();\r
+            ActivityWindow.Activate();\r
         }\r
         #endregion\r
 \r
@@ -845,7 +879,7 @@ namespace Handbrake
             if (DVD_Open.ShowDialog() == DialogResult.OK)\r
             {\r
                 this.selectedSourceType = SourceType.Folder;\r
-                selectSource(DVD_Open.SelectedPath);\r
+                SelectSource(DVD_Open.SelectedPath);\r
             }\r
             else\r
                 UpdateSourceLabel();\r
@@ -855,7 +889,7 @@ namespace Handbrake
             if (ISO_Open.ShowDialog() == DialogResult.OK)\r
             {\r
                 this.selectedSourceType = SourceType.VideoFile;\r
-                selectSource(ISO_Open.FileName);\r
+                SelectSource(ISO_Open.FileName);\r
             }\r
             else\r
                 UpdateSourceLabel();\r
@@ -864,9 +898,9 @@ namespace Handbrake
         {\r
             if (this.dvdDrivePath == null) return;\r
             this.selectedSourceType = SourceType.DvdDrive;\r
-            selectSource(this.dvdDrivePath);\r
+            SelectSource(this.dvdDrivePath);\r
         }\r
-        private void selectSource(string file)\r
+        private void SelectSource(string file)\r
         {\r
             Check_ChapterMarkers.Enabled = true;\r
             lastAction = "scan";\r
@@ -878,17 +912,8 @@ namespace Handbrake
                 return;\r
             }\r
 \r
-            if (file.StartsWith("\\")) // NO UNC Paths\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
-                return;\r
-            }\r
-\r
             sourcePath = Path.GetFileName(file);\r
-            startScan(file);\r
+            StartScan(file, 0);\r
         }\r
         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
         {\r
@@ -898,6 +923,7 @@ namespace Handbrake
         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
         {\r
             UnRegisterPresetEventHandler();\r
+            drop_mode.SelectedIndex = 0;\r
 \r
             PictureSettings.lbl_Aspect.Text = "Select a Title"; // Reset some values on the form\r
             drop_chapterStart.Items.Clear();\r
@@ -909,11 +935,12 @@ namespace Handbrake
             {\r
                 selectedTitle = drp_dvdtitle.SelectedItem as Title;\r
                 lbl_duration.Text = selectedTitle.Duration.ToString();\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
@@ -943,17 +970,17 @@ namespace Handbrake
                 AudioSettings.SetTrackList(selectedTitle);\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(this);\r
+                string autoPath = Main.AutoName(this);\r
                 if (autoPath != null)\r
                     text_destination.Text = autoPath;\r
                 else\r
@@ -963,7 +990,7 @@ namespace Handbrake
             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
@@ -981,6 +1008,9 @@ namespace Handbrake
         }\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
             Control ctl = (Control)sender;\r
             int chapterStart, chapterEnd;\r
             int.TryParse(drop_chapterStart.Text, out chapterStart);\r
@@ -1024,11 +1054,11 @@ namespace Handbrake
             }\r
 \r
             // Update the Duration\r
-            lbl_duration.Text = Main.calculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle).ToString();\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(this);\r
+                text_destination.Text = Main.AutoName(this);\r
 \r
             // Disable chapter markers if only 1 chapter is selected.\r
             if (chapterStart == chapterEnd)\r
@@ -1047,6 +1077,74 @@ namespace Handbrake
                 }\r
             }\r
         }\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
+            switch (drop_mode.SelectedIndex)\r
+            {\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
+                    return;\r
+            }\r
+        }\r
+        private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)\r
+        {\r
+            // Reset\r
+            this.drop_chapterFinish.TextChanged -= new System.EventHandler(this.SecondsOrFramesChanged);\r
+            this.drop_chapterStart.TextChanged -= new System.EventHandler(this.SecondsOrFramesChanged);\r
+\r
+            // Do Work\r
+            switch (drop_mode.SelectedIndex)\r
+            {\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 System.EventHandler(this.SecondsOrFramesChanged);\r
+                    this.drop_chapterFinish.TextChanged += new System.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 System.EventHandler(this.SecondsOrFramesChanged);\r
+                    this.drop_chapterFinish.TextChanged += new System.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
+        }\r
 \r
         //Destination\r
         private void btn_destBrowse_Click(object sender, EventArgs e)\r
@@ -1066,34 +1164,29 @@ 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 = 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 (!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
+                    case 1:\r
+                        if (!Path.GetExtension(DVD_Save.FileName).Equals(".mp4", 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 (!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
         private void text_destination_TextChanged(object sender, EventArgs e)\r
@@ -1122,7 +1215,7 @@ namespace Handbrake
             }\r
 \r
             AudioSettings.SetContainer(drop_format.Text);\r
-            Subtitles.setContainer(drop_format.SelectedIndex);\r
+            Subtitles.SetContainer(drop_format.SelectedIndex);\r
 \r
             if (drop_format.Text.Contains("MP4"))\r
             {\r
@@ -1169,7 +1262,7 @@ namespace Handbrake
                 check_turbo.CheckState = CheckState.Unchecked;\r
                 check_turbo.Enabled = false;\r
                 tab_advanced.Enabled = false;\r
-                x264Panel.x264Query = "";\r
+                x264Panel.X264Query = "";\r
                 check_iPodAtom.Enabled = false;\r
                 check_iPodAtom.Checked = false;\r
             }\r
@@ -1294,24 +1387,15 @@ namespace Handbrake
             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).ToString(new CultureInfo("en-US")) + "% 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 * cqStep;\r
-                    max = slider_videoQuality.Maximum * cqStep;\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).ToString(new CultureInfo("en-US")) + "% RF:" + rfValue.ToString(new CultureInfo("en-US"));\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).ToString(new CultureInfo("en-US")) + "% QP:" + slider_videoQuality.Value;\r
+                    lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;\r
                     break;\r
             }\r
         }\r
@@ -1377,7 +1461,7 @@ namespace Handbrake
             if (File_ChapterImport.ShowDialog() == DialogResult.OK)\r
             {\r
                 String filename = File_ChapterImport.FileName;\r
-                DataGridView imported = Main.importChapterNames(data_chpt, filename);\r
+                DataGridView imported = Main.ImportChapterNames(data_chpt, filename);\r
                 if (imported != null)\r
                     data_chpt = imported;\r
             }\r
@@ -1385,7 +1469,7 @@ namespace Handbrake
         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
+            DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);\r
             if (chapterGridView != null)\r
             {\r
                 data_chpt = chapterGridView;\r
@@ -1395,7 +1479,7 @@ namespace Handbrake
         // Query Editor Tab\r
         private void btn_generate_Query_Click(object sender, EventArgs e)\r
         {\r
-            rtf_query.Text = queryGen.GenerateCLIQuery(this, 0, null);\r
+            rtf_query.Text = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
         }\r
         private void btn_clear_Click(object sender, EventArgs e)\r
         {\r
@@ -1407,8 +1491,9 @@ namespace Handbrake
 \r
         #region Source Scan\r
         public Boolean isScanning { get; set; }\r
-        private static int scanProcessID { get; set; }\r
-        private void startScan(String filename)\r
+        private Scan SourceScan;\r
+\r
+        private void StartScan(String filename, int title)\r
         {\r
             // Setup the GUI components for the scan.\r
             sourcePath = filename;\r
@@ -1425,91 +1510,65 @@ namespace Handbrake
             tb_preview.Enabled = false;\r
             mnu_killCLI.Visible = true;\r
 \r
-            // Start hte Scan Thread\r
+            if (ActivityWindow != null)\r
+                ActivityWindow.SetScanMode();\r
+\r
+            // Start the Scan\r
             try\r
             {\r
-                if (ActivityWindow != null)\r
-                    ActivityWindow.SetLogView(true);\r
                 isScanning = true;\r
-                ThreadPool.QueueUserWorkItem(scanProcess);\r
+                SourceScan = new Scan();\r
+                SourceScan.ScanSource(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 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, sourcePath, 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
-                        throw new Exception("Unable to retrieve the DVD Info. last_scan_log.txt is missing. \nExpected location of last_scan_log.txt: \n"\r
-                                            + dvdInfoPath);\r
 \r
-                    using (StreamReader sr = new StreamReader(dvdInfoPath))\r
-                    {\r
-                        thisDVD = DVD.Parse(sr);\r
-                        sr.Close();\r
-                        sr.Dispose();\r
-                    }\r
+        void SourceScan_ScanStatusChanged(object sender, EventArgs e)\r
+        {\r
+            UpdateScanStatusLabel();\r
+        }\r
+        void SourceScan_ScanCompleted(object sender, EventArgs e)\r
+        {\r
+            UpdateGuiAfterScan();\r
+        }\r
 \r
-                    updateUIafterScan();\r
-                }\r
-            }\r
-            catch (Exception exc)\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
+        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
+                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
+                if (currentSource.Titles.Count != 0)\r
+                    drp_dvdtitle.SelectedItem = Main.SelectLongestTitle(currentSource);\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
+                if (sourcePath.ToLower().Contains(".iso") || sourcePath.Contains("VIDEO_TS") || Directory.Exists(Path.Combine(sourcePath, "VIDEO_TS")))\r
                     Check_ChapterMarkers.Enabled = true;\r
                 else\r
                 {\r
@@ -1529,20 +1588,21 @@ namespace Handbrake
                 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
+                EnableGUI();\r
             }\r
         }\r
-        private void enableGUI()\r
+\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
                 foreach (Control ctrl in Controls)\r
                     ctrl.Enabled = true;\r
@@ -1555,33 +1615,28 @@ 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
+        private void KillScan()\r
         {\r
             try\r
             {\r
-                enableGUI();\r
-                resetGUI();\r
+                SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+                EnableGUI();\r
+                ResetGUI();\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
+                if (SourceScan.ScanProcess() != null)\r
+                    SourceScan.ScanProcess().Kill();\r
+\r
+                lbl_encode.Text = "Scan Cancelled!";\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
         }\r
-        private void resetGUI()\r
+        private void ResetGUI()\r
         {\r
             drp_dvdtitle.Items.Clear();\r
             drop_chapterStart.Items.Clear();\r
@@ -1591,27 +1646,58 @@ namespace Handbrake
             PictureSettings.lbl_Aspect.Text = "Select a Title";\r
             sourcePath = String.Empty;\r
             text_destination.Text = String.Empty;\r
-            thisDVD = null;\r
             selectedTitle = null;\r
             isScanning = false;\r
         }\r
         private void UpdateSourceLabel()\r
         {\r
             labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;\r
+\r
+            if (selectedTitle != null)\r
+                if (!string.IsNullOrEmpty(selectedTitle.SourceName)) // 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
+        public void RecievingJob(Job job)\r
+        {\r
+            string query = job.Query;\r
+            StartScan(job.Source, 0);\r
+\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
         /// <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
@@ -1637,13 +1723,13 @@ 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
@@ -1658,51 +1744,42 @@ namespace Handbrake
                 MessageBox.Show(exc.ToString());\r
             }\r
         }\r
-        #endregion\r
 \r
-        #region DVD Drive Detection\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 UpdateWindowHandler(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
+                List<DriveInformation> drives = Main.GetDrives();\r
+\r
+                if (drives.Count == 0)\r
                 {\r
-                    if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady)\r
-                    {\r
-                        if (File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))\r
-                        {\r
-                            this.dvdDrivePath = curDrive.RootDirectory + "VIDEO_TS";\r
-                            this.dvdDriveLabel = curDrive.VolumeLabel;\r
-                            mnu_dvd_drive.Text = this.dvdDrivePath + " (" + this.dvdDriveLabel + ")";\r
-                            foundDrive = true;\r
-                            break;\r
-                        }\r
-                    }\r
+                    mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
+                    return;\r
                 }\r
 \r
-                if (foundDrive == false)\r
-                    mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
+                this.dvdDrivePath = drives[0].RootDirectory + "VIDEO_TS";\r
+                this.dvdDriveLabel = drives[0].VolumeLabel;\r
+                mnu_dvd_drive.Text = this.dvdDrivePath + " (" + this.dvdDriveLabel + ")";\r
             }\r
             catch (Exception)\r
             {\r
                 mnu_dvd_drive.Text = "[No DVD Drive Ready / Found]";\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 (!Properties.Settings.Default.presetNotification)\r
@@ -1716,6 +1793,29 @@ namespace Handbrake
         #endregion\r
 \r
         #region Overrides\r
+\r
+        /// <summary>\r
+        /// Handle GUI shortcuts\r
+        /// </summary>\r
+        /// <param name="msg"></param>\r
+        /// <param name="keyData"></param>\r
+        /// <returns></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
@@ -1723,7 +1823,7 @@ namespace Handbrake
         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) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0))\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
@@ -1735,12 +1835,15 @@ namespace Handbrake
         #endregion\r
 \r
         #region In-GUI Encode Status (Experimental)\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
                     encode.readEncodeStatus();\r
             }\r
@@ -1749,11 +1852,22 @@ namespace Handbrake
                 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"></param>\r
+        /// <param name="CurrentTask"></param>\r
+        /// <param name="TaskCount"></param>\r
+        /// <param name="PercentComplete"></param>\r
+        /// <param name="CurrentFps"></param>\r
+        /// <param name="AverageFps"></param>\r
+        /// <param name="TimeRemaining"></param>\r
+        private void EncodeOnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
         {\r
             if (this.InvokeRequired)\r
             {\r
-                this.BeginInvoke(new EncodeProgressEventHandler(encodeOnEncodeProgress),\r
+                this.BeginInvoke(new EncodeProgressEventHandler(EncodeOnEncodeProgress),\r
                     new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
                 return;\r
             }\r
@@ -1761,16 +1875,6 @@ namespace Handbrake
         }\r
         #endregion\r
 \r
-        #region enum\r
-        private enum SourceType\r
-        {\r
-            None = 0,\r
-            Folder,\r
-            DvdDrive,\r
-            VideoFile\r
-        }\r
-        #endregion\r
-\r
         // This is the END of the road ****************************************\r
     }\r
 }
\ No newline at end of file