summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2008-10-25 20:36:04 +0000
committersr55 <[email protected]>2008-10-25 20:36:04 +0000
commit54f291c822357595718264fe167cf63c25e5fbb8 (patch)
tree1c555cf958f438c87511488d74ea6dd29d918a98 /win
parent4539e3ea182732e2faa265dbecc1029ed0f3fa72 (diff)
WinGui:
- Nested Presets bar (Built-in presets only) - Both user and built-in presets are now stored in XML files - Preset bar now has right-click menu with: Expand All, Collapse All and Delete Known Issues: - When a preset is removed, all items in the preset bar with child presets are collapsed. - Right Click menu only works if the preset was selected before right clicking. Code is probably a bit buggy so all feedback on this new bar is welcome. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1866 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r--win/C#/Functions/Presets.cs275
-rw-r--r--win/C#/HandBrakeCS.csproj3
-rw-r--r--win/C#/Presets/PresetsHandler.cs317
-rw-r--r--win/C#/Presets/preset.cs60
-rw-r--r--win/C#/frmAddPreset.cs6
-rw-r--r--win/C#/frmMain.Designer.cs80
-rw-r--r--win/C#/frmMain.cs158
-rw-r--r--win/C#/frmMain.resx21
8 files changed, 588 insertions, 332 deletions
diff --git a/win/C#/Functions/Presets.cs b/win/C#/Functions/Presets.cs
deleted file mode 100644
index 20106727b..000000000
--- a/win/C#/Functions/Presets.cs
+++ /dev/null
@@ -1,275 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Windows.Forms;
-using System.IO;
-using System.Text.RegularExpressions;
-using System.Diagnostics;
-
-namespace Handbrake.Functions
-{
- public class Presets
- {
- List<string> presets = new List<string>();
- List<string> user_presets = new List<string>();
-
- /// <summary>
- /// Add a new preset to the system
- /// </summary>
- /// <param name="presetName">String, The name of the new preset</param>
- /// <param name="query">String, the CLI query for the new preset</param>
- public Boolean addPreset(string presetName, string query)
- {
- if (checkIfPresetExists(presetName) == false)
- {
- String preset = "+ " + presetName + ": " + query;
- user_presets.Add(preset);
- addPresetToFile(preset);
- return true;
- }
- else
- {
- MessageBox.Show("Sorry, that preset name already exists. Please choose another!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
-
- /// <summary>
- /// Remove a preset with a given name from either the built in or user preset list.
- /// </summary>
- /// <param name="name">String, the preset name</param>
- public void remove(string name)
- {
- List<string> newPresets = new List<string>();
- List<string> newUserPresets = new List<string>();
-
- // Built In Presets
- foreach (string item in presets)
- {
- string x = item.Replace("+ ", "");
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(x);
- if (presetName[0] != name)
- newPresets.Add(item);
- }
-
- // User Presets
- foreach (string item in user_presets)
- {
- string x = item.Replace("+ ", "");
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(x);
- if (presetName[0] != name)
- newUserPresets.Add(item);
- }
-
- // Now, Update the presets.dat and user_presets.dat file with the new items.
- string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";
- string presetsFile = Application.StartupPath.ToString() + "\\presets.dat";
-
- // Rebuild the presets.dat file
- StreamWriter line = new StreamWriter(presetsFile);
- foreach (string item in newPresets)
- {
- line.WriteLine("+ " + item);
- }
- line.Close();
- line.Dispose();
-
- // Rebuild the user_presets.dat file
- line = new StreamWriter(userPresets);
- foreach (string item in newUserPresets)
- {
- line.WriteLine("+ " + item);
- }
- line.Close();
- line.Dispose();
- }
-
- /// <summary>
- /// Get a List of all the built in preset names.
- /// </summary>
- /// <returns>List<String> of preset names</returns>
- public List<string> getBuildInPresetNames()
- {
- List<string> names = new List<string>();
-
- // Built In Presets
- foreach (string item in presets)
- {
- string x = item.Replace("+ ", "");
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(x);
- names.Add(presetName[0]);
-
- }
- return names;
- }
-
- /// <summary>
- /// Get a List of all the User preset names.
- /// </summary>
- /// <returns>List<String> of preset names</returns>
- public List<string> getUserPresetNames()
- {
- List<string> names = new List<string>();
-
- // User Presets
- foreach (string item in user_presets)
- {
- string x = item.Replace("+ ", "");
- Regex r = new Regex("(: )");
- string[] presetName = r.Split(x);
- names.Add(presetName[0]);
-
- }
-
- return names;
- }
-
- /// <summary>
- /// Return the CLI query for a preset name given in name
- /// </summary>
- /// <param name="name">String, The preset's name</param>
- /// <returns>String, the CLI query for the given preset name</returns>
- public string getCliForPreset(string name)
- {
- // Built In Presets
- foreach (string item in presets)
- {
- string x = item.Replace("+ ", "");
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(x);
- if (presetName[0] == name)
- return presetName[2];
- }
-
- // User Presets
- foreach (string item in user_presets)
- {
- string x = item.Replace("+ ", "");
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(x);
- if (presetName[0] == name)
- return presetName[2];
- }
-
- return null;
- }
-
- /// <summary>
- /// Update the presets.dat file with the latest version of HandBrake's presets from the CLI
- /// </summary>
- public void grabCLIPresets()
- {
- string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
- string presetsPath = Path.Combine(Application.StartupPath, "presets.dat");
-
- string strCmdLine = String.Format(@"cmd /c """"{0}"" --preset-list >""{1}"" 2>&1""", handbrakeCLIPath, presetsPath);
-
- ProcessStartInfo hbGetPresets = new ProcessStartInfo("CMD.exe", strCmdLine);
- hbGetPresets.WindowStyle = ProcessWindowStyle.Hidden;
-
- Process hbproc = Process.Start(hbGetPresets);
- hbproc.WaitForExit();
- hbproc.Dispose();
- hbproc.Close();
- }
-
- /// <summary>
- /// Load in the preset data from presets.dat and user_presets.dat
- /// Load it into the 2 arraylist's presets and user_presets
- /// </summary>
- public void loadPresetFiles()
- {
- // First clear the presets arraylists
- presets.Clear();
- user_presets.Clear();
-
- // Load in the built in presets from presets.dat
- // We'll store them in the array in the format: presetName: ClI Query
- string filePath = Application.StartupPath.ToString() + "\\presets.dat";
- if (File.Exists(filePath))
- {
- StreamReader presetInput = new StreamReader(filePath);
- while (!presetInput.EndOfStream)
- {
- string line = presetInput.ReadLine();
-
- if (line.Contains("+"))
- presets.Add(line.Replace("+ ", "").Trim());
- }
- presetInput.Close();
- presetInput.Dispose();
- }
-
- // Load in the users presets from user_presets.dat
- filePath = Application.StartupPath.ToString() + "\\user_presets.dat";
- if (File.Exists(filePath))
- {
- StreamReader presetInput = new StreamReader(filePath);
- while (!presetInput.EndOfStream)
- {
- if ((char)presetInput.Peek() == '+')
- user_presets.Add(presetInput.ReadLine().Replace("+ ", ""));
- else
- presetInput.ReadLine();
- }
- presetInput.Close();
- presetInput.Dispose();
- }
- }
-
- // Add a single preset to user_presets.dat
- private void addPresetToFile(string preset)
- {
- string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";
- try
- {
- // Create a StreamWriter and open the file
- StreamWriter line = File.AppendText(userPresets);
-
- // Generate and write the preset string to the file
- line.WriteLine(preset);
-
- // close the stream
- line.Close();
- line.Dispose();
- }
- catch (Exception exc)
- {
- MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.\n Error Information: \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- }
- }
-
- // Check if a preset already exists in either the built in or user presets
- private Boolean checkIfPresetExists(string name)
- {
- if (name == string.Empty)
- return true;
-
- // Built In Presets
- foreach (string item in presets)
- {
- string x = item.Replace("+ ", "");
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(x);
- if (presetName[0] == name)
- return true;
- }
-
- // User Presets
- foreach (string item in user_presets)
- {
- string x = item.Replace("+ ", "");
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(x);
- if (presetName[0] == name)
- return true;
- }
-
- return false;
- }
- }
-
-} \ No newline at end of file
diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj
index 5a4c605b9..4ff6d0a23 100644
--- a/win/C#/HandBrakeCS.csproj
+++ b/win/C#/HandBrakeCS.csproj
@@ -150,7 +150,8 @@
<Compile Include="frmMain\QueryGenerator.cs" />
<Compile Include="Functions\SystemInfo.cs" />
<Compile Include="Functions\Main.cs" />
- <Compile Include="Functions\Presets.cs" />
+ <Compile Include="Presets\preset.cs" />
+ <Compile Include="Presets\PresetsHandler.cs" />
<Compile Include="Functions\Queue.cs" />
<Compile Include="Functions\AppcastReader.cs" />
<Compile Include="Functions\Encode.cs" />
diff --git a/win/C#/Presets/PresetsHandler.cs b/win/C#/Presets/PresetsHandler.cs
new file mode 100644
index 000000000..172125a9f
--- /dev/null
+++ b/win/C#/Presets/PresetsHandler.cs
@@ -0,0 +1,317 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Forms;
+using System.IO;
+using System.Text.RegularExpressions;
+using System.Diagnostics;
+using System.Xml.Serialization;
+
+namespace Handbrake.Presets
+{
+ public class PresetsHandler
+ {
+ List<Preset> presets = new List<Preset>(); // Category+Level+Preset Name: Query
+ List<Preset> user_presets = new List<Preset>(); // Preset Name: Query
+ private static XmlSerializer ser = new XmlSerializer(typeof(List<Preset>));
+
+ /// <summary>
+ /// Add a new preset to the system
+ /// </summary>
+ /// <param name="presetName">String, The name of the new preset</param>
+ /// <param name="query">String, the CLI query for the new preset</param>
+ public Boolean addPreset(string presetName, string query)
+ {
+ if (checkIfPresetExists(presetName) == false)
+ {
+ Preset newPreset = new Preset();
+ newPreset.Name = presetName;
+ newPreset.Query = query;
+ user_presets.Add(newPreset);
+ updateUserPresetsFile();
+ return true;
+ }
+ else
+ {
+ MessageBox.Show("Sorry, that preset name already exists. Please choose another!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Remove a preset with a given name from either the built in or user preset list.
+ /// </summary>
+ /// <param name="name">String, the preset name</param>
+ public void remove(string name)
+ {
+ List<Preset> newPresets = new List<Preset>();
+ List<Preset> newUserPresets = new List<Preset>();
+
+ // Built In Presets
+ foreach (Preset item in presets)
+ {
+ if (item.Name != name)
+ {
+ newPresets.Add(item);
+ }
+ }
+ presets = newPresets;
+
+ // User Presets
+ foreach (Preset item in user_presets)
+ {
+ if (item.Name != name)
+ {
+ newUserPresets.Add(item);
+ }
+ }
+ user_presets = newUserPresets;
+
+ // Now, Update the presets.xml and user_presets.xml file with the new items.
+ string userPresets = Application.StartupPath.ToString() + "\\user_presets.xml";
+ string presetsFile = Application.StartupPath.ToString() + "\\presets.xml";
+
+ // Rebuild the user_presets.xml file
+ updateUserPresetsFile();
+ updatePresetsFile();
+ }
+
+ /// <summary>
+ /// Get a List of all the built in preset names.
+ /// </summary>
+ /// <returns>List<String> of preset names</returns>
+ public List<Preset> getBuildInPresets()
+ {
+ return presets;
+ }
+
+ /// <summary>
+ /// Get a List of all the User preset names.
+ /// </summary>
+ /// <returns>List<String> of preset names</returns>
+ public List<string> getUserPresetNames()
+ {
+ List<string> names = new List<string>();
+
+ // User Presets
+ foreach (Preset item in user_presets)
+ {
+ names.Add(item.Name);
+ }
+
+ return names;
+ }
+
+ /// <summary>
+ /// Return the CLI query for a preset name given in name
+ /// </summary>
+ /// <param name="name">String, The preset's name</param>
+ /// <returns>String, the CLI query for the given preset name</returns>
+ public string getCliForPreset(string name)
+ {
+ // Built In Presets
+ foreach (Preset item in presets)
+ {
+ if (item.Name == name)
+ return item.Query;
+ }
+
+ // User Presets
+ foreach (Preset item in user_presets)
+ {
+ if (item.Name == name)
+ return item.Query;
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Reads the CLI's CLI output format and load's them into the preset List<Preset>
+ /// </summary>
+ public void updateBuiltInPresets()
+ {
+ // 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);
+ hbGetPresets.WindowStyle = ProcessWindowStyle.Hidden;
+
+ Process hbproc = Process.Start(hbGetPresets);
+ hbproc.WaitForExit();
+ hbproc.Dispose();
+ hbproc.Close();
+
+ // 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;
+
+ while (!presetInput.EndOfStream)
+ {
+ string line = presetInput.ReadLine();
+ if (line.Contains("<") && !line.Contains("<<"))
+ {
+ level = 1;
+ category = line.Replace("<", "").Trim();
+ level_1_category = category;
+ }
+
+ if (line.Contains("<<"))
+ {
+ level = 2;
+ category = line.Replace("<<", "").Trim();
+ }
+
+ if (line.Trim().Contains(">>"))
+ {
+ level = 1;
+ category = level_1_category;
+ }
+
+ if (line.Contains("+"))
+ {
+ Regex r = new Regex("(: )"); // Split on hyphens.
+ string[] presetName = r.Split(line);
+
+ Preset newPreset = new Preset();
+ newPreset.Level = level;
+ newPreset.Category = category;
+ newPreset.Name = presetName[0].Replace("+", "").Trim();
+ newPreset.Query = presetName[2];
+ presets.Add(newPreset);
+ }
+ }
+ presetInput.Close();
+ presetInput.Dispose();
+ }
+
+ // Finally, Create a new or update the current presets.xml file
+ updatePresetsFile();
+ }
+
+ /// <summary>
+ /// Load in the preset data from presets.xml and user_presets.xml
+ /// Load it into the 2 arraylist's presets and user_presets
+ /// </summary>
+ public void loadPresetData()
+ {
+ // First clear the presets arraylists
+ presets.Clear();
+ user_presets.Clear();
+
+ string filePath = string.Empty;
+
+ // Load in the users presets from user_presets.xml
+ filePath = Application.StartupPath.ToString() + "\\presets.xml";
+ if (File.Exists(filePath))
+ {
+ using (FileStream strm = new FileStream(filePath, FileMode.Open, FileAccess.Read))
+ {
+ if (strm.Length != 0)
+ {
+ List<Preset> list = ser.Deserialize(strm) as List<Preset>;
+
+ foreach (Preset preset in list)
+ presets.Add(preset);
+ }
+ }
+ }
+
+ // Load in the users presets from user_presets.xml
+ filePath = Application.StartupPath.ToString() + "\\user_presets.xml";
+ if (File.Exists(filePath))
+ {
+ using (FileStream strm = new FileStream(filePath, FileMode.Open, FileAccess.Read))
+ {
+ if (strm.Length != 0)
+ {
+ List<Preset> list = ser.Deserialize(strm) as List<Preset>;
+
+ foreach (Preset preset in list)
+ user_presets.Add(preset);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// 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
+ /// </summary>
+ private void updatePresetsFile()
+ {
+ string userPresets = Application.StartupPath.ToString() + "\\presets.xml";
+ try
+ {
+ using (FileStream strm = new FileStream(userPresets, FileMode.Create, FileAccess.Write))
+ {
+ ser.Serialize(strm, presets);
+ strm.Close();
+ strm.Dispose();
+ }
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.\n Error Information: \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
+ }
+ }
+
+ /// <summary>
+ /// Updates the user_presets.xml file which contains the built in presets
+ /// It takes the List of Presets and converts them into XML which is stored in user_presets.xml
+ /// </summary>
+ private void updateUserPresetsFile()
+ {
+ string userPresets = Application.StartupPath.ToString() + "\\user_presets.xml";
+ try
+ {
+ using (FileStream strm = new FileStream(userPresets, FileMode.Create, FileAccess.Write))
+ {
+ ser.Serialize(strm, user_presets);
+ strm.Close();
+ strm.Dispose();
+ }
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.\n Error Information: \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
+ }
+ }
+
+ /// <summary>
+ /// Check if the preset "name" exists in either presets or user_presets lists.
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ private Boolean checkIfPresetExists(string name)
+ {
+ if (name == string.Empty)
+ return true;
+
+ // Built In Presets
+ foreach (Preset item in presets)
+ {
+ if (item.Name == name)
+ return true;
+ }
+
+ // User Presets
+ foreach (Preset item in user_presets)
+ {
+ if (item.Name == name)
+ return true;
+ }
+
+ return false;
+ }
+ }
+} \ No newline at end of file
diff --git a/win/C#/Presets/preset.cs b/win/C#/Presets/preset.cs
new file mode 100644
index 000000000..9f7eed8bd
--- /dev/null
+++ b/win/C#/Presets/preset.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Forms;
+using System.IO;
+using System.Text.RegularExpressions;
+using System.Diagnostics;
+
+namespace Handbrake.Presets
+{
+ public class Preset
+ {
+
+ private int level = 0;
+ private string category = null;
+ private string name;
+ private string query;
+
+ public Preset()
+ {
+ }
+
+ /// <summary>
+ /// Get or Set the preset's level. This indicated if it is a root or child node
+ /// </summary>
+ public int Level
+ {
+ get { return level; }
+ set { this.level = value; }
+ }
+
+ /// <summary>
+ /// Get or Set the category which the preset resides under
+ /// </summary>
+ public string Category
+ {
+ get { return category; }
+ set { this.category = value; }
+ }
+
+ /// <summary>
+ /// Get or Set the preset name
+ /// </summary>
+ public string Name
+ {
+ get { return name; }
+ set { this.name = value; }
+ }
+
+ /// <summary>
+ /// Get or set the preset query
+ /// </summary>
+ public string Query
+ {
+ get { return query; }
+ set { this.query = value; }
+ }
+
+ }
+} \ No newline at end of file
diff --git a/win/C#/frmAddPreset.cs b/win/C#/frmAddPreset.cs
index bc2743771..3fa157d40 100644
--- a/win/C#/frmAddPreset.cs
+++ b/win/C#/frmAddPreset.cs
@@ -18,10 +18,10 @@ namespace Handbrake
public partial class frmAddPreset : Form
{
private frmMain frmMainWindow;
- Functions.Presets presetCode;
+ Presets.PresetsHandler presetCode;
private string query = "";
-
- public frmAddPreset(frmMain fmw, string query_string, Functions.Presets presetHandler)
+
+ public frmAddPreset(frmMain fmw, string query_string, Presets.PresetsHandler presetHandler)
{
InitializeComponent();
frmMainWindow = fmw;
diff --git a/win/C#/frmMain.Designer.cs b/win/C#/frmMain.Designer.cs
index ec9953948..32fa4ab6d 100644
--- a/win/C#/frmMain.Designer.cs
+++ b/win/C#/frmMain.Designer.cs
@@ -254,6 +254,11 @@ namespace Handbrake
this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.StatusStrip = new System.Windows.Forms.StatusStrip();
this.lbl_encode = new System.Windows.Forms.ToolStripStatusLabel();
+ this.presets_menu = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.pmnu_delete = new System.Windows.Forms.ToolStripMenuItem();
+ this.pmnu_expandAll = new System.Windows.Forms.ToolStripMenuItem();
+ this.sep1 = new System.Windows.Forms.ToolStripSeparator();
+ this.pmnu_collapse = new System.Windows.Forms.ToolStripMenuItem();
Label38 = new System.Windows.Forms.Label();
notifyIconMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
notifyIconMenu.SuspendLayout();
@@ -282,6 +287,7 @@ namespace Handbrake
this.groupBox2.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.StatusStrip.SuspendLayout();
+ this.presets_menu.SuspendLayout();
this.SuspendLayout();
//
// Label38
@@ -301,12 +307,12 @@ namespace Handbrake
this.btn_restore});
notifyIconMenu.Name = "notifyIconMenu";
notifyIconMenu.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
- notifyIconMenu.Size = new System.Drawing.Size(129, 26);
+ notifyIconMenu.Size = new System.Drawing.Size(153, 48);
//
// btn_restore
//
this.btn_restore.Name = "btn_restore";
- this.btn_restore.Size = new System.Drawing.Size(128, 22);
+ this.btn_restore.Size = new System.Drawing.Size(152, 22);
this.btn_restore.Text = "Restore";
this.btn_restore.Click += new System.EventHandler(this.btn_restore_Click);
//
@@ -543,7 +549,7 @@ namespace Handbrake
this.btn_setDefault.FlatAppearance.BorderColor = System.Drawing.Color.Black;
this.btn_setDefault.Font = new System.Drawing.Font("Verdana", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_setDefault.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
- this.btn_setDefault.Location = new System.Drawing.Point(115, 508);
+ this.btn_setDefault.Location = new System.Drawing.Point(873, 584);
this.btn_setDefault.Name = "btn_setDefault";
this.btn_setDefault.Size = new System.Drawing.Size(72, 22);
this.btn_setDefault.TabIndex = 1;
@@ -660,7 +666,7 @@ namespace Handbrake
this.btn_addPreset.FlatAppearance.BorderColor = System.Drawing.Color.Black;
this.btn_addPreset.Font = new System.Drawing.Font("Verdana", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_addPreset.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
- this.btn_addPreset.Location = new System.Drawing.Point(10, 508);
+ this.btn_addPreset.Location = new System.Drawing.Point(768, 584);
this.btn_addPreset.Name = "btn_addPreset";
this.btn_addPreset.Size = new System.Drawing.Size(35, 22);
this.btn_addPreset.TabIndex = 3;
@@ -675,7 +681,7 @@ namespace Handbrake
this.btn_removePreset.FlatAppearance.BorderColor = System.Drawing.Color.Black;
this.btn_removePreset.Font = new System.Drawing.Font("Verdana", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_removePreset.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
- this.btn_removePreset.Location = new System.Drawing.Point(51, 508);
+ this.btn_removePreset.Location = new System.Drawing.Point(809, 584);
this.btn_removePreset.Name = "btn_removePreset";
this.btn_removePreset.Size = new System.Drawing.Size(58, 22);
this.btn_removePreset.TabIndex = 4;
@@ -1628,7 +1634,7 @@ namespace Handbrake
this.HelpToolStripMenuItem});
this.frmMainMenu.Location = new System.Drawing.Point(0, 0);
this.frmMainMenu.Name = "frmMainMenu";
- this.frmMainMenu.Size = new System.Drawing.Size(958, 24);
+ this.frmMainMenu.Size = new System.Drawing.Size(985, 24);
this.frmMainMenu.TabIndex = 0;
this.frmMainMenu.Text = "MenuStrip1";
//
@@ -2933,29 +2939,28 @@ namespace Handbrake
//
// groupBox2
//
- this.groupBox2.Controls.Add(this.btn_removePreset);
- this.groupBox2.Controls.Add(this.btn_addPreset);
this.groupBox2.Controls.Add(this.treeView_presets);
- this.groupBox2.Controls.Add(this.btn_setDefault);
this.groupBox2.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.groupBox2.ForeColor = System.Drawing.Color.Black;
this.groupBox2.Location = new System.Drawing.Point(728, 70);
this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(218, 546);
+ this.groupBox2.Size = new System.Drawing.Size(245, 508);
this.groupBox2.TabIndex = 6;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Presets";
//
// treeView_presets
//
+ this.treeView_presets.ContextMenuStrip = this.presets_menu;
+ this.treeView_presets.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView_presets.ForeColor = System.Drawing.Color.DarkBlue;
this.treeView_presets.FullRowSelect = true;
this.treeView_presets.HideSelection = false;
this.treeView_presets.ItemHeight = 21;
- this.treeView_presets.Location = new System.Drawing.Point(10, 23);
+ this.treeView_presets.Location = new System.Drawing.Point(3, 17);
this.treeView_presets.Name = "treeView_presets";
this.treeView_presets.ShowLines = false;
- this.treeView_presets.Size = new System.Drawing.Size(198, 473);
+ this.treeView_presets.Size = new System.Drawing.Size(239, 488);
this.treeView_presets.TabIndex = 0;
this.treeView_presets.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_presets_AfterSelect);
this.treeView_presets.KeyUp += new System.Windows.Forms.KeyEventHandler(this.treeView_presets_deleteKey);
@@ -2976,7 +2981,7 @@ namespace Handbrake
this.toolStrip1.Location = new System.Drawing.Point(0, 24);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
- this.toolStrip1.Size = new System.Drawing.Size(958, 39);
+ this.toolStrip1.Size = new System.Drawing.Size(985, 39);
this.toolStrip1.TabIndex = 1;
this.toolStrip1.Text = "toolStrip1";
//
@@ -3112,7 +3117,7 @@ namespace Handbrake
this.lbl_encode});
this.StatusStrip.Location = new System.Drawing.Point(0, 629);
this.StatusStrip.Name = "StatusStrip";
- this.StatusStrip.Size = new System.Drawing.Size(958, 22);
+ this.StatusStrip.Size = new System.Drawing.Size(985, 22);
this.StatusStrip.TabIndex = 7;
this.StatusStrip.Text = "statusStrip1";
//
@@ -3123,13 +3128,52 @@ namespace Handbrake
this.lbl_encode.Size = new System.Drawing.Size(31, 17);
this.lbl_encode.Text = "{0}";
//
+ // presets_menu
+ //
+ this.presets_menu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.pmnu_expandAll,
+ this.pmnu_collapse,
+ this.sep1,
+ this.pmnu_delete});
+ this.presets_menu.Name = "presets_menu";
+ this.presets_menu.Size = new System.Drawing.Size(146, 76);
+ //
+ // pmnu_delete
+ //
+ this.pmnu_delete.Name = "pmnu_delete";
+ this.pmnu_delete.Size = new System.Drawing.Size(145, 22);
+ this.pmnu_delete.Text = "Delete";
+ this.pmnu_delete.Click += new System.EventHandler(this.pmnu_delete_Click);
+ //
+ // pmnu_expandAll
+ //
+ this.pmnu_expandAll.Name = "pmnu_expandAll";
+ this.pmnu_expandAll.Size = new System.Drawing.Size(145, 22);
+ this.pmnu_expandAll.Text = "Expand All";
+ this.pmnu_expandAll.Click += new System.EventHandler(this.pmnu_expandAll_Click);
+ //
+ // sep1
+ //
+ this.sep1.Name = "sep1";
+ this.sep1.Size = new System.Drawing.Size(142, 6);
+ //
+ // pmnu_collapse
+ //
+ this.pmnu_collapse.Name = "pmnu_collapse";
+ this.pmnu_collapse.Size = new System.Drawing.Size(145, 22);
+ this.pmnu_collapse.Text = "Collapse All";
+ this.pmnu_collapse.Click += new System.EventHandler(this.pmnu_collapse_Click);
+ //
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(958, 651);
+ this.ClientSize = new System.Drawing.Size(985, 651);
+ this.Controls.Add(this.btn_setDefault);
this.Controls.Add(this.GroupBox1);
+ this.Controls.Add(this.btn_removePreset);
this.Controls.Add(this.groupBox_dest);
+ this.Controls.Add(this.btn_addPreset);
this.Controls.Add(this.groupBox_output);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.toolStrip1);
@@ -3180,6 +3224,7 @@ namespace Handbrake
this.toolStrip1.PerformLayout();
this.StatusStrip.ResumeLayout(false);
this.StatusStrip.PerformLayout();
+ this.presets_menu.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -3402,6 +3447,11 @@ namespace Handbrake
internal System.Windows.Forms.OpenFileDialog ISO_Open;
internal System.Windows.Forms.FolderBrowserDialog DVD_Open;
internal System.Windows.Forms.ToolStripMenuItem mnu_dvd_drive;
+ private System.Windows.Forms.ContextMenuStrip presets_menu;
+ private System.Windows.Forms.ToolStripMenuItem pmnu_expandAll;
+ private System.Windows.Forms.ToolStripMenuItem pmnu_collapse;
+ private System.Windows.Forms.ToolStripSeparator sep1;
+ private System.Windows.Forms.ToolStripMenuItem pmnu_delete;
}
} \ No newline at end of file
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs
index 7b91e2e16..d07120af4 100644
--- a/win/C#/frmMain.cs
+++ b/win/C#/frmMain.cs
@@ -26,7 +26,7 @@ namespace Handbrake
Functions.Main hb_common_func = new Functions.Main();
Functions.Encode cliObj = new Functions.Encode();
Functions.Queue encodeQueue = new Functions.Queue();
- Functions.Presets presetHandler = new Functions.Presets();
+ Presets.PresetsHandler presetHandler = new Presets.PresetsHandler();
Parsing.Title selectedTitle;
// Objects belonging to this window only
@@ -193,7 +193,7 @@ namespace Handbrake
#endregion
- // The Applications Main Menu *****************************************
+ // The Applications Main Menu and Menus *******************************
#region File Menu
private void mnu_exit_Click(object sender, EventArgs e)
@@ -229,7 +229,7 @@ namespace Handbrake
#region Presets Menu
private void mnu_presetReset_Click(object sender, EventArgs e)
{
- presetHandler.grabCLIPresets();
+ presetHandler.updateBuiltInPresets();
loadPresetPanel();
if (treeView_presets.Nodes.Count == 0)
MessageBox.Show("Unable to load the presets.dat file. Please select \"Update Built-in Presets\" from the Presets Menu \nMake sure you are running the program in Admin mode if running on Vista. See Windows FAQ for details!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -240,10 +240,19 @@ namespace Handbrake
{
// Empty the preset file
string presetsFile = Application.StartupPath.ToString() + "\\presets.dat";
- StreamWriter line = new StreamWriter(presetsFile);
- line.WriteLine("");
- line.Close();
- line.Dispose();
+ if (File.Exists(presetsFile))
+ File.Delete(presetsFile);
+
+ try
+ {
+ FileStream strm = new FileStream(presetsFile, FileMode.Create, FileAccess.Write);
+ strm.Close();
+ strm.Dispose();
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show("An error has occured during the preset removal process.\n If you are using Windows Vista, you may need to run under Administrator Mode to complete this task. \n" + exc.ToString());
+ }
// Reload the preset panel
loadPresetPanel();
@@ -290,6 +299,30 @@ namespace Handbrake
}
#endregion
+ #region Preset Menu
+ private void pmnu_expandAll_Click(object sender, EventArgs e)
+ {
+ treeView_presets.ExpandAll();
+ }
+ private void pmnu_collapse_Click(object sender, EventArgs e)
+ {
+ treeView_presets.CollapseAll();
+ }
+ private void pmnu_delete_Click(object sender, EventArgs e)
+ {
+ DialogResult result = MessageBox.Show("Are you sure you wish to delete the selected preset?", "Preset", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+ if (result == DialogResult.Yes)
+ {
+ if (treeView_presets.SelectedNode != null)
+ presetHandler.remove(treeView_presets.SelectedNode.Text);
+ // Now reload the preset panel
+ loadPresetPanel();
+ }
+ treeView_presets.Select();
+ }
+ #endregion
+
+
// MainWindow Components, Actions and Functions ***********************
#region Actions
@@ -582,7 +615,7 @@ namespace Handbrake
// Run the Autonaming function
if (Properties.Settings.Default.autoNaming == "Checked")
- text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);
+ text_destination.Text = hb_common_func.autoName(drp_dvdtitle, drop_chapterStart.Text, drop_chapterFinish.Text, text_source.Text, text_destination.Text, drop_format.SelectedIndex);
}
//Destination
@@ -740,7 +773,7 @@ namespace Handbrake
{
if (drp_anamorphic.Text == "None")
{
- int height = hb_common_func.cacluateNonAnamorphicHeight(width, text_top.Value, text_bottom.Value,text_left.Value, text_right.Value, selectedTitle);
+ int height = hb_common_func.cacluateNonAnamorphicHeight(width, text_top.Value, text_bottom.Value, text_left.Value, text_right.Value, selectedTitle);
text_height.Text = height.ToString();
}
}
@@ -1378,18 +1411,21 @@ namespace Handbrake
string presetName = treeView_presets.SelectedNode.Text;
string query = presetHandler.getCliForPreset(presetName);
- //Ok, Reset all the H264 widgets before changing the preset
- x264PanelFunctions.reset2Defaults(this);
+ if (query != null)
+ {
+ //Ok, Reset all the H264 widgets before changing the preset
+ x264PanelFunctions.reset2Defaults(this);
- // Send the query from the file to the Query Parser class
- Functions.QueryParser presetQuery = Functions.QueryParser.Parse(query);
+ // Send the query from the file to the Query Parser class
+ Functions.QueryParser presetQuery = Functions.QueryParser.Parse(query);
- // Now load the preset
- presetLoader.presetLoader(this, presetQuery, presetName);
+ // Now load the preset
+ presetLoader.presetLoader(this, presetQuery, presetName);
- // The x264 widgets will need updated, so do this now:
- x264PanelFunctions.X264_StandardizeOptString(this);
- x264PanelFunctions.X264_SetCurrentSettingsInPanel(this);
+ // The x264 widgets will need updated, so do this now:
+ x264PanelFunctions.X264_StandardizeOptString(this);
+ x264PanelFunctions.X264_SetCurrentSettingsInPanel(this);
+ }
}
private void treeView_presets_deleteKey(object sender, KeyEventArgs e)
{
@@ -1418,7 +1454,7 @@ namespace Handbrake
}
}
#endregion
-
+
#region Drive Detection
// Source Button Drive Detection
private delegate void ProgressUpdateHandler();
@@ -1794,29 +1830,93 @@ namespace Handbrake
this.thisDVD = dvd;
}
-
/// <summary>
/// Reload the preset panel display
/// </summary>
public void loadPresetPanel()
{
- presetHandler.loadPresetFiles();
+ presetHandler.loadPresetData();
treeView_presets.Nodes.Clear();
- List<string> presetNameList = new List<string>();
+
+ List<Presets.Preset> presetNameList = new List<Presets.Preset>();
+ List<string> presetNames = new List<string>();
TreeNode preset_treeview = new TreeNode();
- presetNameList = presetHandler.getBuildInPresetNames();
- foreach (string preset in presetNameList)
+ TreeNode rootNode = new TreeNode();
+ TreeNode rootNodeTwo = new TreeNode();
+ TreeNode childNode = new TreeNode();
+ int workingLevel = 0;
+ string previousCategory = String.Empty;
+ string currentCategory = String.Empty;
+
+ presetNameList = presetHandler.getBuildInPresets();
+ if (presetNameList.Count != 0)
{
- preset_treeview = new TreeNode(preset);
+ foreach (Presets.Preset preset in presetNameList)
+ {
+ // Handle Root Nodes
- // Now Fill Out List View with Items
- treeView_presets.Nodes.Add(preset_treeview);
+ // 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 && previousCategory == preset.Category)
+ {
+ 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);
}
- presetNameList = presetHandler.getUserPresetNames();
- foreach (string preset in presetNameList)
+
+ // User Presets
+ presetNames = presetHandler.getUserPresetNames();
+ foreach (string preset in presetNames)
{
preset_treeview = new TreeNode(preset);
preset_treeview.ForeColor = Color.Black;
diff --git a/win/C#/frmMain.resx b/win/C#/frmMain.resx
index 7636871d6..1ae5e6636 100644
--- a/win/C#/frmMain.resx
+++ b/win/C#/frmMain.resx
@@ -121,16 +121,16 @@
<value>False</value>
</metadata>
<metadata name="notifyIconMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>931, 18</value>
+ <value>977, 15</value>
</metadata>
<metadata name="notifyIconMenu.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="DVD_Save.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>529, 18</value>
+ <value>556, 15</value>
</metadata>
<metadata name="File_Save.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>633, 18</value>
+ <value>664, 15</value>
</metadata>
<metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>18, 15</value>
@@ -243,19 +243,22 @@ Don't select none assuming it will be faster; instead it will take longer and lo
If you're going to choose between spatial and temporal, spatial is usually better. </value>
</data>
<metadata name="DVD_Open.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>223, 15</value>
+ <value>232, 15</value>
</metadata>
<metadata name="File_Open.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>430, 18</value>
+ <value>450, 15</value>
</metadata>
<metadata name="ISO_Open.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>329, 15</value>
+ <value>343, 15</value>
</metadata>
<metadata name="frmMainMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>106, 15</value>
</metadata>
+ <metadata name="presets_menu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>1224, 15</value>
+ </metadata>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>731, 18</value>
+ <value>767, 15</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="btn_dvd_source.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
@@ -276,7 +279,7 @@ If you're going to choose between spatial and temporal, spatial is usually bette
</value>
</data>
<metadata name="notifyIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>830, 18</value>
+ <value>871, 15</value>
</metadata>
<data name="notifyIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
@@ -658,7 +661,7 @@ If you're going to choose between spatial and temporal, spatial is usually bette
</value>
</data>
<metadata name="StatusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>1060, 18</value>
+ <value>1113, 15</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>56</value>