2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr/>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
9 using System.Collections.Generic;
\r
10 using System.ComponentModel;
\r
11 using System.Diagnostics;
\r
12 using System.Drawing;
\r
13 using System.Globalization;
\r
15 using System.Reflection;
\r
16 using System.Threading;
\r
17 using System.Windows.Forms;
\r
20 using HandBrake.ApplicationServices.Model;
\r
21 using HandBrake.ApplicationServices.Parsing;
\r
22 using HandBrake.ApplicationServices.Services;
\r
28 public partial class frmMain : Form
\r
30 // Objects which may be used by one or more other objects *************
\r
31 private Queue encodeQueue = new Queue();
\r
32 private PresetsHandler presetHandler = new PresetsHandler();
\r
34 // Windows ************************************************************
\r
35 private frmQueue queueWindow;
\r
36 private frmPreview qtpreview;
\r
37 private frmActivityWindow ActivityWindow;
\r
38 private frmSplashScreen splash = new frmSplashScreen();
\r
40 // Globals: Mainly used for tracking. *********************************
\r
41 public Title selectedTitle;
\r
42 public string sourcePath;
\r
43 private SourceType selectedSourceType;
\r
44 private string dvdDrivePath;
\r
45 private string dvdDriveLabel;
\r
46 private Preset CurrentlySelectedPreset;
\r
47 private DVD currentSource;
\r
48 private ScanService SourceScan = new ScanService();
\r
49 private List<DriveInformation> drives;
\r
50 private Thread encodeMonitor;
\r
52 // Delegates **********************************************************
\r
53 private delegate void UpdateWindowHandler();
\r
55 // Applicaiton Startup ************************************************
\r
60 /// Gets SourceName.
\r
62 public string SourceName
\r
66 if (this.selectedSourceType == SourceType.DvdDrive)
\r
68 return this.dvdDriveLabel;
\r
71 if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")
\r
72 return Path.GetFileNameWithoutExtension(this.sourcePath);
\r
74 return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));
\r
80 #region Application Startup
\r
84 // Load and setup the splash screen in this thread
\r
86 Label lblStatus = new Label { Size = new Size(150, 20), Location = new Point(182, 102) };
\r
87 splash.Controls.Add(lblStatus);
\r
89 InitializeComponent();
\r
91 // Update the users config file with the CLI version data.
\r
92 UpdateSplashStatus(lblStatus, "Checking CLI Version Data ...");
\r
93 Main.SetCliVersionData();
\r
94 Main.CheckForValidCliVersion();
\r
96 if (Settings.Default.hb_version.Contains("svn"))
\r
98 Version v = Assembly.GetExecutingAssembly().GetName().Version;
\r
99 this.Text += " " + v.ToString(4);
\r
102 // Show the form, but leave disabled until preloading is complete then show the main form)
\r
103 this.Enabled = false;
\r
105 Application.DoEvents(); // Forces frmMain to draw
\r
107 // Check for new versions, if update checking is enabled
\r
108 if (Properties.Settings.Default.updateStatus)
\r
110 DateTime now = DateTime.Now;
\r
111 DateTime lastCheck = Properties.Settings.Default.lastUpdateCheckDate;
\r
112 TimeSpan elapsed = now.Subtract(lastCheck);
\r
113 if (elapsed.TotalDays > Properties.Settings.Default.daysBetweenUpdateCheck)
\r
115 UpdateSplashStatus(lblStatus, "Checking for updates ...");
\r
116 Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false);
\r
120 // Clear the log files in the background
\r
121 if (Properties.Settings.Default.clearOldLogs)
\r
123 UpdateSplashStatus(lblStatus, "Clearing Old Log Files ..");
\r
124 Thread clearLog = new Thread(Main.ClearOldLogs);
\r
128 // Setup the GUI components
\r
129 UpdateSplashStatus(lblStatus, "Setting up the GUI ...");
\r
130 LoadPresetPanel(); // Load the Preset Panel
\r
131 treeView_presets.ExpandAll();
\r
132 lbl_encode.Text = string.Empty;
\r
133 drop_mode.SelectedIndex = 0;
\r
134 queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue
\r
135 if (!Properties.Settings.Default.QueryEditorTab)
\r
136 tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.
\r
137 if (Properties.Settings.Default.tooltipEnable)
\r
138 ToolTip.Active = true;
\r
140 // Load the user's default settings or Normal Preset
\r
141 if (Properties.Settings.Default.defaultPreset != string.Empty && presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)
\r
143 string query = presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).Query;
\r
146 x264Panel.Reset2Defaults();
\r
148 QueryParser presetQuery = QueryParser.Parse(query);
\r
149 PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset,
\r
150 presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).PictureSettings);
\r
152 x264Panel.X264_StandardizeOptString();
\r
153 x264Panel.X264_SetCurrentSettingsInPanel();
\r
157 loadNormalPreset();
\r
159 // Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)
\r
160 GrowlCommunicator.Register();
\r
162 // Finished Loading
\r
163 UpdateSplashStatus(lblStatus, "Loading Complete.");
\r
166 this.Enabled = true;
\r
168 // Event Handlers and Queue Recovery
\r
173 private void UpdateCheckDone(IAsyncResult result)
\r
175 if (InvokeRequired)
\r
177 Invoke(new MethodInvoker(() => UpdateCheckDone(result)));
\r
181 UpdateCheckInformation info;
\r
185 info = Main.EndCheckForUpdates(result);
\r
187 if (info.NewVersionAvailable)
\r
189 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
190 updateWindow.ShowDialog();
\r
193 catch (Exception ex)
\r
195 if ((bool)result.AsyncState)
\r
196 Main.ShowExceptiowWindow("Unable to check for updates, Please try again later.", ex.ToString());
\r
200 // Startup Functions
\r
201 private void queueRecovery()
\r
203 if (Main.CheckQueueRecovery())
\r
205 DialogResult result =
\r
207 "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?",
\r
208 "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
210 if (result == DialogResult.Yes)
\r
211 encodeQueue.LoadQueueFromFile("hb_queue_recovery.xml"); // Start Recovery
\r
214 // Remove the Queue recovery file if the user doesn't want to recovery the last queue.
\r
215 string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
\r
216 if (File.Exists(queuePath))
\r
217 File.Delete(queuePath);
\r
222 private void UpdateSplashStatus(Label status, string text)
\r
224 status.Text = text;
\r
225 Application.DoEvents();
\r
232 // Encoding Events for setting up the GUI
\r
233 private void events()
\r
235 // Handle Widget changes when preset is selected.
\r
236 RegisterPresetEventHandler();
\r
238 // Handle Window Resize
\r
239 if (Properties.Settings.Default.MainWindowMinimize)
\r
240 this.Resize += new EventHandler(frmMain_Resize);
\r
242 // Handle Encode Start / Finish / Pause
\r
243 encodeQueue.QueuePauseRequested += new EventHandler(encodePaused);
\r
244 encodeQueue.EncodeStarted += new EventHandler(encodeStarted);
\r
245 encodeQueue.EncodeEnded += new EventHandler(encodeEnded);
\r
247 // Handle a file being draged onto the GUI.
\r
248 this.DragEnter += new DragEventHandler(frmMain_DragEnter);
\r
249 this.DragDrop += new DragEventHandler(frmMain_DragDrop);
\r
252 // 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
253 private void RegisterPresetEventHandler()
\r
256 drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
257 check_largeFile.CheckedChanged += new EventHandler(changePresetLabel);
\r
258 check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel);
\r
259 check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);
\r
261 // Picture Settings
\r
262 PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);
\r
265 Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);
\r
268 drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
269 check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel);
\r
270 check_turbo.CheckedChanged += new EventHandler(changePresetLabel);
\r
271 text_filesize.TextChanged += new EventHandler(changePresetLabel);
\r
272 text_bitrate.TextChanged += new EventHandler(changePresetLabel);
\r
273 slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel);
\r
276 AudioSettings.AudioListChanged += new EventHandler(changePresetLabel);
\r
279 x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);
\r
282 private void UnRegisterPresetEventHandler()
\r
284 // Output Settings
\r
285 drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
286 check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel);
\r
287 check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel);
\r
288 check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);
\r
290 // Picture Settings
\r
291 PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);
\r
294 Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);
\r
297 drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
298 check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel);
\r
299 check_turbo.CheckedChanged -= new EventHandler(changePresetLabel);
\r
300 text_filesize.TextChanged -= new EventHandler(changePresetLabel);
\r
301 text_bitrate.TextChanged -= new EventHandler(changePresetLabel);
\r
302 slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel);
\r
305 AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel);
\r
308 x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);
\r
311 private void changePresetLabel(object sender, EventArgs e)
\r
313 labelPreset.Text = "Output Settings (Preset: Custom)";
\r
314 CurrentlySelectedPreset = null;
\r
317 private static void frmMain_DragEnter(object sender, DragEventArgs e)
\r
319 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
\r
320 e.Effect = DragDropEffects.All;
\r
323 private void frmMain_DragDrop(object sender, DragEventArgs e)
\r
325 string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
\r
326 sourcePath = string.Empty;
\r
328 if (fileList != null)
\r
330 if (!string.IsNullOrEmpty(fileList[0]))
\r
332 this.selectedSourceType = SourceType.VideoFile;
\r
333 StartScan(fileList[0], 0);
\r
336 UpdateSourceLabel();
\r
339 UpdateSourceLabel();
\r
342 private void encodeStarted(object sender, EventArgs e)
\r
344 SetEncodeStarted();
\r
346 // Experimental HBProc Process Monitoring.
\r
347 if (Properties.Settings.Default.enocdeStatusInGui)
\r
349 encodeMonitor = new Thread(EncodeMonitorThread);
\r
350 encodeMonitor.Start();
\r
354 private void encodeEnded(object sender, EventArgs e)
\r
356 SetEncodeFinished();
\r
359 private void encodePaused(object sender, EventArgs e)
\r
361 SetEncodeFinished();
\r
366 // User Interface Menus / Tool Strips *********************************
\r
371 /// Kill The scan menu Item
\r
373 /// <param name="sender">
\r
376 /// <param name="e">
\r
379 private void mnu_killCLI_Click(object sender, EventArgs e)
\r
385 /// Exit the Application Menu Item
\r
387 /// <param name="sender">
\r
390 /// <param name="e">
\r
393 private void mnu_exit_Click(object sender, EventArgs e)
\r
395 Application.Exit();
\r
403 /// Menu - Start Button
\r
405 /// <param name="sender">
\r
408 /// <param name="e">
\r
411 private void mnu_encode_Click(object sender, EventArgs e)
\r
413 queueWindow.Show();
\r
417 /// Menu - Display the Log Window
\r
419 /// <param name="sender">
\r
422 /// <param name="e">
\r
425 private void mnu_encodeLog_Click(object sender, EventArgs e)
\r
427 frmActivityWindow dvdInfoWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
428 dvdInfoWindow.Show();
\r
432 /// Menu - Display the Options Window
\r
434 /// <param name="sender">
\r
437 /// <param name="e">
\r
440 private void mnu_options_Click(object sender, EventArgs e)
\r
442 Form options = new frmOptions(this);
\r
443 options.ShowDialog();
\r
448 #region Presets Menu
\r
451 /// Reset the Built in Presets
\r
453 /// <param name="sender">
\r
456 /// <param name="e">
\r
459 private void mnu_presetReset_Click(object sender, EventArgs e)
\r
461 presetHandler.UpdateBuiltInPresets();
\r
463 if (treeView_presets.Nodes.Count == 0)
\r
465 "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
466 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
468 MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
470 treeView_presets.ExpandAll();
\r
474 /// Delete the selected preset
\r
476 /// <param name="sender">
\r
479 /// <param name="e">
\r
482 private void mnu_delete_preset_Click(object sender, EventArgs e)
\r
484 presetHandler.RemoveBuiltInPresets();
\r
485 LoadPresetPanel(); // Reload the preset panel
\r
489 /// Select the Normal preset
\r
491 /// <param name="sender">
\r
494 /// <param name="e">
\r
497 private void mnu_SelectDefault_Click(object sender, EventArgs e)
\r
499 loadNormalPreset();
\r
503 /// Import a plist Preset
\r
505 /// <param name="sender">
\r
508 /// <param name="e">
\r
511 private void mnu_importMacPreset_Click(object sender, EventArgs e)
\r
517 /// Export a Plist Preset
\r
519 /// <param name="sender">
\r
522 /// <param name="e">
\r
525 private void mnu_exportMacPreset_Click(object sender, EventArgs e)
\r
531 /// Create a new Preset
\r
533 /// <param name="sender">
\r
536 /// <param name="e">
\r
539 private void btn_new_preset_Click(object sender, EventArgs e)
\r
541 Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),
\r
543 preset.ShowDialog();
\r
551 /// Menu - Display the User Guide Web Page
\r
553 /// <param name="sender">
\r
556 /// <param name="e">
\r
559 private void mnu_user_guide_Click(object sender, EventArgs e)
\r
561 Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");
\r
565 /// Menu - Check for Updates
\r
567 /// <param name="sender">
\r
570 /// <param name="e">
\r
573 private void mnu_UpdateCheck_Click(object sender, EventArgs e)
\r
575 lbl_updateCheck.Visible = true;
\r
576 Main.BeginCheckForUpdates(new AsyncCallback(updateCheckDoneMenu), false);
\r
580 /// Menu - Display the About Window
\r
582 /// <param name="sender">
\r
585 /// <param name="e">
\r
588 private void mnu_about_Click(object sender, EventArgs e)
\r
590 using (frmAbout About = new frmAbout())
\r
592 About.ShowDialog();
\r
601 /// RMenu - Expand All
\r
603 /// <param name="sender">
\r
606 /// <param name="e">
\r
609 private void pmnu_expandAll_Click(object sender, EventArgs e)
\r
611 treeView_presets.ExpandAll();
\r
615 /// RMenu - Collaspe All
\r
617 /// <param name="sender">
\r
620 /// <param name="e">
\r
623 private void pmnu_collapse_Click(object sender, EventArgs e)
\r
625 treeView_presets.CollapseAll();
\r
629 /// Menu - Import Preset
\r
631 /// <param name="sender">
\r
634 /// <param name="e">
\r
637 private void pmnu_import_Click(object sender, EventArgs e)
\r
643 /// RMenu - Save Changes to Preset
\r
645 /// <param name="sender">
\r
648 /// <param name="e">
\r
651 private void pmnu_saveChanges_Click(object sender, EventArgs e)
\r
653 DialogResult result =
\r
655 "Do you wish to include picture settings when updating the preset: " +
\r
656 treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,
\r
657 MessageBoxIcon.Question);
\r
658 if (result == DialogResult.Yes)
\r
659 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
660 QueryGenerator.GenerateTabbedComponentsQuery(this), true);
\r
661 else if (result == DialogResult.No)
\r
662 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
663 QueryGenerator.GenerateTabbedComponentsQuery(this), false);
\r
667 /// RMenu - Delete Preset
\r
669 /// <param name="sender">
\r
672 /// <param name="e">
\r
675 private void pmnu_delete_click(object sender, EventArgs e)
\r
677 if (treeView_presets.SelectedNode != null)
\r
679 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
680 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
682 treeView_presets.Select();
\r
686 /// Preset Menu Is Opening. Setup the Menu
\r
688 /// <param name="sender">
\r
691 /// <param name="e">
\r
694 private void presets_menu_Opening(object sender, CancelEventArgs e)
\r
696 // Make sure that the save menu is always disabled by default
\r
697 pmnu_saveChanges.Enabled = false;
\r
699 // Now enable the save menu if the selected preset is a user preset
\r
700 if (treeView_presets.SelectedNode != null)
\r
701 if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))
\r
702 pmnu_saveChanges.Enabled = true;
\r
704 treeView_presets.Select();
\r
707 // Presets Management
\r
710 /// Button - Add a preset
\r
712 /// <param name="sender">
\r
715 /// <param name="e">
\r
718 private void btn_addPreset_Click(object sender, EventArgs e)
\r
720 Form preset = new frmAddPreset(this, QueryGenerator.GenerateTabbedComponentsQuery(this), presetHandler);
\r
721 preset.ShowDialog();
\r
725 /// Button - remove a Preset
\r
727 /// <param name="sender">
\r
730 /// <param name="e">
\r
733 private void btn_removePreset_Click(object sender, EventArgs e)
\r
735 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
736 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
737 if (result == DialogResult.Yes)
\r
739 if (treeView_presets.SelectedNode != null)
\r
741 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
742 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
745 treeView_presets.Select();
\r
749 /// Button - Set the selected preset as the default
\r
751 /// <param name="sender">
\r
754 /// <param name="e">
\r
757 private void btn_setDefault_Click(object sender, EventArgs e)
\r
759 if (treeView_presets.SelectedNode != null)
\r
761 DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",
\r
762 "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
763 if (result == DialogResult.Yes)
\r
765 Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;
\r
766 Properties.Settings.Default.Save();
\r
767 MessageBox.Show("New default preset set.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
771 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
775 /// PresetBar Mouse Down event
\r
777 /// <param name="sender">
\r
780 /// <param name="e">
\r
783 private void treeview_presets_mouseUp(object sender, MouseEventArgs e)
\r
785 if (e.Button == MouseButtons.Right)
\r
786 treeView_presets.SelectedNode = treeView_presets.GetNodeAt(e.Location);
\r
787 else if (e.Button == MouseButtons.Left)
\r
789 if (treeView_presets.GetNodeAt(e.Location) != null)
\r
791 if (labelPreset.Text.Contains(treeView_presets.GetNodeAt(e.Location).Text))
\r
796 treeView_presets.Select();
\r
800 /// Preset Bar after selecting the preset
\r
802 /// <param name="sender">
\r
805 /// <param name="e">
\r
808 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
814 /// Preset Bar - Handle the Delete Key
\r
816 /// <param name="sender">
\r
819 /// <param name="e">
\r
822 private void treeView_presets_deleteKey(object sender, KeyEventArgs e)
\r
824 if (e.KeyCode == Keys.Delete)
\r
826 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
827 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
828 if (result == DialogResult.Yes)
\r
830 if (treeView_presets.SelectedNode != null)
\r
831 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
833 // Remember each nodes expanded status so we can reload it
\r
834 List<bool> nodeStatus = new List<bool>();
\r
835 foreach (TreeNode node in treeView_presets.Nodes)
\r
836 nodeStatus.Add(node.IsExpanded);
\r
838 // Now reload the preset panel
\r
841 // And finally, re-expand any of the nodes if required
\r
843 foreach (TreeNode node in treeView_presets.Nodes)
\r
855 /// Select the selected preset and setup the GUI
\r
857 private void selectPreset()
\r
859 if (treeView_presets.SelectedNode != null)
\r
861 // Ok, so, we've selected a preset. Now we want to load it.
\r
862 string presetName = treeView_presets.SelectedNode.Text;
\r
863 Preset preset = presetHandler.GetPreset(presetName);
\r
864 if (preset != null)
\r
866 string query = presetHandler.GetPreset(presetName).Query;
\r
867 bool loadPictureSettings = presetHandler.GetPreset(presetName).PictureSettings;
\r
871 // Ok, Reset all the H264 widgets before changing the preset
\r
872 x264Panel.Reset2Defaults();
\r
874 // Send the query from the file to the Query Parser class
\r
875 QueryParser presetQuery = QueryParser.Parse(query);
\r
877 // Now load the preset
\r
878 PresetLoader.LoadPreset(this, presetQuery, presetName, loadPictureSettings);
\r
880 // The x264 widgets will need updated, so do this now:
\r
881 x264Panel.X264_StandardizeOptString();
\r
882 x264Panel.X264_SetCurrentSettingsInPanel();
\r
884 // Finally, let this window have a copy of the preset settings.
\r
885 CurrentlySelectedPreset = preset;
\r
886 PictureSettings.SetPresetCropWarningLabel(preset);
\r
893 /// Load the Normal Preset
\r
895 private void loadNormalPreset()
\r
897 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
899 foreach (TreeNode node in treenode.Nodes)
\r
901 if (node.Text.Equals("Normal"))
\r
902 treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0];
\r
908 /// Import a plist preset
\r
910 private void ImportPreset()
\r
912 if (openPreset.ShowDialog() == DialogResult.OK)
\r
914 QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);
\r
915 if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))
\r
917 DialogResult result =
\r
918 MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",
\r
919 "Overwrite preset?",
\r
920 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
921 if (result == DialogResult.Yes)
\r
923 PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);
\r
924 presetHandler.Update(parsed.PresetName + " (Imported)",
\r
925 QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),
\r
926 parsed.UsesPictureSettings);
\r
931 PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);
\r
932 if (presetHandler.Add(parsed.PresetName + " (Imported)",
\r
933 QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),
\r
934 parsed.UsesPictureSettings))
\r
936 TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")
\r
938 ForeColor = Color.Black
\r
940 treeView_presets.Nodes.Add(preset_treeview);
\r
947 /// Export a plist Preset
\r
949 private void ExportPreset()
\r
951 MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
954 SaveFileDialog savefiledialog = new SaveFileDialog();
\r
955 savefiledialog.Filter = "plist|*.plist";
\r
957 if (treeView_presets.SelectedNode != null)
\r
960 if (savefiledialog.ShowDialog() == DialogResult.OK)
\r
962 Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);
\r
963 PlistPresetHandler.Export(savefiledialog.FileName, preset);
\r
973 /// 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
975 /// <param name="sender">
\r
978 /// <param name="e">
\r
981 private void btn_source_Click(object sender, EventArgs e)
\r
983 // Remove old Drive Menu Items.
\r
984 List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();
\r
985 foreach (var item in btn_source.DropDownItems)
\r
987 if (item.GetType() == typeof(ToolStripMenuItem))
\r
989 ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
\r
990 if (menuItem.Name.StartsWith("Drive"))
\r
992 itemsToRemove.Add(menuItem);
\r
997 foreach (ToolStripMenuItem item in itemsToRemove)
\r
998 btn_source.DropDownItems.Remove(item);
\r
1000 Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);
\r
1001 driveInfoThread.Start();
\r
1005 /// Toolbar - Start The Encode
\r
1007 /// <param name="sender">
\r
1010 /// <param name="e">
\r
1013 private void btn_start_Click(object sender, EventArgs e)
\r
1015 if (btn_start.Text == "Stop")
\r
1017 DialogResult result;
\r
1018 if (Properties.Settings.Default.enocdeStatusInGui &&
\r
1019 !Properties.Settings.Default.showCliForInGuiEncodeStatus)
\r
1021 result = MessageBox.Show(
\r
1022 "Are you sure you wish to cancel the encode?\n\nPlease note, when 'Enable in-GUI encode status' is enabled, stopping this encode will render the file unplayable. ",
\r
1023 "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1027 result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?",
\r
1028 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1031 if (result == DialogResult.Yes)
\r
1033 // Pause The Queue
\r
1034 encodeQueue.Pause();
\r
1036 if (Properties.Settings.Default.enocdeStatusInGui &&
\r
1037 !Properties.Settings.Default.showCliForInGuiEncodeStatus)
\r
1039 encodeQueue.Stop();
\r
1040 if (encodeQueue.HbProcess != null)
\r
1041 encodeQueue.HbProcess.WaitForExit();
\r
1045 encodeQueue.SafelyClose();
\r
1051 if (encodeQueue.Count != 0 ||
\r
1052 (!string.IsNullOrEmpty(sourcePath) && !string.IsNullOrEmpty(text_destination.Text)))
\r
1054 string generatedQuery = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);
\r
1055 string specifiedQuery = rtf_query.Text != string.Empty
\r
1057 : QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);
\r
1058 string query = string.Empty;
\r
1060 // Check to make sure the generated query matches the GUI settings
\r
1061 if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) &&
\r
1062 generatedQuery != specifiedQuery)
\r
1064 DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " +
\r
1065 "does not match the current GUI settings.\n\nBecause the manual query takes " +
\r
1066 "priority over the GUI, your recently updated settings will not be taken " +
\r
1067 "into account when encoding this job." +
\r
1068 Environment.NewLine + Environment.NewLine +
\r
1069 "Do you want to replace the manual query with the updated GUI-generated query?",
\r
1070 "Manual Query does not Match GUI",
\r
1071 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,
\r
1072 MessageBoxDefaultButton.Button3);
\r
1076 case DialogResult.Yes:
\r
1077 // Replace the manual query with the generated one
\r
1078 query = generatedQuery;
\r
1079 rtf_query.Text = generatedQuery;
\r
1081 case DialogResult.No:
\r
1082 // Use the manual query
\r
1083 query = specifiedQuery;
\r
1085 case DialogResult.Cancel:
\r
1086 // Don't start the encode
\r
1092 query = specifiedQuery;
\r
1095 DialogResult overwrite = DialogResult.Yes;
\r
1096 if (text_destination.Text != string.Empty)
\r
1097 if (File.Exists(text_destination.Text))
\r
1100 "The destination file already exists. Are you sure you want to overwrite it?",
\r
1101 "Overwrite File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1103 if (overwrite == DialogResult.Yes)
\r
1105 if (encodeQueue.Count == 0)
\r
1106 encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));
\r
1108 queueWindow.SetQueue();
\r
1109 if (encodeQueue.Count > 1)
\r
1110 queueWindow.Show(false);
\r
1112 SetEncodeStarted(); // Encode is running, so setup the GUI appropriately
\r
1113 encodeQueue.Start(); // Start The Queue Encoding Process
\r
1118 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1119 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1120 MessageBoxIcon.Warning);
\r
1125 /// Toolbar - Add the current job to the Queue
\r
1127 /// <param name="sender">
\r
1130 /// <param name="e">
\r
1133 private void btn_add2Queue_Click(object sender, EventArgs e)
\r
1135 if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1136 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1139 if (!Directory.Exists(Path.GetDirectoryName(text_destination.Text)))
\r
1141 MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1145 string query = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);
\r
1146 if (rtf_query.Text != string.Empty)
\r
1147 query = rtf_query.Text;
\r
1149 if (encodeQueue.CheckForDestinationDuplicate(text_destination.Text))
\r
1151 DialogResult result =
\r
1153 "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
1154 "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
1155 if (result == DialogResult.Yes)
\r
1156 encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));
\r
1159 encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));
\r
1161 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";
\r
1163 queueWindow.Show();
\r
1168 /// Toolbar - Show the Queue
\r
1170 /// <param name="sender">
\r
1173 /// <param name="e">
\r
1176 private void btn_showQueue_Click(object sender, EventArgs e)
\r
1178 queueWindow.Show();
\r
1179 queueWindow.Activate();
\r
1183 /// Toolbar - Show the Preview Window
\r
1185 /// <param name="sender">
\r
1188 /// <param name="e">
\r
1191 private void tb_preview_Click(object sender, EventArgs e)
\r
1193 if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1194 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1195 MessageBoxIcon.Warning);
\r
1198 if (qtpreview == null)
\r
1200 qtpreview = new frmPreview(this);
\r
1203 else if (qtpreview.IsDisposed)
\r
1205 qtpreview = new frmPreview(this);
\r
1209 MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,
\r
1210 MessageBoxIcon.Warning);
\r
1215 /// Toolbar - Show the Activity log Window
\r
1217 /// <param name="sender">
\r
1220 /// <param name="e">
\r
1223 private void btn_ActivityWindow_Click(object sender, EventArgs e)
\r
1225 if (ActivityWindow == null || !ActivityWindow.IsHandleCreated)
\r
1226 ActivityWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
1228 ActivityWindow.Show();
\r
1229 ActivityWindow.Activate();
\r
1234 #region System Tray Icon
\r
1237 /// Handle Resizing of the main window when deaing with the Notify Icon
\r
1239 /// <param name="sender">
\r
1242 /// <param name="e">
\r
1245 private void frmMain_Resize(object sender, EventArgs e)
\r
1247 if (FormWindowState.Minimized == this.WindowState)
\r
1249 notifyIcon.Visible = true;
\r
1252 else if (FormWindowState.Normal == this.WindowState)
\r
1253 notifyIcon.Visible = false;
\r
1257 /// Double Click the Tray Icon
\r
1259 /// <param name="sender">
\r
1262 /// <param name="e">
\r
1265 private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
\r
1267 this.Visible = true;
\r
1269 this.WindowState = FormWindowState.Normal;
\r
1270 notifyIcon.Visible = false;
\r
1274 /// Tray Icon - Restore Menu Item - Resture the Window
\r
1276 /// <param name="sender">
\r
1279 /// <param name="e">
\r
1282 private void btn_restore_Click(object sender, EventArgs e)
\r
1284 this.Visible = true;
\r
1286 this.WindowState = FormWindowState.Normal;
\r
1287 notifyIcon.Visible = false;
\r
1292 #region Main Window and Tab Control
\r
1295 private void btn_dvd_source_Click(object sender, EventArgs e)
\r
1297 if (DVD_Open.ShowDialog() == DialogResult.OK)
\r
1299 this.selectedSourceType = SourceType.Folder;
\r
1300 SelectSource(DVD_Open.SelectedPath);
\r
1303 UpdateSourceLabel();
\r
1306 private void btn_file_source_Click(object sender, EventArgs e)
\r
1308 if (ISO_Open.ShowDialog() == DialogResult.OK)
\r
1310 this.selectedSourceType = SourceType.VideoFile;
\r
1311 SelectSource(ISO_Open.FileName);
\r
1314 UpdateSourceLabel();
\r
1317 private void mnu_dvd_drive_Click(object sender, EventArgs e)
\r
1319 ToolStripMenuItem item = sender as ToolStripMenuItem;
\r
1322 string driveId = item.Name.Replace("Drive", string.Empty);
\r
1324 if (int.TryParse(driveId, out id))
\r
1327 this.dvdDrivePath = drives[id].RootDirectory;
\r
1328 this.dvdDriveLabel = drives[id].VolumeLabel;
\r
1330 if (this.dvdDrivePath == null) return;
\r
1331 this.selectedSourceType = SourceType.DvdDrive;
\r
1332 SelectSource(this.dvdDrivePath);
\r
1337 private void SelectSource(string file)
\r
1339 Check_ChapterMarkers.Enabled = true;
\r
1340 sourcePath = string.Empty;
\r
1342 if (file == string.Empty) // Must have a file or path
\r
1344 UpdateSourceLabel();
\r
1348 sourcePath = Path.GetFileName(file);
\r
1349 StartScan(file, 0);
\r
1352 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
1354 if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))
\r
1356 "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",
\r
1357 "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
1360 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1362 UnRegisterPresetEventHandler();
\r
1363 drop_mode.SelectedIndex = 0;
\r
1365 drop_chapterStart.Items.Clear();
\r
1366 drop_chapterFinish.Items.Clear();
\r
1368 // If the dropdown is set to automatic nothing else needs to be done.
\r
1369 // Otheriwse if its not, title data has to be loaded from parsing.
\r
1370 if (drp_dvdtitle.Text != "Automatic")
\r
1372 selectedTitle = drp_dvdtitle.SelectedItem as Title;
\r
1373 lbl_duration.Text = selectedTitle.Duration.ToString();
\r
1374 PictureSettings.CurrentlySelectedPreset = CurrentlySelectedPreset;
\r
1375 PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control
\r
1377 // Populate the Angles dropdown
\r
1378 drop_angle.Items.Clear();
\r
1379 if (!Properties.Settings.Default.noDvdNav)
\r
1381 drop_angle.Visible = true;
\r
1382 lbl_angle.Visible = true;
\r
1384 for (int i = 1; i <= selectedTitle.AngleCount; i++)
\r
1385 drop_angle.Items.Add(i.ToString());
\r
1387 if (drop_angle.Items.Count != 0)
\r
1388 drop_angle.SelectedIndex = 0;
\r
1392 drop_angle.Visible = false;
\r
1393 lbl_angle.Visible = false;
\r
1396 // Populate the Start chapter Dropdown
\r
1397 drop_chapterStart.Items.Clear();
\r
1398 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1399 if (drop_chapterStart.Items.Count > 0)
\r
1400 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
1402 // Populate the Final Chapter Dropdown
\r
1403 drop_chapterFinish.Items.Clear();
\r
1404 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1405 if (drop_chapterFinish.Items.Count > 0)
\r
1406 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
1408 // Populate the Audio Channels Dropdown
\r
1409 AudioSettings.SetTrackList(selectedTitle, CurrentlySelectedPreset);
\r
1411 // Populate the Subtitles dropdown
\r
1412 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());
\r
1414 // Update the source label if we have multiple streams
\r
1415 if (selectedTitle != null)
\r
1416 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
1417 labelSource.Text = labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
1419 // Run the AutoName & ChapterNaming functions
\r
1420 if (Properties.Settings.Default.autoNaming)
\r
1422 string autoPath = Main.AutoName(this);
\r
1423 if (autoPath != null)
\r
1424 text_destination.Text = autoPath;
\r
1427 "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
1428 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1431 data_chpt.Rows.Clear();
\r
1432 if (selectedTitle.Chapters.Count != 1)
\r
1434 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1435 if (chapterGridView != null)
\r
1436 data_chpt = chapterGridView;
\r
1440 Check_ChapterMarkers.Checked = false;
\r
1441 Check_ChapterMarkers.Enabled = false;
\r
1444 // Hack to force the redraw of the scrollbars which don't resize properly when the control is disabled.
\r
1445 data_chpt.Columns[0].Width = 166;
\r
1446 data_chpt.Columns[0].Width = 165;
\r
1448 RegisterPresetEventHandler();
\r
1451 private void chapersChanged(object sender, EventArgs e)
\r
1453 if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.
\r
1456 Control ctl = (Control)sender;
\r
1457 int chapterStart, chapterEnd;
\r
1458 int.TryParse(drop_chapterStart.Text, out chapterStart);
\r
1459 int.TryParse(drop_chapterFinish.Text, out chapterEnd);
\r
1463 case "drop_chapterStart":
\r
1464 if (drop_chapterFinish.SelectedIndex == -1 && drop_chapterFinish.Items.Count != 0)
\r
1465 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1467 if (chapterEnd != 0)
\r
1468 if (chapterStart > chapterEnd)
\r
1469 drop_chapterFinish.Text = chapterStart.ToString();
\r
1471 case "drop_chapterFinish":
\r
1472 if (drop_chapterStart.Items.Count >= 1 && drop_chapterStart.SelectedIndex == -1)
\r
1473 drop_chapterStart.SelectedIndex = 0;
\r
1475 if (chapterStart != 0)
\r
1476 if (chapterEnd < chapterStart)
\r
1477 drop_chapterFinish.Text = chapterStart.ToString();
\r
1479 // Add more rows to the Chapter menu if needed.
\r
1480 if (Check_ChapterMarkers.Checked)
\r
1482 int i = data_chpt.Rows.Count, finish = 0;
\r
1483 int.TryParse(drop_chapterFinish.Text, out finish);
\r
1485 while (i < finish)
\r
1487 int n = data_chpt.Rows.Add();
\r
1488 data_chpt.Rows[n].Cells[0].Value = (i + 1);
\r
1489 data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
\r
1490 data_chpt.Rows[n].Cells[0].ValueType = typeof(int);
\r
1491 data_chpt.Rows[n].Cells[1].ValueType = typeof(string);
\r
1498 // Update the Duration
\r
1499 lbl_duration.Text =
\r
1500 Main.CalculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle)
\r
1503 // Run the Autonaming function
\r
1504 if (Properties.Settings.Default.autoNaming)
\r
1505 text_destination.Text = Main.AutoName(this);
\r
1507 // Disable chapter markers if only 1 chapter is selected.
\r
1508 if (chapterStart == chapterEnd)
\r
1510 Check_ChapterMarkers.Enabled = false;
\r
1511 btn_importChapters.Enabled = false;
\r
1512 data_chpt.Enabled = false;
\r
1516 Check_ChapterMarkers.Enabled = true;
\r
1517 if (Check_ChapterMarkers.Checked)
\r
1519 btn_importChapters.Enabled = true;
\r
1520 data_chpt.Enabled = true;
\r
1525 private void SecondsOrFramesChanged(object sender, EventArgs e)
\r
1528 int.TryParse(drop_chapterStart.Text, out start);
\r
1529 int.TryParse(drop_chapterFinish.Text, out end);
\r
1530 double duration = end - start;
\r
1532 switch (drop_mode.SelectedIndex)
\r
1535 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1538 if (selectedTitle != null)
\r
1540 duration = duration / selectedTitle.Fps;
\r
1541 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1544 lbl_duration.Text = "--:--:--";
\r
1550 private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)
\r
1553 this.drop_chapterFinish.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1554 this.drop_chapterStart.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1557 switch (drop_mode.SelectedIndex)
\r
1560 drop_chapterStart.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1561 drop_chapterFinish.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1562 if (drop_chapterStart.Items.Count != 0)
\r
1564 drop_chapterStart.SelectedIndex = 0;
\r
1565 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1568 lbl_duration.Text = "--:--:--";
\r
1571 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1572 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1573 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1574 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1575 if (selectedTitle != null)
\r
1577 drop_chapterStart.Text = "0";
\r
1578 drop_chapterFinish.Text = selectedTitle.Duration.TotalSeconds.ToString();
\r
1582 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1583 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1584 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1585 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1586 if (selectedTitle != null)
\r
1588 drop_chapterStart.Text = "0";
\r
1589 drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();
\r
1596 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
1598 // This removes the file extension from the filename box on the save file dialog.
\r
1599 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
1600 DVD_Save.FileName = Path.GetFileNameWithoutExtension(text_destination.Text);
\r
1602 if (Path.IsPathRooted(text_destination.Text))
\r
1603 DVD_Save.InitialDirectory = Path.GetDirectoryName(text_destination.Text);
\r
1605 // Show the dialog and set the main form file path
\r
1606 if (drop_format.SelectedIndex.Equals(0))
\r
1607 DVD_Save.FilterIndex = 1;
\r
1608 else if (drop_format.SelectedIndex.Equals(1))
\r
1609 DVD_Save.FilterIndex = 2;
\r
1611 if (DVD_Save.ShowDialog() == DialogResult.OK)
\r
1613 // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames
\r
1614 switch (DVD_Save.FilterIndex)
\r
1618 !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",
\r
1619 StringComparison.InvariantCultureIgnoreCase))
\r
1620 if (Properties.Settings.Default.useM4v)
\r
1621 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");
\r
1623 DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");
\r
1627 !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))
\r
1628 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");
\r
1634 text_destination.Text = DVD_Save.FileName;
\r
1636 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
1637 if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)
\r
1638 SetExtension(".m4v");
\r
1642 private void text_destination_TextChanged(object sender, EventArgs e)
\r
1644 string path = text_destination.Text;
\r
1645 if (path.EndsWith(".mp4") || path.EndsWith(".m4v"))
\r
1646 drop_format.SelectedIndex = 0;
\r
1647 else if (path.EndsWith(".mkv"))
\r
1648 drop_format.SelectedIndex = 1;
\r
1651 // Output Settings
\r
1652 private void drop_format_SelectedIndexChanged(object sender, EventArgs e)
\r
1654 switch (drop_format.SelectedIndex)
\r
1657 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||
\r
1658 AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())
\r
1659 SetExtension(".m4v");
\r
1661 SetExtension(".mp4");
\r
1664 SetExtension(".mkv");
\r
1668 AudioSettings.SetContainer(drop_format.Text);
\r
1670 if (drop_format.Text.Contains("MP4"))
\r
1672 if (drp_videoEncoder.Items.Contains("VP3 (Theora)"))
\r
1674 drp_videoEncoder.Items.Remove("VP3 (Theora)");
\r
1675 drp_videoEncoder.SelectedIndex = 1;
\r
1678 else if (drop_format.Text.Contains("MKV"))
\r
1679 drp_videoEncoder.Items.Add("VP3 (Theora)");
\r
1682 public void SetExtension(string newExtension)
\r
1684 if (newExtension == ".mp4" || newExtension == ".m4v")
\r
1685 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||
\r
1686 Subtitles.RequiresM4V())
\r
1687 newExtension = ".m4v";
\r
1689 newExtension = ".mp4";
\r
1691 if (Path.HasExtension(newExtension))
\r
1692 text_destination.Text = Path.ChangeExtension(text_destination.Text, newExtension);
\r
1696 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
1698 setContainerOpts();
\r
1700 // Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
1701 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1703 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
1704 check_turbo.Enabled = true;
\r
1706 tab_advanced.Enabled = true;
\r
1707 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1708 check_iPodAtom.Enabled = true;
\r
1710 check_iPodAtom.Enabled = false;
\r
1714 check_turbo.CheckState = CheckState.Unchecked;
\r
1715 check_turbo.Enabled = false;
\r
1716 tab_advanced.Enabled = false;
\r
1717 x264Panel.X264Query = string.Empty;
\r
1718 check_iPodAtom.Enabled = false;
\r
1719 check_iPodAtom.Checked = false;
\r
1722 // Setup the CQ Slider
\r
1723 switch (drp_videoEncoder.Text)
\r
1725 case "MPEG-4 (FFmpeg)":
\r
1726 if (slider_videoQuality.Value > 31)
\r
1727 slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.
\r
1728 slider_videoQuality.Minimum = 1;
\r
1729 slider_videoQuality.Maximum = 31;
\r
1731 case "H.264 (x264)":
\r
1732 slider_videoQuality.Minimum = 0;
\r
1733 slider_videoQuality.TickFrequency = 1;
\r
1735 CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
\r
1736 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1737 double multiplier = 1.0 / cqStep;
\r
1738 double value = slider_videoQuality.Value * multiplier;
\r
1740 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1742 if (value < slider_videoQuality.Maximum)
\r
1743 slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;
\r
1746 case "VP3 (Theora)":
\r
1747 if (slider_videoQuality.Value > 63)
\r
1748 slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.
\r
1749 slider_videoQuality.Minimum = 0;
\r
1750 slider_videoQuality.Maximum = 63;
\r
1756 /// Set the container format options
\r
1758 public void setContainerOpts()
\r
1760 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1762 check_largeFile.Enabled = true;
\r
1763 check_optimiseMP4.Enabled = true;
\r
1764 check_iPodAtom.Enabled = true;
\r
1768 check_largeFile.Enabled = false;
\r
1769 check_optimiseMP4.Enabled = false;
\r
1770 check_iPodAtom.Enabled = false;
\r
1771 check_largeFile.Checked = false;
\r
1772 check_optimiseMP4.Checked = false;
\r
1773 check_iPodAtom.Checked = false;
\r
1777 private double _cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1780 /// Update the CQ slider for x264 for a new CQ step. This is set from option
\r
1782 public void setQualityFromSlider()
\r
1784 // Work out the current RF value.
\r
1785 double cqStep = _cachedCqStep;
\r
1786 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1788 // Change the maximum value for the slider
\r
1789 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1791 // Reset the CQ slider to RF0
\r
1792 slider_videoQuality.Value = slider_videoQuality.Maximum;
\r
1794 // Reset the CQ slider back to the previous value as close as possible
\r
1795 double cqStepNew = Properties.Settings.Default.x264cqstep;
\r
1796 double rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1797 while (rfValueCurrent < rfValue)
\r
1799 slider_videoQuality.Value--;
\r
1800 rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1803 // Cache the CQ step for the next calculation
\r
1804 _cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1807 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
1809 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1810 switch (drp_videoEncoder.Text)
\r
1812 case "MPEG-4 (FFmpeg)":
\r
1813 lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);
\r
1815 case "H.264 (x264)":
\r
1816 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1817 rfValue = Math.Round(rfValue, 2);
\r
1818 lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));
\r
1820 case "VP3 (Theora)":
\r
1821 lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;
\r
1826 private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)
\r
1828 text_bitrate.Enabled = false;
\r
1829 text_filesize.Enabled = true;
\r
1830 slider_videoQuality.Enabled = false;
\r
1832 check_2PassEncode.Enabled = true;
\r
1835 private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)
\r
1837 text_bitrate.Enabled = true;
\r
1838 text_filesize.Enabled = false;
\r
1839 slider_videoQuality.Enabled = false;
\r
1841 check_2PassEncode.Enabled = true;
\r
1844 private void radio_cq_CheckedChanged(object sender, EventArgs e)
\r
1846 text_bitrate.Enabled = false;
\r
1847 text_filesize.Enabled = false;
\r
1848 slider_videoQuality.Enabled = true;
\r
1850 check_2PassEncode.Enabled = false;
\r
1851 check_2PassEncode.CheckState = CheckState.Unchecked;
\r
1854 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
1856 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
1858 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1859 check_turbo.Enabled = true;
\r
1863 check_turbo.Enabled = false;
\r
1864 check_turbo.CheckState = CheckState.Unchecked;
\r
1868 // Chapter Marker Tab
\r
1869 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
1871 if (Check_ChapterMarkers.Checked)
\r
1873 if (drop_format.SelectedIndex != 1)
\r
1874 SetExtension(".m4v");
\r
1875 data_chpt.Enabled = true;
\r
1876 btn_importChapters.Enabled = true;
\r
1880 if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v)
\r
1881 SetExtension(".mp4");
\r
1882 data_chpt.Enabled = false;
\r
1883 btn_importChapters.Enabled = false;
\r
1887 private void btn_importChapters_Click(object sender, EventArgs e)
\r
1889 if (File_ChapterImport.ShowDialog() == DialogResult.OK)
\r
1891 string filename = File_ChapterImport.FileName;
\r
1892 DataGridView imported = Main.ImportChapterNames(data_chpt, filename);
\r
1893 if (imported != null)
\r
1894 data_chpt = imported;
\r
1898 private void btn_export_Click(object sender, EventArgs e)
\r
1900 SaveFileDialog saveFileDialog = new SaveFileDialog();
\r
1901 saveFileDialog.Filter = "Csv File|*.csv";
\r
1902 saveFileDialog.DefaultExt = "csv";
\r
1903 if (saveFileDialog.ShowDialog() == DialogResult.OK)
\r
1905 string filename = saveFileDialog.FileName;
\r
1907 Main.SaveChapterMarkersToCsv(this, filename);
\r
1911 private void mnu_resetChapters_Click(object sender, EventArgs e)
\r
1913 data_chpt.Rows.Clear();
\r
1914 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1915 if (chapterGridView != null)
\r
1917 data_chpt = chapterGridView;
\r
1921 // Query Editor Tab
\r
1922 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
1924 rtf_query.Text = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);
\r
1927 private void btn_clear_Click(object sender, EventArgs e)
\r
1929 rtf_query.Clear();
\r
1934 // MainWindow Components, Actions and Functions ***********************
\r
1936 #region Source Scan
\r
1939 /// Start the Scan Process
\r
1941 /// <param name="filename">
\r
1944 /// <param name="title">
\r
1947 private void StartScan(string filename, int title)
\r
1949 // Setup the GUI components for the scan.
\r
1950 sourcePath = filename;
\r
1952 this.DisableGUI();
\r
1957 SourceScan.Scan(sourcePath, title);
\r
1958 SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);
\r
1959 SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);
\r
1961 catch (Exception exc)
\r
1963 MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1968 /// Update the Status label for the scan
\r
1970 /// <param name="sender">
\r
1973 /// <param name="e">
\r
1976 private void SourceScan_ScanStatusChanged(object sender, EventArgs e)
\r
1978 UpdateScanStatusLabel();
\r
1982 /// Update the UI after the scan has completed
\r
1984 /// <param name="sender">
\r
1987 /// <param name="e">
\r
1990 private void SourceScan_ScanCompleted(object sender, EventArgs e)
\r
1992 UpdateGuiAfterScan();
\r
1996 /// Update the Scan Status Label
\r
1998 private void UpdateScanStatusLabel()
\r
2000 if (InvokeRequired)
\r
2002 BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));
\r
2005 lbl_encode.Text = SourceScan.ScanStatus;
\r
2009 /// Reset the GUI when the scan has completed
\r
2011 private void UpdateGuiAfterScan()
\r
2013 if (InvokeRequired)
\r
2015 BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));
\r
2021 currentSource = SourceScan.SouceData;
\r
2023 // Setup some GUI components
\r
2024 drp_dvdtitle.Items.Clear();
\r
2025 if (currentSource.Titles.Count != 0)
\r
2026 drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());
\r
2028 foreach (Title title in currentSource.Titles)
\r
2030 if (title.MainTitle)
\r
2032 drp_dvdtitle.SelectedItem = title;
\r
2036 if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)
\r
2038 drp_dvdtitle.SelectedIndex = 0;
\r
2041 // Enable the creation of chapter markers if the file is an image of a dvd.
\r
2043 int.TryParse(drop_chapterStart.Items[0].ToString(), out start);
\r
2044 int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);
\r
2046 Check_ChapterMarkers.Enabled = true;
\r
2049 Check_ChapterMarkers.Enabled = false;
\r
2050 Check_ChapterMarkers.Checked = false;
\r
2051 data_chpt.Rows.Clear();
\r
2054 // If no titles were found, Display an error message
\r
2055 if (drp_dvdtitle.Items.Count == 0)
\r
2058 "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
2059 "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
2060 sourcePath = string.Empty;
\r
2062 UpdateSourceLabel();
\r
2064 // Enable the GUI components and enable any disabled components
\r
2067 catch (Exception exc)
\r
2069 MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,
\r
2070 MessageBoxIcon.Error);
\r
2076 /// Enable the GUI
\r
2078 private void EnableGUI()
\r
2082 if (InvokeRequired)
\r
2083 BeginInvoke(new UpdateWindowHandler(EnableGUI));
\r
2084 lbl_encode.Text = "Scan Completed";
\r
2085 foreach (Control ctrl in Controls)
\r
2086 ctrl.Enabled = true;
\r
2087 btn_start.Enabled = true;
\r
2088 btn_showQueue.Enabled = true;
\r
2089 btn_add2Queue.Enabled = true;
\r
2090 tb_preview.Enabled = true;
\r
2091 btn_source.Enabled = true;
\r
2092 mnu_killCLI.Visible = false;
\r
2094 catch (Exception exc)
\r
2096 MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2101 /// Disable the GUI
\r
2103 private void DisableGUI()
\r
2105 foreach (Control ctrl in Controls)
\r
2106 if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))
\r
2107 ctrl.Enabled = false;
\r
2109 lbl_encode.Visible = true;
\r
2110 lbl_encode.Text = "Scanning ...";
\r
2111 btn_source.Enabled = false;
\r
2112 btn_start.Enabled = false;
\r
2113 btn_showQueue.Enabled = false;
\r
2114 btn_add2Queue.Enabled = false;
\r
2115 tb_preview.Enabled = false;
\r
2116 mnu_killCLI.Visible = true;
\r
2122 private void KillScan()
\r
2124 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2128 SourceScan.Stop();
\r
2130 lbl_encode.Text = "Scan Cancelled!";
\r
2136 private void ResetGUI()
\r
2138 drp_dvdtitle.Items.Clear();
\r
2139 drop_chapterStart.Items.Clear();
\r
2140 drop_chapterFinish.Items.Clear();
\r
2141 lbl_duration.Text = "Select a Title";
\r
2142 PictureSettings.lbl_src_res.Text = "Select a Title";
\r
2143 sourcePath = String.Empty;
\r
2144 text_destination.Text = String.Empty;
\r
2145 selectedTitle = null;
\r
2149 /// Update the Source Label
\r
2151 private void UpdateSourceLabel()
\r
2153 labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;
\r
2155 if (selectedTitle != null)
\r
2156 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
2157 // If it's one of multiple source files, make sure we don't use the folder name
\r
2158 labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
2162 /// Take a job from the Queue, rescan it, and reload the GUI for that job.
\r
2164 /// <param name="job">
\r
2167 public void RecievingJob(Job job)
\r
2169 string query = job.Query;
\r
2170 StartScan(job.Source, job.Title);
\r
2172 if (query != null)
\r
2174 // Ok, Reset all the H264 widgets before changing the preset
\r
2175 x264Panel.Reset2Defaults();
\r
2177 // Send the query from the file to the Query Parser class
\r
2178 QueryParser presetQuery = QueryParser.Parse(query);
\r
2180 // Now load the preset
\r
2181 PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue", true);
\r
2183 // The x264 widgets will need updated, so do this now:
\r
2184 x264Panel.X264_StandardizeOptString();
\r
2185 x264Panel.X264_SetCurrentSettingsInPanel();
\r
2187 // Finally, let this window have a copy of the preset settings.
\r
2188 CurrentlySelectedPreset = null;
\r
2189 PictureSettings.SetPresetCropWarningLabel(null);
\r
2195 #region GUI Functions and Actions
\r
2198 /// Set the GUI to it's finished encoding state.
\r
2200 private void SetEncodeFinished()
\r
2204 if (InvokeRequired)
\r
2206 BeginInvoke(new UpdateWindowHandler(SetEncodeFinished));
\r
2210 lbl_encode.Text = "Encoding Finished";
\r
2211 ProgressBarStatus.Visible = false;
\r
2212 btn_start.Text = "Start";
\r
2213 btn_start.ToolTipText = "Start the encoding process";
\r
2214 btn_start.Image = Properties.Resources.Play;
\r
2216 // If the window is minimized, display the notification in a popup.
\r
2217 if (Properties.Settings.Default.trayIconAlerts)
\r
2218 if (FormWindowState.Minimized == this.WindowState)
\r
2220 notifyIcon.BalloonTipText = lbl_encode.Text;
\r
2221 notifyIcon.ShowBalloonTip(500);
\r
2224 catch (Exception exc)
\r
2226 MessageBox.Show(exc.ToString());
\r
2231 /// Set the GUI to it's started encoding state.
\r
2233 private void SetEncodeStarted()
\r
2237 if (InvokeRequired)
\r
2239 BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));
\r
2242 lbl_encode.Visible = true;
\r
2243 ProgressBarStatus.Value = 0;
\r
2244 ProgressBarStatus.Visible = true;
\r
2245 lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";
\r
2246 btn_start.Text = "Stop";
\r
2247 btn_start.ToolTipText = "Stop the encoding process.";
\r
2248 btn_start.Image = Properties.Resources.stop;
\r
2250 catch (Exception exc)
\r
2252 MessageBox.Show(exc.ToString());
\r
2257 /// Set the DVD Drive selection in the "Source" Menu
\r
2259 private void SetDriveSelectionMenuItem()
\r
2263 if (InvokeRequired)
\r
2265 BeginInvoke(new UpdateWindowHandler(SetDriveSelectionMenuItem));
\r
2269 drives = Main.GetDrives();
\r
2271 List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
\r
2272 foreach (DriveInformation drive in drives)
\r
2274 ToolStripMenuItem menuItem = new ToolStripMenuItem
\r
2276 Name = drive.ToString(),
\r
2277 Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",
\r
2278 Image = Resources.disc_small
\r
2280 menuItem.Click += new EventHandler(mnu_dvd_drive_Click);
\r
2281 menuItems.Add(menuItem);
\r
2284 foreach (ToolStripMenuItem item in menuItems)
\r
2285 btn_source.DropDownItems.Add(item);
\r
2287 catch (Exception exc)
\r
2289 MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);
\r
2294 /// Access the preset Handler and setup the preset panel.
\r
2296 private void LoadPresetPanel()
\r
2298 if (presetHandler.CheckIfPresetsAreOutOfDate())
\r
2299 if (!Properties.Settings.Default.presetNotification)
\r
2300 MessageBox.Show(splash,
\r
2301 "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",
\r
2302 "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
2304 presetHandler.GetPresetPanel(ref treeView_presets);
\r
2305 treeView_presets.Update();
\r
2309 /// Get the title from the selected item in the title dropdown.
\r
2314 private int getTitle()
\r
2317 if (drp_dvdtitle.SelectedItem != null)
\r
2319 string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');
\r
2320 int.TryParse(titleInfo[0], out title);
\r
2327 /// Handle the Update Check Finishing.
\r
2329 /// <param name="result">
\r
2332 private void updateCheckDoneMenu(IAsyncResult result)
\r
2334 // Make sure it's running on the calling thread
\r
2335 if (InvokeRequired)
\r
2337 Invoke(new MethodInvoker(() => updateCheckDoneMenu(result)));
\r
2340 UpdateCheckInformation info;
\r
2343 // Get the information about the new build, if any, and close the window
\r
2344 info = Main.EndCheckForUpdates(result);
\r
2346 if (info.NewVersionAvailable && info.BuildInformation != null)
\r
2348 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
2349 updateWindow.ShowDialog();
\r
2352 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,
\r
2353 MessageBoxIcon.Information);
\r
2354 lbl_updateCheck.Visible = false;
\r
2357 catch (Exception ex)
\r
2359 if ((bool)result.AsyncState)
\r
2361 "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,
\r
2362 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2371 /// Handle GUI shortcuts
\r
2373 /// <param name="msg">Message</param>
\r
2374 /// <param name="keyData">Keys</param>
\r
2375 /// <returns>Bool</returns>
\r
2376 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
2378 if (keyData == (Keys.Control | Keys.S))
\r
2380 btn_start_Click(this, new EventArgs());
\r
2384 if (keyData == (Keys.Control | Keys.A))
\r
2386 btn_add2Queue_Click(this, new EventArgs());
\r
2389 return base.ProcessCmdKey(ref msg, keyData);
\r
2393 /// If the queue is being processed, prompt the user to confirm application close.
\r
2395 /// <param name="e">FormClosingEventArgs</param>
\r
2396 protected override void OnFormClosing(FormClosingEventArgs e)
\r
2398 // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.
\r
2399 if (encodeQueue.IsEncoding)
\r
2401 DialogResult result =
\r
2403 "HandBrake has queue items to process. Closing HandBrake will stop the current encoding.\n\nDo you want to close HandBrake?",
\r
2404 "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
2406 if (result == DialogResult.No)
\r
2409 // Try to safely close out if we can, or kill the cli if using in-gui status
\r
2410 if (Settings.Default.enocdeStatusInGui)
\r
2411 encodeQueue.Stop();
\r
2413 encodeQueue.SafelyClose();
\r
2416 if (SourceScan.IsScanning)
\r
2418 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2419 SourceScan.Stop();
\r
2421 base.OnFormClosing(e);
\r
2426 #region In-GUI Encode Status
\r
2429 /// Starts a new thread to monitor and process the CLI encode status
\r
2431 private void EncodeMonitorThread()
\r
2435 Parser encode = new Parser(encodeQueue.HbProcess.StandardOutput.BaseStream);
\r
2436 encode.OnEncodeProgress += EncodeOnEncodeProgress;
\r
2437 while (!encode.EndOfStream)
\r
2438 encode.ReadEncodeStatus();
\r
2440 SetEncodeFinished();
\r
2442 catch (Exception exc)
\r
2444 MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2449 /// Displays the Encode status in the GUI
\r
2451 /// <param name="sender">The sender</param>
\r
2452 /// <param name="currentTask">The current task</param>
\r
2453 /// <param name="taskCount">Number of tasks</param>
\r
2454 /// <param name="percentComplete">Percent complete</param>
\r
2455 /// <param name="currentFps">Current encode speed in fps</param>
\r
2456 /// <param name="av">Avg encode speed</param>
\r
2457 /// <param name="timeRemaining">Time Left</param>
\r
2458 private void EncodeOnEncodeProgress(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float av, TimeSpan timeRemaining)
\r
2460 if (this.InvokeRequired)
\r
2463 new EncodeProgressEventHandler(EncodeOnEncodeProgress),
\r
2464 new[] { sender, currentTask, taskCount, percentComplete, currentFps, av, timeRemaining });
\r
2469 "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}",
\r
2475 ProgressBarStatus.Value = (int)Math.Round(percentComplete);
\r
2480 // This is the END of the road ****************************************
\r