// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // The Shell View Model // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.ViewModels { using System.Windows; using Caliburn.Micro; using HandBrake.ApplicationServices.Services.Interfaces; using HandBrakeWPF.Model; using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; /// /// The Shell View Model /// public class ShellViewModel : ViewModelBase, IShellViewModel { /// /// Backing field for the error service. /// private readonly IErrorService errorService; #region Constants and Fields /// /// The show main window. /// private bool showMainWindow; /// /// The show options. /// private bool showOptions; /// /// The show instant. /// private bool showInstant; #endregion /// /// Initializes a new instance of the class. /// /// /// The error Service. /// public ShellViewModel(IErrorService errorService) { this.errorService = errorService; if (!AppArguments.IsInstantHandBrake) { this.showMainWindow = true; this.showOptions = false; this.showInstant = false; } else { this.showMainWindow = false; this.showOptions = false; this.showInstant = true; } } /// /// Change the page displayed on this window. /// /// /// The window. /// public void DisplayWindow(ShellWindow window) { if (window == ShellWindow.MainWindow) { this.ShowMainWindow = true; this.ShowOptions = false; this.ShowInstant = false; } else if (window == ShellWindow.OptionsWindow) { this.ShowOptions = true; this.ShowMainWindow = false; this.ShowInstant = false; } else if (window == ShellWindow.InstantMainWindow) { this.ShowInstant = true; this.ShowOptions = false; this.ShowMainWindow = false; } else { this.ShowMainWindow = true; this.ShowOptions = false; this.ShowInstant = false; } } #region Properties /// /// Gets or sets MainViewModel. /// public IMainViewModel MainViewModel { get; set; } /// /// Gets or sets OptionsViewModel. /// public IOptionsViewModel OptionsViewModel { get; set; } /// /// Gets or sets the instant view model. /// public IInstantViewModel InstantViewModel { get; set; } /// /// Gets or sets a value indicating whether ShowMainWindow. /// public bool ShowMainWindow { get { return this.showMainWindow; } set { this.showMainWindow = value; this.NotifyOfPropertyChange(() => this.ShowMainWindow); } } /// /// Gets or sets a value indicating whether ShowOptions. /// public bool ShowOptions { get { return this.showOptions; } set { this.showOptions = value; this.NotifyOfPropertyChange(() => this.ShowOptions); } } /// /// Gets or sets a value indicating whether ShowInstant. /// public bool ShowInstant { get { return this.showInstant; } set { this.showInstant = value; this.NotifyOfPropertyChange(() => this.ShowInstant); } } /// /// Gets WindowTitle. /// public string WindowTitle { get { return AppArguments.IsInstantHandBrake ? "Instant HandBrake" : "HandBrake"; } } #endregion /// /// Checks with the use if this window can be closed. /// /// /// Returns true if the window can be closed. /// public bool CanClose() { IQueueProcessor processor = IoC.Get(); if (processor != null && processor.EncodeService.IsEncoding) { MessageBoxResult result = errorService.ShowMessageBox( "An Encode is currently running. Exiting HandBrake will stop this encode.\nAre you sure you wish to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { processor.Pause(); processor.EncodeService.Stop(); if (this.MainViewModel != null) { this.MainViewModel.Shutdown(); } return true; } return false; } if (this.MainViewModel != null) { this.MainViewModel.Shutdown(); } return true; } } }