summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels')
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs70
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs230
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs2
3 files changed, 210 insertions, 92 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index b2f067670..54622b392 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -95,7 +95,7 @@ namespace HandBrakeWPF.ViewModels
/// <summary>
/// The Toolbar Status Label
/// </summary>
- private string programStatusLabel;
+ private string statusLabel;
/// <summary>
/// Backing field for the scanned source.
@@ -171,7 +171,7 @@ namespace HandBrakeWPF.ViewModels
this.queueProcessor.QueuePaused += this.QueuePaused;
this.queueProcessor.EncodeService.EncodeStarted += this.EncodeStarted;
this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;
-
+
this.Presets = this.presetService.Presets;
}
@@ -237,19 +237,19 @@ namespace HandBrakeWPF.ViewModels
/// Gets or sets the Program Status Toolbar Label
/// This indicates the status of HandBrake
/// </summary>
- public string ProgramStatusLabel
+ public string StatusLabel
{
get
{
- return string.IsNullOrEmpty(this.programStatusLabel) ? "Ready" : this.sourceLabel;
+ return string.IsNullOrEmpty(this.statusLabel) ? "Ready" : this.statusLabel;
}
set
{
- if (!Equals(this.programStatusLabel, value))
+ if (!Equals(this.statusLabel, value))
{
- this.programStatusLabel = value;
- this.NotifyOfPropertyChange("ProgramStatusLabel");
+ this.statusLabel = value;
+ this.NotifyOfPropertyChange(() => this.StatusLabel);
}
}
}
@@ -741,7 +741,7 @@ namespace HandBrakeWPF.ViewModels
if (!this.IsEncoding)
{
- this.ProgramStatusLabel = string.Format("{0} Encodes Pending", this.queueProcessor.QueueManager.Count);
+ this.StatusLabel = string.Format("{0} Encodes Pending", this.queueProcessor.QueueManager.Count);
}
}
@@ -778,7 +778,14 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public void StartEncode()
{
- // Santiy Checking.
+ // Check if we already have jobs, and if we do, just start the queue.
+ if (this.queueProcessor.QueueManager.Count != 0)
+ {
+ this.queueProcessor.Start();
+ return;
+ }
+
+ // Otherwise, perform Santiy Checking then add to the queue and start if everything is ok.
if (this.ScannedSource == null || this.CurrentTask == null)
{
this.errorService.ShowMessageBox("You must first scan a source.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
@@ -1129,7 +1136,7 @@ namespace HandBrakeWPF.ViewModels
switch (this.SelectedPointToPoint)
{
case PointToPointMode.Chapters:
- return this.SelectedTitle.CalculateDuration(this.SelectedStartPoint -1, this.SelectedEndPoint -1).ToString();
+ return this.SelectedTitle.CalculateDuration(this.SelectedStartPoint - 1, this.SelectedEndPoint - 1).ToString();
case PointToPointMode.Seconds:
return TimeSpan.FromSeconds(startEndDuration).ToString();
case PointToPointMode.Frames:
@@ -1183,6 +1190,7 @@ namespace HandBrakeWPF.ViewModels
}
this.SourceLabel = "Scan Completed";
+ this.StatusLabel = "Scan Completed";
});
// TODO Re-enable GUI.
@@ -1199,6 +1207,11 @@ namespace HandBrakeWPF.ViewModels
/// </param>
private void ScanStared(object sender, EventArgs e)
{
+ Execute.OnUIThread(
+ () =>
+ {
+ this.StatusLabel = "Scanning source, please wait...";
+ });
// TODO - Disable relevant parts of the UI.
}
@@ -1213,15 +1226,19 @@ namespace HandBrakeWPF.ViewModels
/// </param>
private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e)
{
- ProgramStatusLabel =
- string.Format(
- "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}, Elapsed: {4:hh\\:mm\\:ss}, Pending Jobs {5}",
- e.PercentComplete,
- e.CurrentFrameRate,
- e.AverageFrameRate,
- e.EstimatedTimeLeft,
- e.ElapsedTime,
- this.queueProcessor.QueueManager.Count);
+ Execute.OnUIThread(
+ () =>
+ {
+ this.StatusLabel =
+ string.Format(
+ "{0:00.00}%, FPS: {1:000.0}, Avg FPS: {2:000.0}, Time Remaining: {3}, Elapsed: {4:hh\\:mm\\:ss}, Pending Jobs {5}",
+ e.PercentComplete,
+ e.CurrentFrameRate,
+ e.AverageFrameRate,
+ e.EstimatedTimeLeft,
+ e.ElapsedTime,
+ this.queueProcessor.QueueManager.Count);
+ });
}
/// <summary>
@@ -1235,6 +1252,13 @@ namespace HandBrakeWPF.ViewModels
/// </param>
private void EncodeStarted(object sender, EventArgs e)
{
+ Execute.OnUIThread(
+ () =>
+ {
+ this.StatusLabel = "Preparing to encode ...";
+ this.IsEncoding = true;
+ });
+
// TODO Handle Updating the UI
}
@@ -1249,6 +1273,7 @@ namespace HandBrakeWPF.ViewModels
/// </param>
private void QueuePaused(object sender, EventArgs e)
{
+ this.IsEncoding = false;
// TODO Handle Updating the UI
}
@@ -1265,6 +1290,13 @@ namespace HandBrakeWPF.ViewModels
{
this.IsEncoding = false;
+ Execute.OnUIThread(
+ () =>
+ {
+ this.StatusLabel = "Queue Finished";
+ this.IsEncoding = false;
+ });
+
// TODO Handle Updating the UI
}
#endregion
diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs
index 7c3d79994..b5344788d 100644
--- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs
@@ -9,29 +9,29 @@
namespace HandBrakeWPF.ViewModels
{
+ using System;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Windows;
using Caliburn.Micro;
+ using HandBrake.ApplicationServices.EventArgs;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.ViewModels.Interfaces;
+ using Ookii.Dialogs.Wpf;
+
/// <summary>
/// The Preview View Model
/// </summary>
[Export(typeof(IQueueViewModel))]
public class QueueViewModel : ViewModelBase, IQueueViewModel
{
- #region Private Fields
- /// <summary>
- /// Queue Processor Backing field
- /// </summary>
- private readonly IQueueProcessor queueProcessor;
+ #region Constants and Fields
/// <summary>
/// The Error Service Backing field
@@ -39,9 +39,14 @@ namespace HandBrakeWPF.ViewModels
private readonly IErrorService errorService;
/// <summary>
- /// Jobs pending backing field
+ /// Queue Processor Backing field
/// </summary>
- private string jobsPending;
+ private readonly IQueueProcessor queueProcessor;
+
+ /// <summary>
+ /// IsEncoding Backing field
+ /// </summary>
+ private bool isEncoding;
/// <summary>
/// Job Status Backing field.
@@ -49,22 +54,26 @@ namespace HandBrakeWPF.ViewModels
private string jobStatus;
/// <summary>
- /// IsEncoding Backing field
+ /// Jobs pending backing field
/// </summary>
- private bool isEncoding;
+ private string jobsPending;
#endregion
+ #region Constructors and Destructors
+
/// <summary>
/// Initializes a new instance of the <see cref="QueueViewModel"/> class.
/// </summary>
/// <param name="windowManager">
/// The window manager.
/// </param>
- /// <param name="queueProcessor">
+ /// <param name="queueProcessor">
+ ///
/// The Queue Processor Service
/// </param>
- /// <param name="errorService">
+ /// <param name="errorService">
+ ///
/// The Error Service
/// </param>
public QueueViewModel(IWindowManager windowManager, IQueueProcessor queueProcessor, IErrorService errorService)
@@ -76,13 +85,9 @@ namespace HandBrakeWPF.ViewModels
this.JobStatus = "There are no jobs currently encoding";
}
- /// <summary>
- /// Gets QueueJobs.
- /// </summary>
- public ObservableCollection<QueueTask> QueueJobs
- {
- get { return this.queueProcessor.QueueManager.Queue; }
- }
+ #endregion
+
+ #region Properties
/// <summary>
/// Gets or sets a value indicating whether IsEncoding.
@@ -97,7 +102,7 @@ namespace HandBrakeWPF.ViewModels
set
{
this.isEncoding = value;
- this.NotifyOfPropertyChange("IsEncoding");
+ this.NotifyOfPropertyChange(() => IsEncoding);
}
}
@@ -114,7 +119,7 @@ namespace HandBrakeWPF.ViewModels
set
{
this.jobStatus = value;
- this.NotifyOfPropertyChange("JobStatus");
+ this.NotifyOfPropertyChange(() => this.JobStatus);
}
}
@@ -131,22 +136,64 @@ namespace HandBrakeWPF.ViewModels
set
{
this.jobsPending = value;
- this.NotifyOfPropertyChange("JobsPending");
+ this.NotifyOfPropertyChange(() => this.JobsPending);
}
}
/// <summary>
- /// Start Encode
+ /// Gets QueueJobs.
/// </summary>
- public void StartEncode()
+ public ObservableCollection<QueueTask> QueueJobs
{
- if (this.queueProcessor.QueueManager.Count == 0)
+ get
{
- this.errorService.ShowMessageBox("There are no pending jobs.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
+ return this.queueProcessor.QueueManager.Queue;
}
+ }
- this.queueProcessor.Start();
+ #endregion
+
+ #region Public Methods
+
+ /// <summary>
+ /// Clear the Queue
+ /// </summary>
+ public void Clear()
+ {
+ this.queueProcessor.QueueManager.Clear();
+ }
+
+ /// <summary>
+ /// Clear Completed Items
+ /// </summary>
+ public void ClearCompleted()
+ {
+ this.queueProcessor.QueueManager.ClearCompleted();
+ }
+
+ /// <summary>
+ /// Close this window.
+ /// </summary>
+ public void Close()
+ {
+ this.TryClose();
+ }
+
+ /// <summary>
+ /// Handle the On Window Load
+ /// </summary>
+ public override void OnLoad()
+ {
+ this.queueProcessor.JobProcessingStarted += this.queueProcessor_JobProcessingStarted;
+ this.queueProcessor.QueueCompleted += this.queueProcessor_QueueCompleted;
+ this.queueProcessor.QueuePaused += this.queueProcessor_QueuePaused;
+ this.queueProcessor.QueueManager.QueueChanged += this.QueueManager_QueueChanged;
+
+ // Setup the window to the correct state.
+ this.IsEncoding = this.queueProcessor.EncodeService.IsEncoding;
+ this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.QueueManager.Count);
+
+ base.OnLoad();
}
/// <summary>
@@ -167,12 +214,16 @@ namespace HandBrakeWPF.ViewModels
{
if (task.Status == QueueItemStatus.InProgress)
{
- MessageBoxResult result = this.errorService.ShowMessageBox(
- "This encode is currently in progress. If you delete it, the encode will be stoped. Are you sure you wish to proceed?",
- "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question);
+ MessageBoxResult result =
+ this.errorService.ShowMessageBox(
+ "This encode is currently in progress. If you delete it, the encode will be stoped. Are you sure you wish to proceed?",
+ "Warning",
+ MessageBoxButton.YesNo,
+ MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
+ this.queueProcessor.EncodeService.Stop();
this.queueProcessor.QueueManager.Remove(task);
}
}
@@ -185,31 +236,58 @@ namespace HandBrakeWPF.ViewModels
}
/// <summary>
- /// Handle the On Window Load
+ /// Reset the job state to waiting.
/// </summary>
- public override void OnLoad()
+ /// <param name="task">
+ /// The task.
+ /// </param>
+ public void RetryJob(QueueTask task)
{
- this.queueProcessor.JobProcessingStarted += queueProcessor_JobProcessingStarted;
- this.queueProcessor.QueueCompleted += queueProcessor_QueueCompleted;
- this.queueProcessor.QueuePaused += queueProcessor_QueuePaused;
- this.queueProcessor.QueueManager.QueueChanged += QueueManager_QueueChanged;
+ task.Status = QueueItemStatus.Waiting;
+ }
- // Setup the window to the correct state.
- this.IsEncoding = queueProcessor.EncodeService.IsEncoding;
- this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.QueueManager.Count);
+ /// <summary>
+ /// Start Encode
+ /// </summary>
+ public void StartEncode()
+ {
+ if (this.queueProcessor.QueueManager.Count == 0)
+ {
+ this.errorService.ShowMessageBox(
+ "There are no pending jobs.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ return;
+ }
- base.OnLoad();
+ this.queueProcessor.Start();
}
/// <summary>
- /// Close this window.
+ /// Export the Queue to a file.
/// </summary>
- public void Close()
+ public void Export()
{
- this.TryClose();
+ VistaSaveFileDialog dialog = new VistaSaveFileDialog { Filter = "HandBrake Queue Files (*.hbq)|*.hbq"};
+ dialog.ShowDialog();
+
+ this.queueProcessor.QueueManager.BackupQueue(dialog.FileName);
}
/// <summary>
+ /// Import a saved queue
+ /// </summary>
+ public void Import()
+ {
+ VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "HandBrake Queue Files (*.hbq)|*.hbq", CheckFileExists = true };
+ dialog.ShowDialog();
+
+ this.queueProcessor.QueueManager.RestoreQueue(dialog.FileName);
+ }
+
+ #endregion
+
+ #region Methods
+
+ /// <summary>
/// Override the OnActive to run the Screen Loading code in the view model base.
/// </summary>
protected override void OnActivate()
@@ -219,33 +297,41 @@ namespace HandBrakeWPF.ViewModels
}
/// <summary>
- /// Handle the Queue Paused Event
+ /// Handle the Encode Status Changed Event.
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
- /// The EventArgs.
+ /// The EncodeProgressEventArgs.
/// </param>
- private void queueProcessor_QueuePaused(object sender, System.EventArgs e)
+ private void EncodeService_EncodeStatusChanged(
+ object sender, EncodeProgressEventArgs e)
{
- this.JobStatus = "Queue Paused";
- this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.QueueManager.Count);
+ this.JobStatus =
+ string.Format(
+ "Encoding: Pass {0} of {1}, {2:00.00}%, FPS: {3:000.0}, Avg FPS: {4:000.0}, Time Remaining: {5}, Elapsed: {6:hh\\:mm\\:ss}",
+ e.Task,
+ e.TaskCount,
+ e.PercentComplete,
+ e.CurrentFrameRate,
+ e.AverageFrameRate,
+ e.EstimatedTimeLeft,
+ e.ElapsedTime);
}
/// <summary>
- /// Handle the Queue Completed Event
+ /// Handle the Queue Changed Event.
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
- /// The EventArgs.
+ /// The e.
/// </param>
- private void queueProcessor_QueueCompleted(object sender, System.EventArgs e)
+ private void QueueManager_QueueChanged(object sender, EventArgs e)
{
- this.JobStatus = "Queue Completed";
- this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.QueueManager.Count);
+ // TODO
}
/// <summary>
@@ -257,47 +343,47 @@ namespace HandBrakeWPF.ViewModels
/// <param name="e">
/// The QueueProgressEventArgs.
/// </param>
- private void queueProcessor_JobProcessingStarted(object sender, HandBrake.ApplicationServices.EventArgs.QueueProgressEventArgs e)
+ private void queueProcessor_JobProcessingStarted(
+ object sender, QueueProgressEventArgs e)
{
this.JobStatus = "Queue Started";
this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.QueueManager.Count);
- this.queueProcessor.EncodeService.EncodeStatusChanged += EncodeService_EncodeStatusChanged;
+ this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeService_EncodeStatusChanged;
+ this.IsEncoding = true;
}
/// <summary>
- /// Handle the Encode Status Changed Event.
+ /// Handle the Queue Completed Event
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
- /// The EncodeProgressEventArgs.
+ /// The EventArgs.
/// </param>
- private void EncodeService_EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e)
+ private void queueProcessor_QueueCompleted(object sender, EventArgs e)
{
- this.JobStatus = string.Format(
- "Encoding: Pass {0} of {1}, {2:00.00}%, FPS: {3:000.0}, Avg FPS: {4:000.0}, Time Remaining: {5}, Elapsed: {6:hh\\:mm\\:ss}",
- e.Task,
- e.TaskCount,
- e.PercentComplete,
- e.CurrentFrameRate,
- e.AverageFrameRate,
- e.EstimatedTimeLeft,
- e.ElapsedTime);
+ this.JobStatus = "Queue Completed";
+ this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.QueueManager.Count);
+ this.IsEncoding = false;
}
/// <summary>
- /// Handle the Queue Changed Event.
+ /// Handle the Queue Paused Event
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
- /// The e.
+ /// The EventArgs.
/// </param>
- private void QueueManager_QueueChanged(object sender, System.EventArgs e)
+ private void queueProcessor_QueuePaused(object sender, EventArgs e)
{
- // TODO
+ this.JobStatus = "Queue Paused";
+ this.JobsPending = string.Format("{0} jobs pending", this.queueProcessor.QueueManager.Count);
+ this.IsEncoding = false;
}
+
+ #endregion
}
-}
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs
index 8fa221b21..358ebcbf5 100644
--- a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs
@@ -96,7 +96,7 @@ namespace HandBrakeWPF.ViewModels
{
get
{
- return new List<string> { "Same as source", "5", "10", "12", "15", "23.976", "24", "25", "29.97`" };
+ return new List<string> { "Same as source", "5", "10", "12", "15", "23.976", "24", "25", "29.97", "30", "50", "59.94", "60" };
}
}