3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.m0k.org/>.
\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
28 InitializeComponent();
\r
31 #region Queue Handling
\r
32 Boolean cancel = false;
\r
34 private void btn_encode_Click(object sender, EventArgs e)
\r
36 // Reset some values
\r
38 if (list_queue.Items.Count != 0)
\r
40 lbl_status.Visible = false;
\r
41 btn_encode.Enabled = false;
\r
48 if (list_queue.Items.Count != 0)
\r
50 // Setup or reset some values
\r
51 btn_stop.Visible = true;
\r
52 progressBar.Value = 0;
\r
53 lbl_progressValue.Text = "0 %";
\r
54 progressBar.Step = 100 / list_queue.Items.Count;
\r
55 progressBar.Update();
\r
56 //ThreadPool.QueueUserWorkItem(startProc);
\r
57 // Testing a new way of launching a thread. Hopefully will fix a random freeze up of the main thread.
\r
58 Thread theQ = new Thread(startProc);
\r
62 catch (Exception exc)
\r
64 MessageBox.Show(exc.ToString());
\r
68 private void btn_stop_Click(object sender, EventArgs e)
\r
71 btn_stop.Visible = false;
\r
72 btn_encode.Enabled = true;
\r
73 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
76 [DllImport("user32.dll")]
\r
77 public static extern void LockWorkStation();
\r
78 [DllImport("user32.dll")]
\r
79 public static extern int ExitWindowsEx(int uFlags, int dwReason);
\r
81 private void startProc(object state)
\r
85 while (list_queue.Items.Count != 0)
\r
87 string query = list_queue.Items[0].ToString();
\r
91 Functions.CLI process = new Functions.CLI();
\r
92 Process hbProc = process.runCli(this, query, false, false, false, false);
\r
94 hbProc.WaitForExit();
\r
100 if (cancel == true)
\r
108 // Do something whent he encode ends.
\r
109 switch (Properties.Settings.Default.CompletionOption)
\r
112 System.Diagnostics.Process.Start("Shutdown", "-s -t 60");
\r
115 ExitWindowsEx(0, 0);
\r
118 Application.SetSuspendState(PowerState.Suspend, true, true);
\r
121 Application.SetSuspendState(PowerState.Hibernate, true, true);
\r
123 case "Lock System":
\r
126 case "Quit HandBrake":
\r
127 Application.Exit();
\r
133 catch (Exception exc)
\r
135 MessageBox.Show(exc.ToString());
\r
139 private void updateUIElements()
\r
143 if (this.InvokeRequired)
\r
145 this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
\r
148 this.list_queue.Items.RemoveAt(0);
\r
150 progressBar.PerformStep();
\r
151 lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
\r
152 progressBar.Update();
\r
154 catch (Exception exc)
\r
156 MessageBox.Show(exc.ToString());
\r
160 private void resetQueue()
\r
164 if (this.InvokeRequired)
\r
166 this.BeginInvoke(new ProgressUpdateHandler(resetQueue));
\r
170 btn_stop.Visible = false;
\r
171 btn_encode.Enabled = true;
\r
173 if (cancel == true)
\r
175 lbl_status.Visible = true;
\r
176 lbl_status.Text = "Encode Queue Cancelled!";
\r
177 text_edit.Text = "";
\r
181 lbl_status.Visible = true;
\r
182 lbl_status.Text = "Encode Queue Completed!";
\r
183 text_edit.Text = "";
\r
186 lbl_progressValue.Text = "0 %";
\r
187 progressBar.Value = 0;
\r
188 progressBar.Update();
\r
190 lbl_source.Text = "-";
\r
191 lbl_dest.Text = "-";
\r
192 lbl_vEnc.Text = "-";
\r
193 lbl_aEnc.Text = "-";
\r
194 lbl_title.Text = "-";
\r
195 lbl_chapt.Text = "-";
\r
197 catch (Exception exc)
\r
199 MessageBox.Show(exc.ToString());
\r
203 private void setEncValue()
\r
207 if (this.InvokeRequired)
\r
209 this.BeginInvoke(new setEncoding(setEncValue));
\r
212 string query = query = list_queue.Items[0].ToString();
\r
214 // found query is a global varible
\r
215 Functions.QueryParser parsed = Functions.QueryParser.Parse(query);
\r
216 lbl_source.Text = parsed.Source;
\r
217 lbl_dest.Text = parsed.Destination;
\r
220 if (parsed.DVDTitle == 0)
\r
221 lbl_title.Text = "Auto";
\r
223 lbl_title.Text = parsed.DVDTitle.ToString();
\r
225 string chapters = "";
\r
226 if (parsed.DVDChapterStart == 0)
\r
228 lbl_chapt.Text = "Auto";
\r
232 chapters = parsed.DVDChapterStart.ToString();
\r
233 if (parsed.DVDChapterFinish != 0)
\r
234 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
235 lbl_chapt.Text = chapters;
\r
238 lbl_vEnc.Text = parsed.VideoEncoder;
\r
239 lbl_aEnc.Text = parsed.AudioEncoder;
\r
249 #region Queue Management
\r
251 private void btn_up_Click(object sender, EventArgs e)
\r
253 int count = list_queue.Items.Count;
\r
254 int itemToMove = list_queue.SelectedIndex;
\r
255 int previousItemint = 0;
\r
256 String previousItem = "";
\r
258 if (itemToMove > 0)
\r
260 previousItemint = itemToMove - 1;
\r
261 previousItem = list_queue.Items[previousItemint].ToString();
\r
262 list_queue.Items[previousItemint] = list_queue.Items[itemToMove];
\r
263 list_queue.Items[itemToMove] = previousItem;
\r
264 list_queue.SelectedIndex = list_queue.SelectedIndex - 1;
\r
268 private void btn_down_Click(object sender, EventArgs e)
\r
270 int count = list_queue.Items.Count;
\r
271 int itemToMove = list_queue.SelectedIndex;
\r
272 int itemAfterInt = 0;
\r
273 String itemAfter = "";
\r
275 if (itemToMove < (count - 1))
\r
277 itemAfterInt = itemToMove + 1;
\r
278 itemAfter = list_queue.Items[itemAfterInt].ToString();
\r
279 list_queue.Items[itemAfterInt] = list_queue.Items[itemToMove];
\r
280 list_queue.Items[itemToMove] = itemAfter;
\r
281 list_queue.SelectedIndex = list_queue.SelectedIndex + 1;
\r
285 private void btn_delete_Click(object sender, EventArgs e)
\r
287 list_queue.Items.Remove(list_queue.SelectedItem);
\r
292 #region Queue Item Modification
\r
296 private void btn_updateQuery_Click(object sender, EventArgs e)
\r
298 if (text_edit.Text != "")
\r
300 if (list_queue.Items.Count != listCount)
\r
302 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
306 if (list_queue.SelectedItem != null)
\r
307 list_queue.Items[list_queue.SelectedIndex] = text_edit.Text;
\r
313 private void list_queue_SelectedIndexChanged(object sender, EventArgs e)
\r
315 if (list_queue.SelectedItem != null)
\r
316 text_edit.Text = list_queue.SelectedItem.ToString();
\r
318 listCount = list_queue.Items.Count;
\r
323 #region Queue Save & Batch Script
\r
324 private void btn_batch_Click(object sender, EventArgs e)
\r
326 string queries = "";
\r
327 for (int i = 0; i < list_queue.Items.Count; i++)
\r
329 string query = list_queue.Items[i].ToString();
\r
330 string fullQuery = '"' + Application.StartupPath.ToString()+ "\\HandBrakeCLI.exe"+ '"' + query;
\r
333 queries = queries + fullQuery;
\r
335 queries = queries + " && " + fullQuery;
\r
337 string strCmdLine = queries;
\r
339 SaveFile.ShowDialog();
\r
340 string filename = SaveFile.FileName;
\r
342 if (filename != "")
\r
346 // Create a StreamWriter and open the file
\r
347 StreamWriter line = new StreamWriter(filename);
\r
349 // Write the batch file query to the file
\r
350 line.WriteLine(strCmdLine);
\r
352 // close the stream
\r
355 MessageBox.Show("Your batch script has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
359 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
368 private void btn_Close_Click(object sender, EventArgs e)
\r
373 protected override void OnClosing(CancelEventArgs e)
\r