2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr/>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
9 using System.Collections.Generic;
\r
10 using System.ComponentModel;
\r
11 using System.Diagnostics;
\r
12 using System.Drawing;
\r
13 using System.Globalization;
\r
15 using System.Reflection;
\r
16 using System.Threading;
\r
17 using System.Windows.Forms;
\r
20 using HandBrake.ApplicationServices.Model;
\r
21 using HandBrake.ApplicationServices.Parsing;
\r
22 using HandBrake.ApplicationServices.Services;
\r
23 using HandBrake.ApplicationServices.Services.Interfaces;
\r
29 public partial class frmMain : Form
\r
31 // Objects which may be used by one or more other objects *************
\r
32 private IQueue encodeQueue = new Queue();
\r
33 private PresetsHandler presetHandler = new PresetsHandler();
\r
35 // Windows ************************************************************
\r
36 private frmQueue queueWindow;
\r
37 private frmPreview qtpreview;
\r
38 private frmActivityWindow activityWindow;
\r
39 private frmSplashScreen splash = new frmSplashScreen();
\r
41 // Globals: Mainly used for tracking. *********************************
\r
42 public Title selectedTitle;
\r
43 public string sourcePath;
\r
44 private SourceType selectedSourceType;
\r
45 private string dvdDrivePath;
\r
46 private string dvdDriveLabel;
\r
47 private Preset currentlySelectedPreset;
\r
48 private DVD currentSource;
\r
49 private IScan SourceScan = new ScanService();
\r
50 private List<DriveInformation> drives;
\r
52 // Delegates **********************************************************
\r
53 private delegate void UpdateWindowHandler();
\r
55 // Applicaiton Startup ************************************************
\r
60 /// Gets SourceName.
\r
62 public string SourceName
\r
66 if (this.selectedSourceType == SourceType.DvdDrive)
\r
68 return this.dvdDriveLabel;
\r
71 if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")
\r
72 return Path.GetFileNameWithoutExtension(this.sourcePath);
\r
74 return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));
\r
80 #region Application Startup
\r
83 /// Initializes a new instance of the <see cref="frmMain"/> class.
\r
85 /// <param name="args">
\r
86 /// The arguments passed in on application startup.
\r
88 public frmMain(string[] args)
\r
90 // Load and setup the splash screen in this thread
\r
92 Label lblStatus = new Label { Size = new Size(150, 20), Location = new Point(182, 102) };
\r
93 splash.Controls.Add(lblStatus);
\r
95 InitializeComponent();
\r
97 // Update the users config file with the CLI version data.
\r
98 UpdateSplashStatus(lblStatus, "Checking CLI Version Data ...");
\r
99 Main.SetCliVersionData();
\r
100 Main.CheckForValidCliVersion();
\r
102 if (Settings.Default.hb_version.Contains("svn"))
\r
104 Version v = Assembly.GetExecutingAssembly().GetName().Version;
\r
105 this.Text += " " + v.ToString(4);
\r
108 // Show the form, but leave disabled until preloading is complete then show the main form)
\r
109 this.Enabled = false;
\r
111 Application.DoEvents(); // Forces frmMain to draw
\r
113 // Check for new versions, if update checking is enabled
\r
114 if (Properties.Settings.Default.updateStatus)
\r
116 DateTime now = DateTime.Now;
\r
117 DateTime lastCheck = Properties.Settings.Default.lastUpdateCheckDate;
\r
118 TimeSpan elapsed = now.Subtract(lastCheck);
\r
119 if (elapsed.TotalDays > Properties.Settings.Default.daysBetweenUpdateCheck)
\r
121 UpdateSplashStatus(lblStatus, "Checking for updates ...");
\r
122 Main.BeginCheckForUpdates(new AsyncCallback(UpdateCheckDone), false);
\r
126 // Clear the log files in the background
\r
127 if (Properties.Settings.Default.clearOldLogs)
\r
129 UpdateSplashStatus(lblStatus, "Clearing Old Log Files ..");
\r
130 Thread clearLog = new Thread(Main.ClearOldLogs);
\r
134 // Setup the GUI components
\r
135 UpdateSplashStatus(lblStatus, "Setting up the GUI ...");
\r
136 LoadPresetPanel(); // Load the Preset Panel
\r
137 treeView_presets.ExpandAll();
\r
138 lbl_encode.Text = string.Empty;
\r
139 drop_mode.SelectedIndex = 0;
\r
140 queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue
\r
141 if (!Properties.Settings.Default.QueryEditorTab)
\r
142 tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.
\r
143 if (Properties.Settings.Default.tooltipEnable)
\r
144 ToolTip.Active = true;
\r
146 // Load the user's default settings or Normal Preset
\r
147 if (Properties.Settings.Default.defaultPreset != string.Empty && presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)
\r
149 string query = presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).Query;
\r
152 x264Panel.Reset2Defaults();
\r
154 QueryParser presetQuery = QueryParser.Parse(query);
\r
155 PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset);
\r
157 x264Panel.StandardizeOptString();
\r
158 x264Panel.SetCurrentSettingsInPanel();
\r
162 loadNormalPreset();
\r
164 // Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)
\r
165 GrowlCommunicator.Register();
\r
167 // Finished Loading
\r
168 UpdateSplashStatus(lblStatus, "Loading Complete.");
\r
171 this.Enabled = true;
\r
173 // Event Handlers and Queue Recovery
\r
177 // If have a file passed in via command arguemtents, check it's a file and try scanning it.
\r
178 if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0])))
\r
180 this.StartScan(args[0], 0);
\r
184 private void UpdateCheckDone(IAsyncResult result)
\r
186 if (InvokeRequired)
\r
188 Invoke(new MethodInvoker(() => UpdateCheckDone(result)));
\r
192 UpdateCheckInformation info;
\r
196 info = Main.EndCheckForUpdates(result);
\r
198 if (info.NewVersionAvailable)
\r
200 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
201 updateWindow.ShowDialog();
\r
204 catch (Exception ex)
\r
206 if ((bool)result.AsyncState)
\r
207 Main.ShowExceptiowWindow("Unable to check for updates, Please try again later.", ex.ToString());
\r
211 // Startup Functions
\r
212 private void queueRecovery()
\r
214 if (Main.CheckQueueRecovery())
\r
216 DialogResult result =
\r
218 "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?",
\r
219 "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
221 if (result == DialogResult.Yes)
\r
222 encodeQueue.LoadQueueFromFile("hb_queue_recovery.xml"); // Start Recovery
\r
225 // Remove the Queue recovery file if the user doesn't want to recovery the last queue.
\r
226 string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
\r
227 if (File.Exists(queuePath))
\r
228 File.Delete(queuePath);
\r
233 private void UpdateSplashStatus(Label status, string text)
\r
235 status.Text = text;
\r
236 Application.DoEvents();
\r
243 // Encoding Events for setting up the GUI
\r
244 private void events()
\r
246 // Handle Widget changes when preset is selected.
\r
247 RegisterPresetEventHandler();
\r
249 // Handle Window Resize
\r
250 if (Properties.Settings.Default.MainWindowMinimize)
\r
251 this.Resize += new EventHandler(frmMain_Resize);
\r
253 // Handle Encode Start / Finish / Pause
\r
254 encodeQueue.EncodeStarted += new EventHandler(encodeStarted);
\r
255 encodeQueue.EncodeEnded += new EventHandler(encodeEnded);
\r
257 // Handle a file being draged onto the GUI.
\r
258 this.DragEnter += new DragEventHandler(frmMain_DragEnter);
\r
259 this.DragDrop += new DragEventHandler(frmMain_DragDrop);
\r
262 // Change the preset label to custom when a user changes a setting. Don't want to give the impression that users can change settings and still be using a preset
\r
263 private void RegisterPresetEventHandler()
\r
266 drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
267 check_largeFile.CheckedChanged += new EventHandler(changePresetLabel);
\r
268 check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel);
\r
269 check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);
\r
271 // Picture Settings
\r
272 PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);
\r
275 Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);
\r
278 drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
279 check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel);
\r
280 check_turbo.CheckedChanged += new EventHandler(changePresetLabel);
\r
281 text_filesize.TextChanged += new EventHandler(changePresetLabel);
\r
282 text_bitrate.TextChanged += new EventHandler(changePresetLabel);
\r
283 slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel);
\r
286 AudioSettings.AudioListChanged += new EventHandler(changePresetLabel);
\r
289 x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);
\r
292 private void UnRegisterPresetEventHandler()
\r
294 // Output Settings
\r
295 drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
296 check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel);
\r
297 check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel);
\r
298 check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);
\r
300 // Picture Settings
\r
301 PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);
\r
304 Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);
\r
307 drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
308 check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel);
\r
309 check_turbo.CheckedChanged -= new EventHandler(changePresetLabel);
\r
310 text_filesize.TextChanged -= new EventHandler(changePresetLabel);
\r
311 text_bitrate.TextChanged -= new EventHandler(changePresetLabel);
\r
312 slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel);
\r
315 AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel);
\r
318 x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);
\r
321 private void changePresetLabel(object sender, EventArgs e)
\r
323 labelPreset.Text = "Output Settings (Preset: Custom)";
\r
324 this.currentlySelectedPreset = null;
\r
327 private static void frmMain_DragEnter(object sender, DragEventArgs e)
\r
329 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
\r
330 e.Effect = DragDropEffects.All;
\r
333 private void frmMain_DragDrop(object sender, DragEventArgs e)
\r
335 string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
\r
336 sourcePath = string.Empty;
\r
338 if (fileList != null)
\r
340 if (!string.IsNullOrEmpty(fileList[0]))
\r
342 this.selectedSourceType = SourceType.VideoFile;
\r
343 StartScan(fileList[0], 0);
\r
346 UpdateSourceLabel();
\r
349 UpdateSourceLabel();
\r
352 private void encodeStarted(object sender, EventArgs e)
\r
354 SetEncodeStarted();
\r
355 encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;
\r
358 private void encodeEnded(object sender, EventArgs e)
\r
360 encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;
\r
361 SetEncodeFinished();
\r
365 // User Interface Menus / Tool Strips *********************************
\r
370 /// Kill The scan menu Item
\r
372 /// <param name="sender">
\r
375 /// <param name="e">
\r
378 private void mnu_killCLI_Click(object sender, EventArgs e)
\r
384 /// Exit the Application Menu Item
\r
386 /// <param name="sender">
\r
389 /// <param name="e">
\r
392 private void mnu_exit_Click(object sender, EventArgs e)
\r
394 Application.Exit();
\r
402 /// Menu - Start Button
\r
404 /// <param name="sender">
\r
407 /// <param name="e">
\r
410 private void mnu_encode_Click(object sender, EventArgs e)
\r
412 queueWindow.Show();
\r
416 /// Menu - Display the Log Window
\r
418 /// <param name="sender">
\r
421 /// <param name="e">
\r
424 private void mnu_encodeLog_Click(object sender, EventArgs e)
\r
426 frmActivityWindow dvdInfoWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
427 dvdInfoWindow.Show();
\r
431 /// Menu - Display the Options Window
\r
433 /// <param name="sender">
\r
436 /// <param name="e">
\r
439 private void mnu_options_Click(object sender, EventArgs e)
\r
441 Form options = new frmOptions(this);
\r
442 options.ShowDialog();
\r
447 #region Presets Menu
\r
450 /// Reset the Built in Presets
\r
452 /// <param name="sender">
\r
455 /// <param name="e">
\r
458 private void mnu_presetReset_Click(object sender, EventArgs e)
\r
460 presetHandler.UpdateBuiltInPresets();
\r
462 if (treeView_presets.Nodes.Count == 0)
\r
464 "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
465 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
467 MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
469 treeView_presets.ExpandAll();
\r
473 /// Delete the selected preset
\r
475 /// <param name="sender">
\r
478 /// <param name="e">
\r
481 private void mnu_delete_preset_Click(object sender, EventArgs e)
\r
483 presetHandler.RemoveBuiltInPresets();
\r
484 LoadPresetPanel(); // Reload the preset panel
\r
488 /// Select the Normal preset
\r
490 /// <param name="sender">
\r
493 /// <param name="e">
\r
496 private void mnu_SelectDefault_Click(object sender, EventArgs e)
\r
498 loadNormalPreset();
\r
502 /// Import a plist Preset
\r
504 /// <param name="sender">
\r
507 /// <param name="e">
\r
510 private void mnu_importMacPreset_Click(object sender, EventArgs e)
\r
516 /// Export a Plist Preset
\r
518 /// <param name="sender">
\r
521 /// <param name="e">
\r
524 private void mnu_exportMacPreset_Click(object sender, EventArgs e)
\r
530 /// Create a new Preset
\r
532 /// <param name="sender">
\r
535 /// <param name="e">
\r
538 private void btn_new_preset_Click(object sender, EventArgs e)
\r
540 Form preset = new frmAddPreset(this, presetHandler);
\r
541 if (preset.ShowDialog() == DialogResult.OK)
\r
543 TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };
\r
544 treeView_presets.Nodes.Add(presetTreeview);
\r
545 presetHandler.LastPresetAdded = null;
\r
554 /// Menu - Display the User Guide Web Page
\r
556 /// <param name="sender">
\r
559 /// <param name="e">
\r
562 private void mnu_user_guide_Click(object sender, EventArgs e)
\r
564 Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");
\r
568 /// Menu - Check for Updates
\r
570 /// <param name="sender">
\r
573 /// <param name="e">
\r
576 private void mnu_UpdateCheck_Click(object sender, EventArgs e)
\r
578 lbl_updateCheck.Visible = true;
\r
579 Main.BeginCheckForUpdates(new AsyncCallback(this.UpdateCheckDoneMenu), false);
\r
583 /// Menu - Display the About Window
\r
585 /// <param name="sender">
\r
588 /// <param name="e">
\r
591 private void mnu_about_Click(object sender, EventArgs e)
\r
593 using (frmAbout About = new frmAbout())
\r
595 About.ShowDialog();
\r
604 /// RMenu - Expand All
\r
606 /// <param name="sender">
\r
609 /// <param name="e">
\r
612 private void pmnu_expandAll_Click(object sender, EventArgs e)
\r
614 treeView_presets.ExpandAll();
\r
618 /// RMenu - Collaspe All
\r
620 /// <param name="sender">
\r
623 /// <param name="e">
\r
626 private void pmnu_collapse_Click(object sender, EventArgs e)
\r
628 treeView_presets.CollapseAll();
\r
632 /// Menu - Import Preset
\r
634 /// <param name="sender">
\r
637 /// <param name="e">
\r
640 private void pmnu_import_Click(object sender, EventArgs e)
\r
646 /// RMenu - Save Changes to Preset
\r
648 /// <param name="sender">
\r
651 /// <param name="e">
\r
654 private void pmnu_saveChanges_Click(object sender, EventArgs e)
\r
656 // TODO this requires a re-think since the Query Editor has changed.
\r
657 DialogResult result =
\r
659 "Do you wish to include picture settings when updating the preset: " +
\r
660 treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,
\r
661 MessageBoxIcon.Question);
\r
662 if (result == DialogResult.Yes)
\r
663 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
664 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);
\r
665 else if (result == DialogResult.No)
\r
666 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
667 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);
\r
671 /// RMenu - Delete Preset
\r
673 /// <param name="sender">
\r
676 /// <param name="e">
\r
679 private void pmnu_delete_click(object sender, EventArgs e)
\r
681 if (treeView_presets.SelectedNode != null)
\r
683 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
684 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
686 treeView_presets.Select();
\r
690 /// Preset Menu Is Opening. Setup the Menu
\r
692 /// <param name="sender">
\r
695 /// <param name="e">
\r
698 private void presets_menu_Opening(object sender, CancelEventArgs e)
\r
700 // Make sure that the save menu is always disabled by default
\r
701 pmnu_saveChanges.Enabled = false;
\r
703 // Now enable the save menu if the selected preset is a user preset
\r
704 if (treeView_presets.SelectedNode != null)
\r
705 if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))
\r
706 pmnu_saveChanges.Enabled = true;
\r
708 treeView_presets.Select();
\r
711 // Presets Management
\r
714 /// Button - Add a preset
\r
716 /// <param name="sender">
\r
719 /// <param name="e">
\r
722 private void btn_addPreset_Click(object sender, EventArgs e)
\r
724 Form preset = new frmAddPreset(this, presetHandler);
\r
725 if (preset.ShowDialog() == DialogResult.OK)
\r
727 TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };
\r
728 treeView_presets.Nodes.Add(presetTreeview);
\r
729 presetHandler.LastPresetAdded = null;
\r
734 /// Button - remove a Preset
\r
736 /// <param name="sender">
\r
739 /// <param name="e">
\r
742 private void btn_removePreset_Click(object sender, EventArgs e)
\r
744 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
745 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
746 if (result == DialogResult.Yes)
\r
748 if (treeView_presets.SelectedNode != null)
\r
750 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
751 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
754 treeView_presets.Select();
\r
758 /// Button - Set the selected preset as the default
\r
760 /// <param name="sender">
\r
763 /// <param name="e">
\r
766 private void btn_setDefault_Click(object sender, EventArgs e)
\r
768 if (treeView_presets.SelectedNode != null)
\r
770 DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",
\r
771 "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
772 if (result == DialogResult.Yes)
\r
774 Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;
\r
775 Properties.Settings.Default.Save();
\r
776 MessageBox.Show("New default preset set.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
780 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
784 /// PresetBar Mouse Down event
\r
786 /// <param name="sender">
\r
789 /// <param name="e">
\r
792 private void treeview_presets_mouseUp(object sender, MouseEventArgs e)
\r
794 if (e.Button == MouseButtons.Right)
\r
795 treeView_presets.SelectedNode = treeView_presets.GetNodeAt(e.Location);
\r
796 else if (e.Button == MouseButtons.Left)
\r
798 if (treeView_presets.GetNodeAt(e.Location) != null)
\r
800 if (labelPreset.Text.Contains(treeView_presets.GetNodeAt(e.Location).Text))
\r
805 treeView_presets.Select();
\r
809 /// Preset Bar after selecting the preset
\r
811 /// <param name="sender">
\r
814 /// <param name="e">
\r
817 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
823 /// Preset Bar - Handle the Delete Key
\r
825 /// <param name="sender">
\r
828 /// <param name="e">
\r
831 private void treeView_presets_deleteKey(object sender, KeyEventArgs e)
\r
833 if (e.KeyCode == Keys.Delete)
\r
835 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
836 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
837 if (result == DialogResult.Yes)
\r
839 if (treeView_presets.SelectedNode != null)
\r
840 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
842 // Remember each nodes expanded status so we can reload it
\r
843 List<bool> nodeStatus = new List<bool>();
\r
844 foreach (TreeNode node in treeView_presets.Nodes)
\r
845 nodeStatus.Add(node.IsExpanded);
\r
847 // Now reload the preset panel
\r
850 // And finally, re-expand any of the nodes if required
\r
852 foreach (TreeNode node in treeView_presets.Nodes)
\r
864 /// Select the selected preset and setup the GUI
\r
866 private void selectPreset()
\r
868 if (treeView_presets.SelectedNode != null)
\r
870 // Ok, so, we've selected a preset. Now we want to load it.
\r
871 string presetName = treeView_presets.SelectedNode.Text;
\r
872 Preset preset = presetHandler.GetPreset(presetName);
\r
873 if (preset != null)
\r
875 string query = presetHandler.GetPreset(presetName).Query;
\r
879 // Ok, Reset all the H264 widgets before changing the preset
\r
880 x264Panel.Reset2Defaults();
\r
882 // Send the query from the file to the Query Parser class
\r
883 QueryParser presetQuery = QueryParser.Parse(query);
\r
885 // Now load the preset
\r
886 PresetLoader.LoadPreset(this, presetQuery, presetName);
\r
888 // The x264 widgets will need updated, so do this now:
\r
889 x264Panel.StandardizeOptString();
\r
890 x264Panel.SetCurrentSettingsInPanel();
\r
892 // Finally, let this window have a copy of the preset settings.
\r
893 this.currentlySelectedPreset = preset;
\r
894 PictureSettings.SetPresetCropWarningLabel(preset);
\r
901 /// Load the Normal Preset
\r
903 private void loadNormalPreset()
\r
905 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
907 foreach (TreeNode node in treenode.Nodes)
\r
909 if (node.Text.Equals("Normal"))
\r
910 treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0];
\r
916 /// Import a plist preset
\r
918 private void ImportPreset()
\r
920 if (openPreset.ShowDialog() == DialogResult.OK)
\r
922 QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);
\r
923 if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))
\r
925 DialogResult result =
\r
926 MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",
\r
927 "Overwrite preset?",
\r
928 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
929 if (result == DialogResult.Yes)
\r
931 PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
\r
932 presetHandler.Update(parsed.PresetName + " (Imported)",
\r
933 QueryGenerator.GenerateFullQuery(this),
\r
934 parsed.UsesPictureSettings);
\r
939 PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
\r
940 if (presetHandler.Add(parsed.PresetName + " (Imported)",
\r
941 QueryGenerator.GenerateFullQuery(this),
\r
942 parsed.UsesPictureSettings))
\r
944 TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")
\r
946 ForeColor = Color.Black
\r
948 treeView_presets.Nodes.Add(preset_treeview);
\r
955 /// Export a plist Preset
\r
957 private void ExportPreset()
\r
959 MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
962 SaveFileDialog savefiledialog = new SaveFileDialog();
\r
963 savefiledialog.Filter = "plist|*.plist";
\r
965 if (treeView_presets.SelectedNode != null)
\r
968 if (savefiledialog.ShowDialog() == DialogResult.OK)
\r
970 Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);
\r
971 PlistPresetHandler.Export(savefiledialog.FileName, preset);
\r
981 /// 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
983 /// <param name="sender">
\r
986 /// <param name="e">
\r
989 private void btn_source_Click(object sender, EventArgs e)
\r
991 // Remove old Drive Menu Items.
\r
992 List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();
\r
993 foreach (var item in btn_source.DropDownItems)
\r
995 if (item.GetType() == typeof(ToolStripMenuItem))
\r
997 ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
\r
998 if (menuItem.Name.StartsWith("Drive"))
\r
1000 itemsToRemove.Add(menuItem);
\r
1005 foreach (ToolStripMenuItem item in itemsToRemove)
\r
1006 btn_source.DropDownItems.Remove(item);
\r
1008 Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);
\r
1009 driveInfoThread.Start();
\r
1013 /// Toolbar - Start The Encode
\r
1015 /// <param name="sender">
\r
1018 /// <param name="e">
\r
1021 private void btn_start_Click(object sender, EventArgs e)
\r
1023 if (btn_start.Text == "Stop")
\r
1025 DialogResult result;
\r
1026 if (Properties.Settings.Default.enocdeStatusInGui &&
\r
1027 !Properties.Settings.Default.showCliForInGuiEncodeStatus)
\r
1029 result = MessageBox.Show(
\r
1030 "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
1031 "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1035 result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?",
\r
1036 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1039 if (result == DialogResult.Yes)
\r
1041 // Pause The Queue
\r
1042 encodeQueue.Pause();
\r
1044 if (Settings.Default.enocdeStatusInGui && !Settings.Default.showCliForInGuiEncodeStatus)
\r
1046 encodeQueue.Stop();
\r
1050 encodeQueue.SafelyClose();
\r
1056 // 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
1057 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1058 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1060 if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))
\r
1062 string generatedQuery = QueryGenerator.GenerateFullQuery(this);
\r
1063 string specifiedQuery = rtf_query.Text != string.Empty
\r
1065 : QueryGenerator.GenerateFullQuery(this);
\r
1066 string query = string.Empty;
\r
1068 // Check to make sure the generated query matches the GUI settings
\r
1069 if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) &&
\r
1070 generatedQuery != specifiedQuery)
\r
1072 DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " +
\r
1073 "does not match the current GUI settings.\n\nBecause the manual query takes " +
\r
1074 "priority over the GUI, your recently updated settings will not be taken " +
\r
1075 "into account when encoding this job." +
\r
1076 Environment.NewLine + Environment.NewLine +
\r
1077 "Do you want to replace the manual query with the updated GUI-generated query?",
\r
1078 "Manual Query does not Match GUI",
\r
1079 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,
\r
1080 MessageBoxDefaultButton.Button3);
\r
1084 case DialogResult.Yes:
\r
1085 // Replace the manual query with the generated one
\r
1086 query = generatedQuery;
\r
1087 rtf_query.Text = generatedQuery;
\r
1089 case DialogResult.No:
\r
1090 // Use the manual query
\r
1091 query = specifiedQuery;
\r
1093 case DialogResult.Cancel:
\r
1094 // Don't start the encode
\r
1100 query = specifiedQuery;
\r
1103 DialogResult overwrite = DialogResult.Yes;
\r
1104 if (!string.IsNullOrEmpty(jobDestination) && File.Exists(jobDestination))
\r
1106 overwrite = MessageBox.Show(
\r
1107 "The destination file already exists. Are you sure you want to overwrite it?",
\r
1108 "Overwrite File?",
\r
1109 MessageBoxButtons.YesNo,
\r
1110 MessageBoxIcon.Question);
\r
1113 if (overwrite == DialogResult.Yes)
\r
1115 if (encodeQueue.Count == 0)
\r
1116 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1118 queueWindow.SetQueue();
\r
1119 if (encodeQueue.Count > 1)
\r
1120 queueWindow.Show(false);
\r
1122 SetEncodeStarted(); // Encode is running, so setup the GUI appropriately
\r
1123 encodeQueue.Start(); // Start The Queue Encoding Process
\r
1128 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1129 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1130 MessageBoxIcon.Warning);
\r
1135 /// Toolbar - Add the current job to the Queue
\r
1137 /// <param name="sender">
\r
1140 /// <param name="e">
\r
1143 private void btn_add2Queue_Click(object sender, EventArgs e)
\r
1145 // Get the CLI query or use the query editor if it's not empty.
\r
1146 string query = QueryGenerator.GenerateFullQuery(this);
\r
1147 if (!string.IsNullOrEmpty(rtf_query.Text))
\r
1148 query = rtf_query.Text;
\r
1150 // 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
1151 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1152 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1154 // Make sure we have a Source and Destination.
\r
1155 if (string.IsNullOrEmpty(jobSourcePath) || string.IsNullOrEmpty(jobDestination))
\r
1157 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1161 // Make sure the destination path exists.
\r
1162 if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))
\r
1164 MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1168 // Make sure we don't have a duplciate on the queue.
\r
1169 if (encodeQueue.CheckForDestinationDuplicate(jobDestination))
\r
1171 DialogResult result =
\r
1173 "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
1174 "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
1175 if (result == DialogResult.Yes)
\r
1176 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1179 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1181 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";
\r
1183 queueWindow.Show();
\r
1188 /// Toolbar - Show the Queue
\r
1190 /// <param name="sender">
\r
1193 /// <param name="e">
\r
1196 private void btn_showQueue_Click(object sender, EventArgs e)
\r
1198 queueWindow.Show();
\r
1199 queueWindow.Activate();
\r
1203 /// Toolbar - Show the Preview Window
\r
1205 /// <param name="sender">
\r
1208 /// <param name="e">
\r
1211 private void tb_preview_Click(object sender, EventArgs e)
\r
1213 if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1214 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1215 MessageBoxIcon.Warning);
\r
1218 if (qtpreview == null)
\r
1220 qtpreview = new frmPreview(this);
\r
1223 else if (qtpreview.IsDisposed)
\r
1225 qtpreview = new frmPreview(this);
\r
1229 MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,
\r
1230 MessageBoxIcon.Warning);
\r
1235 /// Toolbar - Show the Activity log Window
\r
1237 /// <param name="sender">
\r
1240 /// <param name="e">
\r
1243 private void btn_ActivityWindow_Click(object sender, EventArgs e)
\r
1245 if (this.activityWindow == null || !this.activityWindow.IsHandleCreated)
\r
1246 this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
1248 this.activityWindow.Show();
\r
1249 this.activityWindow.Activate();
\r
1254 #region System Tray Icon
\r
1257 /// Handle Resizing of the main window when deaing with the Notify Icon
\r
1259 /// <param name="sender">
\r
1262 /// <param name="e">
\r
1265 private void frmMain_Resize(object sender, EventArgs e)
\r
1267 if (FormWindowState.Minimized == this.WindowState)
\r
1269 notifyIcon.Visible = true;
\r
1272 else if (FormWindowState.Normal == this.WindowState)
\r
1273 notifyIcon.Visible = false;
\r
1277 /// Double Click the Tray Icon
\r
1279 /// <param name="sender">
\r
1282 /// <param name="e">
\r
1285 private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
\r
1287 this.Visible = true;
\r
1289 this.WindowState = FormWindowState.Normal;
\r
1290 notifyIcon.Visible = false;
\r
1294 /// Tray Icon - Restore Menu Item - Resture the Window
\r
1296 /// <param name="sender">
\r
1299 /// <param name="e">
\r
1302 private void btn_restore_Click(object sender, EventArgs e)
\r
1304 this.Visible = true;
\r
1306 this.WindowState = FormWindowState.Normal;
\r
1307 notifyIcon.Visible = false;
\r
1312 #region Main Window and Tab Control
\r
1315 private void btn_dvd_source_Click(object sender, EventArgs e)
\r
1317 if (DVD_Open.ShowDialog() == DialogResult.OK)
\r
1319 this.selectedSourceType = SourceType.Folder;
\r
1320 SelectSource(DVD_Open.SelectedPath);
\r
1323 UpdateSourceLabel();
\r
1326 private void btn_file_source_Click(object sender, EventArgs e)
\r
1328 if (ISO_Open.ShowDialog() == DialogResult.OK)
\r
1330 this.selectedSourceType = SourceType.VideoFile;
\r
1331 SelectSource(ISO_Open.FileName);
\r
1334 UpdateSourceLabel();
\r
1337 private void mnu_dvd_drive_Click(object sender, EventArgs e)
\r
1339 ToolStripMenuItem item = sender as ToolStripMenuItem;
\r
1342 string driveId = item.Name.Replace("Drive", string.Empty);
\r
1344 if (int.TryParse(driveId, out id))
\r
1347 this.dvdDrivePath = drives[id].RootDirectory;
\r
1348 this.dvdDriveLabel = drives[id].VolumeLabel;
\r
1350 if (this.dvdDrivePath == null) return;
\r
1351 this.selectedSourceType = SourceType.DvdDrive;
\r
1352 SelectSource(this.dvdDrivePath);
\r
1357 private void SelectSource(string file)
\r
1359 Check_ChapterMarkers.Enabled = true;
\r
1360 sourcePath = string.Empty;
\r
1362 if (file == string.Empty) // Must have a file or path
\r
1364 UpdateSourceLabel();
\r
1368 sourcePath = Path.GetFileName(file);
\r
1369 StartScan(file, 0);
\r
1372 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
1374 if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))
\r
1376 "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",
\r
1377 "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
1380 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1382 UnRegisterPresetEventHandler();
\r
1383 drop_mode.SelectedIndex = 0;
\r
1385 drop_chapterStart.Items.Clear();
\r
1386 drop_chapterFinish.Items.Clear();
\r
1388 // If the dropdown is set to automatic nothing else needs to be done.
\r
1389 // Otheriwse if its not, title data has to be loaded from parsing.
\r
1390 if (drp_dvdtitle.Text != "Automatic")
\r
1392 selectedTitle = drp_dvdtitle.SelectedItem as Title;
\r
1393 lbl_duration.Text = selectedTitle.Duration.ToString();
\r
1394 PictureSettings.CurrentlySelectedPreset = this.currentlySelectedPreset;
\r
1395 PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control
\r
1397 // Populate the Angles dropdown
\r
1398 drop_angle.Items.Clear();
\r
1399 if (!Properties.Settings.Default.noDvdNav)
\r
1401 drop_angle.Visible = true;
\r
1402 lbl_angle.Visible = true;
\r
1404 for (int i = 1; i <= selectedTitle.AngleCount; i++)
\r
1405 drop_angle.Items.Add(i.ToString());
\r
1407 if (drop_angle.Items.Count != 0)
\r
1408 drop_angle.SelectedIndex = 0;
\r
1412 drop_angle.Visible = false;
\r
1413 lbl_angle.Visible = false;
\r
1416 // Populate the Start chapter Dropdown
\r
1417 drop_chapterStart.Items.Clear();
\r
1418 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1419 if (drop_chapterStart.Items.Count > 0)
\r
1420 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
1422 // Populate the Final Chapter Dropdown
\r
1423 drop_chapterFinish.Items.Clear();
\r
1424 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1425 if (drop_chapterFinish.Items.Count > 0)
\r
1426 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
1428 // Populate the Audio Channels Dropdown
\r
1429 AudioSettings.SetTrackList(selectedTitle, this.currentlySelectedPreset);
\r
1431 // Populate the Subtitles dropdown
\r
1432 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());
\r
1434 // Update the source label if we have multiple streams
\r
1435 if (selectedTitle != null)
\r
1436 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
1437 labelSource.Text = labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
1439 // Run the AutoName & ChapterNaming functions
\r
1440 if (Properties.Settings.Default.autoNaming)
\r
1442 string autoPath = Main.AutoName(this);
\r
1443 if (autoPath != null)
\r
1444 text_destination.Text = autoPath;
\r
1447 "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
1448 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1451 data_chpt.Rows.Clear();
\r
1452 if (selectedTitle.Chapters.Count != 1)
\r
1454 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1455 if (chapterGridView != null)
\r
1456 data_chpt = chapterGridView;
\r
1460 Check_ChapterMarkers.Checked = false;
\r
1461 Check_ChapterMarkers.Enabled = false;
\r
1464 // Hack to force the redraw of the scrollbars which don't resize properly when the control is disabled.
\r
1465 data_chpt.Columns[0].Width = 166;
\r
1466 data_chpt.Columns[0].Width = 165;
\r
1468 RegisterPresetEventHandler();
\r
1471 private void chapersChanged(object sender, EventArgs e)
\r
1473 if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.
\r
1476 Control ctl = (Control)sender;
\r
1477 int chapterStart, chapterEnd;
\r
1478 int.TryParse(drop_chapterStart.Text, out chapterStart);
\r
1479 int.TryParse(drop_chapterFinish.Text, out chapterEnd);
\r
1483 case "drop_chapterStart":
\r
1484 if (drop_chapterFinish.SelectedIndex == -1 && drop_chapterFinish.Items.Count != 0)
\r
1485 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1487 if (chapterEnd != 0)
\r
1488 if (chapterStart > chapterEnd)
\r
1489 drop_chapterFinish.Text = chapterStart.ToString();
\r
1491 case "drop_chapterFinish":
\r
1492 if (drop_chapterStart.Items.Count >= 1 && drop_chapterStart.SelectedIndex == -1)
\r
1493 drop_chapterStart.SelectedIndex = 0;
\r
1495 if (chapterStart != 0)
\r
1496 if (chapterEnd < chapterStart)
\r
1497 drop_chapterFinish.Text = chapterStart.ToString();
\r
1499 // Add more rows to the Chapter menu if needed.
\r
1500 if (Check_ChapterMarkers.Checked)
\r
1502 int i = data_chpt.Rows.Count, finish = 0;
\r
1503 int.TryParse(drop_chapterFinish.Text, out finish);
\r
1505 while (i < finish)
\r
1507 int n = data_chpt.Rows.Add();
\r
1508 data_chpt.Rows[n].Cells[0].Value = (i + 1);
\r
1509 data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
\r
1510 data_chpt.Rows[n].Cells[0].ValueType = typeof(int);
\r
1511 data_chpt.Rows[n].Cells[1].ValueType = typeof(string);
\r
1518 // Update the Duration
\r
1519 lbl_duration.Text =
\r
1520 Main.CalculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle)
\r
1523 // Run the Autonaming function
\r
1524 if (Properties.Settings.Default.autoNaming)
\r
1525 text_destination.Text = Main.AutoName(this);
\r
1527 // Disable chapter markers if only 1 chapter is selected.
\r
1528 if (chapterStart == chapterEnd)
\r
1530 Check_ChapterMarkers.Enabled = false;
\r
1531 btn_importChapters.Enabled = false;
\r
1532 data_chpt.Enabled = false;
\r
1536 Check_ChapterMarkers.Enabled = true;
\r
1537 if (Check_ChapterMarkers.Checked)
\r
1539 btn_importChapters.Enabled = true;
\r
1540 data_chpt.Enabled = true;
\r
1545 private void SecondsOrFramesChanged(object sender, EventArgs e)
\r
1548 int.TryParse(drop_chapterStart.Text, out start);
\r
1549 int.TryParse(drop_chapterFinish.Text, out end);
\r
1550 double duration = end - start;
\r
1552 switch (drop_mode.SelectedIndex)
\r
1555 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1558 if (selectedTitle != null)
\r
1560 duration = duration / selectedTitle.Fps;
\r
1561 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1564 lbl_duration.Text = "--:--:--";
\r
1570 private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)
\r
1573 this.drop_chapterFinish.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1574 this.drop_chapterStart.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1577 switch (drop_mode.SelectedIndex)
\r
1580 drop_chapterStart.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1581 drop_chapterFinish.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1582 if (drop_chapterStart.Items.Count != 0)
\r
1584 drop_chapterStart.SelectedIndex = 0;
\r
1585 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1588 lbl_duration.Text = "--:--:--";
\r
1591 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1592 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1593 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1594 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1595 if (selectedTitle != null)
\r
1597 drop_chapterStart.Text = "0";
\r
1598 drop_chapterFinish.Text = selectedTitle.Duration.TotalSeconds.ToString();
\r
1602 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1603 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1604 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1605 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1606 if (selectedTitle != null)
\r
1608 drop_chapterStart.Text = "0";
\r
1609 drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();
\r
1616 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
1618 // This removes the file extension from the filename box on the save file dialog.
\r
1619 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
1620 DVD_Save.FileName = Path.GetFileNameWithoutExtension(text_destination.Text);
\r
1622 if (Path.IsPathRooted(text_destination.Text))
\r
1623 DVD_Save.InitialDirectory = Path.GetDirectoryName(text_destination.Text);
\r
1625 // Show the dialog and set the main form file path
\r
1626 if (drop_format.SelectedIndex.Equals(0))
\r
1627 DVD_Save.FilterIndex = 1;
\r
1628 else if (drop_format.SelectedIndex.Equals(1))
\r
1629 DVD_Save.FilterIndex = 2;
\r
1631 if (DVD_Save.ShowDialog() == DialogResult.OK)
\r
1633 // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames
\r
1634 switch (DVD_Save.FilterIndex)
\r
1638 !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",
\r
1639 StringComparison.InvariantCultureIgnoreCase))
\r
1640 if (Properties.Settings.Default.useM4v)
\r
1641 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");
\r
1643 DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");
\r
1647 !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))
\r
1648 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");
\r
1654 text_destination.Text = DVD_Save.FileName;
\r
1656 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
1657 if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)
\r
1658 SetExtension(".m4v");
\r
1662 private void text_destination_TextChanged(object sender, EventArgs e)
\r
1664 string path = text_destination.Text;
\r
1665 if (path.EndsWith(".mp4") || path.EndsWith(".m4v"))
\r
1666 drop_format.SelectedIndex = 0;
\r
1667 else if (path.EndsWith(".mkv"))
\r
1668 drop_format.SelectedIndex = 1;
\r
1671 // Output Settings
\r
1672 private void drop_format_SelectedIndexChanged(object sender, EventArgs e)
\r
1674 switch (drop_format.SelectedIndex)
\r
1677 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||
\r
1678 AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())
\r
1679 SetExtension(".m4v");
\r
1681 SetExtension(".mp4");
\r
1684 SetExtension(".mkv");
\r
1688 AudioSettings.SetContainer(drop_format.Text);
\r
1690 if (drop_format.Text.Contains("MP4"))
\r
1692 if (drp_videoEncoder.Items.Contains("VP3 (Theora)"))
\r
1694 drp_videoEncoder.Items.Remove("VP3 (Theora)");
\r
1695 drp_videoEncoder.SelectedIndex = 1;
\r
1698 else if (drop_format.Text.Contains("MKV"))
\r
1699 drp_videoEncoder.Items.Add("VP3 (Theora)");
\r
1702 public void SetExtension(string newExtension)
\r
1704 if (newExtension == ".mp4" || newExtension == ".m4v")
\r
1705 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||
\r
1706 Subtitles.RequiresM4V())
\r
1707 newExtension = ".m4v";
\r
1709 newExtension = ".mp4";
\r
1711 if (Path.HasExtension(newExtension))
\r
1712 text_destination.Text = Path.ChangeExtension(text_destination.Text, newExtension);
\r
1716 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
1718 setContainerOpts();
\r
1720 // Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
1721 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1723 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
1724 check_turbo.Enabled = true;
\r
1726 tab_advanced.Enabled = true;
\r
1727 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1728 check_iPodAtom.Enabled = true;
\r
1730 check_iPodAtom.Enabled = false;
\r
1734 check_turbo.CheckState = CheckState.Unchecked;
\r
1735 check_turbo.Enabled = false;
\r
1736 tab_advanced.Enabled = false;
\r
1737 x264Panel.X264Query = string.Empty;
\r
1738 check_iPodAtom.Enabled = false;
\r
1739 check_iPodAtom.Checked = false;
\r
1742 // Setup the CQ Slider
\r
1743 switch (drp_videoEncoder.Text)
\r
1745 case "MPEG-4 (FFmpeg)":
\r
1746 if (slider_videoQuality.Value > 31)
\r
1747 slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.
\r
1748 slider_videoQuality.Minimum = 1;
\r
1749 slider_videoQuality.Maximum = 31;
\r
1751 case "H.264 (x264)":
\r
1752 slider_videoQuality.Minimum = 0;
\r
1753 slider_videoQuality.TickFrequency = 1;
\r
1755 CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
\r
1756 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1757 double multiplier = 1.0 / cqStep;
\r
1758 double value = slider_videoQuality.Value * multiplier;
\r
1760 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1762 if (value < slider_videoQuality.Maximum)
\r
1763 slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;
\r
1766 case "VP3 (Theora)":
\r
1767 if (slider_videoQuality.Value > 63)
\r
1768 slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.
\r
1769 slider_videoQuality.Minimum = 0;
\r
1770 slider_videoQuality.Maximum = 63;
\r
1776 /// When the FrameRate is not Same As Source, show the Max/Constant Mode dropdown
\r
1778 /// <param name="sender">
\r
1781 /// <param name="e">
\r
1784 private void drp_videoFramerate_SelectedIndexChanged(object sender, EventArgs e)
\r
1786 if (this.drp_videoFramerate.SelectedIndex == 0)
\r
1788 this.checkMaximumFramerate.Visible = false;
\r
1789 this.checkMaximumFramerate.CheckState = CheckState.Unchecked;
\r
1793 this.checkMaximumFramerate.Visible = true;
\r
1798 /// Set the container format options
\r
1800 public void setContainerOpts()
\r
1802 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1804 check_largeFile.Enabled = true;
\r
1805 check_optimiseMP4.Enabled = true;
\r
1806 check_iPodAtom.Enabled = true;
\r
1810 check_largeFile.Enabled = false;
\r
1811 check_optimiseMP4.Enabled = false;
\r
1812 check_iPodAtom.Enabled = false;
\r
1813 check_largeFile.Checked = false;
\r
1814 check_optimiseMP4.Checked = false;
\r
1815 check_iPodAtom.Checked = false;
\r
1819 private double _cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1822 /// Update the CQ slider for x264 for a new CQ step. This is set from option
\r
1824 public void setQualityFromSlider()
\r
1826 // Work out the current RF value.
\r
1827 double cqStep = _cachedCqStep;
\r
1828 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1830 // Change the maximum value for the slider
\r
1831 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1833 // Reset the CQ slider to RF0
\r
1834 slider_videoQuality.Value = slider_videoQuality.Maximum;
\r
1836 // Reset the CQ slider back to the previous value as close as possible
\r
1837 double cqStepNew = Properties.Settings.Default.x264cqstep;
\r
1838 double rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1839 while (rfValueCurrent < rfValue)
\r
1841 slider_videoQuality.Value--;
\r
1842 rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1845 // Cache the CQ step for the next calculation
\r
1846 _cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1849 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
1851 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1852 switch (drp_videoEncoder.Text)
\r
1854 case "MPEG-4 (FFmpeg)":
\r
1855 lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);
\r
1857 case "H.264 (x264)":
\r
1858 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1859 rfValue = Math.Round(rfValue, 2);
\r
1860 lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));
\r
1862 case "VP3 (Theora)":
\r
1863 lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;
\r
1868 private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)
\r
1870 text_bitrate.Enabled = false;
\r
1871 text_filesize.Enabled = true;
\r
1872 slider_videoQuality.Enabled = false;
\r
1874 check_2PassEncode.Enabled = true;
\r
1877 private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)
\r
1879 text_bitrate.Enabled = true;
\r
1880 text_filesize.Enabled = false;
\r
1881 slider_videoQuality.Enabled = false;
\r
1883 check_2PassEncode.Enabled = true;
\r
1886 private void radio_cq_CheckedChanged(object sender, EventArgs e)
\r
1888 text_bitrate.Enabled = false;
\r
1889 text_filesize.Enabled = false;
\r
1890 slider_videoQuality.Enabled = true;
\r
1892 check_2PassEncode.Enabled = false;
\r
1893 check_2PassEncode.CheckState = CheckState.Unchecked;
\r
1896 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
1898 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
1900 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1901 check_turbo.Enabled = true;
\r
1905 check_turbo.Enabled = false;
\r
1906 check_turbo.CheckState = CheckState.Unchecked;
\r
1910 // Chapter Marker Tab
\r
1911 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
1913 if (Check_ChapterMarkers.Checked)
\r
1915 if (drop_format.SelectedIndex != 1)
\r
1916 SetExtension(".m4v");
\r
1917 data_chpt.Enabled = true;
\r
1918 btn_importChapters.Enabled = true;
\r
1922 if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v)
\r
1923 SetExtension(".mp4");
\r
1924 data_chpt.Enabled = false;
\r
1925 btn_importChapters.Enabled = false;
\r
1929 private void btn_importChapters_Click(object sender, EventArgs e)
\r
1931 if (File_ChapterImport.ShowDialog() == DialogResult.OK)
\r
1933 string filename = File_ChapterImport.FileName;
\r
1934 DataGridView imported = Main.ImportChapterNames(data_chpt, filename);
\r
1935 if (imported != null)
\r
1936 data_chpt = imported;
\r
1940 private void btn_export_Click(object sender, EventArgs e)
\r
1942 SaveFileDialog saveFileDialog = new SaveFileDialog();
\r
1943 saveFileDialog.Filter = "Csv File|*.csv";
\r
1944 saveFileDialog.DefaultExt = "csv";
\r
1945 if (saveFileDialog.ShowDialog() == DialogResult.OK)
\r
1947 string filename = saveFileDialog.FileName;
\r
1949 Main.SaveChapterMarkersToCsv(this, filename);
\r
1953 private void mnu_resetChapters_Click(object sender, EventArgs e)
\r
1955 data_chpt.Rows.Clear();
\r
1956 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1957 if (chapterGridView != null)
\r
1959 data_chpt = chapterGridView;
\r
1963 // Query Editor Tab
\r
1964 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
1966 rtf_query.Text = QueryGenerator.GenerateFullQuery(this);
\r
1969 private void btn_clear_Click(object sender, EventArgs e)
\r
1971 rtf_query.Clear();
\r
1976 // MainWindow Components, Actions and Functions ***********************
\r
1978 #region Source Scan
\r
1981 /// Start the Scan Process
\r
1983 /// <param name="filename">
\r
1986 /// <param name="title">
\r
1989 private void StartScan(string filename, int title)
\r
1991 // Setup the GUI components for the scan.
\r
1992 sourcePath = filename;
\r
1994 this.DisableGUI();
\r
1999 SourceScan.Scan(sourcePath, title);
\r
2000 SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);
\r
2001 SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);
\r
2003 catch (Exception exc)
\r
2005 MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2010 /// Update the Status label for the scan
\r
2012 /// <param name="sender">
\r
2015 /// <param name="e">
\r
2018 private void SourceScan_ScanStatusChanged(object sender, EventArgs e)
\r
2020 UpdateScanStatusLabel();
\r
2024 /// Update the UI after the scan has completed
\r
2026 /// <param name="sender">
\r
2029 /// <param name="e">
\r
2032 private void SourceScan_ScanCompleted(object sender, EventArgs e)
\r
2034 UpdateGuiAfterScan();
\r
2038 /// Update the Scan Status Label
\r
2040 private void UpdateScanStatusLabel()
\r
2042 if (InvokeRequired)
\r
2044 BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));
\r
2047 lbl_encode.Text = SourceScan.ScanStatus;
\r
2051 /// Reset the GUI when the scan has completed
\r
2053 private void UpdateGuiAfterScan()
\r
2055 if (InvokeRequired)
\r
2057 BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));
\r
2063 currentSource = SourceScan.SouceData;
\r
2065 // Setup some GUI components
\r
2066 drp_dvdtitle.Items.Clear();
\r
2067 if (currentSource.Titles.Count != 0)
\r
2068 drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());
\r
2070 foreach (Title title in currentSource.Titles)
\r
2072 if (title.MainTitle)
\r
2074 drp_dvdtitle.SelectedItem = title;
\r
2078 if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)
\r
2080 drp_dvdtitle.SelectedIndex = 0;
\r
2083 // Enable the creation of chapter markers if the file is an image of a dvd
\r
2084 if (drop_chapterStart.Items.Count > 0)
\r
2087 int.TryParse(drop_chapterStart.Items[0].ToString(), out start);
\r
2088 int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);
\r
2089 if (end > start) Check_ChapterMarkers.Enabled = true;
\r
2092 Check_ChapterMarkers.Enabled = false;
\r
2093 Check_ChapterMarkers.Checked = false;
\r
2094 data_chpt.Rows.Clear();
\r
2098 // If no titles were found, Display an error message
\r
2099 if (drp_dvdtitle.Items.Count == 0)
\r
2102 "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
2103 "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
2104 sourcePath = string.Empty;
\r
2106 UpdateSourceLabel();
\r
2108 // Enable the GUI components and enable any disabled components
\r
2111 catch (Exception exc)
\r
2113 MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,
\r
2114 MessageBoxIcon.Error);
\r
2120 /// Enable the GUI
\r
2122 private void EnableGUI()
\r
2126 if (InvokeRequired)
\r
2127 BeginInvoke(new UpdateWindowHandler(EnableGUI));
\r
2128 lbl_encode.Text = "Scan Completed";
\r
2129 foreach (Control ctrl in Controls)
\r
2130 ctrl.Enabled = true;
\r
2131 btn_start.Enabled = true;
\r
2132 btn_showQueue.Enabled = true;
\r
2133 btn_add2Queue.Enabled = true;
\r
2134 tb_preview.Enabled = true;
\r
2135 btn_source.Enabled = true;
\r
2136 mnu_killCLI.Visible = false;
\r
2138 catch (Exception exc)
\r
2140 MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2145 /// Disable the GUI
\r
2147 private void DisableGUI()
\r
2149 foreach (Control ctrl in Controls)
\r
2150 if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))
\r
2151 ctrl.Enabled = false;
\r
2153 lbl_encode.Visible = true;
\r
2154 lbl_encode.Text = "Scanning ...";
\r
2155 btn_source.Enabled = false;
\r
2156 btn_start.Enabled = false;
\r
2157 btn_showQueue.Enabled = false;
\r
2158 btn_add2Queue.Enabled = false;
\r
2159 tb_preview.Enabled = false;
\r
2160 mnu_killCLI.Visible = true;
\r
2166 private void KillScan()
\r
2168 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2172 SourceScan.Stop();
\r
2174 lbl_encode.Text = "Scan Cancelled!";
\r
2180 private void ResetGUI()
\r
2182 drp_dvdtitle.Items.Clear();
\r
2183 drop_chapterStart.Items.Clear();
\r
2184 drop_chapterFinish.Items.Clear();
\r
2185 lbl_duration.Text = "Select a Title";
\r
2186 PictureSettings.lbl_src_res.Text = "Select a Title";
\r
2187 sourcePath = String.Empty;
\r
2188 text_destination.Text = String.Empty;
\r
2189 selectedTitle = null;
\r
2193 /// Update the Source Label
\r
2195 private void UpdateSourceLabel()
\r
2197 labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;
\r
2199 if (selectedTitle != null)
\r
2200 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
2201 // If it's one of multiple source files, make sure we don't use the folder name
\r
2202 labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
2206 /// Take a job from the Queue, rescan it, and reload the GUI for that job.
\r
2208 /// <param name="job">
\r
2211 public void RecievingJob(Job job)
\r
2213 string query = job.Query;
\r
2214 StartScan(job.Source, job.Title);
\r
2216 if (query != null)
\r
2218 // Ok, Reset all the H264 widgets before changing the preset
\r
2219 x264Panel.Reset2Defaults();
\r
2221 // Send the query from the file to the Query Parser class
\r
2222 QueryParser presetQuery = QueryParser.Parse(query);
\r
2224 // Now load the preset
\r
2225 PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue");
\r
2227 // The x264 widgets will need updated, so do this now:
\r
2228 x264Panel.StandardizeOptString();
\r
2229 x264Panel.SetCurrentSettingsInPanel();
\r
2231 // Finally, let this window have a copy of the preset settings.
\r
2232 this.currentlySelectedPreset = null;
\r
2233 PictureSettings.SetPresetCropWarningLabel(null);
\r
2239 #region GUI Functions and Actions
\r
2242 /// Set the GUI to it's finished encoding state.
\r
2244 private void SetEncodeFinished()
\r
2248 if (InvokeRequired)
\r
2250 BeginInvoke(new UpdateWindowHandler(SetEncodeFinished));
\r
2254 lbl_encode.Text = "Encoding Finished";
\r
2255 ProgressBarStatus.Visible = false;
\r
2256 btn_start.Text = "Start";
\r
2257 btn_start.ToolTipText = "Start the encoding process";
\r
2258 btn_start.Image = Properties.Resources.Play;
\r
2260 // If the window is minimized, display the notification in a popup.
\r
2261 if (Properties.Settings.Default.trayIconAlerts)
\r
2262 if (FormWindowState.Minimized == this.WindowState)
\r
2264 notifyIcon.BalloonTipText = lbl_encode.Text;
\r
2265 notifyIcon.ShowBalloonTip(500);
\r
2268 catch (Exception exc)
\r
2270 MessageBox.Show(exc.ToString());
\r
2275 /// Set the GUI to it's started encoding state.
\r
2277 private void SetEncodeStarted()
\r
2281 if (InvokeRequired)
\r
2283 BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));
\r
2286 lbl_encode.Visible = true;
\r
2287 ProgressBarStatus.Value = 0;
\r
2288 ProgressBarStatus.Visible = true;
\r
2289 lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";
\r
2290 btn_start.Text = "Stop";
\r
2291 btn_start.ToolTipText = "Stop the encoding process.";
\r
2292 btn_start.Image = Properties.Resources.stop;
\r
2294 catch (Exception exc)
\r
2296 MessageBox.Show(exc.ToString());
\r
2301 /// Display the Encode Status
\r
2303 /// <param name="sender">
\r
2306 /// <param name="e">
\r
2309 private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)
\r
2311 if (this.InvokeRequired)
\r
2313 this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });
\r
2319 "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}",
\r
2320 e.PercentComplete,
\r
2321 e.CurrentFrameRate,
\r
2322 e.AverageFrameRate,
\r
2323 e.EstimatedTimeLeft);
\r
2325 ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);
\r
2329 /// Set the DVD Drive selection in the "Source" Menu
\r
2331 private void SetDriveSelectionMenuItem()
\r
2335 if (InvokeRequired)
\r
2337 BeginInvoke(new UpdateWindowHandler(SetDriveSelectionMenuItem));
\r
2341 drives = Main.GetDrives();
\r
2343 List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
\r
2344 foreach (DriveInformation drive in drives)
\r
2346 ToolStripMenuItem menuItem = new ToolStripMenuItem
\r
2348 Name = drive.ToString(),
\r
2349 Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",
\r
2350 Image = Resources.disc_small
\r
2352 menuItem.Click += new EventHandler(mnu_dvd_drive_Click);
\r
2353 menuItems.Add(menuItem);
\r
2356 foreach (ToolStripMenuItem item in menuItems)
\r
2357 btn_source.DropDownItems.Add(item);
\r
2359 catch (Exception exc)
\r
2361 MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);
\r
2366 /// Access the preset Handler and setup the preset panel.
\r
2368 private void LoadPresetPanel()
\r
2370 if (presetHandler.CheckIfPresetsAreOutOfDate())
\r
2371 if (!Properties.Settings.Default.presetNotification)
\r
2372 MessageBox.Show(splash,
\r
2373 "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",
\r
2374 "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
2376 presetHandler.GetPresetPanel(ref treeView_presets);
\r
2377 treeView_presets.Update();
\r
2381 /// Get the title from the selected item in the title dropdown.
\r
2386 private int GetTitle()
\r
2389 if (drp_dvdtitle.SelectedItem != null)
\r
2391 string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');
\r
2392 int.TryParse(titleInfo[0], out title);
\r
2399 /// Handle the Update Check Finishing.
\r
2401 /// <param name="result">
\r
2404 private void UpdateCheckDoneMenu(IAsyncResult result)
\r
2406 // Make sure it's running on the calling thread
\r
2407 if (InvokeRequired)
\r
2409 Invoke(new MethodInvoker(() => this.UpdateCheckDoneMenu(result)));
\r
2412 UpdateCheckInformation info;
\r
2415 // Get the information about the new build, if any, and close the window
\r
2416 info = Main.EndCheckForUpdates(result);
\r
2418 if (info.NewVersionAvailable && info.BuildInformation != null)
\r
2420 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
2421 updateWindow.ShowDialog();
\r
2424 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,
\r
2425 MessageBoxIcon.Information);
\r
2426 lbl_updateCheck.Visible = false;
\r
2429 catch (Exception ex)
\r
2431 if ((bool)result.AsyncState)
\r
2433 "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,
\r
2434 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2443 /// Handle GUI shortcuts
\r
2445 /// <param name="msg">Message</param>
\r
2446 /// <param name="keyData">Keys</param>
\r
2447 /// <returns>Bool</returns>
\r
2448 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
2450 if (keyData == (Keys.Control | Keys.S))
\r
2452 btn_start_Click(this, new EventArgs());
\r
2456 if (keyData == (Keys.Control | Keys.A))
\r
2458 btn_add2Queue_Click(this, new EventArgs());
\r
2461 return base.ProcessCmdKey(ref msg, keyData);
\r
2465 /// If the queue is being processed, prompt the user to confirm application close.
\r
2467 /// <param name="e">FormClosingEventArgs</param>
\r
2468 protected override void OnFormClosing(FormClosingEventArgs e)
\r
2470 // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.
\r
2471 if (encodeQueue.IsEncoding)
\r
2473 DialogResult result =
\r
2475 "HandBrake has queue items to process. Closing HandBrake will stop the current encoding.\n\nDo you want to close HandBrake?",
\r
2476 "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
2478 if (result == DialogResult.No)
\r
2484 // Try to safely close out if we can, or kill the cli if using in-gui status
\r
2485 if (Settings.Default.enocdeStatusInGui)
\r
2486 encodeQueue.Stop();
\r
2488 encodeQueue.SafelyClose();
\r
2491 if (SourceScan.IsScanning)
\r
2493 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2494 SourceScan.Stop();
\r
2496 base.OnFormClosing(e);
\r
2501 // This is the END of the road ****************************************
\r