From 60a94bdb9e2dc1cb8678d0050559f88f3bcee492 Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 23 Apr 2009 23:26:31 +0000 Subject: WinGui: - Moved the code which loads the preset panel into the PresetHandler class. - rewritten the preset panel loader so that it's easier to understand. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2352 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Presets/PresetsHandler.cs | 109 ++++++++++++++++++++++++++------------- win/C#/Presets/preset.cs | 2 + 2 files changed, 74 insertions(+), 37 deletions(-) (limited to 'win/C#/Presets') diff --git a/win/C#/Presets/PresetsHandler.cs b/win/C#/Presets/PresetsHandler.cs index e29c4d227..657807c10 100644 --- a/win/C#/Presets/PresetsHandler.cs +++ b/win/C#/Presets/PresetsHandler.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Windows.Forms; using System.IO; using System.Text.RegularExpressions; using System.Diagnostics; using System.Xml.Serialization; +using System.Collections; namespace Handbrake.Presets { @@ -24,7 +26,7 @@ namespace Handbrake.Presets { if (checkIfPresetExists(presetName) == false) { - Preset newPreset = new Preset {Name = presetName, Query = query, PictureSettings = pictureSettings}; + Preset newPreset = new Preset { Name = presetName, Query = query, PictureSettings = pictureSettings }; user_presets.Add(newPreset); updateUserPresetsFile(); return true; @@ -88,37 +90,11 @@ namespace Handbrake.Presets } } - /// - /// Get a List of all the built in preset names. - /// - /// List of preset names - public List getBuildInPresets() - { - return presets; - } - - /// - /// Get a List of all the User preset names. - /// - /// List of preset names - public List getUserPresetNames() - { - List names = new List(); - - // User Presets - foreach (Preset item in user_presets) - { - names.Add(item.Name); - } - - return names; - } - /// /// Return the CLI query for a preset name given in name /// /// String, The preset's name - /// String, the CLI query for the given preset name + /// String, the CLI query for the given preset name not public Preset getPreset(string name) { // Built In Presets @@ -146,12 +122,9 @@ namespace Handbrake.Presets // Create a new tempory file and execute the CLI to get the built in presets. string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe"); string presetsPath = Path.Combine(Path.GetTempPath(), "temp_presets.dat"); - string strCmdLine = String.Format(@"cmd /c """"{0}"" --preset-list >""{1}"" 2>&1""", handbrakeCLIPath, presetsPath); - ProcessStartInfo hbGetPresets = new ProcessStartInfo("CMD.exe", strCmdLine) - {WindowStyle = ProcessWindowStyle.Hidden}; - + ProcessStartInfo hbGetPresets = new ProcessStartInfo("CMD.exe", strCmdLine) { WindowStyle = ProcessWindowStyle.Hidden }; Process hbproc = Process.Start(hbGetPresets); if (hbproc != null) { @@ -163,9 +136,11 @@ namespace Handbrake.Presets // Clear the current built in presets and now parse the tempory presets file. presets.Clear(); string filePath = Path.Combine(Path.GetTempPath(), "temp_presets.dat"); + if (File.Exists(filePath)) { StreamReader presetInput = new StreamReader(filePath); + int level = 1; string category = String.Empty; string level_1_category = String.Empty; @@ -173,26 +148,26 @@ namespace Handbrake.Presets while (!presetInput.EndOfStream) { string line = presetInput.ReadLine(); - if (line.Contains("<") && !line.Contains("<<")) + if (line.Contains("<") && !line.Contains("<<")) // Found the beginning of a preset block { level = 1; category = line.Replace("<", "").Trim(); level_1_category = category; } - if (line.Contains("<<")) + if (line.Contains("<<")) // found a sub preset block { level = 2; category = line.Replace("<<", "").Trim(); } - if (line.Trim().Contains(">>")) + if (line.Trim().Contains(">>")) // End of sub preset block { level = 1; category = level_1_category; } - if (line.Contains("+")) + if (line.Contains("+")) // A Preset { Regex r = new Regex("(: )"); // Split on hyphens. string[] presetName = r.Split(line); @@ -201,6 +176,7 @@ namespace Handbrake.Presets { Level = level, Category = category, + TopCategory = level_1_category, Name = presetName[0].Replace("+", "").Trim(), Query = presetName[2] }; @@ -219,7 +195,7 @@ namespace Handbrake.Presets /// Load in the preset data from presets.xml and user_presets.xml /// Load it into the 2 arraylist's presets and user_presets /// - public void loadPresetData() + private void loadPresetData() { // First clear the presets arraylists presets.Clear(); @@ -260,6 +236,65 @@ namespace Handbrake.Presets } } + /// + /// Setup the frmMain preset panel + /// + /// + public void getPresetPanel(ref TreeView presetPanel) + { + this.loadPresetData(); + presetPanel.Nodes.Clear(); + + if (presets.Count != 0) + { + string category = presets[0].Category; + TreeNode rootNode = new TreeNode(presets[0].Category); + TreeNode childNode = null; + Boolean addChildNode = false; + + foreach (Preset preset in presets) + { + // Deal with Root + if (preset.Category == category && preset.TopCategory == category) + rootNode.Nodes.Add(preset.Name); + else if (preset.Category != category && preset.TopCategory == category) + // Deal with child nodes for that root + { + if (childNode == null) // For the first child node + childNode = new TreeNode(preset.Category); + + childNode.Nodes.Add(preset.Name); + addChildNode = true; + } + else if (preset.Category != category && preset.TopCategory != category && preset.Level == 1) + // Deal with changing root nodes + { + // If we find there are child nodes, add them to the current root node set before adding the rootnode to the panel. + if (addChildNode) + { + rootNode.Nodes.Add(childNode); + childNode = null; + addChildNode = false; + } + // Add the current rootnodes to the panel, and prepare for a new category of presets + presetPanel.Nodes.Add(rootNode); + rootNode = new TreeNode(preset.Category); + rootNode.Nodes.Add(preset.Name); + + category = preset.Category; + } + } + presetPanel.Nodes.Add(rootNode); // Add the final set of nodes + } + + // User Presets + foreach (Preset preset in user_presets) + { + TreeNode preset_treeview = new TreeNode(preset.Name) { ForeColor = Color.Black }; + presetPanel.Nodes.Add(preset_treeview); + } + } + /// /// Updates the presets.xml file which contains the built in presets /// It takes the List of Presets and converts them into XML which is stored in presets.xml diff --git a/win/C#/Presets/preset.cs b/win/C#/Presets/preset.cs index 34689327b..4431c9ce1 100644 --- a/win/C#/Presets/preset.cs +++ b/win/C#/Presets/preset.cs @@ -14,6 +14,8 @@ namespace Handbrake.Presets /// public string Category { get; set; } + public string TopCategory { get; set; } + /// /// Get or Set the preset name /// -- cgit v1.2.3