summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2011-12-22 17:24:04 +0000
committersr55 <[email protected]>2011-12-22 17:24:04 +0000
commiteef8f901a34f163693bd3f79d0e2265d592b880e (patch)
treeac46c4dc5c78a32d89ad78524d95ffdfd0eb7d4d /win
parentbb768a36a9a4e5736267f8722b240492fef0cac6 (diff)
WinGui: (WPF) Work on the Chapters Panel + Missing Image files.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4384 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj1
-rw-r--r--win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml13
-rw-r--r--win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml.cs134
-rw-r--r--win/CS/HandBrakeWPF/Views/Images/Close.pngbin0 -> 1038 bytes
-rw-r--r--win/CS/HandBrakeWPF/Views/Images/Help24.pngbin0 -> 1684 bytes
-rw-r--r--win/CS/HandBrakeWPF/Views/Images/delete.pngbin0 -> 3106 bytes
6 files changed, 137 insertions, 11 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index cea841fe4..fa78a1515 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -225,6 +225,7 @@
<Content Include="defaultsettings.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <Resource Include="Views\Images\delete.png" />
<Resource Include="Views\Images\Close.png" />
<Resource Include="Views\Images\Help24.png" />
<Resource Include="Views\Images\Help32.png" />
diff --git a/win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml b/win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml
index 5a749a568..1f905065d 100644
--- a/win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml
+++ b/win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml
@@ -21,12 +21,17 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<CheckBox Content="Create chapter markers" IsChecked="{Binding IncludeChapterMarkers, RelativeSource={RelativeSource AncestorType=UserControl}}" Grid.Column="0" VerticalAlignment="Center" />
- <Button Content="Import" Grid.Column="2" Width="75" Margin="0,0,10,0" />
- <Button Content="Export" Grid.Column="3" Width="75" />
+ <Button Content="Import" Name="import" Grid.Column="2" Width="75" Margin="0,0,10,0" Click="Import_Click" />
+ <Button Content="Export" Name="export" Grid.Column="3" Width="75" Click="Export_Click" />
</Grid>
- <DataGrid Grid.Row="2" Margin="10" ItemsSource="{Binding Chapters, RelativeSource={RelativeSource AncestorType=UserControl}}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
-
+ <DataGrid Grid.Row="2" Margin="10" ItemsSource="{Binding Chapters, RelativeSource={RelativeSource AncestorType=UserControl}}"
+ VerticalAlignment="Stretch" HorizontalAlignment="Stretch" AutoGenerateColumns="False"
+ CanUserSortColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False">
+ <DataGrid.Columns>
+ <DataGridTextColumn Header="Chapter Number" Width="150" Binding="{Binding ChapterNumber}" IsReadOnly="True" />
+ <DataGridTextColumn Header="Chapter Name" Width="*" Binding="{Binding ChapterName}" IsReadOnly="False" />
+ </DataGrid.Columns>
</DataGrid>
diff --git a/win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml.cs b/win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml.cs
index a9ef20d95..247378875 100644
--- a/win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml.cs
+++ b/win/CS/HandBrakeWPF/Views/Controls/ChaptersView.xaml.cs
@@ -12,10 +12,15 @@ namespace HandBrakeWPF.Views.Controls
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+ using System.IO;
using System.Windows;
using System.Windows.Controls;
+ using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Model.Encoding;
+ using HandBrake.ApplicationServices.Parsing;
+
+ using Ookii.Dialogs.Wpf;
/// <summary>
/// Interaction logic for ChaptersView.xaml
@@ -23,11 +28,17 @@ namespace HandBrakeWPF.Views.Controls
public partial class ChaptersView : UserControl
{
/// <summary>
+ /// Gets or sets SourceChapterList.
+ /// </summary>
+ private ObservableCollection<Chapter> SourceChapterList { get; set; }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="ChaptersView"/> class.
/// </summary>
public ChaptersView()
{
InitializeComponent();
+ this.SourceChapterList = new ObservableCollection<Chapter>();
}
/// <summary>
@@ -43,7 +54,7 @@ namespace HandBrakeWPF.Views.Controls
/// <summary>
/// Gets or sets State.
/// </summary>
- public IList<ChapterMarker> Chapters
+ public ObservableCollection<ChapterMarker> Chapters
{
get { return (ObservableCollection<ChapterMarker>)this.GetValue(ChaptersProperty); }
set { this.SetValue(ChaptersProperty, value); }
@@ -59,19 +70,128 @@ namespace HandBrakeWPF.Views.Controls
}
/// <summary>
- /// Import from CSV
+ /// Set the Source Chapters List
+ /// </summary>
+ /// <param name="sourceChapters">
+ /// The source chapters.
+ /// </param>
+ public void SetSourceChapters(IEnumerable<Chapter> sourceChapters)
+ {
+ // Cache the chapters in this screen
+ this.SourceChapterList = new ObservableCollection<Chapter>(sourceChapters);
+ this.Chapters.Clear();
+
+ // Then Add new Chapter Markers.
+ foreach (Chapter chapter in SourceChapterList)
+ {
+ ChapterMarker marker = new ChapterMarker(chapter.ChapterNumber, chapter.ChapterName);
+ this.Chapters.Add(marker);
+ }
+ }
+
+ /// <summary>
+ /// Export the Chapter Markers to a CSV file
/// </summary>
- public void Import()
+ /// <param name="filename">
+ /// The filename.
+ /// </param>
+ /// <exception cref="GeneralApplicationException">
+ /// Thrown when exporting fails.
+ /// </exception>
+ public void ExportChaptersToCSV(string filename)
{
- throw new NotImplementedException("Not Implemented Yet");
+ try
+ {
+ string csv = string.Empty;
+
+ foreach (ChapterMarker row in this.Chapters)
+ {
+ csv += row.ChapterNumber.ToString();
+ csv += ",";
+ csv += row.ChapterName.Replace(",", "\\,");
+ csv += Environment.NewLine;
+ }
+ StreamWriter file = new StreamWriter(filename);
+ file.Write(csv);
+ file.Close();
+ file.Dispose();
+ }
+ catch (Exception exc)
+ {
+ throw new GeneralApplicationException("Unable to save Chapter Makrers file! ", "Chapter marker names will NOT be saved in your encode.", exc);
+ }
+ }
+
+ /// <summary>
+ /// Import a CSV file
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The RoutedEventArgs.
+ /// </param>
+ private void Import_Click(object sender, RoutedEventArgs e)
+ {
+ VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "CSV files (*.csv)|*.csv", CheckFileExists = true };
+ dialog.ShowDialog();
+ string filename = dialog.FileName;
+
+ if (string.IsNullOrEmpty(filename))
+ {
+ return;
+ }
+
+ IDictionary<int, string> chapterMap = new Dictionary<int, string>();
+ try
+ {
+ StreamReader sr = new StreamReader(filename);
+ string csv = sr.ReadLine();
+ while (csv != null)
+ {
+ if (csv.Trim() != string.Empty)
+ {
+ csv = csv.Replace("\\,", "<!comma!>");
+ string[] contents = csv.Split(',');
+ int chapter;
+ int.TryParse(contents[0], out chapter);
+ chapterMap.Add(chapter, contents[1].Replace("<!comma!>", ","));
+ }
+ csv = sr.ReadLine();
+ }
+ }
+ catch (Exception)
+ {
+ // Do Nothing
+ }
+
+ // Now iterate over each chatper we have, and set it's name
+ foreach (ChapterMarker item in Chapters)
+ {
+ string chapterName;
+ chapterMap.TryGetValue(item.ChapterNumber, out chapterName);
+ item.ChapterName = chapterName;
+ // TODO force a fresh of this property
+ }
}
/// <summary>
- /// Export to CSV
+ /// Export a CSV file.
/// </summary>
- public void Export()
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The RoutedEventArgs.
+ /// </param>
+ private void Export_Click(object sender, RoutedEventArgs e)
{
- throw new NotImplementedException("Not Implemented Yet");
+ VistaSaveFileDialog saveFileDialog = new VistaSaveFileDialog { Filter = "Csv File|*.csv", DefaultExt = "csv", CheckPathExists = true };
+ saveFileDialog.ShowDialog();
+ if (!string.IsNullOrEmpty(saveFileDialog.FileName))
+ {
+ this.ExportChaptersToCSV(saveFileDialog.FileName);
+ }
}
}
}
diff --git a/win/CS/HandBrakeWPF/Views/Images/Close.png b/win/CS/HandBrakeWPF/Views/Images/Close.png
new file mode 100644
index 000000000..7d84e5b80
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Views/Images/Close.png
Binary files differ
diff --git a/win/CS/HandBrakeWPF/Views/Images/Help24.png b/win/CS/HandBrakeWPF/Views/Images/Help24.png
new file mode 100644
index 000000000..1c6e13069
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Views/Images/Help24.png
Binary files differ
diff --git a/win/CS/HandBrakeWPF/Views/Images/delete.png b/win/CS/HandBrakeWPF/Views/Images/delete.png
new file mode 100644
index 000000000..5e6c9627d
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Views/Images/delete.png
Binary files differ