summaryrefslogtreecommitdiffstats
path: root/win/C#/HandBrakeWPF
diff options
context:
space:
mode:
authorsr55 <[email protected]>2011-01-23 15:00:58 +0000
committersr55 <[email protected]>2011-01-23 15:00:58 +0000
commitc0ac2af7f81171a91f726cdf3833af1deadf8511 (patch)
tree3727abbd76bf4ec9c4da492ac9125475a1a10333 /win/C#/HandBrakeWPF
parentb55c482455353fea828f52d6889ad451202a6a5f (diff)
WinGui:
- Started Hooking up the WPF main window. Initial events subscribed. Some initial bindings and actions. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3766 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/HandBrakeWPF')
-rw-r--r--win/C#/HandBrakeWPF/HandBrakeWPF.csproj1
-rw-r--r--win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs239
-rw-r--r--win/C#/HandBrakeWPF/ViewModels/ViewModelBase.cs12
-rw-r--r--win/C#/HandBrakeWPF/Views/MainView.xaml29
4 files changed, 263 insertions, 18 deletions
diff --git a/win/C#/HandBrakeWPF/HandBrakeWPF.csproj b/win/C#/HandBrakeWPF/HandBrakeWPF.csproj
index cd2eef097..512833dc5 100644
--- a/win/C#/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/C#/HandBrakeWPF/HandBrakeWPF.csproj
@@ -72,6 +72,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="ViewModels\MainViewModel.cs" />
+ <Compile Include="ViewModels\ViewModelBase.cs" />
<Compile Include="Views\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
</Compile>
diff --git a/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs
index 8008064f3..4b2180dd3 100644
--- a/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/C#/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -5,26 +5,74 @@
namespace HandBrakeWPF.ViewModels
{
- using Caliburn.Core;
+ using System;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Windows;
+
+ using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Parsing;
+ using HandBrake.ApplicationServices.Services;
+ using HandBrake.ApplicationServices.Services.Interfaces;
/// <summary>
/// HandBrakes Main Window
/// </summary>
- public class MainViewModel : PropertyChangedBase
+ public class MainViewModel : ViewModelBase
{
+ #region Private Variables and Services
+
+ /// <summary>
+ /// The Source Scan Service.
+ /// </summary>
+ private readonly IScan scanService;
+
+ /// <summary>
+ /// The Encode Service
+ /// </summary>
+ private readonly IQueueProcessor queueProcessor;
+
/// <summary>
/// HandBrakes Main Window Title
/// </summary>
private string windowName;
/// <summary>
+ /// The Source Label
+ /// </summary>
+ private string sourceLabel;
+
+ /// <summary>
+ /// The Toolbar Status Label
+ /// </summary>
+ private string programStatusLabel;
+
+ #endregion
+
+ /// <summary>
/// Initializes a new instance of the <see cref="MainViewModel"/> class.
/// </summary>
public MainViewModel()
{
+ // Setup Services
+ this.scanService = File.Exists("hb.dll") ? (IScan)new LibScan() : new ScanService();
+ this.queueProcessor = new QueueProcessor(Process.GetProcessesByName("HandBrake").Length);
+
+ // Setup Properties
this.WindowTitle = "HandBrake WPF Test Application";
+
+ // Setup Events
+ this.scanService.ScanStared += this.ScanStared;
+ this.scanService.ScanCompleted += this.ScanCompleted;
+ this.scanService.ScanStatusChanged += this.ScanStatusChanged;
+
+ this.queueProcessor.QueueCompleted += this.QueueCompleted;
+ this.queueProcessor.QueuePaused += this.QueuePaused;
+ this.queueProcessor.EncodeService.EncodeStarted += this.EncodeStarted;
+ this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;
}
+ #region Properties
/// <summary>
/// Gets or sets TestProperty.
/// </summary>
@@ -44,5 +92,190 @@ namespace HandBrakeWPF.ViewModels
}
}
}
+
+ /// <summary>
+ /// Gets or sets The Current Encode Task that the user is building
+ /// </summary>
+ public EncodeTask CurrentTask { get; set; }
+
+ /// <summary>
+ /// Gets or sets the Last Scanned Source
+ /// This object contains information about the scanned source.
+ /// </summary>
+ public Source ScannedSource { get; set; }
+
+ /// <summary>
+ /// Gets or sets the Source Label
+ /// This indicates the status of scans.
+ /// </summary>
+ public string SourceLabel
+ {
+ get
+ {
+ return string.IsNullOrEmpty(this.sourceLabel) ? "Select 'Source' to continue" : this.sourceLabel;
+ }
+
+ set
+ {
+ if (!object.Equals(this.sourceLabel, value))
+ {
+ this.sourceLabel = value;
+ this.NotifyOfPropertyChange("SourceLabel");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the Program Status Toolbar Label
+ /// This indicates the status of HandBrake
+ /// </summary>
+ public string ProgramStatusLabel
+ {
+ get
+ {
+ return string.IsNullOrEmpty(this.programStatusLabel) ? "Ready" : this.sourceLabel;
+ }
+
+ set
+ {
+ if (!object.Equals(this.programStatusLabel, value))
+ {
+ this.programStatusLabel = value;
+ this.NotifyOfPropertyChange("ProgramStatusLabel");
+ }
+ }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Shutdown this View
+ /// </summary>
+ public override void Shutdown()
+ {
+ // Unsubscribe from Events.
+ this.scanService.ScanStared -= this.ScanStared;
+ this.scanService.ScanCompleted -= this.ScanCompleted;
+ this.scanService.ScanStatusChanged -= this.ScanStatusChanged;
+
+ this.queueProcessor.QueueCompleted -= this.QueueCompleted;
+ this.queueProcessor.QueuePaused -= this.QueuePaused;
+ this.queueProcessor.EncodeService.EncodeStarted -= this.EncodeStarted;
+ this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;
+
+ // Shutdown Normally
+ base.Shutdown();
+ }
+
+ /// <summary>
+ /// Shutdown the Application
+ /// </summary>
+ public void ExitApplication()
+ {
+ Application.Current.Shutdown();
+ }
+
+ #region Event Handlers
+ /// <summary>
+ /// Handle the Scan Status Changed Event.
+ /// </summary>
+ /// <param name="sender">
+ /// The Sender
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs
+ /// </param>
+ private void ScanStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.ScanProgressEventArgs e)
+ {
+ this.SourceLabel = "Scanning Title " + e.CurrentTitle + " of " + e.Titles;
+ }
+
+ /// <summary>
+ /// Handle the Scan Completed Event
+ /// </summary>
+ /// <param name="sender">
+ /// The Sender
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs
+ /// </param>
+ private void ScanCompleted(object sender, HandBrake.ApplicationServices.EventArgs.ScanCompletedEventArgs e)
+ {
+ if (e.Successful)
+ {
+ this.ScannedSource = this.scanService.SouceData;
+ }
+ }
+
+ /// <summary>
+ /// Handle the Scan Started Event
+ /// </summary>
+ /// <param name="sender">
+ /// The Sender
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs
+ /// </param>
+ private void ScanStared(object sender, EventArgs e)
+ {
+ // TODO - Disable relevant parts of the UI.
+ }
+
+ /// <summary>
+ /// The Encode Status has changed Handler
+ /// </summary>
+ /// <param name="sender">
+ /// The Sender
+ /// </param>
+ /// <param name="e">
+ /// The Encode Progress Event Args
+ /// </param>
+ private void EncodeStatusChanged(object sender, HandBrake.ApplicationServices.EventArgs.EncodeProgressEventArgs e)
+ {
+ //
+ }
+
+ /// <summary>
+ /// Encode Started Handler
+ /// </summary>
+ /// <param name="sender">
+ /// The Sender
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs
+ /// </param>
+ private void EncodeStarted(object sender, EventArgs e)
+ {
+ // TODO Handle Updating the UI
+ }
+
+ /// <summary>
+ /// The Queue has been paused handler
+ /// </summary>
+ /// <param name="sender">
+ /// The Sender
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs
+ /// </param>
+ private void QueuePaused(object sender, EventArgs e)
+ {
+ // TODO Handle Updating the UI
+ }
+
+ /// <summary>
+ /// The Queue has completed handler
+ /// </summary>
+ /// <param name="sender">
+ /// The Sender
+ /// </param>
+ /// <param name="e">
+ /// The EventArgs
+ /// </param>
+ private void QueueCompleted(object sender, EventArgs e)
+ {
+ // TODO Handle Updating the UI
+ }
+ #endregion
}
-}
+} \ 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
index 000000000..829524606
--- /dev/null
+++ b/win/C#/HandBrakeWPF/ViewModels/ViewModelBase.cs
@@ -0,0 +1,12 @@
+namespace HandBrakeWPF.ViewModels
+{
+ using Caliburn.Core;
+ using Caliburn.PresentationFramework.ApplicationModel;
+
+ /// <summary>
+ /// A Base Class for the View Models which contains reusable code.
+ /// </summary>
+ public class ViewModelBase : MultiPresenterManager
+ {
+ }
+}
diff --git a/win/C#/HandBrakeWPF/Views/MainView.xaml b/win/C#/HandBrakeWPF/Views/MainView.xaml
index 493cb357a..86f807854 100644
--- a/win/C#/HandBrakeWPF/Views/MainView.xaml
+++ b/win/C#/HandBrakeWPF/Views/MainView.xaml
@@ -1,7 +1,6 @@
<Window x:Class="HandBrakeWPF.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="{Binding Path=WindowTitle}" Height="645" Width="1015" FontSize="11">
+ 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>
@@ -19,7 +18,7 @@
<Menu Height="23" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<MenuItem Header="File">
<MenuItem Header="Cancel Scan" />
- <MenuItem Header="Exit" />
+ <MenuItem Header="Exit" PresentationFramework:Message.Attach="[Event Click] = [Action ExitApplication]" />
</MenuItem>
<MenuItem Header="Tools">
@@ -98,20 +97,20 @@
<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="Select 'Source' to continue" />
+ <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" />
+ <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"/>
+ <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" />
- <ComboBox Name="StartPoint" Margin="8,0,0,0" MinWidth="60" />
+ <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" />
+ <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>
@@ -122,7 +121,7 @@
<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" />
+ <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>
@@ -132,11 +131,11 @@
<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" />
+ <ComboBox Name="Container" Margin="8,0,0,0" MinWidth="100" SelectedItem="{Binding Path=CurrentTask.OutputFormat}" />
- <CheckBox Name="LargeFileMp4" Content="Large File Size" VerticalAlignment="Center" Margin="8,0,0,0" />
- <CheckBox Name="WebOptimized" Content="Web Optimized" VerticalAlignment="Center" Margin="8,0,0,0" />
- <CheckBox Name="iPod5G" Content="iPod 5G Support" VerticalAlignment="Center" Margin="8,0,0,0" />
+ <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>
@@ -164,7 +163,7 @@
<!-- Status Bar -->
<StatusBar Grid.Row="6" Height="30" VerticalAlignment="Bottom">
- <Label Content="Ready" FontSize="11" />
+ <Label Content="{Binding Path=ProgramStatusLabel}" FontSize="10" VerticalAlignment="Center" />
</StatusBar>
</Grid>