OSDN Git Service

WinGui: more cleanup in frmMain
[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 System.Diagnostics.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 frmDvdInfo dvdInfoWindow = new frmDvdInfo();\r
24         private frmQueue queueWindow = new frmQueue();\r
25 \r
26         public frmMain()\r
27         {\r
28             InitializeComponent();\r
29 \r
30             // Set the Version number lable to the corect version.\r
31             Version.Text = "Version " + Properties.Settings.Default.GuiVersion;\r
32 \r
33             // Run the update checker.\r
34             updateCheck();\r
35 \r
36             // Now load the users default if required.\r
37             loadUserDefaults();\r
38         }\r
39 \r
40         public void loadUserDefaults()\r
41         { \r
42             try\r
43             {\r
44                 if (Properties.Settings.Default.defaultSettings == "Checked")\r
45                 {\r
46                     // Source\r
47                     text_source.Text = Properties.Settings.Default.DVDSource;\r
48                     drp_dvdtitle.Text = Properties.Settings.Default.DVDTitle;\r
49                     drop_chapterStart.Text = Properties.Settings.Default.ChapterStart;\r
50                     drop_chapterFinish.Text = Properties.Settings.Default.ChapterFinish;\r
51 \r
52                     // Destination\r
53                     text_destination.Text = Properties.Settings.Default.VideoDest;\r
54                     drp_videoEncoder.Text = Properties.Settings.Default.VideoEncoder;\r
55                     drp_audioCodec.Text = Properties.Settings.Default.AudioEncoder;\r
56                     text_width.Text = Properties.Settings.Default.Width;\r
57                     text_height.Text = Properties.Settings.Default.Height;\r
58 \r
59                     // Picture Settings Tab\r
60                     drp_crop.Text = Properties.Settings.Default.CroppingOption;\r
61                     text_top.Text = Properties.Settings.Default.CropTop;\r
62                     text_bottom.Text = Properties.Settings.Default.CropBottom;\r
63                     text_left.Text = Properties.Settings.Default.CropLeft;\r
64                     text_right.Text = Properties.Settings.Default.CropRight;\r
65                     drp_subtitle.Text = Properties.Settings.Default.Subtitles;\r
66 \r
67                     // Video Settings Tab\r
68                     text_bitrate.Text = Properties.Settings.Default.VideoBitrate;\r
69                     text_filesize.Text = Properties.Settings.Default.VideoFilesize;\r
70                     slider_videoQuality.Value = Properties.Settings.Default.VideoQuality;\r
71 \r
72                     if (Properties.Settings.Default.TwoPass == "Checked")\r
73                     {\r
74                         check_2PassEncode.CheckState = CheckState.Checked;\r
75                     }\r
76                     if (Properties.Settings.Default.DeInterlace == "Checked")\r
77                     {\r
78                         check_DeInterlace.CheckState = CheckState.Checked;\r
79                     }\r
80                     if (Properties.Settings.Default.Grayscale == "Checked")\r
81                     {\r
82                         check_grayscale.CheckState = CheckState.Checked;\r
83                     }\r
84 \r
85                     drp_videoFramerate.Text = Properties.Settings.Default.Framerate;\r
86 \r
87                     if (Properties.Settings.Default.PixelRatio == "Checked")\r
88                     {\r
89                         CheckPixelRatio.CheckState = CheckState.Checked;\r
90                     }\r
91                     if (Properties.Settings.Default.turboFirstPass == "Checked")\r
92                     {\r
93                         check_turbo.CheckState = CheckState.Checked;\r
94                     }\r
95                     if (Properties.Settings.Default.largeFile == "Checked")\r
96                     {\r
97                         check_largeFile.CheckState = CheckState.Checked;\r
98                     }\r
99                     // Audio Settings Tab\r
100                     drp_audioBitrate.Text = Properties.Settings.Default.AudioBitrate;\r
101                     drp_audioSampleRate.Text = Properties.Settings.Default.AudioSampleRate;\r
102                     drp_audioChannels.Text = Properties.Settings.Default.AudioChannels;\r
103 \r
104                     // H264 Tab\r
105                     if (Properties.Settings.Default.CRF == "Checked")\r
106                     {\r
107                         CheckCRF.CheckState = CheckState.Checked;\r
108                     }\r
109                     rtf_h264advanced.Text = Properties.Settings.Default.H264;\r
110                 }\r
111             }\r
112             catch (Exception)\r
113             {\r
114                 // No real need to alert the user. Try/Catch only in just incase there is a problem reading the settings xml file.\r
115             }\r
116         }\r
117 \r
118         public void updateCheck()\r
119         {\r
120             if (Properties.Settings.Default.updateStatus == "Checked")\r
121             {\r
122 \r
123                 try\r
124                 {\r
125                     String updateFile = Properties.Settings.Default.updateFile;\r
126                     WebClient client = new WebClient();\r
127                     String data = client.DownloadString(updateFile);\r
128                     String[] versionData = data.Split('\n');\r
129 \r
130                     if ((versionData[0] != Properties.Settings.Default.GuiVersion) || (versionData[1] != Properties.Settings.Default.CliVersion))\r
131                     {\r
132                         lbl_update.Visible = true;\r
133                     }\r
134                 }\r
135                 // else fail displaying an error message.\r
136                 catch (Exception)\r
137                 {\r
138                     // Silently ignore the error\r
139                 }\r
140             }\r
141         }\r
142 \r
143         #region The Menu Bar\r
144 \r
145         #region File Menu\r
146 \r
147         private void mnu_open_Click(object sender, EventArgs e)\r
148         {\r
149             string filename;\r
150             File_Open.ShowDialog();\r
151             filename = File_Open.FileName;\r
152             if (filename != "")\r
153             {\r
154                 try\r
155                 {\r
156                     // Create StreamReader & open file\r
157                     StreamReader line = new StreamReader(filename);\r
158                     string temporyLine; // Used for reading the line into a varible before processing on the checkState items below.\r
159                     \r
160                     // Read in the data and set the correct GUI component with the setting.\r
161                     text_source.Text = line.ReadLine();\r
162                     drp_dvdtitle.Text = line.ReadLine();\r
163                     drop_chapterStart.Text = line.ReadLine();\r
164                     drop_chapterFinish.Text = line.ReadLine();\r
165                     text_destination.Text = line.ReadLine();\r
166                     drp_videoEncoder.Text = line.ReadLine();\r
167                     drp_audioCodec.Text = line.ReadLine();\r
168                     text_width.Text = line.ReadLine();\r
169                     text_height.Text = line.ReadLine();\r
170                     text_top.Text = line.ReadLine();\r
171                     text_bottom.Text = line.ReadLine();\r
172                     text_left.Text = line.ReadLine();\r
173                     text_right.Text = line.ReadLine();\r
174                     drp_subtitle.Text = line.ReadLine();\r
175                     text_bitrate.Text = line.ReadLine();\r
176                     text_filesize.Text = line.ReadLine();\r
177                     slider_videoQuality.Value = int.Parse(line.ReadLine());\r
178 \r
179                     temporyLine = line.ReadLine();\r
180                     if (temporyLine == "Checked")\r
181                     {\r
182                         check_2PassEncode.CheckState = CheckState.Checked;\r
183                     }\r
184 \r
185                     temporyLine = line.ReadLine();\r
186                     if (temporyLine == "Checked")\r
187                     {\r
188                         check_DeInterlace.CheckState = CheckState.Checked;\r
189                     }\r
190 \r
191                     temporyLine = line.ReadLine();\r
192                     if (temporyLine == "Checked")\r
193                     {\r
194                         check_grayscale.CheckState = CheckState.Checked;\r
195                     }\r
196 \r
197                     drp_videoFramerate.Text = line.ReadLine();\r
198 \r
199                     temporyLine = line.ReadLine();\r
200                     if (temporyLine == "Checked")\r
201                     {\r
202                         Check_ChapterMarkers.CheckState = CheckState.Checked;\r
203                     }\r
204 \r
205                     temporyLine = line.ReadLine();\r
206                     if (temporyLine == "Checked")\r
207                     {\r
208                         CheckPixelRatio.CheckState = CheckState.Checked;\r
209                     }\r
210 \r
211                     temporyLine = line.ReadLine();\r
212                     if (temporyLine == "Checked")\r
213                     {\r
214                         check_turbo.CheckState = CheckState.Checked;\r
215                     }\r
216 \r
217                     temporyLine = line.ReadLine();\r
218                     if (temporyLine == "Checked")\r
219                     {\r
220                         check_largeFile.CheckState = CheckState.Checked;\r
221                     }\r
222    \r
223                     drp_audioBitrate.Text = line.ReadLine();\r
224                     drp_audioSampleRate.Text = line.ReadLine();\r
225                     drp_audioChannels.Text = line.ReadLine();\r
226                     drp_audioMixDown.Text = line.ReadLine();\r
227                     \r
228                     // Advanced H264 Options\r
229                     temporyLine = line.ReadLine();\r
230                     if (temporyLine == "Checked")\r
231                     {\r
232                         CheckCRF.CheckState = CheckState.Checked;\r
233                     }\r
234                     rtf_h264advanced.Text = line.ReadLine();\r
235 \r
236                     // Close the stream\r
237                     line.Close();\r
238 \r
239 \r
240                     // Fix for SliderValue not appearing when Opening saved file\r
241                     SliderValue.Text = slider_videoQuality.Value + "%";\r
242 \r
243                 } catch (Exception){\r
244                     MessageBox.Show("Unable to load profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
245                 }\r
246             }\r
247         }\r
248 \r
249         private void mnu_save_Click(object sender, EventArgs e)\r
250         {\r
251 \r
252             string filename;\r
253             File_Save.ShowDialog();\r
254             filename = File_Save.FileName;\r
255             if (filename != "")\r
256             {\r
257                 try\r
258                 {\r
259                     // Create a StreamWriter and open the file\r
260                     StreamWriter line = new StreamWriter(filename);\r
261 \r
262                     //Source\r
263                     line.WriteLine(text_source.Text);\r
264                     line.WriteLine(drp_dvdtitle.Text);\r
265                     line.WriteLine(drop_chapterStart.Text);\r
266                     line.WriteLine(drop_chapterFinish.Text);\r
267                     //Destination\r
268                     line.WriteLine(text_destination.Text);\r
269                     line.WriteLine(drp_videoEncoder.Text);\r
270                     line.WriteLine(drp_audioCodec.Text);\r
271                     line.WriteLine(text_width.Text);\r
272                     line.WriteLine(text_height.Text);\r
273                     //Picture Settings Tab\r
274                     line.WriteLine(text_top.Text);\r
275                     line.WriteLine(text_bottom.Text);\r
276                     line.WriteLine(text_left.Text);\r
277                     line.WriteLine(text_right.Text);\r
278                     line.WriteLine(drp_subtitle.Text);\r
279                     //Video Settings Tab\r
280                     line.WriteLine(text_bitrate.Text);\r
281                     line.WriteLine(text_filesize.Text);\r
282                     line.WriteLine(slider_videoQuality.Value.ToString());\r
283                     line.WriteLine(check_2PassEncode.CheckState.ToString());\r
284                     line.WriteLine(check_DeInterlace.CheckState.ToString());\r
285                     line.WriteLine(check_grayscale.CheckState.ToString());\r
286                     line.WriteLine(drp_videoFramerate.Text);\r
287                     line.WriteLine(Check_ChapterMarkers.CheckState.ToString());\r
288                     line.WriteLine(CheckPixelRatio.CheckState.ToString());\r
289                     line.WriteLine(check_turbo.CheckState.ToString());\r
290                     line.WriteLine(check_largeFile.CheckState.ToString());\r
291                     //Audio Settings Tab\r
292                     line.WriteLine(drp_audioBitrate.Text);\r
293                     line.WriteLine(drp_audioSampleRate.Text);\r
294                     line.WriteLine(drp_audioChannels.Text);\r
295                     line.WriteLine(drp_audioMixDown.Text);\r
296                     //H264 Tab\r
297                     line.WriteLine(CheckCRF.CheckState.ToString());\r
298                     line.WriteLine(rtf_h264advanced.Text);\r
299                     // close the stream\r
300                     line.Close();\r
301                     MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
302                 }\r
303                 catch(Exception)\r
304                 {\r
305                     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
306                 }\r
307                 \r
308             }\r
309         }\r
310 \r
311         private void mnu_update_Click(object sender, EventArgs e)\r
312         {\r
313             Form Update = new frmUpdate();\r
314             Update.ShowDialog();\r
315         }\r
316 \r
317         private void mnu_exit_Click(object sender, EventArgs e)\r
318         {\r
319             this.Close();\r
320         }\r
321 \r
322         #endregion\r
323 \r
324         #region Tools Menu\r
325 \r
326         private void mnu_encode_Click(object sender, EventArgs e)\r
327         {\r
328             showQueue();\r
329         }\r
330 \r
331         private void mnu_viewDVDdata_Click(object sender, EventArgs e)\r
332         {\r
333             dvdInfoWindow.Show();\r
334         }\r
335 \r
336         private void mnu_options_Click(object sender, EventArgs e)\r
337         {\r
338             Form Options = new frmOptions();\r
339             Options.ShowDialog();\r
340         }\r
341 \r
342         #endregion\r
343 \r
344         #region Presets Menu\r
345 \r
346         private void mnu_preset_ipod133_Click(object sender, EventArgs e)\r
347         {\r
348             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
349             text_width.Text = "640";\r
350             text_height.Text = "480";\r
351             drp_videoEncoder.Text = "H.264 (iPod)";\r
352             text_bitrate.Text = "1000";\r
353             text_filesize.Text = "";\r
354             slider_videoQuality.Value = 0;\r
355             SliderValue.Text = "0%";\r
356             drp_audioBitrate.Text = "160";\r
357             rtf_h264advanced.Text = "";\r
358             drp_crop.Text = "No Crop";\r
359         }\r
360 \r
361         private void mnu_preset_ipod178_Click(object sender, EventArgs e)\r
362         {\r
363             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
364             text_width.Text = "640";\r
365             text_height.Text = "352";\r
366             drp_videoEncoder.Text = "H.264 (iPod)";\r
367             text_bitrate.Text = "1000";\r
368             text_filesize.Text = "";\r
369             slider_videoQuality.Value = 0;\r
370             SliderValue.Text = "0%";\r
371             drp_audioBitrate.Text = "160";\r
372             rtf_h264advanced.Text = "";\r
373             drp_crop.Text = "No Crop";\r
374         }\r
375 \r
376         private void mnu_preset_ipod235_Click(object sender, EventArgs e)\r
377         {\r
378             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
379             text_width.Text = "640";\r
380             text_height.Text = "272";\r
381             drp_videoEncoder.Text = "H.264 (iPod)";\r
382             text_bitrate.Text = "1000";\r
383             text_filesize.Text = "";\r
384             slider_videoQuality.Value = 0;\r
385             SliderValue.Text = "0%";\r
386             drp_audioBitrate.Text = "160";\r
387             rtf_h264advanced.Text = "";\r
388             drp_crop.Text = "No Crop";\r
389         }\r
390 \r
391         private void mnu_appleTv_Click(object sender, EventArgs e)\r
392         {\r
393             text_width.Text = "";\r
394             text_height.Text = "";\r
395             drp_videoEncoder.Text = "H.264";\r
396             text_bitrate.Text = "3000";\r
397             text_filesize.Text = "";\r
398             slider_videoQuality.Value = 0;\r
399             SliderValue.Text = "0%";\r
400             drp_audioBitrate.Text = "160";\r
401             CheckPixelRatio.CheckState = CheckState.Checked;\r
402             drp_audioSampleRate.Text = "48";\r
403             rtf_h264advanced.Text = "bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:no-dct-decimate=1:trellis=2";\r
404             drp_crop.Text = "No Crop";\r
405             \r
406         }\r
407 \r
408         private void mnu_presetPS3_Click(object sender, EventArgs e)\r
409         {\r
410             CheckPixelRatio.CheckState = CheckState.Unchecked;\r
411             text_width.Text = "";\r
412             text_height.Text = "";\r
413             drp_videoEncoder.Text = "H.264";\r
414             text_bitrate.Text = "3000";\r
415             text_filesize.Text = "";\r
416             slider_videoQuality.Value = 0;\r
417             SliderValue.Text = "0%";\r
418             drp_audioBitrate.Text = "160";\r
419             CheckPixelRatio.CheckState = CheckState.Checked;\r
420             drp_audioSampleRate.Text = "48";\r
421             rtf_h264advanced.Text = "level=41";\r
422             drp_crop.Text = "No Crop";\r
423         }\r
424 \r
425         private void mnu_ProgramDefaultOptions_Click(object sender, EventArgs e)\r
426         {\r
427             //Source\r
428             Properties.Settings.Default.DVDSource = text_source.Text;\r
429             Properties.Settings.Default.DVDTitle = drp_dvdtitle.Text;\r
430             Properties.Settings.Default.ChapterStart = drop_chapterStart.Text;\r
431             Properties.Settings.Default.ChapterFinish = drop_chapterFinish.Text;\r
432             //Destination\r
433             Properties.Settings.Default.VideoDest = text_destination.Text;\r
434             Properties.Settings.Default.VideoEncoder = drp_videoEncoder.Text;\r
435             Properties.Settings.Default.AudioEncoder = drp_audioCodec.Text;\r
436             Properties.Settings.Default.Width = text_width.Text;\r
437             Properties.Settings.Default.Height = text_height.Text;\r
438             //Picture Settings Tab\r
439             Properties.Settings.Default.CroppingOption = drp_crop.Text;\r
440             Properties.Settings.Default.CropTop = text_top.Text;\r
441             Properties.Settings.Default.CropBottom = text_bottom.Text;\r
442             Properties.Settings.Default.CropLeft = text_left.Text;\r
443             Properties.Settings.Default.CropRight = text_right.Text;\r
444             Properties.Settings.Default.Subtitles = drp_subtitle.Text;\r
445             //Video Settings Tab\r
446             Properties.Settings.Default.VideoBitrate = text_bitrate.Text;\r
447             Properties.Settings.Default.VideoFilesize = text_filesize.Text;\r
448             Properties.Settings.Default.VideoQuality = slider_videoQuality.Value;\r
449             Properties.Settings.Default.TwoPass = check_2PassEncode.CheckState.ToString();\r
450             Properties.Settings.Default.DeInterlace = check_DeInterlace.CheckState.ToString();\r
451             Properties.Settings.Default.Grayscale = check_grayscale.CheckState.ToString();\r
452             Properties.Settings.Default.Framerate = drp_videoFramerate.Text;\r
453             Properties.Settings.Default.PixelRatio = CheckPixelRatio.CheckState.ToString();\r
454             Properties.Settings.Default.turboFirstPass = check_turbo.CheckState.ToString();\r
455             Properties.Settings.Default.largeFile = check_largeFile.CheckState.ToString();\r
456             //Audio Settings Tab\r
457             Properties.Settings.Default.AudioBitrate = drp_audioBitrate.Text;\r
458             Properties.Settings.Default.AudioSampleRate = drp_audioSampleRate.Text;\r
459             Properties.Settings.Default.AudioChannels = drp_audioChannels.Text;\r
460             //H264 Tab\r
461             Properties.Settings.Default.CRF = CheckCRF.CheckState.ToString();\r
462             Properties.Settings.Default.H264 = rtf_h264advanced.Text;\r
463             Properties.Settings.Default.Save();\r
464         }\r
465 \r
466         #endregion\r
467 \r
468         #region Help Menu\r
469 \r
470         private void mnu_wiki_Click(object sender, EventArgs e)\r
471         {\r
472            Process.Start("http://handbrake.m0k.org/trac");\r
473         }\r
474 \r
475         private void mnu_onlineDocs_Click(object sender, EventArgs e)\r
476         {\r
477             Process.Start("http://handbrake.m0k.org/?page_id=11");\r
478         }\r
479 \r
480         private void mnu_faq_Click(object sender, EventArgs e)\r
481         {\r
482             Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");\r
483         }\r
484 \r
485         private void mnu_homepage_Click(object sender, EventArgs e)\r
486         {\r
487            Process.Start("http://handbrake.m0k.org");\r
488         }\r
489 \r
490         private void mnu_forum_Click(object sender, EventArgs e)\r
491         {\r
492             Process.Start("http://handbrake.m0k.org/forum");\r
493         }\r
494 \r
495         private void mnu_about_Click(object sender, EventArgs e)\r
496         {\r
497                         Form About = new frmAbout();\r
498             About.ShowDialog();\r
499         }\r
500 \r
501         #endregion\r
502 \r
503         #endregion\r
504 \r
505         // -------------------------------------------------------------- \r
506         // Buttons on the main Window\r
507         // --------------------------------------------------------------\r
508         private void btn_Browse_Click(object sender, EventArgs e)\r
509         {\r
510             \r
511             String filename ="";\r
512             text_source.Text = "";\r
513 \r
514             if (RadioDVD.Checked)\r
515             {\r
516                 DVD_Open.ShowDialog();\r
517                 filename = DVD_Open.SelectedPath;\r
518                 if (filename != "")\r
519                 {\r
520                     text_source.Text = filename;\r
521                     Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);\r
522                     frmReadDVD.ShowDialog();\r
523                 }\r
524             }\r
525             else\r
526             {\r
527                 ISO_Open.ShowDialog();\r
528                 filename = ISO_Open.FileName;\r
529                 if (filename != "")\r
530                 {\r
531                     text_source.Text = filename;\r
532                     Form frmReadDVD = new frmReadDVD(filename, this, dvdInfoWindow);\r
533                     frmReadDVD.ShowDialog();\r
534                 }\r
535             }  \r
536 \r
537             // Quick check to make sure some titles were found.\r
538             if (filename != "")\r
539             {\r
540                 if (drp_dvdtitle.Items.Count == 0)\r
541                 {\r
542                     MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
543                 }\r
544             }\r
545             else\r
546             {\r
547                 text_source.Text = "Click 'Browse' to continue";\r
548             }\r
549 \r
550         }\r
551 \r
552         private void btn_destBrowse_Click(object sender, EventArgs e)\r
553         {\r
554             // TODO: Need to write some code to check if there is a reasonable amount of disk space left.\r
555 \r
556             DVD_Save.ShowDialog();\r
557             text_destination.Text = DVD_Save.FileName;\r
558 \r
559             if (Check_ChapterMarkers.Checked)\r
560             {\r
561                 string destination = text_destination.Text;\r
562                 destination = destination.Replace(".mp4", ".m4v");\r
563                 text_destination.Text = destination;\r
564             }\r
565         }\r
566 \r
567         private void btn_h264Clear_Click(object sender, EventArgs e)\r
568         {\r
569             rtf_h264advanced.Text = "";\r
570         }\r
571 \r
572         private void GenerateQuery_Click(object sender, EventArgs e)\r
573         {\r
574             String query = GenerateTheQuery();\r
575             QueryEditorText.Text = query;\r
576         }\r
577 \r
578         private void btn_ClearQuery_Click(object sender, EventArgs e)\r
579         {\r
580             QueryEditorText.Text = "";\r
581         }\r
582 \r
583         private void btn_queue_Click(object sender, EventArgs e)\r
584         {\r
585             String query = GenerateTheQuery();\r
586             queueWindow.list_queue.Items.Add(query);\r
587             queueWindow.Show();\r
588         }\r
589 \r
590         private void showQueue()\r
591         {\r
592             queueWindow.Show();\r
593         }\r
594 \r
595         private void btn_encode_Click(object sender, EventArgs e)\r
596         {\r
597             String query = "";\r
598  \r
599             if (QueryEditorText.Text == "")\r
600             {\r
601                 query = GenerateTheQuery();\r
602             }\r
603             else\r
604             {\r
605                 query = QueryEditorText.Text;\r
606             }\r
607 \r
608             hbProc = new System.Diagnostics.Process();\r
609             hbProc.StartInfo.FileName = "hbcli.exe";\r
610             hbProc.StartInfo.Arguments = query;\r
611             hbProc.StartInfo.UseShellExecute = false;\r
612             hbProc.Start();\r
613 \r
614             // Set the process Priority\r
615             string priority = Properties.Settings.Default.processPriority;\r
616             switch (priority)\r
617             {\r
618                 case "Realtime":\r
619                     hbProc.PriorityClass = ProcessPriorityClass.RealTime;\r
620                     break;\r
621                 case "High":\r
622                     hbProc.PriorityClass = ProcessPriorityClass.High;\r
623                     break;\r
624                 case "Above Normal":\r
625                     hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;\r
626                     break;\r
627                 case "Normal":\r
628                     hbProc.PriorityClass = ProcessPriorityClass.Normal;\r
629                     break;\r
630                 case "Low":\r
631                     hbProc.PriorityClass = ProcessPriorityClass.Idle;\r
632                     break;\r
633                 default:\r
634                     hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;\r
635                     break;\r
636             }\r
637 \r
638             ThreadPool.QueueUserWorkItem(procMonitor);\r
639             // TODO: Need to write a bit of code here to do process monitoring.\r
640         }\r
641 \r
642         private void procMonitor(object state)\r
643         {\r
644             MessageBox.Show("The encode process has now started.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
645             hbProc.WaitForExit();\r
646             hbProc.Close();\r
647             hbProc.Dispose();\r
648             MessageBox.Show("The encode process has now ended.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
649         }\r
650 \r
651 \r
652         //---------------------------------------------------\r
653         //  Items that require actions on frmMain\r
654         //---------------------------------------------------\r
655 \r
656         private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)\r
657         {\r
658             QueryEditorText.Text = "";\r
659             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
660             {\r
661                 try\r
662                 {\r
663                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
664                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
665 \r
666                     if (chapterFinish < chapterStart)\r
667                     {\r
668                         MessageBox.Show("Invalid Chapter Range! - Final chapter can not be smaller than the starting chapter.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
669                     }\r
670                 }\r
671                 catch (Exception)\r
672                 {\r
673                     MessageBox.Show("Invalid Character Entered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
674                 }\r
675             }\r
676 \r
677             \r
678         }\r
679 \r
680         private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)\r
681         {\r
682             QueryEditorText.Text = "";\r
683             if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))\r
684             {\r
685                 try\r
686                 {\r
687                     int chapterFinish = int.Parse(drop_chapterFinish.Text);\r
688                     int chapterStart = int.Parse(drop_chapterStart.Text);\r
689 \r
690                     if (chapterFinish < chapterStart)\r
691                     {\r
692                         MessageBox.Show("Invalid Chapter Range! - Start chapter can not be larger than the Final chapter.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
693                     }\r
694                 }\r
695                 catch (Exception)\r
696                 {\r
697                     MessageBox.Show("Invalid Character Entered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
698                 }\r
699             }\r
700         }\r
701 \r
702         private void text_bitrate_TextChanged(object sender, EventArgs e)\r
703         {\r
704             text_filesize.Text = "";\r
705             slider_videoQuality.Value = 0;\r
706             SliderValue.Text = "0%";\r
707             CheckCRF.CheckState = CheckState.Unchecked;\r
708         }\r
709 \r
710         private void text_filesize_TextChanged(object sender, EventArgs e)\r
711         {\r
712             text_bitrate.Text = "";\r
713             slider_videoQuality.Value = 0;\r
714             SliderValue.Text = "0%";\r
715             CheckCRF.CheckState = CheckState.Unchecked;\r
716         }\r
717 \r
718         private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
719         {\r
720             SliderValue.Text = slider_videoQuality.Value.ToString() + "%";\r
721             text_bitrate.Text = "";\r
722             text_filesize.Text = "";\r
723         }\r
724 \r
725         private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
726         {\r
727             Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");\r
728         }\r
729 \r
730         private void text_width_TextChanged(object sender, EventArgs e)\r
731         {\r
732             try\r
733             {\r
734                 if (CheckPixelRatio.Checked) {\r
735                     text_width.Text = "";\r
736                 } else {\r
737                     if ((int.Parse(text_width.Text) % 16) != 0){\r
738                         text_width.BackColor = Color.LightCoral;\r
739                     }else {\r
740                         text_width.BackColor = Color.LightGreen;\r
741                     }\r
742                 }\r
743 \r
744                 // There is a bug here *******************************************************************\r
745                 if (!lbl_Aspect.Text.Equals("Select a Title")){\r
746                     int height = int.Parse(text_width.Text) / int.Parse(lbl_Aspect.Text);\r
747                     MessageBox.Show("test");\r
748                     int mod16 = height % 16;\r
749                     height = height - mod16;\r
750                     text_height.Text = height.ToString();\r
751                 }\r
752                \r
753             } catch(Exception){\r
754                 // No need to alert the user if there is a problem here.\r
755             }\r
756         }\r
757 \r
758         private void text_height_TextChanged(object sender, EventArgs e)\r
759         {\r
760             try\r
761             {\r
762                 if (CheckPixelRatio.Checked)\r
763                 {\r
764                     text_height.Text = "";\r
765                 }\r
766                 else\r
767                 {\r
768                     if ((int.Parse(text_height.Text) % 16) != 0)\r
769                     {\r
770                         text_height.BackColor = Color.LightCoral;\r
771                     }\r
772                     else\r
773                     {\r
774                         text_height.BackColor = Color.LightGreen;\r
775                     }\r
776                 }\r
777             } catch(Exception){\r
778                 // No need to alert the user.\r
779             }\r
780         }\r
781 \r
782         private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)\r
783         {\r
784             if ((string)drp_crop.SelectedItem == "Manual")\r
785             {\r
786             text_left.Enabled = true;\r
787             text_right.Enabled = true;\r
788             text_top.Enabled = true;\r
789             text_bottom.Enabled = true;\r
790             }\r
791 \r
792             if ((string)drp_crop.SelectedItem == "Auto Crop")\r
793             {\r
794                 text_left.Enabled = false;\r
795                 text_right.Enabled = false;\r
796                 text_top.Enabled = false;\r
797                 text_bottom.Enabled = false;\r
798                 text_left.Text = "";\r
799                 text_right.Text = "";\r
800                 text_top.Text = "";\r
801                 text_bottom.Text = "";\r
802 \r
803                 if (lbl_RecomendedCrop.Text != "Select a Title")\r
804                 {\r
805                     string[] temp = new string[4];\r
806                     temp = lbl_RecomendedCrop.Text.Split('/');\r
807                     text_left.Text = temp[2];\r
808                     text_right.Text = temp[3];\r
809                     text_top.Text = temp[0];\r
810                     text_bottom.Text = temp[1];\r
811                 }\r
812             }\r
813 \r
814             if ((string)drp_crop.SelectedItem == "No Crop")\r
815             {\r
816                 text_left.Enabled = false;\r
817                 text_right.Enabled = false;\r
818                 text_top.Enabled = false;\r
819                 text_bottom.Enabled = false;\r
820                 text_left.Text = "0";\r
821                 text_right.Text = "0";\r
822                 text_top.Text = "0";\r
823                 text_bottom.Text = "0";\r
824 \r
825             }\r
826         }\r
827         \r
828         private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)\r
829         {\r
830             text_width.Text = "";\r
831             text_height.Text = "";\r
832             text_width.BackColor = Color.White;\r
833             text_height.BackColor = Color.White;\r
834         }\r
835 \r
836         private void drp_dvdtitle_Click(object sender, EventArgs e)\r
837         {\r
838             if (drp_dvdtitle.Items.Count == 1)\r
839             {\r
840                 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
841             }\r
842         }\r
843 \r
844         private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)\r
845         {\r
846 \r
847             //CLI Audio mixdown Names: mono stereo dpl1 dpl2 6ch\r
848 \r
849             drp_audioMixDown.Items.Clear();\r
850 \r
851             if (drp_audioCodec.Text == "AAC")\r
852             {\r
853                 drp_audioMixDown.Items.Clear();\r
854                 drp_audioMixDown.Items.Add("Mono");\r
855                 drp_audioMixDown.Items.Add("Stereo");\r
856                 drp_audioMixDown.Items.Add("Dolby Surround");\r
857                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
858                 drp_audioMixDown.Items.Add("6 Channel Discrete");\r
859                 \r
860                 drp_audioBitrate.Items.Clear();\r
861                 drp_audioBitrate.Items.Add("32");\r
862                 drp_audioBitrate.Items.Add("40");\r
863                 drp_audioBitrate.Items.Add("48");\r
864                 drp_audioBitrate.Items.Add("56");\r
865                 drp_audioBitrate.Items.Add("64");\r
866                 drp_audioBitrate.Items.Add("80");\r
867                 drp_audioBitrate.Items.Add("86");\r
868                 drp_audioBitrate.Items.Add("112");\r
869                 drp_audioBitrate.Items.Add("128");\r
870                 drp_audioBitrate.Items.Add("160");\r
871 \r
872             }\r
873             else\r
874             {\r
875                 drp_audioMixDown.Items.Clear();\r
876                 drp_audioMixDown.Items.Add("Stereo");\r
877                 drp_audioMixDown.Items.Add("Dolby Surround");\r
878                 drp_audioMixDown.Items.Add("Dolby Pro Logic II");\r
879 \r
880                 drp_audioBitrate.Items.Clear();\r
881                 drp_audioBitrate.Items.Add("32");\r
882                 drp_audioBitrate.Items.Add("40");\r
883                 drp_audioBitrate.Items.Add("48");\r
884                 drp_audioBitrate.Items.Add("56");\r
885                 drp_audioBitrate.Items.Add("64");\r
886                 drp_audioBitrate.Items.Add("80");\r
887                 drp_audioBitrate.Items.Add("86");\r
888                 drp_audioBitrate.Items.Add("112");\r
889                 drp_audioBitrate.Items.Add("128");\r
890                 drp_audioBitrate.Items.Add("160");\r
891                 drp_audioBitrate.Items.Add("192");\r
892                 drp_audioBitrate.Items.Add("224");\r
893                 drp_audioBitrate.Items.Add("256");\r
894                 drp_audioBitrate.Items.Add("320");\r
895                 drp_audioBitrate.Items.Add("384");\r
896             }\r
897         }\r
898 \r
899         private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)\r
900         {\r
901             if (drp_audioCodec.Text == "AAC")\r
902             {\r
903                 if (drp_audioMixDown.Text == "6 Channel Discrete")\r
904                 {\r
905 \r
906                     drp_audioBitrate.Items.Clear();\r
907                     drp_audioBitrate.Items.Add("32");\r
908                     drp_audioBitrate.Items.Add("40");\r
909                     drp_audioBitrate.Items.Add("48");\r
910                     drp_audioBitrate.Items.Add("56");\r
911                     drp_audioBitrate.Items.Add("64");\r
912                     drp_audioBitrate.Items.Add("80");\r
913                     drp_audioBitrate.Items.Add("86");\r
914                     drp_audioBitrate.Items.Add("112");\r
915                     drp_audioBitrate.Items.Add("128");\r
916                     drp_audioBitrate.Items.Add("160");\r
917                     drp_audioBitrate.Items.Add("192");\r
918                     drp_audioBitrate.Items.Add("224");\r
919                     drp_audioBitrate.Items.Add("256");\r
920                     drp_audioBitrate.Items.Add("320");\r
921                     drp_audioBitrate.Items.Add("384");\r
922                 }\r
923             }\r
924         }\r
925 \r
926         private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)\r
927         {\r
928             if (Check_ChapterMarkers.Checked)\r
929             {\r
930                 string destination = text_destination.Text;\r
931                 destination = destination.Replace(".mp4", ".m4v");\r
932                 text_destination.Text = destination;\r
933             }\r
934         }\r
935 \r
936         private void check_largeFile_CheckedChanged(object sender, EventArgs e)\r
937         {\r
938             if (!text_destination.Text.Contains(".mp4"))\r
939             {\r
940                 MessageBox.Show("This option is only compatible with the mp4 file container.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
941                 check_largeFile.CheckState = CheckState.Unchecked;\r
942             }\r
943         }\r
944 \r
945         private void check_turbo_CheckedChanged(object sender, EventArgs e)\r
946         {\r
947             if (!drp_videoEncoder.Text.Contains("H.264"))\r
948             {\r
949                 MessageBox.Show("This option is only compatible with the H.264 encoder's", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
950                 check_turbo.CheckState = CheckState.Unchecked;\r
951             }\r
952         }\r
953 \r
954         private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
955         {\r
956             //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
957             if (!drp_videoEncoder.Text.Contains("H.264"))\r
958             {\r
959                 check_turbo.CheckState = CheckState.Unchecked;\r
960                 CheckCRF.CheckState = CheckState.Unchecked;\r
961             }\r
962         }\r
963 \r
964         private void CheckCRF_CheckedChanged(object sender, EventArgs e)\r
965         {\r
966             if (slider_videoQuality.Value == 0)\r
967             {\r
968                 MessageBox.Show("This option is can only be used with the 'Video Quality' slider.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
969                 CheckCRF.CheckState = CheckState.Unchecked;\r
970             }\r
971         }\r
972 \r
973         public void setStreamReader(Parsing.DVD dvd)\r
974         {\r
975             this.thisDVD = dvd;\r
976         }\r
977 \r
978         private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
979         {\r
980             // Reset some values on the form\r
981             lbl_Aspect.Text = "Select a Title";\r
982             lbl_RecomendedCrop.Text = "Select a Title";\r
983             drop_chapterStart.Items.Clear();\r
984             drop_chapterFinish.Items.Clear();\r
985             QueryEditorText.Text = "";\r
986 \r
987             // If the dropdown is set to automatic nothing else needs to be done.\r
988             // Otheriwse if its not, title data has to be loased from parsing.\r
989             if (drp_dvdtitle.Text != "Automatic")\r
990             {\r
991                 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;\r
992                 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();\r
993                 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);\r
994 \r
995                 drop_chapterStart.Items.Clear();\r
996                 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());\r
997                 if (drop_chapterStart.Items.Count > 0)\r
998                 {\r
999                     drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();\r
1000                 }\r
1001 \r
1002                 drop_chapterFinish.Items.Clear();\r
1003                 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());\r
1004                 if (drop_chapterFinish.Items.Count > 0)\r
1005                 {\r
1006                     drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
1007                 }\r
1008 \r
1009                 drp_audioChannels.Items.Clear();\r
1010                 drp_audioChannels.Items.AddRange(selectedTitle.AudioTracks.ToArray());\r
1011                 if (drp_audioChannels.Items.Count > 0)\r
1012                 {\r
1013                     drp_audioChannels.Text = drp_audioChannels.Items[0].ToString();\r
1014                 }\r
1015 \r
1016                 drp_subtitle.Items.Clear();\r
1017                 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
1018                 if (drp_subtitle.Items.Count > 0)\r
1019                 {\r
1020                     drp_subtitle.Text = drp_subtitle.Items[0].ToString();\r
1021                 }\r
1022             }\r
1023         } \r
1024 \r
1025         /// <summary>\r
1026         /// The Query Generation Function\r
1027         /// This function was imported from old vb.net version of this application.\r
1028         /// It could probably do with being cleaned up a good deal at some point\r
1029         /// </summary>\r
1030         /// <returns></returns>\r
1031         public string GenerateTheQuery()\r
1032         {\r
1033             string source = text_source.Text;\r
1034             string dvdTitle = drp_dvdtitle.Text;\r
1035             string chapterStart = drop_chapterStart.Text;\r
1036             string chapterFinish = drop_chapterFinish.Text;\r
1037             int totalChapters = drop_chapterFinish.Items.Count - 1;\r
1038             string dvdChapter = "";\r
1039 \r
1040             if (source ==  "")\r
1041                 MessageBox.Show("No Source has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1042             else\r
1043             {\r
1044                 source = " -i " + '"' + source+ '"'; //'"'+\r
1045             }\r
1046 \r
1047             if (dvdTitle ==  "Automatic")\r
1048                 dvdTitle = "";\r
1049             else\r
1050             {\r
1051                 string[] titleInfo = dvdTitle.Split(' ');\r
1052                 dvdTitle = " -t "+ titleInfo[0];\r
1053             }\r
1054 \r
1055             if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))\r
1056                 dvdChapter = "";\r
1057             else if (chapterFinish == chapterStart)\r
1058                 dvdChapter = " -c " + chapterStart;\r
1059             else\r
1060                 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;\r
1061 \r
1062             string querySource = source+ dvdTitle+ dvdChapter;\r
1063             // ----------------------------------------------------------------------\r
1064 \r
1065             // Destination\r
1066 \r
1067             string destination = text_destination.Text;\r
1068             string videoEncoder = drp_videoEncoder.Text;\r
1069             string audioEncoder = drp_audioCodec.Text;\r
1070             string width = text_width.Text;\r
1071             string height = text_height.Text;\r
1072 \r
1073             if (destination ==  "")\r
1074                 MessageBox.Show("No destination has been selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
1075             else\r
1076                 destination = " -o " + '"' + destination + '"'; //'"'+ \r
1077 \r
1078 \r
1079             switch (videoEncoder)\r
1080             {\r
1081                 case "Mpeg 4":\r
1082                     videoEncoder = " -e ffmpeg";\r
1083                     break;\r
1084                 case "Xvid":\r
1085                     videoEncoder = " -e xvid";\r
1086                     break;\r
1087                 case "H.264":\r
1088                     videoEncoder = " -e x264";\r
1089                     break;\r
1090                 case "H.264 Baseline 1.3":\r
1091                     videoEncoder = " -e x264b13";\r
1092                     break;\r
1093                 case "H.264 (iPod)":\r
1094                     videoEncoder = " -e x264b30";\r
1095                     break;\r
1096                 default:\r
1097                     videoEncoder = " -e x264";\r
1098                     break;\r
1099             }\r
1100            \r
1101             switch (audioEncoder)\r
1102             {\r
1103                 case "AAC":\r
1104                     audioEncoder = " -E faac";\r
1105                     break;\r
1106                 case "MP3":\r
1107                     audioEncoder = " -E lame";\r
1108                     break;\r
1109                 case "Vorbis":\r
1110                     audioEncoder = " -E vorbis";\r
1111                     break;\r
1112                 case "AC3":\r
1113                     audioEncoder = " -E ac3";\r
1114                     break;\r
1115                 default:\r
1116                     audioEncoder = " -E faac";\r
1117                     break;\r
1118             }\r
1119 \r
1120             if (width !=  "")\r
1121                 width = " -w "+ width;\r
1122             \r
1123 \r
1124             if (height !=  "")\r
1125                 height = " -l "+ height;\r
1126             \r
1127 \r
1128             string queryDestination = destination+ videoEncoder+ audioEncoder+ width+ height;\r
1129             // ----------------------------------------------------------------------\r
1130 \r
1131             // Picture Settings Tab\r
1132 \r
1133             string cropSetting = drp_crop.Text;\r
1134             string cropTop = text_top.Text;\r
1135             string cropBottom = text_bottom.Text;\r
1136             string cropLeft = text_left.Text;\r
1137             string cropRight = text_right.Text;\r
1138             string subtitles = drp_subtitle.Text;\r
1139             string cropOut = "";\r
1140             // Returns Crop Query\r
1141 \r
1142             if (cropSetting == "Auto Crop")\r
1143                 cropOut = "";\r
1144             else if (cropSetting == "No Crop")\r
1145                 cropOut = " --crop 0:0:0:0 ";\r
1146             else\r
1147                 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;\r
1148 \r
1149             if (subtitles ==  "None")\r
1150                 subtitles = "";\r
1151             else if (subtitles ==  "")\r
1152                 subtitles = "";\r
1153             else\r
1154             {\r
1155                 string[] tempSub;\r
1156                 tempSub = subtitles.Split(' ');\r
1157                 subtitles = " -s "+ tempSub[0];\r
1158             }\r
1159 \r
1160             string queryPictureSettings = cropOut+ subtitles;\r
1161             // ----------------------------------------------------------------------\r
1162 \r
1163             // Video Settings Tab\r
1164 \r
1165             string videoBitrate = text_bitrate.Text;\r
1166             string videoFilesize = text_filesize.Text;\r
1167             int videoQuality = slider_videoQuality.Value;\r
1168             string vidQSetting = "";\r
1169             string twoPassEncoding = "";\r
1170             string deinterlace = "";\r
1171             string grayscale = "";\r
1172             string videoFramerate = drp_videoFramerate.Text;\r
1173             string pixelRatio = "";\r
1174             string ChapterMarkers = "";\r
1175             string turboH264 = "";\r
1176             string largeFile = "";\r
1177 \r
1178             if (videoBitrate !=  "")\r
1179                 videoBitrate = " -b "+ videoBitrate;\r
1180 \r
1181             if (videoFilesize !=  "")\r
1182                 videoFilesize = " -S "+ videoFilesize;\r
1183 \r
1184             // Video Quality Setting\r
1185 \r
1186             if ((videoQuality ==  0))\r
1187                 vidQSetting = "";\r
1188             else\r
1189             {\r
1190                 videoQuality = videoQuality/ 100;\r
1191                 if (videoQuality ==  1)\r
1192                 {\r
1193                     vidQSetting = "1.0";\r
1194                 }\r
1195 \r
1196                 vidQSetting = " -q " + videoQuality.ToString();\r
1197             }\r
1198 \r
1199             if (check_2PassEncode.Checked)\r
1200                 twoPassEncoding = " -2 ";\r
1201 \r
1202             if (check_DeInterlace.Checked)\r
1203                 deinterlace = " -d ";\r
1204 \r
1205             if (check_grayscale.Checked)\r
1206                 grayscale = " -g ";\r
1207 \r
1208             if (videoFramerate ==  "Automatic")\r
1209                 videoFramerate = "";\r
1210             else\r
1211                 videoFramerate = " -r "+ videoFramerate;\r
1212 \r
1213             if (CheckPixelRatio.Checked)\r
1214                 pixelRatio = " -p ";\r
1215 \r
1216             if (Check_ChapterMarkers.Checked)\r
1217                 ChapterMarkers = " -m ";\r
1218 \r
1219             if (check_turbo.Checked)\r
1220                 turboH264 = " -T ";\r
1221 \r
1222             if (check_largeFile.Checked)\r
1223                 largeFile = " -4 ";\r
1224 \r
1225             string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + deinterlace + grayscale + videoFramerate + pixelRatio + ChapterMarkers + turboH264 + largeFile;\r
1226             // ----------------------------------------------------------------------\r
1227 \r
1228             // Audio Settings Tab\r
1229 \r
1230             string audioBitrate = drp_audioBitrate.Text;\r
1231             string audioSampleRate = drp_audioSampleRate.Text;\r
1232             string audioChannels = drp_audioChannels.Text;\r
1233             string Mixdown = drp_audioMixDown.Text;\r
1234             string SixChannelAudio = "";\r
1235 \r
1236             if (audioBitrate !=  "")\r
1237                 audioBitrate = " -B "+ audioBitrate;\r
1238 \r
1239             if (audioSampleRate !=  "")\r
1240                 audioSampleRate = " -R "+ audioSampleRate;\r
1241 \r
1242             if (audioChannels ==  "Automatic")\r
1243                 audioChannels = "";\r
1244             else if (audioChannels ==  "")\r
1245                 audioChannels = "";\r
1246             else\r
1247             {\r
1248                 string[] tempSub;\r
1249                 tempSub = audioChannels.Split(' ');\r
1250                 audioChannels = " -a "+ tempSub[0];\r
1251             }\r
1252 \r
1253             switch (Mixdown)\r
1254             {\r
1255                 case "Automatic":\r
1256                     Mixdown = "";\r
1257                     break;\r
1258                 case "Mono":\r
1259                     Mixdown = "mono";\r
1260                     break;\r
1261                 case "Stereo":\r
1262                     Mixdown = "stereo";\r
1263                     break;\r
1264                 case "Dolby Surround":\r
1265                     Mixdown = "dpl1";\r
1266                     break;\r
1267                 case "Dolby Pro Logic II":\r
1268                     Mixdown = "dpl2";\r
1269                     break;\r
1270                 case "6 Channel Discrete":\r
1271                     Mixdown = "6ch";\r
1272                     break;\r
1273                 default:\r
1274                     Mixdown = "stero";\r
1275                     break;\r
1276             }\r
1277 \r
1278             if (Mixdown !=  "")\r
1279                 SixChannelAudio = " -6 "+ Mixdown;\r
1280             else\r
1281                 SixChannelAudio = "";\r
1282 \r
1283             string queryAudioSettings = audioBitrate+ audioSampleRate+ audioChannels+ SixChannelAudio;\r
1284             // ----------------------------------------------------------------------\r
1285 \r
1286             //  H.264 Tab\r
1287 \r
1288             string CRF = CheckCRF.CheckState.ToString();\r
1289             string h264Advanced = rtf_h264advanced.Text;\r
1290             if ((CRF ==  "1"))\r
1291                 CRF = " -Q ";\r
1292             else\r
1293                 CRF = "";\r
1294 \r
1295             if ((h264Advanced ==  ""))\r
1296                 h264Advanced = "";\r
1297             else\r
1298                 h264Advanced = " -x "+ h264Advanced;\r
1299     \r
1300 \r
1301             string h264Settings = CRF+ h264Advanced;\r
1302             // ----------------------------------------------------------------------\r
1303 \r
1304             // Processors (Program Settings)\r
1305 \r
1306             string processors = Properties.Settings.Default.Processors;\r
1307             //  Number of Processors Handler\r
1308 \r
1309             if (processors ==  "Automatic")\r
1310                 processors = "";\r
1311             else\r
1312                 processors = " -C "+ processors+ " ";\r
1313 \r
1314 \r
1315             string queryAdvancedSettings = processors;\r
1316             // ----------------------------------------------------------------------\r
1317 \r
1318             //  Verbose option (Program Settings)\r
1319 \r
1320             string verbose = "";\r
1321             if (Properties.Settings.Default.verbose ==  "Checked")\r
1322                 verbose = " -v ";\r
1323 \r
1324             // ----------------------------------------------------------------------\r
1325 \r
1326             return querySource+ queryDestination+ queryPictureSettings+ queryVideoSettings+ h264Settings+ queryAudioSettings+ queryAdvancedSettings+ verbose;\r
1327         }\r
1328 \r
1329         // This is the END of the road ------------------------------------------------------------------------------\r
1330     }\r
1331 }