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
13 using Handbrake.Model;
\r
17 public partial class frmQueue : Form
\r
19 private delegate void UpdateHandler();
\r
20 private Queue queue;
\r
21 private frmMain mainWindow;
\r
23 public frmQueue(Queue q, frmMain mw)
\r
25 InitializeComponent();
\r
27 this.mainWindow = mw;
\r
30 queue.EncodeStarted += new EventHandler(QueueOnEncodeStart);
\r
31 queue.QueueCompleted += new EventHandler(QueueOnQueueFinished);
\r
32 queue.QueuePauseRequested += new EventHandler(QueueOnPaused);
\r
35 private void QueueOnPaused(object sender, EventArgs e)
\r
37 SetUIEncodeFinished();
\r
40 private void QueueOnQueueFinished(object sender, EventArgs e)
\r
42 SetUIEncodeFinished();
\r
43 ResetQueue(); // Reset the Queue Window
\r
45 private void QueueOnEncodeStart(object sender, EventArgs e)
\r
47 SetUIEncodeStarted(); // make sure the UI is set correctly
\r
48 SetCurrentEncodeInformation();
\r
49 UpdateUIElements(); // Redraw the Queue, a new encode has started.
\r
53 /// Initializes the Queue list with the Arraylist from the Queue class
\r
55 public void SetQueue()
\r
61 /// Initializes the Queue list, then shows and activates the window
\r
63 public new void Show()
\r
69 /// Initializes the Queue list only if doSetQueue is true, then shows and activates the window
\r
71 /// <param name="doSetQueue">Indicates whether to call setQueue() before showing the window</param>
\r
72 public void Show(bool doSetQueue)
\r
74 if (doSetQueue) SetQueue();
\r
80 // Start and Stop Controls
\r
81 private void btn_encode_Click(object sender, EventArgs e)
\r
83 if (queue.PauseRequested)
\r
85 SetUIEncodeStarted();
\r
86 MessageBox.Show("Encoding restarted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
89 if (!queue.IsEncoding)
\r
93 private void btn_pause_Click(object sender, EventArgs e)
\r
96 SetUIEncodeFinished();
\r
98 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
102 // Window Display Management
\r
103 private void SetUIEncodeStarted()
\r
105 if (InvokeRequired)
\r
107 BeginInvoke(new UpdateHandler(SetUIEncodeStarted));
\r
110 btn_encode.Enabled = false;
\r
111 btn_pause.Visible = true;
\r
113 private void SetUIEncodeFinished()
\r
115 if (InvokeRequired)
\r
117 BeginInvoke(new UpdateHandler(SetUIEncodeFinished));
\r
120 btn_pause.Visible = false;
\r
121 btn_encode.Enabled = true;
\r
123 private void ResetQueue()
\r
125 if (InvokeRequired)
\r
127 BeginInvoke(new UpdateHandler(ResetQueue));
\r
130 btn_pause.Visible = false;
\r
131 btn_encode.Enabled = true;
\r
133 lbl_source.Text = "-";
\r
134 lbl_dest.Text = "-";
\r
135 lbl_vEnc.Text = "-";
\r
136 lbl_aEnc.Text = "-";
\r
137 lbl_title.Text = "-";
\r
138 lbl_chapt.Text = "-";
\r
140 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
\r
142 private void RedrawQueue()
\r
144 if (InvokeRequired)
\r
146 BeginInvoke(new UpdateHandler(RedrawQueue));
\r
150 list_queue.Items.Clear();
\r
151 ReadOnlyCollection<Job> theQueue = queue.CurrentQueue;
\r
152 foreach (Job queue_item in theQueue)
\r
154 string q_item = queue_item.Query;
\r
155 Functions.QueryParser parsed = Functions.QueryParser.Parse(q_item);
\r
157 // Get the DVD Title
\r
158 string title = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();
\r
160 // Get the DVD Chapters
\r
162 if (parsed.DVDChapterStart == 0)
\r
166 chapters = parsed.DVDChapterStart.ToString();
\r
167 if (parsed.DVDChapterFinish != 0)
\r
168 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
171 ListViewItem item = new ListViewItem();
\r
172 item.Text = title; // Title
\r
173 item.SubItems.Add(chapters); // Chapters
\r
174 item.SubItems.Add(queue_item.Source); // Source
\r
175 item.SubItems.Add(queue_item.Destination); // Destination
\r
176 item.SubItems.Add(parsed.VideoEncoder); // Video
\r
178 // Display The Audio Track Information
\r
179 string audio = string.Empty;
\r
180 foreach (AudioTrack track in parsed.AudioInformation)
\r
183 audio += ", " + track.Encoder;
\r
185 audio = track.Encoder;
\r
187 item.SubItems.Add(audio); // Audio
\r
189 list_queue.Items.Add(item);
\r
192 private void UpdateUIElements()
\r
194 if (InvokeRequired)
\r
196 BeginInvoke(new UpdateHandler(UpdateUIElements));
\r
201 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
\r
203 private void SetCurrentEncodeInformation()
\r
207 if (InvokeRequired)
\r
209 BeginInvoke(new UpdateHandler(SetCurrentEncodeInformation));
\r
212 // found query is a global varible
\r
213 Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.LastEncode.Query);
\r
214 lbl_source.Text = queue.LastEncode.Source;
\r
215 lbl_dest.Text = queue.LastEncode.Destination;
\r
217 lbl_title.Text = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();
\r
219 if (Equals(parsed.DVDChapterStart, 0))
\r
220 lbl_chapt.Text = "Auto";
\r
223 string chapters = parsed.DVDChapterStart.ToString();
\r
224 if (parsed.DVDChapterFinish != 0)
\r
225 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
226 lbl_chapt.Text = chapters;
\r
229 lbl_vEnc.Text = parsed.VideoEncoder;
\r
231 // Display The Audio Track Information
\r
232 string audio = string.Empty;
\r
233 foreach (AudioTrack track in parsed.AudioInformation)
\r
236 audio += ", " + track.Encoder;
\r
238 audio = track.Encoder;
\r
240 lbl_aEnc.Text = audio;
\r
247 private void DeleteSelectedItems()
\r
249 // If there are selected items
\r
250 if (list_queue.SelectedIndices.Count > 0)
\r
252 // Save the selected indices to select them after the move
\r
253 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
254 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
255 selectedIndices.Add(selectedIndex);
\r
257 int firstSelectedIndex = selectedIndices[0];
\r
259 // Reverse the list to delete the items from last to first (preserves indices)
\r
260 selectedIndices.Reverse();
\r
262 // Remove each selected item
\r
263 foreach (int selectedIndex in selectedIndices)
\r
264 queue.Remove(selectedIndex);
\r
266 UpdateUIElements();
\r
268 // Select the item where the first deleted item was previously
\r
269 if (firstSelectedIndex < list_queue.Items.Count)
\r
270 list_queue.Items[firstSelectedIndex].Selected = true;
\r
273 list_queue.Select(); // Activate the control to show the selected items
\r
276 // Queue Management
\r
277 private void mnu_up_Click(object sender, EventArgs e)
\r
281 private void mnu_Down_Click(object sender, EventArgs e)
\r
285 private void mnu_delete_Click(object sender, EventArgs e)
\r
287 DeleteSelectedItems();
\r
289 private void btn_up_Click(object sender, EventArgs e)
\r
293 private void btn_down_Click(object sender, EventArgs e)
\r
297 private void btn_delete_Click(object sender, EventArgs e)
\r
299 DeleteSelectedItems();
\r
301 private void list_queue_deleteKey(object sender, KeyEventArgs e)
\r
303 if (e.KeyCode == Keys.Delete)
\r
304 DeleteSelectedItems();
\r
306 private void MoveUp()
\r
308 // If there are selected items and the first item is not selected
\r
309 if (list_queue.SelectedIndices.Count > 0 && !list_queue.SelectedIndices.Contains(0))
\r
311 // Copy the selected indices to preserve them during the movement
\r
312 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
313 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
314 selectedIndices.Add(selectedIndex);
\r
316 // Move up each selected item
\r
317 foreach (int selectedIndex in selectedIndices)
\r
318 queue.MoveUp(selectedIndex);
\r
320 UpdateUIElements();
\r
322 // Keep the selected item(s) selected, now moved up one index
\r
323 foreach (int selectedIndex in selectedIndices)
\r
324 if (selectedIndex - 1 > -1) // Defensive programming: ensure index is good
\r
325 list_queue.Items[selectedIndex - 1].Selected = true;
\r
328 list_queue.Select(); // Activate the control to show the selected items
\r
330 private void MoveDown()
\r
332 // If there are selected items and the last item is not selected
\r
333 if (list_queue.SelectedIndices.Count > 0 &&
\r
334 !list_queue.SelectedIndices.Contains(list_queue.Items[list_queue.Items.Count - 1].Index))
\r
336 // Copy the selected indices to preserve them during the movement
\r
337 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
338 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
339 selectedIndices.Add(selectedIndex);
\r
341 // Reverse the indices to move the items down from last to first (preserves indices)
\r
342 selectedIndices.Reverse();
\r
344 // Move down each selected item
\r
345 foreach (int selectedIndex in selectedIndices)
\r
346 queue.MoveDown(selectedIndex);
\r
348 UpdateUIElements();
\r
350 // Keep the selected item(s) selected, now moved down one index
\r
351 foreach (int selectedIndex in selectedIndices)
\r
352 if (selectedIndex + 1 < list_queue.Items.Count) // Defensive programming: ensure index is good
\r
353 list_queue.Items[selectedIndex + 1].Selected = true;
\r
356 list_queue.Select(); // Activate the control to show the selected items
\r
359 // Queue Import/Export Features
\r
360 private void mnu_batch_Click(object sender, EventArgs e)
\r
362 SaveFile.FileName = "";
\r
363 SaveFile.Filter = "Batch|.bat";
\r
364 SaveFile.ShowDialog();
\r
365 if (SaveFile.FileName != String.Empty)
\r
366 queue.WriteBatchScriptToFile(SaveFile.FileName);
\r
368 private void mnu_export_Click(object sender, EventArgs e)
\r
370 SaveFile.FileName = "";
\r
371 SaveFile.Filter = "HandBrake Queue|*.queue";
\r
372 SaveFile.ShowDialog();
\r
373 if (SaveFile.FileName != String.Empty)
\r
374 queue.WriteQueueStateToFile(SaveFile.FileName);
\r
376 private void mnu_import_Click(object sender, EventArgs e)
\r
378 OpenFile.FileName = "";
\r
379 OpenFile.ShowDialog();
\r
380 if (OpenFile.FileName != String.Empty)
\r
381 queue.LoadQueueFromFile(OpenFile.FileName);
\r
382 UpdateUIElements();
\r
384 private void mnu_readd_Click(object sender, EventArgs e)
\r
386 if (!queue.LastEncode.IsEmpty)
\r
388 queue.Add(queue.LastEncode.Query, queue.LastEncode.Source, queue.LastEncode.Destination, queue.LastEncode.CustomQuery);
\r
389 UpdateUIElements();
\r
392 private void mnu_reconfigureJob_Click(object sender, EventArgs e)
\r
394 if (list_queue.SelectedIndices != null)
\r
400 int index = list_queue.SelectedIndices[0];
\r
401 mainWindow.RecievingJob(queue.GetJob(index));
\r
402 queue.Remove(index);
\r
410 // Hide's the window when the user tries to "x" out of the window instead of closing it.
\r
411 protected override void OnClosing(CancelEventArgs e)
\r