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
11 using System.Drawing;
\r
13 using System.Windows.Forms;
\r
14 using System.Threading;
\r
15 using System.Diagnostics;
\r
16 using System.Runtime.InteropServices;
\r
21 public partial class frmQueue : Form
\r
23 private delegate void ProgressUpdateHandler();
\r
24 private delegate void setEncoding();
\r
25 Functions.CLI cliObj = new Functions.CLI();
\r
26 Boolean cancel = false;
\r
27 Process hbProc = null;
\r
31 InitializeComponent();
\r
35 #region Queue / Handling
\r
37 public Boolean isEncoding()
\r
45 private void btn_encode_Click(object sender, EventArgs e)
\r
47 // Reset some values
\r
49 if (list_queue.Items.Count != 0)
\r
51 lbl_status.Visible = false;
\r
52 btn_encode.Enabled = false;
\r
59 if (list_queue.Items.Count != 0)
\r
61 // Setup or reset some values
\r
62 btn_stop.Visible = true;
\r
63 progressBar.Value = 0;
\r
64 lbl_progressValue.Text = "0 %";
\r
65 progressBar.Step = 100 / list_queue.Items.Count;
\r
66 progressBar.Update();
\r
67 //ThreadPool.QueueUserWorkItem(startProc);
\r
68 // Testing a new way of launching a thread. Hopefully will fix a random freeze up of the main thread.
\r
69 Thread theQ = new Thread(startProc);
\r
73 catch (Exception exc)
\r
75 MessageBox.Show(exc.ToString());
\r
79 private void btn_stop_Click(object sender, EventArgs e)
\r
82 btn_stop.Visible = false;
\r
83 btn_encode.Enabled = true;
\r
84 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
87 private void startProc(object state)
\r
92 while (list_queue.Items.Count != 0)
\r
94 string query = list_queue.Items[0].ToString();
\r
99 hbProc = cliObj.runCli(this, query);
\r
101 hbProc.WaitForExit();
\r
108 if (cancel == true)
\r
117 // After the encode is done, we may want to shutdown, suspend etc.
\r
118 cliObj.afterEncodeAction();
\r
120 catch (Exception exc)
\r
122 MessageBox.Show(exc.ToString());
\r
126 private void updateUIElements()
\r
130 if (this.InvokeRequired)
\r
132 this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
\r
135 this.list_queue.Items.RemoveAt(0);
\r
137 progressBar.PerformStep();
\r
138 lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
\r
139 progressBar.Update();
\r
141 catch (Exception exc)
\r
143 MessageBox.Show(exc.ToString());
\r
147 private void resetQueue()
\r
151 if (this.InvokeRequired)
\r
153 this.BeginInvoke(new ProgressUpdateHandler(resetQueue));
\r
157 btn_stop.Visible = false;
\r
158 btn_encode.Enabled = true;
\r
160 if (cancel == true)
\r
162 lbl_status.Visible = true;
\r
163 lbl_status.Text = "Encode Queue Cancelled!";
\r
164 text_edit.Text = "";
\r
168 lbl_status.Visible = true;
\r
169 lbl_status.Text = "Encode Queue Completed!";
\r
170 text_edit.Text = "";
\r
173 lbl_progressValue.Text = "0 %";
\r
174 progressBar.Value = 0;
\r
175 progressBar.Update();
\r
177 lbl_source.Text = "-";
\r
178 lbl_dest.Text = "-";
\r
179 lbl_vEnc.Text = "-";
\r
180 lbl_aEnc.Text = "-";
\r
181 lbl_title.Text = "-";
\r
182 lbl_chapt.Text = "-";
\r
184 catch (Exception exc)
\r
186 MessageBox.Show(exc.ToString());
\r
190 private void setEncValue()
\r
194 if (this.InvokeRequired)
\r
196 this.BeginInvoke(new setEncoding(setEncValue));
\r
199 string query = query = list_queue.Items[0].ToString();
\r
201 // found query is a global varible
\r
202 Functions.QueryParser parsed = Functions.QueryParser.Parse(query);
\r
203 lbl_source.Text = parsed.Source;
\r
204 lbl_dest.Text = parsed.Destination;
\r
207 if (parsed.DVDTitle == 0)
\r
208 lbl_title.Text = "Auto";
\r
210 lbl_title.Text = parsed.DVDTitle.ToString();
\r
212 string chapters = "";
\r
213 if (parsed.DVDChapterStart == 0)
\r
215 lbl_chapt.Text = "Auto";
\r
219 chapters = parsed.DVDChapterStart.ToString();
\r
220 if (parsed.DVDChapterFinish != 0)
\r
221 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
222 lbl_chapt.Text = chapters;
\r
225 lbl_vEnc.Text = parsed.VideoEncoder;
\r
226 lbl_aEnc.Text = parsed.AudioEncoder1;
\r
234 private void list_queue_SelectedIndexChanged(object sender, EventArgs e)
\r
236 if (list_queue.SelectedItem != null)
\r
237 text_edit.Text = list_queue.SelectedItem.ToString();
\r
239 listCount = list_queue.Items.Count;
\r
246 private void btn_up_Click(object sender, EventArgs e)
\r
248 int count = list_queue.Items.Count;
\r
249 int itemToMove = list_queue.SelectedIndex;
\r
250 int previousItemint = 0;
\r
251 String previousItem = "";
\r
253 if (itemToMove > 0)
\r
255 previousItemint = itemToMove - 1;
\r
256 previousItem = list_queue.Items[previousItemint].ToString();
\r
257 list_queue.Items[previousItemint] = list_queue.Items[itemToMove];
\r
258 list_queue.Items[itemToMove] = previousItem;
\r
259 list_queue.SelectedIndex = list_queue.SelectedIndex - 1;
\r
263 private void btn_down_Click(object sender, EventArgs e)
\r
265 int count = list_queue.Items.Count;
\r
266 int itemToMove = list_queue.SelectedIndex;
\r
267 int itemAfterInt = 0;
\r
268 String itemAfter = "";
\r
270 if (itemToMove < (count - 1))
\r
272 itemAfterInt = itemToMove + 1;
\r
273 itemAfter = list_queue.Items[itemAfterInt].ToString();
\r
274 list_queue.Items[itemAfterInt] = list_queue.Items[itemToMove];
\r
275 list_queue.Items[itemToMove] = itemAfter;
\r
276 list_queue.SelectedIndex = list_queue.SelectedIndex + 1;
\r
280 private void btn_delete_Click(object sender, EventArgs e)
\r
282 list_queue.Items.Remove(list_queue.SelectedItem);
\r
285 private void btn_batch_Click(object sender, EventArgs e)
\r
287 string queries = "";
\r
288 for (int i = 0; i < list_queue.Items.Count; i++)
\r
290 string query = list_queue.Items[i].ToString();
\r
291 string fullQuery = '"' + Application.StartupPath.ToString() + "\\HandBrakeCLI.exe" + '"' + query;
\r
294 queries = queries + fullQuery;
\r
296 queries = queries + " && " + fullQuery;
\r
298 string strCmdLine = queries;
\r
300 SaveFile.ShowDialog();
\r
301 string filename = SaveFile.FileName;
\r
303 if (filename != "")
\r
307 // Create a StreamWriter and open the file
\r
308 StreamWriter line = new StreamWriter(filename);
\r
310 // Write the batch file query to the file
\r
311 line.WriteLine(strCmdLine);
\r
313 // close the stream
\r
316 MessageBox.Show("Your batch script has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
320 MessageBox.Show("Unable to write to the file. Please make sure that the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
327 private void btn_updateQuery_Click(object sender, EventArgs e)
\r
329 if (text_edit.Text != "")
\r
331 if (list_queue.Items.Count != listCount)
\r
333 MessageBox.Show("Unable to modify the selected item. The number of items on the list has changed. \nPlease avoid modifying an item when a new encode is about to start!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
337 if (list_queue.SelectedItem != null)
\r
338 list_queue.Items[list_queue.SelectedIndex] = text_edit.Text;
\r
344 private void btn_Close_Click(object sender, EventArgs e)
\r
351 protected override void OnClosing(CancelEventArgs e)
\r