// --------------------------------------------------------------------------------------------------------------------
//
// 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 Caliburn.Micro;
using Interfaces;
using HandBrake.ApplicationServices.EventArgs;
///
/// The Log View Model
///
public class LogViewModel : ViewModelBase, ILogViewModel
{
/**
* TODO
* - Live update the log file.
*/
#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 window manager.
///
///
/// The encode service.
///
///
/// The scan service.
///
public LogViewModel(IWindowManager windowManager, IEncode encodeService, IScan scanService)
{
this.encodeService = encodeService;
this.scanService = scanService;
this.Title = "Log Viewer";
this.SelectedMode = 0;
}
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 += scanService_ScanStared;
this.scanService.ScanCompleted += scanService_ScanCompleted;
this.encodeService.EncodeStarted += encodeService_EncodeStarted;
this.encodeService.EncodeCompleted += encodeService_EncodeCompleted;
this.encodeService.EncodeStatusChanged += this.encodeService_EncodeStatusChanged;
this.scanService.ScanStatusChanged += this.scanService_ScanStatusChanged;
base.OnActivate();
}
private void scanService_ScanStatusChanged(object sender, ScanProgressEventArgs e)
{
this.NotifyOfPropertyChange(() => this.Log);
}
private void encodeService_EncodeStatusChanged(object sender, EncodeProgressEventArgs e)
{
this.NotifyOfPropertyChange(() => this.Log);
}
///
/// Handle the OnDeactivate Caliburn Event
///
///
/// The close.
///
protected override void OnDeactivate(bool close)
{
this.scanService.ScanStared -= scanService_ScanStared;
this.encodeService.EncodeStarted -= encodeService_EncodeStarted;
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 encodeService_EncodeStarted(object sender, EventArgs e)
{
this.SelectedMode = 0;
this.NotifyOfPropertyChange(() => this.Log);
}
///
/// Scan Started Event Handler
///
///
/// The sender.
///
///
/// The e.
///
private void scanService_ScanStared(object sender, EventArgs e)
{
this.SelectedMode = 1;
this.NotifyOfPropertyChange(() => this.Log);
}
///
/// Scan Completed Event Handler.
///
///
/// The sender.
///
///
/// The e.
///
private void scanService_ScanCompleted(object sender, ScanCompletedEventArgs e)
{
this.NotifyOfPropertyChange(() => this.Log);
}
///
/// Encode Completed Event Handler.
///
///
/// The sender.
///
///
/// The e.
///
private void encodeService_EncodeCompleted(object sender, EncodeCompletedEventArgs e)
{
this.NotifyOfPropertyChange(() => this.Log);
}
}
}