OSDN Git Service

WinGui
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 18 Feb 2011 21:56:19 +0000 (21:56 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 18 Feb 2011 21:56:19 +0000 (21:56 +0000)
- Wire in the new preset service.

git-svn-id: svn://localhost/HandBrake/trunk@3799 b64f7644-9d1e-0410-96f1-a4d463321fa5

12 files changed:
win/C#/Controls/AudioPanel.cs
win/C#/Controls/PictureSettings.cs
win/C#/HandBrake.ApplicationServices/Model/Preset.cs
win/C#/HandBrake.ApplicationServices/Services/Interfaces/IPresetService.cs
win/C#/HandBrake.ApplicationServices/Services/PresetService.cs
win/C#/HandBrakeCS.csproj
win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs
win/C#/HandBrakeWPF/Views/MainView.xaml
win/C#/Presets/PresetsHandler.cs [deleted file]
win/C#/Program.cs
win/C#/frmAddPreset.cs
win/C#/frmMain.cs

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