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