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
10 using System.Collections.Generic;
\r
11 using System.Collections.ObjectModel;
\r
12 using System.ComponentModel;
\r
13 using System.Windows.Forms;
\r
18 public partial class frmQueue : Form
\r
20 private delegate void UpdateHandler();
\r
22 private Queue queue;
\r
23 private frmMain mainWindow;
\r
25 public frmQueue(Queue q, frmMain mw)
\r
27 InitializeComponent();
\r
29 this.mainWindow = mw;
\r
32 queue.EncodeStarted += new EventHandler(QueueOnEncodeStart);
\r
33 queue.QueueCompleted += new EventHandler(QueueOnQueueFinished);
\r
34 queue.QueuePauseRequested += new EventHandler(QueueOnPaused);
\r
37 private void QueueOnPaused(object sender, EventArgs e)
\r
39 SetUIEncodeFinished();
\r
43 private void QueueOnQueueFinished(object sender, EventArgs e)
\r
45 SetUIEncodeFinished();
\r
46 ResetQueue(); // Reset the Queue Window
\r
49 private void QueueOnEncodeStart(object sender, EventArgs e)
\r
51 SetUIEncodeStarted(); // make sure the UI is set correctly
\r
52 SetCurrentEncodeInformation();
\r
53 UpdateUIElements(); // Redraw the Queue, a new encode has started.
\r
57 /// Initializes the Queue list with the Arraylist from the Queue class
\r
59 public void SetQueue()
\r
65 /// Initializes the Queue list, then shows and activates the window
\r
67 public new void Show()
\r
73 /// Initializes the Queue list only if doSetQueue is true, then shows and activates the window
\r
75 /// <param name="doSetQueue">Indicates whether to call setQueue() before showing the window</param>
\r
76 public void Show(bool doSetQueue)
\r
78 if (doSetQueue) SetQueue();
\r
84 // Start and Stop Controls
\r
85 private void btn_encode_Click(object sender, EventArgs e)
\r
87 if (queue.PauseRequested)
\r
89 SetUIEncodeStarted();
\r
90 MessageBox.Show("Encoding restarted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
93 if (!queue.IsEncoding)
\r
97 private void btn_pause_Click(object sender, EventArgs e)
\r
100 SetUIEncodeFinished();
\r
103 "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
104 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
108 // Window Display Management
\r
109 private void SetUIEncodeStarted()
\r
111 if (InvokeRequired)
\r
113 BeginInvoke(new UpdateHandler(SetUIEncodeStarted));
\r
116 btn_encode.Enabled = false;
\r
117 btn_pause.Visible = true;
\r
120 private void SetUIEncodeFinished()
\r
122 if (InvokeRequired)
\r
124 BeginInvoke(new UpdateHandler(SetUIEncodeFinished));
\r
127 btn_pause.Visible = false;
\r
128 btn_encode.Enabled = true;
\r
131 private void ResetQueue()
\r
133 if (InvokeRequired)
\r
135 BeginInvoke(new UpdateHandler(ResetQueue));
\r
138 btn_pause.Visible = false;
\r
139 btn_encode.Enabled = true;
\r
141 lbl_source.Text = "-";
\r
142 lbl_dest.Text = "-";
\r
143 lbl_vEnc.Text = "-";
\r
144 lbl_aEnc.Text = "-";
\r
145 lbl_title.Text = "-";
\r
146 lbl_chapt.Text = "-";
\r
148 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
\r
151 private void RedrawQueue()
\r
153 if (InvokeRequired)
\r
155 BeginInvoke(new UpdateHandler(RedrawQueue));
\r
159 list_queue.Items.Clear();
\r
160 ReadOnlyCollection<Job> theQueue = queue.CurrentQueue;
\r
161 foreach (Job queue_item in theQueue)
\r
163 string q_item = queue_item.Query;
\r
164 QueryParser parsed = Functions.QueryParser.Parse(q_item);
\r
166 // Get the DVD Title
\r
167 string title = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();
\r
169 // Get the DVD Chapters
\r
171 if (parsed.DVDChapterStart == 0)
\r
175 chapters = parsed.DVDChapterStart.ToString();
\r
176 if (parsed.DVDChapterFinish != 0)
\r
177 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
180 ListViewItem item = new ListViewItem();
\r
181 item.Text = title; // Title
\r
182 item.SubItems.Add(chapters); // Chapters
\r
183 item.SubItems.Add(queue_item.Source); // Source
\r
184 item.SubItems.Add(queue_item.Destination); // Destination
\r
185 item.SubItems.Add(parsed.VideoEncoder); // Video
\r
187 // Display The Audio Track Information
\r
188 string audio = string.Empty;
\r
189 foreach (AudioTrack track in parsed.AudioInformation)
\r
191 if (audio != string.Empty)
\r
192 audio += ", " + track.Encoder;
\r
194 audio = track.Encoder;
\r
196 item.SubItems.Add(audio); // Audio
\r
198 list_queue.Items.Add(item);
\r
202 private void UpdateUIElements()
\r
204 if (InvokeRequired)
\r
206 BeginInvoke(new UpdateHandler(UpdateUIElements));
\r
211 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
\r
214 private void SetCurrentEncodeInformation()
\r
218 if (InvokeRequired)
\r
220 BeginInvoke(new UpdateHandler(SetCurrentEncodeInformation));
\r
223 // found query is a global varible
\r
224 QueryParser parsed = Functions.QueryParser.Parse(queue.LastEncode.Query);
\r
225 lbl_source.Text = queue.LastEncode.Source;
\r
226 lbl_dest.Text = queue.LastEncode.Destination;
\r
228 lbl_title.Text = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();
\r
230 if (Equals(parsed.DVDChapterStart, 0))
\r
231 lbl_chapt.Text = "Auto";
\r
234 string chapters = parsed.DVDChapterStart.ToString();
\r
235 if (parsed.DVDChapterFinish != 0)
\r
236 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
237 lbl_chapt.Text = chapters;
\r
240 lbl_vEnc.Text = parsed.VideoEncoder;
\r
242 // Display The Audio Track Information
\r
243 string audio = string.Empty;
\r
244 foreach (AudioTrack track in parsed.AudioInformation)
\r
246 if (audio != string.Empty)
\r
247 audio += ", " + track.Encoder;
\r
249 audio = track.Encoder;
\r
251 lbl_aEnc.Text = audio;
\r
259 private void DeleteSelectedItems()
\r
261 // If there are selected items
\r
262 if (list_queue.SelectedIndices.Count > 0)
\r
264 // Save the selected indices to select them after the move
\r
265 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
266 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
267 selectedIndices.Add(selectedIndex);
\r
269 int firstSelectedIndex = selectedIndices[0];
\r
271 // Reverse the list to delete the items from last to first (preserves indices)
\r
272 selectedIndices.Reverse();
\r
274 // Remove each selected item
\r
275 foreach (int selectedIndex in selectedIndices)
\r
276 queue.Remove(selectedIndex);
\r
278 UpdateUIElements();
\r
280 // Select the item where the first deleted item was previously
\r
281 if (firstSelectedIndex < list_queue.Items.Count)
\r
282 list_queue.Items[firstSelectedIndex].Selected = true;
\r
285 list_queue.Select(); // Activate the control to show the selected items
\r
288 // Queue Management
\r
289 private void mnu_up_Click(object sender, EventArgs e)
\r
294 private void mnu_Down_Click(object sender, EventArgs e)
\r
299 private void mnu_delete_Click(object sender, EventArgs e)
\r
301 DeleteSelectedItems();
\r
304 private void btn_up_Click(object sender, EventArgs e)
\r
309 private void btn_down_Click(object sender, EventArgs e)
\r
314 private void btn_delete_Click(object sender, EventArgs e)
\r
316 DeleteSelectedItems();
\r
319 private void list_queue_deleteKey(object sender, KeyEventArgs e)
\r
321 if (e.KeyCode == Keys.Delete)
\r
322 DeleteSelectedItems();
\r
325 private void MoveUp()
\r
327 // If there are selected items and the first item is not selected
\r
328 if (list_queue.SelectedIndices.Count > 0 && !list_queue.SelectedIndices.Contains(0))
\r
330 // Copy the selected indices to preserve them during the movement
\r
331 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
332 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
333 selectedIndices.Add(selectedIndex);
\r
335 // Move up each selected item
\r
336 foreach (int selectedIndex in selectedIndices)
\r
337 queue.MoveUp(selectedIndex);
\r
339 UpdateUIElements();
\r
341 // Keep the selected item(s) selected, now moved up one index
\r
342 foreach (int selectedIndex in selectedIndices)
\r
343 if (selectedIndex - 1 > -1) // Defensive programming: ensure index is good
\r
344 list_queue.Items[selectedIndex - 1].Selected = true;
\r
347 list_queue.Select(); // Activate the control to show the selected items
\r
350 private void MoveDown()
\r
352 // If there are selected items and the last item is not selected
\r
353 if (list_queue.SelectedIndices.Count > 0 &&
\r
354 !list_queue.SelectedIndices.Contains(list_queue.Items[list_queue.Items.Count - 1].Index))
\r
356 // Copy the selected indices to preserve them during the movement
\r
357 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
358 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
359 selectedIndices.Add(selectedIndex);
\r
361 // Reverse the indices to move the items down from last to first (preserves indices)
\r
362 selectedIndices.Reverse();
\r
364 // Move down each selected item
\r
365 foreach (int selectedIndex in selectedIndices)
\r
366 queue.MoveDown(selectedIndex);
\r
368 UpdateUIElements();
\r
370 // Keep the selected item(s) selected, now moved down one index
\r
371 foreach (int selectedIndex in selectedIndices)
\r
372 if (selectedIndex + 1 < list_queue.Items.Count) // Defensive programming: ensure index is good
\r
373 list_queue.Items[selectedIndex + 1].Selected = true;
\r
376 list_queue.Select(); // Activate the control to show the selected items
\r
379 // Queue Import/Export Features
\r
380 private void mnu_batch_Click(object sender, EventArgs e)
\r
382 SaveFile.FileName = string.Empty;
\r
383 SaveFile.Filter = "Batch|.bat";
\r
384 SaveFile.ShowDialog();
\r
385 if (SaveFile.FileName != String.Empty)
\r
386 queue.WriteBatchScriptToFile(SaveFile.FileName);
\r
389 private void mnu_export_Click(object sender, EventArgs e)
\r
391 SaveFile.FileName = string.Empty;
\r
392 SaveFile.Filter = "HandBrake Queue|*.queue";
\r
393 SaveFile.ShowDialog();
\r
394 if (SaveFile.FileName != String.Empty)
\r
395 queue.WriteQueueStateToFile(SaveFile.FileName);
\r
398 private void mnu_import_Click(object sender, EventArgs e)
\r
400 OpenFile.FileName = string.Empty;
\r
401 OpenFile.ShowDialog();
\r
402 if (OpenFile.FileName != String.Empty)
\r
403 queue.LoadQueueFromFile(OpenFile.FileName);
\r
404 UpdateUIElements();
\r
407 private void mnu_readd_Click(object sender, EventArgs e)
\r
409 if (!queue.LastEncode.IsEmpty)
\r
411 queue.Add(queue.LastEncode.Query, queue.LastEncode.Source, queue.LastEncode.Destination,
\r
412 queue.LastEncode.CustomQuery);
\r
413 UpdateUIElements();
\r
417 private void mnu_reconfigureJob_Click(object sender, EventArgs e)
\r
419 if (list_queue.SelectedIndices != null)
\r
425 int index = list_queue.SelectedIndices[0];
\r
426 mainWindow.RecievingJob(queue.GetJob(index));
\r
427 queue.Remove(index);
\r
435 // Hide's the window when the user tries to "x" out of the window instead of closing it.
\r
436 protected override void OnClosing(CancelEventArgs e)
\r