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.Collections;
\r
10 using System.ComponentModel;
\r
12 using System.Drawing;
\r
14 using System.Windows.Forms;
\r
15 using System.Threading;
\r
16 using System.Diagnostics;
\r
17 using System.Runtime.InteropServices;
\r
22 public partial class frmQueue : Form
\r
24 private delegate void ProgressUpdateHandler();
\r
25 private delegate void setEncoding();
\r
26 Functions.Encode cliObj = new Functions.Encode();
\r
27 Boolean cancel = false;
\r
28 Process hbProc = null;
\r
29 Functions.Queue queue;
\r
33 InitializeComponent();
\r
37 /// Initializes the Queue list with the Arraylist from the Queue class
\r
39 /// <param name="qw"></param>
\r
40 public void setQueue(Functions.Queue qw)
\r
47 /// Returns if there is currently an item being encoded by the queue
\r
49 /// <returns>Boolean true if encoding</returns>
\r
50 public Boolean isEncoding()
\r
58 // Redraw's the queue with the latest data from the Queue class
\r
59 private void redrawQueue()
\r
61 list_queue.Items.Clear();
\r
62 foreach (ArrayList queue_item in queue.getQueue())
\r
64 string q_item = queue_item[1].ToString();
\r
65 Functions.QueryParser parsed = Functions.QueryParser.Parse(q_item);
\r
67 // Get the DVD Title
\r
69 if (parsed.DVDTitle == 0)
\r
72 title = parsed.DVDTitle.ToString();
\r
74 // Get the DVD Chapters
\r
75 string chapters = "";
\r
76 if (parsed.DVDChapterStart == 0)
\r
80 chapters = parsed.DVDChapterStart.ToString();
\r
81 if (parsed.DVDChapterFinish != 0)
\r
82 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
85 ListViewItem item = new ListViewItem();
\r
86 item.Text = title; // Title
\r
87 item.SubItems.Add(chapters); // Chapters
\r
88 item.SubItems.Add(parsed.Source); // Source
\r
89 item.SubItems.Add(parsed.Destination); // Destination
\r
90 item.SubItems.Add(parsed.VideoEncoder); // Video
\r
91 item.SubItems.Add(parsed.AudioEncoder1); // Audio
\r
93 list_queue.Items.Add(item);
\r
97 // Initializes the encode process
\r
98 private void btn_encode_Click(object sender, EventArgs e)
\r
100 if (queue.count() != 0)
\r
102 btn_encode.Enabled = false;
\r
106 // Start the encode
\r
109 if (queue.count() != 0)
\r
111 // Setup or reset some values
\r
112 btn_stop.Visible = true;
\r
113 progressBar.Value = 0;
\r
114 lbl_progressValue.Text = "0 %";
\r
115 progressBar.Step = 100 / queue.count();
\r
116 Thread theQ = new Thread(startProc);
\r
117 theQ.IsBackground = true;
\r
121 catch (Exception exc)
\r
123 MessageBox.Show(exc.ToString());
\r
127 // Starts the encoding process
\r
128 private void startProc(object state)
\r
132 // Run through each item on the queue
\r
133 while (queue.count() != 0)
\r
135 string query = queue.getNextItemForEncoding();
\r
138 updateUIElements();
\r
140 hbProc = cliObj.runCli(this, query);
\r
142 hbProc.WaitForExit();
\r
149 if (cancel == true)
\r
157 // After the encode is done, we may want to shutdown, suspend etc.
\r
158 cliObj.afterEncodeAction();
\r
160 catch (Exception exc)
\r
162 MessageBox.Show(exc.ToString());
\r
166 // Reset's the window to the default state.
\r
167 private void resetQueue()
\r
171 if (this.InvokeRequired)
\r
173 this.BeginInvoke(new ProgressUpdateHandler(resetQueue));
\r
177 btn_stop.Visible = false;
\r
178 btn_encode.Enabled = true;
\r
180 if (cancel == true)
\r
182 lbl_progressValue.Text = "Encode Queue Cancelled!";
\r
186 lbl_progressValue.Text = "Encode Queue Completed!";
\r
189 progressBar.Value = 0;
\r
191 lbl_source.Text = "-";
\r
192 lbl_dest.Text = "-";
\r
193 lbl_vEnc.Text = "-";
\r
194 lbl_aEnc.Text = "-";
\r
195 lbl_title.Text = "-";
\r
196 lbl_chapt.Text = "-";
\r
198 catch (Exception exc)
\r
200 MessageBox.Show(exc.ToString());
\r
204 // Stop's the queue from continuing.
\r
205 private void btn_stop_Click(object sender, EventArgs e)
\r
208 btn_stop.Visible = false;
\r
209 btn_encode.Enabled = true;
\r
210 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
213 // Updates the progress bar and progress label for a new status.
\r
214 private void updateUIElements()
\r
218 if (this.InvokeRequired)
\r
220 this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
\r
226 progressBar.PerformStep();
\r
227 lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
\r
229 catch (Exception exc)
\r
231 MessageBox.Show(exc.ToString());
\r
235 // Set's the information lables about the current encode.
\r
236 private void setEncValue()
\r
240 if (this.InvokeRequired)
\r
242 this.BeginInvoke(new setEncoding(setEncValue));
\r
245 // found query is a global varible
\r
246 Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQuery());
\r
247 lbl_source.Text = parsed.Source;
\r
248 lbl_dest.Text = parsed.Destination;
\r
251 if (parsed.DVDTitle == 0)
\r
252 lbl_title.Text = "Auto";
\r
254 lbl_title.Text = parsed.DVDTitle.ToString();
\r
256 string chapters = "";
\r
257 if (parsed.DVDChapterStart == 0)
\r
259 lbl_chapt.Text = "Auto";
\r
263 chapters = parsed.DVDChapterStart.ToString();
\r
264 if (parsed.DVDChapterFinish != 0)
\r
265 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
266 lbl_chapt.Text = chapters;
\r
269 lbl_vEnc.Text = parsed.VideoEncoder;
\r
270 lbl_aEnc.Text = parsed.AudioEncoder1;
\r
278 // Move an item up the Queue
\r
279 private void btn_up_Click(object sender, EventArgs e)
\r
281 if (list_queue.SelectedIndices.Count != 0)
\r
283 queue.moveUp(list_queue.SelectedIndices[0]);
\r
284 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
289 // Move an item down the Queue
\r
290 private void btn_down_Click(object sender, EventArgs e)
\r
292 if (list_queue.SelectedIndices.Count != 0)
\r
294 queue.moveDown(list_queue.SelectedIndices[0]);
\r
295 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
300 // Remove an item from the queue
\r
301 private void btn_delete_Click(object sender, EventArgs e)
\r
303 if (list_queue.SelectedIndices.Count != 0)
\r
305 queue.remove(list_queue.SelectedIndices[0]);
\r
306 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
311 // Generate a Saveable batch script on the users request
\r
312 private void mnu_batch_Click(object sender, EventArgs e)
\r
314 SaveFile.Filter = "Batch|.bat";
\r
315 SaveFile.ShowDialog();
\r
316 if (SaveFile.FileName != String.Empty)
\r
317 queue.writeBatchScript(SaveFile.FileName);
\r
320 // Export the HandBrake Queue to a file.
\r
321 private void mnu_export_Click(object sender, EventArgs e)
\r
323 SaveFile.Filter = "HandBrake Queue|*.queue";
\r
324 SaveFile.ShowDialog();
\r
325 if (SaveFile.FileName != String.Empty)
\r
326 queue.write2disk(SaveFile.FileName);
\r
329 // Import an exported queue
\r
330 private void mnu_import_Click(object sender, EventArgs e)
\r
332 OpenFile.ShowDialog();
\r
333 if (OpenFile.FileName != String.Empty)
\r
334 queue.recoverQueue(OpenFile.FileName);
\r
338 // Delete a selected item on the queue, if the delete key is pressed.
\r
339 private void list_queue_deleteKey(object sender, KeyEventArgs e)
\r
341 if (e.KeyCode == Keys.Delete)
\r
343 if (list_queue.SelectedIndices.Count != 0)
\r
345 queue.remove(list_queue.SelectedIndices[0]);
\r
346 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
352 // Hide's the window from the users view.
\r
353 private void btn_Close_Click(object sender, EventArgs e)
\r
358 // Hide's the window when the user tries to "x" out of the window instead of closing it.
\r
359 protected override void OnClosing(CancelEventArgs e)
\r