OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 23 Jan 2011 15:00:58 +0000 (15:00 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sun, 23 Jan 2011 15:00:58 +0000 (15:00 +0000)
 - Started Hooking up the WPF main window. Initial events subscribed. Some initial bindings and actions.

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

win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
win/C#/HandBrake.ApplicationServices/Model/EncodeTask.cs
win/C#/HandBrake.ApplicationServices/Parsing/Source.cs [moved from win/C#/HandBrake.ApplicationServices/Parsing/DVD.cs with 78% similarity]
win/C#/HandBrake.ApplicationServices/Services/Interfaces/IScan.cs
win/C#/HandBrake.ApplicationServices/Services/LibScan.cs
win/C#/HandBrake.ApplicationServices/Services/ScanService.cs
win/C#/HandBrakeWPF/HandBrakeWPF.csproj
win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs
win/C#/HandBrakeWPF/ViewModels/ViewModelBase.cs [new file with mode: 0644]
win/C#/HandBrakeWPF/Views/MainView.xaml
win/C#/frmMain.cs

index 57c3ca4..d45228a 100644 (file)
     <Compile Include="Model\Encoding\SubtitleType.cs" />\r
     <Compile Include="Parsing\AudioTrack.cs" />\r
     <Compile Include="Parsing\Chapter.cs" />\r
-    <Compile Include="Parsing\DVD.cs" />\r
+    <Compile Include="Parsing\Source.cs" />\r
     <Compile Include="Parsing\Parser.cs" />\r
     <Compile Include="Parsing\Subtitle.cs" />\r
     <Compile Include="Parsing\Title.cs" />\r
index dfc0fbf..a735902 100644 (file)
@@ -33,6 +33,11 @@ namespace HandBrake.ApplicationServices.Model
         public int Title { get; set; }\r
 \r
         /// <summary>\r
+        /// Gets or sets the Angle\r
+        /// </summary>\r
+        public int Angle { get; set; }\r
+\r
+        /// <summary>\r
         /// Gets or sets PointToPointMode.\r
         /// </summary>\r
         public PointToPointMode PointToPointMode { get; set; }\r
@@ -1,4 +1,4 @@
-/*  DVD.cs $    This file is part of the HandBrake source code.\r
+/*  Source.cs $    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
@@ -10,13 +10,13 @@ namespace HandBrake.ApplicationServices.Parsing
     /// <summary>\r
     /// An object representing a scanned DVD\r
     /// </summary>\r
-    public class DVD\r
+    public class Source\r
     {\r
         /// <summary>\r
-        /// Initializes a new instance of the <see cref="DVD"/> class. \r
+        /// Initializes a new instance of the <see cref="Source"/> class. \r
         /// Default constructor for this object\r
         /// </summary>\r
-        public DVD()\r
+        public Source()\r
         {\r
             Titles = new List<Title>();\r
         }\r
@@ -35,9 +35,9 @@ namespace HandBrake.ApplicationServices.Parsing
         /// <returns>\r
         /// A DVD object which contains a list of title inforamtion\r
         /// </returns>\r
-        public static DVD Parse(StreamReader output)\r
+        public static Source Parse(StreamReader output)\r
         {\r
-            var thisDVD = new DVD();\r
+            var thisDVD = new Source();\r
 \r
             while (!output.EndOfStream)\r
             {\r
index b053903..6cbce52 100644 (file)
@@ -60,7 +60,7 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
         /// <summary>\r
         /// Gets the Souce Data.\r
         /// </summary>\r
-        DVD SouceData { get; }\r
+        Source SouceData { get; }\r
 \r
         /// <summary>\r
         /// Gets ActivityLog.\r
index 50be6aa..ea27ffd 100644 (file)
@@ -97,7 +97,7 @@ namespace HandBrake.ApplicationServices.Services
         /// <summary>\r
         /// Gets the Souce Data.\r
         /// </summary>\r
-        public DVD SouceData { get; private set; }\r
+        public Source SouceData { get; private set; }\r
 \r
         /// <summary>\r
         /// Gets ActivityLog.\r
@@ -179,7 +179,7 @@ namespace HandBrake.ApplicationServices.Services
         /// </param>\r
         private void InstanceScanCompleted(object sender, EventArgs e)\r
         {\r
-            this.SouceData = new DVD { Titles = ConvertTitles(this.instance.Titles) };\r
+            this.SouceData = new Source { Titles = ConvertTitles(this.instance.Titles) };\r
 \r
             IsScanning = false;\r
 \r
index 9b85740..2529f52 100644 (file)
@@ -86,7 +86,7 @@ namespace HandBrake.ApplicationServices.Services
         /// <summary>\r
         /// Gets the Souce Data.\r
         /// </summary>\r
-        public DVD SouceData { get; private set; }\r
+        public Source SouceData { get; private set; }\r
 \r
         /// <summary>\r
         /// Gets ActivityLog.\r
@@ -227,7 +227,7 @@ namespace HandBrake.ApplicationServices.Services
 \r
                 this.readData = new Parser(this.hbProc.StandardError.BaseStream);\r
                 this.readData.OnScanProgress += this.OnScanProgress;\r
-                this.SouceData = DVD.Parse(this.readData);\r
+                this.SouceData = Source.Parse(this.readData);\r
 \r
                 // Write the Buffer out to file.\r
                 using (StreamWriter scanLog = new StreamWriter(dvdInfoPath))\r
index cd2eef0..512833d 100644 (file)
@@ -72,6 +72,7 @@
       <SubType>Code</SubType>\r
     </Compile>\r
     <Compile Include="ViewModels\MainViewModel.cs" />\r
+    <Compile Include="ViewModels\ViewModelBase.cs" />\r
     <Compile Include="Views\MainView.xaml.cs">\r
       <DependentUpon>MainView.xaml</DependentUpon>\r
     </Compile>\r
index 8008064..4b2180d 100644 (file)
@@ -5,26 +5,74 @@
 \r
 namespace HandBrakeWPF.ViewModels\r
 {\r
-    using Caliburn.Core;\r
+    using System;\r
+    using System.Diagnostics;\r
+    using System.IO;\r
+    using System.Windows;\r
+\r
+    using HandBrake.ApplicationServices.Model;\r
+    using HandBrake.ApplicationServices.Parsing;\r
+    using HandBrake.ApplicationServices.Services;\r
+    using HandBrake.ApplicationServices.Services.Interfaces;\r
 \r
     /// <summary>\r
     /// HandBrakes Main Window\r
     /// </summary>\r
-    public class MainViewModel : PropertyChangedBase\r
+    public class MainViewModel : ViewModelBase\r
     {\r
+        #region Private Variables and Services\r
+\r
+        /// <summary>\r
+        /// The Source Scan Service.\r
+        /// </summary>\r
+        private readonly IScan scanService;\r
+\r
+        /// <summary>\r
+        /// The Encode Service\r
+        /// </summary>\r
+        private readonly IQueueProcessor queueProcessor;\r
+\r
         /// <summary>\r
         /// HandBrakes Main Window Title\r
         /// </summary>\r
         private string windowName;\r
 \r
         /// <summary>\r
+        /// The Source Label\r
+        /// </summary>\r
+        private string sourceLabel;\r
+\r
+        /// <summary>\r
+        /// The Toolbar Status Label\r
+        /// </summary>\r
+        private string programStatusLabel;\r
+\r
+        #endregion\r
+\r
+        /// <summary>\r
         /// Initializes a new instance of the <see cref="MainViewModel"/> class.\r
         /// </summary>\r
         public MainViewModel()\r
         {\r
+            // Setup Services\r
+            this.scanService = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService();\r
+            this.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length);\r
+\r
+            // Setup Properties\r
             this.WindowTitle = "HandBrake WPF Test Application";\r
+\r
+            // Setup Events\r
+            this.scanService.ScanStared += this.ScanStared;\r
+            this.scanService.ScanCompleted += this.ScanCompleted;\r
+            this.scanService.ScanStatusChanged += this.ScanStatusChanged;\r
+\r
+            this.queueProcessor.QueueCompleted += this.QueueCompleted;\r
+            this.queueProcessor.QueuePaused += this.QueuePaused;\r
+            this.queueProcessor.EncodeService.EncodeStarted += this.EncodeStarted;\r
+            this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;\r
         }\r
 \r
+        #region Properties\r
         /// <summary>\r
         /// Gets or sets TestProperty.\r
         /// </summary>\r
@@ -44,5 +92,190 @@ namespace HandBrakeWPF.ViewModels
                 }\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
+\r
+        /// <summary>\r
+        /// Gets or sets the Last Scanned Source\r
+        /// This object contains information about the scanned source.\r
+        /// </summary>\r
+        public Source ScannedSource { get; set; }\r
+\r
+        /// <summary>\r
+        /// Gets or sets the Source Label\r
+        /// This indicates the status of scans.\r
+        /// </summary>\r
+        public string SourceLabel\r
+        {\r
+            get\r
+            {\r
+                return string.IsNullOrEmpty(this.sourceLabel) ? "Select 'Source' to continue" : this.sourceLabel;\r
+            }\r
+\r
+            set\r
+            {\r
+                if (!object.Equals(this.sourceLabel, value))\r
+                {\r
+                    this.sourceLabel = value;\r
+                    this.NotifyOfPropertyChange("SourceLabel");\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets or sets the Program Status Toolbar Label\r
+        /// This indicates the status of HandBrake\r
+        /// </summary>\r
+        public string ProgramStatusLabel\r
+        {\r
+            get\r
+            {\r
+                return string.IsNullOrEmpty(this.programStatusLabel) ? "Ready" : this.sourceLabel;\r
+            }\r
+\r
+            set\r
+            {\r
+                if (!object.Equals(this.programStatusLabel, value))\r
+                {\r
+                    this.programStatusLabel = value;\r
+                    this.NotifyOfPropertyChange("ProgramStatusLabel");\r
+                }\r
+            }\r
+        }\r
+\r
+        #endregion\r
+\r
+        /// <summary>\r
+        /// Shutdown this View\r
+        /// </summary>\r
+        public override void Shutdown()\r
+        {\r
+            // Unsubscribe from Events.\r
+            this.scanService.ScanStared -= this.ScanStared;\r
+            this.scanService.ScanCompleted -= this.ScanCompleted;\r
+            this.scanService.ScanStatusChanged -= this.ScanStatusChanged;\r
+\r
+            this.queueProcessor.QueueCompleted -= this.QueueCompleted;\r
+            this.queueProcessor.QueuePaused -= this.QueuePaused;\r
+            this.queueProcessor.EncodeService.EncodeStarted -= this.EncodeStarted;\r
+            this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;\r
+\r
+            // Shutdown Normally\r
+            base.Shutdown();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Shutdown the Application\r
+        /// </summary>\r
+        public void ExitApplication()\r
+        {\r
+            Application.Current.Shutdown();\r
+        }\r
+\r
+        #region Event Handlers\r
+        /// <summary>\r
+        /// Handle the Scan Status Changed Event.\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The Sender\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The EventArgs\r
+        /// </param>\r
+        private void ScanStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs e)\r
+        {\r
+            this.SourceLabel = "Scanning Title " + e.CurrentTitle + " of " + e.Titles;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Handle the Scan Completed Event\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The Sender\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The EventArgs\r
+        /// </param>\r
+        private void ScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)\r
+        {\r
+            if (e.Successful)\r
+            {\r
+                this.ScannedSource = this.scanService.SouceData;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Handle the Scan Started Event\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The Sender\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The EventArgs\r
+        /// </param>\r
+        private void ScanStared(object sender, EventArgs e)\r
+        {\r
+            // TODO - Disable relevant parts of the UI.\r
+        }\r
+\r
+        /// <summary>\r
+        /// The Encode Status has changed Handler\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The Sender\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The Encode Progress Event Args\r
+        /// </param>\r
+        private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e)\r
+        {\r
+            //\r
+        }\r
+\r
+        /// <summary>\r
+        /// Encode Started Handler\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The Sender\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The EventArgs\r
+        /// </param>\r
+        private void EncodeStarted(object sender, EventArgs e)\r
+        {\r
+            // TODO Handle Updating the UI\r
+        }\r
+\r
+        /// <summary>\r
+        /// The Queue has been paused handler\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The Sender\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The EventArgs\r
+        /// </param>\r
+        private void QueuePaused(object sender, EventArgs e)\r
+        {\r
+            // TODO Handle Updating the UI\r
+        }\r
+\r
+        /// <summary>\r
+        /// The Queue has completed handler\r
+        /// </summary>\r
+        /// <param name="sender">\r
+        /// The Sender\r
+        /// </param>\r
+        /// <param name="e">\r
+        /// The EventArgs\r
+        /// </param>\r
+        private void QueueCompleted(object sender, EventArgs e)\r
+        {\r
+            // TODO Handle Updating the UI\r
+        }\r
+        #endregion\r
     }\r
-}\r
+}
\ No newline at end of file
diff --git a/win/C#/HandBrakeWPF/ViewModels/ViewModelBase.cs b/win/C#/HandBrakeWPF/ViewModels/ViewModelBase.cs
new file mode 100644 (file)
index 0000000..8295246
--- /dev/null
@@ -0,0 +1,12 @@
+namespace HandBrakeWPF.ViewModels\r
+{\r
+    using Caliburn.Core;\r
+    using Caliburn.PresentationFramework.ApplicationModel;\r
+\r
+    /// <summary>\r
+    /// A Base Class for the View Models which contains reusable code.\r
+    /// </summary>\r
+    public class ViewModelBase : MultiPresenterManager\r
+    {\r
+    }\r
+}\r
index 493cb35..86f8078 100644 (file)
@@ -1,7 +1,6 @@
 <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"\r
-        Title="{Binding Path=WindowTitle}" Height="645" Width="1015" FontSize="11">\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
     <Grid>\r
         <Grid.RowDefinitions>\r
@@ -19,7 +18,7 @@
         <Menu Height="23" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Stretch">\r
             <MenuItem Header="File">\r
                 <MenuItem Header="Cancel Scan" />\r
-                <MenuItem Header="Exit" />\r
+                <MenuItem Header="Exit" PresentationFramework:Message.Attach="[Event Click] = [Action ExitApplication]" />\r
             </MenuItem>\r
 \r
             <MenuItem Header="Tools">\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="Select 'Source' to continue" />\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" />\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"/>\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" />\r
-                <ComboBox Name="StartPoint" Margin="8,0,0,0" MinWidth="60" />\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" />\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
             <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" />\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
             <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" />\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" VerticalAlignment="Center" Margin="8,0,0,0" />\r
-                <CheckBox Name="WebOptimized" Content="Web Optimized" VerticalAlignment="Center" Margin="8,0,0,0" />\r
-                <CheckBox Name="iPod5G" Content="iPod 5G Support" VerticalAlignment="Center" Margin="8,0,0,0" />\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
         \r
         <!-- Status Bar -->\r
         <StatusBar Grid.Row="6" Height="30" VerticalAlignment="Bottom">\r
-            <Label Content="Ready" FontSize="11" />\r
+            <Label Content="{Binding Path=ProgramStatusLabel}" FontSize="10" VerticalAlignment="Center" />\r
         </StatusBar>\r
         \r
     </Grid>\r
index b4feee8..f1462e8 100644 (file)
@@ -55,7 +55,7 @@ namespace Handbrake
         private string dvdDrivePath;\r
         private string dvdDriveLabel;\r
         private Preset currentlySelectedPreset;\r
-        private DVD currentSource;\r
+        private Source currentSource;\r
 \r
         private IScan SourceScan;\r
         private List<DriveInformation> drives;\r