X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=win%2FC%23%2FfrmMain.cs;h=184af65a6413f6cc138321c0230796f727955fe9;hb=01adcc9f552746e1c6b4503c78d4c27891d68f68;hp=165da56d4242d5e9bf8ce5f0f2ce69b5b8970ae2;hpb=fafadbe3daf0e611a2c12e9d46c670f36e82c0ee;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 165da56d..184af65a 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -12,10 +12,16 @@ namespace Handbrake using System.Drawing; using System.Globalization; using System.IO; + using System.Linq; using System.Threading; using System.Windows.Forms; + + using DevExpress.Utils.Menu; + using Functions; + using HandBrake.ApplicationServices.EventArgs; + using HandBrake.ApplicationServices.Utilities; using HandBrake.Framework.Model; using HandBrake.Framework.Services; using HandBrake.Framework.Views; @@ -28,7 +34,6 @@ namespace Handbrake using Handbrake.ToolWindows; using Model; - using Presets; using Properties; using Main = Handbrake.Functions.Main; @@ -39,8 +44,8 @@ namespace Handbrake public partial class frmMain : Form { // Objects which may be used by one or more other objects ************* - private IQueue encodeQueue = new Queue(); - private PresetsHandler presetHandler = new PresetsHandler(); + private IQueueProcessor queueProcessor = new QueueProcessor(Program.InstanceId); + private PresetService presetHandler = new PresetService(); // Windows ************************************************************ private frmQueue queueWindow; @@ -54,9 +59,11 @@ namespace Handbrake private string dvdDrivePath; private string dvdDriveLabel; private Preset currentlySelectedPreset; - private DVD currentSource; - private IScan SourceScan = new ScanService(); + private Source currentSource; + + private IScan SourceScan; private List drives; + private QueueTask queueEdit; // Delegates ********************************************************** private delegate void UpdateWindowHandler(); @@ -82,6 +89,19 @@ namespace Handbrake return Path.GetFileName(selectedTitle.SourceName); } + // We have a drive, selected as a folder. + if (this.sourcePath.EndsWith("\\")) + { + drives = UtilityService.GetDrives(); + foreach (DriveInformation item in drives) + { + if (item.RootDirectory.Contains(this.sourcePath)) + { + return item.VolumeLabel; + } + } + } + if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS") return Path.GetFileNameWithoutExtension(this.sourcePath); @@ -102,6 +122,10 @@ namespace Handbrake public frmMain(string[] args) { InitializeComponent(); + this.presetsToolStrip.Renderer = new ToolStripRenderOverride(); + + // We can use LibHB, if the library hb.dll exists. + this.SourceScan = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService(); // Update the users config file with the CLI version data. Main.SetCliVersionData(); @@ -129,7 +153,7 @@ namespace Handbrake // Clear the log files in the background if (Settings.Default.clearOldLogs) { - Thread clearLog = new Thread(Main.ClearOldLogs); + Thread clearLog = new Thread(() => UtilityService.ClearLogFiles(30)); clearLog.Start(); } @@ -138,7 +162,7 @@ namespace Handbrake treeView_presets.ExpandAll(); lbl_encode.Text = string.Empty; drop_mode.SelectedIndex = 0; - queueWindow = new frmQueue(encodeQueue, this); // Prepare the Queue + queueWindow = new frmQueue(this.queueProcessor, this); // Prepare the Queue if (!Settings.Default.QueryEditorTab) tabs_panel.TabPages.RemoveAt(7); // Remove the query editor tab if the user does not want it enabled. if (Settings.Default.tooltipEnable) @@ -152,7 +176,7 @@ namespace Handbrake { x264Panel.Reset2Defaults(); - QueryParser presetQuery = QueryParser.Parse(query); + EncodeTask presetQuery = QueryParserUtility.Parse(query); PresetLoader.LoadPreset(this, presetQuery, Settings.Default.defaultPreset); x264Panel.StandardizeOptString(); @@ -167,7 +191,7 @@ namespace Handbrake // Event Handlers and Queue Recovery events(); - Main.RecoverQueue(encodeQueue); + Main.RecoverQueue(this.queueProcessor); // If have a file passed in via command arguemtents, check it's a file and try scanning it. if (args.Length >= 1 && (File.Exists(args[0]) || Directory.Exists(args[0]))) @@ -216,75 +240,77 @@ namespace Handbrake RegisterPresetEventHandler(); // Handle Window Resize - if (Properties.Settings.Default.MainWindowMinimize) - this.Resize += new EventHandler(frmMain_Resize); + if (Settings.Default.MainWindowMinimize) + this.Resize += this.frmMain_Resize; // Handle Encode Start / Finish / Pause - encodeQueue.EncodeStarted += new EventHandler(encodeStarted); - encodeQueue.EncodeEnded += new EventHandler(encodeEnded); + this.queueProcessor.EncodeService.EncodeStarted += this.encodeStarted; + this.queueProcessor.EncodeService.EncodeCompleted += encodeEnded; + + // Scan Started and Completed Events + SourceScan.ScanStatusChanged += this.SourceScanScanStatusChanged; + SourceScan.ScanCompleted += this.SourceScanScanCompleted; // Handle a file being draged onto the GUI. - this.DragEnter += new DragEventHandler(frmMain_DragEnter); - this.DragDrop += new DragEventHandler(frmMain_DragDrop); + this.DragEnter += frmMain_DragEnter; + this.DragDrop += this.frmMain_DragDrop; } // 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 private void RegisterPresetEventHandler() { // Output Settings - drop_format.SelectedIndexChanged += new EventHandler(changePresetLabel); - check_largeFile.CheckedChanged += new EventHandler(changePresetLabel); - check_iPodAtom.CheckedChanged += new EventHandler(changePresetLabel); - check_optimiseMP4.CheckedChanged += new EventHandler(changePresetLabel); + drop_format.SelectedIndexChanged += this.changePresetLabel; + check_largeFile.CheckedChanged += this.changePresetLabel; + check_iPodAtom.CheckedChanged += this.changePresetLabel; + check_optimiseMP4.CheckedChanged += this.changePresetLabel; // Picture Settings - PictureSettings.PictureSettingsChanged += new EventHandler(changePresetLabel); + PictureSettings.PictureSettingsChanged += this.changePresetLabel; // Filter Settings - Filters.FilterSettingsChanged += new EventHandler(changePresetLabel); + Filters.FilterSettingsChanged += this.changePresetLabel; // Video Tab - drp_videoEncoder.SelectedIndexChanged += new EventHandler(changePresetLabel); - check_2PassEncode.CheckedChanged += new EventHandler(changePresetLabel); - check_turbo.CheckedChanged += new EventHandler(changePresetLabel); - text_filesize.TextChanged += new EventHandler(changePresetLabel); - text_bitrate.TextChanged += new EventHandler(changePresetLabel); - slider_videoQuality.ValueChanged += new EventHandler(changePresetLabel); + drp_videoEncoder.SelectedIndexChanged += this.changePresetLabel; + check_2PassEncode.CheckedChanged += this.changePresetLabel; + check_turbo.CheckedChanged += this.changePresetLabel; + text_bitrate.TextChanged += this.changePresetLabel; + slider_videoQuality.ValueChanged += this.changePresetLabel; // Audio Panel - AudioSettings.AudioListChanged += new EventHandler(changePresetLabel); + AudioSettings.AudioListChanged += this.changePresetLabel; // Advanced Tab - x264Panel.rtf_x264Query.TextChanged += new EventHandler(changePresetLabel); + x264Panel.rtf_x264Query.TextChanged += this.changePresetLabel; } private void UnRegisterPresetEventHandler() { // Output Settings - drop_format.SelectedIndexChanged -= new EventHandler(changePresetLabel); - check_largeFile.CheckedChanged -= new EventHandler(changePresetLabel); - check_iPodAtom.CheckedChanged -= new EventHandler(changePresetLabel); - check_optimiseMP4.CheckedChanged -= new EventHandler(changePresetLabel); + drop_format.SelectedIndexChanged -= this.changePresetLabel; + check_largeFile.CheckedChanged -= this.changePresetLabel; + check_iPodAtom.CheckedChanged -= this.changePresetLabel; + check_optimiseMP4.CheckedChanged -= this.changePresetLabel; // Picture Settings - PictureSettings.PictureSettingsChanged -= new EventHandler(changePresetLabel); + PictureSettings.PictureSettingsChanged -= this.changePresetLabel; // Filter Settings - Filters.FilterSettingsChanged -= new EventHandler(changePresetLabel); + Filters.FilterSettingsChanged -= this.changePresetLabel; // Video Tab - drp_videoEncoder.SelectedIndexChanged -= new EventHandler(changePresetLabel); - check_2PassEncode.CheckedChanged -= new EventHandler(changePresetLabel); - check_turbo.CheckedChanged -= new EventHandler(changePresetLabel); - text_filesize.TextChanged -= new EventHandler(changePresetLabel); - text_bitrate.TextChanged -= new EventHandler(changePresetLabel); - slider_videoQuality.ValueChanged -= new EventHandler(changePresetLabel); + drp_videoEncoder.SelectedIndexChanged -= this.changePresetLabel; + check_2PassEncode.CheckedChanged -= this.changePresetLabel; + check_turbo.CheckedChanged -= this.changePresetLabel; + text_bitrate.TextChanged -= this.changePresetLabel; + slider_videoQuality.ValueChanged -= this.changePresetLabel; // Audio Panel - AudioSettings.AudioListChanged -= new EventHandler(changePresetLabel); + AudioSettings.AudioListChanged -= this.changePresetLabel; // Advanced Tab - x264Panel.rtf_x264Query.TextChanged -= new EventHandler(changePresetLabel); + x264Panel.rtf_x264Query.TextChanged -= this.changePresetLabel; } private void changePresetLabel(object sender, EventArgs e) @@ -321,12 +347,12 @@ namespace Handbrake private void encodeStarted(object sender, EventArgs e) { SetEncodeStarted(); - encodeQueue.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged; + this.queueProcessor.EncodeService.EncodeStatusChanged += EncodeQueue_EncodeStatusChanged; } private void encodeEnded(object sender, EventArgs e) { - encodeQueue.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged; + this.queueProcessor.EncodeService.EncodeStatusChanged -= EncodeQueue_EncodeStatusChanged; SetEncodeFinished(); } #endregion @@ -412,136 +438,24 @@ namespace Handbrake #endregion - #region Presets Menu - - /// - /// Reset the Built in Presets - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void mnu_presetReset_Click(object sender, EventArgs e) - { - presetHandler.UpdateBuiltInPresets(); - LoadPresetPanel(); - if (treeView_presets.Nodes.Count == 0) - 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); - else - MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); - - treeView_presets.ExpandAll(); - } - - /// - /// Delete the selected preset - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void mnu_delete_preset_Click(object sender, EventArgs e) - { - presetHandler.RemoveBuiltInPresets(); - LoadPresetPanel(); // Reload the preset panel - } - - /// - /// Select the Normal preset - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void mnu_SelectDefault_Click(object sender, EventArgs e) - { - loadNormalPreset(); - } - - /// - /// Import a plist Preset - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void mnu_importMacPreset_Click(object sender, EventArgs e) - { - ImportPreset(); - } - - /// - /// Export a Plist Preset - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void mnu_exportMacPreset_Click(object sender, EventArgs e) - { - ExportPreset(); - } - - /// - /// Create a new Preset - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void btn_new_preset_Click(object sender, EventArgs e) - { - Form preset = new frmAddPreset(this, presetHandler); - if (preset.ShowDialog() == DialogResult.OK) - { - TreeNode presetTreeview = new TreeNode(presetHandler.LastPresetAdded.Name) { ForeColor = Color.Black }; - treeView_presets.Nodes.Add(presetTreeview); - presetHandler.LastPresetAdded = null; - } - } - - #endregion - - #region Help Menu + #region Help Menu (Toolbar) /// - /// Menu - Display the User Guide Web Page + /// Menu - Display the User Guide Web Page /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void mnu_user_guide_Click(object sender, EventArgs e) + /// The Sender + /// The EventArgs + private void MnuUserGuide_Click(object sender, EventArgs e) { Process.Start("http://trac.handbrake.fr/wiki/HandBrakeGuide"); } /// - /// Menu - Check for Updates + /// Check for Updates /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void mnu_UpdateCheck_Click(object sender, EventArgs e) + /// The Sender + /// The EventArgs + private void MnuCheckForUpdates_Click(object sender, EventArgs e) { lbl_updateCheck.Visible = true; Settings.Default.lastUpdateCheckDate = DateTime.Now; @@ -555,13 +469,9 @@ namespace Handbrake /// /// Menu - Display the About Window /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void mnu_about_Click(object sender, EventArgs e) + /// The Sender + /// The EventArgs + private void MnuAboutHandBrake_Click(object sender, EventArgs e) { using (frmAbout About = new frmAbout()) { @@ -626,18 +536,21 @@ namespace Handbrake /// private void pmnu_saveChanges_Click(object sender, EventArgs e) { - // TODO this requires a re-think since the Query Editor has changed. 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); - if (result == DialogResult.Yes) - presetHandler.Update(treeView_presets.SelectedNode.Text, - QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true); - else if (result == DialogResult.No) - presetHandler.Update(treeView_presets.SelectedNode.Text, - QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false); + + Preset preset = new Preset + { + Name = this.treeView_presets.SelectedNode.Text, + Query = + QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), + CropSettings = (result == DialogResult.Yes) + }; + + presetHandler.Update(preset); } /// @@ -653,7 +566,7 @@ namespace Handbrake { if (treeView_presets.SelectedNode != null) { - presetHandler.Remove(treeView_presets.SelectedNode.Text); + presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag); treeView_presets.Nodes.Remove(treeView_presets.SelectedNode); } treeView_presets.Select(); @@ -675,7 +588,7 @@ namespace Handbrake // Now enable the save menu if the selected preset is a user preset if (treeView_presets.SelectedNode != null) - if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text)) + if (presetHandler.CheckIfPresetExists(treeView_presets.SelectedNode.Text)) pmnu_saveChanges.Enabled = true; treeView_presets.Select(); @@ -683,16 +596,7 @@ namespace Handbrake // Presets Management - /// - /// Button - Add a preset - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void btn_addPreset_Click(object sender, EventArgs e) + private void BtnAddPreset_Click(object sender, EventArgs e) { Form preset = new frmAddPreset(this, presetHandler); if (preset.ShowDialog() == DialogResult.OK) @@ -703,16 +607,7 @@ namespace Handbrake } } - /// - /// Button - remove a Preset - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void btn_removePreset_Click(object sender, EventArgs e) + private void BtnRemovePreset_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question); @@ -720,23 +615,15 @@ namespace Handbrake { if (treeView_presets.SelectedNode != null) { - presetHandler.Remove(treeView_presets.SelectedNode.Text); + presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag); treeView_presets.Nodes.Remove(treeView_presets.SelectedNode); } } treeView_presets.Select(); } - /// - /// Button - Set the selected preset as the default - /// - /// - /// The sender. - /// - /// - /// The e. - /// - private void btn_setDefault_Click(object sender, EventArgs e) + + private void MnuSetDefaultPreset_Click(object sender, EventArgs e) { if (treeView_presets.SelectedNode != null) { @@ -753,6 +640,30 @@ namespace Handbrake MessageBox.Show("Please select a preset first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } + private void MnuImportPreset_Click(object sender, EventArgs e) + { + this.ImportPreset(); + } + + private void MnuExportPreset_Click(object sender, EventArgs e) + { + this.ExportPreset(); + } + + private void MnuResetBuiltInPresets_Click(object sender, EventArgs e) + { + presetHandler.UpdateBuiltInPresets(string.Empty); + LoadPresetPanel(); + if (treeView_presets.Nodes.Count == 0) + 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); + else + MessageBox.Show("Presets have been updated!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information); + + treeView_presets.ExpandAll(); + } + /// /// PresetBar Mouse Down event /// @@ -793,6 +704,29 @@ namespace Handbrake } /// + /// When the mouse moves, display a preset + /// + /// The Sender + /// the MouseEventArgs + private void TreeViewPresetsMouseMove(object sender, MouseEventArgs e) + { + TreeNode theNode = this.treeView_presets.GetNodeAt(e.X, e.Y); + + if ((theNode != null)) + { + // Change the ToolTip only if the pointer moved to a new node. + if (theNode.ToolTipText != this.ToolTip.GetToolTip(this.treeView_presets)) + { + this.ToolTip.SetToolTip(this.treeView_presets, theNode.ToolTipText); + } + } + else // Pointer is not over a node so clear the ToolTip. + { + this.ToolTip.SetToolTip(this.treeView_presets, string.Empty); + } + } + + /// /// Preset Bar - Handle the Delete Key /// /// @@ -810,7 +744,7 @@ namespace Handbrake if (result == DialogResult.Yes) { if (treeView_presets.SelectedNode != null) - presetHandler.Remove(treeView_presets.SelectedNode.Text); + presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag); // Remember each nodes expanded status so we can reload it List nodeStatus = new List(); @@ -853,7 +787,7 @@ namespace Handbrake x264Panel.Reset2Defaults(); // Send the query from the file to the Query Parser class - QueryParser presetQuery = QueryParser.Parse(query); + EncodeTask presetQuery = QueryParserUtility.Parse(query); // Now load the preset PresetLoader.LoadPreset(this, presetQuery, presetName); @@ -892,8 +826,8 @@ namespace Handbrake { if (openPreset.ShowDialog() == DialogResult.OK) { - QueryParser parsed = PlistPresetHandler.Import(openPreset.FileName); - if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)")) + EncodeTask parsed = PlistPresetHandler.Import(openPreset.FileName); + if (presetHandler.CheckIfPresetExists(parsed.PresetName + " (Imported)")) { DialogResult result = MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?", @@ -902,17 +836,29 @@ namespace Handbrake if (result == DialogResult.Yes) { PresetLoader.LoadPreset(this, parsed, parsed.PresetName); - presetHandler.Update(parsed.PresetName + " (Imported)", - QueryGenerator.GenerateFullQuery(this), - parsed.UsesPictureSettings); + + Preset preset = new Preset + { + Name = parsed.PresetName + " (Imported)", + Query = QueryGenerator.GenerateFullQuery(this), + CropSettings = parsed.UsesPictureSettings + }; + + presetHandler.Update(preset); } } else { PresetLoader.LoadPreset(this, parsed, parsed.PresetName); - if (presetHandler.Add(parsed.PresetName + " (Imported)", - QueryGenerator.GenerateFullQuery(this), - parsed.UsesPictureSettings)) + + Preset preset = new Preset + { + Name = parsed.PresetName + " (Imported)", + Query = QueryGenerator.GenerateFullQuery(this), + CropSettings = parsed.UsesPictureSettings + }; + + if (presetHandler.Add(preset)) { TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)") { @@ -1005,12 +951,12 @@ namespace Handbrake if (result == DialogResult.Yes) { // Pause The Queue - encodeQueue.Pause(); + this.queueProcessor.Pause(); if (Settings.Default.showCliForInGuiEncodeStatus) - encodeQueue.SafelyClose(); + this.queueProcessor.EncodeService.SafelyStop(); else - encodeQueue.Stop(); + this.queueProcessor.EncodeService.Stop(); } } else @@ -1019,7 +965,7 @@ namespace Handbrake string jobSourcePath = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetSourceFromQuery(rtf_query.Text) : sourcePath; string jobDestination = !string.IsNullOrEmpty(rtf_query.Text) ? Main.GetDestinationFromQuery(rtf_query.Text) : text_destination.Text; - if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination))) + if (this.queueProcessor.QueueManager.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination))) { string generatedQuery = QueryGenerator.GenerateFullQuery(this); string specifiedQuery = rtf_query.Text != string.Empty @@ -1074,15 +1020,23 @@ namespace Handbrake if (overwrite == DialogResult.Yes) { - if (encodeQueue.Count == 0) - encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty)); + QueueTask task = new QueueTask(query) + { + Title = this.GetTitle(), + Source = jobSourcePath, + Destination = jobDestination, + CustomQuery = (this.rtf_query.Text != string.Empty) + }; + + if (this.queueProcessor.QueueManager.Count == 0) + this.queueProcessor.QueueManager.Add(task); queueWindow.SetQueue(); - if (encodeQueue.Count > 1) + if (this.queueProcessor.QueueManager.Count > 1) queueWindow.Show(false); SetEncodeStarted(); // Encode is running, so setup the GUI appropriately - encodeQueue.Start(); // Start The Queue Encoding Process + this.queueProcessor.Start(); // Start The Queue Encoding Process } this.Focus(); @@ -1104,7 +1058,64 @@ namespace Handbrake /// private void btn_add2Queue_Click(object sender, EventArgs e) { - // Get the CLI query or use the query editor if it's not empty. + // Add the item to the queue. + AddItemToQueue(true); + queueWindow.Show(); + } + + /// + /// Add Multiple Items to the Queue at once. + /// + /// The Sender + /// The EventArgs + private void MnuAddMultiToQueueClick(object sender, EventArgs e) + { + if (!Settings.Default.autoNaming) + { + MessageBox.Show("Destination Auto Naming must be enabled in preferences for this feature to work.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (this.SourceScan.SouceData == null) + { + MessageBox.Show("You must first scan a source or collection of source to use this feature.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + BatchAdd batchAdd = new BatchAdd(); + if (batchAdd.ShowDialog() == DialogResult.OK) + { + int min = batchAdd.Min; + int max = batchAdd.Max; + bool errors = false; + + foreach (Title title in this.SourceScan.SouceData.Titles) + { + if (title.Duration.TotalMinutes > min && title.Duration.TotalMinutes < max) + { + // Add to Queue + this.drp_dvdtitle.SelectedItem = title; + + if (!this.AddItemToQueue(false)) + { + errors = true; + } + } + } + + if (errors) + { + MessageBox.Show( + "One or more items could not be added to the queue. You should check your queue and manually add any missing jobs.", + "Warning", + MessageBoxButtons.OK, + MessageBoxIcon.Warning); + } + } + } + + private bool AddItemToQueue(bool showError) + { string query = QueryGenerator.GenerateFullQuery(this); if (!string.IsNullOrEmpty(rtf_query.Text)) query = rtf_query.Text; @@ -1116,33 +1127,55 @@ namespace Handbrake // Make sure we have a Source and Destination. if (string.IsNullOrEmpty(jobSourcePath) || string.IsNullOrEmpty(jobDestination)) { - MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; + if (showError) + MessageBox.Show("No source or destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return false; } // Make sure the destination path exists. if (!Directory.Exists(Path.GetDirectoryName(jobDestination))) { - 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); - return; + if (showError) + 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); + return false; } // Make sure we don't have a duplciate on the queue. - if (encodeQueue.CheckForDestinationDuplicate(jobDestination)) + if (this.queueProcessor.QueueManager.CheckForDestinationPathDuplicates(jobDestination)) { - DialogResult result = - MessageBox.Show( - 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), - "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); - if (result == DialogResult.Yes) - encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty)); + if (showError) + { + DialogResult result; + result = + MessageBox.Show( + 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), + "Warning", + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning); + + if (result != DialogResult.Yes) return false; + } + else + { + return false; + } } - else - encodeQueue.Add(query, this.GetTitle(), jobSourcePath, jobDestination, (rtf_query.Text != string.Empty)); - lbl_encode.Text = encodeQueue.Count + " encode(s) pending in the queue"; + // Add the job. + QueueTask task = new QueueTask(query) + { + Title = this.GetTitle(), + Source = jobSourcePath, + Destination = jobDestination, + CustomQuery = (this.rtf_query.Text != string.Empty) + }; + this.queueProcessor.QueueManager.Add(task); - queueWindow.Show(); + lbl_encode.Text = this.queueProcessor.QueueManager.Count + " encode(s) pending in the queue"; + + return true; } /// @@ -1204,7 +1237,7 @@ namespace Handbrake private void btn_ActivityWindow_Click(object sender, EventArgs e) { if (this.activityWindow == null || !this.activityWindow.IsHandleCreated) - this.activityWindow = new frmActivityWindow(encodeQueue, SourceScan); + this.activityWindow = new frmActivityWindow(this.queueProcessor.EncodeService, SourceScan); this.activityWindow.Show(); this.activityWindow.Activate(); @@ -1457,7 +1490,7 @@ namespace Handbrake data_chpt.Rows.Clear(); if (selectedTitle.Chapters.Count != 1) { - DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text); + DataGridView chapterGridView = Main.ChapterNaming(selectedTitle, data_chpt, drop_chapterFinish.Text); if (chapterGridView != null) data_chpt = chapterGridView; } @@ -1640,17 +1673,14 @@ namespace Handbrake switch (DVD_Save.FilterIndex) { case 1: - if ( - !Path.GetExtension(DVD_Save.FileName).Equals(".mp4", - StringComparison.InvariantCultureIgnoreCase)) - if (Properties.Settings.Default.useM4v) + if (!Path.GetExtension(DVD_Save.FileName).Equals(".mp4", StringComparison.InvariantCultureIgnoreCase)) + if (Properties.Settings.Default.useM4v == 2 || Properties.Settings.Default.useM4v == 0) DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".m4v").Replace(".mkv", ".m4v"); else DVD_Save.FileName = DVD_Save.FileName.Replace(".m4v", ".mp4").Replace(".mkv", ".mp4"); break; case 2: - if ( - !Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase)) + if (!Path.GetExtension(DVD_Save.FileName).Equals(".mkv", StringComparison.InvariantCultureIgnoreCase)) DVD_Save.FileName = DVD_Save.FileName.Replace(".mp4", ".mkv").Replace(".m4v", ".mkv"); break; default: @@ -1680,11 +1710,7 @@ namespace Handbrake switch (drop_format.SelectedIndex) { case 0: - if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || - AudioSettings.RequiresM4V() || Subtitles.RequiresM4V()) - SetExtension(".m4v"); - else - SetExtension(".mp4"); + SetExtension(".mp4"); break; case 1: SetExtension(".mkv"); @@ -1708,9 +1734,8 @@ namespace Handbrake public void SetExtension(string newExtension) { if (newExtension == ".mp4" || newExtension == ".m4v") - if (Properties.Settings.Default.useM4v || Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() || - Subtitles.RequiresM4V()) - newExtension = ".m4v"; + if (Check_ChapterMarkers.Checked || AudioSettings.RequiresM4V() || Subtitles.RequiresM4V() || Properties.Settings.Default.useM4v == 2) + newExtension = Properties.Settings.Default.useM4v == 1 ? ".mp4" : ".m4v"; else newExtension = ".mp4"; @@ -1864,6 +1889,7 @@ namespace Handbrake double rfValue = 51.0 - slider_videoQuality.Value * cqStep; rfValue = Math.Round(rfValue, 2); lbl_SliderValue.Text = "RF:" + rfValue.ToString(new CultureInfo("en-US")); + this.lbl_rfwarn.Visible = rfValue == 0; break; case "VP3 (Theora)": lbl_SliderValue.Text = "QP:" + slider_videoQuality.Value; @@ -1871,19 +1897,9 @@ namespace Handbrake } } - private void radio_targetFilesize_CheckedChanged(object sender, EventArgs e) - { - text_bitrate.Enabled = false; - text_filesize.Enabled = true; - slider_videoQuality.Enabled = false; - - check_2PassEncode.Enabled = true; - } - private void radio_avgBitrate_CheckedChanged(object sender, EventArgs e) { text_bitrate.Enabled = true; - text_filesize.Enabled = false; slider_videoQuality.Enabled = false; check_2PassEncode.Enabled = true; @@ -1892,7 +1908,6 @@ namespace Handbrake private void radio_cq_CheckedChanged(object sender, EventArgs e) { text_bitrate.Enabled = false; - text_filesize.Enabled = false; slider_videoQuality.Enabled = true; check_2PassEncode.Enabled = false; @@ -1925,7 +1940,7 @@ namespace Handbrake } else { - if (drop_format.SelectedIndex != 1 && !Properties.Settings.Default.useM4v) + if (drop_format.SelectedIndex != 1) SetExtension(".mp4"); data_chpt.Enabled = false; btn_importChapters.Enabled = false; @@ -1959,7 +1974,7 @@ namespace Handbrake private void mnu_resetChapters_Click(object sender, EventArgs e) { data_chpt.Rows.Clear(); - DataGridView chapterGridView = Main.ChapterNaming(data_chpt, drop_chapterFinish.Text); + DataGridView chapterGridView = Main.ChapterNaming(selectedTitle, data_chpt, drop_chapterFinish.Text); if (chapterGridView != null) { data_chpt = chapterGridView; @@ -2003,8 +2018,6 @@ namespace Handbrake try { SourceScan.Scan(sourcePath, title); - SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged); - SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted); } catch (Exception exc) { @@ -2021,9 +2034,15 @@ namespace Handbrake /// /// The e. /// - private void SourceScan_ScanStatusChanged(object sender, EventArgs e) + private void SourceScanScanStatusChanged(object sender, ScanProgressEventArgs e) { - UpdateScanStatusLabel(); + if (this.InvokeRequired) + { + this.BeginInvoke(new ScanProgessStatus(this.SourceScanScanStatusChanged), new[] { sender, e }); + return; + } + + labelSource.Text = string.Format("Processing Title: {0} of {1}", e.CurrentTitle, e.Titles); } /// @@ -2035,32 +2054,11 @@ namespace Handbrake /// /// The e. /// - private void SourceScan_ScanCompleted(object sender, EventArgs e) - { - UpdateGuiAfterScan(); - } - - /// - /// Update the Scan Status Label - /// - private void UpdateScanStatusLabel() + private void SourceScanScanCompleted(object sender, EventArgs e) { - if (InvokeRequired) - { - BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel)); - return; - } - labelSource.Text = SourceScan.ScanStatus; - } - - /// - /// Reset the GUI when the scan has completed - /// - private void UpdateGuiAfterScan() - { - if (InvokeRequired) + if (this.InvokeRequired) { - BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan)); + this.BeginInvoke(new ScanCompletedStatus(this.SourceScanScanCompleted), new[] { sender, e }); return; } @@ -2111,6 +2109,34 @@ namespace Handbrake } UpdateSourceLabel(); + // This is a bit of a hack to fix the queue editing. + // If afte the scan, we find a job sitting in queueEdit, then the user has rescaned the source from the queue by clicking edit. + // When this occures, we want to repopulate their old settings. + if (queueEdit != null) + { + // Setup UI + if (queueEdit.Query != null) + { + // Send the query from the file to the Query Parser class + EncodeTask presetQuery = QueryParserUtility.Parse(queueEdit.Query); + + // Now load the preset + PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue"); + + // Set the destination path + this.text_destination.Text = queueEdit.Destination; + + // The x264 widgets will need updated, so do this now: + x264Panel.StandardizeOptString(); + x264Panel.SetCurrentSettingsInPanel(); + + // Set the crop label + PictureSettings.SetPresetCropWarningLabel(null); + } + + queueEdit = null; + } + // Enable the GUI components and enable any disabled components EnableGUI(); } @@ -2171,7 +2197,7 @@ namespace Handbrake /// private void KillScan() { - SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted); + SourceScan.ScanCompleted -= this.SourceScanScanCompleted; EnableGUI(); ResetGUI(); @@ -2209,30 +2235,15 @@ namespace Handbrake /// /// The job. /// - public void RecievingJob(Job job) + public void RecievingJob(QueueTask job) { - string query = job.Query; - StartScan(job.Source, job.Title); - - if (query != null) - { - // Ok, Reset all the H264 widgets before changing the preset - x264Panel.Reset2Defaults(); - - // Send the query from the file to the Query Parser class - QueryParser presetQuery = QueryParser.Parse(query); - - // Now load the preset - PresetLoader.LoadPreset(this, presetQuery, "Load Back From Queue"); - - // The x264 widgets will need updated, so do this now: - x264Panel.StandardizeOptString(); - x264Panel.SetCurrentSettingsInPanel(); + // Reset + this.currentlySelectedPreset = null; + x264Panel.Reset2Defaults(); - // Finally, let this window have a copy of the preset settings. - this.currentlySelectedPreset = null; - PictureSettings.SetPresetCropWarningLabel(null); - } + // Scan + queueEdit = job; // Nasty but will do for now. TODO + StartScan(job.Source, job.Title); } #endregion @@ -2287,7 +2298,7 @@ namespace Handbrake lbl_encode.Visible = true; ProgressBarStatus.Value = 0; ProgressBarStatus.Visible = true; - lbl_encode.Text = "Encoding with " + encodeQueue.Count + " encode(s) pending"; + lbl_encode.Text = "Encoding with " + this.queueProcessor.QueueManager.Count + " encode(s) pending"; btn_start.Text = "Stop"; btn_start.ToolTipText = "Stop the encoding process."; btn_start.Image = Properties.Resources.stop; @@ -2307,11 +2318,11 @@ namespace Handbrake /// /// The e. /// - private void EncodeQueue_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EncodeProgressEventArgs e) + private void EncodeQueue_EncodeStatusChanged(object sender, EncodeProgressEventArgs e) { if (this.InvokeRequired) { - this.BeginInvoke(new Encode.EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e }); + this.BeginInvoke(new EncodeProgessStatus(EncodeQueue_EncodeStatusChanged), new[] { sender, e }); return; } @@ -2322,7 +2333,7 @@ namespace Handbrake e.CurrentFrameRate, e.AverageFrameRate, e.EstimatedTimeLeft, - encodeQueue.Count); + this.queueProcessor.QueueManager.Count); ProgressBarStatus.Value = (int)Math.Round(e.PercentComplete); } @@ -2340,7 +2351,7 @@ namespace Handbrake return; } - drives = Main.GetDrives(); + drives = UtilityService.GetDrives(); List menuItems = new List(); foreach (DriveInformation drive in drives) @@ -2375,7 +2386,44 @@ namespace Handbrake "HandBrake has determined your built-in presets are out of date... These presets will now be updated.", "Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information); - presetHandler.GetPresetPanel(ref treeView_presets); + // Clear the old presets + treeView_presets.Nodes.Clear(); + + + string category = string.Empty; // The category we are currnetly processing + TreeNode rootNode = null; + foreach (Preset preset in this.presetHandler.Presets.Where(p => p.IsBuildIn)) + { + // If the category of this preset doesn't match the current category we are processing + // Then we need to create a new root node. + if (preset.Category != category) + { + rootNode = new TreeNode(preset.Category) { ForeColor = Color.DarkBlue }; + treeView_presets.Nodes.Add(rootNode); + category = preset.Category; + } + + if (preset.Category == category && rootNode != null) + rootNode.Nodes.Add(new TreeNode(preset.Name) { ToolTipText = preset.Description, ForeColor = Color.DarkBlue }); + } + + rootNode = null; + category = null; + foreach (Preset preset in this.presetHandler.Presets.Where(p => !p.IsBuildIn)) // User Presets + { + if (preset.Category != category && preset.Category != string.Empty) + { + rootNode = new TreeNode(preset.Category) { ForeColor = Color.Black }; + treeView_presets.Nodes.Add(rootNode); + category = preset.Category; + } + + if (preset.Category == category && rootNode != null) + rootNode.Nodes.Add(new TreeNode(preset.Name) { ForeColor = Color.Black, ToolTipText = preset.Description }); + else + treeView_presets.Nodes.Add(new TreeNode(preset.Name) { ForeColor = Color.Black, ToolTipText = preset.Description }); + } + treeView_presets.Update(); } @@ -2472,7 +2520,7 @@ namespace Handbrake try { // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close. - if (encodeQueue.IsEncoding) + if (this.queueProcessor.EncodeService.IsEncoding) { DialogResult result = MessageBox.Show( @@ -2487,14 +2535,17 @@ namespace Handbrake return; } - encodeQueue.Stop(); + this.queueProcessor.Pause(); + this.queueProcessor.EncodeService.Stop(); } if (SourceScan.IsScanning) { - SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted); SourceScan.Stop(); } + + SourceScan.ScanCompleted -= this.SourceScanScanCompleted; + SourceScan.ScanStatusChanged -= this.SourceScanScanStatusChanged; } catch (Exception exc) {