OSDN Git Service

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