diff options
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs | 227 |
1 files changed, 117 insertions, 110 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs index cc882b160..9595855bc 100644 --- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs @@ -10,7 +10,6 @@ namespace HandBrakeWPF.ViewModels
{
using System.Collections.Generic;
- using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel.Composition;
using System.Linq;
@@ -36,11 +35,6 @@ namespace HandBrakeWPF.ViewModels #region Constants and Fields
/// <summary>
- /// The subtitle tracks.
- /// </summary>
- private ObservableCollection<SubtitleTrack> subtitleTracks;
-
- /// <summary>
/// Backing field for the source subtitle tracks.
/// </summary>
private IEnumerable<Subtitle> sourceTracks;
@@ -60,32 +54,20 @@ namespace HandBrakeWPF.ViewModels /// </param>
public SubtitlesViewModel(IWindowManager windowManager, IUserSettingService userSettingService)
{
- this.SubtitleTracks = new ObservableCollection<SubtitleTrack>();
+ this.Task = new EncodeTask();
- Langauges = LanguageUtilities.MapLanguages().Keys;
- CharacterCodes = CharCodesUtilities.GetCharacterCodes();
+ this.Langauges = LanguageUtilities.MapLanguages().Keys;
+ this.CharacterCodes = CharCodesUtilities.GetCharacterCodes();
}
#endregion
- #region Public Properties
+ #region Properties
/// <summary>
- /// Gets or sets State.
+ /// Gets or sets CharacterCodes.
/// </summary>
- public ObservableCollection<SubtitleTrack> SubtitleTracks
- {
- get
- {
- return this.subtitleTracks;
- }
-
- set
- {
- this.subtitleTracks = value;
- this.NotifyOfPropertyChange(() => this.SubtitleTracks);
- }
- }
+ public IEnumerable<string> CharacterCodes { get; set; }
/// <summary>
/// Gets or sets Langauges.
@@ -93,11 +75,6 @@ namespace HandBrakeWPF.ViewModels public IEnumerable<string> Langauges { get; set; }
/// <summary>
- /// Gets or sets CharacterCodes.
- /// </summary>
- public IEnumerable<string> CharacterCodes { get; set; }
-
- /// <summary>
/// Gets or sets SourceTracks.
/// </summary>
public IEnumerable<Subtitle> SourceTracks
@@ -106,13 +83,19 @@ namespace HandBrakeWPF.ViewModels {
return this.sourceTracks;
}
+
set
{
this.sourceTracks = value;
- this.NotifyOfPropertyChange(() => SourceTracks);
+ this.NotifyOfPropertyChange(() => this.SourceTracks);
}
}
+ /// <summary>
+ /// Gets or sets Task.
+ /// </summary>
+ public EncodeTask Task { get; set; }
+
#endregion
#region Public Methods
@@ -126,11 +109,46 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
+ /// Automatic Subtitle Selection based on user preferences.
+ /// </summary>
+ public void AutomaticSubtitleSelection()
+ {
+ this.Task.SubtitleTracks.Clear();
+
+ // New DUB Settings
+ int mode = this.UserSettingService.GetUserSetting<int>(UserSettingConstants.DubModeSubtitle);
+ switch (mode)
+ {
+ case 1: // Adding all remaining subtitle tracks
+ this.AddAllRemaining();
+ break;
+ case 2: // Adding only the first or preferred first subtitle track.
+ this.Add();
+ break;
+ case 3: // Selected Languages Only
+ this.AddAllRemainingForSelectedLanguages();
+ break;
+ case 4: // Prefered Only
+ this.AddForPreferredLanaguages(true);
+ break;
+ case 5: // Prefered Only All
+ this.AddForPreferredLanaguages(false);
+ break;
+ }
+
+ // Add all closed captions if enabled.
+ this.AddAllClosedCaptions();
+ }
+
+ /// <summary>
/// Import an SRT File.
/// </summary>
public void Import()
{
- VistaOpenFileDialog dialog = new VistaOpenFileDialog { Filter = "SRT files (*.srt)|*.srt", CheckFileExists = true, Multiselect = true };
+ VistaOpenFileDialog dialog = new VistaOpenFileDialog
+ {
+ Filter = "SRT files (*.srt)|*.srt", CheckFileExists = true, Multiselect = true
+ };
dialog.ShowDialog();
@@ -138,13 +156,13 @@ namespace HandBrakeWPF.ViewModels {
SubtitleTrack track = new SubtitleTrack
{
- SrtFileName = srtFile,
- SrtOffset = 0,
- SrtCharCode = "UTF-8",
- SrtLang = "English",
+ SrtFileName = srtFile,
+ SrtOffset = 0,
+ SrtCharCode = "UTF-8",
+ SrtLang = "English",
SubtitleType = SubtitleType.SRT
};
- this.SubtitleTracks.Add(track);
+ this.Task.SubtitleTracks.Add(track);
}
}
@@ -156,75 +174,56 @@ namespace HandBrakeWPF.ViewModels /// </param>
public void Remove(SubtitleTrack track)
{
- this.SubtitleTracks.Remove(track);
+ this.Task.SubtitleTracks.Remove(track);
}
+ #endregion
+
+ #region Implemented Interfaces
+
+ #region ITabInterface
+
/// <summary>
- /// Setup this window for a new source
+ /// Setup this tab for the specified preset.
/// </summary>
- /// <param name="title">
- /// The title.
- /// </param>
/// <param name="preset">
/// The preset.
/// </param>
/// <param name="task">
/// The task.
/// </param>
- public void SetSource(Title title, Preset preset, EncodeTask task)
+ public void SetPreset(Preset preset, EncodeTask task)
{
- this.SourceTracks = title.Subtitles;
- this.SubtitleTracks = task.SubtitleTracks;
-
- this.AutomaticSubtitleSelection();
+ this.Task = task;
+ this.NotifyOfPropertyChange(() => this.Task);
}
/// <summary>
- /// Setup this tab for the specified preset.
+ /// Setup this window for a new source
/// </summary>
+ /// <param name="title">
+ /// The title.
+ /// </param>
/// <param name="preset">
/// The preset.
/// </param>
- public void SetPreset(Preset preset)
- {
- // We don't currently support subtitles within presets.
- }
-
- /// <summary>
- /// Automatic Subtitle Selection based on user preferences.
- /// </summary>
- public void AutomaticSubtitleSelection()
+ /// <param name="task">
+ /// The task.
+ /// </param>
+ public void SetSource(Title title, Preset preset, EncodeTask task)
{
- this.SubtitleTracks.Clear();
-
- // New DUB Settings
- int mode = UserSettingService.GetUserSetting<int>(UserSettingConstants.DubModeSubtitle);
- switch (mode)
- {
- case 1: // Adding all remaining subtitle tracks
- this.AddAllRemaining();
- break;
- case 2: // Adding only the first or preferred first subtitle track.
- this.Add();
- break;
- case 3: // Selected Languages Only
- this.AddAllRemainingForSelectedLanguages();
- break;
- case 4: // Prefered Only
- this.AddForPreferredLanaguages(true);
- break;
- case 5: // Prefered Only All
- this.AddForPreferredLanaguages(false);
- break;
- }
+ this.SourceTracks = title.Subtitles;
+ this.Task = task;
+ this.NotifyOfPropertyChange(() => this.Task);
- // Add all closed captions if enabled.
- this.AddAllClosedCaptions();
+ this.AutomaticSubtitleSelection();
}
#endregion
- #region Private Methods
+ #endregion
+
+ #region Methods
/// <summary>
/// Add a subtitle track.
@@ -241,20 +240,36 @@ namespace HandBrakeWPF.ViewModels {
if (this.SourceTracks != null)
{
- string preferred = UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles);
+ string preferred =
+ this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles);
- Subtitle source = subtitle ?? (this.SourceTracks.FirstOrDefault(l => l.Language == preferred) ??
- this.SourceTracks.FirstOrDefault());
+ Subtitle source = subtitle ??
+ (this.SourceTracks.FirstOrDefault(l => l.Language == preferred) ??
+ this.SourceTracks.FirstOrDefault());
if (source != null)
{
SubtitleTrack track = new SubtitleTrack
- {
- SubtitleType = SubtitleType.VobSub,
- SourceTrack = source,
- };
+ {
+ SubtitleType = SubtitleType.VobSub, SourceTrack = source,
+ };
- this.SubtitleTracks.Add(track);
+ this.Task.SubtitleTracks.Add(track);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Add all closed captions not already on the list.
+ /// </summary>
+ private void AddAllClosedCaptions()
+ {
+ if (this.UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseClosedCaption))
+ {
+ foreach (
+ Subtitle subtitle in this.SourceTitlesSubset(null).Where(s => s.SubtitleType == SubtitleType.CC))
+ {
+ this.Add(subtitle);
}
}
}
@@ -276,9 +291,12 @@ namespace HandBrakeWPF.ViewModels private void AddAllRemainingForSelectedLanguages()
{
// Get a list of subtitle tracks that match the users lanaguages
- StringCollection userSelectedLanguages = UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages);
- userSelectedLanguages.Add(UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles));
- List<Subtitle> availableTracks = this.SourceTracks.Where(subtitle => userSelectedLanguages.Contains(subtitle.Language)).ToList();
+ StringCollection userSelectedLanguages =
+ this.UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages);
+ userSelectedLanguages.Add(
+ this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles));
+ List<Subtitle> availableTracks =
+ this.SourceTracks.Where(subtitle => userSelectedLanguages.Contains(subtitle.Language)).ToList();
foreach (Subtitle subtitle in this.SourceTitlesSubset(availableTracks))
{
@@ -294,8 +312,8 @@ namespace HandBrakeWPF.ViewModels /// </param>
private void AddForPreferredLanaguages(bool firstOnly)
{
- string preferred = UserSettingService.GetUserSetting<string>(
- UserSettingConstants.NativeLanguageForSubtitles);
+ string preferred =
+ this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles);
foreach (Subtitle subtitle in this.SourceTitlesSubset(null))
{
@@ -311,20 +329,6 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
- /// Add all closed captions not already on the list.
- /// </summary>
- private void AddAllClosedCaptions()
- {
- if (UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseClosedCaption))
- {
- foreach (Subtitle subtitle in this.SourceTitlesSubset(null).Where(s => s.SubtitleType == SubtitleType.CC))
- {
- this.Add(subtitle);
- }
- }
- }
-
- /// <summary>
/// Gets a list of Source subtitle tracks that are not currently used.
/// </summary>
/// <param name="subtitles">
@@ -335,8 +339,11 @@ namespace HandBrakeWPF.ViewModels /// </returns>
private IEnumerable<Subtitle> SourceTitlesSubset(IEnumerable<Subtitle> subtitles)
{
- return subtitles != null ? subtitles.Where(subtitle => !this.SubtitleTracks.Any(track => track.SourceTrack == subtitle)).ToList()
- : this.SourceTracks.Where(subtitle => !this.SubtitleTracks.Any(track => track.SourceTrack == subtitle)).ToList();
+ return subtitles != null
+ ? subtitles.Where(
+ subtitle => !this.Task.SubtitleTracks.Any(track => track.SourceTrack == subtitle)).ToList()
+ : this.SourceTracks.Where(
+ subtitle => !this.Task.SubtitleTracks.Any(track => track.SourceTrack == subtitle)).ToList();
}
#endregion
|