3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr/>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections;
\r
9 using System.ComponentModel;
\r
11 using System.Drawing;
\r
13 using System.Windows.Forms;
\r
16 using System.Diagnostics;
\r
17 using System.Threading;
\r
18 using System.Runtime.InteropServices;
\r
19 using System.Globalization;
\r
20 using System.Text.RegularExpressions;
\r
24 public partial class frmMain : Form
\r
26 // --------------------------------------------------------------
\r
27 // Applicaiton Startup Stuff
\r
28 // --------------------------------------------------------------
\r
30 #region Application Startup
\r
32 // Some stuff that needs to be Initialized.
\r
33 private Process hbProc;
\r
34 private Parsing.DVD thisDVD;
\r
35 private frmQueue queueWindow = new frmQueue();
\r
36 private delegate void updateStatusChanger();
\r
37 Functions.Common hb_common_func = new Functions.Common();
\r
41 // Load the splash screen in this thread
\r
42 Form splash = new frmSplashScreen();
\r
45 //Create a label that can be updated from the parent thread.
\r
46 Label lblStatus = new Label();
\r
47 lblStatus.Size = new Size(250, 20);
\r
48 lblStatus.Location = new Point(10, 280);
\r
49 splash.Controls.Add(lblStatus);
\r
51 //Fire a thread to wait for 2 seconds. The splash screen will exit when the time expires
\r
52 Thread timer = new Thread(splashTimer);
\r
55 InitializeComponent();
\r
57 // show the form, but leave disabled until preloading is complete then show the main form
\r
58 this.Enabled = false;
\r
62 // Forces frmMain to draw
\r
63 Application.DoEvents();
\r
65 // update the status
\r
66 if (Properties.Settings.Default.updateStatus == "Checked")
\r
68 lblStatus.Text = "Checking for updates ...";
\r
69 Application.DoEvents();
\r
70 Thread updateCheckThread = new Thread(startupUpdateCheck);
\r
71 updateCheckThread.Start();
\r
76 // Set some defaults for the dropdown menus. Just incase the normal or user presets dont load.
\r
77 drp_crop.SelectedIndex = 0;
\r
79 lblStatus.Text = "Loading Presets ...";
\r
80 Application.DoEvents();
\r
81 if (Properties.Settings.Default.updatePresets == "Checked")
\r
88 // Now load the users default if required. (Will overide the above setting)
\r
89 if (Properties.Settings.Default.defaultSettings == "Checked")
\r
91 lblStatus.Text = "Loading User Default Settings...";
\r
92 Application.DoEvents();
\r
99 // Enable or disable tooltips
\r
100 if (Properties.Settings.Default.tooltipEnable == "Checked")
\r
102 lblStatus.Text = "Loading Tooltips ...";
\r
103 Application.DoEvents();
\r
104 ToolTip.Active = true;
\r
109 lblStatus.Text = "Loading Complete!";
\r
110 Application.DoEvents();
\r
113 // Wait until splash screen is done
\r
114 while (timer.IsAlive)
\r
115 { Thread.Sleep(100); }
\r
117 //Close the splash screen
\r
121 // Turn the interface back to the user
\r
122 this.Enabled = true;
\r
125 private void startupUpdateCheck()
\r
129 if (this.InvokeRequired)
\r
131 this.BeginInvoke(new updateStatusChanger(startupUpdateCheck));
\r
135 Boolean update = hb_common_func.updateCheck();
\r
136 if (update == true)
\r
138 frmUpdater updateWindow = new frmUpdater();
\r
139 updateWindow.Show();
\r
142 catch (Exception exc)
\r
144 MessageBox.Show(exc.ToString());
\r
148 private void splashTimer(object sender)
\r
150 Thread.Sleep(1000); //sit for 1 seconds then exit
\r
153 private void showSplash(object sender)
\r
155 Form splash = new frmSplashScreen();
\r
159 private void loadUserDefaults()
\r
161 string userDefaults = Properties.Settings.Default.defaultUserSettings;
\r
164 // Some things that need to be done to reset some gui components:
\r
165 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
167 // Send the query from the file to the Query Parser class Then load the preset
\r
168 Functions.QueryParser presetQuery = Functions.QueryParser.Parse(userDefaults);
\r
169 hb_common_func.presetLoader(this, presetQuery, "User Defaults ");
\r
171 catch (Exception exc)
\r
173 MessageBox.Show("Unable to load user Default Settings. \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
179 #region Set Varible Function
\r
180 public void setStreamReader(Parsing.DVD dvd)
\r
182 this.thisDVD = dvd;
\r
186 // --------------------------------------------------------------
\r
187 // The main Menu bar.
\r
188 // --------------------------------------------------------------
\r
191 private void mnu_open_Click(object sender, EventArgs e)
\r
194 File_Open.ShowDialog();
\r
195 filename = File_Open.FileName;
\r
197 if (filename != "")
\r
201 // Create StreamReader & open file
\r
202 StreamReader line = new StreamReader(filename);
\r
204 // Send the query from the file to the Query Parser class then load the preset
\r
205 Functions.QueryParser presetQuery = Functions.QueryParser.Parse(line.ReadLine());
\r
206 hb_common_func.presetLoader(this, presetQuery, filename);
\r
208 // Close the stream
\r
211 catch (Exception exc)
\r
213 MessageBox.Show("Unable to load profile. \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
218 private void mnu_save_Click(object sender, EventArgs e)
\r
221 File_Save.ShowDialog();
\r
222 filename = File_Save.FileName;
\r
223 if (filename != "")
\r
227 // Create a StreamWriter and open the file
\r
228 StreamWriter line = new StreamWriter(filename);
\r
230 // Generate and write the query string to the file
\r
231 String query = hb_common_func.GenerateTheQuery(this);
\r
232 line.WriteLine(query);
\r
234 // close the stream
\r
236 MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
240 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
246 private void mnu_exit_Click(object sender, EventArgs e)
\r
248 Application.Exit();
\r
255 private void mnu_encode_Click(object sender, EventArgs e)
\r
260 private void mnu_viewDVDdata_Click(object sender, EventArgs e)
\r
262 frmDvdInfo dvdInfoWindow = new frmDvdInfo();
\r
263 dvdInfoWindow.Show();
\r
266 private void mnu_options_Click(object sender, EventArgs e)
\r
268 Form Options = new frmOptions();
\r
269 Options.ShowDialog();
\r
275 #region Presets Menu
\r
277 private void mnu_presetReset_Click(object sender, EventArgs e)
\r
279 treeView_presets.Nodes.Clear();
\r
282 if (treeView_presets.Nodes.Count == 0)
\r
283 MessageBox.Show("Unable to load the presets.dat file. Please select \"Update Built-in Presets\" from the Presets Menu \nMake sure you are running the program in Admin mode if running on Vista. See Windows FAQ for details!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
285 MessageBox.Show("Presets have been updated", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
288 private void mnu_SelectDefault_Click(object sender, EventArgs e)
\r
290 loadNormalPreset();
\r
297 private void mnu_wiki_Click(object sender, EventArgs e)
\r
299 Process.Start("http://handbrake.fr/trac");
\r
302 private void mnu_faq_Click(object sender, EventArgs e)
\r
304 Process.Start("http://handbrake.fr/trac/wiki/SupportFAQ");
\r
307 private void mnu_onlineDocs_Click(object sender, EventArgs e)
\r
309 Process.Start("http://handbrake.fr/?article=documentation");
\r
312 private void mnu_homepage_Click(object sender, EventArgs e)
\r
314 Process.Start("http://handbrake.fr");
\r
317 private void mnu_forum_Click(object sender, EventArgs e)
\r
319 Process.Start("http://handbrake.fr/forum");
\r
322 private void mnu_UpdateCheck_Click(object sender, EventArgs e)
\r
324 Boolean update = hb_common_func.updateCheck();
\r
325 if (update == true)
\r
327 frmUpdater updateWindow = new frmUpdater();
\r
328 updateWindow.Show();
\r
331 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
334 private void mnu_about_Click(object sender, EventArgs e)
\r
336 Form About = new frmAbout();
\r
337 About.ShowDialog();
\r
342 // --------------------------------------------------------------
\r
343 // Buttons on the main Window and items that require actions
\r
344 // --------------------------------------------------------------
\r
348 private void btn_Browse_Click(object sender, EventArgs e)
\r
350 String filename = "";
\r
351 text_source.Text = "";
\r
352 frmDvdInfo dvdInfoWindow = new frmDvdInfo();
\r
354 if (RadioDVD.Checked)
\r
356 DVD_Open.ShowDialog();
\r
357 filename = DVD_Open.SelectedPath;
\r
361 ISO_Open.ShowDialog();
\r
362 filename = ISO_Open.FileName;
\r
365 if (filename != "")
\r
367 Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);
\r
368 text_source.Text = filename;
\r
369 frmRD.ShowDialog();
\r
372 text_source.Text = "Click 'Browse' to continue";
\r
374 // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.
\r
375 if (drp_dvdtitle.Items.Count == 0)
\r
376 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
379 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
381 // This removes the file extension from the filename box on the save file dialog.
\r
382 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
383 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", "").Replace(".m4v", "").Replace(".mkv", "").Replace(".ogm", "").Replace(".avi", "");
\r
385 // Show the dialog and set the main form file path
\r
386 DVD_Save.ShowDialog();
\r
387 text_destination.Text = DVD_Save.FileName;
\r
389 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
390 if (Check_ChapterMarkers.Checked)
\r
391 text_destination.Text = text_destination.Text.Replace(".mp4", ".m4v");
\r
394 private void btn_h264Clear_Click(object sender, EventArgs e)
\r
396 rtf_h264advanced.Text = "";
\r
399 private void btn_ActivityWindow_Click(object sender, EventArgs e)
\r
401 Form ActivityWindow = new frmActivityWindow();
\r
402 ActivityWindow.ShowDialog();
\r
407 #region frmMain Actions
\r
409 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
411 // Reset some values on the form
\r
412 lbl_Aspect.Text = "Select a Title";
\r
413 lbl_RecomendedCrop.Text = "Select a Title";
\r
414 drop_chapterStart.Items.Clear();
\r
415 drop_chapterFinish.Items.Clear();
\r
417 // If the dropdown is set to automatic nothing else needs to be done.
\r
418 // Otheriwse if its not, title data has to be loased from parsing.
\r
419 if (drp_dvdtitle.Text != "Automatic")
\r
421 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;
\r
423 // Set the Aspect Ratio
\r
424 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();
\r
426 // Set the Recommended Cropping values
\r
427 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);
\r
429 // Populate the Start chapter Dropdown
\r
430 drop_chapterStart.Items.Clear();
\r
431 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
432 if (drop_chapterStart.Items.Count > 0)
\r
433 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
435 // Populate the Final Chapter Dropdown
\r
436 drop_chapterFinish.Items.Clear();
\r
437 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
438 if (drop_chapterFinish.Items.Count > 0)
\r
439 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
441 // Populate the Audio Channels Dropdown
\r
442 drp_track1Audio.Items.Clear();
\r
443 drp_track1Audio.Items.Add("Automatic");
\r
444 drp_track1Audio.Items.Add("None");
\r
445 drp_track1Audio.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
446 if (drp_track1Audio.Items.Count > 0)
\r
447 drp_track1Audio.Text = drp_track1Audio.Items[0].ToString();
\r
449 drp_track2Audio.Items.Clear();
\r
450 drp_track2Audio.Items.Add("None");
\r
451 drp_track2Audio.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
452 if (drp_track2Audio.Items.Count > 0)
\r
453 drp_track2Audio.Text = drp_track2Audio.Items[0].ToString();
\r
455 // Populate the Subtitles dropdown
\r
456 drp_subtitle.Items.Clear();
\r
457 drp_subtitle.Items.Add("None");
\r
458 drp_subtitle.Items.Add("Autoselect");
\r
459 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());
\r
460 if (drp_subtitle.Items.Count > 0)
\r
461 drp_subtitle.Text = drp_subtitle.Items[0].ToString();
\r
465 // Run the autoName & chapterNaming functions
\r
466 hb_common_func.autoName(this);
\r
467 hb_common_func.chapterNaming(this);
\r
470 private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)
\r
472 drop_chapterStart.BackColor = Color.White;
\r
473 if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
\r
477 int chapterFinish = int.Parse(drop_chapterFinish.Text);
\r
478 int chapterStart = int.Parse(drop_chapterStart.Text);
\r
480 if (chapterFinish < chapterStart)
\r
481 drop_chapterStart.BackColor = Color.LightCoral;
\r
485 drop_chapterStart.BackColor = Color.LightCoral;
\r
488 // Run the Autonaming function
\r
489 hb_common_func.autoName(this);
\r
492 private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)
\r
494 drop_chapterFinish.BackColor = Color.White;
\r
495 if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
\r
499 int chapterFinish = int.Parse(drop_chapterFinish.Text);
\r
500 int chapterStart = int.Parse(drop_chapterStart.Text);
\r
502 if (chapterFinish < chapterStart)
\r
503 drop_chapterFinish.BackColor = Color.LightCoral;
\r
507 drop_chapterFinish.BackColor = Color.LightCoral;
\r
511 // Run the Autonaming function
\r
512 hb_common_func.autoName(this);
\r
515 private void text_bitrate_TextChanged(object sender, EventArgs e)
\r
517 text_filesize.Text = "";
\r
518 slider_videoQuality.Value = 0;
\r
519 SliderValue.Text = "0%";
\r
522 private void text_filesize_TextChanged(object sender, EventArgs e)
\r
524 text_bitrate.Text = "";
\r
525 slider_videoQuality.Value = 0;
\r
526 SliderValue.Text = "0%";
\r
529 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
531 SliderValue.Text = slider_videoQuality.Value.ToString() + "%";
\r
532 text_bitrate.Text = "";
\r
533 text_filesize.Text = "";
\r
536 private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
538 Process.Start("http://handbrake.fr/trac/wiki/x264Options");
\r
541 private void text_width_TextChanged(object sender, EventArgs e)
\r
545 if (CheckPixelRatio.Checked)
\r
547 text_width.Text = "";
\r
548 text_width.BackColor = Color.LightCoral;
\r
549 CheckPixelRatio.BackColor = Color.LightCoral;
\r
553 if ((int.Parse(text_width.Text) % 16) != 0)
\r
554 text_width.BackColor = Color.LightCoral;
\r
556 text_width.BackColor = Color.LightGreen;
\r
559 if ((lbl_Aspect.Text != "Select a Title") && (drp_crop.SelectedIndex == 2))
\r
561 double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);
\r
562 double mod16 = height % 16;
\r
563 height = height - mod16;
\r
565 if (text_width.Text == "")
\r
567 text_height.Text = "";
\r
568 text_width.BackColor = Color.White;
\r
571 text_height.Text = height.ToString();
\r
576 // No need to throw an error here.
\r
580 private void text_height_TextChanged(object sender, EventArgs e)
\r
584 if (CheckPixelRatio.Checked)
\r
586 text_height.Text = "";
\r
587 text_height.BackColor = Color.LightCoral;
\r
588 CheckPixelRatio.BackColor = Color.LightCoral;
\r
592 if ((int.Parse(text_height.Text) % 16) != 0)
\r
593 text_height.BackColor = Color.LightCoral;
\r
595 text_height.BackColor = Color.LightGreen;
\r
601 // No need to alert the user.
\r
605 private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)
\r
607 if ((string)drp_crop.SelectedItem == "Custom")
\r
609 text_left.Enabled = true;
\r
610 text_right.Enabled = true;
\r
611 text_top.Enabled = true;
\r
612 text_bottom.Enabled = true;
\r
613 text_left.Text = "0";
\r
614 text_right.Text = "0";
\r
615 text_top.Text = "0";
\r
616 text_bottom.Text = "0";
\r
619 if ((string)drp_crop.SelectedItem == "Automatic")
\r
621 text_left.Enabled = false;
\r
622 text_right.Enabled = false;
\r
623 text_top.Enabled = false;
\r
624 text_bottom.Enabled = false;
\r
626 if (lbl_RecomendedCrop.Text != "Select a Title")
\r
628 string[] temp = new string[4];
\r
629 temp = lbl_RecomendedCrop.Text.Split('/');
\r
630 text_left.Text = temp[2];
\r
631 text_right.Text = temp[3];
\r
632 text_top.Text = temp[0];
\r
633 text_bottom.Text = temp[1];
\r
637 text_left.Text = "";
\r
638 text_right.Text = "";
\r
639 text_top.Text = "";
\r
640 text_bottom.Text = "";
\r
644 if ((string)drp_crop.SelectedItem == "No Crop")
\r
646 text_left.Enabled = false;
\r
647 text_right.Enabled = false;
\r
648 text_top.Enabled = false;
\r
649 text_bottom.Enabled = false;
\r
650 text_left.Text = "0";
\r
651 text_right.Text = "0";
\r
652 text_top.Text = "0";
\r
653 text_bottom.Text = "0";
\r
658 private void check_vfr_CheckedChanged(object sender, EventArgs e)
\r
660 if (check_vfr.CheckState == CheckState.Checked)
\r
662 check_detelecine.Enabled = false;
\r
663 check_detelecine.CheckState = CheckState.Checked;
\r
664 drp_videoFramerate.Enabled = false;
\r
665 drp_videoFramerate.SelectedItem = "29.97";
\r
666 lbl_vfr.Visible = true;
\r
670 check_detelecine.Enabled = true;
\r
671 drp_videoFramerate.Enabled = true;
\r
672 drp_videoFramerate.SelectedItem = "Automatic";
\r
673 lbl_vfr.Visible = false;
\r
677 private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)
\r
679 text_width.Text = "";
\r
680 text_height.Text = "";
\r
681 text_width.BackColor = Color.White;
\r
682 text_height.BackColor = Color.White;
\r
683 CheckPixelRatio.BackColor = TabPage1.BackColor;
\r
685 if (CheckPixelRatio.Checked)
\r
687 check_lAnamorphic.Enabled = false;
\r
688 check_lAnamorphic.Checked = false;
\r
689 text_height.BackColor = Color.LightGray;
\r
690 text_width.BackColor = Color.LightGray;
\r
691 text_height.Enabled = false;
\r
692 text_width.Enabled = false;
\r
696 check_lAnamorphic.Enabled = true;
\r
697 text_height.BackColor = Color.White;
\r
698 text_width.BackColor = Color.White;
\r
699 text_height.Enabled = true;
\r
700 text_width.Enabled = true;
\r
704 private void check_lAnamorphic_CheckedChanged(object sender, EventArgs e)
\r
706 if (check_lAnamorphic.Checked)
\r
708 CheckPixelRatio.Enabled = false;
\r
709 CheckPixelRatio.Checked = false;
\r
710 text_height.Text = "";
\r
711 text_height.Enabled = false;
\r
712 text_height.BackColor = Color.LightGray;
\r
716 CheckPixelRatio.Enabled = true;
\r
717 text_height.Enabled = true;
\r
718 text_height.BackColor = Color.White;
\r
722 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
724 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
726 if (drp_videoEncoder.Text.Contains("H.264"))
\r
727 check_turbo.Enabled = true;
\r
731 check_turbo.Enabled = false;
\r
732 check_turbo.CheckState = CheckState.Unchecked;
\r
736 private void check_largeFile_CheckedChanged(object sender, EventArgs e)
\r
738 if ((!text_destination.Text.Contains(".mp4")) && (!text_destination.Text.Contains(".m4v")))
\r
740 check_largeFile.BackColor = Color.LightCoral;
\r
741 check_largeFile.CheckState = CheckState.Unchecked;
\r
745 check_largeFile.BackColor = Color.Transparent;
\r
749 private void check_iPodAtom_CheckedChanged(object sender, EventArgs e)
\r
751 if ((!text_destination.Text.Contains(".mp4")) && (!text_destination.Text.Contains(".m4v")))
\r
753 text_destination.BackColor = Color.LightCoral;
\r
754 check_iPodAtom.BackColor = Color.LightCoral;
\r
755 check_iPodAtom.CheckState = CheckState.Unchecked;
\r
759 check_iPodAtom.BackColor = Color.Transparent;
\r
760 text_destination.BackColor = Color.White;
\r
764 private void check_optimiseMP4_CheckedChanged(object sender, EventArgs e)
\r
766 if ((!text_destination.Text.Contains(".mp4")) && (!text_destination.Text.Contains(".m4v")))
\r
768 check_optimiseMP4.BackColor = Color.LightCoral;
\r
769 text_destination.BackColor = Color.LightCoral;
\r
770 check_optimiseMP4.CheckState = CheckState.Unchecked;
\r
774 check_optimiseMP4.BackColor = Color.Transparent;
\r
775 text_destination.BackColor = Color.White;
\r
779 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
781 if (drp_dvdtitle.Items.Count == 0)
\r
782 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
785 private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)
\r
787 if (drp_audioCodec.Text == "AAC + AC3")
\r
789 drp_audioMixDown.Enabled = false;
\r
790 drp_audioMixDown.Text = "Automatic";
\r
791 text_destination.Text.Replace(".mp4", ".m4v");
\r
795 drp_audioMixDown.Enabled = true;
\r
798 if (drp_audioCodec.Text == "AC3")
\r
800 drp_audioBitrate.Enabled = false;
\r
801 drp_audioSampleRate.Enabled = false;
\r
802 drp_audioBitrate.Text = "";
\r
803 drp_audioSampleRate.Text = "";
\r
807 drp_audioBitrate.Enabled = true;
\r
808 drp_audioSampleRate.Enabled = true;
\r
809 drp_audioBitrate.Text = "160";
\r
810 drp_audioSampleRate.Text = "48";
\r
812 if (drp_audioCodec.Text == "AAC")
\r
814 drp_audioMixDown.Items.Clear();
\r
815 drp_audioMixDown.Items.Add("Mono");
\r
816 drp_audioMixDown.Items.Add("Stereo");
\r
817 drp_audioMixDown.Items.Add("Dolby Surround");
\r
818 drp_audioMixDown.Items.Add("Dolby Pro Logic II");
\r
819 drp_audioMixDown.Items.Add("6 Channel Discrete");
\r
821 drp_audioBitrate.Items.Clear();
\r
822 drp_audioBitrate.Items.Add("32");
\r
823 drp_audioBitrate.Items.Add("40");
\r
824 drp_audioBitrate.Items.Add("48");
\r
825 drp_audioBitrate.Items.Add("56");
\r
826 drp_audioBitrate.Items.Add("64");
\r
827 drp_audioBitrate.Items.Add("80");
\r
828 drp_audioBitrate.Items.Add("86");
\r
829 drp_audioBitrate.Items.Add("112");
\r
830 drp_audioBitrate.Items.Add("128");
\r
831 drp_audioBitrate.Items.Add("160");
\r
836 drp_audioMixDown.Items.Clear();
\r
837 drp_audioMixDown.Items.Add("Stereo");
\r
838 drp_audioMixDown.Items.Add("Dolby Surround");
\r
839 drp_audioMixDown.Items.Add("Dolby Pro Logic II");
\r
841 drp_audioBitrate.Items.Clear();
\r
842 drp_audioBitrate.Items.Add("32");
\r
843 drp_audioBitrate.Items.Add("40");
\r
844 drp_audioBitrate.Items.Add("48");
\r
845 drp_audioBitrate.Items.Add("56");
\r
846 drp_audioBitrate.Items.Add("64");
\r
847 drp_audioBitrate.Items.Add("80");
\r
848 drp_audioBitrate.Items.Add("86");
\r
849 drp_audioBitrate.Items.Add("112");
\r
850 drp_audioBitrate.Items.Add("128");
\r
851 drp_audioBitrate.Items.Add("160");
\r
852 drp_audioBitrate.Items.Add("192");
\r
853 drp_audioBitrate.Items.Add("224");
\r
854 drp_audioBitrate.Items.Add("256");
\r
855 drp_audioBitrate.Items.Add("320");
\r
859 private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)
\r
861 if ((drp_audioCodec.Text == "AAC") && (drp_audioMixDown.Text == "6 Channel Discrete"))
\r
863 drp_audioBitrate.Items.Clear();
\r
864 drp_audioBitrate.Items.Add("32");
\r
865 drp_audioBitrate.Items.Add("40");
\r
866 drp_audioBitrate.Items.Add("48");
\r
867 drp_audioBitrate.Items.Add("56");
\r
868 drp_audioBitrate.Items.Add("64");
\r
869 drp_audioBitrate.Items.Add("80");
\r
870 drp_audioBitrate.Items.Add("86");
\r
871 drp_audioBitrate.Items.Add("112");
\r
872 drp_audioBitrate.Items.Add("128");
\r
873 drp_audioBitrate.Items.Add("160");
\r
874 drp_audioBitrate.Items.Add("192");
\r
875 drp_audioBitrate.Items.Add("224");
\r
876 drp_audioBitrate.Items.Add("256");
\r
877 drp_audioBitrate.Items.Add("320");
\r
878 drp_audioBitrate.Items.Add("384");
\r
882 private void slider_drc_Scroll(object sender, EventArgs e)
\r
884 double value = slider_drc.Value / 10.0;
\r
887 lbl_drc.Text = value.ToString();
\r
890 private void drp_subtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
892 if (drp_subtitle.Text.Contains("None"))
\r
894 check_forced.Enabled = false;
\r
895 check_forced.Checked = false;
\r
898 check_forced.Enabled = true;
\r
901 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
903 if (Check_ChapterMarkers.Checked)
\r
905 string destination = text_destination.Text;
\r
906 destination = destination.Replace(".mp4", ".m4v");
\r
907 text_destination.Text = destination;
\r
908 data_chpt.Rows.Clear();
\r
909 data_chpt.Enabled = true;
\r
910 hb_common_func.chapterNaming(this);
\r
914 string destination = text_destination.Text;
\r
915 destination = destination.Replace(".m4v", ".mp4");
\r
916 text_destination.Text = destination;
\r
917 data_chpt.Rows.Clear();
\r
918 data_chpt.Enabled = false;
\r
922 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
924 //Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
925 if (!drp_videoEncoder.Text.Contains("H.264"))
\r
927 check_turbo.CheckState = CheckState.Unchecked;
\r
928 check_turbo.Enabled = false;
\r
929 h264Tab.Enabled = false;
\r
930 rtf_h264advanced.Text = "";
\r
931 check_iPodAtom.Enabled = false;
\r
932 check_iPodAtom.Checked = false;
\r
933 check_optimiseMP4.Enabled = false;
\r
934 check_lAnamorphic.Enabled = false;
\r
935 check_lAnamorphic.Checked = false;
\r
939 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
940 check_turbo.Enabled = true;
\r
942 h264Tab.Enabled = true;
\r
943 check_iPodAtom.Enabled = true;
\r
944 check_optimiseMP4.Enabled = true;
\r
945 check_lAnamorphic.Enabled = true;
\r
952 #region Query Editor Tab
\r
954 private void btn_clear_Click(object sender, EventArgs e)
\r
959 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
961 rtf_query.Text = hb_common_func.GenerateTheQuery(this);
\r
964 private void btn_copy2C_Click(object sender, EventArgs e)
\r
966 if (rtf_query.Text != "")
\r
967 Clipboard.SetText(rtf_query.Text, TextDataFormat.Text);
\r
972 // --------------------------------------------------------------
\r
973 // Main Window Preset System
\r
974 // --------------------------------------------------------------
\r
976 #region Preset System
\r
978 // Import Current Presets
\r
979 private void loadPresetPanel()
\r
981 ArrayList presetNameList = new ArrayList();
\r
983 string appPath = Application.StartupPath.ToString() + "\\presets.dat";
\r
984 if (File.Exists(appPath))
\r
986 StreamReader presetInput = new StreamReader(appPath);
\r
987 while (!presetInput.EndOfStream)
\r
989 if ((char)presetInput.Peek() == '+')
\r
991 string preset = presetInput.ReadLine().Replace("+ ", "");
\r
992 Regex r = new Regex("(: )"); // Split on hyphens.
\r
993 presetNameList.Add(r.Split(preset));
\r
996 presetInput.ReadLine();
\r
1000 TreeNode preset_treeview = new TreeNode();
\r
1001 foreach (string[] preset in presetNameList)
\r
1003 preset_treeview = new TreeNode(preset[0]);
\r
1005 // Now Fill Out List View with Items
\r
1006 treeView_presets.Nodes.Add(preset_treeview);
\r
1010 // Generate a new presets.dat file from the CLI
\r
1011 private void grabCLIPresets()
\r
1013 string appPath = Application.StartupPath.ToString() + "\\";
\r
1014 string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " --preset-list >" + '"' + appPath + "presets.dat" + '"' + " 2>&1" + '"';
\r
1015 Process hbproc = Process.Start("CMD.exe", strCmdLine);
\r
1016 hbproc.WaitForExit();
\r
1021 // Selects the preset called "normal". This is HandBrakes default settings
\r
1022 private void loadNormalPreset()
\r
1026 string appPath = Application.StartupPath.ToString() + "\\presets.dat";
\r
1027 if (File.Exists(appPath))
\r
1031 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
1033 if (treenode.ToString().Equals("TreeNode: Normal"))
\r
1034 normal = treenode.Index;
\r
1037 TreeNode np = treeView_presets.Nodes[normal];
\r
1039 treeView_presets.SelectedNode = np;
\r
1048 // Set's the current options set in the program as the new defaults for the program.
\r
1049 private void btn_setDefault_Click(object sender, EventArgs e)
\r
1051 String query = hb_common_func.GenerateTheQuery(this);
\r
1052 Properties.Settings.Default.defaultUserSettings = query;
\r
1053 // Save the new default Settings
\r
1054 Properties.Settings.Default.Save();
\r
1055 MessageBox.Show("New default settings saved.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
1058 // When the user select a preset from the treeview, load it
\r
1059 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
1061 string selectedPreset = null;
\r
1062 selectedPreset = treeView_presets.SelectedNode.Text;
\r
1066 string appPath = Application.StartupPath.ToString() + "\\presets.dat";
\r
1067 if (File.Exists(appPath))
\r
1069 StreamReader presetInput = new StreamReader(appPath);
\r
1070 while (!presetInput.EndOfStream)
\r
1072 if ((char)presetInput.Peek() == '+')
\r
1074 string preset = presetInput.ReadLine().Replace("+ ", "");
\r
1075 Regex r = new Regex("(: )"); // Split on hyphens.
\r
1076 string[] presetName = r.Split(preset);
\r
1078 if (selectedPreset == presetName[0])
\r
1080 // Need to disable anamorphic now, otherwise it may overide the width / height values later.
\r
1081 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
1083 // Send the query from the file to the Query Parser class
\r
1084 Functions.QueryParser presetQuery = Functions.QueryParser.Parse(preset);
\r
1086 // Now load the preset
\r
1087 hb_common_func.presetLoader(this, presetQuery, selectedPreset);
\r
1091 presetInput.ReadLine();
\r
1095 catch (Exception exc)
\r
1097 MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1103 //---------------------------------------------------
\r
1104 // Encode / Cancel Buttons
\r
1105 // Encode Progress Text Handler
\r
1106 //---------------------------------------------------
\r
1108 #region Encodeing and Queue
\r
1110 Functions.CLI process = new Functions.CLI();
\r
1111 private delegate void UpdateUIHandler();
\r
1113 [DllImport("user32.dll")]
\r
1114 public static extern void LockWorkStation();
\r
1115 [DllImport("user32.dll")]
\r
1116 public static extern int ExitWindowsEx(int uFlags, int dwReason);
\r
1118 private void btn_start_Click(object sender, EventArgs e)
\r
1120 if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")
\r
1121 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1125 if (rtf_query.Text != "")
\r
1126 query = rtf_query.Text;
\r
1128 query = hb_common_func.GenerateTheQuery(this);
\r
1130 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
1131 lbl_encode.Visible = true;
\r
1132 lbl_encode.Text = "Encoding in Progress";
\r
1136 private void btn_add2Queue_Click(object sender, EventArgs e)
\r
1138 if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")
\r
1139 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1143 if (rtf_query.Text != "")
\r
1144 query = rtf_query.Text;
\r
1146 query = hb_common_func.GenerateTheQuery(this);
\r
1148 queueWindow.list_queue.Items.Add(query);
\r
1149 queueWindow.Show();
\r
1153 private void btn_showQueue_Click(object sender, EventArgs e)
\r
1158 private void showQueue()
\r
1160 queueWindow.Show();
\r
1163 private void procMonitor(object state)
\r
1165 // Make sure we are not already encoding and if we are then display an error.
\r
1166 if (hbProc != null)
\r
1167 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1170 hbProc = process.runCli(this, (string)state, false, false, false, false);
\r
1171 hbProc.WaitForExit();
\r
1176 // Do something whent he encode ends.
\r
1177 switch (Properties.Settings.Default.CompletionOption)
\r
1180 System.Diagnostics.Process.Start("Shutdown", "-s -t 60");
\r
1183 ExitWindowsEx(0, 0);
\r
1186 Application.SetSuspendState(PowerState.Suspend, true, true);
\r
1189 Application.SetSuspendState(PowerState.Hibernate, true, true);
\r
1191 case "Lock System":
\r
1192 LockWorkStation();
\r
1194 case "Quit HandBrake":
\r
1195 Application.Exit();
\r
1203 private void setEncodeLabel()
\r
1205 if (this.InvokeRequired)
\r
1207 this.BeginInvoke(new UpdateUIHandler(setEncodeLabel));
\r
1210 lbl_encode.Text = "Encoding Finished";
\r
1217 // This is the END of the road ------------------------------------------------------------------------------
\r