using System.Drawing;\r
using System.Globalization;\r
using System.IO;\r
+ using System.Linq;\r
using System.Threading;\r
using System.Windows.Forms;\r
+\r
+ using DevExpress.Utils.Menu;\r
+\r
using Functions;\r
\r
+ using HandBrake.ApplicationServices.EventArgs;\r
+ using HandBrake.ApplicationServices.Utilities;\r
using HandBrake.Framework.Model;\r
using HandBrake.Framework.Services;\r
using HandBrake.Framework.Views;\r
using Handbrake.ToolWindows;\r
\r
using Model;\r
- using Presets;\r
using Properties;\r
\r
using Main = Handbrake.Functions.Main;\r
public partial class frmMain : Form\r
{\r
// Objects which may be used by one or more other objects *************\r
- private IQueue encodeQueue = new Queue();\r
- private PresetsHandler presetHandler = new PresetsHandler();\r
+ private IQueueProcessor queueProcessor = new QueueProcessor(Program.InstanceId);\r
+ private PresetService presetHandler = new PresetService();\r
\r
// Windows ************************************************************\r
private frmQueue queueWindow;\r
private string dvdDrivePath;\r
private string dvdDriveLabel;\r
private Preset currentlySelectedPreset;\r
- private DVD currentSource;\r
- private IScan SourceScan = new ScanService();\r
+ private Source currentSource;\r
+\r
+ private IScan SourceScan;\r
private List<DriveInformation> drives;\r
+ private QueueTask queueEdit;\r
\r
// Delegates **********************************************************\r
private delegate void UpdateWindowHandler();\r
return Path.GetFileName(selectedTitle.SourceName);\r
}\r
\r
+ // We have a drive, selected as a folder.\r
+ if (this.sourcePath.EndsWith("\\"))\r
+ {\r
+ drives = UtilityService.GetDrives();\r
+ foreach (DriveInformation item in drives)\r
+ {\r
+ if (item.RootDirectory.Contains(this.sourcePath))\r
+ {\r
+ return item.VolumeLabel;\r
+ }\r
+ }\r
+ }\r
+\r
if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")\r
return Path.GetFileNameWithoutExtension(this.sourcePath);\r
\r
public frmMain(string[] args)\r
{\r
InitializeComponent();\r
+ this.presetsToolStrip.Renderer = new ToolStripRenderOverride();\r
+\r
+ // We can use LibHB, if the library hb.dll exists.\r
+ this.SourceScan = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService();\r
\r
// Update the users config file with the CLI version data.\r
Main.SetCliVersionData();\r
// Clear the log files in the background\r
if (Settings.Default.clearOldLogs)\r
{\r
- Thread clearLog = new Thread(Main.ClearOldLogs);\r
+ Thread clearLog = new Thread(() => UtilityService.ClearLogFiles(30));\r
clearLog.Start();\r
}\r
\r
treeView_presets.ExpandAll();\r
lbl_encode.Text = string.Empty;\r
drop_mode.SelectedIndex = 0;\r
- queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue\r
+ queueWindow = new frmQueue(this.queueProcessor, this); // Prepare the Queue\r
if (!Settings.Default.QueryEditorTab)\r
tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled.\r
if (Settings.Default.tooltipEnable)\r
{\r
x264Panel.Reset2Defaults();\r
\r
- QueryParser presetQuery = QueryParser.Parse(query);\r
+ EncodeTask presetQuery = QueryParserUtility.Parse(query);\r
PresetLoader.LoadPreset(this, presetQuery, Settings.Default.defaultPreset);\r
\r
x264Panel.StandardizeOptString();\r
\r
// Event Handlers and Queue Recovery\r
events();\r
- Main.RecoverQueue(encodeQueue);\r
+ Main.RecoverQueue(this.queueProcessor);\r
\r
// If have a file passed in via command arguemtents, check it's a file and try scanning it.\r
if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0])))\r
RegisterPresetEventHandler();\r
\r
// Handle Window Resize\r
- if (Properties.Settings.Default.MainWindowMinimize)\r
- this.Resize += new EventHandler(frmMain_Resize);\r
+ if (Settings.Default.MainWindowMinimize)\r
+ this.Resize += this.frmMain_Resize;\r
\r
// Handle Encode Start / Finish / Pause\r
- encodeQueue.EncodeStarted += new EventHandler(encodeStarted);\r
- encodeQueue.EncodeEnded += new EventHandler(encodeEnded);\r
+ this.queueProcessor.EncodeService.EncodeStarted += this.encodeStarted;\r
+ this.queueProcessor.EncodeService.EncodeCompleted += encodeEnded;\r
+\r
+ // Scan Started and Completed Events\r
+ SourceScan.ScanStatusChanged += this.SourceScanScanStatusChanged;\r
+ SourceScan.ScanCompleted += this.SourceScanScanCompleted;\r
\r
// Handle a file being draged onto the GUI.\r
- this.DragEnter += new DragEventHandler(frmMain_DragEnter);\r
- this.DragDrop += new DragEventHandler(frmMain_DragDrop);\r
+ this.DragEnter += frmMain_DragEnter;\r
+ this.DragDrop += this.frmMain_DragDrop;\r
}\r
\r
// Change the preset label to custom when a user changes a setting. Don't want to give the impression that users can change settings and still be using a preset\r
private void RegisterPresetEventHandler()\r
{\r
// Output Settings\r
- drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel);\r
- check_largeFile.CheckedChanged += new EventHandler(changePresetLabel);\r
- check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel);\r
- check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel);\r
+ drop_format.SelectedIndexChanged += this.changePresetLabel;\r
+ check_largeFile.CheckedChanged += this.changePresetLabel;\r
+ check_iPodAtom.CheckedChanged += this.changePresetLabel;\r
+ check_optimiseMP4.CheckedChanged += this.changePresetLabel;\r
\r
// Picture Settings\r
- PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel);\r
+ PictureSettings.PictureSettingsChanged += this.changePresetLabel;\r
\r
// Filter Settings\r
- Filters.FilterSettingsChanged += new EventHandler(changePresetLabel);\r
+ Filters.FilterSettingsChanged += this.changePresetLabel;\r
\r
// Video Tab\r
- drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel);\r
- check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel);\r
- check_turbo.CheckedChanged += new EventHandler(changePresetLabel);\r
- text_filesize.TextChanged += new EventHandler(changePresetLabel);\r
- text_bitrate.TextChanged += new EventHandler(changePresetLabel);\r
- slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel);\r
+ drp_videoEncoder.SelectedIndexChanged += this.changePresetLabel;\r
+ check_2PassEncode.CheckedChanged += this.changePresetLabel;\r
+ check_turbo.CheckedChanged += this.changePresetLabel;\r
+ text_bitrate.TextChanged += this.changePresetLabel;\r
+ slider_videoQuality.ValueChanged += this.changePresetLabel;\r
\r
// Audio Panel\r
- AudioSettings.AudioListChanged += new EventHandler(changePresetLabel);\r
+ AudioSettings.AudioListChanged += this.changePresetLabel;\r
\r
// Advanced Tab\r
- x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel);\r
+ x264Panel.rtf_x264Query.TextChanged += this.changePresetLabel;\r
}\r
\r
private void UnRegisterPresetEventHandler()\r
{\r
// Output Settings \r
- drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel);\r
- check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel);\r
- check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel);\r
- check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel);\r
+ drop_format.SelectedIndexChanged -= this.changePresetLabel;\r
+ check_largeFile.CheckedChanged -= this.changePresetLabel;\r
+ check_iPodAtom.CheckedChanged -= this.changePresetLabel;\r
+ check_optimiseMP4.CheckedChanged -= this.changePresetLabel;\r
\r
// Picture Settings\r
- PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel);\r
+ PictureSettings.PictureSettingsChanged -= this.changePresetLabel;\r
\r
// Filter Settings\r
- Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel);\r
+ Filters.FilterSettingsChanged -= this.changePresetLabel;\r
\r
// Video Tab\r
- drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel);\r
- check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel);\r
- check_turbo.CheckedChanged -= new EventHandler(changePresetLabel);\r
- text_filesize.TextChanged -= new EventHandler(changePresetLabel);\r
- text_bitrate.TextChanged -= new EventHandler(changePresetLabel);\r
- slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel);\r
+ drp_videoEncoder.SelectedIndexChanged -= this.changePresetLabel;\r
+ check_2PassEncode.CheckedChanged -= this.changePresetLabel;\r
+ check_turbo.CheckedChanged -= this.changePresetLabel;\r
+ text_bitrate.TextChanged -= this.changePresetLabel;\r
+ slider_videoQuality.ValueChanged -= this.changePresetLabel;\r
\r
// Audio Panel\r
- AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel);\r
+ AudioSettings.AudioListChanged -= this.changePresetLabel;\r
\r
// Advanced Tab\r
- x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel);\r
+ x264Panel.rtf_x264Query.TextChanged -= this.changePresetLabel;\r
}\r
\r
private void changePresetLabel(object sender, EventArgs e)\r
private void encodeStarted(object sender, EventArgs e)\r
{\r
SetEncodeStarted();\r
- encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;\r
+ this.queueProcessor.EncodeService.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged;\r
}\r
\r
private void encodeEnded(object sender, EventArgs e)\r
{\r
- encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;\r
+ this.queueProcessor.EncodeService.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged;\r
SetEncodeFinished();\r
}\r
#endregion\r
\r
#endregion\r
\r
- #region Presets Menu\r
-\r
- /// <summary>\r
- /// Reset the Built in Presets\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void mnu_presetReset_Click(object sender, EventArgs e)\r
- {\r
- presetHandler.UpdateBuiltInPresets();\r
- LoadPresetPanel();\r
- if (treeView_presets.Nodes.Count == 0)\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
- /// <summary>\r
- /// Delete the selected preset\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void mnu_delete_preset_Click(object sender, EventArgs e)\r
- {\r
- presetHandler.RemoveBuiltInPresets();\r
- LoadPresetPanel(); // Reload the preset panel\r
- }\r
-\r
- /// <summary>\r
- /// Select the Normal preset\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void mnu_SelectDefault_Click(object sender, EventArgs e)\r
- {\r
- loadNormalPreset();\r
- }\r
-\r
- /// <summary>\r
- /// Import a plist Preset\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void mnu_importMacPreset_Click(object sender, EventArgs e)\r
- {\r
- ImportPreset();\r
- }\r
-\r
- /// <summary>\r
- /// Export a Plist Preset\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void mnu_exportMacPreset_Click(object sender, EventArgs e)\r
- {\r
- ExportPreset();\r
- }\r
-\r
- /// <summary>\r
- /// Create a new Preset\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void btn_new_preset_Click(object sender, EventArgs e)\r
- {\r
- Form preset = new frmAddPreset(this, presetHandler);\r
- if (preset.ShowDialog() == DialogResult.OK)\r
- {\r
- TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black };\r
- treeView_presets.Nodes.Add(presetTreeview);\r
- presetHandler.LastPresetAdded = null;\r
- }\r
- }\r
-\r
- #endregion\r
-\r
- #region Help Menu\r
+ #region Help Menu (Toolbar)\r
\r
/// <summary>\r
- /// Menu - Display the User Guide Web Page\r
+ /// Menu - Display the User Guide Web Page\r
/// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void mnu_user_guide_Click(object sender, EventArgs e)\r
+ /// <param name="sender">The Sender</param>\r
+ /// <param name="e">The EventArgs</param>\r
+ private void MnuUserGuide_Click(object sender, EventArgs e)\r
{\r
Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide");\r
}\r
\r
/// <summary>\r
- /// Menu - Check for Updates\r
+ /// Check for Updates\r
/// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void mnu_UpdateCheck_Click(object sender, EventArgs e)\r
+ /// <param name="sender">The Sender</param>\r
+ /// <param name="e">The EventArgs</param>\r
+ private void MnuCheckForUpdates_Click(object sender, EventArgs e)\r
{\r
lbl_updateCheck.Visible = true;\r
Settings.Default.lastUpdateCheckDate = DateTime.Now;\r
/// <summary>\r
/// Menu - Display the About Window\r
/// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void mnu_about_Click(object sender, EventArgs e)\r
+ /// <param name="sender">The Sender</param>\r
+ /// <param name="e">The EventArgs</param>\r
+ private void MnuAboutHandBrake_Click(object sender, EventArgs e)\r
{\r
using (frmAbout About = new frmAbout())\r
{\r
/// </param>\r
private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
{\r
- // TODO this requires a re-think since the Query Editor has changed.\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,\r
- QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);\r
- else if (result == DialogResult.No)\r
- presetHandler.Update(treeView_presets.SelectedNode.Text,\r
- QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);\r
+\r
+ Preset preset = new Preset\r
+ {\r
+ Name = this.treeView_presets.SelectedNode.Text,\r
+ Query =\r
+ QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0),\r
+ CropSettings = (result == DialogResult.Yes)\r
+ };\r
+\r
+ presetHandler.Update(preset);\r
}\r
\r
/// <summary>\r
{\r
if (treeView_presets.SelectedNode != null)\r
{\r
- presetHandler.Remove(treeView_presets.SelectedNode.Text);\r
+ presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag);\r
treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);\r
}\r
treeView_presets.Select();\r
\r
// Now enable the save menu if the selected preset is a user preset\r
if (treeView_presets.SelectedNode != null)\r
- if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))\r
+ if (presetHandler.CheckIfPresetExists(treeView_presets.SelectedNode.Text))\r
pmnu_saveChanges.Enabled = true;\r
\r
treeView_presets.Select();\r
\r
// Presets Management\r
\r
- /// <summary>\r
- /// Button - Add a preset\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void btn_addPreset_Click(object sender, EventArgs e)\r
+ private void BtnAddPreset_Click(object sender, EventArgs e)\r
{\r
Form preset = new frmAddPreset(this, presetHandler);\r
if (preset.ShowDialog() == DialogResult.OK)\r
}\r
}\r
\r
- /// <summary>\r
- /// Button - remove a Preset\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void btn_removePreset_Click(object sender, EventArgs e)\r
+ private void BtnRemovePreset_Click(object sender, EventArgs e)\r
{\r
DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset",\r
MessageBoxButtons.YesNo, MessageBoxIcon.Question);\r
{\r
if (treeView_presets.SelectedNode != null)\r
{\r
- presetHandler.Remove(treeView_presets.SelectedNode.Text);\r
+ presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag);\r
treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);\r
}\r
}\r
treeView_presets.Select();\r
}\r
\r
- /// <summary>\r
- /// Button - Set the selected preset as the default\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The sender.\r
- /// </param>\r
- /// <param name="e">\r
- /// The e.\r
- /// </param>\r
- private void btn_setDefault_Click(object sender, EventArgs e)\r
+\r
+ private void MnuSetDefaultPreset_Click(object sender, EventArgs e)\r
{\r
if (treeView_presets.SelectedNode != null)\r
{\r
MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
}\r
\r
+ private void MnuImportPreset_Click(object sender, EventArgs e)\r
+ {\r
+ this.ImportPreset();\r
+ }\r
+\r
+ private void MnuExportPreset_Click(object sender, EventArgs e)\r
+ {\r
+ this.ExportPreset();\r
+ }\r
+\r
+ private void MnuResetBuiltInPresets_Click(object sender, EventArgs e)\r
+ {\r
+ presetHandler.UpdateBuiltInPresets(string.Empty);\r
+ LoadPresetPanel();\r
+ if (treeView_presets.Nodes.Count == 0)\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
/// <summary>\r
/// PresetBar Mouse Down event\r
/// </summary>\r
}\r
\r
/// <summary>\r
+ /// When the mouse moves, display a preset\r
+ /// </summary>\r
+ /// <param name="sender">The Sender</param>\r
+ /// <param name="e">the MouseEventArgs</param>\r
+ private void TreeViewPresetsMouseMove(object sender, MouseEventArgs e)\r
+ {\r
+ TreeNode theNode = this.treeView_presets.GetNodeAt(e.X, e.Y);\r
+\r
+ if ((theNode != null))\r
+ {\r
+ // Change the ToolTip only if the pointer moved to a new node.\r
+ if (theNode.ToolTipText != this.ToolTip.GetToolTip(this.treeView_presets))\r
+ {\r
+ this.ToolTip.SetToolTip(this.treeView_presets, theNode.ToolTipText);\r
+ }\r
+ }\r
+ else // Pointer is not over a node so clear the ToolTip.\r
+ {\r
+ this.ToolTip.SetToolTip(this.treeView_presets, string.Empty);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
/// Preset Bar - Handle the Delete Key\r
/// </summary>\r
/// <param name="sender">\r
if (result == DialogResult.Yes)\r
{\r
if (treeView_presets.SelectedNode != null)\r
- presetHandler.Remove(treeView_presets.SelectedNode.Text);\r
+ presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag);\r
\r
// Remember each nodes expanded status so we can reload it\r
List<bool> nodeStatus = new List<bool>();\r
x264Panel.Reset2Defaults();\r
\r
// Send the query from the file to the Query Parser class\r
- QueryParser presetQuery = QueryParser.Parse(query);\r
+ EncodeTask presetQuery = QueryParserUtility.Parse(query);\r
\r
// Now load the preset\r
PresetLoader.LoadPreset(this, presetQuery, presetName);\r
{\r
if (openPreset.ShowDialog() == DialogResult.OK)\r
{\r
- QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName);\r
- if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))\r
+ EncodeTask parsed = PlistPresetHandler.Import(openPreset.FileName);\r
+ if (presetHandler.CheckIfPresetExists(parsed.PresetName + " (Imported)"))\r
{\r
DialogResult result =\r
MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",\r
if (result == DialogResult.Yes)\r
{\r
PresetLoader.LoadPreset(this, parsed, parsed.PresetName);\r
- presetHandler.Update(parsed.PresetName + " (Imported)",\r
- QueryGenerator.GenerateFullQuery(this),\r
- parsed.UsesPictureSettings);\r
+\r
+ Preset preset = new Preset\r
+ {\r
+ Name = parsed.PresetName + " (Imported)",\r
+ Query = QueryGenerator.GenerateFullQuery(this),\r
+ CropSettings = parsed.UsesPictureSettings\r
+ };\r
+\r
+ presetHandler.Update(preset);\r
}\r
}\r
else\r
{\r
PresetLoader.LoadPreset(this, parsed, parsed.PresetName);\r
- if (presetHandler.Add(parsed.PresetName + " (Imported)",\r
- QueryGenerator.GenerateFullQuery(this),\r
- parsed.UsesPictureSettings))\r
+\r
+ Preset preset = new Preset\r
+ {\r
+ Name = parsed.PresetName + " (Imported)",\r
+ Query = QueryGenerator.GenerateFullQuery(this),\r
+ CropSettings = parsed.UsesPictureSettings\r
+ };\r
+\r
+ if (presetHandler.Add(preset))\r
{\r
TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")\r
{\r
if (result == DialogResult.Yes)\r
{\r
// Pause The Queue\r
- encodeQueue.Pause();\r
+ this.queueProcessor.Pause();\r
\r
if (Settings.Default.showCliForInGuiEncodeStatus)\r
- encodeQueue.SafelyClose();\r
+ this.queueProcessor.EncodeService.SafelyStop();\r
else\r
- encodeQueue.Stop();\r
+ this.queueProcessor.EncodeService.Stop();\r
}\r
}\r
else\r
string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath;\r
string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text;\r
\r
- if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))\r
+ if (this.queueProcessor.QueueManager.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))\r
{\r
string generatedQuery = QueryGenerator.GenerateFullQuery(this);\r
string specifiedQuery = rtf_query.Text != string.Empty\r
\r
if (overwrite == DialogResult.Yes)\r
{\r
- if (encodeQueue.Count == 0)\r
- encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
+ QueueTask task = new QueueTask(query)\r
+ {\r
+ Title = this.GetTitle(),\r
+ Source = jobSourcePath,\r
+ Destination = jobDestination,\r
+ CustomQuery = (this.rtf_query.Text != string.Empty)\r
+ };\r
+\r
+ if (this.queueProcessor.QueueManager.Count == 0)\r
+ this.queueProcessor.QueueManager.Add(task);\r
\r
queueWindow.SetQueue();\r
- if (encodeQueue.Count > 1)\r
+ if (this.queueProcessor.QueueManager.Count > 1)\r
queueWindow.Show(false);\r
\r
SetEncodeStarted(); // Encode is running, so setup the GUI appropriately\r
- encodeQueue.Start(); // Start The Queue Encoding Process\r
+ this.queueProcessor.Start(); // Start The Queue Encoding Process\r
}\r
\r
this.Focus();\r
/// </param>\r
private void btn_add2Queue_Click(object sender, EventArgs e)\r
{\r
- // Get the CLI query or use the query editor if it's not empty.\r
+ // Add the item to the queue.\r
+ AddItemToQueue(true);\r
+ queueWindow.Show();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Add Multiple Items to the Queue at once.\r
+ /// </summary>\r
+ /// <param name="sender">The Sender</param>\r
+ /// <param name="e">The EventArgs</param>\r
+ private void MnuAddMultiToQueueClick(object sender, EventArgs e)\r
+ {\r
+ if (!Settings.Default.autoNaming)\r
+ {\r
+ MessageBox.Show("Destination Auto Naming must be enabled in preferences for this feature to work.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ return;\r
+ }\r
+\r
+ if (this.SourceScan.SouceData == null)\r
+ {\r
+ MessageBox.Show("You must first scan a source or collection of source to use this feature.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ return;\r
+ }\r
+\r
+ BatchAdd batchAdd = new BatchAdd();\r
+ if (batchAdd.ShowDialog() == DialogResult.OK)\r
+ {\r
+ int min = batchAdd.Min;\r
+ int max = batchAdd.Max;\r
+ bool errors = false;\r
+\r
+ foreach (Title title in this.SourceScan.SouceData.Titles)\r
+ {\r
+ if (title.Duration.TotalMinutes > min && title.Duration.TotalMinutes < max)\r
+ {\r
+ // Add to Queue\r
+ this.drp_dvdtitle.SelectedItem = title;\r
+\r
+ if (!this.AddItemToQueue(false))\r
+ {\r
+ errors = true;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (errors)\r
+ {\r
+ MessageBox.Show(\r
+ "One or more items could not be added to the queue. You should check your queue and manually add any missing jobs.",\r
+ "Warning",\r
+ MessageBoxButtons.OK,\r
+ MessageBoxIcon.Warning);\r
+ }\r
+ }\r
+ }\r
+\r
+ private bool AddItemToQueue(bool showError)\r
+ {\r
string query = QueryGenerator.GenerateFullQuery(this);\r
if (!string.IsNullOrEmpty(rtf_query.Text))\r
query = rtf_query.Text;\r
// Make sure we have a Source and Destination.\r
if (string.IsNullOrEmpty(jobSourcePath) || string.IsNullOrEmpty(jobDestination))\r
{\r
- MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
- return;\r
+ if (showError)\r
+ MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return false;\r
}\r
\r
// Make sure the destination path exists.\r
if (!Directory.Exists(Path.GetDirectoryName(jobDestination)))\r
{\r
- MessageBox.Show(string.Format("Destination Path does not exist.\nPath: {0}\n\nThis item was not added to the Queue.", Path.GetDirectoryName(jobDestination)), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
- return;\r
+ if (showError)\r
+ MessageBox.Show(string.Format("Destination Path does not exist.\nPath: {0}\n\nThis item was not added to the Queue.", Path.GetDirectoryName(jobDestination)), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return false;\r
}\r
\r
// Make sure we don't have a duplciate on the queue.\r
- if (encodeQueue.CheckForDestinationDuplicate(jobDestination))\r
+ if (this.queueProcessor.QueueManager.CheckForDestinationPathDuplicates(jobDestination))\r
{\r
- DialogResult result =\r
- MessageBox.Show(\r
- string.Format("There is already a queue item for this destination path.\nDestination Path: {0} \n\nIf you continue, the encode will be overwritten. Do you wish to continue?", jobDestination),\r
- "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);\r
- if (result == DialogResult.Yes)\r
- encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
+ if (showError)\r
+ {\r
+ DialogResult result;\r
+ result =\r
+ MessageBox.Show(\r
+ string.Format(\r
+ "There is already a queue item for this destination path.\nDestination Path: {0} \n\nIf you continue, the encode will be overwritten. Do you wish to continue?",\r
+ jobDestination),\r
+ "Warning",\r
+ MessageBoxButtons.YesNo,\r
+ MessageBoxIcon.Warning);\r
+\r
+ if (result != DialogResult.Yes) return false;\r
+ }\r
+ else\r
+ {\r
+ return false;\r
+ }\r
}\r
- else\r
- encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty));\r
\r
- lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue";\r
+ // Add the job.\r
+ QueueTask task = new QueueTask(query)\r
+ {\r
+ Title = this.GetTitle(),\r
+ Source = jobSourcePath,\r
+ Destination = jobDestination,\r
+ CustomQuery = (this.rtf_query.Text != string.Empty)\r
+ };\r
+ this.queueProcessor.QueueManager.Add(task);\r
\r
- queueWindow.Show();\r
+ lbl_encode.Text = this.queueProcessor.QueueManager.Count + " encode(s) pending in the queue";\r
+\r
+ return true;\r
}\r
\r
/// <summary>\r
private void btn_ActivityWindow_Click(object sender, EventArgs e)\r
{\r
if (this.activityWindow == null || !this.activityWindow.IsHandleCreated)\r
- this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan);\r
+ this.activityWindow = new frmActivityWindow(this.queueProcessor.EncodeService, SourceScan);\r
\r
this.activityWindow.Show();\r
this.activityWindow.Activate();\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(selectedTitle, data_chpt, drop_chapterFinish.Text);\r
if (chapterGridView != null)\r
data_chpt = chapterGridView;\r
}\r
switch (DVD_Save.FilterIndex)\r
{\r
case 1:\r
- if (\r
- !Path.GetExtension(DVD_Save.FileName).Equals(".mp4",\r
- StringComparison.InvariantCultureIgnoreCase))\r
- if (Properties.Settings.Default.useM4v)\r
+ if (!Path.GetExtension(DVD_Save.FileName).Equals(".mp4", StringComparison.InvariantCultureIgnoreCase))\r
+ if (Properties.Settings.Default.useM4v == 2 || Properties.Settings.Default.useM4v == 0)\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
+ 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
switch (drop_format.SelectedIndex)\r
{\r
case 0:\r
- if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked ||\r
- AudioSettings.RequiresM4V() || Subtitles.RequiresM4V())\r
- SetExtension(".m4v");\r
- else\r
- SetExtension(".mp4");\r
+ SetExtension(".mp4");\r
break;\r
case 1:\r
SetExtension(".mkv");\r
public void SetExtension(string newExtension)\r
{\r
if (newExtension == ".mp4" || newExtension == ".m4v")\r
- if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() ||\r
- Subtitles.RequiresM4V())\r
- newExtension = ".m4v";\r
+ if (Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() || Subtitles.RequiresM4V() || Properties.Settings.Default.useM4v == 2) \r
+ newExtension = Properties.Settings.Default.useM4v == 1 ? ".mp4" : ".m4v";\r
else\r
newExtension = ".mp4";\r
\r
double rfValue = 51.0 - slider_videoQuality.Value * cqStep;\r
rfValue = Math.Round(rfValue, 2);\r
lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US"));\r
+ this.lbl_rfwarn.Visible = rfValue == 0;\r
break;\r
case "VP3 (Theora)":\r
lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value;\r
}\r
}\r
\r
- private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e)\r
- {\r
- text_bitrate.Enabled = false;\r
- text_filesize.Enabled = true;\r
- slider_videoQuality.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
- text_filesize.Enabled = false;\r
slider_videoQuality.Enabled = false;\r
\r
check_2PassEncode.Enabled = true;\r
private void radio_cq_CheckedChanged(object sender, EventArgs e)\r
{\r
text_bitrate.Enabled = false;\r
- text_filesize.Enabled = false;\r
slider_videoQuality.Enabled = true;\r
\r
check_2PassEncode.Enabled = false;\r
}\r
else\r
{\r
- if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v)\r
+ if (drop_format.SelectedIndex != 1)\r
SetExtension(".mp4");\r
data_chpt.Enabled = false;\r
btn_importChapters.Enabled = false;\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(selectedTitle, data_chpt, drop_chapterFinish.Text);\r
if (chapterGridView != null)\r
{\r
data_chpt = chapterGridView;\r
try\r
{\r
SourceScan.Scan(sourcePath, title);\r
- SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);\r
- SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);\r
}\r
catch (Exception exc)\r
{\r
/// <param name="e">\r
/// The e.\r
/// </param>\r
- private void SourceScan_ScanStatusChanged(object sender, EventArgs e)\r
+ private void SourceScanScanStatusChanged(object sender, ScanProgressEventArgs e)\r
{\r
- UpdateScanStatusLabel();\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(new ScanProgessStatus(this.SourceScanScanStatusChanged), new[] { sender, e });\r
+ return;\r
+ }\r
+\r
+ labelSource.Text = string.Format("Processing Title: {0} of {1}", e.CurrentTitle, e.Titles);\r
}\r
\r
/// <summary>\r
/// <param name="e">\r
/// The e.\r
/// </param>\r
- private void SourceScan_ScanCompleted(object sender, EventArgs e)\r
- {\r
- UpdateGuiAfterScan();\r
- }\r
-\r
- /// <summary>\r
- /// Update the Scan Status Label\r
- /// </summary>\r
- private void UpdateScanStatusLabel()\r
+ private void SourceScanScanCompleted(object sender, EventArgs e)\r
{\r
- if (InvokeRequired)\r
- {\r
- BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));\r
- return;\r
- }\r
- labelSource.Text = SourceScan.ScanStatus;\r
- }\r
-\r
- /// <summary>\r
- /// Reset the GUI when the scan has completed\r
- /// </summary>\r
- private void UpdateGuiAfterScan()\r
- {\r
- if (InvokeRequired)\r
+ if (this.InvokeRequired)\r
{\r
- BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));\r
+ this.BeginInvoke(new ScanCompletedStatus(this.SourceScanScanCompleted), new[] { sender, e });\r
return;\r
}\r
\r
}\r
UpdateSourceLabel();\r
\r
+ // This is a bit of a hack to fix the queue editing.\r
+ // If afte the scan, we find a job sitting in queueEdit, then the user has rescaned the source from the queue by clicking edit.\r
+ // When this occures, we want to repopulate their old settings.\r
+ if (queueEdit != null)\r
+ {\r
+ // Setup UI\r
+ if (queueEdit.Query != null)\r
+ {\r
+ // Send the query from the file to the Query Parser class\r
+ EncodeTask presetQuery = QueryParserUtility.Parse(queueEdit.Query);\r
+\r
+ // Now load the preset\r
+ PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue");\r
+\r
+ // Set the destination path\r
+ this.text_destination.Text = queueEdit.Destination;\r
+\r
+ // The x264 widgets will need updated, so do this now:\r
+ x264Panel.StandardizeOptString();\r
+ x264Panel.SetCurrentSettingsInPanel();\r
+\r
+ // Set the crop label\r
+ PictureSettings.SetPresetCropWarningLabel(null);\r
+ }\r
+\r
+ queueEdit = null;\r
+ }\r
+\r
// Enable the GUI components and enable any disabled components\r
EnableGUI();\r
}\r
/// </summary>\r
private void KillScan()\r
{\r
- SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
+ SourceScan.ScanCompleted -= this.SourceScanScanCompleted;\r
EnableGUI();\r
ResetGUI();\r
\r
/// <param name="job">\r
/// The job.\r
/// </param>\r
- public void RecievingJob(Job job)\r
+ public void RecievingJob(QueueTask 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");\r
-\r
- // The x264 widgets will need updated, so do this now:\r
- x264Panel.StandardizeOptString();\r
- x264Panel.SetCurrentSettingsInPanel();\r
+ // Reset\r
+ this.currentlySelectedPreset = null;\r
+ x264Panel.Reset2Defaults();\r
\r
- // Finally, let this window have a copy of the preset settings.\r
- this.currentlySelectedPreset = null;\r
- PictureSettings.SetPresetCropWarningLabel(null);\r
- }\r
+ // Scan\r
+ queueEdit = job; // Nasty but will do for now. TODO\r
+ StartScan(job.Source, job.Title);\r
}\r
\r
#endregion\r
lbl_encode.Visible = true;\r
ProgressBarStatus.Value = 0;\r
ProgressBarStatus.Visible = true;\r
- lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending";\r
+ lbl_encode.Text = "Encoding with " + this.queueProcessor.QueueManager.Count + " encode(s) pending";\r
btn_start.Text = "Stop";\r
btn_start.ToolTipText = "Stop the encoding process.";\r
btn_start.Image = Properties.Resources.stop;\r
/// <param name="e">\r
/// The e.\r
/// </param>\r
- private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e)\r
+ private void EncodeQueue_EncodeStatusChanged(object sender, EncodeProgressEventArgs e)\r
{\r
if (this.InvokeRequired)\r
{\r
- this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });\r
+ this.BeginInvoke(new EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e });\r
return;\r
}\r
\r
e.CurrentFrameRate,\r
e.AverageFrameRate,\r
e.EstimatedTimeLeft,\r
- encodeQueue.Count);\r
+ this.queueProcessor.QueueManager.Count);\r
\r
ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete);\r
}\r
return;\r
}\r
\r
- drives = Main.GetDrives();\r
+ drives = UtilityService.GetDrives();\r
\r
List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();\r
foreach (DriveInformation drive in drives)\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
+ // Clear the old presets\r
+ treeView_presets.Nodes.Clear();\r
+\r
+\r
+ string category = string.Empty; // The category we are currnetly processing\r
+ TreeNode rootNode = null;\r
+ foreach (Preset preset in this.presetHandler.Presets.Where(p => p.IsBuildIn))\r
+ {\r
+ // If the category of this preset doesn't match the current category we are processing\r
+ // Then we need to create a new root node.\r
+ if (preset.Category != category)\r
+ {\r
+ rootNode = new TreeNode(preset.Category) { ForeColor = Color.DarkBlue };\r
+ treeView_presets.Nodes.Add(rootNode);\r
+ category = preset.Category;\r
+ }\r
+\r
+ if (preset.Category == category && rootNode != null)\r
+ rootNode.Nodes.Add(new TreeNode(preset.Name) { ToolTipText = preset.Description, ForeColor = Color.DarkBlue });\r
+ }\r
+\r
+ rootNode = null;\r
+ category = null;\r
+ foreach (Preset preset in this.presetHandler.Presets.Where(p => !p.IsBuildIn)) // User Presets\r
+ {\r
+ if (preset.Category != category && preset.Category != string.Empty)\r
+ {\r
+ rootNode = new TreeNode(preset.Category) { ForeColor = Color.Black };\r
+ treeView_presets.Nodes.Add(rootNode);\r
+ category = preset.Category;\r
+ }\r
+\r
+ if (preset.Category == category && rootNode != null)\r
+ rootNode.Nodes.Add(new TreeNode(preset.Name) { ForeColor = Color.Black, ToolTipText = preset.Description });\r
+ else\r
+ treeView_presets.Nodes.Add(new TreeNode(preset.Name) { ForeColor = Color.Black, ToolTipText = preset.Description });\r
+ }\r
+\r
treeView_presets.Update();\r
}\r
\r
try\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)\r
+ if (this.queueProcessor.EncodeService.IsEncoding)\r
{\r
DialogResult result =\r
MessageBox.Show(\r
return;\r
}\r
\r
- encodeQueue.Stop();\r
+ this.queueProcessor.Pause();\r
+ this.queueProcessor.EncodeService.Stop();\r
}\r
\r
if (SourceScan.IsScanning)\r
{\r
- SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);\r
SourceScan.Stop();\r
}\r
+\r
+ SourceScan.ScanCompleted -= this.SourceScanScanCompleted;\r
+ SourceScan.ScanStatusChanged -= this.SourceScanScanStatusChanged;\r
}\r
catch (Exception exc)\r
{\r