From 1a4342793d9c7054b1a70030787af46f77208288 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 30 Dec 2011 16:07:30 +0000 Subject: [PATCH] WinGui: (WPF) Fix build, Audio / Subtitle Panel initial template design, Output settings on the Main UI Wired up. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4392 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs | 201 +++++++++--------- .../HandBrakeWPF/ViewModels/MainViewModel.cs | 149 +++++++++++-- .../Views/Controls/AudioView.xaml | 86 +++++++- .../Views/Controls/SubtitlesView.xaml | 84 +++++++- win/CS/HandBrakeWPF/Views/MainView.xaml | 13 +- 5 files changed, 401 insertions(+), 132 deletions(-) diff --git a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs index 13095ce3098b..f0b942120ae3 100644 --- a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs @@ -54,121 +54,120 @@ public AutoNameHelper(IUserSettingService userSetting) /// public static string AutoName(EncodeTask task, string sourceOrLabelName) { - string autoNamePath = string.Empty; - if (task.Title != 0) // TODO check. + string autoNamePath = string.Empty; + if (task.Title != 0) // TODO check. + { + // Get the Source Name and remove any invalid characters + string sourceName = Path.GetInvalidFileNameChars().Aggregate(sourceOrLabelName, (current, character) => current.Replace(character.ToString(), string.Empty)); + sourceName = Path.GetFileNameWithoutExtension(sourceName); + + // Remove Underscores + if (userSettingService.GetUserSetting(UserSettingConstants.AutoNameRemoveUnderscore)) + sourceName = sourceName.Replace("_", " "); + + // Switch to "Title Case" + if (userSettingService.GetUserSetting(UserSettingConstants.AutoNameTitleCase)) + sourceName = sourceName.ToTitleCase(); + + // Get the Selected Title Number + + string dvdTitle = task.Title.ToString(); + + // Get the Chapter Start and Chapter End Numbers + string chapterStart = task.StartPoint.ToString(); + string chapterFinish = task.EndPoint.ToString(); + string combinedChapterTag = chapterStart; + if (chapterFinish != chapterStart && chapterFinish != string.Empty) + combinedChapterTag = chapterStart + "-" + chapterFinish; + + /* + * File Name + */ + string destinationFilename; + if (userSettingService.GetUserSetting(UserSettingConstants.AutoNameFormat) != string.Empty) { - // Get the Source Name and remove any invalid characters - string sourceName = Path.GetInvalidFileNameChars().Aggregate(sourceOrLabelName, (current, character) => current.Replace(character.ToString(), string.Empty)); - sourceName = Path.GetFileNameWithoutExtension(sourceName); - - // Remove Underscores - if (userSettingService.GetUserSetting(UserSettingConstants.AutoNameRemoveUnderscore)) - sourceName = sourceName.Replace("_", " "); - - // Switch to "Title Case" - if (userSettingService.GetUserSetting(UserSettingConstants.AutoNameTitleCase)) - sourceName = sourceName.ToTitleCase(); - - // Get the Selected Title Number - - string dvdTitle = task.Title.ToString(); - - // Get the Chapter Start and Chapter End Numbers - string chapterStart = task.StartPoint.ToString(); - string chapterFinish = task.EndPoint.ToString(); - string combinedChapterTag = chapterStart; - if (chapterFinish != chapterStart && chapterFinish != string.Empty) - combinedChapterTag = chapterStart + "-" + chapterFinish; - - /* - * File Name - */ - string destinationFilename; - if (userSettingService.GetUserSetting(UserSettingConstants.AutoNameFormat) != string.Empty) - { - destinationFilename = userSettingService.GetUserSetting(UserSettingConstants.AutoNameFormat); - destinationFilename = destinationFilename.Replace("{source}", sourceName) - .Replace("{title}", dvdTitle) - .Replace("{chapters}", combinedChapterTag) - .Replace("{date}", DateTime.Now.Date.ToShortDateString().Replace('/', '-')); - } - else - destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag; + destinationFilename = userSettingService.GetUserSetting(UserSettingConstants.AutoNameFormat); + destinationFilename = destinationFilename.Replace("{source}", sourceName) + .Replace("{title}", dvdTitle) + .Replace("{chapters}", combinedChapterTag) + .Replace("{date}", DateTime.Now.Date.ToShortDateString().Replace('/', '-')); + } + else + destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag; - /* - * File Extension - */ - if (task.OutputFormat == OutputFormat.Mp4 || task.OutputFormat == OutputFormat.M4V) + /* + * File Extension + */ + if (task.OutputFormat == OutputFormat.Mp4 || task.OutputFormat == OutputFormat.M4V) + { + switch (userSettingService.GetUserSetting(UserSettingConstants.UseM4v)) { - switch (userSettingService.GetUserSetting(UserSettingConstants.UseM4v)) - { - case 0: // Automatic - destinationFilename += task.IncludeChapterMarkers || task.RequiresM4v ? ".m4v" : ".mp4"; - break; - case 1: // Always MP4 - destinationFilename += ".mp4"; - break; - case 2: // Always M4V - destinationFilename += ".m4v"; - break; - } + case 0: // Automatic + destinationFilename += task.IncludeChapterMarkers || task.RequiresM4v ? ".m4v" : ".mp4"; + break; + case 1: // Always MP4 + destinationFilename += ".mp4"; + break; + case 2: // Always M4V + destinationFilename += ".m4v"; + break; } - else if (task.OutputFormat == OutputFormat.Mkv) - destinationFilename += ".mkv"; + } + else if (task.OutputFormat == OutputFormat.Mkv) + destinationFilename += ".mkv"; - /* - * File Destination Path - */ + /* + * File Destination Path + */ - // If there is an auto name path, use it... - if (userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") && !string.IsNullOrEmpty(task.Source)) - { - string savedPath = userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim().Replace("{source_path}\\", string.Empty).Replace("{source_path}", string.Empty); - - string directory = Directory.Exists(task.Source) - ? task.Source - : Path.GetDirectoryName(task.Source); - string requestedPath = Path.Combine(directory, savedPath); - - autoNamePath = Path.Combine(requestedPath, destinationFilename); - if (autoNamePath == task.Source) - { - // Append out_ to files that already exist or is the source file - autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), "output_" + destinationFilename); - } - } - else if (userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") && !string.IsNullOrEmpty(task.Source)) + // If there is an auto name path, use it... + if (userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") && !string.IsNullOrEmpty(task.Source)) + { + string savedPath = userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim().Replace("{source_path}\\", string.Empty).Replace("{source_path}", string.Empty); + + string directory = Directory.Exists(task.Source) + ? task.Source + : Path.GetDirectoryName(task.Source); + string requestedPath = Path.Combine(directory, savedPath); + + autoNamePath = Path.Combine(requestedPath, destinationFilename); + if (autoNamePath == task.Source) { - // Second Case: We have a Path, with "{source_folder}" in it, therefore we need to replace it with the folder name from the source. - string path = Path.GetDirectoryName(task.Source); - if (!string.IsNullOrEmpty(path)) - { - string[] filesArray = path.Split(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); - string sourceFolder = filesArray[filesArray.Length - 1]; - - autoNamePath = Path.Combine(userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Replace("{source_folder_name}", sourceFolder), destinationFilename); - } + // Append out_ to files that already exist or is the source file + autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), "output_" + destinationFilename); } - else if (!task.Destination.Contains(Path.DirectorySeparatorChar.ToString())) + } + else if (userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") && !string.IsNullOrEmpty(task.Source)) + { + // Second Case: We have a Path, with "{source_folder}" in it, therefore we need to replace it with the folder name from the source. + string path = Path.GetDirectoryName(task.Source); + if (!string.IsNullOrEmpty(path)) { - // Third case: If the destination box doesn't already contain a path, make one. - if (userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim() != string.Empty && - userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim() != "Click 'Browse' to set the default location") - { - autoNamePath = Path.Combine(userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath), destinationFilename); - } - else // ...otherwise, output to the source directory - autoNamePath = null; + string[] filesArray = path.Split(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); + string sourceFolder = filesArray[filesArray.Length - 1]; + + autoNamePath = Path.Combine(userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Replace("{source_folder_name}", sourceFolder), destinationFilename); } - else // Otherwise, use the path that is already there. + } + else if (!task.Destination.Contains(Path.DirectorySeparatorChar.ToString())) + { + // Third case: If the destination box doesn't already contain a path, make one. + if (userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim() != string.Empty && + userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim() != "Click 'Browse' to set the default location") { - // Use the path and change the file extension to match the previous destination - autoNamePath = Path.Combine(Path.GetDirectoryName(task.Destination), destinationFilename); + autoNamePath = Path.Combine(userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath), destinationFilename); } + else // ...otherwise, output to the source directory + autoNamePath = null; + } + else // Otherwise, use the path that is already there. + { + // Use the path and change the file extension to match the previous destination + autoNamePath = Path.Combine(Path.GetDirectoryName(task.Destination), destinationFilename); } - - return autoNamePath; } + + return autoNamePath; } } } diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 1e6034cf9ebb..d742eea5c08a 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -7,8 +7,6 @@ // // -------------------------------------------------------------------------------------------------------------------- -using HandBrakeWPF.Services.Interfaces; - namespace HandBrakeWPF.ViewModels { using System; @@ -19,12 +17,10 @@ namespace HandBrakeWPF.ViewModels using System.IO; using System.Linq; using System.Windows; - using System.Windows.Media; using Caliburn.Micro; using HandBrake.ApplicationServices; - using HandBrake.ApplicationServices.Exceptions; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Model.Encoding; using HandBrake.ApplicationServices.Parsing; @@ -35,6 +31,8 @@ namespace HandBrakeWPF.ViewModels using Ookii.Dialogs.Wpf; + using HandBrakeWPF.Services.Interfaces; + /// /// HandBrakes Main Window /// @@ -83,6 +81,16 @@ public class MainViewModel : ViewModelBase, IMainViewModel /// private string sourceLabel; + /// + /// The Selected Output Format Backing Field + /// + private OutputFormat selectedOutputFormat; + + /// + /// Is a MKV file backing field + /// + private bool isMkv; + public string sourcePath; private string dvdDrivePath; private string dvdDriveLabel; @@ -289,10 +297,11 @@ public string SourceName { get { - if (this.selectedSourceType == SourceType.DvdDrive) - { - return this.dvdDriveLabel; - } + // TODO + //if (this.selectedSourceType == SourceType.DvdDrive) + //{ + // return this.dvdDriveLabel; + //} if (selectedTitle != null && !string.IsNullOrEmpty(selectedTitle.SourceName)) { @@ -403,7 +412,39 @@ public bool IsEncoding } } - /* Properties for User Selections */ + /// + /// Gets or sets a value indicating whether IsMkv. + /// + public bool IsMkv + { + get + { + return this.isMkv; + } + set + { + this.isMkv = value; + this.NotifyOfPropertyChange("IsMkv"); + } + } + + /// + /// Gets RangeMode. + /// + public IEnumerable OutputFormats + { + get + { + return new List + { + OutputFormat.Mp4, OutputFormat.Mkv + }; + } + } + + #endregion + + #region Properties for Settings /// /// Gets or sets SelectedTitle. @@ -505,6 +546,25 @@ public PointToPointMode SelectedPointToPoint } } + /// + /// Gets or sets SelectedOutputFormat. + /// + public OutputFormat SelectedOutputFormat + { + get + { + return this.selectedOutputFormat; + } + set + { + this.selectedOutputFormat = value; + this.NotifyOfPropertyChange("SelectedOutputFormat"); + this.NotifyOfPropertyChange("IsMkv"); + this.SetExtension(string.Format(".{0}", this.selectedOutputFormat.ToString().ToLower())); // TODO, tidy up + } + } + + #endregion #region Load and Shutdown Handling @@ -574,7 +634,7 @@ public void OpenPreviewWindow() { this.WindowManager.ShowWindow(IoC.Get()); } - + /// /// Launch the Help pages. /// @@ -669,11 +729,11 @@ public void StartEncode() if (File.Exists(this.CurrentTask.Destination)) { - MessageBoxResult result = this.errorService.ShowMessageBox("The current file already exists, do you wish to overwrite it?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (result == MessageBoxResult.No) - { - return; - } + MessageBoxResult result = this.errorService.ShowMessageBox("The current file already exists, do you wish to overwrite it?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question); + if (result == MessageBoxResult.No) + { + return; + } } // Create the Queue Task and Start Processing @@ -733,6 +793,7 @@ public void BrowseDestination() this.CurrentTask.Destination = dialog.FileName; this.NotifyOfPropertyChange("CurrentTask"); + this.SetExtension(Path.GetExtension(dialog.FileName)); } /// @@ -808,16 +869,14 @@ public void PresetImport() MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { - Preset preset = new Preset - { Name = parsed.PresetName, CropSettings = parsed.UsesPictureSettings, Task = parsed }; + Preset preset = new Preset { Name = parsed.PresetName, CropSettings = parsed.UsesPictureSettings, Task = parsed }; presetService.Update(preset); } } else { - Preset preset = new Preset - { Name = parsed.PresetName, Task = parsed, CropSettings = parsed.UsesPictureSettings, }; + Preset preset = new Preset { Name = parsed.PresetName, Task = parsed, CropSettings = parsed.UsesPictureSettings, }; presetService.Add(preset); } @@ -835,7 +894,7 @@ public void PresetExport() { savefiledialog.ShowDialog(); string filename = savefiledialog.FileName; - + if (filename != null) { PlistPresetHandler.Export(savefiledialog.FileName, this.selectedPreset); @@ -859,7 +918,7 @@ public void PresetReset() #endregion - #region Private Worker Methods + #region Private Methods /// /// Start a Scan @@ -878,6 +937,54 @@ private void StartScan(string filename, int title) this.scanService.Scan(filename, title, this.userSettingService.GetUserSetting(ASUserSettingConstants.PreviewScanCount)); } + /// + /// Make sure the correct file extension is set based on user preferences and setup the GUI for the file container selected. + /// + /// + /// The new extension. + /// + private void SetExtension(string newExtension) + { + // Make sure the output extension is set correctly based on the users preferences and selection. + if (newExtension == ".mp4" || newExtension == ".m4v") + { + switch (this.userSettingService.GetUserSetting(UserSettingConstants.UseM4v)) + { + case 0: // Auto + newExtension = this.CurrentTask.RequiresM4v ? ".m4v" : ".mp4"; + break; + case 1: // MP4 + newExtension = ".mp4"; + break; + case 2: // M4v + newExtension = ".m4v"; + break; + } + + this.selectedOutputFormat = OutputFormat.Mp4; + this.IsMkv = false; + } + + // Now disable controls that are not required. The Following are for MP4 only! + if (newExtension == ".mkv") + { + this.IsMkv = true; + this.CurrentTask.LargeFile = false; + this.CurrentTask.OptimizeMP4 = false; + this.CurrentTask.IPod5GSupport = false; + this.selectedOutputFormat = OutputFormat.Mkv; + } + + // Update The browse file extension display + if (Path.HasExtension(newExtension)) + { + this.CurrentTask.Destination = Path.ChangeExtension(this.CurrentTask.Destination, newExtension); + } + + // Update the UI Display + this.NotifyOfPropertyChange("CurrentTask"); + } + #endregion #region Event Handlers diff --git a/win/CS/HandBrakeWPF/Views/Controls/AudioView.xaml b/win/CS/HandBrakeWPF/Views/Controls/AudioView.xaml index 512a1b91defd..161546a41a28 100644 --- a/win/CS/HandBrakeWPF/Views/Controls/AudioView.xaml +++ b/win/CS/HandBrakeWPF/Views/Controls/AudioView.xaml @@ -2,7 +2,10 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" + xmlns:cal="http://www.caliburnproject.org" + xmlns:NumericUpDown="clr-namespace:EagleBoost.Wpf.Presentation.Controls.NumericUpDown;assembly=EagleBoost.Wpf.Presentation" mc:Ignorable="d"> @@ -22,9 +25,86 @@