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#/Functions/Main.cs | 2 +- win/C#/Presets/PresetsHandler.cs | 109 +++++++++++++++++++++++++------------- win/C#/Presets/preset.cs | 2 + win/C#/frmMain.cs | 111 +++++---------------------------------- win/C#/frmUpdater.Designer.cs | 3 ++ 5 files changed, 90 insertions(+), 137 deletions(-) (limited to 'win') diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index acca7e797..6c432208a 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -14,7 +14,7 @@ using System.Xml.Serialization; namespace Handbrake.Functions { - class Main + static class Main { // Private Variables private static readonly XmlSerializer ser = new XmlSerializer(typeof(List)); 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 /// diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 8c3725dae..c40651e12 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -31,7 +31,6 @@ namespace Handbrake private frmQueue queueWindow; private frmPreview qtpreview; private Form splash; - private string lastAction; public int maxWidth; public int maxHeight; @@ -42,10 +41,8 @@ namespace Handbrake // Applicaiton Startup ************************************************ #region Application Startup - public frmMain() { - // Load and setup the splash screen in this thread splash = new frmSplashScreen(); splash.Show(); @@ -124,13 +121,9 @@ namespace Handbrake splash.Dispose(); this.Enabled = true; - // Event Handlers + // Event Handlers and Queue Recovery events(); - - // Queue Recovery queueRecovery(); - - } // Startup Functions @@ -571,8 +564,6 @@ namespace Handbrake } private void loadNormalPreset() { - treeView_presets.Nodes.Find("Normal", true); - foreach (TreeNode treenode in treeView_presets.Nodes) { foreach (TreeNode node in treenode.Nodes) @@ -580,7 +571,7 @@ namespace Handbrake if (node.Text.Equals("Normal")) treeView_presets.SelectedNode = treeView_presets.Nodes[treenode.Index].Nodes[0]; } - } + } } #endregion @@ -1120,7 +1111,6 @@ namespace Handbrake break; } } - /// /// Set the container format options /// @@ -1696,7 +1686,6 @@ namespace Handbrake enableGUI(); } } - private void enableGUI() { try @@ -1808,7 +1797,6 @@ namespace Handbrake #endregion #region DVD Drive Detection - // Source Button Drive Detection private delegate void ProgressUpdateHandler(); private void getDriveInfoThread() { @@ -1975,93 +1963,18 @@ namespace Handbrake #region Public Methods /// - /// Reload the preset panel display + /// Access the preset Handler and setup the preset panel. /// public void loadPresetPanel() { - presetHandler.loadPresetData(); - treeView_presets.Nodes.Clear(); - - TreeNode preset_treeview; - TreeNode rootNode = new TreeNode(); - TreeNode rootNodeTwo = new TreeNode(); - TreeNode childNode; - int workingLevel = 0; - string previousCategory = String.Empty, currentCategory = String.Empty; - - List presetNameList = presetHandler.getBuildInPresets(); - if (presetNameList.Count != 0) - { - foreach (Preset preset in presetNameList) - { - // Handle Root Nodes - - // First Case - No presets have been read yet so setup the root category - if (preset.Level == 1 && currentCategory == String.Empty) - { - rootNode = new TreeNode(preset.Category); - workingLevel = preset.Level; - currentCategory = preset.Category; - previousCategory = preset.Category; - } - - // Second Case - This is the first sub child node. - if (preset.Level == 2 && workingLevel == 1 && currentCategory != preset.Category) - { - rootNodeTwo = new TreeNode(preset.Category); - workingLevel = preset.Level; - currentCategory = preset.Category; - rootNode.Nodes.Add(rootNodeTwo); - } - - // Third Case - Any presets the sub presets detected in the above if statment. - if (preset.Level == 1 && workingLevel == 2) - { - workingLevel = preset.Level; - currentCategory = preset.Category; - } - - // Fourth Case - We've finished this root node and are onto the next root node. - if (preset.Level == 1 && workingLevel == 1 && previousCategory != preset.Category) - { - treeView_presets.Nodes.Add(rootNode); // Add the finished node - - rootNode = new TreeNode(preset.Category); - workingLevel = preset.Level; - currentCategory = preset.Category; - previousCategory = preset.Category; - } - - // Handle Child Nodes - // Add First level child nodes to the current root node - if (preset.Level == 1 && workingLevel == 1 && currentCategory == preset.Category) - { - childNode = new TreeNode(preset.Name); - rootNode.Nodes.Add(childNode); - } - - // Add Second level child nodes to the current sub root node - if (preset.Level == 2 && workingLevel == 2 && currentCategory == preset.Category) - { - childNode = new TreeNode(preset.Name); - rootNodeTwo.Nodes.Add(childNode); - } - } - - // Add the final root node which does not get added above. - treeView_presets.Nodes.Add(rootNode); - } - - // User Presets - List presetNames = presetHandler.getUserPresetNames(); - foreach (string preset in presetNames) - { - preset_treeview = new TreeNode(preset) { ForeColor = Color.Black }; - - // Now Fill Out List View with Items - treeView_presets.Nodes.Add(preset_treeview); - } + presetHandler.getPresetPanel(ref treeView_presets); + treeView_presets.Update(); } + + /// + /// Either Encode or Scan was last performed. + /// + public string lastAction { get; set; } #endregion #region overrides @@ -2083,6 +1996,6 @@ namespace Handbrake } #endregion - // This is the END of the road ------------------------------------------------------------------------------ + // This is the END of the road **************************************** } -} +} \ No newline at end of file diff --git a/win/C#/frmUpdater.Designer.cs b/win/C#/frmUpdater.Designer.cs index 336b29b32..f5c903a95 100644 --- a/win/C#/frmUpdater.Designer.cs +++ b/win/C#/frmUpdater.Designer.cs @@ -84,6 +84,7 @@ namespace Handbrake // this.btn_skip.AutoSize = true; this.btn_skip.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btn_skip.BackColor = System.Drawing.Color.Transparent; this.btn_skip.FlatAppearance.BorderColor = System.Drawing.Color.Black; this.btn_skip.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btn_skip.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); @@ -99,6 +100,7 @@ namespace Handbrake // this.btn_installUpdate.AutoSize = true; this.btn_installUpdate.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btn_installUpdate.BackColor = System.Drawing.Color.Transparent; this.btn_installUpdate.FlatAppearance.BorderColor = System.Drawing.Color.Black; this.btn_installUpdate.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btn_installUpdate.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); @@ -114,6 +116,7 @@ namespace Handbrake // this.btn_remindLater.AutoSize = true; this.btn_remindLater.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btn_remindLater.BackColor = System.Drawing.Color.Transparent; this.btn_remindLater.FlatAppearance.BorderColor = System.Drawing.Color.Black; this.btn_remindLater.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btn_remindLater.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); -- cgit v1.2.3