/* MainViewModel.cs $ This file is part of the HandBrake source code. Homepage: . It may be used under the terms of the GNU General Public License. */ namespace HandBrakeWPF.ViewModels { using System; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Windows; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services; using HandBrake.ApplicationServices.Services.Interfaces; using Microsoft.Practices.ServiceLocation; /// /// HandBrakes Main Window /// public class MainViewModel : ViewModelBase { #region Private Variables and Services /// /// 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 #region Properties public MainViewModel(IServiceLocator locator) : base(locator) { // 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; } /// /// Gets or sets TestProperty. /// public string WindowTitle { get { return this.windowName; } set { if (!object.Equals(this.windowName, value)) { this.windowName = value; this.NotifyOfPropertyChange("TestProperty"); } } } /// /// 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; this.NotifyOfPropertyChange("SourceLabel"); } } } /// /// 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; this.NotifyOfPropertyChange("ProgramStatusLabel"); } } } #endregion /// /// Shutdown this View /// public override 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; // Shutdown Normally base.Shutdown(); } #region Menu and Taskbar public void AboutApplication() { this.ShowDialog(); } /// /// 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 } }