From b9001e7ebc4ad8e04e12423169258d67f6e251e8 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 13 Nov 2011 18:17:56 +0000 Subject: WinGui: (WPF) Further work on the WPF UI and associated servies and utilities. Started working on wiring up the ability to encode. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4347 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/CS/HandBrakeWPF/UserSettingConstants.cs | 1 - win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 103 +++++++++++++++++++-- win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 4 +- win/CS/HandBrakeWPF/Views/MainView.xaml | 9 +- 4 files changed, 100 insertions(+), 17 deletions(-) (limited to 'win/CS/HandBrakeWPF') diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index 41997ffb9..575a65678 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -34,7 +34,6 @@ namespace HandBrakeWPF public const string NativeLanguage = "NativeLanguage"; public const string DubMode = "DubMode"; public const string CliExeHash = "CliExeHash"; - public const string PreviewScanCount = "previewScanCount"; public const string ClearOldLogs = "clearOldLogs"; public const string AutoNameTitleCase = "AutoNameTitleCase"; public const string AutoNameRemoveUnderscore = "AutoNameRemoveUnderscore"; diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 2f3f3d270..206eeba0c 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -13,14 +13,18 @@ namespace HandBrakeWPF.ViewModels using System.Collections.ObjectModel; using System.ComponentModel.Composition; using System.Diagnostics; + using System.IO; using System.Windows; using Caliburn.Micro; + using HandBrake.ApplicationServices; + using HandBrake.ApplicationServices.Exceptions; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services; using HandBrake.ApplicationServices.Services.Interfaces; + using HandBrake.ApplicationServices.Utilities; using HandBrakeWPF.ViewModels.Interfaces; @@ -79,6 +83,11 @@ namespace HandBrakeWPF.ViewModels /// private Source scannedSource; + /// + /// Backing field for the selected title. + /// + private Title selectedTitle; + #endregion /// @@ -179,6 +188,27 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets or sets SelectedTitle. + /// + public Title SelectedTitle + { + get + { + return this.selectedTitle; + } + set + { + if (!object.Equals(this.selectedTitle, value)) + { + this.selectedTitle = value; + // Use the Path on the Title, or the Source Scan path if one doesn't exist. + this.CurrentTask.Source = !string.IsNullOrEmpty(this.selectedTitle.SourceName) ? this.selectedTitle.SourceName : this.ScannedSource.ScanPath; + this.CurrentTask.Title = value.TitleNumber; + } + } + } + /// /// Gets or sets the Source Label /// This indicates the status of scans. @@ -332,7 +362,37 @@ namespace HandBrakeWPF.ViewModels /// public void StartEncode() { - throw new NotImplementedException("Not Yet Implemented"); + // Santiy Checking. + if (this.ScannedSource == null || this.CurrentTask == null) + { + throw new GeneralApplicationException("You must first scan a source.", string.Empty, null); + } + + if (string.IsNullOrEmpty(this.CurrentTask.Destination)) + { + throw new GeneralApplicationException("The Destination field was empty.", "You must first set a destination for the encoded file.", null); + } + + if (this.queueProcessor.IsProcessing) + { + throw new GeneralApplicationException("HandBrake is already encoding.", string.Empty, null); + } + + if (File.Exists(this.CurrentTask.Destination)) + { + // TODO: File Overwrite warning. + } + + // Create the Queue Task and Start Processing + QueueTask task = new QueueTask(null) + { + Destination = this.CurrentTask.Destination, + Task = this.CurrentTask, + Query = QueryGeneratorUtility.GenerateQuery(this.CurrentTask), + CustomQuery = false + }; + this.queueProcessor.QueueManager.Add(task); + this.queueProcessor.Start(); } /// @@ -340,7 +400,7 @@ namespace HandBrakeWPF.ViewModels /// public void PauseEncode() { - throw new NotImplementedException("Not Yet Implemented"); + this.queueProcessor.Pause(); } /// @@ -348,7 +408,7 @@ namespace HandBrakeWPF.ViewModels /// public void StopEncode() { - throw new NotImplementedException("Not Yet Implemented"); + this.encodeService.Stop(); } /// @@ -361,6 +421,22 @@ namespace HandBrakeWPF.ViewModels #endregion + #region Main Window + + /// + /// The Destination Path + /// + public void BrowseDestination() + { + VistaSaveFileDialog dialog = new VistaSaveFileDialog { Filter = "MP4 File (*.mp4)|Mkv File(*.mkv)" }; + dialog.ShowDialog(); + dialog.AddExtension = true; + this.CurrentTask.Destination = dialog.FileName; + this.NotifyOfPropertyChange("CurrentTask"); + } + + #endregion + #region Private Worker Methods /// @@ -376,12 +452,11 @@ namespace HandBrakeWPF.ViewModels { // TODO // 1. Disable GUI. - this.scanService.Scan(filename, title, this.userSettingService.GetUserSetting(UserSettingConstants.PreviewScanCount)); + this.scanService.Scan(filename, title, this.userSettingService.GetUserSetting(ASUserSettingConstants.PreviewScanCount)); } #endregion - #region Event Handlers /// /// Handle the Scan Status Changed Event. @@ -410,13 +485,13 @@ namespace HandBrakeWPF.ViewModels { if (e.Successful) { - this.scanService.SouceData.CopyTo(this.ScannedSource); - this.NotifyOfPropertyChange("ScannedSource"); - this.NotifyOfPropertyChange("ScannedSource.Titles"); + this.scanService.SouceData.CopyTo(this.ScannedSource); + this.NotifyOfPropertyChange("ScannedSource"); + this.NotifyOfPropertyChange("ScannedSource.Titles"); } this.SourceLabel = "Scan Completed"; - + // TODO Re-enable GUI. } @@ -445,7 +520,15 @@ namespace HandBrakeWPF.ViewModels /// private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e) { - // + ProgramStatusLabel = + string.Format( + "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}, Elapsed: {4:hh\\:mm\\:ss}, Pending Jobs {5}", + e.PercentComplete, + e.CurrentFrameRate, + e.AverageFrameRate, + e.EstimatedTimeLeft, + e.ElapsedTime, + this.queueProcessor.QueueManager.Count); } /// diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 463e747ab..eedd247ce 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -1400,7 +1400,7 @@ namespace HandBrakeWPF.ViewModels this.PreviewPicturesToScan.Add(20); this.PreviewPicturesToScan.Add(25); this.PreviewPicturesToScan.Add(30); - this.selectedPreviewCount = this.userSettingService.GetUserSetting(UserSettingConstants.PreviewScanCount); + this.selectedPreviewCount = this.userSettingService.GetUserSetting(ASUserSettingConstants.PreviewScanCount); // x264 step this.ConstantQualityGranularity.Add("1.0"); @@ -1632,7 +1632,7 @@ namespace HandBrakeWPF.ViewModels userSettingService.SetUserSetting(UserSettingConstants.PromptOnUnmatchingQueries, this.PromptOnDifferentQuery); userSettingService.SetUserSetting(UserSettingConstants.PresetNotification, this.DisablePresetUpdateCheckNotification); userSettingService.SetUserSetting(ASUserSettingConstants.ShowCLI, this.ShowCliWindow); - userSettingService.SetUserSetting(UserSettingConstants.PreviewScanCount, this.SelectedPreviewCount); + userSettingService.SetUserSetting(ASUserSettingConstants.PreviewScanCount, this.SelectedPreviewCount); userSettingService.SetUserSetting(ASUserSettingConstants.X264Step, double.Parse(this.SelectedGranulairty)); int value; diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index 5273a008a..f85b7a1a5 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -60,12 +60,13 @@ - +