summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/ViewModels/MiniViewModel.cs
blob: 64809bbf469465db0583eedae2381853469646a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MiniViewModel.cs" company="HandBrake Project (http://handbrake.fr)">
//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
//   The mini view model.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrakeWPF.ViewModels
{
    using System;

    using HandBrakeWPF.EventArgs;
    using HandBrakeWPF.Properties;
    using HandBrakeWPF.Services.Queue.Interfaces;
    using HandBrakeWPF.ViewModels.Interfaces;

    using EncodeProgressEventArgs = HandBrakeWPF.Services.Encode.EventArgs.EncodeProgressEventArgs;
    using IEncode = HandBrakeWPF.Services.Encode.Interfaces.IEncode;

    /// <summary>
    /// The mini view model.
    /// </summary>
    public class MiniViewModel : ViewModelBase, IMiniViewModel
    {
        private readonly IEncode encodeService;
        private readonly IQueueProcessor queueProcessor;
        private string queueStatus;
        private string progress;
        private string task;
        private string windowTitle;

        /// <summary>
        /// Initializes a new instance of the <see cref="MiniViewModel"/> class.
        /// </summary>
        /// <param name="encodeService">
        /// The encode Service.
        /// </param>
        /// <param name="queueProcessor">
        /// The queue Processor.
        /// </param>
        public MiniViewModel(IEncode encodeService, IQueueProcessor queueProcessor)
        {
            this.encodeService = encodeService;
            this.queueProcessor = queueProcessor;

            this.Task = "Ready";
            this.Progress = string.Empty;
            this.QueueStatus = string.Format("{0} jobs pending", this.queueProcessor.Count);
        }

        /// <summary>
        /// Gets or sets the task.
        /// </summary>
        public string Task
        {
            get
            {
                return this.task;
            }
            set
            {
                if (value == this.task)
                {
                    return;
                }
                this.task = value;
                this.NotifyOfPropertyChange(() => this.Task);
            }
        }

        /// <summary>
        /// Gets or sets the progress.
        /// </summary>
        public string Progress
        {
            get
            {
                return this.progress;
            }
            set
            {
                if (value == this.progress)
                {
                    return;
                }
                this.progress = value;
                this.NotifyOfPropertyChange(() => this.Progress);
            }
        }

        /// <summary>
        /// Gets or sets the queue status.
        /// </summary>
        public string QueueStatus
        {
            get
            {
                return this.queueStatus;
            }
            set
            {
                if (value == this.queueStatus)
                {
                    return;
                }
                this.queueStatus = value;
                this.NotifyOfPropertyChange(() => this.QueueStatus);
            }
        }

        /// <summary>
        /// Gets or sets the window title.
        /// </summary>
        public string WindowTitle
        {
            get
            {
                return this.windowTitle;
            }
            set
            {
                if (value == this.windowTitle)
                {
                    return;
                }
                this.windowTitle = value;
                this.NotifyOfPropertyChange(() => this.WindowTitle);
            }
        }

        /// <summary>
        /// The activate.
        /// </summary>
        public void Activate()
        {
            this.encodeService.EncodeStatusChanged += EncodeService_EncodeStatusChanged;
            this.queueProcessor.QueueChanged += QueueProcessor_QueueChanged;
            this.queueProcessor.QueueCompleted += QueueProcessor_QueueCompleted;
            this.WindowTitle = "Mini Status Display";
        }

        /// <summary>
        /// The tear down.
        /// </summary>
        public void Close()
        {
            this.encodeService.EncodeStatusChanged -= EncodeService_EncodeStatusChanged;
            this.queueProcessor.QueueChanged -= QueueProcessor_QueueChanged;
            this.queueProcessor.QueueCompleted -= QueueProcessor_QueueCompleted;
            this.TryClose();
        }

        /// <summary>
        /// The queue processor_ queue completed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void QueueProcessor_QueueCompleted(object sender, QueueCompletedEventArgs e)
        {
            this.Task = "Not Encoding.";
            this.Progress = string.Empty;
            this.QueueStatus = string.Format("{0} jobs pending", this.queueProcessor.Count);
        }

        /// <summary>
        /// The queue processor_ queue changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void QueueProcessor_QueueChanged(object sender, EventArgs e)
        {
            this.QueueStatus = string.Format("{0} jobs pending", this.queueProcessor.Count);
        }

        /// <summary>
        /// The encode service_ encode status changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void EncodeService_EncodeStatusChanged(object sender, EncodeProgressEventArgs e)
        {
            this.Task = queueProcessor.LastProcessedJob.ScannedSourcePath;

            // {0:00.00}%   FPS: {1:000.0}   Avg FPS: {2:000.0}   Time Remaining: {3}   Elapsed: {4:hh\:mm\:ss}
            this.Progress = string.Format(
                Resources.MainViewModel_EncodeStatusChanged_StatusLabel, 
                e.PercentComplete, 
                e.CurrentFrameRate, 
                e.AverageFrameRate, 
                e.EstimatedTimeLeft, 
                e.ElapsedTime);
        }
    }
}