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
20 InitializeComponent();
\r
23 #region Queue Handling
\r
24 Boolean cancel = false;
\r
25 private void btn_q_encoder_Click(object sender, EventArgs e)
\r
27 // Reset some values
\r
29 lbl_status.Visible = false;
\r
35 if (list_queue.Items.Count != 0)
\r
37 // Setup or reset some values
\r
38 btn_cancel.Visible = true;
\r
39 progressBar.Value = 0;
\r
40 lbl_progressValue.Text = "0 %";
\r
41 progressBar.Step = 100 / list_queue.Items.Count;
\r
42 progressBar.Update();
\r
43 //ThreadPool.QueueUserWorkItem(startProc);
\r
44 // Testing a new way of launching a thread. Hopefully will fix a random freeze up of the main thread.
\r
45 Thread theQ = new Thread(startProc);
\r
49 catch (Exception exc)
\r
51 MessageBox.Show(exc.ToString());
\r
55 private void btn_cancel_Click(object sender, EventArgs e)
\r
58 btn_cancel.Visible = false;
\r
59 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
62 [DllImport("user32.dll")]
\r
63 public static extern void LockWorkStation();
\r
64 [DllImport("user32.dll")]
\r
65 public static extern int ExitWindowsEx(int uFlags, int dwReason);
\r
67 private void startProc(object state)
\r
71 while (list_queue.Items.Count != 0)
\r
73 string query = list_queue.Items[0].ToString();
\r
77 Functions.CLI process = new Functions.CLI();
\r
78 Process hbProc = process.runCli(this, query, false, false, false, false);
\r
80 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 catch (Exception exc)
\r
178 MessageBox.Show(exc.ToString());
\r
184 #region Queue Management
\r
185 private void btn_up_Click(object sender, EventArgs e)
\r
187 int count = list_queue.Items.Count;
\r
188 int itemToMove = list_queue.SelectedIndex;
\r
189 int previousItemint = 0;
\r
190 String previousItem = "";
\r
192 if (itemToMove > 0)
\r
194 previousItemint = itemToMove - 1;
\r
195 previousItem = list_queue.Items[previousItemint].ToString();
\r
196 list_queue.Items[previousItemint] = list_queue.Items[itemToMove];
\r
197 list_queue.Items[itemToMove] = previousItem;
\r
198 list_queue.SelectedIndex = list_queue.SelectedIndex - 1;
\r
202 private void btn_down_Click(object sender, EventArgs e)
\r
204 int count = list_queue.Items.Count;
\r
205 int itemToMove = list_queue.SelectedIndex;
\r
206 int itemAfterInt = 0;
\r
207 String itemAfter = "";
\r
209 if (itemToMove < (count - 1))
\r
211 itemAfterInt = itemToMove + 1;
\r
212 itemAfter = list_queue.Items[itemAfterInt].ToString();
\r
213 list_queue.Items[itemAfterInt] = list_queue.Items[itemToMove];
\r
214 list_queue.Items[itemToMove] = itemAfter;
\r
215 list_queue.SelectedIndex = list_queue.SelectedIndex + 1;
\r
219 private void btn_delete_Click(object sender, EventArgs e)
\r
221 list_queue.Items.Remove(list_queue.SelectedItem);
\r
225 #region Queue Item Modification
\r
229 private void btn_updateQuery_Click(object sender, EventArgs e)
\r
231 if (text_edit.Text != "")
\r
233 if (list_queue.Items.Count != listCount)
\r
235 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
239 if (list_queue.SelectedItem != null)
\r
240 list_queue.Items[list_queue.SelectedIndex] = text_edit.Text;
\r
245 private void list_queue_SelectedIndexChanged(object sender, EventArgs e)
\r
247 if (list_queue.SelectedItem != null)
\r
248 text_edit.Text = list_queue.SelectedItem.ToString();
\r
250 listCount = list_queue.Items.Count;
\r
254 private void btn_Close_Click(object sender, EventArgs e)
\r
259 protected override void OnClosing(CancelEventArgs e)
\r