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.Collections.ObjectModel;
\r
10 using System.Diagnostics;
\r
12 using System.Windows;
\r
14 using HandBrake.ApplicationServices.Model;
\r
15 using HandBrake.ApplicationServices.Parsing;
\r
16 using HandBrake.ApplicationServices.Services;
\r
17 using HandBrake.ApplicationServices.Services.Interfaces;
\r
20 /// HandBrakes Main Window
\r
22 public class MainViewModel : ViewModelBase
\r
24 #region Private Variables and Services
\r
27 /// The Source Scan Service.
\r
29 private readonly IScan scanService;
\r
32 /// The Encode Service
\r
34 private readonly IQueueProcessor queueProcessor;
\r
37 /// The preset service
\r
39 private readonly IPresetService presetService;
\r
42 /// HandBrakes Main Window Title
\r
44 private string windowName;
\r
47 /// The Source Label
\r
49 private string sourceLabel;
\r
52 /// The Toolbar Status Label
\r
54 private string programStatusLabel;
\r
59 /// Initializes a new instance of the <see cref="MainViewModel"/> class.
\r
61 public MainViewModel()
\r
63 // Setup Services (TODO - Bring Castle back into the project to wire these up for us)
\r
64 this.scanService = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService();
\r
65 this.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length);
\r
66 this.presetService = new PresetService();
\r
69 this.WindowTitle = "HandBrake WPF Test Application";
\r
72 this.scanService.ScanStared += this.ScanStared;
\r
73 this.scanService.ScanCompleted += this.ScanCompleted;
\r
74 this.scanService.ScanStatusChanged += this.ScanStatusChanged;
\r
76 this.queueProcessor.QueueCompleted += this.QueueCompleted;
\r
77 this.queueProcessor.QueuePaused += this.QueuePaused;
\r
78 this.queueProcessor.EncodeService.EncodeStarted += this.EncodeStarted;
\r
79 this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;
\r
84 /// Gets or sets TestProperty.
\r
86 public string WindowTitle
\r
90 return this.windowName;
\r
95 if (!object.Equals(this.windowName, value))
\r
97 this.windowName = value;
\r
98 this.NotifyOfPropertyChange("TestProperty");
\r
104 /// Gets a list of presets
\r
106 public ObservableCollection<Preset> Presets
\r
110 return this.presetService.Presets;
\r
115 /// Gets or sets The Current Encode Task that the user is building
\r
117 public EncodeTask CurrentTask { get; set; }
\r
120 /// Gets or sets the Last Scanned Source
\r
121 /// This object contains information about the scanned source.
\r
123 public Source ScannedSource { get; set; }
\r
126 /// Gets or sets the Source Label
\r
127 /// This indicates the status of scans.
\r
129 public string SourceLabel
\r
133 return string.IsNullOrEmpty(this.sourceLabel) ? "Select 'Source' to continue" : this.sourceLabel;
\r
138 if (!object.Equals(this.sourceLabel, value))
\r
140 this.sourceLabel = value;
\r
141 this.NotifyOfPropertyChange("SourceLabel");
\r
147 /// Gets or sets the Program Status Toolbar Label
\r
148 /// This indicates the status of HandBrake
\r
150 public string ProgramStatusLabel
\r
154 return string.IsNullOrEmpty(this.programStatusLabel) ? "Ready" : this.sourceLabel;
\r
159 if (!object.Equals(this.programStatusLabel, value))
\r
161 this.programStatusLabel = value;
\r
162 this.NotifyOfPropertyChange("ProgramStatusLabel");
\r
170 /// Shutdown this View
\r
172 public override void Shutdown()
\r
174 // Unsubscribe from Events.
\r
175 this.scanService.ScanStared -= this.ScanStared;
\r
176 this.scanService.ScanCompleted -= this.ScanCompleted;
\r
177 this.scanService.ScanStatusChanged -= this.ScanStatusChanged;
\r
179 this.queueProcessor.QueueCompleted -= this.QueueCompleted;
\r
180 this.queueProcessor.QueuePaused -= this.QueuePaused;
\r
181 this.queueProcessor.EncodeService.EncodeStarted -= this.EncodeStarted;
\r
182 this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;
\r
184 // Shutdown Normally
\r
189 /// Shutdown the Application
\r
191 public void ExitApplication()
\r
193 Application.Current.Shutdown();
\r
196 #region Event Handlers
\r
198 /// Handle the Scan Status Changed Event.
\r
200 /// <param name="sender">
\r
203 /// <param name="e">
\r
206 private void ScanStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs e)
\r
208 this.SourceLabel = "Scanning Title " + e.CurrentTitle + " of " + e.Titles;
\r
212 /// Handle the Scan Completed Event
\r
214 /// <param name="sender">
\r
217 /// <param name="e">
\r
220 private void ScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)
\r
224 this.ScannedSource = this.scanService.SouceData;
\r
229 /// Handle the Scan Started Event
\r
231 /// <param name="sender">
\r
234 /// <param name="e">
\r
237 private void ScanStared(object sender, EventArgs e)
\r
239 // TODO - Disable relevant parts of the UI.
\r
243 /// The Encode Status has changed Handler
\r
245 /// <param name="sender">
\r
248 /// <param name="e">
\r
249 /// The Encode Progress Event Args
\r
251 private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e)
\r
257 /// Encode Started Handler
\r
259 /// <param name="sender">
\r
262 /// <param name="e">
\r
265 private void EncodeStarted(object sender, EventArgs e)
\r
267 // TODO Handle Updating the UI
\r
271 /// The Queue has been paused handler
\r
273 /// <param name="sender">
\r
276 /// <param name="e">
\r
279 private void QueuePaused(object sender, EventArgs e)
\r
281 // TODO Handle Updating the UI
\r
285 /// The Queue has completed handler
\r
287 /// <param name="sender">
\r
290 /// <param name="e">
\r
293 private void QueueCompleted(object sender, EventArgs e)
\r
295 // TODO Handle Updating the UI
\r