1 /* MainViewModel.cs $
\r
2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
6 namespace HandBrakeWPF.ViewModels
\r
9 using System.Diagnostics;
\r
11 using System.Windows;
\r
13 using HandBrake.ApplicationServices.Model;
\r
14 using HandBrake.ApplicationServices.Parsing;
\r
15 using HandBrake.ApplicationServices.Services;
\r
16 using HandBrake.ApplicationServices.Services.Interfaces;
\r
19 /// HandBrakes Main Window
\r
21 public class MainViewModel : ViewModelBase
\r
23 #region Private Variables and Services
\r
26 /// The Source Scan Service.
\r
28 private readonly IScan scanService;
\r
31 /// The Encode Service
\r
33 private readonly IQueueProcessor queueProcessor;
\r
36 /// HandBrakes Main Window Title
\r
38 private string windowName;
\r
41 /// The Source Label
\r
43 private string sourceLabel;
\r
46 /// The Toolbar Status Label
\r
48 private string programStatusLabel;
\r
53 /// Initializes a new instance of the <see cref="MainViewModel"/> class.
\r
55 public MainViewModel()
\r
58 this.scanService = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService();
\r
59 this.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length);
\r
62 this.WindowTitle = "HandBrake WPF Test Application";
\r
65 this.scanService.ScanStared += this.ScanStared;
\r
66 this.scanService.ScanCompleted += this.ScanCompleted;
\r
67 this.scanService.ScanStatusChanged += this.ScanStatusChanged;
\r
69 this.queueProcessor.QueueCompleted += this.QueueCompleted;
\r
70 this.queueProcessor.QueuePaused += this.QueuePaused;
\r
71 this.queueProcessor.EncodeService.EncodeStarted += this.EncodeStarted;
\r
72 this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;
\r
77 /// Gets or sets TestProperty.
\r
79 public string WindowTitle
\r
83 return this.windowName;
\r
88 if (!object.Equals(this.windowName, value))
\r
90 this.windowName = value;
\r
91 this.NotifyOfPropertyChange("TestProperty");
\r
97 /// Gets or sets The Current Encode Task that the user is building
\r
99 public EncodeTask CurrentTask { get; set; }
\r
102 /// Gets or sets the Last Scanned Source
\r
103 /// This object contains information about the scanned source.
\r
105 public Source ScannedSource { get; set; }
\r
108 /// Gets or sets the Source Label
\r
109 /// This indicates the status of scans.
\r
111 public string SourceLabel
\r
115 return string.IsNullOrEmpty(this.sourceLabel) ? "Select 'Source' to continue" : this.sourceLabel;
\r
120 if (!object.Equals(this.sourceLabel, value))
\r
122 this.sourceLabel = value;
\r
123 this.NotifyOfPropertyChange("SourceLabel");
\r
129 /// Gets or sets the Program Status Toolbar Label
\r
130 /// This indicates the status of HandBrake
\r
132 public string ProgramStatusLabel
\r
136 return string.IsNullOrEmpty(this.programStatusLabel) ? "Ready" : this.sourceLabel;
\r
141 if (!object.Equals(this.programStatusLabel, value))
\r
143 this.programStatusLabel = value;
\r
144 this.NotifyOfPropertyChange("ProgramStatusLabel");
\r
152 /// Shutdown this View
\r
154 public override void Shutdown()
\r
156 // Unsubscribe from Events.
\r
157 this.scanService.ScanStared -= this.ScanStared;
\r
158 this.scanService.ScanCompleted -= this.ScanCompleted;
\r
159 this.scanService.ScanStatusChanged -= this.ScanStatusChanged;
\r
161 this.queueProcessor.QueueCompleted -= this.QueueCompleted;
\r
162 this.queueProcessor.QueuePaused -= this.QueuePaused;
\r
163 this.queueProcessor.EncodeService.EncodeStarted -= this.EncodeStarted;
\r
164 this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;
\r
166 // Shutdown Normally
\r
171 /// Shutdown the Application
\r
173 public void ExitApplication()
\r
175 Application.Current.Shutdown();
\r
178 #region Event Handlers
\r
180 /// Handle the Scan Status Changed Event.
\r
182 /// <param name="sender">
\r
185 /// <param name="e">
\r
188 private void ScanStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs e)
\r
190 this.SourceLabel = "Scanning Title " + e.CurrentTitle + " of " + e.Titles;
\r
194 /// Handle the Scan Completed Event
\r
196 /// <param name="sender">
\r
199 /// <param name="e">
\r
202 private void ScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)
\r
206 this.ScannedSource = this.scanService.SouceData;
\r
211 /// Handle the Scan Started Event
\r
213 /// <param name="sender">
\r
216 /// <param name="e">
\r
219 private void ScanStared(object sender, EventArgs e)
\r
221 // TODO - Disable relevant parts of the UI.
\r
225 /// The Encode Status has changed Handler
\r
227 /// <param name="sender">
\r
230 /// <param name="e">
\r
231 /// The Encode Progress Event Args
\r
233 private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e)
\r
239 /// Encode Started Handler
\r
241 /// <param name="sender">
\r
244 /// <param name="e">
\r
247 private void EncodeStarted(object sender, EventArgs e)
\r
249 // TODO Handle Updating the UI
\r
253 /// The Queue has been paused handler
\r
255 /// <param name="sender">
\r
258 /// <param name="e">
\r
261 private void QueuePaused(object sender, EventArgs e)
\r
263 // TODO Handle Updating the UI
\r
267 /// The Queue has completed handler
\r
269 /// <param name="sender">
\r
272 /// <param name="e">
\r
275 private void QueueCompleted(object sender, EventArgs e)
\r
277 // TODO Handle Updating the UI
\r