2 using System.Collections.Generic;
\r
3 using System.ComponentModel;
\r
5 using System.Drawing;
\r
7 using System.Windows.Forms;
\r
8 using System.Threading;
\r
9 using System.Diagnostics;
\r
10 using System.Runtime.InteropServices;
\r
15 public partial class frmQueue : Form
\r
17 private delegate void ProgressUpdateHandler();
\r
18 private delegate void setEncoding();
\r
22 InitializeComponent();
\r
25 #region Queue Handling
\r
26 Boolean cancel = false;
\r
28 private void btn_encode_Click(object sender, EventArgs e)
\r
30 // Reset some values
\r
32 lbl_status.Visible = false;
\r
38 if (list_queue.Items.Count != 0)
\r
40 // Setup or reset some values
\r
41 btn_stop.Visible = true;
\r
42 progressBar.Value = 0;
\r
43 lbl_progressValue.Text = "0 %";
\r
44 progressBar.Step = 100 / list_queue.Items.Count;
\r
45 progressBar.Update();
\r
46 //ThreadPool.QueueUserWorkItem(startProc);
\r
47 // Testing a new way of launching a thread. Hopefully will fix a random freeze up of the main thread.
\r
48 Thread theQ = new Thread(startProc);
\r
52 catch (Exception exc)
\r
54 MessageBox.Show(exc.ToString());
\r
58 private void btn_stop_Click(object sender, EventArgs e)
\r
61 btn_stop.Visible = false;
\r
62 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
65 [DllImport("user32.dll")]
\r
66 public static extern void LockWorkStation();
\r
67 [DllImport("user32.dll")]
\r
68 public static extern int ExitWindowsEx(int uFlags, int dwReason);
\r
70 private void startProc(object state)
\r
74 while (list_queue.Items.Count != 0)
\r
76 string query = list_queue.Items[0].ToString();
\r
80 Functions.CLI process = new Functions.CLI();
\r
81 Process hbProc = process.runCli(this, query, false, false, false, false);
\r
83 hbProc.WaitForExit();
\r
98 // Do something whent he encode ends.
\r
99 switch (Properties.Settings.Default.CompletionOption)
\r
102 System.Diagnostics.Process.Start("Shutdown", "-s -t 60");
\r
105 ExitWindowsEx(0, 0);
\r
108 Application.SetSuspendState(PowerState.Suspend, true, true);
\r
111 Application.SetSuspendState(PowerState.Hibernate, true, true);
\r
113 case "Lock System":
\r
116 case "Quit HandBrake":
\r
117 Application.Exit();
\r
123 catch (Exception exc)
\r
125 MessageBox.Show(exc.ToString());
\r
129 private void updateUIElements()
\r
133 if (this.InvokeRequired)
\r
135 this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
\r
138 this.list_queue.Items.RemoveAt(0);
\r
140 progressBar.PerformStep();
\r
141 lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
\r
142 progressBar.Update();
\r
144 catch (Exception exc)
\r
146 MessageBox.Show(exc.ToString());
\r
150 private void resetQueue()
\r
154 if (this.InvokeRequired)
\r
156 this.BeginInvoke(new ProgressUpdateHandler(resetQueue));
\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
172 btn_stop.Visible = false;
\r
174 lbl_progressValue.Text = "0 %";
\r
175 progressBar.Value = 0;
\r
176 progressBar.Update();
\r
178 lbl_source.Text = "-";
\r
179 lbl_dest.Text = "-";
\r
180 lbl_vEnc.Text = "-";
\r
181 lbl_aEnc.Text = "-";
\r
182 lbl_title.Text = "-";
\r
183 lbl_chapt.Text = "-";
\r
185 catch (Exception exc)
\r
187 MessageBox.Show(exc.ToString());
\r
191 private void setEncValue()
\r
195 if (this.InvokeRequired)
\r
197 this.BeginInvoke(new setEncoding(setEncValue));
\r
200 string query = query = list_queue.Items[0].ToString();
\r
202 // found query is a global varible
\r
203 Functions.QueryParser parsed = Functions.QueryParser.Parse(query);
\r
204 lbl_source.Text = parsed.Source;
\r
205 lbl_dest.Text = parsed.Destination;
\r
208 if (parsed.DVDTitle == 0)
\r
209 lbl_title.Text = "Auto";
\r
211 lbl_title.Text = parsed.DVDTitle.ToString();
\r
213 string chapters = "";
\r
214 if (parsed.DVDChapterStart == 0)
\r
216 lbl_chapt.Text = "Auto";
\r
220 chapters = parsed.DVDChapterStart.ToString();
\r
221 if (parsed.DVDChapterFinish != 0)
\r
222 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
223 lbl_chapt.Text = chapters;
\r
226 lbl_vEnc.Text = parsed.VideoEncoder;
\r
227 lbl_aEnc.Text = parsed.AudioEncoder;
\r
237 #region Queue Management
\r
239 private void btn_up_Click(object sender, EventArgs e)
\r
241 int count = list_queue.Items.Count;
\r
242 int itemToMove = list_queue.SelectedIndex;
\r
243 int previousItemint = 0;
\r
244 String previousItem = "";
\r
246 if (itemToMove > 0)
\r
248 previousItemint = itemToMove - 1;
\r
249 previousItem = list_queue.Items[previousItemint].ToString();
\r
250 list_queue.Items[previousItemint] = list_queue.Items[itemToMove];
\r
251 list_queue.Items[itemToMove] = previousItem;
\r
252 list_queue.SelectedIndex = list_queue.SelectedIndex - 1;
\r
256 private void btn_down_Click(object sender, EventArgs e)
\r
258 int count = list_queue.Items.Count;
\r
259 int itemToMove = list_queue.SelectedIndex;
\r
260 int itemAfterInt = 0;
\r
261 String itemAfter = "";
\r
263 if (itemToMove < (count - 1))
\r
265 itemAfterInt = itemToMove + 1;
\r
266 itemAfter = list_queue.Items[itemAfterInt].ToString();
\r
267 list_queue.Items[itemAfterInt] = list_queue.Items[itemToMove];
\r
268 list_queue.Items[itemToMove] = itemAfter;
\r
269 list_queue.SelectedIndex = list_queue.SelectedIndex + 1;
\r
273 private void btn_delete_Click(object sender, EventArgs e)
\r
275 list_queue.Items.Remove(list_queue.SelectedItem);
\r
280 #region Queue Item Modification
\r
284 private void btn_updateQuery_Click(object sender, EventArgs e)
\r
286 if (text_edit.Text != "")
\r
288 if (list_queue.Items.Count != listCount)
\r
290 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
294 if (list_queue.SelectedItem != null)
\r
295 list_queue.Items[list_queue.SelectedIndex] = text_edit.Text;
\r
301 private void list_queue_SelectedIndexChanged(object sender, EventArgs e)
\r
303 if (list_queue.SelectedItem != null)
\r
304 text_edit.Text = list_queue.SelectedItem.ToString();
\r
306 listCount = list_queue.Items.Count;
\r
311 #region Queue Save & Batch Script
\r
312 private void btn_batch_Click(object sender, EventArgs e)
\r
314 string queries = "";
\r
315 for (int i = 0; i < list_queue.Items.Count; i++)
\r
317 string query = list_queue.Items[i].ToString();
\r
318 string fullQuery = '"' + Application.StartupPath.ToString()+ "\\HandBrakeCLI.exe"+ '"' + query;
\r
321 queries = queries + fullQuery;
\r
323 queries = queries + " && " + fullQuery;
\r
325 string strCmdLine = queries;
\r
327 SaveFile.ShowDialog();
\r
328 string filename = SaveFile.FileName;
\r
330 if (filename != "")
\r
334 // Create a StreamWriter and open the file
\r
335 StreamWriter line = new StreamWriter(filename);
\r
337 // Write the batch file query to the file
\r
338 line.WriteLine(strCmdLine);
\r
340 // close the stream
\r
343 MessageBox.Show("Your batch script has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
347 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
356 private void btn_Close_Click(object sender, EventArgs e)
\r
361 protected override void OnClosing(CancelEventArgs e)
\r