OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmMain.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.Net;\r
9 using System.IO;\r
10 using System.Diagnostics;\r
11 using System.Threading;\r
12 \r
13 \r
14 namespace Handbrake\r
15 {\r
16     public partial class frmMain : Form\r
17     {\r
18         private Process hbProc;\r
19         private Parsing.DVD thisDVD;\r
20 \r
21         // --------------------------------------------------------------\r
22         // Some windows that require only 1 instance.\r
23         // --------------------------------------------------------------\r
24         private frmQueue queueWindow = new frmQueue();  \r
25         \r
26         // -------------------------------------------------------------- \r
27         // Stuff that needs doing on startup.\r
28         // - Load users default settings. (if required)\r
29         // - Do an update check (if required)\r
30         // --------------------------------------------------------------\r
31         private frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
32         \r
33         public frmMain()\r
34         {\r
35 \r
36 \r
37 \r
38             \r
39 \r
40             ThreadPool.QueueUserWorkItem(showSplash);\r
41             Thread.Sleep(3000);\r
42 \r
43             InitializeComponent();\r
44 \r
45             // This is a quick Hack fix for the cross-thread problem with frmDvdIndo ************************\r
46             dvdInfoWindow.Show();\r
47             dvdInfoWindow.Hide();\r
48             // **********************************************************************************************\r
49 \r
50 \r
51             // Set the Version number lable to the corect version.\r
52             Version.Text = "Version " + Properties.Settings.Default.GuiVersion;\r
53 \r
54             // Run the update checker.\r
55             updateCheck();\r
56 \r
57             // Now load the users default if required.\r
58             loadUserDefaults();\r
59 \r
60             // Display the quick start window if required.\r
61             quickStart();\r
62 \r
63             //MessageBox.Show(System.Environment.OSVersion.Version.ToString());\r
64         \r
65         }\r
66 \r
67         public void showSplash(object sender)\r
68         {\r
69             Form splash = new frmSplashScreen();\r
70             splash.Show();\r
71             Thread.Sleep(3000);\r
72             splash.Close();\r
73         }\r
74 \r
75         public void loadUserDefaults()\r
76         { \r
77             try\r
78             {\r
79                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
80                 {\r
81                     // Source\r
82                     text_source.Text = Properties.Settings.Default.DVDSource;\r
83                     drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;\r
84                     drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;\r
85                     drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;\r
86 \r
87                     // Destination\r
88                     text_destination.Text = Properties.Settings.Default.VideoDest;\r
89                     drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;\r
90                     drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;\r
91                     text_width.Text = Properties.Settings.Default.Width;\r
92                     text_height.Text = Properties.Settings.Default.Height;\r
93 \r
94                     // Picture Settings Tab\r
95                     drp_crop.Text = Properties.Settings.Default.CroppingOption;\r
96                     text_top.Text = Properties.Settings.Default.CropTop;\r
97                     text_bottom.Text = Properties.Settings.Default.CropBottom;\r
98                     text_left.Text = Properties.Settings.Default.CropLeft;\r
99                     text_right.Text = Properties.Settings.Default.CropRight;\r
100                     drp_subtitle.Text = Properties.Settings.Default.Subtitles;\r
101 \r
102                     // Video Settings Tab\r
103                     text_bitrate.Text = Properties.Settings.Default.VideoBitrate;\r
104                     text_filesize.Text = Properties.Settings.Default.VideoFilesize;\r
105                     slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;\r
106 \r
107                     if (Properties.Settings.Default.TwoPass == "Checked")\r
108                     {\r
109                         check_2PassEncode.CheckState = CheckState.Checked;\r
110                     }\r
111   \r
112                     drp_deInterlace_option.Text = Properties.Settings.Default.DeInterlace;\r
113                     drp_deNoise.Text = Properties.Settings.Default.denoise;\r
114 \r
115                     if (Properties.Settings.Default.detelecine == "Checked")\r
116                     {\r
117                         check_detelecine.CheckState = CheckState.Checked;\r
118                     }\r
119 \r
120                     if (Properties.Settings.Default.detelecine == "Checked")\r
121                     {\r
122                         check_deblock.CheckState = CheckState.Checked;\r
123                     }\r
124 \r
125 \r
126                     if (Properties.Settings.Default.Grayscale == "Checked")\r
127                     {\r
128                         check_grayscale.CheckState = CheckState.Checked;\r
129                     }\r
130 \r
131                     drp_videoFramerate.Text = Properties.Settings.Default.Framerate;\r
132 \r
133                     if (Properties.Settings.Default.PixelRatio == "Checked")\r
134                     {\r
135                         CheckPixelRatio.CheckState = CheckState.Checked;\r
136                     }\r
137                     if (Properties.Settings.Default.turboFirstPass == "Checked")\r
138                     {\r
139                         check_turbo.CheckState = CheckState.Checked;\r
140                     }\r
141                     if (Properties.Settings.Default.largeFile == "Checked")\r
142                     {\r
143                         check_largeFile.CheckState = CheckState.Checked;\r
144                     }\r
145                     // Audio Settings Tab\r
146                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
147                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
148                     drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;\r
149 \r
150                     // H264 Tab\r
151                     if (Properties.Settings.Default.CRF == "Checked")\r
152                     {\r
153                         CheckCRF.CheckState = CheckState.Checked;\r
154                     }\r
155                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
156                 }\r
157             }\r
158             catch (Exception)\r
159             {\r
160                 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.\r
161             }\r
162         }\r
163 \r
164         public void updateCheck()\r
165         {\r
166             if (Properties.Settings.Default.updateStatus == "Checked")\r
167             {\r
168                 try\r
169                 {\r
170                     String updateFile = Properties.Settings.Default.updateFile;\r
171                     WebClient client = new WebClient();\r
172                     String data = client.DownloadString(updateFile);\r
173                     String[] versionData = data.Split('\n');\r
174 \r
175                     if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
176                     {\r
177                         lbl_update.Visible = true;\r
178                     }\r
179                 }\r
180                 catch (Exception)\r
181                 {\r
182                     // Silently ignore the error\r
183                 }\r
184             }\r
185         }\r
186 \r
187         public void quickStart()\r
188         {\r
189             if ((Properties.Settings.Default.QuickStartWindow == "Checked") || (Properties.Settings.Default.QuickStartWindow == ""))\r
190             {\r
191                 frmQuickStart quickstart = new frmQuickStart();\r
192                 quickstart.ShowDialog();\r
193             }\r
194         }\r
195 \r
196 \r
197         // -------------------------------------------------------------- \r
198         // The main Menu bar.\r
199         // -------------------------------------------------------------- \r
200 \r
201         #region File Menu\r
202 \r
203         private void mnu_open_Click(object sender, EventArgs e)\r
204         {\r
205             string filename;\r
206             File_Open.ShowDialog();\r
207             filename = File_Open.FileName;\r
208             if (filename != "")\r
209             {\r
210                 try\r
211                 {\r
212                     // Create StreamReader & open file\r
213                     StreamReader line = new StreamReader(filename);\r
214                     string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
215                     \r
216                     // Read in the data and set the correct GUI component with the setting.\r
217                     text_source.Text = line.ReadLine();\r
218                     drp_dvdtitle.Text = line.ReadLine();\r
219                     drop_chapterStart.Text = line.ReadLine();\r
220                     drop_chapterFinish.Text = line.ReadLine();\r
221                     text_destination.Text = line.ReadLine();\r
222                     drp_videoEncoder.Text = line.ReadLine();\r
223                     drp_audioCodec.Text = line.ReadLine();\r
224                     text_width.Text = line.ReadLine();\r
225                     text_height.Text = line.ReadLine();\r
226                     text_top.Text = line.ReadLine();\r
227                     text_bottom.Text = line.ReadLine();\r
228                     text_left.Text = line.ReadLine();\r
229                     text_right.Text = line.ReadLine();\r
230                     drp_subtitle.Text = line.ReadLine();\r
231                     text_bitrate.Text = line.ReadLine();\r
232                     text_filesize.Text = line.ReadLine();\r
233                     slider_videoQuality.Value = int.Parse(line.ReadLine());\r
234 \r
235                     temporyLine = line.ReadLine();\r
236                     if (temporyLine == "Checked")\r
237                     {\r
238                         check_2PassEncode.CheckState = CheckState.Checked;\r
239                     }\r
240 \r
241                     drp_deInterlace_option.Text = line.ReadLine();\r
242 \r
243                     temporyLine = line.ReadLine();\r
244                     if (temporyLine == "Checked")\r
245                     {\r
246                         check_grayscale.CheckState = CheckState.Checked;\r
247                     }\r
248 \r
249                     drp_videoFramerate.Text = line.ReadLine();\r
250 \r
251                     temporyLine = line.ReadLine();\r
252                     if (temporyLine == "Checked")\r
253                     {\r
254                         Check_ChapterMarkers.CheckState = CheckState.Checked;\r
255                     }\r
256 \r
257                     temporyLine = line.ReadLine();\r
258                     if (temporyLine == "Checked")\r
259                     {\r
260                         CheckPixelRatio.CheckState = CheckState.Checked;\r
261                     }\r
262 \r
263                     temporyLine = line.ReadLine();\r
264                     if (temporyLine == "Checked")\r
265                     {\r
266                         check_turbo.CheckState = CheckState.Checked;\r
267                     }\r
268 \r
269                     temporyLine = line.ReadLine();\r
270                     if (temporyLine == "Checked")\r
271                     {\r
272                         check_largeFile.CheckState = CheckState.Checked;\r
273                     }\r
274    \r
275                     drp_audioBitrate.Text = line.ReadLine();\r
276                     drp_audioSampleRate.Text = line.ReadLine();\r
277                     drp_audioChannels.Text = line.ReadLine();\r
278                     drp_audioMixDown.Text = line.ReadLine();\r
279                     \r
280                     // Advanced H264 Options\r
281                     temporyLine = line.ReadLine();\r
282                     if (temporyLine == "Checked")\r
283                     {\r
284                         CheckCRF.CheckState = CheckState.Checked;\r
285                     }\r
286                     rtf_h264advanced.Text = line.ReadLine();\r
287 \r
288                     // Close the stream\r
289                     line.Close();\r
290 \r
291 \r
292                     // Fix for SliderValue not appearing when Opening saved file\r
293                     SliderValue.Text = slider_videoQuality.Value + "%";\r
294 \r
295                 } catch (Exception){\r
296                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
297                 }\r
298             }\r
299         }\r
300 \r
301         private void mnu_save_Click(object sender, EventArgs e)\r
302         {\r
303 \r
304             string filename;\r
305             File_Save.ShowDialog();\r
306             filename = File_Save.FileName;\r
307             if (filename != "")\r
308             {\r
309                 try\r
310                 {\r
311                     // Create a StreamWriter and open the file\r
312                     StreamWriter line = new StreamWriter(filename);\r
313 \r
314                     //Source\r
315                     line.WriteLine(text_source.Text);\r
316                     line.WriteLine(drp_dvdtitle.Text);\r
317                     line.WriteLine(drop_chapterStart.Text);\r
318                     line.WriteLine(drop_chapterFinish.Text);\r
319                     //Destination\r
320                     line.WriteLine(text_destination.Text);\r
321                     line.WriteLine(drp_videoEncoder.Text);\r
322                     line.WriteLine(drp_audioCodec.Text);\r
323                     line.WriteLine(text_width.Text);\r
324                     line.WriteLine(text_height.Text);\r
325                     //Picture Settings Tab\r
326                     line.WriteLine(text_top.Text);\r
327                     line.WriteLine(text_bottom.Text);\r
328                     line.WriteLine(text_left.Text);\r
329                     line.WriteLine(text_right.Text);\r
330                     line.WriteLine(drp_subtitle.Text);\r
331                     //Video Settings Tab\r
332                     line.WriteLine(text_bitrate.Text);\r
333                     line.WriteLine(text_filesize.Text);\r
334                     line.WriteLine(slider_videoQuality.Value.ToString());\r
335                     line.WriteLine(check_2PassEncode.CheckState.ToString());\r
336                     line.WriteLine(drp_deInterlace_option.Text);\r
337                     line.WriteLine(check_grayscale.CheckState.ToString());\r
338                     line.WriteLine(drp_videoFramerate.Text);\r
339                     line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
340                     line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
341                     line.WriteLine(check_turbo.CheckState.ToString());\r
342                     line.WriteLine(check_largeFile.CheckState.ToString());\r
343                     //Audio Settings Tab\r
344                     line.WriteLine(drp_audioBitrate.Text);\r
345                     line.WriteLine(drp_audioSampleRate.Text);\r
346                     line.WriteLine(drp_audioChannels.Text);\r
347                     line.WriteLine(drp_audioMixDown.Text);\r
348                     //H264 Tab\r
349                     line.WriteLine(CheckCRF.CheckState.ToString());\r
350                     line.WriteLine(rtf_h264advanced.Text);\r
351                     // close the stream\r
352                     line.Close();\r
353                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
354                 }\r
355                 catch(Exception)\r
356                 {\r
357                     MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
358                 }\r
359                 \r
360             }\r
361         }\r
362 \r
363         private void mnu_update_Click(object sender, EventArgs e)\r
364         {\r
365             Form Update = new frmUpdate();\r
366             Update.ShowDialog();\r
367         }\r
368 \r
369         private void mnu_exit_Click(object sender, EventArgs e)\r
370         {\r
371             this.Close();\r
372         }\r
373 \r
374         #endregion\r
375 \r
376         #region Tools Menu\r
377 \r
378         private void mnu_encode_Click(object sender, EventArgs e)\r
379         {\r
380             showQueue();\r
381         }\r
382 \r
383        \r
384         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
385         {\r
386             try\r
387             {\r
388                 dvdInfoWindow.Show();\r
389                 \r
390             }\r
391             catch (Exception)\r
392             {\r
393                 // No action required\r
394             }\r
395 \r
396             // BUG *******************************************************\r
397             // Cross-thread operation not valid: Control 'rtf_dvdInfo' accessed from a thread other than the thread it was created on.\r
398             // This happens when the DVD is scanned and this item is then selected.\r
399             // If this item is selected so a blank copy of the window appears, then a DVD is scanned, there is no cross-thread issue.\r
400             // NOTE: Try/catch added to prevent final build crashing.\r
401             // NOTE2: Included a quick fix in frmMain(). Simply show and hide the window when starting the app.\r
402             // Note3: Suspect the problem lies with line 30.\r
403             // ***********************************************************\r
404 \r
405         }\r
406 \r
407         private void mnu_options_Click(object sender, EventArgs e)\r
408         {\r
409             Form Options = new frmOptions();\r
410             Options.ShowDialog();\r
411         }\r
412 \r
413         #endregion\r
414 \r
415         #region Presets Menu\r
416 \r
417         private void mnu_preset_ipod133_Click(object sender, EventArgs e)\r
418         {\r
419             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
420             text_width.Text = "640";\r
421             text_height.Text = "Auto";\r
422             drp_videoEncoder.Text = "H.264 (iPod)";\r
423             text_bitrate.Text = "1000";\r
424             text_filesize.Text = "";\r
425             slider_videoQuality.Value = 0;\r
426             SliderValue.Text = "0%";\r
427             drp_audioBitrate.Text = "160";\r
428             rtf_h264advanced.Text = "";\r
429             drp_crop.Text = "No Crop";\r
430         }\r
431 \r
432 \r
433 \r
434         private void mnu_appleTv_Click(object sender, EventArgs e)\r
435         {\r
436             text_width.Text = "";\r
437             text_height.Text = "";\r
438             drp_videoEncoder.Text = "H.264";\r
439             text_bitrate.Text = "3000";\r
440             text_filesize.Text = "";\r
441             slider_videoQuality.Value = 0;\r
442             SliderValue.Text = "0%";\r
443             drp_audioBitrate.Text = "160";\r
444             CheckPixelRatio.CheckState = CheckState.Checked;\r
445             drp_audioSampleRate.Text = "48";\r
446             rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";\r
447             drp_crop.Text = "No Crop";\r
448             \r
449         }\r
450 \r
451         private void mnu_presetPS3_Click(object sender, EventArgs e)\r
452         {\r
453             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
454             text_width.Text = "";\r
455             text_height.Text = "";\r
456             drp_videoEncoder.Text = "H.264";\r
457             text_bitrate.Text = "3000";\r
458             text_filesize.Text = "";\r
459             slider_videoQuality.Value = 0;\r
460             SliderValue.Text = "0%";\r
461             drp_audioBitrate.Text = "160";\r
462             CheckPixelRatio.CheckState = CheckState.Checked;\r
463             drp_audioSampleRate.Text = "48";\r
464             rtf_h264advanced.Text = "level=41";\r
465             drp_crop.Text = "No Crop";\r
466         }\r
467 \r
468         //------------------------------NEW PRESETS START HERE---------------------------\r
469         private void mnu_normal_Click(object sender, EventArgs e)\r
470         {\r
471             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
472             text_width.Text = "";\r
473             text_height.Text = "";\r
474             drp_videoEncoder.Text = "H.264";\r
475             text_bitrate.Text = "3000";\r
476             text_filesize.Text = "";\r
477             slider_videoQuality.Value = 0;\r
478             SliderValue.Text = "0%";\r
479             drp_audioBitrate.Text = "160";\r
480             CheckPixelRatio.CheckState = CheckState.Checked;\r
481             drp_audioSampleRate.Text = "48";\r
482             rtf_h264advanced.Text = "level=41";\r
483             drp_crop.Text = "No Crop";\r
484         }\r
485 \r
486         private void mnu_Classic_Click(object sender, EventArgs e)\r
487         {\r
488             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
489             text_width.Text = "";\r
490             text_height.Text = "";\r
491             drp_videoEncoder.Text = "H.264";\r
492             text_bitrate.Text = "3000";\r
493             text_filesize.Text = "";\r
494             slider_videoQuality.Value = 0;\r
495             SliderValue.Text = "0%";\r
496             drp_audioBitrate.Text = "160";\r
497             CheckPixelRatio.CheckState = CheckState.Checked;\r
498             drp_audioSampleRate.Text = "48";\r
499             rtf_h264advanced.Text = "level=41";\r
500             drp_crop.Text = "No Crop";\r
501         }\r
502 \r
503         private void mnu_film_Click(object sender, EventArgs e)\r
504         {\r
505             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
506             text_width.Text = "";\r
507             text_height.Text = "";\r
508             drp_videoEncoder.Text = "H.264";\r
509             text_bitrate.Text = "3000";\r
510             text_filesize.Text = "";\r
511             slider_videoQuality.Value = 0;\r
512             SliderValue.Text = "0%";\r
513             drp_audioBitrate.Text = "160";\r
514             CheckPixelRatio.CheckState = CheckState.Checked;\r
515             drp_audioSampleRate.Text = "48";\r
516             rtf_h264advanced.Text = "level=41";\r
517             drp_crop.Text = "No Crop";\r
518         }\r
519 \r
520         private void mnu_television_Click(object sender, EventArgs e)\r
521         {\r
522             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
523             text_width.Text = "";\r
524             text_height.Text = "";\r
525             drp_videoEncoder.Text = "H.264";\r
526             text_bitrate.Text = "3000";\r
527             text_filesize.Text = "";\r
528             slider_videoQuality.Value = 0;\r
529             SliderValue.Text = "0%";\r
530             drp_audioBitrate.Text = "160";\r
531             CheckPixelRatio.CheckState = CheckState.Checked;\r
532             drp_audioSampleRate.Text = "48";\r
533             rtf_h264advanced.Text = "level=41";\r
534             drp_crop.Text = "No Crop";\r
535         }\r
536 \r
537         private void mnu_qt_Click(object sender, EventArgs e)\r
538         {\r
539             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
540             text_width.Text = "";\r
541             text_height.Text = "";\r
542             drp_videoEncoder.Text = "H.264";\r
543             text_bitrate.Text = "3000";\r
544             text_filesize.Text = "";\r
545             slider_videoQuality.Value = 0;\r
546             SliderValue.Text = "0%";\r
547             drp_audioBitrate.Text = "160";\r
548             CheckPixelRatio.CheckState = CheckState.Checked;\r
549             drp_audioSampleRate.Text = "48";\r
550             rtf_h264advanced.Text = "level=41";\r
551             drp_crop.Text = "No Crop";\r
552         }\r
553 \r
554         private void mnu_psp_Click(object sender, EventArgs e)\r
555         {\r
556             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
557             text_width.Text = "";\r
558             text_height.Text = "";\r
559             drp_videoEncoder.Text = "H.264";\r
560             text_bitrate.Text = "3000";\r
561             text_filesize.Text = "";\r
562             slider_videoQuality.Value = 0;\r
563             SliderValue.Text = "0%";\r
564             drp_audioBitrate.Text = "160";\r
565             CheckPixelRatio.CheckState = CheckState.Checked;\r
566             drp_audioSampleRate.Text = "48";\r
567             rtf_h264advanced.Text = "level=41";\r
568             drp_crop.Text = "No Crop";\r
569         }\r
570 \r
571 \r
572         private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)\r
573         {\r
574             //Source\r
575             Properties.Settings.Default.DVDSource = text_source.Text;\r
576             Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
577             Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
578             Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
579             //Destination\r
580             Properties.Settings.Default.VideoDest = text_destination.Text;\r
581             Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
582             Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
583             Properties.Settings.Default.Width = text_width.Text;\r
584             Properties.Settings.Default.Height = text_height.Text;\r
585             //Picture Settings Tab\r
586             Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
587             Properties.Settings.Default.CropTop = text_top.Text;\r
588             Properties.Settings.Default.CropBottom = text_bottom.Text;\r
589             Properties.Settings.Default.CropLeft = text_left.Text;\r
590             Properties.Settings.Default.CropRight = text_right.Text;\r
591             Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
592             //Video Settings Tab\r
593             Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
594             Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
595             Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
596             Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
597             Properties.Settings.Default.DeInterlace = drp_deInterlace_option.Text;\r
598             Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
599             Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
600             Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
601             Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
602             Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
603             Properties.Settings.Default.detelecine = check_detelecine.CheckState.ToString();\r
604             Properties.Settings.Default.denoise = drp_deNoise.Text;\r
605             Properties.Settings.Default.deblock = check_deblock.CheckState.ToString();\r
606             //Audio Settings Tab\r
607             Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
608             Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
609             Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
610             //H264 Tab\r
611             Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
612             Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
613             Properties.Settings.Default.Save();\r
614         }\r
615 \r
616         #endregion\r
617 \r
618         #region Help Menu\r
619 \r
620         private void mnu_wiki_Click(object sender, EventArgs e)\r
621         {\r
622            Process.Start("http://handbrake.m0k.org/trac");\r
623         }\r
624 \r
625         private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
626         {\r
627             Process.Start("http://handbrake.m0k.org/?page_id=11");\r
628         }\r
629 \r
630         private void mnu_faq_Click(object sender, EventArgs e)\r
631         {\r
632             Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
633         }\r
634 \r
635         private void mnu_homepage_Click(object sender, EventArgs e)\r
636         {\r
637            Process.Start("http://handbrake.m0k.org");\r
638         }\r
639 \r
640         private void mnu_forum_Click(object sender, EventArgs e)\r
641         {\r
642             Process.Start("http://handbrake.m0k.org/forum");\r
643         }\r
644 \r
645         private void mnu_about_Click(object sender, EventArgs e)\r
646         {\r
647                         Form About = new frmAbout();\r
648             About.ShowDialog();\r
649         }\r
650 \r
651         #endregion\r
652 \r
653         // -------------------------------------------------------------- \r
654         // Buttons on the main Window\r
655         // --------------------------------------------------------------\r
656 \r
657         #region Buttons\r
658         private void btn_Browse_Click(object sender, EventArgs e)\r
659         {\r
660             String filename =""; \r
661                     text_source.Text = ""; \r
662                                  \r
663                     if (RadioDVD.Checked) \r
664                     { \r
665                         DVD_Open.ShowDialog(); \r
666                         filename = DVD_Open.SelectedPath; \r
667                         if (filename != "") \r
668                         { \r
669                             Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); \r
670                             text_source.Text = filename; \r
671                             frmRD.ShowDialog(); \r
672                         } \r
673                      } \r
674                      else \r
675                      { \r
676                         ISO_Open.ShowDialog(); \r
677                         filename = ISO_Open.FileName; \r
678                         if (filename != "") \r
679                         { \r
680                             Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow); \r
681                             text_source.Text = filename; \r
682                             frmRD.ShowDialog(); \r
683                         } \r
684                      }   \r
685                  \r
686                      // Check if there was titles in the dvd title dropdown \r
687                      if (filename == "") \r
688                      { \r
689                         text_source.Text = "Click 'Browse' to continue"; \r
690                      } \r
691                  \r
692                      if (drp_dvdtitle.Items.Count == 0) \r
693                      { \r
694                         MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source. Please refer to the FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); \r
695                      }                  \r
696         }\r
697 \r
698         private void btn_destBrowse_Click(object sender, EventArgs e)\r
699         {\r
700             // TODO: Need to write some code to check if there is a reasonable amount of disk space left.\r
701 \r
702             DVD_Save.ShowDialog();\r
703             text_destination.Text = DVD_Save.FileName;\r
704 \r
705             if (Check_ChapterMarkers.Checked)\r
706             {\r
707                 string destination = text_destination.Text;\r
708                 destination = destination.Replace(".mp4", ".m4v");\r
709                 text_destination.Text = destination;\r
710             }\r
711         }\r
712 \r
713         private void btn_h264Clear_Click(object sender, EventArgs e)\r
714         {\r
715             rtf_h264advanced.Text = "";\r
716         }\r
717 \r
718         private void GenerateQuery_Click(object sender, EventArgs e)\r
719         {\r
720             String query = GenerateTheQuery();\r
721             QueryEditorText.Text = query;\r
722         }\r
723 \r
724         private void btn_ClearQuery_Click(object sender, EventArgs e)\r
725         {\r
726             QueryEditorText.Text = "";\r
727         }\r
728 \r
729         private void btn_queue_Click(object sender, EventArgs e)\r
730         {\r
731             if (text_destination.Text != "" && text_source.Text != "")\r
732             {\r
733                 string query;\r
734                 if (QueryEditorText.Text == "")\r
735                 {\r
736                     query = GenerateTheQuery();\r
737                 }\r
738                 else\r
739                 {\r
740                     query = QueryEditorText.Text;\r
741                 }\r
742                 queueWindow.list_queue.Items.Add(query);\r
743                 queueWindow.Show();\r
744             } \r
745             else \r
746             {\r
747                 MessageBox.Show("No Source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
748             }\r
749         }\r
750 \r
751         private void showQueue()\r
752         {\r
753             queueWindow.Show();\r
754         }\r
755 \r
756         #endregion\r
757 \r
758         //---------------------------------------------------\r
759         // Encode / Cancel Buttons\r
760         // Encode Progress Text Handler\r
761         //---------------------------------------------------\r
762 \r
763         #region Encode/CLI\r
764 \r
765         Functions.CLI process = new Functions.CLI();\r
766 \r
767         private void btn_encode_Click(object sender, EventArgs e)\r
768         {\r
769             btn_eCancel.Enabled = true;\r
770             String query = "";\r
771             lbl_encode.Visible = false;\r
772  \r
773             if (QueryEditorText.Text == "")\r
774             {\r
775                 query = GenerateTheQuery();\r
776             }\r
777             else\r
778             {\r
779                 query = QueryEditorText.Text;\r
780             }\r
781 \r
782             ThreadPool.QueueUserWorkItem(procMonitor, query);\r
783             lbl_encode.Text = "Encoding Started";\r
784         }\r
785 \r
786         private void btn_eCancel_Click(object sender, EventArgs e)\r
787         {\r
788             process.killCLI();\r
789             process.setNull();\r
790             lbl_encode.Text = "Encoding Canceled";\r
791         }\r
792    \r
793         private void procMonitor(object state)\r
794         {\r
795             // Make sure we are not already encoding and if we are then display an error.\r
796             if (hbProc != null)\r
797             {\r
798                 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
799             }\r
800             else\r
801             {\r
802                 hbProc = process.runCli(this, (string)state, false, false, false, false);\r
803                 MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
804                 hbProc.WaitForExit();\r
805 \r
806                 try\r
807                 {\r
808 \r
809                     //*****************************************************************************************\r
810                     // BUG!\r
811                     // When the below code is used and standard error is set to true, hbcli is outputing a\r
812                     // video stream which has mild corruption issues every few seconds.\r
813                     // Maybe an issue with the Parser cauing the CLI to hickup/pause?\r
814                     //*****************************************************************************************\r
815 \r
816                     \r
817                     /*Parsing.Parser encode = new Parsing.Parser(hbProc.StandardError.BaseStream);\r
818                     encode.OnEncodeProgress += encode_OnEncodeProgress;\r
819                     while (!encode.EndOfStream)\r
820                     {\r
821                         encode.ReadLine();\r
822                     }\r
823 \r
824                     hbProc.WaitForExit();\r
825                     process.closeCLI();\r
826                     */\r
827                 }\r
828                 catch (Exception)\r
829                 {\r
830                     // Do nothing\r
831                 }\r
832 \r
833                 MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
834                 hbProc = null;\r
835             }\r
836         }\r
837 \r
838         private void encode_OnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
839         {\r
840             if (this.InvokeRequired)\r
841             {\r
842                 this.BeginInvoke(new Parsing.EncodeProgressEventHandler(encode_OnEncodeProgress),\r
843                     new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
844                 return;\r
845             }\r
846             lbl_encode.Text = string.Format("Encode Progress: {0}%,       FPS: {1},       Avg FPS: {2},       Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
847         }\r
848 \r
849         #endregion\r
850 \r
851         //---------------------------------------------------\r
852         //  Items that require actions on frmMain\r
853         //---------------------------------------------------\r
854 \r
855         #region frmMain Actions\r
856 \r
857         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
858         {\r
859             lbl_chptWarn.Visible = false;\r
860             QueryEditorText.Text = "";\r
861             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
862             {\r
863                 try\r
864                 {\r
865                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
866                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
867 \r
868                     if (chapterFinish < chapterStart)\r
869                     {\r
870                         lbl_chptWarn.Visible = true;\r
871                         lbl_chptWarn.Text = "Invalid Chapter Range!";\r
872                     }\r
873                 }\r
874                 catch (Exception)\r
875                 {\r
876                     lbl_chptWarn.Visible = true;\r
877                     lbl_chptWarn.Text = "Invalid Chapter Range!";\r
878                 }\r
879             }\r
880 \r
881             \r
882         }\r
883 \r
884         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
885         {\r
886             lbl_chptWarn.Visible = false;\r
887             QueryEditorText.Text = "";\r
888             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
889             {\r
890                 try\r
891                 {\r
892                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
893                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
894 \r
895                     if (chapterFinish < chapterStart)\r
896                     {\r
897                         lbl_chptWarn.Visible = true;\r
898                         lbl_chptWarn.Text = "Invalid Chapter Range!";\r
899                     }\r
900                 }\r
901                 catch (Exception)\r
902                 {\r
903                     lbl_chptWarn.Visible = true;\r
904                     lbl_chptWarn.Text = "Invalid Chapter Range!";\r
905                 }\r
906             }\r
907         }\r
908 \r
909         private void text_bitrate_TextChanged(object sender, EventArgs e)\r
910         {\r
911             text_filesize.Text = "";\r
912             slider_videoQuality.Value = 0;\r
913             SliderValue.Text = "0%";\r
914             CheckCRF.CheckState = CheckState.Unchecked;\r
915             CheckCRF.Enabled = false;\r
916         }\r
917 \r
918         private void text_filesize_TextChanged(object sender, EventArgs e)\r
919         {\r
920             text_bitrate.Text = "";\r
921             slider_videoQuality.Value = 0;\r
922             SliderValue.Text = "0%";\r
923             CheckCRF.CheckState = CheckState.Unchecked;\r
924             CheckCRF.Enabled = false;\r
925         }\r
926 \r
927         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
928         {\r
929             SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
930             text_bitrate.Text = "";\r
931             text_filesize.Text = "";\r
932             CheckCRF.Enabled = true;\r
933         }\r
934 \r
935         private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
936         {\r
937             Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");\r
938         }\r
939 \r
940         private void text_width_TextChanged(object sender, EventArgs e)\r
941         {\r
942 \r
943             try\r
944             {\r
945                 if (CheckPixelRatio.Checked)\r
946                 {\r
947                     text_width.Text = "";\r
948                     text_width.BackColor = Color.White;\r
949                 }\r
950                 else\r
951                 {\r
952                     if ((int.Parse(text_width.Text) % 16) != 0)\r
953                     {\r
954                         text_width.BackColor = Color.LightCoral;\r
955                     }\r
956                     else\r
957                     {\r
958                         text_width.BackColor = Color.LightGreen;\r
959                     }\r
960                 }\r
961 \r
962                 if (lbl_Aspect.Text != "Select a Title")\r
963                 {\r
964                     double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);\r
965                     double mod16 = height % 16;\r
966                     height = height - mod16;\r
967 \r
968                     if (text_width.Text == "")\r
969                     {\r
970                         text_height.Text = "";\r
971                         text_width.BackColor = Color.White;\r
972                     }\r
973                     else\r
974                     {\r
975                         text_height.Text = height.ToString();\r
976                     }\r
977                 }\r
978             }\r
979             catch (Exception)\r
980             {\r
981                 // No need to throw an error here.\r
982             }\r
983                \r
984           \r
985         }\r
986 \r
987         private void text_height_TextChanged(object sender, EventArgs e)\r
988         {\r
989             try\r
990             {\r
991                 if (text_height.Text != "Auto")\r
992                 {\r
993                     if (CheckPixelRatio.Checked)\r
994                     {\r
995                         text_height.Text = "";\r
996                         text_width.BackColor = Color.White;\r
997                     }\r
998                     else\r
999                     {\r
1000                         if ((int.Parse(text_height.Text) % 16) != 0)\r
1001                         {\r
1002                             text_height.BackColor = Color.LightCoral;\r
1003                         }\r
1004                         else\r
1005                         {\r
1006                             text_height.BackColor = Color.LightGreen;\r
1007                         }\r
1008                     }\r
1009                 }\r
1010             } catch(Exception){\r
1011                 // No need to alert the user.\r
1012             }\r
1013         }\r
1014 \r
1015         private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)\r
1016         {\r
1017             if ((string)drp_crop.SelectedItem == "Manual")\r
1018             {\r
1019             text_left.Enabled = true;\r
1020             text_right.Enabled = true;\r
1021             text_top.Enabled = true;\r
1022             text_bottom.Enabled = true;\r
1023             }\r
1024 \r
1025             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
1026             {\r
1027                 text_left.Enabled = false;\r
1028                 text_right.Enabled = false;\r
1029                 text_top.Enabled = false;\r
1030                 text_bottom.Enabled = false;\r
1031                 text_left.Text = "";\r
1032                 text_right.Text = "";\r
1033                 text_top.Text = "";\r
1034                 text_bottom.Text = "";\r
1035 \r
1036                 if (lbl_RecomendedCrop.Text != "Select a Title")\r
1037                 {\r
1038                     string[] temp = new string[4];\r
1039                     temp = lbl_RecomendedCrop.Text.Split('/');\r
1040                     text_left.Text = temp[2];\r
1041                     text_right.Text = temp[3];\r
1042                     text_top.Text = temp[0];\r
1043                     text_bottom.Text = temp[1];\r
1044                 }\r
1045             }\r
1046 \r
1047             if ((string)drp_crop.SelectedItem == "No Crop")\r
1048             {\r
1049                 text_left.Enabled = false;\r
1050                 text_right.Enabled = false;\r
1051                 text_top.Enabled = false;\r
1052                 text_bottom.Enabled = false;\r
1053                 text_left.Text = "0";\r
1054                 text_right.Text = "0";\r
1055                 text_top.Text = "0";\r
1056                 text_bottom.Text = "0";\r
1057 \r
1058             }\r
1059         }\r
1060         \r
1061         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
1062         {\r
1063             text_width.Text = "";\r
1064             text_height.Text = "";\r
1065             text_width.BackColor = Color.White;\r
1066             text_height.BackColor = Color.White;\r
1067         }\r
1068 \r
1069         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
1070         {\r
1071             if (drp_dvdtitle.Items.Count == 1)\r
1072             {\r
1073                 MessageBox.Show("There are no titles to select. Please scan the DVD by clicking the 'browse' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
1074             }\r
1075         }\r
1076 \r
1077         private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)\r
1078         {\r
1079 \r
1080             //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch\r
1081 \r
1082             drp_audioMixDown.Items.Clear();\r
1083 \r
1084             if (drp_audioCodec.Text == "AAC")\r
1085             {\r
1086                 drp_audioMixDown.Items.Clear();\r
1087                 drp_audioMixDown.Items.Add("Mono");\r
1088                 drp_audioMixDown.Items.Add("Stereo");\r
1089                 drp_audioMixDown.Items.Add("Dolby Surround");\r
1090                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
1091                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
1092                 \r
1093                 drp_audioBitrate.Items.Clear();\r
1094                 drp_audioBitrate.Items.Add("32");\r
1095                 drp_audioBitrate.Items.Add("40");\r
1096                 drp_audioBitrate.Items.Add("48");\r
1097                 drp_audioBitrate.Items.Add("56");\r
1098                 drp_audioBitrate.Items.Add("64");\r
1099                 drp_audioBitrate.Items.Add("80");\r
1100                 drp_audioBitrate.Items.Add("86");\r
1101                 drp_audioBitrate.Items.Add("112");\r
1102                 drp_audioBitrate.Items.Add("128");\r
1103                 drp_audioBitrate.Items.Add("160");\r
1104 \r
1105             }\r
1106             else\r
1107             {\r
1108                 drp_audioMixDown.Items.Clear();\r
1109                 drp_audioMixDown.Items.Add("Stereo");\r
1110                 drp_audioMixDown.Items.Add("Dolby Surround");\r
1111                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
1112 \r
1113                 drp_audioBitrate.Items.Clear();\r
1114                 drp_audioBitrate.Items.Add("32");\r
1115                 drp_audioBitrate.Items.Add("40");\r
1116                 drp_audioBitrate.Items.Add("48");\r
1117                 drp_audioBitrate.Items.Add("56");\r
1118                 drp_audioBitrate.Items.Add("64");\r
1119                 drp_audioBitrate.Items.Add("80");\r
1120                 drp_audioBitrate.Items.Add("86");\r
1121                 drp_audioBitrate.Items.Add("112");\r
1122                 drp_audioBitrate.Items.Add("128");\r
1123                 drp_audioBitrate.Items.Add("160");\r
1124                 drp_audioBitrate.Items.Add("192");\r
1125                 drp_audioBitrate.Items.Add("224");\r
1126                 drp_audioBitrate.Items.Add("256");\r
1127                 drp_audioBitrate.Items.Add("320");\r
1128                 drp_audioBitrate.Items.Add("384");\r
1129             }\r
1130         }\r
1131 \r
1132         private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)\r
1133         {\r
1134             if (drp_audioCodec.Text == "AAC")\r
1135             {\r
1136                 if (drp_audioMixDown.Text == "6 Channel Discrete")\r
1137                 {\r
1138 \r
1139                     drp_audioBitrate.Items.Clear();\r
1140                     drp_audioBitrate.Items.Add("32");\r
1141                     drp_audioBitrate.Items.Add("40");\r
1142                     drp_audioBitrate.Items.Add("48");\r
1143                     drp_audioBitrate.Items.Add("56");\r
1144                     drp_audioBitrate.Items.Add("64");\r
1145                     drp_audioBitrate.Items.Add("80");\r
1146                     drp_audioBitrate.Items.Add("86");\r
1147                     drp_audioBitrate.Items.Add("112");\r
1148                     drp_audioBitrate.Items.Add("128");\r
1149                     drp_audioBitrate.Items.Add("160");\r
1150                     drp_audioBitrate.Items.Add("192");\r
1151                     drp_audioBitrate.Items.Add("224");\r
1152                     drp_audioBitrate.Items.Add("256");\r
1153                     drp_audioBitrate.Items.Add("320");\r
1154                     drp_audioBitrate.Items.Add("384");\r
1155                 }\r
1156             }\r
1157         }\r
1158 \r
1159         private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)\r
1160         {\r
1161             if (Check_ChapterMarkers.Checked)\r
1162             {\r
1163                 string destination = text_destination.Text;\r
1164                 destination = destination.Replace(".mp4", ".m4v");\r
1165                 text_destination.Text = destination;\r
1166             }\r
1167         }\r
1168 \r
1169         private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
1170         {\r
1171             if (!text_destination.Text.Contains(".mp4"))\r
1172             {\r
1173                 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1174                 check_largeFile.CheckState = CheckState.Unchecked;\r
1175             }\r
1176         }\r
1177 \r
1178         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
1179         {\r
1180             //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
1181             if (!drp_videoEncoder.Text.Contains("H.264"))\r
1182             {\r
1183                 check_turbo.CheckState = CheckState.Unchecked;\r
1184                 CheckCRF.CheckState = CheckState.Unchecked;\r
1185                 CheckCRF.Enabled = false;\r
1186                 check_turbo.Enabled = false;\r
1187                 h264Tab.Enabled = false;\r
1188             }\r
1189             else\r
1190             {\r
1191                 CheckCRF.Enabled = true;\r
1192                 check_turbo.Enabled = true;\r
1193                 h264Tab.Enabled = true;\r
1194             }\r
1195 \r
1196         }\r
1197 \r
1198         public void setStreamReader(Parsing.DVD dvd)\r
1199         {\r
1200             this.thisDVD = dvd;\r
1201         }\r
1202 \r
1203         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
1204         {\r
1205             // Reset some values on the form\r
1206             lbl_Aspect.Text = "Select a Title";\r
1207             lbl_RecomendedCrop.Text = "Select a Title";\r
1208             drop_chapterStart.Items.Clear();\r
1209             drop_chapterFinish.Items.Clear();\r
1210             QueryEditorText.Text = "";\r
1211 \r
1212             // If the dropdown is set to automatic nothing else needs to be done.\r
1213             // Otheriwse if its not, title data has to be loased from parsing.\r
1214             if (drp_dvdtitle.Text != "Automatic")\r
1215             {\r
1216                 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;\r
1217 \r
1218                 // Set the Aspect Ratio\r
1219                 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();\r
1220 \r
1221                 // Set the Recommended Cropping values\r
1222                 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
1223                 \r
1224                 // Populate the Start chapter Dropdown\r
1225                 drop_chapterStart.Items.Clear();\r
1226                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1227                 if (drop_chapterStart.Items.Count > 0)\r
1228                 {\r
1229                     drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();\r
1230                 }\r
1231 \r
1232                 // Populate the Final Chapter Dropdown\r
1233                 drop_chapterFinish.Items.Clear();\r
1234                 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1235                 if (drop_chapterFinish.Items.Count > 0)\r
1236                 {\r
1237                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
1238                 }\r
1239 \r
1240                 // Populate the Audio Channels Dropdown\r
1241                 drp_audioChannels.Items.Clear();\r
1242                 drp_audioChannels.Items.Add("Automatic");\r
1243                 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
1244                 if (drp_audioChannels.Items.Count > 0)\r
1245                 {\r
1246                     drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();\r
1247                 }\r
1248 \r
1249                 // Populate the Subtitles dropdown\r
1250                 drp_subtitle.Items.Clear();\r
1251                 drp_subtitle.Items.Add("None");\r
1252                 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
1253                 if (drp_subtitle.Items.Count > 0)\r
1254                 {\r
1255                     drp_subtitle.Text = drp_subtitle.Items[0].ToString();\r
1256                 }\r
1257             }\r
1258         }\r
1259 \r
1260         #endregion\r
1261 \r
1262         /* \r
1263          * ---------------------------------------------------\r
1264          * \r
1265          * The query Generation function.\r
1266          * \r
1267          * ---------------------------------------------------\r
1268          */\r
1269 \r
1270         #region Program Functions\r
1271 \r
1272         public string GenerateTheQuery()\r
1273         {\r
1274             string source = text_source.Text;\r
1275             string dvdTitle = drp_dvdtitle.Text;\r
1276             string chapterStart = drop_chapterStart.Text;\r
1277             string chapterFinish = drop_chapterFinish.Text;\r
1278             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
1279             string dvdChapter = "";\r
1280 \r
1281             if (source ==  "")\r
1282                 MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1283             else\r
1284             {\r
1285                 source = " -i " + '"' + source+ '"'; //'"'+\r
1286             }\r
1287 \r
1288             if (dvdTitle ==  "Automatic")\r
1289                 dvdTitle = "";\r
1290             else\r
1291             {\r
1292                 string[] titleInfo = dvdTitle.Split(' ');\r
1293                 dvdTitle = " -t "+ titleInfo[0];\r
1294             }\r
1295 \r
1296             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
1297                 dvdChapter = "";\r
1298             else if (chapterFinish == chapterStart)\r
1299                 dvdChapter = " -c " + chapterStart;\r
1300             else\r
1301                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
1302 \r
1303             string querySource = source+ dvdTitle+ dvdChapter;\r
1304             // ----------------------------------------------------------------------\r
1305 \r
1306             // Destination\r
1307 \r
1308             string destination = text_destination.Text;\r
1309             string videoEncoder = drp_videoEncoder.Text;\r
1310             string audioEncoder = drp_audioCodec.Text;\r
1311             string width = text_width.Text;\r
1312             string height = text_height.Text;\r
1313 \r
1314             if (destination ==  "")\r
1315                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1316             else\r
1317                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
1318 \r
1319 \r
1320             switch (videoEncoder)\r
1321             {\r
1322                 case "Mpeg 4":\r
1323                     videoEncoder = " -e ffmpeg";\r
1324                     break;\r
1325                 case "Xvid":\r
1326                     videoEncoder = " -e xvid";\r
1327                     break;\r
1328                 case "H.264":\r
1329                     videoEncoder = " -e x264";\r
1330                     break;\r
1331                 case "H.264 Baseline 1.3":\r
1332                     videoEncoder = " -e x264b13";\r
1333                     break;\r
1334                 case "H.264 (iPod)":\r
1335                     videoEncoder = " -e x264b30";\r
1336                     break;\r
1337                 default:\r
1338                     videoEncoder = " -e x264";\r
1339                     break;\r
1340             }\r
1341            \r
1342             switch (audioEncoder)\r
1343             {\r
1344                 case "AAC":\r
1345                     audioEncoder = " -E faac";\r
1346                     break;\r
1347                 case "MP3":\r
1348                     audioEncoder = " -E lame";\r
1349                     break;\r
1350                 case "Vorbis":\r
1351                     audioEncoder = " -E vorbis";\r
1352                     break;\r
1353                 case "AC3":\r
1354                     audioEncoder = " -E ac3";\r
1355                     break;\r
1356                 default:\r
1357                     audioEncoder = " -E faac";\r
1358                     break;\r
1359             }\r
1360 \r
1361             if (width !=  "")\r
1362                 width = " -w "+ width;\r
1363 \r
1364 \r
1365             if (height == "Auto")\r
1366             {\r
1367                 height = "";\r
1368             }\r
1369             else if (height != "")\r
1370             {\r
1371                 height = " -l " + height;\r
1372             }\r
1373             \r
1374 \r
1375             string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
1376             // ----------------------------------------------------------------------\r
1377 \r
1378             // Picture Settings Tab\r
1379 \r
1380             string cropSetting = drp_crop.Text;\r
1381             string cropTop = text_top.Text;\r
1382             string cropBottom = text_bottom.Text;\r
1383             string cropLeft = text_left.Text;\r
1384             string cropRight = text_right.Text;\r
1385             string subtitles = drp_subtitle.Text;\r
1386             string cropOut = "";\r
1387             string deInterlace_Option = drp_deInterlace_option.Text;\r
1388             string deinterlace = "";\r
1389             string grayscale = "";\r
1390             string pixelRatio = "";\r
1391             string ChapterMarkers = "";\r
1392             // Returns Crop Query\r
1393 \r
1394             if (cropSetting == "Auto Crop")\r
1395                 cropOut = "";\r
1396             else if (cropSetting == "No Crop")\r
1397                 cropOut = " --crop 0:0:0:0 ";\r
1398             else\r
1399                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
1400 \r
1401             if (subtitles ==  "None")\r
1402                 subtitles = "";\r
1403             else if (subtitles ==  "")\r
1404                 subtitles = "";\r
1405             else\r
1406             {\r
1407                 string[] tempSub;\r
1408                 tempSub = subtitles.Split(' ');\r
1409                 subtitles = " -s "+ tempSub[0];\r
1410             }\r
1411 \r
1412             switch (deInterlace_Option)\r
1413             {\r
1414                 case "None":\r
1415                     deinterlace = "";\r
1416                     break;\r
1417                 case "Origional (Fast)":\r
1418                     deinterlace = " --deinterlace";\r
1419                     break;\r
1420                 case "yadif (Slow)":\r
1421                     deinterlace = " --deinterlace=" + '"' + "1" + '"';\r
1422                     break;\r
1423                 case "yadif + mcdeint (Slower)":\r
1424                     deinterlace = " --deinterlace=" + '"' + "1:-1:1" + '"';\r
1425                     break;\r
1426                 case "yadif + mcdeint (Slowest)":\r
1427                     deinterlace = " --deinterlace=" + '"' + "3:-1:2" + '"';\r
1428                     break;\r
1429                 default:\r
1430                     deinterlace = " --deinterlace=";\r
1431                     break;\r
1432             }\r
1433 \r
1434             if (check_grayscale.Checked)\r
1435                 grayscale = " -g ";\r
1436 \r
1437             if (CheckPixelRatio.Checked)\r
1438                 pixelRatio = " -p ";\r
1439 \r
1440             if (Check_ChapterMarkers.Checked)\r
1441                 ChapterMarkers = " -m ";\r
1442 \r
1443             string queryPictureSettings = cropOut + subtitles + deinterlace + grayscale + pixelRatio + ChapterMarkers;\r
1444             // ----------------------------------------------------------------------\r
1445 \r
1446             // Video Settings Tab\r
1447 \r
1448             string videoBitrate = text_bitrate.Text;\r
1449             string videoFilesize = text_filesize.Text;\r
1450             double videoQuality = slider_videoQuality.Value;\r
1451             string vidQSetting = "";\r
1452             string twoPassEncoding = "";\r
1453             string videoFramerate = drp_videoFramerate.Text;\r
1454             string turboH264 = "";\r
1455             string largeFile = "";\r
1456             string deblock = "";\r
1457             string detelecine = "";\r
1458             string denoise = "";\r
1459             string CRF = CheckCRF.CheckState.ToString();\r
1460 \r
1461 \r
1462             if ((CRF == "Checked"))\r
1463                 CRF = " -Q ";\r
1464             else\r
1465                 CRF = "";\r
1466 \r
1467             if (videoBitrate !=  "")\r
1468                 videoBitrate = " -b "+ videoBitrate;\r
1469 \r
1470             if (videoFilesize !=  "")\r
1471                 videoFilesize = " -S "+ videoFilesize;\r
1472 \r
1473             // Video Quality Setting\r
1474 \r
1475             if ((videoQuality ==  0))\r
1476                 vidQSetting = "";\r
1477             else\r
1478             {\r
1479                 MessageBox.Show(videoQuality.ToString());\r
1480                 videoQuality = videoQuality / 100;\r
1481                 MessageBox.Show(videoQuality.ToString());\r
1482                 if (videoQuality ==  1)\r
1483                 {\r
1484                     vidQSetting = "1.0";\r
1485                 }\r
1486 \r
1487                 vidQSetting = " -q " + videoQuality.ToString();\r
1488             }\r
1489 \r
1490             if (check_2PassEncode.Checked)\r
1491                 twoPassEncoding = " -2 ";\r
1492 \r
1493             if (videoFramerate ==  "Automatic")\r
1494                 videoFramerate = "";\r
1495             else\r
1496                 videoFramerate = " -r "+ videoFramerate;\r
1497 \r
1498             if (check_turbo.Checked)\r
1499                 turboH264 = " -T ";\r
1500 \r
1501             if (check_largeFile.Checked)\r
1502                 largeFile = " -4 ";\r
1503 \r
1504             if (check_deblock.Checked)\r
1505                 deblock = " --deblock";\r
1506 \r
1507             if (check_detelecine.Checked)\r
1508                 detelecine = " --detelecine";\r
1509 \r
1510             switch (drp_deNoise.Text)\r
1511             {\r
1512                 case "None":\r
1513                     denoise = "";\r
1514                     break;\r
1515                 case "Weak":\r
1516                     denoise = " --denoise=3:2:3:3";\r
1517                     break;\r
1518                 case "Strong":\r
1519                     denoise = " --denoise=7:7:5:5";\r
1520                     break;\r
1521                 default:\r
1522                     denoise = "";\r
1523                     break;\r
1524             }\r
1525 \r
1526             string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + videoFramerate + turboH264 + largeFile + deblock + detelecine + denoise;\r
1527             // ----------------------------------------------------------------------\r
1528 \r
1529             // Audio Settings Tab\r
1530 \r
1531             string audioBitrate = drp_audioBitrate.Text;\r
1532             string audioSampleRate = drp_audioSampleRate.Text;\r
1533             string audioChannels = drp_audioChannels.Text;\r
1534             string Mixdown = drp_audioMixDown.Text;\r
1535             string SixChannelAudio = "";\r
1536 \r
1537             if (audioBitrate !=  "")\r
1538                 audioBitrate = " -B "+ audioBitrate;\r
1539 \r
1540             if (audioSampleRate !=  "")\r
1541                 audioSampleRate = " -R "+ audioSampleRate;\r
1542 \r
1543             if (audioChannels ==  "Automatic")\r
1544                 audioChannels = "";\r
1545             else if (audioChannels ==  "")\r
1546                 audioChannels = "";\r
1547             else\r
1548             {\r
1549                 string[] tempSub;\r
1550                 tempSub = audioChannels.Split(' ');\r
1551                 audioChannels = " -a "+ tempSub[0];\r
1552             }\r
1553 \r
1554             switch (Mixdown)\r
1555             {\r
1556                 case "Automatic":\r
1557                     Mixdown = "";\r
1558                     break;\r
1559                 case "Mono":\r
1560                     Mixdown = "mono";\r
1561                     break;\r
1562                 case "Stereo":\r
1563                     Mixdown = "stereo";\r
1564                     break;\r
1565                 case "Dolby Surround":\r
1566                     Mixdown = "dpl1";\r
1567                     break;\r
1568                 case "Dolby Pro Logic II":\r
1569                     Mixdown = "dpl2";\r
1570                     break;\r
1571                 case "6 Channel Discrete":\r
1572                     Mixdown = "6ch";\r
1573                     break;\r
1574                 default:\r
1575                     Mixdown = "stero";\r
1576                     break;\r
1577             }\r
1578 \r
1579             if (Mixdown !=  "")\r
1580                 SixChannelAudio = " -6 "+ Mixdown;\r
1581             else\r
1582                 SixChannelAudio = "";\r
1583 \r
1584             string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
1585             // ----------------------------------------------------------------------\r
1586 \r
1587             //  H.264 Tab\r
1588 \r
1589             \r
1590             string h264Advanced = rtf_h264advanced.Text;\r
1591             \r
1592             if ((h264Advanced ==  ""))\r
1593                 h264Advanced = "";\r
1594             else\r
1595                 h264Advanced = " -x "+ h264Advanced;\r
1596     \r
1597 \r
1598             string h264Settings = h264Advanced;\r
1599             // ----------------------------------------------------------------------\r
1600 \r
1601             // Processors (Program Settings)\r
1602 \r
1603             string processors = Properties.Settings.Default.Processors;\r
1604             //  Number of Processors Handler\r
1605 \r
1606             if (processors ==  "Automatic")\r
1607                 processors = "";\r
1608             else\r
1609                 processors = " -C "+ processors+ " ";\r
1610 \r
1611 \r
1612             string queryAdvancedSettings = processors;\r
1613             // ----------------------------------------------------------------------\r
1614 \r
1615             //  Verbose option (Program Settings)\r
1616 \r
1617             string verbose = "";\r
1618             if (Properties.Settings.Default.verbose ==  "Checked")\r
1619                 verbose = " -v ";\r
1620 \r
1621             // ----------------------------------------------------------------------\r
1622 \r
1623             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
1624         }\r
1625 \r
1626         #endregion\r
1627 \r
1628 \r
1629       \r
1630 \r
1631 \r
1632         // This is the END of the road ------------------------------------------------------------------------------\r
1633     }\r
1634 }