+ RedrawQueue();\r
+ lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";\r
+ }\r
+\r
+ /// <summary>\r
+ /// Set the window up with the current encode information\r
+ /// </summary>\r
+ private void SetCurrentEncodeInformation()\r
+ {\r
+ try\r
+ {\r
+ if (InvokeRequired)\r
+ {\r
+ BeginInvoke(new UpdateHandler(SetCurrentEncodeInformation));\r
+ }\r
+\r
+ QueryParser parsed = QueryParser.Parse(queue.LastEncode.Query);\r
+\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.ChapterStart.ToString();\r
+ if (parsed.ChapterFinish != 0)\r
+ chapters = chapters + " - " + parsed.ChapterFinish;\r
+ chapterlbl = chapters;\r
+ }\r
+\r
+ // Get audio information\r
+ string audio = string.Empty;\r
+ foreach (AudioTrack track in parsed.AudioInformation)\r
+ {\r
+ if (audio != string.Empty) \r
+ audio += ", " + track.Encoder;\r
+ else\r
+ audio = track.Encoder;\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
+ /* Right Click Menu */\r
+\r
+ /// <summary>\r
+ /// Handle the Move Up Menu Item\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void MnuUpClick(object sender, EventArgs e)\r
+ {\r
+ MoveUp();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Handle the Move down Menu Item\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void MnuDownClick(object sender, EventArgs e)\r
+ {\r
+ MoveDown();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Edit a job\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void MnuEditClick(object sender, EventArgs e)\r
+ {\r
+ if (list_queue.SelectedIndices != null && list_queue.SelectedIndices.Count != 0)\r
+ {\r
+ lock (queue)\r
+ {\r
+ lock (list_queue)\r
+ {\r
+ int index = list_queue.SelectedIndices[0];\r
+ mainWindow.RecievingJob(queue.GetJob(index));\r
+ queue.Remove(index);\r
+ RedrawQueue();\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Handle the delete Menu Item\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void MnuDeleteClick(object sender, EventArgs e)\r
+ {\r
+ DeleteSelectedItems();\r
+ }\r
+\r
+ /* Keyboard Shortcuts */\r
+\r
+ /// <summary>\r
+ /// Handle the delete keyboard press\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void ListQueueDeleteKey(object sender, KeyEventArgs e)\r
+ {\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
+ private void MoveUp()\r
+ {\r
+ // If there are selected items and the first item is not selected\r
+ if (list_queue.SelectedIndices.Count > 0 && !list_queue.SelectedIndices.Contains(0))\r
+ {\r
+ // Copy the selected indices to preserve them during the movement\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
+ // Move up each selected item\r
+ foreach (int selectedIndex in selectedIndices)\r
+ queue.MoveUp(selectedIndex);\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
+ list_queue.Items[selectedIndex - 1].Selected = true;\r
+ }\r
+\r
+ list_queue.Select(); // Activate the control to show the selected items\r
+ }\r
+\r
+ /// <summary>\r
+ /// Move items down in the queue\r
+ /// </summary>\r
+ private void MoveDown()\r
+ {\r
+ // If there are selected items and the last item is not selected\r
+ if (list_queue.SelectedIndices.Count > 0 &&\r
+ !list_queue.SelectedIndices.Contains(list_queue.Items[list_queue.Items.Count - 1].Index))\r
+ {\r
+ // Copy the selected indices to preserve them during the movement\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
+ // Reverse the indices to move the items down from last to first (preserves indices)\r
+ selectedIndices.Reverse();\r
+\r
+ // Move down each selected item\r
+ foreach (int selectedIndex in selectedIndices)\r
+ queue.MoveDown(selectedIndex);\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
+ list_queue.Items[selectedIndex + 1].Selected = true;\r
+ }\r
+\r
+ list_queue.Select(); // Activate the control to show the selected items\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
+ // 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
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void MnuBatchClick(object sender, EventArgs e)\r
+ {\r
+ SaveFile.FileName = string.Empty;\r
+ SaveFile.Filter = "Batch|.bat";\r
+ SaveFile.ShowDialog();\r
+ if (SaveFile.FileName != String.Empty)\r
+ queue.WriteBatchScriptToFile(SaveFile.FileName);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Export Queue\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void MnuExportClick(object sender, EventArgs e)\r
+ {\r
+ SaveFile.FileName = string.Empty;\r
+ SaveFile.Filter = "HandBrake Queue|*.queue";\r
+ SaveFile.ShowDialog();\r
+ if (SaveFile.FileName != String.Empty)\r
+ queue.WriteQueueStateToFile(SaveFile.FileName);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Import Queue\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void MnuImportClick(object sender, EventArgs e)\r
+ {\r
+ OpenFile.FileName = string.Empty;\r
+ OpenFile.ShowDialog();\r
+ if (OpenFile.FileName != String.Empty)\r
+ queue.LoadQueueFromFile(OpenFile.FileName);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Readd current job to queue\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void MnuReaddClick(object sender, EventArgs e)\r
+ {\r
+ if (queue.LastEncode != null && !queue.LastEncode.IsEmpty)\r
+ {\r
+ queue.Add(\r
+ queue.LastEncode.Query, \r
+ queue.LastEncode.Title, \r
+ queue.LastEncode.Source,\r
+ queue.LastEncode.Destination,\r
+ queue.LastEncode.CustomQuery);\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
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ protected override void OnClosing(CancelEventArgs e)\r
+ {\r
+ e.Cancel = true;\r
+ 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