OSDN Git Service

0aaa4eb846192be803c7c699cc60a39c0ba5b0da
[handbrake-jp/handbrake-jp-git.git] / win / C# / HandBrakeWPF / ViewModels / MainViewModel.cs
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
5 \r
6 namespace HandBrakeWPF.ViewModels\r
7 {\r
8     using System;\r
9     using System.Collections.ObjectModel;\r
10     using System.Diagnostics;\r
11     using System.IO;\r
12     using System.Windows;\r
13 \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
18 \r
19     /// <summary>\r
20     /// HandBrakes Main Window\r
21     /// </summary>\r
22     public class MainViewModel : ViewModelBase\r
23     {\r
24         #region Private Variables and Services\r
25 \r
26         /// <summary>\r
27         /// The Source Scan Service.\r
28         /// </summary>\r
29         private readonly IScan scanService;\r
30 \r
31         /// <summary>\r
32         /// The Encode Service\r
33         /// </summary>\r
34         private readonly IQueueProcessor queueProcessor;\r
35 \r
36         /// <summary>\r
37         /// The preset service\r
38         /// </summary>\r
39         private readonly IPresetService presetService;\r
40 \r
41         /// <summary>\r
42         /// HandBrakes Main Window Title\r
43         /// </summary>\r
44         private string windowName;\r
45 \r
46         /// <summary>\r
47         /// The Source Label\r
48         /// </summary>\r
49         private string sourceLabel;\r
50 \r
51         /// <summary>\r
52         /// The Toolbar Status Label\r
53         /// </summary>\r
54         private string programStatusLabel;\r
55 \r
56         #endregion\r
57 \r
58         /// <summary>\r
59         /// Initializes a new instance of the <see cref="MainViewModel"/> class.\r
60         /// </summary>\r
61         public MainViewModel()\r
62         {\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
67 \r
68             // Setup Properties\r
69             this.WindowTitle = "HandBrake WPF Test Application";\r
70 \r
71             // Setup Events\r
72             this.scanService.ScanStared += this.ScanStared;\r
73             this.scanService.ScanCompleted += this.ScanCompleted;\r
74             this.scanService.ScanStatusChanged += this.ScanStatusChanged;\r
75 \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
80         }\r
81 \r
82         #region Properties\r
83         /// <summary>\r
84         /// Gets or sets TestProperty.\r
85         /// </summary>\r
86         public string WindowTitle\r
87         {\r
88             get\r
89             {\r
90                 return this.windowName;\r
91             }\r
92 \r
93             set\r
94             {\r
95                 if (!object.Equals(this.windowName, value))\r
96                 {\r
97                     this.windowName = value;\r
98                     this.NotifyOfPropertyChange("TestProperty");\r
99                 }\r
100             }\r
101         }\r
102 \r
103         /// <summary>\r
104         /// Gets a list of presets\r
105         /// </summary>\r
106         public ObservableCollection<Preset> Presets\r
107         {\r
108             get\r
109             {\r
110                 return this.presetService.Presets;\r
111             }\r
112         }\r
113 \r
114         /// <summary>\r
115         /// Gets or sets The Current Encode Task that the user is building\r
116         /// </summary>\r
117         public EncodeTask CurrentTask { get; set; }\r
118 \r
119         /// <summary>\r
120         /// Gets or sets the Last Scanned Source\r
121         /// This object contains information about the scanned source.\r
122         /// </summary>\r
123         public Source ScannedSource { get; set; }\r
124 \r
125         /// <summary>\r
126         /// Gets or sets the Source Label\r
127         /// This indicates the status of scans.\r
128         /// </summary>\r
129         public string SourceLabel\r
130         {\r
131             get\r
132             {\r
133                 return string.IsNullOrEmpty(this.sourceLabel) ? "Select 'Source' to continue" : this.sourceLabel;\r
134             }\r
135 \r
136             set\r
137             {\r
138                 if (!object.Equals(this.sourceLabel, value))\r
139                 {\r
140                     this.sourceLabel = value;\r
141                     this.NotifyOfPropertyChange("SourceLabel");\r
142                 }\r
143             }\r
144         }\r
145 \r
146         /// <summary>\r
147         /// Gets or sets the Program Status Toolbar Label\r
148         /// This indicates the status of HandBrake\r
149         /// </summary>\r
150         public string ProgramStatusLabel\r
151         {\r
152             get\r
153             {\r
154                 return string.IsNullOrEmpty(this.programStatusLabel) ? "Ready" : this.sourceLabel;\r
155             }\r
156 \r
157             set\r
158             {\r
159                 if (!object.Equals(this.programStatusLabel, value))\r
160                 {\r
161                     this.programStatusLabel = value;\r
162                     this.NotifyOfPropertyChange("ProgramStatusLabel");\r
163                 }\r
164             }\r
165         }\r
166 \r
167         #endregion\r
168 \r
169         /// <summary>\r
170         /// Shutdown this View\r
171         /// </summary>\r
172         public override void Shutdown()\r
173         {\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
178 \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
183 \r
184             // Shutdown Normally\r
185             base.Shutdown();\r
186         }\r
187 \r
188         /// <summary>\r
189         /// Shutdown the Application\r
190         /// </summary>\r
191         public void ExitApplication()\r
192         {\r
193             Application.Current.Shutdown();\r
194         }\r
195 \r
196         #region Event Handlers\r
197         /// <summary>\r
198         /// Handle the Scan Status Changed Event.\r
199         /// </summary>\r
200         /// <param name="sender">\r
201         /// The Sender\r
202         /// </param>\r
203         /// <param name="e">\r
204         /// The EventArgs\r
205         /// </param>\r
206         private void ScanStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs e)\r
207         {\r
208             this.SourceLabel = "Scanning Title " + e.CurrentTitle + " of " + e.Titles;\r
209         }\r
210 \r
211         /// <summary>\r
212         /// Handle the Scan Completed Event\r
213         /// </summary>\r
214         /// <param name="sender">\r
215         /// The Sender\r
216         /// </param>\r
217         /// <param name="e">\r
218         /// The EventArgs\r
219         /// </param>\r
220         private void ScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)\r
221         {\r
222             if (e.Successful)\r
223             {\r
224                 this.ScannedSource = this.scanService.SouceData;\r
225             }\r
226         }\r
227 \r
228         /// <summary>\r
229         /// Handle the Scan Started Event\r
230         /// </summary>\r
231         /// <param name="sender">\r
232         /// The Sender\r
233         /// </param>\r
234         /// <param name="e">\r
235         /// The EventArgs\r
236         /// </param>\r
237         private void ScanStared(object sender, EventArgs e)\r
238         {\r
239             // TODO - Disable relevant parts of the UI.\r
240         }\r
241 \r
242         /// <summary>\r
243         /// The Encode Status has changed Handler\r
244         /// </summary>\r
245         /// <param name="sender">\r
246         /// The Sender\r
247         /// </param>\r
248         /// <param name="e">\r
249         /// The Encode Progress Event Args\r
250         /// </param>\r
251         private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e)\r
252         {\r
253             //\r
254         }\r
255 \r
256         /// <summary>\r
257         /// Encode Started Handler\r
258         /// </summary>\r
259         /// <param name="sender">\r
260         /// The Sender\r
261         /// </param>\r
262         /// <param name="e">\r
263         /// The EventArgs\r
264         /// </param>\r
265         private void EncodeStarted(object sender, EventArgs e)\r
266         {\r
267             // TODO Handle Updating the UI\r
268         }\r
269 \r
270         /// <summary>\r
271         /// The Queue has been paused handler\r
272         /// </summary>\r
273         /// <param name="sender">\r
274         /// The Sender\r
275         /// </param>\r
276         /// <param name="e">\r
277         /// The EventArgs\r
278         /// </param>\r
279         private void QueuePaused(object sender, EventArgs e)\r
280         {\r
281             // TODO Handle Updating the UI\r
282         }\r
283 \r
284         /// <summary>\r
285         /// The Queue has completed handler\r
286         /// </summary>\r
287         /// <param name="sender">\r
288         /// The Sender\r
289         /// </param>\r
290         /// <param name="e">\r
291         /// The EventArgs\r
292         /// </param>\r
293         private void QueueCompleted(object sender, EventArgs e)\r
294         {\r
295             // TODO Handle Updating the UI\r
296         }\r
297         #endregion\r
298     }\r
299 }