diff options
author | sr55 <[email protected]> | 2011-12-27 22:52:43 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-12-27 22:52:43 +0000 |
commit | 5b745b8f17f8acc6d3799eb3cb86e09c7ca99017 (patch) | |
tree | 5a97790d448b6ac3b85b46f1803df00c34a39820 /win/CS/HandBrakeWPF/ViewModels | |
parent | 20fd52b888f111ac2d7670fa3c41e495661cdebd (diff) |
WinGui: (WPF) Initial work to hookup the log viewer + some additional helper classes ported over form the WinForms version.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4390 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels')
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs | 214 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 43 |
2 files changed, 254 insertions, 3 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs index 83a185276..aeba8e32e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs @@ -9,25 +9,233 @@ namespace HandBrakeWPF.ViewModels
{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Windows;
+
+ using HandBrake.ApplicationServices.Services.Interfaces;
+
using Caliburn.Micro;
- using HandBrakeWPF.ViewModels.Interfaces;
+ using Interfaces;
+
+ using HandBrake.ApplicationServices.EventArgs;
/// <summary>
/// The Log View Model
/// </summary>
public class LogViewModel : ViewModelBase, ILogViewModel
{
+ /**
+ * TODO
+ * - Live update the log file.
+ */
+
+ #region Private Fields
+
+ /// <summary>
+ /// Backing field for the encodeService service
+ /// </summary>
+ private readonly IEncode encodeService;
+
+ /// <summary>
+ /// Backing field for the Scan Service
+ /// </summary>
+ private readonly IScan scanService;
+
+ /// <summary>
+ /// Backing field for the selected mode
+ /// </summary>
+ private int selectedMode;
+
+ /// <summary>
+ /// Backing field for the log info.
+ /// </summary>
+ private string log;
+
+ #endregion
+
/// <summary>
/// Initializes a new instance of the <see cref="LogViewModel"/> class.
/// </summary>
/// <param name="windowManager">
/// The window manager.
/// </param>
- public LogViewModel(IWindowManager windowManager)
+ /// <param name="encodeService">
+ /// The encode service.
+ /// </param>
+ /// <param name="scanService">
+ /// The scan service.
+ /// </param>
+ public LogViewModel(IWindowManager windowManager, IEncode encodeService, IScan scanService)
: base(windowManager)
{
+ this.encodeService = encodeService;
+ this.scanService = scanService;
this.Title = "Log Viewer";
+ this.SelectedMode = 0;
+ }
+
+ /// <summary>
+ /// Gets or sets Log.
+ /// </summary>
+ public string Log
+ {
+ get
+ {
+ return log;
+ }
+ set
+ {
+ log = value;
+ this.NotifyOfPropertyChange("Log");
+ }
+ }
+
+ /// <summary>
+ /// Gets LogModes.
+ /// </summary>
+ public IEnumerable<string> LogModes
+ {
+ get
+ {
+ return new List<string> { "Encode Log", "Scan Log" };
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets SelectedMode.
+ /// </summary>
+ public int SelectedMode
+ {
+ get
+ {
+ return selectedMode;
+ }
+ set
+ {
+ selectedMode = value;
+ this.NotifyOfPropertyChange("SelectedMode");
+ this.ChangeLogDisplay();
+ }
+ }
+
+ /// <summary>
+ /// Open the Log file directory
+ /// </summary>
+ 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();
+ }
+
+ /// <summary>
+ /// Copy the log file to the system clipboard
+ /// </summary>
+ public void CopyLog()
+ {
+ Clipboard.SetDataObject(this.Log, true);
+ }
+
+ /// <summary>
+ /// Handle the OnActivate Caliburn Event
+ /// </summary>
+ 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();
+ }
+
+ /// <summary>
+ /// Handle the OnDeactivate Caliburn Event
+ /// </summary>
+ /// <param name="close">
+ /// The close.
+ /// </param>
+ protected override void OnDeactivate(bool close)
+ {
+ this.scanService.ScanStared -= scanService_ScanStared;
+ this.encodeService.EncodeStarted -= encodeService_EncodeStarted;
+ this.Load();
+ base.OnDeactivate(close);
+ }
+
+ /// <summary>
+ /// Change the Log Display
+ /// </summary>
+ private void ChangeLogDisplay()
+ {
+ this.Log = this.SelectedMode == 0 ? this.encodeService.ActivityLog : this.scanService.ActivityLog;
+ }
+
+ /// <summary>
+ /// Encode Started Event Handler
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void encodeService_EncodeStarted(object sender, EventArgs e)
+ {
+ this.SelectedMode = 0;
+ this.Log = this.encodeService.ActivityLog;
+ }
+
+ /// <summary>
+ /// Scan Started Event Handler
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void scanService_ScanStared(object sender, EventArgs e)
+ {
+ this.SelectedMode = 1;
+ this.Log = this.scanService.ActivityLog;
+ }
+
+ /// <summary>
+ /// Scan Completed Event Handler.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void scanService_ScanCompleted(object sender, ScanCompletedEventArgs e)
+ {
+ if (this.SelectedMode == 1)
+ {
+ this.Log = this.scanService.ActivityLog;
+ }
+ }
+
+ /// <summary>
+ /// Encode Completed Event Handler.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void encodeService_EncodeCompleted(object sender, EncodeCompletedEventArgs e)
+ {
+ if (this.SelectedMode == 0)
+ {
+ this.Log = this.encodeService.ActivityLog;
+ }
}
}
-}
+}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 5a8ecd233..1e6034cf9 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -83,6 +83,11 @@ namespace HandBrakeWPF.ViewModels /// </summary>
private string sourceLabel;
+ public string sourcePath;
+ private string dvdDrivePath;
+ private string dvdDriveLabel;
+ private List<DriveInformation> drives;
+
/// <summary>
/// The Toolbar Status Label
/// </summary>
@@ -278,6 +283,43 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
+ /// Gets SourceName.
+ /// </summary>
+ public string SourceName
+ {
+ get
+ {
+ if (this.selectedSourceType == SourceType.DvdDrive)
+ {
+ return this.dvdDriveLabel;
+ }
+
+ if (selectedTitle != null && !string.IsNullOrEmpty(selectedTitle.SourceName))
+ {
+ return Path.GetFileName(selectedTitle.SourceName);
+ }
+
+ // We have a drive, selected as a folder.
+ if (this.sourcePath.EndsWith("\\"))
+ {
+ drives = GeneralUtilities.GetDrives();
+ foreach (DriveInformation item in drives)
+ {
+ if (item.RootDirectory.Contains(this.sourcePath))
+ {
+ return item.VolumeLabel;
+ }
+ }
+ }
+
+ if (Path.GetFileNameWithoutExtension(this.sourcePath) != "VIDEO_TS")
+ return Path.GetFileNameWithoutExtension(this.sourcePath);
+
+ return Path.GetFileNameWithoutExtension(Path.GetDirectoryName(this.sourcePath));
+ }
+ }
+
+ /// <summary>
/// Gets RangeMode.
/// </summary>
public IEnumerable<PointToPointMode> RangeMode
@@ -832,6 +874,7 @@ namespace HandBrakeWPF.ViewModels {
// TODO
// 1. Disable GUI.
+ this.sourcePath = filename;
this.scanService.Scan(filename, title, this.userSettingService.GetUserSetting<int>(ASUserSettingConstants.PreviewScanCount));
}
|