summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2013-01-13 16:50:49 +0000
committersr55 <[email protected]>2013-01-13 16:50:49 +0000
commitb62992bfb1623ae6c0930c41e00c2b150ea780d9 (patch)
tree4e70b89c49f51b3548904794309584d7e63cec9a
parentd917bc2ad4fa1e2c12828f0e234a32cd19f682c1 (diff)
WinGui: Numerous bug fixes. Many around the automatic selection feature on the Audio Panel.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5168 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs2
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs141
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs1
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs8
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs82
-rw-r--r--win/CS/HandBrakeWPF/Views/OptionsView.xaml2
6 files changed, 117 insertions, 119 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs
index 051052e47..c8238927f 100644
--- a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs
+++ b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs
@@ -260,7 +260,7 @@ namespace HandBrake.ApplicationServices.Model.Encoding
}
/// <summary>
- /// Gets the The UI display value for sample rate
+ /// Gets or sets the The UI display value for sample rate
/// </summary>
public string SampleRateDisplayValue
{
diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs
index 8f7cbbc01..eeb3def77 100644
--- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs
@@ -259,7 +259,7 @@ namespace HandBrakeWPF.ViewModels
{
if (this.SourceTracks != null)
{
- Audio track = sourceTrack ?? this.SourceTracks.FirstOrDefault();
+ Audio track = sourceTrack ?? this.GetPreferredAudioTrack();
if (track != null)
{
this.Task.AudioTracks.Add(new AudioTrack { ScannedTrack = track });
@@ -272,11 +272,20 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
private void AddAllRemainingTracks()
{
+ // For all the source audio tracks
foreach (Audio sourceTrack in this.SourceTracks)
{
- bool found = this.Task.AudioTracks.Any(audioTrack => audioTrack.ScannedTrack == sourceTrack);
+ // Step 1: If "Add only One per language" is turned on, check to see if this language is already added.
+ if (this.CanSkipSourceTrack(sourceTrack))
+ {
+ continue;
+ }
+
+ // Step 2: Check if the track list already contrains this track
+ bool found = this.Task.AudioTracks.Any(audioTrack => Equals(audioTrack.ScannedTrack, sourceTrack));
if (!found)
{
+ // If it doesn't, add it.
this.Add(sourceTrack);
}
}
@@ -287,24 +296,20 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public void AddAllRemainingForSelectedLanguages()
{
- // Figure out the source tracks we want to add
- List<Audio> trackList = new List<Audio>();
- foreach (
- string language in
- this.UserSettingService.GetUserSetting<StringCollection>(
- UserSettingConstants.SelectedLanguages))
- {
- // TODO add support for "Add only 1 per language"
- trackList.AddRange(this.SourceTracks.Where(source => source.Language.Trim() == language));
- }
-
// Add them if they are not already added.
- foreach (Audio sourceTrack in trackList)
+ foreach (Audio sourceTrack in this.GetSelectedLanguagesTracks())
{
- bool found = this.Task.AudioTracks.Any(audioTrack => audioTrack.ScannedTrack == sourceTrack);
+ // Step 1: If "Add only One per language" is turned on, check to see if this language is already added.
+ if (this.CanSkipSourceTrack(sourceTrack))
+ {
+ continue;
+ }
+ // Step 2: Check if the track list already contrains this track
+ bool found = this.Task.AudioTracks.Any(audioTrack => Equals(audioTrack.ScannedTrack, sourceTrack));
if (!found)
{
+ // If it doesn't, add it.
this.Add(sourceTrack);
}
}
@@ -321,18 +326,10 @@ namespace HandBrakeWPF.ViewModels
// Clear out the old tracks
this.Task.AudioTracks.Clear();
- // Get the preferred Language
- IEnumerable<Audio> preferredAudioTracks =
- this.SourceTracks.Where(
- item =>
- item.Language.Contains(
- this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage)));
- Audio preferred = preferredAudioTracks.FirstOrDefault() ?? this.SourceTracks.FirstOrDefault();
-
// Add the preset audio tracks with the preferred language
foreach (AudioTrack track in preset.Task.AudioTracks)
{
- this.Task.AudioTracks.Add(new AudioTrack(track) { ScannedTrack = preferred });
+ this.Task.AudioTracks.Add(new AudioTrack(track) { ScannedTrack = this.GetPreferredAudioTrack() });
}
}
@@ -341,44 +338,24 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
private void AutomaticTrackSelection()
{
- List<Audio> trackList = new List<Audio>();
if (!this.SourceTracks.Any())
{
+ // Clear out the old tracks
+ this.Task.AudioTracks.Clear();
+
return;
}
- // Step 1: Fetch all the Preferred Language settings
- if (this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage) == "Any")
+ // Default all the language tracks to the preferred or first language of this source.
+ foreach (AudioTrack track in this.Task.AudioTracks)
{
- // If we have Any as the preferred Language, just set the first track to all audio tracks.
- trackList.Add(this.SourceTracks.FirstOrDefault());
- }
- else
- {
- // Otherwise, fetch the preferred language.
- foreach (
- Audio item in
- this.SourceTracks.Where(
- item =>
- item.Language.Contains(
- this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage))))
- {
- trackList.Add(item);
- break;
- }
+ track.ScannedTrack = this.GetPreferredAudioTrack();
}
- // Step 2: Handle "All Remaining Tracks" and "All for Selected Languages" or use the default behaviour
+ // Handle the default selection behaviour.
int mode = this.UserSettingService.GetUserSetting<int>(UserSettingConstants.DubModeAudio);
-
switch (mode)
{
- default: // Default by setting all existing tracks to a preferred or first source track.
- foreach (AudioTrack track in this.Task.AudioTracks)
- {
- track.ScannedTrack = trackList.FirstOrDefault() ?? this.SourceTracks.FirstOrDefault();
- }
- break;
case 1: // Adding all remaining audio tracks
this.AddAllRemaining();
break;
@@ -389,35 +366,59 @@ namespace HandBrakeWPF.ViewModels
}
/// <summary>
- /// The get language tracks.
+ /// The get preferred audio track, or the first if none available.
/// </summary>
/// <returns>
- /// The Users desired audio tracks
+ /// The users preferred language, or the first if none available.
/// </returns>
- private List<Audio> GetLanguageTracks()
+ private Audio GetPreferredAudioTrack()
+ {
+ // Get the preferred Language
+ IEnumerable<Audio> preferredAudioTracks =
+ this.SourceTracks.Where(
+ item =>
+ item.Language.Contains(
+ this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage)));
+ return preferredAudioTracks.FirstOrDefault() ?? this.SourceTracks.FirstOrDefault();
+ }
+
+ /// <summary>
+ /// Gets a list of source tracks for the users selected languages.
+ /// </summary>
+ /// <returns>
+ /// A list of source audio tracks.
+ /// </returns>
+ private IEnumerable<Audio> GetSelectedLanguagesTracks()
{
List<Audio> trackList = new List<Audio>();
- if (this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage) == "Any")
+ foreach (string language in this.UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages))
{
- // If we have Any as the preferred Language, just set the first track to all audio tracks.
- trackList.Add(this.SourceTracks.FirstOrDefault());
+ trackList.AddRange(this.SourceTracks.Where(source => source.Language.Trim() == language));
}
- else
+
+ return trackList;
+ }
+
+ /// <summary>
+ /// Checks to see if we can skip over the given source audio track.
+ /// True when the user has set "Add only one per language" feature AND the language is contained in the track list.
+ /// </summary>
+ /// <param name="sourceTrack">
+ /// The source track.
+ /// </param>
+ /// <returns>
+ /// True when the user has set "Add only one per language" feature AND the language is contained in the track list
+ /// </returns>
+ private bool CanSkipSourceTrack(Audio sourceTrack)
+ {
+ bool addOnlyOnePerLanguage = this.UserSettingService.GetUserSetting<bool>(UserSettingConstants.AddOnlyOneAudioPerLanguage);
+ bool sourceTrackLanguageFound = this.Task.AudioTracks.Any(audioTrack => audioTrack.ScannedTrack != null && sourceTrack.Language == audioTrack.ScannedTrack.Language);
+ if (addOnlyOnePerLanguage && sourceTrackLanguageFound)
{
- // Otherwise, fetch the preferred language.
- foreach (
- Audio item in
- this.SourceTracks.Where(
- item =>
- item.Language.Contains(
- this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguage))))
- {
- trackList.Add(item);
- break;
- }
+ return true; // This track can be skipped.
}
- return trackList;
+ return false;
}
#endregion
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index fee34fcb7..7a9461b25 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -1673,7 +1673,6 @@ namespace HandBrakeWPF.ViewModels
this.NotifyOfPropertyChange(() => this.ScannedSource.Titles);
this.SelectedTitle = this.ScannedSource.Titles.FirstOrDefault(t => t.MainTitle)
?? this.ScannedSource.Titles.FirstOrDefault();
- this.SetupTabs();
}
this.ShowStatusWindow = false;
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
index 82c0daa3c..6dc2a44dc 100644
--- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
@@ -800,7 +800,7 @@ namespace HandBrakeWPF.ViewModels
set
{
this.selectedPreferredLangauge = value;
- this.NotifyOfPropertyChange("SelectedPreferreedLangauge");
+ this.NotifyOfPropertyChange(() => SelectedPreferredLangauge);
}
}
@@ -817,7 +817,7 @@ namespace HandBrakeWPF.ViewModels
set
{
this.selectedPreferredSubtitleLangauge = value;
- this.NotifyOfPropertyChange("SelectedPreferredSubtitleLangauge");
+ this.NotifyOfPropertyChange(() => SelectedPreferredSubtitleLangauge);
}
}
@@ -1731,7 +1731,7 @@ namespace HandBrakeWPF.ViewModels
/// <summary>
/// Audio List Move Left
/// </summary>
- public void LanguageMoveLeft()
+ public void LanguageMoveRight()
{
if (this.SelectedAvailableToMove.Count > 0)
{
@@ -1749,7 +1749,7 @@ namespace HandBrakeWPF.ViewModels
/// <summary>
/// Audio List Move Right
/// </summary>
- public void LanguageMoveRight()
+ public void LanguageMoveLeft()
{
if (this.SelectedLangaugesToMove.Count > 0)
{
diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
index 446fab6cf..b52dd961a 100644
--- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs
@@ -120,13 +120,10 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
public void AddAllClosedCaptions()
{
- if (this.UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseClosedCaption))
+
+ foreach (Subtitle subtitle in this.SourceTitlesSubset(null).Where(s => s.SubtitleType == SubtitleType.CC))
{
- foreach (
- Subtitle subtitle in this.SourceTitlesSubset(null).Where(s => s.SubtitleType == SubtitleType.CC))
- {
- this.Add(subtitle);
- }
+ this.Add(subtitle);
}
}
@@ -161,38 +158,6 @@ 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()
@@ -279,6 +244,41 @@ namespace HandBrakeWPF.ViewModels
this.NotifyOfPropertyChange(() => this.Task);
}
+ /// <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.
+ if (this.UserSettingService.GetUserSetting<bool>(UserSettingConstants.UseClosedCaption))
+ {
+ this.AddAllClosedCaptions();
+ }
+ }
+
#endregion
#region Implemented Interfaces
@@ -419,10 +419,8 @@ namespace HandBrakeWPF.ViewModels
private IEnumerable<Subtitle> SourceTitlesSubset(IEnumerable<Subtitle> subtitles)
{
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();
+ ? subtitles.Where(subtitle => !this.Task.SubtitleTracks.Any(track => Equals(track.SourceTrack, subtitle))).ToList()
+ : this.SourceTracks.Where(subtitle => !this.Task.SubtitleTracks.Any(track => Equals(track.SourceTrack, subtitle))).ToList();
}
#endregion
diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml
index c5d5d3e60..9c2080db5 100644
--- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml
+++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml
@@ -236,8 +236,8 @@
<DockPanel Grid.Column="1" Margin="10,0,10,0">
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
- <Button Content="Move Left" VerticalAlignment="Center" Margin="0,0,0,5" cal:Message.Attach="[Event Click] = [Action LanguageMoveLeft]" Width="80" />
<Button Content="Move Right" VerticalAlignment="Center" Margin="0,0,0,5" cal:Message.Attach="[Event Click] = [Action LanguageMoveRight]" Width="80" />
+ <Button Content="Move Left" VerticalAlignment="Center" Margin="0,0,0,5" cal:Message.Attach="[Event Click] = [Action LanguageMoveLeft]" Width="80" />
<Button Content="Clear" VerticalAlignment="Center" Margin="0,0,0,5" cal:Message.Attach="[Event Click] = [Action LanguageClearAll]" Width="80"/>
</StackPanel>
</DockPanel>