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