OSDN Git Service

CLI: update the built in presets
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmQueue.cs
index b6d1904..2684772 100644 (file)
@@ -9,10 +9,15 @@ namespace Handbrake
     using System.Collections.Generic;\r
     using System.Collections.ObjectModel;\r
     using System.ComponentModel;\r
+    using System.IO;\r
     using System.Windows.Forms;\r
     using Functions;\r
+\r
+    using HandBrake.ApplicationServices.Model;\r
+    using HandBrake.ApplicationServices.Services;\r
+    using HandBrake.ApplicationServices.Services.Interfaces;\r
+\r
     using Model;\r
-    using Services;\r
 \r
     /// <summary>\r
     /// The Queue Window\r
@@ -27,7 +32,7 @@ namespace Handbrake
         /// <summary>\r
         /// An instance of the Queue service\r
         /// </summary>\r
-        private readonly Queue queue;\r
+        private readonly IQueue queue;\r
 \r
         /// <summary>\r
         /// A reference to the main application window\r
@@ -43,7 +48,7 @@ namespace Handbrake
         /// <param name="mw">\r
         /// The main window.\r
         /// </param>\r
-        public frmQueue(Queue q, frmMain mw)\r
+        public frmQueue(IQueue q, frmMain mw)\r
         {\r
             InitializeComponent();\r
 \r
@@ -53,6 +58,82 @@ namespace Handbrake
             queue.EncodeStarted += new EventHandler(QueueOnEncodeStart);\r
             queue.QueueCompleted += new EventHandler(QueueOnQueueFinished);\r
             queue.QueuePauseRequested += new EventHandler(QueueOnPaused);\r
+            queue.QueueListChanged += new EventHandler(queue_QueueListChanged);\r
+\r
+            queue.EncodeStarted += new EventHandler(queue_EncodeStarted);\r
+            queue.EncodeEnded += new EventHandler(queue_EncodeEnded);\r
+\r
+            drp_completeOption.Text = Properties.Settings.Default.CompletionOption;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Queue Changed\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void queue_QueueListChanged(object sender, EventArgs e)\r
+        {\r
+            UpdateUiElementsOnQueueChange();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Encode Ended\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void queue_EncodeEnded(object sender, EventArgs e)\r
+        {\r
+            queue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;\r
+            ResetEncodeText();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Queue Started\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void queue_EncodeStarted(object sender, EventArgs e)\r
+        {\r
+            this.SetCurrentEncodeInformation();\r
+            queue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;        \r
+        }\r
+\r
+        /// <summary>\r
+        /// Display the Encode Status\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The e.\r
+        /// </param>\r
+        private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)\r
+        {\r
+            if (this.InvokeRequired)\r
+            {\r
+                this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });\r
+                return;\r
+            }\r
+\r
+            lbl_encodeStatus.Text =\r
+                string.Format(\r
+                "Encoding: Pass {0} of {1}, {2:00.00}% Time Remaining: {3}",\r
+                e.Task,\r
+                e.TaskCount,\r
+                e.PercentComplete,\r
+                e.EstimatedTimeLeft);\r
         }\r
 \r
         /// <summary>\r
@@ -67,7 +148,7 @@ namespace Handbrake
         private void QueueOnPaused(object sender, EventArgs e)\r
         {\r
             SetUiEncodeFinished();\r
-            UpdateUiElements();\r
+            UpdateUiElementsOnQueueChange();\r
         }\r
 \r
         /// <summary>\r
@@ -97,8 +178,7 @@ namespace Handbrake
         private void QueueOnEncodeStart(object sender, EventArgs e)\r
         {\r
             SetUiEncodeStarted(); // make sure the UI is set correctly\r
-            SetCurrentEncodeInformation();\r
-            UpdateUiElements(); // Redraw the Queue, a new encode has started.\r
+            UpdateUiElementsOnQueueChange(); // Redraw the Queue, a new encode has started.\r
         }\r
 \r
         /// <summary>\r
@@ -106,7 +186,7 @@ namespace Handbrake
         /// </summary>\r
         public void SetQueue()\r
         {\r
-            UpdateUiElements();\r
+            UpdateUiElementsOnQueueChange();\r
         }\r
 \r
         /// <summary>\r
@@ -125,8 +205,6 @@ namespace Handbrake
         {\r
             if (doSetQueue) SetQueue();\r
             base.Show();\r
-\r
-            // Activate();\r
         }\r
 \r
         /// <summary>\r
@@ -136,14 +214,13 @@ namespace Handbrake
         /// <param name="e">the EventArgs</param>\r
         private void BtnEncodeClick(object sender, EventArgs e)\r
         {\r
-            if (queue.PauseRequested)\r
+            if (queue.Paused)\r
             {\r
                 SetUiEncodeStarted();\r
-                MessageBox.Show("Encoding restarted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
             }\r
 \r
-            if (!queue.IsEncoding)\r
-                queue.Start();\r
+            lbl_encodeStatus.Text = "Encoding ...";\r
+            queue.Start();\r
         }\r
 \r
         /// <summary>\r
@@ -158,8 +235,6 @@ namespace Handbrake
         private void BtnPauseClick(object sender, EventArgs e)\r
         {\r
             queue.Pause();\r
-            SetUiEncodeFinished();\r
-            ResetQueue();\r
             MessageBox.Show(\r
                 "No further items on the queue will start. The current encode process will continue until it is finished. \nClick 'Encode' when you wish to continue encoding the queue.",\r
                 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
@@ -208,12 +283,24 @@ namespace Handbrake
             btn_pause.Visible = false;\r
             btn_encode.Enabled = true;\r
 \r
+            ResetEncodeText();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Reset the current job text\r
+        /// </summary>\r
+        private void ResetEncodeText()\r
+        {\r
+            if (InvokeRequired)\r
+            {\r
+                BeginInvoke(new UpdateHandler(ResetEncodeText));\r
+                return;\r
+            }\r
+            lbl_encodeStatus.Text = "Ready";\r
+\r
             lbl_source.Text = "-";\r
             lbl_dest.Text = "-";\r
-            lbl_vEnc.Text = "-";\r
-            lbl_aEnc.Text = "-";\r
-            lbl_title.Text = "-";\r
-            lbl_chapt.Text = "-";\r
+            lbl_encodeOptions.Text = "-";\r
 \r
             lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";\r
         }\r
@@ -237,17 +324,17 @@ namespace Handbrake
                 QueryParser parsed = Functions.QueryParser.Parse(qItem);\r
 \r
                 // Get the DVD Title\r
-                string title = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();\r
+                string title = parsed.Title == 0 ? "Auto" : parsed.Title.ToString();\r
 \r
                 // Get the DVD Chapters\r
                 string chapters;\r
-                if (parsed.DVDChapterStart == 0)\r
+                if (parsed.ChapterStart == 0)\r
                     chapters = "Auto";\r
                 else\r
                 {\r
-                    chapters = parsed.DVDChapterStart.ToString();\r
-                    if (parsed.DVDChapterFinish != 0)\r
-                        chapters = chapters + " - " + parsed.DVDChapterFinish;\r
+                    chapters = parsed.ChapterStart.ToString();\r
+                    if (parsed.ChapterFinish != 0)\r
+                        chapters = chapters + " - " + parsed.ChapterFinish;\r
                 }\r
 \r
                 ListViewItem item = new ListViewItem();\r
@@ -275,11 +362,11 @@ namespace Handbrake
         /// <summary>\r
         /// Update the UI elements\r
         /// </summary>\r
-        private void UpdateUiElements()\r
+        private void UpdateUiElementsOnQueueChange()\r
         {\r
             if (InvokeRequired)\r
             {\r
-                BeginInvoke(new UpdateHandler(UpdateUiElements));\r
+                BeginInvoke(new UpdateHandler(UpdateUiElementsOnQueueChange));\r
                 return;\r
             }\r
 \r
@@ -299,75 +386,46 @@ namespace Handbrake
                     BeginInvoke(new UpdateHandler(SetCurrentEncodeInformation));\r
                 }\r
 \r
-                // found query is a global varible\r
-                QueryParser parsed = Functions.QueryParser.Parse(queue.LastEncode.Query);\r
-                lbl_source.Text = queue.LastEncode.Source;\r
-                lbl_dest.Text = queue.LastEncode.Destination;\r
-\r
-                lbl_title.Text = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();\r
+                QueryParser parsed = QueryParser.Parse(queue.LastEncode.Query);\r
 \r
-                if (Equals(parsed.DVDChapterStart, 0))\r
-                    lbl_chapt.Text = "Auto";\r
+                // Get title and chapters\r
+                string title = parsed.Title == 0 ? "Auto" : parsed.Title.ToString();\r
+                string chapterlbl;\r
+                if (Equals(parsed.ChapterStart, 0))\r
+                    chapterlbl = "Auto";\r
                 else\r
                 {\r
-                    string chapters = parsed.DVDChapterStart.ToString();\r
-                    if (parsed.DVDChapterFinish != 0)\r
-                        chapters = chapters + " - " + parsed.DVDChapterFinish;\r
-                    lbl_chapt.Text = chapters;\r
+                    string chapters = parsed.ChapterStart.ToString();\r
+                    if (parsed.ChapterFinish != 0)\r
+                        chapters = chapters + " - " + parsed.ChapterFinish;\r
+                    chapterlbl = chapters;\r
                 }\r
 \r
-                lbl_vEnc.Text = parsed.VideoEncoder;\r
-\r
-                // Display The Audio Track Information\r
+                // Get audio information\r
                 string audio = string.Empty;\r
                 foreach (AudioTrack track in parsed.AudioInformation)\r
                 {\r
-                    if (audio != string.Empty)\r
+                    if (audio != string.Empty) \r
                         audio += ", " + track.Encoder;\r
                     else\r
                         audio = track.Encoder;\r
                 }\r
-                lbl_aEnc.Text = audio;\r
-            }\r
+\r
+                // found query is a global varible        \r
+                lbl_encodeStatus.Text = "Encoding ...";\r
+                lbl_source.Text = queue.LastEncode.Source + "(Title: " + title + " Chapters: " + chapterlbl + ")";\r
+                lbl_dest.Text = queue.LastEncode.Destination;\r
+                lbl_encodeOptions.Text = "Video: " + parsed.VideoEncoder + " Audio: " + audio + Environment.NewLine +\r
+                                    "x264 Options: " + parsed.H264Query;\r
+               }\r
             catch (Exception)\r
             {\r
                 // Do Nothing\r
             }\r
         }\r
 \r
-        /// <summary>\r
-        /// Delete the currently selected items on the queue\r
-        /// </summary>\r
-        private void DeleteSelectedItems()\r
-        {\r
-            // If there are selected items\r
-            if (list_queue.SelectedIndices.Count > 0)\r
-            {\r
-                // Save the selected indices to select them after the move\r
-                List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);\r
-                foreach (int selectedIndex in list_queue.SelectedIndices)\r
-                    selectedIndices.Add(selectedIndex);\r
-\r
-                int firstSelectedIndex = selectedIndices[0];\r
-\r
-                // Reverse the list to delete the items from last to first (preserves indices)\r
-                selectedIndices.Reverse();\r
-\r
-                // Remove each selected item\r
-                foreach (int selectedIndex in selectedIndices)\r
-                    queue.Remove(selectedIndex);\r
-\r
-                UpdateUiElements();\r
-\r
-                // Select the item where the first deleted item was previously\r
-                if (firstSelectedIndex < list_queue.Items.Count)\r
-                    list_queue.Items[firstSelectedIndex].Selected = true;\r
-            }\r
-\r
-            list_queue.Select(); // Activate the control to show the selected items\r
-        }\r
+        /* Right Click Menu */\r
 \r
-        // Queue Management\r
         /// <summary>\r
         /// Handle the Move Up Menu Item\r
         /// </summary>\r
@@ -407,7 +465,7 @@ namespace Handbrake
         /// </param>\r
         private void MnuEditClick(object sender, EventArgs e)\r
         {\r
-            if (list_queue.SelectedIndices != null)\r
+            if (list_queue.SelectedIndices != null && list_queue.SelectedIndices.Count != 0)\r
             {\r
                 lock (queue)\r
                 {\r
@@ -436,47 +494,7 @@ namespace Handbrake
             DeleteSelectedItems();\r
         }\r
 \r
-        /// <summary>\r
-        /// Handle the Button Up Click\r
-        /// </summary>\r
-        /// <param name="sender">\r
-        /// The sender.\r
-        /// </param>\r
-        /// <param name="e">\r
-        /// The e.\r
-        /// </param>\r
-        private void BtnUpClick(object sender, EventArgs e)\r
-        {\r
-            MoveUp();\r
-        }\r
-\r
-        /// <summary>\r
-        /// Handle the button down click\r
-        /// </summary>\r
-        /// <param name="sender">\r
-        /// The sender.\r
-        /// </param>\r
-        /// <param name="e">\r
-        /// The e.\r
-        /// </param>\r
-        private void BtnDownClick(object sender, EventArgs e)\r
-        {\r
-            MoveDown();\r
-        }\r
-\r
-        /// <summary>\r
-        /// Handle the delete button click\r
-        /// </summary>\r
-        /// <param name="sender">\r
-        /// The sender.\r
-        /// </param>\r
-        /// <param name="e">\r
-        /// The e.\r
-        /// </param>\r
-        private void BtnDeleteClick(object sender, EventArgs e)\r
-        {\r
-            DeleteSelectedItems();\r
-        }\r
+        /* Keyboard Shortcuts */\r
 \r
         /// <summary>\r
         /// Handle the delete keyboard press\r
@@ -489,10 +507,12 @@ namespace Handbrake
         /// </param>\r
         private void ListQueueDeleteKey(object sender, KeyEventArgs e)\r
         {\r
-            if (e.KeyCode == Keys.Delete)\r
+            if (e.KeyCode == Keys.Delete && e.Modifiers == Keys.None)\r
                 DeleteSelectedItems();\r
         }\r
 \r
+        /* Queue Management */\r
+\r
         /// <summary>\r
         /// Move items up in the queue\r
         /// </summary>\r
@@ -510,8 +530,6 @@ namespace Handbrake
                 foreach (int selectedIndex in selectedIndices)\r
                     queue.MoveUp(selectedIndex);\r
 \r
-                UpdateUiElements();\r
-\r
                 // Keep the selected item(s) selected, now moved up one index\r
                 foreach (int selectedIndex in selectedIndices)\r
                     if (selectedIndex - 1 > -1) // Defensive programming: ensure index is good\r
@@ -542,8 +560,6 @@ namespace Handbrake
                 foreach (int selectedIndex in selectedIndices)\r
                     queue.MoveDown(selectedIndex);\r
 \r
-                UpdateUiElements();\r
-\r
                 // Keep the selected item(s) selected, now moved down one index\r
                 foreach (int selectedIndex in selectedIndices)\r
                     if (selectedIndex + 1 < list_queue.Items.Count) // Defensive programming: ensure index is good\r
@@ -553,7 +569,37 @@ namespace Handbrake
             list_queue.Select(); // Activate the control to show the selected items\r
         }\r
 \r
-        // Queue Import/Export Features\r
+        /// <summary>\r
+        /// Delete the currently selected items on the queue\r
+        /// </summary>\r
+        private void DeleteSelectedItems()\r
+        {\r
+            // If there are selected items\r
+            if (list_queue.SelectedIndices.Count > 0)\r
+            {\r
+                // Save the selected indices to select them after the move\r
+                List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);\r
+                foreach (int selectedIndex in list_queue.SelectedIndices)\r
+                    selectedIndices.Add(selectedIndex);\r
+\r
+                int firstSelectedIndex = selectedIndices[0];\r
+\r
+                // Reverse the list to delete the items from last to first (preserves indices)\r
+                selectedIndices.Reverse();\r
+\r
+                // Remove each selected item\r
+                foreach (int selectedIndex in selectedIndices)\r
+                    queue.Remove(selectedIndex);\r
+\r
+                // Select the item where the first deleted item was previously\r
+                if (firstSelectedIndex < list_queue.Items.Count)\r
+                    list_queue.Items[firstSelectedIndex].Selected = true;\r
+            }\r
+\r
+            list_queue.Select(); // Activate the control to show the selected items\r
+        }\r
+\r
+        /* Queue Import / Export features */\r
 \r
         /// <summary>\r
         /// Create a batch script\r
@@ -606,7 +652,6 @@ namespace Handbrake
             OpenFile.ShowDialog();\r
             if (OpenFile.FileName != String.Empty)\r
                 queue.LoadQueueFromFile(OpenFile.FileName);\r
-            UpdateUiElements();\r
         }\r
 \r
         /// <summary>\r
@@ -620,7 +665,7 @@ namespace Handbrake
         /// </param>\r
         private void MnuReaddClick(object sender, EventArgs e)\r
         {\r
-            if (!queue.LastEncode.IsEmpty)\r
+            if (queue.LastEncode != null && !queue.LastEncode.IsEmpty)\r
             {\r
                 queue.Add(\r
                     queue.LastEncode.Query, \r
@@ -628,10 +673,11 @@ namespace Handbrake
                     queue.LastEncode.Source,\r
                     queue.LastEncode.Destination,\r
                     queue.LastEncode.CustomQuery);\r
-                UpdateUiElements();\r
             }\r
         }\r
 \r
+        /* Overrides */\r
+\r
         /// <summary>\r
         /// Hide's the window when the user tries to "x" out of the window instead of closing it.\r
         /// </summary>\r
@@ -644,5 +690,21 @@ namespace Handbrake
             this.Hide();\r
             base.OnClosing(e);\r
         }\r
+\r
+        /// <summary>\r
+        /// Change the OnComplete option setting.\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The sender.\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The EventArgs.\r
+        /// </param>\r
+        private void CompleteOptionChanged(object sender, EventArgs e)\r
+        {\r
+            Properties.Settings.Default.CompletionOption = drp_completeOption.Text;\r
+            HandBrake.ApplicationServices.Init.CompletionOption = drp_completeOption.Text;\r
+            Properties.Settings.Default.Save();\r
+        }\r
     }\r
 }
\ No newline at end of file