// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// HandBrakes Main Window
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.ViewModels
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Caliburn.Micro;
using HandBrake.ApplicationServices;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Model.Encoding;
using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Helpers;
using HandBrakeWPF.Model;
using HandBrakeWPF.ViewModels.Interfaces;
using Ookii.Dialogs.Wpf;
using HandBrakeWPF.Services.Interfaces;
using Image = System.Windows.Controls.Image;
///
/// HandBrakes Main Window
///
[Export(typeof(IMainViewModel))]
public class MainViewModel : ViewModelBase, IMainViewModel
{
#region Private Variables and Services
///
/// The Source Scan Service.
///
private readonly IScan scanService;
///
/// The Encode Service
///
private readonly IEncode encodeService;
///
/// The Encode Service
///
private readonly IQueueProcessor queueProcessor;
///
/// The preset service
///
private readonly IPresetService presetService;
///
/// The Error Service Backing field.
///
private readonly IErrorService errorService;
///
/// The Shell View Model
///
private readonly IShellViewModel shellViewModel;
///
/// Backing field for the update serivce.
///
private readonly IUpdateService updateService;
///
/// Backing field for the user setting service.
///
private readonly IUserSettingService userSettingService;
///
/// HandBrakes Main Window Title
///
private string windowName;
///
/// The Source Label
///
private string sourceLabel;
///
/// The Selected Output Format Backing Field
///
private OutputFormat selectedOutputFormat;
///
/// Is a MKV file backing field
///
private bool isMkv;
///
/// The Toolbar Status Label
///
private string statusLabel;
///
/// Program Status Label
///
private string programStatusLabel;
///
/// Backing field for the scanned source.
///
private Source scannedSource;
///
/// Backing field for the selected title.
///
private Title selectedTitle;
///
/// Backing field for duration
///
private string duration;
///
/// Is Encoding Backing Field
///
private bool isEncoding;
///
/// An Indicated to show the status window
///
private bool showStatusWindow;
///
/// Backing field for the selected preset.
///
private Preset selectedPreset;
///
/// Queue Edit Task
///
private EncodeTask queueEditTask;
#endregion
///
/// Initializes a new instance of the class.
/// The viewmodel for HandBrakes main window.
///
///
/// The window manager.
///
///
/// The User Setting Service
///
///
/// The scan Service.
///
///
/// The encode Service.
///
///
/// The preset Service.
///
///
/// The Error Service
///
///
/// The shell View Model.
///
///
/// The update Service.
///
[ImportingConstructor]
public MainViewModel(IWindowManager windowManager, IUserSettingService userSettingService, IScan scanService, IEncode encodeService, IPresetService presetService,
IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService)
{
GeneralUtilities.SetInstanceId();
this.scanService = scanService;
this.encodeService = encodeService;
this.presetService = presetService;
this.errorService = errorService;
this.shellViewModel = shellViewModel;
this.updateService = updateService;
this.userSettingService = userSettingService;
this.queueProcessor = IoC.Get();
queueProcessor.QueueManager.ResetInstanceId();
// Setup Properties
this.WindowTitle = "HandBrake";
this.CurrentTask = new EncodeTask();
this.ScannedSource = new Source();
// Setup Events
this.scanService.ScanStared += this.ScanStared;
this.scanService.ScanCompleted += this.ScanCompleted;
this.scanService.ScanStatusChanged += this.ScanStatusChanged;
this.queueProcessor.JobProcessingStarted += this.QueueProcessorJobProcessingStarted;
this.queueProcessor.QueueCompleted += this.QueueCompleted;
this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;
this.Presets = this.presetService.Presets;
}
#region View Model Properties
///
/// Gets or sets PictureSettingsViewModel.
///
public IPictureSettingsViewModel PictureSettingsViewModel { get; set; }
///
/// Gets or sets AudioViewModel.
///
public IAudioViewModel AudioViewModel { get; set; }
///
/// Gets or sets SubtitleViewModel.
///
public ISubtitlesViewModel SubtitleViewModel { get; set; }
///
/// Gets or sets ChaptersViewModel.
///
public IChaptersViewModel ChaptersViewModel { get; set; }
///
/// Gets or sets AdvancedViewModel.
///
public IAdvancedViewModel AdvancedViewModel { get; set; }
///
/// Gets or sets VideoViewModel.
///
public IVideoViewModel VideoViewModel { get; set; }
///
/// Gets or sets FiltersViewModel.
///
public IFiltersViewModel FiltersViewModel { get; set; }
#endregion
#region Properties
///
/// Gets or sets TestProperty.
///
public string WindowTitle
{
get
{
return this.windowName;
}
set
{
if (!Equals(this.windowName, value))
{
this.windowName = value;
}
}
}
///
/// Gets or sets the Program Status Toolbar Label
/// This indicates the status of HandBrake
///
public string ProgramStatusLabel
{
get
{
return string.IsNullOrEmpty(this.programStatusLabel) ? "Ready" : this.programStatusLabel;
}
set
{
if (!Equals(this.statusLabel, value))
{
this.programStatusLabel = value;
this.NotifyOfPropertyChange(() => this.ProgramStatusLabel);
}
}
}
///
/// Gets or sets the Program Status Toolbar Label
/// This indicates the status of HandBrake
///
public string StatusLabel
{
get
{
return string.IsNullOrEmpty(this.statusLabel) ? "Ready" : this.statusLabel;
}
set
{
if (!Equals(this.statusLabel, value))
{
this.statusLabel = value;
this.NotifyOfPropertyChange(() => this.StatusLabel);
}
}
}
///
/// Gets SourceToolbarMenu.
///
public IEnumerable