diff options
author | sr55 <[email protected]> | 2011-02-18 21:56:19 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-02-18 21:56:19 +0000 |
commit | da4025b6af1d0f5550159b87bf6a14c025752107 (patch) | |
tree | fd8ccfe1d0cab83b70f39afcc4e85b8c3de185fb /win | |
parent | 1955a68ebccad7cd78534f6140550456b3e22756 (diff) |
WinGui
- Wire in the new preset service.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3799 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r-- | win/C#/Controls/AudioPanel.cs | 2 | ||||
-rw-r--r-- | win/C#/Controls/PictureSettings.cs | 2 | ||||
-rw-r--r-- | win/C#/HandBrake.ApplicationServices/Model/Preset.cs | 13 | ||||
-rw-r--r-- | win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs | 4 | ||||
-rw-r--r-- | win/C#/HandBrake.ApplicationServices/Services/PresetService.cs | 72 | ||||
-rw-r--r-- | win/C#/HandBrakeCS.csproj | 2 | ||||
-rw-r--r-- | win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs | 20 | ||||
-rw-r--r-- | win/C#/HandBrakeWPF/Views/MainView.xaml | 333 | ||||
-rw-r--r-- | win/C#/Presets/PresetsHandler.cs | 452 | ||||
-rw-r--r-- | win/C#/Program.cs | 6 | ||||
-rw-r--r-- | win/C#/frmAddPreset.cs | 20 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 102 |
12 files changed, 364 insertions, 664 deletions
diff --git a/win/C#/Controls/AudioPanel.cs b/win/C#/Controls/AudioPanel.cs index ed56bf384..b31d2c17b 100644 --- a/win/C#/Controls/AudioPanel.cs +++ b/win/C#/Controls/AudioPanel.cs @@ -17,8 +17,6 @@ namespace Handbrake.Controls using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Utilities;
- using Presets;
-
using AudioTrack = HandBrake.ApplicationServices.Model.Encoding.AudioTrack;
/// <summary>
diff --git a/win/C#/Controls/PictureSettings.cs b/win/C#/Controls/PictureSettings.cs index 2425407ea..c4ae909c0 100644 --- a/win/C#/Controls/PictureSettings.cs +++ b/win/C#/Controls/PictureSettings.cs @@ -13,8 +13,6 @@ namespace Handbrake.Controls using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
- using Presets;
-
/// <summary>
/// The Picture Settings Panel
/// </summary>
diff --git a/win/C#/HandBrake.ApplicationServices/Model/Preset.cs b/win/C#/HandBrake.ApplicationServices/Model/Preset.cs index 988e3da80..e20ad2dee 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Preset.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Preset.cs @@ -8,7 +8,7 @@ namespace HandBrake.ApplicationServices.Model /// <summary>
/// A Preset for encoding with.
/// </summary>
- public class Preset
+ public class Preset
{
/// <summary>
/// Gets or sets the category which the preset resides under
@@ -49,5 +49,16 @@ namespace HandBrake.ApplicationServices.Model /// Gets or sets a value indicating whether this is a built in preset
/// </summary>
public bool IsBuildIn { get; set; }
+
+ /// <summary>
+ /// Override the ToString Method
+ /// </summary>
+ /// <returns>
+ /// The Preset Name
+ /// </returns>
+ public override string ToString()
+ {
+ return this.Name;
+ }
}
}
\ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs b/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs index b947a955e..07daab3c9 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs @@ -5,7 +5,7 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
{
- using System.ComponentModel;
+ using System.Collections.ObjectModel;
using HandBrake.ApplicationServices.Model;
@@ -17,7 +17,7 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// <summary>
/// Gets or sets a Collection of presets.
/// </summary>
- ICollectionView Presets { get; set; }
+ ObservableCollection<Preset> Presets { get; set; }
/// <summary>
/// Add a new preset to the system
diff --git a/win/C#/HandBrake.ApplicationServices/Services/PresetService.cs b/win/C#/HandBrake.ApplicationServices/Services/PresetService.cs index dbfb8782f..9a9f26564 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/PresetService.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/PresetService.cs @@ -28,7 +28,8 @@ namespace HandBrake.ApplicationServices.Services * TODO:
* - Wire this into the Forms and WPF UI's
* - Note: This is untested so far. It'll likely need fixes before it can be used.
- **/
+ * - Maybe change the collection to a dictionary to allow easier lookups?
+ **/
#region Private Variables
@@ -59,14 +60,30 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
public PresetService()
{
- this.Presets = CollectionViewSource.GetDefaultView(this.presets);
+ // this.Presets = CollectionViewSource.GetDefaultView(this.presets);
this.LoadPresets();
}
/// <summary>
/// Gets or sets a Collection of presets.
/// </summary>
- public ICollectionView Presets { get; set; }
+ public ObservableCollection<Preset> Presets
+ {
+ get
+ {
+ return this.presets;
+ }
+
+ set
+ {
+ this.presets = value;
+ }
+ }
+
+ /// <summary>
+ /// The last preset added.
+ /// </summary>
+ public Preset LastPresetAdded { get; set; }
#region Public Methods
@@ -85,6 +102,7 @@ namespace HandBrake.ApplicationServices.Services if (this.CheckIfPresetExists(preset.Name) == false)
{
this.presets.Add(preset);
+ this.LastPresetAdded = preset;
// Update the presets file
this.UpdatePresetFiles();
@@ -95,6 +113,25 @@ namespace HandBrake.ApplicationServices.Services }
/// <summary>
+ /// Update a preset
+ /// </summary>
+ /// <param name="update">
+ /// The updated preset
+ /// </param>
+ public void Update(Preset update)
+ {
+ // TODO - Change this to be a lookup
+ foreach (Preset preset in this.presets)
+ {
+ if (preset.Name == update.Name)
+ {
+ preset.Query = update.Query;
+ break;
+ }
+ }
+ }
+
+ /// <summary>
/// Remove a preset with a given name from either the built in or user preset list.
/// </summary>
/// <param name="preset">
@@ -154,7 +191,7 @@ namespace HandBrake.ApplicationServices.Services string handbrakeCLIPath = Path.Combine(cliPath, "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 getPresets = new ProcessStartInfo("CMD.exe", strCmdLine) { WindowStyle = ProcessWindowStyle.Hidden };
Process hbproc = Process.Start(getPresets);
@@ -163,7 +200,7 @@ namespace HandBrake.ApplicationServices.Services hbproc.Close();
// Clear the current built in Presets and now parse the tempory Presets file.
- this.presets.Clear();
+ this.ClearBuiltIn();
if (File.Exists(presetsPath))
{
@@ -176,13 +213,13 @@ namespace HandBrake.ApplicationServices.Services string line = presetInput.ReadLine();
// Found the beginning of a preset block
- if (line != null && line.Contains("<") && !line.Contains("<<"))
+ if (line != null && line.Contains("<") && !line.Contains("<<"))
{
category = line.Replace("<", string.Empty).Trim();
}
// Found a preset
- if (line != null && line.Contains("+"))
+ if (line != null && line.Contains("+"))
{
Regex r = new Regex("(: )"); // Split on hyphens.
string[] presetName = r.Split(line);
@@ -194,14 +231,15 @@ namespace HandBrake.ApplicationServices.Services }
Preset newPreset = new Preset
- {
- Category = category,
- Name = presetName[0].Replace("+", string.Empty).Trim(),
- Query = presetName[2],
- Version = Init.Version,
- CropSettings = pic,
- Description = string.Empty // Maybe one day we will populate this.
- };
+ {
+ Category = category,
+ Name = presetName[0].Replace("+", string.Empty).Trim(),
+ Query = presetName[2],
+ Version = Init.Version,
+ CropSettings = pic,
+ Description = string.Empty, // Maybe one day we will populate this.
+ IsBuildIn = true
+ };
this.presets.Add(newPreset);
}
}
@@ -327,14 +365,14 @@ namespace HandBrake.ApplicationServices.Services {
using (FileStream strm = new FileStream(this.builtInPresetFile, FileMode.Create, FileAccess.Write))
{
- Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn));
+ Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn).ToList());
strm.Close();
strm.Dispose();
}
using (FileStream strm = new FileStream(this.userPresetFile, FileMode.Create, FileAccess.Write))
{
- Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn == false));
+ Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn == false).ToList());
strm.Close();
strm.Dispose();
}
diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index 2edb86514..bd9e78197 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -174,6 +174,7 @@ <Reference Include="System.Messaging" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.XML" />
+ <Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\AudioPanel.cs">
@@ -256,7 +257,6 @@ <DependentUpon>frmActivityWindow.cs</DependentUpon>
</Compile>
<Compile Include="Model\SourceType.cs" />
- <Compile Include="Presets\PresetsHandler.cs" />
<Compile Include="Program.cs" />
<Compile Include="ToolWindows\BatchAdd.cs">
<SubType>Form</SubType>
diff --git a/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs index 4b2180dd3..0aaa4eb84 100644 --- a/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -6,6 +6,7 @@ namespace HandBrakeWPF.ViewModels
{
using System;
+ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Windows;
@@ -33,6 +34,11 @@ namespace HandBrakeWPF.ViewModels private readonly IQueueProcessor queueProcessor;
/// <summary>
+ /// The preset service
+ /// </summary>
+ private readonly IPresetService presetService;
+
+ /// <summary>
/// HandBrakes Main Window Title
/// </summary>
private string windowName;
@@ -54,9 +60,10 @@ namespace HandBrakeWPF.ViewModels /// </summary>
public MainViewModel()
{
- // Setup Services
+ // Setup Services (TODO - Bring Castle back into the project to wire these up for us)
this.scanService = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService();
this.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length);
+ this.presetService = new PresetService();
// Setup Properties
this.WindowTitle = "HandBrake WPF Test Application";
@@ -94,6 +101,17 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
+ /// Gets a list of presets
+ /// </summary>
+ public ObservableCollection<Preset> Presets
+ {
+ get
+ {
+ return this.presetService.Presets;
+ }
+ }
+
+ /// <summary>
/// Gets or sets The Current Encode Task that the user is building
/// </summary>
public EncodeTask CurrentTask { get; set; }
diff --git a/win/C#/HandBrakeWPF/Views/MainView.xaml b/win/C#/HandBrakeWPF/Views/MainView.xaml index 86f807854..ea4d41ad2 100644 --- a/win/C#/HandBrakeWPF/Views/MainView.xaml +++ b/win/C#/HandBrakeWPF/Views/MainView.xaml @@ -1,170 +1,197 @@ <Window x:Class="HandBrakeWPF.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:PresentationFramework="clr-namespace:Caliburn.PresentationFramework;assembly=Caliburn.PresentationFramework" Title="{Binding Path=WindowTitle}" Height="655" Width="1015" FontSize="11">
-
+
<Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="*" />
- <RowDefinition Height="Auto" />
- </Grid.RowDefinitions>
-
- <!-- Main Menu -->
- <Menu Height="23" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Stretch">
- <MenuItem Header="File">
- <MenuItem Header="Cancel Scan" />
- <MenuItem Header="Exit" PresentationFramework:Message.Attach="[Event Click] = [Action ExitApplication]" />
- </MenuItem>
-
- <MenuItem Header="Tools">
- <MenuItem Header="Show Queue" />
- <MenuItem Header="Activity Window" />
- </MenuItem>
-
- <MenuItem Header="Presets">
- <MenuItem Header="Reset Built-in Presets" />
- <MenuItem Header="Delete Built-in Presets" />
- <Separator />
- <MenuItem Header="Save As New Preset" />
- <MenuItem Header="Import" />
- <MenuItem Header="Export" />
- <MenuItem Header="Set as Default" />
- </MenuItem>
-
- <MenuItem Header="Help">
- <MenuItem Header="HandBrake User Guide" />
- <Separator />
- <MenuItem Header="Check for Updates" />
- <Separator />
- <MenuItem Header="About..." />
- </MenuItem>
- </Menu>
-
- <!-- ToolBar -->
- <ToolBar Grid.Row="1" Name="mainToolBar" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SnapsToDevicePixels="False">
-
- <Button Name="Source">
- <StackPanel Orientation="Horizontal">
- <Image Source="Images/Movies.png" Height="32" Width="32" />
- <Label Content="Source" Margin="8,0,0,0" VerticalAlignment="Center" />
- </StackPanel>
- </Button>
-
- <Separator />
-
- <Button Name="Start">
- <StackPanel Orientation="Horizontal">
- <Image Source="Images/Play.png" Height="32" Width="32" />
- <Label Content="Start" Margin="8,0,0,0" VerticalAlignment="Center" />
- </StackPanel>
- </Button>
- <Button Name="AddToQueue">
- <StackPanel Orientation="Horizontal">
- <Image Source="Images/AddToQueue.png" Height="32" Width="32" />
- <Label Content="Add To Queue" Margin="8,0,0,0" VerticalAlignment="Center" />
- </StackPanel>
- </Button>
+ <StackPanel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
+ <!-- Menu and Taskbar-->
+ <StackPanel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
+ <!-- Main Menu -->
+ <Menu Height="23" VerticalAlignment="Top" HorizontalAlignment="Stretch">
+ <MenuItem Header="File">
+ <MenuItem Header="Cancel Scan" />
+ <MenuItem Header="Exit" PresentationFramework:Message.Attach="[Event Click] = [Action ExitApplication]" />
+ </MenuItem>
- <Button Name="ShowQueue">
- <StackPanel Orientation="Horizontal">
- <Image Source="Images/Queue.png" Height="32" Width="32" />
- <Label Content="Show Queue" Margin="8,0,0,0" VerticalAlignment="Center" />
- </StackPanel>
- </Button>
+ <MenuItem Header="Tools">
+ <MenuItem Header="Show Queue" />
+ <MenuItem Header="Activity Window" />
+ </MenuItem>
+
+ <MenuItem Header="Presets">
+ <MenuItem Header="Reset Built-in Presets" />
+ <MenuItem Header="Delete Built-in Presets" />
+ <Separator />
+ <MenuItem Header="Save As New Preset" />
+ <MenuItem Header="Import" />
+ <MenuItem Header="Export" />
+ <MenuItem Header="Set as Default" />
+ </MenuItem>
+
+ <MenuItem Header="Help">
+ <MenuItem Header="HandBrake User Guide" />
+ <Separator />
+ <MenuItem Header="Check for Updates" />
+ <Separator />
+ <MenuItem Header="About..." />
+ </MenuItem>
+ </Menu>
+
+ <!-- ToolBar -->
+ <ToolBar Name="mainToolBar" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SnapsToDevicePixels="False">
- <Separator />
+ <Button Name="Source">
+ <StackPanel Orientation="Horizontal">
+ <Image Source="Images/Movies.png" Height="32" Width="32" />
+ <Label Content="Source" Margin="8,0,0,0" VerticalAlignment="Center" />
+ </StackPanel>
+ </Button>
+
+ <Separator />
+
+ <Button Name="Start">
+ <StackPanel Orientation="Horizontal">
+ <Image Source="Images/Play.png" Height="32" Width="32" />
+ <Label Content="Start" Margin="8,0,0,0" VerticalAlignment="Center" />
+ </StackPanel>
+ </Button>
+ <Button Name="AddToQueue">
+ <StackPanel Orientation="Horizontal">
+ <Image Source="Images/AddToQueue.png" Height="32" Width="32" />
+ <Label Content="Add To Queue" Margin="8,0,0,0" VerticalAlignment="Center" />
+ </StackPanel>
+ </Button>
+
+ <Button Name="ShowQueue">
+ <StackPanel Orientation="Horizontal">
+ <Image Source="Images/Queue.png" Height="32" Width="32" />
+ <Label Content="Show Queue" Margin="8,0,0,0" VerticalAlignment="Center" />
+ </StackPanel>
+ </Button>
+
+ <Separator />
+
+ <Button Name="Preview">
+ <StackPanel Orientation="Horizontal">
+ <Image Source="Images/window.png" Height="32" Width="32" />
+ <Label Content="Preview" Margin="8,0,0,0" VerticalAlignment="Center" />
+ </StackPanel>
+ </Button>
+ <Button Name="ActivityWindow">
+ <StackPanel Orientation="Horizontal">
+ <Image Source="Images/ActivityWindow.png" Height="32" Width="32" />
+ <Label Content="Activity Window" Margin="8,0,0,0" VerticalAlignment="Center" />
+ </StackPanel>
+ </Button>
+ </ToolBar>
+ </StackPanel>
- <Button Name="Preview">
- <StackPanel Orientation="Horizontal">
- <Image Source="Images/window.png" Height="32" Width="32" />
- <Label Content="Preview" Margin="8,0,0,0" VerticalAlignment="Center" />
+ <!-- Main Body-->
+ <StackPanel Orientation="Horizontal">
+
+ <!-- Main Controls-->
+ <StackPanel Orientation="Vertical">
+ <!-- Source -->
+ <StackPanel Margin="10,5,10,5" MaxWidth="725" Width="725" HorizontalAlignment="Left">
+ <StackPanel Orientation="Horizontal">
+ <Label Content="Source" FontWeight="Bold" />
+ <Label Content="{Binding Path=SourceLabel}" />
+ </StackPanel>
+
+ <StackPanel Orientation="Horizontal">
+ <Label Content="Title" Margin="8,0,0,0" />
+ <ComboBox Name="Titles" Margin="8,0,0,0" MinWidth="100" SelectedItem="{Binding Path=CurrentTask.Title}" />
+
+ <Label Content="Angle" Margin="8,0,0,0" />
+ <ComboBox Name="Angles" Margin="8,0,0,0" MinWidth="60" SelectedItem="{Binding Path=CurrentTask.Angle}"/>
+
+ <ComboBox Name="PointToPointMode" Margin="8,0,0,0" MinWidth="80" SelectedItem="{Binding Path=CurrentTask.PointToPointMode}" />
+ <ComboBox Name="StartPoint" Margin="8,0,0,0" MinWidth="60" SelectedItem="{Binding Path=CurrentTask.StartPoint}" />
+ <Label Content="through" Margin="8,0,0,0" />
+ <ComboBox Name="EndPoint" Margin="8,0,0,0" MinWidth="60" SelectedItem="{Binding Path=CurrentTask.EndPoint}" />
+ <Label Content="Duration" Margin="8,0,0,0" />
+ <Label Content="--:--:--" Margin="8,0,0,0" />
+ </StackPanel>
+ </StackPanel>
+
+ <!-- Destination -->
+ <StackPanel Margin="10,5,10,5" MaxWidth="725" Width="725" HorizontalAlignment="Left">
+ <Label Content="Destination" FontWeight="Bold" />
+ <StackPanel Orientation="Horizontal">
+ <Label Content="File" Margin="8,0,0,0" />
+ <TextBox Name="Destination" Margin="8,0,0,0" Width="600" Text="{}" />
+ <Button Name="DestinationBrowser" Margin="8,0,0,0" Padding="8,0,8,0" Content="Browse" />
+ </StackPanel>
+ </StackPanel>
+
+ <!-- Output Options -->
+ <StackPanel Margin="10,5,10,5" MaxWidth="725" Width="725" HorizontalAlignment="Left">
+ <Label Content="Output Settings (Preset: None)" FontWeight="Bold" />
+ <StackPanel Orientation="Horizontal">
+ <Label Content="Container" Margin="8,0,0,0" />
+ <ComboBox Name="Container" Margin="8,0,0,0" MinWidth="100" SelectedItem="{Binding Path=CurrentTask.OutputFormat}" />
+
+ <CheckBox Name="LargeFileMp4" Content="Large File Size" IsChecked="{Binding Path=CurrentTask.LargeFile}" VerticalAlignment="Center" Margin="8,0,0,0" />
+ <CheckBox Name="WebOptimized" Content="Web Optimized" IsChecked="{Binding Path=CurrentTask.OptimizeMP4}" VerticalAlignment="Center" Margin="8,0,0,0" />
+ <CheckBox Name="iPod5G" Content="iPod 5G Support" IsChecked="{Binding Path=CurrentTask.IPod5GSupport}" VerticalAlignment="Center" Margin="8,0,0,0" />
+ </StackPanel>
+ </StackPanel>
+
+ <!-- Tab Control -->
+ <TabControl HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="725" Height="330" Margin="10,10,10,10" Name="tabControl" >
+ <TabItem Header="Picture" Name="pictureTab">
+ <Grid />
+ </TabItem>
+ <TabItem Header="Video Filters" Name="filtersTab">
+ <Grid />
+ </TabItem>
+ <TabItem Header="Video" Name="videoTab">
+ <Grid />
+ </TabItem>
+ <TabItem Header="Audio" Name="audioTab">
+ <Grid />
+ </TabItem>
+ <TabItem Header="Chapters" Name="chaptersTab">
+ <Grid />
+ </TabItem>
+ <TabItem Header="Advanced" Name="advancedTab">
+ <Grid />
+ </TabItem>
+ </TabControl>
+
</StackPanel>
- </Button>
- <Button Name="ActivityWindow">
- <StackPanel Orientation="Horizontal">
- <Image Source="Images/ActivityWindow.png" Height="32" Width="32" />
- <Label Content="Activity Window" Margin="8,0,0,0" VerticalAlignment="Center" />
+
+ <!-- Presets -->
+ <StackPanel Margin="5,5,5,5" Orientation="Vertical">
+ <GroupBox Header="Presets" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
+ <StackPanel Orientation="Vertical">
+ <TreeView ItemsSource="{Binding Presets}" Width="240" Height="460" >
+
+ </TreeView>
+
+ <StackPanel Orientation="Horizontal">
+ <Button Content="Add" Margin="5,5,5,5" />
+ <Button Content="Remove" Margin="5,5,5,5" />
+ <Button Content="Set Default" Margin="5,5,5,5" />
+ </StackPanel>
+ </StackPanel>
+ </GroupBox>
</StackPanel>
- </Button>
- </ToolBar>
-
- <!-- Source -->
- <StackPanel Grid.Row="2" Margin="10,5,10,5" MaxWidth="725" Width="725" HorizontalAlignment="Left">
- <StackPanel Orientation="Horizontal">
- <Label Content="Source" FontWeight="Bold" />
- <Label Content="{Binding Path=SourceLabel}" />
+
</StackPanel>
- <StackPanel Orientation="Horizontal">
- <Label Content="Title" Margin="8,0,0,0" />
- <ComboBox Name="Titles" Margin="8,0,0,0" MinWidth="100" SelectedItem="{Binding Path=CurrentTask.Title}" />
-
- <Label Content="Angle" Margin="8,0,0,0" />
- <ComboBox Name="Angles" Margin="8,0,0,0" MinWidth="60" SelectedItem="{Binding Path=CurrentTask.Angle}"/>
-
- <ComboBox Name="PointToPointMode" Margin="8,0,0,0" MinWidth="80" SelectedItem="{Binding Path=CurrentTask.PointToPointMode}" />
- <ComboBox Name="StartPoint" Margin="8,0,0,0" MinWidth="60" SelectedItem="{Binding Path=CurrentTask.StartPoint}" />
- <Label Content="through" Margin="8,0,0,0" />
- <ComboBox Name="EndPoint" Margin="8,0,0,0" MinWidth="60" SelectedItem="{Binding Path=CurrentTask.EndPoint}" />
- <Label Content="Duration" Margin="8,0,0,0" />
- <Label Content="--:--:--" Margin="8,0,0,0" />
- </StackPanel>
- </StackPanel>
-
- <!-- Destination -->
- <StackPanel Grid.Row="3" Margin="10,5,10,5" MaxWidth="725" Width="725" HorizontalAlignment="Left">
- <Label Content="Destination" FontWeight="Bold" />
- <StackPanel Orientation="Horizontal">
- <Label Content="File" Margin="8,0,0,0" />
- <TextBox Name="Destination" Margin="8,0,0,0" Width="600" Text="{}" />
- <Button Name="DestinationBrowser" Margin="8,0,0,0" Padding="8,0,8,0" Content="Browse" />
- </StackPanel>
+
+ <!-- Status Bar -->
+ <StatusBar Grid.Row="6" Height="30" Grid.ColumnSpan="2" VerticalAlignment="Bottom">
+ <Label Content="{Binding Path=ProgramStatusLabel}" FontSize="10" VerticalAlignment="Center" />
+ </StatusBar>
+
</StackPanel>
+
- <!-- Output Options -->
- <StackPanel Grid.Row="4" Margin="10,5,10,5" MaxWidth="725" Width="725" HorizontalAlignment="Left">
- <Label Content="Output Settings (Preset: None)" FontWeight="Bold" />
- <StackPanel Orientation="Horizontal">
- <Label Content="Container" Margin="8,0,0,0" />
- <ComboBox Name="Container" Margin="8,0,0,0" MinWidth="100" SelectedItem="{Binding Path=CurrentTask.OutputFormat}" />
- <CheckBox Name="LargeFileMp4" Content="Large File Size" IsChecked="{Binding Path=CurrentTask.LargeFile}" VerticalAlignment="Center" Margin="8,0,0,0" />
- <CheckBox Name="WebOptimized" Content="Web Optimized" IsChecked="{Binding Path=CurrentTask.OptimizeMP4}" VerticalAlignment="Center" Margin="8,0,0,0" />
- <CheckBox Name="iPod5G" Content="iPod 5G Support" IsChecked="{Binding Path=CurrentTask.IPod5GSupport}" VerticalAlignment="Center" Margin="8,0,0,0" />
- </StackPanel>
- </StackPanel>
- <!-- Tab Control -->
- <TabControl HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="725" Height="330" Grid.Row="5" Margin="10,10,10,10" Name="tabControl" >
- <TabItem Header="Picture" Name="pictureTab">
- <Grid />
- </TabItem>
- <TabItem Header="Video Filters" Name="filtersTab">
- <Grid />
- </TabItem>
- <TabItem Header="Video" Name="videoTab">
- <Grid />
- </TabItem>
- <TabItem Header="Audio" Name="audioTab">
- <Grid />
- </TabItem>
- <TabItem Header="Chapters" Name="chaptersTab">
- <Grid />
- </TabItem>
- <TabItem Header="Advanced" Name="advancedTab">
- <Grid />
- </TabItem>
- </TabControl>
-
- <!-- Status Bar -->
- <StatusBar Grid.Row="6" Height="30" VerticalAlignment="Bottom">
- <Label Content="{Binding Path=ProgramStatusLabel}" FontSize="10" VerticalAlignment="Center" />
- </StatusBar>
-
+
+
</Grid>
</Window>
diff --git a/win/C#/Presets/PresetsHandler.cs b/win/C#/Presets/PresetsHandler.cs deleted file mode 100644 index 40ddeb28a..000000000 --- a/win/C#/Presets/PresetsHandler.cs +++ /dev/null @@ -1,452 +0,0 @@ -/* PresetHandler.cs $
- This file is part of the HandBrake source code.
- Homepage: <http://handbrake.fr>.
- It may be used under the terms of the GNU General Public License. */
-
-namespace Handbrake.Presets
-{
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using System.Xml.Serialization;
-
- using HandBrake.ApplicationServices.Model;
-
- /// <summary>
- /// The Preset Handler Class
- /// </summary>
- public class PresetsHandler
- {
- /// <summary>
- /// The User Preset file
- /// </summary>
- private readonly string userPresetFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\user_presets.xml";
-
- /// <summary>
- /// The Built In Presets File
- /// </summary>
- private readonly string hbPresetFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\presets.xml";
-
- /// <summary>
- /// XML Serializer
- /// </summary>
- private static readonly XmlSerializer Ser = new XmlSerializer(typeof(List<Preset>));
-
- /// <summary>
- /// A List of built-in presets
- /// </summary>
- private List<Preset> presets = new List<Preset>();
-
- /// <summary>
- /// A List of user presets
- /// </summary>
- private List<Preset> userPresets = new List<Preset>();
-
- /// <summary>
- /// Gets or sets the Last preset added
- /// </summary>
- public Preset LastPresetAdded { get; set; }
-
- /// <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>
- /// <param name="pictureSettings">
- /// Bool, store crop/picture sizes in the Presets
- /// </param>
- /// <param name="description">
- /// The description.
- /// </param>
- /// <returns>
- /// The add.
- /// </returns>
- public bool Add(string presetName, string query, bool pictureSettings, string description)
- {
- if (this.CheckIfPresetExists(presetName) == false)
- {
- Preset newPreset = new Preset
- {
- Name = presetName,
- Query = query,
- CropSettings = pictureSettings,
- Version = Properties.Settings.Default.hb_version
- };
- this.userPresets.Add(newPreset);
- this.UpdatePresetFiles();
- this.LastPresetAdded = newPreset;
- return true;
- }
- 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 this.presets)
- {
- if (item.Name != name)
- {
- newPresets.Add(item);
- }
- }
- this.presets = newPresets;
-
- // User Presets
- foreach (Preset item in this.userPresets)
- {
- if (item.Name != name)
- {
- newUserPresets.Add(item);
- }
- }
- this.userPresets = newUserPresets;
-
- // Rebuild the Preset XML files
- this.UpdatePresetFiles();
- }
-
- /// <summary>
- /// Remove all built in Presets;
- /// </summary>
- public void RemoveBuiltInPresets()
- {
- this.presets.Clear();
- this.UpdatePresetFiles();
- }
-
- /// <summary>
- /// Save changes to a given preset in the user preset list.
- /// </summary>
- /// <param name="presetName">String, The name of the new preset</param>
- /// <param name="query">String, the CLI query for the new preset</param>
- /// <param name="pictureSettings"> Bool, store crop/picture sizes in the preset</param>
- public void Update(string presetName, string query, bool pictureSettings)
- {
- // User Presets
- foreach (Preset item in this.userPresets)
- {
- if (item.Name == presetName)
- {
- item.Query = query;
- item.CropSettings = pictureSettings;
- MessageBox.Show(
- "Changes to \"" + presetName + "\" Saved",
- "Success",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- this.UpdatePresetFiles();
- }
- }
- }
-
- /// <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> not
- public Preset GetPreset(string name)
- {
- // Built In Presets
- foreach (Preset item in this.presets)
- {
- if (item.Name == name)
- return item;
- }
-
- // User Presets
- return this.userPresets.FirstOrDefault(item => item.Name == name);
- }
-
- /// <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)
- {
- WindowStyle = ProcessWindowStyle.Hidden
- };
- Process hbproc = Process.Start(hbGetPresets);
- if (hbproc != null)
- {
- hbproc.WaitForExit();
- hbproc.Dispose();
- hbproc.Close();
- }
-
- // Clear the current built in Presets and now parse the tempory Presets file.
- this.presets.Clear();
-
- if (File.Exists(presetsPath))
- {
- StreamReader presetInput = new StreamReader(presetsPath);
-
- string category = String.Empty;
-
- while (!presetInput.EndOfStream)
- {
- string line = presetInput.ReadLine();
- if (line.Contains("<") && !line.Contains("<<")) // Found the beginning of a preset block
- category = line.Replace("<", string.Empty).Trim();
-
- if (line.Contains("+")) // A Preset
- {
- Regex r = new Regex("(: )"); // Split on hyphens.
- string[] presetName = r.Split(line);
-
- bool pic = false;
- if (presetName[2].Contains("crop"))
- pic = true;
-
- Preset newPreset = new Preset
- {
- Category = category,
- Name = presetName[0].Replace("+", string.Empty).Trim(),
- Query = presetName[2],
- Version = Properties.Settings.Default.hb_version,
- CropSettings = pic,
- Description = string.Empty // Maybe one day we will populate this.
- };
- this.presets.Add(newPreset);
- }
- }
- presetInput.Close();
- presetInput.Dispose();
- }
-
- // Finally, Create a new or update the current Presets.xml file
- this.UpdatePresetFiles();
- }
-
- /// <summary>
- /// Setup the frmMain preset panel
- /// </summary>
- /// <param name="presetPanel">The Preset Panel from the Main Window</param>
- public void GetPresetPanel(ref TreeView presetPanel)
- {
- this.LoadPresetData();
- presetPanel.Nodes.Clear();
- string category = string.Empty; // The category we are currnetly processing
- TreeNode rootNode = null;
-
- if (this.presets.Count != 0) // Built In Presets
- {
- foreach (Preset preset in this.presets)
- {
- // If the category of this preset doesn't match the current category we are processing
- // Then we need to create a new root node.
- if (preset.Category != category)
- {
- rootNode = new TreeNode(preset.Category);
- presetPanel.Nodes.Add(rootNode);
- category = preset.Category;
- }
-
- if (preset.Category == category && rootNode != null)
- rootNode.Nodes.Add(new TreeNode(preset.Name) { ToolTipText = preset.Description });
- }
- }
-
- rootNode = null;
- category = null;
- foreach (Preset preset in this.userPresets) // User Presets
- {
- if (preset.Category != category && preset.Category != string.Empty)
- {
- rootNode = new TreeNode(preset.Category) {ForeColor = Color.Black};
- presetPanel.Nodes.Add(rootNode);
- category = preset.Category;
- }
-
- if (preset.Category == category && rootNode != null)
- rootNode.Nodes.Add(new TreeNode(preset.Name) {ForeColor = Color.Black, ToolTipText = preset.Description});
- else
- presetPanel.Nodes.Add(new TreeNode(preset.Name) { ForeColor = Color.Black, ToolTipText = preset.Description });
- }
- }
-
- /// <summary>
- /// Check if the user preset "name" exists in UserPresets list.
- /// </summary>
- /// <param name="name">Name of the preset</param>
- /// <returns>true if found</returns>
- public bool CheckIfUserPresetExists(string name)
- {
- return name != string.Empty && this.userPresets.Any(item => item.Name == name);
- }
-
- /// <summary>
- /// Check if the built in Presets stored are not out of date.
- /// Update them if they are.
- /// </summary>
- /// <returns>true if out of date</returns>
- public bool CheckIfPresetsAreOutOfDate()
- {
- this.LoadPresetData();
- // Update built-in Presets if the built-in Presets belong to an older version.
- if (this.presets.Count != 0)
- if (this.presets[0].Version != Properties.Settings.Default.hb_version)
- {
- this.UpdateBuiltInPresets();
- return true;
- }
-
- return false;
- }
-
- /// <summary>
- /// Load in the preset data from Presets.xml and UserPresets.xml
- /// Load it into the 2 arraylist's Presets and UserPresets
- /// </summary>
- private void LoadPresetData()
- {
- // First clear the Presets arraylists
- this.presets.Clear();
- this.userPresets.Clear();
-
- try
- {
- // Load in the users Presets from UserPresets.xml
- if (File.Exists(this.hbPresetFile))
- {
- using (FileStream strm = new FileStream(this.hbPresetFile, FileMode.Open, FileAccess.Read))
- {
- if (strm.Length != 0)
- {
- List<Preset> list = Ser.Deserialize(strm) as List<Preset>;
-
- if (list != null)
- foreach (Preset preset in list)
- this.presets.Add(preset);
- }
- }
- }
- }
- catch (Exception)
- {
- MessageBox.Show(
- "HandBrakes preset file appears to have been corrupted. This file will now be re-generated!\n" +
- "If the problem presists, please delete the file: \n\n" + this.hbPresetFile,
- "Error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- this.UpdateBuiltInPresets();
- }
-
- try
- {
- // Load in the users Presets from UserPresets.xml
- if (File.Exists(this.userPresetFile))
- {
- using (FileStream strm = new FileStream(this.userPresetFile, FileMode.Open, FileAccess.Read))
- {
- if (strm.Length != 0)
- {
- List<Preset> list = Ser.Deserialize(strm) as List<Preset>;
-
- if (list != null)
- foreach (Preset preset in list)
- this.userPresets.Add(preset);
- }
- }
- }
- }
- catch (Exception)
- {
- MessageBox.Show(
- "Your User presets file appears to have been corrupted.\n" +
- "Your presets will not be loaded. You may need to re-create your presets.\n\n" +
- "Your user presets file has been renamed to 'user_presets.xml.old' and is located in:\n " +
- Path.GetDirectoryName(this.userPresetFile) + "\n" +
- "You may be able to recover some presets if you know the XML language.",
- "Error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error);
-
- // Recover from Error.
- if (File.Exists(this.userPresetFile))
- {
- string disabledFile = this.userPresetFile + ".old";
- if (File.Exists(disabledFile))
- File.Delete(disabledFile);
- File.Move(this.userPresetFile, disabledFile);
- }
- }
- }
-
- /// <summary>
- /// Update the preset files
- /// </summary>
- private void UpdatePresetFiles()
- {
- try
- {
- using (FileStream strm = new FileStream(this.hbPresetFile, FileMode.Create, FileAccess.Write))
- {
- Ser.Serialize(strm, this.presets);
- strm.Close();
- strm.Dispose();
- }
-
- using (FileStream strm = new FileStream(this.userPresetFile, FileMode.Create, FileAccess.Write))
- {
- Ser.Serialize(strm, this.userPresets);
- 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,
- "Error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Hand);
- }
- }
-
- /// <summary>
- /// Check if the preset "name" exists in either Presets or UserPresets lists.
- /// </summary>
- /// <param name="name">Name of the preset</param>
- /// <returns>True if found</returns>
- private bool CheckIfPresetExists(string name)
- {
- if (name == string.Empty)
- return true;
-
- // Built In Presets
- foreach (Preset item in this.presets)
- {
- if (item.Name == name)
- return true;
- }
-
- // User Presets
- return this.userPresets.Any(item => item.Name == name);
- }
- }
-}
\ No newline at end of file diff --git a/win/C#/Program.cs b/win/C#/Program.cs index 6b2ab110c..919543c48 100644 --- a/win/C#/Program.cs +++ b/win/C#/Program.cs @@ -12,8 +12,8 @@ namespace Handbrake using System.Windows.Forms;
using HandBrake.ApplicationServices;
+ using HandBrake.ApplicationServices.Services;
- using Handbrake.Presets;
using Handbrake.Properties;
/// <summary>
@@ -90,8 +90,8 @@ namespace Handbrake if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\presets.xml")))
{
- PresetsHandler x = new PresetsHandler();
- x.UpdateBuiltInPresets();
+ PresetService x = new PresetService();
+ x.UpdateBuiltInPresets(string.Empty);
}
InitializeApplicationServices();
diff --git a/win/C#/frmAddPreset.cs b/win/C#/frmAddPreset.cs index 208dd1cc3..bfc804cd5 100644 --- a/win/C#/frmAddPreset.cs +++ b/win/C#/frmAddPreset.cs @@ -8,11 +8,12 @@ namespace Handbrake using System;
using System.Windows.Forms;
+ using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Services;
+
using Handbrake.Functions;
using Handbrake.Model;
- using Presets;
-
/// <summary>
/// The Add Preset Window
/// </summary>
@@ -23,7 +24,7 @@ namespace Handbrake /// <summary>
/// The Preset Handler
/// </summary>
- private readonly PresetsHandler presetCode;
+ private readonly PresetService presetCode;
/// <summary>
/// Initializes a new instance of the <see cref="frmAddPreset"/> class.
@@ -34,7 +35,7 @@ namespace Handbrake /// <param name="presetHandler">
/// The preset handler.
/// </param>
- public frmAddPreset(frmMain mainWindow, PresetsHandler presetHandler)
+ public frmAddPreset(frmMain mainWindow, PresetService presetHandler)
{
InitializeComponent();
this.mainWindow = mainWindow;
@@ -78,7 +79,16 @@ namespace Handbrake string query = QueryGenerator.GenerateQueryForPreset(mainWindow, pictureSettingsMode, check_useFilters.Checked, 0, 0);
- if (presetCode.Add(txt_preset_name.Text.Trim(), query, pictureSettingsMode != QueryPictureSettingsMode.None, string.Empty))
+
+ Preset preset = new Preset
+ {
+ Name = this.txt_preset_name.Text,
+ Query = query,
+ CropSettings = pictureSettingsMode != QueryPictureSettingsMode.None,
+ Description = string.Empty
+ };
+
+ if (presetCode.Add(preset))
{
this.DialogResult = DialogResult.OK;
this.Close();
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index d1b3476e8..64ce8c058 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -12,6 +12,7 @@ namespace Handbrake using System.Drawing;
using System.Globalization;
using System.IO;
+ using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Functions;
@@ -30,7 +31,6 @@ namespace Handbrake using Handbrake.ToolWindows;
using Model;
- using Presets;
using Properties;
using Main = Handbrake.Functions.Main;
@@ -42,7 +42,7 @@ namespace Handbrake {
// Objects which may be used by one or more other objects *************
private IQueueProcessor queueProcessor = new QueueProcessor(Program.InstanceId);
- private PresetsHandler presetHandler = new PresetsHandler();
+ private PresetService presetHandler = new PresetService();
// Windows ************************************************************
private frmQueue queueWindow;
@@ -447,7 +447,7 @@ namespace Handbrake /// </param>
private void mnu_presetReset_Click(object sender, EventArgs e)
{
- presetHandler.UpdateBuiltInPresets();
+ presetHandler.UpdateBuiltInPresets(string.Empty);
LoadPresetPanel();
if (treeView_presets.Nodes.Count == 0)
MessageBox.Show(
@@ -470,7 +470,7 @@ namespace Handbrake /// </param>
private void mnu_delete_preset_Click(object sender, EventArgs e)
{
- presetHandler.RemoveBuiltInPresets();
+ presetHandler.ClearBuiltIn();
LoadPresetPanel(); // Reload the preset panel
}
@@ -648,18 +648,21 @@ namespace Handbrake /// </param>
private void pmnu_saveChanges_Click(object sender, EventArgs e)
{
- // TODO this requires a re-think since the Query Editor has changed.
DialogResult result =
MessageBox.Show(
"Do you wish to include picture settings when updating the preset: " +
treeView_presets.SelectedNode.Text, "Update Preset", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
- if (result == DialogResult.Yes)
- presetHandler.Update(treeView_presets.SelectedNode.Text,
- QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);
- else if (result == DialogResult.No)
- presetHandler.Update(treeView_presets.SelectedNode.Text,
- QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);
+
+ Preset preset = new Preset
+ {
+ Name = this.treeView_presets.SelectedNode.Text,
+ Query =
+ QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0),
+ CropSettings = (result == DialogResult.Yes)
+ };
+
+ presetHandler.Update(preset);
}
/// <summary>
@@ -675,7 +678,7 @@ namespace Handbrake {
if (treeView_presets.SelectedNode != null)
{
- presetHandler.Remove(treeView_presets.SelectedNode.Text);
+ presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag);
treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
}
treeView_presets.Select();
@@ -697,7 +700,7 @@ namespace Handbrake // Now enable the save menu if the selected preset is a user preset
if (treeView_presets.SelectedNode != null)
- if (presetHandler.CheckIfUserPresetExists(treeView_presets.SelectedNode.Text))
+ if (presetHandler.CheckIfPresetExists(treeView_presets.SelectedNode.Text))
pmnu_saveChanges.Enabled = true;
treeView_presets.Select();
@@ -742,7 +745,7 @@ namespace Handbrake {
if (treeView_presets.SelectedNode != null)
{
- presetHandler.Remove(treeView_presets.SelectedNode.Text);
+ presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag);
treeView_presets.Nodes.Remove(treeView_presets.SelectedNode);
}
}
@@ -855,7 +858,7 @@ namespace Handbrake if (result == DialogResult.Yes)
{
if (treeView_presets.SelectedNode != null)
- presetHandler.Remove(treeView_presets.SelectedNode.Text);
+ presetHandler.Remove((Preset)treeView_presets.SelectedNode.Tag);
// Remember each nodes expanded status so we can reload it
List<bool> nodeStatus = new List<bool>();
@@ -938,7 +941,7 @@ namespace Handbrake if (openPreset.ShowDialog() == DialogResult.OK)
{
EncodeTask parsed = PlistPresetHandler.Import(openPreset.FileName);
- if (presetHandler.CheckIfUserPresetExists(parsed.PresetName + " (Imported)"))
+ if (presetHandler.CheckIfPresetExists(parsed.PresetName + " (Imported)"))
{
DialogResult result =
MessageBox.Show("This preset appears to already exist. Would you like to overwrite it?",
@@ -947,17 +950,29 @@ namespace Handbrake if (result == DialogResult.Yes)
{
PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
- presetHandler.Update(parsed.PresetName + " (Imported)",
- QueryGenerator.GenerateFullQuery(this),
- parsed.UsesPictureSettings);
+
+ Preset preset = new Preset
+ {
+ Name = parsed.PresetName + " (Imported)",
+ Query = QueryGenerator.GenerateFullQuery(this),
+ CropSettings = parsed.UsesPictureSettings
+ };
+
+ presetHandler.Update(preset);
}
}
else
{
PresetLoader.LoadPreset(this, parsed, parsed.PresetName);
- if (presetHandler.Add(parsed.PresetName + " (Imported)",
- QueryGenerator.GenerateFullQuery(this),
- parsed.UsesPictureSettings, string.Empty))
+
+ Preset preset = new Preset
+ {
+ Name = parsed.PresetName + " (Imported)",
+ Query = QueryGenerator.GenerateFullQuery(this),
+ CropSettings = parsed.UsesPictureSettings
+ };
+
+ if (presetHandler.Add(preset))
{
TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")
{
@@ -2149,7 +2164,7 @@ namespace Handbrake return;
}
- labelSource.Text = string.Format("Processing Title: {0} of {1}", e.CurrentTitle, e.Titles);
+ labelSource.Text = string.Format("Processing Title: {0} of {1}", e.CurrentTitle, e.Titles);
}
/// <summary>
@@ -2493,7 +2508,44 @@ namespace Handbrake "HandBrake has determined your built-in presets are out of date... These presets will now be updated.",
"Preset Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
- presetHandler.GetPresetPanel(ref treeView_presets);
+ // Clear the old presets
+ treeView_presets.Nodes.Clear();
+
+
+ string category = string.Empty; // The category we are currnetly processing
+ TreeNode rootNode = null;
+ foreach (Preset preset in this.presetHandler.Presets.Where(p => p.IsBuildIn))
+ {
+ // If the category of this preset doesn't match the current category we are processing
+ // Then we need to create a new root node.
+ if (preset.Category != category)
+ {
+ rootNode = new TreeNode(preset.Category) { ForeColor = Color.DarkBlue };
+ treeView_presets.Nodes.Add(rootNode);
+ category = preset.Category;
+ }
+
+ if (preset.Category == category && rootNode != null)
+ rootNode.Nodes.Add(new TreeNode(preset.Name) { ToolTipText = preset.Description, ForeColor = Color.DarkBlue });
+ }
+
+ rootNode = null;
+ category = null;
+ foreach (Preset preset in this.presetHandler.Presets.Where(p => !p.IsBuildIn)) // User Presets
+ {
+ if (preset.Category != category && preset.Category != string.Empty)
+ {
+ rootNode = new TreeNode(preset.Category) { ForeColor = Color.Black };
+ treeView_presets.Nodes.Add(rootNode);
+ category = preset.Category;
+ }
+
+ if (preset.Category == category && rootNode != null)
+ rootNode.Nodes.Add(new TreeNode(preset.Name) { ForeColor = Color.Black, ToolTipText = preset.Description });
+ else
+ treeView_presets.Nodes.Add(new TreeNode(preset.Name) { ForeColor = Color.Black, ToolTipText = preset.Description });
+ }
+
treeView_presets.Update();
}
@@ -2610,7 +2662,7 @@ namespace Handbrake }
if (SourceScan.IsScanning)
- {
+ {
SourceScan.Stop();
}
|