// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// Defines the LogViewModel type.
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.ViewModels
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using HandBrake.ApplicationServices.Services.Interfaces;
using Interfaces;
using HandBrake.ApplicationServices.EventArgs;
///
/// The Log View Model
///
public class LogViewModel : ViewModelBase, ILogViewModel
{
#region Private Fields
///
/// Backing field for the encodeService service
///
private readonly IEncode encodeService;
///
/// Backing field for the Scan Service
///
private readonly IScan scanService;
///
/// Backing field for the selected mode
///
private int selectedMode;
///
/// Backing field for the log info.
///
private string log;
#endregion
///
/// Initializes a new instance of the class.
///
///
/// The encode service.
///
///
/// The scan service.
///
public LogViewModel(IEncode encodeService, IScan scanService)
{
this.encodeService = encodeService;
this.scanService = scanService;
this.Title = "Log Viewer";
this.SelectedMode = 0;
}
///
/// Gets Log.
///
public string Log
{
get
{
return this.SelectedMode == 0 ? this.encodeService.ActivityLog : this.scanService.ActivityLog;
}
}
///
/// Gets LogModes.
///
public IEnumerable LogModes
{
get
{
return new List { "Encode Log", "Scan Log" };
}
}
///
/// Gets or sets SelectedMode.
///
public int SelectedMode
{
get
{
return selectedMode;
}
set
{
selectedMode = value;
this.NotifyOfPropertyChange(() => this.SelectedMode);
this.ChangeLogDisplay();
}
}
///
/// Open the Log file directory
///
public void OpenLogDirectory()
{
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
string windir = Environment.GetEnvironmentVariable("WINDIR");
Process prc = new Process { StartInfo = { FileName = windir + @"\explorer.exe", Arguments = logDir } };
prc.Start();
}
///
/// Copy the log file to the system clipboard
///
public void CopyLog()
{
Clipboard.SetDataObject(this.Log, true);
}
///
/// Handle the OnActivate Caliburn Event
///
protected override void OnActivate()
{
this.scanService.ScanStared += ScanServiceScanStared;
this.scanService.ScanCompleted += ScanServiceScanCompleted;
this.encodeService.EncodeStarted += EncodeServiceEncodeStarted;
this.encodeService.EncodeCompleted += EncodeServiceEncodeCompleted;
this.encodeService.EncodeStatusChanged += this.EncodeServiceEncodeStatusChanged;
this.scanService.ScanStatusChanged += this.ScanServiceScanStatusChanged;
base.OnActivate();
}
///
/// Scan Status has changed, update log window.
///
///
/// The sender.
///
///
/// The e.
///
private void ScanServiceScanStatusChanged(object sender, ScanProgressEventArgs e)
{
this.NotifyOfPropertyChange(() => this.Log);
}
///
/// Encode Status has changed, update log window
///
///
/// The sender.
///
///
/// The e.
///
private void EncodeServiceEncodeStatusChanged(object sender, EncodeProgressEventArgs e)
{
this.NotifyOfPropertyChange(() => this.Log);
}
///
/// Handle the OnDeactivate Caliburn Event
///
///
/// The close.
///
protected override void OnDeactivate(bool close)
{
this.scanService.ScanStared -= ScanServiceScanStared;
this.encodeService.EncodeStarted -= EncodeServiceEncodeStarted;
this.Load();
base.OnDeactivate(close);
}
///
/// Change the Log Display
///
private void ChangeLogDisplay()
{
this.NotifyOfPropertyChange(() => this.Log);
}
///
/// Encode Started Event Handler
///
///
/// The sender.
///
///
/// The e.
///
private void EncodeServiceEncodeStarted(object sender, EventArgs e)
{
this.SelectedMode = 0;
}
///
/// Scan Started Event Handler
///
///
/// The sender.
///
///
/// The e.
///
private void ScanServiceScanStared(object sender, EventArgs e)
{
this.SelectedMode = 1;
}
///
/// Scan Completed Event Handler.
///
///
/// The sender.
///
///
/// The e.
///
private void ScanServiceScanCompleted(object sender, ScanCompletedEventArgs e)
{
this.NotifyOfPropertyChange(() => this.Log);
}
///
/// Encode Completed Event Handler.
///
///
/// The sender.
///
///
/// The e.
///
private void EncodeServiceEncodeCompleted(object sender, EncodeCompletedEventArgs e)
{
this.NotifyOfPropertyChange(() => this.Log);
}
}
}