// --------------------------------------------------------------------------------------------------------------------
//
// 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.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 showOverlayPanel;
private bool isMainPanelEnabled;
#endregion
///
/// Initializes a new instance of the class.
///
///
/// The error Service.
///
public ShellViewModel(IErrorService errorService)
{
this.errorService = errorService;
this.showMainWindow = true;
this.showOptions = false;
this.IsMainPanelEnabled = true;
}
///
/// The show overlay.
///
///
/// The panel.
///
public void ShowOverlay(IOverlayPanel panel)
{
this.OverlayPanelViewModel = panel;
this.NotifyOfPropertyChange(() => this.OverlayPanelViewModel);
this.ShowOverlayPanel = true;
}
///
/// The hide overlay.
///
public void HideOverlay()
{
this.ShowOverlayPanel = false;
this.OverlayPanelViewModel = null;
}
///
/// 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 the overlay panel view model.
///
public IOverlayPanel OverlayPanelViewModel { 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 or sets a value indicating whether show overlay panel.
///
public bool ShowOverlayPanel
{
get
{
return this.showOverlayPanel;
}
set
{
if (value.Equals(this.showOverlayPanel))
{
return;
}
this.showOverlayPanel = value;
this.IsMainPanelEnabled = !value;
this.NotifyOfPropertyChange(() => this.ShowOverlayPanel);
}
}
///
/// 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(
"An Encode is currently running. Exiting HandBrake will stop this encode.\nAre you sure you wish to exit HandBrake?",
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;
}
}
}