3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr/>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections;
\r
9 using System.Collections.Generic;
\r
10 using System.Drawing;
\r
11 using System.Windows.Forms;
\r
13 using System.Diagnostics;
\r
14 using System.Threading;
\r
15 using Handbrake.Functions;
\r
16 using Handbrake.Presets;
\r
20 public partial class frmMain : Form
\r
22 // Objects which may be used by one or more other objects
\r
23 private delegate void UpdateWindowHandler();
\r
24 Main hb_common_func = new Main();
\r
25 Encode encodeHandler = new Encode();
\r
26 Queue.QueueHandler encodeQueue = new Queue.QueueHandler();
\r
27 PresetsHandler presetHandler = new PresetsHandler();
\r
28 Parsing.Title selectedTitle;
\r
29 Parsing.DVD thisDVD;
\r
31 // Objects belonging to this window only
\r
32 PresetLoader presetLoader = new PresetLoader();
\r
33 QueryGenerator queryGen = new QueryGenerator();
\r
35 // Globals: Mainly used for tracking.
\r
36 private frmQueue queueWindow;
\r
37 private frmPreview qtpreview;
\r
38 private string lastAction;
\r
39 public int maxWidth;
\r
40 public int maxHeight;
\r
43 // Applicaiton Startup ************************************************
\r
45 #region Application Startup
\r
49 // Load the splash screen in this thread
\r
50 Form splash = new frmSplashScreen();
\r
53 //Create a label that can be updated from the parent thread.
\r
54 Label lblStatus = new Label {Size = new Size(250, 20), Location = new Point(10, 280)};
\r
55 splash.Controls.Add(lblStatus);
\r
56 InitializeComponent();
\r
58 // Update the users config file with the CLI version data.
\r
59 lblStatus.Text = "Setting Version Data ...";
\r
60 Application.DoEvents();
\r
61 ArrayList x = hb_common_func.getCliVersionData();
\r
62 Properties.Settings.Default.hb_build = int.Parse(x[1].ToString());
\r
63 Properties.Settings.Default.hb_version = x[0].ToString();
\r
65 // show the form, but leave disabled until preloading is complete then show the main form
\r
66 this.Enabled = false;
\r
68 Application.DoEvents(); // Forces frmMain to draw
\r
70 // update the status
\r
71 if (Properties.Settings.Default.updateStatus == "Checked")
\r
73 lblStatus.Text = "Checking for updates ...";
\r
74 Application.DoEvents();
\r
75 Thread updateCheckThread = new Thread(startupUpdateCheck);
\r
76 updateCheckThread.Start();
\r
79 // Setup the GUI components
\r
80 lblStatus.Text = "Setting up the GUI ...";
\r
81 Application.DoEvents();
\r
82 x264Panel.reset2Defaults(); // Initialize all the x264 widgets to their default values
\r
83 loadPresetPanel(); // Load the Preset Panel
\r
84 treeView_presets.ExpandAll();
\r
85 lbl_encode.Text = "";
\r
87 queueWindow = new frmQueue(encodeQueue); // Prepare the Queue
\r
88 if (Properties.Settings.Default.QueryEditorTab != "Checked")
\r
89 tabs_panel.TabPages.RemoveAt(5); // Remove the query editor tab if the user does not want it enabled.
\r
91 // Load the user's default settings or Normal Preset
\r
92 if (Properties.Settings.Default.defaultSettings == "Checked" && Properties.Settings.Default.defaultPreset != "")
\r
94 // Ok, so, we've selected a preset. Now we want to load it.
\r
95 if (presetHandler.getPreset(Properties.Settings.Default.defaultPreset) != null)
\r
97 string query = presetHandler.getPreset(Properties.Settings.Default.defaultPreset).Query;
\r
98 Boolean loadPictureSettings = presetHandler.getPreset(Properties.Settings.Default.defaultPreset).PictureSettings;
\r
102 //Ok, Reset all the H264 widgets before changing the preset
\r
103 x264Panel.reset2Defaults();
\r
105 // Send the query from the file to the Query Parser class, then load the preset
\r
106 Functions.QueryParser presetQuery = Functions.QueryParser.Parse(query);
\r
107 presetLoader.presetLoader(this, presetQuery, Properties.Settings.Default.defaultPreset, loadPictureSettings);
\r
109 // The x264 widgets will need updated, so do this now:
\r
110 x264Panel.X264_StandardizeOptString();
\r
111 x264Panel.X264_SetCurrentSettingsInPanel();
\r
115 loadNormalPreset();
\r
118 loadNormalPreset();
\r
120 // Enabled GUI tooltip's if Required
\r
121 if (Properties.Settings.Default.tooltipEnable == "Checked")
\r
123 x264Panel.setToolTipActive(true);
\r
124 ToolTip.Active = true;
\r
128 lblStatus.Text = "Loading Complete!";
\r
129 Application.DoEvents();
\r
132 this.Enabled = true;
\r
141 // Startup Functions
\r
142 private delegate void updateStatusChanger();
\r
143 private void startupUpdateCheck()
\r
147 if (InvokeRequired)
\r
149 BeginInvoke(new updateStatusChanger(startupUpdateCheck));
\r
153 Boolean update = hb_common_func.updateCheck(false);
\r
156 frmUpdater updateWindow = new frmUpdater();
\r
157 updateWindow.Show();
\r
160 catch (Exception) { /* Do Nothing*/ }
\r
162 private void queueRecovery()
\r
164 if (hb_common_func.check_queue_recovery())
\r
166 DialogResult result = MessageBox.Show("HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?", "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
168 if (result == DialogResult.Yes)
\r
169 encodeQueue.recoverQueue("hb_queue_recovery.xml"); // Start Recovery
\r
172 // Remove the Queue recovery file if the user doesn't want to recovery the last queue.
\r
173 string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
\r
174 if (File.Exists(queuePath))
\r
175 File.Delete(queuePath);
\r
182 // Encoding Events for setting up the GUI
\r
183 private void events()
\r
185 // Handle Window Resize
\r
186 if (Properties.Settings.Default.MainWindowMinimize == "Checked")
\r
187 this.Resize += new EventHandler(frmMain_Resize);
\r
189 // Handle Encode Start / Finish / Pause
\r
190 encodeQueue.OnEncodeEnded += new EventHandler(encodeEnded);
\r
191 encodeQueue.OnPaused += new EventHandler(encodePaused);
\r
192 encodeQueue.OnEncodeStart += new EventHandler(encodeStarted);
\r
194 // Handle a file being draged onto the GUI.
\r
195 this.DragEnter += new DragEventHandler(frmMain_DragEnter);
\r
196 this.DragDrop += new DragEventHandler(frmMain_DragDrop);
\r
199 private static void frmMain_DragEnter(object sender, DragEventArgs e)
\r
201 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
\r
202 e.Effect = DragDropEffects.All;
\r
204 private void frmMain_DragDrop(object sender, DragEventArgs e)
\r
206 string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
\r
207 if (fileList != null)
\r
209 if (fileList[0].StartsWith("\\"))
\r
210 MessageBox.Show("Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
213 if (fileList[0] != "")
\r
215 setupGUIforScan(fileList[0]);
\r
216 startScan(fileList[0]);
\r
219 text_source.Text = "Click 'Source' to continue";
\r
223 private void encodeStarted(object sender, EventArgs e)
\r
225 setLastAction("encode");
\r
226 setEncodeStarted();
\r
228 private void encodeEnded(object sender, EventArgs e)
\r
230 setEncodeFinished();
\r
232 private void encodePaused(object sender, EventArgs e)
\r
234 setEncodeFinished();
\r
238 // User Interface Menus / Tool Strips *********************************
\r
241 private void mnu_killCLI_Click(object sender, EventArgs e)
\r
245 private void mnu_exit_Click(object sender, EventArgs e)
\r
247 Application.Exit();
\r
252 private void mnu_encode_Click(object sender, EventArgs e)
\r
254 queueWindow.Show();
\r
256 private void mnu_encodeLog_Click(object sender, EventArgs e)
\r
259 file = lastAction == "scan" ? "dvdinfo.dat" : "hb_encode_log.dat";
\r
261 frmActivityWindow dvdInfoWindow = new frmActivityWindow(file, encodeHandler);
\r
262 dvdInfoWindow.Show();
\r
264 private void mnu_options_Click(object sender, EventArgs e)
\r
266 Form Options = new frmOptions();
\r
267 Options.ShowDialog();
\r
271 #region Presets Menu
\r
272 private void mnu_presetReset_Click(object sender, EventArgs e)
\r
274 presetHandler.updateBuiltInPresets();
\r
276 if (treeView_presets.Nodes.Count == 0)
\r
277 MessageBox.Show("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!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
279 MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
281 treeView_presets.ExpandAll();
\r
283 private void mnu_delete_preset_Click(object sender, EventArgs e)
\r
285 // Empty the preset file
\r
286 string presetsFile = Application.StartupPath + "\\presets.xml";
\r
287 if (File.Exists(presetsFile))
\r
288 File.Delete(presetsFile);
\r
292 FileStream strm = new FileStream(presetsFile, FileMode.Create, FileAccess.Write);
\r
296 catch (Exception exc)
\r
298 MessageBox.Show("An error has occured during the preset removal process.\n If you are using Windows Vista, you may need to run under Administrator Mode to complete this task. \n" + exc);
\r
301 // Reload the preset panel
\r
304 private void mnu_SelectDefault_Click(object sender, EventArgs e)
\r
306 loadNormalPreset();
\r
308 private void btn_new_preset_Click(object sender, EventArgs e)
\r
310 // Remember each nodes expanded status so we can reload it
\r
311 List<Boolean> nodeStatus = saveTreeViewState();
\r
312 nodeStatus.Add(true);
\r
314 Form preset = new frmAddPreset(this, queryGen.GenerateTheQuery(this), presetHandler);
\r
315 preset.ShowDialog();
\r
317 // Now reload the TreeView states
\r
318 loadTreeViewStates(nodeStatus);
\r
323 private void mnu_handbrake_forums_Click(object sender, EventArgs e)
\r
325 Process.Start("http://forum.handbrake.fr/");
\r
327 private void mnu_user_guide_Click(object sender, EventArgs e)
\r
329 Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");
\r
331 private void mnu_handbrake_home_Click(object sender, EventArgs e)
\r
333 Process.Start("http://handbrake.fr");
\r
335 private void mnu_UpdateCheck_Click(object sender, EventArgs e)
\r
337 Boolean update = hb_common_func.updateCheck(true);
\r
340 frmUpdater updateWindow = new frmUpdater();
\r
341 updateWindow.Show();
\r
344 MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
346 private void mnu_about_Click(object sender, EventArgs e)
\r
348 Form About = new frmAbout();
\r
349 About.ShowDialog();
\r
354 private void mnu_qptest_Click(object sender, EventArgs e)
\r
356 QueryParserTester qptest = new QueryParserTester();
\r
362 // Right Click Menu Code
\r
363 private void pmnu_expandAll_Click(object sender, EventArgs e)
\r
365 treeView_presets.ExpandAll();
\r
367 private void pmnu_collapse_Click(object sender, EventArgs e)
\r
369 treeView_presets.CollapseAll();
\r
371 private void pmnu_saveChanges_Click(object sender, EventArgs e)
\r
373 DialogResult result = MessageBox.Show("Do you wish to include picture settings when updating the preset: " + treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
\r
374 if (result == DialogResult.Yes)
\r
375 presetHandler.updatePreset(treeView_presets.SelectedNode.Text, queryGen.generateTabbedComponentsQuery(this), true);
\r
376 else if (result == DialogResult.No)
\r
377 presetHandler.updatePreset(treeView_presets.SelectedNode.Text, queryGen.generateTabbedComponentsQuery(this), false);
\r
379 private void pmnu_delete_click(object sender, EventArgs e)
\r
381 if (treeView_presets.SelectedNode != null)
\r
383 presetHandler.remove(treeView_presets.SelectedNode.Text);
\r
385 // Remember each nodes expanded status so we can reload it
\r
386 List<Boolean> nodeStatus = saveTreeViewState();
\r
388 // Now reload the preset panel
\r
391 // Now reload the TreeView states
\r
392 loadTreeViewStates(nodeStatus);
\r
394 treeView_presets.Select();
\r
396 private void presets_menu_Opening(object sender, System.ComponentModel.CancelEventArgs e)
\r
398 // Make sure that the save menu is always disabled by default
\r
399 pmnu_saveChanges.Enabled = false;
\r
401 // Now enable the save menu if the selected preset is a user preset
\r
402 if (treeView_presets.SelectedNode != null)
\r
404 if (presetHandler.checkIfUserPresetExists(treeView_presets.SelectedNode.Text))
\r
406 pmnu_saveChanges.Enabled = true;
\r
409 treeView_presets.Select();
\r
412 // Presets Management
\r
413 private void btn_addPreset_Click(object sender, EventArgs e)
\r
415 // Remember each nodes expanded status so we can reload it
\r
416 List<Boolean> nodeStatus = saveTreeViewState();
\r
417 nodeStatus.Add(true);
\r
419 // Now add the new preset
\r
420 Form preset = new frmAddPreset(this, queryGen.generateTabbedComponentsQuery(this), presetHandler);
\r
421 preset.ShowDialog();
\r
423 // Now reload the TreeView states
\r
424 loadTreeViewStates(nodeStatus);
\r
426 private void btn_removePreset_Click(object sender, EventArgs e)
\r
428 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
429 if (result == DialogResult.Yes)
\r
431 if (treeView_presets.SelectedNode != null)
\r
432 presetHandler.remove(treeView_presets.SelectedNode.Text);
\r
434 // Remember each nodes expanded status so we can reload it
\r
435 List<Boolean> nodeStatus = saveTreeViewState();
\r
437 // Now reload the preset panel
\r
440 // Now reload the TreeView states
\r
441 loadTreeViewStates(nodeStatus);
\r
443 treeView_presets.Select();
\r
445 private void btn_setDefault_Click(object sender, EventArgs e)
\r
447 if (treeView_presets.SelectedNode != null)
\r
449 DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
450 if (result == DialogResult.Yes)
\r
452 Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;
\r
453 Properties.Settings.Default.Save();
\r
454 MessageBox.Show("New default preset set.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
458 MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
460 private void treeview_presets_mouseUp(object sender, MouseEventArgs e)
\r
462 if (e.Button == MouseButtons.Right)
\r
463 treeView_presets.SelectedNode = treeView_presets.GetNodeAt(e.Location);
\r
464 else if (e.Button == MouseButtons.Left)
\r
466 if (treeView_presets.GetNodeAt(e.Location) != null)
\r
468 if (groupBox_output.Text.Contains(treeView_presets.GetNodeAt(e.Location).Text))
\r
473 treeView_presets.Select();
\r
475 private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)
\r
479 private void selectPreset()
\r
481 if (treeView_presets.SelectedNode != null)
\r
483 // Ok, so, we've selected a preset. Now we want to load it.
\r
484 string presetName = treeView_presets.SelectedNode.Text;
\r
485 if (presetHandler.getPreset(presetName) != null)
\r
487 string query = presetHandler.getPreset(presetName).Query;
\r
488 Boolean loadPictureSettings = presetHandler.getPreset(presetName).PictureSettings;
\r
492 //Ok, Reset all the H264 widgets before changing the preset
\r
493 x264Panel.reset2Defaults();
\r
495 // Send the query from the file to the Query Parser class
\r
496 QueryParser presetQuery = QueryParser.Parse(query);
\r
498 // Now load the preset
\r
499 presetLoader.presetLoader(this, presetQuery, presetName, loadPictureSettings);
\r
501 // The x264 widgets will need updated, so do this now:
\r
502 x264Panel.X264_StandardizeOptString();
\r
503 x264Panel.X264_SetCurrentSettingsInPanel();
\r
505 if (maxWidth != 0 && maxHeight != 0)
\r
506 lbl_max.Text = "Max Width / Height";
\r
507 else if (maxWidth != 0)
\r
508 lbl_max.Text = "Max Width";
\r
515 private void treeView_presets_deleteKey(object sender, KeyEventArgs e)
\r
517 if (e.KeyCode == Keys.Delete)
\r
519 DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
520 if (result == DialogResult.Yes)
\r
522 if (treeView_presets.SelectedNode != null)
\r
523 presetHandler.remove(treeView_presets.SelectedNode.Text);
\r
525 // Remember each nodes expanded status so we can reload it
\r
526 List<Boolean> nodeStatus = new List<Boolean>();
\r
527 foreach (TreeNode node in treeView_presets.Nodes)
\r
528 nodeStatus.Add(node.IsExpanded);
\r
530 // Now reload the preset panel
\r
533 // And finally, re-expand any of the nodes if required
\r
535 foreach (TreeNode node in treeView_presets.Nodes)
\r
545 private List<Boolean> saveTreeViewState()
\r
547 // Remember each nodes expanded status so we can reload it
\r
548 List<Boolean> nodeStatus = new List<Boolean>();
\r
549 foreach (TreeNode node in treeView_presets.Nodes)
\r
551 nodeStatus.Add(node.IsExpanded);
\r
552 foreach (TreeNode subNode in node.Nodes)
\r
553 nodeStatus.Add(node.IsExpanded);
\r
557 private void loadTreeViewStates(List<Boolean> nodeStatus)
\r
559 // And finally, re-expand any of the nodes if required
\r
561 foreach (TreeNode node in treeView_presets.Nodes)
\r
566 foreach (TreeNode subNode in node.Nodes)
\r
575 private void loadNormalPreset()
\r
577 treeView_presets.Nodes.Find("Normal", true);
\r
579 foreach (TreeNode treenode in treeView_presets.Nodes)
\r
581 foreach (TreeNode node in treenode.Nodes)
\r
583 if (node.Text.Equals("Normal"))
\r
584 treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0];
\r
591 private void btn_source_Click(object sender, EventArgs e)
\r
593 if (Properties.Settings.Default.drive_detection == "Checked")
\r
595 mnu_dvd_drive.Visible = true;
\r
596 Thread driveInfoThread = new Thread(getDriveInfoThread);
\r
597 driveInfoThread.Start();
\r
600 mnu_dvd_drive.Visible = false;
\r
602 private void btn_start_Click(object sender, EventArgs e)
\r
604 if (btn_start.Text == "Stop")
\r
606 DialogResult result = MessageBox.Show("Are you sure you wish to cancel the encode? Please note that this may break the encoded file. \nTo safely cancel your encode, press ctrl-c on your keyboard in the CLI window. This *may* allow you to preview your encoded content.", "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
608 if (result == DialogResult.Yes)
\r
611 encodeQueue.pauseEncode();
\r
613 // Kill the current process.
\r
614 Process[] aProc = Process.GetProcessesByName("HandBrakeCLI");
\r
615 Process HandBrakeCLI;
\r
616 if (aProc.Length > 0)
\r
618 HandBrakeCLI = aProc[0];
\r
619 HandBrakeCLI.Kill();
\r
623 setEncodeFinished();
\r
628 if (encodeQueue.count() != 0 || (text_source.Text != string.Empty && text_source.Text != "Click 'Source' to continue" && text_destination.Text != string.Empty))
\r
630 // Set the last action to encode.
\r
631 // This is used for tracking which file to load in the activity window
\r
632 lastAction = "encode";
\r
634 String query = rtf_query.Text != "" ? rtf_query.Text : queryGen.GenerateTheQuery(this);
\r
636 if (encodeQueue.count() == 0)
\r
638 encodeQueue.add(query, text_source.Text, text_destination.Text);
\r
639 encodeQueue.write2disk("hb_queue_recovery.xml");
\r
641 queueWindow.setQueue();
\r
642 if (encodeQueue.count() > 1)
\r
643 queueWindow.Show(false);
\r
645 setEncodeStarted(); // Encode is running, so setup the GUI appropriately
\r
646 encodeQueue.startEncode(); // Start The Queue Encoding Process
\r
649 else if (text_source.Text == string.Empty || text_source.Text == "Click 'Source' to continue" || text_destination.Text == string.Empty)
\r
650 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
654 private void btn_add2Queue_Click(object sender, EventArgs e)
\r
656 if (text_source.Text == string.Empty || text_source.Text == "Click 'Source' to continue" || text_destination.Text == string.Empty)
\r
657 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
660 String query = queryGen.GenerateTheQuery(this);
\r
661 if (rtf_query.Text != "")
\r
662 query = rtf_query.Text;
\r
665 if (encodeQueue.checkDestinationPath(text_destination.Text))
\r
667 DialogResult result = MessageBox.Show("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
668 "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
\r
669 if (result == DialogResult.Yes)
\r
670 encodeQueue.add(query, text_source.Text, text_destination.Text);
\r
674 encodeQueue.add(query, text_source.Text, text_destination.Text);
\r
676 encodeQueue.write2disk("hb_queue_recovery.xml"); // Writes the queue to the recovery file, just incase the GUI crashes.
\r
677 queueWindow.Show();
\r
680 private void btn_showQueue_Click(object sender, EventArgs e)
\r
682 queueWindow.Show();
\r
684 private void tb_preview_Click(object sender, EventArgs e)
\r
686 if (text_source.Text == "" || text_source.Text == "Click 'Source' to continue" || text_destination.Text == "")
\r
687 MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
690 if (qtpreview == null)
\r
692 qtpreview = new frmPreview(this);
\r
695 else if (qtpreview.IsDisposed)
\r
697 qtpreview = new frmPreview(this);
\r
701 MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
704 private void btn_ActivityWindow_Click(object sender, EventArgs e)
\r
706 String file = lastAction == "scan" ? "dvdinfo.dat" : "hb_encode_log.dat";
\r
708 frmActivityWindow ActivityWindow = new frmActivityWindow(file, encodeHandler);
\r
709 ActivityWindow.Show();
\r
713 #region System Tray Icon
\r
714 private void frmMain_Resize(object sender, EventArgs e)
\r
716 if (FormWindowState.Minimized == this.WindowState)
\r
718 notifyIcon.Visible = true;
\r
719 notifyIcon.BalloonTipText = lbl_encode.Text != "" ? lbl_encode.Text : "Not Encoding";
\r
720 notifyIcon.ShowBalloonTip(500);
\r
723 else if (FormWindowState.Normal == this.WindowState)
\r
724 notifyIcon.Visible = false;
\r
726 private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
\r
728 this.Visible = true;
\r
730 this.WindowState = FormWindowState.Normal;
\r
731 notifyIcon.Visible = false;
\r
733 private void btn_restore_Click(object sender, EventArgs e)
\r
735 this.Visible = true;
\r
737 this.WindowState = FormWindowState.Normal;
\r
738 notifyIcon.Visible = false;
\r
742 #region Tab Control
\r
745 private void btn_dvd_source_Click(object sender, EventArgs e)
\r
747 // Enable the creation of chapter markers.
\r
748 Check_ChapterMarkers.Enabled = true;
\r
750 // Set the last action to scan.
\r
751 // This is used for tracking which file to load in the activity window
\r
752 lastAction = "scan";
\r
753 text_source.Text = "";
\r
755 if (DVD_Open.ShowDialog() == DialogResult.OK)
\r
757 String filename = DVD_Open.SelectedPath;
\r
759 if (filename.StartsWith("\\"))
\r
760 MessageBox.Show("Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
764 if (filename != "")
\r
766 setupGUIforScan(filename);
\r
767 startScan(filename);
\r
770 text_source.Text = "Click 'Source' to continue";
\r
774 text_source.Text = "Click 'Source' to continue";
\r
776 private void btn_file_source_Click(object sender, EventArgs e)
\r
778 // Set the last action to scan.
\r
779 // This is used for tracking which file to load in the activity window
\r
780 lastAction = "scan";
\r
781 text_source.Text = "";
\r
783 if (ISO_Open.ShowDialog() == DialogResult.OK)
\r
785 String filename = ISO_Open.FileName;
\r
786 if (filename.StartsWith("\\"))
\r
788 "Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer",
\r
789 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
792 if (filename != "")
\r
794 setupGUIforScan(filename);
\r
795 startScan(filename);
\r
798 text_source.Text = "Click 'Source' to continue";
\r
802 text_source.Text = "Click 'Source' to continue";
\r
804 private void mnu_dvd_drive_Click(object sender, EventArgs e)
\r
806 // Enable the creation of chapter markers.
\r
807 Check_ChapterMarkers.Enabled = true;
\r
809 // Set the last action to scan.
\r
810 // This is used for tracking which file to load in the activity window
\r
811 lastAction = "scan";
\r
813 if (mnu_dvd_drive.Text.Contains("VIDEO_TS"))
\r
815 string[] path = mnu_dvd_drive.Text.Split(' ');
\r
816 String filename = path[0];
\r
817 setupGUIforScan(filename);
\r
818 startScan(filename);
\r
821 // If there are no titles in the dropdown menu then the scan has obviously failed. Display an error message explaining to the user.
\r
822 if (drp_dvdtitle.Items.Count == 0)
\r
823 MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.\nYour Source may be copy protected, badly mastered or a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
825 lbl_encode.Text = "";
\r
827 private void drp_dvdtitle_Click(object sender, EventArgs e)
\r
829 if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))
\r
830 MessageBox.Show("There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
\r
832 private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
834 // Reset some values on the form
\r
835 lbl_Aspect.Text = "Select a Title";
\r
836 //lbl_RecomendedCrop.Text = "Select a Title";
\r
837 drop_chapterStart.Items.Clear();
\r
838 drop_chapterFinish.Items.Clear();
\r
840 // If the dropdown is set to automatic nothing else needs to be done.
\r
841 // Otheriwse if its not, title data has to be loased from parsing.
\r
842 if (drp_dvdtitle.Text != "Automatic")
\r
844 selectedTitle = drp_dvdtitle.SelectedItem as Parsing.Title;
\r
846 // Set the Aspect Ratio
\r
847 lbl_Aspect.Text = selectedTitle.AspectRatio.ToString();
\r
848 lbl_src_res.Text = selectedTitle.Resolution.Width + " x " + selectedTitle.Resolution.Height;
\r
849 lbl_duration.Text = selectedTitle.Duration.ToString();
\r
851 // Set the Recommended Cropping values
\r
852 text_top.Text = selectedTitle.AutoCropDimensions[0].ToString();
\r
853 text_bottom.Text = selectedTitle.AutoCropDimensions[1].ToString();
\r
854 text_left.Text = selectedTitle.AutoCropDimensions[2].ToString();
\r
855 text_right.Text = selectedTitle.AutoCropDimensions[3].ToString();
\r
857 // Populate the Start chapter Dropdown
\r
858 drop_chapterStart.Items.Clear();
\r
859 drop_chapterStart.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
860 if (drop_chapterStart.Items.Count > 0)
\r
861 drop_chapterStart.Text = drop_chapterStart.Items[0].ToString();
\r
863 // Populate the Final Chapter Dropdown
\r
864 drop_chapterFinish.Items.Clear();
\r
865 drop_chapterFinish.Items.AddRange(selectedTitle.Chapters.ToArray());
\r
866 if (drop_chapterFinish.Items.Count > 0)
\r
867 drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();
\r
869 // Populate the Audio Channels Dropdown
\r
870 drp_track1Audio.Items.Clear();
\r
871 drp_track1Audio.Items.Add("Automatic");
\r
872 drp_track1Audio.Items.Add("None");
\r
873 drp_track1Audio.Items.AddRange(selectedTitle.AudioTracks.ToArray());
\r
874 drp_track1Audio.SelectedIndex = 0;
\r
876 // Populate the Subtitles dropdown
\r
877 drp_subtitle.Items.Clear();
\r
878 drp_subtitle.Items.Add("None");
\r
879 drp_subtitle.Items.Add("Autoselect");
\r
880 drp_subtitle.Items.AddRange(selectedTitle.Subtitles.ToArray());
\r
881 if (drp_subtitle.Items.Count > 0)
\r
882 drp_subtitle.Text = drp_subtitle.Items[0].ToString();
\r
886 // Run the autoName & chapterNaming functions
\r
887 if (Properties.Settings.Default.autoNaming == "Checked")
\r
889 string autoPath = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);
\r
890 if (autoPath != null)
\r
891 text_destination.Text = autoPath;
\r
893 MessageBox.Show("You currently have automatic file naming enabled for the destination box, but you do not have a default direcotry set. You should set this in the program options (see Tools Menu)", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
896 data_chpt.Rows.Clear();
\r
897 DataGridView chapterGridView = hb_common_func.chapterNaming(data_chpt, drop_chapterFinish.Text);
\r
898 if (chapterGridView != null)
\r
899 data_chpt = chapterGridView;
\r
901 // Hack to force the redraw of the scrollbars which don't resize properly when the control is disabled.
\r
902 data_chpt.Columns[0].Width = 166;
\r
903 data_chpt.Columns[0].Width = 165;
\r
905 private void drop_chapterStart_SelectedIndexChanged(object sender, EventArgs e)
\r
907 int c_start, c_end;
\r
909 if (drop_chapterFinish.Text == "Auto" && drop_chapterFinish.Items.Count != 0)
\r
910 drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;
\r
912 int.TryParse(drop_chapterStart.Text, out c_start);
\r
913 int.TryParse(drop_chapterFinish.Text, out c_end);
\r
917 if (c_start > c_end)
\r
918 drop_chapterFinish.Text = c_start.ToString();
\r
921 lbl_duration.Text = hb_common_func.calculateDuration(drop_chapterStart.Text, drop_chapterFinish.Text, selectedTitle).ToString();
\r
923 // Run the Autonaming function
\r
924 if (Properties.Settings.Default.autoNaming == "Checked")
\r
925 text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);
\r
928 private void drop_chapterFinish_SelectedIndexChanged(object sender, EventArgs e)
\r
930 int c_start, c_end;
\r
932 if (drop_chapterStart.Text == "Auto" && drop_chapterStart.Items.Count >= 1)
\r
933 drop_chapterStart.SelectedIndex = 1;
\r
935 int.TryParse(drop_chapterStart.Text, out c_start);
\r
936 int.TryParse(drop_chapterFinish.Text, out c_end);
\r
940 if (c_end < c_start)
\r
941 drop_chapterFinish.Text = c_start.ToString();
\r
944 lbl_duration.Text = hb_common_func.calculateDuration(drop_chapterStart.Text, drop_chapterFinish.Text, selectedTitle).ToString();
\r
946 // Run the Autonaming function
\r
947 if (Properties.Settings.Default.autoNaming == "Checked")
\r
948 text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);
\r
950 // Add more rows to the Chapter menu if needed.
\r
951 if (Check_ChapterMarkers.Checked)
\r
953 int i = data_chpt.Rows.Count, finish = 0;
\r
955 if (drop_chapterFinish.Text != "Auto")
\r
956 int.TryParse(drop_chapterFinish.Text, out finish);
\r
960 int n = data_chpt.Rows.Add();
\r
961 data_chpt.Rows[n].Cells[0].Value = (i + 1);
\r
962 data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
\r
963 data_chpt.Rows[n].Cells[0].ValueType = typeof(int);
\r
964 data_chpt.Rows[n].Cells[1].ValueType = typeof(string);
\r
971 private void btn_destBrowse_Click(object sender, EventArgs e)
\r
973 // This removes the file extension from the filename box on the save file dialog.
\r
974 // It's daft but some users don't realise that typing an extension overrides the dropdown extension selected.
\r
975 if (Path.HasExtension(text_destination.Text))
\r
976 DVD_Save.FileName = Path.Combine(Path.GetDirectoryName(text_destination.Text), Path.GetFileNameWithoutExtension(text_destination.Text));
\r
978 // Show the dialog and set the main form file path
\r
979 if (drop_format.SelectedIndex.Equals(0))
\r
980 DVD_Save.FilterIndex = 1;
\r
981 else if (drop_format.SelectedIndex.Equals(1))
\r
982 DVD_Save.FilterIndex = 2;
\r
983 else if (drop_format.SelectedIndex.Equals(2))
\r
984 DVD_Save.FilterIndex = 3;
\r
985 else if (drop_format.SelectedIndex.Equals(3))
\r
986 DVD_Save.FilterIndex = 4;
\r
987 else if (drop_format.SelectedIndex.Equals(4))
\r
988 DVD_Save.FilterIndex = 5;
\r
990 if (DVD_Save.ShowDialog() == DialogResult.OK)
\r
992 if (DVD_Save.FileName.StartsWith("\\"))
\r
993 MessageBox.Show("Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
996 setAudioByContainer(DVD_Save.FileName);
\r
997 text_destination.Text = DVD_Save.FileName;
\r
999 // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)
\r
1000 if (Check_ChapterMarkers.Checked)
\r
1001 text_destination.Text = text_destination.Text.Replace(".mp4", ".m4v");
\r
1005 private void text_destination_TextChanged(object sender, EventArgs e)
\r
1007 string path = text_destination.Text;
\r
1008 if (path.EndsWith(".mp4"))
\r
1009 drop_format.SelectedIndex = 0;
\r
1010 else if (path.EndsWith(".m4v"))
\r
1011 drop_format.SelectedIndex = 1;
\r
1012 else if (path.EndsWith(".mkv"))
\r
1013 drop_format.SelectedIndex = 2;
\r
1016 // Output Settings
\r
1017 private void drop_format_SelectedIndexChanged(object sender, EventArgs e)
\r
1019 if (drop_format.SelectedIndex == 0)
\r
1020 setExtension(".mp4");
\r
1021 else if (drop_format.SelectedIndex == 1)
\r
1022 setExtension(".m4v");
\r
1023 else if (drop_format.SelectedIndex == 2)
\r
1024 setExtension(".mkv");
\r
1026 setAudioByContainer(drop_format.Text);
\r
1027 setVideoByContainer(drop_format.Text);
\r
1029 private void setExtension(string newExtension)
\r
1031 text_destination.Text = text_destination.Text.Replace(".mp4", newExtension);
\r
1032 text_destination.Text = text_destination.Text.Replace(".m4v", newExtension);
\r
1033 text_destination.Text = text_destination.Text.Replace(".mkv", newExtension);
\r
1037 private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)
\r
1039 if ((text_destination.Text.Contains(".mp4")) || (text_destination.Text.Contains(".m4v")))
\r
1041 check_largeFile.Enabled = true;
\r
1042 check_optimiseMP4.Enabled = true;
\r
1043 check_iPodAtom.Enabled = true;
\r
1047 check_largeFile.Enabled = false;
\r
1048 check_optimiseMP4.Enabled = false;
\r
1049 check_iPodAtom.Enabled = false;
\r
1050 check_largeFile.Checked = false;
\r
1051 check_optimiseMP4.Checked = false;
\r
1052 check_iPodAtom.Checked = false;
\r
1055 //Turn off some options which are H.264 only when the user selects a non h.264 encoder
\r
1056 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1058 if (check_2PassEncode.CheckState == CheckState.Checked)
\r
1059 check_turbo.Enabled = true;
\r
1061 h264Tab.Enabled = true;
\r
1062 if ((text_destination.Text.Contains(".mp4")) || (text_destination.Text.Contains(".m4v")))
\r
1063 check_iPodAtom.Enabled = true;
\r
1065 check_iPodAtom.Enabled = false;
\r
1069 check_turbo.CheckState = CheckState.Unchecked;
\r
1070 check_turbo.Enabled = false;
\r
1071 h264Tab.Enabled = false;
\r
1072 x264Panel.x264Query = "";
\r
1073 check_iPodAtom.Enabled = false;
\r
1074 check_iPodAtom.Checked = false;
\r
1077 // Setup the CQ Slider
\r
1078 switch (drp_videoEncoder.Text)
\r
1080 case "MPEG-4 (FFmpeg)":
\r
1081 slider_videoQuality.Minimum = 1;
\r
1082 slider_videoQuality.Maximum = 31;
\r
1083 slider_videoQuality.Value = 1;
\r
1084 SliderValue.Text = "0% QP: 31.00";
\r
1086 case "MPEG-4 (XviD)":
\r
1087 slider_videoQuality.Minimum = 1;
\r
1088 slider_videoQuality.Maximum = 31;
\r
1089 slider_videoQuality.Value = 1;
\r
1090 SliderValue.Text = "0% QP: 31.00";
\r
1092 case "H.264 (x264)":
\r
1093 slider_videoQuality.Minimum = 0;
\r
1094 slider_videoQuality.Value = 0;
\r
1095 slider_videoQuality.TickFrequency = 1;
\r
1096 SliderValue.Text = "0% RF: 51.00";
\r
1097 String step = Properties.Settings.Default.x264cqstep;
\r
1101 slider_videoQuality.Maximum = 255;
\r
1104 slider_videoQuality.Maximum = 204;
\r
1107 slider_videoQuality.Maximum = 155;
\r
1110 slider_videoQuality.Maximum = 102;
\r
1113 slider_videoQuality.Maximum = 51;
\r
1116 slider_videoQuality.Maximum = 51;
\r
1120 case "VP3 (Theora)":
\r
1121 slider_videoQuality.Minimum = 0;
\r
1122 slider_videoQuality.Maximum = 63;
\r
1123 slider_videoQuality.Value = 0;
\r
1124 SliderValue.Text = "0% QP: 0.00";
\r
1128 private void slider_videoQuality_Scroll(object sender, EventArgs e)
\r
1130 switch (drp_videoEncoder.Text)
\r
1132 case "MPEG-4 (FFmpeg)":
\r
1133 double rfValue = 31 - (slider_videoQuality.Value - 1);
\r
1134 double max = slider_videoQuality.Maximum;
\r
1135 double min = slider_videoQuality.Minimum;
\r
1136 double val = ((max - min) - (rfValue - min)) / (max - min);
\r
1137 SliderValue.Text = Math.Round((val * 100), 2) + "% QP:" + (32 - slider_videoQuality.Value);
\r
1139 case "MPEG-4 (XviD)":
\r
1140 rfValue = 31 - (slider_videoQuality.Value - 1);
\r
1141 max = slider_videoQuality.Maximum;
\r
1142 min = slider_videoQuality.Minimum;
\r
1143 val = ((max - min) - (rfValue - min)) / (max - min);
\r
1144 SliderValue.Text = Math.Round((val * 100), 2) + "% QP:" + (32 - slider_videoQuality.Value);
\r
1146 case "H.264 (x264)":
\r
1148 System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
\r
1149 double.TryParse(Properties.Settings.Default.x264cqstep,
\r
1150 System.Globalization.NumberStyles.Number,
\r
1153 rfValue = 51.0 - slider_videoQuality.Value * divided;
\r
1154 max = slider_videoQuality.Maximum * divided;
\r
1155 min = slider_videoQuality.Minimum;
\r
1156 val = ((max - min) - (rfValue - min)) / (max - min);
\r
1157 rfValue = Math.Round(rfValue, 2);
\r
1158 SliderValue.Text = Math.Round((val * 100), 2) + "% RF:" + rfValue;
\r
1160 case "VP3 (Theora)":
\r
1161 rfValue = slider_videoQuality.Value;
\r
1162 double value = rfValue / 63;
\r
1163 SliderValue.Text = Math.Round((value * 100), 2) + "% QP:" + slider_videoQuality.Value;
\r
1167 private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)
\r
1169 text_bitrate.Enabled = false;
\r
1170 text_filesize.Enabled = true;
\r
1171 slider_videoQuality.Enabled = false;
\r
1173 check_2PassEncode.Enabled = true;
\r
1175 private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)
\r
1177 text_bitrate.Enabled = true;
\r
1178 text_filesize.Enabled = false;
\r
1179 slider_videoQuality.Enabled = false;
\r
1181 check_2PassEncode.Enabled = true;
\r
1183 private void radio_cq_CheckedChanged(object sender, EventArgs e)
\r
1185 text_bitrate.Enabled = false;
\r
1186 text_filesize.Enabled = false;
\r
1187 slider_videoQuality.Enabled = true;
\r
1189 check_2PassEncode.Enabled = false;
\r
1190 check_2PassEncode.CheckState = CheckState.Unchecked;
\r
1192 private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)
\r
1194 if (check_2PassEncode.CheckState.ToString() == "Checked")
\r
1196 if (drp_videoEncoder.Text.Contains("H.264"))
\r
1197 check_turbo.Enabled = true;
\r
1201 check_turbo.Enabled = false;
\r
1202 check_turbo.CheckState = CheckState.Unchecked;
\r
1207 private void text_width_TextChanged(object sender, EventArgs e)
\r
1209 if (text_width.Text == "")
\r
1210 text_width.BackColor = Color.White;
\r
1212 maxWidth = 0; maxHeight = 0; // Reset max width so that it's not using the MaxWidth -X. Quick hack to allow -X for preset usage.
\r
1213 lbl_max.Text = "";
\r
1216 Boolean parsed = int.TryParse(text_width.Text, out width);
\r
1219 text_width.BackColor = (width % 16) != 0 ? Color.LightCoral : Color.LightGreen;
\r
1221 if (lbl_Aspect.Text != "Select a Title" && maxWidth == 0 && maxHeight == 0)
\r
1223 if (drp_anamorphic.Text == "None")
\r
1225 int height = hb_common_func.cacluateNonAnamorphicHeight(width, text_top.Value, text_bottom.Value, text_left.Value, text_right.Value, selectedTitle);
\r
1227 text_height.Text = height.ToString();
\r
1232 private void text_height_TextChanged(object sender, EventArgs e)
\r
1234 if (text_height.Text == "")
\r
1235 text_height.BackColor = Color.White;
\r
1237 maxHeight = 0; // Reset max height so that it's not using the MaxHeight -Y. Quick hack to allow -Y for preset usage.
\r
1238 if (maxWidth != 0)
\r
1239 lbl_max.Text = "Max Width";
\r
1241 lbl_max.Text = "";
\r
1244 Boolean parsed = int.TryParse(text_height.Text, out height);
\r
1246 text_height.BackColor = (height % 16) != 0 ? Color.LightCoral : Color.LightGreen;
\r
1248 private void check_customCrop_CheckedChanged(object sender, EventArgs e)
\r
1250 text_left.Enabled = true;
\r
1251 text_right.Enabled = true;
\r
1252 text_top.Enabled = true;
\r
1253 text_bottom.Enabled = true;
\r
1254 if (selectedTitle != null)
\r
1256 text_top.Text = selectedTitle.AutoCropDimensions[0].ToString();
\r
1257 text_bottom.Text = selectedTitle.AutoCropDimensions[1].ToString();
\r
1258 text_left.Text = selectedTitle.AutoCropDimensions[2].ToString();
\r
1259 text_right.Text = selectedTitle.AutoCropDimensions[3].ToString();
\r
1263 text_left.Text = "0";
\r
1264 text_right.Text = "0";
\r
1265 text_top.Text = "0";
\r
1266 text_bottom.Text = "0";
\r
1269 private void check_autoCrop_CheckedChanged(object sender, EventArgs e)
\r
1271 text_left.Enabled = false;
\r
1272 text_right.Enabled = false;
\r
1273 text_top.Enabled = false;
\r
1274 text_bottom.Enabled = false;
\r
1276 private void drp_anamorphic_SelectedIndexChanged(object sender, EventArgs e)
\r
1278 if (drp_anamorphic.SelectedIndex == 1)
\r
1280 text_height.BackColor = Color.LightGray;
\r
1281 text_width.BackColor = Color.LightGray;
\r
1282 text_height.Text = "";
\r
1283 text_width.Text = "";
\r
1284 text_height.Enabled = false;
\r
1285 text_width.Enabled = false;
\r
1288 if (drp_anamorphic.SelectedIndex == 2)
\r
1290 text_height.Text = "";
\r
1291 text_height.Enabled = false;
\r
1292 text_height.BackColor = Color.LightGray;
\r
1294 text_width.Enabled = true;
\r
1295 text_width.BackColor = Color.White;
\r
1298 if (drp_anamorphic.SelectedIndex == 0)
\r
1300 text_height.BackColor = Color.White;
\r
1301 text_width.BackColor = Color.White;
\r
1302 text_height.Enabled = true;
\r
1303 text_width.Enabled = true;
\r
1308 private void ctl_decomb_changed(object sender, EventArgs e)
\r
1310 if (ctl_decomb.getDropValue != "Off")
\r
1311 if (ctl_deinterlace.getDropValue != "None")
\r
1312 ctl_deinterlace.setOption("None");
\r
1314 private void ctl_deinterlace_changed(object sender, EventArgs e)
\r
1316 if (ctl_detelecine.getDropValue != "None")
\r
1317 if (ctl_decomb.getDropValue != "Off")
\r
1318 ctl_decomb.setOption("Off");
\r
1320 private void slider_deblock_Scroll(object sender, EventArgs e)
\r
1322 lbl_deblockVal.Text = slider_deblock.Value == 4 ? "Off" : slider_deblock.Value.ToString();
\r
1326 private void drp_track1Audio_SelectedIndexChanged(object sender, EventArgs e)
\r
1328 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
1330 lv_audioList.Items[lv_audioList.SelectedIndices[0]].Text = drp_track1Audio.Text;
\r
1331 lv_audioList.Select();
\r
1334 private void drp_audenc_1_SelectedIndexChanged(object sender, EventArgs e)
\r
1336 if (drp_audenc_1.Text == "AC3")
\r
1338 drp_audmix_1.Enabled = false;
\r
1339 drp_audbit_1.Enabled = false;
\r
1340 drp_audsr_1.Enabled = false;
\r
1342 drp_audmix_1.SelectedIndex = 0;
\r
1343 drp_audbit_1.SelectedIndex = 0;
\r
1344 drp_audsr_1.SelectedIndex = 0;
\r
1348 drp_audmix_1.Enabled = true;
\r
1349 drp_audbit_1.Enabled = true;
\r
1350 drp_audsr_1.Enabled = true;
\r
1352 drp_audmix_1.Text = "Automatic";
\r
1353 drp_audbit_1.Text = "160";
\r
1354 drp_audsr_1.Text = "Auto";
\r
1357 if (drp_audenc_1.Text == "AAC")
\r
1359 setMixDownAllOptions(drp_audmix_1);
\r
1360 setBitrateSelections160(drp_audbit_1);
\r
1364 setMixDownNotAAC(drp_audmix_1);
\r
1365 setBitrateSelections320(drp_audbit_1);
\r
1368 // Update an item in the Audio list if required.
\r
1369 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
1371 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text = drp_audenc_1.Text;
\r
1372 lv_audioList.Select();
\r
1375 private void drp_audmix_1_SelectedIndexChanged(object sender, EventArgs e)
\r
1377 if ((drp_audenc_1.Text == "AAC") && (drp_audmix_1.Text == "6 Channel Discrete"))
\r
1378 setBitrateSelections384(drp_audbit_1);
\r
1379 else if ((drp_audenc_1.Text == "AAC") && (drp_audmix_1.Text != "6 Channel Discrete"))
\r
1380 setBitrateSelections160(drp_audbit_1); drp_audbit_1.Text = "160";
\r
1382 // Update an item in the Audio list if required.
\r
1383 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
1385 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text = drp_audmix_1.Text;
\r
1386 lv_audioList.Select();
\r
1389 private void drp_audsr_1_SelectedIndexChanged(object sender, EventArgs e)
\r
1391 // Update an item in the Audio list if required.
\r
1392 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
1394 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text = drp_audsr_1.Text;
\r
1395 lv_audioList.Select();
\r
1398 private void drp_audbit_1_SelectedIndexChanged(object sender, EventArgs e)
\r
1400 // Update an item in the Audio list if required.
\r
1401 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
1403 if (drp_audenc_1.Text == "AC3")
\r
1404 drp_audbit_1.Text = "Auto";
\r
1405 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text = drp_audbit_1.Text;
\r
1406 lv_audioList.Select();
\r
1409 private void tb_drc_Scroll(object sender, EventArgs e)
\r
1412 if (tb_drc.Value == 0) value = 0;
\r
1414 value = ((tb_drc.Value - 1) / 10.0) + 1;
\r
1416 lbl_drc.Text = value.ToString();
\r
1418 // Update an item in the Audio list if required.
\r
1419 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
1421 lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text = lbl_drc.Text;
\r
1422 lv_audioList.Select();
\r
1426 private void btn_addAudioTrack_Click(object sender, EventArgs e)
\r
1428 // Create a new row for the Audio list based on the currently selected items in the dropdown.
\r
1429 ListViewItem newTrack = new ListViewItem(drp_track1Audio.Text);
\r
1430 newTrack.SubItems.Add(drp_audenc_1.Text);
\r
1431 newTrack.SubItems.Add(drp_audmix_1.Text);
\r
1432 newTrack.SubItems.Add(drp_audsr_1.Text);
\r
1433 newTrack.SubItems.Add(drp_audbit_1.Text);
\r
1434 newTrack.SubItems.Add(lbl_drc.Text);
\r
1436 // Select the newly added track and select the control
\r
1437 lv_audioList.Items.Add(newTrack);
\r
1438 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
1439 lv_audioList.Select();
\r
1441 private void btn_RemoveAudioTrack_Click(object sender, EventArgs e)
\r
1443 removeAudioTrack();
\r
1445 private void audioList_moveup_Click(object sender, EventArgs e)
\r
1447 if (lv_audioList.SelectedIndices.Count != 0)
\r
1449 ListViewItem item = lv_audioList.SelectedItems[0];
\r
1450 int index = item.Index;
\r
1453 if (lv_audioList.Items.Count > index && index >= 0)
\r
1455 lv_audioList.Items.Remove(item);
\r
1456 lv_audioList.Items.Insert(index, item);
\r
1457 item.Selected = true;
\r
1458 lv_audioList.Focus();
\r
1462 private void audioList_movedown_Click(object sender, EventArgs e)
\r
1464 if (lv_audioList.SelectedIndices.Count != 0)
\r
1466 ListViewItem item = lv_audioList.SelectedItems[0];
\r
1467 int index = item.Index;
\r
1470 if (index < lv_audioList.Items.Count)
\r
1472 lv_audioList.Items.Remove(item);
\r
1473 lv_audioList.Items.Insert(index, item);
\r
1474 item.Selected = true;
\r
1475 lv_audioList.Focus();
\r
1480 private void audioList_remove_Click(object sender, EventArgs e)
\r
1482 removeAudioTrack();
\r
1484 private void removeAudioTrack()
\r
1486 // Remove the Item and reselect the control if the following conditions are met.
\r
1487 if (lv_audioList.SelectedItems.Count != 0)
\r
1489 // Record the current selected index.
\r
1490 int currentPosition = lv_audioList.SelectedIndices[0];
\r
1492 lv_audioList.Items.RemoveAt(lv_audioList.SelectedIndices[0]);
\r
1494 // Now reslect the correct item and give focus to the audio list.
\r
1495 if (lv_audioList.Items.Count != 0)
\r
1497 if (currentPosition <= (lv_audioList.Items.Count - 1))
\r
1498 lv_audioList.Items[currentPosition].Selected = true;
\r
1499 else if (currentPosition > (lv_audioList.Items.Count - 1))
\r
1500 lv_audioList.Items[lv_audioList.Items.Count - 1].Selected = true;
\r
1502 lv_audioList.Select();
\r
1506 private void lv_audioList_SelectedIndexChanged(object sender, EventArgs e)
\r
1508 // Set the dropdown controls based on the selected item in the Audio List.
\r
1509 if (lv_audioList.Items.Count != 0 && lv_audioList.SelectedIndices.Count != 0)
\r
1511 drp_track1Audio.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].Text;
\r
1512 drp_audenc_1.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[1].Text;
\r
1513 drp_audmix_1.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[2].Text;
\r
1514 drp_audsr_1.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[3].Text;
\r
1515 drp_audbit_1.Text = lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[4].Text;
\r
1516 double drcValue; int drcCalculated;
\r
1517 double.TryParse(lv_audioList.Items[lv_audioList.SelectedIndices[0]].SubItems[5].Text, out drcValue);
\r
1518 if (drcValue == 0) drcCalculated = 0;
\r
1520 drcValue = ((drcValue * 10) + 1) - 10;
\r
1521 int.TryParse(drcValue.ToString(), out drcCalculated);
\r
1522 tb_drc.Value = drcCalculated;
\r
1526 private void drp_subtitle_SelectedIndexChanged(object sender, EventArgs e)
\r
1528 if (drp_subtitle.Text.Contains("None"))
\r
1530 check_forced.Enabled = false;
\r
1531 check_forced.Checked = false;
\r
1534 check_forced.Enabled = true;
\r
1537 // Chapter Marker Tab
\r
1538 private void Check_ChapterMarkers_CheckedChanged(object sender, EventArgs e)
\r
1540 if (Check_ChapterMarkers.Checked)
\r
1542 text_destination.Text = text_destination.Text.Replace(".m4v", ".mp4");
\r
1543 data_chpt.Rows.Clear();
\r
1544 data_chpt.Enabled = true;
\r
1545 DataGridView chapterGridView = hb_common_func.chapterNaming(data_chpt, drop_chapterFinish.Text);
\r
1546 if (chapterGridView != null)
\r
1547 data_chpt = chapterGridView;
\r
1551 text_destination.Text = text_destination.Text.Replace(".m4v", ".mp4");
\r
1552 data_chpt.Rows.Clear();
\r
1553 data_chpt.Enabled = false;
\r
1557 // Query Editor Tab
\r
1558 private void btn_generate_Query_Click(object sender, EventArgs e)
\r
1560 rtf_query.Text = queryGen.GenerateTheQuery(this);
\r
1562 private void btn_clear_Click(object sender, EventArgs e)
\r
1564 rtf_query.Clear();
\r
1568 // MainWindow Components, Actions and Functions ***********************
\r
1570 #region Source Scan
\r
1571 private void setupGUIforScan(String filename)
\r
1573 text_source.Text = filename;
\r
1575 foreach (Control ctrl in Controls)
\r
1577 if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))
\r
1578 ctrl.Enabled = false;
\r
1580 lbl_encode.Visible = true;
\r
1581 lbl_encode.Text = "Scanning ...";
\r
1582 gb_source.Text = "Source: Scanning ...";
\r
1583 btn_source.Enabled = false;
\r
1584 btn_start.Enabled = false;
\r
1585 btn_showQueue.Enabled = false;
\r
1586 btn_add2Queue.Enabled = false;
\r
1587 tb_preview.Enabled = false;
\r
1588 mnu_killCLI.Visible = true;
\r
1590 private void startScan(String filename)
\r
1594 lbl_encode.Visible = true;
\r
1595 lbl_encode.Text = "Scanning...";
\r
1596 ThreadPool.QueueUserWorkItem(scanProcess, filename);
\r
1598 catch (Exception exc)
\r
1600 MessageBox.Show("frmMain.cs - startScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1603 private void scanProcess(object state)
\r
1607 string inputFile = (string)state;
\r
1608 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
1609 string dvdInfoPath = Path.Combine(Path.GetTempPath(), "dvdinfo.dat");
\r
1611 // Make we don't pick up a stale hb_encode_log.dat (and that we have rights to the file)
\r
1612 if (File.Exists(dvdInfoPath))
\r
1613 File.Delete(dvdInfoPath);
\r
1615 string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 -v >""{2}"" 2>&1""", handbrakeCLIPath, inputFile, dvdInfoPath);
\r
1617 ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine)
\r
1618 {WindowStyle = ProcessWindowStyle.Hidden};
\r
1620 using (hbproc = Process.Start(hbParseDvd))
\r
1622 hbproc.WaitForExit();
\r
1625 if (!File.Exists(dvdInfoPath))
\r
1627 throw new Exception("Unable to retrieve the DVD Info. dvdinfo.dat is missing. \nExpected location of dvdinfo.dat: \n" + dvdInfoPath);
\r
1630 using (StreamReader sr = new StreamReader(dvdInfoPath))
\r
1632 thisDVD = Parsing.DVD.Parse(sr);
\r
1637 updateUIafterScan();
\r
1639 catch (Exception exc)
\r
1641 MessageBox.Show("frmMain.cs - scanProcess() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1645 private void updateUIafterScan()
\r
1649 if (InvokeRequired)
\r
1651 BeginInvoke(new UpdateWindowHandler(updateUIafterScan));
\r
1655 // Setup some GUI components
\r
1656 drp_dvdtitle.Items.Clear();
\r
1657 if (thisDVD.Titles.Count != 0)
\r
1658 drp_dvdtitle.Items.AddRange(thisDVD.Titles.ToArray());
\r
1659 drp_dvdtitle.Text = "Automatic";
\r
1660 drop_chapterFinish.Text = "Auto";
\r
1661 drop_chapterStart.Text = "Auto";
\r
1663 // Now select the longest title
\r
1664 if (thisDVD.Titles.Count != 0)
\r
1665 drp_dvdtitle.SelectedItem = hb_common_func.selectLongestTitle(drp_dvdtitle);
\r
1667 // Enable the creation of chapter markers if the file is an image of a dvd.
\r
1668 if (text_source.Text.ToLower().Contains(".iso") || text_source.Text.ToLower().Contains("VIDEO_TS"))
\r
1669 Check_ChapterMarkers.Enabled = true;
\r
1672 Check_ChapterMarkers.Enabled = false;
\r
1673 Check_ChapterMarkers.Checked = false;
\r
1674 data_chpt.Rows.Clear();
\r
1677 // If no titles were found, Display an error message
\r
1678 if (drp_dvdtitle.Items.Count == 0)
\r
1679 MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.\nYour Source may be copy protected, badly mastered or a format which HandBrake does not support. \nPlease refer to the Documentation and FAQ (see Help Menu).", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
1681 // Enable the GUI components and enable any disabled components
\r
1684 catch (Exception exc)
\r
1686 MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1691 private void enableGUI()
\r
1695 if (InvokeRequired)
\r
1697 BeginInvoke(new UpdateWindowHandler(updateUIafterScan));
\r
1699 lbl_encode.Text = "Scan Completed";
\r
1700 gb_source.Text = "Source";
\r
1701 foreach (Control ctrl in Controls)
\r
1702 ctrl.Enabled = true;
\r
1703 btn_start.Enabled = true;
\r
1704 btn_showQueue.Enabled = true;
\r
1705 btn_add2Queue.Enabled = true;
\r
1706 tb_preview.Enabled = true;
\r
1707 btn_source.Enabled = true;
\r
1708 mnu_killCLI.Visible = false;
\r
1710 catch (Exception exc)
\r
1712 MessageBox.Show("frmMain.cs - enableGUI " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1715 private static void killCLI()
\r
1717 // This may seem like a long way of killing HandBrakeCLI, but for whatever reason,
\r
1718 // hbproc.kill/close just won't do the trick.
\r
1721 string AppName = "HandBrakeCLI";
\r
1723 AppName = AppName.ToUpper();
\r
1725 Process[] prs = Process.GetProcesses();
\r
1726 foreach (Process proces in prs)
\r
1728 if (proces.ProcessName.ToUpper() == AppName)
\r
1731 if (!proces.HasExited)
\r
1736 catch (Exception ex)
\r
1738 MessageBox.Show("Unable to kill HandBrakeCLI.exe \nYou may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically within the next few minutes. \n\nError Information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
1743 #region DVD Drive Detection
\r
1744 // Source Button Drive Detection
\r
1745 private delegate void ProgressUpdateHandler();
\r
1746 private void getDriveInfoThread()
\r
1750 if (InvokeRequired)
\r
1752 BeginInvoke(new ProgressUpdateHandler(getDriveInfoThread));
\r
1756 Boolean foundDrive = false;
\r
1757 DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();
\r
1758 foreach (DriveInfo curDrive in theCollectionOfDrives)
\r
1760 if (curDrive.DriveType == DriveType.CDRom)
\r
1762 if (curDrive.IsReady)
\r
1764 if (File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))
\r
1766 mnu_dvd_drive.Text = curDrive.RootDirectory + "VIDEO_TS (" + curDrive.VolumeLabel + ")";
\r
1767 foundDrive = true;
\r
1775 if (foundDrive == false)
\r
1776 mnu_dvd_drive.Text = "[No DVD Drive Ready]";
\r
1780 mnu_dvd_drive.Text = "[No DVD Drive Ready / Found]";
\r
1785 #region Audio Panel Code Helpers
\r
1786 private void setAudioByContainer(String path)
\r
1790 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
1792 oldval = drp_audenc_1.Text;
\r
1793 drp_audenc_1.Items.Clear();
\r
1794 drp_audenc_1.Items.Add("AAC");
\r
1795 drp_audenc_1.Items.Add("AC3");
\r
1796 if ((oldval != "AAC") && (oldval != "AC3"))
\r
1797 drp_audenc_1.SelectedIndex = 0;
\r
1800 else if (path.Contains("MKV"))
\r
1802 drp_audenc_1.Items.Clear();
\r
1803 drp_audenc_1.Items.Add("AAC");
\r
1804 drp_audenc_1.Items.Add("MP3");
\r
1805 drp_audenc_1.Items.Add("AC3");
\r
1806 drp_audenc_1.Items.Add("Vorbis");
\r
1807 if (drp_audenc_1.Text == string.Empty)
\r
1808 drp_audenc_1.SelectedIndex = 0;
\r
1811 // Make sure the table is updated with new audio codecs
\r
1812 foreach (ListViewItem row in lv_audioList.Items)
\r
1814 if (!drp_audenc_1.Items.Contains(row.SubItems[1].Text))
\r
1815 row.SubItems[1].Text = drp_audenc_1.Items[0].ToString();
\r
1818 private void setVideoByContainer(String path)
\r
1822 if ((path.Contains("MP4")) || (path.Contains("M4V")))
\r
1824 oldval = drp_videoEncoder.Text;
\r
1825 drp_videoEncoder.Items.Clear();
\r
1826 drp_videoEncoder.Items.Add("MPEG-4 (FFmpeg)");
\r
1827 drp_videoEncoder.Items.Add("MPEG-4 (XviD)");
\r
1828 drp_videoEncoder.Items.Add("H.264 (x264)");
\r
1829 if (oldval == "VP3 (Theora)")
\r
1830 drp_videoEncoder.SelectedIndex = 2;
\r
1832 drp_videoEncoder.Text = oldval;
\r
1835 else if (path.Contains("MKV"))
\r
1837 oldval = drp_videoEncoder.Text;
\r
1838 drp_videoEncoder.Items.Clear();
\r
1839 drp_videoEncoder.Items.Add("MPEG-4 (FFmpeg)");
\r
1840 drp_videoEncoder.Items.Add("MPEG-4 (XviD)");
\r
1841 drp_videoEncoder.Items.Add("H.264 (x264)");
\r
1842 drp_videoEncoder.Items.Add("VP3 (Theora)");
\r
1843 drp_videoEncoder.Text = oldval;
\r
1846 private static void setBitrateSelections384(ComboBox dropDown)
\r
1848 dropDown.Items.Clear();
\r
1849 dropDown.Items.Add("32");
\r
1850 dropDown.Items.Add("40");
\r
1851 dropDown.Items.Add("48");
\r
1852 dropDown.Items.Add("56");
\r
1853 dropDown.Items.Add("64");
\r
1854 dropDown.Items.Add("80");
\r
1855 dropDown.Items.Add("86");
\r
1856 dropDown.Items.Add("112");
\r
1857 dropDown.Items.Add("128");
\r
1858 dropDown.Items.Add("160");
\r
1859 dropDown.Items.Add("192");
\r
1860 dropDown.Items.Add("224");
\r
1861 dropDown.Items.Add("256");
\r
1862 dropDown.Items.Add("320");
\r
1863 dropDown.Items.Add("384");
\r
1865 private static void setBitrateSelections320(ComboBox dropDown)
\r
1867 dropDown.Items.Clear();
\r
1868 dropDown.Items.Add("32");
\r
1869 dropDown.Items.Add("40");
\r
1870 dropDown.Items.Add("48");
\r
1871 dropDown.Items.Add("56");
\r
1872 dropDown.Items.Add("64");
\r
1873 dropDown.Items.Add("80");
\r
1874 dropDown.Items.Add("86");
\r
1875 dropDown.Items.Add("112");
\r
1876 dropDown.Items.Add("128");
\r
1877 dropDown.Items.Add("160");
\r
1878 dropDown.Items.Add("192");
\r
1879 dropDown.Items.Add("224");
\r
1880 dropDown.Items.Add("256");
\r
1881 dropDown.Items.Add("320");
\r
1883 private static void setBitrateSelections160(ComboBox dropDown)
\r
1885 dropDown.Items.Clear();
\r
1886 dropDown.Items.Add("32");
\r
1887 dropDown.Items.Add("40");
\r
1888 dropDown.Items.Add("48");
\r
1889 dropDown.Items.Add("56");
\r
1890 dropDown.Items.Add("64");
\r
1891 dropDown.Items.Add("80");
\r
1892 dropDown.Items.Add("86");
\r
1893 dropDown.Items.Add("112");
\r
1894 dropDown.Items.Add("128");
\r
1895 dropDown.Items.Add("160");
\r
1897 private static void setMixDownAllOptions(ComboBox dropdown)
\r
1899 dropdown.Items.Clear();
\r
1900 dropdown.Items.Add("Automatic");
\r
1901 dropdown.Items.Add("Mono");
\r
1902 dropdown.Items.Add("Stereo");
\r
1903 dropdown.Items.Add("Dolby Surround");
\r
1904 dropdown.Items.Add("Dolby Pro Logic II");
\r
1905 dropdown.Items.Add("6 Channel Discrete");
\r
1907 private static void setMixDownNotAAC(ComboBox dropdown)
\r
1909 dropdown.Items.Clear();
\r
1910 dropdown.Items.Add("Automatic");
\r
1911 dropdown.Items.Add("Stereo");
\r
1912 dropdown.Items.Add("Dolby Surround");
\r
1913 dropdown.Items.Add("Dolby Pro Logic II");
\r
1917 #region Public Methods
\r
1920 /// Setup the GUI for Encoding or finished Encoding.
\r
1921 /// 1 = Encode Running
\r
1922 /// 0 = Encode Finished.
\r
1924 public void setEncodeFinished()
\r
1928 if (InvokeRequired)
\r
1930 BeginInvoke(new UpdateWindowHandler(setEncodeFinished));
\r
1934 lbl_encode.Text = "Encoding Finished";
\r
1935 btn_start.Text = "Start";
\r
1936 btn_start.ToolTipText = "Start the encoding process";
\r
1937 btn_start.Image = Properties.Resources.Play;
\r
1939 // If the window is minimized, display the notification in a popup.
\r
1940 if (FormWindowState.Minimized == this.WindowState)
\r
1942 notifyIcon.BalloonTipText = lbl_encode.Text;
\r
1943 notifyIcon.ShowBalloonTip(500);
\r
1946 catch (Exception exc)
\r
1948 MessageBox.Show(exc.ToString());
\r
1951 public void setEncodeStarted()
\r
1955 if (InvokeRequired)
\r
1957 BeginInvoke(new UpdateWindowHandler(setEncodeStarted));
\r
1961 lbl_encode.Visible = true;
\r
1962 lbl_encode.Text = "Encoding in Progress";
\r
1963 btn_start.Text = "Stop";
\r
1964 btn_start.ToolTipText = "Stop the encoding process. \nWarning: This may break your file. Press ctrl-c in the CLI window if you wish it to exit cleanly.";
\r
1965 btn_start.Image = Properties.Resources.stop;
\r
1967 catch (Exception exc)
\r
1969 MessageBox.Show(exc.ToString());
\r
1974 /// Action can be "encode" or "scan"
\r
1975 /// Set the last action varible in the main window.
\r
1976 /// This is used to control which log file is displayed when the Activity window is displayed.
\r
1978 /// <param name="last">String</param>
\r
1979 public void setLastAction(string last)
\r
1981 this.lastAction = last;
\r
1985 /// DVD parseing. Pass in a parsed DVD.
\r
1987 /// <param name="dvd"></param>
\r
1988 public void setStreamReader(Parsing.DVD dvd)
\r
1990 this.thisDVD = dvd;
\r
1994 /// Reload the preset panel display
\r
1996 public void loadPresetPanel()
\r
1998 presetHandler.loadPresetData();
\r
1999 treeView_presets.Nodes.Clear();
\r
2001 TreeNode preset_treeview;
\r
2002 TreeNode rootNode = new TreeNode();
\r
2003 TreeNode rootNodeTwo = new TreeNode();
\r
2004 TreeNode childNode;
\r
2005 int workingLevel = 0;
\r
2006 string previousCategory = String.Empty, currentCategory = String.Empty;
\r
2008 List<Preset> presetNameList = presetHandler.getBuildInPresets();
\r
2009 if (presetNameList.Count != 0)
\r
2011 foreach (Preset preset in presetNameList)
\r
2013 // Handle Root Nodes
\r
2015 // First Case - No presets have been read yet so setup the root category
\r
2016 if (preset.Level == 1 && currentCategory == String.Empty)
\r
2018 rootNode = new TreeNode(preset.Category);
\r
2019 workingLevel = preset.Level;
\r
2020 currentCategory = preset.Category;
\r
2021 previousCategory = preset.Category;
\r
2024 // Second Case - This is the first sub child node.
\r
2025 if (preset.Level == 2 && workingLevel == 1 && currentCategory != preset.Category)
\r
2027 rootNodeTwo = new TreeNode(preset.Category);
\r
2028 workingLevel = preset.Level;
\r
2029 currentCategory = preset.Category;
\r
2030 rootNode.Nodes.Add(rootNodeTwo);
\r
2033 // Third Case - Any presets the sub presets detected in the above if statment.
\r
2034 if (preset.Level == 1 && workingLevel == 2)
\r
2036 workingLevel = preset.Level;
\r
2037 currentCategory = preset.Category;
\r
2040 // Fourth Case - We've finished this root node and are onto the next root node.
\r
2041 if (preset.Level == 1 && workingLevel == 1 && previousCategory != preset.Category)
\r
2043 treeView_presets.Nodes.Add(rootNode); // Add the finished node
\r
2045 rootNode = new TreeNode(preset.Category);
\r
2046 workingLevel = preset.Level;
\r
2047 currentCategory = preset.Category;
\r
2048 previousCategory = preset.Category;
\r
2051 // Handle Child Nodes
\r
2052 // Add First level child nodes to the current root node
\r
2053 if (preset.Level == 1 && workingLevel == 1 && currentCategory == preset.Category)
\r
2055 childNode = new TreeNode(preset.Name);
\r
2056 rootNode.Nodes.Add(childNode);
\r
2059 // Add Second level child nodes to the current sub root node
\r
2060 if (preset.Level == 2 && workingLevel == 2 && currentCategory == preset.Category)
\r
2062 childNode = new TreeNode(preset.Name);
\r
2063 rootNodeTwo.Nodes.Add(childNode);
\r
2067 // Add the final root node which does not get added above.
\r
2068 treeView_presets.Nodes.Add(rootNode);
\r
2072 List<string> presetNames = presetHandler.getUserPresetNames();
\r
2073 foreach (string preset in presetNames)
\r
2075 preset_treeview = new TreeNode(preset) {ForeColor = Color.Black};
\r
2077 // Now Fill Out List View with Items
\r
2078 treeView_presets.Nodes.Add(preset_treeview);
\r
2086 /// If the queue is being processed, prompt the user to confirm application close.
\r
2088 /// <param name="e"></param>
\r
2089 protected override void OnFormClosing(FormClosingEventArgs e)
\r
2091 // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.
\r
2092 if ((encodeQueue.isEncoding) && (!encodeQueue.isPaused) && (encodeQueue.count() > 0))
\r
2094 DialogResult result = MessageBox.Show("HandBrake has queue items to process. Closing HandBrake will not stop the current encoding, but will stop processing the queue.\n\nDo you want to close HandBrake?",
\r
2095 "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
\r
2096 if (result == DialogResult.No)
\r
2099 base.OnFormClosing(e);
\r
2102 // This is the END of the road ------------------------------------------------------------------------------
\r