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
46 catch (Exception exc)
\r
48 MessageBox.Show(exc.ToString());
\r
52 private void btn_cancel_Click(object sender, EventArgs e)
\r
55 btn_cancel.Visible = false;
\r
56 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
59 [DllImport("user32.dll")]
\r
60 public static extern void LockWorkStation();
\r
61 [DllImport("user32.dll")]
\r
62 public static extern int ExitWindowsEx(int uFlags, int dwReason);
\r
64 private void startProc(object state)
\r
68 while (list_queue.Items.Count != 0)
\r
70 string query = list_queue.Items[0].ToString();
\r
74 Functions.CLI process = new Functions.CLI();
\r
75 Process hbProc = process.runCli(this, query, false, false, false, false);
\r
77 hbProc.WaitForExit();
\r
93 // Do something whent he encode ends.
\r
94 switch (Properties.Settings.Default.CompletionOption)
\r
97 System.Diagnostics.Process.Start("Shutdown", "-s -t 60");
\r
100 ExitWindowsEx(0, 0);
\r
103 Application.SetSuspendState(PowerState.Suspend, true, true);
\r
106 Application.SetSuspendState(PowerState.Hibernate, true, true);
\r
108 case "Lock System":
\r
111 case "Quit HandBrake":
\r
112 Application.Exit();
\r
118 catch (Exception exc)
\r
120 MessageBox.Show(exc.ToString());
\r
124 private void updateUIElements()
\r
128 if (this.InvokeRequired)
\r
130 this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));
\r
133 this.list_queue.Items.RemoveAt(0);
\r
135 progressBar.PerformStep();
\r
136 lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
\r
137 progressBar.Update();
\r
139 catch (Exception exc)
\r
141 MessageBox.Show(exc.ToString());
\r
145 private void resetQueue()
\r
149 if (this.InvokeRequired)
\r
151 this.BeginInvoke(new ProgressUpdateHandler(resetQueue));
\r
155 if (cancel == true)
\r
157 lbl_status.Visible = true;
\r
158 lbl_status.Text = "Encode Queue Cancelled!";
\r
162 lbl_status.Visible = true;
\r
163 lbl_status.Text = "Encode Queue Completed!";
\r
165 btn_cancel.Visible = false;
\r
167 lbl_progressValue.Text = "0 %";
\r
168 progressBar.Value = 0;
\r
169 progressBar.Update();
\r
171 catch (Exception exc)
\r
173 MessageBox.Show(exc.ToString());
\r
179 #region Queue Management
\r
180 private void btn_up_Click(object sender, EventArgs e)
\r
182 int count = list_queue.Items.Count;
\r
183 int itemToMove = list_queue.SelectedIndex;
\r
184 int previousItemint = 0;
\r
185 String previousItem = "";
\r
187 if (itemToMove > 0)
\r
189 previousItemint = itemToMove - 1;
\r
190 previousItem = list_queue.Items[previousItemint].ToString();
\r
191 list_queue.Items[previousItemint] = list_queue.Items[itemToMove];
\r
192 list_queue.Items[itemToMove] = previousItem;
\r
193 list_queue.SelectedIndex = list_queue.SelectedIndex - 1;
\r
197 private void btn_down_Click(object sender, EventArgs e)
\r
199 int count = list_queue.Items.Count;
\r
200 int itemToMove = list_queue.SelectedIndex;
\r
201 int itemAfterInt = 0;
\r
202 String itemAfter = "";
\r
204 if (itemToMove < (count - 1))
\r
206 itemAfterInt = itemToMove + 1;
\r
207 itemAfter = list_queue.Items[itemAfterInt].ToString();
\r
208 list_queue.Items[itemAfterInt] = list_queue.Items[itemToMove];
\r
209 list_queue.Items[itemToMove] = itemAfter;
\r
210 list_queue.SelectedIndex = list_queue.SelectedIndex + 1;
\r
214 private void btn_delete_Click(object sender, EventArgs e)
\r
216 list_queue.Items.Remove(list_queue.SelectedItem);
\r
221 private void btn_Close_Click(object sender, EventArgs e)
\r
226 protected override void OnClosing(CancelEventArgs e)
\r