/* frmMain.cs $\r
- \r
- This file is part of the HandBrake source code.\r
- Homepage: <http://handbrake.fr/>.\r
- It may be used under the terms of the GNU General Public License. */\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Drawing;\r
-using System.Globalization;\r
-using System.Windows.Forms;\r
-using System.IO;\r
-using System.Diagnostics;\r
-using System.Threading;\r
-using Handbrake.EncodeQueue;\r
-using Handbrake.Functions;\r
-using Handbrake.Presets;\r
-using Handbrake.Parsing;\r
+ This file is part of the HandBrake source code.\r
+ Homepage: <http://handbrake.fr/>.\r
+ It may be used under the terms of the GNU General Public License. */\r
\r
namespace Handbrake\r
{\r
+ using System;\r
+ using System.Collections.Generic;\r
+ using System.ComponentModel;\r
+ using System.Diagnostics;\r
+ using System.Drawing;\r
+ using System.Globalization;\r
+ using System.IO;\r
+ using System.Reflection;\r
+ using System.Threading;\r
+ using System.Windows.Forms;\r
+ using Functions;\r
+ using Model;\r
+ using Parsing;\r
+ using Presets;\r
+ using Properties;\r
+ using Services;\r
+\r
public partial class frmMain : Form\r
{\r
// Objects which may be used by one or more other objects *************\r
- EncodeAndQueueHandler encodeQueue = new EncodeAndQueueHandler();\r
- PresetsHandler presetHandler = new PresetsHandler();\r
- QueryGenerator queryGen = new QueryGenerator();\r
+ private Queue encodeQueue = new Queue();\r
+ private PresetsHandler presetHandler = new PresetsHandler();\r
\r
// Globals: Mainly used for tracking. *********************************\r
public Title selectedTitle;\r
- private DVD thisDVD;\r
private frmQueue queueWindow;\r
private frmPreview qtpreview;\r
private frmActivityWindow ActivityWindow;\r
private Form splash;\r
public string sourcePath;\r
- private string lastAction;\r
+ private ActivityLogMode lastAction;\r
+ private SourceType selectedSourceType;\r
+ private string dvdDrivePath;\r
+ private string dvdDriveLabel;\r
+ private Preset CurrentlySelectedPreset;\r
+ private DVD currentSource;\r
+ private Scan SourceScan = new Scan();\r
+ private List<DriveInformation> drives;\r
\r
// Delegates **********************************************************\r
private delegate void UpdateWindowHandler();\r
// Applicaiton Startup ************************************************\r
\r
#region Application Startup\r
+\r
public frmMain()\r
{\r
// Load and setup the splash screen in this thread\r
InitializeComponent();\r
\r
// Update the users config file with the CLI version data.\r
- lblStatus.Text = "Setting Version Data ...";\r
+ lblStatus.Text = "Checking CLI Version Data ...";\r
Application.DoEvents();\r
- Main.setCliVersionData();\r
+ Main.SetCliVersionData();\r
+ Main.CheckForValidCliVersion();\r
+\r
+ if (Settings.Default.hb_version.Contains("svn"))\r
+ {\r
+ Version v = Assembly.GetExecutingAssembly().GetName().Version;\r
+ this.Text += " " + v.ToString(4);\r
+ }\r
\r
- // Show the form, but leave disabled until preloading is complete then show the main form\r
+ // Show the form, but leave disabled until preloading is complete then show the main form)\r
this.Enabled = false;\r
this.Show();\r
Application.DoEvents(); // Forces frmMain to draw\r
}\r
}\r
\r
+ // Clear the log files in the background\r
+ if (Properties.Settings.Default.clearOldLogs)\r
+ {\r
+ lblStatus.Text = "Clearing Old Log Files ...";\r
+ Application.DoEvents();\r
+ Thread clearLog = new Thread(Main.ClearOldLogs);\r
+ clearLog.Start();\r
+ }\r
+\r
// Setup the GUI components\r
lblStatus.Text = "Setting up the GUI ...";\r
Application.DoEvents();\r
- loadPresetPanel(); // Load the Preset Panel\r
+ LoadPresetPanel(); // Load the Preset Panel\r
treeView_presets.ExpandAll();\r
- lbl_encode.Text = "";\r
- queueWindow = new frmQueue(encodeQueue); // Prepare the Queue\r
+ lbl_encode.Text = string.Empty;\r
+ drop_mode.SelectedIndex = 0;\r
+ queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue\r
if (!Properties.Settings.Default.QueryEditorTab)\r
tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.\r
\r
// Load the user's default settings or Normal Preset\r
- if (Properties.Settings.Default.defaultPreset != "")\r
+ if (Properties.Settings.Default.defaultPreset != string.Empty)\r
{\r
if (presetHandler.GetPreset(Properties.Settings.Default.defaultPreset) != null)\r
{\r
string query = presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).Query;\r
- Boolean loadPictureSettings = presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).PictureSettings;\r
+ bool loadPictureSettings =\r
+ presetHandler.GetPreset(Properties.Settings.Default.defaultPreset).PictureSettings;\r
\r
if (query != null)\r
{\r
- //Ok, Reset all the H264 widgets before changing the preset\r
- x264Panel.reset2Defaults();\r
+ x264Panel.Reset2Defaults();\r
\r
- // Send the query from the file to the Query Parser class, then load the preset\r
QueryParser presetQuery = QueryParser.Parse(query);\r
- PresetLoader.presetLoader(this, presetQuery, Properties.Settings.Default.defaultPreset, loadPictureSettings);\r
+ PresetLoader.LoadPreset(this, presetQuery, Properties.Settings.Default.defaultPreset,\r
+ loadPictureSettings);\r
\r
- // The x264 widgets will need updated, so do this now:\r
x264Panel.X264_StandardizeOptString();\r
x264Panel.X264_SetCurrentSettingsInPanel();\r
}\r
// Register with Growl (if not using Growl for the encoding completion action, this wont hurt anything)\r
GrowlCommunicator.Register();\r
\r
- //Finished Loading\r
+ // Finished Loading\r
lblStatus.Text = "Loading Complete!";\r
Application.DoEvents();\r
splash.Close();\r
catch (Exception ex)\r
{\r
if ((bool)result.AsyncState)\r
- MessageBox.Show("Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ MessageBox.Show(\r
+ "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,\r
+ "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
}\r
\r
// Startup Functions \r
private void queueRecovery()\r
{\r
- if (Main.checkQueueRecovery())\r
+ if (Main.CheckQueueRecovery())\r
{\r
- 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
+ DialogResult result =\r
+ MessageBox.Show(\r
+ "HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?",\r
+ "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
\r
if (result == DialogResult.Yes)\r
encodeQueue.LoadQueueFromFile("hb_queue_recovery.xml"); // Start Recovery\r
}\r
}\r
}\r
+\r
+ #endregion\r
+\r
+ #region Properties\r
+\r
+ public string SourceName\r
+ {\r
+ get\r
+ {\r
+ if (this.selectedSourceType == SourceType.DvdDrive)\r
+ {\r
+ return this.dvdDriveLabel;\r
+ }\r
+\r
+ if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")\r
+ return Path.GetFileNameWithoutExtension(this.sourcePath);\r
+\r
+ return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));\r
+ }\r
+ }\r
+\r
#endregion\r
\r
#region Events\r
+\r
// Encoding Events for setting up the GUI\r
private void events()\r
{\r
this.Resize += new EventHandler(frmMain_Resize);\r
\r
// Handle Encode Start / Finish / Pause\r
- encodeQueue.CurrentJobCompleted += new EventHandler(encodeEnded);\r
+\r
encodeQueue.QueuePauseRequested += new EventHandler(encodePaused);\r
- encodeQueue.NewJobStarted += new EventHandler(encodeStarted);\r
+ encodeQueue.EncodeStarted += new EventHandler(encodeStarted);\r
+ encodeQueue.EncodeEnded += new EventHandler(encodeEnded);\r
\r
// Handle a file being draged onto the GUI.\r
this.DragEnter += new DragEventHandler(frmMain_DragEnter);\r
check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);\r
\r
// Picture Settings\r
- //PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);\r
+ // PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);\r
\r
// Filter Settings\r
Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);\r
// Advanced Tab\r
x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);\r
}\r
+\r
private void UnRegisterPresetEventHandler()\r
{\r
// Output Settings \r
check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);\r
\r
// Picture Settings\r
- //PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);\r
+ // PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);\r
\r
// Filter Settings\r
Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);\r
// Advanced Tab\r
x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);\r
}\r
+\r
private void changePresetLabel(object sender, EventArgs e)\r
{\r
labelPreset.Text = "Output Settings (Preset: Custom)";\r
+ CurrentlySelectedPreset = null;\r
}\r
\r
private static void frmMain_DragEnter(object sender, DragEventArgs e)\r
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))\r
e.Effect = DragDropEffects.All;\r
}\r
+\r
private void frmMain_DragDrop(object sender, DragEventArgs e)\r
{\r
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];\r
\r
if (fileList != null)\r
{\r
- if (fileList[0].StartsWith("\\"))\r
+ if (fileList[0] != string.Empty)\r
{\r
- MessageBox.Show(\r
- "Sorry, HandBrake does not support UNC file paths. \nTry mounting the network share as a network drive in My Computer",\r
- "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
- UpdateSourceLabel();\r
+ this.selectedSourceType = SourceType.VideoFile;\r
+ StartScan(fileList[0], 0);\r
}\r
else\r
- {\r
- if (fileList[0] != "")\r
- startScan(fileList[0]);\r
- else\r
- UpdateSourceLabel();\r
- }\r
+ UpdateSourceLabel();\r
}\r
else\r
UpdateSourceLabel();\r
}\r
+\r
private void encodeStarted(object sender, EventArgs e)\r
{\r
- lastAction = "encode";\r
- setEncodeStarted();\r
+ lastAction = ActivityLogMode.Encode;\r
+ SetEncodeStarted();\r
\r
// Experimental HBProc Process Monitoring.\r
if (Properties.Settings.Default.enocdeStatusInGui)\r
{\r
- Thread encodeMon = new Thread(encodeMonitorThread);\r
+ Thread encodeMon = new Thread(EncodeMonitorThread);\r
encodeMon.Start();\r
}\r
}\r
+\r
private void encodeEnded(object sender, EventArgs e)\r
{\r
- setEncodeFinished();\r
+ SetEncodeFinished();\r
}\r
+\r
private void encodePaused(object sender, EventArgs e)\r
{\r
- setEncodeFinished();\r
+ SetEncodeFinished();\r
}\r
+\r
#endregion\r
\r
// User Interface Menus / Tool Strips *********************************\r
\r
#region File Menu\r
+\r
private void mnu_killCLI_Click(object sender, EventArgs e)\r
{\r
- killScan();\r
+ KillScan();\r
}\r
+\r
private void mnu_exit_Click(object sender, EventArgs e)\r
{\r
Application.Exit();\r
}\r
+\r
#endregion\r
\r
#region Tools Menu\r
+\r
private void mnu_encode_Click(object sender, EventArgs e)\r
{\r
queueWindow.Show();\r
}\r
+\r
private void mnu_encodeLog_Click(object sender, EventArgs e)\r
{\r
- String file = lastAction == "scan" ? "last_scan_log.txt" : "last_encode_log.txt";\r
-\r
- frmActivityWindow dvdInfoWindow = new frmActivityWindow(file, encodeQueue, this);\r
+ frmActivityWindow dvdInfoWindow = new frmActivityWindow(lastAction, encodeQueue, SourceScan);\r
dvdInfoWindow.Show();\r
}\r
+\r
private void mnu_options_Click(object sender, EventArgs e)\r
{\r
Form options = new frmOptions(this);\r
options.ShowDialog();\r
}\r
+\r
#endregion\r
\r
#region Presets Menu\r
+\r
private void mnu_presetReset_Click(object sender, EventArgs e)\r
{\r
presetHandler.UpdateBuiltInPresets();\r
- loadPresetPanel();\r
+ LoadPresetPanel();\r
if (treeView_presets.Nodes.Count == 0)\r
- 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
+ MessageBox.Show(\r
+ "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
+ "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
else\r
MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
\r
treeView_presets.ExpandAll();\r
}\r
+\r
private void mnu_delete_preset_Click(object sender, EventArgs e)\r
{\r
presetHandler.RemoveBuiltInPresets();\r
- loadPresetPanel(); // Reload the preset panel\r
+ LoadPresetPanel(); // Reload the preset panel\r
}\r
+\r
private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
{\r
loadNormalPreset();\r
}\r
+\r
private void mnu_importMacPreset_Click(object sender, EventArgs e)\r
{\r
- importPreset();\r
+ ImportPreset();\r
}\r
+\r
private void btn_new_preset_Click(object sender, EventArgs e)\r
{\r
- Form preset = new frmAddPreset(this, queryGen.GenerateCLIQuery(this, 0, null), presetHandler);\r
+ Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+ presetHandler);\r
preset.ShowDialog();\r
}\r
+\r
#endregion\r
\r
#region Help Menu\r
- private void mnu_handbrake_forums_Click(object sender, EventArgs e)\r
- {\r
- Process.Start("http://forum.handbrake.fr/");\r
- }\r
+\r
private void mnu_user_guide_Click(object sender, EventArgs e)\r
{\r
Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");\r
}\r
+\r
private void mnu_handbrake_home_Click(object sender, EventArgs e)\r
{\r
Process.Start("http://handbrake.fr");\r
}\r
+\r
private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
{\r
lbl_updateCheck.Visible = true;\r
Main.BeginCheckForUpdates(new AsyncCallback(updateCheckDoneMenu), false);\r
}\r
+\r
private void updateCheckDoneMenu(IAsyncResult result)\r
{\r
// Make sure it's running on the calling thread\r
updateWindow.ShowDialog();\r
}\r
else\r
- MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
+ MessageBox.Show("There are no new updates at this time.", "Update Check", MessageBoxButtons.OK,\r
+ MessageBoxIcon.Information);\r
lbl_updateCheck.Visible = false;\r
return;\r
}\r
catch (Exception ex)\r
{\r
if ((bool)result.AsyncState)\r
- MessageBox.Show("Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ MessageBox.Show(\r
+ "Unable to check for updates, Please try again later.\n\nDetailed Error Information:\n" + ex,\r
+ "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
}\r
+\r
private void mnu_about_Click(object sender, EventArgs e)\r
{\r
using (frmAbout About = new frmAbout())\r
About.ShowDialog();\r
}\r
}\r
+\r
#endregion\r
\r
#region Preset Bar\r
+\r
// Right Click Menu Code\r
private void pmnu_expandAll_Click(object sender, EventArgs e)\r
{\r
treeView_presets.ExpandAll();\r
}\r
+\r
private void pmnu_collapse_Click(object sender, EventArgs e)\r
{\r
treeView_presets.CollapseAll();\r
}\r
+\r
private void pmnu_import_Click(object sender, EventArgs e)\r
{\r
- importPreset();\r
+ ImportPreset();\r
}\r
+\r
private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
{\r
- 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
+ DialogResult result =\r
+ MessageBox.Show(\r
+ "Do you wish to include picture settings when updating the preset: " +\r
+ treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,\r
+ MessageBoxIcon.Question);\r
if (result == DialogResult.Yes)\r
- presetHandler.Update(treeView_presets.SelectedNode.Text, QueryGenerator.GenerateTabbedComponentsQuery(this), true);\r
+ presetHandler.Update(treeView_presets.SelectedNode.Text,\r
+ QueryGenerator.GenerateTabbedComponentsQuery(this), true);\r
else if (result == DialogResult.No)\r
- presetHandler.Update(treeView_presets.SelectedNode.Text, QueryGenerator.GenerateTabbedComponentsQuery(this), false);\r
+ presetHandler.Update(treeView_presets.SelectedNode.Text,\r
+ QueryGenerator.GenerateTabbedComponentsQuery(this), false);\r
}\r
+\r
private void pmnu_delete_click(object sender, EventArgs e)\r
{\r
if (treeView_presets.SelectedNode != null)\r
}\r
treeView_presets.Select();\r
}\r
- private void presets_menu_Opening(object sender, System.ComponentModel.CancelEventArgs e)\r
+\r
+ private void presets_menu_Opening(object sender, CancelEventArgs e)\r
{\r
// Make sure that the save menu is always disabled by default\r
pmnu_saveChanges.Enabled = false;\r
Form preset = new frmAddPreset(this, QueryGenerator.GenerateTabbedComponentsQuery(this), presetHandler);\r
preset.ShowDialog();\r
}\r
+\r
private void btn_removePreset_Click(object sender, EventArgs e)\r
{\r
- DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+ DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",\r
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
if (result == DialogResult.Yes)\r
{\r
if (treeView_presets.SelectedNode != null)\r
}\r
treeView_presets.Select();\r
}\r
+\r
private void btn_setDefault_Click(object sender, EventArgs e)\r
{\r
if (treeView_presets.SelectedNode != null)\r
{\r
- DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+ DialogResult result = MessageBox.Show("Are you sure you wish to set this preset as the default?",\r
+ "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
if (result == DialogResult.Yes)\r
{\r
Properties.Settings.Default.defaultPreset = treeView_presets.SelectedNode.Text;\r
else\r
MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
}\r
+\r
private void treeview_presets_mouseUp(object sender, MouseEventArgs e)\r
{\r
if (e.Button == MouseButtons.Right)\r
\r
treeView_presets.Select();\r
}\r
+\r
private void treeView_presets_AfterSelect(object sender, TreeViewEventArgs e)\r
{\r
selectPreset();\r
}\r
+\r
private void treeView_presets_deleteKey(object sender, KeyEventArgs e)\r
{\r
if (e.KeyCode == Keys.Delete)\r
{\r
- DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+ DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",\r
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
if (result == DialogResult.Yes)\r
{\r
if (treeView_presets.SelectedNode != null)\r
presetHandler.Remove(treeView_presets.SelectedNode.Text);\r
\r
// Remember each nodes expanded status so we can reload it\r
- List<Boolean> nodeStatus = new List<Boolean>();\r
+ List<bool> nodeStatus = new List<bool>();\r
foreach (TreeNode node in treeView_presets.Nodes)\r
nodeStatus.Add(node.IsExpanded);\r
\r
// Now reload the preset panel\r
- loadPresetPanel();\r
+ LoadPresetPanel();\r
\r
// And finally, re-expand any of the nodes if required\r
int i = 0;\r
}\r
}\r
}\r
+\r
private void selectPreset()\r
{\r
if (treeView_presets.SelectedNode != null)\r
{\r
// Ok, so, we've selected a preset. Now we want to load it.\r
string presetName = treeView_presets.SelectedNode.Text;\r
- if (presetHandler.GetPreset(presetName) != null)\r
+ Preset preset = presetHandler.GetPreset(presetName);\r
+ if (preset != null)\r
{\r
string query = presetHandler.GetPreset(presetName).Query;\r
- Boolean loadPictureSettings = presetHandler.GetPreset(presetName).PictureSettings;\r
+ bool loadPictureSettings = presetHandler.GetPreset(presetName).PictureSettings;\r
\r
if (query != null)\r
{\r
- //Ok, Reset all the H264 widgets before changing the preset\r
- x264Panel.reset2Defaults();\r
+ // Ok, Reset all the H264 widgets before changing the preset\r
+ x264Panel.Reset2Defaults();\r
\r
// Send the query from the file to the Query Parser class\r
QueryParser presetQuery = QueryParser.Parse(query);\r
\r
// Now load the preset\r
- PresetLoader.presetLoader(this, presetQuery, presetName, loadPictureSettings);\r
+ PresetLoader.LoadPreset(this, presetQuery, presetName, loadPictureSettings);\r
\r
// The x264 widgets will need updated, so do this now:\r
x264Panel.X264_StandardizeOptString();\r
x264Panel.X264_SetCurrentSettingsInPanel();\r
+\r
+ // Finally, let this window have a copy of the preset settings.\r
+ CurrentlySelectedPreset = preset;\r
+ PictureSettings.SetPresetCropWarningLabel(preset);\r
}\r
}\r
}\r
}\r
+\r
private void loadNormalPreset()\r
{\r
foreach (TreeNode treenode in treeView_presets.Nodes)\r
}\r
}\r
}\r
- private void importPreset()\r
+\r
+ private void ImportPreset()\r
{\r
- Import imp = new Import();\r
if (openPreset.ShowDialog() == DialogResult.OK)\r
{\r
- QueryParser parsed = imp.importMacPreset(openPreset.FileName);\r
+ QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);\r
if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))\r
{\r
- DialogResult result = MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?", "Overwrite preset?",\r
- MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
+ DialogResult result =\r
+ MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",\r
+ "Overwrite preset?",\r
+ MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
if (result == DialogResult.Yes)\r
{\r
- PresetLoader.presetLoader(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
- presetHandler.Update(parsed.PresetName + " (Imported)", queryGen.GenerateCLIQuery(this, 0, null),\r
- parsed.UsesPictureSettings);\r
+ PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
+ presetHandler.Update(parsed.PresetName + " (Imported)",\r
+ QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+ parsed.UsesPictureSettings);\r
}\r
}\r
else\r
{\r
- PresetLoader.presetLoader(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
- presetHandler.Add(parsed.PresetName, queryGen.GenerateCLIQuery(this, 0, null), parsed.UsesPictureSettings);\r
-\r
- if (presetHandler.Add(parsed.PresetName + " (Imported)", queryGen.GenerateCLIQuery(this, 0, null), parsed.UsesPictureSettings))\r
+ PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
+ if (presetHandler.Add(parsed.PresetName + " (Imported)",\r
+ QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+ parsed.UsesPictureSettings))\r
{\r
- TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)") { ForeColor = Color.Black };\r
+ TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")\r
+ {\r
+ ForeColor = Color.Black\r
+ };\r
treeView_presets.Nodes.Add(preset_treeview);\r
}\r
}\r
}\r
}\r
+\r
#endregion\r
\r
#region ToolStrip\r
+\r
private void btn_source_Click(object sender, EventArgs e)\r
{\r
- mnu_dvd_drive.Visible = true;\r
- Thread driveInfoThread = new Thread(getDriveInfoThread);\r
+ // Remove old Drive Menu Items.\r
+ List<ToolStripMenuItem> itemsToRemove = new List<ToolStripMenuItem>();\r
+ foreach (var item in btn_source.DropDownItems)\r
+ {\r
+ if (item.GetType() == typeof(ToolStripMenuItem))\r
+ {\r
+ ToolStripMenuItem menuItem = (ToolStripMenuItem)item;\r
+ if (menuItem.Name.StartsWith("Drive"))\r
+ {\r
+ itemsToRemove.Add(menuItem);\r
+ }\r
+ }\r
+ }\r
+\r
+ foreach (ToolStripMenuItem item in itemsToRemove)\r
+ btn_source.DropDownItems.Remove(item);\r
+\r
+ Thread driveInfoThread = new Thread(SetDriveSelectionMenuItem);\r
driveInfoThread.Start();\r
}\r
+\r
private void btn_start_Click(object sender, EventArgs e)\r
{\r
if (btn_start.Text == "Stop")\r
{\r
- DialogResult result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+ DialogResult result;\r
+ if (Properties.Settings.Default.enocdeStatusInGui &&\r
+ !Properties.Settings.Default.showCliForInGuiEncodeStatus)\r
+ {\r
+ result = MessageBox.Show(\r
+ "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
+ "Cancel Encode?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+ }\r
+ else\r
+ {\r
+ result = MessageBox.Show("Are you sure you wish to cancel the encode?", "Cancel Encode?",\r
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+ }\r
\r
if (result == DialogResult.Yes)\r
{\r
// Pause The Queue\r
- encodeQueue.RequestPause();\r
+ encodeQueue.Pause();\r
\r
- // Allow the CLI to exit cleanly\r
- Win32.SetForegroundWindow((int)encodeQueue.processHandle);\r
- SendKeys.Send("^C");\r
+ if (Properties.Settings.Default.enocdeStatusInGui &&\r
+ !Properties.Settings.Default.showCliForInGuiEncodeStatus)\r
+ {\r
+ encodeQueue.Stop();\r
+ if (encodeQueue.HbProcess != null)\r
+ encodeQueue.HbProcess.WaitForExit();\r
+ }\r
+ else\r
+ {\r
+ encodeQueue.SafelyClose();\r
+ }\r
\r
// Update the GUI\r
- setEncodeFinished();\r
+ SetEncodeFinished();\r
}\r
}\r
else\r
{\r
- if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(sourcePath) && !string.IsNullOrEmpty(text_destination.Text)))\r
+ if (encodeQueue.Count != 0 ||\r
+ (!string.IsNullOrEmpty(sourcePath) && !string.IsNullOrEmpty(text_destination.Text)))\r
{\r
- string generatedQuery = queryGen.GenerateCLIQuery(this, 0, null);\r
- string specifiedQuery = rtf_query.Text != "" ? rtf_query.Text : queryGen.GenerateCLIQuery(this, 0, null);\r
+ string generatedQuery = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+ string specifiedQuery = rtf_query.Text != string.Empty\r
+ ? rtf_query.Text\r
+ : QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
string query = string.Empty;\r
\r
// Check to make sure the generated query matches the GUI settings\r
- if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) && generatedQuery != specifiedQuery)\r
+ if (Properties.Settings.Default.PromptOnUnmatchingQueries && !string.IsNullOrEmpty(specifiedQuery) &&\r
+ generatedQuery != specifiedQuery)\r
{\r
DialogResult result = MessageBox.Show("The query under the \"Query Editor\" tab " +\r
- "does not match the current GUI settings. Because the manual query takes " +\r
- "priority over the GUI, your recently updated settings will not be taken " +\r
- "into account when encoding this job." + Environment.NewLine + Environment.NewLine +\r
- "Do you want to replace the manual query with the GUI-generated query?",\r
- "Manual Query does not Match GUI",\r
- MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,\r
- MessageBoxDefaultButton.Button3);\r
+ "does not match the current GUI settings.\n\nBecause the manual query takes " +\r
+ "priority over the GUI, your recently updated settings will not be taken " +\r
+ "into account when encoding this job." +\r
+ Environment.NewLine + Environment.NewLine +\r
+ "Do you want to replace the manual query with the updated GUI-generated query?",\r
+ "Manual Query does not Match GUI",\r
+ MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk,\r
+ MessageBoxDefaultButton.Button3);\r
\r
switch (result)\r
{\r
}\r
else\r
{\r
- query = generatedQuery;\r
+ query = specifiedQuery;\r
}\r
\r
DialogResult overwrite = DialogResult.Yes;\r
- if (text_destination.Text != "")\r
+ if (text_destination.Text != string.Empty)\r
if (File.Exists(text_destination.Text))\r
- overwrite = MessageBox.Show("The destination file already exists. Are you sure you want to overwrite it?", "Overwrite File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+ overwrite =\r
+ MessageBox.Show(\r
+ "The destination file already exists. Are you sure you want to overwrite it?",\r
+ "Overwrite File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
\r
if (overwrite == DialogResult.Yes)\r
{\r
if (encodeQueue.Count == 0)\r
- encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
+ encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
\r
- queueWindow.setQueue();\r
+ queueWindow.SetQueue();\r
if (encodeQueue.Count > 1)\r
queueWindow.Show(false);\r
\r
- setEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
- encodeQueue.StartEncodeQueue(); // Start The Queue Encoding Process\r
- lastAction = "encode"; // Set the last action to encode - Used for activity window.\r
-\r
- if (ActivityWindow != null)\r
- ActivityWindow.SetLogView(false);\r
-\r
+ SetEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
+ encodeQueue.Start(); // Start The Queue Encoding Process\r
+ lastAction = ActivityLogMode.Encode; // Set the last action to encode - Used for activity window.\r
}\r
+ if (ActivityWindow != null)\r
+ ActivityWindow.SetMode(ActivityLogMode.Encode);\r
+\r
this.Focus();\r
}\r
else if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
- MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,\r
+ MessageBoxIcon.Warning);\r
}\r
}\r
+\r
private void btn_add2Queue_Click(object sender, EventArgs e)\r
{\r
if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
- MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,\r
+ MessageBoxIcon.Warning);\r
else\r
{\r
- String query = queryGen.GenerateCLIQuery(this, 0, null);\r
- if (rtf_query.Text != "")\r
+ string query = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+ if (rtf_query.Text != string.Empty)\r
query = rtf_query.Text;\r
\r
if (encodeQueue.CheckForDestinationDuplicate(text_destination.Text))\r
{\r
- 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
- "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
+ DialogResult result =\r
+ MessageBox.Show(\r
+ "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
+ "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
if (result == DialogResult.Yes)\r
- encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
-\r
+ encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
}\r
else\r
- encodeQueue.AddJob(query, sourcePath, text_destination.Text);\r
+ encodeQueue.Add(query, getTitle(), sourcePath, text_destination.Text, (rtf_query.Text != string.Empty));\r
\r
lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
\r
queueWindow.Show();\r
}\r
}\r
+\r
private void btn_showQueue_Click(object sender, EventArgs e)\r
{\r
queueWindow.Show();\r
queueWindow.Activate();\r
}\r
+\r
private void tb_preview_Click(object sender, EventArgs e)\r
{\r
if (string.IsNullOrEmpty(sourcePath) || string.IsNullOrEmpty(text_destination.Text))\r
- MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK,\r
+ MessageBoxIcon.Warning);\r
else\r
{\r
if (qtpreview == null)\r
qtpreview.Show();\r
}\r
else\r
- MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ MessageBox.Show(qtpreview, "The preview window is already open!", "Warning", MessageBoxButtons.OK,\r
+ MessageBoxIcon.Warning);\r
}\r
}\r
+\r
private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
{\r
- String file = lastAction == "scan" ? "last_scan_log.txt" : "last_encode_log.txt";\r
- if (ActivityWindow == null)\r
- ActivityWindow = new frmActivityWindow(file, encodeQueue, this);\r
+ if (ActivityWindow == null || !ActivityWindow.IsHandleCreated)\r
+ ActivityWindow = new frmActivityWindow(lastAction, encodeQueue, SourceScan);\r
+ else\r
+ switch (lastAction)\r
+ {\r
+ case ActivityLogMode.Scan:\r
+ ActivityWindow.SetMode(ActivityLogMode.Scan);\r
+ break;\r
+ case ActivityLogMode.Encode:\r
+ ActivityWindow.SetMode(ActivityLogMode.Encode);\r
+ break;\r
+ default:\r
+ ActivityWindow.SetMode(ActivityLogMode.Encode);\r
+ break;\r
+ }\r
\r
ActivityWindow.Show();\r
+ ActivityWindow.Activate();\r
}\r
+\r
#endregion\r
\r
#region System Tray Icon\r
+\r
private void frmMain_Resize(object sender, EventArgs e)\r
{\r
if (FormWindowState.Minimized == this.WindowState)\r
else if (FormWindowState.Normal == this.WindowState)\r
notifyIcon.Visible = false;\r
}\r
+\r
private void notifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)\r
{\r
this.Visible = true;\r
this.WindowState = FormWindowState.Normal;\r
notifyIcon.Visible = false;\r
}\r
+\r
private void btn_restore_Click(object sender, EventArgs e)\r
{\r
this.Visible = true;\r
this.Activate();\r
this.WindowState = FormWindowState.Normal;\r
notifyIcon.Visible = false;\r
+\r
+ this.StartScan(null, 2);\r
}\r
+\r
#endregion\r
\r
#region Tab Control\r
\r
- //Source\r
+ // Source\r
private void btn_dvd_source_Click(object sender, EventArgs e)\r
{\r
if (DVD_Open.ShowDialog() == DialogResult.OK)\r
- selectSource(DVD_Open.SelectedPath);\r
+ {\r
+ this.selectedSourceType = SourceType.Folder;\r
+ SelectSource(DVD_Open.SelectedPath);\r
+ }\r
else\r
UpdateSourceLabel();\r
}\r
+\r
private void btn_file_source_Click(object sender, EventArgs e)\r
{\r
if (ISO_Open.ShowDialog() == DialogResult.OK)\r
- selectSource(ISO_Open.FileName);\r
+ {\r
+ this.selectedSourceType = SourceType.VideoFile;\r
+ SelectSource(ISO_Open.FileName);\r
+ }\r
else\r
UpdateSourceLabel();\r
}\r
+\r
private void mnu_dvd_drive_Click(object sender, EventArgs e)\r
{\r
- if (!mnu_dvd_drive.Text.Contains("VIDEO_TS")) return;\r
- string[] path = mnu_dvd_drive.Text.Split(' ');\r
- selectSource(path[0]);\r
+ ToolStripMenuItem item = sender as ToolStripMenuItem;\r
+ if (item != null)\r
+ {\r
+ string driveId = item.Name.Replace("Drive", string.Empty);\r
+ int id;\r
+ if (int.TryParse(driveId, out id))\r
+ {\r
+\r
+ this.dvdDrivePath = drives[id].RootDirectory;\r
+ this.dvdDriveLabel = drives[id].VolumeLabel;\r
+\r
+ if (this.dvdDrivePath == null) return;\r
+ this.selectedSourceType = SourceType.DvdDrive;\r
+ SelectSource(this.dvdDrivePath);\r
+ }\r
+ }\r
}\r
- private void selectSource(string file)\r
+\r
+ private void SelectSource(string file)\r
{\r
Check_ChapterMarkers.Enabled = true;\r
- lastAction = "scan";\r
+ lastAction = ActivityLogMode.Scan;\r
sourcePath = string.Empty;\r
\r
if (file == string.Empty) // Must have a file or path\r
return;\r
}\r
\r
- if (file.StartsWith("\\")) // NO UNC Paths\r
- {\r
- MessageBox.Show(\r
- "Sorry, HandBrake does not support UNC file paths. \nTry mounting the share as a network drive in My Computer",\r
- "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
- UpdateSourceLabel();\r
- return;\r
- }\r
-\r
sourcePath = Path.GetFileName(file);\r
- startScan(file);\r
+ StartScan(file, 0);\r
}\r
+\r
private void drp_dvdtitle_Click(object sender, EventArgs e)\r
{\r
if ((drp_dvdtitle.Items.Count == 1) && (drp_dvdtitle.Items[0].ToString() == "Automatic"))\r
- 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
+ MessageBox.Show(\r
+ "There are no titles to select. Please load a source file by clicking the 'Source' button above before trying to select a title.",\r
+ "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
}\r
+\r
private void drp_dvdtitle_SelectedIndexChanged(object sender, EventArgs e)\r
{\r
UnRegisterPresetEventHandler();\r
+ drop_mode.SelectedIndex = 0;\r
\r
- PictureSettings.lbl_Aspect.Text = "Select a Title"; // Reset some values on the form\r
drop_chapterStart.Items.Clear();\r
drop_chapterFinish.Items.Clear();\r
\r
// If the dropdown is set to automatic nothing else needs to be done.\r
- // Otheriwse if its not, title data has to be loased from parsing.\r
+ // Otheriwse if its not, title data has to be loaded from parsing.\r
if (drp_dvdtitle.Text != "Automatic")\r
{\r
selectedTitle = drp_dvdtitle.SelectedItem as Title;\r
lbl_duration.Text = selectedTitle.Duration.ToString();\r
- PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control\r
+ PictureSettings.CurrentlySelectedPreset = CurrentlySelectedPreset;\r
+ PictureSettings.Source = selectedTitle; // Setup Picture Settings Tab Control\r
\r
// Populate the Angles dropdown\r
drop_angle.Items.Clear();\r
- if (Properties.Settings.Default.dvdnav)\r
+ if (!Properties.Settings.Default.noDvdNav)\r
{\r
drop_angle.Visible = true;\r
lbl_angle.Visible = true;\r
drop_chapterFinish.Text = drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString();\r
\r
// Populate the Audio Channels Dropdown\r
- AudioSettings.SetTrackList(selectedTitle);\r
+ AudioSettings.SetTrackList(selectedTitle, CurrentlySelectedPreset);\r
\r
// Populate the Subtitles dropdown\r
- Subtitles.drp_subtitleTracks.Items.Clear();\r
- Subtitles.drp_subtitleTracks.Items.Add("Foreign Audio Search (Bitmap)");\r
- Subtitles.drp_subtitleTracks.Items.AddRange(selectedTitle.Subtitles.ToArray());\r
- Subtitles.drp_subtitleTracks.SelectedIndex = 0;\r
- Subtitles.setSubtitleTrackAuto();\r
+ Subtitles.SetSubtitleTrackAuto(selectedTitle.Subtitles.ToArray());\r
}\r
+ // Update the source label if we have multiple streams\r
+ if (selectedTitle != null)\r
+ if (!string.IsNullOrEmpty(selectedTitle.SourceName))\r
+ labelSource.Text = labelSource.Text = Path.GetFileName(selectedTitle.SourceName);\r
\r
- // Run the autoName & chapterNaming functions\r
+ // Run the AutoName & ChapterNaming functions\r
if (Properties.Settings.Default.autoNaming)\r
{\r
- string autoPath = Main.autoName(this);\r
+ string autoPath = Main.AutoName(this);\r
if (autoPath != null)\r
text_destination.Text = autoPath;\r
else\r
- MessageBox.Show("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')", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ MessageBox.Show(\r
+ "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
+ "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
}\r
\r
data_chpt.Rows.Clear();\r
if (selectedTitle.Chapters.Count != 1)\r
{\r
- DataGridView chapterGridView = Main.chapterNaming(data_chpt, drop_chapterFinish.Text);\r
+ DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);\r
if (chapterGridView != null)\r
data_chpt = chapterGridView;\r
}\r
\r
RegisterPresetEventHandler();\r
}\r
+\r
private void chapersChanged(object sender, EventArgs e)\r
{\r
+ if (drop_mode.SelectedIndex != 0) // Function is not used if we are not in chapters mode.\r
+ return;\r
+\r
Control ctl = (Control)sender;\r
int chapterStart, chapterEnd;\r
int.TryParse(drop_chapterStart.Text, out chapterStart);\r
}\r
\r
// Update the Duration\r
- lbl_duration.Text = Main.calculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle).ToString();\r
+ lbl_duration.Text =\r
+ Main.CalculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle)\r
+ .ToString();\r
\r
// Run the Autonaming function\r
if (Properties.Settings.Default.autoNaming)\r
- text_destination.Text = Main.autoName(this);\r
+ text_destination.Text = Main.AutoName(this);\r
\r
// Disable chapter markers if only 1 chapter is selected.\r
if (chapterStart == chapterEnd)\r
}\r
}\r
\r
- //Destination\r
+ private void SecondsOrFramesChanged(object sender, EventArgs e)\r
+ {\r
+ int start, end;\r
+ int.TryParse(drop_chapterStart.Text, out start);\r
+ int.TryParse(drop_chapterFinish.Text, out end);\r
+ double duration = end - start;\r
+\r
+ switch (drop_mode.SelectedIndex)\r
+ {\r
+ case 1:\r
+ lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();\r
+ return;\r
+ case 2:\r
+ if (selectedTitle != null)\r
+ {\r
+ duration = duration / selectedTitle.Fps;\r
+ lbl_duration.Text = TimeSpan.FromSeconds(duration).ToString();\r
+ }\r
+ else\r
+ lbl_duration.Text = "--:--:--";\r
+\r
+ return;\r
+ }\r
+ }\r
+\r
+ private void drop_mode_SelectedIndexChanged(object sender, EventArgs e)\r
+ {\r
+ // Reset\r
+ this.drop_chapterFinish.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);\r
+ this.drop_chapterStart.TextChanged -= new EventHandler(this.SecondsOrFramesChanged);\r
+\r
+ // Do Work\r
+ switch (drop_mode.SelectedIndex)\r
+ {\r
+ case 0:\r
+ drop_chapterStart.DropDownStyle = ComboBoxStyle.DropDownList;\r
+ drop_chapterFinish.DropDownStyle = ComboBoxStyle.DropDownList;\r
+ if (drop_chapterStart.Items.Count != 0)\r
+ {\r
+ drop_chapterStart.SelectedIndex = 0;\r
+ drop_chapterFinish.SelectedIndex = drop_chapterFinish.Items.Count - 1;\r
+ }\r
+ else\r
+ lbl_duration.Text = "--:--:--";\r
+ return;\r
+ case 1:\r
+ this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);\r
+ this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);\r
+ drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;\r
+ drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;\r
+ if (selectedTitle != null)\r
+ {\r
+ drop_chapterStart.Text = "0";\r
+ drop_chapterFinish.Text = selectedTitle.Duration.TotalSeconds.ToString();\r
+ }\r
+ return;\r
+ case 2:\r
+ this.drop_chapterStart.TextChanged += new EventHandler(this.SecondsOrFramesChanged);\r
+ this.drop_chapterFinish.TextChanged += new EventHandler(this.SecondsOrFramesChanged);\r
+ drop_chapterStart.DropDownStyle = ComboBoxStyle.Simple;\r
+ drop_chapterFinish.DropDownStyle = ComboBoxStyle.Simple;\r
+ if (selectedTitle != null)\r
+ {\r
+ drop_chapterStart.Text = "0";\r
+ drop_chapterFinish.Text = (selectedTitle.Fps * selectedTitle.Duration.TotalSeconds).ToString();\r
+ }\r
+ return;\r
+ }\r
+ }\r
+\r
+ // Destination\r
private void btn_destBrowse_Click(object sender, EventArgs e)\r
{\r
// This removes the file extension from the filename box on the save file dialog.\r
\r
if (DVD_Save.ShowDialog() == DialogResult.OK)\r
{\r
- if (DVD_Save.FileName.StartsWith("\\"))\r
- 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
- else\r
+ // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames\r
+ switch (DVD_Save.FilterIndex)\r
{\r
- // Add a file extension manually, as FileDialog.AddExtension has issues with dots in filenames\r
- switch (DVD_Save.FilterIndex)\r
- {\r
- case 1:\r
- if (!Path.GetExtension(DVD_Save.FileName).Equals(".mp4", StringComparison.InvariantCultureIgnoreCase))\r
- if (Properties.Settings.Default.useM4v)\r
- DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");\r
- else\r
- DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");\r
- break;\r
- case 2:\r
- if (!Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))\r
- DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");\r
- break;\r
- default:\r
- //do nothing \r
- break;\r
- }\r
- text_destination.Text = DVD_Save.FileName;\r
-\r
- // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)\r
- if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)\r
- SetExtension(".m4v");\r
+ case 1:\r
+ if (\r
+ !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",\r
+ StringComparison.InvariantCultureIgnoreCase))\r
+ if (Properties.Settings.Default.useM4v)\r
+ DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v");\r
+ else\r
+ DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4");\r
+ break;\r
+ case 2:\r
+ if (\r
+ !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase))\r
+ DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv");\r
+ break;\r
+ default:\r
+ // do nothing \r
+ break;\r
}\r
+ text_destination.Text = DVD_Save.FileName;\r
+\r
+ // Quicktime requires .m4v file for chapter markers to work. If checked, change the extension to .m4v (mp4 and m4v are the same thing)\r
+ if (Check_ChapterMarkers.Checked && DVD_Save.FilterIndex != 2)\r
+ SetExtension(".m4v");\r
}\r
}\r
+\r
private void text_destination_TextChanged(object sender, EventArgs e)\r
{\r
string path = text_destination.Text;\r
switch (drop_format.SelectedIndex)\r
{\r
case 0:\r
- if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())\r
+ if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||\r
+ AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())\r
SetExtension(".m4v");\r
else\r
SetExtension(".mp4");\r
}\r
\r
AudioSettings.SetContainer(drop_format.Text);\r
- Subtitles.setContainer(drop_format.SelectedIndex);\r
+ Subtitles.SetContainer(drop_format.SelectedIndex);\r
\r
if (drop_format.Text.Contains("MP4"))\r
{\r
else if (drop_format.Text.Contains("MKV"))\r
drp_videoEncoder.Items.Add("VP3 (Theora)");\r
}\r
+\r
public void SetExtension(string newExtension)\r
{\r
if (newExtension == ".mp4" || newExtension == ".m4v")\r
- if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())\r
+ if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||\r
+ Subtitles.RequiresM4V())\r
newExtension = ".m4v";\r
else\r
newExtension = ".mp4";\r
text_destination.Text = Path.ChangeExtension(text_destination.Text, newExtension);\r
}\r
\r
- //Video Tab\r
+ // Video Tab\r
private void drp_videoEncoder_SelectedIndexChanged(object sender, EventArgs e)\r
{\r
setContainerOpts();\r
\r
- //Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
+ // Turn off some options which are H.264 only when the user selects a non h.264 encoder\r
if (drp_videoEncoder.Text.Contains("H.264"))\r
{\r
if (check_2PassEncode.CheckState == CheckState.Checked)\r
check_turbo.CheckState = CheckState.Unchecked;\r
check_turbo.Enabled = false;\r
tab_advanced.Enabled = false;\r
- x264Panel.x264Query = "";\r
+ x264Panel.X264Query = string.Empty;\r
check_iPodAtom.Enabled = false;\r
check_iPodAtom.Checked = false;\r
}\r
{\r
case "MPEG-4 (FFmpeg)":\r
if (slider_videoQuality.Value > 31)\r
- slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.\r
+ slider_videoQuality.Value = 20; // Just reset to 70% QP 10 on encode change.\r
slider_videoQuality.Minimum = 1;\r
slider_videoQuality.Maximum = 31;\r
break;\r
double multiplier = 1.0 / cqStep;\r
double value = slider_videoQuality.Value * multiplier;\r
\r
- switch (Properties.Settings.Default.x264cqstep.ToString(culture))\r
- {\r
- case "0.2":\r
- slider_videoQuality.Maximum = 255;\r
- break;\r
- case "0.25":\r
- slider_videoQuality.Maximum = 204;\r
- break;\r
- case "0.5":\r
- slider_videoQuality.Maximum = 102;\r
- break;\r
- case "1":\r
- slider_videoQuality.Maximum = 51;\r
- break;\r
- default:\r
- slider_videoQuality.Maximum = 51;\r
- break;\r
- }\r
+ slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);\r
+\r
if (value < slider_videoQuality.Maximum)\r
slider_videoQuality.Value = slider_videoQuality.Maximum - (int)value;\r
\r
break;\r
case "VP3 (Theora)":\r
if (slider_videoQuality.Value > 63)\r
- slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.\r
+ slider_videoQuality.Value = 45; // Just reset to 70% QP 45 on encode change.\r
slider_videoQuality.Minimum = 0;\r
slider_videoQuality.Maximum = 63;\r
break;\r
}\r
}\r
+\r
/// <summary>\r
/// Set the container format options\r
/// </summary>\r
check_iPodAtom.Checked = false;\r
}\r
}\r
+\r
private double _cachedCqStep = Properties.Settings.Default.x264cqstep;\r
+\r
/// <summary>\r
/// Update the CQ slider for x264 for a new CQ step. This is set from option\r
/// </summary>\r
double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
\r
// Change the maximum value for the slider\r
- switch (Properties.Settings.Default.x264cqstep.ToString(new CultureInfo("en-US")))\r
- {\r
- case "0.2":\r
- slider_videoQuality.Maximum = 255;\r
- break;\r
- case "0.25":\r
- slider_videoQuality.Maximum = 204;\r
- break;\r
- case "0.5":\r
- slider_videoQuality.Maximum = 102;\r
- break;\r
- case "1":\r
- slider_videoQuality.Maximum = 51;\r
- break;\r
- default:\r
- slider_videoQuality.Maximum = 51;\r
- break;\r
- }\r
+ slider_videoQuality.Maximum = (int)(51 / Properties.Settings.Default.x264cqstep);\r
\r
// Reset the CQ slider to RF0\r
slider_videoQuality.Value = slider_videoQuality.Maximum;\r
// Cache the CQ step for the next calculation\r
_cachedCqStep = Properties.Settings.Default.x264cqstep;\r
}\r
+\r
private void slider_videoQuality_Scroll(object sender, EventArgs e)\r
{\r
double cqStep = Properties.Settings.Default.x264cqstep;\r
switch (drp_videoEncoder.Text)\r
{\r
case "MPEG-4 (FFmpeg)":\r
- double rfValue = 31 - (slider_videoQuality.Value - 1);\r
- double max = slider_videoQuality.Maximum;\r
- double min = slider_videoQuality.Minimum;\r
- double val = ((max - min) - (rfValue - min)) / (max - min);\r
- SliderValue.Text = Math.Round((val * 100), 2).ToString(new CultureInfo("en-US")) + "% QP:" + (32 - slider_videoQuality.Value);\r
+ lbl_SliderValue.Text = "QP:" + (32 - slider_videoQuality.Value);\r
break;\r
case "H.264 (x264)":\r
- rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
- max = slider_videoQuality.Maximum * cqStep;\r
- min = slider_videoQuality.Minimum;\r
- val = ((max - min) - (rfValue - min)) / (max - min);\r
+ double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
rfValue = Math.Round(rfValue, 2);\r
- SliderValue.Text = Math.Round((val * 100), 2).ToString(new CultureInfo("en-US")) + "% RF:" + rfValue.ToString(new CultureInfo("en-US"));\r
+ lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));\r
break;\r
case "VP3 (Theora)":\r
- rfValue = slider_videoQuality.Value;\r
- double value = rfValue / 63;\r
- SliderValue.Text = Math.Round((value * 100), 2).ToString(new CultureInfo("en-US")) + "% QP:" + slider_videoQuality.Value;\r
+ lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;\r
break;\r
}\r
}\r
+\r
private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)\r
{\r
text_bitrate.Enabled = false;\r
\r
check_2PassEncode.Enabled = true;\r
}\r
+\r
private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e)\r
{\r
text_bitrate.Enabled = true;\r
\r
check_2PassEncode.Enabled = true;\r
}\r
+\r
private void radio_cq_CheckedChanged(object sender, EventArgs e)\r
{\r
text_bitrate.Enabled = false;\r
check_2PassEncode.Enabled = false;\r
check_2PassEncode.CheckState = CheckState.Unchecked;\r
}\r
+\r
private void check_2PassEncode_CheckedChanged(object sender, EventArgs e)\r
{\r
if (check_2PassEncode.CheckState.ToString() == "Checked")\r
btn_importChapters.Enabled = false;\r
}\r
}\r
+\r
private void btn_importChapters_Click(object sender, EventArgs e)\r
{\r
if (File_ChapterImport.ShowDialog() == DialogResult.OK)\r
{\r
- String filename = File_ChapterImport.FileName;\r
- DataGridView imported = Main.importChapterNames(data_chpt, filename);\r
+ string filename = File_ChapterImport.FileName;\r
+ DataGridView imported = Main.ImportChapterNames(data_chpt, filename);\r
if (imported != null)\r
data_chpt = imported;\r
}\r
}\r
+\r
+ private void btn_export_Click(object sender, EventArgs e)\r
+ {\r
+ SaveFileDialog saveFileDialog = new SaveFileDialog();\r
+ saveFileDialog.Filter = "Csv File|*.csv";\r
+ saveFileDialog.DefaultExt = "csv";\r
+ if (saveFileDialog.ShowDialog() == DialogResult.OK)\r
+ {\r
+ string filename = saveFileDialog.FileName;\r
+\r
+ Main.SaveChapterMarkersToCsv(this, filename);\r
+ }\r
+ }\r
+\r
private void mnu_resetChapters_Click(object sender, EventArgs e)\r
{\r
data_chpt.Rows.Clear();\r
- DataGridView chapterGridView = Main.chapterNaming(data_chpt, drop_chapterFinish.Text);\r
+ DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text);\r
if (chapterGridView != null)\r
{\r
data_chpt = chapterGridView;\r
// Query Editor Tab\r
private void btn_generate_Query_Click(object sender, EventArgs e)\r
{\r
- rtf_query.Text = queryGen.GenerateCLIQuery(this, 0, null);\r
+ rtf_query.Text = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
}\r
+\r
private void btn_clear_Click(object sender, EventArgs e)\r
{\r
rtf_query.Clear();\r
}\r
+\r
#endregion\r
\r
// MainWindow Components, Actions and Functions ***********************\r
\r
#region Source Scan\r
- public Boolean isScanning { get; set; }\r
- private static int scanProcessID { get; set; }\r
- private void startScan(String filename)\r
+\r
+ public bool isScanning { get; set; }\r
+\r
+ private void StartScan(string filename, int title)\r
{\r
// Setup the GUI components for the scan.\r
sourcePath = filename;\r
- foreach (Control ctrl in Controls)\r
- if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))\r
- ctrl.Enabled = false;\r
\r
- lbl_encode.Visible = true;\r
- lbl_encode.Text = "Scanning ...";\r
- btn_source.Enabled = false;\r
- btn_start.Enabled = false;\r
- btn_showQueue.Enabled = false;\r
- btn_add2Queue.Enabled = false;\r
- tb_preview.Enabled = false;\r
- mnu_killCLI.Visible = true;\r
+ this.DisableGUI();\r
+\r
+ if (ActivityWindow != null)\r
+ ActivityWindow.SetMode(ActivityLogMode.Scan);\r
\r
- // Start hte Scan Thread\r
+ // Start the Scan\r
try\r
{\r
- if (ActivityWindow != null)\r
- ActivityWindow.SetLogView(true);\r
isScanning = true;\r
- ThreadPool.QueueUserWorkItem(scanProcess);\r
+ SourceScan = new Scan();\r
+ SourceScan.ScanSource(sourcePath, title);\r
+ SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);\r
+ SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);\r
}\r
catch (Exception exc)\r
{\r
- MessageBox.Show("frmMain.cs - startScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
}\r
- private void scanProcess(object state)\r
- {\r
- try\r
- {\r
- string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
- string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");\r
-\r
- // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)\r
- if (File.Exists(dvdInfoPath))\r
- File.Delete(dvdInfoPath);\r
-\r
- String dvdnav = string.Empty;\r
- if (Properties.Settings.Default.dvdnav)\r
- dvdnav = " --dvdnav";\r
- string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 {2} -v >""{3}"" 2>&1""", handbrakeCLIPath, sourcePath, dvdnav, dvdInfoPath);\r
-\r
- ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine) { WindowStyle = ProcessWindowStyle.Hidden };\r
\r
- Boolean cleanExit = true;\r
- using (hbproc = Process.Start(hbParseDvd))\r
- {\r
- Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.\r
- scanProcessID = Main.getCliProcess(before);\r
- hbproc.WaitForExit();\r
- if (hbproc.ExitCode != 0)\r
- cleanExit = false;\r
- }\r
-\r
- if (cleanExit) // If 0 exit code, CLI exited cleanly.\r
- {\r
- if (!File.Exists(dvdInfoPath))\r
- throw new Exception("Unable to retrieve the DVD Info. last_scan_log.txt is missing. \nExpected location of last_scan_log.txt: \n"\r
- + dvdInfoPath);\r
+ private void SourceScan_ScanStatusChanged(object sender, EventArgs e)\r
+ {\r
+ UpdateScanStatusLabel();\r
+ }\r
\r
- using (StreamReader sr = new StreamReader(dvdInfoPath))\r
- {\r
- thisDVD = DVD.Parse(sr);\r
- sr.Close();\r
- sr.Dispose();\r
- }\r
+ private void SourceScan_ScanCompleted(object sender, EventArgs e)\r
+ {\r
+ UpdateGuiAfterScan();\r
+ }\r
\r
- updateUIafterScan();\r
- }\r
- }\r
- catch (Exception exc)\r
+ private void UpdateScanStatusLabel()\r
+ {\r
+ if (InvokeRequired)\r
{\r
- MessageBox.Show("frmMain.cs - scanProcess() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
- enableGUI();\r
+ BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));\r
+ return;\r
}\r
+ lbl_encode.Text = SourceScan.ScanStatus();\r
}\r
- private void updateUIafterScan()\r
+\r
+ private void UpdateGuiAfterScan()\r
{\r
+ if (InvokeRequired)\r
+ {\r
+ BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));\r
+ return;\r
+ }\r
+\r
try\r
{\r
- if (InvokeRequired)\r
- {\r
- BeginInvoke(new UpdateWindowHandler(updateUIafterScan));\r
- return;\r
- }\r
+ currentSource = SourceScan.SouceData();\r
\r
// Setup some GUI components\r
drp_dvdtitle.Items.Clear();\r
- if (thisDVD.Titles.Count != 0)\r
- drp_dvdtitle.Items.AddRange(thisDVD.Titles.ToArray());\r
+ if (currentSource.Titles.Count != 0)\r
+ drp_dvdtitle.Items.AddRange(currentSource.Titles.ToArray());\r
\r
- // Now select the longest title\r
- if (thisDVD.Titles.Count != 0)\r
- drp_dvdtitle.SelectedItem = Main.selectLongestTitle(thisDVD);\r
+ foreach (Title title in currentSource.Titles)\r
+ {\r
+ if (title.MainTitle)\r
+ {\r
+ drp_dvdtitle.SelectedItem = title;\r
+ }\r
+ }\r
+\r
+ if (drp_dvdtitle.SelectedItem == null && drp_dvdtitle.Items.Count > 0)\r
+ {\r
+ drp_dvdtitle.SelectedIndex = 0;\r
+ }\r
\r
// Enable the creation of chapter markers if the file is an image of a dvd.\r
- if (sourcePath.ToLower().Contains(".iso") || sourcePath.Contains("VIDEO_TS"))\r
+ int start, end;\r
+ int.TryParse(drop_chapterStart.Items[0].ToString(), out start);\r
+ int.TryParse(drop_chapterFinish.Items[drop_chapterFinish.Items.Count - 1].ToString(), out end);\r
+ if (end > start)\r
Check_ChapterMarkers.Enabled = true;\r
else\r
{\r
UpdateSourceLabel();\r
\r
// Enable the GUI components and enable any disabled components\r
- enableGUI();\r
+ EnableGUI();\r
}\r
catch (Exception exc)\r
{\r
- MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
- enableGUI();\r
+ MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK,\r
+ MessageBoxIcon.Error);\r
+ EnableGUI();\r
}\r
}\r
- private void enableGUI()\r
+\r
+ private void EnableGUI()\r
{\r
try\r
{\r
if (InvokeRequired)\r
- BeginInvoke(new UpdateWindowHandler(enableGUI));\r
+ BeginInvoke(new UpdateWindowHandler(EnableGUI));\r
lbl_encode.Text = "Scan Completed";\r
foreach (Control ctrl in Controls)\r
ctrl.Enabled = true;\r
}\r
catch (Exception exc)\r
{\r
- MessageBox.Show("frmMain.cs - enableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
}\r
- private void killScan()\r
+\r
+ private void DisableGUI()\r
{\r
- try\r
- {\r
- enableGUI();\r
- resetGUI();\r
+ foreach (Control ctrl in Controls)\r
+ if (!(ctrl is StatusStrip || ctrl is MenuStrip || ctrl is ToolStrip))\r
+ ctrl.Enabled = false;\r
\r
- Process[] prs = Process.GetProcesses();\r
- foreach (Process process in prs)\r
- {\r
- if (process.Id == scanProcessID)\r
- {\r
- process.Refresh();\r
- if (!process.HasExited)\r
- process.Kill();\r
- }\r
- }\r
- }\r
- catch (Exception ex)\r
- {\r
- 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
- }\r
+ lbl_encode.Visible = true;\r
+ lbl_encode.Text = "Scanning ...";\r
+ btn_source.Enabled = false;\r
+ btn_start.Enabled = false;\r
+ btn_showQueue.Enabled = false;\r
+ btn_add2Queue.Enabled = false;\r
+ tb_preview.Enabled = false;\r
+ mnu_killCLI.Visible = true;\r
}\r
- private void resetGUI()\r
+\r
+ private void KillScan()\r
+ {\r
+ SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+ EnableGUI();\r
+ ResetGUI();\r
+\r
+ SourceScan.KillScan();\r
+\r
+ lbl_encode.Text = "Scan Cancelled!";\r
+ }\r
+\r
+ private void ResetGUI()\r
{\r
drp_dvdtitle.Items.Clear();\r
drop_chapterStart.Items.Clear();\r
drop_chapterFinish.Items.Clear();\r
lbl_duration.Text = "Select a Title";\r
PictureSettings.lbl_src_res.Text = "Select a Title";\r
- PictureSettings.lbl_Aspect.Text = "Select a Title";\r
sourcePath = String.Empty;\r
text_destination.Text = String.Empty;\r
- thisDVD = null;\r
selectedTitle = null;\r
isScanning = false;\r
}\r
+\r
private void UpdateSourceLabel()\r
{\r
- labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : Path.GetFileName(sourcePath);\r
+ labelSource.Text = string.IsNullOrEmpty(sourcePath) ? "Select \"Source\" to continue." : this.SourceName;\r
+\r
+ if (selectedTitle != null)\r
+ if (!string.IsNullOrEmpty(selectedTitle.SourceName))\r
+ // If it's one of multiple source files, make sure we don't use the folder name\r
+ labelSource.Text = Path.GetFileName(selectedTitle.SourceName);\r
+ }\r
+\r
+ public void RecievingJob(Job job)\r
+ {\r
+ string query = job.Query;\r
+ StartScan(job.Source, job.Title);\r
+\r
+ if (query != null)\r
+ {\r
+ // Ok, Reset all the H264 widgets before changing the preset\r
+ x264Panel.Reset2Defaults();\r
+\r
+ // Send the query from the file to the Query Parser class\r
+ QueryParser presetQuery = QueryParser.Parse(query);\r
+\r
+ // Now load the preset\r
+ PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue", true);\r
+\r
+ // The x264 widgets will need updated, so do this now:\r
+ x264Panel.X264_StandardizeOptString();\r
+ x264Panel.X264_SetCurrentSettingsInPanel();\r
+\r
+ // Finally, let this window have a copy of the preset settings.\r
+ CurrentlySelectedPreset = null;\r
+ PictureSettings.SetPresetCropWarningLabel(null);\r
+ }\r
}\r
+\r
#endregion\r
\r
- #region GUI\r
+ #region GUI Functions and Actions\r
+\r
/// <summary>\r
/// Set the GUI to it's finished encoding state.\r
/// </summary>\r
- private void setEncodeFinished()\r
+ private void SetEncodeFinished()\r
{\r
try\r
{\r
if (InvokeRequired)\r
{\r
- BeginInvoke(new UpdateWindowHandler(setEncodeFinished));\r
+ BeginInvoke(new UpdateWindowHandler(SetEncodeFinished));\r
return;\r
}\r
\r
/// <summary>\r
/// Set the GUI to it's started encoding state.\r
/// </summary>\r
- private void setEncodeStarted()\r
+ private void SetEncodeStarted()\r
{\r
try\r
{\r
if (InvokeRequired)\r
{\r
- BeginInvoke(new UpdateWindowHandler(setEncodeStarted));\r
+ BeginInvoke(new UpdateWindowHandler(SetEncodeStarted));\r
return;\r
}\r
\r
MessageBox.Show(exc.ToString());\r
}\r
}\r
- #endregion\r
\r
- #region DVD Drive Detection\r
- private void getDriveInfoThread()\r
+ /// <summary>\r
+ /// Set the DVD Drive selection in the "Source" Menu\r
+ /// </summary>\r
+ private void SetDriveSelectionMenuItem()\r
{\r
try\r
{\r
if (InvokeRequired)\r
{\r
- BeginInvoke(new UpdateWindowHandler(getDriveInfoThread));\r
+ BeginInvoke(new UpdateWindowHandler(SetDriveSelectionMenuItem));\r
return;\r
}\r
\r
- Boolean foundDrive = false;\r
- DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();\r
- foreach (DriveInfo curDrive in theCollectionOfDrives)\r
+ drives = Main.GetDrives();\r
+\r
+ List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();\r
+ foreach (DriveInformation drive in drives)\r
{\r
- if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady)\r
- {\r
- if (File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))\r
- {\r
- mnu_dvd_drive.Text = curDrive.RootDirectory + "VIDEO_TS (" + curDrive.VolumeLabel + ")";\r
- foundDrive = true;\r
- break;\r
- }\r
- }\r
+ ToolStripMenuItem menuItem = new ToolStripMenuItem();\r
+ menuItem.Name = drive.ToString();\r
+ menuItem.Text = drive.RootDirectory + " (" + drive.VolumeLabel + ")";\r
+ menuItem.Image = Resources.disc_small;\r
+ menuItem.Click += new EventHandler(mnu_dvd_drive_Click);\r
+ menuItems.Add(menuItem);\r
}\r
\r
- if (foundDrive == false)\r
- mnu_dvd_drive.Text = "[No DVD Drive Ready]";\r
+ foreach (ToolStripMenuItem item in menuItems)\r
+ btn_source.DropDownItems.Add(item);\r
}\r
- catch (Exception)\r
+ catch (Exception exc)\r
{\r
- mnu_dvd_drive.Text = "[No DVD Drive Ready / Found]";\r
+ MessageBox.Show("Error in SetDriveSelectionMenuItem" + exc);\r
}\r
}\r
- #endregion\r
\r
- #region Public Methods\r
/// <summary>\r
/// Access the preset Handler and setup the preset panel.\r
/// </summary>\r
- public void loadPresetPanel()\r
+ private void LoadPresetPanel()\r
{\r
if (presetHandler.CheckIfPresetsAreOutOfDate())\r
if (!Properties.Settings.Default.presetNotification)\r
MessageBox.Show(splash,\r
- "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",\r
- "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
+ "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",\r
+ "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);\r
\r
presetHandler.GetPresetPanel(ref treeView_presets);\r
treeView_presets.Update();\r
}\r
+\r
+ /// <summary>\r
+ /// Get the title from the selected item in the title dropdown.\r
+ /// </summary>\r
+ /// <returns>\r
+ /// The title.\r
+ /// </returns>\r
+ private int getTitle()\r
+ {\r
+ int title = 0;\r
+ if (drp_dvdtitle.SelectedItem != null)\r
+ {\r
+ string[] titleInfo = drp_dvdtitle.SelectedItem.ToString().Split(' ');\r
+ int.TryParse(titleInfo[0], out title);\r
+ }\r
+\r
+ return title;\r
+ }\r
+\r
#endregion\r
\r
#region Overrides\r
+\r
+ /// <summary>\r
+ /// Handle GUI shortcuts\r
+ /// </summary>\r
+ /// <param name="msg">Message</param>\r
+ /// <param name="keyData">Keys</param>\r
+ /// <returns>Bool</returns>\r
+ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)\r
+ {\r
+ if (keyData == (Keys.Control | Keys.S))\r
+ {\r
+ btn_start_Click(this, new EventArgs());\r
+ return true;\r
+ }\r
+\r
+ if (keyData == (Keys.Control | Keys.A))\r
+ {\r
+ btn_add2Queue_Click(this, new EventArgs());\r
+ return true;\r
+ }\r
+ return base.ProcessCmdKey(ref msg, keyData);\r
+ }\r
+\r
/// <summary>\r
/// If the queue is being processed, prompt the user to confirm application close.\r
/// </summary>\r
- /// <param name="e"></param>\r
+ /// <param name="e">FormClosingEventArgs</param>\r
protected override void OnFormClosing(FormClosingEventArgs e)\r
{\r
// If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.\r
- if ((encodeQueue.isEncoding) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0))\r
+ if (encodeQueue.IsEncoding)\r
{\r
- 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
- "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+ DialogResult result =\r
+ MessageBox.Show(\r
+ "HandBrake has queue items to process. Closing HandBrake will stop the current encoding.\n\nDo you want to close HandBrake?",\r
+ "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
+\r
if (result == DialogResult.No)\r
e.Cancel = true;\r
+\r
+ // Try to safely close out if we can, or kill the cli if using in-gui status\r
+ if (Settings.Default.enocdeStatusInGui)\r
+ encodeQueue.Stop();\r
+ else\r
+ encodeQueue.SafelyClose();\r
+ }\r
+\r
+ if (SourceScan.IsScanning)\r
+ {\r
+ SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+ SourceScan.KillScan();\r
}\r
base.OnFormClosing(e);\r
}\r
+\r
#endregion\r
\r
#region In-GUI Encode Status (Experimental)\r
- private void encodeMonitorThread()\r
+\r
+ /// <summary>\r
+ /// Starts a new thread to monitor and process the CLI encode status\r
+ /// </summary>\r
+ private void EncodeMonitorThread()\r
{\r
try\r
{\r
- Parser encode = new Parser(encodeQueue.hbProcess.StandardOutput.BaseStream);\r
- encode.OnEncodeProgress += encodeOnEncodeProgress;\r
+ Parser encode = new Parser(encodeQueue.HbProcess.StandardOutput.BaseStream);\r
+ encode.OnEncodeProgress += EncodeOnEncodeProgress;\r
while (!encode.EndOfStream)\r
- encode.readEncodeStatus();\r
+ encode.ReadEncodeStatus();\r
}\r
catch (Exception exc)\r
{\r
MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
}\r
}\r
- private void encodeOnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
+\r
+ /// <summary>\r
+ /// Displays the Encode status in the GUI\r
+ /// </summary>\r
+ /// <param name="Sender"></param>\r
+ /// <param name="CurrentTask"></param>\r
+ /// <param name="TaskCount"></param>\r
+ /// <param name="PercentComplete"></param>\r
+ /// <param name="CurrentFps"></param>\r
+ /// <param name="AverageFps"></param>\r
+ /// <param name="TimeRemaining"></param>\r
+ private void EncodeOnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
{\r
if (this.InvokeRequired)\r
{\r
- this.BeginInvoke(new EncodeProgressEventHandler(encodeOnEncodeProgress),\r
- new object[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
+ this.BeginInvoke(\r
+ new EncodeProgressEventHandler(EncodeOnEncodeProgress),\r
+ new[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
return;\r
}\r
- lbl_encode.Text = string.Format("Encode Progress: {0}%, FPS: {1}, Avg FPS: {2}, Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
+ lbl_encode.Text =\r
+ string.Format("Encode Progress: {0}%, FPS: {1}, Avg FPS: {2}, Time Remaining: {3} ", PercentComplete, CurrentFps, AverageFps, TimeRemaining);\r
}\r
+\r
#endregion\r
\r
+\r
// This is the END of the road ****************************************\r
}\r
}
\ No newline at end of file