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
14 public partial class frmQueue : Form
\r
16 private delegate void UpdateHandler();
\r
17 Queue.QueueHandler queue;
\r
19 public frmQueue(Queue.QueueHandler q)
\r
21 InitializeComponent();
\r
24 queue.OnEncodeStart += new EventHandler(queue_OnEncodeStart);
\r
25 queue.OnQueueFinished += new EventHandler(queue_OnQueueFinished);
\r
26 queue.OnPaused += new EventHandler(queue_OnPaused);
\r
28 void queue_OnPaused(object sender, EventArgs e)
\r
30 setUIEncodeFinished();
\r
33 void queue_OnQueueFinished(object sender, EventArgs e)
\r
35 setUIEncodeFinished();
\r
36 resetQueue(); // Reset the Queue Window
\r
38 void queue_OnEncodeStart(object sender, EventArgs e)
\r
40 setUIEncodeStarted(); // make sure the UI is set correctly
\r
41 setCurrentEncodeInformation();
\r
42 updateUIElements(); // Redraw the Queue, a new encode has started.
\r
46 /// Initializes the Queue list with the Arraylist from the Queue class
\r
48 public void setQueue()
\r
54 /// Initializes the Queue list, then shows and activates the window
\r
56 public new void Show()
\r
62 /// Initializes the Queue list only if doSetQueue is true, then shows and activates the window
\r
64 /// <param name="doSetQueue">Indicates whether to call setQueue() before showing the window</param>
\r
65 public void Show(bool doSetQueue)
\r
67 if (doSetQueue) setQueue();
\r
72 // Start and Stop Controls
\r
73 private void btn_encode_Click(object sender, EventArgs e)
\r
77 setUIEncodeStarted();
\r
78 MessageBox.Show("Encoding restarted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
81 if (!queue.isEncodeStarted)
\r
82 queue.startEncode();
\r
85 private void btn_pause_Click(object sender, EventArgs e)
\r
87 queue.pauseEncode();
\r
88 setUIEncodeFinished();
\r
90 MessageBox.Show("No further items on the queue will start. The current encode process will continue until it is finished. \nClick 'Encode Video' when you wish to continue encoding the queue.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
93 // Window Display Management
\r
94 private void setUIEncodeStarted()
\r
98 BeginInvoke(new UpdateHandler(setUIEncodeStarted));
\r
101 btn_encode.Enabled = false;
\r
102 btn_pause.Visible = true;
\r
104 private void setUIEncodeFinished()
\r
106 if (InvokeRequired)
\r
108 BeginInvoke(new UpdateHandler(setUIEncodeFinished));
\r
111 btn_pause.Visible = false;
\r
112 btn_encode.Enabled = true;
\r
114 private void resetQueue()
\r
116 if (InvokeRequired)
\r
118 BeginInvoke(new UpdateHandler(resetQueue));
\r
121 btn_pause.Visible = false;
\r
122 btn_encode.Enabled = true;
\r
124 lbl_source.Text = "-";
\r
125 lbl_dest.Text = "-";
\r
126 lbl_vEnc.Text = "-";
\r
127 lbl_aEnc.Text = "-";
\r
128 lbl_title.Text = "-";
\r
129 lbl_chapt.Text = "-";
\r
131 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
\r
133 private void redrawQueue()
\r
135 if (InvokeRequired)
\r
137 BeginInvoke(new UpdateHandler(redrawQueue));
\r
141 list_queue.Items.Clear();
\r
142 List<Queue.QueueItem> theQueue = queue.getQueue();
\r
143 foreach (Queue.QueueItem queue_item in theQueue)
\r
145 string q_item = queue_item.Query;
\r
146 Functions.QueryParser parsed = Functions.QueryParser.Parse(q_item);
\r
148 // Get the DVD Title
\r
149 string title = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();
\r
151 // Get the DVD Chapters
\r
153 if (parsed.DVDChapterStart == 0)
\r
157 chapters = parsed.DVDChapterStart.ToString();
\r
158 if (parsed.DVDChapterFinish != 0)
\r
159 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
162 ListViewItem item = new ListViewItem();
\r
163 item.Text = title; // Title
\r
164 item.SubItems.Add(chapters); // Chapters
\r
165 item.SubItems.Add(queue_item.Source); // Source
\r
166 item.SubItems.Add(queue_item.Destination); // Destination
\r
167 item.SubItems.Add(parsed.VideoEncoder); // Video
\r
169 // Display the first 4 audio tracks.
\r
170 String audio = parsed.AudioEncoder1;
\r
171 if (parsed.AudioEncoder2 != null)
\r
172 audio += ", " + parsed.AudioEncoder2;
\r
174 if (parsed.AudioEncoder3 != null)
\r
175 audio += ", " + parsed.AudioEncoder3;
\r
177 if (parsed.AudioEncoder4 != null)
\r
178 audio += ", " + parsed.AudioEncoder4;
\r
180 item.SubItems.Add(audio); // Audio
\r
182 list_queue.Items.Add(item);
\r
185 private void updateUIElements()
\r
187 if (InvokeRequired)
\r
189 BeginInvoke(new UpdateHandler(updateUIElements));
\r
194 lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
\r
196 private void setCurrentEncodeInformation()
\r
200 if (InvokeRequired)
\r
202 BeginInvoke(new UpdateHandler(setCurrentEncodeInformation));
\r
205 // found query is a global varible
\r
206 Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQueryItem().Query);
\r
207 lbl_source.Text = queue.getLastQueryItem().Source;
\r
208 lbl_dest.Text = queue.getLastQueryItem().Destination;
\r
210 lbl_title.Text = parsed.DVDTitle == 0 ? "Auto" : parsed.DVDTitle.ToString();
\r
212 if (Equals(parsed.DVDChapterStart, 0))
\r
213 lbl_chapt.Text = "Auto";
\r
216 string chapters = parsed.DVDChapterStart.ToString();
\r
217 if (parsed.DVDChapterFinish != 0)
\r
218 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
219 lbl_chapt.Text = chapters;
\r
222 lbl_vEnc.Text = parsed.VideoEncoder;
\r
223 String audio = parsed.AudioEncoder1;
\r
224 if (parsed.AudioEncoder2 != null)
\r
225 audio += ", " + parsed.AudioEncoder2;
\r
227 if (parsed.AudioEncoder3 != null)
\r
228 audio += ", " + parsed.AudioEncoder3;
\r
230 if (parsed.AudioEncoder4 != null)
\r
231 audio += ", " + parsed.AudioEncoder4;
\r
233 lbl_aEnc.Text = audio;
\r
240 private void deleteSelectedItems()
\r
242 // If there are selected items
\r
243 if (list_queue.SelectedIndices.Count > 0)
\r
245 // Save the selected indices to select them after the move
\r
246 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
247 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
248 selectedIndices.Add(selectedIndex);
\r
250 int firstSelectedIndex = selectedIndices[0];
\r
252 // Reverse the list to delete the items from last to first (preserves indices)
\r
253 selectedIndices.Reverse();
\r
255 // Remove each selected item
\r
256 foreach (int selectedIndex in selectedIndices)
\r
257 queue.remove(selectedIndex);
\r
259 queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
\r
260 updateUIElements();
\r
262 // Select the item where the first deleted item was previously
\r
263 if (firstSelectedIndex < list_queue.Items.Count)
\r
264 list_queue.Items[firstSelectedIndex].Selected = true;
\r
267 list_queue.Select(); // Activate the control to show the selected items
\r
270 // Queue Management
\r
271 private void btn_up_Click(object sender, EventArgs e)
\r
273 // If there are selected items and the first item is not selected
\r
274 if (list_queue.SelectedIndices.Count > 0 && ! list_queue.SelectedIndices.Contains(0))
\r
276 // Copy the selected indices to preserve them during the movement
\r
277 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
278 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
279 selectedIndices.Add(selectedIndex);
\r
281 // Move up each selected item
\r
282 foreach (int selectedIndex in selectedIndices)
\r
283 queue.moveUp(selectedIndex);
\r
285 queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
\r
286 updateUIElements();
\r
288 // Keep the selected item(s) selected, now moved up one index
\r
289 foreach (int selectedIndex in selectedIndices)
\r
290 if (selectedIndex - 1 > -1) // Defensive programming: ensure index is good
\r
291 list_queue.Items[selectedIndex - 1].Selected = true;
\r
294 list_queue.Select(); // Activate the control to show the selected items
\r
296 private void btn_down_Click(object sender, EventArgs e)
\r
298 // If there are selected items and the last item is not selected
\r
299 if (list_queue.SelectedIndices.Count > 0 &&
\r
300 ! list_queue.SelectedIndices.Contains(list_queue.Items[list_queue.Items.Count-1].Index))
\r
302 // Copy the selected indices to preserve them during the movement
\r
303 List<int> selectedIndices = new List<int>(list_queue.SelectedIndices.Count);
\r
304 foreach (int selectedIndex in list_queue.SelectedIndices)
\r
305 selectedIndices.Add(selectedIndex);
\r
307 // Reverse the indices to move the items down from last to first (preserves indices)
\r
308 selectedIndices.Reverse();
\r
310 // Move down each selected item
\r
311 foreach (int selectedIndex in selectedIndices)
\r
312 queue.moveDown(selectedIndex);
\r
314 queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
\r
315 updateUIElements();
\r
317 // Keep the selected item(s) selected, now moved down one index
\r
318 foreach (int selectedIndex in selectedIndices)
\r
319 if (selectedIndex + 1 < list_queue.Items.Count) // Defensive programming: ensure index is good
\r
320 list_queue.Items[selectedIndex + 1].Selected = true;
\r
323 list_queue.Select(); // Activate the control to show the selected items
\r
325 private void btn_delete_Click(object sender, EventArgs e)
\r
327 deleteSelectedItems();
\r
329 private void list_queue_deleteKey(object sender, KeyEventArgs e)
\r
331 if (e.KeyCode == Keys.Delete)
\r
332 deleteSelectedItems();
\r
335 // Queue Import/Export Features
\r
336 private void mnu_batch_Click(object sender, EventArgs e)
\r
338 SaveFile.FileName = "";
\r
339 SaveFile.Filter = "Batch|.bat";
\r
340 SaveFile.ShowDialog();
\r
341 if (SaveFile.FileName != String.Empty)
\r
342 queue.writeBatchScript(SaveFile.FileName);
\r
344 private void mnu_export_Click(object sender, EventArgs e)
\r
346 SaveFile.FileName = "";
\r
347 SaveFile.Filter = "HandBrake Queue|*.queue";
\r
348 SaveFile.ShowDialog();
\r
349 if (SaveFile.FileName != String.Empty)
\r
350 queue.write2disk(SaveFile.FileName);
\r
352 private void mnu_import_Click(object sender, EventArgs e)
\r
354 OpenFile.FileName = "";
\r
355 OpenFile.ShowDialog();
\r
356 if (OpenFile.FileName != String.Empty)
\r
357 queue.recoverQueue(OpenFile.FileName);
\r
358 updateUIElements();
\r
360 private void mnu_readd_Click(object sender, EventArgs e)
\r
362 if (queue.getLastQueryItem() != null)
\r
364 queue.add(queue.getLastQueryItem().Query, queue.getLastQueryItem().Source, queue.getLastQueryItem().Destination);
\r
365 queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
\r
366 updateUIElements();
\r
370 // Hide's the window when the user tries to "x" out of the window instead of closing it.
\r
371 protected override void OnClosing(CancelEventArgs e)
\r