From 8abbd723f6f4feb900a8d64a515508f0935c6ddd Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 18 Feb 2011 21:56:19 +0000 Subject: [PATCH] WinGui - Wire in the new preset service. git-svn-id: svn://localhost/HandBrake/trunk@3799 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Controls/AudioPanel.cs | 2 - win/C#/Controls/PictureSettings.cs | 2 - .../HandBrake.ApplicationServices/Model/Preset.cs | 13 +- .../Services/Interfaces/IPresetService.cs | 4 +- .../Services/PresetService.cs | 72 +++- win/C#/HandBrakeCS.csproj | 2 +- win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs | 20 +- win/C#/HandBrakeWPF/Views/MainView.xaml | 333 ++++++++------- win/C#/Presets/PresetsHandler.cs | 452 --------------------- win/C#/Program.cs | 6 +- win/C#/frmAddPreset.cs | 20 +- win/C#/frmMain.cs | 102 +++-- 12 files changed, 364 insertions(+), 664 deletions(-) delete mode 100644 win/C#/Presets/PresetsHandler.cs diff --git a/win/C#/Controls/AudioPanel.cs b/win/C#/Controls/AudioPanel.cs index ed56bf38..b31d2c17 100644 --- a/win/C#/Controls/AudioPanel.cs +++ b/win/C#/Controls/AudioPanel.cs @@ -17,8 +17,6 @@ namespace Handbrake.Controls using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Utilities; - using Presets; - using AudioTrack = HandBrake.ApplicationServices.Model.Encoding.AudioTrack; /// diff --git a/win/C#/Controls/PictureSettings.cs b/win/C#/Controls/PictureSettings.cs index 2425407e..c4ae909c 100644 --- a/win/C#/Controls/PictureSettings.cs +++ b/win/C#/Controls/PictureSettings.cs @@ -13,8 +13,6 @@ namespace Handbrake.Controls using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Parsing; - using Presets; - /// /// The Picture Settings Panel /// diff --git a/win/C#/HandBrake.ApplicationServices/Model/Preset.cs b/win/C#/HandBrake.ApplicationServices/Model/Preset.cs index 988e3da8..e20ad2de 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Preset.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Preset.cs @@ -8,7 +8,7 @@ namespace HandBrake.ApplicationServices.Model /// /// A Preset for encoding with. /// - public class Preset + public class Preset { /// /// Gets or sets the category which the preset resides under @@ -49,5 +49,16 @@ namespace HandBrake.ApplicationServices.Model /// Gets or sets a value indicating whether this is a built in preset /// public bool IsBuildIn { get; set; } + + /// + /// Override the ToString Method + /// + /// + /// The Preset Name + /// + public override string ToString() + { + return this.Name; + } } } \ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs b/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs index b947a955..07daab3c 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs @@ -5,7 +5,7 @@ namespace HandBrake.ApplicationServices.Services.Interfaces { - using System.ComponentModel; + using System.Collections.ObjectModel; using HandBrake.ApplicationServices.Model; @@ -17,7 +17,7 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// /// Gets or sets a Collection of presets. /// - ICollectionView Presets { get; set; } + ObservableCollection Presets { get; set; } /// /// Add a new preset to the system diff --git a/win/C#/HandBrake.ApplicationServices/Services/PresetService.cs b/win/C#/HandBrake.ApplicationServices/Services/PresetService.cs index dbfb8782..9a9f2656 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/PresetService.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/PresetService.cs @@ -28,7 +28,8 @@ namespace HandBrake.ApplicationServices.Services * TODO: * - Wire this into the Forms and WPF UI's * - Note: This is untested so far. It'll likely need fixes before it can be used. - **/ + * - Maybe change the collection to a dictionary to allow easier lookups? + **/ #region Private Variables @@ -59,14 +60,30 @@ namespace HandBrake.ApplicationServices.Services /// public PresetService() { - this.Presets = CollectionViewSource.GetDefaultView(this.presets); + // this.Presets = CollectionViewSource.GetDefaultView(this.presets); this.LoadPresets(); } /// /// Gets or sets a Collection of presets. /// - public ICollectionView Presets { get; set; } + public ObservableCollection Presets + { + get + { + return this.presets; + } + + set + { + this.presets = value; + } + } + + /// + /// The last preset added. + /// + public Preset LastPresetAdded { get; set; } #region Public Methods @@ -85,6 +102,7 @@ namespace HandBrake.ApplicationServices.Services if (this.CheckIfPresetExists(preset.Name) == false) { this.presets.Add(preset); + this.LastPresetAdded = preset; // Update the presets file this.UpdatePresetFiles(); @@ -95,6 +113,25 @@ namespace HandBrake.ApplicationServices.Services } /// + /// Update a preset + /// + /// + /// The updated preset + /// + public void Update(Preset update) + { + // TODO - Change this to be a lookup + foreach (Preset preset in this.presets) + { + if (preset.Name == update.Name) + { + preset.Query = update.Query; + break; + } + } + } + + /// /// Remove a preset with a given name from either the built in or user preset list. /// /// @@ -154,7 +191,7 @@ namespace HandBrake.ApplicationServices.Services string handbrakeCLIPath = Path.Combine(cliPath, "HandBrakeCLI.exe"); string presetsPath = Path.Combine(Path.GetTempPath(), "temp_presets.dat"); string strCmdLine = String.Format(@"cmd /c """"{0}"" --preset-list >""{1}"" 2>&1""", handbrakeCLIPath, presetsPath); - + ProcessStartInfo getPresets = new ProcessStartInfo("CMD.exe", strCmdLine) { WindowStyle = ProcessWindowStyle.Hidden }; Process hbproc = Process.Start(getPresets); @@ -163,7 +200,7 @@ namespace HandBrake.ApplicationServices.Services hbproc.Close(); // Clear the current built in Presets and now parse the tempory Presets file. - this.presets.Clear(); + this.ClearBuiltIn(); if (File.Exists(presetsPath)) { @@ -176,13 +213,13 @@ namespace HandBrake.ApplicationServices.Services string line = presetInput.ReadLine(); // Found the beginning of a preset block - if (line != null && line.Contains("<") && !line.Contains("<<")) + if (line != null && line.Contains("<") && !line.Contains("<<")) { category = line.Replace("<", string.Empty).Trim(); } // Found a preset - if (line != null && line.Contains("+")) + if (line != null && line.Contains("+")) { Regex r = new Regex("(: )"); // Split on hyphens. string[] presetName = r.Split(line); @@ -194,14 +231,15 @@ namespace HandBrake.ApplicationServices.Services } Preset newPreset = new Preset - { - Category = category, - Name = presetName[0].Replace("+", string.Empty).Trim(), - Query = presetName[2], - Version = Init.Version, - CropSettings = pic, - Description = string.Empty // Maybe one day we will populate this. - }; + { + Category = category, + Name = presetName[0].Replace("+", string.Empty).Trim(), + Query = presetName[2], + Version = Init.Version, + CropSettings = pic, + Description = string.Empty, // Maybe one day we will populate this. + IsBuildIn = true + }; this.presets.Add(newPreset); } } @@ -327,14 +365,14 @@ namespace HandBrake.ApplicationServices.Services { using (FileStream strm = new FileStream(this.builtInPresetFile, FileMode.Create, FileAccess.Write)) { - Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn)); + Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn).ToList()); strm.Close(); strm.Dispose(); } using (FileStream strm = new FileStream(this.userPresetFile, FileMode.Create, FileAccess.Write)) { - Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn == false)); + Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn == false).ToList()); strm.Close(); strm.Dispose(); } diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index 2edb8651..bd9e7819 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -174,6 +174,7 @@ + @@ -256,7 +257,6 @@ frmActivityWindow.cs - Form diff --git a/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs index 4b2180dd..0aaa4eb8 100644 --- a/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -6,6 +6,7 @@ namespace HandBrakeWPF.ViewModels { using System; + using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Windows; @@ -33,6 +34,11 @@ namespace HandBrakeWPF.ViewModels private readonly IQueueProcessor queueProcessor; /// + /// The preset service + /// + private readonly IPresetService presetService; + + /// /// HandBrakes Main Window Title /// private string windowName; @@ -54,9 +60,10 @@ namespace HandBrakeWPF.ViewModels /// public MainViewModel() { - // Setup Services + // 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.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length); + this.presetService = new PresetService(); // Setup Properties this.WindowTitle = "HandBrake WPF Test Application"; @@ -94,6 +101,17 @@ namespace HandBrakeWPF.ViewModels } /// + /// Gets a list of presets + /// + public ObservableCollection Presets + { + get + { + return this.presetService.Presets; + } + } + + /// /// Gets or sets The Current Encode Task that the user is building /// public EncodeTask CurrentTask { get; set; } diff --git a/win/C#/HandBrakeWPF/Views/MainView.xaml b/win/C#/HandBrakeWPF/Views/MainView.xaml index 86f80785..ea4d41ad 100644 --- a/win/C#/HandBrakeWPF/Views/MainView.xaml +++ b/win/C#/HandBrakeWPF/Views/MainView.xaml @@ -1,170 +1,197 @@  - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - -