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
14 public partial class frmQueue : Form
\r
16 private delegate void ProgressUpdateHandler();
\r
17 private delegate void setEncoding();
\r
21 InitializeComponent();
\r
24 #region Queue Handling
\r
25 Boolean cancel = false;
\r
26 private void btn_q_encoder_Click(object sender, EventArgs e)
\r
28 // Reset some values
\r
30 lbl_status.Visible = false;
\r
36 if (list_queue.Items.Count != 0)
\r
38 // Setup or reset some values
\r
39 btn_cancel.Visible = true;
\r
40 progressBar.Value = 0;
\r
41 lbl_progressValue.Text = "0 %";
\r
42 progressBar.Step = 100 / list_queue.Items.Count;
\r
43 progressBar.Update();
\r
44 //ThreadPool.QueueUserWorkItem(startProc);
\r
45 // Testing a new way of launching a thread. Hopefully will fix a random freeze up of the main thread.
\r
46 Thread theQ = new Thread(startProc);
\r
50 catch (Exception exc)
\r
52 MessageBox.Show(exc.ToString());
\r
56 private void btn_cancel_Click(object sender, EventArgs e)
\r
59 btn_cancel.Visible = false;
\r
60 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
63 [DllImport("user32.dll")]
\r
64 public static extern void LockWorkStation();
\r
65 [DllImport("user32.dll")]
\r
66 public static extern int ExitWindowsEx(int uFlags, int dwReason);
\r
68 private void startProc(object state)
\r
72 while (list_queue.Items.Count != 0)
\r
74 string query = list_queue.Items[0].ToString();
\r
78 Functions.CLI process = new Functions.CLI();
\r
79 Process hbProc = process.runCli(this, query, false, false, false, false);
\r
81 hbProc.WaitForExit();
\r
96 // Do something whent he encode ends.
\r
97 switch (Properties.Settings.Default.CompletionOption)
\r
100 System.Diagnostics.Process.Start("Shutdown", "-s -t 60");
\r
103 ExitWindowsEx(0, 0);
\r
106 Application.SetSuspendState(PowerState.Suspend, true, true);
\r
109 Application.SetSuspendState(PowerState.Hibernate, true, true);
\r
111 case "Lock System":
\r
114 case "Quit HandBrake":
\r
115 Application.Exit();
\r
121 catch (Exception exc)
\r
123 MessageBox.Show(exc.ToString());
\r
127 private void updateUIElements()
\r
131 if (this.InvokeRequired)
\r
133 this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
\r
136 this.list_queue.Items.RemoveAt(0);
\r
138 progressBar.PerformStep();
\r
139 lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
\r
140 progressBar.Update();
\r
142 catch (Exception exc)
\r
144 MessageBox.Show(exc.ToString());
\r
148 private void resetQueue()
\r
152 if (this.InvokeRequired)
\r
154 this.BeginInvoke(new ProgressUpdateHandler(resetQueue));
\r
158 if (cancel == true)
\r
160 lbl_status.Visible = true;
\r
161 lbl_status.Text = "Encode Queue Cancelled!";
\r
162 text_edit.Text = "";
\r
166 lbl_status.Visible = true;
\r
167 lbl_status.Text = "Encode Queue Completed!";
\r
168 text_edit.Text = "";
\r
170 btn_cancel.Visible = false;
\r
172 lbl_progressValue.Text = "0 %";
\r
173 progressBar.Value = 0;
\r
174 progressBar.Update();
\r
176 lbl_source.Text = "-";
\r
177 lbl_dest.Text = "-";
\r
178 lbl_vEnc.Text = "-";
\r
179 lbl_aEnc.Text = "-";
\r
180 lbl_title.Text = "-";
\r
181 lbl_chapt.Text = "-";
\r
183 catch (Exception exc)
\r
185 MessageBox.Show(exc.ToString());
\r
189 private void setEncValue()
\r
193 if (this.InvokeRequired)
\r
195 this.BeginInvoke(new setEncoding(setEncValue));
\r
198 string query = query = list_queue.Items[0].ToString();
\r
200 // found query is a global varible
\r
201 Functions.QueryParser parsed = Functions.QueryParser.Parse(query);
\r
202 lbl_source.Text = parsed.Source;
\r
203 lbl_dest.Text = parsed.Destination;
\r
206 if (parsed.DVDTitle == 0)
\r
207 lbl_title.Text = "Auto";
\r
209 lbl_title.Text = parsed.DVDTitle.ToString();
\r
211 string chapters = "";
\r
212 if (parsed.DVDChapterStart == 0)
\r
214 lbl_chapt.Text = "Auto";
\r
218 chapters = parsed.DVDChapterStart.ToString();
\r
219 if (parsed.DVDChapterFinish != 0)
\r
220 chapters = chapters + " - " + parsed.DVDChapterFinish;
\r
221 lbl_chapt.Text = chapters;
\r
224 lbl_vEnc.Text = parsed.VideoEncoder;
\r
225 lbl_aEnc.Text = parsed.AudioEncoder;
\r
235 #region Queue Management
\r
237 private void btn_up_Click(object sender, EventArgs e)
\r
239 int count = list_queue.Items.Count;
\r
240 int itemToMove = list_queue.SelectedIndex;
\r
241 int previousItemint = 0;
\r
242 String previousItem = "";
\r
244 if (itemToMove > 0)
\r
246 previousItemint = itemToMove - 1;
\r
247 previousItem = list_queue.Items[previousItemint].ToString();
\r
248 list_queue.Items[previousItemint] = list_queue.Items[itemToMove];
\r
249 list_queue.Items[itemToMove] = previousItem;
\r
250 list_queue.SelectedIndex = list_queue.SelectedIndex - 1;
\r
254 private void btn_down_Click(object sender, EventArgs e)
\r
256 int count = list_queue.Items.Count;
\r
257 int itemToMove = list_queue.SelectedIndex;
\r
258 int itemAfterInt = 0;
\r
259 String itemAfter = "";
\r
261 if (itemToMove < (count - 1))
\r
263 itemAfterInt = itemToMove + 1;
\r
264 itemAfter = list_queue.Items[itemAfterInt].ToString();
\r
265 list_queue.Items[itemAfterInt] = list_queue.Items[itemToMove];
\r
266 list_queue.Items[itemToMove] = itemAfter;
\r
267 list_queue.SelectedIndex = list_queue.SelectedIndex + 1;
\r
271 private void btn_delete_Click(object sender, EventArgs e)
\r
273 list_queue.Items.Remove(list_queue.SelectedItem);
\r
278 #region Queue Item Modification
\r
282 private void btn_updateQuery_Click(object sender, EventArgs e)
\r
284 if (text_edit.Text != "")
\r
286 if (list_queue.Items.Count != listCount)
\r
288 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
292 if (list_queue.SelectedItem != null)
\r
300 private void list_queue_SelectedIndexChanged(object sender, EventArgs e)
\r
302 if (list_queue.SelectedItem != null)
\r
303 text_edit.Text = list_queue.SelectedItem.ToString();
\r
305 listCount = list_queue.Items.Count;
\r
310 private void btn_Close_Click(object sender, EventArgs e)
\r
315 protected override void OnClosing(CancelEventArgs e)
\r