// -------------------------------------------------------------------------------------------------------------------- // // 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; #endregion /// /// Initializes a new instance of the class. /// /// /// The error Service. /// public ShellViewModel(IErrorService errorService) { this.errorService = errorService; this.showMainWindow = true; this.showOptions = false; } /// /// Change the page displayed on this window. /// /// /// The window. /// public void DisplayWindow(ShellWindow window) { if (window == ShellWindow.MainWindow) { this.ShowMainWindow = true; this.ShowOptions = false; } else if (window == ShellWindow.OptionsWindow) { this.ShowOptions = true; this.ShowMainWindow = false; } else { this.ShowMainWindow = true; this.ShowOptions = false; } } #region Properties /// /// Gets or sets MainViewModel. /// public IMainViewModel MainViewModel { get; set; } /// /// Gets or sets OptionsViewModel. /// public IOptionsViewModel OptionsViewModel { 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 WindowTitle. /// public string WindowTitle { get { return "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.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(); this.MainViewModel.Shutdown(); return true; } return false; } this.MainViewModel.Shutdown(); return true; } } }