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
156 presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).PictureSettings);
\r
158 x264Panel.StandardizeOptString();
\r
159 x264Panel.SetCurrentSettingsInPanel();
\r
163 loadNormalPreset();
\r
165 // Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)
\r
166 GrowlCommunicator.Register();
\r
168 // Finished Loading
\r
169 UpdateSplashStatus(lblStatus, "Loading Complete.");
\r
172 this.Enabled = true;
\r
174 // Event Handlers and Queue Recovery
\r
178 // If have a file passed in via command arguemtents, check it's a file and try scanning it.
\r
179 if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0])))
\r
181 this.StartScan(args[0], 0);
\r
185 private void UpdateCheckDone(IAsyncResult result)
\r
187 if (InvokeRequired)
\r
189 Invoke(new MethodInvoker(() => UpdateCheckDone(result)));
\r
193 UpdateCheckInformation info;
\r
197 info = Main.EndCheckForUpdates(result);
\r
199 if (info.NewVersionAvailable)
\r
201 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
202 updateWindow.ShowDialog();
\r
205 catch (Exception ex)
\r
207 if ((bool)result.AsyncState)
\r
208 Main.ShowExceptiowWindow("Unable to check for updates, Please try again later.", ex.ToString());
\r
212 // Startup Functions
\r
213 private void queueRecovery()
\r
215 if (Main.CheckQueueRecovery())
\r
217 DialogResult result =
\r
219 "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?",
\r
220 "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
222 if (result == DialogResult.Yes)
\r
223 encodeQueue.LoadQueueFromFile("hb_queue_recovery.xml"); // Start Recovery
\r
226 // Remove the Queue recovery file if the user doesn't want to recovery the last queue.
\r
227 string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
\r
228 if (File.Exists(queuePath))
\r
229 File.Delete(queuePath);
\r
234 private void UpdateSplashStatus(Label status, string text)
\r
236 status.Text = text;
\r
237 Application.DoEvents();
\r
244 // Encoding Events for setting up the GUI
\r
245 private void events()
\r
247 // Handle Widget changes when preset is selected.
\r
248 RegisterPresetEventHandler();
\r
250 // Handle Window Resize
\r
251 if (Properties.Settings.Default.MainWindowMinimize)
\r
252 this.Resize += new EventHandler(frmMain_Resize);
\r
254 // Handle Encode Start / Finish / Pause
\r
255 encodeQueue.EncodeStarted += new EventHandler(encodeStarted);
\r
256 encodeQueue.EncodeEnded += new EventHandler(encodeEnded);
\r
258 // Handle a file being draged onto the GUI.
\r
259 this.DragEnter += new DragEventHandler(frmMain_DragEnter);
\r
260 this.DragDrop += new DragEventHandler(frmMain_DragDrop);
\r
263 // 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
264 private void RegisterPresetEventHandler()
\r
267 drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
268 check_largeFile.CheckedChanged += new EventHandler(changePresetLabel);
\r
269 check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel);
\r
270 check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);
\r
272 // Picture Settings
\r
273 PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);
\r
276 Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);
\r
279 drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel);
\r
280 check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel);
\r
281 check_turbo.CheckedChanged += new EventHandler(changePresetLabel);
\r
282 text_filesize.TextChanged += new EventHandler(changePresetLabel);
\r
283 text_bitrate.TextChanged += new EventHandler(changePresetLabel);
\r
284 slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel);
\r
287 AudioSettings.AudioListChanged += new EventHandler(changePresetLabel);
\r
290 x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);
\r
293 private void UnRegisterPresetEventHandler()
\r
295 // Output Settings
\r
296 drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
297 check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel);
\r
298 check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel);
\r
299 check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);
\r
301 // Picture Settings
\r
302 PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);
\r
305 Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);
\r
308 drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel);
\r
309 check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel);
\r
310 check_turbo.CheckedChanged -= new EventHandler(changePresetLabel);
\r
311 text_filesize.TextChanged -= new EventHandler(changePresetLabel);
\r
312 text_bitrate.TextChanged -= new EventHandler(changePresetLabel);
\r
313 slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel);
\r
316 AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel);
\r
319 x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);
\r
322 private void changePresetLabel(object sender, EventArgs e)
\r
324 labelPreset.Text = "Output Settings (Preset: Custom)";
\r
325 this.currentlySelectedPreset = null;
\r
328 private static void frmMain_DragEnter(object sender, DragEventArgs e)
\r
330 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
\r
331 e.Effect = DragDropEffects.All;
\r
334 private void frmMain_DragDrop(object sender, DragEventArgs e)
\r
336 string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
\r
337 sourcePath = string.Empty;
\r
339 if (fileList != null)
\r
341 if (!string.IsNullOrEmpty(fileList[0]))
\r
343 this.selectedSourceType = SourceType.VideoFile;
\r
344 StartScan(fileList[0], 0);
\r
347 UpdateSourceLabel();
\r
350 UpdateSourceLabel();
\r
353 private void encodeStarted(object sender, EventArgs e)
\r
355 SetEncodeStarted();
\r
356 encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;
\r
359 private void encodeEnded(object sender, EventArgs e)
\r
361 encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;
\r
362 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.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0),
\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(this.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 // TODO this requires a re-think since the Query Editor has changed.
\r
654 DialogResult result =
\r
656 "Do you wish to include picture settings when updating the preset: " +
\r
657 treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,
\r
658 MessageBoxIcon.Question);
\r
659 if (result == DialogResult.Yes)
\r
660 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
661 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);
\r
662 else if (result == DialogResult.No)
\r
663 presetHandler.Update(treeView_presets.SelectedNode.Text,
\r
664 QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);
\r
668 /// RMenu - Delete Preset
\r
670 /// <param name="sender">
\r
673 /// <param name="e">
\r
676 private void pmnu_delete_click(object sender, EventArgs e)
\r
678 if (treeView_presets.SelectedNode != null)
\r
680 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
681 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
683 treeView_presets.Select();
\r
687 /// Preset Menu Is Opening. Setup the Menu
\r
689 /// <param name="sender">
\r
692 /// <param name="e">
\r
695 private void presets_menu_Opening(object sender, CancelEventArgs e)
\r
697 // Make sure that the save menu is always disabled by default
\r
698 pmnu_saveChanges.Enabled = false;
\r
700 // Now enable the save menu if the selected preset is a user preset
\r
701 if (treeView_presets.SelectedNode != null)
\r
702 if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))
\r
703 pmnu_saveChanges.Enabled = true;
\r
705 treeView_presets.Select();
\r
708 // Presets Management
\r
711 /// Button - Add a preset
\r
713 /// <param name="sender">
\r
716 /// <param name="e">
\r
719 private void btn_addPreset_Click(object sender, EventArgs e)
\r
721 // TODO this requires a re-think due to the Query Editor Changing.
\r
722 Form preset = new frmAddPreset(this, QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), presetHandler);
\r
723 preset.ShowDialog();
\r
727 /// Button - remove a Preset
\r
729 /// <param name="sender">
\r
732 /// <param name="e">
\r
735 private void btn_removePreset_Click(object sender, EventArgs e)
\r
737 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
738 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
739 if (result == DialogResult.Yes)
\r
741 if (treeView_presets.SelectedNode != null)
\r
743 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
744 treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
\r
747 treeView_presets.Select();
\r
751 /// Button - Set the selected preset as the default
\r
753 /// <param name="sender">
\r
756 /// <param name="e">
\r
759 private void btn_setDefault_Click(object sender, EventArgs e)
\r
761 if (treeView_presets.SelectedNode != null)
\r
763 DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",
\r
764 "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
765 if (result == DialogResult.Yes)
\r
767 Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;
\r
768 Properties.Settings.Default.Save();
\r
769 MessageBox.Show("New default preset set.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
773 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
777 /// PresetBar Mouse Down event
\r
779 /// <param name="sender">
\r
782 /// <param name="e">
\r
785 private void treeview_presets_mouseUp(object sender, MouseEventArgs e)
\r
787 if (e.Button == MouseButtons.Right)
\r
788 treeView_presets.SelectedNode = treeView_presets.GetNodeAt(e.Location);
\r
789 else if (e.Button == MouseButtons.Left)
\r
791 if (treeView_presets.GetNodeAt(e.Location) != null)
\r
793 if (labelPreset.Text.Contains(treeView_presets.GetNodeAt(e.Location).Text))
\r
798 treeView_presets.Select();
\r
802 /// Preset Bar after selecting the preset
\r
804 /// <param name="sender">
\r
807 /// <param name="e">
\r
810 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
816 /// Preset Bar - Handle the Delete Key
\r
818 /// <param name="sender">
\r
821 /// <param name="e">
\r
824 private void treeView_presets_deleteKey(object sender, KeyEventArgs e)
\r
826 if (e.KeyCode == Keys.Delete)
\r
828 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",
\r
829 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
830 if (result == DialogResult.Yes)
\r
832 if (treeView_presets.SelectedNode != null)
\r
833 presetHandler.Remove(treeView_presets.SelectedNode.Text);
\r
835 // Remember each nodes expanded status so we can reload it
\r
836 List<bool> nodeStatus = new List<bool>();
\r
837 foreach (TreeNode node in treeView_presets.Nodes)
\r
838 nodeStatus.Add(node.IsExpanded);
\r
840 // Now reload the preset panel
\r
843 // And finally, re-expand any of the nodes if required
\r
845 foreach (TreeNode node in treeView_presets.Nodes)
\r
857 /// Select the selected preset and setup the GUI
\r
859 private void selectPreset()
\r
861 if (treeView_presets.SelectedNode != null)
\r
863 // Ok, so, we've selected a preset. Now we want to load it.
\r
864 string presetName = treeView_presets.SelectedNode.Text;
\r
865 Preset preset = presetHandler.GetPreset(presetName);
\r
866 if (preset != null)
\r
868 string query = presetHandler.GetPreset(presetName).Query;
\r
869 bool loadPictureSettings = presetHandler.GetPreset(presetName).PictureSettings;
\r
873 // Ok, Reset all the H264 widgets before changing the preset
\r
874 x264Panel.Reset2Defaults();
\r
876 // Send the query from the file to the Query Parser class
\r
877 QueryParser presetQuery = QueryParser.Parse(query);
\r
879 // Now load the preset
\r
880 PresetLoader.LoadPreset(this, presetQuery, presetName, loadPictureSettings);
\r
882 // The x264 widgets will need updated, so do this now:
\r
883 x264Panel.StandardizeOptString();
\r
884 x264Panel.SetCurrentSettingsInPanel();
\r
886 // Finally, let this window have a copy of the preset settings.
\r
887 this.currentlySelectedPreset = preset;
\r
888 PictureSettings.SetPresetCropWarningLabel(preset);
\r
895 /// Load the Normal Preset
\r
897 private void loadNormalPreset()
\r
899 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
901 foreach (TreeNode node in treenode.Nodes)
\r
903 if (node.Text.Equals("Normal"))
\r
904 treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0];
\r
910 /// Import a plist preset
\r
912 private void ImportPreset()
\r
914 if (openPreset.ShowDialog() == DialogResult.OK)
\r
916 QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);
\r
917 if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))
\r
919 DialogResult result =
\r
920 MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",
\r
921 "Overwrite preset?",
\r
922 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
923 if (result == DialogResult.Yes)
\r
925 PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);
\r
926 presetHandler.Update(parsed.PresetName + " (Imported)",
\r
927 QueryGenerator.GenerateFullQuery(this),
\r
928 parsed.UsesPictureSettings);
\r
933 PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);
\r
934 if (presetHandler.Add(parsed.PresetName + " (Imported)",
\r
935 QueryGenerator.GenerateFullQuery(this),
\r
936 parsed.UsesPictureSettings))
\r
938 TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")
\r
940 ForeColor = Color.Black
\r
942 treeView_presets.Nodes.Add(preset_treeview);
\r
949 /// Export a plist Preset
\r
951 private void ExportPreset()
\r
953 MessageBox.Show("This feature has not been implimented yet.", "Not Implimented", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
956 SaveFileDialog savefiledialog = new SaveFileDialog();
\r
957 savefiledialog.Filter = "plist|*.plist";
\r
959 if (treeView_presets.SelectedNode != null)
\r
962 if (savefiledialog.ShowDialog() == DialogResult.OK)
\r
964 Preset preset = presetHandler.GetPreset(treeView_presets.SelectedNode.Text);
\r
965 PlistPresetHandler.Export(savefiledialog.FileName, preset);
\r
975 /// 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
977 /// <param name="sender">
\r
980 /// <param name="e">
\r
983 private void btn_source_Click(object sender, EventArgs e)
\r
985 // Remove old Drive Menu Items.
\r
986 List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();
\r
987 foreach (var item in btn_source.DropDownItems)
\r
989 if (item.GetType() == typeof(ToolStripMenuItem))
\r
991 ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
\r
992 if (menuItem.Name.StartsWith("Drive"))
\r
994 itemsToRemove.Add(menuItem);
\r
999 foreach (ToolStripMenuItem item in itemsToRemove)
\r
1000 btn_source.DropDownItems.Remove(item);
\r
1002 Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);
\r
1003 driveInfoThread.Start();
\r
1007 /// Toolbar - Start The Encode
\r
1009 /// <param name="sender">
\r
1012 /// <param name="e">
\r
1015 private void btn_start_Click(object sender, EventArgs e)
\r
1017 if (btn_start.Text == "Stop")
\r
1019 DialogResult result;
\r
1020 if (Properties.Settings.Default.enocdeStatusInGui &&
\r
1021 !Properties.Settings.Default.showCliForInGuiEncodeStatus)
\r
1023 result = MessageBox.Show(
\r
1024 "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
1025 "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1029 result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?",
\r
1030 MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
1033 if (result == DialogResult.Yes)
\r
1035 // Pause The Queue
\r
1036 encodeQueue.Pause();
\r
1038 if (Settings.Default.enocdeStatusInGui && !Settings.Default.showCliForInGuiEncodeStatus)
\r
1040 encodeQueue.Stop();
\r
1044 encodeQueue.SafelyClose();
\r
1050 // 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
1051 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1052 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1054 if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))
\r
1056 string generatedQuery = QueryGenerator.GenerateFullQuery(this);
\r
1057 string specifiedQuery = rtf_query.Text != string.Empty
\r
1059 : QueryGenerator.GenerateFullQuery(this);
\r
1060 string query = string.Empty;
\r
1062 // Check to make sure the generated query matches the GUI settings
\r
1063 if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) &&
\r
1064 generatedQuery != specifiedQuery)
\r
1066 DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " +
\r
1067 "does not match the current GUI settings.\n\nBecause the manual query takes " +
\r
1068 "priority over the GUI, your recently updated settings will not be taken " +
\r
1069 "into account when encoding this job." +
\r
1070 Environment.NewLine + Environment.NewLine +
\r
1071 "Do you want to replace the manual query with the updated GUI-generated query?",
\r
1072 "Manual Query does not Match GUI",
\r
1073 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,
\r
1074 MessageBoxDefaultButton.Button3);
\r
1078 case DialogResult.Yes:
\r
1079 // Replace the manual query with the generated one
\r
1080 query = generatedQuery;
\r
1081 rtf_query.Text = generatedQuery;
\r
1083 case DialogResult.No:
\r
1084 // Use the manual query
\r
1085 query = specifiedQuery;
\r
1087 case DialogResult.Cancel:
\r
1088 // Don't start the encode
\r
1094 query = specifiedQuery;
\r
1097 DialogResult overwrite = DialogResult.Yes;
\r
1098 if (!string.IsNullOrEmpty(jobDestination) && File.Exists(jobDestination))
\r
1100 overwrite = MessageBox.Show(
\r
1101 "The destination file already exists. Are you sure you want to overwrite it?",
\r
1102 "Overwrite File?",
\r
1103 MessageBoxButtons.YesNo,
\r
1104 MessageBoxIcon.Question);
\r
1107 if (overwrite == DialogResult.Yes)
\r
1109 if (encodeQueue.Count == 0)
\r
1110 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1112 queueWindow.SetQueue();
\r
1113 if (encodeQueue.Count > 1)
\r
1114 queueWindow.Show(false);
\r
1116 SetEncodeStarted(); // Encode is running, so setup the GUI appropriately
\r
1117 encodeQueue.Start(); // Start The Queue Encoding Process
\r
1122 else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1123 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1124 MessageBoxIcon.Warning);
\r
1129 /// Toolbar - Add the current job to the Queue
\r
1131 /// <param name="sender">
\r
1134 /// <param name="e">
\r
1137 private void btn_add2Queue_Click(object sender, EventArgs e)
\r
1139 // Get the CLI query or use the query editor if it's not empty.
\r
1140 string query = QueryGenerator.GenerateFullQuery(this);
\r
1141 if (!string.IsNullOrEmpty(rtf_query.Text))
\r
1142 query = rtf_query.Text;
\r
1144 // 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
1145 string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;
\r
1146 string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;
\r
1148 // Make sure we have a Source and Destination.
\r
1149 if (string.IsNullOrEmpty(jobSourcePath) || string.IsNullOrEmpty(jobDestination))
\r
1151 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1155 // Make sure the destination path exists.
\r
1156 if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))
\r
1158 MessageBox.Show("Destination Path does not exist.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1162 // Make sure we don't have a duplciate on the queue.
\r
1163 if (encodeQueue.CheckForDestinationDuplicate(jobDestination))
\r
1165 DialogResult result =
\r
1167 "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
1168 "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
1169 if (result == DialogResult.Yes)
\r
1170 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1173 encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));
\r
1175 lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";
\r
1177 queueWindow.Show();
\r
1182 /// Toolbar - Show the Queue
\r
1184 /// <param name="sender">
\r
1187 /// <param name="e">
\r
1190 private void btn_showQueue_Click(object sender, EventArgs e)
\r
1192 queueWindow.Show();
\r
1193 queueWindow.Activate();
\r
1197 /// Toolbar - Show the Preview Window
\r
1199 /// <param name="sender">
\r
1202 /// <param name="e">
\r
1205 private void tb_preview_Click(object sender, EventArgs e)
\r
1207 if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))
\r
1208 MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,
\r
1209 MessageBoxIcon.Warning);
\r
1212 if (qtpreview == null)
\r
1214 qtpreview = new frmPreview(this);
\r
1217 else if (qtpreview.IsDisposed)
\r
1219 qtpreview = new frmPreview(this);
\r
1223 MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,
\r
1224 MessageBoxIcon.Warning);
\r
1229 /// Toolbar - Show the Activity log Window
\r
1231 /// <param name="sender">
\r
1234 /// <param name="e">
\r
1237 private void btn_ActivityWindow_Click(object sender, EventArgs e)
\r
1239 if (this.activityWindow == null || !this.activityWindow.IsHandleCreated)
\r
1240 this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan);
\r
1242 this.activityWindow.Show();
\r
1243 this.activityWindow.Activate();
\r
1248 #region System Tray Icon
\r
1251 /// Handle Resizing of the main window when deaing with the Notify Icon
\r
1253 /// <param name="sender">
\r
1256 /// <param name="e">
\r
1259 private void frmMain_Resize(object sender, EventArgs e)
\r
1261 if (FormWindowState.Minimized == this.WindowState)
\r
1263 notifyIcon.Visible = true;
\r
1266 else if (FormWindowState.Normal == this.WindowState)
\r
1267 notifyIcon.Visible = false;
\r
1271 /// Double Click the Tray Icon
\r
1273 /// <param name="sender">
\r
1276 /// <param name="e">
\r
1279 private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
\r
1281 this.Visible = true;
\r
1283 this.WindowState = FormWindowState.Normal;
\r
1284 notifyIcon.Visible = false;
\r
1288 /// Tray Icon - Restore Menu Item - Resture the Window
\r
1290 /// <param name="sender">
\r
1293 /// <param name="e">
\r
1296 private void btn_restore_Click(object sender, EventArgs e)
\r
1298 this.Visible = true;
\r
1300 this.WindowState = FormWindowState.Normal;
\r
1301 notifyIcon.Visible = false;
\r
1306 #region Main Window and Tab Control
\r
1309 private void btn_dvd_source_Click(object sender, EventArgs e)
\r
1311 if (DVD_Open.ShowDialog() == DialogResult.OK)
\r
1313 this.selectedSourceType = SourceType.Folder;
\r
1314 SelectSource(DVD_Open.SelectedPath);
\r
1317 UpdateSourceLabel();
\r
1320 private void btn_file_source_Click(object sender, EventArgs e)
\r
1322 if (ISO_Open.ShowDialog() == DialogResult.OK)
\r
1324 this.selectedSourceType = SourceType.VideoFile;
\r
1325 SelectSource(ISO_Open.FileName);
\r
1328 UpdateSourceLabel();
\r
1331 private void mnu_dvd_drive_Click(object sender, EventArgs e)
\r
1333 ToolStripMenuItem item = sender as ToolStripMenuItem;
\r
1336 string driveId = item.Name.Replace("Drive", string.Empty);
\r
1338 if (int.TryParse(driveId, out id))
\r
1341 this.dvdDrivePath = drives[id].RootDirectory;
\r
1342 this.dvdDriveLabel = drives[id].VolumeLabel;
\r
1344 if (this.dvdDrivePath == null) return;
\r
1345 this.selectedSourceType = SourceType.DvdDrive;
\r
1346 SelectSource(this.dvdDrivePath);
\r
1351 private void SelectSource(string file)
\r
1353 Check_ChapterMarkers.Enabled = true;
\r
1354 sourcePath = string.Empty;
\r
1356 if (file == string.Empty) // Must have a file or path
\r
1358 UpdateSourceLabel();
\r
1362 sourcePath = Path.GetFileName(file);
\r
1363 StartScan(file, 0);
\r
1366 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
1368 if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))
\r
1370 "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",
\r
1371 "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
1374 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1376 UnRegisterPresetEventHandler();
\r
1377 drop_mode.SelectedIndex = 0;
\r
1379 drop_chapterStart.Items.Clear();
\r
1380 drop_chapterFinish.Items.Clear();
\r
1382 // If the dropdown is set to automatic nothing else needs to be done.
\r
1383 // Otheriwse if its not, title data has to be loaded from parsing.
\r
1384 if (drp_dvdtitle.Text != "Automatic")
\r
1386 selectedTitle = drp_dvdtitle.SelectedItem as Title;
\r
1387 lbl_duration.Text = selectedTitle.Duration.ToString();
\r
1388 PictureSettings.CurrentlySelectedPreset = this.currentlySelectedPreset;
\r
1389 PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control
\r
1391 // Populate the Angles dropdown
\r
1392 drop_angle.Items.Clear();
\r
1393 if (!Properties.Settings.Default.noDvdNav)
\r
1395 drop_angle.Visible = true;
\r
1396 lbl_angle.Visible = true;
\r
1398 for (int i = 1; i <= selectedTitle.AngleCount; i++)
\r
1399 drop_angle.Items.Add(i.ToString());
\r
1401 if (drop_angle.Items.Count != 0)
\r
1402 drop_angle.SelectedIndex = 0;
\r
1406 drop_angle.Visible = false;
\r
1407 lbl_angle.Visible = false;
\r
1410 // Populate the Start chapter Dropdown
\r
1411 drop_chapterStart.Items.Clear();
\r
1412 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1413 if (drop_chapterStart.Items.Count > 0)
\r
1414 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
1416 // Populate the Final Chapter Dropdown
\r
1417 drop_chapterFinish.Items.Clear();
\r
1418 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
1419 if (drop_chapterFinish.Items.Count > 0)
\r
1420 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
1422 // Populate the Audio Channels Dropdown
\r
1423 AudioSettings.SetTrackList(selectedTitle, this.currentlySelectedPreset);
\r
1425 // Populate the Subtitles dropdown
\r
1426 Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());
\r
1428 // Update the source label if we have multiple streams
\r
1429 if (selectedTitle != null)
\r
1430 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
1431 labelSource.Text = labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
1433 // Run the AutoName & ChapterNaming functions
\r
1434 if (Properties.Settings.Default.autoNaming)
\r
1436 string autoPath = Main.AutoName(this);
\r
1437 if (autoPath != null)
\r
1438 text_destination.Text = autoPath;
\r
1441 "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
1442 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
1445 data_chpt.Rows.Clear();
\r
1446 if (selectedTitle.Chapters.Count != 1)
\r
1448 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1449 if (chapterGridView != null)
\r
1450 data_chpt = chapterGridView;
\r
1454 Check_ChapterMarkers.Checked = false;
\r
1455 Check_ChapterMarkers.Enabled = false;
\r
1458 // Hack to force the redraw of the scrollbars which don't resize properly when the control is disabled.
\r
1459 data_chpt.Columns[0].Width = 166;
\r
1460 data_chpt.Columns[0].Width = 165;
\r
1462 RegisterPresetEventHandler();
\r
1465 private void chapersChanged(object sender, EventArgs e)
\r
1467 if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.
\r
1470 Control ctl = (Control)sender;
\r
1471 int chapterStart, chapterEnd;
\r
1472 int.TryParse(drop_chapterStart.Text, out chapterStart);
\r
1473 int.TryParse(drop_chapterFinish.Text, out chapterEnd);
\r
1477 case "drop_chapterStart":
\r
1478 if (drop_chapterFinish.SelectedIndex == -1 && drop_chapterFinish.Items.Count != 0)
\r
1479 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1481 if (chapterEnd != 0)
\r
1482 if (chapterStart > chapterEnd)
\r
1483 drop_chapterFinish.Text = chapterStart.ToString();
\r
1485 case "drop_chapterFinish":
\r
1486 if (drop_chapterStart.Items.Count >= 1 && drop_chapterStart.SelectedIndex == -1)
\r
1487 drop_chapterStart.SelectedIndex = 0;
\r
1489 if (chapterStart != 0)
\r
1490 if (chapterEnd < chapterStart)
\r
1491 drop_chapterFinish.Text = chapterStart.ToString();
\r
1493 // Add more rows to the Chapter menu if needed.
\r
1494 if (Check_ChapterMarkers.Checked)
\r
1496 int i = data_chpt.Rows.Count, finish = 0;
\r
1497 int.TryParse(drop_chapterFinish.Text, out finish);
\r
1499 while (i < finish)
\r
1501 int n = data_chpt.Rows.Add();
\r
1502 data_chpt.Rows[n].Cells[0].Value = (i + 1);
\r
1503 data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
\r
1504 data_chpt.Rows[n].Cells[0].ValueType = typeof(int);
\r
1505 data_chpt.Rows[n].Cells[1].ValueType = typeof(string);
\r
1512 // Update the Duration
\r
1513 lbl_duration.Text =
\r
1514 Main.CalculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle)
\r
1517 // Run the Autonaming function
\r
1518 if (Properties.Settings.Default.autoNaming)
\r
1519 text_destination.Text = Main.AutoName(this);
\r
1521 // Disable chapter markers if only 1 chapter is selected.
\r
1522 if (chapterStart == chapterEnd)
\r
1524 Check_ChapterMarkers.Enabled = false;
\r
1525 btn_importChapters.Enabled = false;
\r
1526 data_chpt.Enabled = false;
\r
1530 Check_ChapterMarkers.Enabled = true;
\r
1531 if (Check_ChapterMarkers.Checked)
\r
1533 btn_importChapters.Enabled = true;
\r
1534 data_chpt.Enabled = true;
\r
1539 private void SecondsOrFramesChanged(object sender, EventArgs e)
\r
1542 int.TryParse(drop_chapterStart.Text, out start);
\r
1543 int.TryParse(drop_chapterFinish.Text, out end);
\r
1544 double duration = end - start;
\r
1546 switch (drop_mode.SelectedIndex)
\r
1549 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1552 if (selectedTitle != null)
\r
1554 duration = duration / selectedTitle.Fps;
\r
1555 lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();
\r
1558 lbl_duration.Text = "--:--:--";
\r
1564 private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)
\r
1567 this.drop_chapterFinish.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1568 this.drop_chapterStart.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);
\r
1571 switch (drop_mode.SelectedIndex)
\r
1574 drop_chapterStart.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1575 drop_chapterFinish.DropDownStyle = ComboBoxStyle.DropDownList;
\r
1576 if (drop_chapterStart.Items.Count != 0)
\r
1578 drop_chapterStart.SelectedIndex = 0;
\r
1579 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
1582 lbl_duration.Text = "--:--:--";
\r
1585 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1586 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1587 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1588 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1589 if (selectedTitle != null)
\r
1591 drop_chapterStart.Text = "0";
\r
1592 drop_chapterFinish.Text = selectedTitle.Duration.TotalSeconds.ToString();
\r
1596 this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1597 this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);
\r
1598 drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;
\r
1599 drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;
\r
1600 if (selectedTitle != null)
\r
1602 drop_chapterStart.Text = "0";
\r
1603 drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();
\r
1610 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
1612 // This removes the file extension from the filename box on the save file dialog.
\r
1613 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
1614 DVD_Save.FileName = Path.GetFileNameWithoutExtension(text_destination.Text);
\r
1616 if (Path.IsPathRooted(text_destination.Text))
\r
1617 DVD_Save.InitialDirectory = Path.GetDirectoryName(text_destination.Text);
\r
1619 // Show the dialog and set the main form file path
\r
1620 if (drop_format.SelectedIndex.Equals(0))
\r
1621 DVD_Save.FilterIndex = 1;
\r
1622 else if (drop_format.SelectedIndex.Equals(1))
\r
1623 DVD_Save.FilterIndex = 2;
\r
1625 if (DVD_Save.ShowDialog() == DialogResult.OK)
\r
1627 // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames
\r
1628 switch (DVD_Save.FilterIndex)
\r
1632 !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",
\r
1633 StringComparison.InvariantCultureIgnoreCase))
\r
1634 if (Properties.Settings.Default.useM4v)
\r
1635 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");
\r
1637 DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");
\r
1641 !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))
\r
1642 DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");
\r
1648 text_destination.Text = DVD_Save.FileName;
\r
1650 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
1651 if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)
\r
1652 SetExtension(".m4v");
\r
1656 private void text_destination_TextChanged(object sender, EventArgs e)
\r
1658 string path = text_destination.Text;
\r
1659 if (path.EndsWith(".mp4") || path.EndsWith(".m4v"))
\r
1660 drop_format.SelectedIndex = 0;
\r
1661 else if (path.EndsWith(".mkv"))
\r
1662 drop_format.SelectedIndex = 1;
\r
1665 // Output Settings
\r
1666 private void drop_format_SelectedIndexChanged(object sender, EventArgs e)
\r
1668 switch (drop_format.SelectedIndex)
\r
1671 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||
\r
1672 AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())
\r
1673 SetExtension(".m4v");
\r
1675 SetExtension(".mp4");
\r
1678 SetExtension(".mkv");
\r
1682 AudioSettings.SetContainer(drop_format.Text);
\r
1684 if (drop_format.Text.Contains("MP4"))
\r
1686 if (drp_videoEncoder.Items.Contains("VP3 (Theora)"))
\r
1688 drp_videoEncoder.Items.Remove("VP3 (Theora)");
\r
1689 drp_videoEncoder.SelectedIndex = 1;
\r
1692 else if (drop_format.Text.Contains("MKV"))
\r
1693 drp_videoEncoder.Items.Add("VP3 (Theora)");
\r
1696 public void SetExtension(string newExtension)
\r
1698 if (newExtension == ".mp4" || newExtension == ".m4v")
\r
1699 if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||
\r
1700 Subtitles.RequiresM4V())
\r
1701 newExtension = ".m4v";
\r
1703 newExtension = ".mp4";
\r
1705 if (Path.HasExtension(newExtension))
\r
1706 text_destination.Text = Path.ChangeExtension(text_destination.Text, newExtension);
\r
1710 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
1712 setContainerOpts();
\r
1714 // Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
1715 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1717 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
1718 check_turbo.Enabled = true;
\r
1720 tab_advanced.Enabled = true;
\r
1721 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1722 check_iPodAtom.Enabled = true;
\r
1724 check_iPodAtom.Enabled = false;
\r
1728 check_turbo.CheckState = CheckState.Unchecked;
\r
1729 check_turbo.Enabled = false;
\r
1730 tab_advanced.Enabled = false;
\r
1731 x264Panel.X264Query = string.Empty;
\r
1732 check_iPodAtom.Enabled = false;
\r
1733 check_iPodAtom.Checked = false;
\r
1736 // Setup the CQ Slider
\r
1737 switch (drp_videoEncoder.Text)
\r
1739 case "MPEG-4 (FFmpeg)":
\r
1740 if (slider_videoQuality.Value > 31)
\r
1741 slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.
\r
1742 slider_videoQuality.Minimum = 1;
\r
1743 slider_videoQuality.Maximum = 31;
\r
1745 case "H.264 (x264)":
\r
1746 slider_videoQuality.Minimum = 0;
\r
1747 slider_videoQuality.TickFrequency = 1;
\r
1749 CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
\r
1750 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1751 double multiplier = 1.0 / cqStep;
\r
1752 double value = slider_videoQuality.Value * multiplier;
\r
1754 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1756 if (value < slider_videoQuality.Maximum)
\r
1757 slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;
\r
1760 case "VP3 (Theora)":
\r
1761 if (slider_videoQuality.Value > 63)
\r
1762 slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.
\r
1763 slider_videoQuality.Minimum = 0;
\r
1764 slider_videoQuality.Maximum = 63;
\r
1770 /// When the FrameRate is not Same As Source, show the Max/Constant Mode dropdown
\r
1772 /// <param name="sender">
\r
1775 /// <param name="e">
\r
1778 private void drp_videoFramerate_SelectedIndexChanged(object sender, EventArgs e)
\r
1780 if (this.drp_videoFramerate.SelectedIndex == 0)
\r
1782 this.checkMaximumFramerate.Visible = false;
\r
1783 this.checkMaximumFramerate.CheckState = CheckState.Unchecked;
\r
1787 this.checkMaximumFramerate.Visible = true;
\r
1792 /// Set the container format options
\r
1794 public void setContainerOpts()
\r
1796 if ((drop_format.Text.Contains("MP4")) || (drop_format.Text.Contains("M4V")))
\r
1798 check_largeFile.Enabled = true;
\r
1799 check_optimiseMP4.Enabled = true;
\r
1800 check_iPodAtom.Enabled = true;
\r
1804 check_largeFile.Enabled = false;
\r
1805 check_optimiseMP4.Enabled = false;
\r
1806 check_iPodAtom.Enabled = false;
\r
1807 check_largeFile.Checked = false;
\r
1808 check_optimiseMP4.Checked = false;
\r
1809 check_iPodAtom.Checked = false;
\r
1813 private double _cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1816 /// Update the CQ slider for x264 for a new CQ step. This is set from option
\r
1818 public void setQualityFromSlider()
\r
1820 // Work out the current RF value.
\r
1821 double cqStep = _cachedCqStep;
\r
1822 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1824 // Change the maximum value for the slider
\r
1825 slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);
\r
1827 // Reset the CQ slider to RF0
\r
1828 slider_videoQuality.Value = slider_videoQuality.Maximum;
\r
1830 // Reset the CQ slider back to the previous value as close as possible
\r
1831 double cqStepNew = Properties.Settings.Default.x264cqstep;
\r
1832 double rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1833 while (rfValueCurrent < rfValue)
\r
1835 slider_videoQuality.Value--;
\r
1836 rfValueCurrent = 51.0 - slider_videoQuality.Value * cqStepNew;
\r
1839 // Cache the CQ step for the next calculation
\r
1840 _cachedCqStep = Properties.Settings.Default.x264cqstep;
\r
1843 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
1845 double cqStep = Properties.Settings.Default.x264cqstep;
\r
1846 switch (drp_videoEncoder.Text)
\r
1848 case "MPEG-4 (FFmpeg)":
\r
1849 lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);
\r
1851 case "H.264 (x264)":
\r
1852 double rfValue = 51.0 - slider_videoQuality.Value * cqStep;
\r
1853 rfValue = Math.Round(rfValue, 2);
\r
1854 lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));
\r
1856 case "VP3 (Theora)":
\r
1857 lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;
\r
1862 private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)
\r
1864 text_bitrate.Enabled = false;
\r
1865 text_filesize.Enabled = true;
\r
1866 slider_videoQuality.Enabled = false;
\r
1868 check_2PassEncode.Enabled = true;
\r
1871 private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)
\r
1873 text_bitrate.Enabled = true;
\r
1874 text_filesize.Enabled = false;
\r
1875 slider_videoQuality.Enabled = false;
\r
1877 check_2PassEncode.Enabled = true;
\r
1880 private void radio_cq_CheckedChanged(object sender, EventArgs e)
\r
1882 text_bitrate.Enabled = false;
\r
1883 text_filesize.Enabled = false;
\r
1884 slider_videoQuality.Enabled = true;
\r
1886 check_2PassEncode.Enabled = false;
\r
1887 check_2PassEncode.CheckState = CheckState.Unchecked;
\r
1890 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
1892 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
1894 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1895 check_turbo.Enabled = true;
\r
1899 check_turbo.Enabled = false;
\r
1900 check_turbo.CheckState = CheckState.Unchecked;
\r
1904 // Chapter Marker Tab
\r
1905 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
1907 if (Check_ChapterMarkers.Checked)
\r
1909 if (drop_format.SelectedIndex != 1)
\r
1910 SetExtension(".m4v");
\r
1911 data_chpt.Enabled = true;
\r
1912 btn_importChapters.Enabled = true;
\r
1916 if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v)
\r
1917 SetExtension(".mp4");
\r
1918 data_chpt.Enabled = false;
\r
1919 btn_importChapters.Enabled = false;
\r
1923 private void btn_importChapters_Click(object sender, EventArgs e)
\r
1925 if (File_ChapterImport.ShowDialog() == DialogResult.OK)
\r
1927 string filename = File_ChapterImport.FileName;
\r
1928 DataGridView imported = Main.ImportChapterNames(data_chpt, filename);
\r
1929 if (imported != null)
\r
1930 data_chpt = imported;
\r
1934 private void btn_export_Click(object sender, EventArgs e)
\r
1936 SaveFileDialog saveFileDialog = new SaveFileDialog();
\r
1937 saveFileDialog.Filter = "Csv File|*.csv";
\r
1938 saveFileDialog.DefaultExt = "csv";
\r
1939 if (saveFileDialog.ShowDialog() == DialogResult.OK)
\r
1941 string filename = saveFileDialog.FileName;
\r
1943 Main.SaveChapterMarkersToCsv(this, filename);
\r
1947 private void mnu_resetChapters_Click(object sender, EventArgs e)
\r
1949 data_chpt.Rows.Clear();
\r
1950 DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1951 if (chapterGridView != null)
\r
1953 data_chpt = chapterGridView;
\r
1957 // Query Editor Tab
\r
1958 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
1960 rtf_query.Text = QueryGenerator.GenerateFullQuery(this);
\r
1963 private void btn_clear_Click(object sender, EventArgs e)
\r
1965 rtf_query.Clear();
\r
1970 // MainWindow Components, Actions and Functions ***********************
\r
1972 #region Source Scan
\r
1975 /// Start the Scan Process
\r
1977 /// <param name="filename">
\r
1980 /// <param name="title">
\r
1983 private void StartScan(string filename, int title)
\r
1985 // Setup the GUI components for the scan.
\r
1986 sourcePath = filename;
\r
1988 this.DisableGUI();
\r
1993 SourceScan.Scan(sourcePath, title);
\r
1994 SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);
\r
1995 SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);
\r
1997 catch (Exception exc)
\r
1999 MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2004 /// Update the Status label for the scan
\r
2006 /// <param name="sender">
\r
2009 /// <param name="e">
\r
2012 private void SourceScan_ScanStatusChanged(object sender, EventArgs e)
\r
2014 UpdateScanStatusLabel();
\r
2018 /// Update the UI after the scan has completed
\r
2020 /// <param name="sender">
\r
2023 /// <param name="e">
\r
2026 private void SourceScan_ScanCompleted(object sender, EventArgs e)
\r
2028 UpdateGuiAfterScan();
\r
2032 /// Update the Scan Status Label
\r
2034 private void UpdateScanStatusLabel()
\r
2036 if (InvokeRequired)
\r
2038 BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));
\r
2041 lbl_encode.Text = SourceScan.ScanStatus;
\r
2045 /// Reset the GUI when the scan has completed
\r
2047 private void UpdateGuiAfterScan()
\r
2049 if (InvokeRequired)
\r
2051 BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));
\r
2057 currentSource = SourceScan.SouceData;
\r
2059 // Setup some GUI components
\r
2060 drp_dvdtitle.Items.Clear();
\r
2061 if (currentSource.Titles.Count != 0)
\r
2062 drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());
\r
2064 foreach (Title title in currentSource.Titles)
\r
2066 if (title.MainTitle)
\r
2068 drp_dvdtitle.SelectedItem = title;
\r
2072 if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)
\r
2074 drp_dvdtitle.SelectedIndex = 0;
\r
2077 // Enable the creation of chapter markers if the file is an image of a dvd
\r
2078 if (drop_chapterStart.Items.Count > 0)
\r
2081 int.TryParse(drop_chapterStart.Items[0].ToString(), out start);
\r
2082 int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);
\r
2083 if (end > start) Check_ChapterMarkers.Enabled = true;
\r
2086 Check_ChapterMarkers.Enabled = false;
\r
2087 Check_ChapterMarkers.Checked = false;
\r
2088 data_chpt.Rows.Clear();
\r
2092 // If no titles were found, Display an error message
\r
2093 if (drp_dvdtitle.Items.Count == 0)
\r
2096 "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
2097 "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
2098 sourcePath = string.Empty;
\r
2100 UpdateSourceLabel();
\r
2102 // Enable the GUI components and enable any disabled components
\r
2105 catch (Exception exc)
\r
2107 MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,
\r
2108 MessageBoxIcon.Error);
\r
2114 /// Enable the GUI
\r
2116 private void EnableGUI()
\r
2120 if (InvokeRequired)
\r
2121 BeginInvoke(new UpdateWindowHandler(EnableGUI));
\r
2122 lbl_encode.Text = "Scan Completed";
\r
2123 foreach (Control ctrl in Controls)
\r
2124 ctrl.Enabled = true;
\r
2125 btn_start.Enabled = true;
\r
2126 btn_showQueue.Enabled = true;
\r
2127 btn_add2Queue.Enabled = true;
\r
2128 tb_preview.Enabled = true;
\r
2129 btn_source.Enabled = true;
\r
2130 mnu_killCLI.Visible = false;
\r
2132 catch (Exception exc)
\r
2134 MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2139 /// Disable the GUI
\r
2141 private void DisableGUI()
\r
2143 foreach (Control ctrl in Controls)
\r
2144 if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))
\r
2145 ctrl.Enabled = false;
\r
2147 lbl_encode.Visible = true;
\r
2148 lbl_encode.Text = "Scanning ...";
\r
2149 btn_source.Enabled = false;
\r
2150 btn_start.Enabled = false;
\r
2151 btn_showQueue.Enabled = false;
\r
2152 btn_add2Queue.Enabled = false;
\r
2153 tb_preview.Enabled = false;
\r
2154 mnu_killCLI.Visible = true;
\r
2160 private void KillScan()
\r
2162 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2166 SourceScan.Stop();
\r
2168 lbl_encode.Text = "Scan Cancelled!";
\r
2174 private void ResetGUI()
\r
2176 drp_dvdtitle.Items.Clear();
\r
2177 drop_chapterStart.Items.Clear();
\r
2178 drop_chapterFinish.Items.Clear();
\r
2179 lbl_duration.Text = "Select a Title";
\r
2180 PictureSettings.lbl_src_res.Text = "Select a Title";
\r
2181 sourcePath = String.Empty;
\r
2182 text_destination.Text = String.Empty;
\r
2183 selectedTitle = null;
\r
2187 /// Update the Source Label
\r
2189 private void UpdateSourceLabel()
\r
2191 labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;
\r
2193 if (selectedTitle != null)
\r
2194 if (!string.IsNullOrEmpty(selectedTitle.SourceName))
\r
2195 // If it's one of multiple source files, make sure we don't use the folder name
\r
2196 labelSource.Text = Path.GetFileName(selectedTitle.SourceName);
\r
2200 /// Take a job from the Queue, rescan it, and reload the GUI for that job.
\r
2202 /// <param name="job">
\r
2205 public void RecievingJob(Job job)
\r
2207 string query = job.Query;
\r
2208 StartScan(job.Source, job.Title);
\r
2210 if (query != null)
\r
2212 // Ok, Reset all the H264 widgets before changing the preset
\r
2213 x264Panel.Reset2Defaults();
\r
2215 // Send the query from the file to the Query Parser class
\r
2216 QueryParser presetQuery = QueryParser.Parse(query);
\r
2218 // Now load the preset
\r
2219 PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue", true);
\r
2221 // The x264 widgets will need updated, so do this now:
\r
2222 x264Panel.StandardizeOptString();
\r
2223 x264Panel.SetCurrentSettingsInPanel();
\r
2225 // Finally, let this window have a copy of the preset settings.
\r
2226 this.currentlySelectedPreset = null;
\r
2227 PictureSettings.SetPresetCropWarningLabel(null);
\r
2233 #region GUI Functions and Actions
\r
2236 /// Set the GUI to it's finished encoding state.
\r
2238 private void SetEncodeFinished()
\r
2242 if (InvokeRequired)
\r
2244 BeginInvoke(new UpdateWindowHandler(SetEncodeFinished));
\r
2248 lbl_encode.Text = "Encoding Finished";
\r
2249 ProgressBarStatus.Visible = false;
\r
2250 btn_start.Text = "Start";
\r
2251 btn_start.ToolTipText = "Start the encoding process";
\r
2252 btn_start.Image = Properties.Resources.Play;
\r
2254 // If the window is minimized, display the notification in a popup.
\r
2255 if (Properties.Settings.Default.trayIconAlerts)
\r
2256 if (FormWindowState.Minimized == this.WindowState)
\r
2258 notifyIcon.BalloonTipText = lbl_encode.Text;
\r
2259 notifyIcon.ShowBalloonTip(500);
\r
2262 catch (Exception exc)
\r
2264 MessageBox.Show(exc.ToString());
\r
2269 /// Set the GUI to it's started encoding state.
\r
2271 private void SetEncodeStarted()
\r
2275 if (InvokeRequired)
\r
2277 BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));
\r
2280 lbl_encode.Visible = true;
\r
2281 ProgressBarStatus.Value = 0;
\r
2282 ProgressBarStatus.Visible = true;
\r
2283 lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";
\r
2284 btn_start.Text = "Stop";
\r
2285 btn_start.ToolTipText = "Stop the encoding process.";
\r
2286 btn_start.Image = Properties.Resources.stop;
\r
2288 catch (Exception exc)
\r
2290 MessageBox.Show(exc.ToString());
\r
2295 /// Display the Encode Status
\r
2297 /// <param name="sender">
\r
2300 /// <param name="e">
\r
2303 private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)
\r
2305 if (this.InvokeRequired)
\r
2307 this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });
\r
2313 "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}",
\r
2314 e.PercentComplete,
\r
2315 e.CurrentFrameRate,
\r
2316 e.AverageFrameRate,
\r
2317 e.EstimatedTimeLeft);
\r
2319 ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);
\r
2323 /// Set the DVD Drive selection in the "Source" Menu
\r
2325 private void SetDriveSelectionMenuItem()
\r
2329 if (InvokeRequired)
\r
2331 BeginInvoke(new UpdateWindowHandler(SetDriveSelectionMenuItem));
\r
2335 drives = Main.GetDrives();
\r
2337 List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
\r
2338 foreach (DriveInformation drive in drives)
\r
2340 ToolStripMenuItem menuItem = new ToolStripMenuItem
\r
2342 Name = drive.ToString(),
\r
2343 Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")",
\r
2344 Image = Resources.disc_small
\r
2346 menuItem.Click += new EventHandler(mnu_dvd_drive_Click);
\r
2347 menuItems.Add(menuItem);
\r
2350 foreach (ToolStripMenuItem item in menuItems)
\r
2351 btn_source.DropDownItems.Add(item);
\r
2353 catch (Exception exc)
\r
2355 MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);
\r
2360 /// Access the preset Handler and setup the preset panel.
\r
2362 private void LoadPresetPanel()
\r
2364 if (presetHandler.CheckIfPresetsAreOutOfDate())
\r
2365 if (!Properties.Settings.Default.presetNotification)
\r
2366 MessageBox.Show(splash,
\r
2367 "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",
\r
2368 "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
2370 presetHandler.GetPresetPanel(ref treeView_presets);
\r
2371 treeView_presets.Update();
\r
2375 /// Get the title from the selected item in the title dropdown.
\r
2380 private int GetTitle()
\r
2383 if (drp_dvdtitle.SelectedItem != null)
\r
2385 string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');
\r
2386 int.TryParse(titleInfo[0], out title);
\r
2393 /// Handle the Update Check Finishing.
\r
2395 /// <param name="result">
\r
2398 private void UpdateCheckDoneMenu(IAsyncResult result)
\r
2400 // Make sure it's running on the calling thread
\r
2401 if (InvokeRequired)
\r
2403 Invoke(new MethodInvoker(() => this.UpdateCheckDoneMenu(result)));
\r
2406 UpdateCheckInformation info;
\r
2409 // Get the information about the new build, if any, and close the window
\r
2410 info = Main.EndCheckForUpdates(result);
\r
2412 if (info.NewVersionAvailable && info.BuildInformation != null)
\r
2414 frmUpdater updateWindow = new frmUpdater(info.BuildInformation);
\r
2415 updateWindow.ShowDialog();
\r
2418 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,
\r
2419 MessageBoxIcon.Information);
\r
2420 lbl_updateCheck.Visible = false;
\r
2423 catch (Exception ex)
\r
2425 if ((bool)result.AsyncState)
\r
2427 "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,
\r
2428 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
2437 /// Handle GUI shortcuts
\r
2439 /// <param name="msg">Message</param>
\r
2440 /// <param name="keyData">Keys</param>
\r
2441 /// <returns>Bool</returns>
\r
2442 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
\r
2444 if (keyData == (Keys.Control | Keys.S))
\r
2446 btn_start_Click(this, new EventArgs());
\r
2450 if (keyData == (Keys.Control | Keys.A))
\r
2452 btn_add2Queue_Click(this, new EventArgs());
\r
2455 return base.ProcessCmdKey(ref msg, keyData);
\r
2459 /// If the queue is being processed, prompt the user to confirm application close.
\r
2461 /// <param name="e">FormClosingEventArgs</param>
\r
2462 protected override void OnFormClosing(FormClosingEventArgs e)
\r
2464 // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.
\r
2465 if (encodeQueue.IsEncoding)
\r
2467 DialogResult result =
\r
2469 "HandBrake has queue items to process. Closing HandBrake will stop the current encoding.\n\nDo you want to close HandBrake?",
\r
2470 "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
2472 if (result == DialogResult.No)
\r
2478 // Try to safely close out if we can, or kill the cli if using in-gui status
\r
2479 if (Settings.Default.enocdeStatusInGui)
\r
2480 encodeQueue.Stop();
\r
2482 encodeQueue.SafelyClose();
\r
2485 if (SourceScan.IsScanning)
\r
2487 SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
\r
2488 SourceScan.Stop();
\r
2490 base.OnFormClosing(e);
\r
2495 // This is the END of the road ****************************************
\r