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.Threading;
\r
16 using System.Windows.Forms;
\r
19 using HandBrake.ApplicationServices.Functions;
\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 using Main = Handbrake.Functions.Main;
\r
34 public partial class frmMain : Form
\r
36 // Objects which may be used by one or more other objects *************
\r
37 private IQueue encodeQueue = new Queue();
\r
38 private PresetsHandler presetHandler = new PresetsHandler();
\r
40 // Windows ************************************************************
\r
41 private frmQueue queueWindow;
\r
42 private frmPreview qtpreview;
\r
43 private frmActivityWindow activityWindow;
\r
45 // Globals: Mainly used for tracking. *********************************
\r
46 public Title selectedTitle;
\r
47 public string sourcePath;
\r
48 private SourceType selectedSourceType;
\r
49 private string dvdDrivePath;
\r
50 private string dvdDriveLabel;
\r
51 private Preset currentlySelectedPreset;
\r
52 private DVD currentSource;
\r
53 private IScan SourceScan = new ScanService();
\r
54 private List<DriveInformation> drives;
\r
56 // Delegates **********************************************************
\r
57 private delegate void UpdateWindowHandler();
\r
59 // Applicaiton Startup ************************************************
\r
64 /// Gets SourceName.
\r
66 public string SourceName
\r
70 if (this.selectedSourceType == SourceType.DvdDrive)
\r
72 return this.dvdDriveLabel;
\r
75 if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")
\r
76 return Path.GetFileNameWithoutExtension(this.sourcePath);
\r
78 return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));
\r
84 #region Application Startup
\r
87 /// Initializes a new instance of the <see cref="frmMain"/> class.
\r
89 /// <param name="args">
\r
90 /// The arguments passed in on application startup.
\r
92 public frmMain(string[] args)
\r
94 InitializeComponent();
\r
96 // Update the users config file with the CLI version data.
\r
97 Main.SetCliVersionData();
\r
99 if (Settings.Default.hb_version.Contains("svn"))
\r
101 this.Text += " " + Settings.Default.hb_version;
\r
104 // Check for new versions, if update checking is enabled
\r
105 if (Settings.Default.updateStatus)
\r
107 if (DateTime.Now.Subtract(Settings.Default.lastUpdateCheckDate).TotalDays > Properties.Settings.Default.daysBetweenUpdateCheck)
\r
109 Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false);
\r
113 // Clear the log files in the background
\r
114 if (Settings.Default.clearOldLogs)
\r
116 Thread clearLog = new Thread(Main.ClearOldLogs);
\r
120 // Setup the GUI components
\r
121 LoadPresetPanel(); // Load the Preset Panel
\r
122 treeView_presets.ExpandAll();
\r
123 lbl_encode.Text = string.Empty;
\r
124 drop_mode.SelectedIndex = 0;
\r
125 queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue
\r
126 if (!Settings.Default.QueryEditorTab)
\r
127 tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.
\r
128 if (Settings.Default.tooltipEnable)
\r
129 ToolTip.Active = true;
\r
131 // Load the user's default settings or Normal Preset
\r
132 if (Settings.Default.defaultPreset != string.Empty && presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)
\r
134 string query = presetHandler.GetPreset(Settings.Default.defaultPreset).Query;
\r
137 x264Panel.Reset2Defaults();
\r
139 QueryParser presetQuery = QueryParser.Parse(query);
\r
140 PresetLoader.LoadPreset(this, presetQuery, Settings.Default.defaultPreset);
\r
142 x264Panel.StandardizeOptString();
\r
143 x264Panel.SetCurrentSettingsInPanel();
\r
147 loadNormalPreset();
\r
149 // Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)
\r
150 GrowlCommunicator.Register();
\r
152 // Event Handlers and Queue Recovery
\r
154 Main.RecoverQueue(encodeQueue);
\r
156 // If have a file passed in via command arguemtents, check it's a file and try scanning it.
\r
157 if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0])))
\r
159 this.StartScan(args[0], 0);
\r
164 /// When the update check is done, process the results.
\r
166 /// <param name="result">IAsyncResult result</param>
\r
167 private void UpdateCheckDone(IAsyncResult result)
\r
169 if (InvokeRequired)
\r
171 Invoke(new MethodInvoker(() => UpdateCheckDone(result)));
\r
175 UpdateCheckInformation info;
\r
179 info = Main.EndCheckForUpdates(result);
\r
181 if (info.NewVersionAvailable)
\r
183 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
184 updateWindow.ShowDialog();
\r
187 catch (Exception ex)
\r
189 if ((bool)result.AsyncState)
\r
190 Main.ShowExceptiowWindow("Unable to check for updates, Please try again later.", ex.ToString());
\r
198 // Encoding Events for setting up the GUI
\r
199 private void events()
\r
201 // Handle Widget changes when preset is selected.
\r
202 RegisterPresetEventHandler();
\r
204 // Handle Window Resize
\r
205 if (Properties.Settings.Default.MainWindowMinimize)
\r
206 this.Resize += new EventHandler(frmMain_Resize);
\r
208 // Handle Encode Start / Finish / Pause
\r
209 encodeQueue.EncodeStarted += new EventHandler(encodeStarted);
\r
210 encodeQueue.EncodeEnded += new EventHandler(encodeEnded);
\r
212 // Handle a file being draged onto the GUI.
\r
213 this.DragEnter += new DragEventHandler(frmMain_DragEnter);
\r
214 this.DragDrop += new DragEventHandler(frmMain_DragDrop);
\r
217 // 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
218 private void RegisterPresetEventHandler()
\r
221 drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
222 check_largeFile.CheckedChanged += new EventHandler(changePresetLabel);
\r
223 check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel);
\r
224 check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);
\r
226 // Picture Settings
\r
227 PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);
\r
230 Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);
\r
233 drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
234 check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel);
\r
235 check_turbo.CheckedChanged += new EventHandler(changePresetLabel);
\r
236 text_filesize.TextChanged += new EventHandler(changePresetLabel);
\r
237 text_bitrate.TextChanged += new EventHandler(changePresetLabel);
\r
238 slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel);
\r
241 AudioSettings.AudioListChanged += new EventHandler(changePresetLabel);
\r
244 x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);
\r
247 private void UnRegisterPresetEventHandler()
\r
249 // Output Settings
\r
250 drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
251 check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel);
\r
252 check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel);
\r
253 check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);
\r
255 // Picture Settings
\r
256 PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);
\r
259 Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);
\r
262 drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
263 check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel);
\r
264 check_turbo.CheckedChanged -= new EventHandler(changePresetLabel);
\r
265 text_filesize.TextChanged -= new EventHandler(changePresetLabel);
\r
266 text_bitrate.TextChanged -= new EventHandler(changePresetLabel);
\r
267 slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel);
\r
270 AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel);
\r
273 x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);
\r
276 private void changePresetLabel(object sender, EventArgs e)
\r
278 labelPreset.Text = "Output Settings (Preset: Custom)";
\r
279 this.currentlySelectedPreset = null;
\r
282 private static void frmMain_DragEnter(object sender, DragEventArgs e)
\r
284 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
\r
285 e.Effect = DragDropEffects.All;
\r
288 private void frmMain_DragDrop(object sender, DragEventArgs e)
\r
290 string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
\r
291 sourcePath = string.Empty;
\r
293 if (fileList != null)
\r
295 if (!string.IsNullOrEmpty(fileList[0]))
\r
297 this.selectedSourceType = SourceType.VideoFile;
\r
298 StartScan(fileList[0], 0);
\r
301 UpdateSourceLabel();
\r
304 UpdateSourceLabel();
\r
307 private void encodeStarted(object sender, EventArgs e)
\r
309 SetEncodeStarted();
\r
310 encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;
\r
313 private void encodeEnded(object sender, EventArgs e)
\r
315 encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;
\r
316 SetEncodeFinished();
\r
320 // User Interface Menus / Tool Strips *********************************
\r
325 /// Kill The scan menu Item
\r
327 /// <param name="sender">
\r
330 /// <param name="e">
\r
333 private void mnu_killCLI_Click(object sender, EventArgs e)
\r
339 /// Exit the Application Menu Item
\r
341 /// <param name="sender">
\r
344 /// <param name="e">
\r
347 private void mnu_exit_Click(object sender, EventArgs e)
\r
349 Application.Exit();
\r
357 /// Menu - Start Button
\r
359 /// <param name="sender">
\r
362 /// <param name="e">
\r
365 private void mnu_encode_Click(object sender, EventArgs e)
\r
367 queueWindow.Show();
\r
371 /// Menu - Display the Log Window
\r
373 /// <param name="sender">
\r
376 /// <param name="e">
\r
379 private void mnu_encodeLog_Click(object sender, EventArgs e)
\r
381 this.btn_ActivityWindow_Click(this, null);
\r
385 /// Menu - Display the Options Window
\r
387 /// <param name="sender">
\r
390 /// <param name="e">
\r
393 private void mnu_options_Click(object sender, EventArgs e)
\r
395 Form options = new frmOptions(this);
\r
396 options.ShowDialog();
\r
401 #region Presets Menu
\r
404 /// Reset the Built in Presets
\r
406 /// <param name="sender">
\r
409 /// <param name="e">
\r
412 private void mnu_presetReset_Click(object sender, EventArgs e)
\r
414 presetHandler.UpdateBuiltInPresets();
\r
416 if (treeView_presets.Nodes.Count == 0)
\r
418 "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
419 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
421 MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
423 treeView_presets.ExpandAll();
\r
427 /// Delete the selected preset
\r
429 /// <param name="sender">
\r
432 /// <param name="e">
\r
435 private void mnu_delete_preset_Click(object sender, EventArgs e)
\r
437 presetHandler.RemoveBuiltInPresets();
\r
438 LoadPresetPanel(); // Reload the preset panel
\r
442 /// Select the Normal preset
\r
444 /// <param name="sender">
\r
447 /// <param name="e">
\r
450 private void mnu_SelectDefault_Click(object sender, EventArgs e)
\r
452 loadNormalPreset();
\r
456 /// Import a plist Preset
\r
458 /// <param name="sender">
\r
461 /// <param name="e">
\r
464 private void mnu_importMacPreset_Click(object sender, EventArgs e)
\r
470 /// Export a Plist Preset
\r
472 /// <param name="sender">
\r
475 /// <param name="e">
\r
478 private void mnu_exportMacPreset_Click(object sender, EventArgs e)
\r
484 /// Create a new Preset
\r
486 /// <param name="sender">
\r
489 /// <param name="e">
\r
492 private void btn_new_preset_Click(object sender, EventArgs e)
\r
494 Form preset = new frmAddPreset(this, presetHandler);
\r
495 if (preset.ShowDialog() == DialogResult.OK)
\r
497 TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };
\r
498 treeView_presets.Nodes.Add(presetTreeview);
\r
499 presetHandler.LastPresetAdded = null;
\r
508 /// Menu - Display the User Guide Web Page
\r
510 /// <param name="sender">
\r
513 /// <param name="e">
\r
516 private void mnu_user_guide_Click(object sender, EventArgs e)
\r
518 Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");
\r
522 /// Menu - Check for Updates
\r
524 /// <param name="sender">
\r
527 /// <param name="e">
\r
530 private void mnu_UpdateCheck_Click(object sender, EventArgs e)
\r
532 lbl_updateCheck.Visible = true;
\r
533 Main.BeginCheckForUpdates(new AsyncCallback(this.UpdateCheckDoneMenu), false);
\r
537 /// Menu - Display the About Window
\r
539 /// <param name="sender">
\r
542 /// <param name="e">
\r
545 private void mnu_about_Click(object sender, EventArgs e)
\r
547 using (frmAbout About = new frmAbout())
\r
549 About.ShowDialog();
\r
558 /// RMenu - Expand All
\r
560 /// <param name="sender">
\r
563 /// <param name="e">
\r
566 private void pmnu_expandAll_Click(object sender, EventArgs e)
\r
568 treeView_presets.ExpandAll();
\r
572 /// RMenu - Collaspe All
\r
574 /// <param name="sender">
\r
577 /// <param name="e">
\r
580 private void pmnu_collapse_Click(object sender, EventArgs e)
\r
582 treeView_presets.CollapseAll();
\r
586 /// Menu - Import Preset
\r
588 /// <param name="sender">
\r
591 /// <param name="e">
\r
594 private void pmnu_import_Click(object sender, EventArgs e)
\r
600 /// RMenu - Save Changes to Preset
\r
602 /// <param name="sender">
\r
605 /// <param name="e">
\r
608 private void pmnu_saveChanges_Click(object sender, EventArgs e)
\r
610 // TODO this requires a re-think since the Query Editor has changed.
\r
611 DialogResult result =
\r
613 "Do you wish to include picture settings when updating the preset: " +
\r
614 treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,
\r
615 MessageBoxIcon.Question);
\r
616 if (result == DialogResult.Yes)
\r
617 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
618 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);
\r
619 else if (result == DialogResult.No)
\r
620 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
621 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);
\r
625 /// RMenu - Delete Preset
\r
627 /// <param name="sender">
\r
630 /// <param name="e">
\r
633 private void pmnu_delete_click(object sender, EventArgs e)
\r
635 if (treeView_presets.SelectedNode != null)
\r
637 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
638 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
640 treeView_presets.Select();
\r
644 /// Preset Menu Is Opening. Setup the Menu
\r
646 /// <param name="sender">
\r
649 /// <param name="e">
\r
652 private void presets_menu_Opening(object sender, CancelEventArgs e)
\r
654 // Make sure that the save menu is always disabled by default
\r
655 pmnu_saveChanges.Enabled = false;
\r
657 // Now enable the save menu if the selected preset is a user preset
\r
658 if (treeView_presets.SelectedNode != null)
\r
659 if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))
\r
660 pmnu_saveChanges.Enabled = true;
\r
662 treeView_presets.Select();
\r
665 // Presets Management
\r
668 /// Button - Add a preset
\r
670 /// <param name="sender">
\r
673 /// <param name="e">
\r
676 private void btn_addPreset_Click(object sender, EventArgs e)
\r
678 Form preset = new frmAddPreset(this, presetHandler);
\r
679 if (preset.ShowDialog() == DialogResult.OK)
\r
681 TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };
\r
682 treeView_presets.Nodes.Add(presetTreeview);
\r
683 presetHandler.LastPresetAdded = null;
\r
688 /// Button - remove a Preset
\r
690 /// <param name="sender">
\r
693 /// <param name="e">
\r
696 private void btn_removePreset_Click(object sender, EventArgs e)
\r
698 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
699 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
700 if (result == DialogResult.Yes)
\r
702 if (treeView_presets.SelectedNode != null)
\r
704 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
705 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
708 treeView_presets.Select();
\r
712 /// Button - Set the selected preset as the default
\r
714 /// <param name="sender">
\r
717 /// <param name="e">
\r
720 private void btn_setDefault_Click(object sender, EventArgs e)
\r
722 if (treeView_presets.SelectedNode != null)
\r
724 DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",
\r
725 "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
726 if (result == DialogResult.Yes)
\r
728 Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;
\r
729 Properties.Settings.Default.Save();
\r
730 MessageBox.Show("New default preset set.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
734 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
738 /// PresetBar Mouse Down event
\r
740 /// <param name="sender">
\r
743 /// <param name="e">
\r
746 private void treeview_presets_mouseUp(object sender, MouseEventArgs e)
\r
748 if (e.Button == MouseButtons.Right)
\r
749 treeView_presets.SelectedNode = treeView_presets.GetNodeAt(e.Location);
\r
750 else if (e.Button == MouseButtons.Left)
\r
752 if (treeView_presets.GetNodeAt(e.Location) != null)
\r
754 if (labelPreset.Text.Contains(treeView_presets.GetNodeAt(e.Location).Text))
\r
759 treeView_presets.Select();
\r
763 /// Preset Bar after selecting the preset
\r
765 /// <param name="sender">
\r
768 /// <param name="e">
\r
771 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
777 /// Preset Bar - Handle the Delete Key
\r
779 /// <param name="sender">
\r
782 /// <param name="e">
\r
785 private void treeView_presets_deleteKey(object sender, KeyEventArgs e)
\r
787 if (e.KeyCode == Keys.Delete)
\r
789 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
790 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
791 if (result == DialogResult.Yes)
\r
793 if (treeView_presets.SelectedNode != null)
\r
794 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
796 // Remember each nodes expanded status so we can reload it
\r
797 List<bool> nodeStatus = new List<bool>();
\r
798 foreach (TreeNode node in treeView_presets.Nodes)
\r
799 nodeStatus.Add(node.IsExpanded);
\r
801 // Now reload the preset panel
\r
804 // And finally, re-expand any of the nodes if required
\r
806 foreach (TreeNode node in treeView_presets.Nodes)
\r
818 /// Select the selected preset and setup the GUI
\r
820 private void selectPreset()
\r
822 if (treeView_presets.SelectedNode != null)
\r
824 // Ok, so, we've selected a preset. Now we want to load it.
\r
825 string presetName = treeView_presets.SelectedNode.Text;
\r
826 Preset preset = presetHandler.GetPreset(presetName);
\r
827 if (preset != null)
\r
829 string query = presetHandler.GetPreset(presetName).Query;
\r
833 // Ok, Reset all the H264 widgets before changing the preset
\r
834 x264Panel.Reset2Defaults();
\r
836 // Send the query from the file to the Query Parser class
\r
837 QueryParser presetQuery = QueryParser.Parse(query);
\r
839 // Now load the preset
\r
840 PresetLoader.LoadPreset(this, presetQuery, presetName);
\r
842 // The x264 widgets will need updated, so do this now:
\r
843 x264Panel.StandardizeOptString();
\r
844 x264Panel.SetCurrentSettingsInPanel();
\r
846 // Finally, let this window have a copy of the preset settings.
\r
847 this.currentlySelectedPreset = preset;
\r
848 PictureSettings.SetPresetCropWarningLabel(preset);
\r
855 /// Load the Normal Preset
\r
857 private void loadNormalPreset()
\r
859 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
861 foreach (TreeNode node in treenode.Nodes)
\r
863 if (node.Text.Equals("Normal"))
\r
864 treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0];
\r
870 /// Import a plist preset
\r
872 private void ImportPreset()
\r
874 if (openPreset.ShowDialog() == DialogResult.OK)
\r
876 QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);
\r
877 if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))
\r
879 DialogResult result =
\r
880 MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",
\r
881 "Overwrite preset?",
\r
882 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
883 if (result == DialogResult.Yes)
\r
885 PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
\r
886 presetHandler.Update(parsed.PresetName + " (Imported)",
\r
887 QueryGenerator.GenerateFullQuery(this),
\r
888 parsed.UsesPictureSettings);
\r
893 PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
\r
894 if (presetHandler.Add(parsed.PresetName + " (Imported)",
\r
895 QueryGenerator.GenerateFullQuery(this),
\r
896 parsed.UsesPictureSettings))
\r
898 TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")
\r
900 ForeColor = Color.Black
\r
902 treeView_presets.Nodes.Add(preset_treeview);
\r
909 /// Export a plist Preset
\r
911 private void ExportPreset()
\r
913 MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
916 /*SaveFileDialog savefiledialog = new SaveFileDialog();
\r
917 savefiledialog.Filter = "plist|*.plist";
\r
919 if (treeView_presets.SelectedNode != null)
\r
922 if (savefiledialog.ShowDialog() == DialogResult.OK)
\r
924 Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);
\r
925 PlistPresetHandler.Export(savefiledialog.FileName, preset);
\r
935 /// 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
937 /// <param name="sender">
\r
940 /// <param name="e">
\r
943 private void btn_source_Click(object sender, EventArgs e)
\r
945 // Remove old Drive Menu Items.
\r
946 List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();
\r
947 foreach (var item in btn_source.DropDownItems)
\r
949 if (item.GetType() == typeof(ToolStripMenuItem))
\r
951 ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
\r
952 if (menuItem.Name.StartsWith("Drive"))
\r
954 itemsToRemove.Add(menuItem);
\r
959 foreach (ToolStripMenuItem item in itemsToRemove)
\r
960 btn_source.DropDownItems.Remove(item);
\r
962 Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);
\r
963 driveInfoThread.Start();
\r
967 /// Toolbar - Start The Encode
\r
969 /// <param name="sender">
\r
972 /// <param name="e">
\r
975 private void btn_start_Click(object sender, EventArgs e)
\r
977 if (btn_start.Text == "Stop")
\r
979 DialogResult result = !Properties.Settings.Default.showCliForInGuiEncodeStatus
\r
981 "Are you sure you wish to cancel the encode?\n\nPlease note: Stopping this encode will render the file unplayable. ",
\r
983 MessageBoxButtons.YesNo,
\r
984 MessageBoxIcon.Question)
\r
986 "Are you sure you wish to cancel the encode?",
\r
988 MessageBoxButtons.YesNo,
\r
989 MessageBoxIcon.Question);
\r
991 if (result == DialogResult.Yes)
\r
994 encodeQueue.Pause();
\r
996 if (Settings.Default.showCliForInGuiEncodeStatus)
\r
997 encodeQueue.SafelyClose();
\r
999 encodeQueue.Stop();
\r
1004 // 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
1005 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1006 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1008 if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))
\r
1010 string generatedQuery = QueryGenerator.GenerateFullQuery(this);
\r
1011 string specifiedQuery = rtf_query.Text != string.Empty
\r
1013 : QueryGenerator.GenerateFullQuery(this);
\r
1014 string query = string.Empty;
\r
1016 // Check to make sure the generated query matches the GUI settings
\r
1017 if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) &&
\r
1018 generatedQuery != specifiedQuery)
\r
1020 DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " +
\r
1021 "does not match the current GUI settings.\n\nBecause the manual query takes " +
\r
1022 "priority over the GUI, your recently updated settings will not be taken " +
\r
1023 "into account when encoding this job." +
\r
1024 Environment.NewLine + Environment.NewLine +
\r
1025 "Do you want to replace the manual query with the updated GUI-generated query?",
\r
1026 "Manual Query does not Match GUI",
\r
1027 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,
\r
1028 MessageBoxDefaultButton.Button3);
\r
1032 case DialogResult.Yes:
\r
1033 // Replace the manual query with the generated one
\r
1034 query = generatedQuery;
\r
1035 rtf_query.Text = generatedQuery;
\r
1037 case DialogResult.No:
\r
1038 // Use the manual query
\r
1039 query = specifiedQuery;
\r
1041 case DialogResult.Cancel:
\r
1042 // Don't start the encode
\r
1048 query = specifiedQuery;
\r
1051 DialogResult overwrite = DialogResult.Yes;
\r
1052 if (!string.IsNullOrEmpty(jobDestination) && File.Exists(jobDestination))
\r
1054 overwrite = MessageBox.Show(
\r
1055 "The destination file already exists. Are you sure you want to overwrite it?",
\r
1056 "Overwrite File?",
\r
1057 MessageBoxButtons.YesNo,
\r
1058 MessageBoxIcon.Question);
\r
1061 if (overwrite == DialogResult.Yes)
\r
1063 if (encodeQueue.Count == 0)
\r
1064 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1066 queueWindow.SetQueue();
\r
1067 if (encodeQueue.Count > 1)
\r
1068 queueWindow.Show(false);
\r
1070 SetEncodeStarted(); // Encode is running, so setup the GUI appropriately
\r
1071 encodeQueue.Start(); // Start The Queue Encoding Process
\r
1076 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1077 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1078 MessageBoxIcon.Warning);
\r
1083 /// Toolbar - Add the current job to the Queue
\r
1085 /// <param name="sender">
\r
1088 /// <param name="e">
\r
1091 private void btn_add2Queue_Click(object sender, EventArgs e)
\r
1093 // Get the CLI query or use the query editor if it's not empty.
\r
1094 string query = QueryGenerator.GenerateFullQuery(this);
\r
1095 if (!string.IsNullOrEmpty(rtf_query.Text))
\r
1096 query = rtf_query.Text;
\r
1098 // 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
1099 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1100 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1102 // Make sure we have a Source and Destination.
\r
1103 if (string.IsNullOrEmpty(jobSourcePath) || string.IsNullOrEmpty(jobDestination))
\r
1105 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1109 // Make sure the destination path exists.
\r
1110 if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))
\r
1112 MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1116 // Make sure we don't have a duplciate on the queue.
\r
1117 if (encodeQueue.CheckForDestinationDuplicate(jobDestination))
\r
1119 DialogResult result =
\r
1121 "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
1122 "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
1123 if (result == DialogResult.Yes)
\r
1124 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1127 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1129 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";
\r
1131 queueWindow.Show();
\r
1135 /// Toolbar - Show the Queue
\r
1137 /// <param name="sender">
\r
1140 /// <param name="e">
\r
1143 private void btn_showQueue_Click(object sender, EventArgs e)
\r
1145 queueWindow.Show();
\r
1146 queueWindow.Activate();
\r
1150 /// Toolbar - Show the Preview Window
\r
1152 /// <param name="sender">
\r
1155 /// <param name="e">
\r
1158 private void tb_preview_Click(object sender, EventArgs e)
\r
1160 if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1161 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1162 MessageBoxIcon.Warning);
\r
1165 if (qtpreview == null)
\r
1167 qtpreview = new frmPreview(this);
\r
1170 else if (qtpreview.IsDisposed)
\r
1172 qtpreview = new frmPreview(this);
\r
1176 MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,
\r
1177 MessageBoxIcon.Warning);
\r
1182 /// Toolbar - Show the Activity log Window
\r
1184 /// <param name="sender">
\r
1187 /// <param name="e">
\r
1190 private void btn_ActivityWindow_Click(object sender, EventArgs e)
\r
1192 if (this.activityWindow == null || !this.activityWindow.IsHandleCreated)
\r
1193 this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
1195 this.activityWindow.Show();
\r
1196 this.activityWindow.Activate();
\r
1201 #region System Tray Icon
\r
1204 /// Handle Resizing of the main window when deaing with the Notify Icon
\r
1206 /// <param name="sender">
\r
1209 /// <param name="e">
\r
1212 private void frmMain_Resize(object sender, EventArgs e)
\r
1214 if (FormWindowState.Minimized == this.WindowState)
\r
1216 notifyIcon.Visible = true;
\r
1219 else if (FormWindowState.Normal == this.WindowState)
\r
1220 notifyIcon.Visible = false;
\r
1224 /// Double Click the Tray Icon
\r
1226 /// <param name="sender">
\r
1229 /// <param name="e">
\r
1232 private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
\r
1234 this.Visible = true;
\r
1236 this.WindowState = FormWindowState.Normal;
\r
1237 notifyIcon.Visible = false;
\r
1241 /// Tray Icon - Restore Menu Item - Resture the Window
\r
1243 /// <param name="sender">
\r
1246 /// <param name="e">
\r
1249 private void btn_restore_Click(object sender, EventArgs e)
\r
1251 this.Visible = true;
\r
1253 this.WindowState = FormWindowState.Normal;
\r
1254 notifyIcon.Visible = false;
\r
1259 #region Main Window and Tab Control
\r
1262 private void btn_dvd_source_Click(object sender, EventArgs e)
\r
1264 if (DVD_Open.ShowDialog() == DialogResult.OK)
\r
1266 this.selectedSourceType = SourceType.Folder;
\r
1267 SelectSource(DVD_Open.SelectedPath);
\r
1270 UpdateSourceLabel();
\r
1273 private void btn_file_source_Click(object sender, EventArgs e)
\r
1275 if (ISO_Open.ShowDialog() == DialogResult.OK)
\r
1277 this.selectedSourceType = SourceType.VideoFile;
\r
1278 SelectSource(ISO_Open.FileName);
\r
1281 UpdateSourceLabel();
\r
1284 private void mnu_dvd_drive_Click(object sender, EventArgs e)
\r
1286 ToolStripMenuItem item = sender as ToolStripMenuItem;
\r
1289 string driveId = item.Name.Replace("Drive", string.Empty);
\r
1291 if (int.TryParse(driveId, out id))
\r
1293 this.dvdDrivePath = drives[id].RootDirectory;
\r
1294 this.dvdDriveLabel = drives[id].VolumeLabel;
\r
1296 if (this.dvdDrivePath == null) return;
\r
1297 this.selectedSourceType = SourceType.DvdDrive;
\r
1298 SelectSource(this.dvdDrivePath);
\r
1303 private void SelectSource(string file)
\r
1305 Check_ChapterMarkers.Enabled = true;
\r
1306 sourcePath = string.Empty;
\r
1308 if (file == string.Empty) // Must have a file or path
\r
1310 UpdateSourceLabel();
\r
1314 sourcePath = Path.GetFileName(file);
\r
1315 StartScan(file, 0);
\r
1318 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
1320 if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))
\r
1322 "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",
\r
1323 "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
1326 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1328 UnRegisterPresetEventHandler();
\r
1329 drop_mode.SelectedIndex = 0;
\r
1331 drop_chapterStart.Items.Clear();
\r
1332 drop_chapterFinish.Items.Clear();
\r
1334 // If the dropdown is set to automatic nothing else needs to be done.
\r
1335 // Otheriwse if its not, title data has to be loaded from parsing.
\r
1336 if (drp_dvdtitle.Text != "Automatic")
\r
1338 selectedTitle = drp_dvdtitle.SelectedItem as Title;
\r
1339 lbl_duration.Text = selectedTitle.Duration.ToString();
\r
1340 PictureSettings.CurrentlySelectedPreset = this.currentlySelectedPreset;
\r
1341 PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control
\r
1343 // Populate the Angles dropdown
\r
1344 drop_angle.Items.Clear();
\r
1345 if (!Properties.Settings.Default.noDvdNav)
\r
1347 drop_angle.Visible = true;
\r
1348 lbl_angle.Visible = true;
\r
1350 for (int i = 1; i <= selectedTitle.AngleCount; i++)
\r
1351 drop_angle.Items.Add(i.ToString());
\r
1353 if (drop_angle.Items.Count != 0)
\r
1354 drop_angle.SelectedIndex = 0;
\r
1358 drop_angle.Visible = false;
\r
1359 lbl_angle.Visible = false;
\r
1362 // Populate the Start chapter Dropdown
\r
1363 drop_chapterStart.Items.Clear();
\r
1364 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1365 if (drop_chapterStart.Items.Count > 0)
\r
1366 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
1368 // Populate the Final Chapter Dropdown
\r
1369 drop_chapterFinish.Items.Clear();
\r
1370 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1371 if (drop_chapterFinish.Items.Count > 0)
\r
1372 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
1374 // Populate the Audio Channels Dropdown
\r
1375 AudioSettings.SetTrackList(selectedTitle, this.currentlySelectedPreset);
\r
1377 // Populate the Subtitles dropdown
\r
1378 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());
\r
1380 // Update the source label if we have multiple streams
\r
1381 if (selectedTitle != null)
\r
1382 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
1383 labelSource.Text = labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
1385 // Run the AutoName & ChapterNaming functions
\r
1386 if (Properties.Settings.Default.autoNaming)
\r
1388 string autoPath = Main.AutoName(this);
\r
1389 if (autoPath != null)
\r
1390 text_destination.Text = autoPath;
\r
1393 "You currently have \"Automatically name output files\" enabled for the destination file box, but you do not have a valid default directory set.\n\nYou should set a \"Default Path\" in HandBrakes preferences. (See 'Tools' menu -> 'Options' -> 'General' Tab -> 'Default Path')",
\r
1394 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1397 data_chpt.Rows.Clear();
\r
1398 if (selectedTitle.Chapters.Count != 1)
\r
1400 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1401 if (chapterGridView != null)
\r
1402 data_chpt = chapterGridView;
\r
1406 Check_ChapterMarkers.Checked = false;
\r
1407 Check_ChapterMarkers.Enabled = false;
\r
1410 // Hack to force the redraw of the scrollbars which don't resize properly when the control is disabled.
\r
1411 data_chpt.Columns[0].Width = 166;
\r
1412 data_chpt.Columns[0].Width = 165;
\r
1414 RegisterPresetEventHandler();
\r
1417 private void chapersChanged(object sender, EventArgs e)
\r
1419 if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.
\r
1422 Control ctl = (Control)sender;
\r
1423 int chapterStart, chapterEnd;
\r
1424 int.TryParse(drop_chapterStart.Text, out chapterStart);
\r
1425 int.TryParse(drop_chapterFinish.Text, out chapterEnd);
\r
1429 case "drop_chapterStart":
\r
1430 if (drop_chapterFinish.SelectedIndex == -1 && drop_chapterFinish.Items.Count != 0)
\r
1431 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1433 if (chapterEnd != 0)
\r
1434 if (chapterStart > chapterEnd)
\r
1435 drop_chapterFinish.Text = chapterStart.ToString();
\r
1437 case "drop_chapterFinish":
\r
1438 if (drop_chapterStart.Items.Count >= 1 && drop_chapterStart.SelectedIndex == -1)
\r
1439 drop_chapterStart.SelectedIndex = 0;
\r
1441 if (chapterStart != 0)
\r
1442 if (chapterEnd < chapterStart)
\r
1443 drop_chapterFinish.Text = chapterStart.ToString();
\r
1445 // Add more rows to the Chapter menu if needed.
\r
1446 if (Check_ChapterMarkers.Checked)
\r
1448 int i = data_chpt.Rows.Count, finish = 0;
\r
1449 int.TryParse(drop_chapterFinish.Text, out finish);
\r
1451 while (i < finish)
\r
1453 int n = data_chpt.Rows.Add();
\r
1454 data_chpt.Rows[n].Cells[0].Value = (i + 1);
\r
1455 data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
\r
1456 data_chpt.Rows[n].Cells[0].ValueType = typeof(int);
\r
1457 data_chpt.Rows[n].Cells[1].ValueType = typeof(string);
\r
1464 // Update the Duration
\r
1465 lbl_duration.Text =
\r
1466 Main.CalculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle)
\r
1469 // Run the Autonaming function
\r
1470 if (Properties.Settings.Default.autoNaming)
\r
1471 text_destination.Text = Main.AutoName(this);
\r
1473 // Disable chapter markers if only 1 chapter is selected.
\r
1474 if (chapterStart == chapterEnd)
\r
1476 Check_ChapterMarkers.Enabled = false;
\r
1477 btn_importChapters.Enabled = false;
\r
1478 data_chpt.Enabled = false;
\r
1482 Check_ChapterMarkers.Enabled = true;
\r
1483 if (Check_ChapterMarkers.Checked)
\r
1485 btn_importChapters.Enabled = true;
\r
1486 data_chpt.Enabled = true;
\r
1491 private void SecondsOrFramesChanged(object sender, EventArgs e)
\r
1494 int.TryParse(drop_chapterStart.Text, out start);
\r
1495 int.TryParse(drop_chapterFinish.Text, out end);
\r
1496 double duration = end - start;
\r
1498 switch (drop_mode.SelectedIndex)
\r
1501 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1504 if (selectedTitle != null)
\r
1506 duration = duration / selectedTitle.Fps;
\r
1507 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1510 lbl_duration.Text = "--:--:--";
\r
1516 private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)
\r
1519 this.drop_chapterFinish.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1520 this.drop_chapterStart.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1523 switch (drop_mode.SelectedIndex)
\r
1526 drop_chapterStart.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1527 drop_chapterFinish.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1528 if (drop_chapterStart.Items.Count != 0)
\r
1530 drop_chapterStart.SelectedIndex = 0;
\r
1531 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1534 lbl_duration.Text = "--:--:--";
\r
1537 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1538 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1539 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1540 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1541 if (selectedTitle != null)
\r
1543 drop_chapterStart.Text = "0";
\r
1544 drop_chapterFinish.Text = selectedTitle.Duration.TotalSeconds.ToString();
\r
1548 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1549 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1550 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1551 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1552 if (selectedTitle != null)
\r
1554 drop_chapterStart.Text = "0";
\r
1555 drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();
\r
1562 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
1564 // This removes the file extension from the filename box on the save file dialog.
\r
1565 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
1566 DVD_Save.FileName = Path.GetFileNameWithoutExtension(text_destination.Text);
\r
1568 if (Path.IsPathRooted(text_destination.Text))
\r
1569 DVD_Save.InitialDirectory = Path.GetDirectoryName(text_destination.Text);
\r
1571 // Show the dialog and set the main form file path
\r
1572 if (drop_format.SelectedIndex.Equals(0))
\r
1573 DVD_Save.FilterIndex = 1;
\r
1574 else if (drop_format.SelectedIndex.Equals(1))
\r
1575 DVD_Save.FilterIndex = 2;
\r
1577 if (DVD_Save.ShowDialog() == DialogResult.OK)
\r
1579 // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames
\r
1580 switch (DVD_Save.FilterIndex)
\r
1584 !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",
\r
1585 StringComparison.InvariantCultureIgnoreCase))
\r
1586 if (Properties.Settings.Default.useM4v)
\r
1587 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");
\r
1589 DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");
\r
1593 !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))
\r
1594 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");
\r
1600 text_destination.Text = DVD_Save.FileName;
\r
1602 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
1603 if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)
\r
1604 SetExtension(".m4v");
\r
1608 private void text_destination_TextChanged(object sender, EventArgs e)
\r
1610 string path = text_destination.Text;
\r
1611 if (path.EndsWith(".mp4") || path.EndsWith(".m4v"))
\r
1612 drop_format.SelectedIndex = 0;
\r
1613 else if (path.EndsWith(".mkv"))
\r
1614 drop_format.SelectedIndex = 1;
\r
1617 // Output Settings
\r
1618 private void drop_format_SelectedIndexChanged(object sender, EventArgs e)
\r
1620 switch (drop_format.SelectedIndex)
\r
1623 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||
\r
1624 AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())
\r
1625 SetExtension(".m4v");
\r
1627 SetExtension(".mp4");
\r
1630 SetExtension(".mkv");
\r
1634 AudioSettings.SetContainer(drop_format.Text);
\r
1636 if (drop_format.Text.Contains("MP4"))
\r
1638 if (drp_videoEncoder.Items.Contains("VP3 (Theora)"))
\r
1640 drp_videoEncoder.Items.Remove("VP3 (Theora)");
\r
1641 drp_videoEncoder.SelectedIndex = 1;
\r
1644 else if (drop_format.Text.Contains("MKV"))
\r
1645 drp_videoEncoder.Items.Add("VP3 (Theora)");
\r
1648 public void SetExtension(string newExtension)
\r
1650 if (newExtension == ".mp4" || newExtension == ".m4v")
\r
1651 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||
\r
1652 Subtitles.RequiresM4V())
\r
1653 newExtension = ".m4v";
\r
1655 newExtension = ".mp4";
\r
1657 if (Path.HasExtension(newExtension))
\r
1658 text_destination.Text = Path.ChangeExtension(text_destination.Text, newExtension);
\r
1662 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
1664 setContainerOpts();
\r
1666 // Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
1667 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1669 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
1670 check_turbo.Enabled = true;
\r
1672 tab_advanced.Enabled = true;
\r
1673 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1674 check_iPodAtom.Enabled = true;
\r
1676 check_iPodAtom.Enabled = false;
\r
1680 check_turbo.CheckState = CheckState.Unchecked;
\r
1681 check_turbo.Enabled = false;
\r
1682 tab_advanced.Enabled = false;
\r
1683 x264Panel.X264Query = string.Empty;
\r
1684 check_iPodAtom.Enabled = false;
\r
1685 check_iPodAtom.Checked = false;
\r
1688 // Setup the CQ Slider
\r
1689 switch (drp_videoEncoder.Text)
\r
1691 case "MPEG-4 (FFmpeg)":
\r
1692 if (slider_videoQuality.Value > 31)
\r
1693 slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.
\r
1694 slider_videoQuality.Minimum = 1;
\r
1695 slider_videoQuality.Maximum = 31;
\r
1697 case "H.264 (x264)":
\r
1698 slider_videoQuality.Minimum = 0;
\r
1699 slider_videoQuality.TickFrequency = 1;
\r
1701 CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
\r
1702 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1703 double multiplier = 1.0 / cqStep;
\r
1704 double value = slider_videoQuality.Value * multiplier;
\r
1706 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1708 if (value < slider_videoQuality.Maximum)
\r
1709 slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;
\r
1712 case "VP3 (Theora)":
\r
1713 if (slider_videoQuality.Value > 63)
\r
1714 slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.
\r
1715 slider_videoQuality.Minimum = 0;
\r
1716 slider_videoQuality.Maximum = 63;
\r
1722 /// When the FrameRate is not Same As Source, show the Max/Constant Mode dropdown
\r
1724 /// <param name="sender">
\r
1727 /// <param name="e">
\r
1730 private void drp_videoFramerate_SelectedIndexChanged(object sender, EventArgs e)
\r
1732 if (this.drp_videoFramerate.SelectedIndex == 0)
\r
1734 this.checkMaximumFramerate.Visible = false;
\r
1735 this.checkMaximumFramerate.CheckState = CheckState.Unchecked;
\r
1739 this.checkMaximumFramerate.Visible = true;
\r
1744 /// Set the container format options
\r
1746 public void setContainerOpts()
\r
1748 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1750 check_largeFile.Enabled = true;
\r
1751 check_optimiseMP4.Enabled = true;
\r
1752 check_iPodAtom.Enabled = true;
\r
1756 check_largeFile.Enabled = false;
\r
1757 check_optimiseMP4.Enabled = false;
\r
1758 check_iPodAtom.Enabled = false;
\r
1759 check_largeFile.Checked = false;
\r
1760 check_optimiseMP4.Checked = false;
\r
1761 check_iPodAtom.Checked = false;
\r
1765 private double cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1768 /// Update the CQ slider for x264 for a new CQ step. This is set from option
\r
1770 public void setQualityFromSlider()
\r
1772 // Work out the current RF value.
\r
1773 double cqStep = this.cachedCqStep;
\r
1774 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1776 // Change the maximum value for the slider
\r
1777 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1779 // Reset the CQ slider to RF0
\r
1780 slider_videoQuality.Value = slider_videoQuality.Maximum;
\r
1782 // Reset the CQ slider back to the previous value as close as possible
\r
1783 double cqStepNew = Properties.Settings.Default.x264cqstep;
\r
1784 double rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1785 while (rfValueCurrent < rfValue)
\r
1787 slider_videoQuality.Value--;
\r
1788 rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1791 // Cache the CQ step for the next calculation
\r
1792 this.cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1795 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
1797 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1798 switch (drp_videoEncoder.Text)
\r
1800 case "MPEG-4 (FFmpeg)":
\r
1801 lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);
\r
1803 case "H.264 (x264)":
\r
1804 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1805 rfValue = Math.Round(rfValue, 2);
\r
1806 lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));
\r
1808 case "VP3 (Theora)":
\r
1809 lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;
\r
1814 private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)
\r
1816 text_bitrate.Enabled = false;
\r
1817 text_filesize.Enabled = true;
\r
1818 slider_videoQuality.Enabled = false;
\r
1820 check_2PassEncode.Enabled = true;
\r
1823 private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)
\r
1825 text_bitrate.Enabled = true;
\r
1826 text_filesize.Enabled = false;
\r
1827 slider_videoQuality.Enabled = false;
\r
1829 check_2PassEncode.Enabled = true;
\r
1832 private void radio_cq_CheckedChanged(object sender, EventArgs e)
\r
1834 text_bitrate.Enabled = false;
\r
1835 text_filesize.Enabled = false;
\r
1836 slider_videoQuality.Enabled = true;
\r
1838 check_2PassEncode.Enabled = false;
\r
1839 check_2PassEncode.CheckState = CheckState.Unchecked;
\r
1842 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
1844 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
1846 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1847 check_turbo.Enabled = true;
\r
1851 check_turbo.Enabled = false;
\r
1852 check_turbo.CheckState = CheckState.Unchecked;
\r
1856 // Chapter Marker Tab
\r
1857 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
1859 if (Check_ChapterMarkers.Checked)
\r
1861 if (drop_format.SelectedIndex != 1)
\r
1862 SetExtension(".m4v");
\r
1863 data_chpt.Enabled = true;
\r
1864 btn_importChapters.Enabled = true;
\r
1868 if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v)
\r
1869 SetExtension(".mp4");
\r
1870 data_chpt.Enabled = false;
\r
1871 btn_importChapters.Enabled = false;
\r
1875 private void btn_importChapters_Click(object sender, EventArgs e)
\r
1877 if (File_ChapterImport.ShowDialog() == DialogResult.OK)
\r
1879 string filename = File_ChapterImport.FileName;
\r
1880 DataGridView imported = Main.ImportChapterNames(data_chpt, filename);
\r
1881 if (imported != null)
\r
1882 data_chpt = imported;
\r
1886 private void btn_export_Click(object sender, EventArgs e)
\r
1888 SaveFileDialog saveFileDialog = new SaveFileDialog();
\r
1889 saveFileDialog.Filter = "Csv File|*.csv";
\r
1890 saveFileDialog.DefaultExt = "csv";
\r
1891 if (saveFileDialog.ShowDialog() == DialogResult.OK)
\r
1893 string filename = saveFileDialog.FileName;
\r
1895 Main.SaveChapterMarkersToCsv(this, filename);
\r
1899 private void mnu_resetChapters_Click(object sender, EventArgs e)
\r
1901 data_chpt.Rows.Clear();
\r
1902 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1903 if (chapterGridView != null)
\r
1905 data_chpt = chapterGridView;
\r
1909 // Query Editor Tab
\r
1910 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
1912 rtf_query.Text = QueryGenerator.GenerateFullQuery(this);
\r
1915 private void btn_clear_Click(object sender, EventArgs e)
\r
1917 rtf_query.Clear();
\r
1922 // MainWindow Components, Actions and Functions ***********************
\r
1924 #region Source Scan
\r
1927 /// Start the Scan Process
\r
1929 /// <param name="filename">
\r
1932 /// <param name="title">
\r
1935 private void StartScan(string filename, int title)
\r
1937 // Setup the GUI components for the scan.
\r
1938 sourcePath = filename;
\r
1940 this.DisableGUI();
\r
1945 SourceScan.Scan(sourcePath, title);
\r
1946 SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);
\r
1947 SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);
\r
1949 catch (Exception exc)
\r
1951 MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1956 /// Update the Status label for the scan
\r
1958 /// <param name="sender">
\r
1961 /// <param name="e">
\r
1964 private void SourceScan_ScanStatusChanged(object sender, EventArgs e)
\r
1966 UpdateScanStatusLabel();
\r
1970 /// Update the UI after the scan has completed
\r
1972 /// <param name="sender">
\r
1975 /// <param name="e">
\r
1978 private void SourceScan_ScanCompleted(object sender, EventArgs e)
\r
1980 UpdateGuiAfterScan();
\r
1984 /// Update the Scan Status Label
\r
1986 private void UpdateScanStatusLabel()
\r
1988 if (InvokeRequired)
\r
1990 BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));
\r
1993 lbl_encode.Text = SourceScan.ScanStatus;
\r
1997 /// Reset the GUI when the scan has completed
\r
1999 private void UpdateGuiAfterScan()
\r
2001 if (InvokeRequired)
\r
2003 BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));
\r
2009 currentSource = SourceScan.SouceData;
\r
2011 // Setup some GUI components
\r
2012 drp_dvdtitle.Items.Clear();
\r
2013 if (currentSource.Titles.Count != 0)
\r
2014 drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());
\r
2016 foreach (Title title in currentSource.Titles)
\r
2018 if (title.MainTitle)
\r
2020 drp_dvdtitle.SelectedItem = title;
\r
2024 if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)
\r
2026 drp_dvdtitle.SelectedIndex = 0;
\r
2029 // Enable the creation of chapter markers if the file is an image of a dvd
\r
2030 if (drop_chapterStart.Items.Count > 0)
\r
2033 int.TryParse(drop_chapterStart.Items[0].ToString(), out start);
\r
2034 int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);
\r
2035 if (end > start) Check_ChapterMarkers.Enabled = true;
\r
2038 Check_ChapterMarkers.Enabled = false;
\r
2039 Check_ChapterMarkers.Checked = false;
\r
2040 data_chpt.Rows.Clear();
\r
2044 // If no titles were found, Display an error message
\r
2045 if (drp_dvdtitle.Items.Count == 0)
\r
2048 "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
2049 "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
2050 sourcePath = string.Empty;
\r
2052 UpdateSourceLabel();
\r
2054 // Enable the GUI components and enable any disabled components
\r
2057 catch (Exception exc)
\r
2059 MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,
\r
2060 MessageBoxIcon.Error);
\r
2066 /// Enable the GUI
\r
2068 private void EnableGUI()
\r
2072 if (InvokeRequired)
\r
2073 BeginInvoke(new UpdateWindowHandler(EnableGUI));
\r
2074 lbl_encode.Text = "Scan Completed";
\r
2075 foreach (Control ctrl in Controls)
\r
2076 ctrl.Enabled = true;
\r
2077 btn_start.Enabled = true;
\r
2078 btn_showQueue.Enabled = true;
\r
2079 btn_add2Queue.Enabled = true;
\r
2080 tb_preview.Enabled = true;
\r
2081 btn_source.Enabled = true;
\r
2082 mnu_killCLI.Visible = false;
\r
2084 catch (Exception exc)
\r
2086 MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2091 /// Disable the GUI
\r
2093 private void DisableGUI()
\r
2095 foreach (Control ctrl in Controls)
\r
2096 if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))
\r
2097 ctrl.Enabled = false;
\r
2099 lbl_encode.Visible = true;
\r
2100 lbl_encode.Text = "Scanning ...";
\r
2101 btn_source.Enabled = false;
\r
2102 btn_start.Enabled = false;
\r
2103 btn_showQueue.Enabled = false;
\r
2104 btn_add2Queue.Enabled = false;
\r
2105 tb_preview.Enabled = false;
\r
2106 mnu_killCLI.Visible = true;
\r
2112 private void KillScan()
\r
2114 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2118 SourceScan.Stop();
\r
2120 lbl_encode.Text = "Scan Cancelled!";
\r
2126 private void ResetGUI()
\r
2128 drp_dvdtitle.Items.Clear();
\r
2129 drop_chapterStart.Items.Clear();
\r
2130 drop_chapterFinish.Items.Clear();
\r
2131 lbl_duration.Text = "Select a Title";
\r
2132 PictureSettings.lbl_src_res.Text = "Select a Title";
\r
2133 sourcePath = String.Empty;
\r
2134 text_destination.Text = String.Empty;
\r
2135 selectedTitle = null;
\r
2139 /// Update the Source Label
\r
2141 private void UpdateSourceLabel()
\r
2143 labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;
\r
2145 if (selectedTitle != null)
\r
2146 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
2147 // If it's one of multiple source files, make sure we don't use the folder name
\r
2148 labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
2152 /// Take a job from the Queue, rescan it, and reload the GUI for that job.
\r
2154 /// <param name="job">
\r
2157 public void RecievingJob(Job job)
\r
2159 string query = job.Query;
\r
2160 StartScan(job.Source, job.Title);
\r
2162 if (query != null)
\r
2164 // Ok, Reset all the H264 widgets before changing the preset
\r
2165 x264Panel.Reset2Defaults();
\r
2167 // Send the query from the file to the Query Parser class
\r
2168 QueryParser presetQuery = QueryParser.Parse(query);
\r
2170 // Now load the preset
\r
2171 PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue");
\r
2173 // The x264 widgets will need updated, so do this now:
\r
2174 x264Panel.StandardizeOptString();
\r
2175 x264Panel.SetCurrentSettingsInPanel();
\r
2177 // Finally, let this window have a copy of the preset settings.
\r
2178 this.currentlySelectedPreset = null;
\r
2179 PictureSettings.SetPresetCropWarningLabel(null);
\r
2185 #region GUI Functions and Actions
\r
2188 /// Set the GUI to it's finished encoding state.
\r
2190 private void SetEncodeFinished()
\r
2194 if (InvokeRequired)
\r
2196 BeginInvoke(new UpdateWindowHandler(SetEncodeFinished));
\r
2200 lbl_encode.Text = "Encoding Finished";
\r
2201 ProgressBarStatus.Visible = false;
\r
2202 btn_start.Text = "Start";
\r
2203 btn_start.ToolTipText = "Start the encoding process";
\r
2204 btn_start.Image = Properties.Resources.Play;
\r
2206 // If the window is minimized, display the notification in a popup.
\r
2207 if (Properties.Settings.Default.trayIconAlerts)
\r
2208 if (FormWindowState.Minimized == this.WindowState)
\r
2210 notifyIcon.BalloonTipText = lbl_encode.Text;
\r
2211 notifyIcon.ShowBalloonTip(500);
\r
2214 catch (Exception exc)
\r
2216 MessageBox.Show(exc.ToString());
\r
2221 /// Set the GUI to it's started encoding state.
\r
2223 private void SetEncodeStarted()
\r
2227 if (InvokeRequired)
\r
2229 BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));
\r
2232 lbl_encode.Visible = true;
\r
2233 ProgressBarStatus.Value = 0;
\r
2234 ProgressBarStatus.Visible = true;
\r
2235 lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";
\r
2236 btn_start.Text = "Stop";
\r
2237 btn_start.ToolTipText = "Stop the encoding process.";
\r
2238 btn_start.Image = Properties.Resources.stop;
\r
2240 catch (Exception exc)
\r
2242 MessageBox.Show(exc.ToString());
\r
2247 /// Display the Encode Status
\r
2249 /// <param name="sender">
\r
2252 /// <param name="e">
\r
2255 private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)
\r
2257 if (this.InvokeRequired)
\r
2259 this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });
\r
2265 "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}, Encode(s) Pending {4}",
\r
2266 e.PercentComplete,
\r
2267 e.CurrentFrameRate,
\r
2268 e.AverageFrameRate,
\r
2269 e.EstimatedTimeLeft,
\r
2270 encodeQueue.Count);
\r
2272 ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);
\r
2276 /// Set the DVD Drive selection in the "Source" Menu
\r
2278 private void SetDriveSelectionMenuItem()
\r
2282 if (InvokeRequired)
\r
2284 BeginInvoke(new UpdateWindowHandler(SetDriveSelectionMenuItem));
\r
2288 drives = Main.GetDrives();
\r
2290 List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
\r
2291 foreach (DriveInformation drive in drives)
\r
2293 ToolStripMenuItem menuItem = new ToolStripMenuItem
\r
2295 Name = drive.ToString(),
\r
2296 Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",
\r
2297 Image = Resources.disc_small
\r
2299 menuItem.Click += new EventHandler(mnu_dvd_drive_Click);
\r
2300 menuItems.Add(menuItem);
\r
2303 foreach (ToolStripMenuItem item in menuItems)
\r
2304 btn_source.DropDownItems.Add(item);
\r
2306 catch (Exception exc)
\r
2308 MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);
\r
2313 /// Access the preset Handler and setup the preset panel.
\r
2315 private void LoadPresetPanel()
\r
2317 if (presetHandler.CheckIfPresetsAreOutOfDate())
\r
2318 if (!Settings.Default.presetNotification)
\r
2319 MessageBox.Show(this,
\r
2320 "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",
\r
2321 "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
2323 presetHandler.GetPresetPanel(ref treeView_presets);
\r
2324 treeView_presets.Update();
\r
2328 /// Get the title from the selected item in the title dropdown.
\r
2333 private int GetTitle()
\r
2336 if (drp_dvdtitle.SelectedItem != null)
\r
2338 string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');
\r
2339 int.TryParse(titleInfo[0], out title);
\r
2346 /// Handle the Update Check Finishing.
\r
2348 /// <param name="result">
\r
2351 private void UpdateCheckDoneMenu(IAsyncResult result)
\r
2353 // Make sure it's running on the calling thread
\r
2354 if (InvokeRequired)
\r
2356 Invoke(new MethodInvoker(() => this.UpdateCheckDoneMenu(result)));
\r
2359 UpdateCheckInformation info;
\r
2362 // Get the information about the new build, if any, and close the window
\r
2363 info = Main.EndCheckForUpdates(result);
\r
2365 if (info.NewVersionAvailable && info.BuildInformation != null)
\r
2367 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
2368 updateWindow.ShowDialog();
\r
2371 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,
\r
2372 MessageBoxIcon.Information);
\r
2373 lbl_updateCheck.Visible = false;
\r
2376 catch (Exception ex)
\r
2378 if ((bool)result.AsyncState)
\r
2380 "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,
\r
2381 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2390 /// Handle GUI shortcuts
\r
2392 /// <param name="msg">Message</param>
\r
2393 /// <param name="keyData">Keys</param>
\r
2394 /// <returns>Bool</returns>
\r
2395 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
2397 if (keyData == (Keys.Control | Keys.S))
\r
2399 btn_start_Click(this, new EventArgs());
\r
2403 if (keyData == (Keys.Control | Keys.A))
\r
2405 btn_add2Queue_Click(this, new EventArgs());
\r
2408 return base.ProcessCmdKey(ref msg, keyData);
\r
2412 /// If the queue is being processed, prompt the user to confirm application close.
\r
2414 /// <param name="e">FormClosingEventArgs</param>
\r
2415 protected override void OnFormClosing(FormClosingEventArgs e)
\r
2419 // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.
\r
2420 if (encodeQueue.IsEncoding)
\r
2422 DialogResult result =
\r
2424 "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
2425 "Close HandBrake?",
\r
2426 MessageBoxButtons.YesNo,
\r
2427 MessageBoxIcon.Question);
\r
2429 if (result == DialogResult.No)
\r
2435 encodeQueue.Stop();
\r
2438 if (SourceScan.IsScanning)
\r
2440 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2441 SourceScan.Stop();
\r
2444 catch (Exception exc)
\r
2446 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
2450 base.OnFormClosing(e);
\r
2456 // This is the END of the road ****************************************
\r