From 7afefbc8814370a3c01805f693f7dfb15399453a Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 6 Nov 2011 16:56:00 +0000 Subject: WinGui: (WPF) Starting to wire up bits of the main window. (Source Scan) git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4342 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Parsing/Source.cs | 11 ++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 3 + win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 159 +++++++++++++++++++-- win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 2 +- win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs | 27 ++++ win/CS/HandBrakeWPF/Views/MainView.xaml | 17 ++- win/CS/libraries/EagleBoost.Wpf.Presentation.dll | Bin 0 -> 24064 bytes 7 files changed, 204 insertions(+), 15 deletions(-) create mode 100644 win/CS/libraries/EagleBoost.Wpf.Presentation.dll (limited to 'win') diff --git a/win/CS/HandBrake.ApplicationServices/Parsing/Source.cs b/win/CS/HandBrake.ApplicationServices/Parsing/Source.cs index 0ed9c0033..a79da7040 100644 --- a/win/CS/HandBrake.ApplicationServices/Parsing/Source.cs +++ b/win/CS/HandBrake.ApplicationServices/Parsing/Source.cs @@ -49,5 +49,16 @@ namespace HandBrake.ApplicationServices.Parsing return thisDVD; } + + /// + /// Copy this Source to another Source Model + /// + /// + /// The source. + /// + public void CopyTo(Source source) + { + source.Titles = this.Titles; + } } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 48710e7df..6cdf5c969 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -48,6 +48,9 @@ ..\libraries\caliburn\Common.Logging.dll + + ..\libraries\EagleBoost.Wpf.Presentation.dll + ..\libraries\OokiiDialogs\Ookii.Dialogs.Wpf.dll diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 6e5153e85..2f3f3d270 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -13,7 +13,6 @@ namespace HandBrakeWPF.ViewModels using System.Collections.ObjectModel; using System.ComponentModel.Composition; using System.Diagnostics; - using System.IO; using System.Windows; using Caliburn.Micro; @@ -25,6 +24,8 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.ViewModels.Interfaces; + using Ookii.Dialogs.Wpf; + /// /// HandBrakes Main Window /// @@ -43,6 +44,11 @@ namespace HandBrakeWPF.ViewModels /// private readonly IScan scanService; + /// + /// The Encode Service + /// + private readonly IEncode encodeService; + /// /// The Encode Service /// @@ -68,6 +74,11 @@ namespace HandBrakeWPF.ViewModels /// private string programStatusLabel; + /// + /// Backing field for the scanned source. + /// + private Source scannedSource; + #endregion /// @@ -77,19 +88,32 @@ namespace HandBrakeWPF.ViewModels /// /// The window manager. /// - /// The User Setting Service + /// + /// The User Setting Service + /// + /// + /// The scan Service. + /// + /// + /// The encode Service. + /// + /// + /// The preset Service. + /// [ImportingConstructor] - public MainViewModel(IWindowManager windowManager, IUserSettingService userSettingService) + public MainViewModel(IWindowManager windowManager, IUserSettingService userSettingService, IScan scanService, IEncode encodeService, IPresetService presetService) : base(windowManager) { this.userSettingService = userSettingService; - // Setup Services (TODO - Bring Castle back into the project to wire these up for us) - this.scanService = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService(); + this.scanService = scanService; + this.encodeService = encodeService; + this.presetService = presetService; this.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length); - this.presetService = new PresetService(); // Setup Properties this.WindowTitle = "HandBrake WPF Test Application"; + this.CurrentTask = new EncodeTask(); + this.ScannedSource = new Source(); // Setup Events this.scanService.ScanStared += this.ScanStared; @@ -142,7 +166,18 @@ namespace HandBrakeWPF.ViewModels /// Gets or sets the Last Scanned Source /// This object contains information about the scanned source. /// - public Source ScannedSource { get; set; } + public Source ScannedSource + { + get + { + return this.scannedSource; + } + set + { + this.scannedSource = value; + this.NotifyOfPropertyChange("ScannedSource"); + } + } /// /// Gets or sets the Source Label @@ -160,6 +195,7 @@ namespace HandBrakeWPF.ViewModels if (!object.Equals(this.sourceLabel, value)) { this.sourceLabel = value; + this.NotifyOfPropertyChange("SourceLabel"); } } } @@ -180,12 +216,22 @@ namespace HandBrakeWPF.ViewModels if (!object.Equals(this.programStatusLabel, value)) { this.programStatusLabel = value; + this.NotifyOfPropertyChange("ProgramStatusLabel"); } } } #endregion + #region Load and Shutdown Handling + /// + /// Initialise this view model. + /// + public override void OnLoad() + { + // TODO + } + /// /// Shutdown this View /// @@ -201,6 +247,7 @@ namespace HandBrakeWPF.ViewModels this.queueProcessor.EncodeService.EncodeStarted -= this.EncodeStarted; this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged; } + #endregion #region Menu and Taskbar @@ -228,7 +275,6 @@ namespace HandBrakeWPF.ViewModels this.WindowManager.ShowWindow(new LogViewModel(this.WindowManager)); } - /// /// Open the Queue Window. /// @@ -237,6 +283,74 @@ namespace HandBrakeWPF.ViewModels this.WindowManager.ShowWindow(new QueueViewModel(this.WindowManager)); } + /// + /// Launch the Help pages. + /// + public void LaunchHelp() + { + Process.Start("https://trac.handbrake.fr/wiki/HandBrakeGuide"); + } + + /// + /// Check for Updates. + /// + public void CheckForUpdates() + { + throw new NotImplementedException("Not Yet Implemented"); + } + + /// + /// Folder Scan + /// + public void FolderScan() + { + VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog { Description = "Please select a folder.", UseDescriptionForTitle = true }; + dialog.ShowDialog(); + this.StartScan(dialog.SelectedPath, 0); + } + + /// + /// File Scan + /// + public void FileScan() + { + VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "All files (*.*)|*.*" }; + dialog.ShowDialog(); + this.StartScan(dialog.FileName, 0); + } + + /// + /// Cancel a Scan + /// + public void CancelScan() + { + this.scanService.Stop(); + } + + /// + /// Start an Encode + /// + public void StartEncode() + { + throw new NotImplementedException("Not Yet Implemented"); + } + + /// + /// Pause an Encode + /// + public void PauseEncode() + { + throw new NotImplementedException("Not Yet Implemented"); + } + + /// + /// Stop an Encode. + /// + public void StopEncode() + { + throw new NotImplementedException("Not Yet Implemented"); + } + /// /// Shutdown the Application /// @@ -247,6 +361,27 @@ namespace HandBrakeWPF.ViewModels #endregion + #region Private Worker Methods + + /// + /// Start a Scan + /// + /// + /// The filename. + /// + /// + /// The title. + /// + public void StartScan(string filename, int title) + { + // TODO + // 1. Disable GUI. + this.scanService.Scan(filename, title, this.userSettingService.GetUserSetting(UserSettingConstants.PreviewScanCount)); + } + + #endregion + + #region Event Handlers /// /// Handle the Scan Status Changed Event. @@ -275,8 +410,14 @@ namespace HandBrakeWPF.ViewModels { if (e.Successful) { - this.ScannedSource = this.scanService.SouceData; + this.scanService.SouceData.CopyTo(this.ScannedSource); + this.NotifyOfPropertyChange("ScannedSource"); + this.NotifyOfPropertyChange("ScannedSource.Titles"); } + + this.SourceLabel = "Scan Completed"; + + // TODO Re-enable GUI. } /// diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 35207e3b8..463e747ab 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -1225,7 +1225,7 @@ namespace HandBrakeWPF.ViewModels /// /// Load User Settings /// - public void Load() + public override void OnLoad() { // ############################# // General diff --git a/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs b/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs index eea335d84..f9781800c 100644 --- a/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs +++ b/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs @@ -18,6 +18,11 @@ namespace HandBrakeWPF.ViewModels /// public class ViewModelBase : Screen, IViewModelBase { + /// + /// Backing Field to prevent the Load method being called more than once. + /// + private bool hasLoaded; + /// /// Initializes a new instance of the class. /// @@ -33,5 +38,27 @@ namespace HandBrakeWPF.ViewModels /// Gets WindowManager. /// public IWindowManager WindowManager { get; private set; } + + /// + /// Perform any Initialisation for this ViewModelBase. + /// + public void Load() + { + if (!hasLoaded) + { + hasLoaded = true; + + // Initialise the ViewModels OnLoad method if it exists. + this.OnLoad(); + } + } + + /// + /// Load Method for the ViewModel + /// + public virtual void OnLoad() + { + // Impliment in the ViewModel to perform viewmodel specific code. + } } } diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index 1994f7434..5273a008a 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Data="clr-namespace:System.Windows.Data;assembly=PresentationFramework" xmlns:Micro="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" xmlns:Controls="clr-namespace:HandBrakeWPF.Views.Controls" - Title="{Data:Binding Path=WindowTitle}" Height="655" Width="1015" FontSize="11"> + Title="{Data:Binding Path=WindowTitle}" Height="655" Width="1015" FontSize="11" Background="#FFF0F0F0">