OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmQueue.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.ComponentModel;\r
4 using System.Data;\r
5 using System.Drawing;\r
6 using System.Text;\r
7 using System.Windows.Forms;\r
8 using System.Threading;\r
9 using System.Diagnostics;\r
10 \r
11 namespace Handbrake\r
12 {\r
13     public partial class frmQueue : Form\r
14     {\r
15         private delegate void ProgressUpdateHandler();\r
16 \r
17         public frmQueue()\r
18         {\r
19             InitializeComponent();\r
20         }\r
21 \r
22         private void btn_Close_Click(object sender, EventArgs e)\r
23         {\r
24             this.Hide();\r
25         }\r
26 \r
27         private void btn_delete_Click(object sender, EventArgs e)\r
28         {\r
29             list_queue.Items.Remove(list_queue.SelectedItem);\r
30         }\r
31 \r
32         private void btn_up_Click(object sender, EventArgs e)\r
33         {\r
34             int count = list_queue.Items.Count;\r
35             int itemToMove = list_queue.SelectedIndex;\r
36             int previousItemint = 0; \r
37             String previousItem = "";\r
38 \r
39              if (itemToMove > 0){\r
40                 previousItemint = itemToMove - 1;\r
41                 previousItem = list_queue.Items[previousItemint].ToString();\r
42                 list_queue.Items[previousItemint] = list_queue.Items[itemToMove];\r
43                 list_queue.Items[itemToMove] = previousItem;\r
44                 list_queue.SelectedIndex = list_queue.SelectedIndex - 1;\r
45             }\r
46         }\r
47 \r
48         private void btn_down_Click(object sender, EventArgs e)\r
49         {\r
50             int count = list_queue.Items.Count;\r
51             int itemToMove = list_queue.SelectedIndex;\r
52             int itemAfterInt = 0; \r
53             String itemAfter = "";\r
54 \r
55             if (itemToMove < (count - 1))\r
56             {\r
57                 itemAfterInt = itemToMove + 1;\r
58                 itemAfter = list_queue.Items[itemAfterInt].ToString();\r
59                 list_queue.Items[itemAfterInt] = list_queue.Items[itemToMove];\r
60                 list_queue.Items[itemToMove] = itemAfter;\r
61                 list_queue.SelectedIndex = list_queue.SelectedIndex + 1;\r
62             }\r
63         }\r
64 \r
65         private void btn_q_encoder_Click(object sender, EventArgs e)\r
66         {\r
67             progressBar.Value = 0;\r
68             lbl_progressValue.Text = "0 %";\r
69             progressBar.Step = 100 / list_queue.Items.Count;\r
70             progressBar.Update();\r
71             ThreadPool.QueueUserWorkItem(startProc);\r
72         }\r
73 \r
74         private void startProc(object state)\r
75         {\r
76             // Reminder: There is still a bug here where the loop suddenly halts for no good reson. UpdateUIelements runs, then the loop finishes several items early.\r
77             for (int i = 0; i < list_queue.Items.Count; i++)\r
78             {\r
79                 string query = list_queue.Items[0] as string;\r
80                 Process hbProc = new Process();\r
81                 hbProc.StartInfo.FileName = "hbcli.exe";\r
82                 hbProc.StartInfo.Arguments = query;\r
83                 hbProc.StartInfo.UseShellExecute = false;\r
84                 hbProc.Start();\r
85 \r
86                 // Set the process Priority\r
87 \r
88                 switch (Properties.Settings.Default.processPriority)\r
89                 {\r
90                     case "Realtime":\r
91                         hbProc.PriorityClass = ProcessPriorityClass.RealTime;\r
92                         break;\r
93                     case "High":\r
94                         hbProc.PriorityClass = ProcessPriorityClass.High;\r
95                         break;\r
96                     case "Above Normal":\r
97                         hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;\r
98                         break;\r
99                     case "Normal":\r
100                         hbProc.PriorityClass = ProcessPriorityClass.Normal;\r
101                         break;\r
102                     case "Low":\r
103                         hbProc.PriorityClass = ProcessPriorityClass.Idle;\r
104                         break;\r
105                     default:\r
106                         hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;\r
107                         break;\r
108                 }\r
109 \r
110                 hbProc.WaitForExit();\r
111                 hbProc.Close();\r
112                 hbProc.Dispose();\r
113                 \r
114 \r
115                 updateUIElements();\r
116             }\r
117         }\r
118 \r
119         private void updateUIElements()\r
120         {\r
121             if (this.InvokeRequired)\r
122             {\r
123                 this.BeginInvoke(new ProgressUpdateHandler(updateUIElements));\r
124                 return;\r
125             }\r
126             this.list_queue.Items.RemoveAt(0);\r
127             progressBar.PerformStep();\r
128             lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);\r
129             progressBar.Update();\r
130         }\r
131     }\r
132 }