3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections.Generic;
\r
9 using System.ComponentModel;
\r
10 using System.Windows.Forms;
\r
11 using Handbrake.EncodeQueue;
\r
12 using System.Collections.ObjectModel;
\r
16 public partial class frmQueue : Form
\r
18 private delegate void UpdateHandler();
\r
19 private Queue queue;
\r
20 private frmMain mainWindow;
\r
22 public frmQueue(Queue q, frmMain mw)
\r
24 InitializeComponent();
\r
26 this.mainWindow = mw;
\r
29 queue.NewJobStarted += new EventHandler(QueueOnEncodeStart);
\r
30 queue.QueueCompleted += new EventHandler(QueueOnQueueFinished);
\r
31 queue.QueuePauseRequested += new EventHandler(QueueOnPaused);
\r
34 private void QueueOnPaused(object sender, EventArgs e)
\r
36 SetUIEncodeFinished();
\r
39 private void QueueOnQueueFinished(object sender, EventArgs e)
\r
41 SetUIEncodeFinished();
\r
42 ResetQueue(); // Reset the Queue Window
\r
44 private void QueueOnEncodeStart(object sender, EventArgs e)
\r
46 SetUIEncodeStarted(); // make sure the UI is set correctly
\r
47 SetCurrentEncodeInformation();
\r
48 UpdateUIElements(); // Redraw the Queue, a new encode has started.
\r
52 /// Initializes the Queue list with the Arraylist from the Queue class
\r
54 public void SetQueue()
\r
60 /// Initializes the Queue list, then shows and activates the window
\r
62 public new void Show()
\r
68 /// Initializes the Queue list only if doSetQueue is true, then shows and activates the window
\r
70 /// <param name="doSetQueue">Indicates whether to call setQueue() before showing the window</param>
\r
71 public void Show(bool doSetQueue)
\r
73 if (doSetQueue) SetQueue();
\r
79 // Start and Stop Controls
\r
80 private void btn_encode_Click(object sender, EventArgs e)
\r
82 if (queue.PauseRequested)
\r
84 SetUIEncodeStarted();
\r
85 MessageBox.Show("Encoding restarted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
88 if (!queue.IsEncoding)
\r
92 private void btn_pause_Click(object sender, EventArgs e)
\r
95 SetUIEncodeFinished();
\r
97 MessageBox.Show("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.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
101 // Window Display Management
\r
102 private void SetUIEncodeStarted()
\r
104 if (InvokeRequired)
\r
106 BeginInvoke(new UpdateHandler(SetUIEncodeStarted));
\r
109 btn_encode.Enabled = false;
\r
110 btn_pause.Visible = true;
\r
112 private void SetUIEncodeFinished()
\r
114 if (InvokeRequired)
\r
116 BeginInvoke(new UpdateHandler(SetUIEncodeFinished));
\r
119 btn_pause.Visible = false;
\r
120 btn_encode.Enabled = true;
\r
122 private void ResetQueue()
\r
124 if (InvokeRequired)
\r
126 BeginInvoke(new UpdateHandler(ResetQueue));
\r
129 btn_pause.Visible = false;
\r
130 btn_encode.Enabled = true;
\r
132 lbl_source.Text = "-";
\r
133 lbl_dest.Text = "-";
\r
134 lbl_vEnc.Text = "-";
\r
135 lbl_aEnc.Text = "-";
\r
136 lbl_title.Text = "-";
\r
137 lbl_chapt.Text = "-";
\r
139 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
\r
141 private void RedrawQueue()
\r
143 if (InvokeRequired)
\r
145 BeginInvoke(new UpdateHandler(RedrawQueue));
\r
149 list_queue.Items.Clear();
\r
150 ReadOnlyCollection<Job> theQueue = queue.CurrentQueue;
\r
151 foreach (Job queue_item in theQueue)
\r
153 string q_item = queue_item.Query;
\r
154 Functions.QueryParser parsed = Functions.QueryParser.Parse(q_item);
\r
156 // Get the DVD Title
\r
157 string title = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();
\r
159 // Get the DVD Chapters
\r
161 if (parsed.DVDChapterStart == 0)
\r
165 chapters = parsed.DVDChapterStart.ToString();
\r
166 if (parsed.DVDChapterFinish != 0)
\r
167 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
170 ListViewItem item = new ListViewItem();
\r
171 item.Text = title; // Title
\r
172 item.SubItems.Add(chapters); // Chapters
\r
173 item.SubItems.Add(queue_item.Source); // Source
\r
174 item.SubItems.Add(queue_item.Destination); // Destination
\r
175 item.SubItems.Add(parsed.VideoEncoder); // Video
\r
177 // Display The Audio Track Information
\r
178 string audio = string.Empty;
\r
179 foreach (Functions.AudioTrack track in parsed.AudioInformation)
\r
182 audio += ", " + track.Encoder;
\r
184 audio = track.Encoder;
\r
186 item.SubItems.Add(audio); // Audio
\r
188 list_queue.Items.Add(item);
\r
191 private void UpdateUIElements()
\r
193 if (InvokeRequired)
\r
195 BeginInvoke(new UpdateHandler(UpdateUIElements));
\r
200 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
\r
202 private void SetCurrentEncodeInformation()
\r
206 if (InvokeRequired)
\r
208 BeginInvoke(new UpdateHandler(SetCurrentEncodeInformation));
\r
211 // found query is a global varible
\r
212 Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.LastEncode.Query);
\r
213 lbl_source.Text = queue.LastEncode.Source;
\r
214 lbl_dest.Text = queue.LastEncode.Destination;
\r
216 lbl_title.Text = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();
\r
218 if (Equals(parsed.DVDChapterStart, 0))
\r
219 lbl_chapt.Text = "Auto";
\r
222 string chapters = parsed.DVDChapterStart.ToString();
\r
223 if (parsed.DVDChapterFinish != 0)
\r
224 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
225 lbl_chapt.Text = chapters;
\r
228 lbl_vEnc.Text = parsed.VideoEncoder;
\r
230 // Display The Audio Track Information
\r
231 string audio = string.Empty;
\r
232 foreach (Functions.AudioTrack track in parsed.AudioInformation)
\r
235 audio += ", " + track.Encoder;
\r
237 audio = track.Encoder;
\r
239 lbl_aEnc.Text = audio;
\r
246 private void DeleteSelectedItems()
\r
248 // If there are selected items
\r
249 if (list_queue.SelectedIndices.Count > 0)
\r
251 // Save the selected indices to select them after the move
\r
252 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
253 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
254 selectedIndices.Add(selectedIndex);
\r
256 int firstSelectedIndex = selectedIndices[0];
\r
258 // Reverse the list to delete the items from last to first (preserves indices)
\r
259 selectedIndices.Reverse();
\r
261 // Remove each selected item
\r
262 foreach (int selectedIndex in selectedIndices)
\r
263 queue.Remove(selectedIndex);
\r
265 UpdateUIElements();
\r
267 // Select the item where the first deleted item was previously
\r
268 if (firstSelectedIndex < list_queue.Items.Count)
\r
269 list_queue.Items[firstSelectedIndex].Selected = true;
\r
272 list_queue.Select(); // Activate the control to show the selected items
\r
275 // Queue Management
\r
276 private void mnu_up_Click(object sender, EventArgs e)
\r
280 private void mnu_Down_Click(object sender, EventArgs e)
\r
284 private void mnu_delete_Click(object sender, EventArgs e)
\r
286 DeleteSelectedItems();
\r
288 private void btn_up_Click(object sender, EventArgs e)
\r
292 private void btn_down_Click(object sender, EventArgs e)
\r
296 private void btn_delete_Click(object sender, EventArgs e)
\r
298 DeleteSelectedItems();
\r
300 private void list_queue_deleteKey(object sender, KeyEventArgs e)
\r
302 if (e.KeyCode == Keys.Delete)
\r
303 DeleteSelectedItems();
\r
305 private void MoveUp()
\r
307 // If there are selected items and the first item is not selected
\r
308 if (list_queue.SelectedIndices.Count > 0 && !list_queue.SelectedIndices.Contains(0))
\r
310 // Copy the selected indices to preserve them during the movement
\r
311 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
312 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
313 selectedIndices.Add(selectedIndex);
\r
315 // Move up each selected item
\r
316 foreach (int selectedIndex in selectedIndices)
\r
317 queue.MoveUp(selectedIndex);
\r
319 UpdateUIElements();
\r
321 // Keep the selected item(s) selected, now moved up one index
\r
322 foreach (int selectedIndex in selectedIndices)
\r
323 if (selectedIndex - 1 > -1) // Defensive programming: ensure index is good
\r
324 list_queue.Items[selectedIndex - 1].Selected = true;
\r
327 list_queue.Select(); // Activate the control to show the selected items
\r
329 private void MoveDown()
\r
331 // If there are selected items and the last item is not selected
\r
332 if (list_queue.SelectedIndices.Count > 0 &&
\r
333 !list_queue.SelectedIndices.Contains(list_queue.Items[list_queue.Items.Count - 1].Index))
\r
335 // Copy the selected indices to preserve them during the movement
\r
336 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
337 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
338 selectedIndices.Add(selectedIndex);
\r
340 // Reverse the indices to move the items down from last to first (preserves indices)
\r
341 selectedIndices.Reverse();
\r
343 // Move down each selected item
\r
344 foreach (int selectedIndex in selectedIndices)
\r
345 queue.MoveDown(selectedIndex);
\r
347 UpdateUIElements();
\r
349 // Keep the selected item(s) selected, now moved down one index
\r
350 foreach (int selectedIndex in selectedIndices)
\r
351 if (selectedIndex + 1 < list_queue.Items.Count) // Defensive programming: ensure index is good
\r
352 list_queue.Items[selectedIndex + 1].Selected = true;
\r
355 list_queue.Select(); // Activate the control to show the selected items
\r
358 // Queue Import/Export Features
\r
359 private void mnu_batch_Click(object sender, EventArgs e)
\r
361 SaveFile.FileName = "";
\r
362 SaveFile.Filter = "Batch|.bat";
\r
363 SaveFile.ShowDialog();
\r
364 if (SaveFile.FileName != String.Empty)
\r
365 queue.WriteBatchScriptToFile(SaveFile.FileName);
\r
367 private void mnu_export_Click(object sender, EventArgs e)
\r
369 SaveFile.FileName = "";
\r
370 SaveFile.Filter = "HandBrake Queue|*.queue";
\r
371 SaveFile.ShowDialog();
\r
372 if (SaveFile.FileName != String.Empty)
\r
373 queue.WriteQueueStateToFile(SaveFile.FileName);
\r
375 private void mnu_import_Click(object sender, EventArgs e)
\r
377 OpenFile.FileName = "";
\r
378 OpenFile.ShowDialog();
\r
379 if (OpenFile.FileName != String.Empty)
\r
380 queue.LoadQueueFromFile(OpenFile.FileName);
\r
381 UpdateUIElements();
\r
383 private void mnu_readd_Click(object sender, EventArgs e)
\r
385 if (!queue.LastEncode.IsEmpty)
\r
387 queue.Add(queue.LastEncode.Query, queue.LastEncode.Source, queue.LastEncode.Destination, queue.LastEncode.CustomQuery);
\r
388 UpdateUIElements();
\r
391 private void mnu_reconfigureJob_Click(object sender, EventArgs e)
\r
393 if (list_queue.SelectedIndices != null)
\r
399 int index = list_queue.SelectedIndices[0];
\r
400 mainWindow.RecievingJob(queue.GetJob(index));
\r
401 queue.Remove(index);
\r
409 // Hide's the window when the user tries to "x" out of the window instead of closing it.
\r
410 protected override void OnClosing(CancelEventArgs e)
\r