From f3fcc49085f080ad5f075da4a87bbaff47f92572 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 13 Jan 2013 17:51:42 +0000 Subject: [PATCH] WinGui: Options screen refactoring. Help -> Check for updates now takes the user to the options screen update tab. Help -> About now takes the user to the options screen about tab. Saves popping up annoying window. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5169 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Commands/OpenOptionsScreenCommand.cs | 62 ++++++++++++++++ .../Converters/Options/OptionsTabConverter.cs | 27 ++++--- .../Options/OptionsTabNameConverter.cs | 71 +++++++++++++++++++ win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 4 ++ win/CS/HandBrakeWPF/Model/OptionsTab.cs | 37 ++++++++++ .../Properties/Resources.Designer.cs | 19 +++++ win/CS/HandBrakeWPF/Properties/Resources.resx | 17 +++++ .../HandBrakeWPF/ViewModels/AudioViewModel.cs | 11 +++ .../Interfaces/IOptionsViewModel.cs | 9 +++ .../HandBrakeWPF/ViewModels/MainViewModel.cs | 37 ++-------- .../ViewModels/OptionsViewModel.cs | 36 ++++++---- .../ViewModels/SubtitlesViewModel.cs | 11 +++ win/CS/HandBrakeWPF/Views/AboutView.xaml | 55 +++----------- win/CS/HandBrakeWPF/Views/AboutView.xaml.cs | 4 +- win/CS/HandBrakeWPF/Views/AudioView.xaml | 7 +- win/CS/HandBrakeWPF/Views/OptionsView.xaml | 43 ++++++++--- win/CS/HandBrakeWPF/Views/SubtitlesView.xaml | 2 + 17 files changed, 333 insertions(+), 119 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Commands/OpenOptionsScreenCommand.cs create mode 100644 win/CS/HandBrakeWPF/Converters/Options/OptionsTabNameConverter.cs create mode 100644 win/CS/HandBrakeWPF/Model/OptionsTab.cs diff --git a/win/CS/HandBrakeWPF/Commands/OpenOptionsScreenCommand.cs b/win/CS/HandBrakeWPF/Commands/OpenOptionsScreenCommand.cs new file mode 100644 index 000000000..30a473d90 --- /dev/null +++ b/win/CS/HandBrakeWPF/Commands/OpenOptionsScreenCommand.cs @@ -0,0 +1,62 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// A Command to display the options window. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Commands +{ + using System; + using System.Windows.Input; + + using Caliburn.Micro; + + using HandBrakeWPF.Model; + using HandBrakeWPF.ViewModels.Interfaces; + + /// + /// A Command to display the options window. + /// + public class OpenOptionsScreenCommand : ICommand + { + /// + /// The can execute changed. + /// + public event EventHandler CanExecuteChanged; + + /// + /// The can execute. + /// + /// + /// The parameter. + /// + /// + /// The . + /// + public bool CanExecute(object parameter) + { + return true; + } + + /// + /// The execute. + /// + /// + /// The parameter. + /// + public void Execute(object parameter) + { + var shellViewModel = IoC.Get(); + shellViewModel.DisplayWindow(ShellWindow.OptionsWindow); + + if (parameter != null && parameter.GetType() == typeof(OptionsTab)) + { + var optionsViewModel = IoC.Get(); + optionsViewModel.GotoTab((OptionsTab)parameter); + } + } + } +} \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Converters/Options/OptionsTabConverter.cs b/win/CS/HandBrakeWPF/Converters/Options/OptionsTabConverter.cs index 9c561e549..128596f3f 100644 --- a/win/CS/HandBrakeWPF/Converters/Options/OptionsTabConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Options/OptionsTabConverter.cs @@ -15,6 +15,8 @@ namespace HandBrakeWPF.Converters.Options using System.Windows; using System.Windows.Data; + using HandBrakeWPF.Model; + /// /// The Options Tab Converter. Controls which tab is dispalyed. /// @@ -31,22 +33,25 @@ namespace HandBrakeWPF.Converters.Options { if (value != null && parameter != null) { - switch (value.ToString()) + switch ((OptionsTab)value) { - case "General": - if (parameter.ToString() == "General") return Visibility.Visible; + case OptionsTab.General: + if ((OptionsTab)parameter == OptionsTab.General) return Visibility.Visible; + break; + case OptionsTab.OutputFiles: + if ((OptionsTab)parameter == OptionsTab.OutputFiles) return Visibility.Visible; break; - case "Output Files": - if (parameter.ToString() == "Output Files") return Visibility.Visible; + case OptionsTab.AudioAndSubtitles: + if ((OptionsTab)parameter == OptionsTab.AudioAndSubtitles) return Visibility.Visible; break; - case "Audio and Subtitles": - if (parameter.ToString() == "Audio and Subtitles") return Visibility.Visible; + case OptionsTab.Advanced: + if ((OptionsTab)parameter == OptionsTab.Advanced) return Visibility.Visible; break; - case "Advanced": - if (parameter.ToString() == "Advanced") return Visibility.Visible; + case OptionsTab.Updates: + if ((OptionsTab)parameter == OptionsTab.Updates) return Visibility.Visible; break; - case "Updates": - if (parameter.ToString() == "Updates") return Visibility.Visible; + case OptionsTab.About: + if ((OptionsTab)parameter == OptionsTab.About) return Visibility.Visible; break; } } diff --git a/win/CS/HandBrakeWPF/Converters/Options/OptionsTabNameConverter.cs b/win/CS/HandBrakeWPF/Converters/Options/OptionsTabNameConverter.cs new file mode 100644 index 000000000..beddd18be --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Options/OptionsTabNameConverter.cs @@ -0,0 +1,71 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// A Converter to get the Display Name of each options tab. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Options +{ + using System; + using System.Globalization; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Utilities; + + using HandBrakeWPF.Model; + + /// + /// A Converter to get the Display Name of each options tab. + /// + public class OptionsTabNameConverter : IValueConverter + { + /// + /// The convert. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return EnumHelper.GetDisplay((OptionsTab)value); + } + + /// + /// The convert back. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return EnumHelper.GetValue(value.ToString()); + } + } +} \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index fe4287bda..e11f8e8f9 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -101,6 +101,7 @@ + @@ -124,6 +125,7 @@ + @@ -142,10 +144,12 @@ + + diff --git a/win/CS/HandBrakeWPF/Model/OptionsTab.cs b/win/CS/HandBrakeWPF/Model/OptionsTab.cs new file mode 100644 index 000000000..93692d13d --- /dev/null +++ b/win/CS/HandBrakeWPF/Model/OptionsTab.cs @@ -0,0 +1,37 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// A enum representing each tab on the options screen. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Model +{ + using System.ComponentModel.DataAnnotations; + + /// + /// A enum representing each tab on the options screen. + /// + public enum OptionsTab + { + [Display(Name = "General")] + General = 0, + + [Display(Name = "Output Files")] + OutputFiles, + + [Display(Name = "Audio and Subtitles")] + AudioAndSubtitles, + + [Display(Name = "Advanced")] + Advanced, + + [Display(Name = "Updates")] + Updates, + + [Display(Name = "About HandBrake")] + About, + } +} diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 3b5ef0e3c..5adc38011 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -60,6 +60,25 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Copyright (C) 2003-2013 The HandBrake Team + /// + ///This program is free software; you can redistribute it and/or + ///modify it under the terms of the GNU General Public License + ///as published by the Free Software Foundation; either version 2 + ///of the License, or (at your option) any later version. + /// + ///This program is distributed in the hope that it will be useful, + ///but WITHOUT ANY WARRANTY; without even the implied warranty of + ///MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ///GNU General Public License f [rest of string was truncated]";. + /// + public static string About_GPL { + get { + return ResourceManager.GetString("About_GPL", resourceCulture); + } + } + /// /// Looks up a localized string similar to You can optionally store a maximum resolution for encodes that use this preset. There are 3 modes: /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 2d4c9f8a3..6148d29c6 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -304,4 +304,21 @@ Source Maximum: Similar to custom, but the resolution of your current source is The above controls are only a subset of useful x264 parameters. This box allows you to add or modify additional or current parameters as desired. + + Copyright (C) 2003-2013 The HandBrake Team + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index eeb3def77..516fc7642 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -23,6 +23,8 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Utilities; using HandBrake.Interop.Model.Encoding; + using HandBrakeWPF.Commands; + using HandBrakeWPF.Model; using HandBrakeWPF.ViewModels.Interfaces; /// @@ -167,6 +169,15 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Open the options screen to the Audio and Subtitles tab. + /// + public void SetDefaultBehaviour() + { + OpenOptionsScreenCommand command = new OpenOptionsScreenCommand(); + command.Execute(OptionsTab.AudioAndSubtitles); + } + #endregion #region Implemented Interfaces diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IOptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IOptionsViewModel.cs index 7805aea63..c2d48f8e5 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IOptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IOptionsViewModel.cs @@ -9,10 +9,19 @@ namespace HandBrakeWPF.ViewModels.Interfaces { + using HandBrakeWPF.Model; + /// /// The Options Screen View Model Interface /// public interface IOptionsViewModel { + /// + /// The goto tab. + /// + /// + /// The tab. + /// + void GotoTab(OptionsTab tab); } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 7a9461b25..335509150 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -896,16 +896,8 @@ namespace HandBrakeWPF.ViewModels /// public void OpenAboutApplication() { - Window window = Application.Current.Windows.Cast().FirstOrDefault(x => x.GetType() == typeof(AboutView)); - - if (window != null) - { - window.Activate(); - } - else - { - this.WindowManager.ShowWindow(IoC.Get()); - } + OpenOptionsScreenCommand command = new OpenOptionsScreenCommand(); + command.Execute(OptionsTab.About); } /// @@ -983,8 +975,8 @@ namespace HandBrakeWPF.ViewModels /// public void CheckForUpdates() { - this.ProgramStatusLabel = "Checking for Updates ..."; - this.updateService.CheckForUpdates(this.HandleManualUpdateCheckResults); + OpenOptionsScreenCommand command = new OpenOptionsScreenCommand(); + command.Execute(OptionsTab.Updates); } /// @@ -1614,27 +1606,6 @@ namespace HandBrakeWPF.ViewModels this.ProgramStatusLabel = "A New Update is Available. Goto Tools Menu > Options to Install"; } } - - /// - /// Handle Update Check Results - /// - /// - /// The information. - /// - private void HandleManualUpdateCheckResults(UpdateCheckInformation information) - { - if (information.NewVersionAvailable) - { - MessageBox.Show("A New Version is available. Goto Tools Menu > Options to Install or visit http://handbrake.fr for details.", "Update Available", MessageBoxButton.OK, MessageBoxImage.Information); - } - else - { - MessageBox.Show("There is no new updates at this time.", "No Update Available", MessageBoxButton.OK, MessageBoxImage.Information); - } - - this.ProgramStatusLabel = "Ready"; - } - #endregion #region Event Handlers diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 6dc2a44dc..36fa35985 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -309,7 +309,7 @@ namespace HandBrakeWPF.ViewModels /// /// The options tab that is selected. /// - private string selectedTab; + private OptionsTab selectedTab; /// /// Update Message @@ -380,7 +380,7 @@ namespace HandBrakeWPF.ViewModels this.updateService = updateService; this.OnLoad(); - this.SelectedTab = "General"; + this.SelectedTab = OptionsTab.General; this.UpdateMessage = "Click 'Check for Updates' to check for new versions"; } @@ -388,21 +388,10 @@ namespace HandBrakeWPF.ViewModels #region Window Properties - /// - /// Gets OptionTabs. - /// - public IEnumerable OptionTabs - { - get - { - return new List { "General", "Output Files", "Audio and Subtitles", "Advanced", "Updates" }; - } - } - /// /// Gets or sets SelectedTab. /// - public string SelectedTab + public OptionsTab SelectedTab { get { @@ -415,6 +404,12 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.SelectedTab); } } + + /// + /// Gets or sets the about view model. + /// + public IAboutViewModel AboutViewModel { get; set; } + #endregion #region Properties @@ -1344,7 +1339,7 @@ namespace HandBrakeWPF.ViewModels } /// - /// Enable Debugging features in the UI. + /// Gets or sets a value indicating whether debug features are enabled. /// public bool EnableDebugFeatures { @@ -1962,5 +1957,16 @@ namespace HandBrakeWPF.ViewModels Process.Start(Path.Combine(Path.GetTempPath(), "handbrake-setup.exe")); Application.Current.Shutdown(); } + + /// + /// The goto tab. + /// + /// + /// The tab. + /// + public void GotoTab(OptionsTab tab) + { + this.SelectedTab = tab; + } } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs index b52dd961a..3fcca18aa 100644 --- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs @@ -22,6 +22,8 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Services.Interfaces; using HandBrake.ApplicationServices.Utilities; + using HandBrakeWPF.Commands; + using HandBrakeWPF.Model; using HandBrakeWPF.ViewModels.Interfaces; using Ookii.Dialogs.Wpf; @@ -279,6 +281,15 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Open the options screen to the Audio and Subtitles tab. + /// + public void SetDefaultBehaviour() + { + OpenOptionsScreenCommand command = new OpenOptionsScreenCommand(); + command.Execute(OptionsTab.AudioAndSubtitles); + } + #endregion #region Implemented Interfaces diff --git a/win/CS/HandBrakeWPF/Views/AboutView.xaml b/win/CS/HandBrakeWPF/Views/AboutView.xaml index a9e7e4319..d7b63c08b 100644 --- a/win/CS/HandBrakeWPF/Views/AboutView.xaml +++ b/win/CS/HandBrakeWPF/Views/AboutView.xaml @@ -1,13 +1,7 @@ - + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Properties="clr-namespace:HandBrakeWPF.Properties" + TextOptions.TextFormattingMode="Display"> @@ -32,7 +26,6 @@ - @@ -41,47 +34,17 @@ - - + + - + - - - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - + - -