OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.cs
index 1fb52db..bfa4054 100644 (file)
@@ -1,8 +1,7 @@
 /*  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
+    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
@@ -13,6 +12,7 @@ namespace Handbrake
     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
@@ -62,11 +62,18 @@ namespace Handbrake
             InitializeComponent();\r
 \r
             // Update the users config file with the CLI version data.\r
-            lblStatus.Text = "Setting Version Data ...";\r
+            lblStatus.Text = "Checking CLI Version Data ...";\r
             Application.DoEvents();\r
             Main.SetCliVersionData();\r
+            Main.CheckForValidCliVersion();\r
 \r
-            // Show the form, but leave disabled until preloading is complete then show the main form\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
             this.Enabled = false;\r
             this.Show();\r
             Application.DoEvents(); // Forces frmMain to draw\r
@@ -857,7 +864,7 @@ namespace Handbrake
                     if (overwrite == DialogResult.Yes)\r
                     {\r
                         if (encodeQueue.Count == 0)\r
-                            encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+                            encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
 \r
                         queueWindow.SetQueue();\r
                         if (encodeQueue.Count > 1)\r
@@ -896,10 +903,10 @@ namespace Handbrake
                             "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, sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
+                        encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
                 }\r
                 else\r
-                    encodeQueue.Add(query, sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\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
@@ -987,6 +994,8 @@ namespace Handbrake
             this.Activate();\r
             this.WindowState = FormWindowState.Normal;\r
             notifyIcon.Visible = false;\r
+\r
+            this.StartScan(null, 2);\r
         }\r
 \r
         #endregion\r
@@ -1324,8 +1333,7 @@ namespace Handbrake
                         break;\r
                     case 2:\r
                         if (\r
-                            !Path.GetExtension(DVD_Save.FileName).Equals(".mkv",\r
-                                                                         StringComparison.InvariantCultureIgnoreCase))\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
@@ -1439,24 +1447,8 @@ namespace Handbrake
                     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.2":\r
-                            slider_videoQuality.Maximum = 255;\r
-                            break;\r
-                        case "0.25":\r
-                            slider_videoQuality.Maximum = 204;\r
-                            break;\r
-                        case "0.5":\r
-                            slider_videoQuality.Maximum = 102;\r
-                            break;\r
-                        case "1":\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
@@ -1504,24 +1496,7 @@ namespace Handbrake
             double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
 \r
             // Change the maximum value for the slider\r
-            switch (Properties.Settings.Default.x264cqstep.ToString(new CultureInfo("en-US")))\r
-            {\r
-                case "0.2":\r
-                    slider_videoQuality.Maximum = 255;\r
-                    break;\r
-                case "0.25":\r
-                    slider_videoQuality.Maximum = 204;\r
-                    break;\r
-                case "0.5":\r
-                    slider_videoQuality.Maximum = 102;\r
-                    break;\r
-                case "1":\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
             // Reset the CQ slider to RF0\r
             slider_videoQuality.Value = slider_videoQuality.Maximum;\r
@@ -1630,6 +1605,19 @@ namespace Handbrake
             }\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
@@ -1663,18 +1651,8 @@ namespace Handbrake
         {\r
             // Setup the GUI components for the scan.\r
             sourcePath = filename;\r
-            foreach (Control ctrl in Controls)\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
-            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
+            this.DisableGUI();\r
 \r
             if (ActivityWindow != null)\r
                 ActivityWindow.SetMode(ActivityLogMode.Scan);\r
@@ -1731,13 +1709,24 @@ namespace Handbrake
                 if (currentSource.Titles.Count != 0)\r
                     drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());\r
 \r
-                // Now select the longest title\r
-                if (currentSource.Titles.Count != 0)\r
-                    drp_dvdtitle.SelectedItem = Main.SelectLongestTitle(currentSource);\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
-                    Directory.Exists(Path.Combine(sourcePath, "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
@@ -1789,25 +1778,31 @@ namespace Handbrake
             }\r
         }\r
 \r
+        private void DisableGUI()\r
+        {\r
+            foreach (Control ctrl in Controls)\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
+            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
+\r
         private void KillScan()\r
         {\r
-            try\r
-            {\r
-                SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
-                EnableGUI();\r
-                ResetGUI();\r
+            SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+            EnableGUI();\r
+            ResetGUI();\r
 \r
-                if (SourceScan.ScanProcess() != null)\r
-                    SourceScan.ScanProcess().Kill();\r
+            SourceScan.KillScan();\r
 \r
-                lbl_encode.Text = "Scan Cancelled!";\r
-            }\r
-            catch (Exception ex)\r
-            {\r
-                MessageBox.Show(\r
-                    "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" +\r
-                    ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-            }\r
+            lbl_encode.Text = "Scan Cancelled!";\r
         }\r
 \r
         private void ResetGUI()\r
@@ -1836,8 +1831,7 @@ namespace Handbrake
         public void RecievingJob(Job job)\r
         {\r
             string query = job.Query;\r
-            StartScan(job.Source, 0);\r
-\r
+            StartScan(job.Source, job.Title);\r
 \r
             if (query != null)\r
             {\r
@@ -1971,6 +1965,24 @@ namespace Handbrake
             treeView_presets.Update();\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
         #endregion\r
 \r
         #region Overrides\r
@@ -1978,9 +1990,9 @@ namespace Handbrake
         /// <summary>\r
         /// Handle GUI shortcuts\r
         /// </summary>\r
-        /// <param name="msg"></param>\r
-        /// <param name="keyData"></param>\r
-        /// <returns></returns>\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
@@ -2000,18 +2012,31 @@ namespace Handbrake
         /// <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 =\r
                     MessageBox.Show(\r
-                        "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
+                        "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.KillScan();\r
             }\r
             base.OnFormClosing(e);\r
         }\r
@@ -2048,26 +2073,22 @@ namespace Handbrake
         /// <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,\r
-                                            float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\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
-                                 new[]\r
-                                     {\r
-                                         Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, \r
-                                         TimeRemaining\r
-                                     });\r
+                this.BeginInvoke(\r
+                    new EncodeProgressEventHandler(EncodeOnEncodeProgress),\r
+                    new[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
                 return;\r
             }\r
             lbl_encode.Text =\r
-                string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ",\r
-                              PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
+                string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
         }\r
 \r
         #endregion\r
 \r
+\r
         // This is the END of the road ****************************************\r
     }\r
 }
\ No newline at end of file