OSDN Git Service

Change the fifo size from being statically tuned for a Mac Pro with 4 CPUs to dynamic...
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmQueue.cs
index 8e59e11..a08591c 100644 (file)
@@ -7,6 +7,7 @@ using System.Text;
 using System.Windows.Forms;\r
 using System.Threading;\r
 using System.Diagnostics;\r
+using System.Runtime.InteropServices;\r
 \r
 namespace Handbrake\r
 {\r
@@ -19,48 +20,76 @@ namespace Handbrake
             InitializeComponent();\r
         }\r
 \r
-        int initialListCount = 0;\r
-        bool started = false;\r
+        #region Queue Handling\r
 \r
-      \r
         private void btn_q_encoder_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
+            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
-        /*\r
-         * \r
-         * Code to Handle the CLI and updating of the UI as each process is completed.\r
-         * \r
-         */\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
-            started = true;\r
-            initialListCount = list_queue.Items.Count;\r
-            for (int i = 0; i < initialListCount; i++)\r
+            try\r
             {\r
-                string query = list_queue.Items[0].ToString();\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
-                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
-                updateUIElements();\r
+                resetQueue();\r
 \r
-                if ((initialListCount - i) != (list_queue.Items.Count))\r
+                // Do something whent he encode ends.\r
+                switch (Properties.Settings.Default.CompletionOption)\r
                 {\r
-                    initialListCount++;\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
-            started = false;\r
-            resetQueue();\r
-            MessageBox.Show("Encode Queue Completed!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
         }\r
 \r
         private void updateUIElements()\r
@@ -89,11 +118,8 @@ namespace Handbrake
             progressBar.Update();\r
         }\r
 \r
-        /*\r
-         * \r
-         * Code to Re-arrange / Delete items from the Queue\r
-         * \r
-         */\r
+        #endregion\r
+\r
         #region Queue Management\r
 \r
         private void btn_up_Click(object sender, EventArgs e)\r
@@ -133,17 +159,22 @@ namespace Handbrake
         private void btn_delete_Click(object sender, EventArgs e)\r
         {\r
             list_queue.Items.Remove(list_queue.SelectedItem);\r
-            if (started == true)\r
-                initialListCount--;\r
         }\r
         #endregion\r
 \r
-        /*\r
-         * Hide the Queue Window\r
-         */\r
+        #region Window Management\r
+\r
         private void btn_Close_Click(object sender, EventArgs e)\r
         {\r
             this.Hide();\r
         }\r
+\r
+        private void btn_minimise_Click(object sender, EventArgs e)\r
+        {\r
+            this.WindowState = FormWindowState.Minimized;\r
+        }\r
+\r
+        #endregion\r
+\r
     }\r
 }
\ No newline at end of file