// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// The mini view model.
//
// --------------------------------------------------------------------------------------------------------------------
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;
///
/// The mini view model.
///
public class MiniViewModel : ViewModelBase, IMiniViewModel
{
private readonly IEncode encodeService;
private readonly IQueueService queueProcessor;
private string queueStatus;
private string progress;
private string task;
private string windowTitle;
///
/// Initializes a new instance of the class.
///
///
/// The encode Service.
///
///
/// The queue Processor.
///
public MiniViewModel(IEncode encodeService, IQueueService queueProcessor)
{
this.encodeService = encodeService;
this.queueProcessor = queueProcessor;
this.Task = "Ready";
this.Progress = string.Empty;
this.QueueStatus = string.Format("{0} jobs pending", this.queueProcessor.Count);
}
///
/// Gets or sets the task.
///
public string Task
{
get
{
return this.task;
}
set
{
if (value == this.task)
{
return;
}
this.task = value;
this.NotifyOfPropertyChange(() => this.Task);
}
}
///
/// Gets or sets the progress.
///
public string Progress
{
get
{
return this.progress;
}
set
{
if (value == this.progress)
{
return;
}
this.progress = value;
this.NotifyOfPropertyChange(() => this.Progress);
}
}
///
/// Gets or sets the queue status.
///
public string QueueStatus
{
get
{
return this.queueStatus;
}
set
{
if (value == this.queueStatus)
{
return;
}
this.queueStatus = value;
this.NotifyOfPropertyChange(() => this.QueueStatus);
}
}
///
/// Gets or sets the window title.
///
public string WindowTitle
{
get
{
return this.windowTitle;
}
set
{
if (value == this.windowTitle)
{
return;
}
this.windowTitle = value;
this.NotifyOfPropertyChange(() => this.WindowTitle);
}
}
///
/// The activate.
///
public void Activate()
{
this.encodeService.EncodeStatusChanged += EncodeService_EncodeStatusChanged;
this.queueProcessor.QueueChanged += QueueProcessor_QueueChanged;
this.queueProcessor.QueueCompleted += QueueProcessor_QueueCompleted;
this.WindowTitle = "Mini Status Display";
}
///
/// The tear down.
///
public void Close()
{
this.encodeService.EncodeStatusChanged -= EncodeService_EncodeStatusChanged;
this.queueProcessor.QueueChanged -= QueueProcessor_QueueChanged;
this.queueProcessor.QueueCompleted -= QueueProcessor_QueueCompleted;
this.TryClose();
}
///
/// The queue processor_ queue completed.
///
///
/// The sender.
///
///
/// The e.
///
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);
}
///
/// The queue processor_ queue changed.
///
///
/// The sender.
///
///
/// The e.
///
private void QueueProcessor_QueueChanged(object sender, EventArgs e)
{
this.QueueStatus = string.Format("{0} jobs pending", this.queueProcessor.Count);
}
///
/// The encode service_ encode status changed.
///
///
/// The sender.
///
///
/// The e.
///
private void EncodeService_EncodeStatusChanged(object sender, EncodeProgressEventArgs e)
{
this.Task = this.queueProcessor.LastProcessedJob.ScannedSourcePath;
this.Progress =
string.Format(Resources.MiniViewModel_EncodeStatusChanged_StatusLabel,
e.Task,
e.TaskCount,
e.PercentComplete,
e.CurrentFrameRate,
e.AverageFrameRate,
e.EstimatedTimeLeft,
e.ElapsedTime);
}
}
}