// --------------------------------------------------------------------------------------------------------------------
//
// 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 HandBrakeWPF.Model;
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.ViewModels.Interfaces;
using IQueueProcessor = HandBrakeWPF.Services.Queue.Interfaces.IQueueProcessor;
///
/// 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;
private bool isMainPanelEnabled;
#endregion
///
/// Initializes a new instance of the class.
///
///
/// The error Service.
///
///
/// The main View Model.
///
///
/// The options View Model.
///
public ShellViewModel(IErrorService errorService, IMainViewModel mainViewModel, IOptionsViewModel optionsViewModel)
{
this.errorService = errorService;
this.showMainWindow = true;
this.showOptions = false;
this.IsMainPanelEnabled = true;
this.MainViewModel = mainViewModel;
this.OptionsViewModel = optionsViewModel;
}
///
/// 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 or sets a value indicating whether is main panel enabled.
///
public bool IsMainPanelEnabled
{
get
{
return this.isMainPanelEnabled;
}
set
{
if (value.Equals(this.isMainPanelEnabled))
{
return;
}
this.isMainPanelEnabled = value;
this.NotifyOfPropertyChange(() => this.IsMainPanelEnabled);
}
}
///
/// Gets WindowTitle.
///
public string WindowTitle
{
get
{
return "HandBrake";
}
}
#endregion
///
/// The files dropped on window. Pass this through to the active view model.
///
///
/// The DragEventArgs.
///
public void FilesDroppedOnWindow(DragEventArgs e)
{
this.MainViewModel.FilesDroppedOnWindow(e);
}
///
/// 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(
Resources.ShellViewModel_CanClose,
Resources.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;
}
}
}