OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmGenPreview.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 using System.IO;\r
11 \r
12 namespace Handbrake\r
13 {\r
14     public partial class frmGenPreview : Form\r
15     {\r
16         private delegate void UpdateHandler();\r
17         Handbrake.QueryGenerator queryGen = new Handbrake.QueryGenerator();\r
18         Functions.Encode process = new Functions.Encode();\r
19         Process hbProc;\r
20         frmMain mainWindow;\r
21 \r
22         public frmGenPreview(frmMain mw)\r
23         {\r
24             InitializeComponent();\r
25             this.mainWindow = mw;\r
26             cb_duration.SelectedIndex = 0;\r
27         }\r
28 \r
29         private void btn_play_Click(object sender, EventArgs e)\r
30         {\r
31             String currently_playing;\r
32 \r
33             // Get the Destination of the sample video.\r
34             currently_playing = "";\r
35             if (mainWindow.text_destination.Text != "")\r
36                 currently_playing = mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm");\r
37             \r
38             // Launch VLC and play video.\r
39             if (currently_playing != "")\r
40             {\r
41                 if (File.Exists(Properties.Settings.Default.VLC_Path))\r
42                 {\r
43                     String args = "\"" + currently_playing + "\"";\r
44                     ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);\r
45                     Process.Start(vlc);\r
46                     lbl_status.Text = "VLC will now launch.";\r
47                 }\r
48                 else\r
49                 {\r
50                     MessageBox.Show("Unable to detect VLC Player. \nPlease make sure VLC is installed and the directory specified in the program options is correct.", "VLC", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
51                 }\r
52             }\r
53         }\r
54 \r
55         private void btn_encode_Click(object sender, EventArgs e)\r
56         {\r
57             String query = queryGen.GeneratePreviewQuery(mainWindow, cb_duration.Text);\r
58             ThreadPool.QueueUserWorkItem(procMonitor, query);\r
59         }\r
60         private void procMonitor(object state)\r
61         {\r
62             // Make sure we are not already encoding and if we are then display an error.\r
63             if (hbProc != null)\r
64                 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
65             else\r
66             {\r
67                 encodingMessage();\r
68                 hbProc = process.runCli(this, (string)state);\r
69                 hbProc.WaitForExit();\r
70                 hbProc = null;\r
71                 updateUIElements();\r
72             }\r
73         }\r
74         // Update the UI now that the encode has finished.\r
75         private void encodingMessage()\r
76         {\r
77             try\r
78             {\r
79                 if (this.InvokeRequired)\r
80                 {\r
81                     this.BeginInvoke(new UpdateHandler(encodingMessage));\r
82                     return;\r
83                 }\r
84                 lbl_status.Text = "Encoding, Please wait ...";\r
85             }\r
86             catch (Exception exc)\r
87             {\r
88                 MessageBox.Show(exc.ToString());\r
89             }\r
90         }\r
91 \r
92         // Update the UI now that the encode has finished.\r
93         private void updateUIElements()\r
94         {\r
95             try\r
96             {\r
97                 if (this.InvokeRequired)\r
98                 {\r
99                     this.BeginInvoke(new UpdateHandler(updateUIElements));\r
100                     return;\r
101                 }\r
102 \r
103                 btn_play.Visible = true;\r
104                 toolStripSeparator1.Visible = true;\r
105                 lbl_status.Text = "Your sample is ready to play.";\r
106             }\r
107             catch (Exception exc)\r
108             {\r
109                 MessageBox.Show(exc.ToString());\r
110             }\r
111         }\r
112 \r
113 \r
114     }\r
115 }\r