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
19 using Microsoft.Practices.ServiceLocation;
\r
22 /// HandBrakes Main Window
\r
24 public class MainViewModel : ViewModelBase
\r
26 #region Private Variables and Services
\r
29 /// The Source Scan Service.
\r
31 private readonly IScan scanService;
\r
34 /// The Encode Service
\r
36 private readonly IQueueProcessor queueProcessor;
\r
39 /// The preset service
\r
41 private readonly IPresetService presetService;
\r
44 /// HandBrakes Main Window Title
\r
46 private string windowName;
\r
49 /// The Source Label
\r
51 private string sourceLabel;
\r
54 /// The Toolbar Status Label
\r
56 private string programStatusLabel;
\r
62 public MainViewModel(IServiceLocator locator)
\r
65 // Setup Services (TODO - Bring Castle back into the project to wire these up for us)
\r
66 this.scanService = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService();
\r
67 this.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length);
\r
68 this.presetService = new PresetService();
\r
71 this.WindowTitle = "HandBrake WPF Test Application";
\r
74 this.scanService.ScanStared += this.ScanStared;
\r
75 this.scanService.ScanCompleted += this.ScanCompleted;
\r
76 this.scanService.ScanStatusChanged += this.ScanStatusChanged;
\r
78 this.queueProcessor.QueueCompleted += this.QueueCompleted;
\r
79 this.queueProcessor.QueuePaused += this.QueuePaused;
\r
80 this.queueProcessor.EncodeService.EncodeStarted += this.EncodeStarted;
\r
81 this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;
\r
85 /// Gets or sets TestProperty.
\r
87 public string WindowTitle
\r
91 return this.windowName;
\r
96 if (!object.Equals(this.windowName, value))
\r
98 this.windowName = value;
\r
99 this.NotifyOfPropertyChange("TestProperty");
\r
105 /// Gets a list of presets
\r
107 public ObservableCollection<Preset> Presets
\r
111 return this.presetService.Presets;
\r
116 /// Gets or sets The Current Encode Task that the user is building
\r
118 public EncodeTask CurrentTask { get; set; }
\r
121 /// Gets or sets the Last Scanned Source
\r
122 /// This object contains information about the scanned source.
\r
124 public Source ScannedSource { get; set; }
\r
127 /// Gets or sets the Source Label
\r
128 /// This indicates the status of scans.
\r
130 public string SourceLabel
\r
134 return string.IsNullOrEmpty(this.sourceLabel) ? "Select 'Source' to continue" : this.sourceLabel;
\r
139 if (!object.Equals(this.sourceLabel, value))
\r
141 this.sourceLabel = value;
\r
142 this.NotifyOfPropertyChange("SourceLabel");
\r
148 /// Gets or sets the Program Status Toolbar Label
\r
149 /// This indicates the status of HandBrake
\r
151 public string ProgramStatusLabel
\r
155 return string.IsNullOrEmpty(this.programStatusLabel) ? "Ready" : this.sourceLabel;
\r
160 if (!object.Equals(this.programStatusLabel, value))
\r
162 this.programStatusLabel = value;
\r
163 this.NotifyOfPropertyChange("ProgramStatusLabel");
\r
171 /// Shutdown this View
\r
173 public override void Shutdown()
\r
175 // Unsubscribe from Events.
\r
176 this.scanService.ScanStared -= this.ScanStared;
\r
177 this.scanService.ScanCompleted -= this.ScanCompleted;
\r
178 this.scanService.ScanStatusChanged -= this.ScanStatusChanged;
\r
180 this.queueProcessor.QueueCompleted -= this.QueueCompleted;
\r
181 this.queueProcessor.QueuePaused -= this.QueuePaused;
\r
182 this.queueProcessor.EncodeService.EncodeStarted -= this.EncodeStarted;
\r
183 this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;
\r
185 // Shutdown Normally
\r
190 #region Menu and Taskbar
\r
192 public void AboutApplication()
\r
194 this.ShowDialog<AboutViewModel>();
\r
198 /// Shutdown the Application
\r
200 public void ExitApplication()
\r
202 Application.Current.Shutdown();
\r
208 #region Event Handlers
\r
210 /// Handle the Scan Status Changed Event.
\r
212 /// <param name="sender">
\r
215 /// <param name="e">
\r
218 private void ScanStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs e)
\r
220 this.SourceLabel = "Scanning Title " + e.CurrentTitle + " of " + e.Titles;
\r
224 /// Handle the Scan Completed Event
\r
226 /// <param name="sender">
\r
229 /// <param name="e">
\r
232 private void ScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)
\r
236 this.ScannedSource = this.scanService.SouceData;
\r
241 /// Handle the Scan Started Event
\r
243 /// <param name="sender">
\r
246 /// <param name="e">
\r
249 private void ScanStared(object sender, EventArgs e)
\r
251 // TODO - Disable relevant parts of the UI.
\r
255 /// The Encode Status has changed Handler
\r
257 /// <param name="sender">
\r
260 /// <param name="e">
\r
261 /// The Encode Progress Event Args
\r
263 private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e)
\r
269 /// Encode Started Handler
\r
271 /// <param name="sender">
\r
274 /// <param name="e">
\r
277 private void EncodeStarted(object sender, EventArgs e)
\r
279 // TODO Handle Updating the UI
\r
283 /// The Queue has been paused handler
\r
285 /// <param name="sender">
\r
288 /// <param name="e">
\r
291 private void QueuePaused(object sender, EventArgs e)
\r
293 // TODO Handle Updating the UI
\r
297 /// The Queue has completed handler
\r
299 /// <param name="sender">
\r
302 /// <param name="e">
\r
305 private void QueueCompleted(object sender, EventArgs e)
\r
307 // TODO Handle Updating the UI
\r