summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF
diff options
context:
space:
mode:
authorsr55 <[email protected]>2016-03-26 19:09:12 +0000
committersr55 <[email protected]>2016-03-26 19:09:12 +0000
commitce9543f4b6ac63f413287081d5ee4bd1ab14f56b (patch)
treed6bba978008b681498375bb2e377acf0fea53ea1 /win/CS/HandBrakeWPF
parent441d09f5e86b43135958beae4cc2359fa675eb2d (diff)
WinGui: Add a new JSON file type to the queue export functionality. This exports the standardised JSON format that can be imported into the CLI.
Note, the GUI can not yet import the JSON formatted queue file. The old hbq format is still there for that.
Diffstat (limited to 'win/CS/HandBrakeWPF')
-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
5 files changed, 100 insertions, 3 deletions
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);