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 8d91576..a08591c 100644 (file)
@@ -7,36 +7,130 @@ 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
     public partial class frmQueue : Form\r
     {\r
-        private delegate void ProgressUpdateHandler(int progressSplit);\r
+        private delegate void ProgressUpdateHandler();\r
 \r
         public frmQueue()\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
@@ -49,7 +143,7 @@ namespace Handbrake
         {\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
@@ -62,74 +156,25 @@ namespace Handbrake
             }\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.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 listSize = list_queue.Items.Count;\r
-            listSize--;\r
-            int counter = 0;\r
-            int progressSplit = listSize / 100;\r
-\r
-            while (counter <= listSize)\r
-            {\r
-                String query = list_queue.Items[0].ToString();\r
-\r
-                Process hbProc = new Process();\r
-                hbProc.StartInfo.FileName = "hbcli.exe";\r
-                hbProc.StartInfo.Arguments = query;\r
-                hbProc.StartInfo.UseShellExecute = false;\r
-                hbProc.Start();\r
-\r
-                // Set the process Priority\r
-                string priority = Properties.Settings.Default.processPriority;\r
-                switch (priority)\r
-                {\r
-                    case "Realtime":\r
-                        hbProc.PriorityClass = ProcessPriorityClass.RealTime;\r
-                        break;\r
-                    case "High":\r
-                        hbProc.PriorityClass = ProcessPriorityClass.High;\r
-                        break;\r
-                    case "Above Normal":\r
-                        hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;\r
-                        break;\r
-                    case "Normal":\r
-                        hbProc.PriorityClass = ProcessPriorityClass.Normal;\r
-                        break;\r
-                    case "Low":\r
-                        hbProc.PriorityClass = ProcessPriorityClass.Idle;\r
-                        break;\r
-                    default:\r
-                        hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;\r
-                        break;\r
-                }\r
-\r
-                hbProc.WaitForExit();\r
-                hbProc.Close();\r
-                counter++;\r
+        #region Window Management\r
 \r
-                updateUIElements(progressSplit);\r
-            }\r
+        private void btn_Close_Click(object sender, EventArgs e)\r
+        {\r
+            this.Hide();\r
         }\r
 \r
-        private void updateUIElements(int progressSplit)\r
+        private void btn_minimise_Click(object sender, EventArgs e)\r
         {\r
-            if (this.InvokeRequired)\r
-            {\r
-                this.BeginInvoke(new ProgressUpdateHandler(updateUIElements), new object[] { progressSplit });\r
-                return;\r
-            }\r
-\r
-            this.list_queue.Items.Remove(0);\r
-            progressBar.Value = progressBar.Value + progressSplit;\r
-            progressBar.Update();\r
+            this.WindowState = FormWindowState.Minimized;\r
         }\r
+\r
+        #endregion\r
+\r
     }\r
 }
\ No newline at end of file