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.Functions;
\r
21 using HandBrake.ApplicationServices.Model;
\r
22 using HandBrake.ApplicationServices.Parsing;
\r
23 using HandBrake.ApplicationServices.Services;
\r
24 using HandBrake.ApplicationServices.Services.Interfaces;
\r
30 using Main = Handbrake.Functions.Main;
\r
35 public partial class frmMain : Form
\r
37 // Objects which may be used by one or more other objects *************
\r
38 private IQueue encodeQueue = new Queue();
\r
39 private PresetsHandler presetHandler = new PresetsHandler();
\r
41 // Windows ************************************************************
\r
42 private frmQueue queueWindow;
\r
43 private frmPreview qtpreview;
\r
44 private frmActivityWindow activityWindow;
\r
46 // Globals: Mainly used for tracking. *********************************
\r
47 public Title selectedTitle;
\r
48 public string sourcePath;
\r
49 private SourceType selectedSourceType;
\r
50 private string dvdDrivePath;
\r
51 private string dvdDriveLabel;
\r
52 private Preset currentlySelectedPreset;
\r
53 private DVD currentSource;
\r
54 private IScan SourceScan = new ScanService();
\r
55 private List<DriveInformation> drives;
\r
57 // Delegates **********************************************************
\r
58 private delegate void UpdateWindowHandler();
\r
60 // Applicaiton Startup ************************************************
\r
65 /// Gets SourceName.
\r
67 public string SourceName
\r
71 if (this.selectedSourceType == SourceType.DvdDrive)
\r
73 return this.dvdDriveLabel;
\r
76 if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")
\r
77 return Path.GetFileNameWithoutExtension(this.sourcePath);
\r
79 return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));
\r
85 #region Application Startup
\r
88 /// Initializes a new instance of the <see cref="frmMain"/> class.
\r
90 /// <param name="args">
\r
91 /// The arguments passed in on application startup.
\r
93 public frmMain(string[] args)
\r
95 InitializeComponent();
\r
97 // Update the users config file with the CLI version data.
\r
98 Main.SetCliVersionData();
\r
99 Main.CheckForValidCliVersion();
\r
101 if (Settings.Default.hb_version.Contains("svn"))
\r
103 this.Text += " " + Settings.Default.hb_version;
\r
106 // Check for new versions, if update checking is enabled
\r
107 if (Settings.Default.updateStatus)
\r
109 if (DateTime.Now.Subtract(Settings.Default.lastUpdateCheckDate).TotalDays > Properties.Settings.Default.daysBetweenUpdateCheck)
\r
111 Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false);
\r
115 // Clear the log files in the background
\r
116 if (Settings.Default.clearOldLogs)
\r
118 Thread clearLog = new Thread(Main.ClearOldLogs);
\r
122 // Setup the GUI components
\r
123 LoadPresetPanel(); // Load the Preset Panel
\r
124 treeView_presets.ExpandAll();
\r
125 lbl_encode.Text = string.Empty;
\r
126 drop_mode.SelectedIndex = 0;
\r
127 queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue
\r
128 if (!Settings.Default.QueryEditorTab)
\r
129 tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.
\r
130 if (Settings.Default.tooltipEnable)
\r
131 ToolTip.Active = true;
\r
133 // Load the user's default settings or Normal Preset
\r
134 if (Settings.Default.defaultPreset != string.Empty && presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)
\r
136 string query = presetHandler.GetPreset(Settings.Default.defaultPreset).Query;
\r
139 x264Panel.Reset2Defaults();
\r
141 QueryParser presetQuery = QueryParser.Parse(query);
\r
142 PresetLoader.LoadPreset(this, presetQuery, Settings.Default.defaultPreset);
\r
144 x264Panel.StandardizeOptString();
\r
145 x264Panel.SetCurrentSettingsInPanel();
\r
149 loadNormalPreset();
\r
151 // Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)
\r
152 GrowlCommunicator.Register();
\r
154 // Event Handlers and Queue Recovery
\r
156 Main.RecoverQueue(encodeQueue);
\r
158 // If have a file passed in via command arguemtents, check it's a file and try scanning it.
\r
159 if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0])))
\r
161 this.StartScan(args[0], 0);
\r
166 /// When the update check is done, process the results.
\r
168 /// <param name="result">IAsyncResult result</param>
\r
169 private void UpdateCheckDone(IAsyncResult result)
\r
171 if (InvokeRequired)
\r
173 Invoke(new MethodInvoker(() => UpdateCheckDone(result)));
\r
177 UpdateCheckInformation info;
\r
181 info = Main.EndCheckForUpdates(result);
\r
183 if (info.NewVersionAvailable)
\r
185 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
186 updateWindow.ShowDialog();
\r
189 catch (Exception ex)
\r
191 if ((bool)result.AsyncState)
\r
192 Main.ShowExceptiowWindow("Unable to check for updates, Please try again later.", ex.ToString());
\r
200 // Encoding Events for setting up the GUI
\r
201 private void events()
\r
203 // Handle Widget changes when preset is selected.
\r
204 RegisterPresetEventHandler();
\r
206 // Handle Window Resize
\r
207 if (Properties.Settings.Default.MainWindowMinimize)
\r
208 this.Resize += new EventHandler(frmMain_Resize);
\r
210 // Handle Encode Start / Finish / Pause
\r
211 encodeQueue.EncodeStarted += new EventHandler(encodeStarted);
\r
212 encodeQueue.EncodeEnded += new EventHandler(encodeEnded);
\r
214 // Handle a file being draged onto the GUI.
\r
215 this.DragEnter += new DragEventHandler(frmMain_DragEnter);
\r
216 this.DragDrop += new DragEventHandler(frmMain_DragDrop);
\r
219 // 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
220 private void RegisterPresetEventHandler()
\r
223 drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
224 check_largeFile.CheckedChanged += new EventHandler(changePresetLabel);
\r
225 check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel);
\r
226 check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);
\r
228 // Picture Settings
\r
229 PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);
\r
232 Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);
\r
235 drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
236 check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel);
\r
237 check_turbo.CheckedChanged += new EventHandler(changePresetLabel);
\r
238 text_filesize.TextChanged += new EventHandler(changePresetLabel);
\r
239 text_bitrate.TextChanged += new EventHandler(changePresetLabel);
\r
240 slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel);
\r
243 AudioSettings.AudioListChanged += new EventHandler(changePresetLabel);
\r
246 x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);
\r
249 private void UnRegisterPresetEventHandler()
\r
251 // Output Settings
\r
252 drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
253 check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel);
\r
254 check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel);
\r
255 check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);
\r
257 // Picture Settings
\r
258 PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);
\r
261 Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);
\r
264 drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
265 check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel);
\r
266 check_turbo.CheckedChanged -= new EventHandler(changePresetLabel);
\r
267 text_filesize.TextChanged -= new EventHandler(changePresetLabel);
\r
268 text_bitrate.TextChanged -= new EventHandler(changePresetLabel);
\r
269 slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel);
\r
272 AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel);
\r
275 x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);
\r
278 private void changePresetLabel(object sender, EventArgs e)
\r
280 labelPreset.Text = "Output Settings (Preset: Custom)";
\r
281 this.currentlySelectedPreset = null;
\r
284 private static void frmMain_DragEnter(object sender, DragEventArgs e)
\r
286 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
\r
287 e.Effect = DragDropEffects.All;
\r
290 private void frmMain_DragDrop(object sender, DragEventArgs e)
\r
292 string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
\r
293 sourcePath = string.Empty;
\r
295 if (fileList != null)
\r
297 if (!string.IsNullOrEmpty(fileList[0]))
\r
299 this.selectedSourceType = SourceType.VideoFile;
\r
300 StartScan(fileList[0], 0);
\r
303 UpdateSourceLabel();
\r
306 UpdateSourceLabel();
\r
309 private void encodeStarted(object sender, EventArgs e)
\r
311 SetEncodeStarted();
\r
312 encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;
\r
315 private void encodeEnded(object sender, EventArgs e)
\r
317 encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;
\r
318 SetEncodeFinished();
\r
322 // User Interface Menus / Tool Strips *********************************
\r
327 /// Kill The scan menu Item
\r
329 /// <param name="sender">
\r
332 /// <param name="e">
\r
335 private void mnu_killCLI_Click(object sender, EventArgs e)
\r
341 /// Exit the Application Menu Item
\r
343 /// <param name="sender">
\r
346 /// <param name="e">
\r
349 private void mnu_exit_Click(object sender, EventArgs e)
\r
351 Application.Exit();
\r
359 /// Menu - Start Button
\r
361 /// <param name="sender">
\r
364 /// <param name="e">
\r
367 private void mnu_encode_Click(object sender, EventArgs e)
\r
369 queueWindow.Show();
\r
373 /// Menu - Display the Log Window
\r
375 /// <param name="sender">
\r
378 /// <param name="e">
\r
381 private void mnu_encodeLog_Click(object sender, EventArgs e)
\r
383 this.btn_ActivityWindow_Click(this, null);
\r
387 /// Menu - Display the Options Window
\r
389 /// <param name="sender">
\r
392 /// <param name="e">
\r
395 private void mnu_options_Click(object sender, EventArgs e)
\r
397 Form options = new frmOptions(this);
\r
398 options.ShowDialog();
\r
403 #region Presets Menu
\r
406 /// Reset the Built in Presets
\r
408 /// <param name="sender">
\r
411 /// <param name="e">
\r
414 private void mnu_presetReset_Click(object sender, EventArgs e)
\r
416 presetHandler.UpdateBuiltInPresets();
\r
418 if (treeView_presets.Nodes.Count == 0)
\r
420 "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
421 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
423 MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
425 treeView_presets.ExpandAll();
\r
429 /// Delete the selected preset
\r
431 /// <param name="sender">
\r
434 /// <param name="e">
\r
437 private void mnu_delete_preset_Click(object sender, EventArgs e)
\r
439 presetHandler.RemoveBuiltInPresets();
\r
440 LoadPresetPanel(); // Reload the preset panel
\r
444 /// Select the Normal preset
\r
446 /// <param name="sender">
\r
449 /// <param name="e">
\r
452 private void mnu_SelectDefault_Click(object sender, EventArgs e)
\r
454 loadNormalPreset();
\r
458 /// Import a plist Preset
\r
460 /// <param name="sender">
\r
463 /// <param name="e">
\r
466 private void mnu_importMacPreset_Click(object sender, EventArgs e)
\r
472 /// Export a Plist Preset
\r
474 /// <param name="sender">
\r
477 /// <param name="e">
\r
480 private void mnu_exportMacPreset_Click(object sender, EventArgs e)
\r
486 /// Create a new Preset
\r
488 /// <param name="sender">
\r
491 /// <param name="e">
\r
494 private void btn_new_preset_Click(object sender, EventArgs e)
\r
496 Form preset = new frmAddPreset(this, presetHandler);
\r
497 if (preset.ShowDialog() == DialogResult.OK)
\r
499 TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };
\r
500 treeView_presets.Nodes.Add(presetTreeview);
\r
501 presetHandler.LastPresetAdded = null;
\r
510 /// Menu - Display the User Guide Web Page
\r
512 /// <param name="sender">
\r
515 /// <param name="e">
\r
518 private void mnu_user_guide_Click(object sender, EventArgs e)
\r
520 Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");
\r
524 /// Menu - Check for Updates
\r
526 /// <param name="sender">
\r
529 /// <param name="e">
\r
532 private void mnu_UpdateCheck_Click(object sender, EventArgs e)
\r
534 lbl_updateCheck.Visible = true;
\r
535 Main.BeginCheckForUpdates(new AsyncCallback(this.UpdateCheckDoneMenu), false);
\r
539 /// Menu - Display the About Window
\r
541 /// <param name="sender">
\r
544 /// <param name="e">
\r
547 private void mnu_about_Click(object sender, EventArgs e)
\r
549 using (frmAbout About = new frmAbout())
\r
551 About.ShowDialog();
\r
560 /// RMenu - Expand All
\r
562 /// <param name="sender">
\r
565 /// <param name="e">
\r
568 private void pmnu_expandAll_Click(object sender, EventArgs e)
\r
570 treeView_presets.ExpandAll();
\r
574 /// RMenu - Collaspe All
\r
576 /// <param name="sender">
\r
579 /// <param name="e">
\r
582 private void pmnu_collapse_Click(object sender, EventArgs e)
\r
584 treeView_presets.CollapseAll();
\r
588 /// Menu - Import Preset
\r
590 /// <param name="sender">
\r
593 /// <param name="e">
\r
596 private void pmnu_import_Click(object sender, EventArgs e)
\r
602 /// RMenu - Save Changes to Preset
\r
604 /// <param name="sender">
\r
607 /// <param name="e">
\r
610 private void pmnu_saveChanges_Click(object sender, EventArgs e)
\r
612 // TODO this requires a re-think since the Query Editor has changed.
\r
613 DialogResult result =
\r
615 "Do you wish to include picture settings when updating the preset: " +
\r
616 treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,
\r
617 MessageBoxIcon.Question);
\r
618 if (result == DialogResult.Yes)
\r
619 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
620 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);
\r
621 else if (result == DialogResult.No)
\r
622 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
623 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);
\r
627 /// RMenu - Delete Preset
\r
629 /// <param name="sender">
\r
632 /// <param name="e">
\r
635 private void pmnu_delete_click(object sender, EventArgs e)
\r
637 if (treeView_presets.SelectedNode != null)
\r
639 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
640 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
642 treeView_presets.Select();
\r
646 /// Preset Menu Is Opening. Setup the Menu
\r
648 /// <param name="sender">
\r
651 /// <param name="e">
\r
654 private void presets_menu_Opening(object sender, CancelEventArgs e)
\r
656 // Make sure that the save menu is always disabled by default
\r
657 pmnu_saveChanges.Enabled = false;
\r
659 // Now enable the save menu if the selected preset is a user preset
\r
660 if (treeView_presets.SelectedNode != null)
\r
661 if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))
\r
662 pmnu_saveChanges.Enabled = true;
\r
664 treeView_presets.Select();
\r
667 // Presets Management
\r
670 /// Button - Add a preset
\r
672 /// <param name="sender">
\r
675 /// <param name="e">
\r
678 private void btn_addPreset_Click(object sender, EventArgs e)
\r
680 Form preset = new frmAddPreset(this, presetHandler);
\r
681 if (preset.ShowDialog() == DialogResult.OK)
\r
683 TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };
\r
684 treeView_presets.Nodes.Add(presetTreeview);
\r
685 presetHandler.LastPresetAdded = null;
\r
690 /// Button - remove a Preset
\r
692 /// <param name="sender">
\r
695 /// <param name="e">
\r
698 private void btn_removePreset_Click(object sender, EventArgs e)
\r
700 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
701 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
702 if (result == DialogResult.Yes)
\r
704 if (treeView_presets.SelectedNode != null)
\r
706 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
707 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
710 treeView_presets.Select();
\r
714 /// Button - Set the selected preset as the default
\r
716 /// <param name="sender">
\r
719 /// <param name="e">
\r
722 private void btn_setDefault_Click(object sender, EventArgs e)
\r
724 if (treeView_presets.SelectedNode != null)
\r
726 DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",
\r
727 "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
728 if (result == DialogResult.Yes)
\r
730 Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;
\r
731 Properties.Settings.Default.Save();
\r
732 MessageBox.Show("New default preset set.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
736 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
740 /// PresetBar Mouse Down event
\r
742 /// <param name="sender">
\r
745 /// <param name="e">
\r
748 private void treeview_presets_mouseUp(object sender, MouseEventArgs e)
\r
750 if (e.Button == MouseButtons.Right)
\r
751 treeView_presets.SelectedNode = treeView_presets.GetNodeAt(e.Location);
\r
752 else if (e.Button == MouseButtons.Left)
\r
754 if (treeView_presets.GetNodeAt(e.Location) != null)
\r
756 if (labelPreset.Text.Contains(treeView_presets.GetNodeAt(e.Location).Text))
\r
761 treeView_presets.Select();
\r
765 /// Preset Bar after selecting the preset
\r
767 /// <param name="sender">
\r
770 /// <param name="e">
\r
773 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
779 /// Preset Bar - Handle the Delete Key
\r
781 /// <param name="sender">
\r
784 /// <param name="e">
\r
787 private void treeView_presets_deleteKey(object sender, KeyEventArgs e)
\r
789 if (e.KeyCode == Keys.Delete)
\r
791 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
792 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
793 if (result == DialogResult.Yes)
\r
795 if (treeView_presets.SelectedNode != null)
\r
796 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
798 // Remember each nodes expanded status so we can reload it
\r
799 List<bool> nodeStatus = new List<bool>();
\r
800 foreach (TreeNode node in treeView_presets.Nodes)
\r
801 nodeStatus.Add(node.IsExpanded);
\r
803 // Now reload the preset panel
\r
806 // And finally, re-expand any of the nodes if required
\r
808 foreach (TreeNode node in treeView_presets.Nodes)
\r
820 /// Select the selected preset and setup the GUI
\r
822 private void selectPreset()
\r
824 if (treeView_presets.SelectedNode != null)
\r
826 // Ok, so, we've selected a preset. Now we want to load it.
\r
827 string presetName = treeView_presets.SelectedNode.Text;
\r
828 Preset preset = presetHandler.GetPreset(presetName);
\r
829 if (preset != null)
\r
831 string query = presetHandler.GetPreset(presetName).Query;
\r
835 // Ok, Reset all the H264 widgets before changing the preset
\r
836 x264Panel.Reset2Defaults();
\r
838 // Send the query from the file to the Query Parser class
\r
839 QueryParser presetQuery = QueryParser.Parse(query);
\r
841 // Now load the preset
\r
842 PresetLoader.LoadPreset(this, presetQuery, presetName);
\r
844 // The x264 widgets will need updated, so do this now:
\r
845 x264Panel.StandardizeOptString();
\r
846 x264Panel.SetCurrentSettingsInPanel();
\r
848 // Finally, let this window have a copy of the preset settings.
\r
849 this.currentlySelectedPreset = preset;
\r
850 PictureSettings.SetPresetCropWarningLabel(preset);
\r
857 /// Load the Normal Preset
\r
859 private void loadNormalPreset()
\r
861 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
863 foreach (TreeNode node in treenode.Nodes)
\r
865 if (node.Text.Equals("Normal"))
\r
866 treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0];
\r
872 /// Import a plist preset
\r
874 private void ImportPreset()
\r
876 if (openPreset.ShowDialog() == DialogResult.OK)
\r
878 QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);
\r
879 if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))
\r
881 DialogResult result =
\r
882 MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",
\r
883 "Overwrite preset?",
\r
884 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
885 if (result == DialogResult.Yes)
\r
887 PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
\r
888 presetHandler.Update(parsed.PresetName + " (Imported)",
\r
889 QueryGenerator.GenerateFullQuery(this),
\r
890 parsed.UsesPictureSettings);
\r
895 PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
\r
896 if (presetHandler.Add(parsed.PresetName + " (Imported)",
\r
897 QueryGenerator.GenerateFullQuery(this),
\r
898 parsed.UsesPictureSettings))
\r
900 TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")
\r
902 ForeColor = Color.Black
\r
904 treeView_presets.Nodes.Add(preset_treeview);
\r
911 /// Export a plist Preset
\r
913 private void ExportPreset()
\r
915 MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
918 /*SaveFileDialog savefiledialog = new SaveFileDialog();
\r
919 savefiledialog.Filter = "plist|*.plist";
\r
921 if (treeView_presets.SelectedNode != null)
\r
924 if (savefiledialog.ShowDialog() == DialogResult.OK)
\r
926 Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);
\r
927 PlistPresetHandler.Export(savefiledialog.FileName, preset);
\r
937 /// 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
939 /// <param name="sender">
\r
942 /// <param name="e">
\r
945 private void btn_source_Click(object sender, EventArgs e)
\r
947 // Remove old Drive Menu Items.
\r
948 List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();
\r
949 foreach (var item in btn_source.DropDownItems)
\r
951 if (item.GetType() == typeof(ToolStripMenuItem))
\r
953 ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
\r
954 if (menuItem.Name.StartsWith("Drive"))
\r
956 itemsToRemove.Add(menuItem);
\r
961 foreach (ToolStripMenuItem item in itemsToRemove)
\r
962 btn_source.DropDownItems.Remove(item);
\r
964 Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);
\r
965 driveInfoThread.Start();
\r
969 /// Toolbar - Start The Encode
\r
971 /// <param name="sender">
\r
974 /// <param name="e">
\r
977 private void btn_start_Click(object sender, EventArgs e)
\r
979 if (btn_start.Text == "Stop")
\r
981 DialogResult result = !Properties.Settings.Default.showCliForInGuiEncodeStatus
\r
983 "Are you sure you wish to cancel the encode?\n\nPlease note: Stopping this encode will render the file unplayable. ",
\r
985 MessageBoxButtons.YesNo,
\r
986 MessageBoxIcon.Question)
\r
988 "Are you sure you wish to cancel the encode?",
\r
990 MessageBoxButtons.YesNo,
\r
991 MessageBoxIcon.Question);
\r
993 if (result == DialogResult.Yes)
\r
996 encodeQueue.Pause();
\r
998 if (Settings.Default.showCliForInGuiEncodeStatus)
\r
999 encodeQueue.SafelyClose();
\r
1001 encodeQueue.Stop();
\r
1006 // 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
1007 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1008 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1010 if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))
\r
1012 string generatedQuery = QueryGenerator.GenerateFullQuery(this);
\r
1013 string specifiedQuery = rtf_query.Text != string.Empty
\r
1015 : QueryGenerator.GenerateFullQuery(this);
\r
1016 string query = string.Empty;
\r
1018 // Check to make sure the generated query matches the GUI settings
\r
1019 if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) &&
\r
1020 generatedQuery != specifiedQuery)
\r
1022 DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " +
\r
1023 "does not match the current GUI settings.\n\nBecause the manual query takes " +
\r
1024 "priority over the GUI, your recently updated settings will not be taken " +
\r
1025 "into account when encoding this job." +
\r
1026 Environment.NewLine + Environment.NewLine +
\r
1027 "Do you want to replace the manual query with the updated GUI-generated query?",
\r
1028 "Manual Query does not Match GUI",
\r
1029 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,
\r
1030 MessageBoxDefaultButton.Button3);
\r
1034 case DialogResult.Yes:
\r
1035 // Replace the manual query with the generated one
\r
1036 query = generatedQuery;
\r
1037 rtf_query.Text = generatedQuery;
\r
1039 case DialogResult.No:
\r
1040 // Use the manual query
\r
1041 query = specifiedQuery;
\r
1043 case DialogResult.Cancel:
\r
1044 // Don't start the encode
\r
1050 query = specifiedQuery;
\r
1053 DialogResult overwrite = DialogResult.Yes;
\r
1054 if (!string.IsNullOrEmpty(jobDestination) && File.Exists(jobDestination))
\r
1056 overwrite = MessageBox.Show(
\r
1057 "The destination file already exists. Are you sure you want to overwrite it?",
\r
1058 "Overwrite File?",
\r
1059 MessageBoxButtons.YesNo,
\r
1060 MessageBoxIcon.Question);
\r
1063 if (overwrite == DialogResult.Yes)
\r
1065 if (encodeQueue.Count == 0)
\r
1066 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1068 queueWindow.SetQueue();
\r
1069 if (encodeQueue.Count > 1)
\r
1070 queueWindow.Show(false);
\r
1072 SetEncodeStarted(); // Encode is running, so setup the GUI appropriately
\r
1073 encodeQueue.Start(); // Start The Queue Encoding Process
\r
1078 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1079 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1080 MessageBoxIcon.Warning);
\r
1085 /// Toolbar - Add the current job to the Queue
\r
1087 /// <param name="sender">
\r
1090 /// <param name="e">
\r
1093 private void btn_add2Queue_Click(object sender, EventArgs e)
\r
1095 // Get the CLI query or use the query editor if it's not empty.
\r
1096 string query = QueryGenerator.GenerateFullQuery(this);
\r
1097 if (!string.IsNullOrEmpty(rtf_query.Text))
\r
1098 query = rtf_query.Text;
\r
1100 // 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
1101 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1102 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1104 // Make sure we have a Source and Destination.
\r
1105 if (string.IsNullOrEmpty(jobSourcePath) || string.IsNullOrEmpty(jobDestination))
\r
1107 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1111 // Make sure the destination path exists.
\r
1112 if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))
\r
1114 MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1118 // Make sure we don't have a duplciate on the queue.
\r
1119 if (encodeQueue.CheckForDestinationDuplicate(jobDestination))
\r
1121 DialogResult result =
\r
1123 "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
1124 "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
1125 if (result == DialogResult.Yes)
\r
1126 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1129 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1131 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";
\r
1133 queueWindow.Show();
\r
1137 /// Toolbar - Show the Queue
\r
1139 /// <param name="sender">
\r
1142 /// <param name="e">
\r
1145 private void btn_showQueue_Click(object sender, EventArgs e)
\r
1147 queueWindow.Show();
\r
1148 queueWindow.Activate();
\r
1152 /// Toolbar - Show the Preview Window
\r
1154 /// <param name="sender">
\r
1157 /// <param name="e">
\r
1160 private void tb_preview_Click(object sender, EventArgs e)
\r
1162 if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1163 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1164 MessageBoxIcon.Warning);
\r
1167 if (qtpreview == null)
\r
1169 qtpreview = new frmPreview(this);
\r
1172 else if (qtpreview.IsDisposed)
\r
1174 qtpreview = new frmPreview(this);
\r
1178 MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,
\r
1179 MessageBoxIcon.Warning);
\r
1184 /// Toolbar - Show the Activity log Window
\r
1186 /// <param name="sender">
\r
1189 /// <param name="e">
\r
1192 private void btn_ActivityWindow_Click(object sender, EventArgs e)
\r
1194 if (this.activityWindow == null || !this.activityWindow.IsHandleCreated)
\r
1195 this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
1197 this.activityWindow.Show();
\r
1198 this.activityWindow.Activate();
\r
1203 #region System Tray Icon
\r
1206 /// Handle Resizing of the main window when deaing with the Notify Icon
\r
1208 /// <param name="sender">
\r
1211 /// <param name="e">
\r
1214 private void frmMain_Resize(object sender, EventArgs e)
\r
1216 if (FormWindowState.Minimized == this.WindowState)
\r
1218 notifyIcon.Visible = true;
\r
1221 else if (FormWindowState.Normal == this.WindowState)
\r
1222 notifyIcon.Visible = false;
\r
1226 /// Double Click the Tray Icon
\r
1228 /// <param name="sender">
\r
1231 /// <param name="e">
\r
1234 private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
\r
1236 this.Visible = true;
\r
1238 this.WindowState = FormWindowState.Normal;
\r
1239 notifyIcon.Visible = false;
\r
1243 /// Tray Icon - Restore Menu Item - Resture the Window
\r
1245 /// <param name="sender">
\r
1248 /// <param name="e">
\r
1251 private void btn_restore_Click(object sender, EventArgs e)
\r
1253 this.Visible = true;
\r
1255 this.WindowState = FormWindowState.Normal;
\r
1256 notifyIcon.Visible = false;
\r
1261 #region Main Window and Tab Control
\r
1264 private void btn_dvd_source_Click(object sender, EventArgs e)
\r
1266 if (DVD_Open.ShowDialog() == DialogResult.OK)
\r
1268 this.selectedSourceType = SourceType.Folder;
\r
1269 SelectSource(DVD_Open.SelectedPath);
\r
1272 UpdateSourceLabel();
\r
1275 private void btn_file_source_Click(object sender, EventArgs e)
\r
1277 if (ISO_Open.ShowDialog() == DialogResult.OK)
\r
1279 this.selectedSourceType = SourceType.VideoFile;
\r
1280 SelectSource(ISO_Open.FileName);
\r
1283 UpdateSourceLabel();
\r
1286 private void mnu_dvd_drive_Click(object sender, EventArgs e)
\r
1288 ToolStripMenuItem item = sender as ToolStripMenuItem;
\r
1291 string driveId = item.Name.Replace("Drive", string.Empty);
\r
1293 if (int.TryParse(driveId, out id))
\r
1295 this.dvdDrivePath = drives[id].RootDirectory;
\r
1296 this.dvdDriveLabel = drives[id].VolumeLabel;
\r
1298 if (this.dvdDrivePath == null) return;
\r
1299 this.selectedSourceType = SourceType.DvdDrive;
\r
1300 SelectSource(this.dvdDrivePath);
\r
1305 private void SelectSource(string file)
\r
1307 Check_ChapterMarkers.Enabled = true;
\r
1308 sourcePath = string.Empty;
\r
1310 if (file == string.Empty) // Must have a file or path
\r
1312 UpdateSourceLabel();
\r
1316 sourcePath = Path.GetFileName(file);
\r
1317 StartScan(file, 0);
\r
1320 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
1322 if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))
\r
1324 "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",
\r
1325 "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
1328 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1330 UnRegisterPresetEventHandler();
\r
1331 drop_mode.SelectedIndex = 0;
\r
1333 drop_chapterStart.Items.Clear();
\r
1334 drop_chapterFinish.Items.Clear();
\r
1336 // If the dropdown is set to automatic nothing else needs to be done.
\r
1337 // Otheriwse if its not, title data has to be loaded from parsing.
\r
1338 if (drp_dvdtitle.Text != "Automatic")
\r
1340 selectedTitle = drp_dvdtitle.SelectedItem as Title;
\r
1341 lbl_duration.Text = selectedTitle.Duration.ToString();
\r
1342 PictureSettings.CurrentlySelectedPreset = this.currentlySelectedPreset;
\r
1343 PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control
\r
1345 // Populate the Angles dropdown
\r
1346 drop_angle.Items.Clear();
\r
1347 if (!Properties.Settings.Default.noDvdNav)
\r
1349 drop_angle.Visible = true;
\r
1350 lbl_angle.Visible = true;
\r
1352 for (int i = 1; i <= selectedTitle.AngleCount; i++)
\r
1353 drop_angle.Items.Add(i.ToString());
\r
1355 if (drop_angle.Items.Count != 0)
\r
1356 drop_angle.SelectedIndex = 0;
\r
1360 drop_angle.Visible = false;
\r
1361 lbl_angle.Visible = false;
\r
1364 // Populate the Start chapter Dropdown
\r
1365 drop_chapterStart.Items.Clear();
\r
1366 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1367 if (drop_chapterStart.Items.Count > 0)
\r
1368 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
1370 // Populate the Final Chapter Dropdown
\r
1371 drop_chapterFinish.Items.Clear();
\r
1372 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1373 if (drop_chapterFinish.Items.Count > 0)
\r
1374 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
1376 // Populate the Audio Channels Dropdown
\r
1377 AudioSettings.SetTrackList(selectedTitle, this.currentlySelectedPreset);
\r
1379 // Populate the Subtitles dropdown
\r
1380 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());
\r
1382 // Update the source label if we have multiple streams
\r
1383 if (selectedTitle != null)
\r
1384 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
1385 labelSource.Text = labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
1387 // Run the AutoName & ChapterNaming functions
\r
1388 if (Properties.Settings.Default.autoNaming)
\r
1390 string autoPath = Main.AutoName(this);
\r
1391 if (autoPath != null)
\r
1392 text_destination.Text = autoPath;
\r
1395 "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
1396 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1399 data_chpt.Rows.Clear();
\r
1400 if (selectedTitle.Chapters.Count != 1)
\r
1402 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1403 if (chapterGridView != null)
\r
1404 data_chpt = chapterGridView;
\r
1408 Check_ChapterMarkers.Checked = false;
\r
1409 Check_ChapterMarkers.Enabled = false;
\r
1412 // Hack to force the redraw of the scrollbars which don't resize properly when the control is disabled.
\r
1413 data_chpt.Columns[0].Width = 166;
\r
1414 data_chpt.Columns[0].Width = 165;
\r
1416 RegisterPresetEventHandler();
\r
1419 private void chapersChanged(object sender, EventArgs e)
\r
1421 if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.
\r
1424 Control ctl = (Control)sender;
\r
1425 int chapterStart, chapterEnd;
\r
1426 int.TryParse(drop_chapterStart.Text, out chapterStart);
\r
1427 int.TryParse(drop_chapterFinish.Text, out chapterEnd);
\r
1431 case "drop_chapterStart":
\r
1432 if (drop_chapterFinish.SelectedIndex == -1 && drop_chapterFinish.Items.Count != 0)
\r
1433 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1435 if (chapterEnd != 0)
\r
1436 if (chapterStart > chapterEnd)
\r
1437 drop_chapterFinish.Text = chapterStart.ToString();
\r
1439 case "drop_chapterFinish":
\r
1440 if (drop_chapterStart.Items.Count >= 1 && drop_chapterStart.SelectedIndex == -1)
\r
1441 drop_chapterStart.SelectedIndex = 0;
\r
1443 if (chapterStart != 0)
\r
1444 if (chapterEnd < chapterStart)
\r
1445 drop_chapterFinish.Text = chapterStart.ToString();
\r
1447 // Add more rows to the Chapter menu if needed.
\r
1448 if (Check_ChapterMarkers.Checked)
\r
1450 int i = data_chpt.Rows.Count, finish = 0;
\r
1451 int.TryParse(drop_chapterFinish.Text, out finish);
\r
1453 while (i < finish)
\r
1455 int n = data_chpt.Rows.Add();
\r
1456 data_chpt.Rows[n].Cells[0].Value = (i + 1);
\r
1457 data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
\r
1458 data_chpt.Rows[n].Cells[0].ValueType = typeof(int);
\r
1459 data_chpt.Rows[n].Cells[1].ValueType = typeof(string);
\r
1466 // Update the Duration
\r
1467 lbl_duration.Text =
\r
1468 Main.CalculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle)
\r
1471 // Run the Autonaming function
\r
1472 if (Properties.Settings.Default.autoNaming)
\r
1473 text_destination.Text = Main.AutoName(this);
\r
1475 // Disable chapter markers if only 1 chapter is selected.
\r
1476 if (chapterStart == chapterEnd)
\r
1478 Check_ChapterMarkers.Enabled = false;
\r
1479 btn_importChapters.Enabled = false;
\r
1480 data_chpt.Enabled = false;
\r
1484 Check_ChapterMarkers.Enabled = true;
\r
1485 if (Check_ChapterMarkers.Checked)
\r
1487 btn_importChapters.Enabled = true;
\r
1488 data_chpt.Enabled = true;
\r
1493 private void SecondsOrFramesChanged(object sender, EventArgs e)
\r
1496 int.TryParse(drop_chapterStart.Text, out start);
\r
1497 int.TryParse(drop_chapterFinish.Text, out end);
\r
1498 double duration = end - start;
\r
1500 switch (drop_mode.SelectedIndex)
\r
1503 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1506 if (selectedTitle != null)
\r
1508 duration = duration / selectedTitle.Fps;
\r
1509 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1512 lbl_duration.Text = "--:--:--";
\r
1518 private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)
\r
1521 this.drop_chapterFinish.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1522 this.drop_chapterStart.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1525 switch (drop_mode.SelectedIndex)
\r
1528 drop_chapterStart.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1529 drop_chapterFinish.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1530 if (drop_chapterStart.Items.Count != 0)
\r
1532 drop_chapterStart.SelectedIndex = 0;
\r
1533 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1536 lbl_duration.Text = "--:--:--";
\r
1539 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1540 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1541 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1542 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1543 if (selectedTitle != null)
\r
1545 drop_chapterStart.Text = "0";
\r
1546 drop_chapterFinish.Text = selectedTitle.Duration.TotalSeconds.ToString();
\r
1550 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1551 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1552 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1553 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1554 if (selectedTitle != null)
\r
1556 drop_chapterStart.Text = "0";
\r
1557 drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();
\r
1564 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
1566 // This removes the file extension from the filename box on the save file dialog.
\r
1567 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
1568 DVD_Save.FileName = Path.GetFileNameWithoutExtension(text_destination.Text);
\r
1570 if (Path.IsPathRooted(text_destination.Text))
\r
1571 DVD_Save.InitialDirectory = Path.GetDirectoryName(text_destination.Text);
\r
1573 // Show the dialog and set the main form file path
\r
1574 if (drop_format.SelectedIndex.Equals(0))
\r
1575 DVD_Save.FilterIndex = 1;
\r
1576 else if (drop_format.SelectedIndex.Equals(1))
\r
1577 DVD_Save.FilterIndex = 2;
\r
1579 if (DVD_Save.ShowDialog() == DialogResult.OK)
\r
1581 // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames
\r
1582 switch (DVD_Save.FilterIndex)
\r
1586 !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",
\r
1587 StringComparison.InvariantCultureIgnoreCase))
\r
1588 if (Properties.Settings.Default.useM4v)
\r
1589 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");
\r
1591 DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");
\r
1595 !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))
\r
1596 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");
\r
1602 text_destination.Text = DVD_Save.FileName;
\r
1604 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
1605 if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)
\r
1606 SetExtension(".m4v");
\r
1610 private void text_destination_TextChanged(object sender, EventArgs e)
\r
1612 string path = text_destination.Text;
\r
1613 if (path.EndsWith(".mp4") || path.EndsWith(".m4v"))
\r
1614 drop_format.SelectedIndex = 0;
\r
1615 else if (path.EndsWith(".mkv"))
\r
1616 drop_format.SelectedIndex = 1;
\r
1619 // Output Settings
\r
1620 private void drop_format_SelectedIndexChanged(object sender, EventArgs e)
\r
1622 switch (drop_format.SelectedIndex)
\r
1625 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||
\r
1626 AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())
\r
1627 SetExtension(".m4v");
\r
1629 SetExtension(".mp4");
\r
1632 SetExtension(".mkv");
\r
1636 AudioSettings.SetContainer(drop_format.Text);
\r
1638 if (drop_format.Text.Contains("MP4"))
\r
1640 if (drp_videoEncoder.Items.Contains("VP3 (Theora)"))
\r
1642 drp_videoEncoder.Items.Remove("VP3 (Theora)");
\r
1643 drp_videoEncoder.SelectedIndex = 1;
\r
1646 else if (drop_format.Text.Contains("MKV"))
\r
1647 drp_videoEncoder.Items.Add("VP3 (Theora)");
\r
1650 public void SetExtension(string newExtension)
\r
1652 if (newExtension == ".mp4" || newExtension == ".m4v")
\r
1653 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||
\r
1654 Subtitles.RequiresM4V())
\r
1655 newExtension = ".m4v";
\r
1657 newExtension = ".mp4";
\r
1659 if (Path.HasExtension(newExtension))
\r
1660 text_destination.Text = Path.ChangeExtension(text_destination.Text, newExtension);
\r
1664 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
1666 setContainerOpts();
\r
1668 // Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
1669 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1671 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
1672 check_turbo.Enabled = true;
\r
1674 tab_advanced.Enabled = true;
\r
1675 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1676 check_iPodAtom.Enabled = true;
\r
1678 check_iPodAtom.Enabled = false;
\r
1682 check_turbo.CheckState = CheckState.Unchecked;
\r
1683 check_turbo.Enabled = false;
\r
1684 tab_advanced.Enabled = false;
\r
1685 x264Panel.X264Query = string.Empty;
\r
1686 check_iPodAtom.Enabled = false;
\r
1687 check_iPodAtom.Checked = false;
\r
1690 // Setup the CQ Slider
\r
1691 switch (drp_videoEncoder.Text)
\r
1693 case "MPEG-4 (FFmpeg)":
\r
1694 if (slider_videoQuality.Value > 31)
\r
1695 slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.
\r
1696 slider_videoQuality.Minimum = 1;
\r
1697 slider_videoQuality.Maximum = 31;
\r
1699 case "H.264 (x264)":
\r
1700 slider_videoQuality.Minimum = 0;
\r
1701 slider_videoQuality.TickFrequency = 1;
\r
1703 CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
\r
1704 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1705 double multiplier = 1.0 / cqStep;
\r
1706 double value = slider_videoQuality.Value * multiplier;
\r
1708 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1710 if (value < slider_videoQuality.Maximum)
\r
1711 slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;
\r
1714 case "VP3 (Theora)":
\r
1715 if (slider_videoQuality.Value > 63)
\r
1716 slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.
\r
1717 slider_videoQuality.Minimum = 0;
\r
1718 slider_videoQuality.Maximum = 63;
\r
1724 /// When the FrameRate is not Same As Source, show the Max/Constant Mode dropdown
\r
1726 /// <param name="sender">
\r
1729 /// <param name="e">
\r
1732 private void drp_videoFramerate_SelectedIndexChanged(object sender, EventArgs e)
\r
1734 if (this.drp_videoFramerate.SelectedIndex == 0)
\r
1736 this.checkMaximumFramerate.Visible = false;
\r
1737 this.checkMaximumFramerate.CheckState = CheckState.Unchecked;
\r
1741 this.checkMaximumFramerate.Visible = true;
\r
1746 /// Set the container format options
\r
1748 public void setContainerOpts()
\r
1750 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1752 check_largeFile.Enabled = true;
\r
1753 check_optimiseMP4.Enabled = true;
\r
1754 check_iPodAtom.Enabled = true;
\r
1758 check_largeFile.Enabled = false;
\r
1759 check_optimiseMP4.Enabled = false;
\r
1760 check_iPodAtom.Enabled = false;
\r
1761 check_largeFile.Checked = false;
\r
1762 check_optimiseMP4.Checked = false;
\r
1763 check_iPodAtom.Checked = false;
\r
1767 private double cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1770 /// Update the CQ slider for x264 for a new CQ step. This is set from option
\r
1772 public void setQualityFromSlider()
\r
1774 // Work out the current RF value.
\r
1775 double cqStep = this.cachedCqStep;
\r
1776 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1778 // Change the maximum value for the slider
\r
1779 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1781 // Reset the CQ slider to RF0
\r
1782 slider_videoQuality.Value = slider_videoQuality.Maximum;
\r
1784 // Reset the CQ slider back to the previous value as close as possible
\r
1785 double cqStepNew = Properties.Settings.Default.x264cqstep;
\r
1786 double rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1787 while (rfValueCurrent < rfValue)
\r
1789 slider_videoQuality.Value--;
\r
1790 rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1793 // Cache the CQ step for the next calculation
\r
1794 this.cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1797 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
1799 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1800 switch (drp_videoEncoder.Text)
\r
1802 case "MPEG-4 (FFmpeg)":
\r
1803 lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);
\r
1805 case "H.264 (x264)":
\r
1806 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1807 rfValue = Math.Round(rfValue, 2);
\r
1808 lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));
\r
1810 case "VP3 (Theora)":
\r
1811 lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;
\r
1816 private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)
\r
1818 text_bitrate.Enabled = false;
\r
1819 text_filesize.Enabled = true;
\r
1820 slider_videoQuality.Enabled = false;
\r
1822 check_2PassEncode.Enabled = true;
\r
1825 private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)
\r
1827 text_bitrate.Enabled = true;
\r
1828 text_filesize.Enabled = false;
\r
1829 slider_videoQuality.Enabled = false;
\r
1831 check_2PassEncode.Enabled = true;
\r
1834 private void radio_cq_CheckedChanged(object sender, EventArgs e)
\r
1836 text_bitrate.Enabled = false;
\r
1837 text_filesize.Enabled = false;
\r
1838 slider_videoQuality.Enabled = true;
\r
1840 check_2PassEncode.Enabled = false;
\r
1841 check_2PassEncode.CheckState = CheckState.Unchecked;
\r
1844 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
1846 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
1848 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1849 check_turbo.Enabled = true;
\r
1853 check_turbo.Enabled = false;
\r
1854 check_turbo.CheckState = CheckState.Unchecked;
\r
1858 // Chapter Marker Tab
\r
1859 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
1861 if (Check_ChapterMarkers.Checked)
\r
1863 if (drop_format.SelectedIndex != 1)
\r
1864 SetExtension(".m4v");
\r
1865 data_chpt.Enabled = true;
\r
1866 btn_importChapters.Enabled = true;
\r
1870 if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v)
\r
1871 SetExtension(".mp4");
\r
1872 data_chpt.Enabled = false;
\r
1873 btn_importChapters.Enabled = false;
\r
1877 private void btn_importChapters_Click(object sender, EventArgs e)
\r
1879 if (File_ChapterImport.ShowDialog() == DialogResult.OK)
\r
1881 string filename = File_ChapterImport.FileName;
\r
1882 DataGridView imported = Main.ImportChapterNames(data_chpt, filename);
\r
1883 if (imported != null)
\r
1884 data_chpt = imported;
\r
1888 private void btn_export_Click(object sender, EventArgs e)
\r
1890 SaveFileDialog saveFileDialog = new SaveFileDialog();
\r
1891 saveFileDialog.Filter = "Csv File|*.csv";
\r
1892 saveFileDialog.DefaultExt = "csv";
\r
1893 if (saveFileDialog.ShowDialog() == DialogResult.OK)
\r
1895 string filename = saveFileDialog.FileName;
\r
1897 Main.SaveChapterMarkersToCsv(this, filename);
\r
1901 private void mnu_resetChapters_Click(object sender, EventArgs e)
\r
1903 data_chpt.Rows.Clear();
\r
1904 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1905 if (chapterGridView != null)
\r
1907 data_chpt = chapterGridView;
\r
1911 // Query Editor Tab
\r
1912 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
1914 rtf_query.Text = QueryGenerator.GenerateFullQuery(this);
\r
1917 private void btn_clear_Click(object sender, EventArgs e)
\r
1919 rtf_query.Clear();
\r
1924 // MainWindow Components, Actions and Functions ***********************
\r
1926 #region Source Scan
\r
1929 /// Start the Scan Process
\r
1931 /// <param name="filename">
\r
1934 /// <param name="title">
\r
1937 private void StartScan(string filename, int title)
\r
1939 // Setup the GUI components for the scan.
\r
1940 sourcePath = filename;
\r
1942 this.DisableGUI();
\r
1947 SourceScan.Scan(sourcePath, title);
\r
1948 SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);
\r
1949 SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);
\r
1951 catch (Exception exc)
\r
1953 MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1958 /// Update the Status label for the scan
\r
1960 /// <param name="sender">
\r
1963 /// <param name="e">
\r
1966 private void SourceScan_ScanStatusChanged(object sender, EventArgs e)
\r
1968 UpdateScanStatusLabel();
\r
1972 /// Update the UI after the scan has completed
\r
1974 /// <param name="sender">
\r
1977 /// <param name="e">
\r
1980 private void SourceScan_ScanCompleted(object sender, EventArgs e)
\r
1982 UpdateGuiAfterScan();
\r
1986 /// Update the Scan Status Label
\r
1988 private void UpdateScanStatusLabel()
\r
1990 if (InvokeRequired)
\r
1992 BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));
\r
1995 lbl_encode.Text = SourceScan.ScanStatus;
\r
1999 /// Reset the GUI when the scan has completed
\r
2001 private void UpdateGuiAfterScan()
\r
2003 if (InvokeRequired)
\r
2005 BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));
\r
2011 currentSource = SourceScan.SouceData;
\r
2013 // Setup some GUI components
\r
2014 drp_dvdtitle.Items.Clear();
\r
2015 if (currentSource.Titles.Count != 0)
\r
2016 drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());
\r
2018 foreach (Title title in currentSource.Titles)
\r
2020 if (title.MainTitle)
\r
2022 drp_dvdtitle.SelectedItem = title;
\r
2026 if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)
\r
2028 drp_dvdtitle.SelectedIndex = 0;
\r
2031 // Enable the creation of chapter markers if the file is an image of a dvd
\r
2032 if (drop_chapterStart.Items.Count > 0)
\r
2035 int.TryParse(drop_chapterStart.Items[0].ToString(), out start);
\r
2036 int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);
\r
2037 if (end > start) Check_ChapterMarkers.Enabled = true;
\r
2040 Check_ChapterMarkers.Enabled = false;
\r
2041 Check_ChapterMarkers.Checked = false;
\r
2042 data_chpt.Rows.Clear();
\r
2046 // If no titles were found, Display an error message
\r
2047 if (drp_dvdtitle.Items.Count == 0)
\r
2050 "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
2051 "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
2052 sourcePath = string.Empty;
\r
2054 UpdateSourceLabel();
\r
2056 // Enable the GUI components and enable any disabled components
\r
2059 catch (Exception exc)
\r
2061 MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,
\r
2062 MessageBoxIcon.Error);
\r
2068 /// Enable the GUI
\r
2070 private void EnableGUI()
\r
2074 if (InvokeRequired)
\r
2075 BeginInvoke(new UpdateWindowHandler(EnableGUI));
\r
2076 lbl_encode.Text = "Scan Completed";
\r
2077 foreach (Control ctrl in Controls)
\r
2078 ctrl.Enabled = true;
\r
2079 btn_start.Enabled = true;
\r
2080 btn_showQueue.Enabled = true;
\r
2081 btn_add2Queue.Enabled = true;
\r
2082 tb_preview.Enabled = true;
\r
2083 btn_source.Enabled = true;
\r
2084 mnu_killCLI.Visible = false;
\r
2086 catch (Exception exc)
\r
2088 MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2093 /// Disable the GUI
\r
2095 private void DisableGUI()
\r
2097 foreach (Control ctrl in Controls)
\r
2098 if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))
\r
2099 ctrl.Enabled = false;
\r
2101 lbl_encode.Visible = true;
\r
2102 lbl_encode.Text = "Scanning ...";
\r
2103 btn_source.Enabled = false;
\r
2104 btn_start.Enabled = false;
\r
2105 btn_showQueue.Enabled = false;
\r
2106 btn_add2Queue.Enabled = false;
\r
2107 tb_preview.Enabled = false;
\r
2108 mnu_killCLI.Visible = true;
\r
2114 private void KillScan()
\r
2116 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2120 SourceScan.Stop();
\r
2122 lbl_encode.Text = "Scan Cancelled!";
\r
2128 private void ResetGUI()
\r
2130 drp_dvdtitle.Items.Clear();
\r
2131 drop_chapterStart.Items.Clear();
\r
2132 drop_chapterFinish.Items.Clear();
\r
2133 lbl_duration.Text = "Select a Title";
\r
2134 PictureSettings.lbl_src_res.Text = "Select a Title";
\r
2135 sourcePath = String.Empty;
\r
2136 text_destination.Text = String.Empty;
\r
2137 selectedTitle = null;
\r
2141 /// Update the Source Label
\r
2143 private void UpdateSourceLabel()
\r
2145 labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;
\r
2147 if (selectedTitle != null)
\r
2148 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
2149 // If it's one of multiple source files, make sure we don't use the folder name
\r
2150 labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
2154 /// Take a job from the Queue, rescan it, and reload the GUI for that job.
\r
2156 /// <param name="job">
\r
2159 public void RecievingJob(Job job)
\r
2161 string query = job.Query;
\r
2162 StartScan(job.Source, job.Title);
\r
2164 if (query != null)
\r
2166 // Ok, Reset all the H264 widgets before changing the preset
\r
2167 x264Panel.Reset2Defaults();
\r
2169 // Send the query from the file to the Query Parser class
\r
2170 QueryParser presetQuery = QueryParser.Parse(query);
\r
2172 // Now load the preset
\r
2173 PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue");
\r
2175 // The x264 widgets will need updated, so do this now:
\r
2176 x264Panel.StandardizeOptString();
\r
2177 x264Panel.SetCurrentSettingsInPanel();
\r
2179 // Finally, let this window have a copy of the preset settings.
\r
2180 this.currentlySelectedPreset = null;
\r
2181 PictureSettings.SetPresetCropWarningLabel(null);
\r
2187 #region GUI Functions and Actions
\r
2190 /// Set the GUI to it's finished encoding state.
\r
2192 private void SetEncodeFinished()
\r
2196 if (InvokeRequired)
\r
2198 BeginInvoke(new UpdateWindowHandler(SetEncodeFinished));
\r
2202 lbl_encode.Text = "Encoding Finished";
\r
2203 ProgressBarStatus.Visible = false;
\r
2204 btn_start.Text = "Start";
\r
2205 btn_start.ToolTipText = "Start the encoding process";
\r
2206 btn_start.Image = Properties.Resources.Play;
\r
2208 // If the window is minimized, display the notification in a popup.
\r
2209 if (Properties.Settings.Default.trayIconAlerts)
\r
2210 if (FormWindowState.Minimized == this.WindowState)
\r
2212 notifyIcon.BalloonTipText = lbl_encode.Text;
\r
2213 notifyIcon.ShowBalloonTip(500);
\r
2216 catch (Exception exc)
\r
2218 MessageBox.Show(exc.ToString());
\r
2223 /// Set the GUI to it's started encoding state.
\r
2225 private void SetEncodeStarted()
\r
2229 if (InvokeRequired)
\r
2231 BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));
\r
2234 lbl_encode.Visible = true;
\r
2235 ProgressBarStatus.Value = 0;
\r
2236 ProgressBarStatus.Visible = true;
\r
2237 lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";
\r
2238 btn_start.Text = "Stop";
\r
2239 btn_start.ToolTipText = "Stop the encoding process.";
\r
2240 btn_start.Image = Properties.Resources.stop;
\r
2242 catch (Exception exc)
\r
2244 MessageBox.Show(exc.ToString());
\r
2249 /// Display the Encode Status
\r
2251 /// <param name="sender">
\r
2254 /// <param name="e">
\r
2257 private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)
\r
2259 if (this.InvokeRequired)
\r
2261 this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });
\r
2267 "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}, Encode(s) Pending {4}",
\r
2268 e.PercentComplete,
\r
2269 e.CurrentFrameRate,
\r
2270 e.AverageFrameRate,
\r
2271 e.EstimatedTimeLeft,
\r
2272 encodeQueue.Count);
\r
2274 ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);
\r
2278 /// Set the DVD Drive selection in the "Source" Menu
\r
2280 private void SetDriveSelectionMenuItem()
\r
2284 if (InvokeRequired)
\r
2286 BeginInvoke(new UpdateWindowHandler(SetDriveSelectionMenuItem));
\r
2290 drives = Main.GetDrives();
\r
2292 List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
\r
2293 foreach (DriveInformation drive in drives)
\r
2295 ToolStripMenuItem menuItem = new ToolStripMenuItem
\r
2297 Name = drive.ToString(),
\r
2298 Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",
\r
2299 Image = Resources.disc_small
\r
2301 menuItem.Click += new EventHandler(mnu_dvd_drive_Click);
\r
2302 menuItems.Add(menuItem);
\r
2305 foreach (ToolStripMenuItem item in menuItems)
\r
2306 btn_source.DropDownItems.Add(item);
\r
2308 catch (Exception exc)
\r
2310 MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);
\r
2315 /// Access the preset Handler and setup the preset panel.
\r
2317 private void LoadPresetPanel()
\r
2319 if (presetHandler.CheckIfPresetsAreOutOfDate())
\r
2320 if (!Settings.Default.presetNotification)
\r
2321 MessageBox.Show(this,
\r
2322 "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",
\r
2323 "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
2325 presetHandler.GetPresetPanel(ref treeView_presets);
\r
2326 treeView_presets.Update();
\r
2330 /// Get the title from the selected item in the title dropdown.
\r
2335 private int GetTitle()
\r
2338 if (drp_dvdtitle.SelectedItem != null)
\r
2340 string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');
\r
2341 int.TryParse(titleInfo[0], out title);
\r
2348 /// Handle the Update Check Finishing.
\r
2350 /// <param name="result">
\r
2353 private void UpdateCheckDoneMenu(IAsyncResult result)
\r
2355 // Make sure it's running on the calling thread
\r
2356 if (InvokeRequired)
\r
2358 Invoke(new MethodInvoker(() => this.UpdateCheckDoneMenu(result)));
\r
2361 UpdateCheckInformation info;
\r
2364 // Get the information about the new build, if any, and close the window
\r
2365 info = Main.EndCheckForUpdates(result);
\r
2367 if (info.NewVersionAvailable && info.BuildInformation != null)
\r
2369 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
2370 updateWindow.ShowDialog();
\r
2373 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,
\r
2374 MessageBoxIcon.Information);
\r
2375 lbl_updateCheck.Visible = false;
\r
2378 catch (Exception ex)
\r
2380 if ((bool)result.AsyncState)
\r
2382 "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,
\r
2383 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2392 /// Handle GUI shortcuts
\r
2394 /// <param name="msg">Message</param>
\r
2395 /// <param name="keyData">Keys</param>
\r
2396 /// <returns>Bool</returns>
\r
2397 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
2399 if (keyData == (Keys.Control | Keys.S))
\r
2401 btn_start_Click(this, new EventArgs());
\r
2405 if (keyData == (Keys.Control | Keys.A))
\r
2407 btn_add2Queue_Click(this, new EventArgs());
\r
2410 return base.ProcessCmdKey(ref msg, keyData);
\r
2414 /// If the queue is being processed, prompt the user to confirm application close.
\r
2416 /// <param name="e">FormClosingEventArgs</param>
\r
2417 protected override void OnFormClosing(FormClosingEventArgs e)
\r
2421 // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.
\r
2422 if (encodeQueue.IsEncoding)
\r
2424 DialogResult result =
\r
2426 "HandBrake is currently encoding. Closing HandBrake will stop the current encode and will result in an unplayable file.\n\nDo you want to close HandBrake?",
\r
2427 "Close HandBrake?",
\r
2428 MessageBoxButtons.YesNo,
\r
2429 MessageBoxIcon.Question);
\r
2431 if (result == DialogResult.No)
\r
2437 encodeQueue.Stop();
\r
2440 if (SourceScan.IsScanning)
\r
2442 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2443 SourceScan.Stop();
\r
2446 catch (Exception exc)
\r
2448 Main.ShowExceptiowWindow("HandBrake was not able to shutdown properly. You may need to forcefully quit HandBrake CLI from TaskManager if it's still running.", exc.ToString());
\r
2452 base.OnFormClosing(e);
\r
2458 // This is the END of the road ****************************************
\r