// --------------------------------------------------------------------------------------------------------------------
//
// 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;
}
///
/// Gets or sets Log.
///
public string Log
{
get
{
return log;
}
set
{
log = value;
this.NotifyOfPropertyChange("Log");
}
}
///
/// 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("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;
base.OnActivate();
}
///
/// 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.Log = this.SelectedMode == 0 ? this.encodeService.ActivityLog : this.scanService.ActivityLog;
}
///
/// Encode Started Event Handler
///
///
/// The sender.
///
///
/// The e.
///
private void encodeService_EncodeStarted(object sender, EventArgs e)
{
this.SelectedMode = 0;
this.Log = this.encodeService.ActivityLog;
}
///
/// Scan Started Event Handler
///
///
/// The sender.
///
///
/// The e.
///
private void scanService_ScanStared(object sender, EventArgs e)
{
this.SelectedMode = 1;
this.Log = this.scanService.ActivityLog;
}
///
/// Scan Completed Event Handler.
///
///
/// The sender.
///
///
/// The e.
///
private void scanService_ScanCompleted(object sender, ScanCompletedEventArgs e)
{
if (this.SelectedMode == 1)
{
this.Log = this.scanService.ActivityLog;
}
}
///
/// Encode Completed Event Handler.
///
///
/// The sender.
///
///
/// The e.
///
private void encodeService_EncodeCompleted(object sender, EncodeCompletedEventArgs e)
{
if (this.SelectedMode == 0)
{
this.Log = this.encodeService.ActivityLog;
}
}
}
}