using System.Windows.Forms;\r
using System.Threading;\r
using System.Diagnostics;\r
+using System.Runtime.InteropServices;\r
\r
namespace Handbrake\r
{\r
InitializeComponent();\r
}\r
\r
- private void btn_Close_Click(object sender, EventArgs e)\r
+ #region Queue Handling\r
+\r
+ private void btn_q_encoder_Click(object sender, EventArgs e)\r
{\r
- this.Hide();\r
+ if (list_queue.Items.Count != 0)\r
+ {\r
+ progressBar.Value = 0;\r
+ lbl_progressValue.Text = "0 %";\r
+ progressBar.Step = 100 / list_queue.Items.Count;\r
+ progressBar.Update();\r
+ ThreadPool.QueueUserWorkItem(startProc);\r
+ }\r
+ \r
}\r
\r
- private void btn_delete_Click(object sender, EventArgs e)\r
+ [DllImport("user32.dll")]\r
+ public static extern void LockWorkStation();\r
+ [DllImport("user32.dll")]\r
+ public static extern int ExitWindowsEx(int uFlags, int dwReason);\r
+\r
+ private void startProc(object state)\r
{\r
- list_queue.Items.Remove(list_queue.SelectedItem);\r
+ try\r
+ {\r
+ while (list_queue.Items.Count != 0)\r
+ {\r
+ string query = list_queue.Items[0].ToString();\r
+ updateUIElements();\r
+ \r
+ Functions.CLI process = new Functions.CLI();\r
+ Process hbProc = process.runCli(this, query, false, false, false, false);\r
+\r
+ hbProc.WaitForExit();\r
+ hbProc.Close();\r
+ hbProc.Dispose();\r
+ }\r
+\r
+ resetQueue();\r
+\r
+ // Do something whent he encode ends.\r
+ switch (Properties.Settings.Default.CompletionOption)\r
+ {\r
+ case "Shutdown":\r
+ System.Diagnostics.Process.Start("Shutdown", "-s -t 60");\r
+ break;\r
+ case "Log Off":\r
+ ExitWindowsEx(0, 0);\r
+ break;\r
+ case "Suspend":\r
+ Application.SetSuspendState(PowerState.Suspend, true, true);\r
+ break;\r
+ case "Hibernate":\r
+ Application.SetSuspendState(PowerState.Hibernate, true, true);\r
+ break;\r
+ case "Lock System":\r
+ LockWorkStation();\r
+ break;\r
+ case "Quit HandBrake":\r
+ Application.Exit();\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+\r
+ MessageBox.Show("Encode Queue Completed!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show(exc.ToString());\r
+ }\r
+ }\r
+\r
+ private void updateUIElements()\r
+ {\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));\r
+ return;\r
+ }\r
+ this.list_queue.Items.RemoveAt(0);\r
+\r
+ progressBar.PerformStep();\r
+ lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);\r
+ progressBar.Update();\r
+ }\r
+\r
+ private void resetQueue()\r
+ {\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new ProgressUpdateHandler(resetQueue));\r
+ return;\r
+ }\r
+ lbl_progressValue.Text = "0 %";\r
+ progressBar.Value = 0;\r
+ progressBar.Update();\r
}\r
\r
+ #endregion\r
+\r
+ #region Queue Management\r
+\r
private void btn_up_Click(object sender, EventArgs e)\r
{\r
int count = list_queue.Items.Count;\r
int itemToMove = list_queue.SelectedIndex;\r
- int previousItemint = 0; \r
+ int previousItemint = 0;\r
String previousItem = "";\r
\r
- if (itemToMove > 0){\r
+ if (itemToMove > 0)\r
+ {\r
previousItemint = itemToMove - 1;\r
previousItem = list_queue.Items[previousItemint].ToString();\r
list_queue.Items[previousItemint] = list_queue.Items[itemToMove];\r
{\r
int count = list_queue.Items.Count;\r
int itemToMove = list_queue.SelectedIndex;\r
- int itemAfterInt = 0; \r
+ int itemAfterInt = 0;\r
String itemAfter = "";\r
\r
if (itemToMove < (count - 1))\r
}\r
}\r
\r
- private void btn_q_encoder_Click(object sender, EventArgs e)\r
+ private void btn_delete_Click(object sender, EventArgs e)\r
{\r
- progressBar.Value = 0;\r
- lbl_progressValue.Text = "0 %";\r
- progressBar.Step = 100 / list_queue.Items.Count;\r
- progressBar.Update();\r
- ThreadPool.QueueUserWorkItem(startProc);\r
+ list_queue.Items.Remove(list_queue.SelectedItem);\r
}\r
+ #endregion\r
\r
- private void startProc(object state)\r
- {\r
- int initialListCount = list_queue.Items.Count;\r
- for (int i = 0; i < initialListCount; i++)\r
- {\r
- string query = list_queue.Items[0].ToString();\r
-\r
- Functions.CLI process = new Functions.CLI();\r
- Process hbProc = process.runCli(this, query, false, false, false, false);\r
- \r
- hbProc.WaitForExit();\r
- hbProc.Close();\r
- hbProc.Dispose();\r
+ #region Window Management\r
\r
- updateUIElements();\r
- }\r
+ private void btn_Close_Click(object sender, EventArgs e)\r
+ {\r
+ this.Hide();\r
}\r
\r
- private void updateUIElements()\r
+ private void btn_minimise_Click(object sender, EventArgs e)\r
{\r
- if (this.InvokeRequired)\r
- {\r
- this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));\r
- return;\r
- }\r
- this.list_queue.Items.RemoveAt(0);\r
- progressBar.PerformStep();\r
- lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);\r
- progressBar.Update();\r
-\r
- if (progressBar.Value == 100)\r
- {\r
- MessageBox.Show("Encode Queue Completed!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
- progressBar.Value = 0;\r
- progressBar.Update();\r
- lbl_progressValue.Text = "0 %";\r
- }\r
+ this.WindowState = FormWindowState.Minimized;\r
}\r
+\r
+ #endregion\r
+\r
}\r
}
\ No newline at end of file