// -------------------------------------------------------------------------------------------------------------------- // // 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.ObjectModel; using System.ComponentModel.Composition; using System.Diagnostics; using System.IO; using System.Windows; using Caliburn.Micro; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services; using HandBrake.ApplicationServices.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; /// /// HandBrakes Main Window /// [Export(typeof(IMainViewModel))] public class MainViewModel : ViewModelBase, IMainViewModel { #region Private Variables and Services /// /// The Backing field for the user setting service. /// private readonly IUserSettingService userSettingService; /// /// The Source Scan Service. /// private readonly IScan scanService; /// /// The Encode Service /// private readonly IQueueProcessor queueProcessor; /// /// The preset service /// private readonly IPresetService presetService; /// /// HandBrakes Main Window Title /// private string windowName; /// /// The Source Label /// private string sourceLabel; /// /// The Toolbar Status Label /// private string programStatusLabel; #endregion /// /// Initializes a new instance of the class. /// The viewmodel for HandBrakes main window. /// /// /// The window manager. /// /// The User Setting Service [ImportingConstructor] public MainViewModel(IWindowManager windowManager, IUserSettingService userSettingService) : base(windowManager) { this.userSettingService = userSettingService; // Setup Services (TODO - Bring Castle back into the project to wire these up for us) this.scanService = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService(); this.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length); this.presetService = new PresetService(); // Setup Properties this.WindowTitle = "HandBrake WPF Test Application"; // Setup Events this.scanService.ScanStared += this.ScanStared; this.scanService.ScanCompleted += this.ScanCompleted; this.scanService.ScanStatusChanged += this.ScanStatusChanged; this.queueProcessor.QueueCompleted += this.QueueCompleted; this.queueProcessor.QueuePaused += this.QueuePaused; this.queueProcessor.EncodeService.EncodeStarted += this.EncodeStarted; this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged; } #region Properties /// /// Gets or sets TestProperty. /// public string WindowTitle { get { return this.windowName; } set { if (!object.Equals(this.windowName, value)) { this.windowName = value; } } } /// /// Gets a list of presets /// public ObservableCollection Presets { get { return this.presetService.Presets; } } /// /// Gets or sets The Current Encode Task that the user is building /// public EncodeTask CurrentTask { get; set; } /// /// Gets or sets the Last Scanned Source /// This object contains information about the scanned source. /// public Source ScannedSource { get; set; } /// /// Gets or sets the Source Label /// This indicates the status of scans. /// public string SourceLabel { get { return string.IsNullOrEmpty(this.sourceLabel) ? "Select 'Source' to continue" : this.sourceLabel; } set { if (!object.Equals(this.sourceLabel, value)) { this.sourceLabel = 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.sourceLabel; } set { if (!object.Equals(this.programStatusLabel, value)) { this.programStatusLabel = value; } } } #endregion /// /// Shutdown this View /// public void Shutdown() { // Unsubscribe from Events. this.scanService.ScanStared -= this.ScanStared; this.scanService.ScanCompleted -= this.ScanCompleted; this.scanService.ScanStatusChanged -= this.ScanStatusChanged; this.queueProcessor.QueueCompleted -= this.QueueCompleted; this.queueProcessor.QueuePaused -= this.QueuePaused; this.queueProcessor.EncodeService.EncodeStarted -= this.EncodeStarted; this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged; } #region Menu and Taskbar /// /// Open the About Window /// public void OpenAboutApplication() { this.WindowManager.ShowWindow(new AboutViewModel(this.WindowManager, this.userSettingService)); } /// /// Open the Options Window /// public void OpenOptionsWindow() { this.WindowManager.ShowWindow(new OptionsViewModel(this.WindowManager)); } /// /// Open the Queue Window. /// public void OpenQueueWindow() { this.WindowManager.ShowWindow(new QueueViewModel(this.WindowManager)); } /// /// Shutdown the Application /// public void ExitApplication() { Application.Current.Shutdown(); } #endregion #region Event Handlers /// /// Handle the Scan Status Changed Event. /// /// /// The Sender /// /// /// The EventArgs /// private void ScanStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs e) { this.SourceLabel = "Scanning Title " + e.CurrentTitle + " of " + e.Titles; } /// /// Handle the Scan Completed Event /// /// /// The Sender /// /// /// The EventArgs /// private void ScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e) { if (e.Successful) { this.ScannedSource = this.scanService.SouceData; } } /// /// Handle the Scan Started Event /// /// /// The Sender /// /// /// The EventArgs /// private void ScanStared(object sender, EventArgs e) { // TODO - Disable relevant parts of the UI. } /// /// The Encode Status has changed Handler /// /// /// The Sender /// /// /// The Encode Progress Event Args /// private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e) { // } /// /// Encode Started Handler /// /// /// The Sender /// /// /// The EventArgs /// private void EncodeStarted(object sender, EventArgs e) { // TODO Handle Updating the UI } /// /// The Queue has been paused handler /// /// /// The Sender /// /// /// The EventArgs /// private void QueuePaused(object sender, EventArgs e) { // TODO Handle Updating the UI } /// /// The Queue has completed handler /// /// /// The Sender /// /// /// The EventArgs /// private void QueueCompleted(object sender, EventArgs e) { // TODO Handle Updating the UI } #endregion } }