2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr/>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
9 using System.Collections.Generic;
\r
10 using System.ComponentModel;
\r
11 using System.Diagnostics;
\r
12 using System.Drawing;
\r
13 using System.Globalization;
\r
15 using System.Reflection;
\r
16 using System.Threading;
\r
17 using System.Windows.Forms;
\r
20 using HandBrake.ApplicationServices.Model;
\r
21 using HandBrake.ApplicationServices.Parsing;
\r
22 using HandBrake.ApplicationServices.Services;
\r
23 using HandBrake.ApplicationServices.Services.Interfaces;
\r
29 public partial class frmMain : Form
\r
31 // Objects which may be used by one or more other objects *************
\r
32 private IQueue encodeQueue = new Queue();
\r
33 private PresetsHandler presetHandler = new PresetsHandler();
\r
35 // Windows ************************************************************
\r
36 private frmQueue queueWindow;
\r
37 private frmPreview qtpreview;
\r
38 private frmActivityWindow activityWindow;
\r
39 private frmSplashScreen splash = new frmSplashScreen();
\r
41 // Globals: Mainly used for tracking. *********************************
\r
42 public Title selectedTitle;
\r
43 public string sourcePath;
\r
44 private SourceType selectedSourceType;
\r
45 private string dvdDrivePath;
\r
46 private string dvdDriveLabel;
\r
47 private Preset currentlySelectedPreset;
\r
48 private DVD currentSource;
\r
49 private IScan SourceScan = new ScanService();
\r
50 private List<DriveInformation> drives;
\r
52 // Delegates **********************************************************
\r
53 private delegate void UpdateWindowHandler();
\r
55 // Applicaiton Startup ************************************************
\r
60 /// Gets SourceName.
\r
62 public string SourceName
\r
66 if (this.selectedSourceType == SourceType.DvdDrive)
\r
68 return this.dvdDriveLabel;
\r
71 if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")
\r
72 return Path.GetFileNameWithoutExtension(this.sourcePath);
\r
74 return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));
\r
80 #region Application Startup
\r
83 /// Initializes a new instance of the <see cref="frmMain"/> class.
\r
85 /// <param name="args">
\r
86 /// The arguments passed in on application startup.
\r
88 public frmMain(string[] args)
\r
90 // Load and setup the splash screen in this thread
\r
92 Label lblStatus = new Label { Size = new Size(150, 20), Location = new Point(182, 102) };
\r
93 splash.Controls.Add(lblStatus);
\r
95 InitializeComponent();
\r
97 // Update the users config file with the CLI version data.
\r
98 UpdateSplashStatus(lblStatus, "Checking CLI Version Data ...");
\r
99 Main.SetCliVersionData();
\r
100 Main.CheckForValidCliVersion();
\r
102 if (Settings.Default.hb_version.Contains("svn"))
\r
104 Version v = Assembly.GetExecutingAssembly().GetName().Version;
\r
105 this.Text += " " + v.ToString(4);
\r
108 // Show the form, but leave disabled until preloading is complete then show the main form)
\r
109 this.Enabled = false;
\r
111 Application.DoEvents(); // Forces frmMain to draw
\r
113 // Check for new versions, if update checking is enabled
\r
114 if (Properties.Settings.Default.updateStatus)
\r
116 DateTime now = DateTime.Now;
\r
117 DateTime lastCheck = Properties.Settings.Default.lastUpdateCheckDate;
\r
118 TimeSpan elapsed = now.Subtract(lastCheck);
\r
119 if (elapsed.TotalDays > Properties.Settings.Default.daysBetweenUpdateCheck)
\r
121 UpdateSplashStatus(lblStatus, "Checking for updates ...");
\r
122 Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false);
\r
126 // Clear the log files in the background
\r
127 if (Properties.Settings.Default.clearOldLogs)
\r
129 UpdateSplashStatus(lblStatus, "Clearing Old Log Files ..");
\r
130 Thread clearLog = new Thread(Main.ClearOldLogs);
\r
134 // Setup the GUI components
\r
135 UpdateSplashStatus(lblStatus, "Setting up the GUI ...");
\r
136 LoadPresetPanel(); // Load the Preset Panel
\r
137 treeView_presets.ExpandAll();
\r
138 lbl_encode.Text = string.Empty;
\r
139 drop_mode.SelectedIndex = 0;
\r
140 queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue
\r
141 if (!Properties.Settings.Default.QueryEditorTab)
\r
142 tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.
\r
143 if (Properties.Settings.Default.tooltipEnable)
\r
144 ToolTip.Active = true;
\r
146 // Load the user's default settings or Normal Preset
\r
147 if (Properties.Settings.Default.defaultPreset != string.Empty && presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)
\r
149 string query = presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).Query;
\r
152 x264Panel.Reset2Defaults();
\r
154 QueryParser presetQuery = QueryParser.Parse(query);
\r
155 PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset);
\r
157 x264Panel.StandardizeOptString();
\r
158 x264Panel.SetCurrentSettingsInPanel();
\r
162 loadNormalPreset();
\r
164 // Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)
\r
165 GrowlCommunicator.Register();
\r
167 // Finished Loading
\r
168 UpdateSplashStatus(lblStatus, "Loading Complete.");
\r
171 this.Enabled = true;
\r
173 // Event Handlers and Queue Recovery
\r
177 // If have a file passed in via command arguemtents, check it's a file and try scanning it.
\r
178 if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0])))
\r
180 this.StartScan(args[0], 0);
\r
184 private void UpdateCheckDone(IAsyncResult result)
\r
186 if (InvokeRequired)
\r
188 Invoke(new MethodInvoker(() => UpdateCheckDone(result)));
\r
192 UpdateCheckInformation info;
\r
196 info = Main.EndCheckForUpdates(result);
\r
198 if (info.NewVersionAvailable)
\r
200 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
201 updateWindow.ShowDialog();
\r
204 catch (Exception ex)
\r
206 if ((bool)result.AsyncState)
\r
207 Main.ShowExceptiowWindow("Unable to check for updates, Please try again later.", ex.ToString());
\r
211 // Startup Functions
\r
212 private void queueRecovery()
\r
214 if (Main.CheckQueueRecovery())
\r
216 DialogResult result =
\r
218 "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?",
\r
219 "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
221 if (result == DialogResult.Yes)
\r
222 encodeQueue.LoadQueueFromFile("hb_queue_recovery.xml"); // Start Recovery
\r
225 // Remove the Queue recovery file if the user doesn't want to recovery the last queue.
\r
226 string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
\r
227 if (File.Exists(queuePath))
\r
228 File.Delete(queuePath);
\r
233 private void UpdateSplashStatus(Label status, string text)
\r
235 status.Text = text;
\r
236 Application.DoEvents();
\r
243 // Encoding Events for setting up the GUI
\r
244 private void events()
\r
246 // Handle Widget changes when preset is selected.
\r
247 RegisterPresetEventHandler();
\r
249 // Handle Window Resize
\r
250 if (Properties.Settings.Default.MainWindowMinimize)
\r
251 this.Resize += new EventHandler(frmMain_Resize);
\r
253 // Handle Encode Start / Finish / Pause
\r
254 encodeQueue.EncodeStarted += new EventHandler(encodeStarted);
\r
255 encodeQueue.EncodeEnded += new EventHandler(encodeEnded);
\r
257 // Handle a file being draged onto the GUI.
\r
258 this.DragEnter += new DragEventHandler(frmMain_DragEnter);
\r
259 this.DragDrop += new DragEventHandler(frmMain_DragDrop);
\r
262 // Change the preset label to custom when a user changes a setting. Don't want to give the impression that users can change settings and still be using a preset
\r
263 private void RegisterPresetEventHandler()
\r
266 drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
267 check_largeFile.CheckedChanged += new EventHandler(changePresetLabel);
\r
268 check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel);
\r
269 check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);
\r
271 // Picture Settings
\r
272 PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);
\r
275 Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);
\r
278 drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
279 check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel);
\r
280 check_turbo.CheckedChanged += new EventHandler(changePresetLabel);
\r
281 text_filesize.TextChanged += new EventHandler(changePresetLabel);
\r
282 text_bitrate.TextChanged += new EventHandler(changePresetLabel);
\r
283 slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel);
\r
286 AudioSettings.AudioListChanged += new EventHandler(changePresetLabel);
\r
289 x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);
\r
292 private void UnRegisterPresetEventHandler()
\r
294 // Output Settings
\r
295 drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
296 check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel);
\r
297 check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel);
\r
298 check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);
\r
300 // Picture Settings
\r
301 PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);
\r
304 Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);
\r
307 drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
308 check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel);
\r
309 check_turbo.CheckedChanged -= new EventHandler(changePresetLabel);
\r
310 text_filesize.TextChanged -= new EventHandler(changePresetLabel);
\r
311 text_bitrate.TextChanged -= new EventHandler(changePresetLabel);
\r
312 slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel);
\r
315 AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel);
\r
318 x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);
\r
321 private void changePresetLabel(object sender, EventArgs e)
\r
323 labelPreset.Text = "Output Settings (Preset: Custom)";
\r
324 this.currentlySelectedPreset = null;
\r
327 private static void frmMain_DragEnter(object sender, DragEventArgs e)
\r
329 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
\r
330 e.Effect = DragDropEffects.All;
\r
333 private void frmMain_DragDrop(object sender, DragEventArgs e)
\r
335 string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
\r
336 sourcePath = string.Empty;
\r
338 if (fileList != null)
\r
340 if (!string.IsNullOrEmpty(fileList[0]))
\r
342 this.selectedSourceType = SourceType.VideoFile;
\r
343 StartScan(fileList[0], 0);
\r
346 UpdateSourceLabel();
\r
349 UpdateSourceLabel();
\r
352 private void encodeStarted(object sender, EventArgs e)
\r
354 if (Properties.Settings.Default.preventSleep)
\r
356 Win32.PreventSleep();
\r
358 SetEncodeStarted();
\r
359 encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;
\r
362 private void encodeEnded(object sender, EventArgs e)
\r
364 if (Properties.Settings.Default.preventSleep)
\r
366 Win32.AllowSleep();
\r
368 encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;
\r
369 SetEncodeFinished();
\r
373 // User Interface Menus / Tool Strips *********************************
\r
378 /// Kill The scan menu Item
\r
380 /// <param name="sender">
\r
383 /// <param name="e">
\r
386 private void mnu_killCLI_Click(object sender, EventArgs e)
\r
392 /// Exit the Application Menu Item
\r
394 /// <param name="sender">
\r
397 /// <param name="e">
\r
400 private void mnu_exit_Click(object sender, EventArgs e)
\r
402 Application.Exit();
\r
410 /// Menu - Start Button
\r
412 /// <param name="sender">
\r
415 /// <param name="e">
\r
418 private void mnu_encode_Click(object sender, EventArgs e)
\r
420 queueWindow.Show();
\r
424 /// Menu - Display the Log Window
\r
426 /// <param name="sender">
\r
429 /// <param name="e">
\r
432 private void mnu_encodeLog_Click(object sender, EventArgs e)
\r
434 frmActivityWindow dvdInfoWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
435 dvdInfoWindow.Show();
\r
439 /// Menu - Display the Options Window
\r
441 /// <param name="sender">
\r
444 /// <param name="e">
\r
447 private void mnu_options_Click(object sender, EventArgs e)
\r
449 Form options = new frmOptions(this);
\r
450 options.ShowDialog();
\r
455 #region Presets Menu
\r
458 /// Reset the Built in Presets
\r
460 /// <param name="sender">
\r
463 /// <param name="e">
\r
466 private void mnu_presetReset_Click(object sender, EventArgs e)
\r
468 presetHandler.UpdateBuiltInPresets();
\r
470 if (treeView_presets.Nodes.Count == 0)
\r
472 "Unable to load the presets.xml 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!",
\r
473 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
475 MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
477 treeView_presets.ExpandAll();
\r
481 /// Delete the selected preset
\r
483 /// <param name="sender">
\r
486 /// <param name="e">
\r
489 private void mnu_delete_preset_Click(object sender, EventArgs e)
\r
491 presetHandler.RemoveBuiltInPresets();
\r
492 LoadPresetPanel(); // Reload the preset panel
\r
496 /// Select the Normal preset
\r
498 /// <param name="sender">
\r
501 /// <param name="e">
\r
504 private void mnu_SelectDefault_Click(object sender, EventArgs e)
\r
506 loadNormalPreset();
\r
510 /// Import a plist Preset
\r
512 /// <param name="sender">
\r
515 /// <param name="e">
\r
518 private void mnu_importMacPreset_Click(object sender, EventArgs e)
\r
524 /// Export a Plist Preset
\r
526 /// <param name="sender">
\r
529 /// <param name="e">
\r
532 private void mnu_exportMacPreset_Click(object sender, EventArgs e)
\r
538 /// Create a new Preset
\r
540 /// <param name="sender">
\r
543 /// <param name="e">
\r
546 private void btn_new_preset_Click(object sender, EventArgs e)
\r
548 Form preset = new frmAddPreset(this, presetHandler);
\r
549 if (preset.ShowDialog() == DialogResult.OK)
\r
551 TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };
\r
552 treeView_presets.Nodes.Add(presetTreeview);
\r
553 presetHandler.LastPresetAdded = null;
\r
562 /// Menu - Display the User Guide Web Page
\r
564 /// <param name="sender">
\r
567 /// <param name="e">
\r
570 private void mnu_user_guide_Click(object sender, EventArgs e)
\r
572 Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");
\r
576 /// Menu - Check for Updates
\r
578 /// <param name="sender">
\r
581 /// <param name="e">
\r
584 private void mnu_UpdateCheck_Click(object sender, EventArgs e)
\r
586 lbl_updateCheck.Visible = true;
\r
587 Main.BeginCheckForUpdates(new AsyncCallback(this.UpdateCheckDoneMenu), false);
\r
591 /// Menu - Display the About Window
\r
593 /// <param name="sender">
\r
596 /// <param name="e">
\r
599 private void mnu_about_Click(object sender, EventArgs e)
\r
601 using (frmAbout About = new frmAbout())
\r
603 About.ShowDialog();
\r
612 /// RMenu - Expand All
\r
614 /// <param name="sender">
\r
617 /// <param name="e">
\r
620 private void pmnu_expandAll_Click(object sender, EventArgs e)
\r
622 treeView_presets.ExpandAll();
\r
626 /// RMenu - Collaspe All
\r
628 /// <param name="sender">
\r
631 /// <param name="e">
\r
634 private void pmnu_collapse_Click(object sender, EventArgs e)
\r
636 treeView_presets.CollapseAll();
\r
640 /// Menu - Import Preset
\r
642 /// <param name="sender">
\r
645 /// <param name="e">
\r
648 private void pmnu_import_Click(object sender, EventArgs e)
\r
654 /// RMenu - Save Changes to Preset
\r
656 /// <param name="sender">
\r
659 /// <param name="e">
\r
662 private void pmnu_saveChanges_Click(object sender, EventArgs e)
\r
664 // TODO this requires a re-think since the Query Editor has changed.
\r
665 DialogResult result =
\r
667 "Do you wish to include picture settings when updating the preset: " +
\r
668 treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,
\r
669 MessageBoxIcon.Question);
\r
670 if (result == DialogResult.Yes)
\r
671 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
672 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);
\r
673 else if (result == DialogResult.No)
\r
674 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
675 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);
\r
679 /// RMenu - Delete Preset
\r
681 /// <param name="sender">
\r
684 /// <param name="e">
\r
687 private void pmnu_delete_click(object sender, EventArgs e)
\r
689 if (treeView_presets.SelectedNode != null)
\r
691 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
692 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
694 treeView_presets.Select();
\r
698 /// Preset Menu Is Opening. Setup the Menu
\r
700 /// <param name="sender">
\r
703 /// <param name="e">
\r
706 private void presets_menu_Opening(object sender, CancelEventArgs e)
\r
708 // Make sure that the save menu is always disabled by default
\r
709 pmnu_saveChanges.Enabled = false;
\r
711 // Now enable the save menu if the selected preset is a user preset
\r
712 if (treeView_presets.SelectedNode != null)
\r
713 if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))
\r
714 pmnu_saveChanges.Enabled = true;
\r
716 treeView_presets.Select();
\r
719 // Presets Management
\r
722 /// Button - Add a preset
\r
724 /// <param name="sender">
\r
727 /// <param name="e">
\r
730 private void btn_addPreset_Click(object sender, EventArgs e)
\r
732 Form preset = new frmAddPreset(this, presetHandler);
\r
733 if (preset.ShowDialog() == DialogResult.OK)
\r
735 TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };
\r
736 treeView_presets.Nodes.Add(presetTreeview);
\r
737 presetHandler.LastPresetAdded = null;
\r
742 /// Button - remove a Preset
\r
744 /// <param name="sender">
\r
747 /// <param name="e">
\r
750 private void btn_removePreset_Click(object sender, EventArgs e)
\r
752 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
753 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
754 if (result == DialogResult.Yes)
\r
756 if (treeView_presets.SelectedNode != null)
\r
758 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
759 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
762 treeView_presets.Select();
\r
766 /// Button - Set the selected preset as the default
\r
768 /// <param name="sender">
\r
771 /// <param name="e">
\r
774 private void btn_setDefault_Click(object sender, EventArgs e)
\r
776 if (treeView_presets.SelectedNode != null)
\r
778 DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",
\r
779 "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
780 if (result == DialogResult.Yes)
\r
782 Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;
\r
783 Properties.Settings.Default.Save();
\r
784 MessageBox.Show("New default preset set.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
788 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
792 /// PresetBar Mouse Down event
\r
794 /// <param name="sender">
\r
797 /// <param name="e">
\r
800 private void treeview_presets_mouseUp(object sender, MouseEventArgs e)
\r
802 if (e.Button == MouseButtons.Right)
\r
803 treeView_presets.SelectedNode = treeView_presets.GetNodeAt(e.Location);
\r
804 else if (e.Button == MouseButtons.Left)
\r
806 if (treeView_presets.GetNodeAt(e.Location) != null)
\r
808 if (labelPreset.Text.Contains(treeView_presets.GetNodeAt(e.Location).Text))
\r
813 treeView_presets.Select();
\r
817 /// Preset Bar after selecting the preset
\r
819 /// <param name="sender">
\r
822 /// <param name="e">
\r
825 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
831 /// Preset Bar - Handle the Delete Key
\r
833 /// <param name="sender">
\r
836 /// <param name="e">
\r
839 private void treeView_presets_deleteKey(object sender, KeyEventArgs e)
\r
841 if (e.KeyCode == Keys.Delete)
\r
843 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
844 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
845 if (result == DialogResult.Yes)
\r
847 if (treeView_presets.SelectedNode != null)
\r
848 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
850 // Remember each nodes expanded status so we can reload it
\r
851 List<bool> nodeStatus = new List<bool>();
\r
852 foreach (TreeNode node in treeView_presets.Nodes)
\r
853 nodeStatus.Add(node.IsExpanded);
\r
855 // Now reload the preset panel
\r
858 // And finally, re-expand any of the nodes if required
\r
860 foreach (TreeNode node in treeView_presets.Nodes)
\r
872 /// Select the selected preset and setup the GUI
\r
874 private void selectPreset()
\r
876 if (treeView_presets.SelectedNode != null)
\r
878 // Ok, so, we've selected a preset. Now we want to load it.
\r
879 string presetName = treeView_presets.SelectedNode.Text;
\r
880 Preset preset = presetHandler.GetPreset(presetName);
\r
881 if (preset != null)
\r
883 string query = presetHandler.GetPreset(presetName).Query;
\r
887 // Ok, Reset all the H264 widgets before changing the preset
\r
888 x264Panel.Reset2Defaults();
\r
890 // Send the query from the file to the Query Parser class
\r
891 QueryParser presetQuery = QueryParser.Parse(query);
\r
893 // Now load the preset
\r
894 PresetLoader.LoadPreset(this, presetQuery, presetName);
\r
896 // The x264 widgets will need updated, so do this now:
\r
897 x264Panel.StandardizeOptString();
\r
898 x264Panel.SetCurrentSettingsInPanel();
\r
900 // Finally, let this window have a copy of the preset settings.
\r
901 this.currentlySelectedPreset = preset;
\r
902 PictureSettings.SetPresetCropWarningLabel(preset);
\r
909 /// Load the Normal Preset
\r
911 private void loadNormalPreset()
\r
913 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
915 foreach (TreeNode node in treenode.Nodes)
\r
917 if (node.Text.Equals("Normal"))
\r
918 treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0];
\r
924 /// Import a plist preset
\r
926 private void ImportPreset()
\r
928 if (openPreset.ShowDialog() == DialogResult.OK)
\r
930 QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);
\r
931 if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))
\r
933 DialogResult result =
\r
934 MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",
\r
935 "Overwrite preset?",
\r
936 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
937 if (result == DialogResult.Yes)
\r
939 PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
\r
940 presetHandler.Update(parsed.PresetName + " (Imported)",
\r
941 QueryGenerator.GenerateFullQuery(this),
\r
942 parsed.UsesPictureSettings);
\r
947 PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
\r
948 if (presetHandler.Add(parsed.PresetName + " (Imported)",
\r
949 QueryGenerator.GenerateFullQuery(this),
\r
950 parsed.UsesPictureSettings))
\r
952 TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")
\r
954 ForeColor = Color.Black
\r
956 treeView_presets.Nodes.Add(preset_treeview);
\r
963 /// Export a plist Preset
\r
965 private void ExportPreset()
\r
967 MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
970 SaveFileDialog savefiledialog = new SaveFileDialog();
\r
971 savefiledialog.Filter = "plist|*.plist";
\r
973 if (treeView_presets.SelectedNode != null)
\r
976 if (savefiledialog.ShowDialog() == DialogResult.OK)
\r
978 Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);
\r
979 PlistPresetHandler.Export(savefiledialog.FileName, preset);
\r
989 /// Toolbar - When the Source button is clicked, Clear any DVD drives and add any available DVD drives that can be used as a source.
\r
991 /// <param name="sender">
\r
994 /// <param name="e">
\r
997 private void btn_source_Click(object sender, EventArgs e)
\r
999 // Remove old Drive Menu Items.
\r
1000 List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();
\r
1001 foreach (var item in btn_source.DropDownItems)
\r
1003 if (item.GetType() == typeof(ToolStripMenuItem))
\r
1005 ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
\r
1006 if (menuItem.Name.StartsWith("Drive"))
\r
1008 itemsToRemove.Add(menuItem);
\r
1013 foreach (ToolStripMenuItem item in itemsToRemove)
\r
1014 btn_source.DropDownItems.Remove(item);
\r
1016 Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);
\r
1017 driveInfoThread.Start();
\r
1021 /// Toolbar - Start The Encode
\r
1023 /// <param name="sender">
\r
1026 /// <param name="e">
\r
1029 private void btn_start_Click(object sender, EventArgs e)
\r
1031 if (btn_start.Text == "Stop")
\r
1033 DialogResult result;
\r
1034 if (Properties.Settings.Default.enocdeStatusInGui &&
\r
1035 !Properties.Settings.Default.showCliForInGuiEncodeStatus)
\r
1037 result = MessageBox.Show(
\r
1038 "Are you sure you wish to cancel the encode?\n\nPlease note, when 'Enable in-GUI encode status' is enabled, stopping this encode will render the file unplayable. ",
\r
1039 "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1043 result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?",
\r
1044 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1047 if (result == DialogResult.Yes)
\r
1049 // Pause The Queue
\r
1050 encodeQueue.Pause();
\r
1052 if (Settings.Default.enocdeStatusInGui && !Settings.Default.showCliForInGuiEncodeStatus)
\r
1054 encodeQueue.Stop();
\r
1058 encodeQueue.SafelyClose();
\r
1064 // If we have a custom query, then we'll want to figure out what the new source and destination is, otherwise we'll just use the gui components.
\r
1065 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1066 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1068 if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))
\r
1070 string generatedQuery = QueryGenerator.GenerateFullQuery(this);
\r
1071 string specifiedQuery = rtf_query.Text != string.Empty
\r
1073 : QueryGenerator.GenerateFullQuery(this);
\r
1074 string query = string.Empty;
\r
1076 // Check to make sure the generated query matches the GUI settings
\r
1077 if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) &&
\r
1078 generatedQuery != specifiedQuery)
\r
1080 DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " +
\r
1081 "does not match the current GUI settings.\n\nBecause the manual query takes " +
\r
1082 "priority over the GUI, your recently updated settings will not be taken " +
\r
1083 "into account when encoding this job." +
\r
1084 Environment.NewLine + Environment.NewLine +
\r
1085 "Do you want to replace the manual query with the updated GUI-generated query?",
\r
1086 "Manual Query does not Match GUI",
\r
1087 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,
\r
1088 MessageBoxDefaultButton.Button3);
\r
1092 case DialogResult.Yes:
\r
1093 // Replace the manual query with the generated one
\r
1094 query = generatedQuery;
\r
1095 rtf_query.Text = generatedQuery;
\r
1097 case DialogResult.No:
\r
1098 // Use the manual query
\r
1099 query = specifiedQuery;
\r
1101 case DialogResult.Cancel:
\r
1102 // Don't start the encode
\r
1108 query = specifiedQuery;
\r
1111 DialogResult overwrite = DialogResult.Yes;
\r
1112 if (!string.IsNullOrEmpty(jobDestination) && File.Exists(jobDestination))
\r
1114 overwrite = MessageBox.Show(
\r
1115 "The destination file already exists. Are you sure you want to overwrite it?",
\r
1116 "Overwrite File?",
\r
1117 MessageBoxButtons.YesNo,
\r
1118 MessageBoxIcon.Question);
\r
1121 if (overwrite == DialogResult.Yes)
\r
1123 if (encodeQueue.Count == 0)
\r
1124 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1126 queueWindow.SetQueue();
\r
1127 if (encodeQueue.Count > 1)
\r
1128 queueWindow.Show(false);
\r
1130 SetEncodeStarted(); // Encode is running, so setup the GUI appropriately
\r
1131 encodeQueue.Start(); // Start The Queue Encoding Process
\r
1136 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1137 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1138 MessageBoxIcon.Warning);
\r
1143 /// Toolbar - Add the current job to the Queue
\r
1145 /// <param name="sender">
\r
1148 /// <param name="e">
\r
1151 private void btn_add2Queue_Click(object sender, EventArgs e)
\r
1153 // Get the CLI query or use the query editor if it's not empty.
\r
1154 string query = QueryGenerator.GenerateFullQuery(this);
\r
1155 if (!string.IsNullOrEmpty(rtf_query.Text))
\r
1156 query = rtf_query.Text;
\r
1158 // If we have a custom query, then we'll want to figure out what the new source and destination is, otherwise we'll just use the gui components.
\r
1159 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1160 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1162 // Make sure we have a Source and Destination.
\r
1163 if (string.IsNullOrEmpty(jobSourcePath) || string.IsNullOrEmpty(jobDestination))
\r
1165 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1169 // Make sure the destination path exists.
\r
1170 if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))
\r
1172 MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1176 // Make sure we don't have a duplciate on the queue.
\r
1177 if (encodeQueue.CheckForDestinationDuplicate(jobDestination))
\r
1179 DialogResult result =
\r
1181 "There is already a queue item for this destination path. \n\n If you continue, the encode will be overwritten. Do you wish to continue?",
\r
1182 "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
1183 if (result == DialogResult.Yes)
\r
1184 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1187 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1189 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";
\r
1191 queueWindow.Show();
\r
1196 /// Toolbar - Show the Queue
\r
1198 /// <param name="sender">
\r
1201 /// <param name="e">
\r
1204 private void btn_showQueue_Click(object sender, EventArgs e)
\r
1206 queueWindow.Show();
\r
1207 queueWindow.Activate();
\r
1211 /// Toolbar - Show the Preview Window
\r
1213 /// <param name="sender">
\r
1216 /// <param name="e">
\r
1219 private void tb_preview_Click(object sender, EventArgs e)
\r
1221 if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1222 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1223 MessageBoxIcon.Warning);
\r
1226 if (qtpreview == null)
\r
1228 qtpreview = new frmPreview(this);
\r
1231 else if (qtpreview.IsDisposed)
\r
1233 qtpreview = new frmPreview(this);
\r
1237 MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,
\r
1238 MessageBoxIcon.Warning);
\r
1243 /// Toolbar - Show the Activity log Window
\r
1245 /// <param name="sender">
\r
1248 /// <param name="e">
\r
1251 private void btn_ActivityWindow_Click(object sender, EventArgs e)
\r
1253 if (this.activityWindow == null || !this.activityWindow.IsHandleCreated)
\r
1254 this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
1256 this.activityWindow.Show();
\r
1257 this.activityWindow.Activate();
\r
1262 #region System Tray Icon
\r
1265 /// Handle Resizing of the main window when deaing with the Notify Icon
\r
1267 /// <param name="sender">
\r
1270 /// <param name="e">
\r
1273 private void frmMain_Resize(object sender, EventArgs e)
\r
1275 if (FormWindowState.Minimized == this.WindowState)
\r
1277 notifyIcon.Visible = true;
\r
1280 else if (FormWindowState.Normal == this.WindowState)
\r
1281 notifyIcon.Visible = false;
\r
1285 /// Double Click the Tray Icon
\r
1287 /// <param name="sender">
\r
1290 /// <param name="e">
\r
1293 private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
\r
1295 this.Visible = true;
\r
1297 this.WindowState = FormWindowState.Normal;
\r
1298 notifyIcon.Visible = false;
\r
1302 /// Tray Icon - Restore Menu Item - Resture the Window
\r
1304 /// <param name="sender">
\r
1307 /// <param name="e">
\r
1310 private void btn_restore_Click(object sender, EventArgs e)
\r
1312 this.Visible = true;
\r
1314 this.WindowState = FormWindowState.Normal;
\r
1315 notifyIcon.Visible = false;
\r
1320 #region Main Window and Tab Control
\r
1323 private void btn_dvd_source_Click(object sender, EventArgs e)
\r
1325 if (DVD_Open.ShowDialog() == DialogResult.OK)
\r
1327 this.selectedSourceType = SourceType.Folder;
\r
1328 SelectSource(DVD_Open.SelectedPath);
\r
1331 UpdateSourceLabel();
\r
1334 private void btn_file_source_Click(object sender, EventArgs e)
\r
1336 if (ISO_Open.ShowDialog() == DialogResult.OK)
\r
1338 this.selectedSourceType = SourceType.VideoFile;
\r
1339 SelectSource(ISO_Open.FileName);
\r
1342 UpdateSourceLabel();
\r
1345 private void mnu_dvd_drive_Click(object sender, EventArgs e)
\r
1347 ToolStripMenuItem item = sender as ToolStripMenuItem;
\r
1350 string driveId = item.Name.Replace("Drive", string.Empty);
\r
1352 if (int.TryParse(driveId, out id))
\r
1355 this.dvdDrivePath = drives[id].RootDirectory;
\r
1356 this.dvdDriveLabel = drives[id].VolumeLabel;
\r
1358 if (this.dvdDrivePath == null) return;
\r
1359 this.selectedSourceType = SourceType.DvdDrive;
\r
1360 SelectSource(this.dvdDrivePath);
\r
1365 private void SelectSource(string file)
\r
1367 Check_ChapterMarkers.Enabled = true;
\r
1368 sourcePath = string.Empty;
\r
1370 if (file == string.Empty) // Must have a file or path
\r
1372 UpdateSourceLabel();
\r
1376 sourcePath = Path.GetFileName(file);
\r
1377 StartScan(file, 0);
\r
1380 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
1382 if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))
\r
1384 "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",
\r
1385 "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
1388 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1390 UnRegisterPresetEventHandler();
\r
1391 drop_mode.SelectedIndex = 0;
\r
1393 drop_chapterStart.Items.Clear();
\r
1394 drop_chapterFinish.Items.Clear();
\r
1396 // If the dropdown is set to automatic nothing else needs to be done.
\r
1397 // Otheriwse if its not, title data has to be loaded from parsing.
\r
1398 if (drp_dvdtitle.Text != "Automatic")
\r
1400 selectedTitle = drp_dvdtitle.SelectedItem as Title;
\r
1401 lbl_duration.Text = selectedTitle.Duration.ToString();
\r
1402 PictureSettings.CurrentlySelectedPreset = this.currentlySelectedPreset;
\r
1403 PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control
\r
1405 // Populate the Angles dropdown
\r
1406 drop_angle.Items.Clear();
\r
1407 if (!Properties.Settings.Default.noDvdNav)
\r
1409 drop_angle.Visible = true;
\r
1410 lbl_angle.Visible = true;
\r
1412 for (int i = 1; i <= selectedTitle.AngleCount; i++)
\r
1413 drop_angle.Items.Add(i.ToString());
\r
1415 if (drop_angle.Items.Count != 0)
\r
1416 drop_angle.SelectedIndex = 0;
\r
1420 drop_angle.Visible = false;
\r
1421 lbl_angle.Visible = false;
\r
1424 // Populate the Start chapter Dropdown
\r
1425 drop_chapterStart.Items.Clear();
\r
1426 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1427 if (drop_chapterStart.Items.Count > 0)
\r
1428 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
1430 // Populate the Final Chapter Dropdown
\r
1431 drop_chapterFinish.Items.Clear();
\r
1432 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1433 if (drop_chapterFinish.Items.Count > 0)
\r
1434 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
1436 // Populate the Audio Channels Dropdown
\r
1437 AudioSettings.SetTrackList(selectedTitle, this.currentlySelectedPreset);
\r
1439 // Populate the Subtitles dropdown
\r
1440 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());
\r
1442 // Update the source label if we have multiple streams
\r
1443 if (selectedTitle != null)
\r
1444 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
1445 labelSource.Text = labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
1447 // Run the AutoName & ChapterNaming functions
\r
1448 if (Properties.Settings.Default.autoNaming)
\r
1450 string autoPath = Main.AutoName(this);
\r
1451 if (autoPath != null)
\r
1452 text_destination.Text = autoPath;
\r
1455 "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'General' Tab -> 'Default Path')",
\r
1456 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1459 data_chpt.Rows.Clear();
\r
1460 if (selectedTitle.Chapters.Count != 1)
\r
1462 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1463 if (chapterGridView != null)
\r
1464 data_chpt = chapterGridView;
\r
1468 Check_ChapterMarkers.Checked = false;
\r
1469 Check_ChapterMarkers.Enabled = false;
\r
1472 // Hack to force the redraw of the scrollbars which don't resize properly when the control is disabled.
\r
1473 data_chpt.Columns[0].Width = 166;
\r
1474 data_chpt.Columns[0].Width = 165;
\r
1476 RegisterPresetEventHandler();
\r
1479 private void chapersChanged(object sender, EventArgs e)
\r
1481 if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.
\r
1484 Control ctl = (Control)sender;
\r
1485 int chapterStart, chapterEnd;
\r
1486 int.TryParse(drop_chapterStart.Text, out chapterStart);
\r
1487 int.TryParse(drop_chapterFinish.Text, out chapterEnd);
\r
1491 case "drop_chapterStart":
\r
1492 if (drop_chapterFinish.SelectedIndex == -1 && drop_chapterFinish.Items.Count != 0)
\r
1493 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1495 if (chapterEnd != 0)
\r
1496 if (chapterStart > chapterEnd)
\r
1497 drop_chapterFinish.Text = chapterStart.ToString();
\r
1499 case "drop_chapterFinish":
\r
1500 if (drop_chapterStart.Items.Count >= 1 && drop_chapterStart.SelectedIndex == -1)
\r
1501 drop_chapterStart.SelectedIndex = 0;
\r
1503 if (chapterStart != 0)
\r
1504 if (chapterEnd < chapterStart)
\r
1505 drop_chapterFinish.Text = chapterStart.ToString();
\r
1507 // Add more rows to the Chapter menu if needed.
\r
1508 if (Check_ChapterMarkers.Checked)
\r
1510 int i = data_chpt.Rows.Count, finish = 0;
\r
1511 int.TryParse(drop_chapterFinish.Text, out finish);
\r
1513 while (i < finish)
\r
1515 int n = data_chpt.Rows.Add();
\r
1516 data_chpt.Rows[n].Cells[0].Value = (i + 1);
\r
1517 data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
\r
1518 data_chpt.Rows[n].Cells[0].ValueType = typeof(int);
\r
1519 data_chpt.Rows[n].Cells[1].ValueType = typeof(string);
\r
1526 // Update the Duration
\r
1527 lbl_duration.Text =
\r
1528 Main.CalculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle)
\r
1531 // Run the Autonaming function
\r
1532 if (Properties.Settings.Default.autoNaming)
\r
1533 text_destination.Text = Main.AutoName(this);
\r
1535 // Disable chapter markers if only 1 chapter is selected.
\r
1536 if (chapterStart == chapterEnd)
\r
1538 Check_ChapterMarkers.Enabled = false;
\r
1539 btn_importChapters.Enabled = false;
\r
1540 data_chpt.Enabled = false;
\r
1544 Check_ChapterMarkers.Enabled = true;
\r
1545 if (Check_ChapterMarkers.Checked)
\r
1547 btn_importChapters.Enabled = true;
\r
1548 data_chpt.Enabled = true;
\r
1553 private void SecondsOrFramesChanged(object sender, EventArgs e)
\r
1556 int.TryParse(drop_chapterStart.Text, out start);
\r
1557 int.TryParse(drop_chapterFinish.Text, out end);
\r
1558 double duration = end - start;
\r
1560 switch (drop_mode.SelectedIndex)
\r
1563 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1566 if (selectedTitle != null)
\r
1568 duration = duration / selectedTitle.Fps;
\r
1569 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1572 lbl_duration.Text = "--:--:--";
\r
1578 private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)
\r
1581 this.drop_chapterFinish.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1582 this.drop_chapterStart.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1585 switch (drop_mode.SelectedIndex)
\r
1588 drop_chapterStart.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1589 drop_chapterFinish.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1590 if (drop_chapterStart.Items.Count != 0)
\r
1592 drop_chapterStart.SelectedIndex = 0;
\r
1593 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1596 lbl_duration.Text = "--:--:--";
\r
1599 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1600 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1601 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1602 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1603 if (selectedTitle != null)
\r
1605 drop_chapterStart.Text = "0";
\r
1606 drop_chapterFinish.Text = selectedTitle.Duration.TotalSeconds.ToString();
\r
1610 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1611 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1612 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1613 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1614 if (selectedTitle != null)
\r
1616 drop_chapterStart.Text = "0";
\r
1617 drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();
\r
1624 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
1626 // This removes the file extension from the filename box on the save file dialog.
\r
1627 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
1628 DVD_Save.FileName = Path.GetFileNameWithoutExtension(text_destination.Text);
\r
1630 if (Path.IsPathRooted(text_destination.Text))
\r
1631 DVD_Save.InitialDirectory = Path.GetDirectoryName(text_destination.Text);
\r
1633 // Show the dialog and set the main form file path
\r
1634 if (drop_format.SelectedIndex.Equals(0))
\r
1635 DVD_Save.FilterIndex = 1;
\r
1636 else if (drop_format.SelectedIndex.Equals(1))
\r
1637 DVD_Save.FilterIndex = 2;
\r
1639 if (DVD_Save.ShowDialog() == DialogResult.OK)
\r
1641 // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames
\r
1642 switch (DVD_Save.FilterIndex)
\r
1646 !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",
\r
1647 StringComparison.InvariantCultureIgnoreCase))
\r
1648 if (Properties.Settings.Default.useM4v)
\r
1649 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");
\r
1651 DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");
\r
1655 !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))
\r
1656 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");
\r
1662 text_destination.Text = DVD_Save.FileName;
\r
1664 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
1665 if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)
\r
1666 SetExtension(".m4v");
\r
1670 private void text_destination_TextChanged(object sender, EventArgs e)
\r
1672 string path = text_destination.Text;
\r
1673 if (path.EndsWith(".mp4") || path.EndsWith(".m4v"))
\r
1674 drop_format.SelectedIndex = 0;
\r
1675 else if (path.EndsWith(".mkv"))
\r
1676 drop_format.SelectedIndex = 1;
\r
1679 // Output Settings
\r
1680 private void drop_format_SelectedIndexChanged(object sender, EventArgs e)
\r
1682 switch (drop_format.SelectedIndex)
\r
1685 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||
\r
1686 AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())
\r
1687 SetExtension(".m4v");
\r
1689 SetExtension(".mp4");
\r
1692 SetExtension(".mkv");
\r
1696 AudioSettings.SetContainer(drop_format.Text);
\r
1698 if (drop_format.Text.Contains("MP4"))
\r
1700 if (drp_videoEncoder.Items.Contains("VP3 (Theora)"))
\r
1702 drp_videoEncoder.Items.Remove("VP3 (Theora)");
\r
1703 drp_videoEncoder.SelectedIndex = 1;
\r
1706 else if (drop_format.Text.Contains("MKV"))
\r
1707 drp_videoEncoder.Items.Add("VP3 (Theora)");
\r
1710 public void SetExtension(string newExtension)
\r
1712 if (newExtension == ".mp4" || newExtension == ".m4v")
\r
1713 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||
\r
1714 Subtitles.RequiresM4V())
\r
1715 newExtension = ".m4v";
\r
1717 newExtension = ".mp4";
\r
1719 if (Path.HasExtension(newExtension))
\r
1720 text_destination.Text = Path.ChangeExtension(text_destination.Text, newExtension);
\r
1724 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
1726 setContainerOpts();
\r
1728 // Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
1729 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1731 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
1732 check_turbo.Enabled = true;
\r
1734 tab_advanced.Enabled = true;
\r
1735 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1736 check_iPodAtom.Enabled = true;
\r
1738 check_iPodAtom.Enabled = false;
\r
1742 check_turbo.CheckState = CheckState.Unchecked;
\r
1743 check_turbo.Enabled = false;
\r
1744 tab_advanced.Enabled = false;
\r
1745 x264Panel.X264Query = string.Empty;
\r
1746 check_iPodAtom.Enabled = false;
\r
1747 check_iPodAtom.Checked = false;
\r
1750 // Setup the CQ Slider
\r
1751 switch (drp_videoEncoder.Text)
\r
1753 case "MPEG-4 (FFmpeg)":
\r
1754 if (slider_videoQuality.Value > 31)
\r
1755 slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.
\r
1756 slider_videoQuality.Minimum = 1;
\r
1757 slider_videoQuality.Maximum = 31;
\r
1759 case "H.264 (x264)":
\r
1760 slider_videoQuality.Minimum = 0;
\r
1761 slider_videoQuality.TickFrequency = 1;
\r
1763 CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
\r
1764 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1765 double multiplier = 1.0 / cqStep;
\r
1766 double value = slider_videoQuality.Value * multiplier;
\r
1768 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1770 if (value < slider_videoQuality.Maximum)
\r
1771 slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;
\r
1774 case "VP3 (Theora)":
\r
1775 if (slider_videoQuality.Value > 63)
\r
1776 slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.
\r
1777 slider_videoQuality.Minimum = 0;
\r
1778 slider_videoQuality.Maximum = 63;
\r
1784 /// When the FrameRate is not Same As Source, show the Max/Constant Mode dropdown
\r
1786 /// <param name="sender">
\r
1789 /// <param name="e">
\r
1792 private void drp_videoFramerate_SelectedIndexChanged(object sender, EventArgs e)
\r
1794 if (this.drp_videoFramerate.SelectedIndex == 0)
\r
1796 this.checkMaximumFramerate.Visible = false;
\r
1797 this.checkMaximumFramerate.CheckState = CheckState.Unchecked;
\r
1801 this.checkMaximumFramerate.Visible = true;
\r
1806 /// Set the container format options
\r
1808 public void setContainerOpts()
\r
1810 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1812 check_largeFile.Enabled = true;
\r
1813 check_optimiseMP4.Enabled = true;
\r
1814 check_iPodAtom.Enabled = true;
\r
1818 check_largeFile.Enabled = false;
\r
1819 check_optimiseMP4.Enabled = false;
\r
1820 check_iPodAtom.Enabled = false;
\r
1821 check_largeFile.Checked = false;
\r
1822 check_optimiseMP4.Checked = false;
\r
1823 check_iPodAtom.Checked = false;
\r
1827 private double _cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1830 /// Update the CQ slider for x264 for a new CQ step. This is set from option
\r
1832 public void setQualityFromSlider()
\r
1834 // Work out the current RF value.
\r
1835 double cqStep = _cachedCqStep;
\r
1836 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1838 // Change the maximum value for the slider
\r
1839 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1841 // Reset the CQ slider to RF0
\r
1842 slider_videoQuality.Value = slider_videoQuality.Maximum;
\r
1844 // Reset the CQ slider back to the previous value as close as possible
\r
1845 double cqStepNew = Properties.Settings.Default.x264cqstep;
\r
1846 double rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1847 while (rfValueCurrent < rfValue)
\r
1849 slider_videoQuality.Value--;
\r
1850 rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1853 // Cache the CQ step for the next calculation
\r
1854 _cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1857 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
1859 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1860 switch (drp_videoEncoder.Text)
\r
1862 case "MPEG-4 (FFmpeg)":
\r
1863 lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);
\r
1865 case "H.264 (x264)":
\r
1866 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1867 rfValue = Math.Round(rfValue, 2);
\r
1868 lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));
\r
1870 case "VP3 (Theora)":
\r
1871 lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;
\r
1876 private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)
\r
1878 text_bitrate.Enabled = false;
\r
1879 text_filesize.Enabled = true;
\r
1880 slider_videoQuality.Enabled = false;
\r
1882 check_2PassEncode.Enabled = true;
\r
1885 private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)
\r
1887 text_bitrate.Enabled = true;
\r
1888 text_filesize.Enabled = false;
\r
1889 slider_videoQuality.Enabled = false;
\r
1891 check_2PassEncode.Enabled = true;
\r
1894 private void radio_cq_CheckedChanged(object sender, EventArgs e)
\r
1896 text_bitrate.Enabled = false;
\r
1897 text_filesize.Enabled = false;
\r
1898 slider_videoQuality.Enabled = true;
\r
1900 check_2PassEncode.Enabled = false;
\r
1901 check_2PassEncode.CheckState = CheckState.Unchecked;
\r
1904 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
1906 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
1908 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1909 check_turbo.Enabled = true;
\r
1913 check_turbo.Enabled = false;
\r
1914 check_turbo.CheckState = CheckState.Unchecked;
\r
1918 // Chapter Marker Tab
\r
1919 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
1921 if (Check_ChapterMarkers.Checked)
\r
1923 if (drop_format.SelectedIndex != 1)
\r
1924 SetExtension(".m4v");
\r
1925 data_chpt.Enabled = true;
\r
1926 btn_importChapters.Enabled = true;
\r
1930 if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v)
\r
1931 SetExtension(".mp4");
\r
1932 data_chpt.Enabled = false;
\r
1933 btn_importChapters.Enabled = false;
\r
1937 private void btn_importChapters_Click(object sender, EventArgs e)
\r
1939 if (File_ChapterImport.ShowDialog() == DialogResult.OK)
\r
1941 string filename = File_ChapterImport.FileName;
\r
1942 DataGridView imported = Main.ImportChapterNames(data_chpt, filename);
\r
1943 if (imported != null)
\r
1944 data_chpt = imported;
\r
1948 private void btn_export_Click(object sender, EventArgs e)
\r
1950 SaveFileDialog saveFileDialog = new SaveFileDialog();
\r
1951 saveFileDialog.Filter = "Csv File|*.csv";
\r
1952 saveFileDialog.DefaultExt = "csv";
\r
1953 if (saveFileDialog.ShowDialog() == DialogResult.OK)
\r
1955 string filename = saveFileDialog.FileName;
\r
1957 Main.SaveChapterMarkersToCsv(this, filename);
\r
1961 private void mnu_resetChapters_Click(object sender, EventArgs e)
\r
1963 data_chpt.Rows.Clear();
\r
1964 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1965 if (chapterGridView != null)
\r
1967 data_chpt = chapterGridView;
\r
1971 // Query Editor Tab
\r
1972 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
1974 rtf_query.Text = QueryGenerator.GenerateFullQuery(this);
\r
1977 private void btn_clear_Click(object sender, EventArgs e)
\r
1979 rtf_query.Clear();
\r
1984 // MainWindow Components, Actions and Functions ***********************
\r
1986 #region Source Scan
\r
1989 /// Start the Scan Process
\r
1991 /// <param name="filename">
\r
1994 /// <param name="title">
\r
1997 private void StartScan(string filename, int title)
\r
1999 // Setup the GUI components for the scan.
\r
2000 sourcePath = filename;
\r
2002 this.DisableGUI();
\r
2007 SourceScan.Scan(sourcePath, title);
\r
2008 SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);
\r
2009 SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);
\r
2011 catch (Exception exc)
\r
2013 MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2018 /// Update the Status label for the scan
\r
2020 /// <param name="sender">
\r
2023 /// <param name="e">
\r
2026 private void SourceScan_ScanStatusChanged(object sender, EventArgs e)
\r
2028 UpdateScanStatusLabel();
\r
2032 /// Update the UI after the scan has completed
\r
2034 /// <param name="sender">
\r
2037 /// <param name="e">
\r
2040 private void SourceScan_ScanCompleted(object sender, EventArgs e)
\r
2042 UpdateGuiAfterScan();
\r
2046 /// Update the Scan Status Label
\r
2048 private void UpdateScanStatusLabel()
\r
2050 if (InvokeRequired)
\r
2052 BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));
\r
2055 lbl_encode.Text = SourceScan.ScanStatus;
\r
2059 /// Reset the GUI when the scan has completed
\r
2061 private void UpdateGuiAfterScan()
\r
2063 if (InvokeRequired)
\r
2065 BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));
\r
2071 currentSource = SourceScan.SouceData;
\r
2073 // Setup some GUI components
\r
2074 drp_dvdtitle.Items.Clear();
\r
2075 if (currentSource.Titles.Count != 0)
\r
2076 drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());
\r
2078 foreach (Title title in currentSource.Titles)
\r
2080 if (title.MainTitle)
\r
2082 drp_dvdtitle.SelectedItem = title;
\r
2086 if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)
\r
2088 drp_dvdtitle.SelectedIndex = 0;
\r
2091 // Enable the creation of chapter markers if the file is an image of a dvd
\r
2092 if (drop_chapterStart.Items.Count > 0)
\r
2095 int.TryParse(drop_chapterStart.Items[0].ToString(), out start);
\r
2096 int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);
\r
2097 if (end > start) Check_ChapterMarkers.Enabled = true;
\r
2100 Check_ChapterMarkers.Enabled = false;
\r
2101 Check_ChapterMarkers.Checked = false;
\r
2102 data_chpt.Rows.Clear();
\r
2106 // If no titles were found, Display an error message
\r
2107 if (drp_dvdtitle.Items.Count == 0)
\r
2110 "No Title(s) found. \n\nYour Source may be copy protected, badly mastered or in a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).",
\r
2111 "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
2112 sourcePath = string.Empty;
\r
2114 UpdateSourceLabel();
\r
2116 // Enable the GUI components and enable any disabled components
\r
2119 catch (Exception exc)
\r
2121 MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,
\r
2122 MessageBoxIcon.Error);
\r
2128 /// Enable the GUI
\r
2130 private void EnableGUI()
\r
2134 if (InvokeRequired)
\r
2135 BeginInvoke(new UpdateWindowHandler(EnableGUI));
\r
2136 lbl_encode.Text = "Scan Completed";
\r
2137 foreach (Control ctrl in Controls)
\r
2138 ctrl.Enabled = true;
\r
2139 btn_start.Enabled = true;
\r
2140 btn_showQueue.Enabled = true;
\r
2141 btn_add2Queue.Enabled = true;
\r
2142 tb_preview.Enabled = true;
\r
2143 btn_source.Enabled = true;
\r
2144 mnu_killCLI.Visible = false;
\r
2146 catch (Exception exc)
\r
2148 MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2153 /// Disable the GUI
\r
2155 private void DisableGUI()
\r
2157 foreach (Control ctrl in Controls)
\r
2158 if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))
\r
2159 ctrl.Enabled = false;
\r
2161 lbl_encode.Visible = true;
\r
2162 lbl_encode.Text = "Scanning ...";
\r
2163 btn_source.Enabled = false;
\r
2164 btn_start.Enabled = false;
\r
2165 btn_showQueue.Enabled = false;
\r
2166 btn_add2Queue.Enabled = false;
\r
2167 tb_preview.Enabled = false;
\r
2168 mnu_killCLI.Visible = true;
\r
2174 private void KillScan()
\r
2176 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2180 SourceScan.Stop();
\r
2182 lbl_encode.Text = "Scan Cancelled!";
\r
2188 private void ResetGUI()
\r
2190 drp_dvdtitle.Items.Clear();
\r
2191 drop_chapterStart.Items.Clear();
\r
2192 drop_chapterFinish.Items.Clear();
\r
2193 lbl_duration.Text = "Select a Title";
\r
2194 PictureSettings.lbl_src_res.Text = "Select a Title";
\r
2195 sourcePath = String.Empty;
\r
2196 text_destination.Text = String.Empty;
\r
2197 selectedTitle = null;
\r
2201 /// Update the Source Label
\r
2203 private void UpdateSourceLabel()
\r
2205 labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;
\r
2207 if (selectedTitle != null)
\r
2208 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
2209 // If it's one of multiple source files, make sure we don't use the folder name
\r
2210 labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
2214 /// Take a job from the Queue, rescan it, and reload the GUI for that job.
\r
2216 /// <param name="job">
\r
2219 public void RecievingJob(Job job)
\r
2221 string query = job.Query;
\r
2222 StartScan(job.Source, job.Title);
\r
2224 if (query != null)
\r
2226 // Ok, Reset all the H264 widgets before changing the preset
\r
2227 x264Panel.Reset2Defaults();
\r
2229 // Send the query from the file to the Query Parser class
\r
2230 QueryParser presetQuery = QueryParser.Parse(query);
\r
2232 // Now load the preset
\r
2233 PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue");
\r
2235 // The x264 widgets will need updated, so do this now:
\r
2236 x264Panel.StandardizeOptString();
\r
2237 x264Panel.SetCurrentSettingsInPanel();
\r
2239 // Finally, let this window have a copy of the preset settings.
\r
2240 this.currentlySelectedPreset = null;
\r
2241 PictureSettings.SetPresetCropWarningLabel(null);
\r
2247 #region GUI Functions and Actions
\r
2250 /// Set the GUI to it's finished encoding state.
\r
2252 private void SetEncodeFinished()
\r
2256 if (InvokeRequired)
\r
2258 BeginInvoke(new UpdateWindowHandler(SetEncodeFinished));
\r
2262 lbl_encode.Text = "Encoding Finished";
\r
2263 ProgressBarStatus.Visible = false;
\r
2264 btn_start.Text = "Start";
\r
2265 btn_start.ToolTipText = "Start the encoding process";
\r
2266 btn_start.Image = Properties.Resources.Play;
\r
2268 // If the window is minimized, display the notification in a popup.
\r
2269 if (Properties.Settings.Default.trayIconAlerts)
\r
2270 if (FormWindowState.Minimized == this.WindowState)
\r
2272 notifyIcon.BalloonTipText = lbl_encode.Text;
\r
2273 notifyIcon.ShowBalloonTip(500);
\r
2276 catch (Exception exc)
\r
2278 MessageBox.Show(exc.ToString());
\r
2283 /// Set the GUI to it's started encoding state.
\r
2285 private void SetEncodeStarted()
\r
2289 if (InvokeRequired)
\r
2291 BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));
\r
2294 lbl_encode.Visible = true;
\r
2295 ProgressBarStatus.Value = 0;
\r
2296 ProgressBarStatus.Visible = true;
\r
2297 lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";
\r
2298 btn_start.Text = "Stop";
\r
2299 btn_start.ToolTipText = "Stop the encoding process.";
\r
2300 btn_start.Image = Properties.Resources.stop;
\r
2302 catch (Exception exc)
\r
2304 MessageBox.Show(exc.ToString());
\r
2309 /// Display the Encode Status
\r
2311 /// <param name="sender">
\r
2314 /// <param name="e">
\r
2317 private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)
\r
2319 if (this.InvokeRequired)
\r
2321 this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });
\r
2327 "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}",
\r
2328 e.PercentComplete,
\r
2329 e.CurrentFrameRate,
\r
2330 e.AverageFrameRate,
\r
2331 e.EstimatedTimeLeft);
\r
2333 ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);
\r
2337 /// Set the DVD Drive selection in the "Source" Menu
\r
2339 private void SetDriveSelectionMenuItem()
\r
2343 if (InvokeRequired)
\r
2345 BeginInvoke(new UpdateWindowHandler(SetDriveSelectionMenuItem));
\r
2349 drives = Main.GetDrives();
\r
2351 List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
\r
2352 foreach (DriveInformation drive in drives)
\r
2354 ToolStripMenuItem menuItem = new ToolStripMenuItem
\r
2356 Name = drive.ToString(),
\r
2357 Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",
\r
2358 Image = Resources.disc_small
\r
2360 menuItem.Click += new EventHandler(mnu_dvd_drive_Click);
\r
2361 menuItems.Add(menuItem);
\r
2364 foreach (ToolStripMenuItem item in menuItems)
\r
2365 btn_source.DropDownItems.Add(item);
\r
2367 catch (Exception exc)
\r
2369 MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);
\r
2374 /// Access the preset Handler and setup the preset panel.
\r
2376 private void LoadPresetPanel()
\r
2378 if (presetHandler.CheckIfPresetsAreOutOfDate())
\r
2379 if (!Properties.Settings.Default.presetNotification)
\r
2380 MessageBox.Show(splash,
\r
2381 "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",
\r
2382 "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
2384 presetHandler.GetPresetPanel(ref treeView_presets);
\r
2385 treeView_presets.Update();
\r
2389 /// Get the title from the selected item in the title dropdown.
\r
2394 private int GetTitle()
\r
2397 if (drp_dvdtitle.SelectedItem != null)
\r
2399 string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');
\r
2400 int.TryParse(titleInfo[0], out title);
\r
2407 /// Handle the Update Check Finishing.
\r
2409 /// <param name="result">
\r
2412 private void UpdateCheckDoneMenu(IAsyncResult result)
\r
2414 // Make sure it's running on the calling thread
\r
2415 if (InvokeRequired)
\r
2417 Invoke(new MethodInvoker(() => this.UpdateCheckDoneMenu(result)));
\r
2420 UpdateCheckInformation info;
\r
2423 // Get the information about the new build, if any, and close the window
\r
2424 info = Main.EndCheckForUpdates(result);
\r
2426 if (info.NewVersionAvailable && info.BuildInformation != null)
\r
2428 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
2429 updateWindow.ShowDialog();
\r
2432 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,
\r
2433 MessageBoxIcon.Information);
\r
2434 lbl_updateCheck.Visible = false;
\r
2437 catch (Exception ex)
\r
2439 if ((bool)result.AsyncState)
\r
2441 "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,
\r
2442 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2451 /// Handle GUI shortcuts
\r
2453 /// <param name="msg">Message</param>
\r
2454 /// <param name="keyData">Keys</param>
\r
2455 /// <returns>Bool</returns>
\r
2456 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
2458 if (keyData == (Keys.Control | Keys.S))
\r
2460 btn_start_Click(this, new EventArgs());
\r
2464 if (keyData == (Keys.Control | Keys.A))
\r
2466 btn_add2Queue_Click(this, new EventArgs());
\r
2469 return base.ProcessCmdKey(ref msg, keyData);
\r
2473 /// If the queue is being processed, prompt the user to confirm application close.
\r
2475 /// <param name="e">FormClosingEventArgs</param>
\r
2476 protected override void OnFormClosing(FormClosingEventArgs e)
\r
2478 // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.
\r
2479 if (encodeQueue.IsEncoding)
\r
2481 DialogResult result =
\r
2483 "HandBrake has queue items to process. Closing HandBrake will stop the current encoding.\n\nDo you want to close HandBrake?",
\r
2484 "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
2486 if (result == DialogResult.No)
\r
2492 // Try to safely close out if we can, or kill the cli if using in-gui status
\r
2493 if (Settings.Default.enocdeStatusInGui)
\r
2494 encodeQueue.Stop();
\r
2496 encodeQueue.SafelyClose();
\r
2499 if (SourceScan.IsScanning)
\r
2501 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2502 SourceScan.Stop();
\r
2504 base.OnFormClosing(e);
\r
2509 // This is the END of the road ****************************************
\r