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
136 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
139 updateUIElements();
\r
141 hbProc = cliObj.runCli(this, query);
\r
143 hbProc.WaitForExit();
\r
150 if (cancel == true)
\r
158 // After the encode is done, we may want to shutdown, suspend etc.
\r
159 cliObj.afterEncodeAction();
\r
161 catch (Exception exc)
\r
163 MessageBox.Show(exc.ToString());
\r
167 // Reset's the window to the default state.
\r
168 private void resetQueue()
\r
172 if (this.InvokeRequired)
\r
174 this.BeginInvoke(new ProgressUpdateHandler(resetQueue));
\r
178 btn_stop.Visible = false;
\r
179 btn_encode.Enabled = true;
\r
181 if (cancel == true)
\r
183 lbl_progressValue.Text = "Encode Queue Cancelled!";
\r
187 lbl_progressValue.Text = "Encode Queue Completed!";
\r
190 progressBar.Value = 0;
\r
192 lbl_source.Text = "-";
\r
193 lbl_dest.Text = "-";
\r
194 lbl_vEnc.Text = "-";
\r
195 lbl_aEnc.Text = "-";
\r
196 lbl_title.Text = "-";
\r
197 lbl_chapt.Text = "-";
\r
199 catch (Exception exc)
\r
201 MessageBox.Show(exc.ToString());
\r
205 // Stop's the queue from continuing.
\r
206 private void btn_stop_Click(object sender, EventArgs e)
\r
209 btn_stop.Visible = false;
\r
210 btn_encode.Enabled = true;
\r
211 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
214 // Updates the progress bar and progress label for a new status.
\r
215 private void updateUIElements()
\r
219 if (this.InvokeRequired)
\r
221 this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
\r
227 progressBar.PerformStep();
\r
228 lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
\r
230 catch (Exception exc)
\r
232 MessageBox.Show(exc.ToString());
\r
236 // Set's the information lables about the current encode.
\r
237 private void setEncValue()
\r
241 if (this.InvokeRequired)
\r
243 this.BeginInvoke(new setEncoding(setEncValue));
\r
246 // found query is a global varible
\r
247 Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQuery());
\r
248 lbl_source.Text = parsed.Source;
\r
249 lbl_dest.Text = parsed.Destination;
\r
252 if (parsed.DVDTitle == 0)
\r
253 lbl_title.Text = "Auto";
\r
255 lbl_title.Text = parsed.DVDTitle.ToString();
\r
257 string chapters = "";
\r
258 if (parsed.DVDChapterStart == 0)
\r
260 lbl_chapt.Text = "Auto";
\r
264 chapters = parsed.DVDChapterStart.ToString();
\r
265 if (parsed.DVDChapterFinish != 0)
\r
266 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
267 lbl_chapt.Text = chapters;
\r
270 lbl_vEnc.Text = parsed.VideoEncoder;
\r
271 lbl_aEnc.Text = parsed.AudioEncoder1;
\r
279 // Move an item up the Queue
\r
280 private void btn_up_Click(object sender, EventArgs e)
\r
282 if (list_queue.SelectedIndices.Count != 0)
\r
284 queue.moveUp(list_queue.SelectedIndices[0]);
\r
285 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
290 // Move an item down the Queue
\r
291 private void btn_down_Click(object sender, EventArgs e)
\r
293 if (list_queue.SelectedIndices.Count != 0)
\r
295 queue.moveDown(list_queue.SelectedIndices[0]);
\r
296 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
301 // Remove an item from the queue
\r
302 private void btn_delete_Click(object sender, EventArgs e)
\r
304 if (list_queue.SelectedIndices.Count != 0)
\r
306 queue.remove(list_queue.SelectedIndices[0]);
\r
307 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
312 // Generate a Saveable batch script on the users request
\r
313 private void mnu_batch_Click(object sender, EventArgs e)
\r
315 SaveFile.Filter = "Batch|.bat";
\r
316 SaveFile.ShowDialog();
\r
317 if (SaveFile.FileName != String.Empty)
\r
318 queue.writeBatchScript(SaveFile.FileName);
\r
321 // Export the HandBrake Queue to a file.
\r
322 private void mnu_export_Click(object sender, EventArgs e)
\r
324 SaveFile.Filter = "HandBrake Queue|*.queue";
\r
325 SaveFile.ShowDialog();
\r
326 if (SaveFile.FileName != String.Empty)
\r
327 queue.write2disk(SaveFile.FileName);
\r
330 // Import an exported queue
\r
331 private void mnu_import_Click(object sender, EventArgs e)
\r
333 OpenFile.ShowDialog();
\r
334 if (OpenFile.FileName != String.Empty)
\r
335 queue.recoverQueue(OpenFile.FileName);
\r
339 // Delete a selected item on the queue, if the delete key is pressed.
\r
340 private void list_queue_deleteKey(object sender, KeyEventArgs e)
\r
342 if (e.KeyCode == Keys.Delete)
\r
344 if (list_queue.SelectedIndices.Count != 0)
\r
346 queue.remove(list_queue.SelectedIndices[0]);
\r
347 queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
\r
353 // Hide's the window from the users view.
\r
354 private void btn_Close_Click(object sender, EventArgs e)
\r
359 // Hide's the window when the user tries to "x" out of the window instead of closing it.
\r
360 protected override void OnClosing(CancelEventArgs e)
\r