<Application x:Class="HandBrakeWPF.App"\r
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:HandBrakeWPF.Startup">\r
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:HandBrakeWPF.Startup"\r
+ ShutdownMode="OnMainWindowClose">\r
<Application.Resources>\r
<ResourceDictionary>\r
<ResourceDictionary.MergedDictionaries>\r
/// The window.\r
/// </param>\r
void DisplayWindow(ShellWindow window);\r
+\r
+ /// <summary>\r
+ /// Checks with the use if this window can be closed.\r
+ /// </summary>\r
+ /// <returns>\r
+ /// Returns true if the window can be closed.\r
+ /// </returns>\r
+ bool CanClose();\r
}\r
}\r
this.scanService.ScanStatusChanged += this.ScanStatusChanged;\r
this.queueProcessor.JobProcessingStarted += this.QueueProcessorJobProcessingStarted;\r
this.queueProcessor.QueueCompleted += this.QueueCompleted;\r
- this.queueProcessor.QueuePaused += this.QueuePaused;\r
this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;\r
\r
this.Presets = this.presetService.Presets;\r
this.scanService.ScanStatusChanged -= this.ScanStatusChanged;\r
\r
this.queueProcessor.QueueCompleted -= this.QueueCompleted;\r
- this.queueProcessor.QueuePaused -= this.QueuePaused;\r
this.queueProcessor.JobProcessingStarted -= this.QueueProcessorJobProcessingStarted;\r
this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;\r
}\r
}\r
\r
QueueTask task = new QueueTask { Task = new EncodeTask(this.CurrentTask) };\r
- this.queueProcessor.QueueManager.Add(task);\r
+ if (!this.queueProcessor.QueueManager.CheckForDestinationPathDuplicates(task.Task.Destination))\r
+ {\r
+ this.queueProcessor.QueueManager.Add(task);\r
+ } \r
+ else\r
+ {\r
+ this.errorService.ShowMessageBox("There are jobs on the queue with the same destination path. Please choose a different path for this job.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);\r
+ }\r
+ \r
\r
if (!this.IsEncoding)\r
{\r
/// </summary>\r
public void StartEncode()\r
{\r
+ if (this.queueProcessor.IsProcessing)\r
+ {\r
+ this.errorService.ShowMessageBox("HandBrake is already encoding.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);\r
+ return;\r
+ }\r
+\r
// Check if we already have jobs, and if we do, just start the queue.\r
if (this.queueProcessor.QueueManager.Count != 0)\r
{\r
return;\r
}\r
\r
- if (this.queueProcessor.IsProcessing)\r
- {\r
- this.errorService.ShowMessageBox("HandBrake is already encoding.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);\r
- return;\r
- }\r
\r
if (File.Exists(this.Destination))\r
{\r
/// </summary>\r
public void StopEncode()\r
{\r
+ this.queueProcessor.Pause();\r
this.encodeService.Stop();\r
}\r
\r
this.ProgramStatusLabel = "Preparing to encode ...";\r
this.IsEncoding = true;\r
});\r
-\r
- // TODO Handle Updating the UI\r
- }\r
-\r
- /// <summary>\r
- /// The Queue has been paused handler\r
- /// </summary>\r
- /// <param name="sender">\r
- /// The Sender\r
- /// </param>\r
- /// <param name="e">\r
- /// The EventArgs\r
- /// </param>\r
- private void QueuePaused(object sender, EventArgs e)\r
- {\r
- this.IsEncoding = false;\r
- // TODO Handle Updating the UI\r
}\r
\r
/// <summary>\r
this.ProgramStatusLabel = "Queue Finished";\r
this.IsEncoding = false;\r
});\r
-\r
- // TODO Handle Updating the UI\r
}\r
\r
/// <summary>\r
namespace HandBrakeWPF.ViewModels\r
{\r
using System.ComponentModel.Composition;\r
+ using System.Windows;\r
+\r
+ using Caliburn.Micro;\r
+\r
+ using HandBrake.ApplicationServices.Services.Interfaces;\r
\r
using HandBrakeWPF.Model;\r
+ using HandBrakeWPF.Services.Interfaces;\r
using HandBrakeWPF.ViewModels.Interfaces;\r
\r
/// <summary>\r
[Export(typeof(IShellViewModel))]\r
public class ShellViewModel : ViewModelBase, IShellViewModel\r
{\r
+ /// <summary>\r
+ /// Backing field for the error service.\r
+ /// </summary>\r
+ private readonly IErrorService errorService;\r
+\r
#region Constants and Fields\r
\r
/// <summary>\r
/// <summary>\r
/// Initializes a new instance of the <see cref="ShellViewModel"/> class.\r
/// </summary>\r
- public ShellViewModel()\r
+ /// <param name="errorService">\r
+ /// The error Service.\r
+ /// </param>\r
+ public ShellViewModel(IErrorService errorService)\r
{\r
+ this.errorService = errorService;\r
this.showMainWindow = true;\r
this.showOptions = false;\r
}\r
{\r
this.ShowOptions = true;\r
this.ShowMainWindow = false;\r
- } \r
+ }\r
else\r
{\r
this.ShowMainWindow = true;\r
}\r
\r
#endregion\r
+\r
+ /// <summary>\r
+ /// Checks with the use if this window can be closed.\r
+ /// </summary>\r
+ /// <returns>\r
+ /// Returns true if the window can be closed.\r
+ /// </returns>\r
+ public bool CanClose()\r
+ {\r
+ IQueueProcessor processor = IoC.Get<IQueueProcessor>();\r
+ if (processor.EncodeService.IsEncoding)\r
+ {\r
+ MessageBoxResult result =\r
+ errorService.ShowMessageBox(\r
+ "An Encode is currently running. Exiting HandBrake will stop this encode.\nAre you sure you wish to continue?",\r
+ "Warning",\r
+ MessageBoxButton.YesNo,\r
+ MessageBoxImage.Warning);\r
+\r
+ if (result == MessageBoxResult.Yes)\r
+ {\r
+ processor.Pause();\r
+ processor.EncodeService.Stop();\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+ }\r
}\r
}
\ No newline at end of file
\r
<ListBox.ContextMenu>\r
<ContextMenu>\r
- <MenuItem cal:Message.Attach="[Event Click] = [Action Import]" Header="Import Queue" />\r
- <MenuItem cal:Message.Attach="[Event Click] = [Action Export]" Header="Export Queue" />\r
- <Separator />\r
<MenuItem cal:Message.Attach="[Event Click] = [Action Clear]" Header="Clear" />\r
<MenuItem cal:Message.Attach="[Event Click] = [Action ClearCompleted]" Header="Clear Completed" />\r
+ <Separator />\r
+ <MenuItem cal:Message.Attach="[Event Click] = [Action Import]" Header="Import Queue" />\r
+ <MenuItem cal:Message.Attach="[Event Click] = [Action Export]" Header="Export Queue" />\r
</ContextMenu>\r
</ListBox.ContextMenu>\r
\r
<TextBlock FontWeight="Bold" Text="Destination: " />\r
<TextBlock Text="{Binding Task.Destination, Converter={StaticResource filePathToFilenameConverter}}" />\r
</StackPanel>\r
-\r
- <StackPanel Orientation="Horizontal">\r
- <TextBlock FontWeight="Bold" Text="Status: " />\r
- <TextBlock Text="{Binding Status, Converter={StaticResource enumComboConverter}}" />\r
- </StackPanel>\r
</StackPanel>\r
\r
<!-- Delete -->\r
{\r
using System.Windows;\r
\r
+ using HandBrakeWPF.ViewModels.Interfaces;\r
+\r
/// <summary>\r
/// Interaction logic for ShellView.xaml\r
/// </summary>\r
{\r
this.InitializeComponent();\r
}\r
+\r
+ /// <summary>\r
+ /// Check with the user before closing.\r
+ /// </summary>\r
+ /// <param name="e">\r
+ /// The CancelEventArgs.\r
+ /// </param>\r
+ protected override void OnClosing(System.ComponentModel.CancelEventArgs e)\r
+ {\r
+ bool canClose = ((IShellViewModel)this.DataContext).CanClose();\r
+ if (!canClose)\r
+ {\r
+ e.Cancel = true;\r
+ }\r
+\r
+ base.OnClosing(e);\r
+ }\r
}\r
}\r