2 using System.Collections.Generic;
\r
3 using System.Collections.Specialized;
\r
4 using System.ComponentModel;
\r
6 using System.Drawing;
\r
8 using System.Windows.Forms;
\r
11 using System.Diagnostics;
\r
12 using System.Threading;
\r
13 using System.Runtime.InteropServices;
\r
14 using System.Globalization;
\r
15 using System.Text.RegularExpressions;
\r
19 public partial class frmMain : Form
\r
21 // --------------------------------------------------------------
\r
22 // Applicaiton Startup Stuff
\r
23 // --------------------------------------------------------------
\r
25 #region Application Startup
\r
27 // Some stuff that needs to be Initialized.
\r
28 private Process hbProc;
\r
29 private Parsing.DVD thisDVD;
\r
30 private frmQueue queueWindow = new frmQueue();
\r
31 private delegate void updateStatusChanger();
\r
32 Functions.Common hb_common_func = new Functions.Common();
\r
36 // Load the splash screen in this thread
\r
37 Form splash = new frmSplashScreen();
\r
40 //Create a label that can be updated from the parent thread.
\r
41 Label lblStatus = new Label();
\r
42 lblStatus.Size = new Size(250, 20);
\r
43 lblStatus.Location = new Point(10, 280);
\r
44 splash.Controls.Add(lblStatus);
\r
46 //Fire a thread to wait for 2 seconds. The splash screen will exit when the time expires
\r
47 Thread timer = new Thread(splashTimer);
\r
50 InitializeComponent();
\r
52 // show the form, but leave disabled until preloading is complete then show the main form
\r
53 this.Enabled = false;
\r
57 // Forces frmMain to draw
\r
58 Application.DoEvents();
\r
60 // update the status
\r
61 if (Properties.Settings.Default.updateStatus == "Checked")
\r
63 lblStatus.Text = "Checking for updates ...";
\r
64 Application.DoEvents();
\r
65 Thread updateCheckThread = new Thread(startupUpdateCheck);
\r
66 updateCheckThread.Start();
\r
70 // Update the presets
\r
71 if (Properties.Settings.Default.updatePresets == "Checked")
\r
73 lblStatus.Text = "Updaing Presets ...";
\r
74 Application.DoEvents();
\r
79 // Load the presets for the preset box
\r
82 // Now load the users default if required. (Will overide the above setting)
\r
83 if (Properties.Settings.Default.defaultSettings == "Checked")
\r
85 lblStatus.Text = "Loading User Default Settings...";
\r
86 Application.DoEvents();
\r
93 // Enable or disable tooltips
\r
94 if (Properties.Settings.Default.tooltipEnable == "Checked")
\r
96 lblStatus.Text = "Loading Tooltips ...";
\r
97 Application.DoEvents();
\r
98 ToolTip.Active = true;
\r
102 // Make sure a default cropping option is selected. Not sure why this is not defaulting like the other checkdowns,
\r
103 // Can fix it later.
\r
104 drp_crop.SelectedItem = "Automatic";
\r
107 lblStatus.Text = "Loading Complete!";
\r
108 Application.DoEvents();
\r
111 // Wait until splash screen is done
\r
112 while (timer.IsAlive)
\r
113 { Thread.Sleep(100); }
\r
115 //Close the splash screen
\r
119 // Turn the interface back to the user
\r
120 this.Enabled = true;
\r
123 private void startupUpdateCheck()
\r
127 if (this.InvokeRequired)
\r
129 this.BeginInvoke(new updateStatusChanger(startupUpdateCheck));
\r
133 Boolean update = hb_common_func.updateCheck();
\r
134 if (update == true)
\r
136 frmUpdater updateWindow = new frmUpdater();
\r
137 updateWindow.Show();
\r
140 catch (Exception exc)
\r
142 MessageBox.Show(exc.ToString());
\r
146 private void splashTimer(object sender)
\r
148 Thread.Sleep(1000); //sit for 1 seconds then exit
\r
151 private void showSplash(object sender)
\r
153 Form splash = new frmSplashScreen();
\r
157 private void loadUserDefaults()
\r
159 string userDefaults = Properties.Settings.Default.defaultUserSettings;
\r
162 // Some things that need to be done to reset some gui components:
\r
163 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
165 // Send the query from the file to the Query Parser class Then load the preset
\r
166 Functions.QueryParser presetQuery = Functions.QueryParser.Parse(userDefaults);
\r
167 hb_common_func.presetLoader(this, presetQuery, "User Defaults ");
\r
169 catch (Exception exc)
\r
171 MessageBox.Show("Unable to load user Default Settings. \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
177 #region Set Varible Function
\r
178 public void setStreamReader(Parsing.DVD dvd)
\r
180 this.thisDVD = dvd;
\r
184 // --------------------------------------------------------------
\r
185 // The main Menu bar.
\r
186 // --------------------------------------------------------------
\r
189 private void mnu_open_Click(object sender, EventArgs e)
\r
192 File_Open.ShowDialog();
\r
193 filename = File_Open.FileName;
\r
195 if (filename != "")
\r
199 // Create StreamReader & open file
\r
200 StreamReader line = new StreamReader(filename);
\r
202 // Send the query from the file to the Query Parser class then load the preset
\r
203 Functions.QueryParser presetQuery = Functions.QueryParser.Parse(line.ReadLine());
\r
204 hb_common_func.presetLoader(this, presetQuery, filename);
\r
206 // Close the stream
\r
209 catch (Exception exc)
\r
211 MessageBox.Show("Unable to load profile. \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
216 private void mnu_save_Click(object sender, EventArgs e)
\r
219 File_Save.ShowDialog();
\r
220 filename = File_Save.FileName;
\r
221 if (filename != "")
\r
225 // Create a StreamWriter and open the file
\r
226 StreamWriter line = new StreamWriter(filename);
\r
228 // Generate and write the query string to the file
\r
229 String query = hb_common_func.GenerateTheQuery(this);
\r
230 line.WriteLine(query);
\r
232 // close the stream
\r
234 MessageBox.Show("Your profile has been sucessfully saved.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
238 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
244 private void mnu_exit_Click(object sender, EventArgs e)
\r
246 Application.Exit();
\r
253 private void mnu_encode_Click(object sender, EventArgs e)
\r
258 private void mnu_viewDVDdata_Click(object sender, EventArgs e)
\r
260 frmDvdInfo dvdInfoWindow = new frmDvdInfo();
\r
261 dvdInfoWindow.Show();
\r
264 private void mnu_options_Click(object sender, EventArgs e)
\r
266 Form Options = new frmOptions();
\r
267 Options.ShowDialog();
\r
273 #region Presets Menu
\r
275 private void mnu_presetReset_Click(object sender, EventArgs e)
\r
277 treeView_presets.Nodes.Clear();
\r
280 MessageBox.Show("Presets have been updated", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
283 private void mnu_SelectDefault_Click(object sender, EventArgs e)
\r
285 loadNormalPreset();
\r
292 private void mnu_wiki_Click(object sender, EventArgs e)
\r
294 Process.Start("http://handbrake.m0k.org/trac");
\r
297 private void mnu_faq_Click(object sender, EventArgs e)
\r
299 Process.Start("http://handbrake.m0k.org/trac/wiki/WindowsGuiFaq");
\r
302 private void mnu_onlineDocs_Click(object sender, EventArgs e)
\r
304 Process.Start("http://handbrake.m0k.org/?page_id=11");
\r
307 private void mnu_homepage_Click(object sender, EventArgs e)
\r
309 Process.Start("http://handbrake.m0k.org");
\r
312 private void mnu_forum_Click(object sender, EventArgs e)
\r
314 Process.Start("http://handbrake.m0k.org/forum");
\r
317 private void mnu_UpdateCheck_Click(object sender, EventArgs e)
\r
319 Boolean update = hb_common_func.updateCheck();
\r
320 if (update == true)
\r
322 frmUpdater updateWindow = new frmUpdater();
\r
323 updateWindow.Show();
\r
326 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
329 private void mnu_about_Click(object sender, EventArgs e)
\r
331 Form About = new frmAbout();
\r
332 About.ShowDialog();
\r
337 // --------------------------------------------------------------
\r
338 // Buttons on the main Window and items that require actions
\r
339 // --------------------------------------------------------------
\r
343 private void btn_Browse_Click(object sender, EventArgs e)
\r
345 String filename = "";
\r
346 text_source.Text = "";
\r
347 frmDvdInfo dvdInfoWindow = new frmDvdInfo();
\r
349 if (RadioDVD.Checked)
\r
351 DVD_Open.ShowDialog();
\r
352 filename = DVD_Open.SelectedPath;
\r
356 ISO_Open.ShowDialog();
\r
357 filename = ISO_Open.FileName;
\r
360 if (filename != "")
\r
362 Form frmRD = new frmReadDVD(filename, this, dvdInfoWindow);
\r
363 text_source.Text = filename;
\r
364 frmRD.ShowDialog();
\r
367 text_source.Text = "Click 'Browse' to continue";
\r
369 // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.
\r
370 if (drp_dvdtitle.Items.Count == 0)
\r
371 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
374 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
376 // This removes the file extension from the filename box on the save file dialog.
\r
377 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
378 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", "").Replace(".m4v", "").Replace(".mkv", "").Replace(".ogm", "").Replace(".avi", "");
\r
380 // Show the dialog and set the main form file path
\r
381 DVD_Save.ShowDialog();
\r
382 text_destination.Text = DVD_Save.FileName;
\r
384 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
385 if (Check_ChapterMarkers.Checked)
\r
386 text_destination.Text = text_destination.Text.Replace(".mp4", ".m4v");
\r
389 private void btn_h264Clear_Click(object sender, EventArgs e)
\r
391 rtf_h264advanced.Text = "";
\r
396 #region frmMain Actions
\r
398 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
400 // Reset some values on the form
\r
401 lbl_Aspect.Text = "Select a Title";
\r
402 lbl_RecomendedCrop.Text = "Select a Title";
\r
403 drop_chapterStart.Items.Clear();
\r
404 drop_chapterFinish.Items.Clear();
\r
406 // If the dropdown is set to automatic nothing else needs to be done.
\r
407 // Otheriwse if its not, title data has to be loased from parsing.
\r
408 if (drp_dvdtitle.Text != "Automatic")
\r
410 Parsing.Title selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;
\r
412 // Set the Aspect Ratio
\r
413 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();
\r
415 // Set the Recommended Cropping values
\r
416 lbl_RecomendedCrop.Text = string.Format("{0}/{1}/{2}/{3}", selectedTitle.AutoCropDimensions[0], selectedTitle.AutoCropDimensions[1], selectedTitle.AutoCropDimensions[2], selectedTitle.AutoCropDimensions[3]);
\r
418 // Populate the Start chapter Dropdown
\r
419 drop_chapterStart.Items.Clear();
\r
420 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
421 if (drop_chapterStart.Items.Count > 0)
\r
422 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
424 // Populate the Final Chapter Dropdown
\r
425 drop_chapterFinish.Items.Clear();
\r
426 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
427 if (drop_chapterFinish.Items.Count > 0)
\r
428 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
430 // Populate the Audio Channels Dropdown
\r
431 drp_track1Audio.Items.Clear();
\r
432 drp_track1Audio.Items.Add("Automatic");
\r
433 drp_track1Audio.Items.Add("None");
\r
434 drp_track1Audio.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
435 if (drp_track1Audio.Items.Count > 0)
\r
436 drp_track1Audio.Text = drp_track1Audio.Items[0].ToString();
\r
438 drp_track2Audio.Items.Clear();
\r
439 drp_track2Audio.Items.Add("None");
\r
440 drp_track2Audio.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
441 if (drp_track2Audio.Items.Count > 0)
\r
442 drp_track2Audio.Text = drp_track2Audio.Items[0].ToString();
\r
444 // Populate the Subtitles dropdown
\r
445 drp_subtitle.Items.Clear();
\r
446 drp_subtitle.Items.Add("None");
\r
447 drp_subtitle.Items.Add("Autoselect");
\r
448 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());
\r
449 if (drp_subtitle.Items.Count > 0)
\r
450 drp_subtitle.Text = drp_subtitle.Items[0].ToString();
\r
454 // Run the autoName & chapterNaming functions
\r
455 hb_common_func.autoName(this);
\r
456 hb_common_func.chapterNaming(this);
\r
459 private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)
\r
461 drop_chapterStart.BackColor = Color.White;
\r
462 if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
\r
466 int chapterFinish = int.Parse(drop_chapterFinish.Text);
\r
467 int chapterStart = int.Parse(drop_chapterStart.Text);
\r
469 if (chapterFinish < chapterStart)
\r
470 drop_chapterStart.BackColor = Color.LightCoral;
\r
474 drop_chapterStart.BackColor = Color.LightCoral;
\r
477 // Run the Autonaming function
\r
478 hb_common_func.autoName(this);
\r
481 private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)
\r
483 drop_chapterFinish.BackColor = Color.White;
\r
484 if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
\r
488 int chapterFinish = int.Parse(drop_chapterFinish.Text);
\r
489 int chapterStart = int.Parse(drop_chapterStart.Text);
\r
491 if (chapterFinish < chapterStart)
\r
492 drop_chapterFinish.BackColor = Color.LightCoral;
\r
496 drop_chapterFinish.BackColor = Color.LightCoral;
\r
500 // Run the Autonaming function
\r
501 hb_common_func.autoName(this);
\r
504 private void text_bitrate_TextChanged(object sender, EventArgs e)
\r
506 text_filesize.Text = "";
\r
507 slider_videoQuality.Value = 0;
\r
508 SliderValue.Text = "0%";
\r
511 private void text_filesize_TextChanged(object sender, EventArgs e)
\r
513 text_bitrate.Text = "";
\r
514 slider_videoQuality.Value = 0;
\r
515 SliderValue.Text = "0%";
\r
518 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
520 SliderValue.Text = slider_videoQuality.Value.ToString() + "%";
\r
521 text_bitrate.Text = "";
\r
522 text_filesize.Text = "";
\r
525 private void label_h264_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
527 Process.Start("http://handbrake.m0k.org/trac/wiki/x264Options");
\r
530 private void text_width_TextChanged(object sender, EventArgs e)
\r
534 if (CheckPixelRatio.Checked)
\r
536 text_width.Text = "";
\r
537 text_width.BackColor = Color.LightCoral;
\r
538 CheckPixelRatio.BackColor = Color.LightCoral;
\r
542 if ((int.Parse(text_width.Text) % 16) != 0)
\r
543 text_width.BackColor = Color.LightCoral;
\r
545 text_width.BackColor = Color.LightGreen;
\r
548 if ((lbl_Aspect.Text != "Select a Title") && (drp_crop.SelectedIndex == 2))
\r
550 double height = int.Parse(text_width.Text) / double.Parse(lbl_Aspect.Text);
\r
551 double mod16 = height % 16;
\r
552 height = height - mod16;
\r
554 if (text_width.Text == "")
\r
556 text_height.Text = "";
\r
557 text_width.BackColor = Color.White;
\r
560 text_height.Text = height.ToString();
\r
565 // No need to throw an error here.
\r
569 private void text_height_TextChanged(object sender, EventArgs e)
\r
573 if (CheckPixelRatio.Checked)
\r
575 text_height.Text = "";
\r
576 text_height.BackColor = Color.LightCoral;
\r
577 CheckPixelRatio.BackColor = Color.LightCoral;
\r
581 if ((int.Parse(text_height.Text) % 16) != 0)
\r
582 text_height.BackColor = Color.LightCoral;
\r
584 text_height.BackColor = Color.LightGreen;
\r
590 // No need to alert the user.
\r
594 private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)
\r
596 if ((string)drp_crop.SelectedItem == "Custom")
\r
598 text_left.Enabled = true;
\r
599 text_right.Enabled = true;
\r
600 text_top.Enabled = true;
\r
601 text_bottom.Enabled = true;
\r
602 text_left.Text = "0";
\r
603 text_right.Text = "0";
\r
604 text_top.Text = "0";
\r
605 text_bottom.Text = "0";
\r
608 if ((string)drp_crop.SelectedItem == "Automatic")
\r
610 text_left.Enabled = false;
\r
611 text_right.Enabled = false;
\r
612 text_top.Enabled = false;
\r
613 text_bottom.Enabled = false;
\r
615 if (lbl_RecomendedCrop.Text != "Select a Title")
\r
617 string[] temp = new string[4];
\r
618 temp = lbl_RecomendedCrop.Text.Split('/');
\r
619 text_left.Text = temp[2];
\r
620 text_right.Text = temp[3];
\r
621 text_top.Text = temp[0];
\r
622 text_bottom.Text = temp[1];
\r
626 text_left.Text = "";
\r
627 text_right.Text = "";
\r
628 text_top.Text = "";
\r
629 text_bottom.Text = "";
\r
633 if ((string)drp_crop.SelectedItem == "No Crop")
\r
635 text_left.Enabled = false;
\r
636 text_right.Enabled = false;
\r
637 text_top.Enabled = false;
\r
638 text_bottom.Enabled = false;
\r
639 text_left.Text = "0";
\r
640 text_right.Text = "0";
\r
641 text_top.Text = "0";
\r
642 text_bottom.Text = "0";
\r
647 private void check_vfr_CheckedChanged(object sender, EventArgs e)
\r
649 if (check_vfr.CheckState == CheckState.Checked)
\r
651 check_detelecine.Enabled = false;
\r
652 check_detelecine.CheckState = CheckState.Checked;
\r
653 drp_videoFramerate.Enabled = false;
\r
654 drp_videoFramerate.SelectedItem = "29.97";
\r
655 lbl_vfr.Visible = true;
\r
659 check_detelecine.Enabled = true;
\r
660 drp_videoFramerate.Enabled = true;
\r
661 drp_videoFramerate.SelectedItem = "Automatic";
\r
662 lbl_vfr.Visible = false;
\r
666 private void CheckPixelRatio_CheckedChanged(object sender, EventArgs e)
\r
668 text_width.Text = "";
\r
669 text_height.Text = "";
\r
670 text_width.BackColor = Color.White;
\r
671 text_height.BackColor = Color.White;
\r
672 CheckPixelRatio.BackColor = TabPage1.BackColor;
\r
674 if (CheckPixelRatio.Checked)
\r
676 check_lAnamorphic.Enabled = false;
\r
677 check_lAnamorphic.Checked = false;
\r
680 check_lAnamorphic.Enabled = true;
\r
683 private void check_lAnamorphic_CheckedChanged(object sender, EventArgs e)
\r
685 if (check_lAnamorphic.Checked)
\r
687 CheckPixelRatio.Enabled = false;
\r
688 CheckPixelRatio.Checked = false;
\r
691 CheckPixelRatio.Enabled = true;
\r
694 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
696 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
698 if (drp_videoEncoder.Text.Contains("H.264"))
\r
699 check_turbo.Enabled = true;
\r
703 check_turbo.Enabled = false;
\r
704 check_turbo.CheckState = CheckState.Unchecked;
\r
708 private void check_largeFile_CheckedChanged(object sender, EventArgs e)
\r
710 if (!text_destination.Text.Contains(".mp4"))
\r
712 lbl_largeMp4Warning.Text = "Warning: Only mp4 files are supported";
\r
713 lbl_largeMp4Warning.ForeColor = Color.Red;
\r
714 check_largeFile.CheckState = CheckState.Unchecked;
\r
718 lbl_largeMp4Warning.Text = "Warning: Breaks iPod, @TV, PS3 compatibility.";
\r
719 lbl_largeMp4Warning.ForeColor = Color.Black;
\r
723 private void check_iPodAtom_CheckedChanged(object sender, EventArgs e)
\r
725 if (!text_destination.Text.Contains(".mp4"))
\r
727 lbl_ipodAtom.Visible = true;
\r
728 check_iPodAtom.CheckState = CheckState.Unchecked;
\r
731 lbl_ipodAtom.Visible = false;
\r
734 private void check_optimiseMP4_CheckedChanged(object sender, EventArgs e)
\r
736 if (!text_destination.Text.Contains(".mp4"))
\r
738 check_optimiseMP4.BackColor = Color.LightCoral;
\r
739 check_optimiseMP4.CheckState = CheckState.Unchecked;
\r
742 check_optimiseMP4.BackColor = Color.Transparent;
\r
745 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
747 if (drp_dvdtitle.Items.Count == 0)
\r
748 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
751 private void drp_audioCodec_SelectedIndexChanged(object sender, EventArgs e)
\r
753 if (drp_audioCodec.Text == "AAC")
\r
755 drp_audioMixDown.Items.Clear();
\r
756 drp_audioMixDown.Items.Add("Mono");
\r
757 drp_audioMixDown.Items.Add("Stereo");
\r
758 drp_audioMixDown.Items.Add("Dolby Surround");
\r
759 drp_audioMixDown.Items.Add("Dolby Pro Logic II");
\r
760 drp_audioMixDown.Items.Add("6 Channel Discrete");
\r
762 drp_audioBitrate.Items.Clear();
\r
763 drp_audioBitrate.Items.Add("32");
\r
764 drp_audioBitrate.Items.Add("40");
\r
765 drp_audioBitrate.Items.Add("48");
\r
766 drp_audioBitrate.Items.Add("56");
\r
767 drp_audioBitrate.Items.Add("64");
\r
768 drp_audioBitrate.Items.Add("80");
\r
769 drp_audioBitrate.Items.Add("86");
\r
770 drp_audioBitrate.Items.Add("112");
\r
771 drp_audioBitrate.Items.Add("128");
\r
772 drp_audioBitrate.Items.Add("160");
\r
777 drp_audioMixDown.Items.Clear();
\r
778 drp_audioMixDown.Items.Add("Stereo");
\r
779 drp_audioMixDown.Items.Add("Dolby Surround");
\r
780 drp_audioMixDown.Items.Add("Dolby Pro Logic II");
\r
782 drp_audioBitrate.Items.Clear();
\r
783 drp_audioBitrate.Items.Add("32");
\r
784 drp_audioBitrate.Items.Add("40");
\r
785 drp_audioBitrate.Items.Add("48");
\r
786 drp_audioBitrate.Items.Add("56");
\r
787 drp_audioBitrate.Items.Add("64");
\r
788 drp_audioBitrate.Items.Add("80");
\r
789 drp_audioBitrate.Items.Add("86");
\r
790 drp_audioBitrate.Items.Add("112");
\r
791 drp_audioBitrate.Items.Add("128");
\r
792 drp_audioBitrate.Items.Add("160");
\r
793 drp_audioBitrate.Items.Add("192");
\r
794 drp_audioBitrate.Items.Add("224");
\r
795 drp_audioBitrate.Items.Add("256");
\r
796 drp_audioBitrate.Items.Add("320");
\r
800 private void drp_audioMixDown_SelectedIndexChanged(object sender, EventArgs e)
\r
802 if ((drp_audioCodec.Text == "AAC") && (drp_audioMixDown.Text == "6 Channel Discrete"))
\r
804 drp_audioBitrate.Items.Clear();
\r
805 drp_audioBitrate.Items.Add("32");
\r
806 drp_audioBitrate.Items.Add("40");
\r
807 drp_audioBitrate.Items.Add("48");
\r
808 drp_audioBitrate.Items.Add("56");
\r
809 drp_audioBitrate.Items.Add("64");
\r
810 drp_audioBitrate.Items.Add("80");
\r
811 drp_audioBitrate.Items.Add("86");
\r
812 drp_audioBitrate.Items.Add("112");
\r
813 drp_audioBitrate.Items.Add("128");
\r
814 drp_audioBitrate.Items.Add("160");
\r
815 drp_audioBitrate.Items.Add("192");
\r
816 drp_audioBitrate.Items.Add("224");
\r
817 drp_audioBitrate.Items.Add("256");
\r
818 drp_audioBitrate.Items.Add("320");
\r
819 drp_audioBitrate.Items.Add("384");
\r
823 private void slider_drc_Scroll(object sender, EventArgs e)
\r
825 double value = slider_drc.Value / 10.0;
\r
828 lbl_drc.Text = value.ToString();
\r
831 private void drp_subtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
833 if (drp_subtitle.Text.Contains("None"))
\r
835 check_forced.Enabled = false;
\r
836 check_forced.Checked = false;
\r
839 check_forced.Enabled = true;
\r
842 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
844 if (Check_ChapterMarkers.Checked)
\r
846 string destination = text_destination.Text;
\r
847 destination = destination.Replace(".mp4", ".m4v");
\r
848 text_destination.Text = destination;
\r
849 data_chpt.Rows.Clear();
\r
850 data_chpt.Enabled = true;
\r
851 hb_common_func.chapterNaming(this);
\r
855 string destination = text_destination.Text;
\r
856 destination = destination.Replace(".m4v", ".mp4");
\r
857 text_destination.Text = destination;
\r
858 data_chpt.Rows.Clear();
\r
859 data_chpt.Enabled = false;
\r
863 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
865 //Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
866 if (!drp_videoEncoder.Text.Contains("H.264"))
\r
868 check_turbo.CheckState = CheckState.Unchecked;
\r
869 check_turbo.Enabled = false;
\r
870 h264Tab.Enabled = false;
\r
871 rtf_h264advanced.Text = "";
\r
872 check_iPodAtom.Enabled = false;
\r
873 check_iPodAtom.Checked = false;
\r
874 lbl_ipodAtom.Visible = false;
\r
875 check_optimiseMP4.Enabled = false;
\r
879 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
880 check_turbo.Enabled = true;
\r
882 h264Tab.Enabled = true;
\r
883 check_iPodAtom.Enabled = true;
\r
884 lbl_ipodAtom.Visible = false;
\r
885 check_optimiseMP4.Enabled = true;
\r
892 #region Query Editor Tab
\r
894 private void btn_clear_Click(object sender, EventArgs e)
\r
899 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
901 rtf_query.Text = hb_common_func.GenerateTheQuery(this);
\r
904 private void btn_copy2C_Click(object sender, EventArgs e)
\r
906 if (rtf_query.Text != "")
\r
907 Clipboard.SetText(rtf_query.Text, TextDataFormat.Text);
\r
912 // --------------------------------------------------------------
\r
913 // Main Window Preset System
\r
914 // --------------------------------------------------------------
\r
916 #region Preset System
\r
918 // Import Current Presets
\r
919 private void updatePresets()
\r
921 string[] presets = new string[17];
\r
922 presets[0] = "Animation";
\r
923 presets[1] = "AppleTV";
\r
924 presets[2] = "Bedlam";
\r
925 presets[3] = "Blind";
\r
926 presets[4] = "Broke";
\r
927 presets[5] = "Classic";
\r
928 presets[6] = "Constant Quality Rate";
\r
929 presets[7] = "Deux Six Quatre";
\r
930 presets[8] = "Film";
\r
931 presets[9] = "iPhone / iPod Touch";
\r
932 presets[10] = "iPod High-Rez";
\r
933 presets[11] = "iPod Low-Rez";
\r
934 presets[12] = "Normal";
\r
935 presets[13] = "PS3";
\r
936 presets[14] = "PSP";
\r
937 presets[15] = "QuickTime";
\r
938 presets[16] = "Television";
\r
940 TreeNode preset_treeview = new TreeNode();
\r
942 foreach (string preset in presets)
\r
944 preset_treeview = new TreeNode(preset);
\r
946 // Now Fill Out List View with Items
\r
947 treeView_presets.Nodes.Add(preset_treeview);
\r
951 private void grabCLIPresets()
\r
953 string appPath = Application.StartupPath.ToString() + "\\";
\r
954 string strCmdLine = "cmd /c " + '"' + '"' + appPath + "HandBrakeCLI.exe" + '"' + " --preset-list >" + '"' + appPath + "presets.dat" + '"' + " 2>&1" + '"';
\r
955 Process hbproc = Process.Start("CMD.exe", strCmdLine);
\r
956 hbproc.WaitForExit();
\r
961 // Function to select the default preset.
\r
962 private void loadNormalPreset()
\r
965 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
967 if (treenode.ToString().Equals("TreeNode: Normal"))
\r
968 normal = treenode.Index;
\r
971 TreeNode np = treeView_presets.Nodes[normal];
\r
973 treeView_presets.SelectedNode = np;
\r
977 private void btn_setDefault_Click(object sender, EventArgs e)
\r
979 String query = hb_common_func.GenerateTheQuery(this);
\r
980 Properties.Settings.Default.defaultUserSettings = query;
\r
981 // Save the new default Settings
\r
982 Properties.Settings.Default.Save();
\r
983 MessageBox.Show("New default settings saved.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
986 // Preset Selection
\r
987 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
989 string selectedPreset = null;
\r
990 selectedPreset = treeView_presets.SelectedNode.Text;
\r
994 string appPath = Application.StartupPath.ToString() + "\\";
\r
995 StreamReader presetInput = new StreamReader(appPath + "presets.dat");
\r
997 while (!presetInput.EndOfStream)
\r
999 if ((char)presetInput.Peek() == '+')
\r
1001 string preset = presetInput.ReadLine().Replace("+ ", "");
\r
1002 Regex r = new Regex("(: )"); // Split on hyphens.
\r
1003 string[] presetName = r.Split(preset);
\r
1006 if (selectedPreset == presetName[0])
\r
1008 // Need to disable anamorphic now, otherwise it may overide the width / height values later.
\r
1009 CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
1011 // Send the query from the file to the Query Parser class
\r
1012 Functions.QueryParser presetQuery = Functions.QueryParser.Parse(preset);
\r
1014 // Now load the preset
\r
1015 hb_common_func.presetLoader(this, presetQuery, selectedPreset);
\r
1020 presetInput.ReadLine();
\r
1023 catch (Exception exc)
\r
1025 MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1031 //---------------------------------------------------
\r
1032 // Encode / Cancel Buttons
\r
1033 // Encode Progress Text Handler
\r
1034 //---------------------------------------------------
\r
1036 #region Encodeing and Queue
\r
1038 Functions.CLI process = new Functions.CLI();
\r
1039 private delegate void UpdateUIHandler();
\r
1041 [DllImport("user32.dll")]
\r
1042 public static extern void LockWorkStation();
\r
1043 [DllImport("user32.dll")]
\r
1044 public static extern int ExitWindowsEx(int uFlags, int dwReason);
\r
1046 private void btn_queue_Click(object sender, EventArgs e)
\r
1049 if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")
\r
1050 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1054 if (rtf_query.Text != "")
\r
1055 query = rtf_query.Text;
\r
1057 query = hb_common_func.GenerateTheQuery(this);
\r
1059 queueWindow.list_queue.Items.Add(query);
\r
1060 queueWindow.Show();
\r
1064 private void showQueue()
\r
1066 queueWindow.Show();
\r
1069 private void btn_encode_Click(object sender, EventArgs e)
\r
1071 if (text_source.Text == "" || text_source.Text == "Click 'Browse' to continue" || text_destination.Text == "")
\r
1072 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1076 if (rtf_query.Text != "")
\r
1077 query = rtf_query.Text;
\r
1079 query = hb_common_func.GenerateTheQuery(this);
\r
1081 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
1082 lbl_encode.Visible = true;
\r
1083 lbl_encode.Text = "Encoding in Progress";
\r
1087 private void procMonitor(object state)
\r
1089 // Make sure we are not already encoding and if we are then display an error.
\r
1090 if (hbProc != null)
\r
1091 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1094 hbProc = process.runCli(this, (string)state, false, false, false, false);
\r
1095 hbProc.WaitForExit();
\r
1100 // Do something whent he encode ends.
\r
1101 switch (Properties.Settings.Default.CompletionOption)
\r
1104 System.Diagnostics.Process.Start("Shutdown", "-s -t 60");
\r
1107 ExitWindowsEx(0, 0);
\r
1110 Application.SetSuspendState(PowerState.Suspend, true, true);
\r
1113 Application.SetSuspendState(PowerState.Hibernate, true, true);
\r
1115 case "Lock System":
\r
1116 LockWorkStation();
\r
1118 case "Quit HandBrake":
\r
1119 Application.Exit();
\r
1127 private void setEncodeLabel()
\r
1129 if (this.InvokeRequired)
\r
1131 this.BeginInvoke(new UpdateUIHandler(setEncodeLabel));
\r
1134 lbl_encode.Text = "Encoding Finished";
\r
1141 // This is the END of the road ------------------------------------------------------------------------------
\r