summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj1
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/Json/Queue/Task.cs24
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj1
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/Factories/QueueFactory.cs55
-rw-r--r--win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs8
-rw-r--r--win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs24
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs15
7 files changed, 125 insertions, 3 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
index 91342b059..c3f86fb4d 100644
--- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
+++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
@@ -119,6 +119,7 @@
<Compile Include="Interop\Json\Presets\HBPreset.cs" />
<Compile Include="Interop\Json\Presets\PresetCategory.cs" />
<Compile Include="Interop\Json\Presets\PresetTransportContainer.cs" />
+ <Compile Include="Interop\Json\Queue\Task.cs" />
<Compile Include="Interop\Json\Shared\PAR.cs" />
<Compile Include="Interop\Json\Encode\Audio.cs" />
<Compile Include="Interop\Json\Encode\AudioTrack.cs" />
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Json/Queue/Task.cs b/win/CS/HandBrake.ApplicationServices/Interop/Json/Queue/Task.cs
new file mode 100644
index 000000000..e1805c3d9
--- /dev/null
+++ b/win/CS/HandBrake.ApplicationServices/Interop/Json/Queue/Task.cs
@@ -0,0 +1,24 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="Task.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The task.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Interop.Json.Queue
+{
+ using HandBrake.ApplicationServices.Interop.Json.Encode;
+
+ /// <summary>
+ /// The task.
+ /// </summary>
+ public class Task
+ {
+ /// <summary>
+ /// Gets or sets the job.
+ /// </summary>
+ public JsonEncodeObject Job { get; set; }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index f5c0fcb70..797663f9b 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -190,6 +190,7 @@
<Compile Include="Services\Encode\EventArgs\EncodeCompletedEventArgs.cs" />
<Compile Include="Services\Encode\EventArgs\EncodeProgressEventArgs.cs" />
<Compile Include="Services\Encode\Factories\EncodeFactory.cs" />
+ <Compile Include="Services\Encode\Factories\QueueFactory.cs" />
<Compile Include="Services\Encode\Factories\VideoLevelFactory.cs" />
<Compile Include="Services\Encode\Factories\VideoPresetFactory.cs" />
<Compile Include="Services\Encode\Factories\VideoProfileFactory.cs" />
diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/QueueFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/QueueFactory.cs
new file mode 100644
index 000000000..1046dec4a
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/QueueFactory.cs
@@ -0,0 +1,55 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="QueueFactory.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Defines the QueueFactory type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Services.Encode.Factories
+{
+ using System.Collections.Generic;
+
+ using HandBrake.ApplicationServices.Interop.Json.Queue;
+ using HandBrake.ApplicationServices.Model;
+
+ using HandBrakeWPF.Services.Encode.Model;
+
+ using Newtonsoft.Json;
+
+ /// <summary>
+ /// The queue factory.
+ /// </summary>
+ public class QueueFactory
+ {
+ /// <summary>
+ /// For a givent set of tasks, return the Queue JSON that can be used for the CLI.
+ /// </summary>
+ /// <param name="tasks">
+ /// The tasks.
+ /// </param>
+ /// <param name="configuration">
+ /// The configuration.
+ /// </param>
+ /// <returns>
+ /// The <see cref="string"/>.
+ /// </returns>
+ public static string GetQueueJson(List<EncodeTask> tasks, HBConfiguration configuration)
+ {
+ JsonSerializerSettings settings = new JsonSerializerSettings
+ {
+ NullValueHandling = NullValueHandling.Ignore,
+ };
+
+ List<Task> queueJobs = new List<Task>();
+ foreach (var item in tasks)
+ {
+ Task task = new Task { Job = EncodeFactory.Create(item, configuration) };
+ queueJobs.Add(task);
+ }
+
+ return JsonConvert.SerializeObject(queueJobs, Formatting.Indented, settings);
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs
index 1e86d06ba..ffc9107bb 100644
--- a/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs
+++ b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs
@@ -107,6 +107,14 @@ namespace HandBrakeWPF.Services.Queue.Interfaces
void BackupQueue(string exportPath);
/// <summary>
+ /// Export the Queue the standardised JSON format.
+ /// </summary>
+ /// <param name="exportPath">
+ /// The export path.
+ /// </param>
+ void ExportJson(string exportPath);
+
+ /// <summary>
/// Checks the current queue for an existing instance of the specified destination.
/// </summary>
/// <param name="destination">
diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
index 59b321d7b..46df938ce 100644
--- a/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
+++ b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
@@ -18,7 +18,12 @@ namespace HandBrakeWPF.Services.Queue
using System.Windows;
using System.Xml.Serialization;
+ using HandBrake.ApplicationServices.Model;
+
+ using HandBrakeWPF.Factories;
using HandBrakeWPF.Properties;
+ using HandBrakeWPF.Services.Encode.Factories;
+ using HandBrakeWPF.Services.Encode.Model;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Queue.Model;
using HandBrakeWPF.Utilities;
@@ -240,6 +245,25 @@ namespace HandBrakeWPF.Services.Queue
}
/// <summary>
+ /// Export the Queue the standardised JSON format.
+ /// </summary>
+ public void ExportJson(string exportPath)
+ {
+ List<QueueTask> jobs = this.queue.Where(item => item.Status != QueueItemStatus.Completed).ToList();
+ List<EncodeTask> workUnits = jobs.Select(job => job.Task).ToList();
+ HBConfiguration config = HBConfigurationFactory.Create(); // Default to current settings for now. These will hopefully go away in the future.
+
+ string json = QueueFactory.GetQueueJson(workUnits, config);
+
+ using (var strm = new StreamWriter(exportPath, false))
+ {
+ strm.Write(json);
+ strm.Close();
+ strm.Dispose();
+ }
+ }
+
+ /// <summary>
/// Checks the current queue for an existing instance of the specified destination.
/// </summary>
/// <param name="destination">
diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs
index e3dccd32c..3ad23d605 100644
--- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs
@@ -12,6 +12,7 @@ namespace HandBrakeWPF.ViewModels
using System;
using System.Collections.Generic;
using System.ComponentModel;
+ using System.IO;
using System.Linq;
using System.Windows;
@@ -332,14 +333,22 @@ namespace HandBrakeWPF.ViewModels
{
SaveFileDialog dialog = new SaveFileDialog
{
- Filter = "HandBrake Queue Files (*.hbq)|*.hbq",
+ Filter = "Legacy Queue Files (*.hbq)|*.hbq|Json for CLI (*.json)|*.json",
OverwritePrompt = true,
DefaultExt = ".hbq",
AddExtension = true
};
+
if (dialog.ShowDialog() == true)
{
- this.queueProcessor.BackupQueue(dialog.FileName);
+ if (Path.GetExtension(dialog.FileName).ToLower().Trim() == ".json")
+ {
+ this.queueProcessor.ExportJson(dialog.FileName);
+ }
+ else
+ {
+ this.queueProcessor.BackupQueue(dialog.FileName);
+ }
}
}
@@ -348,7 +357,7 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public void Import()
{
- OpenFileDialog dialog = new OpenFileDialog { Filter = "HandBrake Queue Files (*.hbq)|*.hbq", CheckFileExists = true };
+ OpenFileDialog dialog = new OpenFileDialog { Filter = "Legacy Queue Files (*.hbq)|*.hbq", CheckFileExists = true };
if (dialog.ShowDialog() == true)
{
this.queueProcessor.RestoreQueue(dialog.FileName);