OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index 1a7590b..91ed404 100644 (file)
@@ -35,7 +35,7 @@ namespace Handbrake
         // Windows ************************************************************\r
         private frmQueue queueWindow;\r
         private frmPreview qtpreview;\r
-        private frmActivityWindow ActivityWindow;\r
+        private frmActivityWindow activityWindow;\r
         private frmSplashScreen splash = new frmSplashScreen();\r
 \r
         // Globals: Mainly used for tracking. *********************************\r
@@ -44,7 +44,7 @@ namespace Handbrake
         private SourceType selectedSourceType;\r
         private string dvdDrivePath;\r
         private string dvdDriveLabel;\r
-        private Preset CurrentlySelectedPreset;\r
+        private Preset currentlySelectedPreset;\r
         private DVD currentSource;\r
         private IScan SourceScan = new ScanService();\r
         private List<DriveInformation> drives;\r
@@ -152,8 +152,7 @@ namespace Handbrake
                     x264Panel.Reset2Defaults();\r
 \r
                     QueryParser presetQuery = QueryParser.Parse(query);\r
-                    PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset,\r
-                                            presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).PictureSettings);\r
+                    PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset);\r
 \r
                     x264Panel.StandardizeOptString();\r
                     x264Panel.SetCurrentSettingsInPanel();\r
@@ -176,7 +175,7 @@ namespace Handbrake
             queueRecovery();\r
 \r
             // If have a file passed in via command arguemtents, check it's a file and try scanning it.\r
-            if (args.Length >= 1 && File.Exists(args[0]))\r
+            if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0])))\r
             {\r
                 this.StartScan(args[0], 0);\r
             }\r
@@ -212,21 +211,37 @@ namespace Handbrake
         // Startup Functions   \r
         private void queueRecovery()\r
         {\r
-            if (Main.CheckQueueRecovery())\r
+            DialogResult result = DialogResult.None;\r
+            List<string> queueFiles = Main.CheckQueueRecovery();\r
+            if (queueFiles.Count == 1)\r
             {\r
-                DialogResult result =\r
-                    MessageBox.Show(\r
+                result = 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
+            else if (queueFiles.Count > 1)\r
+            {\r
+                result = MessageBox.Show(\r
+                        "HandBrake has detected multiple unfinished queue files. These will be from multiple instances of HandBrake running. Would you like to recover all unfinished jobs?",\r
+                        "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+            }\r
 \r
-                if (result == DialogResult.Yes)\r
-                    encodeQueue.LoadQueueFromFile("hb_queue_recovery.xml"); // Start Recovery\r
-                else\r
+            if (result == DialogResult.Yes)\r
+            {\r
+                foreach (string file in queueFiles)\r
+                {\r
+                    encodeQueue.LoadQueueFromFile(file); // Start Recovery\r
+                }\r
+            }\r
+            else\r
+            {\r
+                if (Main.IsMultiInstance) return; // Don't tamper with the files if we are multi instance\r
+\r
+                string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");\r
+                foreach (string file in queueFiles)\r
                 {\r
-                    // Remove the Queue recovery file if the user doesn't want to recovery the last queue.\r
-                    string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");\r
-                    if (File.Exists(queuePath))\r
-                        File.Delete(queuePath);\r
+                    if (File.Exists(Path.Combine(tempPath, file)))\r
+                        File.Delete(Path.Combine(tempPath, file));\r
                 }\r
             }\r
         }\r
@@ -322,7 +337,7 @@ namespace Handbrake
         private void changePresetLabel(object sender, EventArgs e)\r
         {\r
             labelPreset.Text = "Output Settings (Preset: Custom)";\r
-            CurrentlySelectedPreset = null;\r
+            this.currentlySelectedPreset = null;\r
         }\r
 \r
         private static void frmMain_DragEnter(object sender, DragEventArgs e)\r
@@ -538,9 +553,13 @@ namespace Handbrake
         /// </param>\r
         private void btn_new_preset_Click(object sender, EventArgs e)\r
         {\r
-            Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
-                                           presetHandler);\r
-            preset.ShowDialog();\r
+            Form preset = new frmAddPreset(this, presetHandler);\r
+            if (preset.ShowDialog() == DialogResult.OK)\r
+            {\r
+                TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };\r
+                treeView_presets.Nodes.Add(presetTreeview);\r
+                presetHandler.LastPresetAdded = null;\r
+            }\r
         }\r
 \r
         #endregion\r
@@ -650,6 +669,7 @@ namespace Handbrake
         /// </param>\r
         private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
         {\r
+            // TODO this requires a re-think since the Query Editor has changed.\r
             DialogResult result =\r
                 MessageBox.Show(\r
                     "Do you wish to include picture settings when updating the preset: " +\r
@@ -657,10 +677,10 @@ namespace Handbrake
                     MessageBoxIcon.Question);\r
             if (result == DialogResult.Yes)\r
                 presetHandler.Update(treeView_presets.SelectedNode.Text,\r
-                                     QueryGenerator.GenerateTabbedComponentsQuery(this), true);\r
+                                     QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);\r
             else if (result == DialogResult.No)\r
                 presetHandler.Update(treeView_presets.SelectedNode.Text,\r
-                                     QueryGenerator.GenerateTabbedComponentsQuery(this), false);\r
+                                     QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);\r
         }\r
 \r
         /// <summary>\r
@@ -717,8 +737,13 @@ namespace Handbrake
         /// </param>\r
         private void btn_addPreset_Click(object sender, EventArgs e)\r
         {\r
-            Form preset = new frmAddPreset(this, QueryGenerator.GenerateTabbedComponentsQuery(this), presetHandler);\r
-            preset.ShowDialog();\r
+            Form preset = new frmAddPreset(this, presetHandler);\r
+            if (preset.ShowDialog() == DialogResult.OK)\r
+            {\r
+                TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };\r
+                treeView_presets.Nodes.Add(presetTreeview);\r
+                presetHandler.LastPresetAdded = null;\r
+            }\r
         }\r
 \r
         /// <summary>\r
@@ -864,7 +889,6 @@ namespace Handbrake
                 if (preset != null)\r
                 {\r
                     string query = presetHandler.GetPreset(presetName).Query;\r
-                    bool loadPictureSettings = presetHandler.GetPreset(presetName).PictureSettings;\r
 \r
                     if (query != null)\r
                     {\r
@@ -875,14 +899,14 @@ namespace Handbrake
                         QueryParser presetQuery = QueryParser.Parse(query);\r
 \r
                         // Now load the preset\r
-                        PresetLoader.LoadPreset(this, presetQuery, presetName, loadPictureSettings);\r
+                        PresetLoader.LoadPreset(this, presetQuery, presetName);\r
 \r
                         // The x264 widgets will need updated, so do this now:\r
                         x264Panel.StandardizeOptString();\r
                         x264Panel.SetCurrentSettingsInPanel();\r
 \r
                         // Finally, let this window have a copy of the preset settings.\r
-                        CurrentlySelectedPreset = preset;\r
+                        this.currentlySelectedPreset = preset;\r
                         PictureSettings.SetPresetCropWarningLabel(preset);\r
                     }\r
                 }\r
@@ -920,17 +944,17 @@ namespace Handbrake
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
                     if (result == DialogResult.Yes)\r
                     {\r
-                        PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
+                        PresetLoader.LoadPreset(this, parsed, parsed.PresetName);\r
                         presetHandler.Update(parsed.PresetName + " (Imported)",\r
-                                             QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+                                             QueryGenerator.GenerateFullQuery(this),\r
                                              parsed.UsesPictureSettings);\r
                     }\r
                 }\r
                 else\r
                 {\r
-                    PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
+                    PresetLoader.LoadPreset(this, parsed, parsed.PresetName);\r
                     if (presetHandler.Add(parsed.PresetName + " (Imported)",\r
-                                          QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+                                          QueryGenerator.GenerateFullQuery(this),\r
                                           parsed.UsesPictureSettings))\r
                     {\r
                         TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")\r
@@ -1014,45 +1038,41 @@ namespace Handbrake
         {\r
             if (btn_start.Text == "Stop")\r
             {\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
+                DialogResult result = !Properties.Settings.Default.showCliForInGuiEncodeStatus\r
+                             ? MessageBox.Show(\r
+                                 "Are you sure you wish to cancel the encode?\n\nPlease note: Stopping this encode will render the file unplayable. ",\r
+                                 "Cancel Encode?",\r
+                                 MessageBoxButtons.YesNo,\r
+                                 MessageBoxIcon.Question)\r
+                             : MessageBox.Show(\r
+                                 "Are you sure you wish to cancel the encode?",\r
+                                 "Cancel Encode?",\r
+                                 MessageBoxButtons.YesNo,\r
+                                 MessageBoxIcon.Question);\r
 \r
                 if (result == DialogResult.Yes)\r
                 {\r
                     // Pause The Queue\r
                     encodeQueue.Pause();\r
 \r
-                    if (Properties.Settings.Default.enocdeStatusInGui &&\r
-                        !Properties.Settings.Default.showCliForInGuiEncodeStatus)\r
-                    {\r
-                        encodeQueue.Stop();\r
-                    }\r
-                    else\r
-                    {\r
+                    if (Settings.Default.showCliForInGuiEncodeStatus)\r
                         encodeQueue.SafelyClose();\r
-                    }\r
+                    else\r
+                        encodeQueue.Stop();\r
                 }\r
             }\r
             else\r
             {\r
-                if (encodeQueue.Count != 0 ||\r
-                    (!string.IsNullOrEmpty(sourcePath) && !string.IsNullOrEmpty(text_destination.Text)))\r
+                // If we have a custom query, then we'll want to figure out what the new source and destination is, otherwise we'll just use the gui components.\r
+                string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;\r
+                string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;\r
+\r
+                if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))\r
                 {\r
-                    string generatedQuery = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+                    string generatedQuery = QueryGenerator.GenerateFullQuery(this);\r
                     string specifiedQuery = rtf_query.Text != string.Empty\r
                                                 ? rtf_query.Text\r
-                                                : QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+                                                : QueryGenerator.GenerateFullQuery(this);\r
                     string query = string.Empty;\r
 \r
                     // Check to make sure the generated query matches the GUI settings\r
@@ -1091,17 +1111,19 @@ namespace Handbrake
                     }\r
 \r
                     DialogResult overwrite = DialogResult.Yes;\r
-                    if (text_destination.Text != string.Empty)\r
-                        if (File.Exists(text_destination.Text))\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
+                    if (!string.IsNullOrEmpty(jobDestination) && File.Exists(jobDestination))\r
+                    {\r
+                        overwrite = MessageBox.Show(\r
+                                "The destination file already exists. Are you sure you want to overwrite it?",\r
+                                "Overwrite File?",\r
+                                MessageBoxButtons.YesNo,\r
+                                MessageBoxIcon.Question);\r
+                    }\r
 \r
                     if (overwrite == DialogResult.Yes)\r
                     {\r
                         if (encodeQueue.Count == 0)\r
-                            encodeQueue.Add(query, this.GetTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+                            encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
 \r
                         queueWindow.SetQueue();\r
                         if (encodeQueue.Count > 1)\r
@@ -1130,36 +1152,46 @@ namespace Handbrake
         /// </param>\r
         private void btn_add2Queue_Click(object sender, EventArgs e)\r
         {\r
-            if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
+            // Get the CLI query or use the query editor if it's not empty.\r
+            string query = QueryGenerator.GenerateFullQuery(this);\r
+            if (!string.IsNullOrEmpty(rtf_query.Text))\r
+                query = rtf_query.Text;\r
+\r
+            // If we have a custom query, then we'll want to figure out what the new source and destination is, otherwise we'll just use the gui components.\r
+            string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;\r
+            string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;\r
+\r
+            // Make sure we have a Source and Destination.\r
+            if (string.IsNullOrEmpty(jobSourcePath) || string.IsNullOrEmpty(jobDestination))\r
+            {\r
                 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-            else\r
+                return;\r
+            }\r
+\r
+            // Make sure the destination path exists.\r
+            if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))\r
             {\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
+                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
+            // Make sure we don't have a duplciate on the queue.\r
+            if (encodeQueue.CheckForDestinationDuplicate(jobDestination))\r
+            {\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.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
+            }\r
+            else\r
+                encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
 \r
-                if (encodeQueue.CheckForDestinationDuplicate(text_destination.Text))\r
-                {\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.Add(query, this.GetTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
-                }\r
-                else\r
-                    encodeQueue.Add(query, this.GetTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+            lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
 \r
-                lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
+            queueWindow.Show();\r
 \r
-                queueWindow.Show();\r
-            }\r
         }\r
 \r
         /// <summary>\r
@@ -1220,11 +1252,11 @@ namespace Handbrake
         /// </param>\r
         private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
         {\r
-            if (ActivityWindow == null || !ActivityWindow.IsHandleCreated)\r
-                ActivityWindow = new frmActivityWindow(encodeQueue, SourceScan);\r
+            if (this.activityWindow == null || !this.activityWindow.IsHandleCreated)\r
+                this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan);\r
 \r
-            ActivityWindow.Show();\r
-            ActivityWindow.Activate();\r
+            this.activityWindow.Show();\r
+            this.activityWindow.Activate();\r
         }\r
 \r
         #endregion\r
@@ -1369,7 +1401,7 @@ namespace Handbrake
             {\r
                 selectedTitle = drp_dvdtitle.SelectedItem as Title;\r
                 lbl_duration.Text = selectedTitle.Duration.ToString();\r
-                PictureSettings.CurrentlySelectedPreset = CurrentlySelectedPreset;\r
+                PictureSettings.CurrentlySelectedPreset = this.currentlySelectedPreset;\r
                 PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control\r
 \r
                 // Populate the Angles dropdown\r
@@ -1404,7 +1436,7 @@ 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, CurrentlySelectedPreset);\r
+                AudioSettings.SetTrackList(selectedTitle, this.currentlySelectedPreset);\r
 \r
                 // Populate the Subtitles dropdown\r
                 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());\r
@@ -1765,7 +1797,7 @@ namespace Handbrake
             {\r
                 this.checkMaximumFramerate.Visible = false;\r
                 this.checkMaximumFramerate.CheckState = CheckState.Unchecked;\r
-            } \r
+            }\r
             else\r
             {\r
                 this.checkMaximumFramerate.Visible = true;\r
@@ -1941,7 +1973,7 @@ namespace Handbrake
         // Query Editor Tab\r
         private void btn_generate_Query_Click(object sender, EventArgs e)\r
         {\r
-            rtf_query.Text = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+            rtf_query.Text = QueryGenerator.GenerateFullQuery(this);\r
         }\r
 \r
         private void btn_clear_Click(object sender, EventArgs e)\r
@@ -2200,14 +2232,14 @@ namespace Handbrake
                 QueryParser presetQuery = QueryParser.Parse(query);\r
 \r
                 // Now load the preset\r
-                PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue", true);\r
+                PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue");\r
 \r
                 // The x264 widgets will need updated, so do this now:\r
                 x264Panel.StandardizeOptString();\r
                 x264Panel.SetCurrentSettingsInPanel();\r
 \r
                 // Finally, let this window have a copy of the preset settings.\r
-                CurrentlySelectedPreset = null;\r
+                this.currentlySelectedPreset = null;\r
                 PictureSettings.SetPresetCropWarningLabel(null);\r
             }\r
         }\r
@@ -2460,7 +2492,7 @@ namespace Handbrake
                 }\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
+                if (!Settings.Default.showCliForInGuiEncodeStatus)\r
                     encodeQueue.Stop();\r
                 else\r
                     encodeQueue.SafelyClose();\r