From 122ea23a9cc9b22313fee0648fa9831132074817 Mon Sep 17 00:00:00 2001 From: sr55 Date: Wed, 21 Dec 2011 18:01:05 +0000 Subject: WinGui: (WPF) Some further work on the WPF GUI. Started to hook up presets. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4379 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Converters/BooleanToVisibilityConverter.cs | 86 ++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 7 + .../ViewModels/Interfaces/IMainViewModel.cs | 7 + win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 174 ++++++++++++++++++++- win/CS/HandBrakeWPF/Views/Images/Add16.png | Bin 0 -> 595 bytes win/CS/HandBrakeWPF/Views/Images/Help32.png | Bin 0 -> 2531 bytes win/CS/HandBrakeWPF/Views/Images/Options24.png | Bin 0 -> 857 bytes win/CS/HandBrakeWPF/Views/MainView.xaml | 66 +++++++- win/CS/HandBrakeWPF/Views/MainView.xaml.cs | 30 ++++ win/CS/HandBrakeWPF/Views/QueueView.xaml | 4 +- win/CS/HandBrakeWPF/Views/QueueView.xaml.cs | 4 +- 11 files changed, 361 insertions(+), 17 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Converters/BooleanToVisibilityConverter.cs create mode 100644 win/CS/HandBrakeWPF/Views/Images/Add16.png create mode 100644 win/CS/HandBrakeWPF/Views/Images/Help32.png create mode 100644 win/CS/HandBrakeWPF/Views/Images/Options24.png (limited to 'win/CS/HandBrakeWPF') diff --git a/win/CS/HandBrakeWPF/Converters/BooleanToVisibilityConverter.cs b/win/CS/HandBrakeWPF/Converters/BooleanToVisibilityConverter.cs new file mode 100644 index 000000000..81e12ddc8 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/BooleanToVisibilityConverter.cs @@ -0,0 +1,86 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the BooleanToVisibilityConverter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters +{ + using System.Globalization; + using System.Windows; + using System.Windows.Data; + using System; + + /// + /// Boolean to Visibility Converter + /// + public sealed class BooleanToVisibilityConverter : IValueConverter + { + /// + /// Convert a boolean to visibility property. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. (A boolean which inverts the output) + /// + /// + /// The culture. + /// + /// + /// Visibility property + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + // Paramater is a boolean which inverts the output. + var param = System.Convert.ToBoolean(parameter, CultureInfo.InvariantCulture); + + if (value is Boolean) + { + if (param) + { + return (bool)value ? Visibility.Collapsed : Visibility.Visible; + } + else + { + return (bool)value ? Visibility.Visible : Visibility.Collapsed; + } + } + + return value; + } + + /// + /// Convert Back for the IValueConverter Interface. Not used! + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// Nothing + /// + /// + /// This method is not used! + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 4772fd13f..cea841fe4 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -78,6 +78,7 @@ MSBuild:Compile Designer + @@ -224,6 +225,11 @@ Always + + + + + @@ -273,6 +279,7 @@ + diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs index 96519f42b..e9e2c4901 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs @@ -9,11 +9,18 @@ namespace HandBrakeWPF.ViewModels.Interfaces { + using HandBrake.ApplicationServices.Model; + /// /// The Main Window View Model /// public interface IMainViewModel { + /// + /// Sets SelectedPreset. + /// + Preset SelectedPreset { set; } + /// /// Shutdown the Application /// diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index e939c5d52..c1b008613 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -17,18 +17,15 @@ namespace HandBrakeWPF.ViewModels using System.IO; using System.Linq; using System.Windows; + using System.Windows.Media; using Caliburn.Micro; - using Castle.Components.DictionaryAdapter; - using HandBrake.ApplicationServices; using HandBrake.ApplicationServices.Exceptions; - using HandBrake.ApplicationServices.Functions; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Model.Encoding; using HandBrake.ApplicationServices.Parsing; - using HandBrake.ApplicationServices.Services; using HandBrake.ApplicationServices.Services.Interfaces; using HandBrake.ApplicationServices.Utilities; @@ -99,6 +96,16 @@ namespace HandBrakeWPF.ViewModels /// private string duration; + /// + /// Is Encoding Backing Field + /// + private bool isEncoding; + + /// + /// Backing field for the selected preset. + /// + private Preset selectedPreset; + #endregion /// @@ -177,6 +184,22 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets or sets SelectedPreset. + /// + public Preset SelectedPreset + { + get + { + return this.selectedPreset; + } + set + { + this.selectedPreset = value; + this.NotifyOfPropertyChange("SelectedPreset"); + } + } + /// /// Gets or sets The Current Encode Task that the user is building /// @@ -309,6 +332,23 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets or sets a value indicating whether IsEncoding. + /// + public bool IsEncoding + { + get + { + return this.isEncoding; + } + + set + { + this.isEncoding = value; + this.NotifyOfPropertyChange("IsEncoding"); + } + } + /* Properties for User Selections */ /// @@ -553,6 +593,7 @@ namespace HandBrakeWPF.ViewModels }; this.queueProcessor.QueueManager.Add(task); this.queueProcessor.Start(); + this.IsEncoding = true; } /// @@ -601,6 +642,126 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange("CurrentTask"); } + /// + /// Add a Preset + /// + public void PresetAdd() + { + throw new NotImplementedException("Still to do this"); + } + + /// + /// Remove a Preset + /// + public void PresetRemove() + { + if (this.selectedPreset != null) + { + this.presetService.Remove(this.selectedPreset); + } + else + { + MessageBox.Show("Please select a preset.", "Presets", MessageBoxButton.OK, MessageBoxImage.Warning); + } + } + + /// + /// Set a default preset + /// + public void PresetSetDefault() + { + if (this.selectedPreset != null) + { + this.presetService.SetDefault(this.selectedPreset); + MessageBox.Show(string.Format("New Default Preset Set: {0}", this.selectedPreset.Name), "Presets", MessageBoxButton.OK, MessageBoxImage.Warning); + } + else + { + MessageBox.Show("Please select a preset.", "Presets", MessageBoxButton.OK, MessageBoxImage.Warning); + } + } + + /// + /// Import a Preset + /// + public void PresetImport() + { + VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "Plist (*.plist)|*.plist", CheckFileExists = true }; + dialog.ShowDialog(); + string filename = dialog.FileName; + + if (!string.IsNullOrEmpty(filename)) + { + EncodeTask parsed = PlistPresetHandler.Import(filename); + if (this.presetService.CheckIfPresetExists(parsed.PresetName)) + { + if (!presetService.CanUpdatePreset(parsed.PresetName)) + { + MessageBox.Show( + "You can not import a preset with the same name as a built-in preset.", + "Error", + MessageBoxButton.OK, + MessageBoxImage.Error); + return; + } + + MessageBoxResult result = + MessageBox.Show( + "This preset appears to already exist. Would you like to overwrite it?", + "Overwrite preset?", + MessageBoxButton.YesNo, + MessageBoxImage.Warning); + if (result == MessageBoxResult.Yes) + { + 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, }; + presetService.Add(preset); + } + + this.NotifyOfPropertyChange("Presets"); + } + } + + /// + /// Export a Preset + /// + public void PresetExport() + { + VistaSaveFileDialog savefiledialog = new VistaSaveFileDialog { Filter = "plist|*.plist", CheckPathExists = true }; + if (this.selectedPreset != null) + { + savefiledialog.ShowDialog(); + string filename = savefiledialog.FileName; + + if (filename != null) + { + PlistPresetHandler.Export(savefiledialog.FileName, this.selectedPreset); + } + } + else + { + MessageBox.Show("Please select a preset.", "Presets", MessageBoxButton.OK, MessageBoxImage.Warning); + } + } + + /// + /// Reset built-in presets + /// + public void PresetReset() + { + this.presetService.UpdateBuiltInPresets(); + this.NotifyOfPropertyChange("Presets"); + this.SelectedPreset = this.presetService.DefaultPreset; + } + #endregion #region Private Worker Methods @@ -614,7 +775,7 @@ namespace HandBrakeWPF.ViewModels /// /// The title. /// - public void StartScan(string filename, int title) + private void StartScan(string filename, int title) { // TODO // 1. Disable GUI. @@ -654,7 +815,6 @@ namespace HandBrakeWPF.ViewModels this.scanService.SouceData.CopyTo(this.ScannedSource); this.NotifyOfPropertyChange("ScannedSource"); this.NotifyOfPropertyChange("ScannedSource.Titles"); - this.NotifyOfPropertyChange("T"); this.SelectedTitle = this.ScannedSource.Titles.Where(t => t.MainTitle).FirstOrDefault(); } @@ -738,6 +898,8 @@ namespace HandBrakeWPF.ViewModels /// private void QueueCompleted(object sender, EventArgs e) { + this.IsEncoding = false; + // TODO Handle Updating the UI } #endregion diff --git a/win/CS/HandBrakeWPF/Views/Images/Add16.png b/win/CS/HandBrakeWPF/Views/Images/Add16.png new file mode 100644 index 000000000..bad13b66a Binary files /dev/null and b/win/CS/HandBrakeWPF/Views/Images/Add16.png differ diff --git a/win/CS/HandBrakeWPF/Views/Images/Help32.png b/win/CS/HandBrakeWPF/Views/Images/Help32.png new file mode 100644 index 000000000..e3dc78d0b Binary files /dev/null and b/win/CS/HandBrakeWPF/Views/Images/Help32.png differ diff --git a/win/CS/HandBrakeWPF/Views/Images/Options24.png b/win/CS/HandBrakeWPF/Views/Images/Options24.png new file mode 100644 index 000000000..ac5ca9678 Binary files /dev/null and b/win/CS/HandBrakeWPF/Views/Images/Options24.png differ diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index a6649a268..483fbde1b 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -1,6 +1,7 @@  @@ -12,6 +13,14 @@ + + + + @@ -75,13 +84,20 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml.cs b/win/CS/HandBrakeWPF/Views/MainView.xaml.cs index 165e74923..347b83547 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml.cs @@ -11,6 +11,10 @@ namespace HandBrakeWPF.Views { using System.Windows; + using HandBrake.ApplicationServices.Model; + + using HandBrakeWPF.ViewModels.Interfaces; + /// /// Interaction logic for MainView.xaml /// @@ -23,5 +27,31 @@ namespace HandBrakeWPF.Views { InitializeComponent(); } + + /// + /// Gets ViewModel. + /// + private IMainViewModel ViewModel + { + get + { + return ((IMainViewModel)this.DataContext); + } + } + + /// + /// Set the Selected Preset Property. + /// The SelectedItem property of a treeview is readonly. + /// + /// + /// The sender. + /// + /// + /// The RoutedPropertyChangedEventArgs. + /// + private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) + { + this.ViewModel.SelectedPreset = e.NewValue as Preset; + } } } diff --git a/win/CS/HandBrakeWPF/Views/QueueView.xaml b/win/CS/HandBrakeWPF/Views/QueueView.xaml index f3fae9b26..8007ae889 100644 --- a/win/CS/HandBrakeWPF/Views/QueueView.xaml +++ b/win/CS/HandBrakeWPF/Views/QueueView.xaml @@ -1,4 +1,4 @@ - - + diff --git a/win/CS/HandBrakeWPF/Views/QueueView.xaml.cs b/win/CS/HandBrakeWPF/Views/QueueView.xaml.cs index 7b6fa9fdf..f4af15fc3 100644 --- a/win/CS/HandBrakeWPF/Views/QueueView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/QueueView.xaml.cs @@ -9,12 +9,12 @@ namespace HandBrakeWPF.Views { - using System.Windows.Controls; + using System.Windows; /// /// Interaction logic for VideoView.xaml /// - public partial class QueueView : UserControl + public partial class QueueView : Window { /// /// Initializes a new instance of the class. -- cgit v1.2.3